]> git.saurik.com Git - wxWidgets.git/blame - include/wx/msw/window.h
* prgodlgg.h: Update() use wxString instead of 'char *'
[wxWidgets.git] / include / wx / msw / window.h
CommitLineData
2bda0e17
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: window.h
3// Purpose: wxWindow class
4// Author: Julian Smart
5// Modified by:
6// Created: 01/02/97
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart and Markus Holzem
cc2b7472 9// Licence: wxWindows licence
2bda0e17
KB
10/////////////////////////////////////////////////////////////////////////////
11
bbcdf8bc
JS
12#ifndef _WX_WINDOW_H_
13#define _WX_WINDOW_H_
2bda0e17 14
cc2b7472
VZ
15// ---------------------------------------------------------------------------
16// headers
17// ---------------------------------------------------------------------------
18
2bda0e17 19#ifdef __GNUG__
cc2b7472 20 #pragma interface "window.h"
2bda0e17
KB
21#endif
22
cc2b7472
VZ
23// windows.h #defines the following identifiers which are also used in wxWin
24#ifdef GetCharWidth
25 #undef GetCharWidth
2bda0e17
KB
26#endif
27
cc2b7472
VZ
28#ifdef FindWindow
29 #undef FindWindow
2bda0e17
KB
30#endif
31
a23fd0e1
VZ
32// VZ: apparently some version of Windows send extra mouse move messages after
33// a mouse click. My tests under NT 4.0 and 95 didn't show it so I'm
34// tempted to think that it was just an effect of a poor mouse and so the
35// code to work around this is currently disabled - just define this as 1
36// to reenable it
37#define wxUSE_MOUSEEVENT_HACK 0
38
cc2b7472
VZ
39// ---------------------------------------------------------------------------
40// forward declarations
41// ---------------------------------------------------------------------------
2bda0e17 42
cc2b7472 43class WXDLLEXPORT wxButton;
2bda0e17 44
cc2b7472
VZ
45// ---------------------------------------------------------------------------
46// constants
47// ---------------------------------------------------------------------------
1e6d9499 48
cc2b7472
VZ
49// FIXME does anybody use those? they're unused by wxWindows...
50enum
1e6d9499 51{
cc2b7472
VZ
52 wxKEY_SHIFT = 1,
53 wxKEY_CTRL = 2
1e6d9499
JS
54};
55
cc2b7472
VZ
56// ---------------------------------------------------------------------------
57// wxWindow declaration for MSW
58// ---------------------------------------------------------------------------
59class WXDLLEXPORT wxWindow : public wxWindowBase
1e6d9499 60{
cc2b7472 61 DECLARE_DYNAMIC_CLASS(wxWindow);
2bda0e17
KB
62
63public:
cc2b7472
VZ
64 wxWindow() { Init(); }
65
66 wxWindow(wxWindow *parent,
67 wxWindowID id,
68 const wxPoint& pos = wxDefaultPosition,
69 const wxSize& size = wxDefaultSize,
70 long style = 0,
71 const wxString& name = wxPanelNameStr)
bfc6fde4
VZ
72 {
73 Init();
74 Create(parent, id, pos, size, style, name);
75 }
2bda0e17 76
bfc6fde4 77 virtual ~wxWindow();
2bda0e17 78
cc2b7472
VZ
79 bool Create(wxWindow *parent,
80 wxWindowID id,
81 const wxPoint& pos = wxDefaultPosition,
82 const wxSize& size = wxDefaultSize,
83 long style = 0,
84 const wxString& name = wxPanelNameStr);
bfc6fde4 85
cc2b7472 86 // implement base class pure virtuals
bfc6fde4 87 virtual void Raise();
bfc6fde4
VZ
88 virtual void Lower();
89
cc2b7472
VZ
90 virtual bool Show( bool show = TRUE );
91 virtual bool Enable( bool enable = TRUE );
bfc6fde4 92
cc2b7472 93 virtual void SetFocus();
bfc6fde4 94
cc2b7472 95 virtual bool Reparent( wxWindow *newParent );
bfc6fde4 96
cc2b7472
VZ
97 virtual void WarpPointer(int x, int y);
98 virtual void CaptureMouse();
99 virtual void ReleaseMouse();
bfc6fde4 100
cc2b7472
VZ
101 virtual void Refresh( bool eraseBackground = TRUE,
102 const wxRect *rect = (const wxRect *) NULL );
103 virtual void Clear();
bfc6fde4 104
cc2b7472
VZ
105 virtual bool SetCursor( const wxCursor &cursor );
106 virtual bool SetFont( const wxFont &font );
bfc6fde4 107
bfc6fde4
VZ
108 virtual int GetCharHeight() const;
109 virtual int GetCharWidth() const;
cc2b7472
VZ
110 virtual void GetTextExtent(const wxString& string,
111 int *x, int *y,
112 int *descent = (int *) NULL,
113 int *externalLeading = (int *) NULL,
114 const wxFont *theFont = (const wxFont *) NULL)
115 const;
116
117 virtual void ClientToScreen( int *x, int *y ) const;
118 virtual void ScreenToClient( int *x, int *y ) const;
7af6f327
RD
119 wxPoint ClientToScreen(const wxPoint& pt) const
120 { int x = pt.x; int y = pt.y; ClientToScreen(& x, & y); return wxPoint(x, y); }
121 wxPoint ScreenToClient(const wxPoint& pt) const
122 { int x = pt.x; int y = pt.y; ScreenToClient(& x, & y); return wxPoint(x, y); }
cc2b7472
VZ
123
124 virtual bool PopupMenu( wxMenu *menu, int x, int y );
125
126 virtual void SetScrollbar( int orient, int pos, int thumbVisible,
127 int range, bool refresh = TRUE );
128 virtual void SetScrollPos( int orient, int pos, bool refresh = TRUE );
129 virtual int GetScrollPos( int orient ) const;
130 virtual int GetScrollThumb( int orient ) const;
131 virtual int GetScrollRange( int orient ) const;
132 virtual void ScrollWindow( int dx, int dy,
133 const wxRect* rect = (wxRect *) NULL );
2bda0e17 134
47d67540 135#if wxUSE_DRAG_AND_DROP
cc2b7472
VZ
136 virtual void SetDropTarget( wxDropTarget *dropTarget );
137#endif // wxUSE_DRAG_AND_DROP
9f3362c4 138
bfc6fde4
VZ
139 // Accept files for dragging
140 virtual void DragAcceptFiles(bool accept);
2bda0e17 141
2bda0e17 142#if WXWIN_COMPATIBILITY
bfc6fde4
VZ
143 // Set/get scroll attributes
144 virtual void SetScrollRange(int orient, int range, bool refresh = TRUE);
145 virtual void SetScrollPage(int orient, int page, bool refresh = TRUE);
146 virtual int OldGetScrollRange(int orient) const;
147 virtual int GetScrollPage(int orient) const;
cc2b7472 148#endif // WXWIN_COMPATIBILITY
bfc6fde4 149
cc2b7472 150 // caret manipulation (MSW only)
bfc6fde4
VZ
151 virtual void CreateCaret(int w, int h);
152 virtual void CreateCaret(const wxBitmap *bitmap);
153 virtual void DestroyCaret();
154 virtual void ShowCaret(bool show);
155 virtual void SetCaretPos(int x, int y);
156 virtual void GetCaretPos(int *x, int *y) const;
157
cc2b7472
VZ
158 // event handlers (FIXME: shouldn't they be inside WXWIN_COMPATIBILITY?)
159 // Handle a control command
bfc6fde4
VZ
160 virtual void OnCommand(wxWindow& win, wxCommandEvent& event);
161
cc2b7472
VZ
162 // Override to define new behaviour for default action (e.g. double
163 // clicking on a listbox)
bfc6fde4
VZ
164 virtual void OnDefaultAction(wxControl *initiatingItem);
165
cc2b7472
VZ
166 // Native resource loading (implemented in src/msw/nativdlg.cpp)
167 // FIXME: should they really be all virtual?
bfc6fde4
VZ
168 virtual bool LoadNativeDialog(wxWindow* parent, wxWindowID& id);
169 virtual bool LoadNativeDialog(wxWindow* parent, const wxString& name);
cc2b7472
VZ
170 virtual wxWindow* GetWindowChild1(wxWindowID id);
171 virtual wxWindow* GetWindowChild(wxWindowID id);
2bda0e17 172
cc2b7472
VZ
173 // implementation from now on
174 // --------------------------
2bda0e17 175
cc2b7472
VZ
176 // simple accessors
177 // ----------------
2bda0e17 178
d7c24517
VZ
179 WXHWND GetHWND() const { return m_hWnd; }
180 void SetHWND(WXHWND hWnd) { m_hWnd = hWnd; }
181 virtual WXWidget GetHandle() const { return GetHWND(); }
2bda0e17 182
cc2b7472
VZ
183 bool GetUseCtl3D() const { return m_useCtl3D; }
184 bool GetTransparentBackground() const { return m_backgroundTransparent; }
185 void SetTransparent(bool t = TRUE) { m_backgroundTransparent = t; }
2bda0e17 186
cc2b7472
VZ
187 // event handlers
188 // --------------
bfc6fde4 189 void OnEraseBackground(wxEraseEvent& event);
bfc6fde4 190 void OnIdle(wxIdleEvent& event);
2bda0e17 191
cc2b7472
VZ
192 // a window may have a default button
193 // TODO move into wxPanel and/or wxFrame
194 wxButton *GetDefaultItem() const { return m_btnDefault; }
195 void SetDefaultItem(wxButton *btn) { m_btnDefault = btn; }
52476186 196
2bda0e17 197public:
bfc6fde4
VZ
198 // For implementation purposes - sometimes decorations make the client area
199 // smaller
200 virtual wxPoint GetClientAreaOrigin() const;
201
202 // Makes an adjustment to the window position (for example, a frame that has
203 // a toolbar that it manages itself).
204 virtual void AdjustForParentClientOrigin(int& x, int& y, int sizeFlags);
205
206 // Windows subclassing
207 void SubclassWin(WXHWND hWnd);
208 void UnsubclassWin();
bfc6fde4
VZ
209 virtual bool MSWCommand(WXUINT param, WXWORD id);
210
a23fd0e1
VZ
211 WXFARPROC MSWGetOldWndProc() const { return m_oldWndProc; }
212 void MSWSetOldWndProc(WXFARPROC proc) { m_oldWndProc = proc; }
bfc6fde4
VZ
213
214 virtual wxWindow *FindItem(int id) const;
215 virtual wxWindow *FindItemByHWND(WXHWND hWnd, bool controlOnly = FALSE) const ;
216 virtual void PreDelete(WXHDC dc); // Allows system cleanup
bfc6fde4
VZ
217
218 // Make a Windows extended style from the given wxWindows window style
219 virtual WXDWORD MakeExtendedStyle(long style, bool eliminateBorders = TRUE);
220 // Determine whether 3D effects are wanted
221 virtual WXDWORD Determine3DEffects(WXDWORD defaultBorderStyle, bool *want3D);
222
bfc6fde4
VZ
223 // MSW only: TRUE if this control is part of the main control
224 virtual bool ContainsHWND(WXHWND WXUNUSED(hWnd)) const { return FALSE; };
225
bfc6fde4
VZ
226 wxObject *GetChild(int number) const ;
227
a23fd0e1
VZ
228 // returns TRUE if the window has been created
229 bool MSWCreate(int id,
230 wxWindow *parent,
231 const char *wclass,
232 wxWindow *wx_win,
233 const char *title,
234 int x, int y, int width, int height,
235 WXDWORD style,
236 const char *dialog_template = NULL,
237 WXDWORD exendedStyle = 0);
bfc6fde4
VZ
238
239 // Actually defined in wx_canvs.cc since requires wxCanvas declaration
240 virtual void MSWDeviceToLogical(float *x, float *y) const ;
241
242 // Create an appropriate wxWindow from a HWND
243 virtual wxWindow* CreateWindowFromHWND(wxWindow* parent, WXHWND hWnd);
244
245 // Make sure the window style reflects the HWND style (roughly)
246 virtual void AdoptAttributesFromHWND();
247
248 // Setup background and foreground colours correctly
249 virtual void SetupColours();
250
a23fd0e1
VZ
251 // ------------------------------------------------------------------------
252 // internal handlers for MSW messages: all handlers return a boolen value:
253 // TRUE means that the handler processed the event and FALSE that it didn't
254 // ------------------------------------------------------------------------
bfc6fde4 255
a23fd0e1
VZ
256 // TODO: all this should go away, overriding MSWWindowProc() is enough to
257 // implement this functionality
258 virtual bool MSWOnCreate(WXLPCREATESTRUCT cs, bool *mayCreate);
bfc6fde4 259 virtual bool MSWOnPaint();
bfc6fde4 260 virtual bool MSWOnEraseBkgnd(WXHDC pDC);
a23fd0e1
VZ
261 virtual bool MSWOnSize(int x, int y, WXUINT flag);
262
263 virtual bool MSWOnQueryDragIcon(WXHICON *hIcon);
264 virtual bool MSWOnWindowPosChanging(void *lpPos);
265
266 // both horizontal and vertical
267 virtual bool MSWOnScroll(int orientation, WXWORD nSBCode,
268 WXWORD pos, WXHWND control);
269
270 virtual bool MSWOnCommand(WXWORD id, WXWORD cmd, WXHWND control);
271 virtual bool MSWOnSysCommand(WXWPARAM wParam, WXLPARAM lParam);
272
273#ifdef __WIN95__
274 virtual bool MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result);
275#endif // __WIN95__
276
277 virtual bool MSWOnCtlColor(WXHBRUSH *hBrush,
278 WXHDC hdc,
279 WXHWND hWnd,
280 WXUINT nCtlColor,
281 WXUINT message,
282 WXWPARAM wParam,
283 WXLPARAM lParam);
284
285 virtual bool MSWOnPaletteChanged(WXHWND hWndPalChange);
286 virtual bool MSWOnQueryNewPalette();
287
288 virtual bool MSWOnQueryEndSession(long logOff, bool *mayEnd);
bfc6fde4 289 virtual bool MSWOnEndSession(bool endSession, long logOff);
a23fd0e1 290
bfc6fde4
VZ
291 virtual bool MSWOnDestroy();
292 virtual bool MSWOnSetFocus(WXHWND wnd);
293 virtual bool MSWOnKillFocus(WXHWND wnd);
a23fd0e1 294 virtual bool MSWOnDropFiles(WXWPARAM wParam);
bfc6fde4 295 virtual bool MSWOnInitDialog(WXHWND hWndFocus);
a23fd0e1 296 virtual bool MSWOnShow(bool show, int status);
bfc6fde4 297
a23fd0e1
VZ
298 virtual bool MSWOnMouseEvent(WXUINT msg, int x, int y, WXUINT flags);
299 virtual bool MSWOnMouseMove(int x, int y, WXUINT flags);
bfc6fde4 300
bfc6fde4 301 virtual bool MSWOnChar(WXWORD wParam, WXLPARAM lParam, bool isASCII = FALSE);
4d91c1d1
VZ
302 virtual bool MSWOnKeyDown(WXWORD wParam, WXLPARAM lParam);
303 virtual bool MSWOnKeyUp(WXWORD wParam, WXLPARAM lParam);
bfc6fde4
VZ
304
305 virtual bool MSWOnActivate(int flag, bool minimized, WXHWND activate);
a23fd0e1 306 virtual bool MSWOnMDIActivate(long flag, WXHWND activate, WXHWND deactivate);
bfc6fde4
VZ
307
308 virtual bool MSWOnDrawItem(int id, WXDRAWITEMSTRUCT *item);
309 virtual bool MSWOnMeasureItem(int id, WXMEASUREITEMSTRUCT *item);
310
bfc6fde4
VZ
311 // Window procedure
312 virtual long MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
313
314 // Calls an appropriate default window procedure
315 virtual long MSWDefWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
316 virtual bool MSWProcessMessage(WXMSG* pMsg);
317 virtual bool MSWTranslateMessage(WXMSG* pMsg);
318 virtual void MSWDestroyWindow();
319
320 // Detach "Window" menu from menu bar so it doesn't get deleted
321 void MSWDetachWindowMenu();
322
a23fd0e1
VZ
323 // this function should return the brush to paint the window background
324 // with or 0 for the default brush
325 virtual WXHBRUSH OnCtlColor(WXHDC hDC,
326 WXHWND hWnd,
327 WXUINT nCtlColor,
328 WXUINT message,
329 WXWPARAM wParam,
330 WXLPARAM lParam);
bfc6fde4 331
cc2b7472
VZ
332#if WXWIN_COMPATIBILITY
333 void SetShowing(bool show) { (void)Show(show); }
334 bool IsUserEnabled() const { return IsEnabled(); }
335#endif // WXWIN_COMPATIBILITY
bfc6fde4
VZ
336
337 // Responds to colour changes: passes event on to children.
338 void OnSysColourChanged(wxSysColourChangedEvent& event);
339
a23fd0e1
VZ
340 // initialize various fields of wxMouseEvent (common part of MSWOnMouseXXX)
341 void InitMouseEvent(wxMouseEvent& event, int x, int y, WXUINT flags);
bfc6fde4 342
2bda0e17 343protected:
d7c24517
VZ
344 // the window handle
345 WXHWND m_hWnd;
346
cc2b7472 347 // the old window proc (we subclass all windows)
bfc6fde4 348 WXFARPROC m_oldWndProc;
2bda0e17 349
cc2b7472
VZ
350 // additional (MSW specific) flags
351 bool m_useCtl3D:1; // Using CTL3D for this control
cc2b7472
VZ
352 bool m_backgroundTransparent:1;
353 bool m_mouseInWindow:1;
354 bool m_doubleClickAllowed:1;
355 bool m_winCaptured:1;
bfc6fde4
VZ
356
357 // Caret data
cc2b7472
VZ
358 bool m_caretEnabled:1;
359 bool m_caretShown:1;
bfc6fde4
VZ
360 int m_caretWidth;
361 int m_caretHeight;
2bda0e17 362
cc2b7472 363 // the size of one page for scrolling
bfc6fde4
VZ
364 int m_xThumbSize;
365 int m_yThumbSize;
2bda0e17 366
a23fd0e1
VZ
367#if wxUSE_MOUSEEVENT_HACK
368 // the coordinates of the last mouse event and the type of it
cc2b7472
VZ
369 long m_lastMouseX,
370 m_lastMouseY;
371 int m_lastMouseEvent;
a23fd0e1 372#endif // wxUSE_MOUSEEVENT_HACK
bfc6fde4 373
bfc6fde4 374 WXHMENU m_hMenu; // Menu, if any
bfc6fde4 375
cc2b7472
VZ
376 wxButton *m_btnDefault;
377
378 // implement the base class pure virtuals
379 virtual void DoGetPosition( int *x, int *y ) const;
380 virtual void DoGetSize( int *width, int *height ) const;
381 virtual void DoGetClientSize( int *width, int *height ) const;
382 virtual void DoSetSize(int x, int y,
383 int width, int height,
384 int sizeFlags = wxSIZE_AUTO);
bfc6fde4 385 virtual void DoSetClientSize(int width, int height);
2bda0e17 386
cc2b7472
VZ
387#if wxUSE_TOOLTIPS
388 virtual void DoSetToolTip( wxToolTip *tip );
389#endif // wxUSE_TOOLTIPS
390
fd3f686c
VZ
391private:
392 // common part of all ctors
393 void Init();
394
a23fd0e1
VZ
395 // the (non-virtual) handlers for the events
396 bool HandleMove(int x, int y);
397 bool HandleJoystickEvent(WXUINT msg, int x, int y, WXUINT flags);
398
399#ifdef __WIN95__
400 bool HandleNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result);
401#endif // __WIN95__
402
403 DECLARE_NO_COPY_CLASS(wxWindow);
fd3f686c 404 DECLARE_EVENT_TABLE()
2bda0e17
KB
405};
406
cc2b7472
VZ
407// ---------------------------------------------------------------------------
408// global functions
409// ---------------------------------------------------------------------------
2bda0e17 410
cc2b7472 411// kbd code translation
184b5d99
JS
412WXDLLEXPORT int wxCharCodeMSWToWX(int keySym);
413WXDLLEXPORT int wxCharCodeWXToMSW(int id, bool *IsVirtual);
2bda0e17 414
2bda0e17 415#endif
bbcdf8bc 416 // _WX_WINDOW_H_