]> git.saurik.com Git - wxWidgets.git/blame - include/wx/motif/window.h
Updated Italian translations
[wxWidgets.git] / include / wx / motif / window.h
CommitLineData
9b6dbb09
JS
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
34636400 9// Licence: wxWindows licence
9b6dbb09
JS
10/////////////////////////////////////////////////////////////////////////////
11
12#ifndef _WX_WINDOW_H_
13#define _WX_WINDOW_H_
14
15#ifdef __GNUG__
34636400 16 #pragma interface "window.h"
9b6dbb09
JS
17#endif
18
25f47127 19#include "wx/region.h"
af0bb3b1 20
34636400
VZ
21// ----------------------------------------------------------------------------
22// wxWindow class for Motif - see also wxWindowBase
23// ----------------------------------------------------------------------------
9b6dbb09 24
34636400 25class wxWindow : public wxWindowBase
9b6dbb09 26{
34636400
VZ
27friend class WXDLLEXPORT wxDC;
28friend class WXDLLEXPORT wxWindowDC;
9b6dbb09
JS
29
30public:
34636400
VZ
31 wxWindow() { Init(); }
32
33 wxWindow(wxWindow *parent,
c4ea2971
GD
34 wxWindowID id,
35 const wxPoint& pos = wxDefaultPosition,
36 const wxSize& size = wxDefaultSize,
37 long style = 0,
38 const wxString& name = wxPanelNameStr)
bfc6fde4 39 {
34636400 40 Init();
bfc6fde4
VZ
41 Create(parent, id, pos, size, style, name);
42 }
43
44 virtual ~wxWindow();
45
34636400
VZ
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);
bfc6fde4 52
34636400
VZ
53 // implement base class pure virtuals
54 virtual void SetTitle( const wxString& title);
55 virtual wxString GetTitle() const;
bfc6fde4 56
bfc6fde4 57 virtual void Raise();
bfc6fde4
VZ
58 virtual void Lower();
59
34636400
VZ
60 virtual bool Show( bool show = TRUE );
61 virtual bool Enable( bool enable = TRUE );
bfc6fde4 62
34636400 63 virtual void SetFocus();
bfc6fde4 64
34636400
VZ
65 virtual void WarpPointer(int x, int y);
66 virtual void CaptureMouse();
67 virtual void ReleaseMouse();
bfc6fde4 68
34636400
VZ
69 virtual void Refresh( bool eraseBackground = TRUE,
70 const wxRect *rect = (const wxRect *) NULL );
71 virtual void Clear();
bfc6fde4 72
af0bb3b1
VZ
73 virtual bool SetBackgroundColour( const wxColour &colour );
74 virtual bool SetForegroundColour( const wxColour &colour );
75
34636400
VZ
76 virtual bool SetCursor( const wxCursor &cursor );
77 virtual bool SetFont( const wxFont &font );
bfc6fde4 78
bfc6fde4
VZ
79 virtual int GetCharHeight() const;
80 virtual int GetCharWidth() const;
34636400
VZ
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
34636400
VZ
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 );
9b6dbb09 96
af0bb3b1 97 virtual void SetSizeHints(int minW, int minH,
d75638f8
RR
98 int maxW = -1, int maxH = -1,
99 int incW = -1, int incH = -1);
47d67540 100#if wxUSE_DRAG_AND_DROP
34636400
VZ
101 virtual void SetDropTarget( wxDropTarget *dropTarget );
102#endif // wxUSE_DRAG_AND_DROP
9b6dbb09 103
bfc6fde4
VZ
104 // Accept files for dragging
105 virtual void DragAcceptFiles(bool accept);
9b6dbb09 106
af0bb3b1
VZ
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
dfe1eee3
VZ
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
bfc6fde4
VZ
172 // For implementation purposes - sometimes decorations make the client area
173 // smaller
174 virtual wxPoint GetClientAreaOrigin() const;
175
d6eaea28
VS
176protected:
177 // event handlers (not virtual by design)
178 void OnIdle(wxIdleEvent& event);
179
bfc6fde4
VZ
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
34636400
VZ
184 wxWindow *GetChild(int number) const
185 { return GetChildren().Item(number)->GetData(); }
bfc6fde4
VZ
186
187 // Responds to colour changes: passes event on to children.
188 void OnSysColourChanged(wxSysColourChangedEvent& event);
189
34636400 190 // Motif-specific
bfc6fde4 191
34636400 192 // CanvasXXXSiize functions
bfc6fde4
VZ
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
34636400
VZ
199 void SetMainWidget(WXWidget w) { m_mainWidget = w; }
200
bfc6fde4
VZ
201 bool CanAddEventHandler() const { return m_canAddEventHandler; }
202 void SetCanAddEventHandler(bool flag) { m_canAddEventHandler = flag; }
203
9806a47c 204public:
34636400 205 WXPixmap GetBackingPixmap() const { return m_backingPixmap; }
9806a47c 206 void SetBackingPixmap(WXPixmap pixmap) { m_backingPixmap = pixmap; }
bfc6fde4
VZ
207 int GetPixmapWidth() const { return m_pixmapWidth; }
208 int GetPixmapHeight() const { return m_pixmapHeight; }
9806a47c
JS
209 void SetPixmapWidth(int w) { m_pixmapWidth = w; }
210 void SetPixmapHeight(int h) { m_pixmapHeight = h; }
bfc6fde4
VZ
211
212 // Change properties
213 virtual void ChangeFont(bool keepOriginalSize = TRUE); // Change to the current font (often overridden)
34636400
VZ
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();
bfc6fde4 220
da175b2c 221protected:
bfc6fde4 222 // Adds the widget to the hash table and adds event handlers.
34636400
VZ
223 bool AttachWidget(wxWindow* parent, WXWidget mainWidget,
224 WXWidget formWidget, int x, int y, int width, int height);
bfc6fde4
VZ
225 bool DetachWidget(WXWidget widget);
226
34636400
VZ
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
bfc6fde4
VZ
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,
34636400
VZ
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
bfc6fde4 238 // event and send it.
d75638f8 239public:
bfc6fde4 240 virtual bool ProcessAccelerator(wxKeyEvent& event);
d75638f8
RR
241
242protected:
34636400
VZ
243 // unmanage and destroy an X widget f it's !NULL (passing NULL is ok)
244 void UnmanageAndDestroy(WXWidget widget);
9b6dbb09 245
34636400
VZ
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);
9b6dbb09 249
af0bb3b1
VZ
250 // scrolling stuff
251 // ---------------
252
253 // create/destroy window scrollbars
254 void CreateScrollbar(wxOrientation orientation);
255 void DestroyScrollbar(wxOrientation orientation);
256
34636400
VZ
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
af0bb3b1
VZ
271 // --------------------
272
34636400
VZ
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;
9b6dbb09 278
bfc6fde4 279 // For double-click detection
34636400
VZ
280 long m_lastTS; // last timestamp
281 int m_lastButton; // last pressed button
af0bb3b1
VZ
282
283 // List of wxRects representing damaged region
284 wxRectList m_updateRects;
34636400 285
9b6dbb09 286protected:
bfc6fde4
VZ
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;
bfc6fde4 301
34636400
VZ
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;
bfc6fde4
VZ
313 virtual void DoSetSize(int x, int y,
314 int width, int height,
315 int sizeFlags = wxSIZE_AUTO);
bfc6fde4 316 virtual void DoSetClientSize(int width, int height);
9d9b7755 317 virtual void DoMoveWindow(int x, int y, int width, int height);
ee31c392 318 virtual bool DoPopupMenu(wxMenu *menu, int x, int y);
bfc6fde4 319
34636400
VZ
320#if wxUSE_TOOLTIPS
321 virtual void DoSetToolTip( wxToolTip *tip );
322#endif // wxUSE_TOOLTIPS
323
bfc6fde4 324private:
34636400
VZ
325 // common part of all ctors
326 void Init();
327
c4ea2971
GD
328 DECLARE_DYNAMIC_CLASS(wxWindow)
329 DECLARE_NO_COPY_CLASS(wxWindow)
bfc6fde4 330 DECLARE_EVENT_TABLE()
9b6dbb09
JS
331};
332
34636400 333// ----------------------------------------------------------------------------
af0bb3b1
VZ
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.
34636400 339//
af0bb3b1
VZ
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.
34636400 342// ----------------------------------------------------------------------------
af0bb3b1
VZ
343
344class WXDLLEXPORT wxNoOptimize
88150e60
JS
345{
346public:
af0bb3b1
VZ
347 wxNoOptimize() { ms_count++; }
348 ~wxNoOptimize() { ms_count--; }
88150e60 349
af0bb3b1 350 static bool CanOptimize() { return ms_count == 0; }
88150e60
JS
351
352protected:
af0bb3b1 353 static int ms_count;
88150e60
JS
354};
355
9b6dbb09
JS
356#endif
357 // _WX_WINDOW_H_