"Fossies" - the Fresh Open Source Software Archive

Member "blassic-0.11.0/key.cpp" (25 Apr 2006, 5629 Bytes) of package /linux/privat/blassic-0.11.0.tgz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "key.cpp" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 0.10.3_vs_0.11.0.

    1 // key.cpp
    2 // Revision 25-apr-2006
    3 
    4 
    5 #include "key.h"
    6 
    7 #include "trace.h"
    8 
    9 
   10 #include <map>
   11 
   12 
   13 #include "config_win.h"
   14 
   15 
   16 #if BLASSIC_USE_WINDOWS
   17 
   18 #include <windows.h>
   19 
   20 #endif
   21 
   22 
   23 namespace blassic {
   24 
   25 
   26 const std::string
   27     keynames::strPAGEUP   ("PAGEUP"),
   28     keynames::strPAGEDOWN ("PAGEDOWN"),
   29     keynames::strEND      ("END"),
   30     keynames::strHOME     ("HOME"),
   31     keynames::strLEFT     ("LEFT"),
   32     keynames::strUP       ("UP"),
   33     keynames::strRIGHT    ("RIGHT"),
   34     keynames::strDOWN     ("DOWN"),
   35     keynames::strINSERT   ("INSERT"),
   36     keynames::strDELETE   ("DELETE"),
   37     keynames::strF1       ("F1"),
   38     keynames::strF2       ("F2"),
   39     keynames::strF3       ("F3"),
   40     keynames::strF4       ("F4"),
   41     keynames::strF5       ("F5"),
   42     keynames::strF6       ("F6"),
   43     keynames::strF7       ("F7"),
   44     keynames::strF8       ("F8"),
   45     keynames::strF9       ("F9"),
   46     keynames::strF10      ("F10"),
   47     keynames::strF11      ("F11"),
   48     keynames::strF12      ("F12"),
   49     keynames::strENTER    ("\n"),
   50     keynames::strCLICK    ("CLICK"),
   51     keynames::strSCLICK   ("SCLICK"),
   52     keynames::strRELEASE  ("RELEASE"),
   53     keynames::strSRELEASE ("SRELEASE");
   54 
   55 
   56 } // namespace blassic
   57 
   58 
   59 #if BLASSIC_USE_WINDOWS
   60 
   61 
   62 namespace {
   63 
   64 
   65 typedef std::map <int, std::string> mapkeyWin_t;
   66 
   67 mapkeyWin_t mapkeyWin;
   68 
   69 inline void assignmapkeyWin (int code, const std::string & name)
   70 {
   71     #ifndef NDEBUG
   72     mapkeyWin_t::iterator it;
   73     if ( (it= mapkeyWin.find (code) ) != mapkeyWin.end () )
   74     {
   75         std::cerr << "Error: key " << name <<
   76             " has equal code than " << it->second <<
   77             std::endl;
   78         throw 1;
   79     }
   80     #endif
   81     mapkeyWin [code]= name;
   82 }
   83 
   84 class InitMapkeyWin {
   85     InitMapkeyWin ();
   86     static InitMapkeyWin instance;
   87 };
   88 
   89 InitMapkeyWin InitMapkeyWin::instance;
   90 
   91 InitMapkeyWin::InitMapkeyWin ()
   92 {
   93     TRF;
   94 
   95     using namespace blassic::keynames;
   96 
   97     assignmapkeyWin (VK_PRIOR,  strPAGEUP);
   98     assignmapkeyWin (VK_NEXT,   strPAGEDOWN);
   99     assignmapkeyWin (VK_END,    strEND);
  100     assignmapkeyWin (VK_HOME,   strHOME);
  101     assignmapkeyWin (VK_LEFT,   strLEFT);
  102     assignmapkeyWin (VK_UP,     strUP);
  103     assignmapkeyWin (VK_RIGHT,  strRIGHT);
  104     assignmapkeyWin (VK_DOWN,   strDOWN);
  105     assignmapkeyWin (VK_INSERT, strINSERT);
  106     assignmapkeyWin (VK_DELETE, strDELETE);
  107     assignmapkeyWin (VK_F1,     strF1);
  108     assignmapkeyWin (VK_F2,     strF2);
  109     assignmapkeyWin (VK_F3,     strF3);
  110     assignmapkeyWin (VK_F4,     strF4);
  111     assignmapkeyWin (VK_F5,     strF5);
  112     assignmapkeyWin (VK_F6,     strF6);
  113     assignmapkeyWin (VK_F7,     strF7);
  114     assignmapkeyWin (VK_F8,     strF8);
  115     assignmapkeyWin (VK_F9,     strF9);
  116     assignmapkeyWin (VK_F10,    strF10);
  117     assignmapkeyWin (VK_F11,    strF11);
  118     assignmapkeyWin (VK_F12,    strF12);
  119 }
  120 
  121 } // namespace
  122 
  123 
  124 std::string blassic::string_from_key_Win (int key)
  125 {
  126     mapkeyWin_t::const_iterator it= mapkeyWin.find (key);
  127     if (it != mapkeyWin.end () )
  128         return it->second;
  129     return std::string ();
  130 }
  131 
  132 
  133 #endif
  134 
  135 
  136 #if 0
  137 
  138 namespace {
  139 
  140 typedef std::map <unsigned int, std::string> mapkey_t;
  141 
  142 mapkey_t mapkey;
  143 
  144 inline void assignmapkey (unsigned int code, const std::string & name)
  145 {
  146     #ifndef NDEBUG
  147     mapkey_t::iterator it;
  148     if ( (it= mapkey.find (code) ) != mapkey.end () )
  149     {
  150         std::cerr << "Error: key " << name <<
  151             " has equal code than " << it->second <<
  152             std::endl;
  153         throw 1;
  154     }
  155     #endif
  156     mapkey [code]= name;
  157 }
  158 
  159 bool initmapkey ()
  160 {
  161     TRACEFUNC (tr, "initmapkey");
  162 
  163     #if BLASSIC_USE_WINDOWS
  164 
  165     assignmapkey (VK_PRIOR,  strPAGEUP);
  166     assignmapkey (VK_NEXT,   strPAGEDOWN);
  167     assignmapkey (VK_END,    strEND);
  168     assignmapkey (VK_HOME,   strHOME);
  169     assignmapkey (VK_LEFT,   strLEFT);
  170     assignmapkey (VK_UP,     strUP);
  171     assignmapkey (VK_RIGHT,  strRIGHT);
  172     assignmapkey (VK_DOWN,   strDOWN);
  173     assignmapkey (VK_INSERT, strINSERT);
  174     assignmapkey (VK_DELETE, strDELETE);
  175     assignmapkey (VK_F1,     strF1);
  176     assignmapkey (VK_F2,     strF2);
  177     assignmapkey (VK_F3,     strF3);
  178     assignmapkey (VK_F4,     strF4);
  179     assignmapkey (VK_F5,     strF5);
  180     assignmapkey (VK_F6,     strF6);
  181     assignmapkey (VK_F7,     strF7);
  182     assignmapkey (VK_F8,     strF8);
  183     assignmapkey (VK_F9,     strF9);
  184     assignmapkey (VK_F10,    strF10);
  185     assignmapkey (VK_F11,    strF11);
  186     assignmapkey (VK_F12,    strF12);
  187 
  188     #elif BLASSIC_USE_X
  189 
  190     assignmapkey (XK_Prior,     strPAGEUP);
  191     assignmapkey (XK_KP_Prior,  strPAGEUP);
  192     assignmapkey (XK_Next,      strPAGEDOWN);
  193     assignmapkey (XK_KP_Next,   strPAGEDOWN);
  194     assignmapkey (XK_End,       strEND);
  195     assignmapkey (XK_KP_End,    strEND);
  196     assignmapkey (XK_Home,      strHOME);
  197     assignmapkey (XK_KP_Home,   strHOME);
  198     assignmapkey (XK_Left,      strLEFT);
  199     assignmapkey (XK_KP_Left,   strLEFT);
  200     assignmapkey (XK_Up,        strUP);
  201     assignmapkey (XK_KP_Up,     strUP);
  202     assignmapkey (XK_Right,     strRIGHT);
  203     assignmapkey (XK_KP_Right,  strRIGHT);
  204     assignmapkey (XK_Down,      strDOWN);
  205     assignmapkey (XK_KP_Down,   strDOWN);
  206     assignmapkey (XK_Insert,    strINSERT);
  207     assignmapkey (XK_KP_Insert, strINSERT);
  208     assignmapkey (XK_Delete,    strDELETE);
  209     assignmapkey (XK_KP_Delete, strDELETE);
  210     assignmapkey (XK_F1,        strF1);
  211     assignmapkey (XK_F2,        strF2);
  212     assignmapkey (XK_F3,        strF3);
  213     assignmapkey (XK_F4,        strF4);
  214     assignmapkey (XK_F5,        strF5);
  215     assignmapkey (XK_F6,        strF6);
  216     assignmapkey (XK_F7,        strF7);
  217     assignmapkey (XK_F8,        strF8);
  218     assignmapkey (XK_F9,        strF9);
  219     assignmapkey (XK_F10,       strF10);
  220     assignmapkey (XK_F11,       strF11);
  221     assignmapkey (XK_F12,       strF12);
  222 
  223     #endif
  224 
  225     return true;
  226 }
  227 
  228 const bool mapkeyinited= initmapkey ();
  229 
  230 } // namespace
  231 
  232 std::string string_from_key (unsigned int key)
  233 {
  234     mapkey_t::const_iterator it= mapkey.find (key);
  235     if (it != mapkey.end () )
  236         return it->second;
  237     return std::string ();
  238 }
  239 
  240 #endif
  241 
  242 // End of key.cpp