]> git.saurik.com Git - wxWidgets.git/blob - include/wx/motif/window.h
Try loading even English translations if provided.
[wxWidgets.git] / include / wx / motif / window.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/motif/window.h
3 // Purpose: wxWindow class
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 17/09/98
7 // Copyright: (c) Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 #ifndef _WX_WINDOW_H_
12 #define _WX_WINDOW_H_
13
14 #include "wx/region.h"
15
16 // ----------------------------------------------------------------------------
17 // wxWindow class for Motif - see also wxWindowBase
18 // ----------------------------------------------------------------------------
19
20 class WXDLLIMPEXP_CORE wxWindow : public wxWindowBase
21 {
22 friend class WXDLLIMPEXP_FWD_CORE wxDC;
23 friend class WXDLLIMPEXP_FWD_CORE wxWindowDC;
24
25 public:
26 wxWindow() { Init(); }
27
28 wxWindow(wxWindow *parent,
29 wxWindowID id,
30 const wxPoint& pos = wxDefaultPosition,
31 const wxSize& size = wxDefaultSize,
32 long style = 0,
33 const wxString& name = wxPanelNameStr)
34 {
35 Init();
36 Create(parent, id, pos, size, style, name);
37 }
38
39 virtual ~wxWindow();
40
41 bool Create(wxWindow *parent,
42 wxWindowID id,
43 const wxPoint& pos = wxDefaultPosition,
44 const wxSize& size = wxDefaultSize,
45 long style = 0,
46 const wxString& name = wxPanelNameStr);
47
48 // implement base class pure virtuals
49 virtual void SetLabel(const wxString& label);
50 virtual wxString GetLabel() const;
51
52 virtual void Raise();
53 virtual void Lower();
54
55 virtual bool Show( bool show = true );
56 virtual bool Enable( bool enable = true );
57
58 virtual void SetFocus();
59
60 virtual void WarpPointer(int x, int y);
61
62 virtual void Refresh( bool eraseBackground = true,
63 const wxRect *rect = (const wxRect *) NULL );
64
65 virtual bool SetBackgroundColour( const wxColour &colour );
66 virtual bool SetForegroundColour( const wxColour &colour );
67
68 virtual bool SetCursor( const wxCursor &cursor );
69 virtual bool SetFont( const wxFont &font );
70
71 virtual int GetCharHeight() const;
72 virtual int GetCharWidth() const;
73
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 );
82
83 #if wxUSE_DRAG_AND_DROP
84 virtual void SetDropTarget( wxDropTarget *dropTarget );
85 #endif // wxUSE_DRAG_AND_DROP
86
87 // Accept files for dragging
88 virtual void DragAcceptFiles(bool accept);
89
90 // Get the unique identifier of a window
91 virtual WXWidget GetHandle() const { return GetMainWidget(); }
92
93 // implementation from now on
94 // --------------------------
95
96 // accessors
97 // ---------
98
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
105 // windows on)
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;
111
112 // Get the underlying X window and display
113 WXWindow GetClientXWindow() const;
114 WXWindow GetXWindow() const;
115 WXDisplay *GetXDisplay() const;
116
117 void SetLastClick(int button, long timestamp)
118 { m_lastButton = button; m_lastTS = timestamp; }
119
120 int GetLastClickedButton() const { return m_lastButton; }
121 long GetLastClickTime() const { return m_lastTS; }
122
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();
126
127 // Generates a paint event
128 virtual void DoPaint();
129
130 // update rectangle/region manipulation
131 // (for wxWindowDC and Motif callbacks only)
132 // -----------------------------------------
133
134 // Adds a recangle to the updates list
135 void AddUpdateRect(int x, int y, int w, int h);
136
137 void ClearUpdateRegion() { m_updateRegion.Clear(); }
138 void SetUpdateRegion(const wxRegion& region) { m_updateRegion = region; }
139
140 // post-creation activities
141 void PostCreation();
142
143 // pre-creation activities
144 void PreCreation();
145
146 protected:
147 // Responds to colour changes: passes event on to children.
148 void OnSysColourChanged(wxSysColourChangedEvent& event);
149
150 // Motif-specific
151
152 void SetMainWidget(WXWidget w) { m_mainWidget = w; }
153
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);
161
162 // for DoMoveWindowIntr flags
163 enum
164 {
165 wxMOVE_X = 1,
166 wxMOVE_Y = 2,
167 wxMOVE_WIDTH = 4,
168 wxMOVE_HEIGHT = 8
169 };
170
171 void DoMoveWindowIntr(int x, int y, int width, int height,
172 int flags);
173
174 // helper function, to remove duplicate code, used in wxScrollBar
175 WXWidget DoCreateScrollBar(WXWidget parent, wxOrientation orientation,
176 void (*callback)());
177 public:
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; }
184
185 // Change properties
186 // Change to the current font (often overridden)
187 virtual void ChangeFont(bool keepOriginalSize = true);
188
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();
194
195 protected:
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);
200
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.
213 public:
214 virtual bool ProcessAccelerator(wxKeyEvent& event);
215
216 protected:
217 // unmanage and destroy an X widget f it's !NULL (passing NULL is ok)
218 void UnmanageAndDestroy(WXWidget widget);
219
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);
223
224 // scrolling stuff
225 // ---------------
226
227 // create/destroy window scrollbars
228 void CreateScrollbar(wxOrientation orientation);
229 void DestroyScrollbar(wxOrientation orientation);
230
231 // get either hor or vert scrollbar widget
232 WXWidget GetScrollbar(wxOrientation orient) const
233 { return orient == wxHORIZONTAL ? m_hScrollBar : m_vScrollBar; }
234
235 // set the scroll pos
236 void SetInternalScrollPos(wxOrientation orient, int pos)
237 {
238 if ( orient == wxHORIZONTAL )
239 m_scrollPosX = pos;
240 else
241 m_scrollPosY = pos;
242 }
243
244 // Motif-specific flags
245 // --------------------
246
247 bool m_needsRefresh:1; // repaint backing store?
248
249 // For double-click detection
250 long m_lastTS; // last timestamp
251 unsigned m_lastButton:2; // last pressed button
252
253 protected:
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;
262 int m_pixmapWidth;
263 int m_pixmapHeight;
264 int m_pixmapOffsetX;
265 int m_pixmapOffsetY;
266
267 // Store the last scroll pos, since in wxWin the pos isn't set
268 // automatically by system
269 int m_scrollPosX;
270 int m_scrollPosY;
271
272 // implement the base class pure virtuals
273 virtual void DoGetTextExtent(const wxString& string,
274 int *x, int *y,
275 int *descent = NULL,
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();
291
292 #if wxUSE_TOOLTIPS
293 virtual void DoSetToolTip( wxToolTip *tip );
294 #endif // wxUSE_TOOLTIPS
295
296 private:
297 // common part of all ctors
298 void Init();
299
300 DECLARE_DYNAMIC_CLASS(wxWindow)
301 wxDECLARE_NO_COPY_CLASS(wxWindow);
302 DECLARE_EVENT_TABLE()
303 };
304
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.
311 //
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
314 // from scope.
315 // ----------------------------------------------------------------------------
316
317 class WXDLLIMPEXP_CORE wxNoOptimize
318 {
319 public:
320 wxNoOptimize() { ms_count++; }
321 ~wxNoOptimize() { ms_count--; }
322
323 static bool CanOptimize() { return ms_count == 0; }
324
325 protected:
326 static int ms_count;
327 };
328
329 #endif // _WX_WINDOW_H_