---
 vncviewer/CMakeLists.txt    |    1 +
 vncviewer/OptionsDialog.cxx |   20 ++++--------
 vncviewer/Viewport.cxx      |   12 +------
 vncviewer/keysyms.cxx       |   71 +++++++++++++++++++++++++++++++++++++++++++
 vncviewer/keysyms.h         |   30 ++++++++++++++++++
 5 files changed, 111 insertions(+), 23 deletions(-)
 create mode 100644 vncviewer/keysyms.cxx
 create mode 100644 vncviewer/keysyms.h

diff --git a/vncviewer/CMakeLists.txt b/vncviewer/CMakeLists.txt
index 5ea0ab4..a32c42c 100644
--- a/vncviewer/CMakeLists.txt
+++ b/vncviewer/CMakeLists.txt
@@ -4,6 +4,7 @@ include_directories(${GETTEXT_INCLUDE_DIR})
 include_directories(${CMAKE_SOURCE_DIR}/common)
 set(VNCVIEWER_SOURCES
   buildTime.cxx
+  keysyms.cxx
   CConn.cxx
   DesktopWindow.cxx
   UserDialog.cxx
diff --git a/vncviewer/OptionsDialog.cxx b/vncviewer/OptionsDialog.cxx
index 220ca96..6505284 100644
--- a/vncviewer/OptionsDialog.cxx
+++ b/vncviewer/OptionsDialog.cxx
@@ -36,6 +36,7 @@
 #include "OptionsDialog.h"
 #include "fltk_layout.h"
 #include "i18n.h"
+#include "keysyms.h"
 #include "parameters.h"
 
 #include <FL/Fl_Tabs.H>
@@ -268,11 +269,9 @@ void OptionsDialog::loadOptions(void)
   menuKeyChoice->value(0);
 
   menuKeyBuf = menuKey;
-  if (menuKeyBuf[0] == 'F') {
-    int num = atoi(menuKeyBuf+1);
-    if ((num >= 1) && (num <= 12))
-      menuKeyChoice->value(num);
-  }
+  for (int i = 0; i < getMenuKeySymbolCount(); i++)
+    if (!strcmp(getMenuKeySymbols()[i].name, menuKeyBuf))
+      menuKeyChoice->value(i + 1);
 
   /* Misc. */
   sharedCheckbox->value(shared);
@@ -361,9 +360,7 @@ void OptionsDialog::storeOptions(void)
   if (menuKeyChoice->value() == 0)
     menuKey.setParam("");
   else {
-    char buf[16];
-    sprintf(buf, "F%d", menuKeyChoice->value());
-    menuKey.setParam(buf);
+    menuKey.setParam(menuKeyChoice->text());
   }
 
   /* Misc. */
@@ -696,11 +693,8 @@ void OptionsDialog::createInputPage(int tx, int ty, int 
tw, int th)
   menuKeyChoice = new Fl_Choice(LBLLEFT(tx, ty, 150, CHOICE_HEIGHT, _("Menu 
key")));
 
   menuKeyChoice->add(_("None"), 0, NULL, (void*)0, FL_MENU_DIVIDER);
-  for (int i = 1;i <= 12;i++) {
-    char buf[16];
-    sprintf(buf, "F%d", i);
-    menuKeyChoice->add(buf, 0, NULL, (void*)i, 0);
-  }
+  for (int i = 0; i < getMenuKeySymbolCount(); i++)
+    menuKeyChoice->add(getMenuKeySymbols()[i].name, 0, NULL, 0, 0);
 
   ty += CHOICE_HEIGHT + TIGHT_MARGIN;
 
diff --git a/vncviewer/Viewport.cxx b/vncviewer/Viewport.cxx
index 72de8e8..335ce2d 100644
--- a/vncviewer/Viewport.cxx
+++ b/vncviewer/Viewport.cxx
@@ -46,6 +46,7 @@
 #include "fltk_layout.h"
 #include "parameters.h"
 #include "keysym2ucs.h"
+#include "keysyms.h"
 #include "vncviewer.h"
 
 #include <FL/fl_draw.H>
@@ -938,16 +939,7 @@ void Viewport::popupContextMenu()
 
 void Viewport::setMenuKey()
 {
-  const char *menuKeyStr;
-
-  menuKeyCode = 0;
-
-  menuKeyStr = menuKey;
-  if (menuKeyStr[0] == 'F') {
-    int num = atoi(menuKeyStr + 1);
-    if ((num >= 1) && (num <= 12))
-      menuKeyCode = FL_F + num;
-  }
+  menuKeyCode = getMenuKeyCode();
 
   // Need to repopulate the context menu as it contains references to
   // the menu key
diff --git a/vncviewer/keysyms.cxx b/vncviewer/keysyms.cxx
new file mode 100644
index 0000000..240a522
--- /dev/null
+++ b/vncviewer/keysyms.cxx
@@ -0,0 +1,71 @@
+/* Copyright 2011 Martin Koegler <mkoeg...@auto.tuwien.ac.at>
+ * Copyright 2011 Pierre Ossman <oss...@cendio.se> for Cendio AB
+ * 
+ * This is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ * 
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this software; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
+ * USA.
+ */
+
+#include <string.h>
+#include <FL/Fl.H>
+
+#include "keysyms.h"
+#include "parameters.h"
+
+static const MenuKeySymbol menuSymbols[] = {
+  {"F1", FL_F + 1},
+  {"F2", FL_F + 2},
+  {"F3", FL_F + 3},
+  {"F4", FL_F + 4},
+  {"F5", FL_F + 5},
+  {"F6", FL_F + 6},
+  {"F7", FL_F + 7},
+  {"F8", FL_F + 8},
+  {"F9", FL_F + 9},
+  {"F10", FL_F + 10},
+  {"F11", FL_F + 11},
+  {"F12", FL_F + 12},
+  {"Pause", FL_Pause},
+  {"Print", FL_Print},
+  {"Scroll_Lock", FL_Scroll_Lock},
+  {"Escape", FL_Escape},
+  {"Insert", FL_Insert},
+  {"Delete", FL_Delete},
+  {"Home", FL_Home},
+  {"Page_Up", FL_Page_Up},
+  {"Page_Down", FL_Page_Down},
+};
+
+int getMenuKeySymbolCount()
+{
+  return sizeof(menuSymbols)/sizeof(menuSymbols[0]);
+}
+
+const MenuKeySymbol* getMenuKeySymbols()
+{
+  return menuSymbols;
+}
+
+int getMenuKeyCode()
+{
+    const char *menuKeyStr;
+    int menuKeyCode = 0;
+
+    menuKeyStr = menuKey;
+    for(int i = 0; i < getMenuKeySymbolCount(); i++)
+      if (!strcmp(menuSymbols[i].name, menuKeyStr))
+        menuKeyCode = menuSymbols[i].keycode;
+
+    return menuKeyCode;
+}
diff --git a/vncviewer/keysyms.h b/vncviewer/keysyms.h
new file mode 100644
index 0000000..ecb46ed
--- /dev/null
+++ b/vncviewer/keysyms.h
@@ -0,0 +1,30 @@
+/* Copyright 2011 Martin Koegler <mkoeg...@auto.tuwien.ac.at>
+ * 
+ * This is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ * 
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this software; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
+ * USA.
+ */
+#ifndef __KEYSYM_H__
+#define __KEYSYM_H__
+
+typedef struct {
+  const char* name;
+  int keycode;
+} MenuKeySymbol;
+
+int getMenuKeyCode();
+int getMenuKeySymbolCount();
+const MenuKeySymbol* getMenuKeySymbols();
+
+#endif
-- 
1.7.2.5


------------------------------------------------------------------------------
EMC VNX: the world's simplest storage, starting under $10K
The only unified storage solution that offers unified management 
Up to 160% more powerful than alternatives and 25% more efficient. 
Guaranteed. http://p.sf.net/sfu/emc-vnx-dev2dev
_______________________________________________
Tigervnc-devel mailing list
Tigervnc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tigervnc-devel

Reply via email to