[Mono-osx] 3 cross-platform questions

Mac Programmer MacPgmr at fastermac.net
Wed Feb 25 23:03:54 EST 2009


> Mac Programmer a écrit :
>
> > (1) How does one create a true cross-platform custom control,  
> meaning
> >  a control that functions both with WinForms and Cocoa?
>
> As others have tried and discovered, you really can't.
>
> > It appears as though in the .Net world most custom controls are
> > UserControl descendants, which would apparently mean that the custom
> > control is WinForms-only. Is there some other way?
>
> Since UserControl relies entirely on the Win32 APIs to draw  
> themselves,
> and Cocoa has its own way of "talking to the metal", I would say  
> that it
> is highly unlikely.
>
> If you then consider that the Cocoa UI is so much more  
> sophisticated in
> the facilities it provides, with things like Core Animation, you would
> have to ask how would you include the functionality of one  
> framework in
> a control based on the other?

Actually, that's what WinForms on Mac does, calling functions in the  
Carbon framework, so I don't know why it would be any different with  
Cocoa.

But really, if cross-platform custom controls are not the norm, how  
then is Mono a useful cross-platform tool? Most of my projects  
involve custom controls, but if using them means WinForms, then Mono  
starts looking more like a Windows emulator and maybe it would make  
more sense to tell users just to get Windows and run the real thing.


>  From the start, Windows RAD design tools have always "encouraged" the
> writing of all your code in the form class.

Not sure I would assign even a small part of the blame on RAD tools  
like Delphi. It's pretty easy to prevent this from happening. Just  
include a requirement for a project that says something like "Core  
functionality/calculating engine/whatever must also be available to  
use in a console app, DLL, COM Automation server, Web app (pick any  
one)". That will pretty much sever the head from the body.


> The Controller class will only resemble Winforms classes if you are  
> used
> to writing your event handlers on the form class. We have been  
> using the
> MVP pattern, in C#, for a number of years now and our forms are purely
> visual design, there is absolutely no interaction code in the form
> classes; that is taken care of by the Presenter and Interactor classes
> that are part of our frameworks.

Here's some nib-less code that creates the controls rather than  
nibbing them out of the ether.

type
   MainForm = class(Cocoa.Object)
   private
     mainWindow : Cocoa.Window;
     button1 : Cocoa.Button;

     method button1_Click(sender: System.Object; e: System.EventArgs);
   public
     method InitializeComponent;
   end;


implementation


method MainForm.InitializeComponent;
begin
   mainWindow := new Cocoa.Window(new Cocoa.Rect(200, 200, 400, 300),
                                  WindowStyle.Resizable or
                                  WindowStyle.Closable or
                                  WindowStyle.Titled,
                                  BackingStoreType.Buffered, True);
   mainWindow.Title := 'Hey, there!';

   button1 := new Cocoa.Button(new Cocoa.Rect(200, 20, 82, 32));
   button1.BezelStyle := BezelStyle.Rounded;
   button1.Title := 'Blank';
   button1.Action += new System.EventHandler(button1_Click);

   mainWindow.View.AddSubView(button1);
   mainWindow.Show();
end;


method MainForm.button1_Click(sender: System.Object; e:  
System.EventArgs);
begin
   button1.Title := 'Pushed';
end;


Thanks.

-Phil

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-osx/attachments/20090225/a8a86ef7/attachment.html 


More information about the Mono-osx mailing list