X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/ad81651f00edc6f489d9b6a0839d316a964fd521..6be0b53f3d08680cf2e719e05d9756f3442c166c:/src/os2/accel.cpp diff --git a/src/os2/accel.cpp b/src/os2/accel.cpp index 7be1c6acd3..662e2c63f0 100644 --- a/src/os2/accel.cpp +++ b/src/os2/accel.cpp @@ -16,6 +16,8 @@ #include #include "wx/setup.h" #include "wx/window.h" +#include "wx/app.h" +#include "wx/frame.h" #endif #include "wx/os2/accel.h" @@ -42,59 +44,136 @@ protected: wxAcceleratorRefData::wxAcceleratorRefData() { - // TODO -/* - HACCEL m_hAccel; -*/ -} + m_ok = FALSE; + m_hAccel = 0; +} // end of wxAcceleratorRefData::wxAcceleratorRefData wxAcceleratorRefData::~wxAcceleratorRefData() { -/* - if (m_hAccel) - { - DestroyAcceleratorTable((HACCEL) m_hAccel); - } - m_hAccel = 0 ; -*/ -} + if (m_hAccel) + { + WinDestroyAccelTable((HACCEL) m_hAccel); + } + m_hAccel = 0 ; +} // end of wxAcceleratorRefData::~wxAcceleratorRefData wxAcceleratorTable::wxAcceleratorTable() { - m_refData = NULL; -} + m_refData = NULL; +} // end of wxAcceleratorTable::wxAcceleratorTable wxAcceleratorTable::~wxAcceleratorTable() { -} +} // end of wxAcceleratorTable::~wxAcceleratorTable // Load from .rc resource -wxAcceleratorTable::wxAcceleratorTable(const wxString& resource) +wxAcceleratorTable::wxAcceleratorTable( + const wxString& rResource +) { + HACCEL hAccel; + ULONG ulId; + m_refData = new wxAcceleratorRefData; -/* TODO: load acelerator from resource, if appropriate for your platform + ulId = atol((char*)rResource.c_str()); + hAccel = ::WinLoadAccelTable( vHabmain + ,NULL // resources always in .exe + ,(ULONG)ulId + ); + if (wxTheApp->GetTopWindow() != NULL) + { + // + // If we have accelerators the top window is the frame + // + wxFrame* pFrame = (wxFrame*)wxTheApp->GetTopWindow(); + + ::WinSetAccelTable( vHabmain + ,hAccel + ,(HWND)pFrame->GetFrame() + ); + } M_ACCELDATA->m_hAccel = hAccel; M_ACCELDATA->m_ok = (hAccel != 0); -*/ } -extern int wxCharCodeWXToOS2(int id, bool *isVirtual); +extern int wxCharCodeWXToOS2( + int nId +, bool* pbIsVirtual +); // Create from an array -wxAcceleratorTable::wxAcceleratorTable(int n, wxAcceleratorEntry entries[]) +wxAcceleratorTable::wxAcceleratorTable( + int n +, const wxAcceleratorEntry vaEntries[] +) { - m_refData = new wxAcceleratorRefData; + int nAccelLength = ((sizeof(ACCEL) * n) + sizeof(ACCELTABLE)); + PACCELTABLE pArr; + int i; -/* TODO: create table from entries - */ -} + m_refData = new wxAcceleratorRefData; + pArr = (PACCELTABLE) new BYTE[nAccelLength]; + + for (i = 0; i < n; i++) + { + USHORT uVirt = AF_CHAR; + + if (vaEntries[i].GetFlags() & wxACCEL_ALT) + { + uVirt |= AF_ALT; + uVirt |= AF_VIRTUALKEY; + } + if (vaEntries[i].GetFlags() & wxACCEL_SHIFT) + { + uVirt |= AF_SHIFT; + uVirt |= AF_VIRTUALKEY; + } + if (vaEntries[i].GetFlags() & wxACCEL_CTRL) + { + uVirt |= AF_CONTROL; + uVirt |= AF_VIRTUALKEY; + } + + bool bIsVirtual; + USHORT uKey = wxCharCodeWXToOS2( vaEntries[i].GetKeyCode() + ,&bIsVirtual + ); + if (bIsVirtual) + uVirt = AF_CHAR | AF_VIRTUALKEY; + + USHORT uCmd = vaEntries[i].GetCommand(); + + pArr->aaccel[i].fs = uVirt; + pArr->aaccel[i].key = uKey; + pArr->aaccel[i].cmd = uCmd; + } + pArr->codepage = ::WinQueryCp(wxTheApp->m_hMq); + pArr->cAccel = (USHORT)n; + M_ACCELDATA->m_hAccel = ::WinCreateAccelTable( vHabmain + ,pArr + ); + if (wxTheApp->GetTopWindow() != NULL) + { + // + // If we have accelerators the top window is the frame + // + wxFrame* pFrame = (wxFrame*)wxTheApp->GetTopWindow(); + + ::WinSetAccelTable( vHabmain + ,M_ACCELDATA->m_hAccel + ,(HWND)pFrame->GetFrame() + ); + } + + delete[] pArr; + M_ACCELDATA->m_ok = (M_ACCELDATA->m_hAccel != 0); +} // end of wxAcceleratorTable::wxAcceleratorTable bool wxAcceleratorTable::Ok() const { - // TODO - return FALSE; -} + return(M_ACCELDATA && (M_ACCELDATA->m_ok)); +} // end of wxAcceleratorTable::Ok void wxAcceleratorTable::SetHACCEL(WXHACCEL hAccel) { @@ -111,14 +190,23 @@ WXHACCEL wxAcceleratorTable::GetHACCEL() const return (WXHACCEL) M_ACCELDATA->m_hAccel; } -bool wxAcceleratorTable::Translate(wxWindow *window, WXMSG *wxmsg) const +bool wxAcceleratorTable::Translate( + WXHWND hWnd +, WXMSG* pWxmsg +) const { - // TODO: -/* - MSG *msg = (MSG *)wxmsg; - - return Ok() && ::TranslateAccelerator(GetHwndOf(window), GetHaccel(), msg); -*/ - return FALSE; -} + PQMSG pMsg = (PQMSG)pWxmsg; + BOOL rc = FALSE; + + rc = ::WinTranslateAccel( vHabmain + ,(HWND)hWnd + ,GetHaccel() + ,pMsg + ); + if (rc) + { + int x = 1; + } + return (Ok() && rc); +} // end of wxAcceleratorTable::Translate