1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxWindow class
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
16 #pragma interface "window.h"
19 // ---------------------------------------------------------------------------
20 // forward declarations
21 // ---------------------------------------------------------------------------
23 class WXDLLEXPORT wxButton
;
25 // ---------------------------------------------------------------------------
27 // ---------------------------------------------------------------------------
29 // FIXME does anybody use those? they're unused by wxWindows...
36 class WXDLLEXPORT wxWindow
: public wxWindowBase
38 DECLARE_DYNAMIC_CLASS(wxWindow
);
41 friend class wxPaintDC
;
44 typedef struct MacWindowData
46 SInt16 m_macWindowBackgroundTheme
;
47 WindowRef m_macWindow
;
48 ControlHandle m_macRootControl
;
49 wxWindow
* m_macFocus
;
53 wxWindow() { Init(); }
55 wxWindow(wxWindow
*parent
,
57 const wxPoint
& pos
= wxDefaultPosition
,
58 const wxSize
& size
= wxDefaultSize
,
60 const wxString
& name
= wxPanelNameStr
)
63 Create(parent
, id
, pos
, size
, style
, name
);
68 bool Create(wxWindow
*parent
,
70 const wxPoint
& pos
= wxDefaultPosition
,
71 const wxSize
& size
= wxDefaultSize
,
73 const wxString
& name
= wxPanelNameStr
);
76 // implement base class pure virtuals
77 virtual void SetTitle( const wxString
& title
);
78 virtual wxString
GetTitle() const;
83 virtual bool Show( bool show
= TRUE
);
84 virtual bool Enable( bool enable
= TRUE
);
86 virtual void SetFocus();
88 virtual bool Reparent( wxWindow
*newParent
);
90 virtual void WarpPointer(int x
, int y
);
91 virtual void CaptureMouse();
92 virtual void ReleaseMouse();
94 virtual void Refresh( bool eraseBackground
= TRUE
,
95 const wxRect
*rect
= (const wxRect
*) NULL
);
98 virtual bool SetCursor( const wxCursor
&cursor
);
99 virtual bool SetFont( const wxFont
&font
);
101 virtual int GetCharHeight() const;
102 virtual int GetCharWidth() const;
103 virtual void GetTextExtent(const wxString
& string
,
105 int *descent
= (int *) NULL
,
106 int *externalLeading
= (int *) NULL
,
107 const wxFont
*theFont
= (const wxFont
*) NULL
)
110 virtual bool DoPopupMenu( wxMenu
*menu
, int x
, int y
);
112 virtual void SetScrollbar( int orient
, int pos
, int thumbVisible
,
113 int range
, bool refresh
= TRUE
);
114 virtual void SetScrollPos( int orient
, int pos
, bool refresh
= TRUE
);
115 virtual int GetScrollPos( int orient
) const;
116 virtual int GetScrollThumb( int orient
) const;
117 virtual int GetScrollRange( int orient
) const;
118 virtual void ScrollWindow( int dx
, int dy
,
119 const wxRect
* rect
= (wxRect
*) NULL
);
121 #if wxUSE_DRAG_AND_DROP
122 virtual void SetDropTarget( wxDropTarget
*dropTarget
);
123 #endif // wxUSE_DRAG_AND_DROP
125 // Accept files for dragging
126 virtual void DragAcceptFiles(bool accept
);
128 #if WXWIN_COMPATIBILITY
129 // Set/get scroll attributes
130 virtual void SetScrollRange(int orient
, int range
, bool refresh
= TRUE
);
131 virtual void SetScrollPage(int orient
, int page
, bool refresh
= TRUE
);
132 virtual int OldGetScrollRange(int orient
) const;
133 virtual int GetScrollPage(int orient
) const;
136 // Handle a control command
137 virtual void OnCommand(wxWindow
& win
, wxCommandEvent
& event
);
139 // Override to define new behaviour for default action (e.g. double
140 // clicking on a listbox)
141 virtual void OnDefaultAction(wxControl
* WXUNUSED(initiatingItem
)) { }
142 #endif // WXWIN_COMPATIBILITY
144 #if wxUSE_CARET && WXWIN_COMPATIBILITY
145 // caret manipulation (old MSW only functions, see wxCaret class for the
147 void CreateCaret(int w
, int h
);
148 void CreateCaret(const wxBitmap
*bitmap
);
150 void ShowCaret(bool show
);
151 void SetCaretPos(int x
, int y
);
152 void GetCaretPos(int *x
, int *y
) const;
153 #endif // wxUSE_CARET
155 // Native resource loading (implemented in src/msw/nativdlg.cpp)
156 // FIXME: should they really be all virtual?
157 virtual bool LoadNativeDialog(wxWindow
* parent
, wxWindowID
& id
);
158 virtual bool LoadNativeDialog(wxWindow
* parent
, const wxString
& name
);
159 wxWindow
* GetWindowChild1(wxWindowID id
);
160 wxWindow
* GetWindowChild(wxWindowID id
);
162 // implementation from now on
163 // --------------------------
165 void MacClientToRootWindow( int *x
, int *y
) const ;
166 void MacRootWindowToClient( int *x
, int *y
) const ;
172 WXHWND
GetHWND() const { return m_hWnd
; }
173 void SetHWND(WXHWND hWnd
) { m_hWnd
= hWnd
; }
174 virtual WXWidget
GetHandle() const { return (WXWidget
) GetHWND(); }
176 bool GetUseCtl3D() const { return m_useCtl3D
; }
177 bool GetTransparentBackground() const { return m_backgroundTransparent
; }
178 void SetTransparent(bool t
= TRUE
) { m_backgroundTransparent
= t
; }
182 void OnEraseBackground(wxEraseEvent
& event
);
183 void OnIdle(wxIdleEvent
& event
);
186 // For implementation purposes - sometimes decorations make the client area
188 virtual wxPoint
GetClientAreaOrigin() const;
190 // Makes an adjustment to the window position (for example, a frame that has
191 // a toolbar that it manages itself).
192 virtual void AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
);
194 wxWindow
*FindItem(long id
) const;
195 wxWindow
*FindItemByHWND(WXHWND hWnd
, bool controlOnly
= FALSE
) const;
197 // Make a Windows extended style from the given wxWindows window style
198 static WXDWORD
MakeExtendedStyle(long style
,
199 bool eliminateBorders
= TRUE
);
200 // Determine whether 3D effects are wanted
201 WXDWORD
Determine3DEffects(WXDWORD defaultBorderStyle
, bool *want3D
) const;
203 // MSW only: TRUE if this control is part of the main control
204 virtual bool ContainsHWND(WXHWND
WXUNUSED(hWnd
)) const { return FALSE
; };
206 #if WXWIN_COMPATIBILITY
207 wxObject
*GetChild(int number
) const;
208 virtual void MSWDeviceToLogical(float *x
, float *y
) const;
209 #endif // WXWIN_COMPATIBILITY
211 // Create an appropriate wxWindow from a HWND
212 virtual wxWindow
* CreateWindowFromHWND(wxWindow
* parent
, WXHWND hWnd
);
214 // Make sure the window style reflects the HWND style (roughly)
215 virtual void AdoptAttributesFromHWND();
217 // Setup background and foreground colours correctly
218 virtual void SetupColours();
221 #if WXWIN_COMPATIBILITY
222 void SetShowing(bool show
) { (void)Show(show
); }
223 bool IsUserEnabled() const { return IsEnabled(); }
224 #endif // WXWIN_COMPATIBILITY
226 // Responds to colour changes: passes event on to children.
227 void OnSysColourChanged(wxSysColourChangedEvent
& event
);
233 // the old window proc (we subclass all windows)
234 WXFARPROC m_oldWndProc
;
236 // additional (MSW specific) flags
237 bool m_useCtl3D
:1; // Using CTL3D for this control
238 bool m_backgroundTransparent
:1;
239 bool m_mouseInWindow
:1;
240 bool m_doubleClickAllowed
:1;
241 bool m_winCaptured
:1;
243 // the size of one page for scrolling
247 WXHMENU m_hMenu
; // Menu, if any
249 // the return value of WM_GETDLGCODE handler
252 // implement the base class pure virtuals
253 virtual void DoClientToScreen( int *x
, int *y
) const;
254 virtual void DoScreenToClient( int *x
, int *y
) const;
255 virtual void DoGetPosition( int *x
, int *y
) const;
256 virtual void DoGetSize( int *width
, int *height
) const;
257 virtual void DoGetClientSize( int *width
, int *height
) const;
258 virtual void DoSetSize(int x
, int y
,
259 int width
, int height
,
260 int sizeFlags
= wxSIZE_AUTO
);
261 virtual void DoSetClientSize(int width
, int height
);
263 // get the size which best suits the window: e.g., for a static text it
264 // will be the width and height of the text
265 virtual wxSize
DoGetBestSize();
267 // move the window to the specified location and resize it: this is called
268 // from both DoSetSize() and DoSetClientSize() and would usually just call
269 // ::MoveWindow() except for composite controls which will want to arrange
270 // themselves inside the given rectangle
271 virtual void DoMoveWindow(int x
, int y
, int width
, int height
);
274 virtual void DoSetToolTip( wxToolTip
*tip
);
275 #endif // wxUSE_TOOLTIPS
278 // common part of all ctors
281 DECLARE_NO_COPY_CLASS(wxWindow
);
282 DECLARE_EVENT_TABLE()
285 // associate mac windows with wx counterparts
287 wxWindow
* wxFindWinFromMacWindow( WindowRef inWindow
) ;
288 void wxAssociateWinWithMacWindow(WindowRef inWindow
, wxWindow
*win
) ;
289 void wxRemoveMacWindowAssociation(wxWindow
*win
) ;
291 class wxMacFocusHelper
294 wxMacFocusHelper( wxWindow
* theWindow
) ;
295 ~wxMacFocusHelper() ;
296 bool Ok() { return m_ok
; }
299 GrafPtr m_formerPort
;
300 GrafPtr m_currentPort
;
304 class wxMacDrawingHelper
307 wxMacDrawingHelper( wxWindow
* theWindow
) ;
308 ~wxMacDrawingHelper() ;
309 bool Ok() { return m_ok
; }
312 GrafPtr m_formerPort
;
313 GrafPtr m_currentPort
;
314 PenState m_savedPenState
;
318 class wxMacFocusClientHelper
321 wxMacFocusClientHelper( wxWindow
* theWindow
) ;
322 ~wxMacFocusClientHelper() ;
323 bool Ok() { return m_ok
; }
326 GrafPtr m_formerPort
;
327 GrafPtr m_currentPort
;
331 class wxMacDrawingClientHelper
334 wxMacDrawingClientHelper( wxWindow
* theWindow
) ;
335 ~wxMacDrawingClientHelper() ;
336 bool Ok() { return m_ok
; }
339 GrafPtr m_formerPort
;
340 GrafPtr m_currentPort
;
341 PenState m_savedPenState
;