File: manual_30.html

package info (click to toggle)
ipe 6.0pre30-5
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 5,100 kB
  • ctags: 5,419
  • sloc: cpp: 30,430; ansic: 1,045; xml: 845; makefile: 78; sh: 5
file content (102 lines) | stat: -rw-r--r-- 5,303 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
   "DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<!-- XML file produced from file: manual.tex
     using Hyperlatex v 2.6 (c) Otfried Cheong
     on Emacs 21.4.1, Sun Dec 24 00:03:23 2006 -->
<head>
<title>Ipe Manual -- 9 Writing ipelets</title>

<style type="text/css">
.maketitle { align : center }
div.abstract { margin-left: 20%; margin-right: 10%; }
h3.abstract  { align : center }
div.verse, div.quote, div.quotation {
  margin-left : 10%; 
  margin-right : 10%;
}
</style>

<meta http-equiv="Content-Type" 
        content="text/html; charset=UTF-8">
</head>
<body bgcolor="#ffffe6">
<table width="100%" cellpadding=0 cellspacing=2><tr><td bgcolor="#99ccff"><a href="manual_31.html"><img border="0" alt="10 Troubleshooting the LaTeX-conversion" src="next.png"></a></td><td bgcolor="#99ccff"><a href="manual.html"><img border="0" alt="Top" src="up.png"></a></td><td bgcolor="#99ccff"><a href="manual_29.html"><img border="0" alt="8 Page views" src="previous.png"></a></td><td align="center" bgcolor="#99ccff" width="100%"><b>9 Writing ipelets</b></td></tr></table>
<h1>9 Writing ipelets</h1>

<p>An ipelet is a dynamically loaded library (DLL), that you place on
Ipe's ipelet search path.  Ipe loads all DLLs it can find on that path
during start-up.  The DLL has to be written in C++, and must export a
function <code>NewIpelet</code> that creates an object derived from the
class <code>Ipelet</code> (defined in <em>ipelet.h</em>).  Here is minimal
ipelet implementation:
<pre>
#include "ipelet.h"

class MyIpelet : public Ipelet {
public:
  virtual int IpelibVersion() const { return IPELIB_VERSION; }
  virtual const char *Label() const { return "My label"; }
  virtual void Run(IpePage *page, IpeletHelper *helper);
};

void MyIpelet::Run(int function, IpePage *page, IpeletHelper *helper)
{
  // this is where you do all the work
}

IPELET_DECLARE Ipelet *NewIpelet()
{
  return new MyIpelet;
}
</pre>
When the ipelet is executed, Ipe hands it a pointer to the current
page of the document.  The ipelet can examine the selected objects,
and modify the page in any way it wishes. It can also request services
from the Ipe application through the <code>IpeHelper</code> object, for
instance to display a message in the status bar, to pop up message
boxes, to obtain input from the user, etc.  Through the
<code>IpeHelper</code>, it is also possible to access the complete document
(for instance to write an ipelet that allows the user to reorganize
the pages of the document), or to access some Ipe settings.
<p>The Ipelib documentation in HTML-format is <a href="index.html">here</a>.  You may want to have a look at
the standard ipelets.  <em>Kgon</em>, for instance, is a minimal ipelet
that you can use as the basis for your own development.
<em>Goodies</em> is an example of an ipelet that contains more than one
function--it also needs to implement the member functions
<code>NumFunctions</code> and <code>SubLabel</code>.  Note that it is possible for
ipelets to define keyboard shortcuts (the <em>Align</em> ipelet does
that, for instance), but in general it is not a good idea to do that
for ipelets you plan to make available for others.

<h4><a name="id1">Compiling ipelets on Windows</a></h4>
The ipelet must be compiled as a DLL and must be linked with the Ipe
library "ipe.dll".  C++ mandates that it must be compiled with the
same compiler that was used to compile Ipe.  If you use the binary Ipe
distribution for Windows, that means you have to use the MinGW
compiler.  (If you haven't used it before: MinGW is a port of g++ for
Windows).  Using g++ under Cygwin may also work with the
<code>-mno-cygwin</code> option (it didn't always work for me--please let
me know if you find out why).
<p>The Ipe Windows distribution contains the necessary header files and
the library to compile ipelets, as well as the source of the "kgon"
and "goodies" ipelets as examples.  To compile the "kgon" example,
open a command shell, make sure MinGW g++ is on your path, and say:
<pre>
  g++ -c -O2 -DWIN32 -fno-exceptions -fno-rtti -Iinclude kgon.cpp
  g++ -Wl,-enable-stdcall-fixup -Wl,-enable-auto-import \
  -Wl,-enable-runtime-pseudo-reloc -Wl,-s -shared -o kgon.dll kgon.o \
  -Llib -lipe
</pre>
Place the resulting <i>kgon.dll</i> in the <i>ipelets</i>
subdirectory, and restart Ipe.

<h4><a name="id2">Compiling ipelets on Unix</a></h4>
The ipelet must be compiled as a shared library and must be linked
with the Ipe library "libipe.so".  C++ mandates that it must be
compiled with the same compiler that was used to compile Ipe.  Have a
look at the ipelet sources in the Ipe source distribution, and their
project files for details on compiling them.
<hr />
<table width="100%" cellpadding=0 cellspacing=2><tr><td bgcolor="#99ccff"><a href="manual_31.html"><img border="0" alt="10 Troubleshooting the LaTeX-conversion" src="next.png"></a></td><td bgcolor="#99ccff"><a href="manual.html"><img border="0" alt="Top" src="up.png"></a></td><td bgcolor="#99ccff"><a href="manual_29.html"><img border="0" alt="8 Page views" src="previous.png"></a></td><td align="center" bgcolor="#99ccff" width="100%"><b>9 Writing ipelets</b></td></tr></table></body></html>