1 /**
2 *  Copyright Mikael H�gdahl - triyana@users.sourceforge.net
3 *
4 *  This source is distributed under the terms of the Q Public License version 1.0,
5 *  created by Trolltech (www.trolltech.com).
6 */
7 
8 #ifndef XTrader_h
9 #define XTrader_h
10 
11 #include <FL/Fl.H>
12 #include <FL/fl_ask.H>
13 #include <FL/fl_draw.H>
14 #include <FL/Fl_Box.H>
15 #include <FL/Fl_Double_Window.H>
16 #include <FL/Fl_Tabs.H>
17 #include <gui/BaseView.h>
18 #include <MHDebug.h>
19 #include <MHMessage.h>
20 #include <MHString.h>
21 
22 class Fl_Layout;
23 class Fl_Menu_Bar;
24 struct Fl_Menu_Item;
25 
26 
27 
28 /**
29 *
30 */
31 class Tabs : public Fl_Tabs {
32 public:
Tabs(int x,int y,int w,int h)33                             Tabs (int x, int y, int w, int h) : Fl_Tabs(x, y, w, h, 0) {aOff = false;}
off(bool o)34     void                    off (bool o) {aOff = o;}
resize(int x,int y,int w,int h)35     void                    resize (int x, int y, int w, int h) {
36                                 DBG ("Tabs::resize")
37                                 Fl_Widget::resize(x, y, w, h);
38                                 if (aOff == true) return;
39                                 for (int f = 0; f < this->children(); f++) {
40                                     DBG_LOG1 ("%d", f)
41                                     BaseView* v = (BaseView*) this->child (f);
42                                     //if (this->w() != v->w() || (this->h() - 20) != v->h())
43                                         v->resize (this->x(), this->y() + 20, this->w(), this->h() - 20);
44                                     DBG_LOG4 ("view       %4d, %4d, %4d, %4d", v->x(),  v->y(),  v->w(),  v->h())
45                                 }
46                             }
47 private:
48     bool                    aOff;
49 };
50 
51 
52 
53 /**
54 *  XTrader is main window object and manages the menu,
55 *  toolbar, statusbar and the different tab views
56 */
57 class XTrader : public Fl_Double_Window {
58 public:
59                             XTrader (int w, int h);
60                             ~XTrader ();
61 
62     void                    BuildToolbar ();
63     void                    cbClose ();
cbClose_(Fl_Double_Window * w,void * data)64     static void             cbClose_ (Fl_Double_Window* w, void* data) {XTrader::GetApp()->cbClose ();}
65     void                    cbMenu (int id);
cbMenu_(Fl_Menu_Bar * w,void * data)66     static void             cbMenu_ (Fl_Menu_Bar* w, void* data) {XTrader::GetApp()->cbMenu ((unsigned long)data);}
67     bool                    Close ();
Close(BaseView * view)68     static void             Close (BaseView* view) {XTrader::aaApp->close (view);}
69     static void             FixButton (Fl_Button* b);
70     static int              FontSize ();
GetApp()71     static XTrader*         GetApp () {return aaApp;}
72     int                     handle (int event);
73     void                    LoadWorkSpace ();
74     void                    resize (int x, int y, int w, int h);
75     void                    SavePos ();
76     void                    SaveWorkSpace ();
77     void                    Show (int argc, char** argv);
78     static void             SendMessage (const MH* sender, const char* m1 = 0, const char* m2 = 0, const char* m3 = 0, void* m4 = 0) {XTrader::aaApp->aListeners->Send (sender, m1, m2, m3, m4);}
SetError(const char * message)79     static void             SetError (const char* message) {STRNCPY (XTrader::aaApp->aBuffer, message, 199); XTrader::aaApp->aStatus->label (XTrader::aaApp->aBuffer); fl_beep (FL_BEEP_ERROR); XTrader::aaApp->aStatus->redraw(); Fl::flush();}
SetInfo(const char * message)80     static void             SetInfo (const char* message) {STRNCPY (XTrader::aaApp->aBuffer, message, 199); XTrader::aaApp->aStatus->label (XTrader::aaApp->aBuffer); fl_beep (FL_BEEP_MESSAGE); XTrader::aaApp->aStatus->redraw(); Fl::flush();}
SetMessage(const char * message)81     static void             SetMessage (const char* message) {STRNCPY (XTrader::aaApp->aBuffer, message, 199); XTrader::aaApp->aStatus->label (XTrader::aaApp->aBuffer); XTrader::aaApp->aStatus->redraw(); Fl::flush();}
82     static void             StartWork (const char* message, int showtime = 0);
83     static void             StopWork (const char* message);
84 
85 
86 protected:
87     MHMessage*              aListeners;
88     BaseView*               aLastClosedView;
89     Tabs*                   aTabs;
90     Fl_Menu_Bar*            aMenu;
91     Fl_BorderLayout*        aLayout;
92     Fl_Box*                 aStatus;
93     Fl_BorderLayout*        aTop;
94     Fl_HorizontalLayout*    aToolbar;
95     static XTrader*         aaApp;
96     char                    aBuffer[200];
97     MHString                aLabel;
98     bool                    aInitSize;
99     int                     aX, aY, aW, aH;
100 
101     void                    close (BaseView* view);
102     void                    createMenu ();
103     BaseView*               createView (const char* view);
104     bool                    findView (const char* label);
105     Fl_Menu_Item*           getMenuItem (const char* label);
106 };
107 
108 #endif
109