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

Annotation of /trunk/Src/wptTrayPop.cpp

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26