1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxWindow class
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
16 #pragma interface "window.h"
19 #include "wx/region.h"
21 // ----------------------------------------------------------------------------
22 // wxWindow class for Motif - see also wxWindowBase
23 // ----------------------------------------------------------------------------
25 class wxWindowX11
: public wxWindowBase
27 friend class WXDLLEXPORT wxDC
;
28 friend class WXDLLEXPORT wxWindowDC
;
31 wxWindowX11() { Init(); }
33 wxWindowX11(wxWindow
*parent
,
35 const wxPoint
& pos
= wxDefaultPosition
,
36 const wxSize
& size
= wxDefaultSize
,
38 const wxString
& name
= wxPanelNameStr
)
41 Create(parent
, id
, pos
, size
, style
, name
);
44 virtual ~wxWindowX11();
46 bool Create(wxWindow
*parent
,
48 const wxPoint
& pos
= wxDefaultPosition
,
49 const wxSize
& size
= wxDefaultSize
,
51 const wxString
& name
= wxPanelNameStr
);
56 virtual bool Show( bool show
= TRUE
);
57 virtual bool Enable( bool enable
= TRUE
);
59 virtual void SetFocus();
61 virtual void WarpPointer(int x
, int y
);
63 virtual void Refresh( bool eraseBackground
= TRUE
,
64 const wxRect
*rect
= (const wxRect
*) NULL
);
67 virtual bool SetBackgroundColour( const wxColour
&colour
);
68 virtual bool SetForegroundColour( const wxColour
&colour
);
70 virtual bool SetCursor( const wxCursor
&cursor
);
71 virtual bool SetFont( const wxFont
&font
);
73 virtual int GetCharHeight() const;
74 virtual int GetCharWidth() const;
75 virtual void GetTextExtent(const wxString
& string
,
77 int *descent
= (int *) NULL
,
78 int *externalLeading
= (int *) NULL
,
79 const wxFont
*theFont
= (const wxFont
*) NULL
)
82 virtual void SetScrollbar( int orient
, int pos
, int thumbVisible
,
83 int range
, bool refresh
= TRUE
);
84 virtual void SetScrollPos( int orient
, int pos
, bool refresh
= TRUE
);
85 virtual int GetScrollPos( int orient
) const;
86 virtual int GetScrollThumb( int orient
) const;
87 virtual int GetScrollRange( int orient
) const;
88 virtual void ScrollWindow( int dx
, int dy
,
89 const wxRect
* rect
= (wxRect
*) NULL
);
91 virtual void SetSizeHints(int minW
, int minH
,
92 int maxW
= -1, int maxH
= -1,
93 int incW
= -1, int incH
= -1);
94 #if wxUSE_DRAG_AND_DROP
95 virtual void SetDropTarget( wxDropTarget
*dropTarget
);
96 #endif // wxUSE_DRAG_AND_DROP
98 // Accept files for dragging
99 virtual void DragAcceptFiles(bool accept
);
101 // Get the unique identifier of a window
102 virtual WXWindow
GetHandle() const { return GetMainWindow(); }
104 // implementation from now on
105 // --------------------------
110 // Get main widget for this window, e.g. a text widget
111 virtual WXWindow
GetMainWindow() const;
112 // Get the widget that corresponds to the label (for font setting, label setting etc.)
113 virtual WXWindow
GetLabelWindow() const;
114 // Get the client widget for this window (something we can create other
116 virtual WXWindow
GetClientWindow() const;
117 // Get the top widget for this window, e.g. the scrolled widget parent of a
118 // multi-line text widget. Top means, top in the window hierarchy that
119 // implements this window.
120 virtual WXWindow
GetTopWindow() const;
122 // Get the underlying X window and display
123 WXWindow
GetXWindow() const;
124 WXDisplay
*GetXDisplay() const;
126 void SetLastClick(int button
, long timestamp
)
127 { m_lastButton
= button
; m_lastTS
= timestamp
; }
129 int GetLastClickedButton() const { return m_lastButton
; }
130 long GetLastClickTime() const { return m_lastTS
; }
132 // Gives window a chance to do something in response to a size message, e.g.
133 // arrange status bar, toolbar etc.
134 virtual bool PreResize();
136 // Generates paint events
137 void X11SendPaintEvents();
139 // sets the fore/background colour for the given widget
140 static void DoChangeForegroundColour(WXWindow widget
, wxColour
& foregroundColour
);
141 static void DoChangeBackgroundColour(WXWindow widget
, wxColour
& backgroundColour
, bool changeArmColour
= FALSE
);
143 // For implementation purposes - sometimes decorations make the client area
145 virtual wxPoint
GetClientAreaOrigin() const;
148 // event handlers (not virtual by design)
149 void OnIdle(wxIdleEvent
& event
);
151 // Makes an adjustment to the window position (for example, a frame that has
152 // a toolbar that it manages itself).
153 virtual void AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
);
155 wxWindow
*GetChild(int number
) const
156 { return GetChildren().Item(number
)->GetData(); }
158 // Responds to colour changes: passes event on to children.
159 void OnSysColourChanged(wxSysColourChangedEvent
& event
);
161 void SetMainWindow(WXWindow w
) { m_mainWidget
= w
; }
163 bool CanAddEventHandler() const { return m_canAddEventHandler
; }
164 void SetCanAddEventHandler(bool flag
) { m_canAddEventHandler
= flag
; }
168 virtual void ChangeFont(bool keepOriginalSize
= TRUE
); // Change to the current font (often overridden)
170 // Change background and foreground colour using current background colour
171 // setting (Motif generates foreground based on background)
172 virtual void ChangeBackgroundColour();
173 // Change foreground colour using current foreground colour setting
174 virtual void ChangeForegroundColour();
177 // How to implement accelerators. If we find a key event, translate to
178 // wxWindows wxKeyEvent form. Find a widget for the window. Now find a
179 // wxWindow for the widget. If there isn't one, go up the widget hierarchy
180 // trying to find one. Once one is found, call ProcessAccelerator for the
181 // window. If it returns TRUE (processed the event), skip the X event,
182 // otherwise carry on up the wxWindows window hierarchy calling
183 // ProcessAccelerator. If all return FALSE, process the X event as normal.
184 // Eventually we can implement OnCharHook the same way, but concentrate on
185 // accelerators for now. ProcessAccelerator must look at the current
186 // accelerator table, and try to find what menu id or window (beneath it)
187 // has this ID. Then construct an appropriate command
188 // event and send it.
190 virtual bool ProcessAccelerator(wxKeyEvent
& event
);
196 // create/destroy window scrollbars
197 void CreateScrollbar(wxOrientation orientation
);
198 void DestroyScrollbar(wxOrientation orientation
);
200 // get either hor or vert scrollbar widget
201 WXWindow
GetScrollbar(wxOrientation orient
) const
202 { return orient
== wxHORIZONTAL ? m_hScrollBar
: m_vScrollBar
; }
204 // set the scroll pos
205 void SetInternalScrollPos(wxOrientation orient
, int pos
)
207 if ( orient
== wxHORIZONTAL
)
213 // Motif-specific flags
214 // --------------------
216 bool m_needsRefresh
:1; // repaint backing store?
217 bool m_canAddEventHandler
:1; // ???
219 // For double-click detection
220 long m_lastTS
; // last timestamp
221 int m_lastButton
; // last pressed button
224 WXWindow m_mainWidget
;
226 wxRegion m_clearRegion
;
227 bool m_clipPaintRegion
;
229 WXWindow m_hScrollBar
;
230 WXWindow m_vScrollBar
;
231 WXWindow m_borderWidget
;
232 WXWindow m_scrolledWindow
;
233 WXWindow m_drawingArea
;
238 // Store the last scroll pos, since in wxWin the pos isn't set automatically
243 // Window border size
246 // implement the base class pure virtuals
247 virtual void DoClientToScreen( int *x
, int *y
) const;
248 virtual void DoScreenToClient( int *x
, int *y
) const;
249 virtual void DoGetPosition( int *x
, int *y
) const;
250 virtual void DoGetSize( int *width
, int *height
) const;
251 virtual void DoGetClientSize( int *width
, int *height
) const;
252 virtual void DoSetSize(int x
, int y
,
253 int width
, int height
,
254 int sizeFlags
= wxSIZE_AUTO
);
255 virtual void DoSetClientSize(int width
, int height
);
256 virtual void DoMoveWindow(int x
, int y
, int width
, int height
);
257 virtual bool DoPopupMenu(wxMenu
*menu
, int x
, int y
);
259 virtual void DoCaptureMouse();
260 virtual void DoReleaseMouse();
263 virtual void DoSetToolTip( wxToolTip
*tip
);
264 #endif // wxUSE_TOOLTIPS
267 // common part of all ctors
270 DECLARE_DYNAMIC_CLASS(wxWindowX11
)
271 DECLARE_NO_COPY_CLASS(wxWindowX11
)
272 DECLARE_EVENT_TABLE()
275 // ----------------------------------------------------------------------------
276 // A little class to switch off `size optimization' while an instance of the
277 // object exists: this may be useful to temporarily disable the optimisation
278 // which consists to do nothing when the new size is equal to the old size -
279 // although quite useful usually to avoid flicker, sometimes it leads to
280 // undesired effects.
282 // Usage: create an instance of this class on the stack to disable the size
283 // optimisation, it will be reenabled as soon as the object goes out from scope.
284 // ----------------------------------------------------------------------------
286 class WXDLLEXPORT wxNoOptimize
289 wxNoOptimize() { ms_count
++; }
290 ~wxNoOptimize() { ms_count
--; }
292 static bool CanOptimize() { return ms_count
== 0; }