Ignore:
Timestamp:
Dec 30, 1999, 10:31:03 AM (26 years ago)
Author:
sandervl
Message:

BvL: Added accelerator support

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/user32/winaccel.cpp

    r1429 r2261  
    1 /* $Id: winaccel.cpp,v 1.2 1999-10-24 12:30:29 sandervl Exp $ */
     1/* $Id: winaccel.cpp,v 1.3 1999-12-30 09:31:03 sandervl Exp $ */
    22/*
    3  * Win32 accelartor key functions for OS/2
    4  *
    5  * Copyright 1999 Sander van Leeuwen
     3 * Win32 accelerator key functions for OS/2
     4 *
     5 * Copyright 1999 Bart van Leeuwen
    66 *
    77 *
     
    1212#include <misc.h>
    1313#include <win32wbase.h>
    14 
    15 //******************************************************************************
    16 //******************************************************************************
     14#include <winaccel.h>
     15
     16/*****************************************************************************
     17 * Name      : HACCEL WIN32API LoadAcceleratorsA
     18 * Purpose   : Load accelerator resource and return handle to it
     19 * Parameters: HINSTANCE hinst, LPCSTR lpszAcc
     20 * Variables :
     21 * Result    : Global Handle of resource
     22 * Remark    : see code
     23 * Status    : OK
     24 *
     25 * Author    : Bart van Leeuwen  [Sun, 1998/12/26 17:01]
     26 *****************************************************************************/
    1727HACCEL WIN32API LoadAcceleratorsA(HINSTANCE hinst, LPCSTR lpszAcc)
    1828{
     
    2434    return(rc);
    2535}
    26 //******************************************************************************
    27 //******************************************************************************
     36/*****************************************************************************
     37 * Name      : HACCEL WIN32API LoadAcceleratorsW
     38 * Purpose   : Load accelerator resource and return handle to it
     39 * Parameters: HINSTANCE hinst, LPCSTR lpszAcc
     40 * Variables :
     41 * Result    : Global Handle of resource
     42 * Remark    : see code
     43 * Status    : OK
     44 *
     45 * Author    : Bart van Leeuwen  [Sun, 1998/12/26 17:01]
     46 *****************************************************************************/
     47
    2848HACCEL WIN32API LoadAcceleratorsW(HINSTANCE hinst, LPCWSTR lpszAccel)
    2949{
     
    3151
    3252    rc = (HACCEL)FindResourceW(hinst, lpszAccel, RT_ACCELERATORW);
     53
    3354
    3455    dprintf(("LoadAcceleratorsW returned %d\n", rc));
     
    4162 Win32Resource *winres;
    4263
    43     if(HIWORD(haccel) == 0) {
    44         dprintf(("DestroyAcceleratorTable: invalid haccel %x", haccel));
    45         SetLastError(ERROR_INVALID_PARAMETER);
    46         return FALSE;
    47     }
    4864    dprintf(("DestroyAcceleratorTable %x\n", haccel));
    4965    winres = (Win32Resource *)haccel;
     
    5167    return TRUE;
    5268}
    53 //******************************************************************************
    54 //TODO: Do more than just return?
    55 //******************************************************************************
     69/*****************************************************************************
     70 * Name      : int WIN32API TranslateAcceleratorA
     71 * Purpose   : Translate WM_*KEYDOWN messages to WM_COMMAND messages
     72 *             according to Accelerator table
     73 * Parameters: HWND hwnd, HACCEL haccel, LPMSG lpmsg
     74 * Variables :
     75 * Result    : int FALSE (no accelerator found) TRUE (accelerator found)
     76 * Remark    : if a accelerator is found it is not neccesarely executed
     77 *             depends on window stat
     78 * Status    : finished but not fully tested
     79 *
     80 * Author    : Bart van Leeuwen  [Sun, 1998/12/26 17:01]
     81 *****************************************************************************/
    5682int WIN32API TranslateAcceleratorA(HWND hwnd, HACCEL haccel, LPMSG lpmsg)
    5783{
    58  Win32BaseWindow *window;
    59 
    60     window = Win32BaseWindow::GetWindowFromHandle(hwnd);
    61     if(!window) {
    62 //Msg for (non-client) child of our frame window
    63 //      dprintf(("TranslateAcceleratorA, window %x not found", hwnd));
    64         return FALSE;
     84 Win32BaseWindow *window,*parentWindow,*childWindow;
     85 LPWINACCEL lpAccelTbl;
     86 WINACCEL tmpAccel;
     87 HACCEL temp2;
     88 HGLOBAL GlobHandle;
     89 HWND hwndMenu,parent,child,msgHwnd;
     90 int i,keyMask;
     91 INT16 menuStat;
     92 BOOL sendMessage;
     93
     94
     95    //bvl: check if messages come from keyboard
     96    if ((lpmsg->message != WM_KEYDOWN &&
     97         lpmsg->message != WM_SYSKEYDOWN))
     98         {
     99           //dprintf(("TranslateAcceleratorA called by invalid message"));
     100           SetLastError(ERROR_SUCCESS);
     101           return FALSE;
     102         }
     103
     104    window = Win32BaseWindow::GetWindowFromHandle(lpmsg->hwnd);
     105
     106    if(!window)
     107    {
     108      dprintf(("TranslateAcceleratorA, window %x not found", hwnd));
     109      SetLastError(ERROR_INVALID_WINDOW_HANDLE);
     110      return FALSE;
    65111    }
    66     if(window->GetAccelTable() != haccel) {
    67         dprintf(("TranslateAcceleratorA %X %X %X", hwnd, haccel, lpmsg->hwnd));
    68         window->SetAccelTable(haccel);
    69     }
    70 
    71     //SvL: OS/2 automatically translates accelerator keys
     112
     113    //bvl: Get memory pointer here
     114    GlobHandle = LoadResource(NULL,haccel);
     115    lpAccelTbl = (LPWINACCEL) LockResource(GlobHandle);
     116
     117    keyMask=0;
     118    if(GetKeyState(VK_SHIFT) & 0x8000) keyMask |= FSHIFT;
     119    if(GetKeyState(VK_CONTROL) & 0x8000) keyMask |= FCONTROL;
     120    if(GetKeyState(VK_MENU) & 0x8000) keyMask |= FALT;
     121
     122    i=0;
     123    do
     124    {
     125       if ((lpAccelTbl[i].key == lpmsg->wParam)&&(keyMask == (lpAccelTbl[i].fVirt &
     126           (FSHIFT | FCONTROL | FALT))))
     127        {
     128         //bvl: Accelerator found
     129         dprintf(("Accelerator found for command: %X",lpAccelTbl[i].cmd));
     130         //bvl: this is not right, check control and win stat
     131         // SendMessageA(hwnd,WM_COMMAND,lpAccelTbl[i].cmd,0x00010000L);
     132
     133         sendMessage = FALSE;
     134
     135         if (window->isFrameWindow())
     136           {
     137            if ( !window->IsIconic() )
     138             {
     139              //bvl: this is a frame window so just use that menuhandle
     140              hwndMenu = window->GetMenu();
     141              if ( hwndMenu == NULL )
     142               {
     143                //bvl: window does not have a menu so command isn't a menu
     144                dprintf(("framenomenu"));
     145                sendMessage = TRUE;
     146               }
     147               else
     148               {
     149                //bvl: get menuitem  status
     150                menuStat = GetMenuState(hwndMenu,lpAccelTbl[i++].cmd,MF_BYCOMMAND);
     151                //bvl: -1 means no menu Item
     152                if( !menuStat == -1)
     153                 {
     154                  if( menuStat  & !(MF_DISABLED|MF_GRAYED) )
     155                   {
     156                     //bvl: its a menu item and its enabled
     157                     dprintf(("framemenu"));
     158                     sendMessage = TRUE;
     159                   }
     160                   else
     161                   {
     162                    //bvl: its a menu Item but disabled
     163                    sendMessage = FALSE;
     164                   }
     165                 }
     166                 else
     167                 {
     168                  //bvl: the message is probably not a menu msg so process it
     169                  dprintf(("framemenunoitem"));
     170                  sendMessage = TRUE;
     171                 }
     172               }
     173             }
     174           }
     175           else
     176           {
     177              //bvl: the message is probably not a menu msg so process it
     178              dprintf(("noframe"));
     179              sendMessage = TRUE;
     180           }
     181
     182         if ( sendMessage )
     183         {
     184          //bvl: previous checks indicated that command can be send.
     185          SendMessageA(hwnd,WM_COMMAND,lpAccelTbl[i].cmd,0x00010000L);
     186          return TRUE;
     187
     188         }
     189        }
     190
     191    } while ((lpAccelTbl[i++].fVirt & 0x80) == 0);
     192
     193    SetLastError(ERROR_SUCCESS);
    72194    return FALSE;
    73195}
    74 //******************************************************************************
    75 //******************************************************************************
     196/*****************************************************************************
     197 * Name      : int WIN32API TranslateAcceleratorA
     198 * Remark    : See TranslateAcceleratorA
     199 * Status    : finished but not fully tested
     200 *
     201 * Author    : Bart van Leeuwen  [Sun, 1998/12/26 17:01]
     202 *****************************************************************************/
     203
    76204int WIN32API TranslateAcceleratorW( HWND hwnd, HACCEL hAccel, LPMSG lpMsg)
    77205{
Note: See TracChangeset for help on using the changeset viewer.