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 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916
|
/** <title>GSDisplayServer</title>
<abstract>Abstract display server class.</abstract>
Copyright (C) 2002 Free Software Foundation, Inc.
Author: Adam Fedor <fedor@gnu.org>
Date: Mar 2002
This file is part of the GNU Objective C User interface library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
*/
#include <Foundation/NSArray.h>
#include <Foundation/NSDictionary.h>
#include <Foundation/NSData.h>
#include <Foundation/NSLock.h>
#include <Foundation/NSRunLoop.h>
#include <Foundation/NSThread.h>
#include <Foundation/NSGeometry.h>
#include "AppKit/NSEvent.h"
#include "AppKit/NSImage.h"
#include "AppKit/NSWindow.h"
#include "GNUstepGUI/GSDisplayServer.h"
#include "GNUstepGUI/GSDragView.h"
#include "GSSlideView.h"
/* Display attributes */
NSString * GSDisplayName = @"DisplayName";
NSString * GSDisplayNumber = @"DisplayNumber";
NSString * GSScreenNumber = @"ScreenNumber";
/* The memory zone where all server objects are allocated from (Contexts
are also allocated from this zone) */
static NSZone *_globalGSZone = NULL;
/* The current concrete class */
static Class defaultServerClass = NULL;
/* Maps windows to a server */
static NSMapTable *windowmaps = NULL;
/* Lock for use when creating contexts */
static NSRecursiveLock *serverLock = nil;
static NSString *NSCurrentServerThreadKey;
/** Returns the GSDisplayServer that created the interal
representation for window. If the internal representation has not
yet been created (for instance, if the window is deferred), it
returns the current server */
GSDisplayServer *
GSServerForWindow(NSWindow *window)
{
int num;
if (windowmaps == NULL)
{
NSLog(@"GSServerForWindow: No window server");
return nil;
}
num = [window windowNumber];
if (num == 0)
{
/* Backend window hasn't been initialized yet, assume current server. */
return GSCurrentServer();
}
return NSMapGet(windowmaps, (void *)num);
}
/** Returns the current GSDisplayServer */
GSDisplayServer *
GSCurrentServer(void)
{
NSMutableDictionary *dict = [[NSThread currentThread] threadDictionary];
return (GSDisplayServer*) [dict objectForKey: NSCurrentServerThreadKey];
}
/**
<unit>
<heading>GSDisplayServer</heading>
<p>This is an abstract class which provides a framework for a device
independant window server. A window server handles the very basic control
of the computer display and input. This includes basic window
creation and handling, event handling, cursors, and providing
miscellaneous information about the display.
</p>
<p>Typically a backend library will provide a concrete subclass
which implements the device specific methods described below.
</p>
<p>In almost all cases, you should not call these methods directly
in an application. You should use the equivalent methods available
elsewhere in the library (e.g. NSWindow, NSScreen, etc).
</p>
</unit> */
@implementation GSDisplayServer
+ (void) initialize
{
if (serverLock == nil)
{
[gnustep_global_lock lock];
if (serverLock == nil)
{
serverLock = [NSRecursiveLock new];
_globalGSZone = NSDefaultMallocZone();
defaultServerClass = [GSDisplayServer class];
NSCurrentServerThreadKey = @"NSCurrentServerThreadKey";
}
[gnustep_global_lock unlock];
}
}
/** Set the concrete subclass that will provide the device dependant
implementation.
*/
+ (void) setDefaultServerClass: (Class)aClass
{
defaultServerClass = aClass;
}
/**
<p>Create a window server with attributes, which contains key/value
pairs which describe the specifics of how the window server is to
be initialized. Typically these values are specific to the
concrete implementation. The current set of attributes that can be
used with GSDisplayServer is.
</p>
<list>
<item>GSDisplayName</item>
<item>GSDisplayNumber</item>
<item>GSScreenNumber</item>
</list>
<p>
GSDisplayName is window server specific and shouldn't be used when
creating a GSDisplayServer (although you can retrieve the value with
the -attributes method). On X-Windows the value might be set to something
like "host:d.s" where host is the host name, d is the display number and
s is the screen number. GSDisplayNumber indicates the number of the
display to open. GSScreenNumber indicates the number of the screen to
display on. If not explicitly set, these attributes may be taked from
environment variables or from other operating specific information.
</p>
<p>In almost all applications one would only create a
single instance of a window server. Although it is possible, it is
unlikely that you would need more than one window server (and you
would have to be very careful how you handled window creation and
events in this case).</p>
*/
+ (GSDisplayServer *) serverWithAttributes: (NSDictionary *)attributes
{
GSDisplayServer *server;
if (windowmaps == NULL)
{
windowmaps = NSCreateMapTable(NSNonOwnedPointerMapKeyCallBacks,
NSNonOwnedPointerMapValueCallBacks, 20);
}
if (self == [GSDisplayServer class])
{
server = [[defaultServerClass allocWithZone: _globalGSZone]
initWithAttributes: attributes];
}
else
server = [[self allocWithZone: _globalGSZone]
initWithAttributes: attributes];
return AUTORELEASE(server);
}
/**
Sets the current server that will be handling windows, events,
etc. This method must be called after a window server is created
in order to make it available to the rest of the GUI library
*/
+ (void) setCurrentServer: (GSDisplayServer *)server
{
NSMutableDictionary *dict = [[NSThread currentThread] threadDictionary];
if (server)
[dict setObject: server forKey: NSCurrentServerThreadKey];
else
[dict removeObjectForKey: NSCurrentServerThreadKey];
}
/** <init />
Initializes the server. This typically causes the receiver to
<em>connect</em> to the display (e.g. XOpenDisplay () on an X-Windows
server).
*/
- (id) initWithAttributes: (NSDictionary *)attributes
{
[super init];
server_info = [attributes mutableCopy];
event_queue = [[NSMutableArray allocWithZone: [self zone]]
initWithCapacity: 32];
drag_types = NSCreateMapTable(NSIntMapKeyCallBacks,
NSObjectMapValueCallBacks, 0);
return self;
}
/** Return information used to create the server */
- (NSDictionary *) attributes
{
return AUTORELEASE([server_info copy]);
}
/**
Causes the server to disconnect from the display. If the receiver
is the current server, it removes itself and sets the current
server to nil. Sending any more messages to the receiver after this
is likely to cause severe problems and probably crash the
application.
*/
- (void) closeServer
{
if (self == GSCurrentServer())
[GSDisplayServer setCurrentServer: nil];
}
- (void) dealloc
{
NSMapEnumerator enumerator;
void *key;
void *val;
/*
* Remove the display server from the windows map.
* This depends on a property of GNUstep map tables, that an
* enumerated object can safely be removed from the map.
*/
enumerator = NSEnumerateMapTable(windowmaps);
while (NSNextMapEnumeratorPair(&enumerator, &key, &val))
{
if (val == (void*)self)
{
NSMapRemove(windowmaps, key);
}
}
NSEndMapTableEnumeration(&enumerator);
DESTROY(server_info);
DESTROY(event_queue);
NSFreeMapTable(drag_types);
[super dealloc];
}
- glContextClass
{
return nil;
}
- glPixelFormatClass
{
return nil;
}
- (BOOL) handlesWindowDecorations
{
return YES;
}
/* Drag and drop support. */
/** Convienience method that calls -addDragTypes:toWindow: using the
server that controls win.
*/
+ (BOOL) addDragTypes: (NSArray*)types toWindow: (NSWindow *)win
{
return [GSServerForWindow(win) addDragTypes: types toWindow: win];
}
/** Convienience method that calls -removeDragTypes:fromWindow: using the
server that controls win.
*/
+ (BOOL) removeDragTypes: (NSArray*)types fromWindow: (NSWindow *)win
{
return [GSServerForWindow(win) removeDragTypes: types fromWindow: win];
}
/** Convienience method that calls -dragTypesForWindow: using the
server that controls win.
*/
+ (NSCountedSet*) dragTypesForWindow: (NSWindow *)win
{
return [GSServerForWindow(win) dragTypesForWindow: win];
}
/**
* Add (increment count by 1) each drag type to those registered
* for the window. If this results in a change to the types registered
* in the counted set, return YES, otherwise return NO.
* Subclasses should override this method, call 'super' and take
* appropriate action if the method returns 'YES'.
*/
- (BOOL) addDragTypes: (NSArray*)types toWindow: (NSWindow *)win
{
NSCountedSet *old = (NSCountedSet*)NSMapGet(drag_types, (void*)win);
NSEnumerator *drag_enum = [types objectEnumerator];
id type;
unsigned originalCount;
/*
* Make sure the set exists.
*/
if (old == nil)
{
old = [NSCountedSet new];
NSMapInsert(drag_types, (void*)win, (void*)(gsaddr)old);
RELEASE(old);
}
originalCount = [old count];
while ((type = [drag_enum nextObject]))
{
[old addObject: type];
}
if ([old count] == originalCount)
return NO;
return YES;
}
/**
* Remove (decrement count by 1) each drag type from those registered
* for the window. If this results in a change to the types registered
* in the counted set, return YES, otherwise return NO.
* If given 'nil' as the array of types, remove ALL.
* Subclasses should override this method, call 'super' and take
* appropriate action if the method returns 'YES'.
*/
- (BOOL) removeDragTypes: (NSArray*)types fromWindow: (NSWindow *)win
{
NSCountedSet *old = (NSCountedSet*)NSMapGet(drag_types, (void*)win);
NSEnumerator *drag_enum = [types objectEnumerator];
if (types == nil)
{
if (old == nil)
return NO;
NSMapRemove(drag_types, (void*)win);
return YES;
}
else if (old == nil)
{
return NO;
}
else
{
unsigned originalCount = [old count];
id o;
while ((o = [drag_enum nextObject]))
{
[old removeObject: o];
}
if ([old count] == originalCount)
return NO;
return YES;
}
}
/** Returns the drag types set for the window win. */
- (NSCountedSet*) dragTypesForWindow: (NSWindow *)win
{
return (NSCountedSet*)NSMapGet(drag_types, (void *)win);
}
/** Returns an instance of a class which implements the NSDraggingInfo
protocol. */
- (id <NSDraggingInfo>) dragInfo
{
return [GSDragView sharedDragView];
}
- (BOOL) slideImage: (NSImage*)image from: (NSPoint)from to: (NSPoint)to
{
return [GSSlideView _slideImage: image from: from to: to];
}
- (void) restrictWindow: (int)win toImage: (NSImage*)image
{
[self subclassResponsibility: _cmd];
}
- (int) findWindowAt: (NSPoint)screenLocation
windowRef: (int*)windowRef
excluding: (int)win
{
[self subclassResponsibility: _cmd];
return 0;
}
/* Screen information */
/** Returns the resolution, in points, for the indicated screen of the
display. */
- (NSSize) resolutionForScreen: (int)screen
{
/*[self subclassResponsibility: _cmd];*/
return NSMakeSize(72, 72);
}
/** Returns the bounds, in pixels, for the indicated screen of the
display. */
- (NSRect) boundsForScreen: (int)screen
{
[self subclassResponsibility: _cmd];
return NSZeroRect;
}
/** Returns the default depth of windows that are created on screen. */
- (NSWindowDepth) windowDepthForScreen: (int)screen
{
[self subclassResponsibility: _cmd];
return 0;
}
/** Returns a null terminated list of possible window depths for
screen. */
- (const NSWindowDepth *) availableDepthsForScreen: (int)screen
{
[self subclassResponsibility: _cmd];
return NULL;
}
/**
Returns an array of NSNumbers, where each number describes a screen
that is available on this display. The default screen is listed first.
*/
- (NSArray *) screenList
{
[self subclassResponsibility: _cmd];
return nil;
}
/**
Returns a display dependant pointer that describes the internal
connection to the display. On X-Windows, for example, this is a
pointer to the <code>Display</code> variable. */
- (void *) serverDevice
{
[self subclassResponsibility: _cmd];
return NULL;
}
/**
Returns a display dependant pointer that describes the internal
window representation for win. On X-Windows, for example, this is a
pointer to the <code>Window</code> variable. */
- (void *) windowDevice: (int)win
{
[self subclassResponsibility: _cmd];
return NULL;
}
/** Play the System Beep */
- (void) beep
{
[self subclassResponsibility: _cmd];
}
/**
Returns a display dependent NSImage which will be used as the background
image for AppIcons and MiniWindows. Under Windowmaker, for example this
could be a user specified gradient. */
- (NSImage *) iconTileImage
{
return [NSImage imageNamed: @"common_Tile"];
}
/** Returns the size of icons and miniwindows for screen. */
- (NSSize) iconSize
{
return NSMakeSize(64.0, 64.0);
}
@end
/* ----------------------------------------------------------------------- */
/* GNUstep Window operations */
/* ----------------------------------------------------------------------- */
@implementation GSDisplayServer (WindowOps)
/** Tells the receiver that it owns the window described by
win. Concrete subclasses must call this function when creating a
window. Do not call this method in any other case, particularly
for a window that has already been created */
- (void) _setWindowOwnedByServer: (int)win
{
NSMapInsert (windowmaps, (void*)win, self);
}
/** Creates a window whose location and size is described by frame and
whose backing store is described by type. This window is not
mapped to the screen by this call.
Note that frame is the frame of the drawable window and does not include
any external window decorations. If handlesWindowDecorations returns YES,
a window manager (or something equivalent) might add decorations outside
the drawable window. Use -styleoffsets::::: to determine the extent of
those decorations.
*/
- (int) window: (NSRect)frame : (NSBackingStoreType)type : (unsigned int)style
{
int sn = [[server_info objectForKey: GSScreenNumber] intValue];
return [self window: frame : type : style : sn];
}
/** Like -window::: only there is an additional argument to specify which
screen the window will display on */
- (int) window: (NSRect)frame : (NSBackingStoreType)type : (unsigned int)style
: (int)screen
{
[self subclassResponsibility: _cmd];
return 0;
}
/** Destroys the representation of the window and frees and memory
associated with it. */
- (void) termwindow: (int) win
{
[self subclassResponsibility: _cmd];
}
/** Sets the style of the window. See [NSWindow-styleMask] for a
description of the available styles */
- (void) stylewindow: (unsigned int) style : (int) win
{
[self subclassResponsibility: _cmd];
}
/** Changes window's the backing store to type */
- (void) windowbacking: (NSBackingStoreType)type : (int) win
{
[self subclassResponsibility: _cmd];
}
/** Sets the window title */
- (void) titlewindow: (NSString *) window_title : (int) win
{
[self subclassResponsibility: _cmd];
}
/** Miniaturizes the window */
- (void) miniwindow: (int) win
{
[self subclassResponsibility: _cmd];
}
/** Returns YES if the application should create the miniwindow counterpart
to the full size window and own it. Some display systems handle the
miniwindow themselves. In this case the backend subclass should
override this method to return NO. */
- (BOOL) appOwnsMiniwindow
{
return YES;
}
/** Sets the window device information for the current NSGraphicsContext,
typically by calling [NSGraphicsContext-GSSetDevice:::],
although depending on the concrete implmentation, more information
than this may need to be exchanged. */
- (void) windowdevice: (int) win
{
[self subclassResponsibility: _cmd];
}
/** Causes the window to be ordered onto or off the screen depending
on the value of op. The window is ordered relative to otherWin.
The window will never be ordered in front of the current key/main
window except in the special case where otherWin is negative (This
is a special feature that [NSWindow-orderWindow:relativeTo:] uses
to place the window correctly).
*/
- (void) orderwindow: (int) op : (int) otherWin : (int) win
{
[self subclassResponsibility: _cmd];
}
/** Moves the bottom left cornder of the window to loc */
- (void) movewindow: (NSPoint)loc : (int) win
{
[self subclassResponsibility: _cmd];
}
/** Moves and resizes the window on the screen as described by frame. */
- (void) placewindow: (NSRect)frame : (int) win
{
[self subclassResponsibility: _cmd];
}
/** Returns the frame of the window on the screen */
- (NSRect) windowbounds: (int) win
{
[self subclassResponsibility: _cmd];
return NSZeroRect;
}
/** Set the level of the window as in [NSWindow -setLevel] */
- (void) setwindowlevel: (int) level : (int) win
{
[self subclassResponsibility: _cmd];
}
/** Returns the window level as in [NSWindow -level] */
- (int) windowlevel: (int) win
{
[self subclassResponsibility: _cmd];
return 0;
}
/** Returns the list of windows that the server controls */
- (NSArray *) windowlist
{
[self subclassResponsibility: _cmd];
return nil;
}
/** Returns the depth of the window */
- (int) windowdepth: (int) win
{
[self subclassResponsibility: _cmd];
return 0;
}
/** Set the maximum size of the window */
- (void) setmaxsize: (NSSize)size : (int) win
{
[self subclassResponsibility: _cmd];
}
/** Set the minimum size of the window */
- (void) setminsize: (NSSize)size : (int) win
{
[self subclassResponsibility: _cmd];
}
/** Set the resize incremenet of the window */
- (void) setresizeincrements: (NSSize)size : (int) win
{
[self subclassResponsibility: _cmd];
}
/** Causes buffered graphics to be flushed to the screen */
- (void) flushwindowrect: (NSRect)rect : (int) win
{
[self subclassResponsibility: _cmd];
}
/** Returns the dimensions of window decorations added outside the drawable
window frame by a window manager or equivalent. For instance, t
gives the height of the title bar for the window. The values returned
may be approximations. If handlesWindowDecorations returns NO, there
are no decorations outside the drawable window frame and this method
shouldn't be called. */
- (void) styleoffsets: (float*) l : (float*) r : (float*) t : (float*) b
: (unsigned int) style
{
[self subclassResponsibility: _cmd];
}
/** Sets the document edited flag for the window */
- (void) docedited: (int) edited : (int) win
{
[self subclassResponsibility: _cmd];
}
/** Sets the input state for the window given by the
GSWindowInputState constant. Instructs the window manager that the
specified window is 'key', 'main', or just a normal window. */
- (void) setinputstate: (int)state : (int)win
{
[self subclassResponsibility: _cmd];
}
/** Forces focus to the window so that all key events are sent to this
window */
- (void) setinputfocus: (int) win
{
[self subclassResponsibility: _cmd];
}
/** Sets the transparancy value for the whole window */
- (void) setalpha: (float)alpha: (int) win
{
//[self subclassResponsibility: _cmd];
}
/** Returns the current mouse location on the default screen. If the
pointer is not on the default screen, an invalid point (-1,-1} is
returned. */
- (NSPoint) mouselocation
{
[self subclassResponsibility: _cmd];
return NSZeroPoint;
}
/** Returns the current mouse location on aScreen. If the pointer is
not on aScreen, this method acts like -mouselocation. If aScreen is -1,
then the location of the mouse on any screen is returned. The
win pointer returns the window number of the GNUstep window
that the mouse is in or 0 if it is not in a window. */
- (NSPoint) mouseLocationOnScreen: (int)aScreen window: (int *)win
{
[self subclassResponsibility: _cmd];
return NSZeroPoint;
}
/** Grabs the pointer device so that all future mouse events will be
directed only to the window win. If successful, the return value
is YES and this message must be balanced by a -releasemouse
message. */
- (BOOL) capturemouse: (int) win
{
[self subclassResponsibility: _cmd];
return NO;
}
/** Release a previous captured mouse from -capturemouse: */
- (void) releasemouse
{
[self subclassResponsibility: _cmd];
}
/** Hides the cursor */
- (void) hidecursor
{
[self subclassResponsibility: _cmd];
}
/** Show a previously hidden cursor */
- (void) showcursor
{
[self subclassResponsibility: _cmd];
}
/** Create a standard cursor (such as an arror or IBeam). Returns a
pointer to the internal device representation that can be used
later to make this cursor the current one
*/
- (void) standardcursor: (int) style : (void**) cid
{
[self subclassResponsibility: _cmd];
}
/** Create a cursor from an image. Returns a pointer to the internal
device representation that can be used later to make this cursor
the current one */
- (void) imagecursor: (NSPoint)hotp : (int)w : (int)h : (int) colors
: (const unsigned char *) image : (void**) cid
{
[self subclassResponsibility: _cmd];
}
/** Set the cursor given by the cid representation as being the
current cursor. The cursor has a foreground color fg and a
background color bg. To keep the default color for the cursor, pass
nil for fg and bg. */
- (void) setcursorcolor: (NSColor *)fg : (NSColor *)bg : (void*) cid
{
[self subclassResponsibility: _cmd];
}
@end
/* ----------------------------------------------------------------------- */
/* GNUstep Event Operations */
/* ----------------------------------------------------------------------- */
@implementation GSDisplayServer (EventOps)
- (NSEvent*) getEventMatchingMask: (unsigned)mask
beforeDate: (NSDate*)limit
inMode: (NSString*)mode
dequeue: (BOOL)flag
{
unsigned pos = 0; /* Position in queue scanned so far */
NSRunLoop *loop = nil;
do
{
unsigned count = [event_queue count];
NSEvent *event;
unsigned i = 0;
if (count == 0)
{
event = nil;
}
else if (mask == NSAnyEventMask)
{
/*
* Special case - if the mask matches any event, we just get the
* first event on the queue.
*/
event = [event_queue objectAtIndex: 0];
}
else
{
event = nil;
/*
* Scan the queue from the last position we have seen, up to the end.
*/
if (count > pos)
{
unsigned end = count - pos;
NSRange r = NSMakeRange(pos, end);
NSEvent *events[end];
[event_queue getObjects: events range: r];
for (i = 0; i < end; i++)
{
if (mask & NSEventMaskFromType([events[i] type]))
{
event = events[i];
break;
}
}
}
}
/*
* Note the positon we have read up to.
*/
pos += i;
/*
* If we found a matching event, we (depending on the flag) de-queue it.
* We return the event RETAINED - the caller must release it.
*/
if (event)
{
RETAIN(event);
if (flag)
{
[event_queue removeObjectAtIndex: pos];
}
return AUTORELEASE(event);
}
if (loop == nil)
{
loop = [NSRunLoop currentRunLoop];
}
if ([loop runMode: mode beforeDate: limit] == NO)
{
break; // Nothing we can do ... no input handlers.
}
}
while ([limit timeIntervalSinceNow] > 0.0);
return nil; /* No events in specified time */
}
- (void) discardEventsMatchingMask: (unsigned)mask
beforeEvent: (NSEvent*)limit
{
unsigned index = [event_queue count];
/*
* If there is a range to use - remove all the matching events in it
* which were created before the specified event.
*/
if (index > 0)
{
NSTimeInterval when = [limit timestamp];
NSEvent *events[index];
[event_queue getObjects: events];
while (index-- > 0)
{
NSEvent *event = events[index];
if ([event timestamp] < when)
{
if ((mask == NSAnyEventMask) ||
(mask & NSEventMaskFromType([event type])))
[event_queue removeObjectAtIndex: index];
}
}
}
}
- (void) postEvent: (NSEvent*)anEvent atStart: (BOOL)flag
{
if (flag)
[event_queue insertObject: anEvent atIndex: 0];
else
[event_queue addObject: anEvent];
}
@end
|