discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Renaissance Questions


From: Nicola Pero
Subject: Re: Renaissance Questions
Date: Wed, 4 Feb 2009 13:14:37 +0100

Hi Fred

there are various ways to do this. :-)

I agree with you that trying to call '[[[self window] contentView] rotateByAngle: 20.0]' directly from the .gsmarkup won't work because of the 20.0 argument which you can't really pass. :-)

So, you need to do that call in your own code. Then you want to reference/connect some of the objects in your .gsmarkup file to objects in your code. And, as I said, there are various ways to do it.

First of all, when you load the .gsmarkup file that creates the window, you get the chance of passing an object from your code as the 'NSOwner' of the file. Eg, if you check the Calculator example in
Renaissance, this is done by loading the file with the call

@implementation Calculator

...

- (void)applicationDidFinishLaunching: (NSNotification *)aNotification
{
  [NSBundle loadGSMarkupNamed: @"Calculator"  owner: self];

  ...
}

...

@end

so, when the Calculator object loads the Calculator.gsmarkup file, it sets the NSOwner to self (itself).

And that now allows you to connect things easily. Inside Calculator.gsmarkup, you can reference the NSOwner using the syntax #NSOwner. For example, the button '3' of the Calculator is created
as in

          <button title="*" tag="3" keyEquivalent="*" padding="1"
action="operation:" target="#NSOwner" halign="wexpand" />

notice the target="#NSOwner". This means that when you press the button, the action 'operation:'
of the #NSOwner is called, ie, the button calls

 [#NSOwner operation: self];

because #NSOwner is an object implemented in code (the Calculator object), you then control what happens. Notice the argument, which is the button that called the method. Inside Calculator,
we have the method

-(void) operation: (id)sender
{
   ...
}

that gets called when the button is clicked, and has access to the button as the 'sender' object. :-)

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

OK - so now back to your problem :-)

When you load your .gsmarkup, attach an owner to it - an object of a class that you have implemented.
Ie,

[NSBundle loadGSMarkupNamed: @"{MyFile}" owner: {anObjectOfMyClass}];

Then, set the button to call an action from the owner, which is your object:

 <button action="rotateView:" target="#NSOwner" />

inside your owner object, implement rotateView:

@implementation {MyClass}

- (void) rotateView: (id)sender
{
  /* 'sender' is the button that was clicked. */
  [[[sender window] contentView] rotateByAngle: 20.0];
}

@end

And that should be it. when the button is clicked, your rotateWindow: method is invoked, which
rotates the window's contentView. :-)

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

If you want to rotate another view, not the window's contentView, you may need to tag it with an id, and then connect it to your file owner. Check the Calculator example again. You'll
see at the end of the .gsmarkup file the following bit

  <connectors>
    <outlet source="#NSOwner" target="#textField" key="textField" />
  </connectors>

which basically does

 #NSOwner.textField = #textField

where #textField is the Renaissance object with id="textField", and #NSOwner.textField
is the instance variable defined for each Calculator object --

@interface Calculator
{
  ...

  /* The gsmarkup will set this field to point to the NSTextField
   * on the Calculator window loaded from the gsmarkup.
   */
  IBOutlet NSTextField *textField;
}
...
@end

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

In your case, you need to add an IBOutlet to your @interface,

@interface {MyClass}
{
  IBOutlet NSView *myView;
}
@end

and then, tag the view you want to rotate in your .gsmarkup file,

 <{tag you want to rotate} id="myView">

connect it to the IBOutlet above

<connectors>
  <outlet source="#NSOwner" target="#myView" key="myView" />
</connectors>

and then, when the .gsmarkup file is loaded, your 'myView' instance variable
will automatically be set to point to your myView object.  You can then
rotate it in your rotateView: method --

@implementation {MyClass}

- (void) rotateView: (id)sender
{
  [myView rotateByAngle: 20.0];
}

@end

Check the Renaissance manual for more help on outlets and tagging and connecting objects. :-)

Thanks!

On 3 Feb 2009, at 22:25, Fred Morcos wrote:

---------- Forwarded message ----------
From: Fred Morcos <fred.morcos@gmail.com>
Date: Mon, Feb 2, 2009 at 3:13 PM
Subject: Renaissance Questions
To: n.pero@mi.flashnet.it


Dear Nicola,

I don't know if this is the correct way to ask you Renaissance
questions, but I looked around in all available documentation, .h
files and on IRC but didn't get any answer to my questions.

I have a main window in my gsmarkup file with id="mainWindow", this
window doesn't have a delegate. I have a button inside the window, I
want it when I click the button, the window's [NSWindow contentView]
would get the message rotateByAngle: with argument 20.0. Now, I could
either do that from inside the gsmarkup file (but how will i pass any
arguments (20.0) to the action="rotateByAngle:"?). Or I could do it
from the code, but how can I get the mainWindow instance that was
created by Renaissance so I can send it messages?

Thank You and Best Regards,

--
Fred Morcos
http://fredmorcos.blogspot.com/
http://katoob.googlecode.com/
https://savannah.nongnu.org/projects/objective-gtk/
http://grafer.googlecode.com/
http://opengrafik.googlecode.com/



--
Fred Morcos
http://fredmorcos.blogspot.com/
http://katoob.googlecode.com/
https://savannah.nongnu.org/projects/objective-gtk/
http://grafer.googlecode.com/
http://opengrafik.googlecode.com/





reply via email to

[Prev in Thread] Current Thread [Next in Thread]