| 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 SYSTEM_H |
| 10 | #define SYSTEM_H |
| 11 | |
| 12 | #include "config.h" |
| 13 | #include "ui/strlib.h" |
| 14 | #include "ui/ansiwidget.h" |
| 15 | #include "ui/textedit.h" |
| 16 | |
| 17 | void reset_image_cache(); |
| 18 | |
| 19 | struct Cache : public strlib::Properties<String *> { |
| 20 | Cache(int size) : Properties(size * 2), _index(0) {} |
| 21 | void add(const char *key, const char *value); |
| 22 | int _index; |
| 23 | }; |
| 24 | |
| 25 | struct System { |
| 26 | System(); |
| 27 | virtual ~System(); |
| 28 | |
| 29 | int getPen(int code); |
| 30 | char *getText(char *dest, int maxSize); |
| 31 | bool isActive() const { return _state != kInitState && _state != kDoneState; } |
| 32 | bool isBack() const { return _state == kBackState; } |
| 33 | bool isBreak() const { return _state >= kBreakState; } |
| 34 | bool isClosing() const { return _state >= kClosingState; } |
| 35 | bool isEditing() const { return _state == kEditState; } |
| 36 | bool isInitial() const { return _state == kInitState; } |
| 37 | bool isModal() const { return _state == kModalState; } |
| 38 | bool isRestart() const { return _state == kRestartState; } |
| 39 | bool isRunning() const { return _state == kRunState || _state == kModalState; } |
| 40 | bool isThreadActive() const { return _state == kActiveState; } |
| 41 | bool isSystemScreen() const { return _userScreenId != -1; } |
| 42 | void logStack(const char *keyword, int type, int line); |
| 43 | char *readSource(const char *fileName); |
| 44 | void setBack(); |
| 45 | void setExit(bool quit); |
| 46 | void setLoadBreak(const char *path); |
| 47 | void setLoadPath(const char *path); |
| 48 | void setRunning(bool running); |
| 49 | void systemLog(const char *msg); |
| 50 | void systemPrint(const char *msg, ...); |
| 51 | AnsiWidget *getOutput() { return _output; } |
| 52 | |
| 53 | enum CursorType { |
| 54 | kHand, kArrow, kIBeam |
| 55 | }; |
| 56 | |
| 57 | virtual void enableCursor(bool enabled) = 0; |
| 58 | virtual void addShortcut(const char *path) = 0; |
| 59 | virtual void alert(const char *title, const char *message) = 0; |
| 60 | virtual int ask(const char *title, const char *prompt, bool cancel=true) = 0; |
| 61 | virtual void browseFile(const char *url) = 0; |
| 62 | virtual MAEvent processEvents(int waitFlag) = 0; |
| 63 | virtual char *loadResource(const char *fileName); |
| 64 | virtual void optionsBox(StringList *items) = 0; |
| 65 | virtual void onRunCompleted() = 0; |
| 66 | virtual void saveWindowRect() = 0; |
| 67 | virtual void setWindowSize(int width, int height) = 0; |
| 68 | virtual void setWindowTitle(const char *title) = 0; |
| 69 | virtual void share(const char *path) = 0; |
| 70 | virtual void showCursor(CursorType cursorType) = 0; |
| 71 | virtual void setClipboardText(const char *text) = 0; |
| 72 | virtual char *getClipboardText() = 0; |
| 73 | |
| 74 | protected: |
| 75 | void editSource(strlib::String loadPath, bool restoreOnExit); |
| 76 | bool execute(const char *bas); |
| 77 | bool fileExists(strlib::String &path); |
| 78 | void formatOptions(StringList *items); |
| 79 | MAEvent getNextEvent() { return processEvents(1); } |
| 80 | uint32_t getModifiedTime(); |
| 81 | void handleEvent(MAEvent &event); |
| 82 | void handleMenu(MAEvent &event); |
| 83 | bool isEditEnabled() const {return opt_ide == IDE_INTERNAL || isScratchLoad();} |
| 84 | bool isEditReady() const {return !isRestart() && isEditEnabled() && !isNetworkLoad();} |
| 85 | bool isNetworkLoad() const {return _loadPath.indexOf("://" , 1) != -1;} |
| 86 | bool isScratchLoad() const {return _loadPath.indexOf("scratch" , 0) != -1;} |
| 87 | bool loadSource(const char *fileName); |
| 88 | void resize(); |
| 89 | void runEdit(const char *startupBas); |
| 90 | void runLive(const char *startupBas); |
| 91 | void runMain(const char *mainBasPath); |
| 92 | void runOnce(const char *startupBas, bool runWait); |
| 93 | void saveFile(TextEditInput *edit, strlib::String &path); |
| 94 | void setupPath(String &loadpath); |
| 95 | bool setParentPath(); |
| 96 | void setDimensions(); |
| 97 | void showCompletion(bool success); |
| 98 | void printErrorLine(); |
| 99 | void printSource(); |
| 100 | void printSourceLine(char *text, int line, bool last); |
| 101 | void setRestart(); |
| 102 | void (); |
| 103 | void showSystemScreen(bool showSrc); |
| 104 | void waitForBack(); |
| 105 | void waitForChange(bool error); |
| 106 | |
| 107 | // platform static virtual |
| 108 | bool getPen3(); |
| 109 | void completeKeyword(int index); |
| 110 | |
| 111 | strlib::Stack<String *> _history; |
| 112 | StackTrace _stackTrace; |
| 113 | Cache _cache; |
| 114 | AnsiWidget *_output; |
| 115 | TextEditInput *_editor; |
| 116 | int *; |
| 117 | char *_programSrc; |
| 118 | |
| 119 | enum { |
| 120 | kInitState = 0,// thread not active |
| 121 | kActiveState, // thread activated |
| 122 | kEditState, // program editor is active |
| 123 | kRunState, // program is running |
| 124 | kModalState, // retrieving user input inside program |
| 125 | kConnState, // retrieving remote program source |
| 126 | kBreakState, // running program should abort |
| 127 | kRestartState, // running program should restart |
| 128 | kBackState, // back button detected |
| 129 | kClosingState, // thread is terminating |
| 130 | kDoneState // thread has terminated |
| 131 | } _state; |
| 132 | |
| 133 | int _touchX; |
| 134 | int _touchY; |
| 135 | int _touchCurX; |
| 136 | int _touchCurY; |
| 137 | int _initialFontSize; |
| 138 | int _fontScale; |
| 139 | int _userScreenId; |
| 140 | uint32_t _modifiedTime; |
| 141 | bool _mainBas; |
| 142 | bool _buttonPressed; |
| 143 | bool _srcRendered; |
| 144 | bool ; |
| 145 | strlib::String _loadPath; |
| 146 | strlib::String _activeFile; |
| 147 | }; |
| 148 | |
| 149 | #endif |
| 150 | |
| 151 | |