#include "wx/dcscreen.h"
#include "wx/dcclient.h"
#include "wx/toplevel.h"
- #include "wx/imaglist.h"
#endif
+#include "wx/imaglist.h"
#include "wx/stockitem.h"
#include "wx/msw/private.h"
#include "wx/msw/private/button.h"
#include "wx/msw/private/dc.h"
+#include "wx/private/window.h"
using namespace wxMSWImpl;
#define DT_HIDEPREFIX 0x00100000
#endif
+// set the value for BCM_SETSHIELD (for the UAC shield) if it's not defined in
+// the header
+#ifndef BCM_SETSHIELD
+ #define BCM_SETSHIELD 0x160c
+#endif
+
// ----------------------------------------------------------------------------
// button image data
// ----------------------------------------------------------------------------
::SetWindowLong(hwnd, GWL_STYLE, styleNew);
}
-wxSize wxMSWButton::GetFittingSize(wxWindow *win, const wxSize& sizeLabel)
+wxSize wxMSWButton::GetFittingSize(wxWindow *win,
+ const wxSize& sizeLabel,
+ int flags)
{
// FIXME: this is pure guesswork, need to retrieve the real button margins
wxSize sizeBtn = sizeLabel;
sizeBtn.x += 3*win->GetCharWidth();
sizeBtn.y = 11*EDIT_HEIGHT_FROM_CHAR_HEIGHT(sizeLabel.y)/10;
+ // account for the shield UAC icon if we have it
+ if ( flags & Size_AuthNeeded )
+ sizeBtn.x += wxSystemSettings::GetMetric(wxSYS_SMALLICON_X);
+
return sizeBtn;
}
-wxSize wxMSWButton::ComputeBestSize(wxControl *btn)
+wxSize wxMSWButton::ComputeBestSize(wxControl *btn, int flags)
{
wxClientDC dc(btn);
wxSize sizeBtn;
dc.GetMultiLineTextExtent(btn->GetLabelText(), &sizeBtn.x, &sizeBtn.y);
- sizeBtn = GetFittingSize(btn, sizeBtn);
+ sizeBtn = GetFittingSize(btn, sizeBtn, flags);
// all buttons have at least the standard size unless the user explicitly
// wants them to be of smaller size and used wxBU_EXACTFIT style when
// creating the button
if ( !btn->HasFlag(wxBU_EXACTFIT) )
{
- wxSize sizeDef = wxButton::GetDefaultSize();
+ // The size of a standard button in the dialog units is 50x14, use it.
+ // Note that we intentionally don't use GetDefaultSize() here, because
+ // it's inexact -- dialog units depend on this dialog's font.
+ wxSize sizeDef = btn->ConvertDialogToPixels(wxSize(50, 14));
if ( sizeBtn.x < sizeDef.x )
sizeBtn.x = sizeDef.x;
if ( sizeBtn.y < sizeDef.y )
const wxValidator& validator,
const wxString& name)
{
+ m_authNeeded = false;
+
wxString label(lbl);
if (label.empty() && wxIsStockID(id))
{
{
wxSize size;
- // account for the text part
- if ( ShowsLabel() )
+ // account for the text part if we have it or if we don't have any image at
+ // all (buttons initially created with empty label should still have a non
+ // zero size)
+ if ( ShowsLabel() || !m_imageData )
{
- size = wxMSWButton::ComputeBestSize(const_cast<wxButton *>(this));
+ int flags = 0;
+ if ( GetAuthNeeded() )
+ flags |= wxMSWButton::Size_AuthNeeded;
+
+ size = wxMSWButton::ComputeBestSize(const_cast<wxButton *>(this), flags);
}
if ( m_imageData )
wxScreenDC dc;
dc.SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
- // the size of a standard button in the dialog units is 50x14,
- // translate this to pixels
- // NB1: the multipliers come from the Windows convention
- // NB2: the extra +1/+2 were needed to get the size be the same as the
- // size of the buttons in the standard dialog - I don't know how
- // this happens, but on my system this size is 75x23 in pixels and
- // 23*8 isn't even divisible by 14... Would be nice to understand
- // why these constants are needed though!
- s_sizeBtn.x = (50 * (dc.GetCharWidth() + 1))/4;
- s_sizeBtn.y = ((14 * dc.GetCharHeight()) + 2)/8;
+ // The size of a standard button in the dialog units is 50x14,
+ // translate this to pixels.
+ //
+ // 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.
+ //
+ // NB: wxMulDivInt32() is used, because it correctly rounds the result
+
+ const wxSize base = wxPrivate::GetAverageASCIILetterSize(dc);
+ s_sizeBtn.x = wxMulDivInt32(50, base.x, 4);
+ s_sizeBtn.y = wxMulDivInt32(14, base.y, 8);
}
return s_sizeBtn;
#if wxUSE_UXTHEME
wxUxThemeEngine::GetIfActive() ||
#endif // wxUSE_UXTHEME
- m_imageData && m_imageData->GetBitmap(State_Current).IsOk()
+ (m_imageData && m_imageData->GetBitmap(State_Current).IsOk())
)
)
{
return wxControl::MSWWindowProc(nMsg, wParam, lParam);
}
+// ----------------------------------------------------------------------------
+// authentication needed handling
+// ----------------------------------------------------------------------------
+
+bool wxButton::DoGetAuthNeeded() const
+{
+ return m_authNeeded;
+}
+
+void wxButton::DoSetAuthNeeded(bool show)
+{
+ // show/hide UAC symbol on Windows Vista and later
+ if ( wxGetWinVersion() >= wxWinVersion_6 )
+ {
+ m_authNeeded = show;
+ ::SendMessage(GetHwnd(), BCM_SETSHIELD, 0, show);
+ InvalidateBestSize();
+ }
+}
+
// ----------------------------------------------------------------------------
// button images
// ----------------------------------------------------------------------------
wxCHECK_RET( m_imageData, "SetBitmap() must be called first" );
m_imageData->SetBitmapMargins(x, y);
+ InvalidateBestSize();
}
void wxButton::DoSetBitmapPosition(wxDirection dir)
wxCHECK_RET( m_imageData, "SetBitmap() must be called first" );
m_imageData->SetBitmapPosition(dir);
+ InvalidateBestSize();
}
// ----------------------------------------------------------------------------