1 // -*- C++ -*-
2 // --------------------------------------------------------------------
3 // Ipelets
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 IPELET_H
33 #define IPELET_H
34 
35 #include "ipebase.h"
36 #include "ipeattributes.h"
37 #include "ipesnap.h"
38 
39 #ifdef __MINGW32__
40 #define IPELET_DECLARE extern "C" __declspec(dllexport)
41 #else
42 #define IPELET_DECLARE extern "C"
43 #endif
44 
45 // --------------------------------------------------------------------
46 
47 namespace ipe {
48 
49   class Page;
50   class Document;
51 
52   class IpeletHelper {
53   public:
54     enum { EOkButton, EOkCancelButtons, EYesNoCancelButtons,
55 	   EDiscardCancelButtons, ESaveDiscardCancelButtons };
56     virtual ~IpeletHelper() = 0;
57     //! Show a message in the status bar.
58     virtual void message(const char *msg) = 0;
59     //! Pop up a modal message box.
60     /*! The \a details can be null.
61 
62       Choose one of EOkButton, EOkCancelButtons, EYesNoCancelButtons,
63       EDiscardCancelButtons, ESaveDiscardCancelButtons
64       for \a buttons.
65 
66       Returns 1 for Ok or Yes, 0 for No, -1 for Cancel. */
67     virtual int messageBox(const char *text, const char *details,
68 			   int buttons) = 0;
69     /*! Pop up a modal dialog asking the user to enter a string.
70       Returns true if the user didn't cancel the dialog. */
71     virtual bool getString(const char *prompt, String &str) = 0;
72 
73     /*! Retrieve a parameter value from a table in the Lua wrapper
74       code.  If no table has been passed, or the key is not in the
75       table, or its value is not a string or a number, then an empty
76       string is returned. */
77     virtual String getParameter(const char *key) = 0;
78   };
79 
80   //! Information provided to an ipelet when it is run.
81   struct IpeletData {
82     Page *iPage;
83     const Document *iDoc;
84     int iPageNo, iView, iLayer;
85     AllAttributes iAttributes;
86     Snap iSnap;
87   };
88 
89   // --------------------------------------------------------------------
90 
91   class Ipelet {
92   public:
93     virtual ~Ipelet() = 0;
94     //! Return the version of Ipelib the Ipelet was linked against.
95     virtual int ipelibVersion() const = 0;
96     //! Run a function from the Ipelet.
97     /*! Return true if page was changed and undo registration is necessary. */
98     virtual bool run(int function, IpeletData *data, IpeletHelper *helper) = 0;
99   };
100 
101 } // namespace
102 
103 // --------------------------------------------------------------------
104 #endif
105