]> git.saurik.com Git - wxWidgets.git/blame - include/wx/stubs/window.h
compilation warning removed
[wxWidgets.git] / include / wx / stubs / window.h
CommitLineData
7c23a0b0
JS
1/////////////////////////////////////////////////////////////////////////////
2// Name: window.h
3// Purpose: wxWindow class
4// Author: AUTHOR
5// Modified by:
6// Created: ??/??/98
7// RCS-ID: $Id$
8// Copyright: (c) AUTHOR
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#ifndef _WX_WINDOW_H_
13#define _WX_WINDOW_H_
14
15#ifdef __GNUG__
16#pragma interface "window.h"
17#endif
18
19#include "wx/gdicmn.h"
20#include "wx/icon.h"
21#include "wx/cursor.h"
22#include "wx/pen.h"
23#include "wx/font.h"
24#include "wx/validate.h"
25#include "wx/event.h"
26#include "wx/string.h"
27#include "wx/list.h"
28#include "wx/region.h"
46ccb510 29#include "wx/accel.h"
7c23a0b0
JS
30
31#define wxKEY_SHIFT 1
32#define wxKEY_CTRL 2
33
34/*
35 * Base class for frame, panel, canvas, panel items, dialog box.
36 *
37 */
38
39/*
40 * Event handler: windows have themselves as their event handlers
41 * by default, but their event handlers could be set to another
42 * object entirely. This separation can reduce the amount of
43 * derivation required, and allow alteration of a window's functionality
44 * (e.g. by a resource editor that temporarily switches event handlers).
45 */
46
47class WXDLLEXPORT wxWindow;
48class WXDLLEXPORT wxEvent;
49class WXDLLEXPORT wxCommandEvent;
50class WXDLLEXPORT wxKeyEvent;
51class WXDLLEXPORT wxControl;
52class WXDLLEXPORT wxCursor;
53class WXDLLEXPORT wxColourMap;
54class WXDLLEXPORT wxFont;
55class WXDLLEXPORT wxMenu;
16e93305 56class WXDLLEXPORT wxRect;
7c23a0b0
JS
57class WXDLLEXPORT wxBitmap;
58class WXDLLEXPORT wxSizer;
59class WXDLLEXPORT wxList;
60class WXDLLEXPORT wxLayoutConstraints;
61class WXDLLEXPORT wxMouseEvent;
62class WXDLLEXPORT wxButton;
63class WXDLLEXPORT wxColour;
64class WXDLLEXPORT wxBrush;
65class WXDLLEXPORT wxPen;
66class WXDLLEXPORT wxIcon;
67class WXDLLEXPORT wxDC;
68class WXDLLEXPORT wxValidator;
69
47d67540 70#if wxUSE_DRAG_AND_DROP
5e25ba90 71class WXDLLEXPORT wxDropTarget;
7c23a0b0
JS
72#endif
73
47d67540 74#if wxUSE_WX_RESOURCES
7c23a0b0
JS
75class WXDLLEXPORT wxResourceTable;
76class WXDLLEXPORT wxItemResource;
77#endif
78
79WXDLLEXPORT_DATA(extern const char*) wxPanelNameStr;
80
81WXDLLEXPORT_DATA(extern const wxSize) wxDefaultSize;
82WXDLLEXPORT_DATA(extern const wxPoint) wxDefaultPosition;
83
c0ed460c
JS
84//-----------------------------------------------------------------------------
85// wxClientData
86//-----------------------------------------------------------------------------
87
88class wxClientData
89{
90public:
91 wxClientData() { }
92 virtual ~wxClientData() { }
93};
94
95//-----------------------------------------------------------------------------
96// wxStringClientData
97//-----------------------------------------------------------------------------
98
99class wxStringClientData: public wxClientData
100{
101public:
102 wxStringClientData() { }
103 wxStringClientData( wxString &data ) { m_data = data; }
104 void SetData( wxString &data ) { m_data = data; }
105 wxString GetData() const { return m_data; }
106
107private:
108 wxString m_data;
109};
110
7c23a0b0
JS
111class WXDLLEXPORT wxWindow: public wxEvtHandler
112{
113 DECLARE_ABSTRACT_CLASS(wxWindow)
114
115 friend class wxDC;
116 friend class wxPaintDC;
117
118public:
119 wxWindow();
120 inline wxWindow(wxWindow *parent, wxWindowID id,
121 const wxPoint& pos = wxDefaultPosition,
122 const wxSize& size = wxDefaultSize,
123 long style = 0,
124 const wxString& name = wxPanelNameStr)
125 {
126 m_children = new wxList;
127 Create(parent, id, pos, size, style, name);
128 }
129
130 virtual ~wxWindow();
131
132 bool Create(wxWindow *parent, wxWindowID id,
133 const wxPoint& pos = wxDefaultPosition,
134 const wxSize& size = wxDefaultSize,
135 long style = 0,
136 const wxString& name = wxPanelNameStr);
137
138 // Fit the window around the items
139 virtual void Fit();
140
141 // Show or hide the window
142 virtual bool Show(bool show);
143
144 // Is the window shown?
145 virtual bool IsShown() const;
146
147 // Raise the window to the top of the Z order
148 virtual void Raise();
149
150 // Lower the window to the bottom of the Z order
151 virtual void Lower();
152
153 // Is the window enabled?
154 virtual bool IsEnabled() const;
155
156 // For compatibility
157 inline bool Enabled() const { return IsEnabled(); }
158
159 // Dialog support: override these and call
160 // base class members to add functionality
161 // that can't be done using validators.
162
163 // Transfer values to controls. If returns FALSE,
164 // it's an application error (pops up a dialog)
165 virtual bool TransferDataToWindow();
166
167 // Transfer values from controls. If returns FALSE,
168 // transfer failed: don't quit
169 virtual bool TransferDataFromWindow();
170
171 // Validate controls. If returns FALSE,
172 // validation failed: don't quit
173 virtual bool Validate();
174
175 // Return code for dialogs
176 inline void SetReturnCode(int retCode);
177 inline int GetReturnCode();
178
179 // Set the cursor
180 virtual void SetCursor(const wxCursor& cursor);
181 inline virtual wxCursor *GetCursor() const { return (wxCursor *)& m_windowCursor; };
182
183 // Get the window with the focus
184 static wxWindow *FindFocus();
185
186 // Get character size
187 virtual int GetCharHeight() const;
188 virtual int GetCharWidth() const;
189
190 // Get overall window size
191 virtual void GetSize(int *width, int *height) const;
192
193 // Get window position, relative to parent (or screen if no parent)
194 virtual void GetPosition(int *x, int *y) const;
195
196 // Get client (application-useable) size
197 virtual void GetClientSize(int *width, int *height) const;
198
199 // Set overall size and position
200 virtual void SetSize(int x, int y, int width, int height, int sizeFlags = wxSIZE_AUTO);
201 inline virtual void SetSize(int width, int height) { SetSize(-1, -1, width, height, wxSIZE_USE_EXISTING); }
202 inline virtual void Move(int x, int y) { SetSize(x, y, -1, -1, wxSIZE_USE_EXISTING); }
203
204 // Set client size
205 virtual void SetClientSize(int width, int size);
206
207 // Convert client to screen coordinates
208 virtual void ClientToScreen(int *x, int *y) const;
209
210 // Convert screen to client coordinates
211 virtual void ScreenToClient(int *x, int *y) const;
212
213 // Set the focus to this window
214 virtual void SetFocus();
215
216 // Capture/release mouse
217 virtual void CaptureMouse();
218 virtual void ReleaseMouse();
219
220 // Enable or disable the window
221 virtual void Enable(bool enable);
222
47d67540 223#if wxUSE_DRAG_AND_DROP
7c23a0b0
JS
224 // Associate a drop target with this window (if the window already had a drop
225 // target, it's deleted!) and return the current drop target (may be NULL).
226 void SetDropTarget(wxDropTarget *pDropTarget);
227 wxDropTarget *GetDropTarget() const { return m_pDropTarget; }
228#endif
229
230 // Accept files for dragging
231 virtual void DragAcceptFiles(bool accept);
232
233 // Update region access
234 virtual wxRegion GetUpdateRegion() const;
235 virtual bool IsExposed(int x, int y, int w, int h) const;
236 virtual bool IsExposed(const wxPoint& pt) const;
237 virtual bool IsExposed(const wxRect& rect) const;
238
239 // Set/get the window title
240 virtual inline void SetTitle(const wxString& WXUNUSED(title)) {};
241 inline virtual wxString GetTitle() const { return wxString(""); };
242 // Most windows have the concept of a label; for frames, this is the
243 // title; for items, this is the label or button text.
244 inline virtual wxString GetLabel() const { return GetTitle(); }
245
246 // Set/get the window name (used for resource setting in X)
247 inline virtual wxString GetName() const;
248 inline virtual void SetName(const wxString& name);
249
250 // Centre the window
251 virtual void Centre(int direction) ;
252 inline void Center(int direction = wxHORIZONTAL) { Centre(direction); }
253
254 // Popup a menu
255 virtual bool PopupMenu(wxMenu *menu, int x, int y);
256
257 // Send the window a refresh event
16e93305 258 virtual void Refresh(bool eraseBack = TRUE, const wxRect *rect = NULL);
7c23a0b0
JS
259
260 // New functions that will replace the above.
261 virtual void SetScrollbar(int orient, int pos, int thumbVisible,
262 int range, bool refresh = TRUE);
263
264 virtual void SetScrollPos(int orient, int pos, bool refresh = TRUE);
265 virtual int GetScrollPos(int orient) const;
266 virtual int GetScrollRange(int orient) const;
267 virtual int GetScrollThumb(int orient) const;
268
16e93305 269 virtual void ScrollWindow(int dx, int dy, const wxRect *rect = NULL);
7c23a0b0
JS
270
271 // Caret manipulation
272 virtual void CreateCaret(int w, int h);
273 virtual void CreateCaret(const wxBitmap *bitmap);
274 virtual void DestroyCaret();
275 virtual void ShowCaret(bool show);
276 virtual void SetCaretPos(int x, int y);
277 virtual void GetCaretPos(int *x, int *y) const;
278
279 // Tell window how much it can be sized
280 virtual void SetSizeHints(int minW = -1, int minH = -1, int maxW = -1, int maxH = -1, int incW = -1, int incH = -1);
281
282 // Set/get the window's identifier
283 inline int GetId() const;
284 inline void SetId(int id);
285
46ccb510
JS
286 virtual void SetAcceleratorTable(const wxAcceleratorTable& accel);
287 inline virtual wxAcceleratorTable& GetAcceleratorTable() const { return (wxAcceleratorTable&) m_acceleratorTable; }
288
7c23a0b0
JS
289 // Make the window modal (all other windows unresponsive)
290 virtual void MakeModal(bool modal);
291
292 // Get the private handle (platform-dependent)
293 inline void *GetHandle() const;
294
295 // Set/get the window's relatives
296 inline wxWindow *GetParent() const;
297 inline void SetParent(wxWindow *p) ;
298 inline wxWindow *GetGrandParent() const;
c0ed460c 299 inline wxList& GetChildren() const;
7c23a0b0
JS
300
301 // Set/get the window's font
302 virtual void SetFont(const wxFont& f);
c0ed460c 303 inline virtual wxFont& GetFont() const;
7c23a0b0
JS
304
305 // Set/get the window's validator
306 void SetValidator(const wxValidator& validator);
307 inline wxValidator *GetValidator() const;
308
309 // Set/get the window's style
310 inline void SetWindowStyleFlag(long flag);
311 inline long GetWindowStyleFlag() const;
312
02e8b2f9
JS
313 // Handle a control command
314 virtual void OnCommand(wxWindow& win, wxCommandEvent& event);
315
7c23a0b0
JS
316 // Set/get event handler
317 inline void SetEventHandler(wxEvtHandler *handler);
318 inline wxEvtHandler *GetEventHandler() const;
319
320 // Push/pop event handler (i.e. allow a chain of event handlers
321 // be searched)
322 void PushEventHandler(wxEvtHandler *handler) ;
323 wxEvtHandler *PopEventHandler(bool deleteHandler = FALSE) ;
324
325 // Close the window by calling OnClose, posting a deletion
326 virtual bool Close(bool force = FALSE);
327
328 // Destroy the window (delayed, if a managed window)
329 virtual bool Destroy() ;
330
331 // Mode for telling default OnSize members to
332 // call Layout(), if not using Sizers, just top-down constraints
333 inline void SetAutoLayout(bool a);
334 inline bool GetAutoLayout() const;
335
336 // Set/get constraints
337 inline wxLayoutConstraints *GetConstraints() const;
338 void SetConstraints(wxLayoutConstraints *c);
339
340 // Set/get window background colour
341 inline virtual void SetBackgroundColour(const wxColour& col);
342 inline virtual wxColour GetBackgroundColour() const;
343
344 // Set/get window foreground colour
345 inline virtual void SetForegroundColour(const wxColour& col);
346 inline virtual wxColour GetForegroundColour() const;
347
348 // Get the default button, if there is one
349 inline virtual wxButton *GetDefaultItem() const;
350 inline virtual void SetDefaultItem(wxButton *but);
351
352 // Override to define new behaviour for default action (e.g. double clicking
353 // on a listbox)
354 virtual void OnDefaultAction(wxControl *initiatingItem);
355
356 // Resource loading
47d67540 357#if wxUSE_WX_RESOURCES
7c23a0b0 358 virtual bool LoadFromResource(wxWindow *parent, const wxString& resourceName, const wxResourceTable *table = NULL);
fd71308f
JS
359 virtual wxControl *CreateItem(const wxItemResource* childResource, const wxItemResource* parentResource,
360 const wxResourceTable *table = (const wxResourceTable *) NULL);
7c23a0b0
JS
361#endif
362
7c23a0b0
JS
363 virtual void GetTextExtent(const wxString& string, int *x, int *y,
364 int *descent = NULL,
365 int *externalLeading = NULL,
366 const wxFont *theFont = NULL, bool use16 = FALSE) const;
367
368 // Is the window retained?
369 inline bool IsRetained() const;
370
371 // Warp the pointer the given position
372 virtual void WarpPointer(int x_pos, int y_pos) ;
373
374 // Clear the window
375 virtual void Clear();
376
377 // Find a window by id or name
378 virtual wxWindow *FindWindow(long id);
379 virtual wxWindow *FindWindow(const wxString& name);
380
381 // Constraint operations
382 bool Layout();
383 void SetSizer(wxSizer *sizer); // Adds sizer child to this window
384 inline wxSizer *GetSizer() const ;
385 inline wxWindow *GetSizerParent() const ;
386 inline void SetSizerParent(wxWindow *win);
387
388 // Do Update UI processing for controls
389 void UpdateWindowUI();
390
391 void OnEraseBackground(wxEraseEvent& event);
392 void OnChar(wxKeyEvent& event);
4ce81a75
JS
393 void OnKeyDown(wxKeyEvent& event);
394 void OnKeyUp(wxKeyEvent& event);
7c23a0b0
JS
395 void OnPaint(wxPaintEvent& event);
396 void OnIdle(wxIdleEvent& event);
397
398 // Does this window want to accept keyboard focus?
399 virtual bool AcceptsFocus() const;
400
7f555861
JS
401 virtual void PrepareDC( wxDC &dc ) {};
402
403
7c23a0b0
JS
404public:
405 ////////////////////////////////////////////////////////////////////////
406 //// IMPLEMENTATION
407
408 // For implementation purposes - sometimes decorations make the client area
409 // smaller
410 virtual wxPoint GetClientAreaOrigin() const;
411
412 // Makes an adjustment to the window position (for example, a frame that has
413 // a toolbar that it manages itself).
414 virtual void AdjustForParentClientOrigin(int& x, int& y, int sizeFlags);
415
416 // Executes the default message
417 virtual long Default();
418
7c23a0b0
JS
419/* TODO: you may need something like this
420 // Determine whether 3D effects are wanted
421 virtual WXDWORD Determine3DEffects(WXDWORD defaultBorderStyle, bool *want3D);
422*/
423
424 virtual void AddChild(wxWindow *child); // Adds reference to the child object
425 virtual void RemoveChild(wxWindow *child); // Removes reference to child
426 // (but doesn't delete the child object)
427 virtual void DestroyChildren(); // Removes and destroys all children
428
34138703
JS
429 inline bool IsBeingDeleted() const { return FALSE; } // TODO: Should probably eliminate this
430
7c23a0b0
JS
431 // Constraint implementation
432 void UnsetConstraints(wxLayoutConstraints *c);
433 inline wxList *GetConstraintsInvolvedIn() const ;
434 // Back-pointer to other windows we're involved with, so if we delete
435 // this window, we must delete any constraints we're involved with.
436 void AddConstraintReference(wxWindow *otherWin);
437 void RemoveConstraintReference(wxWindow *otherWin);
438 void DeleteRelatedConstraints();
439
440 virtual void ResetConstraints();
441 virtual void SetConstraintSizes(bool recurse = TRUE);
442 virtual bool LayoutPhase1(int *noChanges);
443 virtual bool LayoutPhase2(int *noChanges);
444 virtual bool DoPhase(int);
445 // Transforms from sizer coordinate space to actual
446 // parent coordinate space
447 virtual void TransformSizerToActual(int *x, int *y) const ;
448
449 // Set size with transformation to actual coordinates if nec.
450 virtual void SizerSetSize(int x, int y, int w, int h);
451 virtual void SizerMove(int x, int y);
452
453 // Only set/get the size/position of the constraint (if any)
454 virtual void SetSizeConstraint(int x, int y, int w, int h);
455 virtual void MoveConstraint(int x, int y);
456 virtual void GetSizeConstraint(int *w, int *h) const ;
457 virtual void GetClientSizeConstraint(int *w, int *h) const ;
458 virtual void GetPositionConstraint(int *x, int *y) const ;
459
fd71308f
JS
460 // Dialog units translations. Implemented in wincmn.cpp.
461 wxPoint ConvertPixelsToDialog(const wxPoint& pt) ;
462 wxPoint ConvertDialogToPixels(const wxPoint& pt) ;
463 inline wxSize ConvertPixelsToDialog(const wxSize& sz)
464 { wxPoint pt(ConvertPixelsToDialog(wxPoint(sz.x, sz.y))); return wxSize(pt.x, pt.y); }
465 inline wxSize ConvertDialogToPixels(const wxSize& sz)
466 { wxPoint pt(ConvertDialogToPixels(wxPoint(sz.x, sz.y))); return wxSize(pt.x, pt.y); }
467
7c23a0b0
JS
468 wxObject *GetChild(int number) const ;
469
34138703
JS
470 // Generates a new id for controls
471 static int NewControlId();
7c23a0b0
JS
472
473 // Responds to colour changes: passes event on to children.
474 void OnSysColourChanged(wxSysColourChangedEvent& event);
475
476 // Transfers data to any child controls
477 void OnInitDialog(wxInitDialogEvent& event);
478
479 // Sends an OnInitDialog event, which in turns transfers data to
480 // to the window via validators.
481 virtual void InitDialog();
482
483 ////////////////////////////////////////////////////////////////////////
484 //// PROTECTED DATA
485protected:
486 int m_windowId;
487 long m_windowStyle; // Store the window's style
488 wxEvtHandler * m_windowEventHandler; // Usually is 'this'
489 wxLayoutConstraints * m_constraints; // Constraints for this window
490 wxList * m_constraintsInvolvedIn; // List of constraints we're involved in
491 wxSizer * m_windowSizer; // Window's top-level sizer (if any)
492 wxWindow * m_sizerParent; // Window's parent sizer (if any)
493 bool m_autoLayout; // Whether to call Layout() in OnSize
494 wxWindow * m_windowParent; // Each window always knows its parent
495 wxValidator * m_windowValidator;
7c23a0b0
JS
496 int m_minSizeX;
497 int m_minSizeY;
498 int m_maxSizeX;
499 int m_maxSizeY;
500
501 // Caret data
502 int m_caretWidth;
503 int m_caretHeight;
504 bool m_caretEnabled;
505 bool m_caretShown;
506 wxFont m_windowFont; // Window's font
7c23a0b0
JS
507 wxCursor m_windowCursor; // Window's cursor
508 wxString m_windowName; // Window name
509
510 wxButton * m_defaultItem;
511
512 wxColour m_backgroundColour ;
513 wxColour m_foregroundColour ;
46ccb510 514 wxAcceleratorTable m_acceleratorTable;
7c23a0b0 515
47d67540 516#if wxUSE_DRAG_AND_DROP
7c23a0b0
JS
517 wxDropTarget *m_pDropTarget; // the current drop target or NULL
518#endif //USE_DRAG_AND_DROP
519
520public:
7c23a0b0
JS
521 wxRegion m_updateRegion;
522 wxList * m_children; // Window's children
523 int m_returnCode;
524
525DECLARE_EVENT_TABLE()
526};
527
528////////////////////////////////////////////////////////////////////////
529//// INLINES
530
531inline void *wxWindow::GetHandle() const { return (void *)NULL; }
532inline int wxWindow::GetId() const { return m_windowId; }
533inline void wxWindow::SetId(int id) { m_windowId = id; }
534inline wxWindow *wxWindow::GetParent() const { return m_windowParent; }
535inline void wxWindow::SetParent(wxWindow *p) { m_windowParent = p; }
7f555861 536inline wxWindow *wxWindow::GetGrandParent() const { return (m_windowParent ? m_windowParent->m_windowParent : (wxWindow*) NULL); }
c0ed460c
JS
537inline wxList& wxWindow::GetChildren() const { return (wxList&) * m_children; }
538inline wxFont& wxWindow::GetFont() const { return (wxFont&) m_windowFont; }
7c23a0b0
JS
539inline wxString wxWindow::GetName() const { return m_windowName; }
540inline void wxWindow::SetName(const wxString& name) { m_windowName = name; }
541inline long wxWindow::GetWindowStyleFlag() const { return m_windowStyle; }
542inline void wxWindow::SetWindowStyleFlag(long flag) { m_windowStyle = flag; }
7c23a0b0
JS
543inline void wxWindow::SetEventHandler(wxEvtHandler *handler) { m_windowEventHandler = handler; }
544inline wxEvtHandler *wxWindow::GetEventHandler() const { return m_windowEventHandler; }
545inline void wxWindow::SetAutoLayout(bool a) { m_autoLayout = a; }
546inline bool wxWindow::GetAutoLayout() const { return m_autoLayout; }
547inline wxLayoutConstraints *wxWindow::GetConstraints() const { return m_constraints; }
548inline void wxWindow::SetBackgroundColour(const wxColour& col) { m_backgroundColour = col; };
549inline wxColour wxWindow::GetBackgroundColour() const { return m_backgroundColour; };
550inline void wxWindow::SetForegroundColour(const wxColour& col) { m_foregroundColour = col; };
551inline wxColour wxWindow::GetForegroundColour() const { return m_foregroundColour; };
552
553inline wxButton *wxWindow::GetDefaultItem() const { return m_defaultItem; }
554inline void wxWindow::SetDefaultItem(wxButton *but) { m_defaultItem = but; }
555inline bool wxWindow::IsRetained() const { return ((m_windowStyle & wxRETAINED) == wxRETAINED); }
556
7c23a0b0
JS
557inline wxList *wxWindow::GetConstraintsInvolvedIn() const { return m_constraintsInvolvedIn; }
558inline wxSizer *wxWindow::GetSizer() const { return m_windowSizer; }
559inline wxWindow *wxWindow::GetSizerParent() const { return m_sizerParent; }
560inline void wxWindow::SetSizerParent(wxWindow *win) { m_sizerParent = win; }
561inline wxValidator *wxWindow::GetValidator() const { return m_windowValidator; }
7c23a0b0
JS
562inline void wxWindow::SetReturnCode(int retCode) { m_returnCode = retCode; }
563inline int wxWindow::GetReturnCode() { return m_returnCode; }
564
565// Get the active window.
566wxWindow* WXDLLEXPORT wxGetActiveWindow();
567
568WXDLLEXPORT_DATA(extern wxList) wxTopLevelWindows;
569
570#endif
571 // _WX_WINDOW_H_