]> git.saurik.com Git - wxWidgets.git/blob - include/wx/motif/window.h
Coupled some core functionality out, to allow its use outside the wxLibrary
[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 // ----------------------------------------------------------------------------
20 // wxWindow class for Motif - see also wxWindowBase
21 // ----------------------------------------------------------------------------
22
23 class wxWindow : public wxWindowBase
24 {
25 DECLARE_DYNAMIC_CLASS(wxWindow)
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 SetCursor( const wxCursor &cursor );
74 virtual bool SetFont( const wxFont &font );
75
76 virtual int GetCharHeight() const;
77 virtual int GetCharWidth() const;
78 virtual void GetTextExtent(const wxString& string,
79 int *x, int *y,
80 int *descent = (int *) NULL,
81 int *externalLeading = (int *) NULL,
82 const wxFont *theFont = (const wxFont *) NULL)
83 const;
84
85 virtual bool PopupMenu( wxMenu *menu, int x, int y );
86
87 virtual void SetScrollbar( int orient, int pos, int thumbVisible,
88 int range, bool refresh = TRUE );
89 virtual void SetScrollPos( int orient, int pos, bool refresh = TRUE );
90 virtual int GetScrollPos( int orient ) const;
91 virtual int GetScrollThumb( int orient ) const;
92 virtual int GetScrollRange( int orient ) const;
93 virtual void ScrollWindow( int dx, int dy,
94 const wxRect* rect = (wxRect *) NULL );
95
96 #if wxUSE_DRAG_AND_DROP
97 virtual void SetDropTarget( wxDropTarget *dropTarget );
98 #endif // wxUSE_DRAG_AND_DROP
99
100 // Accept files for dragging
101 virtual void DragAcceptFiles(bool accept);
102
103 protected:
104 // event handlers (not virtual by design)
105 void OnIdle(wxIdleEvent& event);
106
107 // For implementation purposes - sometimes decorations make the client area
108 // smaller
109 virtual wxPoint GetClientAreaOrigin() const;
110
111 // Makes an adjustment to the window position (for example, a frame that has
112 // a toolbar that it manages itself).
113 virtual void AdjustForParentClientOrigin(int& x, int& y, int sizeFlags);
114
115 virtual void AddChild(wxWindow *child); // Adds reference to the child object
116 virtual void RemoveChild(wxWindow *child); // Removes reference to child
117 virtual void DestroyChildren(); // Removes and destroys all children
118
119 wxWindow *GetChild(int number) const
120 { return GetChildren().Item(number)->GetData(); }
121
122 // Responds to colour changes: passes event on to children.
123 void OnSysColourChanged(wxSysColourChangedEvent& event);
124
125 // Motif-specific
126
127 // empties the m_updateRects list
128 void ClearUpdateRects();
129
130 // CanvasXXXSiize functions
131 void CanvasGetSize(int* width, int* height) const; // If have drawing area
132 void CanvasGetClientSize(int *width, int *height) const;
133 void CanvasGetPosition(int *x, int *y) const; // If have drawing area
134 void CanvasSetClientSize(int width, int size);
135 void CanvasSetSize(int x, int y, int width, int height, int sizeFlags = wxSIZE_AUTO);
136
137 // Gives window a chance to do something in response to a size message, e.g.
138 // arrange status bar, toolbar etc.
139 virtual bool PreResize() { return TRUE; }
140
141 // accessors
142 // ---------
143
144 // Get main widget for this window, e.g. a text widget
145 virtual WXWidget GetMainWidget() const;
146 // Get the widget that corresponds to the label (for font setting, label setting etc.)
147 virtual WXWidget GetLabelWidget() const;
148 // Get the client widget for this window (something we can create other
149 // windows on)
150 virtual WXWidget GetClientWidget() const;
151 // Get the top widget for this window, e.g. the scrolled widget parent of a
152 // multi-line text widget. Top means, top in the window hierarchy that
153 // implements this window.
154 virtual WXWidget GetTopWidget() const;
155
156 // base class pure virtual
157 virtual WXWidget GetHandle() const { return GetMainWidget(); }
158
159 void SetMainWidget(WXWidget w) { m_mainWidget = w; }
160
161 bool CanAddEventHandler() const { return m_canAddEventHandler; }
162 void SetCanAddEventHandler(bool flag) { m_canAddEventHandler = flag; }
163
164 // Get the underlying X window and display
165 WXWindow GetXWindow() const;
166 WXDisplay *GetXDisplay() const;
167
168 WXPixmap GetBackingPixmap() const { return m_backingPixmap; }
169 int GetPixmapWidth() const { return m_pixmapWidth; }
170 int GetPixmapHeight() const { return m_pixmapHeight; }
171
172 // Change properties
173 virtual void ChangeFont(bool keepOriginalSize = TRUE); // Change to the current font (often overridden)
174 virtual void DoChangeForegroundColour(WXWidget widget, wxColour& foregroundColour);
175 virtual void DoChangeBackgroundColour(WXWidget widget, wxColour& backgroundColour, bool changeArmColour = FALSE);
176
177 // Change background and foreground colour using current background colour
178 // setting (Motif generates foreground based on background)
179 virtual void ChangeBackgroundColour();
180 // Change foreground colour using current foreground colour setting
181 virtual void ChangeForegroundColour();
182
183 // Adds the widget to the hash table and adds event handlers.
184 bool AttachWidget(wxWindow* parent, WXWidget mainWidget,
185 WXWidget formWidget, int x, int y, int width, int height);
186 bool DetachWidget(WXWidget widget);
187
188 // Generates a paint event
189 virtual void DoPaint();
190
191 // How to implement accelerators. If we find a key event, translate to
192 // wxWindows wxKeyEvent form. Find a widget for the window. Now find a
193 // wxWindow for the widget. If there isn't one, go up the widget hierarchy
194 // trying to find one. Once one is found, call ProcessAccelerator for the
195 // window. If it returns TRUE (processed the event), skip the X event,
196 // otherwise carry on up the wxWindows window hierarchy calling
197 // ProcessAccelerator. If all return FALSE, process the X event as normal.
198 // Eventually we can implement OnCharHook the same way, but concentrate on
199 // accelerators for now. ProcessAccelerator must look at the current
200 // accelerator table, and try to find what menu id or window (beneath it)
201 // has this ID. Then construct an appropriate command
202 // event and send it.
203 virtual bool ProcessAccelerator(wxKeyEvent& event);
204
205 protected:
206 // unmanage and destroy an X widget f it's !NULL (passing NULL is ok)
207 void UnmanageAndDestroy(WXWidget widget);
208
209 // map or unmap an X widget (passing NULL is ok), returns TRUE if widget was
210 // mapped/unmapped
211 bool MapOrUnmap(WXWidget widget, bool map);
212
213 // get either hor or vert scrollbar widget
214 WXWidget GetScrollbar(wxOrientation orient) const
215 { return orient == wxHORIZONTAL ? m_hScrollBar : m_vScrollBar; }
216
217 // set the scroll pos
218 void SetInternalScrollPos(wxOrientation orient, int pos)
219 {
220 if ( orient == wxHORIZONTAL )
221 m_scrollPosX = pos;
222 else
223 m_scrollPosY = pos;
224 }
225
226 // Motif-specific flags
227 bool m_needsRefresh:1; // repaint backing store?
228 bool m_canAddEventHandler:1; // ???
229 bool m_button1Pressed:1;
230 bool m_button2Pressed:1;
231 bool m_button3Pressed:1;
232
233 // For double-click detection
234 long m_lastTS; // last timestamp
235 int m_lastButton; // last pressed button
236 wxList m_updateRects; // List of wxRects representing damaged region
237
238 protected:
239 WXWidget m_mainWidget;
240 WXWidget m_hScrollBar;
241 WXWidget m_vScrollBar;
242 WXWidget m_borderWidget;
243 WXWidget m_scrolledWindow;
244 WXWidget m_drawingArea;
245 bool m_winCaptured;
246 bool m_hScroll;
247 bool m_vScroll;
248 WXPixmap m_backingPixmap;
249 int m_pixmapWidth;
250 int m_pixmapHeight;
251 int m_pixmapOffsetX;
252 int m_pixmapOffsetY;
253
254 // Store the last scroll pos, since in wxWin the pos isn't set automatically
255 // by system
256 int m_scrollPosX;
257 int m_scrollPosY;
258
259 // implement the base class pure virtuals
260 virtual void DoClientToScreen( int *x, int *y ) const;
261 virtual void DoScreenToClient( int *x, int *y ) const;
262 virtual void DoGetPosition( int *x, int *y ) const;
263 virtual void DoGetSize( int *width, int *height ) const;
264 virtual void DoGetClientSize( int *width, int *height ) const;
265 virtual void DoSetSize(int x, int y,
266 int width, int height,
267 int sizeFlags = wxSIZE_AUTO);
268 virtual void DoSetClientSize(int width, int height);
269
270 #if wxUSE_TOOLTIPS
271 virtual void DoSetToolTip( wxToolTip *tip );
272 #endif // wxUSE_TOOLTIPS
273
274 private:
275 // common part of all ctors
276 void Init();
277
278 DECLARE_NO_COPY_CLASS(wxWindow);
279 DECLARE_EVENT_TABLE()
280 };
281
282 // ----------------------------------------------------------------------------
283 // A little class to switch off size optimization while an instance of the object
284 // exists
285 //
286 // TODO what is it for??
287 // ----------------------------------------------------------------------------
288 class WXDLLEXPORT wxNoOptimize: public wxObject
289 {
290 public:
291 wxNoOptimize();
292 ~wxNoOptimize();
293
294 static bool CanOptimize();
295
296 protected:
297 static int m_count;
298 };
299
300 #endif
301 // _WX_WINDOW_H_