Only reapply the texture states necessary when a different texture
[wine/multimedia.git] / programs / clock / main.c
blobbc635afec8e85cb6bdbcace970d09f8ea38ec567
1 /*
2 * Clock
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
26 #include "config.h"
28 #include <stdio.h>
30 #include "windows.h"
31 #include "commdlg.h"
33 #include "main.h"
34 #include "license.h"
35 #include "language.h"
36 #include "winclock.h"
38 #define INITIAL_WINDOW_SIZE 200
39 #define TIMER_ID 1
40 #define TIMER_PERIOD 50 /* milliseconds */
42 CLOCK_GLOBALS Globals;
44 /***********************************************************************
46 * CLOCK_MenuCommand
48 * All handling of main menu events
51 int CLOCK_MenuCommand (WPARAM wParam)
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;
63 /* switch to digital */
64 case 0x101: {
65 Globals.bAnalog = FALSE;
66 LANGUAGE_UpdateMenuCheckmarks();
67 SendMessage(Globals.hMainWnd, WM_PAINT, 0, 0);
68 break;
70 /* change font */
71 case 0x103: {
72 MAIN_FileChooseFont();
73 break;
75 /* hide title bar */
76 case 0x105: {
77 Globals.bWithoutTitle = !Globals.bWithoutTitle;
78 LANGUAGE_UpdateWindowCaption();
79 LANGUAGE_UpdateMenuCheckmarks();
80 break;
82 /* always on top */
83 case 0x10D: {
84 Globals.bAlwaysOnTop = !Globals.bAlwaysOnTop;
85 LANGUAGE_UpdateMenuCheckmarks();
86 break;
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;
95 /* show or hide date */
96 case 0x108: {
97 Globals.bDate = !Globals.bDate;
98 LANGUAGE_UpdateMenuCheckmarks();
99 LANGUAGE_UpdateWindowCaption();
100 break;
102 /* show license */
103 case 0x109: {
104 WineLicense(Globals.hMainWnd);
105 break;
107 /* show warranties */
108 case 0x10A: {
109 WineWarranty(Globals.hMainWnd);
110 break;
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;
120 /* Handle languages */
122 default:
123 LANGUAGE_DefaultHandle(wParam);
126 return 0;
129 VOID MAIN_FileChooseFont(VOID)
131 CHOOSEFONT font;
132 LOGFONT lf;
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;
150 if (ChooseFont(&font)) {
151 /* do nothing yet */
155 /***********************************************************************
157 * CLOCK_WndProc
160 LRESULT WINAPI CLOCK_WndProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
162 switch (msg) {
164 case WM_CREATE: {
165 break;
168 case WM_RBUTTONUP: {
169 Globals.bWithoutTitle = !Globals.bWithoutTitle;
170 LANGUAGE_UpdateMenuCheckmarks();
171 LANGUAGE_UpdateWindowCaption();
172 UpdateWindow (Globals.hMainWnd);
173 break;
176 case WM_PAINT: {
177 PAINTSTRUCT ps;
178 HDC context;
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;
189 case WM_SIZE: {
190 Globals.MaxX = LOWORD(lParam);
191 Globals.MaxY = HIWORD(lParam);
192 break;
195 case WM_COMMAND: {
196 CLOCK_MenuCommand(wParam);
197 break;
200 case WM_TIMER: {
201 /* Could just invalidate the changed hands,
202 * but it doesn't really seem worth the effort
204 InvalidateRect(Globals.hMainWnd, NULL, FALSE);
205 break;
208 case WM_DESTROY: {
209 PostQuitMessage (0);
210 break;
213 default:
214 return DefWindowProc (hWnd, msg, wParam, lParam);
216 return 0;
221 /***********************************************************************
223 * WinMain
226 int PASCAL WinMain (HINSTANCE hInstance, HINSTANCE prev, LPSTR cmdline, int show)
228 MSG msg;
229 WNDCLASS class;
231 char szClassName[] = "CLClass"; /* To make sure className >= 0x10000 */
232 char szWinName[] = "Clock";
234 /* Setup Globals */
235 Globals.bAnalog = TRUE;
236 Globals.bSeconds = TRUE;
237 Globals.lpszIniFile = "clock.ini";
238 Globals.lpszIcoFile = "clock.ico";
240 Globals.hInstance = hInstance;
241 Globals.hMainIcon = ExtractIcon(Globals.hInstance,
242 Globals.lpszIcoFile, 0);
244 if (!Globals.hMainIcon)
245 Globals.hMainIcon = LoadIcon(0, MAKEINTRESOURCE(DEFAULTICON));
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;
260 if (!RegisterClass (&class)) return FALSE;
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);
268 if (!SetTimer (Globals.hMainWnd, TIMER_ID, TIMER_PERIOD, NULL)) {
269 MessageBox(0, "No available timers", szWinName, MB_ICONEXCLAMATION | MB_OK);
270 return FALSE;
273 LANGUAGE_LoadMenus();
274 SetMenu(Globals.hMainWnd, Globals.hMainMenu);
276 LANGUAGE_UpdateMenuCheckmarks();
278 ShowWindow (Globals.hMainWnd, show);
279 UpdateWindow (Globals.hMainWnd);
281 while (GetMessage(&msg, 0, 0, 0)) {
282 TranslateMessage(&msg);
283 DispatchMessage(&msg);
286 return 0;