summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorleo2006-02-25 01:12:30 +0000
committerleo2006-02-25 01:12:30 +0000
commitd780eb6826a0e0d98f8457259cd922b7bdce6cda (patch)
tree187e89a94baad9c4620862778ad0c51732c14440
parent9e23e95f9b8235e7b9fc84a8cd333f6147206718 (diff)
Popup menu title.
git-svn-id: http://svn.leocad.org/trunk@495 c7d43263-9d01-0410-8a33-9dba5d9f93d6
-rw-r--r--win/Bmpmenu.cpp86
-rw-r--r--win/Bmpmenu.h22
-rw-r--r--win/LeoCAD.rc7
-rw-r--r--win/Mainfrm.cpp20
-rw-r--r--win/Mainfrm.h1
-rw-r--r--win/cadbar.cpp13
-rw-r--r--win/resource.h4
7 files changed, 145 insertions, 8 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);
+}
diff --git a/win/Bmpmenu.h b/win/Bmpmenu.h
index bc17aa1..aae2c14 100644
--- a/win/Bmpmenu.h
+++ b/win/Bmpmenu.h
@@ -145,4 +145,26 @@ protected:
BOOL disable_old_style;
};
+// ============================================================================
+
+class CTitleMenu : public CMenu
+{
+public:
+ CTitleMenu();
+ virtual ~CTitleMenu();
+
+// Operations
+public:
+ void SetMenuTitle(UINT ID, const char* Title);
+
+// Implementation
+public:
+ static void MeasureItem(LPMEASUREITEMSTRUCT lpMIS);
+ static void DrawItem(LPDRAWITEMSTRUCT lpDIS);
+
+protected:
+ static CFont m_Font;
+ HFONT CreateTitleFont();
+};
+
#endif
diff --git a/win/LeoCAD.rc b/win/LeoCAD.rc
index 3398ff2..a6e9074 100644
--- a/win/LeoCAD.rc
+++ b/win/LeoCAD.rc
@@ -449,6 +449,8 @@ BEGIN
END
POPUP "7"
BEGIN
+ MENUITEM "XY Snap", ID_SNAP_XY, INACTIVE
+ MENUITEM SEPARATOR
MENUITEM "None", ID_SNAP_0
MENUITEM "1/20 Stud", ID_SNAP_1
MENUITEM "1/4 Stud", ID_SNAP_2
@@ -459,7 +461,10 @@ BEGIN
MENUITEM "3 Studs", ID_SNAP_7
MENUITEM "4 Studs", ID_SNAP_8
MENUITEM "8 Studs", ID_SNAP_9
- MENUITEM "None", ID_SNAP_10, MENUBREAK
+ MENUITEM "Z Snap", ID_SNAP_Z
+ , INACTIVE, MENUBARBREAK
+ MENUITEM SEPARATOR
+ MENUITEM "None", ID_SNAP_10
MENUITEM "1/20 Stud", ID_SNAP_11
MENUITEM "1/4 Stud", ID_SNAP_12
MENUITEM "1 Flat", ID_SNAP_13
diff --git a/win/Mainfrm.cpp b/win/Mainfrm.cpp
index 4a97393..f21df34 100644
--- a/win/Mainfrm.cpp
+++ b/win/Mainfrm.cpp
@@ -92,6 +92,7 @@ BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
ON_WM_CREATE()
ON_WM_CLOSE()
ON_WM_SETFOCUS()
+ ON_WM_DRAWITEM()
ON_WM_MEASUREITEM()
ON_WM_MENUCHAR()
ON_WM_INITMENUPOPUP()
@@ -378,7 +379,12 @@ void CMainFrame::OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStru
{
if(lpMeasureItemStruct->CtlType == ODT_MENU)
{
- if(IsMenu((HMENU)lpMeasureItemStruct->itemID))
+ if ((lpMeasureItemStruct->itemID == ID_SNAP_XY) || (lpMeasureItemStruct->itemID == ID_SNAP_Z))
+ {
+ CTitleMenu::MeasureItem(lpMeasureItemStruct);
+ return;
+ }
+ else if(IsMenu((HMENU)lpMeasureItemStruct->itemID))
{
CMenu* cmenu = CMenu::FromHandle((HMENU)lpMeasureItemStruct->itemID);
if(m_bmpMenu.IsMenu(cmenu))
@@ -392,6 +398,18 @@ void CMainFrame::OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStru
CFrameWnd::OnMeasureItem(nIDCtl, lpMeasureItemStruct);
}
+void CMainFrame::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)
+{
+ if ((lpDrawItemStruct->itemID == ID_SNAP_XY) || (lpDrawItemStruct->itemID == ID_SNAP_Z))
+ {
+ CTitleMenu::DrawItem(lpDrawItemStruct);
+ }
+ else
+ {
+ CFrameWnd::OnDrawItem(nIDCtl, lpDrawItemStruct);
+ }
+}
+
LRESULT CMainFrame::OnMenuChar(UINT nChar, UINT nFlags, CMenu* pMenu)
{
if (m_bmpMenu.IsMenu(pMenu))
diff --git a/win/Mainfrm.h b/win/Mainfrm.h
index 8d1b42e..8183f1e 100644
--- a/win/Mainfrm.h
+++ b/win/Mainfrm.h
@@ -78,6 +78,7 @@ protected:
afx_msg void OnClose();
afx_msg void OnSetFocus(CWnd* pOldWnd);
afx_msg void OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct);
+ afx_msg void CMainFrame::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct);
afx_msg LRESULT OnMenuChar(UINT nChar, UINT nFlags, CMenu* pMenu);
afx_msg void OnInitMenuPopup(CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu);
afx_msg void OnViewFullscreen();
diff --git a/win/cadbar.cpp b/win/cadbar.cpp
index 25da26c..721900a 100644
--- a/win/cadbar.cpp
+++ b/win/cadbar.cpp
@@ -8,6 +8,7 @@
#include "StepPop.h"
#include "project.h"
#include "lc_application.h"
+#include "bmpmenu.h"
#ifdef _DEBUG
#undef THIS_FILE
@@ -69,15 +70,18 @@ void CCADStatusBar::OnLButtonDown(UINT nFlags, CPoint point)
if (rect.PtInRect(point))
{
ClientToScreen(&point);
- CMenu menuPopups;
+ CTitleMenu menuPopups;
menuPopups.LoadMenu(IDR_POPUPS);
- CMenu* pMenu = menuPopups.GetSubMenu(7);
+ CTitleMenu* pMenu = (CTitleMenu*)menuPopups.GetSubMenu(7);
int SXY, SZ;
lcGetActiveProject()->GetSnapIndex(&SXY, &SZ);
- pMenu->CheckMenuRadioItem(0, 9, SXY, MF_BYPOSITION);
- pMenu->CheckMenuRadioItem(10, 19, 10 + SZ, MF_BYPOSITION);
+ pMenu->SetMenuTitle(ID_SNAP_XY, "XY Snap");
+ pMenu->SetMenuTitle(ID_SNAP_Z, "Z Snap");
+
+ pMenu->CheckMenuRadioItem(2, 11, SXY + 2, MF_BYPOSITION);
+ pMenu->CheckMenuRadioItem(14, 23, SZ + 14, MF_BYPOSITION);
pMenu->TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTBUTTON, point.x, point.y, AfxGetMainWnd());
}
@@ -136,4 +140,3 @@ void CCADStatusBar::AdjustProgressBarPosition()
m_Progress.SetWindowPos(NULL, Rect.right - m_nProgressWidth, Rect.top,
m_nProgressWidth, Rect.Height(), SWP_NOZORDER | SWP_NOACTIVATE);
}
-
diff --git a/win/resource.h b/win/resource.h
index 695a973..88fbb74 100644
--- a/win/resource.h
+++ b/win/resource.h
@@ -676,6 +676,8 @@
#define ID_LIBDLG_CATEGORY_REMOVE 33164
#define ID_LIBDLG_CATEGORY_EDIT 33165
#define ID_LIBDLG_CATEGORY_RESET 33166
+#define ID_SNAP_XY 33167
+#define ID_SNAP_Z 33168
#define ID_VIEW_PIECES_BAR 59425
#define ID_VIEW_TOOLS_BAR 59426
#define ID_VIEW_ANIMATION_BAR 59427
@@ -687,7 +689,7 @@
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_3D_CONTROLS 1
#define _APS_NEXT_RESOURCE_VALUE 240
-#define _APS_NEXT_COMMAND_VALUE 33167
+#define _APS_NEXT_COMMAND_VALUE 33169
#define _APS_NEXT_CONTROL_VALUE 1247
#define _APS_NEXT_SYMED_VALUE 121
#endif