winecfg: Only initialise the audio drivers once.
[wine] / programs / winecfg / about.c
1 /*
2  * WineCfg about panel
3  *
4  * Copyright 2002 Jaco Greeff
5  * Copyright 2003 Dimitrie O. Paun
6  * Copyright 2003 Mike Hearn
7  * Copyright 2010 Joel Holdsworth
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22  *
23  */
24
25 #define COBJMACROS
26
27 #include "config.h"
28
29 #include <windows.h>
30 #include <commctrl.h>
31 #include <shellapi.h>
32 #include <wine/debug.h>
33
34 #include "resource.h"
35 #include "winecfg.h"
36
37 WINE_DEFAULT_DEBUG_CHANNEL(winecfg);
38
39 static HICON logo = NULL;
40 static HFONT titleFont = NULL;
41
42 INT_PTR CALLBACK
43 AboutDlgProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
44 {
45     HWND hWnd;
46     HDC hDC;
47     RECT rcClient, rcRect;
48     char *owner, *org;
49
50     switch (uMsg)
51     {
52     case WM_NOTIFY:
53         switch(((LPNMHDR)lParam)->code)
54         {
55         case PSN_APPLY:
56             /*save registration info to registry */
57             owner = get_text(hDlg, IDC_ABT_OWNER);
58             org   = get_text(hDlg, IDC_ABT_ORG);
59
60             set_reg_key(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion",
61                         "RegisteredOwner", owner ? owner : "");
62             set_reg_key(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion",
63                         "RegisteredOrganization", org ? org : "");
64             set_reg_key(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows NT\\CurrentVersion",
65                         "RegisteredOwner", owner ? owner : "");
66             set_reg_key(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows NT\\CurrentVersion",
67                         "RegisteredOrganization", org ? org : "");
68             apply();
69
70             HeapFree(GetProcessHeap(), 0, owner);
71             HeapFree(GetProcessHeap(), 0, org);
72             break;
73
74         case NM_CLICK:
75         case NM_RETURN:
76             if(wParam == IDC_ABT_WEB_LINK)
77                 ShellExecuteA(NULL, "open", PACKAGE_URL, NULL, NULL, SW_SHOW);
78             break;
79         }
80         break;
81
82     case WM_INITDIALOG:
83
84         hDC = GetDC(hDlg);
85
86         /* read owner and organization info from registry, load it into text box */
87         owner = get_reg_key(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows NT\\CurrentVersion",
88                             "RegisteredOwner", "");
89         org =   get_reg_key(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows NT\\CurrentVersion",
90                             "RegisteredOrganization", "");
91
92         SetDlgItemText(hDlg, IDC_ABT_OWNER, owner);
93         SetDlgItemText(hDlg, IDC_ABT_ORG, org);
94
95         SendMessage(GetParent(hDlg), PSM_UNCHANGED, 0, 0);
96
97         HeapFree(GetProcessHeap(), 0, owner);
98         HeapFree(GetProcessHeap(), 0, org);
99
100         /* prepare the panel */
101         hWnd = GetDlgItem(hDlg, IDC_ABT_PANEL);
102         if(hWnd)
103         {
104             GetClientRect(hDlg, &rcClient);
105             GetClientRect(hWnd, &rcRect);
106             MoveWindow(hWnd, 0, 0, rcClient.right, rcRect.bottom, FALSE);
107
108             logo = LoadImageW((HINSTANCE)GetWindowLongPtrW(hDlg, GWLP_HINSTANCE),
109                 MAKEINTRESOURCEW(IDI_LOGO), IMAGE_ICON, 0, 0, LR_SHARED);
110         }
111
112         /* prepare the title text */
113         hWnd = GetDlgItem(hDlg, IDC_ABT_TITLE_TEXT);
114         if(hWnd)
115         {
116             titleFont = CreateFont(
117                 -MulDiv(24, GetDeviceCaps(hDC, LOGPIXELSY), 72),
118                 0, 0, 0, 0, FALSE, 0, 0, 0, 0, 0, 0, 0,
119                 "Tahoma");
120             SendMessage(hWnd, WM_SETFONT, (WPARAM)titleFont, TRUE);
121         }
122
123         /* prepare the web link */
124         hWnd = GetDlgItem(hDlg, IDC_ABT_WEB_LINK);
125         if(hWnd)
126             SetWindowTextA(hWnd, "<a href=\"" PACKAGE_URL "\">" PACKAGE_URL "</a>");
127
128         ReleaseDC(hDlg, hDC);
129
130         break;
131
132     case WM_DESTROY:
133         if(logo)
134         {
135             DestroyIcon(logo);
136             logo = NULL;
137         }
138
139         if(titleFont)
140         {
141             DeleteObject(titleFont);
142             titleFont = NULL;
143         }
144
145         break;
146
147     case WM_COMMAND:
148         switch(HIWORD(wParam))
149         {
150         case EN_CHANGE:
151             /* enable apply button */
152             SendMessage(GetParent(hDlg), PSM_CHANGED, 0, 0);
153             break;
154         }
155         break;
156
157     case WM_DRAWITEM:
158         if(wParam == IDC_ABT_PANEL)
159         {
160             LPDRAWITEMSTRUCT pDIS = (LPDRAWITEMSTRUCT)lParam;
161             FillRect(pDIS->hDC, &pDIS->rcItem, (HBRUSH) (COLOR_WINDOW+1));
162             DrawIconEx(pDIS->hDC, 0, 0, logo, 0, 0, 0, 0, DI_IMAGE);
163             DrawEdge(pDIS->hDC, &pDIS->rcItem, EDGE_SUNKEN, BF_BOTTOM);
164         }
165         break;
166
167     case WM_CTLCOLORSTATIC:
168         switch(GetDlgCtrlID((HWND)lParam))
169         {
170         case IDC_ABT_TITLE_TEXT:
171             /* set the title to a wine color */
172             SetTextColor((HDC)wParam, 0x0000007F);
173         case IDC_ABT_PANEL_TEXT:
174         case IDC_ABT_LICENSE_TEXT:
175             return (BOOL)CreateSolidBrush(GetSysColor(COLOR_WINDOW));
176         }
177         break;
178     }
179
180     return FALSE;
181 }