2011-08-28 10:58:26 +00:00
|
|
|
/*
|
|
|
|
Copyright (C) 2011 Birunthan Mohanathas
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
2012-01-23 06:36:15 +00:00
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2011-08-28 10:58:26 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "StdAfx.h"
|
|
|
|
#include "Dialog.h"
|
|
|
|
|
2013-05-31 14:28:39 +00:00
|
|
|
HWND Dialog::c_ActiveDialogWindow = nullptr;
|
|
|
|
HWND Dialog::c_ActiveTabWindow = nullptr;
|
2012-02-14 17:00:07 +00:00
|
|
|
|
2011-08-28 10:58:26 +00:00
|
|
|
/*
|
|
|
|
** Constructor.
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
Dialog::Dialog(HWND wnd) :
|
2011-08-28 10:58:26 +00:00
|
|
|
m_Window(wnd),
|
|
|
|
m_Font(),
|
|
|
|
m_FontBold()
|
|
|
|
{
|
|
|
|
NONCLIENTMETRICS ncm;
|
|
|
|
ncm.cbSize = sizeof(NONCLIENTMETRICS) - sizeof(ncm.iPaddedBorderWidth);
|
|
|
|
SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &ncm, 0);
|
|
|
|
m_Font = CreateFontIndirect(&ncm.lfMenuFont);
|
|
|
|
ncm.lfMenuFont.lfWeight = FW_BOLD;
|
|
|
|
ncm.lfMenuFont.lfHeight -= 2;
|
|
|
|
m_FontBold = CreateFontIndirect(&ncm.lfMenuFont);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Destructor.
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
Dialog::~Dialog()
|
2011-08-28 10:58:26 +00:00
|
|
|
{
|
|
|
|
DeleteObject(m_Font);
|
|
|
|
DeleteObject(m_FontBold);
|
|
|
|
}
|
|
|
|
|
2013-05-31 14:18:52 +00:00
|
|
|
INT_PTR Dialog::OnActivate(WPARAM wParam, LPARAM lParam)
|
2012-02-14 17:00:07 +00:00
|
|
|
{
|
2012-02-21 09:03:16 +00:00
|
|
|
if (wParam)
|
|
|
|
{
|
|
|
|
c_ActiveDialogWindow = m_Window;
|
2012-06-16 18:41:17 +00:00
|
|
|
c_ActiveTabWindow = GetActiveWindow();
|
2012-02-21 09:03:16 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-05-31 14:28:39 +00:00
|
|
|
c_ActiveDialogWindow = c_ActiveTabWindow = nullptr;
|
2012-02-21 09:03:16 +00:00
|
|
|
}
|
|
|
|
|
2012-02-14 17:00:07 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2011-08-28 10:58:26 +00:00
|
|
|
/*
|
|
|
|
** Sets dialog font to UI font.
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
void Dialog::SetDialogFont(HWND window)
|
2011-08-28 10:58:26 +00:00
|
|
|
{
|
2012-06-16 18:41:17 +00:00
|
|
|
EnumChildWindows(window, SetFontProc, (WPARAM)m_Font);
|
2011-08-28 10:58:26 +00:00
|
|
|
}
|
|
|
|
|
2013-05-31 14:18:52 +00:00
|
|
|
BOOL CALLBACK Dialog::SetFontProc(HWND hWnd, LPARAM lParam)
|
2011-08-28 10:58:26 +00:00
|
|
|
{
|
|
|
|
SendMessage(hWnd, WM_SETFONT, (WPARAM)lParam, 0);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-06-17 13:31:16 +00:00
|
|
|
/*
|
|
|
|
** Subclass button control to draw arrow on the right.
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
void Dialog::SetMenuButton(HWND button)
|
2012-06-17 13:31:16 +00:00
|
|
|
{
|
2013-05-31 14:28:39 +00:00
|
|
|
SetWindowSubclass(button, MenuButtonProc, 0, 0);
|
2012-06-17 13:31:16 +00:00
|
|
|
}
|
|
|
|
|
2013-05-31 14:18:52 +00:00
|
|
|
LRESULT CALLBACK Dialog::MenuButtonProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData)
|
2012-06-17 13:31:16 +00:00
|
|
|
{
|
2012-06-23 19:17:16 +00:00
|
|
|
LRESULT result = DefSubclassProc(hWnd, uMsg, wParam, lParam);
|
|
|
|
|
2012-06-17 13:31:16 +00:00
|
|
|
switch (uMsg)
|
|
|
|
{
|
|
|
|
case WM_PAINT:
|
|
|
|
{
|
|
|
|
// Draw arrow on top of the button
|
|
|
|
RECT buttonRect;
|
|
|
|
GetClientRect(hWnd, &buttonRect);
|
|
|
|
int arrowX = buttonRect.right - 18;
|
2012-06-19 14:15:51 +00:00
|
|
|
int arrowY = buttonRect.top + 4;
|
|
|
|
RECT arrowRect = { arrowX, arrowY, arrowX + 14, arrowY + 14 };
|
2012-06-17 13:31:16 +00:00
|
|
|
|
2012-06-19 14:15:51 +00:00
|
|
|
HDC dc = GetDC(hWnd);
|
|
|
|
const WORD DFCS_MENUARROWDOWN = 0x0010; // Undocumented
|
2012-06-17 13:31:16 +00:00
|
|
|
DWORD drawFlags = DFCS_TRANSPARENT | DFCS_MENUARROWDOWN | (IsWindowEnabled(hWnd) ? 0 : DFCS_INACTIVE);
|
|
|
|
DrawFrameControl(dc, &arrowRect, DFC_MENU, drawFlags);
|
|
|
|
ReleaseDC(hWnd, dc);
|
2012-06-23 19:17:16 +00:00
|
|
|
}
|
|
|
|
break;
|
2012-06-19 14:15:51 +00:00
|
|
|
|
2012-06-23 19:17:16 +00:00
|
|
|
case WM_GETTEXT:
|
|
|
|
{
|
|
|
|
// Append 3 spaces to the button text to move text to the left so
|
|
|
|
// that it looks better with BS_CENTER.
|
|
|
|
WCHAR* str = (WCHAR*)lParam + result;
|
|
|
|
str[0] = str[1] = str[2] = L' ';
|
|
|
|
str[3] = '\0';
|
|
|
|
result += 3;
|
2012-06-17 13:31:16 +00:00
|
|
|
}
|
|
|
|
break;
|
2012-06-19 14:15:51 +00:00
|
|
|
|
2012-06-23 19:17:16 +00:00
|
|
|
case WM_GETTEXTLENGTH:
|
|
|
|
result += 3;
|
|
|
|
break;
|
|
|
|
|
2012-06-19 14:15:51 +00:00
|
|
|
case WM_NCDESTROY:
|
|
|
|
RemoveWindowSubclass(hWnd, MenuButtonProc, uIdSubclass);
|
|
|
|
break;
|
2012-06-17 13:31:16 +00:00
|
|
|
}
|
|
|
|
|
2012-06-23 19:17:16 +00:00
|
|
|
return result;
|
2012-06-17 13:31:16 +00:00
|
|
|
}
|
|
|
|
|
2011-08-28 10:58:26 +00:00
|
|
|
/*
|
|
|
|
** Constructor.
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
Dialog::Tab::Tab(HINSTANCE instance, HWND owner, WORD tabId, DLGPROC tabProc) :
|
2011-11-25 19:11:46 +00:00
|
|
|
m_Window(CreateDialog(instance, MAKEINTRESOURCE(tabId), owner, tabProc)),
|
2011-08-28 10:58:26 +00:00
|
|
|
m_Initialized(false)
|
|
|
|
{
|
2011-11-21 12:53:55 +00:00
|
|
|
EnableThemeDialogTexture(m_Window, ETDT_ENABLETAB);
|
2011-08-28 10:58:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Destructor.
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
Dialog::Tab::~Tab()
|
2011-08-28 10:58:26 +00:00
|
|
|
{
|
|
|
|
DestroyWindow(m_Window);
|
|
|
|
}
|
2011-11-25 19:11:46 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
** Activates the tab.
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
void Dialog::Tab::Activate()
|
2011-11-25 19:11:46 +00:00
|
|
|
{
|
2012-02-21 09:03:16 +00:00
|
|
|
c_ActiveTabWindow = m_Window;
|
|
|
|
|
2011-11-25 19:11:46 +00:00
|
|
|
if (!m_Initialized)
|
|
|
|
{
|
|
|
|
Initialize();
|
|
|
|
}
|
|
|
|
|
2012-02-14 17:00:07 +00:00
|
|
|
EnableWindow(m_Window, TRUE);
|
2011-11-25 19:11:46 +00:00
|
|
|
BringWindowToTop(m_Window);
|
|
|
|
}
|