00001 // This is core/vgui/vgui.h 00002 #ifndef vgui_h_ 00003 #define vgui_h_ 00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE 00005 #pragma interface 00006 #endif 00007 //: 00008 // \file 00009 // \author Philip C. Pritchett, Robotics Research Group, University of Oxford 00010 // \date 30 Sep 99 00011 // \brief Namespace with a singleton vgui_toolkit instance. 00012 // 00013 // \verbatim 00014 // Modifications 00015 // 30-SEP-1999 P.Pritchett - Initial version. 00016 // 26 Oct 1999 fsm. various changes to facilitate the port of old impl code. 00017 // 30-AUG-2000 Marko Bacic, Oxford RRG -- Added flags to support MFC accel. 00018 // 26-APR-2002 K.Y.McGaul - Added some doxygen style comments. 00019 // 16-NOV_2007 Gamze Tunali - Added a new type of dialog called dialog_extensions 00020 // \endverbatim 00021 00022 #include "dll.h" 00023 #include <vcl_string.h> 00024 #include <vcl_iosfwd.h> // for the status bar vcl_ostream. 00025 00026 class vgui_window; 00027 class vgui_adaptor; 00028 class vgui_event; 00029 class vgui_menu; 00030 class vgui_dialog_impl; 00031 class vgui_dialog_extensions_impl; 00032 class vgui_tableau; 00033 class vgui_toolkit; 00034 struct vgui_tableau_sptr; 00035 00036 //: Namespace with a singleton vgui_toolkit instance. 00037 // 00038 // vgui is a namespace with a singleton vgui_toolkit instance 00039 // which acts as an abstract factory. The static methods on 00040 // vgui simply dispatch the call to the selected toolkit. 00041 // 00042 // Order of things : 00043 // 1. Registration. Toolkits available to the application are registered 00044 // in a global list. Registration is done by the constructor of vgui_toolkit, 00045 // so creating a vgui_toolkit amounts to registration. Sometimes this can be 00046 // done at library initialization time but sometimes it can't, e.g. for 00047 // static builds. In that case, a {\em tag function} must be called 00048 // explicitly. See vgui_tag.* and vgui_register_all.cxx. 00049 // 00050 // 2. Choice of toolkit to use. Several toolkits may be available, and so 00051 // a choice must be made as to which to use. The choice of toolkit is 00052 // specified with the select() methods. 00053 // 00054 // 3. Initialization of toolkit. There is only one method for doing this, namely 00055 // vgui::init(argc, argv); 00056 // which needs a plausible command line. If no toolkit has been selected 00057 // the init() function will try to choose one for you based on the 00058 // given command line. 00059 00060 class vgui 00061 { 00062 //: Selected toolkit instance. 00063 static vgui_DLLDATA vgui_toolkit* instance_; 00064 00065 //: True once init() has been called. 00066 static vgui_DLLDATA bool init_called; 00067 00068 //: True once quit() has been called. 00069 static vgui_DLLDATA bool quit_called; 00070 public: 00071 //: Needed for statusbar. 00072 static vgui_DLLDATA vcl_ostream out; 00073 00074 //: Method for determining if a given toolkit is available. 00075 static bool exists(char const *toolkit); 00076 00077 //: Method for selecting a specific toolkit. 00078 // This will abort() if given a toolkit which is not available. 00079 static void select(char const *toolkit); 00080 00081 //: Select a toolkit from command line arguments and environment variables. 00082 // 00083 // First, the command line is scanned for --factory=xxx options. 00084 // 00085 // If no such option is given, the environment variable 'vgui' is inspected. 00086 // 00087 // If no such environment variable is set, no toolkit is selected and the 00088 // function returns false. Else the return value is true. 00089 static bool select(int &argc, char **argv); 00090 00091 //: Initialize the selected toolkit passing it the given command line. 00092 static void init(int &argc, char **argv); 00093 00094 //: Uninitialize any previously initialized toolkit. 00095 // 00096 // This will be called before application exit; the user normally 00097 // need not call this. 00098 // 00099 static void uninit(); 00100 00101 // Factory methods 00102 //---------------- 00103 00104 //: Produce window with menubar. 00105 static vgui_window* produce_window(int width, int height, 00106 vgui_menu const & menubar, 00107 vcl_string const &title =""); 00108 //: Produce window without menubar. 00109 static vgui_window* produce_window(int width, int height, 00110 vcl_string const &title =""); 00111 //: Produce dialog box. 00112 static vgui_dialog_impl* produce_dialog(vcl_string const &name); 00113 00114 //: Produce dialog box. 00115 static vgui_dialog_extensions_impl* produce_extension_dialog(vcl_string const &name); 00116 00117 // Convenience methods 00118 //-------------------- 00119 00120 //: Display this tableau and run till dead (no menubar). 00121 static int run(vgui_tableau_sptr const&, int w, int h, 00122 vcl_string const &title =""); 00123 00124 //: Display this tableau and run till dead (with menubar) 00125 static int run(vgui_tableau_sptr const&, int w, int h, 00126 vgui_menu const &menubar, vcl_string const &title =""); 00127 00128 //: Create the vgui_window but don't run it (no menubar). 00129 static vgui_window *adapt(vgui_tableau_sptr const&, int w, int h, 00130 vcl_string const &title =""); 00131 00132 //: Create the vgui_window but don't run it (with menubar). 00133 static vgui_window *adapt(vgui_tableau_sptr const&, int w, int h, 00134 vgui_menu const &, vcl_string const &title =""); 00135 00136 // Functions for event-loop management 00137 //------------------------------------ 00138 00139 //: Run until quit is called. 00140 static int run(); 00141 00142 //: Run the next event in the event queue. 00143 static void run_one_event(); 00144 00145 //: Run all events in the event queue. 00146 static void run_till_idle(); 00147 00148 //: Remove all events from the event queue. 00149 static void flush(); 00150 00151 //: Add event to the event queue. 00152 static void add_event(vgui_event const &); 00153 00154 //: Quit application. 00155 static void quit(); 00156 00157 //: Was quit called earlier? 00158 // 00159 // This is to help application-driven vgui programs determine when 00160 // the user has requested the GUI to close. 00161 static bool quit_was_called(); 00162 }; 00163 00164 00165 // Trigger the registration of all the available toolkit 00166 // implementations. This variable has to appear in a translation unit 00167 // (.cxx file) that has a function used by the main 00168 // program. Otherwise, for static libraries, the linker will not link 00169 // in the corresponding object file, which means the variable is never 00170 // initialized, which means that no toolkits are registered. Since 00171 // anyone using vgui must call vgui::init at some point, this 00172 // translation unit will be included in the final executable, and 00173 // therefore the trigger variable below will be initialized, causing 00174 // the toolkits to be registered. 00175 int vgui_register_all_implementations(); 00176 static int trigger = vgui_register_all_implementations(); 00177 00178 // This function is here just to avoid "unused variable" compiler warnings 00179 static int dummy_use_of_trigger() { return trigger? 0: dummy_use_of_trigger(); } 00180 00181 #endif // vgui_h_