- {
- if ( m_hScrollBar )
- return m_hScrollBar->GetThumbSize() ;
- }
- else
- {
- if ( m_vScrollBar )
- return m_vScrollBar->GetThumbSize() ;
- }
- return 0;
-}
-
-void wxWindow::SetScrollPos(int orient, int pos, bool refresh)
-{
- if ( orient == wxHORIZONTAL )
- {
- if ( m_hScrollBar )
- m_hScrollBar->SetThumbPosition( pos ) ;
- }
- else
- {
- if ( m_vScrollBar )
- m_vScrollBar->SetThumbPosition( pos ) ;
- }
-}
-
-// New function that will replace some of the above.
-void wxWindow::SetScrollbar(int orient, int pos, int thumbVisible,
- int range, bool refresh)
-{
- if ( orient == wxHORIZONTAL )
- {
- if ( m_hScrollBar )
- {
- if ( range == 0 || thumbVisible >= range )
- {
- if ( m_hScrollBar->IsShown() )
- m_hScrollBar->Show(false) ;
- }
- else
- {
- if ( !m_hScrollBar->IsShown() )
- m_hScrollBar->Show(true) ;
- m_hScrollBar->SetScrollbar( pos , thumbVisible , range , refresh ) ;
- }
- }
- }
- else
- {
- if ( m_vScrollBar )
- {
- if ( range == 0 || thumbVisible >= range )
- {
- if ( m_vScrollBar->IsShown() )
- m_vScrollBar->Show(false) ;
- }
- else
- {
- if ( !m_vScrollBar->IsShown() )
- m_vScrollBar->Show(true) ;
- m_vScrollBar->SetScrollbar( pos , thumbVisible , range , refresh ) ;
- }
- }
- }
- MacRepositionScrollBars() ;
-}
-
-// Does a physical scroll
-void wxWindow::ScrollWindow(int dx, int dy, const wxRect *rect)
-{
- wxMacDrawingClientHelper focus( this ) ;
- if ( focus.Ok() )
- {
- int width , height ;
- GetClientSize( &width , &height ) ;
- Rect scrollrect = { 0 , 0 , height , width } ;
-
- RgnHandle updateRgn = NewRgn() ;
- ClipRect( &scrollrect ) ;
- if ( rect )
- {
- Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
- SectRect( &scrollrect , &r , &scrollrect ) ;
- }
- ScrollRect( &scrollrect , dx , dy , updateRgn ) ;
- InvalRgn( updateRgn ) ;
- DisposeRgn( updateRgn ) ;
- }
-}
-
-void wxWindow::SetFont(const wxFont& font)
-{
- m_windowFont = font;
-
- if (!m_windowFont.Ok())
- return;
- // TODO
-}
-
-void wxWindow::OnChar(wxKeyEvent& event)
-{
- if ( event.KeyCode() == WXK_TAB ) {
- // propagate the TABs to the parent - it's up to it to decide what
- // to do with it
- if ( GetParent() ) {
- if ( GetParent()->ProcessEvent(event) )
- return;
- }
- }
-}
-
-void wxWindow::OnPaint(wxPaintEvent& event)
-{
-/*
- if ( m_macWindowData )
- {
- wxMacDrawingClientHelper helper ( this ) ;
- long x ,y ,w ,h ;
- GetUpdateRegion().GetBox( x , y , w , h ) ;
- UMASetThemeWindowBackground( m_macWindowData->m_macWindow , m_macWindowData->m_macWindowBackgroundTheme , false ) ;
- Rect r = { y , x, y+h , x+w } ;
- EraseRect( &r ) ;
- }
- else
- {
- wxMacDrawingClientHelper helper ( this ) ;
- long x ,y ,w ,h ;
- GetUpdateRegion().GetBox( x , y , w , h ) ;
- RGBBackColor( &m_backgroundColour.GetPixel() ) ;
- Rect r = { y , x, y+h , x+w } ;
- EraseRect( &r ) ;
- }
-*/
-}
-
-bool wxWindow::IsEnabled() const
-{
- return m_macEnabled ;
-}
-
-// Dialog support: override these and call
-// base class members to add functionality
-// that can't be done using validators.
-// NOTE: these functions assume that controls
-// are direct children of this window, not grandchildren
-// or other levels of descendant.
-
-// Transfer values to controls. If returns FALSE,
-// it's an application error (pops up a dialog)
-bool wxWindow::TransferDataToWindow()
-{
- wxNode *node = GetChildren().First();
- while ( node )
- {
- wxWindow *child = (wxWindow *)node->Data();
- if ( child->GetValidator() &&
- !child->GetValidator()->TransferToWindow() )
- {
- wxMessageBox("Application Error", "Could not transfer data to window", wxOK|wxICON_EXCLAMATION);
- return FALSE;
- }
-
- node = node->Next();
- }
- return TRUE;
-}
-
-// Transfer values from controls. If returns FALSE,
-// validation failed: don't quit
-bool wxWindow::TransferDataFromWindow()
-{
- wxNode *node = GetChildren().First();
- while ( node )
- {
- wxWindow *child = (wxWindow *)node->Data();
- if ( child->GetValidator() && !child->GetValidator()->TransferFromWindow() )
- {
- return FALSE;
- }
-
- node = node->Next();
- }
- return TRUE;
-}
-
-bool wxWindow::Validate()
-{
- wxNode *node = GetChildren().First();
- while ( node )
- {
- wxWindow *child = (wxWindow *)node->Data();
- if ( child->GetValidator() && /* child->GetValidator()->Ok() && */ !child->GetValidator()->Validate(this) )
- {
- return FALSE;
- }
-
- node = node->Next();
- }
- return TRUE;
-}
-
-// Get the window with the focus
-wxWindow *wxWindow::FindFocus()
-{
- return gFocusWindow ;
-}
-
-// ----------------------------------------------------------------------------
-// RTTI
-// ----------------------------------------------------------------------------
-
-bool wxWindow::IsTopLevel() const
-{
- return wxDynamicCast(this, wxFrame) || wxDynamicCast(this, wxDialog);
-}
-
-void wxWindow::AddChild(wxWindow *child)
-{
- GetChildren().Append(child);
- child->m_windowParent = this;
-}
-
-void wxWindow::RemoveChild(wxWindow *child)
-{
- GetChildren().DeleteObject(child);
- child->m_windowParent = NULL;
-}
-
-void wxWindow::DestroyChildren()
-{
- wxNode *node;
- while ((node = GetChildren().First()) != (wxNode *)NULL) {
- wxWindow *child;
- if ((child = (wxWindow *)node->Data()) != (wxWindow *)NULL) {
- delete child;
- if ( GetChildren().Find(child) )
- delete node;
- }
- } /* while */
-}
-
-void wxWindow::MakeModal(bool modal)
-{
- // Disable all other windows
- if (this->IsKindOf(CLASSINFO(wxDialog)) || this->IsKindOf(CLASSINFO(wxFrame)))
- {
- wxNode *node = wxTopLevelWindows.First();
- while (node)
- {
- wxWindow *win = (wxWindow *)node->Data();
- if (win != this)
- win->Enable(!modal);
-
- node = node->Next();
- }
- }
-}
-
-// If nothing defined for this, try the parent.
-// E.g. we may be a button loaded from a resource, with no callback function
-// defined.
-void wxWindow::OnCommand(wxWindow& win, wxCommandEvent& event)
-{
- if (GetEventHandler()->ProcessEvent(event) )
- return;
- if (m_windowParent)
- m_windowParent->GetEventHandler()->OnCommand(win, event);
-}
-
-// ----------------------------------------------------------------------------
-// constraints and sizers
-// ----------------------------------------------------------------------------
-
-#if wxUSE_CONSTRAINTS
-
-void wxWindow::SetConstraints( wxLayoutConstraints *constraints )
-{
- if ( m_constraints )
- {
- UnsetConstraints(m_constraints);
- delete m_constraints;
- }
- m_constraints = constraints;
- if ( m_constraints )
- {
- // Make sure other windows know they're part of a 'meaningful relationship'
- if ( m_constraints->left.GetOtherWindow() && (m_constraints->left.GetOtherWindow() != this) )
- m_constraints->left.GetOtherWindow()->AddConstraintReference(this);
- if ( m_constraints->top.GetOtherWindow() && (m_constraints->top.GetOtherWindow() != this) )
- m_constraints->top.GetOtherWindow()->AddConstraintReference(this);
- if ( m_constraints->right.GetOtherWindow() && (m_constraints->right.GetOtherWindow() != this) )
- m_constraints->right.GetOtherWindow()->AddConstraintReference(this);
- if ( m_constraints->bottom.GetOtherWindow() && (m_constraints->bottom.GetOtherWindow() != this) )
- m_constraints->bottom.GetOtherWindow()->AddConstraintReference(this);
- if ( m_constraints->width.GetOtherWindow() && (m_constraints->width.GetOtherWindow() != this) )
- m_constraints->width.GetOtherWindow()->AddConstraintReference(this);
- if ( m_constraints->height.GetOtherWindow() && (m_constraints->height.GetOtherWindow() != this) )
- m_constraints->height.GetOtherWindow()->AddConstraintReference(this);
- if ( m_constraints->centreX.GetOtherWindow() && (m_constraints->centreX.GetOtherWindow() != this) )
- m_constraints->centreX.GetOtherWindow()->AddConstraintReference(this);
- if ( m_constraints->centreY.GetOtherWindow() && (m_constraints->centreY.GetOtherWindow() != this) )
- m_constraints->centreY.GetOtherWindow()->AddConstraintReference(this);
- }
-}
-
-// This removes any dangling pointers to this window in other windows'
-// constraintsInvolvedIn lists.
-void wxWindow::UnsetConstraints(wxLayoutConstraints *c)
-{
- if ( c )
- {
- if ( c->left.GetOtherWindow() && (c->top.GetOtherWindow() != this) )
- c->left.GetOtherWindow()->RemoveConstraintReference(this);
- if ( c->top.GetOtherWindow() && (c->top.GetOtherWindow() != this) )
- c->top.GetOtherWindow()->RemoveConstraintReference(this);
- if ( c->right.GetOtherWindow() && (c->right.GetOtherWindow() != this) )
- c->right.GetOtherWindow()->RemoveConstraintReference(this);
- if ( c->bottom.GetOtherWindow() && (c->bottom.GetOtherWindow() != this) )
- c->bottom.GetOtherWindow()->RemoveConstraintReference(this);
- if ( c->width.GetOtherWindow() && (c->width.GetOtherWindow() != this) )
- c->width.GetOtherWindow()->RemoveConstraintReference(this);
- if ( c->height.GetOtherWindow() && (c->height.GetOtherWindow() != this) )
- c->height.GetOtherWindow()->RemoveConstraintReference(this);
- if ( c->centreX.GetOtherWindow() && (c->centreX.GetOtherWindow() != this) )
- c->centreX.GetOtherWindow()->RemoveConstraintReference(this);
- if ( c->centreY.GetOtherWindow() && (c->centreY.GetOtherWindow() != this) )
- c->centreY.GetOtherWindow()->RemoveConstraintReference(this);
- }
-}
-
-// Back-pointer to other windows we're involved with, so if we delete this
-// window, we must delete any constraints we're involved with.
-void wxWindow::AddConstraintReference(wxWindow *otherWin)
-{
- if ( !m_constraintsInvolvedIn )
- m_constraintsInvolvedIn = new wxWindowList;
- if ( !m_constraintsInvolvedIn->Find(otherWin) )
- m_constraintsInvolvedIn->Append(otherWin);
-}
-
-// REMOVE back-pointer to other windows we're involved with.
-void wxWindow::RemoveConstraintReference(wxWindow *otherWin)
-{
- if ( m_constraintsInvolvedIn )
- m_constraintsInvolvedIn->DeleteObject(otherWin);
-}
-
-// Reset any constraints that mention this window
-void wxWindow::DeleteRelatedConstraints()
-{
- if ( m_constraintsInvolvedIn )
- {
- wxWindowList::Node *node = m_constraintsInvolvedIn->GetFirst();
- while (node)
- {
- wxWindow *win = node->GetData();
- wxLayoutConstraints *constr = win->GetConstraints();
-
- // Reset any constraints involving this window
- if ( constr )
- {
- constr->left.ResetIfWin(this);
- constr->top.ResetIfWin(this);
- constr->right.ResetIfWin(this);
- constr->bottom.ResetIfWin(this);
- constr->width.ResetIfWin(this);
- constr->height.ResetIfWin(this);
- constr->centreX.ResetIfWin(this);
- constr->centreY.ResetIfWin(this);
- }
-
- wxWindowList::Node *next = node->GetNext();
- delete node;
- node = next;
- }
-
- delete m_constraintsInvolvedIn;
- m_constraintsInvolvedIn = (wxWindowList *) NULL;
- }
-}
-
-void wxWindow::SetSizer(wxSizer *sizer)
-{
- if (m_windowSizer) delete m_windowSizer;
-
- m_windowSizer = sizer;
-}
-
-bool wxWindow::Layout()
-{
- int w, h;
- GetClientSize(&w, &h);
-
- // If there is a sizer, use it instead of the constraints
- if ( GetSizer() )
- {
- GetSizer()->SetDimension( 0, 0, w, h );
- return TRUE;
- }
-
- if ( GetConstraints() )
- {
- GetConstraints()->width.SetValue(w);
- GetConstraints()->height.SetValue(h);
- }
-
- // Evaluate child constraints
- ResetConstraints(); // Mark all constraints as unevaluated
- DoPhase(1); // Just one phase need if no sizers involved
- DoPhase(2);
- SetConstraintSizes(); // Recursively set the real window sizes
-
- return TRUE;
-}
-
-
-// Do a phase of evaluating constraints: the default behaviour. wxSizers may
-// do a similar thing, but also impose their own 'constraints' and order the
-// evaluation differently.
-bool wxWindow::LayoutPhase1(int *noChanges)
-{
- wxLayoutConstraints *constr = GetConstraints();
- if ( constr )
- {
- return constr->SatisfyConstraints(this, noChanges);
- }
- else
- return TRUE;
-}
-
-bool wxWindow::LayoutPhase2(int *noChanges)
-{
- *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;
- wxWindowList succeeded;
- while ((noChanges > 0) && (noIterations < maxIterations))
- {
- noChanges = 0;
- noFailures = 0;
- wxWindowList::Node *node = GetChildren().GetFirst();
- while (node)
- {
- wxWindow *child = node->GetData();
- if ( !child->IsTopLevel() )
- {
- wxLayoutConstraints *constr = child->GetConstraints();
- if ( constr )
- {
- if ( !succeeded.Find(child) )
- {
- int tempNoChanges = 0;
- bool success = ( (phase == 1) ? child->LayoutPhase1(&tempNoChanges) : child->LayoutPhase2(&tempNoChanges) ) ;
- noChanges += tempNoChanges;
- if ( success )
- {
- succeeded.Append(child);
- }
- }
- }
- }
- node = node->GetNext();
- }
-
- 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);
- }
- wxWindowList::Node *node = GetChildren().GetFirst();
- while (node)
- {
- wxWindow *win = node->GetData();
- if ( !win->IsTopLevel() )
- win->ResetConstraints();
- node = node->GetNext();
- }
-}
-
-// 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 ( (constr->width.GetRelationship() != wxAsIs ) ||
- (constr->height.GetRelationship() != wxAsIs) )
- {
- SetSize(x, y, w, h);
- }
- else
- {
- // If we don't want to resize this window, just move it...
- Move(x, y);
- }
- }
- else if ( constr )
- {
- char *windowClass = GetClassInfo()->GetClassName();
-
- wxString winName;
- if ( GetName() == _T("") )
- winName = _T("unnamed");
- else
- winName = GetName();
- wxLogDebug( _T("Constraint(s) not satisfied for window of type %s, name %s:\n"),
- (const char *)windowClass,
- (const char *)winName);
- if ( !constr->left.GetDone()) wxLogDebug( _T(" unsatisfied 'left' constraint.\n") );
- if ( !constr->right.GetDone()) wxLogDebug( _T(" unsatisfied 'right' constraint.\n") );
- if ( !constr->width.GetDone()) wxLogDebug( _T(" unsatisfied 'width' constraint.\n") );
- if ( !constr->height.GetDone()) wxLogDebug( _T(" unsatisfied 'height' constraint.\n") );
- wxLogDebug( _T("Please check constraints: try adding AsIs() constraints.\n") );
- }
-
- if ( recurse )
- {
- wxWindowList::Node *node = GetChildren().GetFirst();
- while (node)
- {
- wxWindow *win = node->GetData();
- if ( !win->IsTopLevel() )
- win->SetConstraintSizes();
- node = node->GetNext();
- }
- }