1: /*
2: ============================================================================
3: xoblite™ -> an advanced "extended shell" for Microsoft® Windows® 11
4: Copyright © 2002-2026 Karl Henrik Henriksson [qwilk/@xoblite]
5: Copyright © 2001-2004 The Blackbox for Windows Development Team
6: http://xoblite.net/ + https://github.com/xoblite/
7: ============================================================================
8:
9: Blackbox for Windows is free software, released under the
10: GNU General Public License (GPL version 2 or later), with an extension
11: that allows linking of proprietary modules under a controlled interface.
12: What this means is that plugins etc. are allowed to be released
13: under any license the author wishes. Please note, however, that the
14: original Blackbox gradient math code used in Blackbox for Windows
15: is available under the BSD license.
16:
17: http://www.fsf.org/licenses/gpl.html
18: http://www.fsf.org/licenses/gpl-faq.html#LinkingOverControlledInterface
19: http://www.xfree86.org/3.3.6/COPYRIGHT2.html#5
20:
21: This program is distributed in the hope that it will be useful,
22: but WITHOUT ANY WARRANTY; without even the implied warranty of
23: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24: GNU General Public License for more details.
25:
26: For additional license information, please read the included license.html.
27:
28: ============================================================================
29: */
30:
31: #include "Tooltips.h"
32:
33: extern Toolbar *pToolbar;
34: extern Taskbar *pTaskbar;
35: extern Settings *pSettings;
36:
37: //===========================================================================
38:
39: Tooltips::Tooltips()
40: {
41: hToolTipsWnd = NULL;
42: }
43:
44: //====================
45:
46: Tooltips::~Tooltips()
47: {
48: if (hToolTipsWnd) DestroyWindow(hToolTipsWnd);
49: }
50:
51: //====================
52:
53: void Tooltips::Initialize(HINSTANCE hInstance, HWND hWnd)
54: {
55: hOwnerInstance = hInstance;
56: hOwnerWnd = hWnd;
57:
58: if (pSettings->taskbarTooltips) CreateTooltipsWindow();
59: }
60:
61: //===========================================================================
62: // Function: CreateTooltipsWindow
63: // Purpose: ...
64: //===========================================================================
65:
66: void Tooltips::CreateTooltipsWindow()
67: {
68: hToolTipsWnd = CreateWindowEx(
69: WS_EX_TOOLWINDOW | WS_EX_TOPMOST, // window style
70: TOOLTIPS_CLASS, // pre-defined system class for tooltips
71: NULL, // window name
72: WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP, // window parameters
73: CW_USEDEFAULT, // x position
74: CW_USEDEFAULT, // y position
75: CW_USEDEFAULT, // window width
76: CW_USEDEFAULT, // window height
77: hOwnerWnd, // owner window
78: NULL, // no menu
79: hOwnerInstance, // hInstance
80: NULL // no window creation data
81: );
82:
83: if (!hToolTipsWnd)
84: {
85: MessageBox(0, "Error creating tooltips window!", "BBToolbar", MB_OK | MB_ICONERROR | MB_TOPMOST);
86: Log("Toolbar: Error creating tooltips window!", NULL);
87: return;
88: }
89:
90: //====================
91:
92: // Set some tooltips configuration parameters...
93: SendMessage(hToolTipsWnd, TTM_SETMAXTIPWIDTH, 0, 300); // -> Sets the maximum width (in pixels) for tooltips, i.e. before breaking the text into multiple lines
94: RECT tipMargin = { 4, 4, 4, 4 };
95: SendMessage(hToolTipsWnd, TTM_SETMARGIN, 0, (LPARAM)&tipMargin); // -> Sets the top, left, bottom, and right margins (in pixels) for tooltips
96: SendMessage(hToolTipsWnd, TTM_SETDELAYTIME, (WPARAM)(DWORD)TTDT_AUTOPOP, (LPARAM)MAKELONG(2000, 0)); // -> Sets the amount of time (in ms) a tooltip remains visible if the pointer is stationary within its bounding rectangle
97: SendMessage(hToolTipsWnd, TTM_SETDELAYTIME, (WPARAM)(DWORD)TTDT_INITIAL, (LPARAM)MAKELONG(100, 0)); // -> Sets the amount of time (in ms) a pointer must remain stationary within the bounding rectangle before the tooltip appears
98: SendMessage(hToolTipsWnd, TTM_SETDELAYTIME, (WPARAM)(DWORD)TTDT_RESHOW, (LPARAM)MAKELONG(10, 0)); // -> Sets the amount of time (in ms) it takes for a subsequent tooltip to appear as the pointer moves from one bounding rectangle to another
99:
100: // Set the tooltips colours... (background+text)
101: // SendMessage(hToolTipsWnd, TTM_SETTIPBKCOLOR, (WPARAM)pSettings->Toolbar->TextColor, 0);
102: // SendMessage(hToolTipsWnd, TTM_SETTIPTEXTCOLOR, (WPARAM)pSettings->Toolbar->Color, 0);
103: // SendMessage(hToolTipsWnd, TTM_SETTIPBKCOLOR, (WPARAM)pSettings->ToolbarWindowLabel->Color, 0);
104: // SendMessage(hToolTipsWnd, TTM_SETTIPTEXTCOLOR, (WPARAM)pSettings->ToolbarWindowLabel->TextColor, 0);
105: SendMessage(hToolTipsWnd, TTM_SETTIPBKCOLOR, (WPARAM)0x000000, 0); // -> Sets the background color for tooltips
106: SendMessage(hToolTipsWnd, TTM_SETTIPTEXTCOLOR, (WPARAM)0xffffff, 0); // -> Sets the text color for tooltips
107: }
108:
109: //===========================================================================
110: // Function: ToggleTooltips
111: // Purpose: ...
112: //===========================================================================
113:
114: void Tooltips::ToggleTooltips()
115: {
116: // Should we enable or disable taskbar tooltips?
117: if (pSettings->taskbarTooltips)
118: {
119: pSettings->taskbarTooltips = false;
120: DeleteAllTooltips();
121: if (hToolTipsWnd) DestroyWindow(hToolTipsWnd);
122: hToolTipsWnd = NULL;
123: }
124: else
125: {
126: pSettings->taskbarTooltips = true;
127: if (!hToolTipsWnd) CreateTooltipsWindow();
128: pToolbar->UpdateToolbarWindow(); // This will also create taskbar tooltips if/as applicable...
129: }
130:
131: // Save the new setting to xoblite.rc...
132: WriteBool(pSettings->xobrcFile, "xoblite.taskbar.tooltips:", pSettings->taskbarTooltips);
133: }
134:
135: //===========================================================================
136: // Function: CreateToolTip
137: // Purpose: Creates (or modifies if it already exists) a single tooltip
138: //===========================================================================
139:
140: void Tooltips::CreateToolTip(unsigned int tipID, RECT tipRect, char tipText[MAX_LINE_LENGTH], int tipType)
141: {
142: if (!hToolTipsWnd) return;
143:
144: // Fill in the basics of the TOOLINFO structure...
145: TOOLINFO ti;
146: ZeroMemory(&ti, sizeof(ti));
147: ti.cbSize = sizeof(TOOLINFO);
148: ti.hwnd = pToolbar->hToolbarWnd;
149: ti.uId = tipID;
150:
151: // Check to see if the tooltip exists...
152: bool exists = SendMessage(hToolTipsWnd, TTM_GETTOOLINFO, 0, (LPARAM)(LPTOOLINFO)&ti) ? true : false;
153:
154: // Complete the rest of the TOOLINFO structure...
155: ti.uFlags = TTF_SUBCLASS | TTF_CENTERTIP; // -> Center the tooltip below the item...
156: ti.hinst = pToolbar->hToolbarInstance;
157: ti.lpszText = tipText;
158: ti.rect = tipRect;
159:
160: // If it exists, modify the tooltip, if not, add it...
161: if (exists) SendMessage(hToolTipsWnd, TTM_SETTOOLINFO, 0, (LPARAM)(LPTOOLINFO)&ti);
162: else SendMessage(hToolTipsWnd, TTM_ADDTOOL, 0, (LPARAM)&ti);
163: }
164:
165: //===========================================================================
166: // Functions: DeleteToolTip / DeleteAllToolTips
167: // Purpose: Deletes a single tooltips / all tooltips
168: //===========================================================================
169:
170: void Tooltips::DeleteToolTip(unsigned int tipID, int tipType)
171: {
172: if (!hToolTipsWnd) return;
173:
174: // Fill in the basics of the TOOLINFO structure...
175: TOOLINFO ti;
176: ZeroMemory(&ti, sizeof(ti));
177: ti.cbSize = sizeof(TOOLINFO);
178: ti.hwnd = pToolbar->hToolbarWnd;
179: ti.uId = tipID;
180:
181: // Check to see if the tooltip exists, and if so delete it...
182: // bool exists = SendMessage(hToolTipsWnd, TTM_GETTOOLINFO, 0, (LPARAM)(LPTOOLINFO)&ti) ? true : false;
183: // if (exists) SendMessage(hToolTipsWnd, TTM_DELTOOL, 0, (LPARAM)(LPTOOLINFO)&ti);
184: SendMessage(hToolTipsWnd, TTM_DELTOOL, 0, (LPARAM)(LPTOOLINFO)&ti);
185: }
186:
187:
188: //====================
189:
190: void Tooltips::DeleteAllTooltips()
191: {
192: // Delete any existing taskbar tooltips...
193: for (int i=0; i < (int)pTaskbar->taskList.size(); i++)
194: {
195: DeleteToolTip((UINT)pTaskbar->taskList[i]->hwnd, TOOLTIP_TYPE_TASK);
196: }
197: }
198:
199: //===========================================================================
200: // Function: RefreshAllTooltips
201: // Purpose: ...
202: //===========================================================================
203: /*
204: void Tooltips::RefreshAllTooltips()
205: {
206: if (!hToolTipsWnd || pSettings->accessLock) return;
207:
208: //====================
209:
210: if (pSettings->taskbarMode == TASKBAR_MODE_HIDDEN) DeleteAllTooltips();
211: else
212: {
213: // Refresh (i.e. create/modify) the taskbar tooltips...
214: for (int i = 0; i < (int)pTaskbar->taskList.size(); i++)
215: {
216: if (!IsWindow(pTaskbar->taskList[i]->hwnd)) break;
217: if (pTaskbar->OnCurrentWorkspace(pTaskbar->taskList[i]->hwnd))
218: {
219: CreateToolTip((UINT)pTaskbar->taskList[i]->hwnd, pTaskbar->taskList[i]->r, pTaskbar->taskList[i]->caption, TOOLTIP_TYPE_TASK);
220: }
221: else DeleteToolTip((UINT)pTaskbar->taskList[i]->hwnd, TOOLTIP_TYPE_TASK); // Delete tooltips for tasks not on this workspace...
222: }
223: }
224: }
225: */
226: //===========================================================================
227: