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