Copyrect should flag destination texture as dirty, to force it to be
[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 #include "windows.h"
30 #include "main.h"
31 #include "license.h"
32 #include "language.h"
33 #include "winclock.h"
34 #include "commdlg.h"
35
36 CLOCK_GLOBALS Globals;
37
38 /***********************************************************************
39  *
40  *           CLOCK_MenuCommand
41  *
42  *  All handling of main menu events
43  */
44
45 int CLOCK_MenuCommand (WPARAM wParam)
46 {
47 CHAR szApp[MAX_STRING_LEN];
48 CHAR szAppRelease[MAX_STRING_LEN];
49    switch (wParam) {
50         /* switch to analog */
51      case 0x100: {
52          Globals.bAnalog = TRUE;
53          LANGUAGE_UpdateMenuCheckmarks();
54          SendMessage(Globals.hMainWnd, WM_PAINT, 0, 0);
55          break;
56        }
57         /* switch to digital */
58      case 0x101: {
59          Globals.bAnalog = FALSE;
60          LANGUAGE_UpdateMenuCheckmarks();
61          SendMessage(Globals.hMainWnd, WM_PAINT, 0, 0);
62          break;
63        }
64         /* change font */
65      case 0x103: {
66          MAIN_FileChooseFont();
67          break;
68        }
69         /* hide title bar */
70      case 0x105: {
71          Globals.bWithoutTitle = !Globals.bWithoutTitle;
72          LANGUAGE_UpdateWindowCaption();
73          LANGUAGE_UpdateMenuCheckmarks();
74          break;
75        }
76         /* always on top */
77      case 0x10D: {
78          Globals.bAlwaysOnTop = !Globals.bAlwaysOnTop;
79          LANGUAGE_UpdateMenuCheckmarks();
80          break;
81        }
82         /* show or hide seconds */
83      case 0x107: {
84          Globals.bSeconds = !Globals.bSeconds;
85          LANGUAGE_UpdateMenuCheckmarks();
86          SendMessage(Globals.hMainWnd, WM_PAINT, 0, 0);
87          break;
88        }
89         /* show or hide date */
90      case 0x108: {
91          Globals.bDate = !Globals.bDate;
92          LANGUAGE_UpdateMenuCheckmarks();
93          LANGUAGE_UpdateWindowCaption();
94          break;
95        }
96         /* show license */
97      case 0x109: {
98          WineLicense(Globals.hMainWnd);
99          break;
100        }
101         /* show warranties */
102      case 0x10A: {
103          WineWarranty(Globals.hMainWnd);
104          break;
105        }
106         /* show "about" box */
107      case 0x10B: {
108          LoadString(Globals.hInstance, 0x10C, szApp, sizeof(szApp));
109          lstrcpy(szAppRelease,szApp);
110          lstrcat(szAppRelease,"\n" PACKAGE_STRING);
111          ShellAbout(Globals.hMainWnd, szApp, szAppRelease, 0);
112          break;
113        }
114      /* Handle languages */
115 /*     default:
116          LANGUAGE_DefaultHandle(wParam);
117 */
118    }
119    return 0;
120 }
121
122 VOID MAIN_FileChooseFont(VOID) {
123
124   CHOOSEFONT font;
125   LOGFONT        lf;
126
127         font.lStructSize     = sizeof(font);
128         font.hwndOwner       = Globals.hMainWnd;
129         font.hDC             = NULL;
130         font.lpLogFont       = &lf;
131         font.iPointSize      = 0;
132         font.Flags           = 0;
133         font.rgbColors       = 0;
134         font.lCustData       = 0;
135         font.lpfnHook        = 0;
136         font.lpTemplateName  = 0;
137         font.hInstance       = Globals.hInstance;
138 /*        font.lpszStyle       = LF_FACESIZE; */
139         font.nFontType       = 0;
140         font.nSizeMin        = 0;
141         font.nSizeMax        = 144;
142
143         if (ChooseFont(&font)) {
144             /* do nothing yet */
145         }
146
147 }
148
149 /***********************************************************************
150  *
151  *           CLOCK_WndProc
152  */
153
154 LRESULT WINAPI CLOCK_WndProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
155 {
156     PAINTSTRUCT ps;
157     HDC context;
158
159     switch (msg) {
160
161         case WM_CREATE: {
162             printf("WM_CREATE\n");
163             break;
164         }
165
166         case WM_RBUTTONUP: {
167             printf("WM_RBUTTONUP\n");
168             Globals.bWithoutTitle = !Globals.bWithoutTitle;
169             LANGUAGE_UpdateMenuCheckmarks();
170             LANGUAGE_UpdateWindowCaption();
171             UpdateWindow (Globals.hMainWnd);
172             break;
173         }
174
175         case WM_PAINT: {
176             printf("WM_PAINT\n");
177             context = BeginPaint(hWnd, &ps);
178             if(Globals.bAnalog) {
179                 DrawFace(context);
180                 Idle(context);
181             }
182                else
183             {
184                /* do nothing */
185             }
186             EndPaint(hWnd, &ps);
187             break;
188         }
189
190         case WM_SIZE: {
191             printf("WM_SIZE\n");
192             Globals.MaxX = LOWORD(lParam);
193             Globals.MaxY = HIWORD(lParam);
194             OldHour.DontRedraw   = TRUE;
195             OldMinute.DontRedraw = TRUE;
196             OldSecond.DontRedraw = TRUE;
197             break;
198         }
199
200         case WM_COMMAND: {
201             CLOCK_MenuCommand(wParam);
202             break;
203         }
204
205         case WM_DESTROY: {
206             printf("WM_DESTROY\n");
207             PostQuitMessage (0);
208             break;
209         }
210
211         default:
212           return DefWindowProc (hWnd, msg, wParam, lParam);
213     }
214     return 0l;
215 }
216
217
218
219 /***********************************************************************
220  *
221  *           WinMain
222  */
223
224 int PASCAL WinMain (HINSTANCE hInstance, HINSTANCE prev, LPSTR cmdline, int show)
225 {
226     MSG      msg;
227     WNDCLASS class;
228
229     char szClassName[] = "CLClass";  /* To make sure className >= 0x10000 */
230     char szWinName[]   = "Clock";
231
232     /* Setup Globals */
233     Globals.bAnalog         = TRUE;
234     Globals.bSeconds        = TRUE;
235     Globals.lpszIniFile     = "clock.ini";
236     Globals.lpszIcoFile     = "clock.ico";
237
238     Globals.hInstance       = hInstance;
239     Globals.hMainIcon       = ExtractIcon(Globals.hInstance,
240                                           Globals.lpszIcoFile, 0);
241
242     if (!Globals.hMainIcon) Globals.hMainIcon =
243                                   LoadIcon(0, MAKEINTRESOURCE(DEFAULTICON));
244
245     if (!prev){
246         class.style         = CS_HREDRAW | CS_VREDRAW;
247         class.lpfnWndProc   = CLOCK_WndProc;
248         class.cbClsExtra    = 0;
249         class.cbWndExtra    = 0;
250         class.hInstance     = Globals.hInstance;
251         class.hIcon         = LoadIcon (0, IDI_APPLICATION);
252         class.hCursor       = LoadCursor (0, IDC_ARROW);
253         class.hbrBackground = GetStockObject (GRAY_BRUSH);
254         class.lpszMenuName  = 0;
255         class.lpszClassName = szClassName;
256     }
257
258     if (!RegisterClass (&class)) return FALSE;
259
260     Globals.hMainWnd = CreateWindow (szClassName, szWinName, WS_OVERLAPPEDWINDOW,
261         CW_USEDEFAULT, CW_USEDEFAULT, Globals.MaxX, Globals.MaxY, 0,
262         LoadMenu(Globals.hInstance, STRING_MENU_Xx), Globals.hInstance, 0);
263
264     LANGUAGE_LoadMenus();
265     SetMenu(Globals.hMainWnd, Globals.hMainMenu);
266
267     LANGUAGE_UpdateMenuCheckmarks();
268
269     ShowWindow (Globals.hMainWnd, show);
270     UpdateWindow (Globals.hMainWnd);
271
272     while (TRUE) {
273         Sleep(1);
274         if (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) {
275                 if (msg.message == WM_QUIT) return msg.wParam;
276                 TranslateMessage(&msg);
277                 DispatchMessage(&msg);
278                 Idle(NULL);
279         }
280           else Idle(NULL);
281     }
282
283     /* We will never reach the following statement !   */
284     return 0;
285 }
286