summaryrefslogtreecommitdiff
path: root/win/Bmpmenu.cpp
diff options
context:
space:
mode:
authorleo2006-02-25 01:12:30 +0000
committerleo2006-02-25 01:12:30 +0000
commitd780eb6826a0e0d98f8457259cd922b7bdce6cda (patch)
tree187e89a94baad9c4620862778ad0c51732c14440 /win/Bmpmenu.cpp
parent9e23e95f9b8235e7b9fc84a8cd333f6147206718 (diff)
Popup menu title.
git-svn-id: http://svn.leocad.org/trunk@495 c7d43263-9d01-0410-8a33-9dba5d9f93d6
Diffstat (limited to 'win/Bmpmenu.cpp')
-rw-r--r--win/Bmpmenu.cpp86
1 files changed, 86 insertions, 0 deletions
diff --git a/win/Bmpmenu.cpp b/win/Bmpmenu.cpp
index 00b748a..6443dc0 100644
--- a/win/Bmpmenu.cpp
+++ b/win/Bmpmenu.cpp
@@ -1447,3 +1447,89 @@ BOOL CBMPMenu::DeleteMenu(UINT nPosition, UINT nFlags)
return (CMenu::DeleteMenu(nPosition, nFlags));
}
+
+// ============================================================================
+
+CFont CTitleMenu::m_Font;
+
+CTitleMenu::CTitleMenu()
+{
+ HFONT hfont = CreateTitleFont();
+ ASSERT(hfont);
+ m_Font.Attach(hfont);
+}
+
+CTitleMenu::~CTitleMenu()
+{
+ m_Font.DeleteObject();
+}
+
+HFONT CTitleMenu::CreateTitleFont()
+{
+ // start by getting the stock menu font
+ HFONT hfont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
+ if (hfont)
+ {
+ LOGFONT lf; //get the complete LOGFONT describing this font
+ if (GetObject(hfont, sizeof(LOGFONT), &lf))
+ {
+ lf.lfWeight = FW_BOLD; // set the weight to bold
+ // recreate this font with just the weight changed
+ return ::CreateFontIndirect(&lf);
+ }
+ }
+ return NULL;
+}
+
+void CTitleMenu::SetMenuTitle(UINT ID, const char* Title)
+{
+ UINT State = GetMenuState(ID, MF_BYCOMMAND);
+ CMenu::ModifyMenu(ID, MF_BYCOMMAND | MF_OWNERDRAW | State, ID, Title);
+}
+
+void CTitleMenu::MeasureItem(LPMEASUREITEMSTRUCT mi)
+{
+ // Get the screen dc to use for retrieving size information.
+ CDC dc;
+ dc.Attach(::GetDC(NULL));
+
+ // Select the title font.
+ HFONT hfontOld = (HFONT)SelectObject(dc.m_hDC, (HFONT)m_Font);
+
+ // Compute the size of the title.
+ CSize size = dc.GetTextExtent((char*)mi->itemData);
+
+ // Deselect the title font.
+ dc.SelectObject(hfontOld);
+
+ // Add in the left margin for the menu item.
+ size.cx += GetSystemMetrics(SM_CXMENUCHECK)+8;
+
+ // Return the width and height.
+ mi->itemWidth = size.cx;
+ mi->itemHeight = size.cy;
+}
+
+void CTitleMenu::DrawItem(LPDRAWITEMSTRUCT di)
+{
+ // Fill the background.
+ HBRUSH bgb = CreateSolidBrush(GetSysColor(COLOR_MENU));
+ FillRect(di->hDC, &di->rcItem, bgb);
+ DeleteObject(bgb);
+
+ // Setup font.
+ int mode = SetBkMode(di->hDC, TRANSPARENT);
+ COLORREF color = SetTextColor(di->hDC, GetSysColor(COLOR_MENUTEXT));
+ HFONT old = (HFONT)SelectObject(di->hDC, (HFONT)m_Font);
+
+ // Add the menu margin offset.
+ di->rcItem.left += GetSystemMetrics(SM_CXMENUCHECK)+8;
+
+ // Draw the text left aligned and vertically centered.
+ DrawText(di->hDC, (char*)di->itemData, -1, &di->rcItem, DT_SINGLELINE|DT_VCENTER|DT_LEFT);
+
+ // Restore everything.
+ SelectObject(di->hDC, old);
+ SetBkMode(di->hDC, mode);
+ SetTextColor(di->hDC, color);
+}