10 Troubleshooting the LaTeX-conversionTop8 Page views9 Writing ipelets

9 Writing ipelets

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 NewIpelet that creates an object derived from the class Ipelet (defined in ipelet.h). Here is minimal ipelet implementation:

#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;
}
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 IpeHelper 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 IpeHelper, 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.

The Ipelib documentation in HTML-format is here. You may want to have a look at the standard ipelets. Kgon, for instance, is a minimal ipelet that you can use as the basis for your own development. Goodies is an example of an ipelet that contains more than one function--it also needs to implement the member functions NumFunctions and SubLabel. Note that it is possible for ipelets to define keyboard shortcuts (the Align 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.

Compiling ipelets on Windows

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 -mno-cygwin option (it didn't always work for me--please let me know if you find out why).

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:

  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
Place the resulting kgon.dll in the ipelets subdirectory, and restart Ipe.

Compiling ipelets on Unix

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.
10 Troubleshooting the LaTeX-conversionTop8 Page views9 Writing ipelets