Placards in Cocoa
-
I'm trying to see if I can create an existing interface using Cocoa. It
uses a placard at the bottom of the window. According to the Human
Interface Guidelines, there is no Cocoa equivalent. (Also, under
Panther the placard doesn't draw a striped background, which the doc
says it does.)
So how do you draw placards in Cocoa? (I know you can call any of the
Appearance primitives, but DrawThemePlacard requires QuickDrawâ¦)
There also doesn't seem to be a way in Interface Builder to skootch the
horizontal scroll bar over to leave room for a placard.
(All of this was quite doable in Constructor, so I assume I'm just
missing something.)
David Dunham A Sharp <david...>
Voice/Fax: 206 783 7404 http://a-sharp.com
Efficiency is intelligent laziness.
_______________________________________________
MacOSX-dev mailing list
<MacOSX-dev...>
http://www.omnigroup.com/mailman/listinfo/macosx-dev -
Sure you can, they are just not called this.
Essentially this is what you want to do (this is all from memory and
typed on Mail.app):
1) simply drag the popup menu into your window, and associate it as an
outlet in your nib.
2) subclass NSScrollView
override awakeFromNib to:
a) get the button cell of the popup and set bordered to no
b) set bezeled to yes
c) set the font to the system small font
(you may also want to explore using one of the mini control sizes
instead - but you can turn that on from IB)
d) do a [self addSubview: yourPopup];
(you may have to manually install the subview you want the scroll view
on)
override -(void)tile to do:
[super tile];
NSRect r = [[self horizontalScroller]frame];
NSRect popupRect;
// snip 75 pixels from the rectangle on the right edge
NSDivideRect(r, &popupRect, 75.0, NSMaxXEdge);
[[self horizontalScroller]setFrame:r];
[yourPopup setFrame:NSInsetRect(popupRect, 1.0,1.0)];
/a
On Jul 10, 2004, at 4:17 PM, David Dunham wrote:> I'm trying to see if I can create an existing interface using Cocoa.
> It uses a placard at the bottom of the window. According to the Human
> Interface Guidelines, there is no Cocoa equivalent. (Also, under
> Panther the placard doesn't draw a striped background, which the doc
> says it does.)
>
> So how do you draw placards in Cocoa? (I know you can call any of the
> Appearance primitives, but DrawThemePlacard requires QuickDrawâ¦)
>
> There also doesn't seem to be a way in Interface Builder to skootch
> the horizontal scroll bar over to leave room for a placard.
>
> (All of this was quite doable in Constructor, so I assume I'm just
> missing something.)
>
> David Dunham A Sharp <david...>
> Voice/Fax: 206 783 7404 http://a-sharp.com
> Efficiency is intelligent laziness.
> _______________________________________________
> MacOSX-dev mailing list
> <MacOSX-dev...>
> http://www.omnigroup.com/mailman/listinfo/macosx-dev
>
>
_______________________________________________
MacOSX-dev mailing list
<MacOSX-dev...>
http://www.omnigroup.com/mailman/listinfo/macosx-dev -
On 10 Jul 2004, at 15:29, Alberto Ricart wrote:> 1) simply drag the popup menu into your window, and associate it as an
> outlet in your nib.
That's two people now who have assumed that placards are popups. They
are not. From the HIG (p. 179): "A placard is a small section at the
bottom of a window used to display information, such as the current
page number." Which is what I want to do.> 2) subclass NSScrollView
I thought Cocoa discouraged subclassing, and Interface Builder could
actually create useful interfaces...
David Dunham A Sharp <david...>
Voice/Fax: 206 783 7404 http://a-sharp.com
"People seem to misinterpret complexity as sophistication" -- Niklaus
Wirth
_______________________________________________
MacOSX-dev mailing list
<MacOSX-dev...>
http://www.omnigroup.com/mailman/listinfo/macosx-dev -
On Jul 10, 2004, at 6:03 PM, David Dunham wrote:> On 10 Jul 2004, at 15:29, Alberto Ricart wrote:
>
>> 1) simply drag the popup menu into your window, and associate it as
>> an outlet in your nib.
>
> That's two people now who have assumed that placards are popups. They
> are not. From the HIG (p. 179): "A placard is a small section at the
> bottom of a window used to display information, such as the current
> page number." Which is what I want to do.
It can be any NSView you want it to be (you are adding a subview).
Typically that is popups, but you can put in whatever you want.>
>> 2) subclass NSScrollView
>
> I thought Cocoa discouraged subclassing, and Interface Builder could
> actually create useful interfaces...
This is not true. This is why IB has a subclass command that allows you
to pick any of the appkit classes. And why you can drag a custom view,
and group it in a scrollview, and why the IB inspector allows you to
pick your own implementation for the grouping view. If they didn't want
you to do this, you wouldn't have IB.
While it is true that you want to use composition instead of
subclassing as much as possible, some of these things are much easier
with subclassing because instead of registering for a bunch of
notification to reset the location of the component, you simply
override 2 methods. And you are done. I am sure the alternative would
be more code than this, so why do more when you can do less? This is
not only true for Cocoa but for Java too. Sometimes is much cleaner to
have the class manage any additional controls you need than to hand
tweak things externally.
If you still care, I wrote a small example. It assumes that in IB, you
will create the popup or whatever you want to put in there and
associate it with the scrollview subclass.
@interface MyScrollView : NSScrollView
{
IBOutlet id myPopup;
}
@end
@implementation MyScrollView
- (void)awakeFromNib
{
id cell = [myPopup cell];
[cell setBordered:NO];
[cell setBezeled:YES];
[self addSubview:myPopup];
}
- (void)tile
{
[super tile];
NSRect scrollerFrame = [[self horizontalScroller]frame];
NSRect popupFrame;
NSDivideRect(scrollerFrame, &popupFrame, &scrollerFrame, 85.0,
NSMinXEdge);
[[self horizontalScroller]setFrame:scrollerFrame];
[myPopup setFrame:NSInsetRect(popupFrame, 1.0,1.0)];
}
@end
If you or anyone wants the sample project, drop me a line.
Cheers,
/a>
> David Dunham A Sharp <david...>
> Voice/Fax: 206 783 7404 http://a-sharp.com
> "People seem to misinterpret complexity as sophistication" -- Niklaus
> Wirth
>
> _______________________________________________
> MacOSX-dev mailing list
> <MacOSX-dev...>
> http://www.omnigroup.com/mailman/listinfo/macosx-dev
>
>
_______________________________________________
MacOSX-dev mailing list
<MacOSX-dev...>
http://www.omnigroup.com/mailman/listinfo/macosx-dev -
>> 2) subclass NSScrollView
>
> I thought Cocoa discouraged subclassing, and Interface Builder could
> actually create useful interfaces...
Interface Builder is only one tool in your arsenal. It can't do
everything. Some things you'll actually have to write yourself. To say
that because it can't do what you're trying to do it therefore can't
"create useful interfaces" is absurd.
If you really want to be able to create placards in IB, file an
enhancement request with Apple. If enough people show desire for it,
they'll add it.
zach
_______________________________________________
MacOSX-dev mailing list
<MacOSX-dev...>
http://www.omnigroup.com/mailman/listinfo/macosx-dev -
On 10/07/2004, at 23:17, David Dunham wrote:> So how do you draw placards in Cocoa?
Have a look at the TextEdit source code available in
/Developer/Examples. I've found the code very easy to follow and it's
a very good example on how to handle a traditional zooming view in
Cocoa by subclassing NSScrollView.
Most of the code in TextEdit's ScalingScrollView.m has to do with
setting up the pop-up button and tiling it in the scroll view. The
tiling is done by getting the horizontal scroller of the scroll view
and moving it to its right place, then the pop-up is moved to its place
too. It takes place in the -tile method of NSScrollView.
ScalingScrollView is fairly reusable in itself and the placard can be
made to look better with some subclassing to handle drawing.
Keynote, for example, uses the same approach. The zooming view is a
subclass of NSScrollView and the placard is a custom NSControl (an
NSImage subclass with a pop-up menu assigned, more specifically).
This is how it has been done since the times of NEXTSTEP, there was
even an example of doing this in Adobe's Purple Book in 1992
(Programming the Display PostScript System with NeXTstep).
_______________________________________________
MacOSX-dev mailing list
<MacOSX-dev...>
http://www.omnigroup.com/mailman/listinfo/macosx-dev -
On Jul 10, 2004, at 4:03 PM, David Dunham wrote:>> 2) subclass NSScrollView
>
> I thought Cocoa discouraged subclassing, and Interface Builder could
> actually create useful interfaces...
Both are true.
In Cocoa, you subclass when you want to create a new is-a relationship,
not a new has-a or can-do relationship. So for example, you don't
subclass NSWindow if you're not going to create a round window. On the
other hand, in your case you're creating a new kind of scroll view: A
scroll view that also has an informational placard in-line with one of
its scrollers. In that case, it makes perfect sense to subclass.
I usually say that Cocoa discourages you from subclassing the world.
You're perfectly free to do so when it makes sense, you just don't have
to do so very much for the common case.
-- Chris
--
Chris Hanson <cmh...>
http://www.livejournal.com/users/chanson/
_______________________________________________
MacOSX-dev mailing list
<MacOSX-dev...>
http://www.omnigroup.com/mailman/listinfo/macosx-dev -
>>> 2) subclass NSScrollView
>>
>> I thought Cocoa discouraged subclassing, and Interface Builder could
>> actually create useful interfaces...
>
> Interface Builder is only one tool in your arsenal. It can't do
> everything. Some things you'll actually have to write yourself. To say
> that because it can't do what you're trying to do it therefore can't
> "create useful interfaces" is absurd.
>
> If you really want to be able to create placards in IB, file an
> enhancement request with Apple. If enough people show desire for it,
> they'll add it.
NOTHING is preventing us from creating our own custom IB palette to
make IB more useful. In the NeXT days, many of the objectware included
an IB palette for this purpose. Currently the issue is that some AppKit
classes are adding features, but IB palettes are lagging behind which
is lame.
/a
_______________________________________________
MacOSX-dev mailing list
<MacOSX-dev...>
http://www.omnigroup.com/mailman/listinfo/macosx-dev -
On 10 Jul 2004, at 19:05, David Lázaro Saz wrote:> Have a look at the TextEdit source code available in
> /Developer/Examples.
This shows how to leave space for a placard. But it just uses a
NSPopUpButton and I want a status-only placard (drawn correctly for any
version of Mac OS X).> ScalingScrollView is fairly reusable in itself and the placard can be
> made to look better with some subclassing to handle drawing.
I want it to look correct in any version of Mac OS X. (In Panther,
placards, which Carbon draws just fine, don't have stripes. I think
they did have stripes in Jaguar.) So how would I use what in Carbon
would be kThemeBackgroundPlacard? (I suppose I could try mixing in the
Carbon calls, but it has a somewhat different drawing model so this
would be a pain.)
I know the HIG says that Cocoa can't do placards, so maybe I should
just resign myself to that. Or stick with Carbon.
David Dunham A Sharp <david...>
Voice/Fax: 206 783 7404 http://a-sharp.com
"People seem to misinterpret complexity as sophistication" -- Niklaus
Wirth
_______________________________________________
MacOSX-dev mailing list
<MacOSX-dev...>
http://www.omnigroup.com/mailman/listinfo/macosx-dev -
On Jul 11, 2004, at 3:24 PM, David Dunham wrote:>> Have a look at the TextEdit source code available inWhat do you want to display? If you just want to display text, then a
>> /Developer/Examples.
> This shows how to leave space for a placard. But it just uses a
> NSPopUpButton and I want a status-only placard (drawn correctly for
> any version of Mac OS X).
>
non-bordered, no-background, NSTextField should do the trick? If you
need a pop-up, then again set it to be non-bordered...
mmalc
_______________________________________________
MacOSX-dev mailing list
<MacOSX-dev...>
http://www.omnigroup.com/mailman/listinfo/macosx-dev -
On Jul 11, 2004, at 3:24 PM, David Dunham wrote:> On 10 Jul 2004, at 19:05, David Lázaro Saz wrote:
>
>> Have a look at the TextEdit source code available in
>> /Developer/Examples.
>
> This shows how to leave space for a placard. But it just uses a
> NSPopUpButton and I want a status-only placard (drawn correctly for
> any version of Mac OS X).
>
>> ScalingScrollView is fairly reusable in itself and the placard can be
>> made to look better with some subclassing to handle drawing.
>
> I want it to look correct in any version of Mac OS X. (In Panther,
> placards, which Carbon draws just fine, don't have stripes. I think
> they did have stripes in Jaguar.) So how would I use what in Carbon
> would be kThemeBackgroundPlacard? (I suppose I could try mixing in the
> Carbon calls, but it has a somewhat different drawing model so this
> would be a pain.)
>
> I know the HIG says that Cocoa can't do placards, so maybe I should
> just resign myself to that. Or stick with Carbon.
It can be done and rather easily if I recall (don't have the time at
the moment to jog my memory)... look at using an NSTextField in place
of the popup menu.
Anyway the cocoa-dev list has more Cocoa expert on it then this list
you may want to ask on that list.
<http://www.lists.apple.com/mailman/listinfo/cocoa-dev>
Finally if you find the default AppKit classes don't provide a feature
you want, one that other likely want as well, make sure to file a
defect with Apple (they may add it or at least outline in sample code
how to do it).
-Shawn
_______________________________________________
MacOSX-dev mailing list
<MacOSX-dev...>
http://www.omnigroup.com/mailman/listinfo/macosx-dev -
On Sat, 10 Jul 2004 14:17:22 -0700, David Dunham <dunham...> wrote:> So how do you draw placards in Cocoa? (I know you can call any of the
> Appearance primitives, but DrawThemePlacard requires QuickDrawââ¬Â¦)
DrawThemePlacard needs QuickDraw, but HIThemeDrawPlacard shouldn't.
(I haven't actually used the HITheme APIs yet, and they don't seem to
have much documentation, but they are supposed to use CoreGraphics
rather than QuickDraw.)
Of course, HITheme requires Panther, so if you're coding for Jaguar
you're out of luck.
Take a look at the HITheme.h file and the HI Toolbox release notes for Panther:
http://developer.apple.com/releasenotes/Carbon/HIToolbox.html
--
Tim Buchheim
_______________________________________________
MacOSX-dev mailing list
<MacOSX-dev...>
http://www.omnigroup.com/mailman/listinfo/macosx-dev -
Hi, just ran into this by accident, but there seems to be some already
prepared code for
placards at stonedesign.com located here:
http://www.stone.com/dev/AccessoryScrollView/
SDScrollerAccessoryScrollView.html
The screenshot seems to have what your looking for, hopefully this can
help!
Bye
On 2004/07/10, at 19:05, David Lázaro Saz wrote:>
> On 10/07/2004, at 23:17, David Dunham wrote:
>
>> So how do you draw placards in Cocoa?
>
> Have a look at the TextEdit source code available in
> /Developer/Examples. I've found the code very easy to follow and it's
> a very good example on how to handle a traditional zooming view in
> Cocoa by subclassing NSScrollView.
>
> Most of the code in TextEdit's ScalingScrollView.m has to do with
> setting up the pop-up button and tiling it in the scroll view. The
> tiling is done by getting the horizontal scroller of the scroll view
> and moving it to its right place, then the pop-up is moved to its
> place too. It takes place in the -tile method of NSScrollView.
> ScalingScrollView is fairly reusable in itself and the placard can be
> made to look better with some subclassing to handle drawing.
>
> Keynote, for example, uses the same approach. The zooming view is a
> subclass of NSScrollView and the placard is a custom NSControl (an
> NSImage subclass with a pop-up menu assigned, more specifically).
>
> This is how it has been done since the times of NEXTSTEP, there was
> even an example of doing this in Adobe's Purple Book in 1992
> (Programming the Display PostScript System with NeXTstep).
>
> _______________________________________________
> MacOSX-dev mailing list
> <MacOSX-dev...>
> http://www.omnigroup.com/mailman/listinfo/macosx-dev
_______________________________________________
MacOSX-dev mailing list
<MacOSX-dev...>
http://www.omnigroup.com/mailman/listinfo/macosx-dev


