#include "StringItem.h"
#include "TitleItem.h"
#include "Menu.h"
#include "../Settings.h"
#include "../BImage.h"
#include "../Toolbar.h"
extern MenuMaker* pMenuMaker;
extern Settings *pSettings;
extern BImage *pBImage;
extern Toolbar *pToolbar;
StringItem::StringItem(char* pszTitle, char* pszCommand, char* pszInit) : TitleItem(pszTitle, MENU_DEFAULT)
{
m_pszCommand = pszCommand ? strdup(pszCommand) : NULL;
m_pszInit = pszInit ? strdup(pszInit) : NULL;
m_hwndEditor = NULL;
HDC fonthdc = CreateDC("DISPLAY", NULL, NULL, NULL);
HGDIOBJ oldEntryfont = SelectObject(fonthdc, pMenuMaker->m_hEntryFont);
GetTextExtentPoint32(fonthdc, "OK", 3, &buttonSize);
SelectObject(fonthdc, oldEntryfont);
DeleteDC(fonthdc);
editboxActive = false;
}
StringItem::~StringItem()
{
if (m_hwndEditor) DestroyWindow(m_hwndEditor);
if(m_pszCommand) free(m_pszCommand);
m_pszCommand = NULL;
if(m_pszInit) free(m_pszInit);
m_pszInit = NULL;
}
void StringItem::Paint(HDC hDC)
{
RECT r;
GetTitleRect(&r);
if (editboxActive)
{
bool status = this->m_bActive;
this->m_bActive = false;
MenuItem::Paint(hDC);
this->m_bActive = status;
RECT rbutton;
rbutton.left = GetWidth() - pSettings->menuBorderWidth - buttonSize.cx - 4;
rbutton.right = rbutton.left + buttonSize.cx;
rbutton.top = r.top;
rbutton.bottom = r.bottom;
pBImage->CreateGradientByRect(hDC, rbutton, pSettings->MenuIndicator->type, pSettings->MenuIndicator->Color, pSettings->MenuIndicator->ColorTo, pSettings->MenuIndicator->interlaced, pSettings->MenuIndicator->bevelstyle, pSettings->MenuIndicator->bevelposition, pSettings->bevelWidth);
DrawTextWithShadow(hDC, "OK", rbutton, DT_CENTER | DT_VCENTER | DT_NOPREFIX | DT_SINGLELINE | DT_END_ELLIPSIS | DT_NOCLIP, pSettings->MenuHilite->TextColor, pSettings->menuHiliteShadowColor, pSettings->MenuHilite->FontShadow);
if (!m_hwndEditor)
{
int editboxX = 3 + pSettings->menuBorderWidth;
int editboxY = r.top;
int editboxWidth = rbutton.left - 3 - editboxX;
int editboxHeight = r.bottom - r.top;
m_hwndEditor = CreateWindowEx(
WS_EX_TOPMOST,
"edit",
NULL,
WS_CHILD|WS_VISIBLE|WS_BORDER|ES_LEFT|ES_AUTOHSCROLL,
editboxX,
editboxY,
editboxWidth,
editboxHeight,
m_pParent->GetWindow(),
NULL,
m_pParent->m_hInstance,
NULL
);
SendMessage(m_hwndEditor, (UINT) WM_SETFONT, (WPARAM) pMenuMaker->m_hEntryFont, TRUE);
SendMessage(m_hwndEditor, (UINT) EM_SETLIMITTEXT, (WPARAM) 255, 0);
SendMessage(m_hwndEditor, WM_SETTEXT, 0, (LPARAM) m_pszInit);
ShowWindow(m_hwndEditor, SW_SHOW);
}
else ShowWindow(m_hwndEditor, SW_SHOWNOACTIVATE);
}
else
{
if (m_hwndEditor) ShowWindow(m_hwndEditor, SW_HIDE);
MenuItem::Paint(hDC);
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 StringItem::Invoke(int button)
{
if (button == 1 && m_hwndEditor)
{
editboxActive = false;
if (pSettings->followActive) SetForegroundWindow(pToolbar->hToolbarWnd);
char editedValue[256], broam[MAX_LINE_LENGTH], display[MAX_LINE_LENGTH];;
SendMessage(m_hwndEditor, WM_GETTEXT, 256, (LPARAM) &editedValue);
strcpy(broam, m_pszCommand);
strcat(broam, " ");
strcat(broam, editedValue);
strcpy(display, "xoblite -> ");
strcat(display, broam);
PostMessage(GetBBWnd(), BB_BROADCAST, 0, (LPARAM)broam);
SendMessage(GetBBWnd(), BB_SETTOOLBARLABEL, 0, (LPARAM)display);
PostMessage(GetBBWnd(), BB_HIDEMENU, 0, 0);
}
else if (button == 2)
{
if (!editboxActive && !pSettings->menuEditboxAlreadyActive)
{
pSettings->menuEditboxAlreadyActive = true;
editboxActive = true;
}
else
{
pSettings->menuEditboxAlreadyActive = false;
editboxActive = false;
}
this->m_bActive = false;
MenuItem::Active(true);
}
}
syntax highlighting by