summaryrefslogtreecommitdiff
path: root/macosx/plugins/PeopsXgl/macsrc/PluginWindow.m
blob: 9a45eb580a1d198e5106d03c9094514e3fcde15f (plain) (blame)
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
/***************************************************************************
    PluginWindow.m
    PeopsSoftGPU
  
    Created by Gil Pedersen on Wed April 21 2004.
    Copyright (c) 2004 Gil Pedersen.
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version. See also the license.txt file for *
 *   additional informations.                                              *
 *                                                                         *
 ***************************************************************************/

#import "PluginWindow.h"
@implementation NetSfPeopsOpenGLGPUPluginWindow
{
	NSWindow* myParent;
	NSPoint initialLocation;
}
/*
- (BOOL)windowShouldClose:(id)sender
{
	[[NSNotificationCenter defaultCenter] postNotificationName:@"emuWindowDidClose" object:self];
	
	return YES;
}*/

- (void)sendEvent:(NSEvent *)theEvent
{
	NSEventType type = [theEvent type];
	if (type == NSKeyDown || type == NSKeyUp) {
		if (type == NSKeyDown && [theEvent keyCode] == 53 /* escape */) {
			// reroute to menu event
			[[NSApp mainMenu] performKeyEquivalent:theEvent];
		}
		
		// ignore all key Events
		return;
	}

	[super sendEvent:theEvent];
}

- (void) windowDidResize:(NSNotification*)notice
{
}

- (void) windowDidUpdate: (NSNotification*)notice
{
}

- (void)windowDidMove:(NSNotification *)notification
{

}

- (BOOL) canBecomeKeyWindow
{
    return YES;
}

- (void)keyDown:(NSEvent *)theEvent
{
}

- (void)keyUp:(NSEvent *)theEvent
{
}

- (BOOL)validateMenuItem:(NSMenuItem*) menuItem
{
//    SEL bleh = [menuItem action];
//    NSLog(@"Validate: %@, action: %@", menuItem, NSStringFromSelector(bleh));
    if ([menuItem action] == @selector(performClose:))
        return YES;
    
    return NO;
    
}

- (void) performClose: (id)sender
{
    if ([self delegate]){
  //      NSLog(@"We have a delegate %@", [self delegate]);

        if ([[self delegate] windowShouldClose:sender])
            [super close];
    }
    else {
        // hmm, just explode I guess
        [super close];
    }
}

- (void)mouseDown:(NSEvent *)theEvent {    

    // Get the mouse location in window coordinates.
    initialLocation = [theEvent locationInWindow];

}


/*

 Once the user starts dragging the mouse, move the window with it. The window has no title bar for the user to drag (so we have to implement dragging ourselves)

 */

- (void)mouseDragged:(NSEvent *)theEvent {

    if ([self level] == NSScreenSaverWindowLevel)
    // we don't drag when in fullscreen
    // note that it is only because a quirk in the ordering of events
    // and the time that NSScreenSaverWindowLevel is set
    // that we'll never be dragged while in the background
        return; 
        
    NSRect screenVisibleFrame = [[NSScreen mainScreen] visibleFrame];
    NSRect windowFrame = [self frame];
    NSPoint newOrigin = windowFrame.origin;

    // Get the mouse location in window coordinates.
    NSPoint currentLocation = [theEvent locationInWindow];

    // Update the origin with the difference between the new mouse location and the old mouse location.
    newOrigin.x += (currentLocation.x - initialLocation.x);
    newOrigin.y += (currentLocation.y - initialLocation.y);

    // Don't let window get dragged up under the menu bar
    if ((newOrigin.y + windowFrame.size.height) > (screenVisibleFrame.origin.y + screenVisibleFrame.size.height)) {
        newOrigin.y = screenVisibleFrame.origin.y + (screenVisibleFrame.size.height - windowFrame.size.height);
    }

    // Move the window to the new location
    [self setFrameOrigin:newOrigin];

}

@end