1 #include "fx.h"
2 
3 
4 /*
5 
6   This is a classical programming example.  Doing it graphically
7   using FOX is, as you see, not a whole lot more involved than
8   its command-line equivalent!
9 
10   Note the following things:
11 
12     - Each FOX application needs one (and only one) application
13       object (FXApp).
14 
15     - Before doing anything, the application object needs to be
16       initialized.  You need to pass argc and argv so that certain
17       command line arguments may be filtered out by FOX (e.g. -display).
18 
19     - You need to create at least one toplevel window; in this case,
20       that is FXMainWindow.
21 
22     - FOX widgets are nested simply by creating them in the right order.
23       Here, we create FXButton as a child of "main."
24 
25     - A single call to FXApp::create() will create X windows for each
26       widget.  Until calling create(), a widget exists only at the client,
27       and has no associated X window yet.
28 
29     - Finally, FXApp::run() will start the main event loop.  This will
30       only return when the application is done.
31 
32 */
33 
34 #include "FXExpression.h"
35 
36 // The entry point where the program starts running
main(int argc,char ** argv)37 int main(int argc,char **argv){
38 
39   // Each FOX GUI program needs one, and only one, application object.
40   // The application objects coordinates some common stuff shared between
41   // all the widgets; for example, it dispatches events, keeps track of
42   // all the windows, and so on.
43   // We pass the "name" of the application, and its "vendor", the name
44   // and vendor are used to search the registry database (which stores
45   // persistent information e.g. fonts and colors).
46   FXApp application("Hello","FoxTest");
47 
48   // Here we initialize the application.  We pass the command line arguments
49   // because FOX may sometimes need to filter out some of the arguments.
50   // This opens up the display as well, and reads the registry database
51   // so that persistent settings are now available.
52   application.init(argc,argv);
53 
54   // This creates the main window. We pass in the title to be displayed
55   // above the window, and possibly some icons for when its iconified.
56   // The decorations determine stuff like the borders, close buttons,
57   // drag handles, and so on the Window Manager is supposed to give this
58   // window.
59   FXMainWindow *main=new FXMainWindow(&application,"Hello",NULL,NULL,DECOR_ALL);
60 
61   // Here we create a button.  The button has a label on it, but no icon in
62   // this case.  An '&' followed by a letter introduces a hot-key so you can
63   // invoke this button from the keyboard.
64   // The button sends an ID_QUIT message to the application object, which
65   // in its default implementation causes the program to quit.
66   new FXButton(main,"&Hello, World!",NULL,&application,FXApp::ID_QUIT);
67 
68   // This "realizes" the widget tree.  This is necessary because GUI's are
69   // a client-server system, i.e. there are actually two programs involved,
70   // a client (in this case, "hello world"), and a server (The X11 server or
71   // Windows GDI).  We can build our C++ widgets but something extra is needed
72   // to tell the server that we want windows on the screen.  Besides windows,
73   // there are various other resources that need to be created, such as icons,
74   // fonts, and so on.  This call recurses through the entire widget tree and
75   // creates them all, insofar as it can know about them.
76   application.create();
77 
78   // Pretty self-explanatory:- this shows the window, and places it in the
79   // middle of the screen.
80   main->show(PLACEMENT_SCREEN);
81 
82   // Now, we actually run the application.  This does not return until we
83   // quit. The function run() is a simple loop which gets events from the
84   // user, executes them, and then waits for the next event, and so on until
85   // we hit the button.
86   return application.run();
87   }
88