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 wxWindow
: public wxWindowBase
27 friend class WXDLLEXPORT wxDC
;
28 friend class WXDLLEXPORT wxWindowDC
;
31 wxWindow() { Init(); }
33 wxWindow(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
);
46 bool Create(wxWindow
*parent
,
48 const wxPoint
& pos
= wxDefaultPosition
,
49 const wxSize
& size
= wxDefaultSize
,
51 const wxString
& name
= wxPanelNameStr
);
53 // implement base class pure virtuals
54 virtual void SetTitle( const wxString
& title
);
55 virtual wxString
GetTitle() const;
60 virtual bool Show( bool show
= TRUE
);
61 virtual bool Enable( bool enable
= TRUE
);
63 virtual void SetFocus();
65 virtual void WarpPointer(int x
, int y
);
67 virtual void Refresh( bool eraseBackground
= TRUE
,
68 const wxRect
*rect
= (const wxRect
*) NULL
);
71 virtual bool SetBackgroundColour( const wxColour
&colour
);
72 virtual bool SetForegroundColour( const wxColour
&colour
);
74 virtual bool SetCursor( const wxCursor
&cursor
);
75 virtual bool SetFont( const wxFont
&font
);
77 virtual int GetCharHeight() const;
78 virtual int GetCharWidth() const;
79 virtual void GetTextExtent(const wxString
& string
,
81 int *descent
= (int *) NULL
,
82 int *externalLeading
= (int *) NULL
,
83 const wxFont
*theFont
= (const wxFont
*) NULL
)
86 virtual void SetScrollbar( int orient
, int pos
, int thumbVisible
,
87 int range
, bool refresh
= TRUE
);
88 virtual void SetScrollPos( int orient
, int pos
, bool refresh
= TRUE
);
89 virtual int GetScrollPos( int orient
) const;
90 virtual int GetScrollThumb( int orient
) const;
91 virtual int GetScrollRange( int orient
) const;
92 virtual void ScrollWindow( int dx
, int dy
,
93 const wxRect
* rect
= (wxRect
*) NULL
);
95 virtual void SetSizeHints(int minW
, int minH
,
96 int maxW
= -1, int maxH
= -1,
97 int incW
= -1, int incH
= -1);
98 #if wxUSE_DRAG_AND_DROP
99 virtual void SetDropTarget( wxDropTarget
*dropTarget
);
100 #endif // wxUSE_DRAG_AND_DROP
102 // Accept files for dragging
103 virtual void DragAcceptFiles(bool accept
);
105 // Get the unique identifier of a window
106 virtual WXWidget
GetHandle() const { return GetMainWidget(); }
108 // implementation from now on
109 // --------------------------
114 // Get main widget for this window, e.g. a text widget
115 virtual WXWidget
GetMainWidget() const;
116 // Get the widget that corresponds to the label (for font setting, label setting etc.)
117 virtual WXWidget
GetLabelWidget() const;
118 // Get the client widget for this window (something we can create other
120 virtual WXWidget
GetClientWidget() const;
121 // Get the top widget for this window, e.g. the scrolled widget parent of a
122 // multi-line text widget. Top means, top in the window hierarchy that
123 // implements this window.
124 virtual WXWidget
GetTopWidget() const;
126 // Get the underlying X window and display
127 WXWindow
GetXWindow() const;
128 WXDisplay
*GetXDisplay() const;
130 // called from Motif callbacks - and should only be called from there
132 void SetButton1(bool pressed
) { m_button1Pressed
= pressed
; }
133 void SetButton2(bool pressed
) { m_button2Pressed
= pressed
; }
134 void SetButton3(bool pressed
) { m_button3Pressed
= pressed
; }
136 void SetLastClick(int button
, long timestamp
)
137 { m_lastButton
= button
; m_lastTS
= timestamp
; }
139 int GetLastClickedButton() const { return m_lastButton
; }
140 long GetLastClickTime() const { return m_lastTS
; }
142 // Gives window a chance to do something in response to a size message, e.g.
143 // arrange status bar, toolbar etc.
144 virtual bool PreResize();
146 // Generates a paint event
147 virtual void DoPaint();
149 // update rectangle/region manipulation
150 // (for wxWindowDC and Motif callbacks only)
151 // -----------------------------------------
153 // read/write access to the update rect list
154 const wxRectList
& GetUpdateRects() const { return m_updateRects
; }
156 // Adds a recangle to the updates list
157 void AddUpdateRect(int x
, int y
, int w
, int h
)
158 { m_updateRects
.Append(new wxRect(x
, y
, w
, h
)); }
160 // Empties the m_updateRects list
161 void ClearUpdateRects();
163 void ClearUpdateRegion() { m_updateRegion
.Clear(); }
164 void SetUpdateRegion(const wxRegion
& region
) { m_updateRegion
= region
; }
166 // sets the fore/background colour for the given widget
167 static void DoChangeForegroundColour(WXWidget widget
, wxColour
& foregroundColour
);
168 static void DoChangeBackgroundColour(WXWidget widget
, wxColour
& backgroundColour
, bool changeArmColour
= FALSE
);
170 // For implementation purposes - sometimes decorations make the client area
172 virtual wxPoint
GetClientAreaOrigin() const;
175 // event handlers (not virtual by design)
176 void OnIdle(wxIdleEvent
& event
);
178 // Makes an adjustment to the window position (for example, a frame that has
179 // a toolbar that it manages itself).
180 virtual void AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
);
182 wxWindow
*GetChild(int number
) const
183 { return GetChildren().Item(number
)->GetData(); }
185 // Responds to colour changes: passes event on to children.
186 void OnSysColourChanged(wxSysColourChangedEvent
& event
);
190 // CanvasXXXSiize functions
191 void CanvasGetSize(int* width
, int* height
) const; // If have drawing area
192 void CanvasGetClientSize(int *width
, int *height
) const;
193 void CanvasGetPosition(int *x
, int *y
) const; // If have drawing area
194 void CanvasSetClientSize(int width
, int size
);
195 void CanvasSetSize(int x
, int y
, int width
, int height
, int sizeFlags
= wxSIZE_AUTO
);
197 void SetMainWidget(WXWidget w
) { m_mainWidget
= w
; }
199 bool CanAddEventHandler() const { return m_canAddEventHandler
; }
200 void SetCanAddEventHandler(bool flag
) { m_canAddEventHandler
= flag
; }
203 WXPixmap
GetBackingPixmap() const { return m_backingPixmap
; }
204 void SetBackingPixmap(WXPixmap pixmap
) { m_backingPixmap
= pixmap
; }
205 int GetPixmapWidth() const { return m_pixmapWidth
; }
206 int GetPixmapHeight() const { return m_pixmapHeight
; }
207 void SetPixmapWidth(int w
) { m_pixmapWidth
= w
; }
208 void SetPixmapHeight(int h
) { m_pixmapHeight
= h
; }
211 virtual void ChangeFont(bool keepOriginalSize
= TRUE
); // Change to the current font (often overridden)
213 // Change background and foreground colour using current background colour
214 // setting (Motif generates foreground based on background)
215 virtual void ChangeBackgroundColour();
216 // Change foreground colour using current foreground colour setting
217 virtual void ChangeForegroundColour();
220 // Adds the widget to the hash table and adds event handlers.
221 bool AttachWidget(wxWindow
* parent
, WXWidget mainWidget
,
222 WXWidget formWidget
, int x
, int y
, int width
, int height
);
223 bool DetachWidget(WXWidget widget
);
225 // How to implement accelerators. If we find a key event, translate to
226 // wxWindows wxKeyEvent form. Find a widget for the window. Now find a
227 // wxWindow for the widget. If there isn't one, go up the widget hierarchy
228 // trying to find one. Once one is found, call ProcessAccelerator for the
229 // window. If it returns TRUE (processed the event), skip the X event,
230 // otherwise carry on up the wxWindows window hierarchy calling
231 // ProcessAccelerator. If all return FALSE, process the X event as normal.
232 // Eventually we can implement OnCharHook the same way, but concentrate on
233 // accelerators for now. ProcessAccelerator must look at the current
234 // accelerator table, and try to find what menu id or window (beneath it)
235 // has this ID. Then construct an appropriate command
236 // event and send it.
238 virtual bool ProcessAccelerator(wxKeyEvent
& event
);
241 // unmanage and destroy an X widget f it's !NULL (passing NULL is ok)
242 void UnmanageAndDestroy(WXWidget widget
);
244 // map or unmap an X widget (passing NULL is ok), returns TRUE if widget was
246 bool MapOrUnmap(WXWidget widget
, bool map
);
251 // create/destroy window scrollbars
252 void CreateScrollbar(wxOrientation orientation
);
253 void DestroyScrollbar(wxOrientation orientation
);
255 // get either hor or vert scrollbar widget
256 WXWidget
GetScrollbar(wxOrientation orient
) const
257 { return orient
== wxHORIZONTAL
? m_hScrollBar
: m_vScrollBar
; }
259 // set the scroll pos
260 void SetInternalScrollPos(wxOrientation orient
, int pos
)
262 if ( orient
== wxHORIZONTAL
)
268 // Motif-specific flags
269 // --------------------
271 bool m_needsRefresh
:1; // repaint backing store?
272 bool m_canAddEventHandler
:1; // ???
273 bool m_button1Pressed
:1;
274 bool m_button2Pressed
:1;
275 bool m_button3Pressed
:1;
277 // For double-click detection
278 long m_lastTS
; // last timestamp
279 int m_lastButton
; // last pressed button
281 // List of wxRects representing damaged region
282 wxRectList m_updateRects
;
285 WXWidget m_mainWidget
;
286 WXWidget m_hScrollBar
;
287 WXWidget m_vScrollBar
;
288 WXWidget m_borderWidget
;
289 WXWidget m_scrolledWindow
;
290 WXWidget m_drawingArea
;
294 WXPixmap m_backingPixmap
;
300 // Store the last scroll pos, since in wxWin the pos isn't set automatically
305 // implement the base class pure virtuals
306 virtual void DoClientToScreen( int *x
, int *y
) const;
307 virtual void DoScreenToClient( int *x
, int *y
) const;
308 virtual void DoGetPosition( int *x
, int *y
) const;
309 virtual void DoGetSize( int *width
, int *height
) const;
310 virtual void DoGetClientSize( int *width
, int *height
) const;
311 virtual void DoSetSize(int x
, int y
,
312 int width
, int height
,
313 int sizeFlags
= wxSIZE_AUTO
);
314 virtual void DoSetClientSize(int width
, int height
);
315 virtual void DoMoveWindow(int x
, int y
, int width
, int height
);
316 virtual bool DoPopupMenu(wxMenu
*menu
, int x
, int y
);
317 virtual void DoCaptureMouse();
318 virtual void DoReleaseMouse();
321 virtual void DoSetToolTip( wxToolTip
*tip
);
322 #endif // wxUSE_TOOLTIPS
325 // common part of all ctors
328 DECLARE_DYNAMIC_CLASS(wxWindow
)
329 DECLARE_NO_COPY_CLASS(wxWindow
)
330 DECLARE_EVENT_TABLE()
333 // ----------------------------------------------------------------------------
334 // A little class to switch off `size optimization' while an instance of the
335 // object exists: this may be useful to temporarily disable the optimisation
336 // which consists to do nothing when the new size is equal to the old size -
337 // although quite useful usually to avoid flicker, sometimes it leads to
338 // undesired effects.
340 // Usage: create an instance of this class on the stack to disable the size
341 // optimisation, it will be reenabled as soon as the object goes out from scope.
342 // ----------------------------------------------------------------------------
344 class WXDLLEXPORT wxNoOptimize
347 wxNoOptimize() { ms_count
++; }
348 ~wxNoOptimize() { ms_count
--; }
350 static bool CanOptimize() { return ms_count
== 0; }