source: branches/CoreData/SapphireFrappliance/Browser/SapphireTextEntryController.m @ 729

Revision 729, 3.5 KB checked in by gbooker, 5 years ago (diff)

Added mark and display menus to the main menu (collections).
Added ability to rename a collection. This is transitory until #264 is complete.
Fixes #254 Refs #264

Line 
1/*
2 * SapphireTextEntryController.m
3 * Sapphire
4 *
5 * Created by Graham Booker on Jan. 6, 2009.
6 * Copyright 2009 Sapphire Development Team and/or www.nanopi.net
7 * All rights reserved.
8 *
9 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
10 * General Public License as published by the Free Software Foundation; either version 3 of the License,
11 * or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
14 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
15 * Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along with this program; if not,
18 * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19 */
20
21#import "SapphireTextEntryController.h"
22#import <SapphireCompatClasses/SapphireFrontRowCompat.h>
23
24@interface BRControl (compat)
25- (void)setName:(NSString *)name;
26@end
27
28@interface BRLayerController (compat)
29- (void)setLayoutManager:(id)layoutManager;
30@end
31
32
33@interface SapphireTextEntryController (private)
34- (void)layoutFrame;
35@end
36
37@implementation SapphireTextEntryController
38
39- (id)initWithScene:(BRRenderScene *)scene title:(NSString *)titleText defaultText:(NSString *)defaultText completionInvocation:(NSInvocation *)completetion
40{
41        self = [super initWithScene:scene];
42        if(!self)
43                return nil;
44       
45        title = [SapphireFrontRowCompat newTextControlWithScene:scene];
46        [SapphireFrontRowCompat setText:titleText withAtrributes:[[BRThemeInfo sharedTheme] paragraphTextAttributes] forControl:title];
47        [self addControl:title];
48
49        textEntry = [SapphireFrontRowCompat newTextEntryControlWithScene:scene];
50        [textEntry setInitialText:defaultText];
51        [textEntry setTextEntryCompleteDelegate:self];
52       
53        entryComplete = [completetion retain];
54       
55        [self addControl:textEntry];
56       
57        //The built in layout manager does a good job here, so fool it with naming of our layers
58        Class layoutManagerClass = NSClassFromString(@"BRTextEntryMenuLayoutManager");
59        if(layoutManagerClass != nil)
60        {
61                [title setName:@"header"];
62                [textEntry setName:@"editor"];
63                id layoutManager = [[layoutManagerClass alloc] init];
64                [self setLayoutManager:layoutManager];
65                [layoutManager release];
66        }
67        else
68        {
69                [self layoutFrame];
70        }
71
72        return self;
73}
74
75- (void) dealloc
76{
77        [title release];
78        [textEntry release];
79        [entryComplete release];
80        [super dealloc];
81}
82
83
84- (void)layoutFrame
85{
86#warning These need to be tuned for 1.1, but since I do not have 1.1 here, I cannot test them.
87        NSRect master = [SapphireFrontRowCompat frameOfController:self];
88        NSSize txtSize = [SapphireFrontRowCompat textControl:title renderedSizeWithMaxSize:NSMakeSize(master.size.width * 2.0f/3.0f, master.size.height * 1.0f / 3.0f)];
89       
90        NSRect frame;
91        frame.origin.x = (master.size.width - txtSize.width) * 0.5f;
92        frame.origin.y = (master.size.height * 1.0f / 3.0f - txtSize.height) * 0.5f + master.size.height * 2.0f/3.0f + master.origin.y;
93        frame.size = txtSize;
94        [title setFrame:frame];
95
96        frame = master;
97        frame.size.height = frame.size.height * 2.0f / 3.0f;
98       
99       
100        NSLog(@"Setting frame to %f %f %f %f", frame.origin.x, frame.origin.y, frame.size.width, frame.size.height);
101        [textEntry setFrame:frame];
102}
103
104- (void)textDidChange:(id)sender
105{
106        //Do nothing
107}
108
109- (void)textDidEndEditing:(id)sender
110{
111        NSString *str = [textEntry stringValue];
112        [entryComplete setArgument:&str atIndex:2];
113        [entryComplete invoke];
114        [[self stack] popController];
115}
116
117@end
Note: See TracBrowser for help on using the repository browser.