]> git.saurik.com Git - wxWidgets.git/blob - include/wx/motif/window.h
fixed compilation warning about signed/unsigned comparison
[wxWidgets.git] / include / wx / motif / window.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: window.h
3 // Purpose: wxWindow class
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 17/09/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_WINDOW_H_
13 #define _WX_WINDOW_H_
14
15 #ifdef __GNUG__
16 #pragma interface "window.h"
17 #endif
18
19 #include "wx/region.h"
20
21 // ----------------------------------------------------------------------------
22 // wxWindow class for Motif - see also wxWindowBase
23 // ----------------------------------------------------------------------------
24
25 class wxWindow : public wxWindowBase
26 {
27 friend class WXDLLEXPORT wxDC;
28 friend class WXDLLEXPORT wxWindowDC;
29
30 public:
31 wxWindow() { Init(); }
32
33 wxWindow(wxWindow *parent,
34 wxWindowID id,
35 const wxPoint& pos = wxDefaultPosition,
36 const wxSize& size = wxDefaultSize,
37 long style = 0,
38 const wxString& name = wxPanelNameStr)
39 {
40 Init();
41 Create(parent, id, pos, size, style, name);
42 }
43
44 virtual ~wxWindow();
45
46 bool Create(wxWindow *parent,
47 wxWindowID id,
48 const wxPoint& pos = wxDefaultPosition,
49 const wxSize& size = wxDefaultSize,
50 long style = 0,
51 const wxString& name = wxPanelNameStr);
52
53 // implement base class pure virtuals
54 virtual void SetTitle( const wxString& title);
55 virtual wxString GetTitle() const;
56
57 virtual void Raise();
58 virtual void Lower();
59
60 virtual bool Show( bool show = TRUE );
61 virtual bool Enable( bool enable = TRUE );
62
63 virtual void SetFocus();
64
65 virtual void WarpPointer(int x, int y);
66 virtual void CaptureMouse();
67 virtual void ReleaseMouse();
68
69 virtual void Refresh( bool eraseBackground = TRUE,
70 const wxRect *rect = (const wxRect *) NULL );
71 virtual void Clear();
72
73 virtual bool SetBackgroundColour( const wxColour &colour );
74 virtual bool SetForegroundColour( const wxColour &colour );
75
76 virtual bool SetCursor( const wxCursor &cursor );
77 virtual bool SetFont( const wxFont &font );
78
79 virtual int GetCharHeight() const;
80 virtual int GetCharWidth() const;
81 virtual void GetTextExtent(const wxString& string,
82 int *x, int *y,
83 int *descent = (int *) NULL,
84 int *externalLeading = (int *) NULL,
85 const wxFont *theFont = (const wxFont *) NULL)
86 const;
87
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 );
96
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
103
104 // Accept files for dragging
105 virtual void DragAcceptFiles(bool accept);
106
107 // Get the unique identifier of a window
108 virtual WXWidget GetHandle() const { return GetMainWidget(); }
109
110 // implementation from now on
111 // --------------------------
112
113 // accessors
114 // ---------
115
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
121 // windows on)
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;
127
128 // Get the underlying X window and display
129 WXWindow GetXWindow() const;
130 WXDisplay *GetXDisplay() const;
131
132 // called from Motif callbacks - and should only be called from there
133
134 void SetButton1(bool pressed) { m_button1Pressed = pressed; }
135 void SetButton2(bool pressed) { m_button2Pressed = pressed; }
136 void SetButton3(bool pressed) { m_button3Pressed = pressed; }
137
138 void SetLastClick(int button, long timestamp)
139 { m_lastButton = button; m_lastTS = timestamp; }
140
141 int GetLastClickedButton() const { return m_lastButton; }
142 long GetLastClickTime() const { return m_lastTS; }
143
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();
147
148 // Generates a paint event
149 virtual void DoPaint();
150
151 // update rectangle/region manipulation
152 // (for wxWindowDC and Motif callbacks only)
153 // -----------------------------------------
154
155 // read/write access to the update rect list
156 const wxRectList& GetUpdateRects() const { return m_updateRects; }
157
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)); }
161
162 // Empties the m_updateRects list
163 void ClearUpdateRects();
164
165 void ClearUpdateRegion() { m_updateRegion.Clear(); }
166 void SetUpdateRegion(const wxRegion& region) { m_updateRegion = region; }
167
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);
171
172 // For implementation purposes - sometimes decorations make the client area
173 // smaller
174 virtual wxPoint GetClientAreaOrigin() const;
175
176 protected:
177 // event handlers (not virtual by design)
178 void OnIdle(wxIdleEvent& event);
179
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);
183
184 wxWindow *GetChild(int number) const
185 { return GetChildren().Item(number)->GetData(); }
186
187 // Responds to colour changes: passes event on to children.
188 void OnSysColourChanged(wxSysColourChangedEvent& event);
189
190 // Motif-specific
191
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);
198
199 void SetMainWidget(WXWidget w) { m_mainWidget = w; }
200
201 bool CanAddEventHandler() const { return m_canAddEventHandler; }
202 void SetCanAddEventHandler(bool flag) { m_canAddEventHandler = flag; }
203
204 public:
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; }
211
212 // Change properties
213 virtual void ChangeFont(bool keepOriginalSize = TRUE); // Change to the current font (often overridden)
214
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();
220
221 protected:
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);
226
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.
239 public:
240 virtual bool ProcessAccelerator(wxKeyEvent& event);
241
242 protected:
243 // unmanage and destroy an X widget f it's !NULL (passing NULL is ok)
244 void UnmanageAndDestroy(WXWidget widget);
245
246 // map or unmap an X widget (passing NULL is ok), returns TRUE if widget was
247 // mapped/unmapped
248 bool MapOrUnmap(WXWidget widget, bool map);
249
250 // scrolling stuff
251 // ---------------
252
253 // create/destroy window scrollbars
254 void CreateScrollbar(wxOrientation orientation);
255 void DestroyScrollbar(wxOrientation orientation);
256
257 // get either hor or vert scrollbar widget
258 WXWidget GetScrollbar(wxOrientation orient) const
259 { return orient == wxHORIZONTAL ? m_hScrollBar : m_vScrollBar; }
260
261 // set the scroll pos
262 void SetInternalScrollPos(wxOrientation orient, int pos)
263 {
264 if ( orient == wxHORIZONTAL )
265 m_scrollPosX = pos;
266 else
267 m_scrollPosY = pos;
268 }
269
270 // Motif-specific flags
271 // --------------------
272
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;
278
279 // For double-click detection
280 long m_lastTS; // last timestamp
281 int m_lastButton; // last pressed button
282
283 // List of wxRects representing damaged region
284 wxRectList m_updateRects;
285
286 protected:
287 WXWidget m_mainWidget;
288 WXWidget m_hScrollBar;
289 WXWidget m_vScrollBar;
290 WXWidget m_borderWidget;
291 WXWidget m_scrolledWindow;
292 WXWidget m_drawingArea;
293 bool m_winCaptured;
294 bool m_hScroll;
295 bool m_vScroll;
296 WXPixmap m_backingPixmap;
297 int m_pixmapWidth;
298 int m_pixmapHeight;
299 int m_pixmapOffsetX;
300 int m_pixmapOffsetY;
301
302 // Store the last scroll pos, since in wxWin the pos isn't set automatically
303 // by system
304 int m_scrollPosX;
305 int m_scrollPosY;
306
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);
319
320 #if wxUSE_TOOLTIPS
321 virtual void DoSetToolTip( wxToolTip *tip );
322 #endif // wxUSE_TOOLTIPS
323
324 private:
325 // common part of all ctors
326 void Init();
327
328 DECLARE_DYNAMIC_CLASS(wxWindow)
329 DECLARE_NO_COPY_CLASS(wxWindow)
330 DECLARE_EVENT_TABLE()
331 };
332
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.
339 //
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 // ----------------------------------------------------------------------------
343
344 class WXDLLEXPORT wxNoOptimize
345 {
346 public:
347 wxNoOptimize() { ms_count++; }
348 ~wxNoOptimize() { ms_count--; }
349
350 static bool CanOptimize() { return ms_count == 0; }
351
352 protected:
353 static int ms_count;
354 };
355
356 #endif
357 // _WX_WINDOW_H_