Recent

Author Topic: OpenMotif and Lazarus?  (Read 7088 times)

guest

  • Guest
OpenMotif and Lazarus?
« on: May 31, 2006, 07:40:05 pm »
Is it possible to write a openmotif/motif widget aplication using Lazarus? For example under FreeBSD system?

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
RE: OpenMotif and Lazarus?
« Reply #1 on: May 31, 2006, 10:34:26 pm »
You mean you want to use the form designed to write a motif application, or you just want a pascal software that called motif functions by code?

To write a free pascal software that uses motif, first you need to translate openmotif c headers to pascal. This is easy, only takes some time. Then you can use lazarus to write a pascal program that calls motif functions. If you need help translating the headers, don´t hesitate to ask.

To use the form designer one needs to write a new interface for Lazarus, so you can use Delphi classes (such as TBitmap, TForm, TLabel, etc), and they will be conected to motif by the interface. Before you write the interface you also need to translate the headers to pascal.

There is a tutorial to create a new lazarus interface here:

http://wiki.lazarus.freepascal.org/index.php/LCL_Internals

Anonymous

  • Guest
RE: OpenMotif and Lazarus?
« Reply #2 on: June 01, 2006, 12:14:00 am »
I have never translated headers before but this seems quite hard.

Isn't there any script or program to convert headers automatically?

By the way... Do I need to translate all the headers of the openmotif or only the ones needed?

[ps: sorry, I am a moderator and I mistakenly edited your post instead of writing an answer =( The "edit" button is very close to the "quote" button]

Anonymous

  • Guest
RE: OpenMotif and Lazarus?
« Reply #3 on: June 01, 2006, 12:40:45 am »
Here is an example frame.h from motif. Could someone show me please how to translate this short header to Lazarus (pascal) one?
----------------------------------------------------------------------------------------------------
#ifndef _XmFrame_h
#define _XmFrame_h

#include <Xm/Xm.h>

#ifdef __cplusplus
extern "C" {
#endif

#ifndef XmIsFrame
#define XmIsFrame(w) XtIsSubclass(w, xmFrameWidgetClass)
#endif /* XmIsFrame */

/* Class record constants */

externalref WidgetClass xmFrameWidgetClass;

typedef struct _XmFrameClassRec * XmFrameWidgetClass;
typedef struct _XmFrameRec      * XmFrameWidget;


/********    Public Function Declarations    ********/

extern Widget XmCreateFrame(
                        Widget parent,
                        char *name,
                        ArgList arglist,
                        Cardinal argcount) ;

/********    End Public Function Declarations    ********/


#ifdef __cplusplus
}  /* Close scope of 'extern "C"' declaration which encloses file. */
#endif

#endif /* _XmFrame_h */
/* DON'T ADD ANYTHING AFTER THIS #endif */

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
RE: OpenMotif and Lazarus?
« Reply #4 on: June 01, 2006, 01:17:42 am »
First you need to take a strategical decision here. Will you convert every file into a unit or create one main unit with many include files?

An example a binding with one main unit (in fact two) and many include files is PascalMagick bindings for ImageMagick. You can download it here: http://sourceforge.net/project/showfiles.php?group_id=92177&package_id=174103

It contains both c headers and pascal headers, so you can easely compare them.

Now, is frame.h a main file that should become a unit or just a small include file? Assuming frame.h will become frame.inc (a include file), it would be like this:

//#include <Xm/Xm.h> ----> remember to add Xm unit to the main unit where this file belongs to

{Careful with this macro:

#ifndef XmIsFrame
#define XmIsFrame(w) XtIsSubclass(w, xmFrameWidgetClass)
#endif }

{ Class record constants }

//externalref WidgetClass xmFrameWidgetClass;

type
  XmFrameWidgetClass: ^_XmFrameClassRec;
  XmFrameWidget: ^_XmFrameRec;

{******** Public Function Declarations ********}

function XmCreateFrame(
parent: Widget;
name: PChar;
_arglist: ArgList;
argcount: Cardinal): Widget; cdecl; external MotifExport;

--------------

On the main unit you will need to declare MotifExport:

const
  WandExport = 'libMotif'; // substitute with real lib name

Please take a look at wand/magick_wand.pas on PascalMagick bindings to see how a main unit of a binding looks like. You can also compare it with the equivalente .h file

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
Re: RE: OpenMotif and Lazarus?
« Reply #5 on: June 01, 2006, 01:25:45 am »
> I have never translated headers before but this seems quite hard.

Not really =) After a while it get´s quite easy. Everything is hard on the first time.

> Isn't there any script or program to convert headers automatically?

Yes, a program that comes with Free Pascal called h2pas can convert headers. But my personal experience was that it didn´t work to me due to macros, strange ways to declare things it cannot understand, etc.

> By the way... Do I need to translate all the headers of the openmotif or only the ones needed?

Only the ones you need, but try to make it extensible. Just coment things you don´t want to convert so someone can convert them on the future. And try to keep things in the same order as on the c files so in the future someone can add missing things more easely.

Marc

  • Administrator
  • Hero Member
  • *
  • Posts: 2674
RE: Re: RE: OpenMotif and Lazarus?
« Reply #6 on: June 01, 2006, 12:32:52 pm »
there are also some conversion tools which convert headers in one go.
If you translater the motif (or lesstif?) headers then they can maybe added to the fpc packages.
Ask the fpc-devel mailinglist for more info on how to convert.
//--
{$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
RE: Re: RE: OpenMotif and Lazarus?
« Reply #7 on: June 02, 2006, 02:12:35 am »
As an extra information, here is a guide about importing c libraries on pascal software:

http://www.drbob42.com/delphi/headconv.htm

Can be very useful.

Mathias

  • Full Member
  • ***
  • Posts: 101
Re: OpenMotif and Lazarus?
« Reply #8 on: April 02, 2023, 06:10:26 pm »
I know the post is a bit old, but it still belongs here.

I took the trouble and translated Openmotif. Today I translated the last header.
I just wanted to try and see if I could translate a library of headers.

I think it will still have bugs for sure, but it just got finished today.

If you want, you can try it out, simply install the following package. The Athena widgets are also included.

https://github.com/sechshelme/Lazarus-Motif_Athena_Widget

https://github.com/sechshelme/Lazarus-Motif_Athena_Widget/tree/main/Motif_Athena_Package

 

TinyPortal © 2005-2018