[BACK]Return to wpause.c CVS log [TXT][DIR] Up to [local] / OpenXM_contrib / gnuplot / win

Annotation of OpenXM_contrib/gnuplot/win/wpause.c, Revision 1.1.1.3

1.1       maekawa     1: #ifndef lint
1.1.1.3 ! ohara       2: static char *RCSid = "$Id: wpause.c,v 1.3.2.1 2002/12/12 12:47:28 broeker Exp $";
1.1       maekawa     3: #endif
                      4:
                      5: /* GNUPLOT - win/wpause.c */
                      6: /*[
                      7:  * Copyright 1992, 1993, 1998   Russell Lang
                      8:  *
                      9:  * Permission to use, copy, and distribute this software and its
                     10:  * documentation for any purpose with or without fee is hereby granted,
                     11:  * provided that the above copyright notice appear in all copies and
                     12:  * that both that copyright notice and this permission notice appear
                     13:  * in supporting documentation.
                     14:  *
                     15:  * Permission to modify the software is granted, but not the right to
                     16:  * distribute the complete modified source code.  Modifications are to
                     17:  * be distributed as patches to the released version.  Permission to
                     18:  * distribute binaries produced by compiling modified sources is granted,
                     19:  * provided you
                     20:  *   1. distribute the corresponding source modifications from the
                     21:  *    released version in the form of a patch file along with the binaries,
                     22:  *   2. add special version identification to distinguish your version
                     23:  *    in addition to the base release version number,
                     24:  *   3. provide your name and address as the primary contact for the
                     25:  *    support of your modified version, and
                     26:  *   4. retain our contact information in regard to use of the base
                     27:  *    software.
                     28:  * Permission to distribute the released version of the source code along
                     29:  * with corresponding source modifications in the form of a patch file is
                     30:  * granted with same provisions 2 through 4 for binary distributions.
                     31:  *
                     32:  * This software is provided "as is" without express or implied warranty
                     33:  * to the extent permitted by applicable law.
                     34: ]*/
                     35:
                     36: /*
                     37:  * AUTHORS
                     38:  *
                     39:  *   Russell Lang
                     40:  *
                     41:  * Send your comments or suggestions to
                     42:  *  info-gnuplot@dartmouth.edu.
                     43:  * This is a mailing list; to join it send a note to
                     44:  *  majordomo@dartmouth.edu.
                     45:  * Send bug reports to
                     46:  *  bug-gnuplot@dartmouth.edu.
                     47:  */
                     48: /* PauseBox() */
                     49:
                     50: /* MessageBox ALWAYS appears in the middle of the screen so instead */
                     51: /* we use this PauseBox so we can decide where it is to be placed */
                     52:
                     53: #define STRICT
                     54: #include <windows.h>
                     55: #include <windowsx.h>
                     56: #include <string.h>
                     57: #include "wgnuplib.h"
                     58: #include "wresourc.h"
                     59: #include "wcommon.h"
                     60:
                     61: /* Pause Window */
                     62: LRESULT CALLBACK WINEXPORT WndPauseProc(HWND, UINT, WPARAM, LPARAM);
                     63: LRESULT CALLBACK WINEXPORT PauseButtonProc(HWND, UINT, WPARAM, LPARAM);
                     64:
                     65: /* Create Pause Class */
                     66: /* called from PauseBox the first time a pause window is created */
                     67: void
                     68: CreatePauseClass(LPPW lppw)
                     69: {
                     70:        WNDCLASS wndclass;
                     71:
                     72:        wndclass.style = 0;
                     73:        wndclass.lpfnWndProc = (WNDPROC)WndPauseProc;
                     74:        wndclass.cbClsExtra = 0;
                     75:        wndclass.cbWndExtra = sizeof(void FAR *);
                     76:        wndclass.hInstance = lppw->hInstance;
                     77:        wndclass.hIcon = NULL;
                     78:        wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
                     79:        wndclass.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
                     80:        wndclass.lpszMenuName = NULL;
                     81:        wndclass.lpszClassName = szPauseClass;
                     82:        RegisterClass(&wndclass);
                     83: }
                     84:
                     85: /* PauseBox */
                     86: int WDPROC
                     87: PauseBox(LPPW lppw)
                     88: {
                     89:        MSG msg;
                     90:        HDC hdc;
                     91:        int width, height;
                     92:        TEXTMETRIC tm;
                     93:        RECT rect;
                     94:
                     95:        if (!lppw->hPrevInstance)
                     96:                CreatePauseClass(lppw);
                     97:        GetWindowRect(GetDesktopWindow(), &rect);
                     98:        if ( (lppw->Origin.x == CW_USEDEFAULT) || (lppw->Origin.x == 0) )
                     99:                lppw->Origin.x = (rect.right + rect.left) / 2;
                    100:        if ( (lppw->Origin.y == CW_USEDEFAULT) || (lppw->Origin.y == 0) )
                    101:                lppw->Origin.y = (rect.bottom + rect.top) / 2;
                    102:
                    103:        hdc = GetDC(NULL);
                    104:        SelectObject(hdc, GetStockObject(SYSTEM_FIXED_FONT));
                    105:        GetTextMetrics(hdc, &tm);
                    106:        width  = max(24,4+_fstrlen(lppw->Message)) * tm.tmAveCharWidth;
                    107:        width = min(width, rect.right-rect.left);
                    108:        height = 28 * (tm.tmHeight + tm.tmExternalLeading) / 4;
                    109:        ReleaseDC(NULL,hdc);
                    110:
                    111: #ifndef WIN32
                    112:        lppw->lpfnPauseButtonProc =
                    113: #ifdef __DLL__
                    114:                (WNDPROC)GetProcAddress(hdllInstance, "PauseButtonProc");
                    115: #else
                    116:                (WNDPROC)MakeProcInstance((FARPROC)PauseButtonProc ,hdllInstance);
                    117: #endif
                    118: #endif
                    119:        lppw->hWndPause = CreateWindowEx(WS_EX_DLGMODALFRAME,
                    120:                szPauseClass, lppw->Title,
                    121: /* HBB 981202: WS_POPUPWINDOW would have WS_SYSMENU in it, but we don't
                    122:  * want, nor need, a System menu in our Pause windows. Actually, it was
                    123:  * emptied manually, in the WM_CREATE handler below, in the original code.
                    124:  * This solution seems cleaner. */
                    125:                WS_POPUP | WS_BORDER | WS_CAPTION,
                    126:                lppw->Origin.x - width/2, lppw->Origin.y - height/2,
                    127:                width, height,
                    128:                lppw->hWndParent, NULL, lppw->hInstance, lppw);
                    129:        ShowWindow(lppw->hWndPause, SW_SHOWNORMAL);
                    130:        BringWindowToTop(lppw->hWndPause);
                    131:        UpdateWindow(lppw->hWndPause);
                    132:
                    133:        lppw->bPause = TRUE;
                    134:        lppw->bPauseCancel = IDCANCEL;
1.1.1.3 ! ohara     135:        while (lppw->bPause) {
        !           136:                /* HBB 20021211: Nigel Nunn found a better way to avoid
        !           137:                 * 100% CPU load --> use it */
        !           138:                if (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) {
1.1       maekawa   139:                        /* wait until window closed */
1.1.1.3 ! ohara     140:                        TranslateMessage(&msg);
        !           141:                        DispatchMessage(&msg);
        !           142:                } else
        !           143:                        WaitMessage();
        !           144:        }
1.1       maekawa   145:        DestroyWindow(lppw->hWndPause);
                    146: #ifndef WIN32
                    147: #ifndef __DLL__
                    148:        FreeProcInstance((FARPROC)lppw->lpfnPauseButtonProc);
                    149: #endif
                    150: #endif
                    151:
                    152:        return(lppw->bPauseCancel);
                    153: }
                    154:
                    155: LRESULT CALLBACK WINEXPORT
                    156: WndPauseProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
                    157: {
                    158:        HDC hdc;
                    159:        PAINTSTRUCT ps;
                    160:        RECT rect;
                    161:        TEXTMETRIC tm;
                    162:        LPPW lppw;
                    163:        int cxChar, cyChar, middle;
                    164:
                    165:        lppw = (LPPW)GetWindowLong(hwnd, 0);
                    166:
                    167:        switch(message) {
                    168:                case WM_KEYDOWN:
                    169:                        if (wParam == VK_RETURN) {
                    170:                                if (lppw->bDefOK)
                    171:                                        SendMessage(hwnd, WM_COMMAND, IDOK, 0L);
                    172:                                else
                    173:                                        SendMessage(hwnd, WM_COMMAND, IDCANCEL, 0L);
                    174:                        }
                    175:                        return(0);
                    176:                case WM_COMMAND:
                    177:                        switch(LOWORD(wParam)) {
                    178:                                case IDCANCEL:
                    179:                                case IDOK:
                    180:                                        lppw->bPauseCancel = LOWORD(wParam);
                    181:                                        lppw->bPause = FALSE;
                    182:                                        break;
                    183:                        }
                    184:                        return(0);
                    185:                case WM_SETFOCUS:
                    186:                        SetFocus(lppw->bDefOK ? lppw->hOK : lppw->hCancel);
                    187:                        return(0);
                    188:                case WM_PAINT:
                    189:                        {
                    190:                        hdc = BeginPaint(hwnd, &ps);
                    191:                        SelectObject(hdc, GetStockObject(SYSTEM_FIXED_FONT));
                    192:                        SetTextAlign(hdc, TA_CENTER);
                    193:                        GetClientRect(hwnd, &rect);
                    194:                        SetBkMode(hdc,TRANSPARENT);
                    195:                        TextOut(hdc,(rect.right+rect.left)/2, (rect.bottom+rect.top)/6,
                    196:                                lppw->Message,_fstrlen(lppw->Message));
                    197:                        EndPaint(hwnd, &ps);
                    198:                        return 0;
                    199:                        }
                    200:                case WM_CREATE:
                    201:                        {
                    202:                        /* HBB 981202 HMENU sysmenu = GetSystemMenu(hwnd, FALSE); */
                    203:                        lppw = ((CREATESTRUCT FAR *)lParam)->lpCreateParams;
                    204:                        SetWindowLong(hwnd, 0, (LONG)lppw);
                    205:                        lppw->hWndPause = hwnd;
                    206:                        hdc = GetDC(hwnd);
                    207:                        SelectObject(hdc, GetStockObject(SYSTEM_FIXED_FONT));
                    208:                        GetTextMetrics(hdc, &tm);
                    209:                        cxChar = tm.tmAveCharWidth;
                    210:                        cyChar = tm.tmHeight + tm.tmExternalLeading;
                    211:                        ReleaseDC(hwnd,hdc);
                    212:                        middle = ((LPCREATESTRUCT) lParam)->cx / 2;
                    213:                        lppw->hOK = CreateWindow((LPSTR)"button", (LPSTR)"OK",
                    214:                                WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON,
                    215:                                        middle - 10*cxChar, 3*cyChar,
                    216:                                        8*cxChar, 7*cyChar/4,
                    217:                                        hwnd, (HMENU)IDOK,
                    218:                                        ((LPCREATESTRUCT) lParam)->hInstance, NULL);
                    219:                        lppw->bDefOK = TRUE;
                    220:                        lppw->hCancel = CreateWindow((LPSTR)"button", (LPSTR)"Cancel",
                    221:                                WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
                    222:                                        middle + 2*cxChar, 3*cyChar,
                    223:                                        8*cxChar, 7*cyChar/4,
                    224:                                        hwnd, (HMENU)IDCANCEL,
                    225:                                        ((LPCREATESTRUCT) lParam)->hInstance, NULL);
                    226:                        lppw->lpfnOK = (WNDPROC) GetWindowLong(lppw->hOK, GWL_WNDPROC);
                    227: #ifdef WIN32
                    228:                        SetWindowLong(lppw->hOK, GWL_WNDPROC, (LONG)PauseButtonProc);
                    229: #else
                    230:                        SetWindowLong(lppw->hOK, GWL_WNDPROC, (LONG)lppw->lpfnPauseButtonProc);
                    231: #endif
                    232:                        lppw->lpfnCancel = (WNDPROC) GetWindowLong(lppw->hCancel, GWL_WNDPROC);
                    233: #ifdef WIN32
                    234:                        SetWindowLong(lppw->hCancel, GWL_WNDPROC, (LONG)PauseButtonProc);
                    235: #else
                    236:                        SetWindowLong(lppw->hCancel, GWL_WNDPROC, (LONG)lppw->lpfnPauseButtonProc);
                    237: #endif
                    238:                        if (GetParent(hwnd))
                    239:                                EnableWindow(GetParent(hwnd),FALSE);
                    240: #if 0 /* HBB 981203 */
                    241:                        DeleteMenu(sysmenu,SC_RESTORE,MF_BYCOMMAND);
                    242:                        DeleteMenu(sysmenu,SC_SIZE,MF_BYCOMMAND);
                    243:                        DeleteMenu(sysmenu,SC_MINIMIZE,MF_BYCOMMAND);
                    244:                        DeleteMenu(sysmenu,SC_MAXIMIZE,MF_BYCOMMAND);
                    245:                        DeleteMenu(sysmenu,SC_TASKLIST,MF_BYCOMMAND);
                    246:                        DeleteMenu(sysmenu,0,MF_BYCOMMAND); /* a separator */
                    247:                        DeleteMenu(sysmenu,0,MF_BYCOMMAND); /* a separator */
                    248: #endif
                    249:                        }
                    250:                        return 0;
                    251:                case WM_DESTROY:
                    252:                        GetWindowRect(hwnd, &rect);
                    253:                        lppw->Origin.x = (rect.right+rect.left)/2;
                    254:                        lppw->Origin.y = (rect.bottom+rect.top)/2;
                    255:                        lppw->bPause = FALSE;
                    256:                        if (GetParent(hwnd))
                    257:                                EnableWindow(GetParent(hwnd),TRUE);
                    258:                        break;
                    259:        }
                    260:        return DefWindowProc(hwnd, message, wParam, lParam);
                    261: }
                    262:
                    263:
                    264: LRESULT CALLBACK WINEXPORT
                    265: PauseButtonProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
                    266: {
                    267:        LPPW lppw;
                    268: #ifdef WIN32
                    269:        LONG n = GetWindowLong(hwnd, GWL_ID);
                    270: #else
                    271:        WORD n = GetWindowWord(hwnd, GWW_ID);
                    272: #endif
                    273:        lppw = (LPPW)GetWindowLong(GetParent(hwnd), 0);
                    274:        switch(message) {
                    275:                case WM_KEYDOWN:
                    276:                        switch(wParam) {
                    277:                          case VK_TAB:
                    278:                          case VK_BACK:
                    279:                          case VK_LEFT:
                    280:                          case VK_RIGHT:
                    281:                          case VK_UP:
                    282:                          case VK_DOWN:
                    283:                                lppw->bDefOK = !(n == IDOK);
                    284:                                if (lppw->bDefOK) {
                    285:                                        SendMessage(lppw->hOK,     BM_SETSTYLE, (WPARAM)BS_DEFPUSHBUTTON, (LPARAM)TRUE);
                    286:                                        SendMessage(lppw->hCancel, BM_SETSTYLE, (WPARAM)BS_PUSHBUTTON, (LPARAM)TRUE);
                    287:                                        SetFocus(lppw->hOK);
                    288:                                }
                    289:                                else {
                    290:                                        SendMessage(lppw->hOK,     BM_SETSTYLE, (WPARAM)BS_PUSHBUTTON, (LPARAM)TRUE);
                    291:                                        SendMessage(lppw->hCancel, BM_SETSTYLE, (WPARAM)BS_DEFPUSHBUTTON, (LPARAM)TRUE);
                    292:                                        SetFocus(lppw->hCancel);
                    293:                                }
                    294:                                break;
                    295:                          default:
                    296:                                SendMessage(GetParent(hwnd), message, wParam, lParam);
                    297:                        }
                    298:                        break;
                    299:        }
                    300:        return CallWindowProc(((n == IDOK) ? lppw->lpfnOK : lppw->lpfnCancel),
                    301:                 hwnd, message, wParam, lParam);
                    302: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>