bug-gnustep
[Top][All Lists]
Advanced

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

[bug #18970] NSToolbarItem setImage: scales image only on initial creati


From: Paddy Smith
Subject: [bug #18970] NSToolbarItem setImage: scales image only on initial creation ?
Date: Tue, 06 Feb 2007 07:49:08 +0000
User-agent: Mozilla/5.0 (X11; U; Linux ppc; en-US; rv:1.8.1.1) Gecko/20061205 Iceweasel/2.0.0.1 (Debian-2.0.0.1+dfsg-2)

URL:
  <http://savannah.gnu.org/bugs/?18970>

                 Summary: NSToolbarItem setImage: scales image only on
initial creation ?
                 Project: GNUstep
            Submitted by: padski
            Submitted on: Tuesday 02/06/2007 at 07:49
                Category: Gui/AppKit
                Severity: 3 - Normal
              Item Group: Bug
                  Status: None
                 Privacy: Public
             Assigned to: None
             Open/Closed: Open
         Discussion Lock: Any

    _______________________________________________________

Details:

test code to show this effect when the images used are 128x128 pngs.  The
button changes the image on the toolbarItem, the second image appears
unscaled.

AppController.h:

#include <Foundation/Foundation.h>
#import <AppKit/AppKit.h>

@class NSWindow;
@class NSTextField;
@class NSNotification;

@interface AppController : NSWindowController
{
    NSWindow *window;
    BOOL readyToPlayStatus;
}
- (void)applicationWillFinishLaunching:(NSNotification *) not;
- (void)applicationDidFinishLaunching:(NSNotification *) not;
@end

AppController.m:

#include "AppController.h"
#include <AppKit/AppKit.h>

@interface AppController (AppControllerToolbar)

- (NSToolbarItem *) toolbar: (NSToolbar *) toolbar
      itemForItemIdentifier: (NSString *) itemIdentifier
  willBeInsertedIntoToolbar: (BOOL) flag;

- (NSArray *) toolbarAllowedItemIdentifiers: (NSToolbar*) toolbar;

- (NSArray *) toolbarDefaultItemIdentifiers: (NSToolbar*) toolbar;

- (BOOL) validateToolbarItem: (NSToolbarItem *) theItem;

@end

@implementation AppController (AppControllerToolbar)

- (NSToolbarItem *) toolbar: (NSToolbar *) toolbar
      itemForItemIdentifier: (NSString *) itemIdentifier
  willBeInsertedIntoToolbar: (BOOL) flag
{
  NSToolbarItem *item;
  if ([itemIdentifier isEqualToString: @"ready"]){
    item = [[NSToolbarItem alloc] initWithItemIdentifier: itemIdentifier];
    [item setLabel: @"Ready"];
    [item setPaletteLabel: @"Toggle Ready"];
    [item setImage: [NSImage imageNamed: @"toolbarStatusNotReady"]];
    [item setTarget: self];
    [item setAction: @selector(toggleReady:)];
  }
  return item;
}

- (NSArray *) toolbarAllowedItemIdentifiers: (NSToolbar*) toolbar
{
  return [NSArray arrayWithObjects: @"ready", nil];
}

- (NSArray *) toolbarDefaultItemIdentifiers: (NSToolbar*) toolbar
{
  return [NSArray arrayWithObjects: @"ready", nil];
}

- (BOOL) validateToolbarItem: (NSToolbarItem *) theItem { return YES; }

@end

@implementation AppController

- (void) toggleReady: (id) sender { NSLog(@"do stuff"); }

- (void) toggleReadyItem: (id) sender
{
        NSToolbarItem *anItem;
        NSEnumerator *enumerator = [[[window toolbar] items]
objectEnumerator];
        while (anItem = [ enumerator nextObject ]){
                if([[anItem itemIdentifier] isEqualToString: @"ready"]){
                        if (readyToPlayStatus) {
                                readyToPlayStatus=NO;
                                [anItem setImage: [NSImage imageNamed:
@"toolbarStatusReady"]];
                        }else{
                                readyToPlayStatus=YES;
                                [anItem setImage: [NSImage imageNamed:
@"toolbarStatusNotReady"]];
                        }
                }
        }
}

- (void) applicationWillFinishLaunching: (NSNotification *) not
{
  NSMenu *menu = [NSMenu new];
  [menu addItemWithTitle: @"Quit"
                  action: @selector(terminate:)
           keyEquivalent: @"q"];
  [NSApp setMainMenu:menu];
  RELEASE(menu);

  window = [[NSWindow alloc] initWithContentRect: NSMakeRect(300, 300, 200,
100)
                                       styleMask: (NSTitledWindowMask |
                                                   NSMiniaturizableWindowMask
|
                                                   NSResizableWindowMask)
                                          backing: NSBackingStoreBuffered
                                           defer: YES];
  [window setTitle: @"Test Toolbar"];

  NSToolbar *aToolbar = [[NSToolbar alloc] initWithIdentifier:
@"AppControllerToolbar"];
  [aToolbar setDelegate: self];
  [aToolbar setAllowsUserCustomization: YES];
  [aToolbar setAutosavesConfiguration: YES];
  [window setToolbar: aToolbar];
  RELEASE(aToolbar);

  readyToPlayStatus=NO;

  NSButton *myButton= [[NSButton alloc] initWithFrame: NSMakeRect(30, 30, 80,
30)];
  [myButton setTarget: self];
  [myButton setAction: @selector(toggleReadyItem:)];
  [[window contentView] addSubview: myButton];
  RELEASE(myButton);

}

- (void) applicationDidFinishLaunching: (NSNotification *) not
{
  [window makeKeyAndOrderFront: self];
}

- (void) dealloc
{
  RELEASE(window);
  [super dealloc];
}

@end

I'm using the gnustep in debian etch (ie: latest gnustep release), but with
base from svn at 20061227.

Regards,
Paddy




    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?18970>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/





reply via email to

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