#include "TitleItem.h"
#include "MenuItem.h"
#include "MenuMaker.h"
#include "../Settings.h"
extern MenuMaker *pMenuMaker;
extern Settings *pSettings;
TitleItem::TitleItem(char* pszTitle, int type)
{
m_pszTitle = pszTitle ? strdup(pszTitle) : NULL;
itemType = type;
if (itemType == MENU_SEPARATOR) SetSortPriority(2);
else if (itemType == MENU_HEADER) SetSortPriority(255);
}
TitleItem::~TitleItem()
{
if (m_pszTitle) free(m_pszTitle);
m_pszTitle = NULL;
}
LRESULT TitleItem::NcHitTest(int x, int y)
{
if (IsOver(x, y))
{
if ((itemType == MENU_HEADER) && !m_pParent->GetParent()) return HTCAPTION;
else return HTCLIENT;
}
else return HTCLIENT;
}
void TitleItem::Invoke(int button)
{
if ((itemType == MENU_HEADER) && (button == 2)) pMenuMaker->Hide();
}
void TitleItem::Paint(HDC hDC)
{
RECT r;
GetTitleRect(&r);
MenuItem::Paint(hDC);
if (itemType == MENU_HEADER)
{
DrawTextWithShadow(hDC, m_pszTitle, r, GetDrawTextFormat(), pSettings->MenuTitle->TextColor, pSettings->menuTitleShadowColor, pSettings->MenuTitle->FontShadow);
}
else if (itemType == MENU_SEPARATOR)
{
HPEN hPen, hOldPen;
hPen = CreatePen(PS_SOLID, 1, pSettings->menuSeparatorColor);
hOldPen = (HPEN) SelectObject(hDC, hPen);
int fromX = m_nLeft + pMenuMaker->m_nBorderWidth + 3;
int toX = m_nLeft + GetWidth() - pMenuMaker->m_nBorderWidth - 3;
int lineY = m_nTop + 3;
MoveToEx(hDC, fromX, lineY, NULL);
LineTo (hDC, toX, lineY);
SelectObject(hDC, hOldPen);
DeleteObject(hPen);
DeleteObject(hOldPen);
}
else if (itemType == MENU_NOP) DrawTextWithShadow(hDC, m_pszTitle, r, GetDrawTextFormat(), pSettings->MenuFrame->TextColor, pSettings->menuFrameShadowColor, pSettings->MenuFrame->FontShadow);
else
{
if (IsActive()) DrawTextWithShadow(hDC, m_pszTitle, r, GetDrawTextFormat(), pSettings->MenuHilite->TextColor, pSettings->menuHiliteShadowColor, pSettings->MenuHilite->FontShadow);
else DrawTextWithShadow(hDC, m_pszTitle, r, GetDrawTextFormat(), pSettings->MenuFrame->TextColor, pSettings->menuFrameShadowColor, pSettings->MenuFrame->FontShadow);
}
}
void TitleItem::GetTitleRect(RECT* r)
{
if (itemType == MENU_HEADER)
{
r->top = m_nTop;
r->left = m_nLeft + pMenuMaker->m_nBorderWidth + 3;
r->bottom = m_nTop + GetHeight();
r->right = m_nLeft + GetWidth() - pMenuMaker->m_nBorderWidth - 3;
if (!stricmp(pSettings->MenuTitle->Font, "nu")) r->bottom--;
}
else
{
r->top = m_nTop;
r->left = m_nLeft + GetIndent();
r->bottom = m_nTop + GetHeight();
r->right = m_nLeft + GetWidth() - GetRightIndent();
}
}
UINT TitleItem::GetDrawTextFormat()
{
if (itemType == MENU_HEADER)
return GetTitleAlignment() | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS | DT_NOCLIP;
else
return GetAlignment() | DT_VCENTER | DT_NOPREFIX | DT_SINGLELINE | DT_END_ELLIPSIS | DT_NOCLIP;
}
void TitleItem::SetTitle(char* pszTitle)
{
if(m_pszTitle) free(m_pszTitle);
m_pszTitle = NULL;
m_pszTitle = pszTitle ? strdup(pszTitle) : NULL;
}
syntax highlighting by