forked from adlr/formulatepro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FPDocumentWindow.m
111 lines (96 loc) · 2.85 KB
/
FPDocumentWindow.m
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
//
// FPDocumentWindow.m
// FormulatePro
//
// Created by Andrew de los Reyes on 12/17/06.
// Copyright 2006 Andrew de los Reyes. All rights reserved.
//
#import "FPDocumentWindow.h"
#import "FPLogging.h"
#import "FPToolPaletteController.h"
NSString *FPBeginQuickMove = @"FPBeginQuickMove";
NSString *FPAbortQuickMove = @"FPAbortQuickMove";
NSString *FPEndQuickMove = @"FPEndQuickMove";
enum {FPDeleteKey = 0x7f};
@implementation FPDocumentWindow
- (void)changeFont:(id)sender
{
DLog(@"font changed.\n");
//NSFont *oldFont = [self selectionFont];
NSFont *newFont = [sender convertFont:_defaultFont];
DLog(@"old %@, new %@\n", _defaultFont, newFont);
if (_defaultFont != newFont) {
[_defaultFont release];
_defaultFont = [newFont retain];
}
return;
}
- (void)changeColor:(id)sender
{
if ([_docView handleColorChange:[sender color]])
return;
DLog(@"default color changed. doc win\n");
NSColor *newColor = [sender color];
if (_defaultColor != newColor) {
[_defaultColor release];
_defaultColor = [newColor retain];
}
}
- (NSColor *)currentColor {
return _defaultColor;
}
- (FPDocumentView *)docView
{
return _docView;
}
- (NSFont *)currentFont
{
return _defaultFont;
}
- (BOOL)becomeFirstResponder
{
DLog(@"becomeFirstResponder\n");
return YES;
}
- (void)awakeFromNib
{
_sentQuickMove = NO;
_defaultFont = [[NSFont userFontOfSize:0.0] retain];
_defaultColor = [[NSColor blackColor] retain];
}
- (void)keyDown:(NSEvent *)theEvent
{
//if ([theEvent modifierFlags]) return;
//[theEvent keyCode]
DLog(@"fp doc window got keys: [%@][%x][%x]\n",
[theEvent charactersIgnoringModifiers],
(unsigned)[[theEvent charactersIgnoringModifiers] characterAtIndex:0],
(unsigned)NSDeleteFunctionKey);
if (FPDeleteKey ==
[[theEvent charactersIgnoringModifiers] characterAtIndex:0]) {
[_docView deleteSelectedGraphics];
} else {
// perhaps it's a keypress to select a tool
[[FPToolPaletteController sharedToolPaletteController] keyDown:theEvent];
}
}
- (void)flagsChanged:(NSEvent *)theEvent
{
DLog(@"flags changed\n");
if ((NO == _sentQuickMove) &&
([theEvent modifierFlags] & NSAlternateKeyMask) &&
([theEvent modifierFlags] & NSCommandKeyMask) &&
([_docView shouldEnterQuickMove])) {
DLog(@"got apple-option\n");
[[NSNotificationCenter defaultCenter] postNotification:
[NSNotification notificationWithName:FPBeginQuickMove
object:self]];
_sentQuickMove = YES;
} else if (YES == _sentQuickMove) {
DLog(@"don't got apple-option\n");
[[NSNotificationCenter defaultCenter] postNotification:
[NSNotification notificationWithName:FPEndQuickMove object:self]];
_sentQuickMove = NO;
}
}
@end