aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPierre Ossman <ossman@cendio.se>2022-09-07 10:34:20 +0200
committerPierre Ossman <ossman@cendio.se>2022-09-07 10:34:20 +0200
commit7f0abbaed390b217627a0536e65f30d3bef90d15 (patch)
treead70e9b986429697bd0f9767673887055836b2ff
parent6416d812699e417c217cf932b702f95182dd48a4 (diff)
downloadtigervnc-7f0abbaed390b217627a0536e65f30d3bef90d15.tar.gz
tigervnc-7f0abbaed390b217627a0536e65f30d3bef90d15.zip
Split out FLTK utility functions
These have nothing to do with layout, so let's split them to their own file.
-rw-r--r--vncviewer/OptionsDialog.cxx1
-rw-r--r--vncviewer/UserDialog.cxx1
-rw-r--r--vncviewer/Viewport.cxx1
-rw-r--r--vncviewer/fltk/layout.h82
-rw-r--r--vncviewer/fltk/util.h110
-rw-r--r--vncviewer/vncviewer.cxx2
6 files changed, 114 insertions, 83 deletions
diff --git a/vncviewer/OptionsDialog.cxx b/vncviewer/OptionsDialog.cxx
index 78197c6f..9ce00316 100644
--- a/vncviewer/OptionsDialog.cxx
+++ b/vncviewer/OptionsDialog.cxx
@@ -41,6 +41,7 @@
#include "parameters.h"
#include "fltk/layout.h"
+#include "fltk/util.h"
#include "fltk/MonitorArrangement.h"
#include <FL/Fl.H>
diff --git a/vncviewer/UserDialog.cxx b/vncviewer/UserDialog.cxx
index acd86b1a..212a5bdb 100644
--- a/vncviewer/UserDialog.cxx
+++ b/vncviewer/UserDialog.cxx
@@ -39,6 +39,7 @@
#include <rfb/Exception.h>
#include "fltk/layout.h"
+#include "fltk/util.h"
#include "i18n.h"
#include "parameters.h"
#include "UserDialog.h"
diff --git a/vncviewer/Viewport.cxx b/vncviewer/Viewport.cxx
index 14116d11..9b5ad872 100644
--- a/vncviewer/Viewport.cxx
+++ b/vncviewer/Viewport.cxx
@@ -56,6 +56,7 @@
#endif
#include "fltk/layout.h"
+#include "fltk/util.h"
#include "Viewport.h"
#include "CConn.h"
#include "OptionsDialog.h"
diff --git a/vncviewer/fltk/layout.h b/vncviewer/fltk/layout.h
index 8153f9b1..ae716e1a 100644
--- a/vncviewer/fltk/layout.h
+++ b/vncviewer/fltk/layout.h
@@ -25,7 +25,6 @@
#define __FLTK_LAYOUT_H__
#include <FL/fl_draw.H>
-#include <FL/Fl_Menu_.H>
/* Calculates the width of a string as printed by FLTK (pixels) */
static inline int gui_str_len(const char *str)
@@ -39,87 +38,6 @@ static inline int gui_str_len(const char *str)
return (int)(len + 0.5f);
}
-/* Escapes all @ in text as those have special meaning in labels */
-static inline size_t fltk_escape(const char *in, char *out, size_t maxlen)
-{
- size_t len;
-
- len = 0;
-
- while (*in != '\0') {
- if (*in == '@') {
- if (maxlen >= 3) {
- *out++ = '@';
- *out++ = '@';
- maxlen -= 2;
- }
-
- len += 2;
- } else {
- if (maxlen >= 2) {
- *out++ = *in;
- maxlen--;
- }
-
- len += 1;
- }
-
- in++;
- }
-
- if (maxlen)
- *out = '\0';
-
- return len;
-}
-
-/* Filter out unsafe characters for menu entries */
-static inline size_t fltk_menu_escape(const char *in, char *out, size_t maxlen)
-{
- size_t len;
-
- len = 0;
-
- while (*in != '\0') {
- if (*in == '/') {
- if (maxlen >= 3) {
- *out++ = '\\';
- *out++ = '/';
- maxlen -= 2;
- }
-
- len += 2;
- } else {
- if (maxlen >= 2) {
- *out++ = *in;
- maxlen--;
- }
-
- len += 1;
- }
-
- in++;
- }
-
- if (maxlen)
- *out = '\0';
-
- return len;
-}
-
-/* Helper to add menu entries safely */
-static inline void fltk_menu_add(Fl_Menu_ *menu, const char *text,
- int shortcut, Fl_Callback *cb,
- void *data = 0, int flags = 0)
-{
- char buffer[1024];
-
- if (fltk_menu_escape(text, buffer, sizeof(buffer)) >= sizeof(buffer))
- return;
-
- menu->add(buffer, shortcut, cb, data, flags);
-}
-
/**** MARGINS ****/
#define OUTER_MARGIN 10
diff --git a/vncviewer/fltk/util.h b/vncviewer/fltk/util.h
new file mode 100644
index 00000000..87765396
--- /dev/null
+++ b/vncviewer/fltk/util.h
@@ -0,0 +1,110 @@
+/* Copyright 2011 Pierre Ossman <ossman@cendio.se> for Cendio AB
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#ifndef __FLTK_UTIL_H__
+#define __FLTK_UTIL_H__
+
+#include <FL/Fl_Menu_.H>
+
+/* Escapes all @ in text as those have special meaning in labels */
+static inline size_t fltk_escape(const char *in, char *out, size_t maxlen)
+{
+ size_t len;
+
+ len = 0;
+
+ while (*in != '\0') {
+ if (*in == '@') {
+ if (maxlen >= 3) {
+ *out++ = '@';
+ *out++ = '@';
+ maxlen -= 2;
+ }
+
+ len += 2;
+ } else {
+ if (maxlen >= 2) {
+ *out++ = *in;
+ maxlen--;
+ }
+
+ len += 1;
+ }
+
+ in++;
+ }
+
+ if (maxlen)
+ *out = '\0';
+
+ return len;
+}
+
+/* Filter out unsafe characters for menu entries */
+static inline size_t fltk_menu_escape(const char *in, char *out, size_t maxlen)
+{
+ size_t len;
+
+ len = 0;
+
+ while (*in != '\0') {
+ if (*in == '/') {
+ if (maxlen >= 3) {
+ *out++ = '\\';
+ *out++ = '/';
+ maxlen -= 2;
+ }
+
+ len += 2;
+ } else {
+ if (maxlen >= 2) {
+ *out++ = *in;
+ maxlen--;
+ }
+
+ len += 1;
+ }
+
+ in++;
+ }
+
+ if (maxlen)
+ *out = '\0';
+
+ return len;
+}
+
+/* Helper to add menu entries safely */
+static inline void fltk_menu_add(Fl_Menu_ *menu, const char *text,
+ int shortcut, Fl_Callback *cb,
+ void *data = 0, int flags = 0)
+{
+ char buffer[1024];
+
+ if (fltk_menu_escape(text, buffer, sizeof(buffer)) >= sizeof(buffer))
+ return;
+
+ menu->add(buffer, shortcut, cb, data, flags);
+}
+
+#endif
diff --git a/vncviewer/vncviewer.cxx b/vncviewer/vncviewer.cxx
index 4dd4eac8..13441900 100644
--- a/vncviewer/vncviewer.cxx
+++ b/vncviewer/vncviewer.cxx
@@ -67,7 +67,7 @@
#include <FL/fl_ask.H>
#include <FL/x.H>
-#include "fltk/layout.h"
+#include "fltk/util.h"
#include "i18n.h"
#include "parameters.h"
#include "CConn.h"