Debian Codegraph @

src/af/xap/win/xap_Win32Dlg_About.cpp

raw
1 /* AbiSource Application Framework
2 * Copyright (C) 1998 AbiSource, Inc.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301 USA.
18 */
19
20 #include <stdlib.h>
21 #include <string.h>
22 #include <stdio.h>
23 #include "ut_string.h"
24 #include "ut_assert.h"
25 #include "ut_debugmsg.h"
26 #include "ut_Win32OS.h"
27 #include "ut_Win32LocaleString.h"
28
29 #include "xap_App.h"
30 #include "xap_Dialog_Id.h"
31 #include "xap_Win32App.h"
32 #include "xap_Frame.h"
33 #include "xap_Win32FrameImpl.h"
34
35 #include "xap_Strings.h"
36 #include "xap_Dialog_Id.h"
37 #include "xap_Dlg_About.h"
38 #include "xap_Win32Dlg_About.h"
39
40 #include "gr_Win32Graphics.h"
41 #include "gr_Win32Image.h"
42 #include "gr_Win32USPGraphics.h"
43 #include "ut_bytebuf.h"
44 #include "ut_png.h"
45
46 /*****************************************************************/
47
48 extern unsigned char g_pngSidebar[]; // see ap_wp_sidebar.cpp
49 extern unsigned long g_pngSidebar_sizeof; // see ap_wp_sidebar.cpp
50
51 bool XAP_Win32Dialog_About::s_bEventLoopDone;
52
53 /*****************************************************************/
54 XAP_Dialog * XAP_Win32Dialog_About::static_constructor(XAP_DialogFactory * pFactory,
55 XAP_Dialog_Id id)
56 {
57 XAP_Win32Dialog_About * p = new XAP_Win32Dialog_About(pFactory,id);
58 return p;
59 }
60
61 XAP_Win32Dialog_About::XAP_Win32Dialog_About(XAP_DialogFactory * pDlgFactory,
62 XAP_Dialog_Id id)
63 : XAP_Dialog_About(pDlgFactory,id)
64 {
65 m_pGrImageSidebar = NULL;
66 }
67
68 XAP_Win32Dialog_About::~XAP_Win32Dialog_About(void)
69 {
70 DELETEP(m_pGrImageSidebar);
71 }
72
73 const int ABOUT_WIDTH = 500;
74 const int ABOUT_HEIGHT = 398;
75 const int BUTTON_WIDTH = 64;
76 const int BUTTON_HEIGHT = 24;
77 const int BUTTON_GAP = 10;
78 const int HEADING_HEIGHT = 36;
79 const int VERSION_HEIGHT = 24;
80 const int COPYRIGHT_HEIGHT = 24;
81 const int GPL_HEIGHT = 180;
82
83 const int ID_BUTTON_URL = 3000;
84
85 void XAP_Win32Dialog_About::runModal(XAP_Frame * pFrame)
86 {
87 // raise the dialog
88 XAP_Win32App * pWin32App = static_cast<XAP_Win32App *>(XAP_App::getApp());
89 UT_Win32LocaleString str, strbis;
90 m_pFrame = pFrame;
91
92 UT_ByteBuf * pBB = new UT_ByteBuf(g_pngSidebar_sizeof);
93 pBB->ins(0,g_pngSidebar,g_pngSidebar_sizeof);
94
95 UT_sint32 iImageWidth;
96 UT_sint32 iImageHeight;
97
98 UT_PNG_getDimensions(pBB, iImageWidth, iImageHeight);
99
100 m_pGrImageSidebar = new GR_Win32Image(NULL);
101 m_pGrImageSidebar->convertFromBuffer(pBB, "image/png", iImageWidth, iImageHeight);
102
103 DELETEP(pBB);
104 const wchar_t * pClassName = L"AbiSource_About";
105
106 ATOM a = UT_RegisterClassEx(CS_HREDRAW | CS_VREDRAW, (WNDPROC) s_dlgProc, pWin32App->getInstance(),
107 NULL, LoadCursorW(NULL, (LPCWSTR)IDC_ARROW), GetSysColorBrush(COLOR_BTNFACE), NULL,
108 NULL, pClassName);
109 if (!a)
110 {
111 ::MessageBeep(MB_ICONEXCLAMATION);
112 return;
113 }
114
115 HWND hWndFrame = static_cast<XAP_Win32FrameImpl*>(m_pFrame->getFrameImpl())->getTopLevelWindow();
116
117 RECT rcScreen;
118 rcScreen.left=rcScreen.right=0;
119
120 #if (_WIN32_WINNT >= 0x0500 )
121 if (GetSystemMetrics(SM_CMONITORS) > 1) {
122 HMONITOR m = MonitorFromWindow(hWndFrame,MONITOR_DEFAULTTONEAREST);
123 if (m) {
124 MONITORINFO mi;
125 mi.cbSize=sizeof(MONITORINFO);
126 if (GetMonitorInfoW(m,&mi))
127 rcScreen = mi.rcWork;
128 }
129 } else
130 #endif
131 SystemParametersInfoW(SPI_GETWORKAREA,0,&rcScreen,0);
132
133 if (rcScreen.left == rcScreen.top)
134 SetRect(&rcScreen,0,0,GetSystemMetrics(SM_CXFULLSCREEN),
135 GetSystemMetrics(SM_CYFULLSCREEN));
136
137 const int iScreenWidth = rcScreen.right - rcScreen.left;
138 const int iScreenHeight = rcScreen.bottom - rcScreen.top;
139
140 BringWindowToTop(hWndFrame);
141 pWin32App->enableAllTopLevelWindows(FALSE);
142
143 wchar_t buf[1024];
144 const XAP_StringSet* pSS = XAP_App::getApp()->getStringSet();
145 str.fromUTF8 (pSS->getValue(XAP_STRING_ID_DLG_ABOUT_Title));
146 strbis.fromASCII (XAP_App::getApp()->getApplicationName());
147 swprintf(buf, str.c_str(), strbis.c_str());
148
149 HWND hwndAbout = UT_CreateWindowEx( 0L, pClassName,
150 buf,
151 WS_OVERLAPPED | WS_VISIBLE,
152 rcScreen.left + (iScreenWidth - ABOUT_WIDTH) / 2,
153 rcScreen.top + (iScreenHeight - ABOUT_HEIGHT) /2,
154 ABOUT_WIDTH,
155 ABOUT_HEIGHT,
156 hWndFrame,
157 NULL,
158 pWin32App->getInstance(),
159 NULL);
160 if (!hwndAbout)
161 {
162 UnregisterClassW(pClassName, pWin32App->getInstance());
163 ::MessageBeep(MB_ICONEXCLAMATION);
164 return;
165 }
166
167 SetWindowLongPtrW(hwndAbout, GWLP_USERDATA, (LONG_PTR)this);
168
169 RECT rcClient;
170 GetClientRect(hwndAbout, &rcClient);
171 const int iWidth = rcClient.right;
172 const int iHeight = rcClient.bottom;
173
174 str.fromUTF8 (pSS->getValue(XAP_STRING_ID_DLG_OK));
175 HWND hwndOK = CreateWindowW(L"BUTTON",
176 str.c_str(),
177 WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_DEFPUSHBUTTON,
178 iWidth - BUTTON_WIDTH - BUTTON_GAP,
179 iHeight - BUTTON_HEIGHT - BUTTON_GAP,
180 BUTTON_WIDTH,
181 BUTTON_HEIGHT,
182 hwndAbout,
183 (HMENU) IDOK,
184 pWin32App->getInstance(),
185 NULL);
186
187 HWND hwndURL = CreateWindowW(L"BUTTON",
188 L"www.abisource.com",
189 WS_CHILD | WS_VISIBLE | WS_TABSTOP,
190 iWidth - BUTTON_WIDTH - BUTTON_GAP - 2*BUTTON_WIDTH - BUTTON_GAP,
191 iHeight - BUTTON_HEIGHT - BUTTON_GAP,
192 BUTTON_WIDTH*2,
193 BUTTON_HEIGHT,
194 hwndAbout,
195 (HMENU) ID_BUTTON_URL,
196 pWin32App->getInstance(),
197 NULL);
198
199 str.fromUTF8 (XAP_App::getApp()->getApplicationName());
200 HWND hwndStatic_Heading = CreateWindowW(L"STATIC",
201 str.c_str(),
202 WS_CHILD | WS_VISIBLE | SS_CENTER,
203 iImageWidth,
204 BUTTON_GAP,
205 iWidth - iImageWidth,
206 HEADING_HEIGHT,
207 hwndAbout,
208 (HMENU) 3001,
209 pWin32App->getInstance(),
210 NULL);
211
212 const char *versiontext=pSS->getValue(XAP_STRING_ID_DLG_ABOUT_Version);
213 UT_UTF8String version = UT_UTF8String_sprintf(versiontext,XAP_App::s_szBuild_Version);
214 str.fromUTF8(version.utf8_str());
215
216 HWND hwndStatic_Version = CreateWindowW(L"STATIC",
217 str.c_str(),
218 WS_CHILD | WS_VISIBLE | SS_CENTER,
219 iImageWidth + BUTTON_GAP,
220 BUTTON_GAP + HEADING_HEIGHT + BUTTON_GAP,
221 iWidth - 2*BUTTON_GAP - iImageWidth,
222 VERSION_HEIGHT,
223 hwndAbout,
224 (HMENU) 3002,
225 pWin32App->getInstance(),
226 NULL);
227
228 str.fromASCII (XAP_ABOUT_COPYRIGHT);
229 HWND hwndStatic_Copyright = CreateWindowW(L"STATIC",
230 str.c_str(),
231 WS_CHILD | WS_VISIBLE | SS_LEFT,
232 iImageWidth + BUTTON_GAP,
233 BUTTON_GAP + HEADING_HEIGHT + BUTTON_GAP + VERSION_HEIGHT + 1*BUTTON_GAP,
234 iWidth - 2*BUTTON_GAP - iImageWidth,
235 COPYRIGHT_HEIGHT,
236 hwndAbout,
237 (HMENU) 3003,
238 pWin32App->getInstance(),
239 NULL);
240
241 str.fromASCII (XAP_App::getApp()->getApplicationName());
242 strbis.fromASCII (XAP_ABOUT_GPL_LONG);
243 swprintf(buf, strbis.c_str(), str.c_str());
244 HWND hwndStatic_GPL = CreateWindowW(L"STATIC",
245 buf,
246 WS_CHILD | WS_VISIBLE | SS_LEFT,
247 iImageWidth + BUTTON_GAP,
248 BUTTON_GAP + HEADING_HEIGHT + BUTTON_GAP + VERSION_HEIGHT + 1*BUTTON_GAP + VERSION_HEIGHT + BUTTON_GAP,
249 iWidth - 2*BUTTON_GAP - iImageWidth,
250 GPL_HEIGHT,
251 hwndAbout,
252 (HMENU) 3004,
253 pWin32App->getInstance(),
254 NULL);
255
256 HWND hwndStatic_USP_Version = 0;
257
258 if(pWin32App->getLastFocussedFrame()->getCurrentView()->getGraphics()->getClassId()==GRID_WIN32_UNISCRIBE)
259 {
260 GR_Win32USPGraphics * pUSP = static_cast<GR_Win32USPGraphics*>(
261 pWin32App->getLastFocussedFrame()->getCurrentView()->getGraphics());
262
263 str.fromASCII (pUSP->getUSPVersion());
264 hwndStatic_USP_Version = CreateWindowW(L"STATIC",
265 str.c_str(),
266 WS_CHILD | WS_VISIBLE | SS_LEFT,
267 BUTTON_GAP/2,
268 iHeight - 3*BUTTON_HEIGHT/4,
269 iImageWidth - BUTTON_GAP/2,
270 3*BUTTON_HEIGHT/4,
271 hwndAbout,
272 (HMENU) 3005,
273 pWin32App->getInstance(),
274 NULL);
275
276
277 }
278
279 LOGFONTW lf;
280 memset(&lf, 0, sizeof(lf));
281
282 wcscpy(lf.lfFaceName, L"MS Shell Dlg 2");
283
284 lf.lfHeight = 13;
285 lf.lfWeight = 0;
286 HFONT hfontPrimary = CreateFontIndirectW(&lf);
287
288 lf.lfHeight = 12;
289 lf.lfWeight = 0;
290 HFONT hfontSmall = CreateFontIndirectW(&lf);
291
292 wcscpy(lf.lfFaceName, L"Arial");
293 lf.lfHeight = 36;
294 lf.lfWeight = FW_BOLD;
295 HFONT hfontHeading = CreateFontIndirectW(&lf);
296
297 SendMessageW(hwndStatic_Heading, WM_SETFONT, (WPARAM) hfontHeading, 0);
298
299 HWND rgFontReceivers[] =
300 { hwndOK, hwndURL, hwndStatic_Version, hwndStatic_Copyright };
301
302 for (UT_uint32 iWnd = 0; iWnd < G_N_ELEMENTS(rgFontReceivers); ++iWnd)
303 {
304 SendMessageW(rgFontReceivers[iWnd], WM_SETFONT, (WPARAM) hfontPrimary, 0);
305 }
306
307 SendMessageW(hwndStatic_GPL, WM_SETFONT, (WPARAM) hfontSmall, 0);
308
309 if(hwndStatic_USP_Version)
310 SendMessageW(hwndStatic_USP_Version, WM_SETFONT, (WPARAM) hfontSmall, 0);
311
312 // the event loop
313 {
314 MSG msg;
315
316 s_bEventLoopDone = false;
317
318 while (!s_bEventLoopDone)
319 {
320 if (GetMessageW(&msg, NULL, 0, 0))
321 {
322 if( hwndAbout && IsDialogMessageW( hwndAbout, &msg ) )
323 continue;
324
325 TranslateMessage(&msg);
326 DispatchMessageW(&msg);
327 }
328 else
329 {
330 break;
331 }
332 }
333 }
334
335 DestroyWindow(hwndAbout);
336
337 UnregisterClassW(pClassName, pWin32App->getInstance());
338
339 pWin32App->enableAllTopLevelWindows(true);
340
341 if (GetWindow(hWndFrame, GW_HWNDFIRST) != hWndFrame)
342 {
343 BringWindowToTop(hWndFrame);
344 }
345
346 if (GetFocus() != hWndFrame)
347 {
348 SetFocus(hWndFrame);
349 }
350 }
351
352 BOOL CALLBACK XAP_Win32Dialog_About::s_dlgProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam)
353 {
354 // This is a static function.
355
356 XAP_Win32Dialog_About * pThis = (XAP_Win32Dialog_About *)GetWindowLongPtrW(hWnd,GWLP_USERDATA);
357
358 if (!pThis)
359 {
360 return UT_DefWindowProc(hWnd, msg, wParam, lParam);
361 }
362
363 switch (msg)
364 {
365 case WM_PAINT:
366 {
367 PAINTSTRUCT ps;
368 HDC hdc = BeginPaint(hWnd, &ps);
369
370 RECT r;
371 GetClientRect(hWnd, &r);
372 r.right = pThis->m_pGrImageSidebar->getDisplayWidth();
373 FillRect(hdc, &r, GetSysColorBrush(COLOR_BTNFACE));
374
375
376 GR_Win32AllocInfo ai(hdc,hWnd);
377 GR_Win32Graphics *pGR = (GR_Win32Graphics *)XAP_App::getApp()->newGraphics(ai);
378 UT_return_val_if_fail(pGR, 0);
379
380 pGR->drawImage(pThis->m_pGrImageSidebar,
381 0,
382 (r.bottom - pThis->m_pGrImageSidebar->getDisplayHeight())/2);
383
384 delete pGR;
385
386 EndPaint(hWnd,&ps);
387 return 0;
388 }
389
390 case WM_CHAR:
391 {
392 switch (wParam)
393 {
394 case 13: // CR
395 case 27: // ESC
396 case 32: // SPACE
397 s_bEventLoopDone = true;
398 return 0;
399 }
400
401 break;
402 }
403
404 case WM_COMMAND:
405 return pThis->_onCommand(hWnd,wParam,lParam);
406
407 case WM_DESTROY:
408 s_bEventLoopDone = true;
409 return 0;
410 }
411
412 return UT_DefWindowProc(hWnd, msg, wParam, lParam);
413 }
414
415 BOOL XAP_Win32Dialog_About::_onCommand(HWND /*hWnd*/, WPARAM wParam, LPARAM /*lParam*/)
416 {
417 WORD wId = LOWORD(wParam);
418
419 switch (wId)
420 {
421 case IDCANCEL:
422 case IDOK: // also XAP_RID_DIALOG_ABOUT_BTN_OK
423 s_bEventLoopDone = true;
424 return 0;
425
426 case ID_BUTTON_URL:
427 XAP_App::getApp()->openURL("http://www.abisource.com/");
428 return 0;
429
430 default: // we did not handle this notification
431 UT_DEBUGMSG(("WM_Command for id %ld\n",wId));
432 return 0; // return zero to let windows take care of it.
433 }
434 }