]> err.no Git - sope/blob - sopex/SOPEX/SOPEXTextView.m
fixed a warning
[sope] / sopex / SOPEX / SOPEXTextView.m
1 /*
2  Copyright (C) 2004 Marcus Mueller <znek@mulle-kybernetik.com>
3
4  This file is part of OGo
5
6  OGo is free software; you can redistribute it and/or modify it under
7  the terms of the GNU Lesser General Public License as published by the
8  Free Software Foundation; either version 2, or (at your option) any
9  later version.
10
11  OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12  WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
14  License for more details.
15
16  You should have received a copy of the GNU Lesser General Public
17  License along with OGo; see the file COPYING.  If not, write to the
18  Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
19  02111-1307, USA.
20  */
21 // $Id: SOPEXTextView.m 1 2004-08-20 11:17:52Z znek $
22 //  Created by znek on Thu Apr 01 2004.
23
24
25 #import "SOPEXTextView.h"
26
27
28 @interface SOPEXTextView (PrivateAPI)
29 - (void)adjustStatusField;
30 @end
31
32
33 @implementation SOPEXTextView
34
35 - (void)awakeFromNib
36 {
37     [self setErrorStatus:nil];
38 }
39
40 - (void)setErrorStatus:(NSError *)status
41 {
42     if((status != nil) && (self->statusField != nil))
43     {
44         [self->statusField setStringValue:[status localizedDescription]];
45         [self adjustStatusField];
46         [self->statusField setHidden:NO];
47         [[self window] makeFirstResponder:self->statusField];
48     }
49     else
50     {
51         [self->statusField setHidden:YES];
52     }
53 }
54
55 - (void)adjustStatusField
56 {
57     NSRect frame, sfFrame;
58
59     frame = [[self superview] frame]; // superview is a clipview
60     frame = [self convertRect:frame toView:[self->statusField superview]];
61     [self->statusField sizeToFit];
62     sfFrame = [self->statusField frame];
63     sfFrame.origin.x = NSWidth(frame) - NSWidth(sfFrame) + 1.0;
64     sfFrame.origin.y = NSMaxY(frame) - NSHeight(sfFrame) + 1.0;
65     [self->statusField setFrame:sfFrame];
66 }
67
68 #if SOPEXTextViewNotifiesAboutResponderState
69 - (void)setDelegate:(id)delegate
70 {
71     [super setDelegate:delegate];
72     delegateFlags.respondsToWillBecomeFirstResponder = [delegate respondsToSelector:@selector(textViewWillBecomeFirstResponder:)];
73     delegateFlags.respondsToWillResignFirstResponder = [delegate respondsToSelector:@selector(textViewWillResignFirstResponder:)];
74 }
75 #endif
76
77 - (BOOL)becomeFirstResponder
78 {
79     BOOL yn;
80     
81     yn = [super becomeFirstResponder];
82 #if SOPEXTextViewNotifiesAboutResponderState
83     if(yn && delegateFlags.respondsToWillBecomeFirstResponder)
84         [[self delegate] textViewWillBecomeFirstResponder:self];
85 #endif
86     [self->statusField setHidden:YES];
87     return yn;
88 }
89
90 - (BOOL)resignFirstResponder
91 {
92     BOOL yn;
93     
94     yn = [super resignFirstResponder];
95 #if SOPEXTextViewNotifiesAboutResponderState
96     if(yn && delegateFlags.respondsToWillResignFirstResponder)
97         [[self delegate] textViewWillResignFirstResponder:self];
98 #endif
99     return yn;
100 }
101
102 @end