window.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/gtk1/window.h
  3. // Purpose:
  4. // Author: Robert Roebling
  5. // Copyright: (c) 1998 Robert Roebling
  6. // Licence: wxWindows licence
  7. /////////////////////////////////////////////////////////////////////////////
  8. #ifndef __GTKWINDOWH__
  9. #define __GTKWINDOWH__
  10. typedef struct _GtkTooltips GtkTooltips;
  11. #ifdef HAVE_XIM
  12. typedef struct _GdkIC GdkIC;
  13. typedef struct _GdkICAttr GdkICAttr;
  14. #endif
  15. //-----------------------------------------------------------------------------
  16. // callback definition for inserting a window (internal)
  17. //-----------------------------------------------------------------------------
  18. class WXDLLIMPEXP_FWD_CORE wxWindowGTK;
  19. typedef void (*wxInsertChildFunction)( wxWindowGTK*, wxWindowGTK* );
  20. //-----------------------------------------------------------------------------
  21. // wxWindowGTK
  22. //-----------------------------------------------------------------------------
  23. class WXDLLIMPEXP_CORE wxWindowGTK : public wxWindowBase
  24. {
  25. public:
  26. // creating the window
  27. // -------------------
  28. wxWindowGTK();
  29. wxWindowGTK(wxWindow *parent,
  30. wxWindowID id,
  31. const wxPoint& pos = wxDefaultPosition,
  32. const wxSize& size = wxDefaultSize,
  33. long style = 0,
  34. const wxString& name = wxPanelNameStr);
  35. bool Create(wxWindow *parent,
  36. wxWindowID id,
  37. const wxPoint& pos = wxDefaultPosition,
  38. const wxSize& size = wxDefaultSize,
  39. long style = 0,
  40. const wxString& name = wxPanelNameStr);
  41. virtual ~wxWindowGTK();
  42. // implement base class (pure) virtual methods
  43. // -------------------------------------------
  44. virtual void SetLabel(const wxString& WXUNUSED(label)) { }
  45. virtual wxString GetLabel() const { return wxEmptyString; }
  46. virtual bool Destroy();
  47. virtual void Raise();
  48. virtual void Lower();
  49. virtual bool Show( bool show = true );
  50. virtual void DoEnable( bool enable );
  51. virtual void SetWindowStyleFlag( long style );
  52. virtual bool IsRetained() const;
  53. virtual void SetFocus();
  54. virtual bool AcceptsFocus() const;
  55. virtual bool Reparent( wxWindowBase *newParent );
  56. virtual void WarpPointer(int x, int y);
  57. virtual void Refresh( bool eraseBackground = true,
  58. const wxRect *rect = (const wxRect *) NULL );
  59. virtual void Update();
  60. virtual void ClearBackground();
  61. virtual bool SetBackgroundColour( const wxColour &colour );
  62. virtual bool SetForegroundColour( const wxColour &colour );
  63. virtual bool SetCursor( const wxCursor &cursor );
  64. virtual bool SetFont( const wxFont &font );
  65. virtual bool SetBackgroundStyle(wxBackgroundStyle style) ;
  66. virtual int GetCharHeight() const;
  67. virtual int GetCharWidth() const;
  68. virtual void SetScrollbar( int orient, int pos, int thumbVisible,
  69. int range, bool refresh = true );
  70. virtual void SetScrollPos( int orient, int pos, bool refresh = true );
  71. virtual int GetScrollPos( int orient ) const;
  72. virtual int GetScrollThumb( int orient ) const;
  73. virtual int GetScrollRange( int orient ) const;
  74. virtual void ScrollWindow( int dx, int dy,
  75. const wxRect* rect = NULL );
  76. #if wxUSE_DRAG_AND_DROP
  77. virtual void SetDropTarget( wxDropTarget *dropTarget );
  78. #endif // wxUSE_DRAG_AND_DROP
  79. virtual bool IsDoubleBuffered() const { return false; }
  80. GdkWindow* GTKGetDrawingWindow() const;
  81. // implementation
  82. // --------------
  83. virtual WXWidget GetHandle() const { return m_widget; }
  84. // I don't want users to override what's done in idle so everything that
  85. // has to be done in idle time in order for wxGTK to work is done in
  86. // OnInternalIdle
  87. virtual void OnInternalIdle();
  88. // Internal representation of Update()
  89. void GtkUpdate();
  90. // For compatibility across platforms (not in event table)
  91. void OnIdle(wxIdleEvent& WXUNUSED(event)) {}
  92. // Used by all window classes in the widget creation process.
  93. bool PreCreation( wxWindowGTK *parent, const wxPoint &pos, const wxSize &size );
  94. void PostCreation();
  95. // Internal addition of child windows. differs from class
  96. // to class not by using virtual functions but by using
  97. // the m_insertCallback.
  98. void DoAddChild(wxWindowGTK *child);
  99. // This methods sends wxPaintEvents to the window. It reads the
  100. // update region, breaks it up into rects and sends an event
  101. // for each rect. It is also responsible for background erase
  102. // events and NC paint events. It is called from "draw" and
  103. // "expose" handlers as well as from ::Update()
  104. void GtkSendPaintEvents();
  105. // The methods below are required because many native widgets
  106. // are composed of several subwidgets and setting a style for
  107. // the widget means setting it for all subwidgets as well.
  108. // also, it is not clear which native widget is the top
  109. // widget where (most of) the input goes. even tooltips have
  110. // to be applied to all subwidgets.
  111. virtual GtkWidget* GetConnectWidget();
  112. virtual bool IsOwnGtkWindow( GdkWindow *window );
  113. void ConnectWidget( GtkWidget *widget );
  114. #if wxUSE_TOOLTIPS
  115. virtual void ApplyToolTip( GtkTooltips *tips, const wxChar *tip );
  116. #endif // wxUSE_TOOLTIPS
  117. // Call after modifing the value of m_hAdjust or m_vAdjust to bring the
  118. // scrolbar in sync (this does not generate any wx events)
  119. void GtkUpdateScrollbar(int orient);
  120. // Called from GTK signal handlers. it indicates that
  121. // the layout functions have to be called later on
  122. // (i.e. in idle time, implemented in OnInternalIdle() ).
  123. void GtkUpdateSize() { m_sizeSet = false; }
  124. // fix up the mouse event coords, used by wxListBox only so far
  125. virtual void FixUpMouseEvent(GtkWidget * WXUNUSED(widget),
  126. wxCoord& WXUNUSED(x),
  127. wxCoord& WXUNUSED(y)) { }
  128. // is this window transparent for the mouse events (as wxStaticBox is)?
  129. virtual bool IsTransparentForMouse() const { return false; }
  130. // is this a radiobutton (used by radiobutton code itself only)?
  131. virtual bool IsRadioButton() const { return false; }
  132. // position and size of the window
  133. int m_x, m_y;
  134. int m_width, m_height;
  135. int m_oldClientWidth,m_oldClientHeight;
  136. // see the docs in src/gtk/window.cpp
  137. GtkWidget *m_widget; // mostly the widget seen by the rest of GTK
  138. GtkWidget *m_wxwindow; // mostly the client area as per wxWidgets
  139. // this widget will be queried for GTK's focus events
  140. GtkWidget *m_focusWidget;
  141. #ifdef HAVE_XIM
  142. // XIM support for wxWidgets
  143. GdkIC *m_ic;
  144. GdkICAttr *m_icattr;
  145. #endif // HAVE_XIM
  146. // The area to be cleared (and not just refreshed)
  147. // We cannot make this distinction under GTK 2.0.
  148. wxRegion m_clearRegion;
  149. // scrolling stuff
  150. GtkAdjustment *m_hAdjust,*m_vAdjust;
  151. float m_oldHorizontalPos;
  152. float m_oldVerticalPos;
  153. // extra (wxGTK-specific) flags
  154. bool m_needParent:1; // ! wxFrame, wxDialog, wxNotebookPage ?
  155. bool m_noExpose:1; // wxGLCanvas has its own redrawing
  156. bool m_nativeSizeEvent:1; // wxGLCanvas sends wxSizeEvent upon "alloc_size"
  157. bool m_hasScrolling:1;
  158. bool m_hasVMT:1;
  159. bool m_sizeSet:1;
  160. bool m_resizing:1;
  161. bool m_acceptsFocus:1; // true if not static
  162. bool m_hasFocus:1; // true if == FindFocus()
  163. bool m_isScrolling:1; // dragging scrollbar thumb?
  164. bool m_clipPaintRegion:1; // true after ScrollWindow()
  165. bool m_needsStyleChange:1; // May not be able to change
  166. // background style until OnIdle
  167. // C++ has no virtual methods in the constrcutor of any class but we need
  168. // different methods of inserting a child window into a wxFrame,
  169. // wxMDIFrame, wxNotebook etc. this is the callback that will get used.
  170. wxInsertChildFunction m_insertCallback;
  171. // implement the base class pure virtuals
  172. virtual void DoGetTextExtent(const wxString& string,
  173. int *x, int *y,
  174. int *descent = NULL,
  175. int *externalLeading = NULL,
  176. const wxFont *theFont = NULL) const;
  177. #if wxUSE_MENUS_NATIVE
  178. virtual bool DoPopupMenu( wxMenu *menu, int x, int y );
  179. #endif // wxUSE_MENUS_NATIVE
  180. virtual void DoClientToScreen( int *x, int *y ) const;
  181. virtual void DoScreenToClient( int *x, int *y ) const;
  182. virtual void DoGetPosition( int *x, int *y ) const;
  183. virtual void DoGetSize( int *width, int *height ) const;
  184. virtual void DoGetClientSize( int *width, int *height ) const;
  185. virtual void DoSetSize(int x, int y,
  186. int width, int height,
  187. int sizeFlags = wxSIZE_AUTO);
  188. virtual void DoSetClientSize(int width, int height);
  189. virtual void DoMoveWindow(int x, int y, int width, int height);
  190. virtual void DoCaptureMouse();
  191. virtual void DoReleaseMouse();
  192. #if wxUSE_TOOLTIPS
  193. virtual void DoSetToolTip( wxToolTip *tip );
  194. #endif // wxUSE_TOOLTIPS
  195. protected:
  196. // common part of all ctors (not virtual because called from ctor)
  197. void Init();
  198. // Called by ApplyWidgetStyle (which is called by SetFont() and
  199. // SetXXXColour etc to apply style changed to native widgets) to create
  200. // modified GTK style with non-standard attributes. If forceStyle=true,
  201. // creates empty GtkRcStyle if there are no modifications, otherwise
  202. // returns NULL in such case.
  203. GtkRcStyle *CreateWidgetStyle(bool forceStyle = false);
  204. // Overridden in many GTK widgets who have to handle subwidgets
  205. virtual void ApplyWidgetStyle(bool forceStyle = false);
  206. // helper function to ease native widgets wrapping, called by
  207. // ApplyWidgetStyle -- override this, not ApplyWidgetStyle
  208. virtual void DoApplyWidgetStyle(GtkRcStyle *style);
  209. private:
  210. DECLARE_DYNAMIC_CLASS(wxWindowGTK)
  211. wxDECLARE_NO_COPY_CLASS(wxWindowGTK);
  212. };
  213. extern WXDLLIMPEXP_CORE wxWindow *wxFindFocusedChild(wxWindowGTK *win);
  214. #endif // __GTKWINDOWH__