File: GSMarkupTagControl.m

package info (click to toggle)
renaissance 0.9.0-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,028 kB
  • sloc: objc: 12,332; makefile: 33; perl: 25
file content (200 lines) | stat: -rw-r--r-- 5,589 bytes parent folder | download | duplicates (5)
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/* -*-objc-*-
   GSMarkupTagControl.m

   Copyright (C) 2002 Free Software Foundation, Inc.

   Author: Nicola Pero <n.pero@mi.flashnet.it>
   Date: March 2002

   This file is part of GNUstep Renaissance

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.
   
   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public
   License along with this library; see the file COPYING.LIB.
   If not, write to the Free Software Foundation,
   59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <TagCommonInclude.h>
#include "GSMarkupTagControl.h"


#ifndef GNUSTEP
# include <Foundation/Foundation.h>
# include <AppKit/AppKit.h>
# include "GNUstep.h"
#else
# include <Foundation/NSString.h>
# include <Foundation/NSDictionary.h>
# include <AppKit/NSControl.h>
#endif

@implementation GSMarkupTagControl

+ (NSString *) tagName
{
  return @"control";
}

+ (Class) platformObjectClass
{
  return [NSControl class];
}

- (id) initPlatformObject: (id)platformObject
{
  platformObject = [platformObject init];
  
  /* action */
  {
    NSString *action = [_attributes objectForKey: @"action"];
  
    if (action != nil)    
      {
	SEL selector = NSSelectorFromString (action);
	if (selector == NULL)
	  {
	    NSLog (@"Warning: <%@> has non-existing action '%@'.  Ignored.",
		   [[self class] tagName], action);
	  }
	else
	  {
	    [platformObject setAction: selector];
	  }
      }
  }

  /* continuous */
  {
    int continuous = [self boolValueForAttribute: @"continuous"];
    
    if (continuous == 1)
      {
	[platformObject setContinuous: YES];
      }
    else if (continuous == 0)
      {
	[platformObject setContinuous: NO];
      }
  }

  /* enabled */
  {
    int enabled = [self boolValueForAttribute: @"enabled"];
    
    if (enabled == 1)
      {
	[platformObject setEnabled: YES];
      }
    else if (enabled == 0)
      {
	[platformObject setEnabled: NO];
      }
  }

  /* tag */
  {
    NSString *tag = [_attributes objectForKey: @"tag"];
    if (tag != nil)
      {
	[(NSControl *)platformObject setTag: [tag intValue]];
      }
  }

  /* sendActionOn */
  {
    NSString *sendActionOn = [_attributes objectForKey: @"sendActionOn"];
    if (sendActionOn != nil)
      {
	NSDictionary *maskValuesDictionary;
	int mask = -1;

	maskValuesDictionary 
	  = [NSDictionary
	      dictionaryWithObjectsAndKeys:
		[NSNumber numberWithInt: NSLeftMouseDownMask], @"leftMouseDown",
	      [NSNumber numberWithInt: NSLeftMouseUpMask], @"leftMouseUp",
	      [NSNumber numberWithInt: NSRightMouseDownMask], @"rightMouseDown",
	      [NSNumber numberWithInt: NSRightMouseUpMask], @"rightMouseUp",
	      [NSNumber numberWithInt: NSMouseMovedMask], @"mouseMoved",
	      [NSNumber numberWithInt: NSLeftMouseDraggedMask], @"leftMouseDragged",
	      [NSNumber numberWithInt: NSRightMouseDraggedMask], @"rightMouseDragged",
	      [NSNumber numberWithInt: NSMouseEnteredMask], @"mouseEntered",
	      [NSNumber numberWithInt: NSMouseExitedMask], @"mouseExited",
	      [NSNumber numberWithInt: NSKeyDownMask], @"keyDown",
	      [NSNumber numberWithInt: NSKeyUpMask], @"keyUp",
	      [NSNumber numberWithInt: NSFlagsChangedMask], @"flagsChanged",
	      [NSNumber numberWithInt: NSAppKitDefinedMask], @"appKeyDefined",
	      [NSNumber numberWithInt: NSSystemDefinedMask], @"systemDefined",
	      [NSNumber numberWithInt: NSApplicationDefinedMask], @"applicationDefined",
	      [NSNumber numberWithInt: NSPeriodicMask], @"periodic",
	      [NSNumber numberWithInt: NSCursorUpdateMask], @"cursorUpdate",
	      [NSNumber numberWithInt: NSScrollWheelMask], @"scrollWheel",
	      [NSNumber numberWithInt: NSOtherMouseDownMask], @"otherMouseDown",
	      [NSNumber numberWithInt: NSOtherMouseUpMask], @"otherMouseUp",
	      [NSNumber numberWithInt: NSOtherMouseDraggedMask], @"otherMouseDragged",
	      [NSNumber numberWithInt: NSAnyEventMask], @"anyEvent",
	     nil];

	mask = [self integerMaskValueForAttribute: @"sendActionOn"
		     withMaskValuesDictionary: maskValuesDictionary];
	[platformObject sendActionOn: mask];
      }
  }

  /* textAlignment */
  {
    NSString *alignment = [_attributes objectForKey: @"textAlignment"];

    /* Backwards-compatible check introduced on 27 Feb 2008, will be
     * removed on 27 Feb 2009.
     */
    if (alignment == nil)
      {
	/* Check for the old name "align"  */
	alignment = [_attributes objectForKey: @"align"];

	if (alignment != nil)
	  {
	    NSLog (@"The 'align' attribute has been renamed to 'textAlignment'.  Please update your gsmarkup files");
	  }
      }
    
    if (alignment != nil)
      {
	if ([alignment isEqualToString: @"left"])
	  {
	    [platformObject setAlignment: NSLeftTextAlignment];
	  }
	else if ([alignment isEqualToString: @"right"])
	  {
	    [platformObject setAlignment: NSRightTextAlignment];
	  }
	else if ([alignment isEqualToString: @"center"])    
	  {
	    [platformObject setAlignment: NSCenterTextAlignment];
	  }
      }
  }

  /* font */
  {
    NSFont *f = [self fontValueForAttribute: @"font"];
    if (f != nil)
      {
	[platformObject setFont: f];
      }
  }

  return platformObject;
}

@end