NSScreen fixes

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@6560 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2000-05-04 18:28:00 +00:00
parent d4c519801f
commit 7cf5df31ea
3 changed files with 58 additions and 20 deletions

View file

@ -30,6 +30,7 @@
@class NSString; @class NSString;
@class NSColor; @class NSColor;
@class NSGraphicsContext;
/* /*
* Colorspace Names * Colorspace Names
@ -119,8 +120,6 @@ int NSBitsPerSampleFromDepth(NSWindowDepth depth);
NSString *NSColorSpaceFromDepth(NSWindowDepth depth); NSString *NSColorSpaceFromDepth(NSWindowDepth depth);
int NSNumberOfColorComponents(NSString *colorSpaceName); int NSNumberOfColorComponents(NSString *colorSpaceName);
BOOL NSPlanarFromDepth(NSWindowDepth depth); BOOL NSPlanarFromDepth(NSWindowDepth depth);
NSWindowDepth GSWindowDepthForScreen(int screen);
const NSWindowDepth *GSAvailableDepthsForScreen(int screen);
/* /*
* Read the Color at a Screen Position * Read the Color at a Screen Position

View file

@ -38,7 +38,6 @@
@class NSArray; @class NSArray;
@class NSDictionary; @class NSDictionary;
@class NSMutableDictionary;
@interface NSScreen : NSObject @interface NSScreen : NSObject
{ {
@ -46,8 +45,7 @@
NSWindowDepth _depth; NSWindowDepth _depth;
NSRect _frame; NSRect _frame;
int _screenNumber; int _screenNumber;
NSWindowDepth *_supportedWindowDepths;
void *_reserved;
} }
/* /*

View file

@ -38,7 +38,18 @@
#include <AppKit/NSGraphicsContext.h> #include <AppKit/NSGraphicsContext.h>
#include <AppKit/DPSOperators.h> #include <AppKit/DPSOperators.h>
#include <AppKit/NSGraphics.h> #include <AppKit/NSGraphics.h>
#include <AppKit/AppKitExceptions.h>
/*
* Forward references
*/
NSWindowDepth GSWindowDepthForScreen(NSGraphicsContext *ctxt, int screen);
const NSWindowDepth *GSAvailableDepthsForScreen(NSGraphicsContext *ctxt,
int screen);
/*
* Returns a list of the screens attached to the system.
*/
static int* static int*
_screenNumbers(int *count) _screenNumbers(int *count)
{ {
@ -106,12 +117,13 @@ _screenNumbers(int *count)
RELEASE(self); RELEASE(self);
return nil; return nil;
} }
// Fill in all of the i-vars with appropriate values. // Fill in all of the i-vars with appropriate values.
_screenNumber = screen; _screenNumber = screen;
DPScurrentwindowbounds(ctxt, screen, &x, &y, &w, &h); DPScurrentwindowbounds(ctxt, _screenNumber, &x, &y, &w, &h);
_frame = NSMakeRect(x, y, w, h); _frame = NSMakeRect(x, y, w, h);
_depth = GSWindowDepthForScreen(screen); _depth = GSWindowDepthForScreen(ctxt, _screenNumber);
_supportedWindowDepths = NULL;
return self; return self;
} }
@ -148,8 +160,8 @@ _screenNumbers(int *count)
NSString *colorSpaceName = nil; NSString *colorSpaceName = nil;
/* /*
* Testing of this method on OS4.2 indicates that the * This method generates a dictionary from the
* dictionary is re-created every time this method is called. * information we have gathered from the screen.
*/ */
// Set the screen number in the current object. // Set the screen number in the current object.
@ -186,14 +198,23 @@ _screenNumbers(int *count)
// Mac OS X methods // Mac OS X methods
- (const NSWindowDepth*) supportedWindowDepths - (const NSWindowDepth*) supportedWindowDepths
{ {
/* // If the variable isn't initialized, get the info and
* Skeletal implementation // store it for the future.
* NSWindowDepth* retval = NSZoneMalloc([self zone], sizeof(NSWindowDepth)*2); if (_supportedWindowDepths == NULL)
* retval[1] = _depth; {
* retval[2] = 0; NSGraphicsContext *ctxt = GSCurrentContext();
* return retval; _supportedWindowDepths =
*/ (NSWindowDepth *)GSAvailableDepthsForScreen(ctxt, _screenNumber);
return GSAvailableDepthsForScreen(_screenNumber);
// Check the results
if (_supportedWindowDepths == NULL)
{
NSLog(@"Internal error: no depth list returned from window server.");
return NULL;
}
}
return _supportedWindowDepths;
} }
- (NSRect) visibleFrame - (NSRect) visibleFrame
@ -280,9 +301,14 @@ _screenNumbers(int *count)
// Get the number of screens. // Get the number of screens.
windows = _screenNumbers(&count); windows = _screenNumbers(&count);
// If the list is empty quit... // If the list is empty throw the appropriate exception and quit...
if (windows == NULL) if (windows == NULL)
return nil; // something is wrong. This shouldn't happen. {
[NSException
raise:NSWindowServerCommunicationException
format:@"Unable to retrieve list of screens from window server."];
return nil; // something is wrong. This shouldn't happen.
}
// Iterate over the list // Iterate over the list
for (index = 0; index < count; index++) for (index = 0; index < count; index++)
@ -297,6 +323,21 @@ _screenNumbers(int *count)
return [NSArray arrayWithArray: screenArray]; return [NSArray arrayWithArray: screenArray];
} }
// Release the memory for the depths array.
- (void) dealloc
{
// _supportedWindowDepths can be NULL since it may or may not
// be necessary to get this info. The most common use of NSScreen
// is to get the depth and frame attributes.
if (_supportedWindowDepths != NULL)
{
NSZoneFree(NSDefaultMallocZone(), _supportedWindowDepths);
}
[super dealloc];
}
@end @end