Skip navigation.
 
mlRe: Changing fonts without font menu?
FROM : Mike Wright
DATE : Sat Jun 10 20:48:15 2006

On Jun 9, 2006, at 13:59, <email_removed> wrote:
> Date: Fri, 9 Jun 2006 11:58:11 -0700
> From: Aki Inoue <<email_removed>>
> Subject: Re: Changing fonts without font menu?
> To: Fredrik Olsson <fredrik.<email_removed>>
> Cc: Cocoa-dev <<email_removed>>
> Message-ID: <<email_removed>>
> Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes
>

>> I tried it with a "Cocoa Application", and then it kind of semi-
>> works with a single nib-file. Only problem is that my connected
>> NSButton can not "unbold" as the menu does (And no selected state as
>> the menus).

> Since the auto validation is currently implemented as -
> validateMenuItem:, it only works with NSMenuItems in Tiger.  I'm
> planning to move the core logic to -validateUserInterfaceItem: in a
> future release, then, at least, enable/disable part of the validation
> should work with NSToolbarItems.
>
> We don't have a generic way of triggering auto validation for
> arbitrary objects (of course, I mean, outside of Cocoa Binding), so
> your NSButtonCells need a bit more manually hook ups.
>

>> And when having a document based app, with the menu in another nib
>> than the NSButton hooked up to NSFontManager, it does not work at
>> all :/

> You can hook up your taget, action, and tag manually in your -
> [NSDocument windowControllerDidLoadNib:].
>

>>> My ugly solution is to extend NSTextField, add bold:, italic:
>>> methods, and let them send key events. Very awkward.

>>
>> My ugly solutions have two major flaws:
>> 1. It makes the Format manu flicker when I click the buttons.
>> 2. I can not think of a clean way to send Cmd-+ and Cmd--.

> In addition to the flaws, you're vulnerable if the user changes the
> key equivalent for these cmds (they are customizable via System
> Prefs).  We normally don't recommend trying to control Cocoa UI
> objects by synthesizing event objects (including CG, Carbon, NS 
> events).
>
> Aki


After a good night's sleep and a cup of coffee, I now understand how -
addFontTrait: works, but I still don't understand how the menu item 
with the NSBoldFontMask (2) tag causes the bold trait to be toggled--
added if it's not there, removed if it is there--while it seems that 
the toolbar item with the same tag can only cause the bold trait to 
be added.

What am I missing here? Is the action for the menu item being reset 
dynamically somehow, based on the face of the first character of the 
current text selection? If so, where is this being done? If not, how 
does it work? Can it be made to work the same way for a toolbar button?

Should I have another cup of coffee and go back to the docs?

Mike Wright

Related mailsAuthorDate
mlChanging fonts without font menu? Fredrik Olsson Jun 8, 14:27
mlRE: Changing fonts without font menu? Mradul Mandhanya Jun 8, 16:29
mlRe: Changing fonts without font menu? Fredrik Olsson Jun 8, 16:48
mlRe: Changing fonts without font menu? Fredrik Olsson Jun 8, 16:48
mlRe: Changing fonts without font menu? Aki Inoue Jun 8, 22:52
mlRe: Changing fonts without font menu? Mike Wright Jun 9, 00:36
mlRe: Changing fonts without font menu? Fredrik Olsson Jun 9, 08:43
mlRe: Changing fonts without font menu? Fredrik Olsson Jun 9, 15:04
mlRe: Changing fonts without font menu? Aki Inoue Jun 9, 20:58
mlRe: Changing fonts without font menu? Mike Wright Jun 10, 20:48
mlRe: Changing fonts without font menu? Fredrik Olsson Jun 12, 08:43
mlRe: Changing fonts without font menu? Aki Inoue Jun 13, 21:20