Adding a new interface
From Lazarus-ccr
This article describes the steps to add a new widgetset interface. This article is intended for developers who want to make an existing widget set available for use with the LCL. It describes the first steps to set up the directories and adapt the IDE for developing the new interface.
Contents |
[edit] Other Interfaces
- Lazarus known issues (things that will never be fixed) - A list of interface compatibility issues
- Win32/64 Interface - The winapi interface for Windows 95/98/Me/2K/XP/Vista, but not CE
- GTK1 Interface - The gtk1 for Unixes, Mac OS X, Windows
- GTK2 Interface - The gtk2 for Unixes, Mac OS X, Windows
- Carbon Interface - The Carbon Interface for Mac OS X
- Qt Interface - The Qt 4 Interface for Unixes, Mac OS X and linux-based PDAs
- Windows CE Interface - For Pocket PC and Smartphones
- fpGUI Interface - A widgetset completely written in Object Pascal
- Cocoa Interface - The Cocoa Interface for Mac OS X
[edit] Platform specific Tips
- OS X Programming Tips - Lazarus installation, useful tools, Unix commands, and more...
- WinCE Programming Tips - Using the telephone API, sending SMSes, and more...
- Windows Programming Tips - Desktop Windows programming tips.
[edit] Interfaces Development Articles
- Carbon interface internals - If you want to help improving the Carbon interface
- Windows CE Development Notes - For Pocket PC and Smartphones
- Adding a new interface - How to add a new widget set interface
- LCL Defines - Choosing the right options to recompile LCL
[edit] Steps
As example we write the steps for adding a new interface for the pogo widget set.
[edit] Register the new widgetset in the IDE
Add 'pogo' to ide/lazconf.pp. In the file lcl/interfacebase.pp add lppogo to TLCLPlatform add 'pogo' to LCLPlatformDirNames. In ide/compileroptions.pp add an entry to LCLWidgetLinkerAddition.
Then rebuild the IDE with the LCL and restart it. You should now see the new wigdetset in the 'Configure build lazarus' dialog. Now the codetools know about it and basic code functions will work.
[edit] Create a directory for the interface
Create a subdirectory pogo in lazarus\lcl\interface.
Then copy the Makefile.fpc from one of the existing widgetsets and adapt it. For example change the unittargetdir. Then create the Makefile with Fpcmake:
For *nix:
cd lazarus/lcl/interfaces/pogo export FPCDIR=/home/username/fpc_sources_2.3/ fpcmake -Tall export FPCDIR=
For windows:
cd lazarus\lcl\interfaces\pogo set FPCDIR=lazarus\fpc\source lazarus\fpc\2.3.1\bin\i386-win32\fpcmake -Tall set FPCDIR=
You must use fpcmake from the latest and greatest and unstable FPC version, so that all FPC platforms are known in the Makefile. For the source it is less critical. The last line sets the variable FPCDIR to none. Otherwise other Makefiles will be auto regenerated too, which can accidently break things. So better make sure with the last line that FPCDIR is not set.
Then copy the interfaces.pp from one of the other widgetsets and adapt it. For example rename the widgetset class to TPogoWidgetSet.
Then create a first unit pogoint.pp for the new class TPogoWidgetSet. Every widgetset needs to override some abstract methods. Position the blinking cursor on class and use the refactoring tool Source Editor / Popup menu / Refactoring / Show abstract methods to automatically add the method stubs. Don't forget to use pogoint in the new interfaces.pp.
[edit] Update Makefiles
Edit lazarus\lcl\interfaces\Makefile.fpc and append pogo to the Target directories
[target] dirs=gtk gtk2 win32 wince qt carbon fpgui pogo
Generate the Makefile in lazarus\lcl\interfaces using Fpcmake.
You can now compile your new widgetset in the IDE, by setting the widgetset in the 'Configure build lazarus' dialog.
[edit] Compiler options / search paths
If the new widgetset has subdirectories or need some extra flags, then these must be added to the Makefile (e.g. lcl/interfaces/pogo/Makefile) and to the codetools components/codetools/definetemplates.pas in method TDefinePool.CreateLazarusSrcTemplate. Search for lcl/interfaces/gtk and see there for some examples. Otherwise: ask Mattias via mail.
