Annotation of os232sdk/toolkt20/c/samples/jigsaw/procs.c, revision 1.1.1.1

1.1       root        1: #include "jigsaw.h"
                      2: #include "globals.h"
                      3: #include <stdio.h>
                      4: 
                      5: /******************************************************************************/
                      6: /*                                                                            */
                      7: /* SendCommand will attempt to post the required command and parameters to   */
                      8: /* the asynchronous drawing thread's message queue. The command will only     */
                      9: /* be posted if the queue exists.                                            */
                     10: /*                                                                            */
                     11: /******************************************************************************/
                     12: BOOL SendCommand( usCommand, mp1, mp2)
                     13: USHORT usCommand;
                     14: MPARAM mp1;
                     15: MPARAM mp2;
                     16: {
                     17:   if( !hmqAsync)
                     18:       return( FALSE);
                     19: 
                     20:   switch( usCommand)
                     21:   {
                     22:     case UM_DIE:
                     23:     case UM_LEFTDOWN:
                     24:     case UM_LEFTUP:
                     25:     case UM_MOUSEMOVE:
                     26:     case UM_DRAW:
                     27:     case UM_HSCROLL:
                     28:     case UM_VSCROLL:
                     29:     case UM_ZOOM:
                     30:     case UM_REDRAW:
                     31:     case UM_SIZING:
                     32:     case UM_JUMBLE:
                     33:     case UM_LOAD:
                     34:     case UM_CHAR:
                     35:  
                     36:        return( WinPostQueueMsg( hmqAsync
                     37:                               , usCommand
                     38:                               , mp1
                     39:                               , mp2 ) );
                     40:        break;
                     41: 
                     42:     default:
                     43:        return( TRUE);
                     44:   }
                     45: }
                     46:  
                     47:  
                     48: /******************************************************************************/
                     49: /*                                                                            */
                     50: /* ClientWndProd is the window procedure associated with the client window.   */
                     51: /*                                                                            */
                     52: /******************************************************************************/
                     53: MRESULT EXPENTRY ClientWndProc(hwnd, msg, mp1, mp2)
                     54: HWND    hwnd;
                     55: USHORT  msg;
                     56: MPARAM  mp1;
                     57: MPARAM  mp2;
                     58: {
                     59:   CHAR  szTemp[128];
                     60:   ULONG ulPostCt;
                     61: 
                     62:   switch( msg)
                     63:   {
                     64:     case WM_CHAR:
                     65:       SendCommand( UM_CHAR, mp1, mp2);
                     66:       break;
                     67: 
                     68:     case WM_CLOSE:
                     69:       WinLoadString( habMain, NULL, TERMINATE, sizeof(szTemp), (PSZ)szTemp );
                     70:       if( WinMessageBox( HWND_DESKTOP
                     71:                       , hwndFrame
                     72:                       , szTemp
                     73:                       , szTitle
                     74:                       , 0
                     75:                       , MB_CUAWARNING | MB_YESNO | MB_DEFBUTTON2)
                     76:               == MBID_YES)
                     77:          WinPostMsg( hwnd, WM_QUIT, NULL, NULL);
                     78:       break;
                     79:  
                     80:     case WM_PAINT:
                     81:       return( WndProcPaint());
                     82:       break;
                     83:  
                     84:     /**************************************************************************/
                     85:     /*                                                                       */
                     86:     /**************************************************************************/
                     87:     case WM_ERASEBACKGROUND:
                     88:       return( ( MRESULT)TRUE);
                     89:       break;
                     90:  
                     91:     /**************************************************************************/
                     92:     /* Process menu item commands, and commands generated from the keyboard   */
                     93:     /* via the accelerator table. Most are handled by the async thread        */
                     94:     /**************************************************************************/
                     95:     case WM_COMMAND:
                     96:       return( WndProcCommand( hwnd, msg, mp1, mp2));
                     97:       break;
                     98:  
                     99:     /**************************************************************************/
                    100:     /* Scrolling is handled by the async drawing thread. Simply pass on the   */
                    101:     /* command and parameters                                                 */
                    102:     /**************************************************************************/
                    103:     case WM_HSCROLL:
                    104:       SendCommand( UM_HSCROLL, mp2, 0);
                    105:       break;
                    106:  
                    107:     case WM_VSCROLL:
                    108:       SendCommand( UM_VSCROLL, mp2, 0);
                    109:       break;
                    110:  
                    111:     /************************************************************************/
                    112:     /* The client area is being resized.                                    */
                    113:     /************************************************************************/
                    114:     case WM_SIZE:
                    115:       DosResetEventSem( hevDrawOn, &ulPostCt);
                    116:       SendCommand( UM_SIZING, mp1, mp2);
                    117:       break;
                    118:  
                    119:     /**************************************************************************/
                    120:     /* Mouse commands are handled by the async thread. Simply send on the     */
                    121:     /* command and parameters.                                                */
                    122:     /**************************************************************************/
                    123:     case WM_BUTTON1DBLCLK:
                    124:     case WM_BUTTON1DOWN:
                    125:       if( hwnd != WinQueryFocus( HWND_DESKTOP, FALSE))
                    126:          WinSetFocus( HWND_DESKTOP, hwnd);
                    127:       if( !fButtonDownMain)
                    128:       {
                    129:          fButtonDownMain = TRUE;
                    130:          SendCommand( UM_LEFTDOWN, mp1, 0);
                    131:       }
                    132:       return( ( MRESULT)TRUE);
                    133:       break;
                    134:  
                    135:     case WM_BUTTON1UP:
                    136:       if( !fButtonDownMain)
                    137:          return( ( MRESULT)TRUE);
                    138:       if( SendCommand( UM_LEFTUP, mp1, 0))
                    139:          fButtonDownMain = FALSE;
                    140:       else
                    141:          WinAlarm( HWND_DESKTOP, WA_WARNING);
                    142:       return( ( MRESULT)TRUE);
                    143:       break;
                    144:  
                    145:     case WM_MOUSEMOVE:
                    146:       DosQueryEventSem( hevMouse, &ulPostCt);
                    147:       if( ulPostCt) {
                    148:        SendCommand( UM_MOUSEMOVE, mp1, 0);
                    149:         }
                    150:       return( WinDefWindowProc( hwnd, msg, mp1, mp2));
                    151:       break;
                    152: 
                    153:     /**************************************************************************/
                    154:     /* Default for the rest                                                  */
                    155:     /**************************************************************************/
                    156:     default:
                    157:       return( WinDefWindowProc( hwnd, msg, mp1, mp2));
                    158:   }
                    159:  
                    160:   return( FALSE);
                    161: }
                    162:  
                    163: /******************************************************************************/
                    164: /*                                                                           */
                    165: /* WM_PAINT message                                                          */
                    166: /*                                                                           */
                    167: /******************************************************************************/
                    168: MRESULT WndProcPaint(VOID)
                    169: {
                    170:   HRGN  hrgnUpdt;
                    171:   ULONG  ulPostCt;
                    172:   SHORT  sRgnType;
                    173:  
                    174:   hrgnUpdt = GpiCreateRegion( hpsPaint, 0L, NULL);
                    175:   sRgnType = WinQueryUpdateRegion( hwndClient, hrgnUpdt);
                    176:   SendCommand( UM_DRAW, (MPARAM)hrgnUpdt, 0);
                    177:   DosQueryEventSem( hevLoadMsg, &ulPostCt);
                    178:   if( ulPostCt) {
                    179:     WinSetDlgItemText(hwndStatus, SID_STATUS, pszLoadMsg);
                    180:     }
                    181:   WinValidateRegion( hwndClient, hrgnUpdt, FALSE);
                    182:   return( FALSE);
                    183: }
                    184:  
                    185: /******************************************************************************/
                    186: /* Process menu item commands, and commands generated from the keyboard via   */
                    187: /* the accelerator table.  Most are handled by the async thread              */
                    188: /******************************************************************************/
                    189: MRESULT WndProcCommand(HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
                    190: {
                    191:   CHAR     szTemp[128];
                    192:   ULONG     ulPostCt;
                    193: 
                    194:   switch( SHORT1FROMMP(mp1))
                    195:   {
                    196:     case MENU_SHOW:
                    197:         WinSetParent(hwndStatus, HWND_DESKTOP, TRUE);
                    198:         WinShowWindow(hwndStatus, TRUE);
                    199:         STATUS_SHOW(FALSE);
                    200:         STATUS_HIDE(TRUE);
                    201:         break;
                    202: 
                    203:     case MENU_HIDE:
                    204:         WinSetParent(hwndStatus, HWND_OBJECT, TRUE);
                    205:         WinShowWindow(hwndStatus, TRUE);
                    206:         STATUS_SHOW(TRUE);
                    207:         STATUS_HIDE(FALSE);
                    208:         break;
                    209: 
                    210:     case MENU_JUMBLE:
                    211:        DosResetEventSem( hevDrawOn, &ulPostCt);
                    212:        SendCommand( UM_JUMBLE, 0, 0);
                    213:        break;
                    214: 
                    215:     case MENU_LOAD:
                    216: 
                    217:         if (WinDlgBox(HWND_DESKTOP
                    218:                     , hwnd
                    219:                     , CheapWndProc
                    220:                     , (HMODULE)NULL
                    221:                     , IDD_OPEN
                    222:                     , NULL) == MBID_CANCEL) {
                    223:           return FALSE;
                    224:           }
                    225: 
                    226: 
                    227:         DosResetEventSem( hevDrawOn, &ulPostCt);
                    228:         SendCommand( UM_LOAD, (MPARAM)pli, 0);
                    229:        break;
                    230:     /**********************************************************************/
                    231:     /* EXIT command, menu item or F3 key pressed. Give the operator a    */
                    232:     /* second chance, if confirmed post a WM_QUIT msg to the application  */
                    233:     /* msg queue. This will force the MAIN thread to terminate.           */
                    234:     /**********************************************************************/
                    235:     case MENU_EXIT:
                    236:       WinLoadString( habMain, NULL, TERMINATE, sizeof(szTemp), szTemp);
                    237:       if( WinMessageBox( HWND_DESKTOP
                    238:                       , hwndFrame
                    239:                       , szTemp
                    240:                       , szTitle
                    241:                       , 0
                    242:                       , MB_CUAWARNING | MB_YESNO | MB_DEFBUTTON2)
                    243:            == MBID_YES)
                    244:        WinPostMsg( hwnd, WM_QUIT, NULL, NULL);
                    245:       break;
                    246:  
                    247:     /**********************************************************************/
                    248:     /* Pass on the rest to the async thread.                             */
                    249:     /**********************************************************************/
                    250:     case MENU_ZOOMIN:
                    251:       DosResetEventSem( hevDrawOn, &ulPostCt);
                    252:       SendCommand( UM_ZOOM, (MPARAM)ZOOM_IN, 0);
                    253:       break;
                    254:  
                    255:     case MENU_ZOOMOUT:
                    256:       DosResetEventSem( hevDrawOn, &ulPostCt);
                    257:       SendCommand( UM_ZOOM, (MPARAM)ZOOM_OUT , 0);
                    258:       break;
                    259: 
                    260:     /**********************************************************************/
                    261:     /* Unrecognised => default                                           */
                    262:     /**********************************************************************/
                    263:     default:
                    264:       return( WinDefWindowProc(hwnd, msg, mp1, mp2));
                    265:   }
                    266:   return( FALSE);
                    267: }
                    268:  
                    269: 
                    270: /******************************************************************************/
                    271: /* Dialog window processing routine                                           */
                    272: /******************************************************************************/
                    273: MRESULT EXPENTRY CheapWndProc(hwnd, msg, mp1, mp2)
                    274: HWND   hwnd;
                    275: USHORT msg;
                    276: MPARAM mp1;
                    277: MPARAM mp2;
                    278: {
                    279:     switch (msg) {
                    280:     case WM_INITDLG:
                    281:         WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, EID_NAME));
                    282:         WinSendDlgItemMsg(hwnd, EID_NAME, EM_SETTEXTLIMIT,
                    283:                 MPFROMSHORT((SHORT) sizeof(pli->szFileName)), (MPARAM) 0L);
                    284:         return ((MRESULT) TRUE);
                    285:         break;
                    286: 
                    287:     case WM_COMMAND:
                    288:         if (LOUSHORT(mp1) == MBID_OK) {
                    289:             ULONG ulDummy;
                    290: 
                    291:             WinQueryDlgItemText(hwnd, EID_NAME, sizeof(pli->szFileName),
                    292:                     pli->szFileName);
                    293: 
                    294:             DosOpen(pli->szFileName, &(pli->hf), &ulDummy, 0, 0x0001,
                    295:                     0x00000001, 0x0010, 0x00000000);
                    296:         }
                    297: 
                    298:         WinDismissDlg(hwnd, LOUSHORT(mp1));
                    299:         break;
                    300: 
                    301:     default:
                    302:         return WinDefDlgProc(hwnd, msg, mp1, mp2);
                    303:     }
                    304: 
                    305:     return (MRESULT)0L;
                    306: }
                    307: 
                    308: /******************************************************************************/
                    309: /* Dialog window processing routine                                           */
                    310: /******************************************************************************/
                    311: MRESULT EXPENTRY StatusDlgProc(hwnd, msg, mp1, mp2)
                    312: HWND   hwnd;
                    313: USHORT msg;
                    314: MPARAM mp1;
                    315: MPARAM mp2;
                    316: {
                    317:     ULONG  ulPostCt;
                    318:     LONG   lTempScale;
                    319: 
                    320:     switch (msg) {
                    321:         case WM_INITDLG:
                    322:             WinSendMsg( hwndMenu,
                    323:                         MM_SETITEMATTR,
                    324:                         MPFROM2SHORT( MENU_SHOW, TRUE),
                    325:                         MPFROM2SHORT( MIA_DISABLED, MIA_DISABLED));
                    326:             hwndZoomScrollBar = WinWindowFromID(hwnd, HID_ZOOM);
                    327: 
                    328:             WinSendMsg(hwndZoomScrollBar, SBM_SETSCROLLBAR,
                    329:                     MPFROMSHORT((USHORT) 0),
                    330:                     MPFROM2SHORT((USHORT) 0, (USHORT) ZOOM_MAX));
                    331:             WinSendMsg(hwndZoomScrollBar, SBM_SETTHUMBSIZE,
                    332:                     MPFROM2SHORT((USHORT) 1, (USHORT) (ZOOM_MAX + 1)), 0L);
                    333:             WinEnableWindow(hwndZoomScrollBar, FALSE);
                    334:             WinSetDlgItemText(hwnd, SID_STATUS, pszStartupMsg);
                    335:             sprintf(szZoomFact, "1:1");
                    336:             WinSetDlgItemText(hwnd, SID_ZOOMFACT, szZoomFact);
                    337: 
                    338:             break;
                    339: 
                    340:         case WM_HSCROLL:
                    341:             /*
                    342:              * if BMP is being loaded ingnore zoom messages
                    343:              */
                    344:             DosQueryEventSem(hevLoadMsg, &ulPostCt);
                    345:             if (ulPostCt) {
                    346:                 break;
                    347:                 }
                    348: 
                    349:             switch (SHORT2FROMMP(mp2)) {
                    350: 
                    351:                 case SB_SLIDERTRACK:
                    352:                     lTempScale = (LONG) -SHORT1FROMMP(mp2);
                    353:                     DisplayZoomFactor(lTempScale);
                    354:                     break;
                    355: 
                    356:                 case SB_SLIDERPOSITION:
                    357:                     lTempScale = (LONG) -SHORT1FROMMP(mp2);
                    358:                     if (lScale != lTempScale) {
                    359:                         lScale = lTempScale;
                    360:                         DosResetEventSem( hevDrawOn, &ulPostCt);
                    361:                         DosPostEventSem( hevKillDraw);
                    362:                         DisplayZoomFactor(lScale);
                    363:                         SendCommand( UM_ZOOM, (MPARAM)ZOOM_IN, 0);
                    364:                         }
                    365:                     break;
                    366: 
                    367:                 case SB_LINELEFT:
                    368:                     if (lScale != 0) {
                    369:                         lScale++;
                    370:                         DosResetEventSem( hevDrawOn, &ulPostCt);
                    371:                         DosPostEventSem( hevKillDraw);
                    372:                         DisplayZoomFactor(lScale);
                    373:                         SendCommand( UM_ZOOM, (MPARAM)ZOOM_IN, 0);
                    374:                         }
                    375:                     break;
                    376: 
                    377:                 case SB_LINERIGHT:
                    378:                     if (lScale != -ZOOM_MAX) {
                    379:                         lScale--;
                    380:                         DosResetEventSem( hevDrawOn, &ulPostCt);
                    381:                         DosPostEventSem( hevKillDraw);
                    382:                         DisplayZoomFactor(lScale);
                    383:                         SendCommand( UM_ZOOM, (MPARAM)ZOOM_OUT , 0);
                    384:                         }
                    385:                     break;
                    386:                 }
                    387:             break;
                    388: 
                    389:         case WM_COMMAND:
                    390: 
                    391:             switch (SHORT1FROMMP(mp1)) {
                    392: 
                    393:                 case 1: // hide dialog box
                    394:                   WinSetParent(hwndStatus, HWND_OBJECT, TRUE);
                    395:                   WinShowWindow(hwndStatus, TRUE);
                    396:                   STATUS_SHOW(TRUE);
                    397:                   STATUS_HIDE(FALSE);
                    398:                   break;
                    399:                 }
                    400:             break;
                    401: 
                    402:         default:
                    403:             return WinDefDlgProc(hwnd, msg, mp1, mp2);
                    404:         }
                    405: 
                    406:     return (MRESULT)0L;
                    407: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.