Recent

Author Topic: interface builder?  (Read 12451 times)

Jo

  • Jr. Member
  • **
  • Posts: 63
    • http://www.taomedic.com
interface builder?
« on: March 23, 2008, 04:20:09 pm »
Is there a way to build the gui using interface builder then connect it to lazarus/fpc code?

Phil

  • Hero Member
  • *****
  • Posts: 2750
Re: interface builder?
« Reply #1 on: March 23, 2008, 04:30:06 pm »
Quote from: "Jo"
Is there a way to build the gui using interface builder then connect it to lazarus/fpc code?


There used to be an Xcode integration kit for adding the FPC compiler to the Xcode IDE, but it doesn't appear as though it's being maintained anymore:

http://www.pascal-central.com/fp-xcode/index.html

Is there something in Xcode that you need that's not available through the Lazarus IDE?

Thanks.

-Phil

Jo

  • Jr. Member
  • **
  • Posts: 63
    • http://www.taomedic.com
RE: Re: interface builder?
« Reply #2 on: March 23, 2008, 05:23:23 pm »
Thanks I’ll check it out.

Although a tremendous work is being done in Lazarus, several components are still missing or lacking some features, mainly visually. For example, buttons don’t match the current look (no control over round edges, the color is not right (for both clicked & unclicked states), the gradient is not exactly it, shadow is not the same – so the overall feeling is of something not quite macish. Same for all sorts of gradients. Same for the rectangular style toolbar (top or buttom) with gradient and controls that you can minimize/maximize with toolbar control in the title bar - almost a must for current mac apps. The left sidebar (source list) is extremely important feature. Some other controls don’t (yet) have the mac look (like treeview) etc. So basically I can create an app that work and looks ok (depends on the gui features needed) but not really top of the line app. So if it would be possible to have a first-class gui with interfacebuilder and fpc for functionality this would help. Although, of course, a complete lazarus ide component functionality would be preferred.

Btw, I’m using leopard 10.5.2 & Lazarus 9.25 snapshot.

Phil

  • Hero Member
  • *****
  • Posts: 2750
Re: RE: Re: interface builder?
« Reply #3 on: March 23, 2008, 06:06:56 pm »
Quote from: "Jo"
so the overall feeling is of something not quite macish.


Sounds like you have the true Mac aesthetic eye. Considering that many of the Lazarus developers are working primarily in the lower-case Linux world, the project could certainly use somebody like you.

You might look at  TCarbonButton.CreateWidget and TCarbonBitBtn.CreateWidget in carbonbuttons.pp to see how Tomas implemented TButton and TBitBtn, then review the Apple docs to see if there are options available with the Carbon calls he's using for fine tuning the aesthetic aspects of buttons. Remember that currently the only things that can be fine tuned at the Lazarus IDE level are button properties in the LCL, so not all Carbon settings may be adjustable in the IDE.

I started porting a 120,000 line component to Lazarus and Carbon last July and working with Tomas it's amazing how far he was able to advance the Carbon widgetset by the end of the year. Certainly for as new a codebase as the Carbon widgetset is, there will be things that eventually will need to be adjusted. If you can help with that, we would all greatly appreciate it.

I've tried working with Xcode on several occasions, but it seems as though there is so much that one has to learn almost simultaneously that I never got very far (Obj C, .nib files, etc., etc.). Whereas coming from Delphi, Lazarus felt very familiar to me. The other issue with Xcode is that it's single platform, meaning you would need two distinct codebases if you wanted your app to be cross platform. That approach doesn't interest me at all.

One question that remains unanswered, I suppose, is whether it's even possible to create a first-class Mac app using non-Apple tools. Certainly FPC and Laz are using lots of Apple API's and tools like the linker, but Apple really wants developers to use Xcode, even though it's an Apple only tool.

Thanks.

-Phil

Jo

  • Jr. Member
  • **
  • Posts: 63
    • http://www.taomedic.com
RE: Re: RE: Re: interface builder?
« Reply #4 on: March 23, 2008, 10:05:23 pm »
I come from the Delphi/windows world. I like the way the Mac looks and operate but I only started using it last week. So I guess I can’t be of much help.

Up to now the Apple developer tools, although look good in themselves from one angle, give me the impression of a horror show. Therefore checking Lazarus again it was a pleasant surprise to see the progress you’ve made into the carbon world (and we should probably get prepared for the cocoa world…).

I did look at the sources and it seems pretty easy to get the up-to-date buttons look, there is only a need to set their appearance property.  For example, setting it to kThemePushButtonNormal will immediately give it a more current look. Having a property for choosing from the over the 20 options in the carbon buttons kinds will cover it all.

Having the right buttons, panel, and sidebar, and maybe an alternating color for the stringgrid lines, I think we will be able to get over 90% of the mac look in every application. Another option would be to bridge the InterfaceBuilder to fpc which would give the best look with a reasonable programming language.

Anyway, thanks for the help.

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2514
    • havefunsoft.com
RE: Re: RE: Re: interface builder?
« Reply #5 on: March 23, 2008, 10:07:28 pm »
I think the problem is with backward compability.The application written for Linux and/or Windows should have the same behavior on any system, including Mac OS. LCL also aimed to be like VCL, so it's a quite a problem to use specific features of GUIs different to the Windows.
For example, VCL idea (and supported by LCL) is that application must close if it's main window is closed. But in Mac OS there's no main window, and if all windows of application is closed the application itself is still active (and it's Main Menu is accessable).
Another problem is hot-keys! Especially with Mac, as it uses 4 system keys (ctrl, alt, shift and cmd), rather that 3 system keys in Windows (ctrl, alt, shift). Switching between tabs in Delphi and Lazarus is ctrl-tab, ctrl-shift-tab. Ported to the Mac OS, ctrl key is replaced with pressing command (win) key, so to switch between tabs one have to press cmd-tab (cmd-shift-tab). But this is also MacOS  application switch hot-key!... to solve this problem, I've modified carbon widgetset units, so ctrl is now treated as ctrl, and I'm happy :)
Focus switching also works different from original Mac OS. Just to make it for the same on any platform.

I think Lazarus and LCL is great thing! Though a lot of work should be done to make it perfect. Currently Lazarus is the only developing tool that allow cross-platform GUI development.

Back to topic:
Yes, It's possible to write applications using Interface Builder. That's exactly what i'm doing.
(I use LCL only to create tools for myself, as for products I'm using FPCMacOSALL unit ;) and some kind of my of my own component library. It's also excellent way to learn Carbon and Mac OS.
If you try to use a link given by Phil, there's a good sample of using Interface Builder and nib files. You can do the same with lazarus.

Start a new 'Custom program'. Use FPCMacOSALL, so Interface Builder functions would be available to you. You'll need to open nib file, and create Menu and Window (if any) with functions provided here: http://developer.apple.com/documentation/Carbon/Reference/Interface_Builder/Reference/reference.html
Menu and Window would be returned to you as handles, so you'll have to assign this handles to the LCL objects, that you should create manually.

Also you'll need create a bundle, and to place a hard link to (or copy) your executable, and place nib file to the resources folder...

I think a code sample would be better than explanation (in bad english =)) do you need it?

Btw: The only Xcode-developing advantage is fully working debugger.
Patron Cocoa Widgetset development https://www.patreon.com/skalogryz

Jo

  • Jr. Member
  • **
  • Posts: 63
    • http://www.taomedic.com
RE: Re: RE: Re: interface builder?
« Reply #6 on: March 23, 2008, 10:24:45 pm »
This sounds like a good option. Your point about learning to use carbon and mac is a good one too. I will be happy for any help; if you have examples/tutorials/whatever it will be great.

Phil

  • Hero Member
  • *****
  • Posts: 2750
Re: RE: Re: RE: Re: interface builder?
« Reply #7 on: March 23, 2008, 10:51:46 pm »
Quote from: "Jo"
I come from the Delphi/windows world. I like the way the Mac looks and operate but I only started using it last week. So I guess I can’t be of much help.

Having the right buttons, panel, and sidebar, and maybe an alternating color for the stringgrid lines, I think we will be able to get over 90% of the mac look in every application. Another option would be to bridge the InterfaceBuilder to fpc which would give the best look with a reasonable programming language.


I tried this tutorial with Xcode and couldn't even get it to compile:

http://cocoadevcentral.com/d/learn_cocoa/tiger/

I maintain a single codebase for my cross-platform apps that can be compiled with Delphi or Lazarus. The toollkit I developed for doing that is here:

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

If you're interested in a more advanced grid control, you might take a look at the TOvcTable control here:

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

TOvcTable has an OnGetCellAttributes event that allows you to change the color, etc of individual cells, etc. That would work for alternating row colors. Note that TOvcTable isn't working perfectly yet on all platforms with Lazarus, but if you want to help out...

Thanks.

-Phil

Phil

  • Hero Member
  • *****
  • Posts: 2750
Re: RE: Re: RE: Re: interface builder?
« Reply #8 on: March 23, 2008, 11:05:02 pm »
Quote from: "skalogryyz"
I think the problem is with backward compability.The application written for Linux and/or Windows should have the same behavior on any system, including Mac OS.

Uh, that's not quite right. Since LCL implementations use native controls for the most part, these will have native behavior and look.

Quote from: "skalogryyz"
For example, VCL idea (and supported by LCL) is that application must close if it's main window is closed. But in Mac OS there's no main window, and if all windows of application is closed the application itself is still active (and it's Main Menu is accessable).

Are you saying it should be like that? Currently, closing the main window of a Carbon app created with Laz quits the app.

Quote from: "skalogryyz"
Back to topic:
Yes, It's possible to write applications using Interface Builder. That's exactly what i'm doing.
(I use LCL only to create tools for myself, as for products I'm using FPCMacOSALL unit ;) and some kind of my of my own component library. It's also excellent way to learn Carbon and Mac OS.
If you try to use a link given by Phil, there's a good sample of using Interface Builder and nib files. You can do the same with lazarus.

I've often wondered if it would make sense to have a converter that would take a Delphi/Lazarus .dfm/.lfm form and convert it to .nib files. Then with FPC support in Xcode to write the event handling code in Pascal. The problem is each time I try to understand the Xcode approach I lose interest pretty quick.

Thanks.

-Phil

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2514
    • havefunsoft.com
Re: RE: Re: RE: Re: interface builder?
« Reply #9 on: March 24, 2008, 12:05:02 am »
Quote from: "Phil"
Uh, that's not quite right. Since LCL implementations use native controls for the most part, these will have native behavior and look.

Yeah, and most of controls do have native behavior, but there always some little difference can be found.

I can't remember exactly right now but here's the difference between Mac OS and Win/Nix tab sheet using.
When tab get's a focus (not content of the tab), you can Tab switch between tabs using arrows.
In win/nix GUI content of the tab would also switch if you select another tab by arrows.
But in Mac Os tab content would remain at last opened, until you press space bar to open the selected tab...
I just don't remember if this is supported by LCL.  

Btw: Phil, have you extended native tab, by adding navigation arrows for Lazarus code editor? Wonderful solution!!!

MacOS have a lot of GUI conflicts between Carbon and Cocoa.
Try to create a Window (or Application?)  using Interface Builder one for Cocoa, and one for Carbon. Place a  single radio group control on each window. And this radio groups would behave differently for carbon and cocoa. You can 'test interface' directly from IB, so you won't need to create an XCode project.

for carbon, each item can be switched by tab only, and would be checked only if you press space.
for cocoa, items can be navigated by arrow keys, and item is autochecked then focused (as it would behave in Win/Nix)

I'm not sure if LCL should care about this bugs.

Quote from: "skalogryyz"
For example, VCL idea (and supported by LCL) is that application must close if it's main window is closed. But in Mac OS there's no main window, and if all windows of application is closed the application itself is still active (and it's Main Menu is accessable).


Quote from: "Phil"

Are you saying it should be like that? Currently, closing the main window of a Carbon app created with Laz quits the app.

Well, I think it's natural for Mac OS users to close all windows of application, and be able to start open new one. I'm not sure if this should be implemented, or even if it is possible to implemend. I think, a lot of programs use main form creation (destruction) to initialize (free) some global variables, data, structures etc...

Quote from: "Phil"

I've often wondered if it would make sense to have a converter that
would take a Delphi/Lazarus .dfm/.lfm form and convert it to .nib files.

.lfm (.dfm) is the best!   :D
Patron Cocoa Widgetset development https://www.patreon.com/skalogryz

Phil

  • Hero Member
  • *****
  • Posts: 2750
Re: RE: Re: RE: Re: interface builder?
« Reply #10 on: March 24, 2008, 12:22:39 am »
Quote from: "skalogryyz"
Btw: Phil, have you extended native tab, by adding navigation arrows for Lazarus code editor? Wonderful solution!!!


No, Tomas made that improvement. I haven't worked on the IDE at all.

Thanks.

-Phil

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2514
    • havefunsoft.com
Re: RE: Re: RE: Re: interface builder?
« Reply #11 on: March 24, 2008, 01:57:41 pm »
Quote from: "Phil"

No, Tomas made that improvement. I haven't worked on the IDE at all.

Tomas, thanks so much!

Jo: I've posted a tutorial here. I'd love someone to edit it, so it would sound more English :)
http://wiki.lazarus.freepascal.org/FPC_and_Carbon#Carbon_Tutorial
also if you have any questions feel free to ask.
Patron Cocoa Widgetset development https://www.patreon.com/skalogryz

Jo

  • Jr. Member
  • **
  • Posts: 63
    • http://www.taomedic.com
interface builder?
« Reply #12 on: March 24, 2008, 02:50:46 pm »
Thanks! It was very simple and tested ok. Can you give an example with firing events too, say a button click implementation?

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2514
    • havefunsoft.com
interface builder?
« Reply #13 on: March 24, 2008, 04:10:54 pm »
Well, first of all, you should open main.nib file again and add a button.
(You can edit .nib file from the bundle directly, so you won't need to copy);
Then you add the button, select it by clicking a mouse on it. Open Inspector (shift-cmd-I) and find there button signature and id is defined.
Set signature to 'AAAA' and id to 1. We will use it lately to access the button in runtime.
Save .nib file and return to the code.

You should change the code to the given below. Build project (don't forget to copy if you need to) and run.
If you done everything correctly, the window caption changes to 'Hello Click' if you press the button.

Code: [Select]

{$mode objfpc}{$H+}

uses
  FPCMacOSAll;

var
  err     : OSStatus;
  nibRef  : IBNibRef = nil;
  window  : WindowRef = nil;
 
  btn     : ControlRef = nil;
  handler : EventHandlerRef = nil;
 
const
  //FOUR_CHAR_CODE should be used, to convert strings to LongWord ids
  BUTTON_SIGN = $41414141; // AAAA, is used for simplicity
  BUTTON_ID   = 1;

function InstallEventHandlerForTarget(ATarget: EventTargetRef;
  EventClass, EventKind: LongWord; EventProc: EventHandlerProcPtr): EventHandlerRef;
var
  upp  :  EventHandlerUpp;
  spec  : EventTypeSpec;
begin
  // upp is the common way to use callbacks with in Mac OS
  // remember, that you should dispose upp as soon as you don't need
  // the callback. this is not shown in the sample
  upp := NewEventHandlerUpp(EventProc);

  // every event is defined by it's kind and it's class
  spec.eventClass := EventClass;
  spec.eventKind := EventKind;
 
  // installing the a event handling proc to the control for the specified event
  if InstallEventHandler(ATarget, upp, 1, @spec, nil, @Result) <> noErr  then
    Result := nil;
end;

function OnClickEvent(inHandlerCallRef: EventHandlerCallRef;  inEvent: EventRef;
  inUserData: Pointer): Integer; mwpascal;
begin
  try
    // should call next (default) event handler, so button can beatufully redraw itself
    CallNextEventHandler(inHandlerCallRef, inEvent);
   
    Result := 0;
    // Change the window caption
    SetWindowTitleWithCFString(window, CFSTR('Hello Click'));
  except
     // if any exception is not handled within event handling proc
     // MacOS will never callback this proc again!
  end;
end;

procedure InstallButtonHandler;
var
  ctrlId  : ControlID;
begin
  // one of the ways, is find the placed button on the window by its signature and ID
  // button control must have it's name and id properly set.
  ctrlID.signature := BUTTON_SIGN;
  ctrlID.id := BUTTON_ID;
  if GetControlByID(window, ctrlID, btn) <> noErr then Exit;
 
  // trying to install a handler proc for the button (that is defined by it's event target)
  // kEventClassControl, kEventControlOnClick is the event definition that
  // we want to handle.
  handler := InstallEventHandlerForTarget( GetControlEventTarget(btn),
    kEventClassControl, kEventControlClick, @OnClickEvent);
end;
 

begin
  err := noErr;
  try
    err := CreateNibReference(CFSTR('main'), nibRef);
    if err <> noErr then  Exit;

    err := SetMenuBarFromNib(nibRef, CFSTR('MainMenu'));
    if err <> noErr then Exit;

    err := CreateWindowFromNib(nibRef, CFSTR('Window'), window);
    if err <> noErr then Exit;

  finally
    if err <> noErr then writeln(err);
    DisposeNibReference(nibRef);
  end;

  try
    ShowWindow(window);
    InstallButtonHandler;
    RunApplicationEventLoop;
  finally
    // you should not release btn handle, as it would be done automatically
    // but you should release event handler, beacuse you've created it
    if Assigned(handler) then  RemoveEventHandler(handler);
  end;
end.


Please review to the following links. Basic knowledge of C is required.

for handling events:
http://developer.apple.com/documentation/Carbon/Conceptual/Carbon_Event_Manager/Intro/chapter_1_section_1.html

for handling newer controls:
http://developer.apple.com/documentation/Carbon/Conceptual/HIViewDoc/Introduction/chapter_1_section_1.html

for handling basic controls:
http://developer.apple.com/documentation/Carbon/Conceptual/Carbon_Event_Manager/Intro/chapter_1_section_1.html

IMHO: Apple documentation is much better than Microsoft's MSDN. A lot of good samples are available, and explanations are really great!
Patron Cocoa Widgetset development https://www.patreon.com/skalogryz

Jo

  • Jr. Member
  • **
  • Posts: 63
    • http://www.taomedic.com
interface builder?
« Reply #14 on: March 25, 2008, 11:08:22 pm »
Spasibo bolshoye.
Is there a way to do it visually or it has to be done all in code?
Also, is there a way to combine few pages with IB and few pages from lazarus in one app?

 

TinyPortal © 2005-2018