- *noChanges = 0;
-
- // Layout children
- DoPhase(1);
- DoPhase(2);
- return TRUE;
-}
-
-// Do a phase of evaluating child constraints
-bool wxWindow::DoPhase(int phase)
-{
- int noIterations = 0;
- int maxIterations = 500;
- int noChanges = 1;
- int noFailures = 0;
- wxList succeeded;
- while ((noChanges > 0) && (noIterations < maxIterations))
- {
- noChanges = 0;
- noFailures = 0;
- wxNode *node = GetChildren().First();
- while (node)
- {
- wxWindow *child = (wxWindow *)node->Data();
- if (!child->IsKindOf(CLASSINFO(wxFrame)) && !child->IsKindOf(CLASSINFO(wxDialog)))
- {
- wxLayoutConstraints *constr = child->GetConstraints();
- if (constr)
- {
- if (succeeded.Member(child))
- {
- }
- else
- {
- int tempNoChanges = 0;
- bool success = ( (phase == 1) ? child->LayoutPhase1(&tempNoChanges) : child->LayoutPhase2(&tempNoChanges) ) ;
- noChanges += tempNoChanges;
- if (success)
- {
- succeeded.Append(child);
- }
- }
- }
- }
- node = node->Next();
- }
- noIterations ++;
- }
- return TRUE;
-}
-
-void wxWindow::ResetConstraints()
-{
- wxLayoutConstraints *constr = GetConstraints();
- if (constr)
- {
- constr->left.SetDone(FALSE);
- constr->top.SetDone(FALSE);
- constr->right.SetDone(FALSE);
- constr->bottom.SetDone(FALSE);
- constr->width.SetDone(FALSE);
- constr->height.SetDone(FALSE);
- constr->centreX.SetDone(FALSE);
- constr->centreY.SetDone(FALSE);
- }
- wxNode *node = GetChildren().First();
- while (node)
- {
- wxWindow *win = (wxWindow *)node->Data();
- if (!win->IsKindOf(CLASSINFO(wxFrame)) && !win->IsKindOf(CLASSINFO(wxDialog)))
- win->ResetConstraints();
- node = node->Next();
- }
-}
-
-// Need to distinguish between setting the 'fake' size for
-// windows and sizers, and setting the real values.
-void wxWindow::SetConstraintSizes(bool recurse)
-{
- wxLayoutConstraints *constr = GetConstraints();
- if (constr && constr->left.GetDone() && constr->right.GetDone() &&
- constr->width.GetDone() && constr->height.GetDone())
- {
- int x = constr->left.GetValue();
- int y = constr->top.GetValue();
- int w = constr->width.GetValue();
- int h = constr->height.GetValue();
-
- // If we don't want to resize this window, just move it...
- if ((constr->width.GetRelationship() != wxAsIs) ||
- (constr->height.GetRelationship() != wxAsIs))
- {
- // Calls Layout() recursively. AAAGH. How can we stop that.
- // Simply take Layout() out of non-top level OnSizes.
- SizerSetSize(x, y, w, h);
- }
- else
- {
- SizerMove(x, y);
- }
- }
- else if (constr)
- {
- char *windowClass = this->GetClassInfo()->GetClassName();
-
- wxString winName;
- if (GetName() == "")
- winName = "unnamed";
- else
- winName = GetName();
- wxDebugMsg("Constraint(s) not satisfied for window of type %s, name %s:\n", (const char *)windowClass, (const char *)winName);
- if (!constr->left.GetDone())
- wxDebugMsg(" unsatisfied 'left' constraint.\n");
- if (!constr->right.GetDone())
- wxDebugMsg(" unsatisfied 'right' constraint.\n");
- if (!constr->width.GetDone())
- wxDebugMsg(" unsatisfied 'width' constraint.\n");
- if (!constr->height.GetDone())
- wxDebugMsg(" unsatisfied 'height' constraint.\n");
- wxDebugMsg("Please check constraints: try adding AsIs() constraints.\n");
- }
-
- if (recurse)
- {
- wxNode *node = GetChildren().First();
- while (node)
- {
- wxWindow *win = (wxWindow *)node->Data();
- if (!win->IsKindOf(CLASSINFO(wxFrame)) && !win->IsKindOf(CLASSINFO(wxDialog)))
- win->SetConstraintSizes();
- node = node->Next();
- }
- }
-}
-
-// This assumes that all sizers are 'on' the same
-// window, i.e. the parent of this window.
-void wxWindow::TransformSizerToActual(int *x, int *y) const
-{
- if (!m_sizerParent || m_sizerParent->IsKindOf(CLASSINFO(wxDialog)) ||
- m_sizerParent->IsKindOf(CLASSINFO(wxFrame)) )
- return;
-
- int xp, yp;
- m_sizerParent->GetPosition(&xp, &yp);
- m_sizerParent->TransformSizerToActual(&xp, &yp);
- *x += xp;
- *y += yp;
-}
-
-void wxWindow::SizerSetSize(int x, int y, int w, int h)
-{
- int xx = x;
- int yy = y;
- TransformSizerToActual(&xx, &yy);
- SetSize(xx, yy, w, h);
-}
-
-void wxWindow::SizerMove(int x, int y)
-{
- int xx = x;
- int yy = y;
- TransformSizerToActual(&xx, &yy);
- Move(xx, yy);
-}
-
-// Only set the size/position of the constraint (if any)
-void wxWindow::SetSizeConstraint(int x, int y, int w, int h)
-{
- wxLayoutConstraints *constr = GetConstraints();
- if (constr)
- {
- if (x != -1)
- {
- constr->left.SetValue(x);
- constr->left.SetDone(TRUE);
- }
- if (y != -1)
- {
- constr->top.SetValue(y);
- constr->top.SetDone(TRUE);
- }
- if (w != -1)
- {
- constr->width.SetValue(w);
- constr->width.SetDone(TRUE);
- }
- if (h != -1)
- {
- constr->height.SetValue(h);
- constr->height.SetDone(TRUE);
- }
- }
-}
-
-void wxWindow::MoveConstraint(int x, int y)
-{
- wxLayoutConstraints *constr = GetConstraints();
- if (constr)
- {
- if (x != -1)
- {
- constr->left.SetValue(x);
- constr->left.SetDone(TRUE);
- }
- if (y != -1)
- {
- constr->top.SetValue(y);
- constr->top.SetDone(TRUE);
- }
- }
-}
-
-void wxWindow::GetSizeConstraint(int *w, int *h) const
-{
- wxLayoutConstraints *constr = GetConstraints();
- if (constr)
- {
- *w = constr->width.GetValue();
- *h = constr->height.GetValue();
- }
- else
- GetSize(w, h);
-}
-
-void wxWindow::GetClientSizeConstraint(int *w, int *h) const
-{
- wxLayoutConstraints *constr = GetConstraints();
- if (constr)
- {
- *w = constr->width.GetValue();
- *h = constr->height.GetValue();
- }
- else
- GetClientSize(w, h);
-}
-
-void wxWindow::GetPositionConstraint(int *x, int *y) const
-{
- wxLayoutConstraints *constr = GetConstraints();
- if (constr)
- {
- *x = constr->left.GetValue();
- *y = constr->top.GetValue();
- }
- else
- GetPosition(x, y);
-}
-
-bool wxWindow::Close(bool force)
-{
- wxCloseEvent event(wxEVT_CLOSE_WINDOW, m_windowId);
- event.SetEventObject(this);
- event.SetForce(force);
-
- return GetEventHandler()->ProcessEvent(event);
-}
-
-wxObject* wxWindow::GetChild(int number) const
-{
- // Return a pointer to the Nth object in the window
- wxNode *node = GetChildren().First();
- int n = number;
- while (node && n--)
- node = node->Next() ;
- if (node)
- {
- wxObject *obj = (wxObject *)node->Data();
- return(obj) ;
- }
- else
- return NULL ;
-}
-
-void wxWindow::OnDefaultAction(wxControl *initiatingItem)
-{
- // Obsolete function
-}
-
-void wxWindow::Clear()
-{
- wxClientDC dc(this);
- wxBrush brush(GetBackgroundColour(), wxSOLID);
- dc.SetBackground(brush);
- dc.Clear();
-}
-
-// Fits the panel around the items
-void wxWindow::Fit()
-{
- int maxX = 0;
- int maxY = 0;
- wxNode *node = GetChildren().First();
- while ( node )
- {
- wxWindow *win = (wxWindow *)node->Data();
- int wx, wy, ww, wh;
- win->GetPosition(&wx, &wy);
- win->GetSize(&ww, &wh);
- if ( wx + ww > maxX )
- maxX = wx + ww;
- if ( wy + wh > maxY )
- maxY = wy + wh;
-
- node = node->Next();
- }
- SetClientSize(maxX + 5, maxY + 5);
-}
-
-void wxWindow::SetValidator(const wxValidator& validator)
-{
- if ( m_windowValidator )
- delete m_windowValidator;
- m_windowValidator = validator.Clone();
-
- if ( m_windowValidator )
- m_windowValidator->SetWindow(this) ;
-}
-
-void wxWindow::SetClientObject( wxClientData *data )
-{
- if (m_clientObject) delete m_clientObject;
- m_clientObject = data;
-}
-
-wxClientData *wxWindow::GetClientObject()
-{
- return m_clientObject;
-}
-
-void wxWindow::SetClientData( void *data )
-{
- m_clientData = data;
-}
-
-void *wxWindow::GetClientData()
-{
- return m_clientData;
-}
-
-// Find a window by id or name
-wxWindow *wxWindow::FindWindow(long id)
-{
- if ( GetId() == id)
- return this;
-
- wxNode *node = GetChildren().First();
- while ( node )
- {
- wxWindow *child = (wxWindow *)node->Data();
- wxWindow *found = child->FindWindow(id);
- if ( found )
- return found;
- node = node->Next();
- }
- return NULL;
-}
-
-wxWindow *wxWindow::FindWindow(const wxString& name)
-{
- if ( GetName() == name)
- return this;
-
- wxNode *node = GetChildren().First();
- while ( node )
- {
- wxWindow *child = (wxWindow *)node->Data();
- wxWindow *found = child->FindWindow(name);
- if ( found )
- return found;
- node = node->Next();
- }
- return NULL;
-}
-
-void wxWindow::OnIdle(wxIdleEvent& event)
-{
- // This calls the UI-update mechanism (querying windows for
- // menu/toolbar/control state information)
- UpdateWindowUI();
-}
-
-// Raise the window to the top of the Z order
-void wxWindow::Raise()
-{
- Window window = XtWindow((Widget) GetTopWidget());
- XRaiseWindow(XtDisplay((Widget) GetTopWidget()), window);
-}
-
-// Lower the window to the bottom of the Z order
-void wxWindow::Lower()
-{
- Window window = XtWindow((Widget) GetTopWidget());
- XLowerWindow(XtDisplay((Widget) GetTopWidget()), window);
-}
-
-bool wxWindow::AcceptsFocus() const
-{
- return IsShown() && IsEnabled();
-}
-
-// Update region access
-wxRegion& wxWindow::GetUpdateRegion() const
-{
- return (wxRegion&) m_updateRegion;
-}
-
-bool wxWindow::IsExposed(int x, int y, int w, int h) const
-{
- return (m_updateRegion.Contains(x, y, w, h) != wxOutRegion);
-}
-
-bool wxWindow::IsExposed(const wxPoint& pt) const
-{
- return (m_updateRegion.Contains(pt) != wxOutRegion);
-}
-
-bool wxWindow::IsExposed(const wxRect& rect) const
-{
- return (m_updateRegion.Contains(rect) != wxOutRegion);
-}
-
-/*
-* Allocates control IDs
-*/
-
-int wxWindow::NewControlId()
-{
- static int s_controlId = 0;
- s_controlId ++;
- return s_controlId;
-}
-
-void wxWindow::SetAcceleratorTable(const wxAcceleratorTable& accel)
-{
- m_acceleratorTable = accel;
-}
-
-// All widgets should have this as their resize proc.
-// OnSize sent to wxWindow via client data.
-void wxWidgetResizeProc(Widget w, XConfigureEvent *event, String args[], int *num_args)
-{
- wxWindow *win = (wxWindow *)wxWidgetHashTable->Get((long)w);
- if (!win)
- return;
-
- if (win->PreResize())
- {
- int width, height;
- win->GetSize(&width, &height);
- wxSizeEvent sizeEvent(wxSize(width, height), win->GetId());
- sizeEvent.SetEventObject(win);
- win->GetEventHandler()->ProcessEvent(sizeEvent);
- }
-}
-
-bool wxAddWindowToTable(Widget w, wxWindow *win)
-{
- wxWindow *oldItem = NULL;
- // printf("Adding widget %ld, name = %s\n", w, win->GetClassInfo()->GetClassName());
- if ((oldItem = (wxWindow *)wxWidgetHashTable->Get ((long) w)))
- {
- wxLogError("Widget table clash: new widget is %ld, %s", (long)w, win->GetClassInfo()->GetClassName());
- return FALSE;
- }
-
- wxWidgetHashTable->Put ((long) w, win);
- return TRUE;
-}
-
-wxWindow *wxGetWindowFromTable(Widget w)
-{
- return (wxWindow *)wxWidgetHashTable->Get ((long) w);
-}
-
-void wxDeleteWindowFromTable(Widget w)
-{
- wxWidgetHashTable->Delete((long)w);
-}
-
-// Get the underlying X window and display
-WXWindow wxWindow::GetXWindow() const
-{
- return (WXWindow) XtWindow((Widget) GetMainWidget());
-}
-
-WXDisplay *wxWindow::GetXDisplay() const
-{
- return (WXDisplay*) XtDisplay((Widget) GetMainWidget());
-}
-
-WXWidget wxWindow::GetMainWidget() const
-{
- if (m_drawingArea)
- return m_drawingArea;
- else
- return m_mainWidget;
-}
-
-WXWidget wxWindow::GetClientWidget() const
-{
- if (m_drawingArea != (WXWidget) 0)
- return m_drawingArea;
- else
- return GetMainWidget();
-}
-
-WXWidget wxWindow::GetTopWidget() const
-{
- return GetMainWidget();
-}
-
-void wxCanvasRepaintProc (Widget drawingArea, XtPointer clientData,
- XmDrawingAreaCallbackStruct * cbs)
-{
- if (!wxWidgetHashTable->Get ((long) (Widget) drawingArea))
- return;
-
- XEvent * event = cbs->event;
- wxWindow * win = (wxWindow *) clientData;
- Display * display = (Display *) win->GetXDisplay();
-
- switch (event->type)