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