Lazarus

Programming => Widgetset => Carbon => Topic started by: Hansaplast on January 26, 2011, 07:30:59 am

Title: How do I create a form to show up as a dialog seen with other Mac apps?
Post by: Hansaplast on January 26, 2011, 07:30:59 am
Not sure if I can explain this properly;

With quite a few applications (probably best know when installing an application on a Mac, and you have to "agree" to the EULA) you see a dialog form appear right under the title bar of your application (without having it's own title bar).

How can I do this in Lazarus?
Is there a certain setting for form style? border style? etc?

(see attachment for an example)
Title: Re: How do I create a form to show up as a dialog seen with other Mac apps?
Post by: IndianaJones on January 26, 2011, 07:38:21 am

Have a look at the PackageMaker tool, which is available when install the Apple Developer Package.
thanks.
Title: Re: How do I create a form to show up as a dialog seen with other Mac apps?
Post by: Phil on January 26, 2011, 04:05:38 pm
With quite a few applications (probably best know when installing an application on a Mac, and you have to "agree" to the EULA) you see a dialog form appear right under the title bar of your application (without having it's own title bar).

That's a modal sheet. Most Mac apps use modal sheets instead of popup modal dialogs because sheets are document modal, rather than application modal. You can do sheets with Cocoa, but I don't know about Carbon. In any case, you can't do sheets with LCL.

More info here:

http://web.me.com/macpgmr/ObjP/MacXPlatform_Part8.html#Dialogs

Thanks.

-Phil
Title: Re: How do I create a form to show up as a dialog seen with other Mac apps?
Post by: Hansaplast on January 26, 2011, 05:52:12 pm
@IndianaJones: I'm not looking for a package maker, I'm trying to get this type of dialog in my regular application.


@Phil: thanks again for the insight ... arg, I wish it would have been easier :)
I'd like to avoid using non LCL calls ... for the purpose of portability ...
Title: Re: How do I create a form to show up as a dialog seen with other Mac apps?
Post by: Phil on January 26, 2011, 07:37:03 pm
@Phil: thanks again for the insight ... arg, I wish it would have been easier :)
I'd like to avoid using non LCL calls ... for the purpose of portability ...

You're now starting to see the limits of "cross-platform": the more code and skill reuse you try for, the more compromises you have to make, particularly on Mac.

Thanks.

-Phil
Title: Re: How do I create a form to show up as a dialog seen with other Mac apps?
Post by: Hansaplast on January 27, 2011, 03:34:45 am
Yeah, I figured that there would be limitations, but so far I can't really complain too much :)
I think Lazarus/FPC is great  8)
I can use my Delphi experience, in a programming language that I really like, and the few little tools I create can be used on at least 3 platforms if I pay enough attention - and I think it's worth it :)

I hope one of these days I can contribute more than just finding "issues" and bugs ;)
Title: Re: How do I create a form to show up as a dialog seen with other Mac apps?
Post by: Hansaplast on January 27, 2011, 05:42:47 am
I figured I'll mimic this behavior by aligning the "form" to the main form, only to find out that the windows function GetSystemMetrics(SM_CYCAPTION) does not seem to return anything useful (0 under carbon?).

So I'm using a trick that "might" work for other platforms as well (probably not as clean as it should be, but it might be helpful to someone);

First I created a form (form2) with borderstyle=bsNone, FormStyle=fsSplash, position=poDesigned - in this form a "busy" indicator.

Next I had quite a challenge determining the titlebar height of the main form (form1), but this trick seems to work ...

1) find a visible object on the main form (form1), say label1 for argument sake. Avoid objects like TPageControl, TGroupBox, etc as they can have an unexpected outcome.

2) Create an onChangeBounds event of the main form (calls this at onShow of the main form at least once to get an initial proper position):

Code: [Select]
procedure Form1.FormChangeBounds(Sender: TObject);
var myPoint:TPoint;
begin
  myPoint := Label1.ClientToScreen(Point(0,0));
  Form2.Top:=myPoint.Y - Label5.Top; // proper alignment, snug under the titlebar
  Form2.Left:=self.Left+(self.Width DIV 2)-(Form2.width DIV 2); // center the form to the main form
end;   
   

Now myPoint.Y gives the absolute position of Label1 (of Form1) on the screen, and we know the top of that object (label1), which is related to the workable area of Form1 -> we now know what Top of Form2 should be :)

Works like a charm ... :)

Edit: This doesn't look all that great in Windows though. Might need to set border style to bsSingle.
Title: Re: How do I create a form to show up as a dialog seen with other Mac apps?
Post by: Hansaplast on January 27, 2011, 08:03:14 pm
@Phil:
Thank you for taking the effort to write http://web.me.com/macpgmr/ObjP/MacXPlatform_Intro.html (http://web.me.com/macpgmr/ObjP/MacXPlatform_Intro.html)
It has been very informative!  :)
Title: Re: How do I create a form to show up as a dialog seen with other Mac apps?
Post by: Phil on January 28, 2011, 03:42:01 am
@Phil:
Thank you for taking the effort to write http://web.me.com/macpgmr/ObjP/MacXPlatform_Intro.html (http://web.me.com/macpgmr/ObjP/MacXPlatform_Intro.html)

You're welcome. The idea was to capture some of what I was discovering. If I didn't write it down, soon I'd forget half of it and then it wouldn't be of much use to anyone, not even to myself.

I would encourage anyone on this forum to write up little articles like this when you discover something that you think others might find interesting or useful. I wouldn't worry about writing it in English if you're not comfortable doing that. Write it in whatever language you have and hope that someone translates it for you.

For example, I wrote this topic on the Laz wiki years ago:

http://wiki.lazarus.freepascal.org/Overview_of_Free_Pascal_and_Lazarus

I'm still in awe at how many times this has been translated (14 by my count). Talk about unsung heroes! To take the time to do that is really commendable.

Anyone can add articles to the wiki. Just keep in mind some of the rough guidelines for any wiki:
 - Don't post someone else's work or copyrighted material.
 - Remember that others might edit your work to improve (or ruin) it.
 - Use a faux-objective writing "voice" like what an encyclopedia uses.
 - Short and sweet is fine.

Thanks.

-Phil
TinyPortal © 2005-2018