135 CRect rcItem = lpDrawItemStruct->rcItem;
136 rcItem.MoveToXY(0, 0);
139 HDC dc(lpDrawItemStruct->hDC);
141 GETRENDERFACTORY->CreateRenderTarget(&pRT, rcItem.Width(), rcItem.Height());
145 MENUITEMINFO mii = {
sizeof(MENUITEMINFO), MIIM_FTYPE, 0 };
146 GetMenuItemInfo((HMENU)lpDrawItemStruct->hwndItem, lpDrawItemStruct->itemID, FALSE, &mii);
148 BOOL bDisabled = lpDrawItemStruct->itemState & ODS_GRAYED;
149 BOOL bSelected = lpDrawItemStruct->itemState & ODS_SELECTED;
150 BOOL bChecked = lpDrawItemStruct->itemState & ODS_CHECKED;
151 BOOL bRadio = mii.fType & MFT_RADIOCHECK;
152 m_attr->m_pItemSkin->DrawByIndex(pRT, rcItem, bSelected ? 1 : 0);
156 int iconOffset = m_attr->GetIconMargin();
158 rcIcon.left = rcItem.left + iconOffset;
159 CSize szIcon = m_attr->GetIconSize();
160 rcIcon.right = rcIcon.left + szIcon.cx;
161 rcIcon.top = rcItem.top + (rcItem.Height() - szIcon.cy) / 2;
162 rcIcon.bottom = rcIcon.top + szIcon.cy;
165 if (m_attr->m_pCheckSkin)
167 m_attr->m_pCheckSkin->DrawByIndex(pRT, rcIcon, bRadio ? 1 : 0);
170 else if (pdmmi->hIcon)
172 pRT->DrawIconEx(rcIcon.left, rcIcon.top, pdmmi->hIcon, rcIcon.Width(), rcIcon.Height(), DI_NORMAL);
174 else if (pdmmi->iIcon != -1 && m_attr->m_pIconSkin)
176 m_attr->m_pIconSkin->DrawByIndex(pRT, rcIcon, pdmmi->iIcon);
178 rcItem.left = rcIcon.right + iconOffset;
181 CRect rcTxt = rcItem;
182 rcTxt.DeflateRect(m_attr->GetTextMargin(), 0);
184 COLORREF crOld = pRT->SetTextColor(bDisabled ? m_attr->m_crTxtGray : (bSelected ? m_attr->m_crTxtSel : m_attr->m_crTxtNormal));
187 pRT->SelectObject(m_attr->GetFontPtr(), (
IRenderObj **)&oldFont);
188 SStringT strLeft, strRight;
189 int pos = pdmmi->strText.ReverseFind(
'\t');
192 const int kArrowSize = 14;
193 rcTxt.right -= kArrowSize * m_attr->GetScale() / 100;
194 strLeft = pdmmi->strText.Left(pos);
195 strRight = pdmmi->strText.Mid(pos + 1);
196 pRT->DrawText(strLeft, strLeft.GetLength(), &rcTxt, DT_SINGLELINE | DT_VCENTER | DT_LEFT | DT_END_ELLIPSIS);
197 pRT->DrawText(strRight, strRight.GetLength(), &rcTxt, DT_SINGLELINE | DT_VCENTER | DT_RIGHT | DT_END_ELLIPSIS);
201 pRT->DrawText(pdmmi->strText, pdmmi->strText.GetLength(), &rcTxt, DT_SINGLELINE | DT_VCENTER | DT_LEFT | DT_END_ELLIPSIS);
203 pRT->SelectObject(oldFont, NULL);
205 pRT->SetTextColor(crOld);
207 if (bSelected && m_attr->m_pItemSkin->GetStates() > 2)
210 CRect rcItem = lpDrawItemStruct->rcItem;
211 rcItem.MoveToXY(0, 0);
212 m_attr->m_pItemSkin->DrawByIndex(pRT, rcItem, 2);
217 if (m_attr->m_pSepSkin)
218 m_attr->m_pSepSkin->DrawByIndex(pRT, rcItem, 0);
220 rcItem = lpDrawItemStruct->rcItem;
223 HDC hmemdc = pRT->GetDC(0);
224 BitBlt(dc, rcItem.left, rcItem.top, rcItem.Width(), rcItem.Height(), hmemdc, 0, 0, SRCCOPY);
225 pRT->ReleaseDC(hmemdc, &rcItem);
230 if (lpMeasureItemStruct->CtlType != ODT_MENU)
237 lpMeasureItemStruct->itemHeight = m_attr->GetItemHeight();
238 lpMeasureItemStruct->itemWidth = m_attr->GetIconSize().cx + m_attr->GetIconMargin() * 2;
241 GETRENDERFACTORY->CreateRenderTarget(&pRT, 0, 0);
243 pRT->SelectObject(m_attr->GetFontPtr(), (
IRenderObj **)&oldFont);
245 pRT->MeasureText(pdmmi->strText, pdmmi->strText.GetLength(), &szTxt);
246 lpMeasureItemStruct->itemWidth += szTxt.cx + m_attr->GetTextMargin() * 2;
247 int itemMaxWidth = m_attr->GetMaxWidth();
248 if (itemMaxWidth != -1 && (
int)lpMeasureItemStruct->itemWidth > itemMaxWidth)
249 lpMeasureItemStruct->itemWidth = itemMaxWidth;
250 pRT->SelectObject(oldFont, NULL);
255 lpMeasureItemStruct->itemHeight = m_attr->m_pSepSkin ? m_attr->m_pSepSkin->GetSkinSize().cy : 3;
256 lpMeasureItemStruct->itemWidth = 0;
377BOOL
SMenu::InsertMenu(UINT nPosition, UINT nFlags, UINT_PTR nIDNewItem, LPCTSTR strText,
int iIcon, HICON hIcon)
379 nFlags |= MF_OWNERDRAW;
380 if (nFlags & MF_SEPARATOR)
382 return ::InsertMenu(m_hMenu, nPosition, nFlags, (UINT_PTR)0, (LPCTSTR)NULL);
386 pMenuData->iIcon = iIcon;
387 pMenuData->hIcon = hIcon;
390 if (!
::InsertMenu(m_hMenu, nPosition, nFlags, nIDNewItem, (LPCTSTR)pMenuData))
395 if (nFlags & MF_POPUP)
397 HMENU hSubMenu = (HMENU)nIDNewItem;
418 SASSERT(IsMenu(m_hMenu));
423 menuOwner.
CreateNative(NULL, WS_POPUP, WS_EX_NOACTIVATE, 0, 0, 0, 0, NULL, 0, NULL);
424 if (IsWindow(hWnd) && IsWindowEnabled(hWnd))
425 ::SetForegroundWindow(hWnd);
426 UINT uNewFlags = uFlags | TPM_RETURNCMD;
429 if (uRet && !(uFlags & TPM_RETURNCMD))
430 ::SendMessage(hWnd, WM_COMMAND, uRet, 0);
440 if (wcsicmp(L
"item", xmlItem.
name()) == 0)
450 strText = TR(GETSTRING(strText),
GetMenuAttr(menuPopup)->m_strTrCtx);
463 while (xmlChild && xmlChild.
type() == node_pcdata)
468 UINT uFlag = MF_OWNERDRAW;
474 uFlag |= MFT_RADIOCHECK | MF_CHECKED;
475 ::AppendMenu(menuPopup, uFlag, (UINT_PTR)nID, (LPCTSTR)pdmmi);
479 HMENU hSubMenu = ::CreatePopupMenu();
482 SetMenuContextHelpId(hSubMenu, xmlItem.
attribute(L
"contextHelpId").
as_uint(0));
484 UINT uFlag = MF_OWNERDRAW | MF_POPUP;
487 ::AppendMenu(menuPopup, uFlag, (UINT_PTR)hSubMenu, (LPCTSTR)pdmmi);
491 else if (wcscmp(L
"sep", xmlItem.
name()) == 0)
493 ::AppendMenu(menuPopup, MF_SEPARATOR | MF_OWNERDRAW, (UINT_PTR)0, (LPCTSTR)NULL);
static SStringW EscapeString(const SStringW &str)
Escapes a string.