Normalize win2000, nt2k, nt2000 to win2k, normalize win2k3 to win2003
[wine] / programs / clock / main.c
1 /*
2  * Clock
3  *
4  * Copyright 1998 Marcel Baur <mbaur@g26.ethz.ch>
5  *
6  * Clock is partially based on
7  * - Program Manager by Ulrich Schmied
8  * - rolex.c by Jim Peterson
9  *
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19  * Lesser General Public License for more details.
20  *
21  * You should have received a copy of the GNU Lesser General Public
22  * License along with this library; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
24  */
25
26 #include "config.h"
27
28 #include <stdio.h>
29
30 #include "windows.h"
31 #include "commdlg.h"
32
33 #include "main.h"
34 #include "license.h"
35 #include "language.h"
36 #include "winclock.h"
37
38 #define INITIAL_WINDOW_SIZE 200
39 #define TIMER_ID 1
40 #define TIMER_PERIOD 50 /* milliseconds */
41
42 CLOCK_GLOBALS Globals;
43
44 /***********************************************************************
45  *
46  *           CLOCK_MenuCommand
47  *
48  *  All handling of main menu events
49  */
50
51 int CLOCK_MenuCommand (WPARAM wParam)
52 {
53     CHAR szApp[MAX_STRING_LEN];
54     CHAR szAppRelease[MAX_STRING_LEN];
55     switch (wParam) {
56         /* switch to analog */
57         case 0x100: {
58             Globals.bAnalog = TRUE;
59             LANGUAGE_UpdateMenuCheckmarks();
60             SendMessage(Globals.hMainWnd, WM_PAINT, 0, 0);
61             break;
62         }
63             /* switch to digital */
64         case 0x101: {
65             Globals.bAnalog = FALSE;
66             LANGUAGE_UpdateMenuCheckmarks();
67             SendMessage(Globals.hMainWnd, WM_PAINT, 0, 0);
68             break;
69         }
70             /* change font */
71         case 0x103: {
72             MAIN_FileChooseFont();
73             break;
74         }
75             /* hide title bar */
76         case 0x105: {
77             Globals.bWithoutTitle = !Globals.bWithoutTitle;
78             LANGUAGE_UpdateWindowCaption();
79             LANGUAGE_UpdateMenuCheckmarks();
80             break;
81         }
82             /* always on top */
83         case 0x10D: {
84             Globals.bAlwaysOnTop = !Globals.bAlwaysOnTop;
85             LANGUAGE_UpdateMenuCheckmarks();
86             break;
87         }
88             /* show or hide seconds */
89         case 0x107: {
90             Globals.bSeconds = !Globals.bSeconds;
91             LANGUAGE_UpdateMenuCheckmarks();
92             SendMessage(Globals.hMainWnd, WM_PAINT, 0, 0);
93             break;
94         }
95             /* show or hide date */
96         case 0x108: {
97             Globals.bDate = !Globals.bDate;
98             LANGUAGE_UpdateMenuCheckmarks();
99             LANGUAGE_UpdateWindowCaption();
100             break;
101         }
102             /* show license */
103         case 0x109: {
104             WineLicense(Globals.hMainWnd);
105             break;
106         }
107             /* show warranties */
108         case 0x10A: {
109             WineWarranty(Globals.hMainWnd);
110             break;
111         }
112             /* show "about" box */
113         case 0x10B: {
114             LoadString(Globals.hInstance, 0x10C, szApp, sizeof(szApp));
115             lstrcpy(szAppRelease,szApp);
116             lstrcat(szAppRelease,"\n" PACKAGE_STRING);
117             ShellAbout(Globals.hMainWnd, szApp, szAppRelease, 0);
118             break;
119         }
120             /* Handle languages */
121             /*
122         default:
123             LANGUAGE_DefaultHandle(wParam);
124             */
125     }
126     return 0;
127 }
128
129 VOID MAIN_FileChooseFont(VOID)
130 {
131     CHOOSEFONT font;
132     LOGFONT      lf;
133     
134     font.lStructSize     = sizeof(font);
135     font.hwndOwner       = Globals.hMainWnd;
136     font.hDC             = NULL;
137     font.lpLogFont       = &lf;
138     font.iPointSize      = 0;
139     font.Flags           = 0;
140     font.rgbColors       = 0;
141     font.lCustData       = 0;
142     font.lpfnHook        = 0;
143     font.lpTemplateName  = 0;
144     font.hInstance       = Globals.hInstance;
145 /*    font.lpszStyle       = LF_FACESIZE; */
146     font.nFontType       = 0;
147     font.nSizeMin        = 0;
148     font.nSizeMax        = 144;
149     
150     if (ChooseFont(&font)) {
151         /* do nothing yet */
152     }
153 }
154
155 /***********************************************************************
156  *
157  *           CLOCK_WndProc
158  */
159
160 LRESULT WINAPI CLOCK_WndProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
161 {
162     switch (msg) {
163       
164         case WM_CREATE: {
165             break;
166         }
167
168         case WM_RBUTTONUP: {
169             Globals.bWithoutTitle = !Globals.bWithoutTitle;
170             LANGUAGE_UpdateMenuCheckmarks();
171             LANGUAGE_UpdateWindowCaption();
172             UpdateWindow (Globals.hMainWnd);
173             break;
174         }
175
176         case WM_PAINT: {
177             PAINTSTRUCT ps;
178             HDC context;
179             
180             context = BeginPaint(hWnd, &ps);
181             if(Globals.bAnalog)
182                 AnalogClock(context, Globals.MaxX, Globals.MaxY);
183             else
184                 DigitalClock(context, Globals.MaxX, Globals.MaxY);
185             EndPaint(hWnd, &ps);
186             break;
187         }
188
189         case WM_SIZE: {
190             Globals.MaxX = LOWORD(lParam);
191             Globals.MaxY = HIWORD(lParam);
192             break;
193         }
194
195         case WM_COMMAND: {
196             CLOCK_MenuCommand(wParam);
197             break;
198         }
199             
200         case WM_TIMER: {
201             /* Could just invalidate the changed hands,
202              * but it doesn't really seem worth the effort
203              */
204             InvalidateRect(Globals.hMainWnd, NULL, FALSE);
205             break;
206         }
207
208         case WM_DESTROY: {
209             PostQuitMessage (0);
210             break;
211         }
212
213         default:
214             return DefWindowProc (hWnd, msg, wParam, lParam);
215     }
216     return 0;
217 }
218
219
220
221 /***********************************************************************
222  *
223  *           WinMain
224  */
225
226 int PASCAL WinMain (HINSTANCE hInstance, HINSTANCE prev, LPSTR cmdline, int show)
227 {
228     MSG      msg;
229     WNDCLASS class;
230     
231     char szClassName[] = "CLClass";  /* To make sure className >= 0x10000 */
232     char szWinName[]   = "Clock";
233     
234     /* Setup Globals */
235     Globals.bAnalog         = TRUE;
236     Globals.bSeconds        = TRUE;
237     Globals.lpszIniFile     = "clock.ini";
238     Globals.lpszIcoFile     = "clock.ico";
239     
240     Globals.hInstance       = hInstance;
241     Globals.hMainIcon       = ExtractIcon(Globals.hInstance,
242                                           Globals.lpszIcoFile, 0);
243     
244     if (!Globals.hMainIcon)
245         Globals.hMainIcon = LoadIcon(0, MAKEINTRESOURCE(DEFAULTICON));
246     
247     if (!prev){
248         class.style         = CS_HREDRAW | CS_VREDRAW;
249         class.lpfnWndProc   = CLOCK_WndProc;
250         class.cbClsExtra    = 0;
251         class.cbWndExtra    = 0;
252         class.hInstance     = Globals.hInstance;
253         class.hIcon         = LoadIcon (0, IDI_APPLICATION);
254         class.hCursor       = LoadCursor (0, IDC_ARROW);
255         class.hbrBackground = GetStockObject (GRAY_BRUSH);
256         class.lpszMenuName  = 0;
257         class.lpszClassName = szClassName;
258     }
259     
260     if (!RegisterClass (&class)) return FALSE;
261     
262     Globals.MaxX = Globals.MaxY = INITIAL_WINDOW_SIZE;
263     Globals.hMainWnd = CreateWindow (szClassName, szWinName, WS_OVERLAPPEDWINDOW,
264                                      CW_USEDEFAULT, CW_USEDEFAULT,
265                                      Globals.MaxX, Globals.MaxY, 0,
266                                      0, Globals.hInstance, 0);
267
268     if (!SetTimer (Globals.hMainWnd, TIMER_ID, TIMER_PERIOD, NULL)) {
269         MessageBox(0, "No available timers", szWinName, MB_ICONEXCLAMATION | MB_OK);
270         return FALSE;
271     }
272
273     LANGUAGE_LoadMenus();
274     SetMenu(Globals.hMainWnd, Globals.hMainMenu);
275     
276     LANGUAGE_UpdateMenuCheckmarks();
277     
278     ShowWindow (Globals.hMainWnd, show);
279     UpdateWindow (Globals.hMainWnd);
280     
281     while (GetMessage(&msg, 0, 0, 0)) {
282         TranslateMessage(&msg);
283         DispatchMessage(&msg);
284     }
285
286     return 0;
287 }