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

Annotation of /trunk/Src/wptTrayPop.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 24 - (hide annotations)
Sat Oct 8 10:43:08 2005 UTC (19 years, 4 months ago) by twoaday
File size: 6679 byte(s)
Bug fixes to correct some problems introduced by
the MyGPGME to GPGME port.

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    
23     /*
24     * ChangeLog
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
27     * because we need it near the dialog. I also removed some code we don't use.
28     * -ts
29     */
30    
31     #include <windows.h>
32    
33 twoaday 23 #include "wptW32API.h"
34    
35 twoaday 24 #define PD_WINDOWNAME "ClsTrayPop"
36     #define PD_TIMER_IDENTIFIER 23
37     #define PD_TIMER_TIMEOUT 1500
38 twoaday 2
39 twoaday 24 /* XXX: use the given text to figure out these params. */
40     #define PD_TRAYPOP_WIDTH 250
41     #define PD_TRAYPOP_HEIGHT 80
42 twoaday 2
43     extern HINSTANCE glob_hinst;
44     extern HWND glob_hwnd;
45    
46    
47     static LPCTSTR
48 twoaday 24 store_text (LPCTSTR alert_text)
49 twoaday 2 {
50     static LPCTSTR text;
51    
52 twoaday 24 if (alert_text)
53 twoaday 2 text = alert_text;
54     return text;
55     } /* store_text */
56    
57    
58     static void
59     paint_alert (HDC *p_hdc, PAINTSTRUCT *p_ps)
60     {
61     SetBkMode(*p_hdc, TRANSPARENT);
62     HFONT hFont = CreateFont(
63     13, // height of font (in css px-style)
64     0, // average character width
65     0, // angle of escapement
66     0, // base-line orientation angle
67     FW_DONTCARE, // font weight
68     FALSE, // italic attribute option
69     FALSE, // underline attribute option
70     FALSE, // strikeout attribute option
71     // TODO: future i18n problem, see docs
72     DEFAULT_CHARSET, // character set identifier
73     OUT_DEFAULT_PRECIS, // output precision
74     CLIP_DEFAULT_PRECIS, // clipping precision
75     DEFAULT_QUALITY, // output quality
76     FF_DONTCARE, // pitch and family
77     "Tahoma" // typeface name
78     );
79    
80     HFONT hOldFont = (HFONT) SelectObject(*p_hdc, hFont);
81     RECT recttext;
82     recttext.top = 0;
83     recttext.bottom = PD_TRAYPOP_HEIGHT - 2;
84     recttext.left = 10;
85     recttext.right = PD_TRAYPOP_WIDTH - 12;
86    
87     MoveToEx(*p_hdc, 0, 0, (LPPOINT) NULL);
88     LineTo(*p_hdc, PD_TRAYPOP_WIDTH - 3, 0);
89     LineTo(*p_hdc, PD_TRAYPOP_WIDTH - 3, PD_TRAYPOP_HEIGHT - 3);
90     LineTo(*p_hdc, 0, PD_TRAYPOP_HEIGHT - 3);
91     LineTo(*p_hdc, 0, 0);
92    
93     UINT dtFormat = DT_END_ELLIPSIS | DT_NOPREFIX | DT_WORDBREAK;
94    
95     // determine text height
96     int text_height = DrawText(
97     *p_hdc, // handle to DC
98     store_text(NULL), // text to draw
99     -1, // text length // TODO: future i18n problem, see docs
100     &recttext, // formatting dimensions
101     dtFormat | DT_CENTER | DT_CALCRECT
102     );
103    
104     // vertically center text in the box
105     recttext.top = PD_TRAYPOP_HEIGHT/2 - text_height/2 - 5;
106     recttext.bottom = PD_TRAYPOP_HEIGHT/2 + text_height/2 + 5;
107     recttext.left = 10;
108     recttext.right = PD_TRAYPOP_WIDTH - 12;
109    
110     // change over to left-justified from centered, for longer lines
111     (text_height > 30)? (dtFormat |= DT_LEFT) : (dtFormat |= DT_CENTER);
112    
113     DrawText (*p_hdc,
114     store_text (NULL),
115     -1, // text length // TODO: future i18n problem, see docs
116     &recttext, // formatting dimensions
117     dtFormat);
118    
119     hFont = (HFONT) SelectObject(*p_hdc, hOldFont);
120     DeleteObject(hFont);
121     } /* paint_alert */
122    
123    
124     static LRESULT CALLBACK
125     WndProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
126     {
127     PAINTSTRUCT ps;
128     HDC hdc;
129    
130     switch (msg)
131     {
132     case WM_PAINT:
133     hdc = BeginPaint (hWnd, &ps);
134     paint_alert (&hdc, &ps);
135     EndPaint (hWnd, &ps);
136     break;
137    
138     case WM_LBUTTONUP:
139     KillTimer (hWnd, PD_TIMER_IDENTIFIER);
140     PostQuitMessage (1);
141     break;
142    
143     case WM_DESTROY:
144     KillTimer (hWnd, PD_TIMER_IDENTIFIER);
145     PostQuitMessage (1);
146     break;
147    
148     default:
149     return DefWindowProc (hWnd, msg, wParam, lParam);
150     }
151    
152     return 0;
153     } /* WndProc */
154    
155    
156     static VOID CALLBACK
157     popup_timer_proc( HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)
158     {
159     DestroyWindow(hwnd);
160     } /* popup_timer_proc */
161    
162    
163     static void
164     init_wclass (WNDCLASS *p_wclass, HINSTANCE hInst)
165     {
166     p_wclass->style = CS_HREDRAW | CS_VREDRAW;
167     p_wclass->lpfnWndProc = WndProc;
168     p_wclass->cbClsExtra = 0;
169     p_wclass->cbWndExtra = 0;
170     p_wclass->hInstance = hInst;
171     p_wclass->hIcon = LoadIcon(hInst, IDI_APPLICATION);
172     p_wclass->hCursor = LoadCursor(NULL, IDC_ARROW);
173     p_wclass->hbrBackground = (HBRUSH) (COLOR_INFOBK + 1);
174     p_wclass->lpszMenuName = NULL;
175     p_wclass->lpszClassName = PD_WINDOWNAME;
176     } /* init_wclass */
177    
178    
179 twoaday 23 /* Show the given message in a pop-up window for millis miliseconds. */
180 twoaday 2 int
181     show_msg (HWND hParentWnd, int millis, LPCTSTR string)
182     {
183     RECT parent;
184     int nWndWidth = PD_TRAYPOP_WIDTH;
185     int nWndHeight = PD_TRAYPOP_HEIGHT;
186     MSG msg;
187     HWND hWnd;
188     UINT_PTR timer;
189     WNDCLASS wClass;
190    
191     store_text (string);
192     GetWindowRect (hParentWnd, &parent);
193    
194     init_wclass (&wClass, glob_hinst);
195     RegisterClass (&wClass);
196    
197     hWnd = CreateWindowEx(
198     WS_EX_TOOLWINDOW | WS_EX_TOPMOST, // extended style
199     PD_WINDOWNAME, // class name
200     PD_WINDOWNAME, // window name
201     WS_POPUP, // window style
202     (parent.right + parent.left) / 2, (parent.bottom + parent.top) / 2,
203     nWndWidth - 2, nWndHeight - 2, // width and height, with corrections
204 twoaday 24 NULL, NULL, glob_hinst, NULL);
205    
206 twoaday 2
207     if (hWnd == NULL)
208 twoaday 24 return 0;
209 twoaday 2 else {
210 twoaday 23 ShowWindow (hWnd, SW_SHOW);
211     UpdateWindow (hWnd);
212 twoaday 2 // ensure parent never loses focus
213 twoaday 23 EnableWindow (hParentWnd, TRUE);
214     center_window (hWnd, hParentWnd);
215     SetActiveWindow (NULL);
216 twoaday 2 }
217    
218 twoaday 24 timer = SetTimer (hWnd, PD_TIMER_IDENTIFIER, millis,
219     (TIMERPROC) popup_timer_proc);
220 twoaday 2
221 twoaday 23 while (GetMessage (&msg, NULL, 0, 0)) {
222     TranslateMessage (&msg);
223     DispatchMessage (&msg);
224 twoaday 2 }
225    
226     return msg.wParam;
227 twoaday 23 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26