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