Don't do initialization that requires the shared application object/backend too early (ie. move it from +initialize to other methods). Add some asserts to try to catch these errors in the future.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@17503 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Alexander Malmberg 2003-08-20 12:43:52 +00:00
parent 39c092170a
commit 0ab3be5eb5
4 changed files with 46 additions and 6 deletions

View file

@ -1,3 +1,22 @@
2003-08-20 14:36 Alexander Malmberg <alexander@malmberg.org>
* Source/GSFontInfo.m (+sharedEnumerator,
+fontInfoForFontName:matrix:screenFont:): Assert that the backend
classes have been set.
* Source/NSBrowser.m (+initialize, -initWithFrame:): Don't create
the shared title cell in +initialize. Creating the cell requires
that the backend has been set up (by creating the shared application
object). We can't assume that this has been done before +initialize
is called.
* Source/NSTextView.m (+initialize, -initWithFrame:textContainer:):
Don't register for services in +initialize for the same reason: the
shared application object might not have been created yet (also, note
that calling +sharedApplication is unsafe; it will create a shared
application object, but in some cases of the wrong class, which would
lead to confusing errors later).
2003-08-20 14:08 Alexander Malmberg <alexander@malmberg.org>
Clean up code to remove warnings issued by (what will become)

View file

@ -33,6 +33,7 @@
#include <Foundation/NSArray.h>
#include <Foundation/NSSet.h>
#include <Foundation/NSValue.h>
#include <Foundation/NSException.h>
static Class fontEnumeratorClass = Nil;
static Class fontInfoClass = Nil;
@ -63,6 +64,10 @@ static GSFontEnumerator *sharedEnumerator = nil;
+ (GSFontEnumerator*) sharedEnumerator
{
NSAssert(fontEnumeratorClass,
@"Called with fontEnumeratorClass unset."
@" The shared NSApplication instance must be created before methods that"
@" need the backend may be called.");
if (!sharedEnumerator)
sharedEnumerator = [[fontEnumeratorClass alloc] init];
return sharedEnumerator;
@ -125,6 +130,10 @@ static GSFontEnumerator *sharedEnumerator = nil;
matrix: (const float *)fmatrix
screenFont: (BOOL)screenFont;
{
NSAssert(fontInfoClass,
@"Called with fontInfoClass unset."
@" The shared NSApplication instance must be created before methods that"
@" need the backend may be called.");
return AUTORELEASE([[fontInfoClass alloc] initWithFontName: nfontName
matrix: fmatrix
screenFont: screenFont]);

View file

@ -1887,7 +1887,6 @@ static NSTextFieldCell *titleCell;
// Initial version
[self setVersion: 1];
scrollerWidth = [NSScroller scrollerWidth];
titleCell = [GSBrowserTitleCell new];
}
}
@ -1901,6 +1900,12 @@ static NSTextFieldCell *titleCell;
NSSize bs;
//NSScroller *hs;
/* Created the shared titleCell if it hasn't been created already. */
if (!titleCell)
{
titleCell = [GSBrowserTitleCell new];
}
self = [super initWithFrame: rect];
// Class setting

View file

@ -375,19 +375,23 @@ this happens when layout has been invalidated, and when we are resized.
{
[self setVersion: currentVersion];
notificationCenter = [NSNotificationCenter defaultCenter];
[self registerForServices];
}
}
static BOOL did_register_for_services;
+(void) registerForServices
{
NSArray *types;
did_register_for_services = YES;
types = [NSArray arrayWithObjects: NSStringPboardType,
NSRTFPboardType, NSRTFDPboardType, nil];
[[NSApplication sharedApplication] registerServicesMenuSendTypes: types
returnTypes: types];
NSAssert(NSApp, @"Called before the shared application object was created.");
[NSApp registerServicesMenuSendTypes: types
returnTypes: types];
}
+(NSDictionary *) defaultTypingAttributes
@ -474,6 +478,9 @@ If a text view is added to an empty text network, it keeps its attributes.
if (!self)
return nil;
if (!did_register_for_services)
[isa registerForServices];
_minSize = NSMakeSize(0, 0);
_maxSize = NSMakeSize(HUGE,HUGE);
_textContainerInset = NSMakeSize(2, 0);