]> git.saurik.com Git - wxWidgets.git/blobdiff - src/os2/accel.cpp
Add missing WXK constants for the control keys
[wxWidgets.git] / src / os2 / accel.cpp
index 881da9b4c56f8b261d377b627c8467cf28fed1b8..c65092363e75cab008d6a33557b2dc91758077f7 100644 (file)
@@ -1,5 +1,5 @@
 /////////////////////////////////////////////////////////////////////////////
 /////////////////////////////////////////////////////////////////////////////
-// Name:        accel.cpp
+// Name:        src/os2/accel.cpp
 // Purpose:     wxAcceleratorTable
 // Author:      David Webster
 // Modified by:
 // Purpose:     wxAcceleratorTable
 // Author:      David Webster
 // Modified by:
 // For compilers that support precompilation, includes "wx.h".
 #include "wx/wxprec.h"
 
 // For compilers that support precompilation, includes "wx.h".
 #include "wx/wxprec.h"
 
+#include "wx/accel.h"
+
 #ifndef WX_PRECOMP
 #ifndef WX_PRECOMP
-#include <stdio.h>
-#include "wx/setup.h"
-#include "wx/window.h"
+    #include <stdio.h>
+    #include "wx/window.h"
+    #include "wx/app.h"
+    #include "wx/frame.h"
 #endif
 
 #endif
 
-#include "wx/os2/accel.h"
-
 #include "wx/os2/private.h"
 
 
 #include "wx/os2/private.h"
 
 
-#if !USE_SHARED_LIBRARIES
 IMPLEMENT_DYNAMIC_CLASS(wxAcceleratorTable, wxObject)
 IMPLEMENT_DYNAMIC_CLASS(wxAcceleratorTable, wxObject)
-#endif
 
 class WXDLLEXPORT wxAcceleratorRefData: public wxObjectRefData
 {
     friend class WXDLLEXPORT wxAcceleratorTable;
 public:
     wxAcceleratorRefData();
 
 class WXDLLEXPORT wxAcceleratorRefData: public wxObjectRefData
 {
     friend class WXDLLEXPORT wxAcceleratorTable;
 public:
     wxAcceleratorRefData();
-    ~wxAcceleratorRefData();
+    virtual ~wxAcceleratorRefData();
 
     inline HACCEL GetHACCEL() const { return m_hAccel; }
 protected:
 
     inline HACCEL GetHACCEL() const { return m_hAccel; }
 protected:
@@ -44,59 +43,135 @@ protected:
 
 wxAcceleratorRefData::wxAcceleratorRefData()
 {
 
 wxAcceleratorRefData::wxAcceleratorRefData()
 {
-    // TODO
-/*
-    HACCEL      m_hAccel;
-*/
-}
+    m_ok = false;
+    m_hAccel = 0;
+} // end of wxAcceleratorRefData::wxAcceleratorRefData
 
 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()
 {
 
 wxAcceleratorTable::wxAcceleratorTable()
 {
-  m_refData = NULL;
-}
+    m_refData = NULL;
+} // end of wxAcceleratorTable::wxAcceleratorTable
 
 wxAcceleratorTable::~wxAcceleratorTable()
 {
 
 wxAcceleratorTable::~wxAcceleratorTable()
 {
-}
+} // end of wxAcceleratorTable::~wxAcceleratorTable
 
 // Load from .rc resource
 
 // Load from .rc resource
-wxAcceleratorTable::wxAcceleratorTable(const wxString& resource)
+wxAcceleratorTable::wxAcceleratorTable(
+  const wxString&                  rResource
+)
 {
 {
+    HACCEL                          hAccel;
+    ULONG                           ulId;
+
     m_refData = new wxAcceleratorRefData;
 
     m_refData = new wxAcceleratorRefData;
 
-/* TODO: load acelerator from resource, if appropriate for your platform
+    ulId = atol(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);
     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
 
 // Create from an array
-wxAcceleratorTable::wxAcceleratorTable(int n, wxAcceleratorEntry entries[])
+wxAcceleratorTable::wxAcceleratorTable(
+  int                               n
+, const wxAcceleratorEntry          vaEntries[]
+)
 {
 {
-    m_refData = new wxAcceleratorRefData;
-
-/* TODO: create table from entries
- */
-}
+    int                             nAccelLength = ((sizeof(ACCEL) * n) + sizeof(ACCELTABLE));
+    PACCELTABLE                     pArr;
+    int                             i;
 
 
-bool wxAcceleratorTable::Ok() const
+    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 = (USHORT)wxCharCodeWXToOS2( vaEntries[i].GetKeyCode(),
+                                                 &bIsVirtual);
+        if (bIsVirtual)
+            uVirt = AF_CHAR | AF_VIRTUALKEY;
+
+        USHORT uCmd = (USHORT)vaEntries[i].GetCommand();
+
+        pArr->aaccel[i].fs  = uVirt;
+        pArr->aaccel[i].key = uKey;
+        pArr->aaccel[i].cmd = uCmd;
+    }
+    pArr->codepage = (USHORT)::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::IsOk() const
 {
 {
-    // TODO
-    return FALSE;
-}
+    return(M_ACCELDATA && (M_ACCELDATA->m_ok));
+} // end of wxAcceleratorTable::IsOk
 
 void wxAcceleratorTable::SetHACCEL(WXHACCEL hAccel)
 {
 
 void wxAcceleratorTable::SetHACCEL(WXHACCEL hAccel)
 {
@@ -113,14 +188,56 @@ WXHACCEL wxAcceleratorTable::GetHACCEL() const
     return (WXHACCEL) M_ACCELDATA->m_hAccel;
 }
 
     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
+                            );
+    return (IsOk() && rc);
+} // end of wxAcceleratorTable::Translate
+
+// ---------------------------------------------------------------------------
+// function for translating labels
+// ---------------------------------------------------------------------------
+
+wxString wxPMTextToLabel( const wxString& rsTitle )
+{
+    wxString      sTitle;
+    const wxChar* zPc;
+
+    if (rsTitle.empty())
+        return(sTitle);
+
+    for (zPc = rsTitle.c_str(); *zPc != wxT('\0'); zPc++)
+    {
+        if (*zPc == wxT('&'))
+        {
+            if (*(zPc + 1) == wxT('&'))
+            {
+                zPc++;
+                sTitle << wxT('&');
+            }
+            else
+                sTitle << wxT('~');
+        }
+        else
+        {
+            if ( *zPc == wxT('~'))
+            {
+                //
+                // Tildes must be doubled to prevent them from being
+                // interpreted as accelerator character prefix by PM ???
+                //
+                sTitle << *zPc;
+            }
+            sTitle << *zPc;
+        }
+    }
+    return(sTitle);
+} // end of wxPMTextToLabel