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 // ----------------------------------------------------------------------------
20 // wxWindow class for Motif - see also wxWindowBase
21 // ----------------------------------------------------------------------------
23 class wxWindow
: public wxWindowBase
25 DECLARE_DYNAMIC_CLASS(wxWindow
)
27 friend class WXDLLEXPORT wxDC
;
28 friend class WXDLLEXPORT wxWindowDC
;
31 wxWindow() { Init(); }
33 wxWindow(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
);
46 bool Create(wxWindow
*parent
,
48 const wxPoint
& pos
= wxDefaultPosition
,
49 const wxSize
& size
= wxDefaultSize
,
51 const wxString
& name
= wxPanelNameStr
);
53 // implement base class pure virtuals
54 virtual void SetTitle( const wxString
& title
);
55 virtual wxString
GetTitle() const;
60 virtual bool Show( bool show
= TRUE
);
61 virtual bool Enable( bool enable
= TRUE
);
63 virtual void SetFocus();
65 virtual void WarpPointer(int x
, int y
);
66 virtual void CaptureMouse();
67 virtual void ReleaseMouse();
69 virtual void Refresh( bool eraseBackground
= TRUE
,
70 const wxRect
*rect
= (const wxRect
*) NULL
);
73 virtual bool SetCursor( const wxCursor
&cursor
);
74 virtual bool SetFont( const wxFont
&font
);
76 virtual int GetCharHeight() const;
77 virtual int GetCharWidth() const;
78 virtual void GetTextExtent(const wxString
& string
,
80 int *descent
= (int *) NULL
,
81 int *externalLeading
= (int *) NULL
,
82 const wxFont
*theFont
= (const wxFont
*) NULL
)
85 virtual bool PopupMenu( wxMenu
*menu
, int x
, int y
);
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
);
96 #if wxUSE_DRAG_AND_DROP
97 virtual void SetDropTarget( wxDropTarget
*dropTarget
);
98 #endif // wxUSE_DRAG_AND_DROP
100 // Accept files for dragging
101 virtual void DragAcceptFiles(bool accept
);
104 // event handlers (not virtual by design)
105 void OnIdle(wxIdleEvent
& event
);
107 // For implementation purposes - sometimes decorations make the client area
109 virtual wxPoint
GetClientAreaOrigin() const;
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
);
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
119 wxWindow
*GetChild(int number
) const
120 { return GetChildren().Item(number
)->GetData(); }
122 // Responds to colour changes: passes event on to children.
123 void OnSysColourChanged(wxSysColourChangedEvent
& event
);
127 // empties the m_updateRects list
128 void ClearUpdateRects();
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
);
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
; }
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
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;
156 // base class pure virtual
157 virtual WXWidget
GetHandle() const { return GetMainWidget(); }
159 void SetMainWidget(WXWidget w
) { m_mainWidget
= w
; }
161 bool CanAddEventHandler() const { return m_canAddEventHandler
; }
162 void SetCanAddEventHandler(bool flag
) { m_canAddEventHandler
= flag
; }
164 // Get the underlying X window and display
165 WXWindow
GetXWindow() const;
166 WXDisplay
*GetXDisplay() const;
168 WXPixmap
GetBackingPixmap() const { return m_backingPixmap
; }
169 int GetPixmapWidth() const { return m_pixmapWidth
; }
170 int GetPixmapHeight() const { return m_pixmapHeight
; }
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
);
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();
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
);
188 // Generates a paint event
189 virtual void DoPaint();
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
);
206 // unmanage and destroy an X widget f it's !NULL (passing NULL is ok)
207 void UnmanageAndDestroy(WXWidget widget
);
209 // map or unmap an X widget (passing NULL is ok), returns TRUE if widget was
211 bool MapOrUnmap(WXWidget widget
, bool map
);
213 // get either hor or vert scrollbar widget
214 WXWidget
GetScrollbar(wxOrientation orient
) const
215 { return orient
== wxHORIZONTAL
? m_hScrollBar
: m_vScrollBar
; }
217 // set the scroll pos
218 void SetInternalScrollPos(wxOrientation orient
, int pos
)
220 if ( orient
== wxHORIZONTAL
)
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;
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
239 WXWidget m_mainWidget
;
240 WXWidget m_hScrollBar
;
241 WXWidget m_vScrollBar
;
242 WXWidget m_borderWidget
;
243 WXWidget m_scrolledWindow
;
244 WXWidget m_drawingArea
;
248 WXPixmap m_backingPixmap
;
254 // Store the last scroll pos, since in wxWin the pos isn't set automatically
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
);
271 virtual void DoSetToolTip( wxToolTip
*tip
);
272 #endif // wxUSE_TOOLTIPS
275 // common part of all ctors
278 DECLARE_NO_COPY_CLASS(wxWindow
);
279 DECLARE_EVENT_TABLE()
282 // ----------------------------------------------------------------------------
283 // A little class to switch off size optimization while an instance of the object
286 // TODO what is it for??
287 // ----------------------------------------------------------------------------
288 class WXDLLEXPORT wxNoOptimize
: public wxObject
294 static bool CanOptimize();