tried to fix the accel string drawing in the owner drawn menu items
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@10263 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
c48269b9f7
commit
6d5b2a57cf
@ -92,6 +92,10 @@ public:
|
||||
void SetCheckable(bool checkable) { m_bCheckable = checkable; }
|
||||
bool IsCheckable() const { return m_bCheckable; }
|
||||
|
||||
// this is for menu items only: accel string is drawn right aligned after the
|
||||
// menu item if not empty
|
||||
void SetAccelString(const wxString& strAccel) { m_strAccel = strAccel; }
|
||||
|
||||
// this function might seem strange, but if it returns FALSE it means that
|
||||
// no non-standard attribute are set, so there is no need for this control
|
||||
// to be owner-drawn. Moreover, you can force owner-drawn to FALSE if you
|
||||
@ -125,7 +129,8 @@ public:
|
||||
virtual bool OnDrawItem(wxDC& dc, const wxRect& rc, wxODAction act, wxODStatus stat);
|
||||
|
||||
protected:
|
||||
wxString m_strName; // label for a manu item
|
||||
wxString m_strName, // label for a manu item
|
||||
m_strAccel; // the accel string ("Ctrl-F17") if any
|
||||
|
||||
private:
|
||||
static size_t ms_nDefaultMarginWidth; // menu check mark width
|
||||
|
@ -29,8 +29,23 @@
|
||||
#include <wx/log.h>
|
||||
#endif
|
||||
|
||||
#if !wxUSE_MENUS
|
||||
// nice try...
|
||||
#error "menu sample requires wxUSE_MENUS=1"
|
||||
#endif // wxUSE_MENUS
|
||||
|
||||
#include "copy.xpm"
|
||||
|
||||
#ifdef __WXUNIVERSAL__
|
||||
#include "wx/univ/theme.h"
|
||||
|
||||
WX_USE_THEME(win32);
|
||||
WX_USE_THEME(gtk);
|
||||
|
||||
// not implemented yet
|
||||
#define wxMessageBox
|
||||
#endif // __WXUNIVERSAL__
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// classes
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -209,7 +224,9 @@ bool MyApp::OnInit()
|
||||
|
||||
frame->Show(TRUE);
|
||||
|
||||
#if wxUSE_STATUSBAR
|
||||
frame->SetStatusText("Hello, wxWindows");
|
||||
#endif // wxUSE_STATUSBAR
|
||||
|
||||
SetTopWindow(frame);
|
||||
|
||||
@ -228,15 +245,21 @@ MyFrame::MyFrame()
|
||||
m_menu = NULL;
|
||||
m_countDummy = 0;
|
||||
|
||||
#if wxUSE_STATUSBAR
|
||||
CreateStatusBar(2);
|
||||
#endif // wxUSE_STATUSBAR
|
||||
|
||||
// create the menubar
|
||||
wxMenu *fileMenu = new wxMenu;
|
||||
fileMenu->Append(Menu_File_Quit, "E&xit\tAlt-X", "Quit toolbar sample" );
|
||||
|
||||
wxMenuItem *bitmap_menu_item = new wxMenuItem( fileMenu, Menu_File_Quit, "Quit with &bitmap\tAlt-Q" );
|
||||
bitmap_menu_item->SetBitmap( wxBitmap( copy_xpm ) );
|
||||
fileMenu->Append( bitmap_menu_item );
|
||||
fileMenu->Append(Menu_File_Quit, "E&xit\tAlt-X", "Quit toolbar sample");
|
||||
|
||||
// not supported just yet
|
||||
#ifndef __WXUNIVERSAL__
|
||||
wxMenuItem *itemBitmap = new wxMenuItem(fileMenu, Menu_File_Quit,
|
||||
"Quit with &bitmap\tAlt-Q");
|
||||
itemBitmap->SetBitmap(wxBitmap(copy_xpm));
|
||||
fileMenu->Append(itemBitmap);
|
||||
#endif // __WXUNIVERSAL__
|
||||
|
||||
wxMenu *menubarMenu = new wxMenu;
|
||||
menubarMenu->Append(Menu_MenuBar_Append, "&Append menu\tCtrl-A",
|
||||
@ -355,7 +378,9 @@ void MyFrame::LogMenuEvent(const wxCommandEvent& event)
|
||||
event.IsChecked() ? "" : "not ");
|
||||
}
|
||||
|
||||
#if wxUSE_STATUSBAR
|
||||
SetStatusText(msg, 1);
|
||||
#endif // wxUSE_STATUSBAR
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
@ -70,11 +70,11 @@
|
||||
// dynamic classes implementation
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#if wxUSE_OWNER_DRAWN
|
||||
IMPLEMENT_DYNAMIC_CLASS2(wxMenuItem, wxMenuItemBase, wxOwnerDrawn)
|
||||
#else //!USE_OWNER_DRAWN
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxMenuItem, wxMenuItemBase)
|
||||
#endif //USE_OWNER_DRAWN
|
||||
#if wxUSE_OWNER_DRAWN
|
||||
IMPLEMENT_DYNAMIC_CLASS2(wxMenuItem, wxMenuItemBase, wxOwnerDrawn)
|
||||
#else //!USE_OWNER_DRAWN
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxMenuItem, wxMenuItemBase)
|
||||
#endif //USE_OWNER_DRAWN
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxMenuItem
|
||||
@ -90,7 +90,7 @@ wxMenuItem::wxMenuItem(wxMenu *pParentMenu,
|
||||
bool bCheckable,
|
||||
wxMenu *pSubMenu)
|
||||
#if wxUSE_OWNER_DRAWN
|
||||
: wxOwnerDrawn(text, bCheckable)
|
||||
: wxOwnerDrawn(GetLabelFromText(text), bCheckable)
|
||||
#endif // owner drawn
|
||||
{
|
||||
wxASSERT_MSG( pParentMenu != NULL, wxT("a menu item should have a parent") );
|
||||
@ -102,10 +102,13 @@ wxMenuItem::wxMenuItem(wxMenu *pParentMenu,
|
||||
SetTextColour(SYS_COLOR(MENUTEXT));
|
||||
SetBackgroundColour(SYS_COLOR(MENU));
|
||||
|
||||
#undef SYS_COLOR
|
||||
|
||||
// we don't want normal items be owner-drawn
|
||||
ResetOwnerDrawn();
|
||||
|
||||
#undef SYS_COLOR
|
||||
// tell the owner drawing code to to show the accel string as well
|
||||
SetAccelString(text.AfterFirst(_T('\t')));
|
||||
#endif // wxUSE_OWNER_DRAWN
|
||||
|
||||
m_parentMenu = pParentMenu;
|
||||
|
@ -127,7 +127,10 @@ bool wxOwnerDrawn::OnMeasureItem(size_t *pwidth, size_t *pheight)
|
||||
#endif
|
||||
|
||||
// draw the item
|
||||
bool wxOwnerDrawn::OnDrawItem(wxDC& dc, const wxRect& rc, wxODAction act, wxODStatus st)
|
||||
bool wxOwnerDrawn::OnDrawItem(wxDC& dc,
|
||||
const wxRect& rc,
|
||||
wxODAction act,
|
||||
wxODStatus st)
|
||||
{
|
||||
// we do nothing on focus change
|
||||
if ( act == wxODFocusChanged )
|
||||
@ -188,9 +191,21 @@ bool wxOwnerDrawn::OnDrawItem(wxDC& dc, const wxRect& rc, wxODAction act, wxODSt
|
||||
|
||||
HFONT hPrevFont = (HFONT) ::SelectObject(hdc, hfont);
|
||||
DrawState(hdc, NULL, NULL,
|
||||
(LPARAM)(const wxChar *)m_strName, m_strName.Length(),
|
||||
(LPARAM)m_strName.c_str(), m_strName.length(),
|
||||
x, rc.y, rc.GetWidth(), rc.GetHeight(),
|
||||
DST_PREFIXTEXT | ( st & wxODDisabled ? DSS_DISABLED : 0) );
|
||||
DST_PREFIXTEXT | (st & wxODDisabled ? DSS_DISABLED : 0));
|
||||
|
||||
if ( !m_strAccel.empty() )
|
||||
{
|
||||
RECT r;
|
||||
r.top = rc.GetTop();
|
||||
r.left = rc.GetLeft();
|
||||
r.right = rc.GetRight() - GetMarginWidth();
|
||||
r.bottom = rc.GetBottom();
|
||||
|
||||
DrawText(hdc, m_strAccel, m_strAccel.length(), &r,
|
||||
DT_SINGLELINE | DT_RIGHT | DT_VCENTER);
|
||||
}
|
||||
|
||||
(void)SelectObject(hdc, hPrevBrush);
|
||||
(void)SelectObject(hdc, hPrevFont);
|
||||
|
Loading…
Reference in New Issue
Block a user