#include "MenuItem.h"
#include "Painter.h"
#include "MenuMaker.h"
#include "Menu.h"
#include "../Settings.h"
#include "../Toolbar.h"
extern MenuMaker *pMenuMaker;
extern Settings *pSettings;
extern Toolbar *pToolbar;
int MenuItem::m_nAlignment = DT_LEFT;
int MenuItem::m_nTitleAlignment = DT_LEFT;
int MenuItem::m_nIndent = 0;
int MenuItem::m_nRightIndent = 0;
MenuItem::MenuItem()
{
m_pParent = NULL;
m_nWidth = 0;
m_nHeight = 0;
m_pForeground = NULL;
m_pBackground = NULL;
m_pActiveForeground = NULL;
m_pActiveBackground = NULL;
m_bActive = false;
m_nSortPriority = 1;
}
MenuItem::~MenuItem()
{
}
void MenuItem::Paint(HDC hDC)
{
SetBkMode(hDC, TRANSPARENT);
if(m_bActive && m_pActiveBackground) m_pActiveBackground->Paint(this, hDC);
else if (m_pBackground) m_pBackground->Paint(this, hDC);
}
void MenuItem::Invoke(int button)
{
if (pSettings->followActive) SetForegroundWindow(pToolbar->hToolbarWnd);
for (int n=0; n < (int)pMenuMaker->m_RootMenus.size(); ++n)
{
Menu *pMenu = pMenuMaker->m_RootMenus[n];
if (pMenu->HasMoved()) break;
pMenuMaker->Hide();
ShowWindow(pMenu->GetWindow(), SW_HIDE);
}
}
void MenuItem::Mouse(UINT nMsg, int x, int y)
{
RECT r;
m_mousePos.x = x;
m_mousePos.y = y;
GetItemRect(&r);
if (PtInRect(&r, m_mousePos))
{
switch (nMsg)
{
case WM_LBUTTONUP:
case WM_NCLBUTTONUP:
Invoke(1);
break;
case WM_RBUTTONUP:
case WM_NCRBUTTONUP:
Invoke(2);
break;
case WM_MBUTTONUP:
case WM_NCMBUTTONUP:
Invoke(3);
break;
case WM_MOUSEMOVE:
case WM_NCMOUSEMOVE:
Active(true);
break;
default:
break;
}
}
else Active(false);
}
void MenuItem::Timer(int nTimer)
{
}
int MenuItem::IsOver(int x, int y)
{
if ((x >= 0) && (x <= GetWidth()) && (y >= m_nTop) && (y <= m_nTop + GetHeight()))
return true;
else
return false;
}
void MenuItem::Attached(Menu* pMenu)
{
m_pParent = pMenu;
}
bool MenuItem::Active(bool bActive)
{
if (GetSortPriority() == 255) return false;
RECT r;
if (m_bActive != bActive)
{
m_bActive = bActive;
GetItemRect(&r);
RedrawWindow(m_pParent->GetWindow(), &r, NULL, RDW_INVALIDATE);
}
return m_bActive;
}
void MenuItem::GetItemRect(LPRECT lpRect)
{
lpRect->top = m_nTop;
lpRect->left = 0;
lpRect->right = lpRect->left + GetWidth();
lpRect->bottom = lpRect->top + GetHeight();
}
void MenuItem::SetPainter(Painter* pBackground)
{
m_pBackground = pBackground;
}
void MenuItem::SetActivePainter(Painter* pBackground)
{
m_pActiveBackground = pBackground;
}
HWND MenuItem::GetWindow()
{
if(m_pParent)
return m_pParent->GetWindow();
else
return NULL;
}
LRESULT MenuItem::Command(WPARAM wParam, LPARAM lParam)
{
return 0;
}
bool MenuItem::Compare(MenuItem* m1,MenuItem* m2)
{
int m1_sort = m1->GetSortPriority();
int m2_sort = m2->GetSortPriority();
if(m1_sort == m2_sort)
return stricmp(m1->GetSortString(), m2->GetSortString()) < 0;
else
return m1_sort > m2_sort;
}
syntax highlighting by