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 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280
|
/* -*-objc-*-
GSMarkupTagView.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 "GSMarkupTagView.h"
#include "GSAutoLayoutDefaults.h"
#ifndef GNUSTEP
# include <Foundation/Foundation.h>
# include <AppKit/AppKit.h>
# include "GNUstep.h"
#else
# include <Foundation/NSString.h>
# include <AppKit/NSView.h>
#endif
#include <NSViewSize.h>
@implementation GSMarkupTagView
+ (NSString *) tagName
{
return @"view";
}
+ (Class) defaultPlatformObjectClass
{
return [NSView class];
}
+ (BOOL) useInstanceOfAttribute
{
return YES;
}
- (void) platformObjectInit
{
[self setPlatformObject: [_platformObject init]];
/* nextKeyView, previousKeyView are outlets :-), done
* automatically. */
}
/* This is done at init time, but should be done *after* all other
* initialization - so it is in a separate method which subclasses
* can/must call at the end of their platformObjectInit method. */
- (void) platformObjectAfterInit
{
[(NSView *)_platformObject sizeToFitContent];
/* Now set the hardcoded frame if any. */
{
NSRect frame = [_platformObject frame];
NSString *x, *y, *width, *height;
BOOL needToSetFrame = NO;
x = [_attributes objectForKey: @"x"];
if (x != nil)
{
frame.origin.x = [x floatValue];
needToSetFrame = YES;
}
y = [_attributes objectForKey: @"y"];
if (y != nil)
{
frame.origin.y = [y floatValue];
needToSetFrame = YES;
}
width = [_attributes objectForKey: @"width"];
if (width != nil)
{
float w = [width floatValue];
if (w > 0)
{
frame.size.width = w;
needToSetFrame = YES;
}
}
height = [_attributes objectForKey: @"height"];
if (height != nil)
{
float h = [height floatValue];
if (h > 0)
{
frame.size.height = h;
needToSetFrame = YES;
}
}
if (needToSetFrame)
{
[_platformObject setFrame: frame];
}
}
/* We don't normally use autoresizing masks, except in special
* cases: stuff contained inside NSBox objects mostly. As a
* simplification for those cases, by default we want a subview to
* get any autoresizing stuff which the superview generates (we will
* then always turn off generating the autoresizing in the superview
* except in the special cases).
*/
[_platformObject setAutoresizingMask:
NSViewWidthSizable | NSViewHeightSizable];
/* You can set autoresizing masks if you're trying to build views in the
* old hardcoded size style. Else, it's pretty useless.
*
* Subclasses have each one their own default autoresizing mask. We
* only modify the existing one if a different one is specified in
* the .gsmarkup file. The format for specifying them is as in
* autoresizingMask="hw" for NSViewHeightSizable |
* NSViewWidthSizable, and autoresizingMask="" for nothing,
* autoresizingMask="xXhy" for NSViewMinXMargin | NSViewMaxXMargin |
* NSViewHeightSizable | NSViewMinYMargin.
*/
{
unsigned autoresizingMask = [_platformObject autoresizingMask];
NSString *autoresizingMaskString = [_attributes objectForKey:
@"autoresizingMask"];
if (autoresizingMaskString != nil)
{
int i, count = [autoresizingMaskString length];
unsigned newAutoresizingMask = 0;
for (i = 0; i < count; i++)
{
unichar c = [autoresizingMaskString characterAtIndex: i];
switch (c)
{
case 'h':
newAutoresizingMask |= NSViewHeightSizable;
break;
case 'w':
newAutoresizingMask |= NSViewWidthSizable;
break;
case 'x':
newAutoresizingMask |= NSViewMinXMargin;
break;
case 'X':
newAutoresizingMask |= NSViewMaxXMargin;
break;
case 'y':
newAutoresizingMask |= NSViewMinYMargin;
break;
case 'Y':
newAutoresizingMask |= NSViewMaxYMargin;
break;
default:
break;
}
}
if (newAutoresizingMask != autoresizingMask)
{
[_platformObject setAutoresizingMask: newAutoresizingMask];
}
}
}
}
- (int) gsAutoLayoutHAlignment
{
NSString *halign;
if ([self boolValueForAttribute: @"hexpand"] == 1)
{
return GSAutoLayoutExpand;
}
halign = [_attributes objectForKey: @"halign"];
if (halign != nil)
{
if ([halign isEqualToString: @"expand"])
{
return GSAutoLayoutExpand;
}
else if ([halign isEqualToString: @"wexpand"])
{
return GSAutoLayoutWeakExpand;
}
else if ([halign isEqualToString: @"min"])
{
return GSAutoLayoutAlignMin;
}
else if ([halign isEqualToString: @"left"])
{
return GSAutoLayoutAlignMin;
}
else if ([halign isEqualToString: @"center"])
{
return GSAutoLayoutAlignCenter;
}
else if ([halign isEqualToString: @"max"])
{
return GSAutoLayoutAlignMax;
}
else if ([halign isEqualToString: @"right"])
{
return GSAutoLayoutAlignMax;
}
}
return 255;
}
- (int) gsAutoLayoutVAlignment
{
NSString *valign;
if ([self boolValueForAttribute: @"vexpand"] == 1)
{
return GSAutoLayoutExpand;
}
valign = [_attributes objectForKey: @"valign"];
if (valign != nil)
{
if ([valign isEqualToString: @"expand"])
{
return GSAutoLayoutExpand;
}
else if ([valign isEqualToString: @"wexpand"])
{
return GSAutoLayoutWeakExpand;
}
else if ([valign isEqualToString: @"min"])
{
return GSAutoLayoutAlignMin;
}
else if ([valign isEqualToString: @"bottom"])
{
return GSAutoLayoutAlignMin;
}
else if ([valign isEqualToString: @"center"])
{
return GSAutoLayoutAlignCenter;
}
else if ([valign isEqualToString: @"max"])
{
return GSAutoLayoutAlignMax;
}
else if ([valign isEqualToString: @"top"])
{
return GSAutoLayoutAlignMax;
}
}
return 255;
}
@end
|