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
);
66 virtual void CaptureMouse();
67 virtual void ReleaseMouse();
69 virtual void Refresh( bool eraseBackground
= TRUE
,
70 const wxRect
*rect
= (const wxRect
*) NULL
);
73 virtual bool SetBackgroundColour( const wxColour
&colour
);
74 virtual bool SetForegroundColour( const wxColour
&colour
);
76 virtual bool SetCursor( const wxCursor
&cursor
);
77 virtual bool SetFont( const wxFont
&font
);
79 virtual int GetCharHeight() const;
80 virtual int GetCharWidth() const;
81 virtual void GetTextExtent(const wxString
& string
,
83 int *descent
= (int *) NULL
,
84 int *externalLeading
= (int *) NULL
,
85 const wxFont
*theFont
= (const wxFont
*) NULL
)
88 virtual void SetScrollbar( int orient
, int pos
, int thumbVisible
,
89 int range
, bool refresh
= TRUE
);
90 virtual void SetScrollPos( int orient
, int pos
, bool refresh
= TRUE
);
91 virtual int GetScrollPos( int orient
) const;
92 virtual int GetScrollThumb( int orient
) const;
93 virtual int GetScrollRange( int orient
) const;
94 virtual void ScrollWindow( int dx
, int dy
,
95 const wxRect
* rect
= (wxRect
*) NULL
);
97 virtual void SetSizeHints(int minW
, int minH
,
98 int maxW
= -1, int maxH
= -1,
99 int incW
= -1, int incH
= -1);
100 #if wxUSE_DRAG_AND_DROP
101 virtual void SetDropTarget( wxDropTarget
*dropTarget
);
102 #endif // wxUSE_DRAG_AND_DROP
104 // Accept files for dragging
105 virtual void DragAcceptFiles(bool accept
);
107 // Get the unique identifier of a window
108 virtual WXWidget
GetHandle() const { return GetMainWidget(); }
110 // implementation from now on
111 // --------------------------
116 // Get main widget for this window, e.g. a text widget
117 virtual WXWidget
GetMainWidget() const;
118 // Get the widget that corresponds to the label (for font setting, label setting etc.)
119 virtual WXWidget
GetLabelWidget() const;
120 // Get the client widget for this window (something we can create other
122 virtual WXWidget
GetClientWidget() const;
123 // Get the top widget for this window, e.g. the scrolled widget parent of a
124 // multi-line text widget. Top means, top in the window hierarchy that
125 // implements this window.
126 virtual WXWidget
GetTopWidget() const;
128 // Get the underlying X window and display
129 WXWindow
GetXWindow() const;
130 WXDisplay
*GetXDisplay() const;
132 // called from Motif callbacks - and should only be called from there
134 void SetButton1(bool pressed
) { m_button1Pressed
= pressed
; }
135 void SetButton2(bool pressed
) { m_button2Pressed
= pressed
; }
136 void SetButton3(bool pressed
) { m_button3Pressed
= pressed
; }
138 void SetLastClick(int button
, long timestamp
)
139 { m_lastButton
= button
; m_lastTS
= timestamp
; }
141 int GetLastClickedButton() const { return m_lastButton
; }
142 long GetLastClickTime() const { return m_lastTS
; }
144 // Gives window a chance to do something in response to a size message, e.g.
145 // arrange status bar, toolbar etc.
146 virtual bool PreResize();
148 // Generates a paint event
149 virtual void DoPaint();
151 // update rectangle/region manipulation
152 // (for wxWindowDC and Motif callbacks only)
153 // -----------------------------------------
155 // read/write access to the update rect list
156 const wxRectList
& GetUpdateRects() const { return m_updateRects
; }
158 // Adds a recangle to the updates list
159 void AddUpdateRect(int x
, int y
, int w
, int h
)
160 { m_updateRects
.Append(new wxRect(x
, y
, w
, h
)); }
162 // Empties the m_updateRects list
163 void ClearUpdateRects();
165 void ClearUpdateRegion() { m_updateRegion
.Clear(); }
166 void SetUpdateRegion(const wxRegion
& region
) { m_updateRegion
= region
; }
168 // sets the fore/background colour for the given widget
169 static void DoChangeForegroundColour(WXWidget widget
, wxColour
& foregroundColour
);
170 static void DoChangeBackgroundColour(WXWidget widget
, wxColour
& backgroundColour
, bool changeArmColour
= FALSE
);
172 // For implementation purposes - sometimes decorations make the client area
174 virtual wxPoint
GetClientAreaOrigin() const;
177 // event handlers (not virtual by design)
178 void OnIdle(wxIdleEvent
& event
);
180 // Makes an adjustment to the window position (for example, a frame that has
181 // a toolbar that it manages itself).
182 virtual void AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
);
184 wxWindow
*GetChild(int number
) const
185 { return GetChildren().Item(number
)->GetData(); }
187 // Responds to colour changes: passes event on to children.
188 void OnSysColourChanged(wxSysColourChangedEvent
& event
);
192 // CanvasXXXSiize functions
193 void CanvasGetSize(int* width
, int* height
) const; // If have drawing area
194 void CanvasGetClientSize(int *width
, int *height
) const;
195 void CanvasGetPosition(int *x
, int *y
) const; // If have drawing area
196 void CanvasSetClientSize(int width
, int size
);
197 void CanvasSetSize(int x
, int y
, int width
, int height
, int sizeFlags
= wxSIZE_AUTO
);
199 void SetMainWidget(WXWidget w
) { m_mainWidget
= w
; }
201 bool CanAddEventHandler() const { return m_canAddEventHandler
; }
202 void SetCanAddEventHandler(bool flag
) { m_canAddEventHandler
= flag
; }
205 WXPixmap
GetBackingPixmap() const { return m_backingPixmap
; }
206 void SetBackingPixmap(WXPixmap pixmap
) { m_backingPixmap
= pixmap
; }
207 int GetPixmapWidth() const { return m_pixmapWidth
; }
208 int GetPixmapHeight() const { return m_pixmapHeight
; }
209 void SetPixmapWidth(int w
) { m_pixmapWidth
= w
; }
210 void SetPixmapHeight(int h
) { m_pixmapHeight
= h
; }
213 virtual void ChangeFont(bool keepOriginalSize
= TRUE
); // Change to the current font (often overridden)
215 // Change background and foreground colour using current background colour
216 // setting (Motif generates foreground based on background)
217 virtual void ChangeBackgroundColour();
218 // Change foreground colour using current foreground colour setting
219 virtual void ChangeForegroundColour();
222 // Adds the widget to the hash table and adds event handlers.
223 bool AttachWidget(wxWindow
* parent
, WXWidget mainWidget
,
224 WXWidget formWidget
, int x
, int y
, int width
, int height
);
225 bool DetachWidget(WXWidget widget
);
227 // How to implement accelerators. If we find a key event, translate to
228 // wxWindows wxKeyEvent form. Find a widget for the window. Now find a
229 // wxWindow for the widget. If there isn't one, go up the widget hierarchy
230 // trying to find one. Once one is found, call ProcessAccelerator for the
231 // window. If it returns TRUE (processed the event), skip the X event,
232 // otherwise carry on up the wxWindows window hierarchy calling
233 // ProcessAccelerator. If all return FALSE, process the X event as normal.
234 // Eventually we can implement OnCharHook the same way, but concentrate on
235 // accelerators for now. ProcessAccelerator must look at the current
236 // accelerator table, and try to find what menu id or window (beneath it)
237 // has this ID. Then construct an appropriate command
238 // event and send it.
240 virtual bool ProcessAccelerator(wxKeyEvent
& event
);
243 // unmanage and destroy an X widget f it's !NULL (passing NULL is ok)
244 void UnmanageAndDestroy(WXWidget widget
);
246 // map or unmap an X widget (passing NULL is ok), returns TRUE if widget was
248 bool MapOrUnmap(WXWidget widget
, bool map
);
253 // create/destroy window scrollbars
254 void CreateScrollbar(wxOrientation orientation
);
255 void DestroyScrollbar(wxOrientation orientation
);
257 // get either hor or vert scrollbar widget
258 WXWidget
GetScrollbar(wxOrientation orient
) const
259 { return orient
== wxHORIZONTAL
? m_hScrollBar
: m_vScrollBar
; }
261 // set the scroll pos
262 void SetInternalScrollPos(wxOrientation orient
, int pos
)
264 if ( orient
== wxHORIZONTAL
)
270 // Motif-specific flags
271 // --------------------
273 bool m_needsRefresh
:1; // repaint backing store?
274 bool m_canAddEventHandler
:1; // ???
275 bool m_button1Pressed
:1;
276 bool m_button2Pressed
:1;
277 bool m_button3Pressed
:1;
279 // For double-click detection
280 long m_lastTS
; // last timestamp
281 int m_lastButton
; // last pressed button
283 // List of wxRects representing damaged region
284 wxRectList m_updateRects
;
287 WXWidget m_mainWidget
;
288 WXWidget m_hScrollBar
;
289 WXWidget m_vScrollBar
;
290 WXWidget m_borderWidget
;
291 WXWidget m_scrolledWindow
;
292 WXWidget m_drawingArea
;
296 WXPixmap m_backingPixmap
;
302 // Store the last scroll pos, since in wxWin the pos isn't set automatically
307 // implement the base class pure virtuals
308 virtual void DoClientToScreen( int *x
, int *y
) const;
309 virtual void DoScreenToClient( int *x
, int *y
) const;
310 virtual void DoGetPosition( int *x
, int *y
) const;
311 virtual void DoGetSize( int *width
, int *height
) const;
312 virtual void DoGetClientSize( int *width
, int *height
) const;
313 virtual void DoSetSize(int x
, int y
,
314 int width
, int height
,
315 int sizeFlags
= wxSIZE_AUTO
);
316 virtual void DoSetClientSize(int width
, int height
);
317 virtual void DoMoveWindow(int x
, int y
, int width
, int height
);
318 virtual bool DoPopupMenu(wxMenu
*menu
, int x
, int y
);
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; }