1/*
2  GormTextFieldAttributesInspector.m
3
4   Copyright (C) 2001-2005 Free Software Foundation, Inc.
5
6   Author:  Adam Fedor <fedor@gnu.org>
7              Laurent Julliard <laurent@julliard-online.org>
8   Date: Aug 2001
9
10   This file is part of GNUstep.
11
12   This program is free software; you can redistribute it and/or modify
13   it under the terms of the GNU General Public License as published by
14   the Free Software Foundation; either version 3 of the License, or
15   (at your option) any later version.
16
17   This program is distributed in the hope that it will be useful,
18   but WITHOUT ANY WARRANTY; without even the implied warranty of
19   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20   GNU General Public License for more details.
21
22   You should have received a copy of the GNU General Public License
23   along with this program; if not, write to the Free Software
24   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA.
25*/
26
27/*
28  July 2005 : Split inspector classes into separate files.
29  Always use ok: revert: methods
30  Clean up
31  Author : Fabien Vallon <fabien@sonappart.net>
32*/
33
34
35#include "GormTextFieldAttributesInspector.h"
36
37#include <GormCore/NSColorWell+GormExtensions.h>
38
39#include <Foundation/NSNotification.h>
40
41#include <AppKit/NSButton.h>
42#include <AppKit/NSForm.h>
43#include <AppKit/NSMatrix.h>
44#include <AppKit/NSNibLoading.h>
45#include <AppKit/NSTextField.h>
46
47
48/*
49  IBObjectAdditions category
50*/
51
52@implementation	NSTextField (IBObjectAdditions)
53
54- (NSString*) inspectorClassName
55{
56  return @"GormTextFieldAttributesInspector";
57}
58@end
59
60
61@implementation GormTextFieldAttributesInspector
62
63- (id) init
64{
65  if ([super init] == nil)
66    return nil;
67
68
69  if ([NSBundle loadNibNamed: @"GormNSTextFieldInspector" owner: self] == NO)
70    {
71      NSLog(@"Could not gorm GormTextFieldInspector");
72      return nil;
73    }
74
75  return self;
76}
77
78
79/* Commit changes that the user makes in the Attributes Inspector */
80- (void) ok: (id) sender
81{
82  if (sender == alignMatrix)
83    {
84      [object setAlignment: (NSTextAlignment)[[sender selectedCell] tag]];
85    }
86  else if (sender == backgroundColor)
87    {
88      [object setBackgroundColor: [sender color]];
89    }
90  else if (sender == drawsBackground)
91    {
92      [object setDrawsBackground: [drawsBackground state]];
93    }
94  else if (sender == textColor)
95    {
96      [object setTextColor: [sender color]];
97    }
98  else if ( sender == editableSwitch )
99    {
100      [object setEditable: [editableSwitch state]];
101    }
102  else if  ( sender == selectableSwitch )
103    {
104      [object setSelectable: [selectableSwitch state]];
105    }
106  else if ( sender == scrollableSwitch )
107    {
108      [[object cell] setScrollable: [scrollableSwitch state]];
109    }
110  else if (sender == borderMatrix)
111    {
112      BOOL bordered=NO, bezeled=NO;
113
114      if ([[sender cellAtRow: 0 column: 0] state] == NSOnState)
115	{
116	  bordered = bezeled = NO;
117	}
118      else if ([[sender cellAtRow: 0 column: 1] state] == NSOnState)
119        {
120          bordered = YES;
121          bezeled = NO;
122        }
123      else if ([[sender cellAtRow: 0 column: 2] state] == NSOnState)
124	{
125	  bordered = NO; bezeled = YES;
126	}
127      [object setBordered: bordered];
128      [object setBezeled: bezeled];
129    }
130  else if (sender == tagForm)
131    {
132      [object setTag: [[sender cellAtIndex: 0] intValue]];
133    }
134  else if (sender == sendActionMatrix)
135    {
136      BOOL sendActionOnEndEditing = ([[sender cellAtRow: 1 column: 0] state] == NSOnState);
137      [[object cell] setSendsActionOnEndEditing: sendActionOnEndEditing];
138    }
139
140  [super ok:sender];
141}
142
143/* Sync from object ( NSTextField ) changes to the inspector   */
144- (void) revert:(id) sender
145{
146  if (object == nil)
147    return;
148
149  [alignMatrix selectCellWithTag: [object alignment]];
150  [backgroundColor setColorWithoutAction: [object backgroundColor]];
151  [textColor setColorWithoutAction: [object textColor]];
152  [drawsBackground setState:
153		     ([object drawsBackground]) ? NSOnState : NSOffState];
154
155  [editableSwitch setState:[object isEditable]];
156  [selectableSwitch setState:[object isSelectable]];
157  [scrollableSwitch setState:[[object cell] isScrollable]];
158
159  if ([object isBordered] == YES)
160    {
161      [borderMatrix selectCellAtRow: 0 column: 1];
162    }
163  else
164    {
165      if ([object isBezeled] == YES)
166        [borderMatrix selectCellAtRow: 0 column: 2];
167      else
168        [borderMatrix selectCellAtRow: 0 column: 0];
169    }
170
171  [[tagForm cellAtIndex: 0] setIntValue: [object tag]];
172
173  if([[object cell] sendsActionOnEndEditing])
174    {
175      [sendActionMatrix selectCellAtRow: 1 column: 0];
176    }
177  else
178    {
179      [sendActionMatrix selectCellAtRow: 0 column: 0];
180    }
181
182  [super revert:sender];
183}
184
185
186/* delegate method for tagForm */
187-(void) controlTextDidChange:(NSNotification *)aNotification
188{
189  [self ok:[aNotification object]];
190}
191
192
193@end
194