| 1 | // This file is part of SmallBASIC |
| 2 | // |
| 3 | // Copyright(C) 2001-2019 Chris Warren-Smith. |
| 4 | // |
| 5 | // This program is distributed under the terms of the GPL v2.0 or later |
| 6 | // Download the GNU Public License (GPL) from www.gnu.org |
| 7 | // |
| 8 | |
| 9 | #ifndef Fl_HELP_WIDGET |
| 10 | #define Fl_HELP_WIDGET |
| 11 | |
| 12 | #include <stdint.h> |
| 13 | #include <FL/fl_draw.H> |
| 14 | #include <FL/Fl_Widget.H> |
| 15 | #include <FL/Fl_Image.H> |
| 16 | #include <FL/Fl_Pixmap.H> |
| 17 | #include <FL/Fl_Shared_Image.H> |
| 18 | #include <FL/Fl_Group.H> |
| 19 | #include <FL/Fl_Scrollbar.H> |
| 20 | #include "ui/strlib.h" |
| 21 | #include "ui/textedit.h" |
| 22 | #include "platform/fltk/utils.h" |
| 23 | |
| 24 | #define ID_BUTTON 1 |
| 25 | #define ID_TEXTBOX 2 |
| 26 | #define ID_TEXTAREA 3 |
| 27 | #define ID_CHKBOX 4 |
| 28 | #define ID_RADIO 5 |
| 29 | #define ID_SELECT 6 |
| 30 | #define ID_RANGEVAL 7 |
| 31 | #define ID_HIDDEN 8 |
| 32 | #define ID_READONLY 9 |
| 33 | |
| 34 | #define MIN_FONT_SIZE 11 |
| 35 | #define MAX_FONT_SIZE 22 |
| 36 | #define EVENT_COPY_TEXT 102 |
| 37 | #define EVENT_SEL_ALL_TEXT 103 |
| 38 | #define EVENT_FIND 104 |
| 39 | |
| 40 | using namespace strlib; |
| 41 | |
| 42 | Fl_Shared_Image *loadImage(const char *name, uchar *buff); |
| 43 | void browseFile(const char *s); |
| 44 | |
| 45 | struct BaseNode; |
| 46 | struct NamedInput; |
| 47 | struct InputNode; |
| 48 | struct AnchorNode; |
| 49 | struct ImageNode; |
| 50 | |
| 51 | class HelpWidget : public Fl_Group { |
| 52 | public: |
| 53 | HelpWidget(Fl_Widget *rect, int fontSize); |
| 54 | virtual ~HelpWidget(); |
| 55 | |
| 56 | void loadBuffer(const char *buffer); |
| 57 | void loadFile(const char *fileName, bool useDocHome = false); |
| 58 | void navigateTo(const char *fileName); |
| 59 | void scrollTo(const char *anchorName); |
| 60 | bool find(const char *s, bool matchCase); |
| 61 | Fl_Widget *getInput(const char *name); |
| 62 | const char *getInputValue(Fl_Widget *button); |
| 63 | const char *getInputValue(int i); |
| 64 | const char *getInputName(Fl_Widget *button); |
| 65 | const char *getTitle() { return title; } |
| 66 | const char *getFileName() { return fileName; } |
| 67 | const char *getDocHome() { return docHome; } |
| 68 | const char *getSelection() { return selection; } |
| 69 | const strlib::String getEventName() { return event; } |
| 70 | void getText(strlib::String *s); |
| 71 | void getInputProperties(Properties<String *> *p); |
| 72 | void setCookies(Properties<String *> *p) { cookies = p; } |
| 73 | void setTheme(EditTheme *theme); |
| 74 | bool setInputValue(const char *assignment); |
| 75 | void selectAll(); |
| 76 | void copySelection(); |
| 77 | void onclick(Fl_Widget *button); |
| 78 | void setDocHome(const char *home); |
| 79 | void reloadImages(); |
| 80 | void setFontSize(int i); |
| 81 | int getFontSize() { return (int)labelsize(); } |
| 82 | void setSelectMode() { mouseMode = mm_select; } |
| 83 | void setPageMode() { mouseMode = mm_page; } |
| 84 | void setScrollMode() { mouseMode = mm_scroll; } |
| 85 | int getNumAnchors() { return anchors.size(); } |
| 86 | const char *getAnchor(int index); |
| 87 | bool isHtmlFile(); |
| 88 | void setTitle(const char *s) { title.empty(); title.append(s); } |
| 89 | |
| 90 | protected: |
| 91 | void reloadPage(); |
| 92 | void compile(); |
| 93 | void init(); |
| 94 | void cleanup(); |
| 95 | void endSelection(); |
| 96 | |
| 97 | // fltk methods |
| 98 | void draw(); |
| 99 | void resize(int x, int y, int w, int h); |
| 100 | int onMove(int event); |
| 101 | int onPush(int event); |
| 102 | int handle(int event); |
| 103 | int handleKeys(); |
| 104 | |
| 105 | private: |
| 106 | bool exposed() { return (damage() & (FL_DAMAGE_EXPOSE | FL_DAMAGE_ALL)); } |
| 107 | void vscroll(int offs); |
| 108 | |
| 109 | Fl_Scrollbar *scrollbar; |
| 110 | Fl_Color background, foreground; |
| 111 | int32_t scrollHeight, scrollWindowHeight; |
| 112 | int16_t markX, markY, pointX, pointY; |
| 113 | int16_t hscroll, scrollY; |
| 114 | enum { mm_select, mm_page, mm_scroll } mouseMode; |
| 115 | strlib::List<BaseNode *> nodeList; |
| 116 | strlib::List<NamedInput *> namedInputs; |
| 117 | strlib::List<InputNode *> inputs; |
| 118 | strlib::List<AnchorNode *> anchors; |
| 119 | strlib::List<ImageNode *> images; |
| 120 | strlib::Properties<String *> *cookies; |
| 121 | strlib::String htmlStr; |
| 122 | strlib::String event; |
| 123 | strlib::String fileName; |
| 124 | strlib::String docHome; |
| 125 | strlib::String title; |
| 126 | strlib::String selection; |
| 127 | }; |
| 128 | |
| 129 | #ifdef Fl_HELP_WIDGET_RESOURCES |
| 130 | // somewhere to keep this clutter |
| 131 | |
| 132 | /* XPM */ |
| 133 | static const char *dot_xpm[] = { |
| 134 | "8 8 3 1" , |
| 135 | " c None" , |
| 136 | ". c #141414" , |
| 137 | "+ c #000000" , |
| 138 | " .. " , |
| 139 | " ++++++ " , |
| 140 | " ++++++ " , |
| 141 | ".++++++." , |
| 142 | ".++++++." , |
| 143 | " ++++++ " , |
| 144 | " ++++++ " , |
| 145 | " .. " |
| 146 | }; |
| 147 | |
| 148 | static Fl_Pixmap dotImage(dot_xpm); |
| 149 | |
| 150 | static const char *ellipse_xpm[] = { |
| 151 | "6 1 2 1" , |
| 152 | " c #000000" , |
| 153 | ". c #FFFFFF" , |
| 154 | " . . ." |
| 155 | }; |
| 156 | |
| 157 | static Fl_Pixmap ellipseImage(ellipse_xpm); |
| 158 | |
| 159 | static const char *broken_xpm[] = { |
| 160 | "16 18 4 1" , |
| 161 | "@ c #000000" , |
| 162 | " c #ffffff" , |
| 163 | "+ c none" , |
| 164 | "x c #ff0000" , |
| 165 | // pixels |
| 166 | "@@@@@@@+++++++++" , |
| 167 | "@ @++++++++++" , |
| 168 | "@ @+++++++++++" , |
| 169 | "@ @++@++++++++" , |
| 170 | "@ @@+++++++++" , |
| 171 | "@ @+++@+++++" , |
| 172 | "@ @++@@++++@" , |
| 173 | "@ xxx @@ @++@@" , |
| 174 | "@ xxx xx@@ @" , |
| 175 | "@ xxx xxx @" , |
| 176 | "@ xxxxxx @" , |
| 177 | "@ xxxx @" , |
| 178 | "@ xxxxxx @" , |
| 179 | "@ xxx xxx @" , |
| 180 | "@ xxx xxx @" , |
| 181 | "@ xxx xxx @" , |
| 182 | "@ @" , |
| 183 | "@@@@@@@@@@@@@@@@" , |
| 184 | NULL |
| 185 | }; |
| 186 | |
| 187 | static Fl_Pixmap brokenImage(broken_xpm); |
| 188 | |
| 189 | #pragma GCC diagnostic ignored "-Wnarrowing" |
| 190 | struct ENTITY_MAP { |
| 191 | const char *ent; |
| 192 | int elen; |
| 193 | char xlat; |
| 194 | } entityMap[] = { |
| 195 | { |
| 196 | "lsquor;" , 8, 130}, { |
| 197 | "fnof;" , 5, 131}, { |
| 198 | "ldquor;" , 8, 132}, { |
| 199 | "hellip;" , 8, 133}, { |
| 200 | "dagger;" , 8, 134}, { |
| 201 | "Dagger;" , 8, 135}, { |
| 202 | "xxx;" , 5, 136}, { |
| 203 | "permil;" , 8, 137}, { |
| 204 | "Scaron;" , 8, 138}, { |
| 205 | "lsaquo;" , 8, 139}, { |
| 206 | "OElig;" , 7, 140}, { |
| 207 | "OElig;" , 7, 141}, { |
| 208 | "OElig;" , 7, 142}, { |
| 209 | "OElig;" , 7, 143}, { |
| 210 | "OElig;" , 7, 144}, { |
| 211 | "lsquo;" , 7, 145}, { |
| 212 | "rsquo;" , 7, 146}, { |
| 213 | "ldquo;" , 7, 147}, { |
| 214 | "rdquo;" , 7, 148}, { |
| 215 | "bull;" , 6, 149}, { |
| 216 | "ndash;" , 7, 150}, { |
| 217 | "mdash;" , 7, 151}, { |
| 218 | "tilde;" , 7, 152}, { |
| 219 | "trade;" , 7, 153}, { |
| 220 | "scaron;" , 8, 154}, { |
| 221 | "rsaquo;" , 8, 155}, { |
| 222 | "oelig;" , 7, 156}, { |
| 223 | "oelig;" , 7, 157}, { |
| 224 | "oelig;" , 7, 158}, { |
| 225 | "Yuml;" , 6, 159}, { |
| 226 | "nbsp;" , 6, ' '}, { |
| 227 | "iexcl;" , 7, 161}, { |
| 228 | "cent;" , 6, 162}, { |
| 229 | "pound;" , 7, 163}, { |
| 230 | "curren;" , 8, 164}, { |
| 231 | "yen;" , 5, 165}, { |
| 232 | "brvbar;" , 8, 166}, { |
| 233 | "sect;" , 6, 167}, { |
| 234 | "uml;" , 5, 168}, { |
| 235 | "copy;" , 6, 169}, { |
| 236 | "ordf;" , 6, 170}, { |
| 237 | "laquo;" , 7, 171}, { |
| 238 | "not;" , 5, 172}, { |
| 239 | "shy;" , 5, 173}, { |
| 240 | "reg;" , 5, 174}, { |
| 241 | "macr;" , 6, 175}, { |
| 242 | "deg;" , 5, 176}, { |
| 243 | "plusmn;" , 8, 177}, { |
| 244 | "sup2;" , 6, 178}, { |
| 245 | "sup3;" , 6, 179}, { |
| 246 | "acute;" , 7, 180}, { |
| 247 | "micro;" , 7, 181}, { |
| 248 | "para;" , 6, 182}, { |
| 249 | "middot;" , 8, 183}, { |
| 250 | "cedil;" , 7, 184}, { |
| 251 | "sup1;" , 6, 185}, { |
| 252 | "ordm;" , 6, 186}, { |
| 253 | "raquo;" , 7, 187}, { |
| 254 | "frac14;" , 8, 188}, { |
| 255 | "frac12;" , 8, 189}, { |
| 256 | "frac34;" , 8, 190}, { |
| 257 | "iquest;" , 8, 191}, { |
| 258 | "Agrave;" , 8, 192}, { |
| 259 | "Aacute;" , 8, 193}, { |
| 260 | "Acirc;" , 7, 194}, { |
| 261 | "Atilde;" , 8, 195}, { |
| 262 | "Auml;" , 6, 196}, { |
| 263 | "Aring;" , 7, 197}, { |
| 264 | "AElig;" , 7, 198}, { |
| 265 | "Ccedil;" , 8, 199}, { |
| 266 | "Egrave;" , 8, 200}, { |
| 267 | "Eacute;" , 8, 201}, { |
| 268 | "Ecirc;" , 7, 202}, { |
| 269 | "Euml;" , 6, 203}, { |
| 270 | "Igrave;" , 8, 204}, { |
| 271 | "Iacute;" , 8, 205}, { |
| 272 | "Icirc;" , 7, 206}, { |
| 273 | "Iuml;" , 6, 207}, { |
| 274 | "ETH;" , 5, 208}, { |
| 275 | "Ntilde;" , 8, 209}, { |
| 276 | "Ograve;" , 8, 210}, { |
| 277 | "Oacute;" , 8, 211}, { |
| 278 | "Ocirc;" , 7, 212}, { |
| 279 | "Otilde;" , 8, 213}, { |
| 280 | "Ouml;" , 6, 214}, { |
| 281 | "times;" , 7, 215}, { |
| 282 | "Oslash;" , 8, 216}, { |
| 283 | "Ugrave;" , 8, 217}, { |
| 284 | "Uacute;" , 8, 218}, { |
| 285 | "Ucirc;" , 7, 219}, { |
| 286 | "Uuml;" , 6, 220}, { |
| 287 | "Yacute;" , 8, 221}, { |
| 288 | "THORN;" , 7, 222}, { |
| 289 | "szlig;" , 7, 223}, { |
| 290 | "agrave;" , 8, 224}, { |
| 291 | "aacute;" , 8, 225}, { |
| 292 | "acirc;" , 7, 226}, { |
| 293 | "atilde;" , 8, 227}, { |
| 294 | "auml;" , 6, 228}, { |
| 295 | "aring;" , 7, 229}, { |
| 296 | "aelig;" , 7, 230}, { |
| 297 | "ccedil;" , 8, 231}, { |
| 298 | "egrave;" , 8, 232}, { |
| 299 | "eacute;" , 8, 233}, { |
| 300 | "ecirc;" , 7, 234}, { |
| 301 | "euml;" , 6, 235}, { |
| 302 | "igrave;" , 8, 236}, { |
| 303 | "iacute;" , 8, 237}, { |
| 304 | "icirc;" , 7, 238}, { |
| 305 | "iuml;" , 6, 239}, { |
| 306 | "eth;" , 5, 240}, { |
| 307 | "ntilde;" , 8, 241}, { |
| 308 | "ograve;" , 8, 242}, { |
| 309 | "oacute;" , 8, 243}, { |
| 310 | "ocirc;" , 7, 244}, { |
| 311 | "otilde;" , 8, 245}, { |
| 312 | "ouml;" , 6, 246}, { |
| 313 | "divide;" , 8, 247}, { |
| 314 | "oslash;" , 8, 248}, { |
| 315 | "ugrave;" , 8, 249}, { |
| 316 | "uacute;" , 8, 250}, { |
| 317 | "ucirc;" , 7, 251}, { |
| 318 | "uuml;" , 6, 252}, { |
| 319 | "yacute;" , 8, 253}, { |
| 320 | "thorn;" , 7, 254}, { |
| 321 | "yuml;" , 6, 255}, { |
| 322 | "gt;" , 4, '>'}, { |
| 323 | "lt;" , 4, '<'}, { |
| 324 | "amp;" , 5, '&'}, { |
| 325 | "quot;" , 6, '\"'},}; |
| 326 | |
| 327 | int entityMapLen = (int)(sizeof(entityMap) / sizeof(entityMap[0])); |
| 328 | |
| 329 | #endif |
| 330 | |
| 331 | #endif |
| 332 | |