#endif
#include "wx/platinfo.h"
+#include "wx/private/window.h"
+
+#ifdef __WXMSW__
+ #include "wx/msw/wrapwin.h"
+#endif
// Windows List
WXDLLIMPEXP_DATA_CORE(wxWindowList) wxTopLevelWindows;
// size, this worked like this in wxWidgets 2.8 and before and generally
// often makes sense for child windows (for top level ones it definitely
// does not as the user should be able to resize the window)
- if ( !wxTopLevelWindows.Find(this) ) // can't use IsTopLevel() from ctor
+ //
+ // note that we can't use IsTopLevel() from ctor
+ if ( size != wxDefaultSize && !wxTopLevelWindows.Find((wxWindow *)this) )
SetMinSize(size);
SetName(name);
// we weren't a dialog class
wxTopLevelWindows.DeleteObject((wxWindow*)this);
+ // Any additional event handlers should be popped before the window is
+ // deleted as otherwise the last handler will be left with a dangling
+ // pointer to this window result in a difficult to diagnose crash later on.
+ wxASSERT_MSG( GetEventHandler() == this,
+ wxT("any pushed event handlers must have been removed") );
+
#if wxUSE_MENUS
// The associated popup menu can still be alive, disassociate from it in
// this case
// This removes any dangling pointers to this window in other windows'
// constraintsInvolvedIn lists.
UnsetConstraints(m_constraints);
- delete m_constraints;
- m_constraints = NULL;
+ wxDELETE(m_constraints);
}
#endif // wxUSE_CONSTRAINTS
return min;
}
+wxSize wxWindowBase::DoGetBorderSize() const
+{
+ // there is one case in which we can implement it for all ports easily
+ if ( GetBorder() == wxBORDER_NONE )
+ return wxSize(0, 0);
+
+ // otherwise use the difference between the real size and the client size
+ // as a fallback: notice that this is incorrect in general as client size
+ // also doesn't take the scrollbars into account
+ return GetSize() - GetClientSize();
+}
+
wxSize wxWindowBase::GetBestSize() const
{
if ( !m_windowSizer && m_bestSizeCache.IsFullySpecified() )
break;
case wxWINDOW_VARIANT_SMALL:
- size *= 3;
- size /= 4;
+ size = wxRound(size * 3.0 / 4.0);
break;
case wxWINDOW_VARIANT_MINI:
- size *= 2;
- size /= 3;
+ size = wxRound(size * 2.0 / 3.0);
break;
case wxWINDOW_VARIANT_LARGE:
- size *= 5;
- size /= 4;
+ size = wxRound(size * 5.0 / 4.0);
break;
default:
void wxWindowBase::NotifyWindowOnEnableChange(bool enabled)
{
+ // Under some platforms there is no need to update the window state
+ // explicitly, it will become disabled when its parent is. On other ones we
+ // do need to disable all windows recursively though.
#ifndef wxHAS_NATIVE_ENABLED_MANAGEMENT
DoEnable(enabled);
#endif // !defined(wxHAS_NATIVE_ENABLED_MANAGEMENT)
OnEnabled(enabled);
- // If we are top-level then the logic doesn't apply - otherwise
- // showing a modal dialog would result in total greying out (and ungreying
- // out later) of everything which would be really ugly
- if ( IsTopLevel() )
+ // Disabling a top level window is typically done when showing a modal
+ // dialog and we don't need to disable its children in this case, they will
+ // be logically disabled anyhow (i.e. their IsEnabled() will return false)
+ // and the TLW won't accept any input for them. Moreover, explicitly
+ // disabling them would look ugly as the entire TLW would be greyed out
+ // whenever a modal dialog is shown and no native applications under any
+ // platform behave like this.
+ if ( IsTopLevel() && !enabled )
return;
+ // When disabling (or enabling back) a non-TLW window we need to
+ // recursively propagate the change of the state to its children, otherwise
+ // they would still show as enabled even though they wouldn't actually
+ // accept any input (at least under MSW where children don't accept input
+ // if any of the windows in their parent chain is enabled).
+ //
+ // Notice that we must do this even for wxHAS_NATIVE_ENABLED_MANAGEMENT
+ // platforms as we still need to call the children OnEnabled() recursively.
for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
node;
node = node->GetNext() )
m_isEnabled = enable;
+ // If we call DoEnable() from NotifyWindowOnEnableChange(), we don't need
+ // to do it from here.
#ifdef wxHAS_NATIVE_ENABLED_MANAGEMENT
DoEnable(enable);
-#else // !defined(wxHAS_NATIVE_ENABLED_MANAGEMENT)
- wxWindowBase * const parent = GetParent();
- if( !IsTopLevel() && parent && !parent->IsEnabled() )
- {
- return true;
- }
#endif // !defined(wxHAS_NATIVE_ENABLED_MANAGEMENT)
NotifyWindowOnEnableChange(enable);
if ( deleteHandler )
{
- delete firstHandler;
- firstHandler = NULL;
+ wxDELETE(firstHandler);
}
return firstHandler;
// NOTE: the wxWindow event handler list is always terminated with "this" handler
wxEvtHandler *handlerCur = GetEventHandler()->GetNextHandler();
- while ( handlerCur != this )
+ while ( handlerCur != this && handlerCur )
{
wxEvtHandler *handlerNext = handlerCur->GetNextHandler();
wxColour colBg = GetDefaultAttributes().colBg;
// we must return some valid colour to avoid redoing this every time
- // and also to avoid surprizing the applications written for older
+ // and also to avoid surprising the applications written for older
// 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)
node = next;
}
- delete m_constraintsInvolvedIn;
- m_constraintsInvolvedIn = NULL;
+ wxDELETE(m_constraintsInvolvedIn);
}
}
if ( (constr->width.GetRelationship() != wxAsIs ) ||
(constr->height.GetRelationship() != wxAsIs) )
{
- SetSize(x, y, w, h);
+ // We really shouldn't set negative sizes for the windows so make
+ // them at least of 1*1 size
+ SetSize(x, y, w > 0 ? w : 1, h > 0 ? h : 1);
}
else
{
// dialog units translations
// ----------------------------------------------------------------------------
-wxPoint wxWindowBase::ConvertPixelsToDialog(const wxPoint& pt)
+// Windows' computes dialog units using average character width over upper-
+// and lower-case ASCII alphabet and not using the average character width
+// metadata stored in the font; see
+// http://support.microsoft.com/default.aspx/kb/145994 for detailed discussion.
+// It's important that we perform the conversion in identical way, because
+// dialog units natively exist only on Windows and Windows HIG is expressed
+// using them.
+wxSize wxWindowBase::GetDlgUnitBase() const
{
- int charWidth = GetCharWidth();
- int charHeight = GetCharHeight();
+ const wxWindowBase * const parent = wxGetTopLevelParent((wxWindow*)this);
+
+ if ( !parent->m_font.IsOk() )
+ {
+ // Default GUI font is used. This is the most common case, so
+ // cache the results.
+ static wxSize s_defFontSize;
+ if ( s_defFontSize.x == 0 )
+ s_defFontSize = wxPrivate::GetAverageASCIILetterSize(*parent);
+ return s_defFontSize;
+ }
+ else
+ {
+ // Custom font, we always need to compute the result
+ return wxPrivate::GetAverageASCIILetterSize(*parent);
+ }
+}
+
+wxPoint wxWindowBase::ConvertPixelsToDialog(const wxPoint& pt) const
+{
+ const wxSize base = GetDlgUnitBase();
+
+ // NB: wxMulDivInt32() is used, because it correctly rounds the result
+
wxPoint pt2 = wxDefaultPosition;
if (pt.x != wxDefaultCoord)
- pt2.x = (int) ((pt.x * 4) / charWidth);
+ pt2.x = wxMulDivInt32(pt.x, 4, base.x);
if (pt.y != wxDefaultCoord)
- pt2.y = (int) ((pt.y * 8) / charHeight);
+ pt2.y = wxMulDivInt32(pt.y, 8, base.y);
return pt2;
}
-wxPoint wxWindowBase::ConvertDialogToPixels(const wxPoint& pt)
+wxPoint wxWindowBase::ConvertDialogToPixels(const wxPoint& pt) const
{
- int charWidth = GetCharWidth();
- int charHeight = GetCharHeight();
+ const wxSize base = GetDlgUnitBase();
+
wxPoint pt2 = wxDefaultPosition;
if (pt.x != wxDefaultCoord)
- pt2.x = (int) ((pt.x * charWidth) / 4);
+ pt2.x = wxMulDivInt32(pt.x, base.x, 4);
if (pt.y != wxDefaultCoord)
- pt2.y = (int) ((pt.y * charHeight) / 8);
+ pt2.y = wxMulDivInt32(pt.y, base.y, 8);
return pt2;
}
// ----------------------------------------------------------------------------
// propagate the colour change event to the subwindows
-void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent& event)
+void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent& WXUNUSED(event))
{
wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
while ( node )
{
wxCHECK_MSG( menu, false, "can't popup NULL menu" );
+ wxMenuInvokingWindowSetter
+ setInvokingWin(*menu, static_cast<wxWindow *>(this));
+
wxCurrentPopupMenu = menu;
const bool rc = DoPopupMenu(menu, x, y);
wxCurrentPopupMenu = NULL;
else
#endif // __WXDEBUG__
{
+#if wxUSE_MSGDLG
// just Ctrl-Alt-middle click shows information about wx version
::wxInfoMessageBox((wxWindow*)this);
+#endif // wxUSE_MSGDLG
}
}
else
if ( event.GetEventObject() == this )
{
wxValidator * const validator = GetValidator();
- if ( validator && validator->ProcessEventHere(event) )
+ if ( validator && validator->ProcessEventLocally(event) )
{
return true;
}