ubit
udisp.hpp
1 /*************************************************************************
2  *
3  * udisp.cpp: Graphical Display (may be remotely located)
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 _udisp_hpp_
18 #define _udisp_hpp_ 1
19 #include <list>
20 #include <ubit/udefs.hpp>
21 #include <ubit/ustr.hpp>
22 #include <ubit/uelem.hpp>
23 #include <ubit/ugeom.hpp>
24 namespace ubit {
25 
26 class UGraphImpl;
27 class UCursorImpl;
28 
44 class UDisp {
45 public:
46  static UDisp* create(const UStr& display_name);
59  virtual ~UDisp();
60 
61  bool isOpened() const {return is_opened;}
63 
64  int getID() const {return id;}
69  const UConf& getConf() const {return conf;}
71 
72  int getBpp() const {return bpp;}
77  const UStr& getDisplayName() const {return display_name;}
79 
80  int getScreenWidth() const {return screen_width;}
82 
83  int getScreenHeight() const {return screen_height;}
85 
86  void setPixelPerInch(double pixel_per_inch);
88 
89  void setPixelPerMM(double pixel_per_mm);
91 
92  // - - - windows - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
93 
94  virtual void add(UWin&);
102  void add(UWin*);
104 
105  virtual void remove(UWin&, bool auto_delete);
110  void remove(UWin*, bool auto_delete);
112 
113  // - - - pointer - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
114 
115  virtual void setPointerPos(const UPoint& screen_pos) = 0;
117 
118  virtual UPoint getPointerPos() const = 0;
120 
121  virtual int getPointerState() const = 0;
123 
124  virtual bool grabPointer(const UCursor* = null) = 0;
132  virtual void ungrabPointer() = 0;
137  virtual bool pickWindow(int& x_in_win, int& y_in_win, UHardwinImpl* window,
138  UCursor* cursor = null, UCall* callback = null) = 0;
152  // - - - event flow - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
153 
154  UEventFlow* getChannelFlow(int channel) const;
164  UEventFlow* obtainChannelFlow(int channel);
170  USelection* getChannelSelection(int channel);
175  // - - - cut & paste - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
176 
177  const UStr& getCopyBuffer() const {return copy_buffer;}
179 
180  UStr* getPasteTarget(int& pos) const;
182 
183  void clearPasteTarget();
185 
186  virtual void copySelection(UMouseEvent&, USelection&);
191  virtual void pasteSelection(UMouseEvent&, UStr* paste_str, int paste_pos);
197  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
198  // Internals.
199 #ifndef NO_DOC
200 public:
201  URenderContext* getDefaultContext();
202  void makeDefaultContextCurrentIfNeeded();
203 
204  void addHardwin(UWin*);
205  void removeHardwin(UWin*);
206 
207  virtual unsigned long createColorPixel(const URgba&) = 0; // for 2D_GRAPHICS
208  virtual UHardwinImpl* createWinImpl(UWin*) = 0;
209  virtual UCursorImpl* createCursorImpl(int curtype) = 0;
210  virtual void deleteCursorImpl(UCursorImpl*) = 0;
211 
212  virtual UHardFont* getFont(const UFontDesc*);
223  virtual UHardFont* realizeFont(const UFont&);
224  virtual UHardFont* realizeFont(const UFontDesc&);
225  virtual void realizeFontFamily(const UFontFamily&);
226 
227  // - - - WITHOUT OpenGL
228 
229  unsigned long getBlackPixel() const {return black_pixel;}
230  unsigned long getWhitePixel() const {return white_pixel;}
231 
232  // attention: les masks varient suivant l'architecture (big endian ou little endian).
233  unsigned long getRedMask() const {return red_mask;}
234  unsigned long getGreenMask() const {return green_mask;}
235  unsigned long getBlueMask() const {return blue_mask;}
236  int getRedShift() const {return red_shift;}
237  int getGreenShift()const {return green_shift;}
238  int getBlueShift() const {return blue_shift;}
239  int getRedBits() const {return red_bits;}
240  int getGreenBits() const {return green_bits;}
241  int getBlueBits() const {return blue_bits;}
242  static void countBits(unsigned long mask, int& bits, int& shift);
243 
244  // - - - Event management
245 
246  UEventFlow* obtainFlow(unsigned int ev_state, int channel);
248 
249  virtual void onPaint(UView* winview, float x, float y, float w, float h);
250  virtual void onResize(UView* winview, const UDimension& size);
251  void onResizeCB(UView* winview);
252 
253  virtual bool setSelectionOwner(UMouseEvent&) {return false;}
255 
263  virtual void copySelectionCB(void* system_event) {}
269  virtual void pasteSelectionCB(void* system_event) {}
275  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
276 private:
277  friend class UAppli;
278  friend class UAppliImpl;
279  friend class UWin;
280  friend class UHardwinImpl;
281  friend class UView;
282  friend class UGraph;
283  friend class UEvent;
284  friend class UFontFamily;
285  friend class UFontMetrics;
286  friend class UGlcontext;
287  friend class UGlcanvas;
288  friend class ULength;
289  friend class UFont;
290  UDisp(const UDisp&);
291  UDisp& operator=(const UDisp&);
292 
293 protected:
294  UDisp(const UStr& display_name);
295 
296  virtual void startAppli() = 0;
297  virtual void quitAppli() = 0;
298  virtual void startLoop(bool main_loop) = 0; // starts the mainloop or a subloop.
299  virtual void quitLoop(bool main_loop) = 0; // quits the mainloop or a subloop.
300 
301  // attention: l'ordre de destruction importe ici: winlist doit etre
302  // detruit en premier ca ca entraine des destructions qui font reference
303  // a flowlist => winlist doit etre declare en DERNIER
304  int id;
305  UConf& conf; // configuration data (may be shared with the UAppli)
306  UStr display_name; // name of the X Display
307  int bpp; // bit per pixel
308  int depth_size, stencil_size;
309  int screen_width, screen_height;
310  int screen_width_mm, screen_height_mm;
311  bool is_opened;
312  URenderContext *default_context;
313  const UGlcontext *current_glcontext;
314  std::vector<UHardFont**> font_map;
315  unsigned long app_motion_time, nat_motion_time; // for lag control
316  unsigned long black_pixel, white_pixel, red_mask, green_mask, blue_mask;
317  int red_shift, green_shift, blue_shift, red_bits, green_bits, blue_bits;
318  double IN_TO_PX, CM_TO_PX, MM_TO_PX, PT_TO_PX, PC_TO_PX;
319 
320  typedef std::list<UHardwinImpl*> HardwinList;
321  HardwinList hardwin_list; // list of hardwins that are event managed
322 
323  // copySelection() copies the content of the selection in this buffer
324  // note: there is 1 selection per UEventFlow but only 1 copy_buffer per UDisp
325  UStr copy_buffer;
326 
327  // pasteSelection() specifies that the selection will be pasted in this UStr
328  // at this pos (uptr<> to avoid deletion)
329  uptr<UStr> paste_str;
330  int paste_pos;
331 
332  // attention: winlist doit etre detruit en premier!
333  UElem winlist; // list of windows belonging to this display
334 
335  struct LastResize {
336  LastResize() : count(0), winview(null) {}
337  int count;
338  UView* winview;
339  UDimension newsize;
340  } last_resize;
341 
342 #endif // NO_DOC
343 };
344 
345 }
346 #endif
2D Dimension.
Definition: ugeom.hpp:55
text selection.
Definition: uselection.hpp:25
[Impl] Native Font.
Definition: uhardfont.hpp:35
2D Point.
Definition: ugeom.hpp:25
const UStr & getDisplayName() const
returns the name of the UDisp&#39;s X11 server (when X11 is used).
Definition: udisp.hpp:77
Length of positions (UPos), sizes (USize) and padding (UPadding)
Definition: ulength.hpp:59
Definition: uappliImpl.hpp:40
Ubit Event class.
Definition: uevent.hpp:30
virtual void copySelectionCB(void *system_event)
[X11 only] copie reellement la selection (ou plus exactement envoie son contenu a l&#39;appli qui la dema...
Definition: udisp.hpp:263
class for drawing on widgets.
Definition: ugraph.hpp:44
virtual void pasteSelection(UMouseEvent &, UStr *paste_str, int paste_pos)
[impl] pastes the X selection into this UStr at this pos.
Definition: udisp.cpp:224
UStr * getPasteTarget(int &pos) const
[impl] returns the string (and the pos in this string) where the paste will take place.
Definition: udisp.cpp:209
Display Context.
Definition: udisp.hpp:44
bool isOpened() const
returns true if the Display was sucessufully opened.
Definition: udisp.hpp:61
USelection * getChannelSelection(int channel)
returns the text selection of a given event flow on this display.
Definition: udisp.cpp:242
[impl] Internal representation for fonts.
Definition: ufontImpl.hpp:24
static UDisp * create(const UStr &display_name)
creates and opens a new Display.
Definition: udisp.cpp:46
virtual void pasteSelectionCB(void *system_event)
[X11 only] recupere effectivement le contenu de la X selection.
Definition: udisp.hpp:269
virtual int getPointerState() const =0
returns the state of the modifier keys and pointer buttons.
virtual bool grabPointer(const UCursor *=null)=0
starts a physical grab of the native pointer.
int getID() const
returns the ID of this Display.
Definition: udisp.hpp:64
UEventFlow * getChannelFlow(int channel) const
returns the Event Flow for this channel on this display (null if not found).
Definition: udisp.cpp:248
The Application Context.
Definition: uappli.hpp:79
A Font Family represents a collection of fonts for all possible sizes and styles. ...
Definition: ufont.hpp:179
const UConf & getConf() const
returns the configuration of this Display.
Definition: udisp.hpp:69
Specifies a RGBA value for defining UColor(s).
Definition: ucolor.hpp:24
virtual void add(UWin &)
add a window (UFrame, UDialog, etc) to this display.
int getScreenWidth() const
returns the width of the UDisp&#39;s screen.
Definition: udisp.hpp:80
lightweight general purpose container.
Definition: uelem.hpp:44
virtual bool pickWindow(int &x_in_win, int &y_in_win, UHardwinImpl *window, UCursor *cursor=null, UCall *callback=null)=0
grabs the pointer and lets the user pick a window interactively with the mouse.
base class of callback objects for firing functions or methods.
Definition: ucall.hpp:144
virtual void ungrabPointer()=0
ends a physical grab of the native pointer.
virtual bool setSelectionOwner(UMouseEvent &)
[X11 only] tells the X-server the appli owns the X selection.
Definition: udisp.hpp:253
virtual void pasteSelectionRequest(UMouseEvent &)
[X11 only] asks the X selection.
Definition: udisp.hpp:256
virtual UPoint getPointerPos() const =0
returns the position of the pointer on the screen.
Definition: udisp.hpp:335
Event Flow.
Definition: ueventflow.hpp:34
Box View.
Definition: uview.hpp:65
Font of a UElem or UBox container.
Definition: ufont.hpp:30
configuration of the UAppli.
Definition: uconf.hpp:68
virtual UHardFont * getFont(const UFontDesc *)
returns (possibily creating) the requested font (see NOTES).
Definition: udisp.cpp:281
Definition: uhardfont.hpp:31
void clearPasteTarget()
[impl] clears the paste target.
Definition: udisp.cpp:214
Definition: urendercontext.hpp:22
Definition: uwinImpl.hpp:84
Definition: ufontmetrics.hpp:21
Base class for windows and menus.
Definition: uwin.hpp:47
const UStr & getCopyBuffer() const
returns the copy buffer.
Definition: udisp.hpp:177
Mouse cursor property.
Definition: ucursor.hpp:31
void setPixelPerInch(double pixel_per_inch)
changes the pixel density (number of pixels per inch).
Definition: udisp.cpp:201
UEventFlow * obtainFlow(unsigned int ev_state, int channel)
returns the corresponding Event Flow (creates it if does not already exist).
Definition: udisp.cpp:419
UEventFlow * obtainChannelFlow(int channel)
gets or creates the Event Flow that corresponds to this channel on this display.
Definition: udisp.cpp:257
virtual void setPointerPos(const UPoint &screen_pos)=0
move the pointer to this position on the screen.
int getBpp() const
returns the number of bit per pixel of this UDisp.
Definition: udisp.hpp:72
void setPixelPerMM(double pixel_per_mm)
changes the pixel density (number of pixels per mm).
Definition: udisp.cpp:193
Ubit String.
Definition: ustr.hpp:72
virtual void copySelection(UMouseEvent &, USelection &)
[impl] copies the content of the selection in the copy buffer and tells the X server we own the X sel...
Definition: udisp.cpp:219
mouse events
Definition: uevent.hpp:172
int getScreenHeight() const
returns the height of the UDisp&#39;s screen.
Definition: udisp.hpp:83