Professional Web Applications Themes

[COCOA] Dynamic button? - Mac Programming

In article <1fzrife.s6p9421wrpd7mN%usenetmile23.com>, [email]usenetmile23.com[/email] (Paul Mitchum) wrote: > The Cocoa docs say that NSResponder (one of NSButton's superclasses) > receives -(void)flagsChanged:(NSEvent *)theEvent when the user presses > or releases a modifier key. So your NSButton subclass should include > something like this: (Untested code alert!) > > -(void)flagsChanged:(NSEvent *)theEvent > { > if ([theEvent modifierFlags] && NSAlternateKeyMask) { > // option key is pressed, so change the button. > } > else { > // option key isn't pressed > } > } This will only work if the button actually becomes the window's first responder. This is unlikely to ...

  1. #1

    Default Re: [COCOA] Dynamic button?

    In article <1fzrife.s6p9421wrpd7mN%usenetmile23.com>,
    [email]usenetmile23.com[/email] (Paul Mitchum) wrote:
    > The Cocoa docs say that NSResponder (one of NSButton's superclasses)
    > receives -(void)flagsChanged:(NSEvent *)theEvent when the user presses
    > or releases a modifier key. So your NSButton subclass should include
    > something like this: (Untested code alert!)
    >
    > -(void)flagsChanged:(NSEvent *)theEvent
    > {
    > if ([theEvent modifierFlags] && NSAlternateKeyMask) {
    > // option key is pressed, so change the button.
    > }
    > else {
    > // option key isn't pressed
    > }
    > }
    This will only work if the button actually becomes the window's first
    responder. This is unlikely to happen, and doesn't really make sense for
    this. The first responder is supposed to be the current active control,
    whereas the OP wants to be able to have this button work at any time, as
    far as I can see.

    You may be able to implement flagsChanged: in your window's delegate, I
    think the delegate becomes part of the responder chain. If it doesn't,
    then you'll probably need a custom subclass of NSWindow. In either case,
    you can modify the button from there.
    Michael Ash Guest

  2. #2

    Default Re: [COCOA] Dynamic button?

    In article <mail-EB9C11.09143916082003localhost>,
    Michael Ash <mailmikeash.com> wrote:
    [snip]
    > This will only work if the button actually becomes the window's first
    > responder. This is unlikely to happen, and doesn't really make sense for
    > this. The first responder is supposed to be the current active control,
    > whereas the OP wants to be able to have this button work at any time, as
    > far as I can see.
    >
    > You may be able to implement flagsChanged: in your window's delegate, I
    > think the delegate becomes part of the responder chain. If it doesn't,
    > then you'll probably need a custom subclass of NSWindow. In either case,
    > you can modify the button from there.
    Thanks, I'll try to get it working. With the knowledge provided,
    shouldn't be _too_ hard.

    Apropos, hasn't anyone doen something like this before? I can't remember
    the apps/Finder-features I've seen this, but I know it is part of
    Apple's apps... AFAIK, a similar thing is done with the menubars in the
    Finder, i.e. the Minimize menu item.

    Problem is, I have a combobox, with dates in them. A user can add a date
    by typing it in, and then push the button "Save" underneath it. In order
    to remove the date, I wanted to let the user press down the option key,
    thus changing the button into "Delete". I have very little room in this
    window, so any other angles of approach are welcome.


    --
    Joost Egelie
    [email]nospamwanadoo.be[/email]

    Please replace "nospam" with "jegelie" in my e-mail address when
    answering by mail.
    Joost Egelie Guest

  3. #3

    Default Re: [COCOA] Dynamic button?

    In article <nospam-DAEB34.10165617082003sinclair.be.wanadoo.com>,
    Joost Egelie <nospamwanadoo.be> wrote:
    > Thanks, I'll try to get it working. With the knowledge provided,
    > shouldn't be _too_ hard.
    >
    > Apropos, hasn't anyone doen something like this before? I can't remember
    > the apps/Finder-features I've seen this, but I know it is part of
    > Apple's apps... AFAIK, a similar thing is done with the menubars in the
    > Finder, i.e. the Minimize menu item.
    >
    > Problem is, I have a combobox, with dates in them. A user can add a date
    > by typing it in, and then push the button "Save" underneath it. In order
    > to remove the date, I wanted to let the user press down the option key,
    > thus changing the button into "Delete". I have very little room in this
    > window, so any other angles of approach are welcome.
    I'm not a big fan of combo boxes to begin with, so I would personally
    prefer an alternate approach, but I can't think of any that would be as
    small. So, why are your space constraints so tight? Screens are bigger
    now, OS X "requires" 800x600 (but runs in less). Can you really not
    spare a few extra pixels for an extra button?

    If you really can't, one possible alternative would be to have two
    buttons, but very small. Change Save to "+", and change Delete to "-".
    You should be able to squeeze that into the same space as one Save
    button. Hopefully people should be able to figure out what they mean,
    and it may be a bit more obvious how to delete things than the option
    key trick. Of course I'm sure you'd doent it, but people seem to skip
    reading the docs too often.
    Michael Ash Guest

  4. #4

    Default Re: [COCOA] Dynamic button?

    In article <mail-7C0EFF.09565917082003localhost>,
    Michael Ash <mailmikeash.com> wrote:

    [snip]
    > I'm not a big fan of combo boxes to begin with, so I would personally
    > prefer an alternate approach, but I can't think of any that would be as
    > small. So, why are your space constraints so tight? Screens are bigger
    > now, OS X "requires" 800x600 (but runs in less). Can you really not
    > spare a few extra pixels for an extra button?
    >
    > If you really can't, one possible alternative would be to have two
    > buttons, but very small. Change Save to "+", and change Delete to "-".
    > You should be able to squeeze that into the same space as one Save
    > button. Hopefully people should be able to figure out what they mean,
    > and it may be a bit more obvious how to delete things than the option
    > key trick. Of course I'm sure you'd doent it, but people seem to skip
    > reading the docs too often.
    Yes, people do that nowadays :-)

    I think I use a whole different approach - that of a doent structure.
    "New, Save, Load, Delete" and such go into the menubar, I can get rid of
    the combobox and have the date stated in a plain non-editable textfield
    or even the window's titlebar, and I have room to spare.

    The doent I have is fairly big - it's a 6/42 Lotto-form from Belgium.
    Those "bulletins" are made of 12 grids of 42 numbers. I managed to make
    a sort of "grid"-control, which lets the user tag 6 numbers and provide
    visual feedback to wether 6 number have been tagged. Although, with 12
    of those, the window is pretty blocked up. And slow in display updates.
    But that I'll probably straighten out in time.

    Thanks for the advice though!


    --
    Joost Egelie
    [email]nospamwanadoo.be[/email]

    Please replace "nospam" with "jegelie" in my e-mail address when
    answering by mail.
    Joost Egelie Guest

  5. #5

    Default Re: [COCOA] Dynamic button?

    In article <nospam-DAEB34.10165617082003sinclair.be.wanadoo.com>,
    Joost Egelie <nospamwanadoo.be> wrote:
    >Apropos, hasn't anyone doen something like this before?
    AppleWorks does it (but bear in mind that AppleWorks is written
    in Carbon, not Cocoa). If you try to close a doent you've
    edited you get up the normal Don't Save/Cancel/Save dialog. If
    you hold down the Command key the names on the buttons change
    to show that, for example, command-D means 'Don't Save'.


    Simon Slavin Guest

  6. #6

    Default Re: [COCOA] Dynamic button?

    In article <BB670ED29668490CDB10.0.1.2>,
    [email]slavinshearsay.demon.co.uk[/email]localhost (Simon Slavin) wrote:
    > In article <nospam-DAEB34.10165617082003sinclair.be.wanadoo.com>,
    > Joost Egelie <nospamwanadoo.be> wrote:
    >
    > >Apropos, hasn't anyone doen something like this before?
    >
    > AppleWorks does it (but bear in mind that AppleWorks is written
    > in Carbon, not Cocoa). If you try to close a doent you've
    > edited you get up the normal Don't Save/Cancel/Save dialog. If
    > you hold down the Command key the names on the buttons change
    > to show that, for example, command-D means 'Don't Save'.
    >
    >

    Yes, I know. But this behaviour was seen under Classic too.

    An example of this in (I presume) Cocoa, is in the prefpane "Startup
    Disk". Press down Option, and the three dots in the "Restart" button
    disappear. Not always though, so I guess it is fairly hard to code such
    a thing. The prefpane seems to have "acceptsFirstResponder" issues, in
    my opinion...

    --
    Joost Egelie
    [email]nospamwanadoo.be[/email]

    Please replace "nospam" with "jegelie" in my e-mail address when
    answering by mail.
    Joost Egelie Guest

  7. #7

    Default Re: [COCOA] Dynamic button?

    In article <nospam-5F9566.09340023082003sinclair.be.wanadoo.com>,
    Joost Egelie <nospamwanadoo.be> wrote:
    > An example of this in (I presume) Cocoa, is in the prefpane "Startup
    > Disk". Press down Option, and the three dots in the "Restart" button
    > disappear. Not always though, so I guess it is fairly hard to code such
    > a thing. The prefpane seems to have "acceptsFirstResponder" issues, in
    > my opinion...
    I was unable to te this.
    Mark Haase Guest

  8. #8

    Default Re: [COCOA] Dynamic button?

    In article <mehaase-D8A2F7.10470324082003netnews.upenn.edu>,
    Mark Haase <mehaaseearthlink.net> wrote:
    > In article <nospam-5F9566.09340023082003sinclair.be.wanadoo.com>,
    > Joost Egelie <nospamwanadoo.be> wrote:
    >
    > > An example of this in (I presume) Cocoa, is in the prefpane "Startup
    > > Disk". Press down Option, and the three dots in the "Restart" button
    > > disappear. Not always though, so I guess it is fairly hard to code such
    > > a thing. The prefpane seems to have "acceptsFirstResponder" issues, in
    > > my opinion...
    >
    > I was unable to te this.

    As I said: not always... Sometimes it helps to click in the Finder, and
    then back in the prefpane. Or close it and open it again. Or perhaps you
    have another version. Mine is Jaguar, 10.2.6.

    But I turned the whole interface upside down and inside out, so I don't
    have need for dynamic buttons now. I manage the more doent-based
    structure now via menu calls.

    --
    Joost Egelie
    [email]nospamwanadoo.be[/email]

    Please replace "nospam" with "jegelie" in my e-mail address when
    answering by mail.
    Joost Egelie Guest

Similar Threads

  1. Making a dynamic button
    By dbach in forum Macromedia Flash Data Integration
    Replies: 2
    Last Post: May 22nd, 03:29 AM
  2. Button with Dynamic Textfield?
    By Razorwyre webforumsuser@macromedia.com in forum Macromedia Flash Actionscript
    Replies: 0
    Last Post: January 14th, 04:17 PM
  3. dynamic button - does not go to handler
    By greg in forum ASP.NET General
    Replies: 2
    Last Post: August 10th, 02:20 PM
  4. How to select a button in a matrix of push button (Cocoa) ?
    By Alain Birtz in forum Mac Programming
    Replies: 1
    Last Post: July 28th, 07:33 PM
  5. Dynamic ASP.NET button control
    By Todd Acheson in forum ASP.NET General
    Replies: 0
    Last Post: July 21st, 01:12 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139