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