discuss-gnustep
[Top][All Lists]
Advanced

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

(no subject)


From: Paul Fox
Subject: (no subject)
Date: Fri, 21 Jun 2002 20:24:02 +0100

To: discuss-gnustep@gnu.org
Subject: Re: Discuss-gnustep digest, Vol 1 #860 - 5 msgs
X-Mailer: Created by CRiSP-Mail v6.3 (CRiSP v8.0.6a)

I managed to get my app which I am developing on MacOSX to compile
and 'run' under GNUstep. I am using GNUstep as an alternate Cocoa
implementation so I can understand the very bad things I see on the
Mac.

But when my app runs - I get an infinite cascade of aattempts to finish
loading. Looking at the stack trace it looks like it is trying to
display an NSAlert panel and this in turn is causing it to generate
another exception ad infinitum.

I also tried a 'simple' app I use for playing with and this only
displays the icon - no dialog panel.

Maybe if I include this here other people can try this out and let me
know what they think.

Note the missing NSCombo definitions in the code which I seem to need
for GNUstep even tho they are defined in externs.m in GNUstep.

This is with the latest 0.7.8 stuff. 

(I have been trying to debug severe memory leaksing in cursorRect tracking
in the Mac but this is giving me no joy on GNUstep -- this part of GNUstep
actually works unlike the Mac. Unfortunately everything else seems to
be strange).

regards

simple.m
=========
# include       <Foundation/Foundation.h>
# include       <AppKit/AppKit.h>

# if !defined(TRUE)
#       define  TRUE    1
#       define  FALSE   0
# endif

#if GNUSTEP
NSString *NSComboBoxWillPopUpNotification = @"NSComboBoxWillPopUpNotification";
NSString *NSComboBoxWillDismissNotification = 
@"NSComboBoxWillDismissNotification";
NSString *NSComboBoxSelectionDidChangeNotification = 
@"NSComboBoxSelectionDidChangeNotification";
NSString *NSComboBoxSelectionIsChangingNotification = 
@"NSComboBoxSelectionIsChangingNotification";
#endif

static void print_view_tree(NSView *v, int level);

/**********************************************************************/
/*   Class interfaces.                                                */
/**********************************************************************/
@interface MyAppClass : NSApplication
{
}
- (id) init;
- (void) applicationDidFinishLaunching: (NSNotification *) n;
- (NSMenu *) applicationDockMenu: (NSApplication *) sender;
@end

@interface MyMenu : NSMenu
{
}
- (void) submenuAction: (id) sender;
@end

@interface MyMenuItem : NSMenuItem
{
}
- (id) init;
- (void) clicked: sender;
- (BOOL) validateMenuItem: (MyMenuItem *) item;
@end

@interface MyWindow : NSWindow
{
}
- (id) init;
- (BOOL) canBecomeKeyWindow;
- (void) becomeMainWindow;
@end

@interface MyView : NSView
{
        NSTrackingRectTag tracking_tag;
}
- (id) init;
- (BOOL) acceptsFirstMouse;
- (BOOL) acceptsFirstResponder;
- (void) mouseDown: (NSEvent *) e;
- (void) mouseUp: (NSEvent *) e;
- (void) resetCursorRects;
@end

/**********************************************************************/
/*   MyAppClass                                                       */
/**********************************************************************/
@implementation MyAppClass : NSApplication
static void create_menu(id s)
{       NSZone *z = [MyMenu menuZone];
        MyMenu *m, *fox;
        MyMenu *menu;
        MyMenuItem *menu_item;
        char    *labels[] = {"Open...", "Close", "Exit", "About"};
        int     i;
static int x;
        char    buf[128];
        NSString *str;

        // menubar
        m = [[MyMenu allocWithZone:z] initWithTitle: [[NSString alloc] 
initWithCString:"fred"]];
        [s setMainMenu:m];

        // menubutton
        menu_item = [[[MyMenuItem alloc] init] autorelease];
        [[s mainMenu] addItem: menu_item];
        
        sprintf(buf, "Files-%d", x++);
        str = [[NSString alloc] initWithCString: buf length: strlen(buf)];
        fox = [[MyMenu allocWithZone:z] initWithTitle: str];
        [menu_item setSubmenu: fox];

        for (i = 0; i < sizeof labels / sizeof labels[0]; i++) {
                sprintf(buf, "%s-%d", labels[i], x++);
                str = [[NSString alloc] initWithCString: buf length: 
strlen(buf)];
                menu_item = [[[MyMenuItem alloc] init] autorelease];
                [menu_item setTitle: str];
                [fox addItem: menu_item];
                }

/*      menu = [NSApp mainMenu];
        printf("menu=%x\n", menu);
        printf("index=%d\n", [menu indexOfItemWithTitle: @"CRiSP"]);*/
}
- (id) init
{
        [super init];
//      create_menu(self);
//      [self setDelegate:self];

        return self;
}
- (void) applicationDidBecomeActive: (NSNotification *) n
{
        printf("applicationDidBecomeActive\n");
}
- (void) applicationDidFinishLaunching: (NSNotification *) n
{
        printf("applicationDidFinishLaunching\n");
}
- (NSMenu *) applicationDockMenu: (NSApplication *) sender
{
        printf("%s\n", __func__);
        return NULL;
}
- (void) applicationWillFinishLaunching: (NSNotification *) n
{
        printf("%s\n", __func__);
}
@end
@implementation MyMenu : NSMenu
- (void) submenuAction: (id) sender
{
        printf("%s\n", __func__);
        [super submenuAction];
}
@end

@implementation MyMenuItem : NSMenuItem
- (id) init
{
        [super init];
        [self setTarget: self];
        [self setAction: @selector(clicked:)];
        return self;
}
- (void) clicked: sender
{
        printf("%s\n", __func__);
}
- (BOOL) validateMenuItem: (MyMenuItem *) item
{
static int level;
        printf("%s %x\n", __func__, item);

        if (level++ == 0)
                create_menu(NSApp);
        level--;
        return YES;
}
@end
/**********************************************************************/
/*   MyWindow                                                         */
/**********************************************************************/
@implementation MyWindow : NSWindow
- (id) init
{
        [super init];
        [self setDelegate: self];
        return self;
}
- (void) becomeMainWindow
{
        [super becomeMainWindow];
        printf("becomeMainWindow\n");
}
- (BOOL) canBecomeKeyWindow
{
        printf("canBecomeKeyWindow\n");
        return YES;
}
- (BOOL) canBecomeMainWindow
{
        printf("canBecomeMainWindow\n");
        return YES;
}
@end
/**********************************************************************/
/*   MyView                                                           */
/**********************************************************************/
@implementation MyView
- (id) init
{
        [super init];
        return self;
}
- (BOOL) acceptsFirstMouse// CrispView
{
printf("%s\n", __func__);
        return TRUE;
}
/**********************************************************************/
/*   Let us have key focus.                                           */
/**********************************************************************/
- (BOOL) acceptsFirstResponder // CrispView
{
printf("%s\n", __func__);
        return TRUE;
}
- (void) drawRect:(NSRect) rect 
{
        printf("%s\n", __func__);
        [NSColor colorWithCalibratedRed: 1.0
                        green: 0.0
                        blue: 0.0
                        alpha: 1.0];
        [NSBezierPath fillRect:rect];
}
- (void) mouseDown: (NSEvent *) e // CrispView
{       int     i;

        printf("%s\n", __func__);
        for (i = 0; i < 1000; i++)
                [[self window] invalidateCursorRectsForView: self];
}
- (void) mouseUp: (NSEvent *) e // CrispView
{
        printf("%s\n", __func__);
}
- (void) resetCursorRects
{       NSRect  r;

        if (tracking_tag)
                [self removeTrackingRect: tracking_tag];

        r = [self bounds];
        r = [self visibleRect];
        tracking_tag = [self addTrackingRect:r
                owner: self
                userData: 0
                assumeInside: FALSE];
printf("Tracking rect %d: %g,%g %gx%g\n", tracking_tag, r.origin.x, r.origin.y, 
r.size.width, r.size.height);
}
@end

static id
add_button(id win, char *str)
{       NSButton *t;
        NSRect  rect;

        t = [[NSButton alloc] init];
        [t setTitleWithMnemonic:[NSString stringWithCString: str]];
        [t sizeToFit];
        [[win contentView] addSubview: t];
        rect = [t frame];
        rect.origin.x = 40;
        rect.origin.y = 300;
        [t setFrame: rect];
        return t;
}
static id
add_field(id win, char *str, int y)
{       NSTextField     *t;
        NSRect  rect;

        t = [[NSTextField alloc] init];
        [t setStringValue:[NSString stringWithCString: str]];
        [t sizeToFit];
        [[win contentView] addSubview: t];
        rect = [t frame];
        rect.origin.x = 50;
        rect.origin.y = y;
        [t setFrame: rect];
        return t;
}
const char *
o_class_name(id w)
{
        return [[w description] cString];
}
static void
print_id_tree(id obj)
{       NSRect  rect;

        rect = [obj frame];
        printf("%s [%g,%g %gx%g]\n", 
                o_class_name(obj),
                rect.origin.x, rect.origin.y, rect.size.width, 
rect.size.height);
        print_view_tree([obj contentView], 1);
}
static void
print_view_tree(NSView *v, int level)
{       NSArray *a;
        int     i;
        NSRect  rect;

        rect = [v frame];
        printf("%d:%*s%s [%g,%g %gx%g]\n", 
                level,
                level * 2, "", 
                o_class_name(v),
                rect.origin.x, rect.origin.y, rect.size.width, 
rect.size.height);
        a = [v subviews];
        for (i = 0; i < [a count]; i++) {
                print_view_tree((NSView *) [a objectAtIndex:i], level+1);
                }
}
int 
main(int argc, const char *argv[])
{       NSAutoreleasePool *pool;
        MyAppClass *m;
        NSWindow *win;
        NSRect rect;
        NSTextField     *f1, *f2;
        NSView  *v;

        pool = [NSAutoreleasePool new];

        [MyAppClass sharedApplication];

        [NSApp setDelegate: NSApp];

        rect.origin.x = 50;
        rect.origin.y = 700;
        rect.size.width = 400;
        rect.size.height = 350;
        win = [[MyWindow alloc] initWithContentRect: rect
                        styleMask: (NSResizableWindowMask | 
NSMiniaturizableWindowMask | NSClosableWindowMask)
                        backing: NSBackingStoreBuffered
                        defer: TRUE];
        [win orderFront:win];
//      [win center];
        [win makeKeyWindow];
        [win makeMainWindow];
                
        f1 = add_field(win, "Hello world", 250);
        f2 = add_field(win, "Hello again", 200);
        [[f1 window] makeFirstResponder: f1];
        add_button(win, "Press me");
        printf("calling run...\n");
        print_id_tree(win);
        create_menu(NSApp);

        // Implement a view.
        v = [[MyView alloc] init];
        [v setFrame: NSMakeRect(20, 300, 100, 100)];
        [[win contentView] addSubview:v];

        [f1 setNextKeyView: f2];
        [f2 setNextKeyView: v];
        [v setNextKeyView: f1];
        // Something in the clipboard
        {NSPasteboard *pb = [NSPasteboard generalPasteboard];
        NSString *str = [[NSString alloc] initWithCString: "This is Paul Fox"];
        [pb declareTypes:[NSArray arrayWithObjects: NSStringPboardType, nil] 
owner: nil];
        [pb setString:str forType:NSStringPboardType];
        }
        [NSApp run];
        printf("calling NSApplicationMain ...\n");

        return NSApplicationMain(argc, argv);
}

===========================================

+-------------------------------------------------------------------------+
| CRiSP - Flexible editor     | CRiSP, syn. for BRIEF                     |#
|                             | Internet:           fox@crisp.demon.co.uk |#
| If you get no reply for     | WWW: (mine)  http://www.crisp.demon.co.uk |#
| support, please check your  | WWW:                 http://www.crisp.com |#
| Reply-To: email address.    | WWW:           http://www.pacemaker.co.uk |#
+-------------------------------------------------------------------------+#
 ###########################################################################




reply via email to

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