1/*
2 Project: Graphos
3 GRTextEditor.m
4
5 Copyright (C) 2000-2015 GNUstep Application Project
6
7 Author: Enrico Sersale (original GDraw implementation)
8 Author: Ing. Riccardo Mottola
9
10 This application is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public
12 License as published by the Free Software Foundation; either
13 version 2 of the License, or (at your option) any later version.
14
15 This application is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 Library General Public License for more details.
19
20 You should have received a copy of the GNU General Public
21 License along with this library; if not, write to the Free
22 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
23 */
24
25
26#import "GRTextEditor.h"
27
28@implementation GRTextEditor
29
30- (id)initEditor:(GRDrawableObject *)anObject
31{
32    unsigned int style = NSTitledWindowMask | NSResizableWindowMask;
33
34    self = [super initEditor:anObject];
35
36    if(self)
37    {
38        myWindow = [[NSWindow alloc] initWithContentRect: NSMakeRect(0, 0, 500, 300)
39                                styleMask: style
40                                  backing: NSBackingStoreBuffered
41                                    defer: NO];
42        isSelect = NO;
43        [myWindow setMaxSize: NSMakeSize(500, 2000)];
44        [myWindow setMinSize: NSMakeSize(500, 300)];
45        [myWindow setTitle: @"Text Editor"];
46        object = anObject;
47        myView = nil;
48    }
49    return self;
50}
51
52- (id)copyWithZone:(NSZone *)zone
53{
54  GRTextEditor *objCopy;
55
56  objCopy = (GRTextEditor *)[super copyWithZone:zone];
57
58  objCopy->myWindow = [myWindow retain];
59  objCopy->myView = nil;
60  objCopy->isSelect = isSelect;
61
62  return objCopy;
63}
64
65
66- (void)setPoint:(NSPoint)p
67      withString:(NSString *)string
68      attributes:(NSDictionary *)attributes
69{
70  if (myView == nil)
71    {
72      myView = [[GRTextEditorView alloc] initWithFrame: [myWindow frame] withString: string attributes: attributes];
73      [myWindow setContentView: myView];
74    }
75  [myWindow center];
76}
77
78- (int) runModal
79{
80  NSApplication *app = [NSApplication sharedApplication];
81  [myView setFirstResponder];
82  [app runModalForWindow: myWindow];
83  return [myView result];
84}
85
86- (void)dealloc
87{
88  [myView release];
89  [super dealloc];
90}
91
92- (GRTextEditorView *)editorView
93{
94    return myView;
95}
96
97
98- (void)selectAsGroup
99{
100    if([object locked])
101        return;
102    isSelect = YES;
103}
104
105- (void)unselect
106{
107    isSelect = NO;
108}
109
110- (BOOL)isSelected
111{
112    return isSelect;
113}
114
115- (BOOL)isGroupSelected
116{
117    return isSelect;
118}
119
120
121@end
122