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
|
//
// MVerticalBox.m
// MySQLGUICommon
//
// Created by Alfredo Kojima on 05/9/12.
// Copyright 2005 MySQL AB. All rights reserved.
//
#import "MVerticalBox.h"
@implementation MVerticalBox
- (id)initWithFrame:(NSRect)frame
{
self= [super initWithFrame:frame];
if (self)
{
_xOffset= 16.0;
_yOffset= 10.0;
_spacing= 0;
}
return self;
}
- (void)setSpacing:(float)spacing
{
_spacing= spacing;
}
- (void)setExpandsHorizontally:(BOOL)flag
{
_expandHorizontally= flag;
}
- (BOOL)isFlipped
{
return YES;
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
[super dealloc];
}
- (void)setOffset:(NSSize)offset
{
_xOffset= offset.width;
_yOffset= offset.height;
}
- (void)_subviewResized:(NSNotification*)notif
{
NSArray *subviews= [self subviews];
int i;
float y= _yOffset;
NSSize size;
for (i= 0; i < [subviews count]; i++)
{
[[subviews objectAtIndex:i] setFrameOrigin:NSMakePoint(_xOffset, y)];
y+= NSHeight([[subviews objectAtIndex:i] frame]) + _spacing;
}
size.width= NSWidth([self frame]);
if (_expandHorizontally)
size.width= NSWidth([[self superview] frame]);
size.height= y;
[self setFrameSize:size];
[self setNeedsDisplay:YES];
}
- (void)resizeSubviewsWithOldSize:(NSSize)oldBoundsSize
{
NSArray *subviews= [self subviews];
int i;
float y= _yOffset;
float width= NSWidth([self frame]);
for (i= 0; i < [subviews count]; i++)
{
NSRect frame;
frame= [[subviews objectAtIndex:i] frame];
frame.origin.y= y;
frame.origin.x= _xOffset;
frame.size.width= width - 2 * _xOffset;
[[subviews objectAtIndex:i] setFrame:frame];
y+= NSHeight(frame) + _spacing;
}
[self setNeedsDisplay:YES];
}
- (void)willRemoveSubview:(NSView*)view
{
NSArray *subviews= [self subviews];
int i;
float y= _yOffset;
float width= NSWidth([self frame]);
for (i= 0; i < [subviews count]; i++)
{
NSRect frame;
if ([subviews objectAtIndex:i] == view)
continue;
frame= [[subviews objectAtIndex:i] frame];
frame.origin.y= y;
frame.origin.x= _xOffset;
frame.size.width= width - 2 * _xOffset;
[[subviews objectAtIndex:i] setFrame:frame];
y+= NSHeight(frame) + _spacing;
}
[self setNeedsDisplay:YES];
}
- (void)didAddSubview:(NSView*)view
{
NSRect rect= [view frame];
rect.size.width= NSWidth([self frame]);
[view setFrame:rect];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(_subviewResized:)
name:NSViewFrameDidChangeNotification
object:view];
[self resizeSubviewsWithOldSize:NSMakeSize(0,0)];
}
@end
|