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