ubit
uappli.hpp
1 /************************************************************************
2  *
3  * uappli.hpp: Appplication Context (must be created first)
4  * Ubit GUI Toolkit - Version 6
5  * (C) 2009 | Eric Lecolinet | TELECOM ParisTech | http://www.enst.fr/~elc/ubit
6  *
7  * ***********************************************************************
8  * COPYRIGHT NOTICE :
9  * THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY AND WITHOUT EVEN THE
10  * IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
11  * YOU CAN REDISTRIBUTE IT AND/OR MODIFY IT UNDER THE TERMS OF THE GNU
12  * GENERAL PUBLIC LICENSE AS PUBLISHED BY THE FREE SOFTWARE FOUNDATION;
13  * EITHER VERSION 2 OF THE LICENSE, OR (AT YOUR OPTION) ANY LATER VERSION.
14  * SEE FILES 'COPYRIGHT' AND 'COPYING' FOR MORE DETAILS.
15  * ***********************************************************************/
16 
17 #ifndef _uappli_hpp_
18 #define _uappli_hpp_ 1
19 #include <cstdio>
20 #include <cstdarg>
21 #include <ubit/udisp.hpp>
22 #include <ubit/uconf.hpp>
23 namespace ubit {
24 
27  typedef std::vector<UEventFlow*> UFlowList;
28 
29 
32  typedef std::vector<UDisp*> UDispList;
33 
34 
79  class UAppli {
80  public:
81  static UConf conf;
91  UAppli(int& argc, char** argv,
92  UOption* command_line_options = null,
93  const char* configuration_file = null);
116  virtual ~UAppli();
117 
118  static UAppli& appli();
124  static UAppli* getAppli();
129  static UConf& getConf() {return conf;}
131 
132  static const char* getVersion();
134 
135  static bool isUsingGL() {return conf.is_using_gl;}
137 
138  static bool isRunning();
140 
141  static bool isExiting();
143 
144  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
145 
146  static void add(UWin&);
162  static void add(UWin*);
164 
165  static void remove(UWin& win, bool auto_delete = true);
175  static void remove(UWin*, bool auto_delete = true);
177 
178  static int start();
183  static void quit(int status = 0);
188  static UFrame* getMainFrame();
193  static const UStr& getName();
195 
196  static UStr getTitle();
198 
199  static void setTitle(const UStr& title);
201 
202  static void setFocus(UView*);
208  static void updateAll(const UUpdate& mode = UUpdate::layoutAndPaint);
214  // - - - Errors and warnings - - - - - - - - - - - - - - - - - - - - - - - -
215 
216  static UErrorHandler& getErrorHandler();
218 
219  static void setErrorHandler(UErrorHandler&);
221 
222 
223  static void error(const char* funcname, const char* format, ...);
225 
226  static void warning(const char* funcname, const char* format, ...);
228 
229  static void fatalError(const char* funcname, const char* format, ...);
231 
232 
233  static void raiseError(int errnum, const UObject*,
234  const char* funcname, const char* format, ...);
250  static void raiseError(int errnum, const UObject*,
251  const char* funcname, const char* format, va_list);
253 
254 
255  // - - - Time and Timeouts - - - - - - - - - - - - - - - - - - - - - - - - -
256 
257  static unsigned long getTime();
259 
260  static void setMotionLag(unsigned long app_lag, unsigned long nat_lag);
266  static void addTimeout(unsigned long msec_delay, int ntimes, UCall& callback);
279  static void postpone(UCall& callback);
290  // - - - Displays and Event Flows - - - - - - - - - - - - - - - - - - - - -
291 
292  static UDisp* getDisp();
294 
295  static UDisp* getDisp(int ID);
303  static const UDispList& getDispList();
304  //< returns the list of Displays that are connected with this UAppli.
305 
306  static UDisp* openDisp(const UStr& display_name);
318  static void closeDisp(UDisp*);
320 
321  static UEventFlow* getFlow(int ID = 0);
331  static const UFlowList& getFlowList();
333 
334  static USelection* getSelection(int ID = 0);
343  // - - - Inter-client Messages - - - - - - - - - - - - - - - - - - - - - - -
344 
345  static void onMessage(const UStr& port_name, UCall& callback);
351  static UMessagePort& getMessagePort(const UStr& name);
353 
354  static UMessagePort* findMessagePort(const UStr& name);
356 
359 
360 
361  // - - - Misc - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
362 
363  static const UStr& getImaPath();
365 
366  static void setImaPath(const UStr& pathname);
372  static UStyleSheet& getStyleSheet();
374 
375  static const UStyle& getDefaultStyle();
377 
378  UMenu* getOpenedMenu();
380 
381  static bool hasTelePointers();
383 
384  // - - - Impl - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
385 
386  friend class UEventFlow;
387 
388  static class UAppliImpl& impl;
390 
391  UStr& initConf(int& argc, char** argv, UOption*, const char* confile);
393 
394  static void internalError(const char* fun, const char* format, ...);
395 
396  static void deleteNotify(UDisp*);
398 
399  static void deleteNotify(UElem*);
401 
402  static void deleteNotify(UView*);
404  };
405 
406 
407  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
410  class UErrorHandler : public UObject {
411  public:
412  UCLASSDEF("UErrorHandler", UErrorHandler, null)
413 
414  UErrorHandler(const UStr& label, std::ostream* out_stream = &std::cerr);
422  virtual ~UErrorHandler();
423 
424  virtual void setOutputStream(std::ostream*);
426 
427  virtual void setOutputBuffer(UStr*);
429 
430  UStr& label() {return *plabel;}
432 
433  virtual void warning(const char* funcname, const char* format, ...) const;
435 
436  virtual void error(const char* funcname, const char* format, ...) const;
438 
439  virtual void error(int errnum, const UObject*, const char* funcname,
440  const char* format, ...) const;
442 
443  virtual void parserError(int errnum, const UChar* text_buffer,
444  const char* msg_start, const UStr& name,
445  const char* msg_end, const UChar* line) const;
447 
448  virtual void raiseError(int errnum, const UObject*, const char* funcname,
449  const char* format, va_list) const;
461  virtual void raiseError(int errnum, UStr* msg) const;
462 
463  virtual const char* getErrorName(int errnum) const;
464  virtual void formatMessage(UError&, const char* format, va_list) const;
465  virtual void printOnStream(const UError&) const;
466  virtual void printOnBuffer(const UError&) const;
467 
468  protected:
469  uptr<UStr> plabel;
470  uptr<UStr> pbuffer;
471  std::ostream* fout;
472  };
473 
474 }
475 #endif
476 
UMenu * getOpenedMenu()
[impl] returns the menu that is currently opened (null otherwise).
Definition: uappli.cpp:537
specification and retreiving of non standard options on the command line.
Definition: uconf.hpp:51
static void onMessage(const UStr &port_name, UCall &callback)
adds a callback that is fired when data is received on this port.
Definition: uappli.cpp:596
static UEventFlow * getFlow(int ID=0)
returns the Event Flow corresponding to this ID (null if not found).
Definition: uappli.cpp:522
static void raiseError(int errnum, const UObject *, const char *funcname, const char *format,...)
raises an error: prints out a message and/or generate an exception.
static void closeDisp(UDisp *)
closes a connection with another X display.
Definition: uappli.cpp:507
static const UUpdate layoutAndPaint
layout then paint: prefined constant for UUpdate(LAYOUT|PAINT);
Definition: uupdate.hpp:50
text selection.
Definition: uselection.hpp:25
static UAppli * getAppli()
returns a pointer the UAppli instance of the program.
Definition: uappli.cpp:148
UFrame: toplevel and main window.
Definition: udialogs.hpp:117
Error management.
Definition: uappli.hpp:410
static USelection * getSelection(int ID=0)
returns the text selection manager.
Definition: uappli.cpp:529
UStr & label()
returns the label property of this UErrorHandler.
Definition: uappli.hpp:430
Definition: uappliImpl.hpp:40
static const UStr & getName()
returns argv[0], the name of the application.
Definition: uappli.cpp:160
static int start()
starts the event main loop of the application.
Definition: uappli.cpp:240
static UMessagePort * findMessagePort(const UStr &name)
Ubit Messages:
Definition: uappli.cpp:586
static UMessagePort & getMessagePort(const UStr &name)
Ubit Messages:
Definition: uappli.cpp:591
Display Context.
Definition: udisp.hpp:44
static void fatalError(const char *funcname, const char *format,...)
raises a fatal error; shortcut for raiseError(UError::FATAL_ERROR, ...).
Definition: uappli.cpp:618
static void error(const char *funcname, const char *format,...)
raises an error; shortcut for raiseError(UError::ERROR ...).
Definition: uappli.cpp:604
static void setImaPath(const UStr &pathname)
get/set the default image path.
Definition: uappli.cpp:546
static UDisp * getDisp()
returns the default display of the appplication.
Definition: uappli.cpp:487
static void setErrorHandler(UErrorHandler &)
changes the current error handler (see UErrorHandler).
Definition: uappli.cpp:660
static bool isRunning()
returns true if the main loop is running.
Definition: uappli.cpp:156
static void updateAll(const UUpdate &mode=UUpdate::layoutAndPaint)
updates all windows.
Definition: uappli.cpp:231
static void quit(int status=0)
quits the main loop of the application.
Definition: uappli.cpp:260
static void setFocus(UView *)
gives the input focus to this view.
Definition: uappli.cpp:184
UStr & initConf(int &argc, char **argv, UOption *, const char *confile)
[impl] parses the config specs, inits the global data of the appli, returns the display name...
Definition: uappli.cpp:75
static const UStyle & getDefaultStyle()
returns the default element style.
Definition: uappli.cpp:169
Impl.
Definition: umessage.hpp:50
specifies how to update UElem, UBox, UWin objects and subclasses.
Definition: uupdate.hpp:25
static UConf conf
configuration of the application, must be set BEFORE the UAppli is created.
Definition: uappli.hpp:81
static bool isUsingGL()
returns true if OpenGL is used for rendering graphics.
Definition: uappli.hpp:135
static UErrorHandler & getErrorHandler()
returns the current error handler (see UErrorHandler).
Definition: uappli.cpp:647
static bool isExiting()
returns true if the applicating is exiting.
Definition: uappli.cpp:150
The Application Context.
Definition: uappli.hpp:79
lightweight general purpose container.
Definition: uelem.hpp:44
static UAppli & appli()
returns a reference to the UAppli instance of the program.
Definition: uappli.cpp:142
static void setMotionLag(unsigned long app_lag, unsigned long nat_lag)
changes the motion lag.
Definition: uappli.cpp:562
static void setTitle(const UStr &title)
changes the title of the Main Frame (
Definition: uappli.cpp:180
static UConf & getConf()
returns the configuration of the application,
Definition: uappli.hpp:129
base class of callback objects for firing functions or methods.
Definition: ucall.hpp:144
static const UFlowList & getFlowList()
returns the list of all event flows on all displays (see getFlow()).
Definition: uappli.cpp:517
static void add(UWin &)
adds a window (UFrame, UDialog, etc) to the UAppli.
UMenu: pulldown and cascaded menux.
Definition: umenu.hpp:64
Event Flow.
Definition: ueventflow.hpp:34
static void deleteNotify(UDisp *)
[impl] notifies that a display is being destroyed.
static UFrame * getMainFrame()
returns the Main Frame (if any, null otherwise).
Definition: uappli.cpp:158
static class UAppliImpl & impl
[impl] reference to the object that stores the application data.
Definition: uappli.hpp:388
Box View.
Definition: uview.hpp:65
configuration of the UAppli.
Definition: uconf.hpp:68
static UStyleSheet & getStyleSheet()
returns the style sheet of the application.
Definition: uappli.cpp:165
Ubit exception.
Definition: uobject.hpp:27
Definition: uclassImpl.hpp:155
static UMessagePortMap * getMessagePortMap()
[impl] Ubit Messages.
Definition: uappli.cpp:584
Ubit Message Port.
Definition: umessage.hpp:36
Definition: uhardfont.hpp:31
static UDisp * openDisp(const UStr &display_name)
opens a connection on another X display.
Definition: uappli.cpp:497
static UStr getTitle()
returns the title of the Main Frame (
Definition: uappli.cpp:175
static void addTimeout(unsigned long msec_delay, int ntimes, UCall &callback)
fire this callback after a given delay.
Definition: uappli.cpp:576
static unsigned long getTime()
returns the current time.
Definition: uappli.cpp:567
static const UStr & getImaPath()
see setImaPath().
Definition: uappli.cpp:542
static void warning(const char *funcname, const char *format,...)
raises a warning; shortcut for raiseError(UError::WARNING, ...).
Definition: uappli.cpp:611
Base class for windows and menus.
Definition: uwin.hpp:47
UAppli(int &argc, char **argv, UOption *command_line_options=null, const char *configuration_file=null)
constructor for creating the Application Context.
Definition: uappli.cpp:90
static bool hasTelePointers()
[impl] returns true if the appli has telepointers.
Definition: uappli.cpp:511
Compiled Object Style.
Definition: ustyle.hpp:44
Ubit String.
Definition: ustr.hpp:72
static const char * getVersion()
returns the version of the Ubit toolkit (for instance "6.0.0").
Definition: uappli.cpp:152
static void postpone(UCall &callback)
fire this callback when the main loop becomes idle.
Definition: uappli.cpp:569
Base class of most Ubit objects (SEE DETAILS!).
Definition: uobject.hpp:113