Fl_OpDesk
Fl_OpDesk.H
Go to the documentation of this file.
00001 #ifndef _FL_OPDESK_H
00002 #define _FL_OPDESK_H
00003 
00004 //INSERT-LGPL-HEADER-HERE//
00005 
00114 
00118 
00119 #include <FL/Fl.H>
00120 #include <FL/Fl_Scroll.H>
00121 #include <FL/fl_draw.H>
00122 
00123 #include <vector>               // STL vector array
00124 #include <cstdio>               // stderr
00125 
00126 #include "Fl_OpBox.H"
00127 #include "Fl_OpConnect.H"
00128 
00132 enum Fl_OpConnectStyle {
00133     FL_OPCONNECT_STYLE_STRAIGHT,        
00134     FL_OPCONNECT_STYLE_TRACE,           
00135     FL_OPCONNECT_STYLE_CURVE,           
00136 };
00137 
00176 class Fl_OpDesk : public Fl_Scroll {
00177 
00178     int opconnect_spacing;              // desk's spacing between opconnect lines
00179     Fl_OpConnectStyle opconnect_style;  // desk's line style (straight,trace) for opconnect lines
00180     int opconnect_width;                // default line width for new opconnect's
00181     Fl_Color opconnect_color;           // default color used for new opconnect's
00182     int opbox_selectedbordersize;       // thickness of selected OpBox's border
00183     std::vector<Fl_OpConnect> connects; // our array of all button interconnects
00184     std::vector<Fl_OpBox*> boxes;       // boxes on desk
00185 
00186     // Clipboard
00187     std::vector<Fl_OpBox*> box_clipboard;               // copy/paste clipboard for Fl_OpBox's
00188 
00189     // Connection dragging
00190     char dragging;                      // on/off flag: 1=dragging, 0=not
00191     int dragging_x1, dragging_y1,       // when dragging=1, these contain the two
00192         dragging_x2, dragging_y2;       // points to draw a connection line between.
00193 
00194 protected:
00195     // PROTECTED METHODS
00196     // Drawing..
00197     void DrawLine(float x1, float y1, float x2, float y2) const;
00198     void DrawConnect(Fl_OpConnect *con) const;
00199 
00200     // Connections..
00201     friend class Fl_OpButton;
00202     friend class Fl_OpBox;
00203     int _ConnectOnly(Fl_OpButton *srcbut, Fl_OpButton *dstbut, std::string &errmsg);
00204     int _DisconnectOnly(Fl_OpButton *a, Fl_OpButton *b);
00205     void CopyConnections(std::vector<Fl_OpBox*> origboxes, std::vector<Fl_OpBox*> copyboxes);
00206 
00207     // Dragging
00208     void DraggingConnection(Fl_OpButton *b);
00209     void DraggingBoxes(int xdiff, int ydiff);
00210 
00211     void _AddBox(Fl_OpBox *b);
00212     void _RemoveBox(Fl_OpBox *b);
00213 
00214 public:
00215     // CTOR
00216     Fl_OpDesk(int X,int Y,int W,int H,const char *L=0);
00217     ~Fl_OpDesk();
00218 
00219     // FLTK
00220     void draw();
00221     int handle(int e);
00222 
00223     // OPBOX
00224     void DeleteBox(Fl_OpBox *box);
00225     int GetOpBoxIndex(const Fl_OpBox*) const;
00226     int GetOpBoxTotal() const;
00227     Fl_OpBox* GetOpBox(int index);
00228     const Fl_OpBox* GetOpBox(int t) const;
00229 
00230     // SELECTION
00231     int DeselectAll();
00232     int SelectAll();
00233 
00234     // COPY/PASTE
00235     virtual int DeleteSelected();
00236     virtual int CutSelected();
00237     virtual int CopySelected();
00238     virtual int PasteSelected();
00239 
00240     // SEARCH FUNCTIONS
00241     Fl_OpBox*    FindBoxForFullName(const std::string& fullname, std::string &errmsg);
00242     Fl_OpButton* FindButtonForFullName(const std::string& fullname, std::string &errmsg);
00243     int          FindButtonByPtr(Fl_OpButton *b) const;
00244     Fl_OpBox*    FindBoxByLabel(std::string &lname, std::string &errmsg);
00245     Fl_OpButton* FindButtonUnderMouse();
00246 
00247     // MAKE/DELETE CONNECTIONS, CONNECTION ATTRIBUTES
00248     int GetOpConnectSpacing() const;
00249     void SetOpConnectSpacing(int val);
00250     int GetOpConnectWidth() const;
00251     void SetOpConnectWidth(int val);
00252     Fl_Color GetOpConnectColor() const;
00253     void SetOpConnectColor(Fl_Color val);
00254     int GetConnectionsTotal() const;
00255     Fl_OpConnect* GetConnection(int index);
00256     Fl_OpConnect* GetConnection(Fl_OpButton *srcbut, Fl_OpButton *dstbut);
00257     Fl_OpConnect* GetLastOpConnect();
00258     int Connect(Fl_OpButton *srcbut, Fl_OpButton *dstbut, std::string &errmsg);
00259     int Connect(Fl_OpBox *srcbox, const std::string& srcbut_lname, 
00260                 Fl_OpBox *dstbox, const std::string& dstbut_lname,
00261                 std::string &errmsg);
00262     int Connect(const std::string& src_name, 
00263                 const std::string& dst_name,
00264                       std::string& errmsg);
00265     int Disconnect(Fl_OpButton *a, Fl_OpButton *b);
00266     int Disconnect(Fl_OpBox *box);
00267     void DisconnectAll();
00268     void BringToFront(Fl_OpBox *box);
00269 
00270     // DISPLAY STYLE
00271     Fl_OpConnectStyle GetConnectStyle(void) const;
00272     void              SetConnectStyle(Fl_OpConnectStyle val);
00273     int GetOpBoxSelectedBorderSize() const;
00274     void SetOpBoxSelectedBorderSize(int val);
00275 
00276     // MISC
00277     void Clear();
00278     int ParseFullButtonName(const std::string &fullname,
00279                                   std::string &boxname,
00280                                   std::string &butname,
00281                                   std::string &errmsg);
00282 
00283     // VIRTUALS
00284 
00304     virtual void ConnectionError(Fl_OpButton* /*srcbut*/, Fl_OpButton* /*dstbut*/, std::string &errmsg) {
00305         fprintf(stderr, "CONNECTION ERROR: %s\n", errmsg.c_str());
00306     }
00307 };
00308 
00309 #endif /*_FL_OPDESK_H*/