NetSurf
about.c
Go to the documentation of this file.
1 /*
2 * Copyright 2009 Mark Benjamin <netsurf-browser.org.MarkBenjamin@dfgh.net>
3 *
4 * This file is part of NetSurf, http://www.netsurf-browser.org/
5 *
6 * NetSurf is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * NetSurf is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 /**
20  * \file
21  * This is The win32 API about dialog implementation.
22  */
23 
24 #include <stdio.h>
25 
26 #include "utils/config.h"
27 
28 #include <windows.h>
29 
30 #include "utils/log.h"
31 #include "utils/messages.h"
32 #include "desktop/version.h"
33 
34 #include "windows/gui.h"
35 #include "windows/window.h"
36 #include "windows/about.h"
37 #include "windows/resourceid.h"
38 
39 #include "windbg.h"
40 
41 /**
42  * Initialize the about dialog text fields
43  */
44 static BOOL init_about_dialog(HWND hwnd)
45 {
46  char ver_str[128];
47  HWND dlg_itm;
48  HFONT hFont;
49 
50  dlg_itm = GetDlgItem(hwnd, IDC_ABOUT_VERSION);
51  if (dlg_itm != NULL) {
52 
53  hFont=CreateFont (26, 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_SWISS, "Arial");
54  if (hFont != NULL) {
55  NSLOG(netsurf, INFO, "Setting font object");
56  SendMessage(dlg_itm, WM_SETFONT, (WPARAM)hFont, 0);
57  }
58 
59  snprintf(ver_str, sizeof(ver_str), "%s %s",
60  messages_get("NetSurf"), netsurf_version);
61 
62  SendMessage(dlg_itm, WM_SETTEXT, 0, (LPARAM)ver_str);
63  }
64 
65  dlg_itm = GetDlgItem(hwnd, IDC_ABOUT_COPYRIGHT);
66  if (dlg_itm != NULL) {
67  snprintf(ver_str, sizeof(ver_str), "%s",
68  messages_get("NetSurfCopyright"));
69 
70  SendMessage(dlg_itm, WM_SETTEXT, 0, (LPARAM)ver_str);
71  }
72 
73  return TRUE;
74 }
75 
76 /**
77  * destroy resources used to create about dialog
78  */
79 static BOOL destroy_about_dialog(HWND hwnd)
80 {
81  HWND dlg_itm;
82  HFONT hFont;
83 
84  dlg_itm = GetDlgItem(hwnd, IDC_ABOUT_VERSION);
85  if (dlg_itm != NULL) {
86  hFont = (HFONT)SendMessage(dlg_itm, WM_GETFONT, 0, 0);
87  if (hFont != NULL) {
88  NSLOG(netsurf, INFO, "Destroyed font object");
89  DeleteObject(hFont);
90  }
91  }
92 
93  return TRUE;
94 
95 }
96 
97 static BOOL CALLBACK
98 nsws_about_event_callback(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
99 {
100 
101  LOG_WIN_MSG(hwnd, msg, wparam, lparam);
102 
103  switch(msg) {
104  case WM_INITDIALOG:
105  return init_about_dialog(hwnd);
106 
107  case WM_COMMAND:
108  switch(LOWORD(wparam)) {
109  case IDOK:
110  NSLOG(netsurf, INFO, "OK clicked");
111  EndDialog(hwnd, IDOK);
112  break;
113 
114  case IDCANCEL:
115  NSLOG(netsurf, INFO, "Cancel clicked");
116  EndDialog(hwnd, IDOK);
117  break;
118 
119  case IDC_BTN_CREDITS:
120  nsws_window_go(hwnd, "about:credits");
121  EndDialog(hwnd, IDOK);
122  break;
123 
124  case IDC_BTN_LICENCE:
125  nsws_window_go(hwnd, "about:licence");
126  EndDialog(hwnd, IDOK);
127  break;
128 
129  }
130  break;
131 
132  case WM_CREATE:
133  return TRUE;
134 
135  case WM_DESTROY:
136  return destroy_about_dialog(hwnd);
137 
138  }
139  return FALSE;
140 }
141 
142 void nsw32_about_dialog_init(HINSTANCE hinst, HWND parent)
143 {
144  int ret = DialogBox(hinst, MAKEINTRESOURCE(IDD_ABOUT), parent,
146  if (ret == -1) {
147  win32_warning(messages_get("NoMemory"), 0);
148  return;
149  }
150 }
static BOOL CALLBACK nsws_about_event_callback(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
Definition: about.c:98
#define IDC_BTN_LICENCE
Definition: resourceid.h:46
Localised message support (interface).
static BOOL init_about_dialog(HWND hwnd)
Initialize the about dialog text fields.
Definition: about.c:44
nserror win32_warning(const char *warning, const char *detail)
Warn the user of an event.
Definition: gui.c:173
static BOOL destroy_about_dialog(HWND hwnd)
destroy resources used to create about dialog
Definition: about.c:79
const char *const netsurf_version
User friendly version string.
Definition: gui_menu.c:92
#define NSLOG(catname, level, logmsg, args...)
Definition: log.h:115
wimp_w parent
Definition: dialog.c:88
#define IDC_ABOUT_COPYRIGHT
Definition: resourceid.h:44
const char * messages_get(const char *key)
Fast lookup of a message by key from the standard Messages hash.
Definition: messages.c:241
#define IDC_BTN_CREDITS
Definition: resourceid.h:45
HINSTANCE hinst
win32 application instance handle.
Definition: gui.c:45
Version information interface.
#define LOG_WIN_MSG(h, m, w, l)
log windows message
Definition: windbg.h:32
bool nsws_window_go(HWND hwnd, const char *urltxt)
Cause a browser window to navigate to a url.
Definition: window.c:1954
#define IDD_ABOUT
Definition: resourceid.h:40
#define IDC_ABOUT_VERSION
Definition: resourceid.h:42
void nsw32_about_dialog_init(HINSTANCE hinst, HWND parent)
Definition: about.c:142