window.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/motif/window.h
  3. // Purpose: wxWindow class
  4. // Author: Julian Smart
  5. // Modified by:
  6. // Created: 17/09/98
  7. // Copyright: (c) Julian Smart
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_WINDOW_H_
  11. #define _WX_WINDOW_H_
  12. #include "wx/region.h"
  13. // ----------------------------------------------------------------------------
  14. // wxWindow class for Motif - see also wxWindowBase
  15. // ----------------------------------------------------------------------------
  16. class WXDLLIMPEXP_CORE wxWindow : public wxWindowBase
  17. {
  18. friend class WXDLLIMPEXP_FWD_CORE wxDC;
  19. friend class WXDLLIMPEXP_FWD_CORE wxWindowDC;
  20. public:
  21. wxWindow() { Init(); }
  22. wxWindow(wxWindow *parent,
  23. wxWindowID id,
  24. const wxPoint& pos = wxDefaultPosition,
  25. const wxSize& size = wxDefaultSize,
  26. long style = 0,
  27. const wxString& name = wxPanelNameStr)
  28. {
  29. Init();
  30. Create(parent, id, pos, size, style, name);
  31. }
  32. virtual ~wxWindow();
  33. bool Create(wxWindow *parent,
  34. wxWindowID id,
  35. const wxPoint& pos = wxDefaultPosition,
  36. const wxSize& size = wxDefaultSize,
  37. long style = 0,
  38. const wxString& name = wxPanelNameStr);
  39. // implement base class pure virtuals
  40. virtual void SetLabel(const wxString& label);
  41. virtual wxString GetLabel() const;
  42. virtual void Raise();
  43. virtual void Lower();
  44. virtual bool Show( bool show = true );
  45. virtual bool Enable( bool enable = true );
  46. virtual void SetFocus();
  47. virtual void WarpPointer(int x, int y);
  48. virtual void Refresh( bool eraseBackground = true,
  49. const wxRect *rect = (const wxRect *) NULL );
  50. virtual bool SetBackgroundColour( const wxColour &colour );
  51. virtual bool SetForegroundColour( const wxColour &colour );
  52. virtual bool SetCursor( const wxCursor &cursor );
  53. virtual bool SetFont( const wxFont &font );
  54. virtual int GetCharHeight() const;
  55. virtual int GetCharWidth() const;
  56. virtual void SetScrollbar( int orient, int pos, int thumbVisible,
  57. int range, bool refresh = true );
  58. virtual void SetScrollPos( int orient, int pos, bool refresh = true );
  59. virtual int GetScrollPos( int orient ) const;
  60. virtual int GetScrollThumb( int orient ) const;
  61. virtual int GetScrollRange( int orient ) const;
  62. virtual void ScrollWindow( int dx, int dy,
  63. const wxRect* rect = NULL );
  64. #if wxUSE_DRAG_AND_DROP
  65. virtual void SetDropTarget( wxDropTarget *dropTarget );
  66. #endif // wxUSE_DRAG_AND_DROP
  67. // Accept files for dragging
  68. virtual void DragAcceptFiles(bool accept);
  69. // Get the unique identifier of a window
  70. virtual WXWidget GetHandle() const { return GetMainWidget(); }
  71. // implementation from now on
  72. // --------------------------
  73. // accessors
  74. // ---------
  75. // Get main widget for this window, e.g. a text widget
  76. virtual WXWidget GetMainWidget() const;
  77. // Get the widget that corresponds to the label (for font setting,
  78. // label setting etc.)
  79. virtual WXWidget GetLabelWidget() const;
  80. // Get the client widget for this window (something we can create other
  81. // windows on)
  82. virtual WXWidget GetClientWidget() const;
  83. // Get the top widget for this window, e.g. the scrolled widget parent of a
  84. // multi-line text widget. Top means, top in the window hierarchy that
  85. // implements this window.
  86. virtual WXWidget GetTopWidget() const;
  87. // Get the underlying X window and display
  88. WXWindow GetClientXWindow() const;
  89. WXWindow GetXWindow() const;
  90. WXDisplay *GetXDisplay() const;
  91. void SetLastClick(int button, long timestamp)
  92. { m_lastButton = button; m_lastTS = timestamp; }
  93. int GetLastClickedButton() const { return m_lastButton; }
  94. long GetLastClickTime() const { return m_lastTS; }
  95. // Gives window a chance to do something in response to a size message,
  96. // e.g. arrange status bar, toolbar etc.
  97. virtual bool PreResize();
  98. // Generates a paint event
  99. virtual void DoPaint();
  100. // update rectangle/region manipulation
  101. // (for wxWindowDC and Motif callbacks only)
  102. // -----------------------------------------
  103. // Adds a recangle to the updates list
  104. void AddUpdateRect(int x, int y, int w, int h);
  105. void ClearUpdateRegion() { m_updateRegion.Clear(); }
  106. void SetUpdateRegion(const wxRegion& region) { m_updateRegion = region; }
  107. // post-creation activities
  108. void PostCreation();
  109. // pre-creation activities
  110. void PreCreation();
  111. protected:
  112. // Responds to colour changes: passes event on to children.
  113. void OnSysColourChanged(wxSysColourChangedEvent& event);
  114. // Motif-specific
  115. void SetMainWidget(WXWidget w) { m_mainWidget = w; }
  116. // See src/motif/window.cpp, near the top, for an explanation
  117. // why this is necessary
  118. void CanvasSetSizeIntr(int x, int y, int width, int height,
  119. int sizeFlags, bool fromCtor);
  120. void DoSetSizeIntr(int x, int y,
  121. int width, int height,
  122. int sizeFlags, bool fromCtor);
  123. // for DoMoveWindowIntr flags
  124. enum
  125. {
  126. wxMOVE_X = 1,
  127. wxMOVE_Y = 2,
  128. wxMOVE_WIDTH = 4,
  129. wxMOVE_HEIGHT = 8
  130. };
  131. void DoMoveWindowIntr(int x, int y, int width, int height,
  132. int flags);
  133. // helper function, to remove duplicate code, used in wxScrollBar
  134. WXWidget DoCreateScrollBar(WXWidget parent, wxOrientation orientation,
  135. void (*callback)());
  136. public:
  137. WXPixmap GetBackingPixmap() const { return m_backingPixmap; }
  138. void SetBackingPixmap(WXPixmap pixmap) { m_backingPixmap = pixmap; }
  139. int GetPixmapWidth() const { return m_pixmapWidth; }
  140. int GetPixmapHeight() const { return m_pixmapHeight; }
  141. void SetPixmapWidth(int w) { m_pixmapWidth = w; }
  142. void SetPixmapHeight(int h) { m_pixmapHeight = h; }
  143. // Change properties
  144. // Change to the current font (often overridden)
  145. virtual void ChangeFont(bool keepOriginalSize = true);
  146. // Change background and foreground colour using current background colour
  147. // setting (Motif generates foreground based on background)
  148. virtual void ChangeBackgroundColour();
  149. // Change foreground colour using current foreground colour setting
  150. virtual void ChangeForegroundColour();
  151. protected:
  152. // Adds the widget to the hash table and adds event handlers.
  153. bool AttachWidget(wxWindow* parent, WXWidget mainWidget,
  154. WXWidget formWidget, int x, int y, int width, int height);
  155. bool DetachWidget(WXWidget widget);
  156. // How to implement accelerators. If we find a key event, translate to
  157. // wxWidgets wxKeyEvent form. Find a widget for the window. Now find a
  158. // wxWindow for the widget. If there isn't one, go up the widget hierarchy
  159. // trying to find one. Once one is found, call ProcessAccelerator for the
  160. // window. If it returns true (processed the event), skip the X event,
  161. // otherwise carry on up the wxWidgets window hierarchy calling
  162. // ProcessAccelerator. If all return false, process the X event as normal.
  163. // Eventually we can implement OnCharHook the same way, but concentrate on
  164. // accelerators for now. ProcessAccelerator must look at the current
  165. // accelerator table, and try to find what menu id or window (beneath it)
  166. // has this ID. Then construct an appropriate command
  167. // event and send it.
  168. public:
  169. virtual bool ProcessAccelerator(wxKeyEvent& event);
  170. protected:
  171. // unmanage and destroy an X widget f it's !NULL (passing NULL is ok)
  172. void UnmanageAndDestroy(WXWidget widget);
  173. // map or unmap an X widget (passing NULL is ok),
  174. // returns true if widget was mapped/unmapped
  175. bool MapOrUnmap(WXWidget widget, bool map);
  176. // scrolling stuff
  177. // ---------------
  178. // create/destroy window scrollbars
  179. void CreateScrollbar(wxOrientation orientation);
  180. void DestroyScrollbar(wxOrientation orientation);
  181. // get either hor or vert scrollbar widget
  182. WXWidget GetScrollbar(wxOrientation orient) const
  183. { return orient == wxHORIZONTAL ? m_hScrollBar : m_vScrollBar; }
  184. // set the scroll pos
  185. void SetInternalScrollPos(wxOrientation orient, int pos)
  186. {
  187. if ( orient == wxHORIZONTAL )
  188. m_scrollPosX = pos;
  189. else
  190. m_scrollPosY = pos;
  191. }
  192. // Motif-specific flags
  193. // --------------------
  194. bool m_needsRefresh:1; // repaint backing store?
  195. // For double-click detection
  196. long m_lastTS; // last timestamp
  197. unsigned m_lastButton:2; // last pressed button
  198. protected:
  199. WXWidget m_mainWidget;
  200. WXWidget m_hScrollBar;
  201. WXWidget m_vScrollBar;
  202. WXWidget m_borderWidget;
  203. WXWidget m_scrolledWindow;
  204. WXWidget m_drawingArea;
  205. bool m_winCaptured:1;
  206. WXPixmap m_backingPixmap;
  207. int m_pixmapWidth;
  208. int m_pixmapHeight;
  209. int m_pixmapOffsetX;
  210. int m_pixmapOffsetY;
  211. // Store the last scroll pos, since in wxWin the pos isn't set
  212. // automatically by system
  213. int m_scrollPosX;
  214. int m_scrollPosY;
  215. // implement the base class pure virtuals
  216. virtual void DoGetTextExtent(const wxString& string,
  217. int *x, int *y,
  218. int *descent = NULL,
  219. int *externalLeading = NULL,
  220. const wxFont *font = NULL) const;
  221. virtual void DoClientToScreen( int *x, int *y ) const;
  222. virtual void DoScreenToClient( int *x, int *y ) const;
  223. virtual void DoGetPosition( int *x, int *y ) const;
  224. virtual void DoGetSize( int *width, int *height ) const;
  225. virtual void DoGetClientSize( int *width, int *height ) const;
  226. virtual void DoSetSize(int x, int y,
  227. int width, int height,
  228. int sizeFlags = wxSIZE_AUTO);
  229. virtual void DoSetClientSize(int width, int height);
  230. virtual void DoMoveWindow(int x, int y, int width, int height);
  231. virtual bool DoPopupMenu(wxMenu *menu, int x, int y);
  232. virtual void DoCaptureMouse();
  233. virtual void DoReleaseMouse();
  234. #if wxUSE_TOOLTIPS
  235. virtual void DoSetToolTip( wxToolTip *tip );
  236. #endif // wxUSE_TOOLTIPS
  237. private:
  238. // common part of all ctors
  239. void Init();
  240. DECLARE_DYNAMIC_CLASS(wxWindow)
  241. wxDECLARE_NO_COPY_CLASS(wxWindow);
  242. DECLARE_EVENT_TABLE()
  243. };
  244. // ----------------------------------------------------------------------------
  245. // A little class to switch off `size optimization' while an instance of the
  246. // object exists: this may be useful to temporarily disable the optimisation
  247. // which consists to do nothing when the new size is equal to the old size -
  248. // although quite useful usually to avoid flicker, sometimes it leads to
  249. // undesired effects.
  250. //
  251. // Usage: create an instance of this class on the stack to disable the size
  252. // optimisation, it will be reenabled as soon as the object goes out
  253. // from scope.
  254. // ----------------------------------------------------------------------------
  255. class WXDLLIMPEXP_CORE wxNoOptimize
  256. {
  257. public:
  258. wxNoOptimize() { ms_count++; }
  259. ~wxNoOptimize() { ms_count--; }
  260. static bool CanOptimize() { return ms_count == 0; }
  261. protected:
  262. static int ms_count;
  263. };
  264. #endif // _WX_WINDOW_H_