1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxWindow class
4 // Author: David Webster
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
16 #pragma interface "window.h"
26 // ---------------------------------------------------------------------------
27 // forward declarations
28 // ---------------------------------------------------------------------------
30 class WXDLLEXPORT wxWindow
;
31 class WXDLLEXPORT wxButton
;
33 #if wxUSE_DRAG_AND_DROP
34 class WXDLLEXPORT wxDropTarget
;
37 #if wxUSE_WX_RESOURCES
38 class WXDLLEXPORT wxResourceTable
;
39 class WXDLLEXPORT wxItemResource
;
42 WXDLLEXPORT_DATA(extern const char*) wxPanelNameStr
;
44 WXDLLEXPORT_DATA(extern const wxSize
) wxDefaultSize
;
45 WXDLLEXPORT_DATA(extern const wxPoint
) wxDefaultPosition
;
47 class WXDLLEXPORT wxWindow
: public wxWindowBase
49 DECLARE_ABSTRACT_CLASS(wxWindow
)
52 friend class wxPaintDC
;
55 wxWindow() { Init(); };
56 inline wxWindow( wxWindow
* parent
58 ,const wxPoint
& pos
= wxDefaultPosition
59 ,const wxSize
& size
= wxDefaultSize
61 ,const wxString
& name
= wxPanelNameStr
65 Create(parent
, id
, pos
, size
, style
, name
);
70 bool Create( wxWindow
* parent
72 ,const wxPoint
& pos
= wxDefaultPosition
73 ,const wxSize
& size
= wxDefaultSize
75 ,const wxString
& name
= wxPanelNameStr
78 // ---------------------------------------------------------------------------
79 // wxWindowBase pure virtual implementations
80 // ---------------------------------------------------------------------------
85 // Set the focus to this window
86 virtual void SetFocus();
87 // Warp the pointer the given position
88 virtual void WarpPointer(int x_pos
, int y_pos
) ;
89 // Capture/release mouse
90 virtual void CaptureMouse();
91 virtual void ReleaseMouse();
92 // Send the window a refresh event
93 virtual void Refresh(bool eraseBack
= TRUE
, const wxRect
*rect
= NULL
);
97 virtual bool SetFont(const wxFont
& f
);
99 virtual int GetCharHeight() const;
100 virtual int GetCharWidth() const;
101 virtual void GetTextExtent( const wxString
& string
105 ,int* externalLeading
= NULL
106 ,const wxFont
* theFont
= NULL
109 // Configure the window's scrollbar
110 virtual void SetScrollbar( int orient
116 virtual void SetScrollPos( int orient
120 virtual int GetScrollPos(int orient
) const;
121 virtual int GetScrollRange(int orient
) const;
122 virtual int GetScrollThumb(int orient
) const;
123 virtual void ScrollWindow( int dx
125 ,const wxRect
* rect
= NULL
127 #if wxUSE_DRAG_AND_DROP
128 void SetDropTarget(wxDropTarget
*pDropTarget
);
130 // coordinates translation
131 virtual void DoClientToScreen( int *x
, int *y
) const;
132 virtual void DoScreenToClient( int *x
, int *y
) const;
134 // retrieve the position/size of the window
135 virtual void DoGetPosition( int *x
, int *y
) const;
136 virtual void DoGetSize( int *width
, int *height
) const;
137 virtual void DoGetClientSize( int *width
, int *height
) const;
139 // this is the virtual function to be overriden in any derived class which
140 // wants to change how SetSize() or Move() works - it is called by all
141 // versions of these functions in the base class
142 virtual void DoSetSize(int x
, int y
,
143 int width
, int height
,
144 int sizeFlags
= wxSIZE_AUTO
);
146 // same as DoSetSize() for the client size
147 virtual void DoSetClientSize(int width
, int height
);
148 virtual bool DoPopupMenu( wxMenu
*menu
, int x
, int y
);
150 // ---------------------------------------------------------------------------
151 // wxWindowBase virtual implementations that need to be overriden
152 // ---------------------------------------------------------------------------
154 // Fit the window around the items
156 // Show or hide the window
157 virtual bool Show(bool show
); // check if base implementation is OK
158 // Enable or disable the window
159 virtual bool Enable(bool enable
); // check if base implementation is OK
161 virtual bool SetCursor(const wxCursor
& cursor
); // check if base implementation is OK
163 // ---------------------------------------------------------------------------
164 // additional functions
165 // ---------------------------------------------------------------------------
167 // Dialog support: override these and call
168 // base class members to add functionality
169 // that can't be done using validators.
170 void SetClientSize( int width
, int height
)
171 { DoSetClientSize(width
, height
); }
173 void SetClientSize( const wxSize
& size
)
174 { DoSetClientSize(size
.x
, size
.y
); }
176 void SetClientSize(const wxRect
& rect
)
177 { SetClientSize( rect
.width
, rect
.height
); }
179 // Validate controls. If returns FALSE,
180 // validation failed: don't quit
181 virtual bool Validate();
183 // Return code for dialogs
184 inline void SetReturnCode(int retCode
);
185 inline int GetReturnCode();
188 // Get the window with the focus
189 static wxWindow
*FindFocus();
191 // Accept files for dragging
192 virtual void DragAcceptFiles(bool accept
);
194 // Most windows have the concept of a label; for frames, this is the
195 // title; for items, this is the label or button text.
196 inline virtual wxString
GetLabel() const { return GetTitle(); }
198 #if wxUSE_CARET && WXWIN_COMPATIBILITY
199 // Caret manipulation
200 virtual void CreateCaret(int w
, int h
);
201 virtual void CreateCaret(const wxBitmap
*bitmap
);
202 virtual void DestroyCaret();
203 virtual void ShowCaret(bool show
);
204 virtual void SetCaretPos(int x
, int y
);
205 virtual void GetCaretPos(int *x
, int *y
) const;
208 // Handle a control command
209 virtual void OnCommand(wxWindow
& win
, wxCommandEvent
& event
);
211 // Get the default button, if there is one
212 inline virtual wxButton
*GetDefaultItem() const;
213 inline virtual void SetDefaultItem(wxButton
*but
);
215 // Override to define new behaviour for default action (e.g. double clicking
217 virtual void OnDefaultAction(wxControl
*initiatingItem
);
220 void OnEraseBackground(wxEraseEvent
& event
);
221 void OnChar(wxKeyEvent
& event
);
222 void OnKeyDown(wxKeyEvent
& event
);
223 void OnKeyUp(wxKeyEvent
& event
);
224 void OnPaint(wxPaintEvent
& event
);
225 void OnIdle(wxIdleEvent
& event
);
229 WXHWND
GetHWND() const { return m_hWnd
; }
230 void SetHWND(WXHWND hWnd
) { m_hWnd
= hWnd
; }
231 virtual WXWidget
GetHandle() const { return GetHWND(); }
234 // ---------------------------------------------------------------------------
236 // ---------------------------------------------------------------------------
238 // For implementation purposes - sometimes decorations make the client area
240 virtual wxPoint
GetClientAreaOrigin() const;
242 // Makes an adjustment to the window position (for example, a frame that has
243 // a toolbar that it manages itself).
244 virtual void AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
);
246 // Windows subclassing
247 void SubclassWin(WXHWND hWnd
);
248 void UnsubclassWin();
250 WXFARPROC
OS2GetOldWndProc() const { return m_oldWndProc
; }
251 void OS2SetOldWndProc(WXFARPROC proc
) { m_oldWndProc
= proc
; }
253 wxWindow
*FindItem(long id
) const;
254 wxWindow
*FindItemByHWND(WXHWND hWnd
, bool controlOnly
= FALSE
) const;
256 // Determine whether 3D effects are wanted
257 WXDWORD
Determine3DEffects(WXDWORD defaultBorderStyle
, bool *want3D
) const;
259 // PM only: TRUE if this control is part of the main control
260 virtual bool ContainsHWND(WXHWND
WXUNUSED(hWnd
)) const { return FALSE
; };
262 // Executes the default message
263 virtual long Default();
265 // Constraint implementation
266 void UnsetConstraints(wxLayoutConstraints
*c
);
267 // Back-pointer to other windows we're involved with, so if we delete
268 // this window, we must delete any constraints we're involved with.
270 wxObject
*GetChild(int number
) const ;
272 // Transfers data to any child controls
273 void OnInitDialog(wxInitDialogEvent
& event
);
275 virtual MRESULT
OS2WindowProc(HWND hwnd
, WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
);
286 wxButton
* m_defaultItem
;
289 WXFARPROC m_oldWndProc
;
291 bool m_isBeingDeleted
;
294 bool m_mouseInWindow
;
295 bool m_backgroundTransparent
;
298 WXHMENU m_hMenu
; // Menu, if any
300 // the size of one page for scrolling
305 DECLARE_EVENT_TABLE()
308 void PMDetachWindowMenu();
311 ////////////////////////////////////////////////////////////////////////
314 inline wxButton
*wxWindow::GetDefaultItem() const { return m_defaultItem
; }
315 inline void wxWindow::SetDefaultItem(wxButton
*but
) { m_defaultItem
= but
; }
316 inline void wxWindow::SetReturnCode(int retCode
) { m_returnCode
= retCode
; }
317 inline int wxWindow::GetReturnCode() { return m_returnCode
; }
319 // Get the active window.
320 wxWindow
* WXDLLEXPORT
wxGetActiveWindow();