1 |
/* wptTrayPop.cpp - Alternative status box |
/* wptTrayPop.cpp - Alternative status box |
2 |
* Copyright (C) 2002, 2004 Timo Schulz |
* Copyright (C) 2002, 2004 Timo Schulz |
3 |
* Copyright (C) 2002 Prasenjeet Dutta. <http://www.chaoszone.org> |
* Copyright (C) 2002 Prasenjeet Dutta. <http://www.chaoszone.org> |
4 |
* |
* |
5 |
* This file is part of WinPT. |
* This file is part of WinPT. |
6 |
* |
* |
7 |
* WinPT is free software; you can redistribute it and/or |
* WinPT is free software; you can redistribute it and/or |
8 |
* modify it under the terms of the GNU General Public License |
* modify it under the terms of the GNU General Public License |
9 |
* as published by the Free Software Foundation; either version 2 |
* as published by the Free Software Foundation; either version 2 |
10 |
* of the License, or (at your option) any later version. |
* of the License, or (at your option) any later version. |
11 |
* |
* |
12 |
* WinPT is distributed in the hope that it will be useful, |
* WinPT is distributed in the hope that it will be useful, |
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 |
* General Public License for more details. |
* General Public License for more details. |
16 |
* |
* |
17 |
* You should have received a copy of the GNU General Public License |
* You should have received a copy of the GNU General Public License |
18 |
* along with WinPT; if not, write to the Free Software Foundation, |
* along with WinPT; if not, write to the Free Software Foundation, |
19 |
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
20 |
* |
* |
21 |
*/ |
*/ |
22 |
|
#ifdef HAVE_CONFIG_H |
23 |
/* |
#include <config.h> |
24 |
* ChangeLog |
#endif |
25 |
* Maybe I didn't understand how to use the code, but the original code |
|
26 |
* always produces a window near the taskbar icon. This is not very useful |
#include <windows.h> |
27 |
* because we need it near the dialog. I also removed some code we don't use. |
|
28 |
* -ts |
#include "wptW32API.h" |
29 |
*/ |
|
30 |
|
#define PD_WINDOWNAME "WinPT_TrayPop" |
31 |
#include <windows.h> |
#define PD_TIMER_IDENTIFIER 23 |
32 |
|
#define PD_TIMER_TIMEOUT 1500 |
33 |
#include "wptW32API.h" |
|
34 |
|
/* XXX: use the given text to figure out these params. */ |
35 |
#define PD_WINDOWNAME "ClsTrayPop" |
#define PD_TRAYPOP_WIDTH 250 |
36 |
#define PD_TIMER_IDENTIFIER 23 |
#define PD_TRAYPOP_HEIGHT 80 |
37 |
#define PD_TIMER_TIMEOUT 1500 |
|
38 |
|
extern HINSTANCE glob_hinst; |
39 |
#define PD_TRAYPOP_WIDTH 200 |
extern HWND glob_hwnd; |
40 |
#define PD_TRAYPOP_HEIGHT 80 |
|
41 |
|
|
42 |
extern HINSTANCE glob_hinst; |
static LPCTSTR |
43 |
extern HWND glob_hwnd; |
store_text (LPCTSTR alert_text) |
44 |
|
{ |
45 |
|
static LPCTSTR text; |
46 |
static LPCTSTR |
|
47 |
store_text( LPCTSTR alert_text ) |
if (alert_text) |
48 |
{ |
text = alert_text; |
49 |
static LPCTSTR text; |
return text; |
50 |
|
} |
51 |
if( alert_text ) |
|
52 |
text = alert_text; |
|
53 |
return text; |
static void |
54 |
} /* store_text */ |
paint_alert (HDC *p_hdc, PAINTSTRUCT *p_ps) |
55 |
|
{ |
56 |
|
SetBkMode(*p_hdc, TRANSPARENT); |
57 |
static void |
HFONT hFont = CreateFont( |
58 |
paint_alert (HDC *p_hdc, PAINTSTRUCT *p_ps) |
13, // height of font (in css px-style) |
59 |
{ |
0, // average character width |
60 |
SetBkMode(*p_hdc, TRANSPARENT); |
0, // angle of escapement |
61 |
HFONT hFont = CreateFont( |
0, // base-line orientation angle |
62 |
13, // height of font (in css px-style) |
FW_DONTCARE, // font weight |
63 |
0, // average character width |
FALSE, // italic attribute option |
64 |
0, // angle of escapement |
FALSE, // underline attribute option |
65 |
0, // base-line orientation angle |
FALSE, // strikeout attribute option |
66 |
FW_DONTCARE, // font weight |
// TODO: future i18n problem, see docs |
67 |
FALSE, // italic attribute option |
DEFAULT_CHARSET, // character set identifier |
68 |
FALSE, // underline attribute option |
OUT_DEFAULT_PRECIS, // output precision |
69 |
FALSE, // strikeout attribute option |
CLIP_DEFAULT_PRECIS, // clipping precision |
70 |
// TODO: future i18n problem, see docs |
DEFAULT_QUALITY, // output quality |
71 |
DEFAULT_CHARSET, // character set identifier |
FF_DONTCARE, // pitch and family |
72 |
OUT_DEFAULT_PRECIS, // output precision |
"Tahoma" // typeface name |
73 |
CLIP_DEFAULT_PRECIS, // clipping precision |
); |
74 |
DEFAULT_QUALITY, // output quality |
|
75 |
FF_DONTCARE, // pitch and family |
HFONT hOldFont = (HFONT) SelectObject (*p_hdc, hFont); |
76 |
"Tahoma" // typeface name |
RECT recttext; |
77 |
); |
recttext.top = 0; |
78 |
|
recttext.bottom = PD_TRAYPOP_HEIGHT - 2; |
79 |
HFONT hOldFont = (HFONT) SelectObject(*p_hdc, hFont); |
recttext.left = 10; |
80 |
RECT recttext; |
recttext.right = PD_TRAYPOP_WIDTH - 12; |
81 |
recttext.top = 0; |
|
82 |
recttext.bottom = PD_TRAYPOP_HEIGHT - 2; |
MoveToEx (*p_hdc, 0, 0, (LPPOINT) NULL); |
83 |
recttext.left = 10; |
LineTo (*p_hdc, PD_TRAYPOP_WIDTH - 3, 0); |
84 |
recttext.right = PD_TRAYPOP_WIDTH - 12; |
LineTo (*p_hdc, PD_TRAYPOP_WIDTH - 3, PD_TRAYPOP_HEIGHT - 3); |
85 |
|
LineTo (*p_hdc, 0, PD_TRAYPOP_HEIGHT - 3); |
86 |
MoveToEx(*p_hdc, 0, 0, (LPPOINT) NULL); |
LineTo (*p_hdc, 0, 0); |
87 |
LineTo(*p_hdc, PD_TRAYPOP_WIDTH - 3, 0); |
|
88 |
LineTo(*p_hdc, PD_TRAYPOP_WIDTH - 3, PD_TRAYPOP_HEIGHT - 3); |
UINT dtFormat = DT_END_ELLIPSIS | DT_NOPREFIX | DT_WORDBREAK; |
89 |
LineTo(*p_hdc, 0, PD_TRAYPOP_HEIGHT - 3); |
|
90 |
LineTo(*p_hdc, 0, 0); |
/* determine text height */ |
91 |
|
int text_height = DrawText (*p_hdc, store_text (NULL), |
92 |
UINT dtFormat = DT_END_ELLIPSIS | DT_NOPREFIX | DT_WORDBREAK; |
-1, &recttext, |
93 |
|
dtFormat | DT_CENTER | DT_CALCRECT); |
94 |
// determine text height |
|
95 |
int text_height = DrawText( |
/* vertically center text in the box */ |
96 |
*p_hdc, // handle to DC |
recttext.top = PD_TRAYPOP_HEIGHT/2 - text_height/2 - 5; |
97 |
store_text(NULL), // text to draw |
recttext.bottom = PD_TRAYPOP_HEIGHT/2 + text_height/2 + 5; |
98 |
-1, // text length // TODO: future i18n problem, see docs |
recttext.left = 10; |
99 |
&recttext, // formatting dimensions |
recttext.right = PD_TRAYPOP_WIDTH - 12; |
100 |
dtFormat | DT_CENTER | DT_CALCRECT |
|
101 |
); |
/* change over to left-justified from centered, for longer lines */ |
102 |
|
(text_height > 30)? (dtFormat |= DT_LEFT) : (dtFormat |= DT_CENTER); |
103 |
// vertically center text in the box |
|
104 |
recttext.top = PD_TRAYPOP_HEIGHT/2 - text_height/2 - 5; |
DrawText (*p_hdc, store_text (NULL), |
105 |
recttext.bottom = PD_TRAYPOP_HEIGHT/2 + text_height/2 + 5; |
-1, &recttext, dtFormat); |
106 |
recttext.left = 10; |
|
107 |
recttext.right = PD_TRAYPOP_WIDTH - 12; |
hFont = (HFONT) SelectObject(*p_hdc, hOldFont); |
108 |
|
DeleteObject(hFont); |
109 |
// change over to left-justified from centered, for longer lines |
} |
110 |
(text_height > 30)? (dtFormat |= DT_LEFT) : (dtFormat |= DT_CENTER); |
|
111 |
|
|
112 |
DrawText (*p_hdc, |
/* Window procedure for the message box. */ |
113 |
store_text (NULL), |
static LRESULT CALLBACK |
114 |
-1, // text length // TODO: future i18n problem, see docs |
window_proc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) |
115 |
&recttext, // formatting dimensions |
{ |
116 |
dtFormat); |
PAINTSTRUCT ps; |
117 |
|
HDC hdc; |
118 |
hFont = (HFONT) SelectObject(*p_hdc, hOldFont); |
|
119 |
DeleteObject(hFont); |
switch (msg) { |
120 |
} /* paint_alert */ |
case WM_PAINT: |
121 |
|
hdc = BeginPaint (hWnd, &ps); |
122 |
|
paint_alert (&hdc, &ps); |
123 |
static LRESULT CALLBACK |
EndPaint (hWnd, &ps); |
124 |
WndProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) |
break; |
125 |
{ |
|
126 |
PAINTSTRUCT ps; |
case WM_LBUTTONUP: |
127 |
HDC hdc; |
KillTimer (hWnd, PD_TIMER_IDENTIFIER); |
128 |
|
PostQuitMessage (1); |
129 |
switch (msg) |
break; |
130 |
{ |
|
131 |
case WM_PAINT: |
case WM_DESTROY: |
132 |
hdc = BeginPaint (hWnd, &ps); |
KillTimer (hWnd, PD_TIMER_IDENTIFIER); |
133 |
paint_alert (&hdc, &ps); |
PostQuitMessage (1); |
134 |
EndPaint (hWnd, &ps); |
break; |
135 |
break; |
|
136 |
|
default: |
137 |
case WM_LBUTTONUP: |
return DefWindowProc (hWnd, msg, wParam, lParam); |
138 |
KillTimer (hWnd, PD_TIMER_IDENTIFIER); |
} |
139 |
PostQuitMessage (1); |
|
140 |
break; |
return 0; |
141 |
|
} |
142 |
case WM_DESTROY: |
|
143 |
KillTimer (hWnd, PD_TIMER_IDENTIFIER); |
|
144 |
PostQuitMessage (1); |
|
145 |
break; |
/* Simple timer function which destroys the (message) window . */ |
146 |
|
static VOID CALLBACK |
147 |
default: |
popup_timer_proc (HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime) |
148 |
return DefWindowProc (hWnd, msg, wParam, lParam); |
{ |
149 |
} |
DestroyWindow (hwnd); |
150 |
|
} |
151 |
return 0; |
|
152 |
} /* WndProc */ |
|
153 |
|
|
154 |
|
/* Init window class. */ |
155 |
static VOID CALLBACK |
static void |
156 |
popup_timer_proc( HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime) |
init_wclass (WNDCLASS *p_wclass, HINSTANCE hInst) |
157 |
{ |
{ |
158 |
DestroyWindow(hwnd); |
p_wclass->style = CS_HREDRAW | CS_VREDRAW; |
159 |
} /* popup_timer_proc */ |
p_wclass->lpfnWndProc = window_proc; |
160 |
|
p_wclass->cbClsExtra = 0; |
161 |
|
p_wclass->cbWndExtra = 0; |
162 |
static void |
p_wclass->hInstance = hInst; |
163 |
init_wclass (WNDCLASS *p_wclass, HINSTANCE hInst) |
p_wclass->hIcon = LoadIcon(hInst, IDI_APPLICATION); |
164 |
{ |
p_wclass->hCursor = LoadCursor(NULL, IDC_ARROW); |
165 |
p_wclass->style = CS_HREDRAW | CS_VREDRAW; |
p_wclass->hbrBackground = (HBRUSH) (COLOR_INFOBK + 1); |
166 |
p_wclass->lpfnWndProc = WndProc; |
p_wclass->lpszMenuName = NULL; |
167 |
p_wclass->cbClsExtra = 0; |
p_wclass->lpszClassName = PD_WINDOWNAME; |
168 |
p_wclass->cbWndExtra = 0; |
} |
169 |
p_wclass->hInstance = hInst; |
|
170 |
p_wclass->hIcon = LoadIcon(hInst, IDI_APPLICATION); |
|
171 |
p_wclass->hCursor = LoadCursor(NULL, IDC_ARROW); |
/* Show the given message in a pop-up window for millis miliseconds. */ |
172 |
p_wclass->hbrBackground = (HBRUSH) (COLOR_INFOBK + 1); |
int |
173 |
p_wclass->lpszMenuName = NULL; |
show_msg (HWND hParentWnd, int millis, LPCTSTR string) |
174 |
p_wclass->lpszClassName = PD_WINDOWNAME; |
{ |
175 |
} /* init_wclass */ |
RECT parent; |
176 |
|
int nWndWidth = PD_TRAYPOP_WIDTH; |
177 |
|
int nWndHeight = PD_TRAYPOP_HEIGHT; |
178 |
/* Show the given message in a pop-up window for millis miliseconds. */ |
MSG msg; |
179 |
int |
HWND hWnd; |
180 |
show_msg (HWND hParentWnd, int millis, LPCTSTR string) |
UINT_PTR timer; |
181 |
{ |
WNDCLASS wClass; |
182 |
RECT parent; |
|
183 |
int nWndWidth = PD_TRAYPOP_WIDTH; |
store_text (string); |
184 |
int nWndHeight = PD_TRAYPOP_HEIGHT; |
GetWindowRect (hParentWnd, &parent); |
185 |
MSG msg; |
|
186 |
HWND hWnd; |
init_wclass (&wClass, glob_hinst); |
187 |
UINT_PTR timer; |
RegisterClass (&wClass); |
188 |
WNDCLASS wClass; |
|
189 |
|
hWnd = CreateWindowEx (WS_EX_TOOLWINDOW | WS_EX_TOPMOST, |
190 |
store_text (string); |
PD_WINDOWNAME, PD_WINDOWNAME, |
191 |
GetWindowRect (hParentWnd, &parent); |
WS_POPUP, |
192 |
|
(parent.right + parent.left) / 2, |
193 |
init_wclass (&wClass, glob_hinst); |
(parent.bottom + parent.top) / 2, |
194 |
RegisterClass (&wClass); |
nWndWidth - 2, nWndHeight - 2, |
195 |
|
NULL, NULL, glob_hinst, NULL); |
196 |
hWnd = CreateWindowEx( |
if (hWnd == NULL) |
197 |
WS_EX_TOOLWINDOW | WS_EX_TOPMOST, // extended style |
return 0; |
198 |
PD_WINDOWNAME, // class name |
else { /* Ensure parent never loses focus. */ |
199 |
PD_WINDOWNAME, // window name |
ShowWindow (hWnd, SW_SHOW); |
200 |
WS_POPUP, // window style |
UpdateWindow (hWnd); |
201 |
(parent.right + parent.left) / 2, (parent.bottom + parent.top) / 2, |
EnableWindow (hParentWnd, TRUE); |
202 |
nWndWidth - 2, nWndHeight - 2, // width and height, with corrections |
center_window (hWnd, hParentWnd); |
203 |
NULL, // parent handle |
SetActiveWindow (NULL); |
204 |
NULL, // menu handle |
} |
205 |
glob_hinst, // instance handle |
|
206 |
NULL // other parameters |
timer = SetTimer (hWnd, PD_TIMER_IDENTIFIER, millis, |
207 |
); |
(TIMERPROC) popup_timer_proc); |
208 |
|
|
209 |
if (hWnd == NULL) |
while (GetMessage (&msg, NULL, 0, 0)) { |
210 |
return 0; |
TranslateMessage (&msg); |
211 |
else { |
DispatchMessage (&msg); |
212 |
ShowWindow (hWnd, SW_SHOW); |
} |
213 |
UpdateWindow (hWnd); |
|
214 |
// ensure parent never loses focus |
return msg.wParam; |
215 |
EnableWindow (hParentWnd, TRUE); |
} |
|
center_window (hWnd, hParentWnd); |
|
|
SetActiveWindow (NULL); |
|
|
} |
|
|
|
|
|
timer = SetTimer (hWnd, // handle to window |
|
|
PD_TIMER_IDENTIFIER, // timer identifier |
|
|
millis, // time-out value |
|
|
(TIMERPROC) popup_timer_proc // timer procedure |
|
|
); |
|
|
|
|
|
while (GetMessage (&msg, NULL, 0, 0)) { |
|
|
TranslateMessage (&msg); |
|
|
DispatchMessage (&msg); |
|
|
} |
|
|
|
|
|
return msg.wParam; |
|
|
} |
|