/[winpt]/trunk/Src/wptTrayPop.cpp
ViewVC logotype

Annotation of /trunk/Src/wptTrayPop.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 25 - (hide annotations)
Wed Oct 12 10:04:26 2005 UTC (19 years, 4 months ago) by twoaday
File size: 6416 byte(s)
First testing phase finished.
Provide bug fixes for a lot of (minor) problems.

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26