1 // -*- C++ -*- 2 // -------------------------------------------------------------------- 3 // Appui 4 // -------------------------------------------------------------------- 5 /* 6 7 This file is part of the extensible drawing editor Ipe. 8 Copyright (c) 1993-2020 Otfried Cheong 9 10 Ipe is free software; you can redistribute it and/or modify it 11 under the terms of the GNU General Public License as published by 12 the Free Software Foundation; either version 3 of the License, or 13 (at your option) any later version. 14 15 As a special exception, you have permission to link Ipe with the 16 CGAL library and distribute executables, as long as you follow the 17 requirements of the Gnu General Public License in regard to all of 18 the software in the executable aside from CGAL. 19 20 Ipe is distributed in the hope that it will be useful, but WITHOUT 21 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 22 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 23 License for more details. 24 25 You should have received a copy of the GNU General Public License 26 along with Ipe; if not, you can find it at 27 "http://www.gnu.org/copyleft/gpl.html", or write to the Free 28 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 29 30 */ 31 32 #ifndef APPUI_H 33 #define APPUI_H 34 35 #include "ipecanvas.h" 36 37 // avoid including Lua headers here 38 typedef struct lua_State lua_State; 39 40 #ifdef IPEUI_GTK 41 #include <gtk/gtk.h> 42 typedef GtkWidget *WINID; 43 typedef GtkMenu *MENUHANDLE; 44 #endif 45 #ifdef IPEUI_WIN32 46 #include <windows.h> 47 #include <commctrl.h> 48 typedef HWND WINID; 49 typedef HMENU MENUHANDLE; 50 #endif 51 #ifdef IPEUI_QT 52 #include <QWidget> 53 #include <QMenu> 54 typedef QWidget *WINID; 55 typedef QMenu *MENUHANDLE; 56 #endif 57 #ifdef IPEUI_COCOA 58 #include <Cocoa/Cocoa.h> 59 typedef NSWindow *WINID; 60 typedef NSMenu *MENUHANDLE; 61 #endif 62 63 using namespace ipe; 64 65 constexpr int COPYRIGHT_YEAR = 2020; 66 67 #define IPEABSOLUTE "<absolute>" 68 69 class AppUiBase; 70 extern WINID check_winid(lua_State *L, int i); 71 extern void push_winid(lua_State *L, WINID win); 72 extern String ipeIconDirectory(); 73 extern Buffer ipeIcon(String action, int size); 74 extern AppUiBase *createAppUi(lua_State *L0, int model); 75 76 // -------------------------------------------------------------------- 77 78 class AppUiBase : public CanvasObserver { 79 public: 80 enum { EFileMenu, EEditMenu, EPropertiesMenu, ESnapMenu, 81 EModeMenu, EZoomMenu, ELayerMenu, EViewMenu, 82 EPageMenu, EIpeletMenu, EHelpMenu, ENumMenu }; 83 84 // change list selectorNames if enum changes 85 enum { EUiStroke, EUiFill, EUiPen, EUiDashStyle, 86 EUiTextSize, EUiMarkShape, EUiSymbolSize, EUiOpacity, 87 EUiGridSize, EUiAngleSize, 88 EUiView, EUiPage, EUiViewMarked, EUiPageMarked }; 89 90 // tags for submenus 91 enum { ESubmenuGridSize = 1000, ESubmenuAngleSize, 92 ESubmenuTextStyle, ESubmenuLabelStyle, 93 ESubmenuSelectLayer, ESubmenuMoveLayer, 94 ESubmenuRecentFiles, 95 ESubmenuFin }; 96 97 public: 98 virtual ~AppUiBase(); 99 canvas()100 CanvasBase *canvas() { return iCanvas; } 101 102 void setupSymbolicNames(const Cascade *sheet); 103 void setGridAngleSize(Attribute abs_grid, Attribute abs_angle); 104 void setAttributes(const AllAttributes &all, Cascade *sheet); 105 106 void luaShowPathStylePopup(Vector v); 107 void luaBookmarkSelected(int index); 108 void luaRecentFileSelected(String name); setInkMode(bool ink)109 inline void setInkMode(bool ink) { isInkMode = ink; } 110 static int readImage(lua_State *L, String fn); 111 112 public: // What platforms must implement: 113 virtual WINID windowId() = 0; 114 virtual int dpi() const; 115 virtual void closeWindow() = 0; 116 virtual bool actionState(const char *name) = 0; 117 virtual void setActionState(const char *name, bool value) = 0; 118 virtual void setNumbers(String vno, bool vm, String pno, bool pm) = 0; 119 virtual void setLayers(const Page *page, int view) = 0; 120 virtual void setZoom(double zoom) = 0; 121 virtual void setWindowCaption(bool mod, const char *s) = 0; 122 virtual void setNotes(String notes) = 0; 123 virtual void explain(const char *s, int t) = 0; 124 virtual void showWindow(int width, int height, int x, int y) = 0; 125 virtual void setFullScreen(int mode) = 0; 126 virtual void action(String name) = 0; 127 virtual void setActionsEnabled(bool mode) = 0; 128 virtual void setMouseIndicator(const char *s) = 0; 129 virtual void setSnapIndicator(const char *s) = 0; 130 virtual void setBookmarks(int no, const String *s) = 0; 131 virtual void setToolVisible(int m, bool vis) = 0; 132 virtual int pageSorter(lua_State *L, Document *doc, int pno, 133 int width, int height, int thumbWidth) = 0; 134 virtual int clipboard(lua_State *L) = 0; 135 virtual int setClipboard(lua_State *L) = 0; 136 // Only used on Windows to compute shortcuts: 137 virtual int actionInfo(lua_State *L) const; 138 139 virtual void setRecentFileMenu(const std::vector<String> & names) = 0; 140 141 protected: // What platforms must implement: 142 virtual void addRootMenu(int id, const char *name) = 0; 143 // if title == 0, add separator 144 virtual void addItem(int id, const char *title = nullptr, const char *name = nullptr) = 0; 145 virtual void startSubMenu(int id, const char *name, int tag = 0) = 0; 146 virtual void addSubItem(const char *title, const char *name) = 0; 147 virtual MENUHANDLE endSubMenu() = 0; 148 virtual void addCombo(int sel, String s) = 0; 149 virtual void resetCombos() = 0; 150 virtual void addComboColors(AttributeSeq &sym, AttributeSeq &abs) = 0; 151 virtual void setComboCurrent(int sel, int idx) = 0; 152 virtual void setPathView(const AllAttributes &all, Cascade *sheet) = 0; 153 virtual void setCheckMark(String name, Attribute a) = 0; 154 virtual void setButtonColor(int sel, Color color) = 0; 155 156 protected: 157 virtual void canvasObserverWheelMoved(double xDegrees, double yDegrees, 158 int kind); 159 virtual void canvasObserverMouseAction(int button); 160 virtual void canvasObserverPositionChanged(); 161 virtual void canvasObserverToolChanged(bool hasTool); 162 virtual void canvasObserverSizeChanged(); 163 164 protected: 165 AppUiBase(lua_State *L0, int model); 166 static const char * const selectorNames[]; 167 168 void luaSelector(String name, String value); 169 void luaAction(String name); 170 void luaShowLayerBoxPopup(Vector v, String layer); 171 void luaLayerAction(String name, String layer); 172 void luaAbsoluteButton(const char *s); 173 174 void buildMenus(); 175 void showInCombo(const Cascade *sheet, Kind kind, 176 int sel, const char *deflt = nullptr); 177 void showMarksInCombo(const Cascade *sheet); 178 void setAttribute(int sel, Attribute a); 179 180 int ipeIcon(String action); 181 182 protected: 183 lua_State *L; 184 int iModel; // reference to Lua model 185 186 MENUHANDLE iRecentFileMenu; 187 MENUHANDLE iSelectLayerMenu; 188 MENUHANDLE iMoveToLayerMenu; 189 MENUHANDLE iTextStyleMenu; 190 MENUHANDLE iLabelStyleMenu; 191 MENUHANDLE iGridSizeMenu; 192 MENUHANDLE iAngleSizeMenu; 193 194 Cascade *iCascade; 195 AllAttributes iAll; // current settings in UI 196 std::vector<String> iComboContents[EUiView]; 197 198 CanvasBase *iCanvas; 199 200 int iWidthNotesBookmarks; 201 std::vector<int> iScalings; 202 String iCoordinatesFormat; 203 int iMouseIn; 204 double iMouseFactor; 205 int iUiScale; 206 int iToolbarScale; 207 int iUiGap; 208 bool isMiniEdit; 209 bool iLeftDockFloats; 210 bool isInkMode; 211 212 std::unique_ptr<Document> ipeIcons; 213 std::unique_ptr<Document> ipeIconsDark; 214 }; 215 216 // -------------------------------------------------------------------- 217 #endif 218