window.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/x11/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 wxWindowX11 : public wxWindowBase
  17. {
  18. friend class WXDLLIMPEXP_FWD_CORE wxDC;
  19. friend class WXDLLIMPEXP_FWD_CORE wxWindowDC;
  20. public:
  21. wxWindowX11() { Init(); }
  22. wxWindowX11(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 ~wxWindowX11();
  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. virtual void Raise();
  40. virtual void Lower();
  41. virtual void SetLabel(const wxString& label);
  42. virtual wxString GetLabel() const;
  43. virtual bool Show( bool show = true );
  44. virtual bool Enable( bool enable = true );
  45. virtual void SetFocus();
  46. virtual void WarpPointer(int x, int y);
  47. virtual void Refresh( bool eraseBackground = true,
  48. const wxRect *rect = (const wxRect *) NULL );
  49. virtual void Update();
  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 ScrollWindow( int dx, int dy, const wxRect* rect = NULL );
  57. #if wxUSE_DRAG_AND_DROP
  58. virtual void SetDropTarget( wxDropTarget *dropTarget );
  59. #endif // wxUSE_DRAG_AND_DROP
  60. // Accept files for dragging
  61. virtual void DragAcceptFiles(bool accept);
  62. // Get the unique identifier of a window
  63. virtual WXWindow GetHandle() const { return X11GetMainWindow(); }
  64. // implementation from now on
  65. // --------------------------
  66. // accessors
  67. // ---------
  68. // Get main X11 window
  69. virtual WXWindow X11GetMainWindow() const;
  70. // Get X11 window representing the client area
  71. virtual WXWindow GetClientAreaWindow() const;
  72. void SetLastClick(int button, long timestamp)
  73. { m_lastButton = button; m_lastTS = timestamp; }
  74. int GetLastClickedButton() const { return m_lastButton; }
  75. long GetLastClickTime() const { return m_lastTS; }
  76. // Gives window a chance to do something in response to a size message, e.g.
  77. // arrange status bar, toolbar etc.
  78. virtual bool PreResize();
  79. // Generates paint events from m_updateRegion
  80. void SendPaintEvents();
  81. // Generates paint events from flag
  82. void SendNcPaintEvents();
  83. // Generates erase events from m_clearRegion
  84. void SendEraseEvents();
  85. // Clip to paint region?
  86. bool GetClipPaintRegion() { return m_clipPaintRegion; }
  87. // Return clear region
  88. wxRegion &GetClearRegion() { return m_clearRegion; }
  89. void NeedUpdateNcAreaInIdle( bool update = true ) { m_updateNcArea = update; }
  90. // Inserting into main window instead of client
  91. // window. This is mostly for a wxWindow's own
  92. // scrollbars.
  93. void SetInsertIntoMain( bool insert = true ) { m_insertIntoMain = insert; }
  94. bool GetInsertIntoMain() { return m_insertIntoMain; }
  95. // sets the fore/background colour for the given widget
  96. static void DoChangeForegroundColour(WXWindow widget, wxColour& foregroundColour);
  97. static void DoChangeBackgroundColour(WXWindow widget, wxColour& backgroundColour, bool changeArmColour = false);
  98. // I don't want users to override what's done in idle so everything that
  99. // has to be done in idle time in order for wxX11 to work is done in
  100. // OnInternalIdle
  101. virtual void OnInternalIdle();
  102. protected:
  103. // Responds to colour changes: passes event on to children.
  104. void OnSysColourChanged(wxSysColourChangedEvent& event);
  105. // For double-click detection
  106. long m_lastTS; // last timestamp
  107. int m_lastButton; // last pressed button
  108. protected:
  109. WXWindow m_mainWindow;
  110. WXWindow m_clientWindow;
  111. bool m_insertIntoMain;
  112. bool m_winCaptured;
  113. wxRegion m_clearRegion;
  114. bool m_clipPaintRegion;
  115. bool m_updateNcArea;
  116. bool m_needsInputFocus; // Input focus set in OnIdle
  117. // implement the base class pure virtuals
  118. virtual void DoGetTextExtent(const wxString& string,
  119. int *x, int *y,
  120. int *descent = NULL,
  121. int *externalLeading = NULL,
  122. const wxFont *font = NULL) const;
  123. virtual void DoClientToScreen( int *x, int *y ) const;
  124. virtual void DoScreenToClient( int *x, int *y ) const;
  125. virtual void DoGetPosition( int *x, int *y ) const;
  126. virtual void DoGetSize( int *width, int *height ) const;
  127. virtual void DoGetClientSize( int *width, int *height ) const;
  128. virtual void DoSetSize(int x, int y,
  129. int width, int height,
  130. int sizeFlags = wxSIZE_AUTO);
  131. virtual void DoSetClientSize(int width, int height);
  132. virtual void DoMoveWindow(int x, int y, int width, int height);
  133. virtual void DoSetSizeHints(int minW, int minH,
  134. int maxW, int maxH,
  135. int incW, int incH);
  136. virtual void DoCaptureMouse();
  137. virtual void DoReleaseMouse();
  138. #if wxUSE_TOOLTIPS
  139. virtual void DoSetToolTip( wxToolTip *tip );
  140. #endif // wxUSE_TOOLTIPS
  141. private:
  142. // common part of all ctors
  143. void Init();
  144. DECLARE_DYNAMIC_CLASS(wxWindowX11)
  145. wxDECLARE_NO_COPY_CLASS(wxWindowX11);
  146. DECLARE_EVENT_TABLE()
  147. };
  148. // ----------------------------------------------------------------------------
  149. // A little class to switch off `size optimization' while an instance of the
  150. // object exists: this may be useful to temporarily disable the optimisation
  151. // which consists to do nothing when the new size is equal to the old size -
  152. // although quite useful usually to avoid flicker, sometimes it leads to
  153. // undesired effects.
  154. //
  155. // Usage: create an instance of this class on the stack to disable the size
  156. // optimisation, it will be reenabled as soon as the object goes out from scope.
  157. // ----------------------------------------------------------------------------
  158. class WXDLLIMPEXP_CORE wxNoOptimize
  159. {
  160. public:
  161. wxNoOptimize() { ms_count++; }
  162. ~wxNoOptimize() { ms_count--; }
  163. static bool CanOptimize() { return ms_count == 0; }
  164. protected:
  165. static int ms_count;
  166. };
  167. #endif // _WX_WINDOW_H_