main.c 7.38 KB
Newer Older
Alexandre Julliard's avatar
Alexandre Julliard committed
1 2 3 4 5 6 7 8 9
/*
 * Clock
 *
 * Copyright 1998 Marcel Baur <mbaur@g26.ethz.ch>
 *
 * Clock is partially based on
 * - Program Manager by Ulrich Schmied
 * - rolex.c by Jim Peterson
 *
10 11 12 13 14 15 16 17 18 19 20 21 22 23
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
Alexandre Julliard's avatar
Alexandre Julliard committed
24 25
 */

26 27
#include "config.h"

Alexandre Julliard's avatar
Alexandre Julliard committed
28 29 30 31 32 33
#include <stdio.h>
#include "windows.h"
#include "main.h"
#include "license.h"
#include "language.h"
#include "winclock.h"
Alexandre Julliard's avatar
Alexandre Julliard committed
34
#include "commdlg.h"
Alexandre Julliard's avatar
Alexandre Julliard committed
35 36 37 38 39 40 41 42 43 44 45

CLOCK_GLOBALS Globals;

/***********************************************************************
 *
 *           CLOCK_MenuCommand
 *
 *  All handling of main menu events
 */

int CLOCK_MenuCommand (WPARAM wParam)
46
{
47 48
CHAR szApp[MAX_STRING_LEN];
CHAR szAppRelease[MAX_STRING_LEN];
Alexandre Julliard's avatar
Alexandre Julliard committed
49
   switch (wParam) {
50
	/* switch to analog */
51
     case 0x100: {
Alexandre Julliard's avatar
Alexandre Julliard committed
52
         Globals.bAnalog = TRUE;
Alexandre Julliard's avatar
Alexandre Julliard committed
53
         LANGUAGE_UpdateMenuCheckmarks();
Alexandre Julliard's avatar
Alexandre Julliard committed
54
	 SendMessage(Globals.hMainWnd, WM_PAINT, 0, 0);
55 56
	 break;
       }
57 58
	/* switch to digital */
     case 0x101: {
Alexandre Julliard's avatar
Alexandre Julliard committed
59
         Globals.bAnalog = FALSE;
Alexandre Julliard's avatar
Alexandre Julliard committed
60
         LANGUAGE_UpdateMenuCheckmarks();
Alexandre Julliard's avatar
Alexandre Julliard committed
61
	 SendMessage(Globals.hMainWnd, WM_PAINT, 0, 0);
62
	 break;
Alexandre Julliard's avatar
Alexandre Julliard committed
63
       }
64 65
	/* change font */
     case 0x103: {
Alexandre Julliard's avatar
Alexandre Julliard committed
66 67
         MAIN_FileChooseFont();
         break;
Alexandre Julliard's avatar
Alexandre Julliard committed
68
       }
69
	/* hide title bar */
70
     case 0x105: {
Alexandre Julliard's avatar
Alexandre Julliard committed
71 72 73 74
         Globals.bWithoutTitle = !Globals.bWithoutTitle;
         LANGUAGE_UpdateWindowCaption();
         LANGUAGE_UpdateMenuCheckmarks();
         break;
75
       }
76 77
	/* always on top */
     case 0x10D: {
Alexandre Julliard's avatar
Alexandre Julliard committed
78 79 80
         Globals.bAlwaysOnTop = !Globals.bAlwaysOnTop;
         LANGUAGE_UpdateMenuCheckmarks();
         break;
81
       }
82 83
	/* show or hide seconds */
     case 0x107: {
Alexandre Julliard's avatar
Alexandre Julliard committed
84 85 86 87 88
         Globals.bSeconds = !Globals.bSeconds;
         LANGUAGE_UpdateMenuCheckmarks();
         SendMessage(Globals.hMainWnd, WM_PAINT, 0, 0);
         break;
       }
89 90
	/* show or hide date */
     case 0x108: {
Alexandre Julliard's avatar
Alexandre Julliard committed
91 92 93 94 95
         Globals.bDate = !Globals.bDate;
         LANGUAGE_UpdateMenuCheckmarks();
         LANGUAGE_UpdateWindowCaption();
         break;
       }
96 97
	/* show license */
     case 0x109: {
98
         WineLicense(Globals.hMainWnd);
Alexandre Julliard's avatar
Alexandre Julliard committed
99 100
         break;
       }
101 102
	/* show warranties */
     case 0x10A: {
103
         WineWarranty(Globals.hMainWnd);
Alexandre Julliard's avatar
Alexandre Julliard committed
104 105
         break;
       }
106 107 108 109
	/* show "about" box */
     case 0x10B: {
         LoadString(Globals.hInstance, 0x10C, szApp, sizeof(szApp));
         lstrcpy(szAppRelease,szApp);
110
         lstrcat(szAppRelease,"\n" PACKAGE_STRING);
111
         ShellAbout(Globals.hMainWnd, szApp, szAppRelease, 0);
Alexandre Julliard's avatar
Alexandre Julliard committed
112
         break;
Alexandre Julliard's avatar
Alexandre Julliard committed
113
       }
114
     /* Handle languages */
115
/*     default:
116
         LANGUAGE_DefaultHandle(wParam);
117
*/
Alexandre Julliard's avatar
Alexandre Julliard committed
118 119 120 121
   }
   return 0;
}

Alexandre Julliard's avatar
Alexandre Julliard committed
122 123 124
VOID MAIN_FileChooseFont(VOID) {

  CHOOSEFONT font;
125 126
  LOGFONT	 lf;

Alexandre Julliard's avatar
Alexandre Julliard committed
127 128 129
        font.lStructSize     = sizeof(font);
        font.hwndOwner       = Globals.hMainWnd;
        font.hDC             = NULL;
130
        font.lpLogFont       = &lf;
Alexandre Julliard's avatar
Alexandre Julliard committed
131 132 133 134 135 136 137
        font.iPointSize      = 0;
        font.Flags           = 0;
        font.rgbColors       = 0;
        font.lCustData       = 0;
        font.lpfnHook        = 0;
        font.lpTemplateName  = 0;
        font.hInstance       = Globals.hInstance;
138
/*        font.lpszStyle       = LF_FACESIZE; */
Alexandre Julliard's avatar
Alexandre Julliard committed
139 140
        font.nFontType       = 0;
        font.nSizeMin        = 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
141
        font.nSizeMax        = 144;
Alexandre Julliard's avatar
Alexandre Julliard committed
142 143 144

        if (ChooseFont(&font)) {
            /* do nothing yet */
145
        }
Alexandre Julliard's avatar
Alexandre Julliard committed
146

Alexandre Julliard's avatar
Alexandre Julliard committed
147
}
Alexandre Julliard's avatar
Alexandre Julliard committed
148 149 150 151 152 153

/***********************************************************************
 *
 *           CLOCK_WndProc
 */

154
LRESULT WINAPI CLOCK_WndProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
155 156 157 158 159 160
{
    PAINTSTRUCT ps;
    HDC context;

    switch (msg) {

Alexandre Julliard's avatar
Alexandre Julliard committed
161 162 163 164 165 166 167 168
        case WM_CREATE: {
            printf("WM_CREATE\n");
   	    break;
        }

        case WM_RBUTTONUP: {
	    printf("WM_RBUTTONUP\n");
            Globals.bWithoutTitle = !Globals.bWithoutTitle;
169
            LANGUAGE_UpdateMenuCheckmarks();
Alexandre Julliard's avatar
Alexandre Julliard committed
170 171 172 173 174 175 176 177 178 179 180 181
            LANGUAGE_UpdateWindowCaption();
            UpdateWindow (Globals.hMainWnd);
            break;
        }

	case WM_PAINT: {
            printf("WM_PAINT\n");
            context = BeginPaint(hWnd, &ps);
	    if(Globals.bAnalog) {
	        DrawFace(context);
	        Idle(context);
	    }
182
	       else
Alexandre Julliard's avatar
Alexandre Julliard committed
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
            {
               /* do nothing */
            }
            EndPaint(hWnd, &ps);
            break;
        }

        case WM_SIZE: {
            printf("WM_SIZE\n");
	    Globals.MaxX = LOWORD(lParam);
	    Globals.MaxY = HIWORD(lParam);
            OldHour.DontRedraw   = TRUE;
            OldMinute.DontRedraw = TRUE;
            OldSecond.DontRedraw = TRUE;
	    break;
        }
199

Alexandre Julliard's avatar
Alexandre Julliard committed
200 201 202
        case WM_COMMAND: {
            CLOCK_MenuCommand(wParam);
            break;
203
        }
Alexandre Julliard's avatar
Alexandre Julliard committed
204 205 206 207 208 209 210 211

        case WM_DESTROY: {
            printf("WM_DESTROY\n");
            PostQuitMessage (0);
            break;
        }

        default:
Alexandre Julliard's avatar
Alexandre Julliard committed
212 213 214 215 216 217 218 219 220 221 222 223
          return DefWindowProc (hWnd, msg, wParam, lParam);
    }
    return 0l;
}



/***********************************************************************
 *
 *           WinMain
 */

224
int PASCAL WinMain (HINSTANCE hInstance, HINSTANCE prev, LPSTR cmdline, int show)
Alexandre Julliard's avatar
Alexandre Julliard committed
225 226 227
{
    MSG      msg;
    WNDCLASS class;
228

Alexandre Julliard's avatar
Alexandre Julliard committed
229 230
    char szClassName[] = "CLClass";  /* To make sure className >= 0x10000 */
    char szWinName[]   = "Clock";
Alexandre Julliard's avatar
Alexandre Julliard committed
231 232

    /* Setup Globals */
Alexandre Julliard's avatar
Alexandre Julliard committed
233 234 235 236
    Globals.bAnalog	    = TRUE;
    Globals.bSeconds        = TRUE;
    Globals.lpszIniFile     = "clock.ini";
    Globals.lpszIcoFile     = "clock.ico";
Alexandre Julliard's avatar
Alexandre Julliard committed
237

Alexandre Julliard's avatar
Alexandre Julliard committed
238
    Globals.hInstance       = hInstance;
239
    Globals.hMainIcon       = ExtractIcon(Globals.hInstance,
Alexandre Julliard's avatar
Alexandre Julliard committed
240
                                          Globals.lpszIcoFile, 0);
241 242

    if (!Globals.hMainIcon) Globals.hMainIcon =
Alexandre Julliard's avatar
Alexandre Julliard committed
243 244 245 246 247 248 249 250 251 252 253
                                  LoadIcon(0, MAKEINTRESOURCE(DEFAULTICON));

    if (!prev){
	class.style         = CS_HREDRAW | CS_VREDRAW;
	class.lpfnWndProc   = CLOCK_WndProc;
	class.cbClsExtra    = 0;
	class.cbWndExtra    = 0;
	class.hInstance     = Globals.hInstance;
	class.hIcon         = LoadIcon (0, IDI_APPLICATION);
	class.hCursor       = LoadCursor (0, IDC_ARROW);
	class.hbrBackground = GetStockObject (GRAY_BRUSH);
Alexandre Julliard's avatar
Alexandre Julliard committed
254
	class.lpszMenuName  = 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
255
	class.lpszClassName = szClassName;
Alexandre Julliard's avatar
Alexandre Julliard committed
256
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
257 258

    if (!RegisterClass (&class)) return FALSE;
Alexandre Julliard's avatar
Alexandre Julliard committed
259

Alexandre Julliard's avatar
Alexandre Julliard committed
260
    Globals.hMainWnd = CreateWindow (szClassName, szWinName, WS_OVERLAPPEDWINDOW,
261
        CW_USEDEFAULT, CW_USEDEFAULT, Globals.MaxX, Globals.MaxY, 0,
Alexandre Julliard's avatar
Alexandre Julliard committed
262
        LoadMenu(Globals.hInstance, STRING_MENU_Xx), Globals.hInstance, 0);
263

264
    LANGUAGE_LoadMenus();
Alexandre Julliard's avatar
Alexandre Julliard committed
265
    SetMenu(Globals.hMainWnd, Globals.hMainMenu);
Alexandre Julliard's avatar
Alexandre Julliard committed
266

Alexandre Julliard's avatar
Alexandre Julliard committed
267 268
    LANGUAGE_UpdateMenuCheckmarks();

Alexandre Julliard's avatar
Alexandre Julliard committed
269 270 271 272
    ShowWindow (Globals.hMainWnd, show);
    UpdateWindow (Globals.hMainWnd);

    while (TRUE) {
Alexandre Julliard's avatar
Alexandre Julliard committed
273 274 275 276 277 278 279 280
        Sleep(1);
        if (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) {
                if (msg.message == WM_QUIT) return msg.wParam;
	        TranslateMessage(&msg);
	        DispatchMessage(&msg);
	        Idle(NULL);
        }
          else Idle(NULL);
Alexandre Julliard's avatar
Alexandre Julliard committed
281 282
    }

283
    /* We will never reach the following statement !   */
284
    return 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
285 286
}