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