1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/motif/window.h
3 // Purpose: wxWindow class
4 // Author: Julian Smart
7 // Copyright: (c) Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
14 #include "wx/region.h"
16 // ----------------------------------------------------------------------------
17 // wxWindow class for Motif - see also wxWindowBase
18 // ----------------------------------------------------------------------------
20 class WXDLLIMPEXP_CORE wxWindow
: public wxWindowBase
22 friend class WXDLLIMPEXP_FWD_CORE wxDC
;
23 friend class WXDLLIMPEXP_FWD_CORE wxWindowDC
;
26 wxWindow() { Init(); }
28 wxWindow(wxWindow
*parent
,
30 const wxPoint
& pos
= wxDefaultPosition
,
31 const wxSize
& size
= wxDefaultSize
,
33 const wxString
& name
= wxPanelNameStr
)
36 Create(parent
, id
, pos
, size
, style
, name
);
41 bool Create(wxWindow
*parent
,
43 const wxPoint
& pos
= wxDefaultPosition
,
44 const wxSize
& size
= wxDefaultSize
,
46 const wxString
& name
= wxPanelNameStr
);
48 // implement base class pure virtuals
49 virtual void SetLabel(const wxString
& label
);
50 virtual wxString
GetLabel() const;
55 virtual bool Show( bool show
= true );
56 virtual bool Enable( bool enable
= true );
58 virtual void SetFocus();
60 virtual void WarpPointer(int x
, int y
);
62 virtual void Refresh( bool eraseBackground
= true,
63 const wxRect
*rect
= (const wxRect
*) NULL
);
65 virtual bool SetBackgroundColour( const wxColour
&colour
);
66 virtual bool SetForegroundColour( const wxColour
&colour
);
68 virtual bool SetCursor( const wxCursor
&cursor
);
69 virtual bool SetFont( const wxFont
&font
);
71 virtual int GetCharHeight() const;
72 virtual int GetCharWidth() const;
74 virtual void SetScrollbar( int orient
, int pos
, int thumbVisible
,
75 int range
, bool refresh
= true );
76 virtual void SetScrollPos( int orient
, int pos
, bool refresh
= true );
77 virtual int GetScrollPos( int orient
) const;
78 virtual int GetScrollThumb( int orient
) const;
79 virtual int GetScrollRange( int orient
) const;
80 virtual void ScrollWindow( int dx
, int dy
,
81 const wxRect
* rect
= NULL
);
83 #if wxUSE_DRAG_AND_DROP
84 virtual void SetDropTarget( wxDropTarget
*dropTarget
);
85 #endif // wxUSE_DRAG_AND_DROP
87 // Accept files for dragging
88 virtual void DragAcceptFiles(bool accept
);
90 // Get the unique identifier of a window
91 virtual WXWidget
GetHandle() const { return GetMainWidget(); }
93 // implementation from now on
94 // --------------------------
99 // Get main widget for this window, e.g. a text widget
100 virtual WXWidget
GetMainWidget() const;
101 // Get the widget that corresponds to the label (for font setting,
102 // label setting etc.)
103 virtual WXWidget
GetLabelWidget() const;
104 // Get the client widget for this window (something we can create other
106 virtual WXWidget
GetClientWidget() const;
107 // Get the top widget for this window, e.g. the scrolled widget parent of a
108 // multi-line text widget. Top means, top in the window hierarchy that
109 // implements this window.
110 virtual WXWidget
GetTopWidget() const;
112 // Get the underlying X window and display
113 WXWindow
GetClientXWindow() const;
114 WXWindow
GetXWindow() const;
115 WXDisplay
*GetXDisplay() const;
117 void SetLastClick(int button
, long timestamp
)
118 { m_lastButton
= button
; m_lastTS
= timestamp
; }
120 int GetLastClickedButton() const { return m_lastButton
; }
121 long GetLastClickTime() const { return m_lastTS
; }
123 // Gives window a chance to do something in response to a size message,
124 // e.g. arrange status bar, toolbar etc.
125 virtual bool PreResize();
127 // Generates a paint event
128 virtual void DoPaint();
130 // update rectangle/region manipulation
131 // (for wxWindowDC and Motif callbacks only)
132 // -----------------------------------------
134 // Adds a recangle to the updates list
135 void AddUpdateRect(int x
, int y
, int w
, int h
);
137 void ClearUpdateRegion() { m_updateRegion
.Clear(); }
138 void SetUpdateRegion(const wxRegion
& region
) { m_updateRegion
= region
; }
140 // post-creation activities
143 // pre-creation activities
147 // Responds to colour changes: passes event on to children.
148 void OnSysColourChanged(wxSysColourChangedEvent
& event
);
152 void SetMainWidget(WXWidget w
) { m_mainWidget
= w
; }
154 // See src/motif/window.cpp, near the top, for an explanation
155 // why this is necessary
156 void CanvasSetSizeIntr(int x
, int y
, int width
, int height
,
157 int sizeFlags
, bool fromCtor
);
158 void DoSetSizeIntr(int x
, int y
,
159 int width
, int height
,
160 int sizeFlags
, bool fromCtor
);
162 // for DoMoveWindowIntr flags
171 void DoMoveWindowIntr(int x
, int y
, int width
, int height
,
174 // helper function, to remove duplicate code, used in wxScrollBar
175 WXWidget
DoCreateScrollBar(WXWidget parent
, wxOrientation orientation
,
178 WXPixmap
GetBackingPixmap() const { return m_backingPixmap
; }
179 void SetBackingPixmap(WXPixmap pixmap
) { m_backingPixmap
= pixmap
; }
180 int GetPixmapWidth() const { return m_pixmapWidth
; }
181 int GetPixmapHeight() const { return m_pixmapHeight
; }
182 void SetPixmapWidth(int w
) { m_pixmapWidth
= w
; }
183 void SetPixmapHeight(int h
) { m_pixmapHeight
= h
; }
186 // Change to the current font (often overridden)
187 virtual void ChangeFont(bool keepOriginalSize
= true);
189 // Change background and foreground colour using current background colour
190 // setting (Motif generates foreground based on background)
191 virtual void ChangeBackgroundColour();
192 // Change foreground colour using current foreground colour setting
193 virtual void ChangeForegroundColour();
196 // Adds the widget to the hash table and adds event handlers.
197 bool AttachWidget(wxWindow
* parent
, WXWidget mainWidget
,
198 WXWidget formWidget
, int x
, int y
, int width
, int height
);
199 bool DetachWidget(WXWidget widget
);
201 // How to implement accelerators. If we find a key event, translate to
202 // wxWidgets wxKeyEvent form. Find a widget for the window. Now find a
203 // wxWindow for the widget. If there isn't one, go up the widget hierarchy
204 // trying to find one. Once one is found, call ProcessAccelerator for the
205 // window. If it returns true (processed the event), skip the X event,
206 // otherwise carry on up the wxWidgets window hierarchy calling
207 // ProcessAccelerator. If all return false, process the X event as normal.
208 // Eventually we can implement OnCharHook the same way, but concentrate on
209 // accelerators for now. ProcessAccelerator must look at the current
210 // accelerator table, and try to find what menu id or window (beneath it)
211 // has this ID. Then construct an appropriate command
212 // event and send it.
214 virtual bool ProcessAccelerator(wxKeyEvent
& event
);
217 // unmanage and destroy an X widget f it's !NULL (passing NULL is ok)
218 void UnmanageAndDestroy(WXWidget widget
);
220 // map or unmap an X widget (passing NULL is ok),
221 // returns true if widget was mapped/unmapped
222 bool MapOrUnmap(WXWidget widget
, bool map
);
227 // create/destroy window scrollbars
228 void CreateScrollbar(wxOrientation orientation
);
229 void DestroyScrollbar(wxOrientation orientation
);
231 // get either hor or vert scrollbar widget
232 WXWidget
GetScrollbar(wxOrientation orient
) const
233 { return orient
== wxHORIZONTAL
? m_hScrollBar
: m_vScrollBar
; }
235 // set the scroll pos
236 void SetInternalScrollPos(wxOrientation orient
, int pos
)
238 if ( orient
== wxHORIZONTAL
)
244 // Motif-specific flags
245 // --------------------
247 bool m_needsRefresh
:1; // repaint backing store?
249 // For double-click detection
250 long m_lastTS
; // last timestamp
251 unsigned m_lastButton
:2; // last pressed button
254 WXWidget m_mainWidget
;
255 WXWidget m_hScrollBar
;
256 WXWidget m_vScrollBar
;
257 WXWidget m_borderWidget
;
258 WXWidget m_scrolledWindow
;
259 WXWidget m_drawingArea
;
260 bool m_winCaptured
:1;
261 WXPixmap m_backingPixmap
;
267 // Store the last scroll pos, since in wxWin the pos isn't set
268 // automatically by system
272 // implement the base class pure virtuals
273 virtual void DoGetTextExtent(const wxString
& string
,
276 int *externalLeading
= NULL
,
277 const wxFont
*font
= NULL
) const;
278 virtual void DoClientToScreen( int *x
, int *y
) const;
279 virtual void DoScreenToClient( int *x
, int *y
) const;
280 virtual void DoGetPosition( int *x
, int *y
) const;
281 virtual void DoGetSize( int *width
, int *height
) const;
282 virtual void DoGetClientSize( int *width
, int *height
) const;
283 virtual void DoSetSize(int x
, int y
,
284 int width
, int height
,
285 int sizeFlags
= wxSIZE_AUTO
);
286 virtual void DoSetClientSize(int width
, int height
);
287 virtual void DoMoveWindow(int x
, int y
, int width
, int height
);
288 virtual bool DoPopupMenu(wxMenu
*menu
, int x
, int y
);
289 virtual void DoCaptureMouse();
290 virtual void DoReleaseMouse();
293 virtual void DoSetToolTip( wxToolTip
*tip
);
294 #endif // wxUSE_TOOLTIPS
297 // common part of all ctors
300 DECLARE_DYNAMIC_CLASS(wxWindow
)
301 wxDECLARE_NO_COPY_CLASS(wxWindow
);
302 DECLARE_EVENT_TABLE()
305 // ----------------------------------------------------------------------------
306 // A little class to switch off `size optimization' while an instance of the
307 // object exists: this may be useful to temporarily disable the optimisation
308 // which consists to do nothing when the new size is equal to the old size -
309 // although quite useful usually to avoid flicker, sometimes it leads to
310 // undesired effects.
312 // Usage: create an instance of this class on the stack to disable the size
313 // optimisation, it will be reenabled as soon as the object goes out
315 // ----------------------------------------------------------------------------
317 class WXDLLIMPEXP_CORE wxNoOptimize
320 wxNoOptimize() { ms_count
++; }
321 ~wxNoOptimize() { ms_count
--; }
323 static bool CanOptimize() { return ms_count
== 0; }
329 #endif // _WX_WINDOW_H_