ubit
uwin.hpp
1 /************************************************************************
2  *
3  * uwin.hpp: ubit windows
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 _uwin_hpp_
18 #define _uwin_hpp_ 1
19 #include <ubit/ubox.hpp>
20 #include <ubit/uview.hpp>
21 namespace ubit {
22 
23  class UWinPlacement;
24  class UWinImpl;
25 
47  class UWin : public UBox {
48  public:
49  UCLASS(UWin)
50 
51  UWin(UArgs nodelist = UArgs::none);
53 
54  virtual ~UWin();
55 
56  virtual UWin* toWin() {return this;} // redefined
57  virtual const UWin* toWin() const {return this;} // redefined
58 
59  static UStyle* createStyle(); // redefined
60  virtual int getDisplayType() const {return wmodes.IS_HARDWIN ? HARDWIN : SOFTWIN;}
61 
62  // - - - position - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
63 
64  virtual UWin& setTitle(const UStr& title);
66 
67  virtual UStr getTitle() const;
69 
70  virtual void setPos(UMouseEvent&, float x = 0, float y = 0);
75  virtual void setPos(const UWin& win, const UPoint&, UDisp* = null);
77 
78  virtual void setPos(const UView& view, const UPoint&);
80 
81  virtual void setPos(const UView& view, const UWinPlacement&);
83 
84  virtual void setScreenPos(const UPoint&, UDisp* = null);
86 
87  virtual void centerOnScreen(UDisp* = null);
88  // centers the window on the screen.
89 
90  virtual UPoint getPos(const UWin& win, UDisp* = null) const;
92 
93  virtual UPoint getPos(const UView& view) const;
95 
96  virtual UPoint getScreenPos(UDisp* = null) const;
98 
99  // - - - size and stacking order - - - - - - - - - - - - - - - - - - - - - - -
100 
101  virtual float getWidth(UDisp* = null) const;
103 
104  virtual float getHeight(UDisp* = null) const;
106 
107  virtual UDimension getSize(UDisp* = null) const;
109 
110  virtual void setSize(const UDimension&, UDisp* = null);
112 
113  virtual void adjustSize();
119  void pack() {adjustSize();}
121 
122  virtual void setFullScreen(bool state, UDisp* = null);
124 
125  virtual void toBack(UDisp* = null);
127 
128  virtual void toFront(UDisp* = null);
130 
131  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
132 
133  virtual bool isShown() const;
135 
136  virtual bool isShown(UDisp*) const;
138 
139  virtual bool isModal() const;
141 
142  virtual void setModal(bool = true) ;
144 
145  virtual void show(bool state = true) {UWin::show(state, null);}
154  virtual void show(bool state, UDisp*);
156 
157  virtual int showModal(UDisp* = null);
165  virtual void close(int status = 0);
190  void repaint() {update(UUpdate::paint);} // redefined
191  void update() {update(UUpdate::layoutAndPaint);} // redefined
192 
193  virtual void update(const UUpdate& update_options, UDisp* = null);
206  virtual void doUpdate(const UUpdate&, UDisp* = null); // redefined
207 
208  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
209 
210  bool isHardwin() const {return wmodes.IS_HARDWIN;}
216  bool isSoftwin() const {return !wmodes.IS_HARDWIN;}
223  virtual UWin& setSoftwin(bool state = true);
230  UWin& setSoftWin(bool state = true) {return setSoftwin(state);}
232 
233  UWin& softwin(bool state = true) {return setSoftwin(state);}
235 
236  bool isMapped() const {return wmodes.IS_MAPPED;}
237  void setMapped(bool s) {wmodes.IS_MAPPED = s;}
238 
239  // - - - Impl. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
240 
241  virtual bool realize();
246  UView* getWinView(UDisp* = null) const;
248 
249  UHardwinImpl* getHardwin(UDisp* = null) const;
255 #ifndef NO_DOC
256  UHardwinImpl* hardImpl() const;
257  USoftwinImpl* softImpl() const;
258  virtual void highlight(bool state);
259  void addWinView(UView*);
260  virtual void initView(UView* parent_view);
261  virtual UView* initViewImpl(UView* parent_view, UDisp*);
262  virtual void deleteViewsInside(const std::vector<UView*>& parent_views);
263 
264  protected:
265  friend class UBox;
266  friend class UAppli;
267  friend class UAppliImpl;
268  friend class UHardwinImpl;
269  friend class USoftwinImpl;
270 
271  struct Modes {
272  unsigned IS_HARDWIN:1; // has a UHardwinImpl implementation (USoftWin otherwise)
273  unsigned IS_MENU:1;
274  unsigned IS_DIALOG:1;
275  unsigned IS_FRAME:1;
276  unsigned IS_MAINFRAME:1; // main frame window?
277  unsigned IS_MODAL:1; // this window is modal
278  unsigned IS_AUTO_OPENED:1; // automatically opened if parent is ARMable
279  unsigned IS_MAPPED:1; // this window is currently mapped on the screen
280  };
281  Modes wmodes;
282  std::vector<UWinImpl*> wimpl; // liste pour multiple displays
283 
284  virtual UView* realizeSoftwin(UWin* hardwin, UView* hardwin_view,
285  UDisp*, bool add_to_the_end);
286 
287  virtual bool realizeHardwin(char window_type);
288  // internal realization function (window_type as defined in UNatWin).
289 
290  virtual void realizeChildren(UView* winview);
291  // called by realize() to create the views of the children
292 #endif
293  };
294 
295 
296  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
310  public:
311  UWinPlacement();
312 
313  // Horizontal placement.
314  // -- Explicit if &uleft() or &uright()
315  // -- Default placement if null or other UHalign values.
316  UHalign* halign;
317 
318  // vertical placement. Explicit if &utop() or &ubottom()
319  UValign* valign;
320 
321  // Relative location from reference object:
322  //
323  // if oppositeBorder is true:
324  // the specified border (eg. uleft()) of the reference object is
325  // aligned with the OPPOSITE border of 'this' object (eg. right)
326  // --> this implies that 'this' object will be located OUTSIDE
327  // the ref. object (exemple: a cascaded submenu located on the
328  // right side of its parent menu)
329  //
330  // if oppositeBorder is false:
331  // same borders are used for both objects (eg. both left
332  // sides are aligned together)
333  // --> this implies that 'this' object will be located INSIDE
334  // the ref. object (in the same way as for usual UH/Valign rules)
335 
336  bool hoppositeBorder, voppositeBorder;
337 
338  // relative 'distance' between reference and 'this' object borders.
339  // Usually 1 or 0. Can be < 0 as it is a relative 'distance'.
340  int hdist, vdist;
341  };
342 
343 }
344 #endif
345 
346 
347 
2D Dimension.
Definition: ugeom.hpp:55
virtual void close(int status=0)
closes the window.
Definition: uwin.cpp:555
virtual int showModal(UDisp *=null)
opens a window and locks the interaction with other widgets until this window is closed.
Definition: uwin.cpp:539
static const UUpdate layoutAndPaint
layout then paint: prefined constant for UUpdate(LAYOUT|PAINT);
Definition: uupdate.hpp:50
virtual float getHeight(UDisp *=null) const
returns the window height.
Definition: uwin.cpp:850
virtual UWin & setTitle(const UStr &title)
changes the title of the window.
Definition: uwin.cpp:394
Box container.
Definition: ubox.hpp:64
2D Point.
Definition: ugeom.hpp:25
Box vertical layout.
Definition: uboxgeom.hpp:480
Definition: uwin.hpp:271
static const UUpdate paint
paint only: prefined constant for UUpdate(PAINT);
Definition: uupdate.hpp:47
Definition: uappliImpl.hpp:40
bool isHardwin() const
returns true if this is a "hard" window.
Definition: uwin.hpp:210
virtual void show(bool state=true)
shows/hides the window.
Definition: uwin.hpp:145
UWin & softwin(bool state=true)
setSoftwin() synonym.
Definition: uwin.hpp:233
virtual const UWin * toWin() const
dynamic cast: returns this object if it derives from UWin and null otherwise.
Definition: uwin.hpp:57
Display Context.
Definition: udisp.hpp:44
virtual UWin * toWin()
dynamic cast: returns this object if it derives from UWin and null otherwise.
Definition: uwin.hpp:56
virtual UPoint getScreenPos(UDisp *=null) const
returns the position of the upper left corner of the window on the screen.
Definition: uwin.cpp:935
virtual void setFullScreen(bool state, UDisp *=null)
set full screen mode on or off.
Definition: uwin.cpp:457
UWin & setSoftWin(bool state=true)
setSoftwin() synonym.
Definition: uwin.hpp:230
Definition: uwinImpl.hpp:62
virtual void adjustSize()
adjusts the size of the window according to its content.
Definition: uwin.cpp:566
specifies how to update UElem, UBox, UWin objects and subclasses.
Definition: uupdate.hpp:25
virtual void doUpdate(const UUpdate &, UDisp *=null)
updates the layout and/or the paint of this object right now.
Definition: uwin.cpp:592
virtual UStr getTitle() const
returns the title of the window.
Definition: uwin.cpp:405
The Application Context.
Definition: uappli.hpp:79
virtual void setSize(const UDimension &, UDisp *=null)
changes the window size on this display.
Definition: uwin.cpp:794
virtual bool isModal() const
is this dialog modal?.
Definition: uwin.cpp:549
bool isSoftwin() const
returns true if this is a "soft" window.
Definition: uwin.hpp:216
virtual void setModal(bool=true)
sets this dialog in modal or non modal mode.
Definition: uwin.cpp:545
virtual bool realize()
[impl] initializes the window and its children.
Definition: uwin.cpp:301
virtual void toBack(UDisp *=null)
sends this window to the back on this display.
Definition: uwin.cpp:438
virtual void setScreenPos(const UPoint &, UDisp *=null)
moves the upper left corner of the window to this position on the screen.
Definition: uwin.cpp:957
Argument list (for passing arguments to constructor or add functions).
Definition: uargs.hpp:43
virtual UPoint getPos(const UWin &win, UDisp *=null) const
returns the position of the upper left corner of the window relatively to &#39;win&#39;.
virtual UWin & setSoftwin(bool state=true)
sets the "soft window" mode if arg is true.
Definition: uwin.cpp:161
UWin(UArgs nodelist=UArgs::none)
creates a new Window;
Definition: uwin.cpp:57
virtual float getWidth(UDisp *=null) const
returns the window width.
Definition: uwin.cpp:846
Box horizontal layout.
Definition: uboxgeom.hpp:412
Box View.
Definition: uview.hpp:65
virtual void toFront(UDisp *=null)
brings this window to the front on this display.
Definition: uwin.cpp:415
Definition: uhardfont.hpp:31
static const UArgs none
the empty arglist.
Definition: uargs.hpp:45
UHardwinImpl * getHardwin(UDisp *=null) const
[impl] returns the related hard window.
Definition: uwin.cpp:126
Definition: uwinImpl.hpp:84
virtual bool isShown() const
is the window currently shown?
Definition: uwin.cpp:477
Base class for windows and menus.
Definition: uwin.hpp:47
virtual void setPos(UMouseEvent &, float x=0, float y=0)
moves the upper left corner of the window to the event location.
Compiled Object Style.
Definition: ustyle.hpp:44
virtual UDimension getSize(UDisp *=null) const
returns the window size on this display.
Definition: uwin.cpp:823
Constraints for Window Placement.
Definition: uwin.hpp:309
UView * getWinView(UDisp *=null) const
[impl] returns the corresponding view.
Definition: uwin.cpp:132
void update()
updates object graphics.
Definition: uwin.hpp:191
Ubit String.
Definition: ustr.hpp:72
void pack()
synonym for adjustSize().
Definition: uwin.hpp:119
mouse events
Definition: uevent.hpp:172