4 * Copyright 1998 Marcel Baur <mbaur@g26.ethz.ch>
6 * Clock is partially based on
7 * - Program Manager by Ulrich Schmied
8 * - rolex.c by Jim Peterson
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.
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.
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
38 #define INITIAL_WINDOW_SIZE 200
41 CLOCK_GLOBALS Globals;
43 /***********************************************************************
47 static BOOL CLOCK_ResetTimer(void)
49 UINT period; /* milliseconds */
51 KillTimer(Globals.hMainWnd, TIMER_ID);
61 if (!SetTimer (Globals.hMainWnd, TIMER_ID, period, NULL)) {
62 CHAR szApp[MAX_STRING_LEN];
63 LoadString(Globals.hInstance, IDS_CLOCK, szApp, sizeof(szApp));
64 MessageBox(0, "No available timers", szApp, MB_ICONEXCLAMATION | MB_OK);
70 /***********************************************************************
74 * All handling of main menu events
77 int CLOCK_MenuCommand (WPARAM wParam)
79 CHAR szApp[MAX_STRING_LEN];
80 CHAR szAppRelease[MAX_STRING_LEN];
82 /* switch to analog */
84 Globals.bAnalog = TRUE;
85 LANGUAGE_UpdateMenuCheckmarks();
87 InvalidateRect(Globals.hMainWnd, NULL, FALSE);
90 /* switch to digital */
92 Globals.bAnalog = FALSE;
93 LANGUAGE_UpdateMenuCheckmarks();
95 InvalidateRect(Globals.hMainWnd, NULL, FALSE);
100 MAIN_FileChooseFont();
105 Globals.bWithoutTitle = !Globals.bWithoutTitle;
106 LANGUAGE_UpdateWindowCaption();
107 LANGUAGE_UpdateMenuCheckmarks();
112 Globals.bAlwaysOnTop = !Globals.bAlwaysOnTop;
113 LANGUAGE_UpdateMenuCheckmarks();
116 /* show or hide seconds */
118 Globals.bSeconds = !Globals.bSeconds;
119 LANGUAGE_UpdateMenuCheckmarks();
121 InvalidateRect(Globals.hMainWnd, NULL, FALSE);
124 /* show or hide date */
126 Globals.bDate = !Globals.bDate;
127 LANGUAGE_UpdateMenuCheckmarks();
128 LANGUAGE_UpdateWindowCaption();
133 WineLicense(Globals.hMainWnd);
136 /* show warranties */
137 case IDM_NOWARRANTY: {
138 WineWarranty(Globals.hMainWnd);
141 /* show "about" box */
143 LoadString(Globals.hInstance, IDS_CLOCK, szApp, sizeof(szApp));
144 lstrcpy(szAppRelease,szApp);
145 lstrcat(szAppRelease,"\n" PACKAGE_STRING);
146 ShellAbout(Globals.hMainWnd, szApp, szAppRelease, 0);
153 VOID MAIN_FileChooseFont(VOID)
158 font.lStructSize = sizeof(font);
159 font.hwndOwner = Globals.hMainWnd;
161 font.lpLogFont = &lf;
167 font.lpTemplateName = 0;
168 font.hInstance = Globals.hInstance;
169 /* font.lpszStyle = LF_FACESIZE; */
174 if (ChooseFont(&font)) {
179 /***********************************************************************
184 LRESULT WINAPI CLOCK_WndProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
193 Globals.bWithoutTitle = !Globals.bWithoutTitle;
194 LANGUAGE_UpdateMenuCheckmarks();
195 LANGUAGE_UpdateWindowCaption();
196 UpdateWindow (Globals.hMainWnd);
204 context = BeginPaint(hWnd, &ps);
206 AnalogClock(context, Globals.MaxX, Globals.MaxY, Globals.bSeconds);
208 DigitalClock(context, Globals.MaxX, Globals.MaxY, Globals.bSeconds);
214 Globals.MaxX = LOWORD(lParam);
215 Globals.MaxY = HIWORD(lParam);
220 CLOCK_MenuCommand(wParam);
225 /* Could just invalidate what has changed,
226 * but it doesn't really seem worth the effort
228 InvalidateRect(Globals.hMainWnd, NULL, FALSE);
238 return DefWindowProc (hWnd, msg, wParam, lParam);
244 /***********************************************************************
249 int PASCAL WinMain (HINSTANCE hInstance, HINSTANCE prev, LPSTR cmdline, int show)
254 char szClassName[] = "CLClass"; /* To make sure className >= 0x10000 */
255 char szWinName[] = "Clock";
258 Globals.bAnalog = TRUE;
259 Globals.bSeconds = TRUE;
260 Globals.lpszIniFile = "clock.ini";
261 Globals.lpszIcoFile = "clock.ico";
263 Globals.hInstance = hInstance;
264 Globals.hMainIcon = ExtractIcon(Globals.hInstance,
265 Globals.lpszIcoFile, 0);
267 if (!Globals.hMainIcon)
268 Globals.hMainIcon = LoadIcon(0, MAKEINTRESOURCE(DEFAULTICON));
271 class.style = CS_HREDRAW | CS_VREDRAW;
272 class.lpfnWndProc = CLOCK_WndProc;
273 class.cbClsExtra = 0;
274 class.cbWndExtra = 0;
275 class.hInstance = Globals.hInstance;
276 class.hIcon = LoadIcon (0, IDI_APPLICATION);
277 class.hCursor = LoadCursor (0, IDC_ARROW);
278 class.hbrBackground = GetStockObject (GRAY_BRUSH);
279 class.lpszMenuName = 0;
280 class.lpszClassName = szClassName;
283 if (!RegisterClass (&class)) return FALSE;
285 Globals.MaxX = Globals.MaxY = INITIAL_WINDOW_SIZE;
286 Globals.hMainWnd = CreateWindow (szClassName, szWinName, WS_OVERLAPPEDWINDOW,
287 CW_USEDEFAULT, CW_USEDEFAULT,
288 Globals.MaxX, Globals.MaxY, 0,
289 0, Globals.hInstance, 0);
291 if (!CLOCK_ResetTimer())
294 LANGUAGE_LoadMenus();
295 SetMenu(Globals.hMainWnd, Globals.hMainMenu);
297 LANGUAGE_UpdateMenuCheckmarks();
299 ShowWindow (Globals.hMainWnd, show);
300 UpdateWindow (Globals.hMainWnd);
302 while (GetMessage(&msg, 0, 0, 0)) {
303 TranslateMessage(&msg);
304 DispatchMessage(&msg);
307 KillTimer(Globals.hMainWnd, TIMER_ID);