]> git.saurik.com Git - wxWidgets.git/blame - src/qt/window.cpp
icon support moved to wxBitmap, allowing for fully transparent usage
[wxWidgets.git] / src / qt / window.cpp
CommitLineData
7c78e7c7 1/////////////////////////////////////////////////////////////////////////////
01b2eeec
KB
2// Name: windows.cpp
3// Purpose: wxWindow
4// Author: AUTHOR
5// Modified by:
6// Created: ??/??/98
7// RCS-ID: $Id$
8// Copyright: (c) AUTHOR
9// Licence: wxWindows licence
7c78e7c7
RR
10/////////////////////////////////////////////////////////////////////////////
11
7c78e7c7
RR
12#ifdef __GNUG__
13#pragma implementation "window.h"
14#endif
15
01b2eeec
KB
16#include "wx/setup.h"
17#include "wx/menu.h"
7c78e7c7 18#include "wx/dc.h"
01b2eeec
KB
19#include "wx/dcclient.h"
20#include "wx/utils.h"
7c78e7c7 21#include "wx/app.h"
01b2eeec 22#include "wx/panel.h"
7c78e7c7 23#include "wx/layout.h"
7c78e7c7 24#include "wx/dialog.h"
01b2eeec
KB
25#include "wx/listbox.h"
26#include "wx/button.h"
27#include "wx/settings.h"
7c78e7c7 28#include "wx/msgdlg.h"
01b2eeec
KB
29
30#include "wx/menuitem.h"
31#include "wx/log.h"
32
47d67540 33#if wxUSE_DRAG_AND_DROP
7c78e7c7 34#include "wx/dnd.h"
01b2eeec 35#endif
7c78e7c7 36
01b2eeec 37#include <string.h>
7c78e7c7
RR
38
39extern wxList wxPendingDelete;
7c78e7c7 40
01b2eeec 41IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxEvtHandler)
7c78e7c7
RR
42
43BEGIN_EVENT_TABLE(wxWindow, wxEvtHandler)
01b2eeec
KB
44 EVT_CHAR(wxWindow::OnChar)
45 EVT_ERASE_BACKGROUND(wxWindow::OnEraseBackground)
7c78e7c7
RR
46 EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged)
47 EVT_INIT_DIALOG(wxWindow::OnInitDialog)
48 EVT_IDLE(wxWindow::OnIdle)
49END_EVENT_TABLE()
50
01b2eeec
KB
51
52
53// Constructor
7c78e7c7
RR
54wxWindow::wxWindow()
55{
01b2eeec
KB
56 // Generic
57 m_windowId = 0;
58 m_windowStyle = 0;
59 m_windowParent = NULL;
60 m_windowEventHandler = this;
61 m_windowName = "";
62 m_windowCursor = *wxSTANDARD_CURSOR;
63 m_children = new wxList;
7c78e7c7 64 m_constraints = NULL;
01b2eeec 65 m_constraintsInvolvedIn = NULL;
7c78e7c7 66 m_windowSizer = NULL;
01b2eeec
KB
67 m_sizerParent = NULL;
68 m_autoLayout = FALSE;
69 m_windowValidator = NULL;
70 m_defaultItem = NULL;
71 m_returnCode = 0;
72 m_caretWidth = 0; m_caretHeight = 0;
73 m_caretEnabled = FALSE;
74 m_caretShown = FALSE;
75 m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW) ; ;
76 m_foregroundColour = *wxBLACK;
77 m_defaultForegroundColour = *wxBLACK ;
78 m_defaultBackgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE) ;
79
47d67540 80#if wxUSE_DRAG_AND_DROP
01b2eeec
KB
81 m_pDropTarget = NULL;
82#endif
83}
7c78e7c7 84
01b2eeec
KB
85// Destructor
86wxWindow::~wxWindow()
7c78e7c7 87{
01b2eeec
KB
88 // Have to delete constraints/sizer FIRST otherwise
89 // sizers may try to look at deleted windows as they
90 // delete themselves.
47d67540 91#if wxUSE_CONSTRAINTS
01b2eeec
KB
92 DeleteRelatedConstraints();
93 if (m_constraints)
94 {
95 // This removes any dangling pointers to this window
96 // in other windows' constraintsInvolvedIn lists.
97 UnsetConstraints(m_constraints);
98 delete m_constraints;
99 m_constraints = NULL;
100 }
101 if (m_windowSizer)
102 {
103 delete m_windowSizer;
104 m_windowSizer = NULL;
105 }
106 // If this is a child of a sizer, remove self from parent
107 if (m_sizerParent)
108 m_sizerParent->RemoveChild((wxWindow *)this);
109#endif
7c78e7c7 110
01b2eeec
KB
111 if (m_windowParent)
112 m_windowParent->RemoveChild(this);
7c78e7c7 113
01b2eeec
KB
114 DestroyChildren();
115
116 // TODO: destroy the window
7c78e7c7 117
01b2eeec
KB
118 delete m_children;
119 m_children = NULL;
120
121 // Just in case the window has been Closed, but
122 // we're then deleting immediately: don't leave
123 // dangling pointers.
124 wxPendingDelete.DeleteObject(this);
125
126 if ( m_windowValidator )
127 delete m_windowValidator;
128}
129
130// Destroy the window (delayed, if a managed window)
131bool wxWindow::Destroy()
7c78e7c7 132{
01b2eeec
KB
133 delete this;
134 return TRUE;
135}
136
137// Constructor
138bool wxWindow::Create(wxWindow *parent, wxWindowID id,
139 const wxPoint& pos,
140 const wxSize& size,
141 long style,
142 const wxString& name)
143{
144 // Generic
145 m_windowId = 0;
146 m_windowStyle = 0;
147 m_windowParent = NULL;
148 m_windowEventHandler = this;
149 m_windowName = "";
150 m_windowCursor = *wxSTANDARD_CURSOR;
151 m_constraints = NULL;
152 m_constraintsInvolvedIn = NULL;
153 m_windowSizer = NULL;
154 m_sizerParent = NULL;
155 m_autoLayout = FALSE;
156 m_windowValidator = NULL;
157
47d67540 158#if wxUSE_DRAG_AND_DROP
01b2eeec
KB
159 m_pDropTarget = NULL;
160#endif
161
162 m_caretWidth = 0; m_caretHeight = 0;
163 m_caretEnabled = FALSE;
164 m_caretShown = FALSE;
165 m_minSizeX = -1;
166 m_minSizeY = -1;
167 m_maxSizeX = -1;
168 m_maxSizeY = -1;
169 m_defaultItem = NULL;
170 m_windowParent = NULL;
171 if (!parent)
172 return FALSE;
173
174 if (parent) parent->AddChild(this);
175
176 m_returnCode = 0;
177
178 SetName(name);
179
180 if ( id == -1 )
181 m_windowId = (int)NewControlId();
182 else
183 m_windowId = id;
184
185 m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW) ; ;
186 m_foregroundColour = *wxBLACK;
187 m_defaultForegroundColour = *wxBLACK ;
188 m_defaultBackgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE) ;
189
190 m_windowStyle = style;
7c78e7c7 191
01b2eeec
KB
192 if ( id == -1 )
193 m_windowId = (int)NewControlId();
194 else
195 m_windowId = id;
196
197 // TODO: create the window
198
199 return TRUE;
200}
201
202void wxWindow::SetFocus()
7c78e7c7 203{
01b2eeec
KB
204 // TODO
205}
7c78e7c7 206
01b2eeec 207void wxWindow::Enable(bool enable)
7c78e7c7 208{
01b2eeec
KB
209 // TODO
210}
7c78e7c7 211
01b2eeec 212void wxWindow::CaptureMouse()
7c78e7c7 213{
01b2eeec
KB
214 // TODO
215}
7c78e7c7 216
01b2eeec 217void wxWindow::ReleaseMouse()
7c78e7c7 218{
01b2eeec
KB
219 // TODO
220}
7c78e7c7 221
01b2eeec
KB
222// Push/pop event handler (i.e. allow a chain of event handlers
223// be searched)
224void wxWindow::PushEventHandler(wxEvtHandler *handler)
7c78e7c7 225{
01b2eeec
KB
226 handler->SetNextHandler(GetEventHandler());
227 SetEventHandler(handler);
228}
7c78e7c7 229
01b2eeec
KB
230wxEvtHandler *wxWindow::PopEventHandler(bool deleteHandler)
231{
232 if ( GetEventHandler() )
233 {
234 wxEvtHandler *handlerA = GetEventHandler();
235 wxEvtHandler *handlerB = handlerA->GetNextHandler();
236 handlerA->SetNextHandler(NULL);
237 SetEventHandler(handlerB);
238 if ( deleteHandler )
239 {
240 delete handlerA;
241 return NULL;
242 }
243 else
244 return handlerA;
245 }
246 else
247 return NULL;
248}
249
47d67540 250#if wxUSE_DRAG_AND_DROP
01b2eeec
KB
251
252void wxWindow::SetDropTarget(wxDropTarget *pDropTarget)
7c78e7c7 253{
01b2eeec
KB
254 if ( m_pDropTarget != 0 ) {
255 m_pDropTarget->Revoke(m_hWnd);
256 delete m_pDropTarget;
257 }
7c78e7c7 258
01b2eeec
KB
259 m_pDropTarget = pDropTarget;
260 if ( m_pDropTarget != 0 )
261 m_pDropTarget->Register(m_hWnd);
262}
263
264#endif
265
266// Old style file-manager drag&drop
267void wxWindow::DragAcceptFiles(bool accept)
7c78e7c7 268{
01b2eeec
KB
269 // TODO
270}
7c78e7c7 271
01b2eeec
KB
272// Get total size
273void wxWindow::GetSize(int *x, int *y) const
7c78e7c7 274{
01b2eeec
KB
275 // TODO
276}
7c78e7c7 277
01b2eeec 278void wxWindow::GetPosition(int *x, int *y) const
7c78e7c7 279{
01b2eeec
KB
280 // TODO
281}
7c78e7c7 282
01b2eeec 283void wxWindow::ScreenToClient(int *x, int *y) const
7c78e7c7 284{
01b2eeec
KB
285 // TODO
286}
7c78e7c7 287
01b2eeec 288void wxWindow::ClientToScreen(int *x, int *y) const
7c78e7c7 289{
01b2eeec
KB
290 // TODO
291}
7c78e7c7 292
01b2eeec 293void wxWindow::SetCursor(const wxCursor& cursor)
7c78e7c7 294{
01b2eeec
KB
295 m_windowCursor = cursor;
296 if (m_windowCursor.Ok())
7c78e7c7 297 {
01b2eeec 298 // TODO
7c78e7c7 299 }
01b2eeec 300}
7c78e7c7 301
7c78e7c7 302
01b2eeec
KB
303// Get size *available for subwindows* i.e. excluding menu bar etc.
304void wxWindow::GetClientSize(int *x, int *y) const
7c78e7c7 305{
01b2eeec
KB
306 // TODO
307}
7c78e7c7 308
01b2eeec 309void wxWindow::SetSize(int x, int y, int width, int height, int sizeFlags)
7c78e7c7 310{
01b2eeec
KB
311 // TODO
312}
7c78e7c7 313
01b2eeec 314void wxWindow::SetClientSize(int width, int height)
7c78e7c7 315{
01b2eeec 316 // TODO
7c78e7c7
RR
317}
318
01b2eeec
KB
319// For implementation purposes - sometimes decorations make the client area
320// smaller
321wxPoint wxWindow::GetClientAreaOrigin() const
7c78e7c7 322{
01b2eeec
KB
323 return wxPoint(0, 0);
324}
7c78e7c7 325
01b2eeec
KB
326// Makes an adjustment to the window position (for example, a frame that has
327// a toolbar that it manages itself).
328void wxWindow::AdjustForParentClientOrigin(int& x, int& y, int sizeFlags)
7c78e7c7 329{
01b2eeec
KB
330 if (((sizeFlags & wxSIZE_NO_ADJUSTMENTS) == 0) && GetParent())
331 {
332 wxPoint pt(GetParent()->GetClientAreaOrigin());
333 x += pt.x; y += pt.y;
334 }
335}
7c78e7c7 336
01b2eeec 337bool wxWindow::Show(bool show)
7c78e7c7 338{
01b2eeec
KB
339 // TODO
340 return FALSE;
341}
7c78e7c7 342
01b2eeec 343bool wxWindow::IsShown() const
7c78e7c7 344{
01b2eeec
KB
345 // TODO
346 return FALSE;
347}
7c78e7c7 348
01b2eeec 349int wxWindow::GetCharHeight() const
7c78e7c7 350{
01b2eeec
KB
351 // TODO
352 return 0;
353}
7c78e7c7 354
01b2eeec 355int wxWindow::GetCharWidth() const
7c78e7c7 356{
01b2eeec
KB
357 // TODO
358 return 0;
359}
7c78e7c7 360
01b2eeec
KB
361void wxWindow::GetTextExtent(const wxString& string, int *x, int *y,
362 int *descent, int *externalLeading, const wxFont *theFont, bool) const
7c78e7c7 363{
01b2eeec
KB
364 wxFont *fontToUse = (wxFont *)theFont;
365 if (!fontToUse)
366 fontToUse = (wxFont *) & m_windowFont;
7c78e7c7 367
01b2eeec
KB
368 // TODO
369}
7c78e7c7 370
16e93305 371void wxWindow::Refresh(bool eraseBack, const wxRect *rect)
7c78e7c7 372{
01b2eeec
KB
373 // TODO
374}
7c78e7c7 375
01b2eeec
KB
376// Responds to colour changes: passes event on to children.
377void wxWindow::OnSysColourChanged(wxSysColourChangedEvent& event)
7c78e7c7 378{
01b2eeec
KB
379 wxNode *node = GetChildren()->First();
380 while ( node )
381 {
382 // Only propagate to non-top-level windows
383 wxWindow *win = (wxWindow *)node->Data();
384 if ( win->GetParent() )
385 {
386 wxSysColourChangedEvent event2;
387 event.m_eventObject = win;
388 win->GetEventHandler()->ProcessEvent(event2);
389 }
7c78e7c7 390
01b2eeec
KB
391 node = node->Next();
392 }
393}
7c78e7c7 394
01b2eeec
KB
395// This can be called by the app (or wxWindows) to do default processing for the current
396// event. Save message/event info in wxWindow so they can be used in this function.
397long wxWindow::Default()
7c78e7c7 398{
01b2eeec
KB
399 // TODO
400 return 0;
401}
7c78e7c7 402
01b2eeec 403void wxWindow::InitDialog()
7c78e7c7 404{
01b2eeec
KB
405 wxInitDialogEvent event(GetId());
406 event.SetEventObject( this );
407 GetEventHandler()->ProcessEvent(event);
408}
7c78e7c7 409
01b2eeec
KB
410// Default init dialog behaviour is to transfer data to window
411void wxWindow::OnInitDialog(wxInitDialogEvent& event)
7c78e7c7 412{
01b2eeec
KB
413 TransferDataToWindow();
414}
7c78e7c7 415
01b2eeec
KB
416// Caret manipulation
417void wxWindow::CreateCaret(int w, int h)
7c78e7c7 418{
01b2eeec
KB
419 m_caretWidth = w;
420 m_caretHeight = h;
421 m_caretEnabled = TRUE;
422}
7c78e7c7 423
01b2eeec 424void wxWindow::CreateCaret(const wxBitmap *WXUNUSED(bitmap))
7c78e7c7 425{
01b2eeec
KB
426 // TODO
427}
7c78e7c7 428
01b2eeec 429void wxWindow::ShowCaret(bool show)
7c78e7c7 430{
01b2eeec
KB
431 // TODO
432}
7c78e7c7 433
01b2eeec 434void wxWindow::DestroyCaret()
7c78e7c7 435{
01b2eeec
KB
436 // TODO
437 m_caretEnabled = FALSE;
438}
7c78e7c7 439
01b2eeec 440void wxWindow::SetCaretPos(int x, int y)
7c78e7c7 441{
01b2eeec
KB
442 // TODO
443}
7c78e7c7 444
01b2eeec 445void wxWindow::GetCaretPos(int *x, int *y) const
7c78e7c7 446{
01b2eeec
KB
447 // TODO
448}
7c78e7c7 449
01b2eeec 450wxWindow *wxGetActiveWindow()
7c78e7c7 451{
01b2eeec
KB
452 // TODO
453 return NULL;
454}
7c78e7c7 455
01b2eeec 456void wxWindow::SetSizeHints(int minW, int minH, int maxW, int maxH, int WXUNUSED(incW), int WXUNUSED(incH))
7c78e7c7 457{
01b2eeec
KB
458 m_minSizeX = minW;
459 m_minSizeY = minH;
460 m_maxSizeX = maxW;
461 m_maxSizeY = maxH;
462}
7c78e7c7 463
01b2eeec 464void wxWindow::Centre(int direction)
7c78e7c7 465{
01b2eeec 466 int x, y, width, height, panel_width, panel_height, new_x, new_y;
7c78e7c7 467
01b2eeec
KB
468 wxWindow *father = (wxWindow *)GetParent();
469 if (!father)
470 return;
7c78e7c7 471
01b2eeec
KB
472 father->GetClientSize(&panel_width, &panel_height);
473 GetSize(&width, &height);
474 GetPosition(&x, &y);
7c78e7c7 475
01b2eeec
KB
476 new_x = -1;
477 new_y = -1;
7c78e7c7 478
01b2eeec
KB
479 if (direction & wxHORIZONTAL)
480 new_x = (int)((panel_width - width)/2);
7c78e7c7 481
01b2eeec
KB
482 if (direction & wxVERTICAL)
483 new_y = (int)((panel_height - height)/2);
7c78e7c7 484
01b2eeec 485 SetSize(new_x, new_y, -1, -1);
7c78e7c7 486
01b2eeec 487}
7c78e7c7 488
01b2eeec
KB
489// Coordinates relative to the window
490void wxWindow::WarpPointer (int x_pos, int y_pos)
7c78e7c7 491{
01b2eeec
KB
492 // TODO
493}
7c78e7c7 494
01b2eeec 495void wxWindow::OnEraseBackground(wxEraseEvent& event)
7c78e7c7 496{
01b2eeec
KB
497 // TODO
498 Default();
499}
7c78e7c7 500
01b2eeec 501int wxWindow::GetScrollPos(int orient) const
7c78e7c7 502{
01b2eeec
KB
503 // TODO
504 return 0;
505}
7c78e7c7 506
01b2eeec
KB
507// This now returns the whole range, not just the number
508// of positions that we can scroll.
509int wxWindow::GetScrollRange(int orient) const
7c78e7c7 510{
01b2eeec
KB
511 // TODO
512 return 0;
513}
7c78e7c7 514
01b2eeec 515int wxWindow::GetScrollThumb(int orient) const
7c78e7c7 516{
01b2eeec
KB
517 // TODO
518 return 0;
519}
7c78e7c7 520
01b2eeec 521void wxWindow::SetScrollPos(int orient, int pos, bool refresh)
7c78e7c7 522{
01b2eeec
KB
523 // TODO
524 return 0;
525}
7c78e7c7 526
01b2eeec
KB
527// New function that will replace some of the above.
528void wxWindow::SetScrollbar(int orient, int pos, int thumbVisible,
529 int range, bool refresh)
7c78e7c7 530{
01b2eeec
KB
531 // TODO
532}
7c78e7c7 533
01b2eeec 534// Does a physical scroll
16e93305 535void wxWindow::ScrollWindow(int dx, int dy, const wxRect *rect)
7c78e7c7 536{
01b2eeec
KB
537 // TODO
538 return 0;
539}
7c78e7c7 540
01b2eeec 541void wxWindow::SetFont(const wxFont& font)
7c78e7c7 542{
01b2eeec 543 m_windowFont = font;
7c78e7c7 544
01b2eeec
KB
545 if (!m_windowFont.Ok())
546 return;
547 // TODO
548}
7c78e7c7 549
01b2eeec 550void wxWindow::OnChar(wxKeyEvent& event)
7c78e7c7 551{
01b2eeec
KB
552 if ( event.KeyCode() == WXK_TAB ) {
553 // propagate the TABs to the parent - it's up to it to decide what
554 // to do with it
555 if ( GetParent() ) {
556 if ( GetParent()->ProcessEvent(event) )
557 return;
558 }
559 }
560}
7c78e7c7 561
01b2eeec 562void wxWindow::OnPaint(wxPaintEvent& event)
7c78e7c7 563{
01b2eeec
KB
564 Default();
565}
7c78e7c7 566
01b2eeec 567bool wxWindow::IsEnabled() const
7c78e7c7 568{
01b2eeec
KB
569 // TODO
570 return FALSE;
571}
7c78e7c7 572
01b2eeec
KB
573// Dialog support: override these and call
574// base class members to add functionality
575// that can't be done using validators.
576// NOTE: these functions assume that controls
577// are direct children of this window, not grandchildren
578// or other levels of descendant.
579
580// Transfer values to controls. If returns FALSE,
581// it's an application error (pops up a dialog)
582bool wxWindow::TransferDataToWindow()
583{
584 wxNode *node = GetChildren()->First();
585 while ( node )
586 {
587 wxWindow *child = (wxWindow *)node->Data();
588 if ( child->GetValidator() &&
589 !child->GetValidator()->TransferToWindow() )
590 {
591 wxMessageBox("Application Error", "Could not transfer data to window", wxOK|wxICON_EXCLAMATION);
592 return FALSE;
593 }
594
595 node = node->Next();
596 }
597 return TRUE;
598}
7c78e7c7 599
01b2eeec
KB
600// Transfer values from controls. If returns FALSE,
601// validation failed: don't quit
602bool wxWindow::TransferDataFromWindow()
603{
604 wxNode *node = GetChildren()->First();
605 while ( node )
606 {
607 wxWindow *child = (wxWindow *)node->Data();
608 if ( child->GetValidator() && !child->GetValidator()->TransferFromWindow() )
609 {
610 return FALSE;
611 }
612
613 node = node->Next();
614 }
615 return TRUE;
616}
617
618bool wxWindow::Validate()
7c78e7c7 619{
01b2eeec
KB
620 wxNode *node = GetChildren()->First();
621 while ( node )
622 {
623 wxWindow *child = (wxWindow *)node->Data();
624 if ( child->GetValidator() && /* child->GetValidator()->Ok() && */ !child->GetValidator()->Validate(this) )
625 {
626 return FALSE;
627 }
7c78e7c7 628
01b2eeec
KB
629 node = node->Next();
630 }
631 return TRUE;
632}
633
634// Get the window with the focus
635wxWindow *wxWindow::FindFocus()
7c78e7c7 636{
01b2eeec
KB
637 // TODO
638 return NULL;
639}
7c78e7c7 640
01b2eeec 641void wxWindow::AddChild(wxWindow *child)
7c78e7c7 642{
01b2eeec
KB
643 GetChildren()->Append(child);
644 child->m_windowParent = this;
645}
7c78e7c7 646
01b2eeec 647void wxWindow::RemoveChild(wxWindow *child)
7c78e7c7 648{
01b2eeec
KB
649 if (GetChildren())
650 GetChildren()->DeleteObject(child);
651 child->m_windowParent = NULL;
652}
7c78e7c7 653
01b2eeec 654void wxWindow::DestroyChildren()
7c78e7c7 655{
01b2eeec
KB
656 if (GetChildren()) {
657 wxNode *node;
658 while ((node = GetChildren()->First()) != (wxNode *)NULL) {
659 wxWindow *child;
660 if ((child = (wxWindow *)node->Data()) != (wxWindow *)NULL) {
661 delete child;
662 if ( GetChildren()->Member(child) )
663 delete node;
664 }
665 } /* while */
666 }
667}
7c78e7c7 668
01b2eeec 669void wxWindow::MakeModal(bool modal)
7c78e7c7 670{
01b2eeec
KB
671 // Disable all other windows
672 if (this->IsKindOf(CLASSINFO(wxDialog)) || this->IsKindOf(CLASSINFO(wxFrame)))
673 {
674 wxNode *node = wxTopLevelWindows.First();
675 while (node)
676 {
677 wxWindow *win = (wxWindow *)node->Data();
678 if (win != this)
679 win->Enable(!modal);
7c78e7c7 680
01b2eeec
KB
681 node = node->Next();
682 }
683 }
684}
7c78e7c7 685
01b2eeec
KB
686// If nothing defined for this, try the parent.
687// E.g. we may be a button loaded from a resource, with no callback function
688// defined.
689void wxWindow::OnCommand(wxWindow& win, wxCommandEvent& event)
7c78e7c7 690{
01b2eeec
KB
691 if (GetEventHandler()->ProcessEvent(event) )
692 return;
693 if (m_windowParent)
694 m_windowParent->GetEventHandler()->OnCommand(win, event);
695}
7c78e7c7 696
01b2eeec 697void wxWindow::SetConstraints(wxLayoutConstraints *c)
7c78e7c7
RR
698{
699 if (m_constraints)
700 {
701 UnsetConstraints(m_constraints);
702 delete m_constraints;
703 }
01b2eeec 704 m_constraints = c;
7c78e7c7
RR
705 if (m_constraints)
706 {
707 // Make sure other windows know they're part of a 'meaningful relationship'
708 if (m_constraints->left.GetOtherWindow() && (m_constraints->left.GetOtherWindow() != this))
709 m_constraints->left.GetOtherWindow()->AddConstraintReference((wxWindow *)this);
710 if (m_constraints->top.GetOtherWindow() && (m_constraints->top.GetOtherWindow() != this))
711 m_constraints->top.GetOtherWindow()->AddConstraintReference((wxWindow *)this);
712 if (m_constraints->right.GetOtherWindow() && (m_constraints->right.GetOtherWindow() != this))
713 m_constraints->right.GetOtherWindow()->AddConstraintReference((wxWindow *)this);
714 if (m_constraints->bottom.GetOtherWindow() && (m_constraints->bottom.GetOtherWindow() != this))
715 m_constraints->bottom.GetOtherWindow()->AddConstraintReference((wxWindow *)this);
716 if (m_constraints->width.GetOtherWindow() && (m_constraints->width.GetOtherWindow() != this))
717 m_constraints->width.GetOtherWindow()->AddConstraintReference((wxWindow *)this);
718 if (m_constraints->height.GetOtherWindow() && (m_constraints->height.GetOtherWindow() != this))
719 m_constraints->height.GetOtherWindow()->AddConstraintReference((wxWindow *)this);
720 if (m_constraints->centreX.GetOtherWindow() && (m_constraints->centreX.GetOtherWindow() != this))
721 m_constraints->centreX.GetOtherWindow()->AddConstraintReference((wxWindow *)this);
722 if (m_constraints->centreY.GetOtherWindow() && (m_constraints->centreY.GetOtherWindow() != this))
723 m_constraints->centreY.GetOtherWindow()->AddConstraintReference((wxWindow *)this);
724 }
7c78e7c7 725}
7c78e7c7
RR
726
727// This removes any dangling pointers to this window
728// in other windows' constraintsInvolvedIn lists.
729void wxWindow::UnsetConstraints(wxLayoutConstraints *c)
730{
731 if (c)
732 {
733 if (c->left.GetOtherWindow() && (c->top.GetOtherWindow() != this))
734 c->left.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this);
735 if (c->top.GetOtherWindow() && (c->top.GetOtherWindow() != this))
736 c->top.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this);
737 if (c->right.GetOtherWindow() && (c->right.GetOtherWindow() != this))
738 c->right.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this);
739 if (c->bottom.GetOtherWindow() && (c->bottom.GetOtherWindow() != this))
740 c->bottom.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this);
741 if (c->width.GetOtherWindow() && (c->width.GetOtherWindow() != this))
742 c->width.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this);
743 if (c->height.GetOtherWindow() && (c->height.GetOtherWindow() != this))
744 c->height.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this);
745 if (c->centreX.GetOtherWindow() && (c->centreX.GetOtherWindow() != this))
746 c->centreX.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this);
747 if (c->centreY.GetOtherWindow() && (c->centreY.GetOtherWindow() != this))
748 c->centreY.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this);
749 }
750}
751
752// Back-pointer to other windows we're involved with, so if we delete
753// this window, we must delete any constraints we're involved with.
754void wxWindow::AddConstraintReference(wxWindow *otherWin)
755{
756 if (!m_constraintsInvolvedIn)
757 m_constraintsInvolvedIn = new wxList;
758 if (!m_constraintsInvolvedIn->Member(otherWin))
759 m_constraintsInvolvedIn->Append(otherWin);
760}
761
762// REMOVE back-pointer to other windows we're involved with.
763void wxWindow::RemoveConstraintReference(wxWindow *otherWin)
764{
765 if (m_constraintsInvolvedIn)
766 m_constraintsInvolvedIn->DeleteObject(otherWin);
767}
768
769// Reset any constraints that mention this window
01b2eeec 770void wxWindow::DeleteRelatedConstraints()
7c78e7c7
RR
771{
772 if (m_constraintsInvolvedIn)
773 {
774 wxNode *node = m_constraintsInvolvedIn->First();
775 while (node)
776 {
777 wxWindow *win = (wxWindow *)node->Data();
778 wxNode *next = node->Next();
779 wxLayoutConstraints *constr = win->GetConstraints();
780
781 // Reset any constraints involving this window
782 if (constr)
783 {
784 constr->left.ResetIfWin((wxWindow *)this);
785 constr->top.ResetIfWin((wxWindow *)this);
786 constr->right.ResetIfWin((wxWindow *)this);
787 constr->bottom.ResetIfWin((wxWindow *)this);
788 constr->width.ResetIfWin((wxWindow *)this);
789 constr->height.ResetIfWin((wxWindow *)this);
790 constr->centreX.ResetIfWin((wxWindow *)this);
791 constr->centreY.ResetIfWin((wxWindow *)this);
792 }
793 delete node;
794 node = next;
795 }
796 delete m_constraintsInvolvedIn;
797 m_constraintsInvolvedIn = NULL;
798 }
799}
800
801void wxWindow::SetSizer(wxSizer *sizer)
802{
803 m_windowSizer = sizer;
804 if (sizer)
805 sizer->SetSizerParent((wxWindow *)this);
806}
807
808/*
809 * New version
810 */
811
01b2eeec 812bool wxWindow::Layout()
7c78e7c7
RR
813{
814 if (GetConstraints())
815 {
816 int w, h;
817 GetClientSize(&w, &h);
818 GetConstraints()->width.SetValue(w);
819 GetConstraints()->height.SetValue(h);
820 }
821
822 // If top level (one sizer), evaluate the sizer's constraints.
823 if (GetSizer())
824 {
825 int noChanges;
826 GetSizer()->ResetConstraints(); // Mark all constraints as unevaluated
827 GetSizer()->LayoutPhase1(&noChanges);
828 GetSizer()->LayoutPhase2(&noChanges);
829 GetSizer()->SetConstraintSizes(); // Recursively set the real window sizes
830 return TRUE;
831 }
832 else
833 {
834 // Otherwise, evaluate child constraints
835 ResetConstraints(); // Mark all constraints as unevaluated
836 DoPhase(1); // Just one phase need if no sizers involved
837 DoPhase(2);
838 SetConstraintSizes(); // Recursively set the real window sizes
839 }
840 return TRUE;
841}
842
843
844// Do a phase of evaluating constraints:
845// the default behaviour. wxSizers may do a similar
846// thing, but also impose their own 'constraints'
847// and order the evaluation differently.
848bool wxWindow::LayoutPhase1(int *noChanges)
849{
850 wxLayoutConstraints *constr = GetConstraints();
851 if (constr)
852 {
853 return constr->SatisfyConstraints((wxWindow *)this, noChanges);
854 }
855 else
856 return TRUE;
857}
858
859bool wxWindow::LayoutPhase2(int *noChanges)
860{
861 *noChanges = 0;
862
863 // Layout children
864 DoPhase(1);
865 DoPhase(2);
866 return TRUE;
867}
868
869// Do a phase of evaluating child constraints
870bool wxWindow::DoPhase(int phase)
871{
872 int noIterations = 0;
873 int maxIterations = 500;
874 int noChanges = 1;
875 int noFailures = 0;
876 wxList succeeded;
877 while ((noChanges > 0) && (noIterations < maxIterations))
878 {
879 noChanges = 0;
880 noFailures = 0;
881 wxNode *node = GetChildren()->First();
882 while (node)
883 {
884 wxWindow *child = (wxWindow *)node->Data();
885 if (!child->IsKindOf(CLASSINFO(wxFrame)) && !child->IsKindOf(CLASSINFO(wxDialog)))
886 {
887 wxLayoutConstraints *constr = child->GetConstraints();
888 if (constr)
889 {
890 if (succeeded.Member(child))
891 {
892 }
893 else
894 {
895 int tempNoChanges = 0;
896 bool success = ( (phase == 1) ? child->LayoutPhase1(&tempNoChanges) : child->LayoutPhase2(&tempNoChanges) ) ;
897 noChanges += tempNoChanges;
898 if (success)
899 {
900 succeeded.Append(child);
901 }
902 }
903 }
904 }
905 node = node->Next();
906 }
907 noIterations ++;
908 }
909 return TRUE;
910}
911
01b2eeec 912void wxWindow::ResetConstraints()
7c78e7c7
RR
913{
914 wxLayoutConstraints *constr = GetConstraints();
915 if (constr)
916 {
917 constr->left.SetDone(FALSE);
918 constr->top.SetDone(FALSE);
919 constr->right.SetDone(FALSE);
920 constr->bottom.SetDone(FALSE);
921 constr->width.SetDone(FALSE);
922 constr->height.SetDone(FALSE);
923 constr->centreX.SetDone(FALSE);
924 constr->centreY.SetDone(FALSE);
925 }
926 wxNode *node = GetChildren()->First();
927 while (node)
928 {
929 wxWindow *win = (wxWindow *)node->Data();
930 if (!win->IsKindOf(CLASSINFO(wxFrame)) && !win->IsKindOf(CLASSINFO(wxDialog)))
931 win->ResetConstraints();
932 node = node->Next();
933 }
934}
935
936// Need to distinguish between setting the 'fake' size for
937// windows and sizers, and setting the real values.
938void wxWindow::SetConstraintSizes(bool recurse)
939{
940 wxLayoutConstraints *constr = GetConstraints();
941 if (constr && constr->left.GetDone() && constr->right.GetDone() &&
942 constr->width.GetDone() && constr->height.GetDone())
943 {
944 int x = constr->left.GetValue();
945 int y = constr->top.GetValue();
946 int w = constr->width.GetValue();
947 int h = constr->height.GetValue();
948
949 // If we don't want to resize this window, just move it...
950 if ((constr->width.GetRelationship() != wxAsIs) ||
951 (constr->height.GetRelationship() != wxAsIs))
952 {
953 // Calls Layout() recursively. AAAGH. How can we stop that.
954 // Simply take Layout() out of non-top level OnSizes.
955 SizerSetSize(x, y, w, h);
956 }
957 else
958 {
959 SizerMove(x, y);
960 }
961 }
962 else if (constr)
963 {
964 char *windowClass = this->GetClassInfo()->GetClassName();
965
966 wxString winName;
01b2eeec
KB
967 if (GetName() == "")
968 winName = "unnamed";
969 else
970 winName = GetName();
7c78e7c7
RR
971 wxDebugMsg("Constraint(s) not satisfied for window of type %s, name %s:\n", (const char *)windowClass, (const char *)winName);
972 if (!constr->left.GetDone())
973 wxDebugMsg(" unsatisfied 'left' constraint.\n");
974 if (!constr->right.GetDone())
975 wxDebugMsg(" unsatisfied 'right' constraint.\n");
976 if (!constr->width.GetDone())
977 wxDebugMsg(" unsatisfied 'width' constraint.\n");
978 if (!constr->height.GetDone())
979 wxDebugMsg(" unsatisfied 'height' constraint.\n");
980 wxDebugMsg("Please check constraints: try adding AsIs() constraints.\n");
981 }
982
983 if (recurse)
984 {
985 wxNode *node = GetChildren()->First();
986 while (node)
987 {
988 wxWindow *win = (wxWindow *)node->Data();
989 if (!win->IsKindOf(CLASSINFO(wxFrame)) && !win->IsKindOf(CLASSINFO(wxDialog)))
990 win->SetConstraintSizes();
991 node = node->Next();
992 }
993 }
994}
995
996// This assumes that all sizers are 'on' the same
997// window, i.e. the parent of this window.
998void wxWindow::TransformSizerToActual(int *x, int *y) const
999{
1000 if (!m_sizerParent || m_sizerParent->IsKindOf(CLASSINFO(wxDialog)) ||
01b2eeec 1001 m_sizerParent->IsKindOf(CLASSINFO(wxFrame)) )
7c78e7c7
RR
1002 return;
1003
1004 int xp, yp;
1005 m_sizerParent->GetPosition(&xp, &yp);
1006 m_sizerParent->TransformSizerToActual(&xp, &yp);
1007 *x += xp;
1008 *y += yp;
1009}
1010
1011void wxWindow::SizerSetSize(int x, int y, int w, int h)
1012{
01b2eeec
KB
1013 int xx = x;
1014 int yy = y;
7c78e7c7
RR
1015 TransformSizerToActual(&xx, &yy);
1016 SetSize(xx, yy, w, h);
1017}
1018
1019void wxWindow::SizerMove(int x, int y)
1020{
01b2eeec
KB
1021 int xx = x;
1022 int yy = y;
7c78e7c7
RR
1023 TransformSizerToActual(&xx, &yy);
1024 Move(xx, yy);
1025}
1026
1027// Only set the size/position of the constraint (if any)
1028void wxWindow::SetSizeConstraint(int x, int y, int w, int h)
1029{
1030 wxLayoutConstraints *constr = GetConstraints();
1031 if (constr)
1032 {
1033 if (x != -1)
1034 {
1035 constr->left.SetValue(x);
1036 constr->left.SetDone(TRUE);
1037 }
1038 if (y != -1)
1039 {
1040 constr->top.SetValue(y);
1041 constr->top.SetDone(TRUE);
1042 }
1043 if (w != -1)
1044 {
1045 constr->width.SetValue(w);
1046 constr->width.SetDone(TRUE);
1047 }
1048 if (h != -1)
1049 {
1050 constr->height.SetValue(h);
1051 constr->height.SetDone(TRUE);
1052 }
1053 }
1054}
1055
1056void wxWindow::MoveConstraint(int x, int y)
1057{
1058 wxLayoutConstraints *constr = GetConstraints();
1059 if (constr)
1060 {
1061 if (x != -1)
1062 {
1063 constr->left.SetValue(x);
1064 constr->left.SetDone(TRUE);
1065 }
1066 if (y != -1)
1067 {
1068 constr->top.SetValue(y);
1069 constr->top.SetDone(TRUE);
1070 }
1071 }
1072}
1073
1074void wxWindow::GetSizeConstraint(int *w, int *h) const
1075{
1076 wxLayoutConstraints *constr = GetConstraints();
1077 if (constr)
1078 {
1079 *w = constr->width.GetValue();
1080 *h = constr->height.GetValue();
1081 }
1082 else
1083 GetSize(w, h);
1084}
1085
1086void wxWindow::GetClientSizeConstraint(int *w, int *h) const
1087{
1088 wxLayoutConstraints *constr = GetConstraints();
1089 if (constr)
1090 {
1091 *w = constr->width.GetValue();
1092 *h = constr->height.GetValue();
1093 }
1094 else
1095 GetClientSize(w, h);
1096}
1097
1098void wxWindow::GetPositionConstraint(int *x, int *y) const
1099{
1100 wxLayoutConstraints *constr = GetConstraints();
1101 if (constr)
1102 {
1103 *x = constr->left.GetValue();
1104 *y = constr->top.GetValue();
1105 }
1106 else
1107 GetPosition(x, y);
1108}
1109
01b2eeec
KB
1110bool wxWindow::Close(bool force)
1111{
1112 wxCloseEvent event(wxEVT_CLOSE_WINDOW, m_windowId);
1113 event.SetEventObject(this);
e3065973 1114#if WXWIN_COMPATIBILITY
01b2eeec 1115 event.SetForce(force);
e3065973
JS
1116#endif
1117 event.SetCanVeto(!force);
01b2eeec
KB
1118
1119 return GetEventHandler()->ProcessEvent(event);
1120}
1121
1122wxObject* wxWindow::GetChild(int number) const
1123{
1124 // Return a pointer to the Nth object in the window
1125 if (!GetChildren())
1126 return(NULL) ;
1127 wxNode *node = GetChildren()->First();
1128 int n = number;
1129 while (node && n--)
1130 node = node->Next() ;
1131 if (node)
1132 {
1133 wxObject *obj = (wxObject *)node->Data();
1134 return(obj) ;
1135 }
1136 else
1137 return NULL ;
1138}
1139
1140void wxWindow::OnDefaultAction(wxControl *initiatingItem)
1141{
1142 // Obsolete function
1143}
1144
1145void wxWindow::Clear()
1146{
1147 wxClientDC dc(this);
1148 wxBrush brush(GetBackgroundColour(), wxSOLID);
1149 dc.SetBackground(brush);
1150 dc.Clear();
1151}
1152
1153// Fits the panel around the items
1154void wxWindow::Fit()
1155{
1156 int maxX = 0;
1157 int maxY = 0;
1158 wxNode *node = GetChildren()->First();
1159 while ( node )
1160 {
1161 wxWindow *win = (wxWindow *)node->Data();
1162 int wx, wy, ww, wh;
1163 win->GetPosition(&wx, &wy);
1164 win->GetSize(&ww, &wh);
1165 if ( wx + ww > maxX )
1166 maxX = wx + ww;
1167 if ( wy + wh > maxY )
1168 maxY = wy + wh;
1169
1170 node = node->Next();
1171 }
1172 SetClientSize(maxX + 5, maxY + 5);
1173}
1174
1175void wxWindow::SetValidator(const wxValidator& validator)
1176{
1177 if ( m_windowValidator )
1178 delete m_windowValidator;
1179 m_windowValidator = validator.Clone();
1180
1181 if ( m_windowValidator )
1182 m_windowValidator->SetWindow(this) ;
1183}
1184
1185// Find a window by id or name
1186wxWindow *wxWindow::FindWindow(long id)
1187{
1188 if ( GetId() == id)
1189 return this;
1190
1191 wxNode *node = GetChildren()->First();
1192 while ( node )
1193 {
1194 wxWindow *child = (wxWindow *)node->Data();
1195 wxWindow *found = child->FindWindow(id);
1196 if ( found )
1197 return found;
1198 node = node->Next();
1199 }
1200 return NULL;
1201}
1202
1203wxWindow *wxWindow::FindWindow(const wxString& name)
1204{
1205 if ( GetName() == name)
1206 return this;
1207
1208 wxNode *node = GetChildren()->First();
1209 while ( node )
1210 {
1211 wxWindow *child = (wxWindow *)node->Data();
1212 wxWindow *found = child->FindWindow(name);
1213 if ( found )
1214 return found;
1215 node = node->Next();
1216 }
1217 return NULL;
1218}
1219
1220void wxWindow::OnIdle(wxIdleEvent& event)
1221{
1222/* TODO: you may need to do something like this
1223 * if your GUI doesn't generate enter/leave events
1224
1225 // Check if we need to send a LEAVE event
1226 if (m_mouseInWindow)
1227 {
1228 POINT pt;
1229 ::GetCursorPos(&pt);
1230 if (::WindowFromPoint(pt) != (HWND) GetHWND())
1231 {
1232 // Generate a LEAVE event
1233 m_mouseInWindow = FALSE;
1234 MSWOnMouseLeave(pt.x, pt.y, 0);
1235 }
1236 }
1237*/
1238
1239 // This calls the UI-update mechanism (querying windows for
1240 // menu/toolbar/control state information)
1241 UpdateWindowUI();
1242}
1243
1244// Raise the window to the top of the Z order
1245void wxWindow::Raise()
1246{
1247 // TODO
1248}
1249
1250// Lower the window to the bottom of the Z order
1251void wxWindow::Lower()
1252{
1253 // TODO
1254}
1255
7c78e7c7
RR
1256bool wxWindow::AcceptsFocus() const
1257{
01b2eeec
KB
1258 return IsShown() && IsEnabled();
1259}
1260
1261// Update region access
1262wxRegion wxWindow::GetUpdateRegion() const
1263{
1264 return m_updateRegion;
7c78e7c7
RR
1265}
1266
01b2eeec 1267bool wxWindow::IsExposed(int x, int y, int w, int h) const
7c78e7c7 1268{
01b2eeec 1269 return (m_updateRegion.Contains(x, y, w, h) != wxOutRegion);
7c78e7c7 1270}
01b2eeec
KB
1271
1272bool wxWindow::IsExposed(const wxPoint& pt) const
1273{
1274 return (m_updateRegion.Contains(pt) != wxOutRegion);
1275}
1276
1277bool wxWindow::IsExposed(const wxRect& rect) const
1278{
1279 return (m_updateRegion.Contains(rect) != wxOutRegion);
1280}
1281
1282