| 1 |
/* |
| 2 |
Copyright (c) 2003 Sunil Kamath |
| 3 |
Modified by Joost Verburg |
| 4 |
|
| 5 |
This software is provided 'as-is', without any express or implied |
| 6 |
warranty. In no event will the authors be held liable for any damages |
| 7 |
arising from the use of this software. |
| 8 |
|
| 9 |
Permission is granted to anyone to use this software for any purpose, |
| 10 |
including commercial applications, and to alter it and redistribute it |
| 11 |
freely, subject to the following restrictions: |
| 12 |
|
| 13 |
1. The origin of this software must not be misrepresented; you must not |
| 14 |
claim that you wrote the original software. If you use this software |
| 15 |
in a product, an acknowledgment in the product documentation would be |
| 16 |
appreciated but is not required. |
| 17 |
2. Altered source versions must be plainly marked as such, and must not be |
| 18 |
misrepresented as being the original software. |
| 19 |
3. This notice may not be removed or altered from any source distribution. |
| 20 |
|
| 21 |
Unicode support by Jim Park -- 08/20/2007 |
| 22 |
|
| 23 |
*/ |
| 24 |
#define TOOLBAR_CPP |
| 25 |
|
| 26 |
#include "makensisw.h" |
| 27 |
#include "resource.h" |
| 28 |
#include "toolbar.h" |
| 29 |
|
| 30 |
NTOOLBAR g_toolbar; |
| 31 |
extern NSCRIPTDATA g_sdata; |
| 32 |
extern NTOOLTIP g_tip; |
| 33 |
|
| 34 |
typedef struct { |
| 35 |
BYTE Style, State; |
| 36 |
BYTE ImgIdx; |
| 37 |
BYTE TTip; |
| 38 |
WORD CmdId; |
| 39 |
} TBBTNDESC; |
| 40 |
#define MKNAMEDTBBTNDESC(id, sta, sty) sty, sta, IDB_##id, IDS_##id, IDM_##id |
| 41 |
|
| 42 |
static const TBBTNDESC g_TBBtnsDesc[BUTTONCOUNT] = { |
| 43 |
/*TBB_LOADSCRIPT*/ { MKNAMEDTBBTNDESC(LOADSCRIPT, TBSTATE_ENABLED, TBSTYLE_BUTTON ) }, |
| 44 |
/*TBB_SAVE */ { MKNAMEDTBBTNDESC(SAVE, TBSTATE_INDETERMINATE, TBSTYLE_BUTTON ) }, |
| 45 |
/*TBB_SEP1 */ { TBSTYLE_SEP }, |
| 46 |
/*TBB_COPY */ { MKNAMEDTBBTNDESC(COPY, TBSTATE_ENABLED, TBSTYLE_BUTTON ) }, |
| 47 |
/*TBB_FIND */ { MKNAMEDTBBTNDESC(FIND, TBSTATE_ENABLED, TBSTYLE_BUTTON ) }, |
| 48 |
/*TBB_CLEARLOG */ { MKNAMEDTBBTNDESC(CLEARLOG, TBSTATE_ENABLED, TBSTYLE_BUTTON ) }, |
| 49 |
/*TBB_SEP2 */ { TBSTYLE_SEP }, |
| 50 |
/*TBB_RECOMPILE */ { MKNAMEDTBBTNDESC(RECOMPILE, TBSTATE_INDETERMINATE, TBSTYLE_BUTTON ) }, |
| 51 |
/*TBB_TEST */ { MKNAMEDTBBTNDESC(TEST, TBSTATE_INDETERMINATE, TBSTYLE_BUTTON ) }, |
| 52 |
/*TBB_COMPRESSOR*/ { MKNAMEDTBBTNDESC(COMPRESSOR, TBSTATE_ENABLED, TBSTYLE_DROPDOWN) }, |
| 53 |
/*TBB_EDITSCRIPT*/ { MKNAMEDTBBTNDESC(EDITSCRIPT, TBSTATE_INDETERMINATE, TBSTYLE_BUTTON ) }, |
| 54 |
/*TBB_BROWSESCR */ { MKNAMEDTBBTNDESC(BROWSESCR, TBSTATE_INDETERMINATE, TBSTYLE_BUTTON ) } |
| 55 |
}; |
| 56 |
|
| 57 |
static const BYTE g_TBIL[] = { |
| 58 |
/* 16 */ IDB_TOOLBAR16N24, IDB_TOOLBAR16D24, IDB_TOOLBAR16H24, |
| 59 |
/* 24 */ IDB_TOOLBAR24N24, IDB_TOOLBAR24D24, IDB_TOOLBAR24H24, |
| 60 |
/* 32 */ IDB_TOOLBAR32N24, IDB_TOOLBAR32D24, IDB_TOOLBAR32H24 |
| 61 |
}; |
| 62 |
|
| 63 |
static void LoadToolBarImages(); |
| 64 |
|
| 65 |
void CreateToolBar() |
| 66 |
{ |
| 67 |
g_toolbar.hwnd = CreateWindowEx(0, TOOLBARCLASSNAME, NULL, |
| 68 |
WS_CHILD | WS_VISIBLE | TBSTYLE_TRANSPARENT | TBSTYLE_FLAT, |
| 69 |
0, 0, 0, 0, g_sdata.hwnd, (HMENU) IDC_TOOLBAR, g_sdata.hInstance, NULL); |
| 70 |
|
| 71 |
TBBUTTON tbbs[BUTTONCOUNT]; |
| 72 |
SendMessage(g_toolbar.hwnd, TB_BUTTONSTRUCTSIZE, sizeof(tbbs[0]), 0); |
| 73 |
for (UINT i = 0; i < BUTTONCOUNT; ++i) |
| 74 |
{ |
| 75 |
tbbs[i].iBitmap = g_TBBtnsDesc[i].ImgIdx; |
| 76 |
tbbs[i].idCommand = g_TBBtnsDesc[i].CmdId; |
| 77 |
tbbs[i].fsState = g_TBBtnsDesc[i].State; |
| 78 |
tbbs[i].fsStyle = g_TBBtnsDesc[i].Style; |
| 79 |
tbbs[i].dwData = 0, tbbs[i].iString = 0; |
| 80 |
} |
| 81 |
SendMessage(g_toolbar.hwnd, TB_ADDBUTTONS, BUTTONCOUNT, (LPARAM) &tbbs); // Note: TB_ADDBUTTONSW is IE4+ |
| 82 |
LoadToolBarImages(); |
| 83 |
} |
| 84 |
|
| 85 |
static void LoadToolBarImages() |
| 86 |
{ |
| 87 |
HWND hTB = g_toolbar.hwnd; |
| 88 |
// Comctl32.dll version detection |
| 89 |
#ifndef _WIN64 |
| 90 |
HMODULE hMod = LoadSysLibrary("COMCTL32"); |
| 91 |
const FARPROC hasCC4_70 = (SupportsW95()) ? GetProcAddress(hMod, "InitCommonControlsEx") : (FARPROC) TRUE; // NT4 shipped with v4.70 |
| 92 |
const FARPROC hasCC4_71 = (SupportsWNT4() || SupportsW95()) ? GetProcAddress(hMod, "DllGetVersion") : (FARPROC) TRUE; // IE4 shipped with v4.71 |
| 93 |
#else |
| 94 |
const bool hasCC4_70 = true, hasCC4_71 = true; |
| 95 |
#endif |
| 96 |
|
| 97 |
UINT iltypecount = 3, s16 = DpiScaleY(hTB, 16), imgsize, iloffs; // 144dpi(150%)=24 120dpi(125%)=20 |
| 98 |
if (s16 > 24) |
| 99 |
imgsize = 32, iloffs = 2 * iltypecount; |
| 100 |
else if (s16 > 16) |
| 101 |
imgsize = 24, iloffs = 1 * iltypecount; |
| 102 |
else |
| 103 |
imgsize = 16, iloffs = 0 * iltypecount; |
| 104 |
|
| 105 |
UINT dispbpp = GetScreenBPP(hTB); |
| 106 |
if (hasCC4_70 && dispbpp > 8) |
| 107 |
{ |
| 108 |
// Version 4.70 => Modern toolbar, 24-bit bitmaps |
| 109 |
g_toolbar.imagelist = ImageList_LoadImage(g_sdata.hInstance, MAKEINTRESOURCE(g_TBIL[iloffs+0]), imgsize, 0, RGB(255, 0, 255), IMAGE_BITMAP, LR_CREATEDIBSECTION); |
| 110 |
g_toolbar.imagelistd = ImageList_LoadImage(g_sdata.hInstance, MAKEINTRESOURCE(g_TBIL[iloffs+1]), imgsize, 0, RGB(255, 0, 255), IMAGE_BITMAP, LR_CREATEDIBSECTION); |
| 111 |
g_toolbar.imagelisth = ImageList_LoadImage(g_sdata.hInstance, MAKEINTRESOURCE(g_TBIL[iloffs+2]), imgsize, 0, RGB(255, 0, 255), IMAGE_BITMAP, LR_CREATEDIBSECTION); |
| 112 |
SendMessage(hTB, TB_SETIMAGELIST, 0, (LPARAM) g_toolbar.imagelist); |
| 113 |
SendMessage(hTB, TB_SETDISABLEDIMAGELIST, 0, (LPARAM) g_toolbar.imagelistd); |
| 114 |
SendMessage(hTB, TB_SETHOTIMAGELIST, 0, (LPARAM) g_toolbar.imagelisth); |
| 115 |
} |
| 116 |
else |
| 117 |
{ |
| 118 |
// Version 4.00 => Old Windows 95 toolbar, 256 color bitmap with system palette |
| 119 |
TBADDBITMAP tbBitmap; |
| 120 |
tbBitmap.hInst = g_sdata.hInstance; |
| 121 |
tbBitmap.nID = IDB_TOOLBAR; |
| 122 |
SendMessage(hTB, TB_ADDBITMAP, IMAGECOUNT, (LPARAM) &tbBitmap); |
| 123 |
} |
| 124 |
if (hasCC4_71) SendMessage(hTB, TB_SETEXTENDEDSTYLE, 0, TBSTYLE_EX_DRAWDDARROWS); |
| 125 |
} |
| 126 |
|
| 127 |
void UpdateToolBarCompressorButton() |
| 128 |
{ |
| 129 |
int iBitmap, iString; |
| 130 |
TCHAR szBuffer[124]; // increased to 124 for good measure, also. |
| 131 |
TCHAR temp[64]; // increased to 64. Hit limit 08/20/2007 -- Jim Park. |
| 132 |
|
| 133 |
if(g_sdata.compressor >= COMPRESSOR_SCRIPT && g_sdata.compressor <= COMPRESSOR_BEST) { |
| 134 |
iBitmap = compressor_bitmaps[(int)g_sdata.compressor]; |
| 135 |
iString = compressor_strings[(int)g_sdata.compressor]; |
| 136 |
} |
| 137 |
else { |
| 138 |
return; |
| 139 |
} |
| 140 |
|
| 141 |
LoadString(g_sdata.hInstance, IDS_COMPRESSOR, temp, COUNTOF(temp)); |
| 142 |
szBuffer[0] = _T('\0'); |
| 143 |
lstrcat(szBuffer,temp); |
| 144 |
lstrcat(szBuffer,_T(" [")); |
| 145 |
LoadString(g_sdata.hInstance, iString, temp, COUNTOF(temp)); |
| 146 |
lstrcat(szBuffer,temp); |
| 147 |
lstrcat(szBuffer,_T("]")); |
| 148 |
|
| 149 |
SendMessage(g_toolbar.hwnd, TB_CHANGEBITMAP, (WPARAM) IDM_COMPRESSOR, (LPARAM) MAKELPARAM(iBitmap, 0)); |
| 150 |
SetTooltipText(g_toolbar.hwnd, (UINT) TBB_COMPRESSOR, szBuffer); |
| 151 |
} |
| 152 |
|
| 153 |
void AddToolBarButtonTooltip(UINT idx, int iString) |
| 154 |
{ |
| 155 |
TOOLINFO ti; |
| 156 |
ti.cbSize = SizeOfStruct(ti); |
| 157 |
ti.uFlags = 0; |
| 158 |
ti.hwnd = g_toolbar.hwnd; |
| 159 |
ti.uId = idx; |
| 160 |
ti.hinst = g_sdata.hInstance, ti.lpszText = MAKEINTRESOURCE(iString); |
| 161 |
SendMessage(g_toolbar.hwnd, TB_GETITEMRECT, idx, (LPARAM) &ti.rect); |
| 162 |
|
| 163 |
SendMessage(g_tip.tip, TTM_ADDTOOL, 0, (LPARAM) &ti); |
| 164 |
} |
| 165 |
|
| 166 |
void AddToolBarTooltips() |
| 167 |
{ |
| 168 |
for (UINT i = 0; i < BUTTONCOUNT; ++i) { |
| 169 |
int ids = g_TBBtnsDesc[i].TTip; |
| 170 |
if (ids) AddToolBarButtonTooltip(i, ids); |
| 171 |
} |
| 172 |
} |
| 173 |
|
| 174 |
void EnableToolBarButton(int cmdid, BOOL enabled) |
| 175 |
{ |
| 176 |
UINT state = enabled ? TBSTATE_ENABLED : TBSTATE_INDETERMINATE; |
| 177 |
SendMessage(g_toolbar.hwnd, TB_SETSTATE, cmdid, MAKELPARAM(state, 0)); |
| 178 |
} |
| 179 |
|
| 180 |
static bool IsRTL(HWND hWnd) { return (((UINT) GetWindowLongPtr(hWnd, GWL_EXSTYLE)) & (WS_EX_LAYOUTRTL)) != 0; } // WS_EX_RIGHT? WS_EX_RTLREADING? |
| 181 |
|
| 182 |
#ifndef TPM_LAYOUTRTL |
| 183 |
#define TPM_LAYOUTRTL 0x8000 // For MinGW (w32api-4.0.3-1) |
| 184 |
#endif |
| 185 |
static UINT GetToolbarDropdownMenuPos(HWND hTB, UINT Id, POINT&pt) |
| 186 |
{ |
| 187 |
RECT r; |
| 188 |
INT_PTR idx = SendMessage(hTB, TB_COMMANDTOINDEX, Id, 0); |
| 189 |
UINT tpm_align = GetMenuDropAlignment(); |
| 190 |
bool ralign = tpm_align != TPM_LEFTALIGN, rtl = SupportsRTLUI() && IsRTL(hTB); |
| 191 |
SendMessage(hTB, TB_GETITEMRECT, idx, (LPARAM) &r); |
| 192 |
MapWindowPoints(hTB, NULL, (POINT*) &r, 2); |
| 193 |
pt.x = (rtl ^ ralign) ? r.right : r.left, pt.y = r.bottom; |
| 194 |
return tpm_align | (rtl ? TPM_LAYOUTRTL : 0) | TPM_VERTICAL; |
| 195 |
} |
| 196 |
|
| 197 |
static void ShowToolbarDropdownMenu(const NMTOOLBAR&nmtb, HWND hNotifyWnd, HMENU hParentMenu, UINT SubMenuId = -1) |
| 198 |
{ |
| 199 |
POINT pt; |
| 200 |
HMENU hMenu = SubMenuId == static_cast<UINT>(-1) ? hParentMenu : FindSubMenu(hParentMenu, SubMenuId); |
| 201 |
UINT tpmf = GetToolbarDropdownMenuPos(nmtb.hdr.hwndFrom, nmtb.iItem, pt); |
| 202 |
SendMessage(g_tip.tip, TTM_ACTIVATE, false, 0); |
| 203 |
TrackPopupMenu(hMenu, tpmf, pt.x, pt.y, 0, hNotifyWnd, NULL); |
| 204 |
SendMessage(g_tip.tip, TTM_ACTIVATE, true, 0); |
| 205 |
} |
| 206 |
|
| 207 |
void ShowCompressorToolbarDropdownMenu(const NMTOOLBAR&nmtb) |
| 208 |
{ |
| 209 |
HMENU hParentMenu = FindSubMenu(g_sdata.menu, IDM_SCRIPT); |
| 210 |
ShowToolbarDropdownMenu(nmtb, g_sdata.hwnd, hParentMenu, IDM_COMPRESSOR_SUBMENU); |
| 211 |
} |