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 // called from Motif callbacks - and should only be called from there
128 void SetButton1(bool pressed
) { m_button1Pressed
= pressed
; }
129 void SetButton2(bool pressed
) { m_button2Pressed
= pressed
; }
130 void SetButton3(bool pressed
) { m_button3Pressed
= pressed
; }
132 void SetLastClick(int button
, long timestamp
)
133 { m_lastButton
= button
; m_lastTS
= timestamp
; }
135 int GetLastClickedButton() const { return m_lastButton
; }
136 long GetLastClickTime() const { return m_lastTS
; }
138 // Gives window a chance to do something in response to a size message, e.g.
139 // arrange status bar, toolbar etc.
140 virtual bool PreResize();
142 // Generates a paint event
143 virtual void DoPaint();
145 // update rectangle/region manipulation
146 // (for wxWindowDC and Motif callbacks only)
147 // -----------------------------------------
149 // read/write access to the update rect list
150 const wxRectList
& GetUpdateRects() const { return m_updateRects
; }
152 // Adds a recangle to the updates list
153 void AddUpdateRect(int x
, int y
, int w
, int h
)
154 { m_updateRects
.Append(new wxRect(x
, y
, w
, h
)); }
156 // Empties the m_updateRects list
157 void ClearUpdateRects();
159 void ClearUpdateRegion() { m_updateRegion
.Clear(); }
160 void SetUpdateRegion(const wxRegion
& region
) { m_updateRegion
= region
; }
162 // sets the fore/background colour for the given widget
163 static void DoChangeForegroundColour(WXWindow widget
, wxColour
& foregroundColour
);
164 static void DoChangeBackgroundColour(WXWindow widget
, wxColour
& backgroundColour
, bool changeArmColour
= FALSE
);
166 // For implementation purposes - sometimes decorations make the client area
168 virtual wxPoint
GetClientAreaOrigin() const;
171 // event handlers (not virtual by design)
172 void OnIdle(wxIdleEvent
& event
);
174 // Makes an adjustment to the window position (for example, a frame that has
175 // a toolbar that it manages itself).
176 virtual void AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
);
178 wxWindow
*GetChild(int number
) const
179 { return GetChildren().Item(number
)->GetData(); }
181 // Responds to colour changes: passes event on to children.
182 void OnSysColourChanged(wxSysColourChangedEvent
& event
);
184 void SetMainWindow(WXWindow w
) { m_mainWidget
= w
; }
186 bool CanAddEventHandler() const { return m_canAddEventHandler
; }
187 void SetCanAddEventHandler(bool flag
) { m_canAddEventHandler
= flag
; }
190 WXPixmap
GetBackingPixmap() const { return m_backingPixmap
; }
191 void SetBackingPixmap(WXPixmap pixmap
) { m_backingPixmap
= pixmap
; }
192 int GetPixmapWidth() const { return m_pixmapWidth
; }
193 int GetPixmapHeight() const { return m_pixmapHeight
; }
194 void SetPixmapWidth(int w
) { m_pixmapWidth
= w
; }
195 void SetPixmapHeight(int h
) { m_pixmapHeight
= h
; }
198 virtual void ChangeFont(bool keepOriginalSize
= TRUE
); // Change to the current font (often overridden)
200 // Change background and foreground colour using current background colour
201 // setting (Motif generates foreground based on background)
202 virtual void ChangeBackgroundColour();
203 // Change foreground colour using current foreground colour setting
204 virtual void ChangeForegroundColour();
207 // How to implement accelerators. If we find a key event, translate to
208 // wxWindows wxKeyEvent form. Find a widget for the window. Now find a
209 // wxWindow for the widget. If there isn't one, go up the widget hierarchy
210 // trying to find one. Once one is found, call ProcessAccelerator for the
211 // window. If it returns TRUE (processed the event), skip the X event,
212 // otherwise carry on up the wxWindows window hierarchy calling
213 // ProcessAccelerator. If all return FALSE, process the X event as normal.
214 // Eventually we can implement OnCharHook the same way, but concentrate on
215 // accelerators for now. ProcessAccelerator must look at the current
216 // accelerator table, and try to find what menu id or window (beneath it)
217 // has this ID. Then construct an appropriate command
218 // event and send it.
220 virtual bool ProcessAccelerator(wxKeyEvent
& event
);
226 // create/destroy window scrollbars
227 void CreateScrollbar(wxOrientation orientation
);
228 void DestroyScrollbar(wxOrientation orientation
);
230 // get either hor or vert scrollbar widget
231 WXWindow
GetScrollbar(wxOrientation orient
) const
232 { return orient
== wxHORIZONTAL ? m_hScrollBar
: m_vScrollBar
; }
234 // set the scroll pos
235 void SetInternalScrollPos(wxOrientation orient
, int pos
)
237 if ( orient
== wxHORIZONTAL
)
243 // Motif-specific flags
244 // --------------------
246 bool m_needsRefresh
:1; // repaint backing store?
247 bool m_canAddEventHandler
:1; // ???
248 bool m_button1Pressed
:1;
249 bool m_button2Pressed
:1;
250 bool m_button3Pressed
:1;
252 // For double-click detection
253 long m_lastTS
; // last timestamp
254 int m_lastButton
; // last pressed button
256 // List of wxRects representing damaged region
257 wxRectList m_updateRects
;
260 WXWindow m_mainWidget
;
261 WXWindow m_hScrollBar
;
262 WXWindow m_vScrollBar
;
263 WXWindow m_borderWidget
;
264 WXWindow m_scrolledWindow
;
265 WXWindow m_drawingArea
;
269 WXPixmap m_backingPixmap
;
275 // Store the last scroll pos, since in wxWin the pos isn't set automatically
280 // Window border size
283 // implement the base class pure virtuals
284 virtual void DoClientToScreen( int *x
, int *y
) const;
285 virtual void DoScreenToClient( int *x
, int *y
) const;
286 virtual void DoGetPosition( int *x
, int *y
) const;
287 virtual void DoGetSize( int *width
, int *height
) const;
288 virtual void DoGetClientSize( int *width
, int *height
) const;
289 virtual void DoSetSize(int x
, int y
,
290 int width
, int height
,
291 int sizeFlags
= wxSIZE_AUTO
);
292 virtual void DoSetClientSize(int width
, int height
);
293 virtual void DoMoveWindow(int x
, int y
, int width
, int height
);
294 virtual bool DoPopupMenu(wxMenu
*menu
, int x
, int y
);
296 virtual void DoCaptureMouse();
297 virtual void DoReleaseMouse();
300 virtual void DoSetToolTip( wxToolTip
*tip
);
301 #endif // wxUSE_TOOLTIPS
304 // common part of all ctors
307 DECLARE_DYNAMIC_CLASS(wxWindowX11
)
308 DECLARE_NO_COPY_CLASS(wxWindowX11
)
309 DECLARE_EVENT_TABLE()
312 // ----------------------------------------------------------------------------
313 // A little class to switch off `size optimization' while an instance of the
314 // object exists: this may be useful to temporarily disable the optimisation
315 // which consists to do nothing when the new size is equal to the old size -
316 // although quite useful usually to avoid flicker, sometimes it leads to
317 // undesired effects.
319 // Usage: create an instance of this class on the stack to disable the size
320 // optimisation, it will be reenabled as soon as the object goes out from scope.
321 // ----------------------------------------------------------------------------
323 class WXDLLEXPORT wxNoOptimize
326 wxNoOptimize() { ms_count
++; }
327 ~wxNoOptimize() { ms_count
--; }
329 static bool CanOptimize() { return ms_count
== 0; }