FLTK Utility Library and Widget Collection (FLU): Flu_DND.h Source File

Main Page | Class Hierarchy | Class List | File List | Class Members

# Flu_DND.h

    00001 // $Id: Flu_DND.h,v 1.17 2003/08/20 16:29:41 jbryan Exp $
    00002
    00003 /***************************************************************
    00004  *                FLU - FLTK Utility Widgets
    00005  *  Copyright (C) 2002 Ohio Supercomputer Center, Ohio State University
    00006  *
    00007  * This file and its content is protected by a software license.
    00008  * You should have received a copy of this license with this file.
    00009  * If not, please contact the Ohio Supercomputer Center immediately:
    00010  * Attn: Jason Bryan Re: FLU 1224 Kinnear Rd, Columbus, Ohio 43212
    00011  *
    00012  ***************************************************************/
    00013
    00014
    00015
    00016 #ifndef _FLU_DND_H
    00017 #define _FLU_DND_H
    00018
    00019 #include <FL/Fl.H>
    00020 #include <FL/fl_draw.H>
    00021
    00022 #include <stdlib.h>
    00023 #include <string.h>
    00024
    00025 #include "FLU/Flu_Enumerations.h"
    00026
    00027 #define FLU_DND_MAX_TYPES 32
    00028
    00030 class FLU_EXPORT Flu_DND_Event
    00031 {
    00032   friend class Flu_DND;
    00033
    00034  public:
    00035
    00037   Flu_DND_Event();
    00038
    00040   ~Flu_DND_Event();
    00041
    00043   inline bool event_is_valid() const
    00044     { return dragging; }
    00045
    00047   inline bool event_is_text() const
    00048     { return( _text != 0 ); }
    00049
    00051   inline bool event_is_other() const
    00052     { return( _text == 0 ); }
    00053
    00055
    00056   inline const char* text() const
    00057     { return _text; }
    00058
    00060
    00061   inline void* data() const
    00062     { return _data; }
    00063
    00065
    00066   inline const char* data_type() const
    00067     { return _dataType; }
    00068
    00070   inline bool is_data_type( const char *t ) const
    00071     { if( !_dataType ) return 0; else return( strcmp( _dataType, t ) == 0 ); }
    00072
    00074   inline int grab_x() const
    00075     { return _grab_x; }
    00076
    00078   inline int grab_y() const
    00079     { return _grab_y; }
    00080
    00082   inline int drop_x() const
    00083     { return _drop_x; }
    00084
    00086   inline int drop_y() const
    00087     { return _drop_y; }
    00088
    00089  private:
    00090
    00091   bool dragging;
    00092   void *objUnderMouse;
    00093   char *_text, *_dataType;
    00094   void *_data;
    00095   int _grab_x, _grab_y, _drop_x, _drop_y;
    00096   bool exit;
    00097
    00098   void clear();
    00099 };
    00100
    00102
    00108 class FLU_EXPORT Flu_DND
    00109 {
    00110  public:
    00111
    00113   inline void dnd_callback( void (*cb)(const Flu_DND_Event*,void*), void *cbd = 0 )
    00114     { dndCallback = cb; dndCallbackData = cbd; }
    00115
    00116  protected:
    00117
    00119   Flu_DND( const char *thisType );
    00120
    00122   virtual ~Flu_DND();
    00123
    00125   inline bool dnd_event_is_text() const
    00126     { return( dndEvent.dragging && !dndEvent._data ); }
    00127
    00129   inline bool dnd_event_is_other() const
    00130     { return( dndEvent.dragging && dndEvent._data ); }
    00131
    00133   inline bool dnd_is_dragging() const
    00134     { return dndEvent.dragging; }
    00135
    00137   inline bool dnd_is_data_type( const char *t ) const
    00138     { return dndEvent.is_data_type( t ); }
    00139
    00141   inline void dnd_allow_text( bool b )
    00142     { allowTextEvents = b; }
    00143
    00145   inline bool dnd_allow_text() const
    00146     { return allowTextEvents; }
    00147
    00149   inline void dnd_allow_dragging( bool b )
    00150     { allowDragging = b; }
    00151
    00153   inline bool dnd_allow_dragging() const
    00154     { return allowDragging; }
    00155
    00157   inline void dnd_allow_dropping( bool b )
    00158     { allowDropping = b; }
    00159
    00161   inline bool dnd_allow_dropping() const
    00162     { return allowDropping; }
    00163
    00165   void dnd_allow_type( const char *t );
    00166
    00168   bool dnd_type_allowed( const char *t ) const;
    00169
    00171   void dnd_grab( void *data, const char *type );
    00172
    00174   int dnd_handle( int event );
    00175
    00177   virtual void on_dnd_release();
    00178
    00180   virtual void on_dnd_enter();
    00181
    00183   virtual void on_dnd_leave();
    00184
    00186   virtual void on_dnd_drop( const Flu_DND_Event *e );
    00187
    00189   virtual bool on_dnd_drag( int X, int Y );
    00190
    00191  private:
    00192
    00193   bool ok2drop();
    00194
    00195   static Flu_DND_Event dndEvent;
    00196   bool allowTextEvents, allowDragging, allowDropping;
    00197   char* _thisType;
    00198   char* allowedTypes[FLU_DND_MAX_TYPES];
    00199   int nTypes;
    00200
    00201   void (*dndCallback)(const Flu_DND_Event*,void*);
    00202   void *dndCallbackData;
    00203
    00204 };
    00205
    00206 #endif