/////////////////////////////////////////////////////////////////////////////
-// Name: src/common/window.cpp
+// Name: src/common/wincmn.cpp
// Purpose: common (to all ports) wxWindow functions
// Author: Julian Smart, Vadim Zeitlin
// Modified by:
#include "wx/platinfo.h"
#include "wx/private/window.h"
-#ifdef __WXMSW__
+#ifdef __WINDOWS__
#include "wx/msw/wrapwin.h"
#endif
// separately otherwise chaos occurs. Right now easiest is to test for negative ids,
// as windows with negative ids never can be recreated anyway
+
bool wxWindowStreamingCallback( const wxObject *object, wxObjectWriter *,
- wxObjectReaderCallback *, wxVariantBaseArray & )
+ wxObjectWriterCallback *, const wxStringToAnyHashMap & )
{
const wxWindow * win = wx_dynamic_cast(const wxWindow*, object);
if ( win && win->GetId() < 0 )
wxCOLLECTION_TYPE_INFO( wxWindow*, wxWindowList );
template<> void wxCollectionToVariantArray( wxWindowList const &theList,
- wxVariantBaseArray &value)
+ wxAnyList &value)
{
- wxListCollectionToVariantArray<wxWindowList::compatibility_iterator>( theList, value );
+ wxListCollectionToAnyList<wxWindowList::compatibility_iterator>( theList, value );
}
wxDEFINE_FLAGS( wxWindowStyle )
wxEMPTY_PARAMETER_VALUE, 0 /*flags*/, wxT("Helpstring"), wxT("group")) // bg
wxPROPERTY( ForegroundColour, wxColour, SetForegroundColour, GetForegroundColour, \
wxEMPTY_PARAMETER_VALUE, 0 /*flags*/, wxT("Helpstring"), wxT("group")) // fg
-wxPROPERTY( Enabled, bool, Enable, IsEnabled, wxVariantBase((bool)true), 0 /*flags*/, \
+wxPROPERTY( Enabled, bool, Enable, IsEnabled, wxAny((bool)true), 0 /*flags*/, \
wxT("Helpstring"), wxT("group"))
-wxPROPERTY( Shown, bool, Show, IsShown, wxVariantBase((bool)true), 0 /*flags*/, \
+wxPROPERTY( Shown, bool, Show, IsShown, wxAny((bool)true), 0 /*flags*/, \
wxT("Helpstring"), wxT("group"))
#if 0
bool wxWindowBase::Destroy()
{
- SendDestroyEvent();
+ // If our handle is invalid, it means that this window has never been
+ // created, either because creating it failed or, more typically, because
+ // this wxWindow object was default-constructed and its Create() method had
+ // never been called. As we didn't send wxWindowCreateEvent in this case
+ // (which is sent after successful creation), don't send the matching
+ // wxWindowDestroyEvent neither.
+ if ( GetHandle() )
+ SendDestroyEvent();
delete this;
// fits the window around the children
void wxWindowBase::Fit()
{
- if ( !GetChildren().empty() )
- {
- SetSize(GetBestSize());
- }
- //else: do nothing if we have no children
+ SetSize(GetBestSize());
}
// fits virtual size (ie. scrolled area etc.) around children
void wxWindowBase::FitInside()
{
- if ( GetChildren().GetCount() > 0 )
- {
- SetVirtualSize( GetBestVirtualSize() );
- }
+ SetVirtualSize( GetBestVirtualSize() );
}
// On Mac, scrollbars are explicitly children.
wxWindow *win = node->GetData();
if ( !win->IsTopLevel() && win->IsShown()
#if wxUSE_SCROLLBAR
- && !win->IsKindOf(CLASSINFO(wxScrollBar))
+ && !wxDynamicCast(win, wxScrollBar)
#endif
)
realChildCount ++;
return size*2;
}
+bool
+wxWindowBase::InformFirstDirection(int direction,
+ int size,
+ int availableOtherDir)
+{
+ return GetSizer() && GetSizer()->InformFirstDirection(direction,
+ size,
+ availableOtherDir);
+}
+
wxSize wxWindowBase::GetEffectiveMinSize() const
{
// merge the best size with the min size, giving priority to the min size
// it to be used
wxSize size = DoGetBestClientSize();
if ( size != wxDefaultSize )
- {
size += DoGetBorderSize();
+ else
+ size = DoGetBestSize();
- CacheBestSize(size);
- return size;
- }
+ // Ensure that the best size is at least as large as min size.
+ size.IncTo(GetMinSize());
+
+ // And not larger than max size.
+ size.DecToIfSpecified(GetMaxSize());
+
+ // Finally cache result and return.
+ CacheBestSize(size);
+ return size;
+}
+
+int wxWindowBase::GetBestHeight(int width) const
+{
+ const int height = DoGetBestClientHeight(width);
+
+ return height == wxDefaultCoord
+ ? GetBestSize().y
+ : height + DoGetBorderSize().y;
+}
- return DoGetBestSize();
+int wxWindowBase::GetBestWidth(int height) const
+{
+ const int width = DoGetBestClientWidth(height);
+
+ return width == wxDefaultCoord
+ ? GetBestSize().x
+ : width + DoGetBorderSize().x;
}
void wxWindowBase::SetMinSize(const wxSize& minSize)
{
m_minWidth = minSize.x;
m_minHeight = minSize.y;
+
+ InvalidateBestSize();
}
void wxWindowBase::SetMaxSize(const wxSize& maxSize)
{
m_maxWidth = maxSize.x;
m_maxHeight = maxSize.y;
+
+ InvalidateBestSize();
}
void wxWindowBase::SetInitialSize(const wxSize& size)
wxSizeEvent event(GetSize(), GetId());
event.SetEventObject(this);
if ( flags & wxSEND_EVENT_POST )
- wxPostEvent(this, event);
+ wxPostEvent(GetEventHandler(), event);
else
HandleWindowEvent(event);
}
}
// ----------------------------------------------------------------------------
-// reparenting the window
+// Dealing with parents and children.
// ----------------------------------------------------------------------------
+bool wxWindowBase::IsDescendant(wxWindowBase* win) const
+{
+ // Iterate until we find this window in the parent chain or exhaust it.
+ while ( win )
+ {
+ if ( win == this )
+ return true;
+
+ // Stop iterating on reaching the top level window boundary.
+ if ( win->IsTopLevel() )
+ break;
+
+ win = win->GetParent();
+ }
+
+ return false;
+}
+
void wxWindowBase::AddChild(wxWindowBase *child)
{
wxCHECK_RET( child, wxT("can't add a NULL child") );
"the first handler of the wxWindow stack should have non-NULL next handler" );
firstHandler->SetNextHandler(NULL);
- secondHandler->SetPreviousHandler(NULL);
+
+ // It is harmless but useless to unset the previous handler of the window
+ // itself as it's always NULL anyhow, so don't do this.
+ if ( secondHandler != this )
+ secondHandler->SetPreviousHandler(NULL);
// now firstHandler is completely unlinked; set secondHandler as the new window event handler
SetEventHandler(secondHandler);
// wxWidgets versions where GetBackgroundColour() always returned
// something -- so give them something even if it doesn't make sense
// for this window (e.g. it has a themed background)
- if ( !colBg.Ok() )
+ if ( !colBg.IsOk() )
colBg = GetClassDefaultAttributes().colBg;
return colBg;
wxColour wxWindowBase::GetForegroundColour() const
{
// logic is the same as above
- if ( !m_hasFgCol && !m_foregroundColour.Ok() )
+ if ( !m_hasFgCol && !m_foregroundColour.IsOk() )
{
wxColour colFg = GetDefaultAttributes().colFg;
return m_foregroundColour;
}
+bool wxWindowBase::SetBackgroundStyle(wxBackgroundStyle style)
+{
+ // The checks below shouldn't be triggered if we're not really changing the
+ // style.
+ if ( style == m_backgroundStyle )
+ return true;
+
+ // Transparent background style can be only set before creation because of
+ // wxGTK limitation.
+ wxCHECK_MSG( (style != wxBG_STYLE_TRANSPARENT) || !GetHandle(),
+ false,
+ "wxBG_STYLE_TRANSPARENT style can only be set before "
+ "Create()-ing the window." );
+
+ // And once it is set, wxBG_STYLE_TRANSPARENT can't be unset.
+ wxCHECK_MSG( (m_backgroundStyle != wxBG_STYLE_TRANSPARENT) ||
+ (style == wxBG_STYLE_TRANSPARENT),
+ false,
+ "wxBG_STYLE_TRANSPARENT can't be unset once it was set." );
+
+ m_backgroundStyle = style;
+
+ return true;
+}
+
+bool wxWindowBase::IsTransparentBackgroundSupported(wxString *reason) const
+{
+ if ( reason )
+ *reason = _("This platform does not support background transparency.");
+
+ return false;
+}
+
bool wxWindowBase::SetBackgroundColour( const wxColour &colour )
{
if ( colour == m_backgroundColour )
m_inheritBgCol = m_hasBgCol;
m_backgroundColour = colour;
- SetThemeEnabled( !m_hasBgCol && !m_foregroundColour.Ok() );
+ SetThemeEnabled( !m_hasBgCol && !m_foregroundColour.IsOk() );
return true;
}
m_hasFgCol = colour.IsOk();
m_inheritFgCol = m_hasFgCol;
m_foregroundColour = colour;
- SetThemeEnabled( !m_hasFgCol && !m_backgroundColour.Ok() );
+ SetThemeEnabled( !m_hasFgCol && !m_backgroundColour.IsOk() );
return true;
}
// dialog oriented functions
// ----------------------------------------------------------------------------
+#if WXWIN_COMPATIBILITY_2_8
void wxWindowBase::MakeModal(bool modal)
{
// Disable all other windows
}
}
}
+#endif // WXWIN_COMPATIBILITY_2_8
bool wxWindowBase::Validate()
{
}
}
+bool wxWindowBase::CopyToolTip(wxToolTip *tip)
+{
+ SetToolTip(tip ? new wxToolTip(tip->GetTip()) : NULL);
+
+ return tip != NULL;
+}
+
#endif // wxUSE_TOOLTIPS
// ----------------------------------------------------------------------------
void wxWindowBase::AdjustForParentClientOrigin(int& x, int& y, int sizeFlags) const
{
- // don't do it for the dialogs/frames - they float independently of their
- // parent
- if ( !IsTopLevel() )
+ wxWindow *parent = GetParent();
+ if ( !(sizeFlags & wxSIZE_NO_ADJUSTMENTS) && parent )
{
- wxWindow *parent = GetParent();
- if ( !(sizeFlags & wxSIZE_NO_ADJUSTMENTS) && parent )
- {
- wxPoint pt(parent->GetClientAreaOrigin());
- x += pt.x;
- y += pt.y;
- }
+ wxPoint pt(parent->GetClientAreaOrigin());
+ x += pt.x;
+ y += pt.y;
}
}
Show(event.GetShown());
}
+// ----------------------------------------------------------------------------
+// Idle processing
+// ----------------------------------------------------------------------------
+
+// Send idle event to window and all subwindows
+bool wxWindowBase::SendIdleEvents(wxIdleEvent& event)
+{
+ bool needMore = false;
+
+ OnInternalIdle();
+
+ // should we send idle event to this window?
+ if (wxIdleEvent::GetMode() == wxIDLE_PROCESS_ALL ||
+ HasExtraStyle(wxWS_EX_PROCESS_IDLE))
+ {
+ event.SetEventObject(this);
+ HandleWindowEvent(event);
+
+ if (event.MoreRequested())
+ needMore = true;
+ }
+ wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
+ for (; node; node = node->GetNext())
+ {
+ wxWindow* child = node->GetData();
+ if (child->SendIdleEvents(event))
+ needMore = true;
+ }
+
+ return needMore;
+}
+
+void wxWindowBase::OnInternalIdle()
+{
+ if ( wxUpdateUIEvent::CanUpdate(this) )
+ UpdateWindowUI(wxUPDATE_UI_FROMIDLE);
+}
+
// ----------------------------------------------------------------------------
// dialog units translations
// ----------------------------------------------------------------------------
{
const wxWindowBase * const parent = wxGetTopLevelParent((wxWindow*)this);
+ wxCHECK_MSG( parent, wxDefaultSize, wxS("Must have TLW parent") );
+
if ( !parent->m_font.IsOk() )
{
// Default GUI font is used. This is the most common case, so
// list classes implementation
// ----------------------------------------------------------------------------
-#if wxUSE_STL
+#if wxUSE_STD_CONTAINERS
#include "wx/listimpl.cpp"
WX_DEFINE_LIST(wxWindowList)
-#else // !wxUSE_STL
+#else // !wxUSE_STD_CONTAINERS
void wxWindowListNode::DeleteData()
{
delete (wxWindow *)GetData();
}
-#endif // wxUSE_STL/!wxUSE_STL
+#endif // wxUSE_STD_CONTAINERS/!wxUSE_STD_CONTAINERS
// ----------------------------------------------------------------------------
// borders
wxWindowList::compatibility_iterator i = siblings.Find(win);
wxCHECK_RET( i, wxT("MoveBefore/AfterInTabOrder(): win is not a sibling") );
- // unfortunately, when wxUSE_STL == 1 DetachNode() is not implemented so we
- // can't just move the node around
+ // unfortunately, when wxUSE_STD_CONTAINERS == 1 DetachNode() is not
+ // implemented so we can't just move the node around
wxWindow *self = (wxWindow *)this;
siblings.DeleteObject(self);
if ( move == OrderAfter )
bool wxWindowBase::HasFocus() const
{
- wxWindowBase *win = DoFindFocus();
- return win == this ||
- win == wxConstCast(this, wxWindowBase)->GetMainWindowOfCompositeControl();
+ wxWindowBase* const win = DoFindFocus();
+ return win &&
+ (this == win || this == win->GetMainWindowOfCompositeControl());
}
// ----------------------------------------------------------------------------
if (win)
{
rect = win->GetRect();
- if (win->GetParent() && !win->IsKindOf(CLASSINFO(wxTopLevelWindow)))
+ if (win->GetParent() && !wxDynamicCast(win, wxTopLevelWindow))
rect.SetPosition(win->GetParent()->ClientToScreen(rect.GetPosition()));
return wxACC_OK;
}
// accessible classes, one for each kind of wxWidgets
// control or window.
#if wxUSE_BUTTON
- if (GetWindow()->IsKindOf(CLASSINFO(wxButton)))
+ if (wxDynamicCast(GetWindow(), wxButton))
title = ((wxButton*) GetWindow())->GetLabel();
else
#endif
if (childId > 0)
return wxACC_NOT_IMPLEMENTED;
- if (GetWindow()->IsKindOf(CLASSINFO(wxControl)))
+ if (wxDynamicCast(GetWindow(), wxControl))
return wxACC_NOT_IMPLEMENTED;
#if wxUSE_STATUSBAR
- if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar)))
+ if (wxDynamicCast(GetWindow(), wxStatusBar))
return wxACC_NOT_IMPLEMENTED;
#endif
#if wxUSE_TOOLBAR
- if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar)))
+ if (wxDynamicCast(GetWindow(), wxToolBar))
return wxACC_NOT_IMPLEMENTED;
#endif
if (childId > 0)
return wxACC_NOT_IMPLEMENTED;
- if (GetWindow()->IsKindOf(CLASSINFO(wxControl)))
+ if (wxDynamicCast(GetWindow(), wxControl))
return wxACC_NOT_IMPLEMENTED;
#if wxUSE_STATUSBAR
- if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar)))
+ if (wxDynamicCast(GetWindow(), wxStatusBar))
return wxACC_NOT_IMPLEMENTED;
#endif
#if wxUSE_TOOLBAR
- if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar)))
+ if (wxDynamicCast(GetWindow(), wxToolBar))
return wxACC_NOT_IMPLEMENTED;
#endif