annotate pkg-src/tree-nx/TreeView.m @ 163:0132846995bd r20-3b8

Import from CVS: tag r20-3b8
author cvs
date Mon, 13 Aug 2007 09:43:35 +0200
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2 #import "TreeView.h"
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3 #import "TreeButton.h"
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4 #import "NamedTree.h"
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
5 #import "Line.h"
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
6
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
7 // constants to determine how the buttons are laid out
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
8 #define BUTTONWIDTH 155.0
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
9 #define BUTTONHEIGHT 24.0
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
10 #define VERTSPACING 8.0
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
11 #define HORIZSPACING 40.0
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
12
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
13 @implementation TreeView
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
14
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
15 - initFrame:(const NXRect *)frameRect
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
16 {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
17 [super initFrame:frameRect];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
18 [self setAutosizing:(unsigned int) (NX_WIDTHSIZABLE | NX_HEIGHTSIZABLE)];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
19
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
20 currentButton = nil;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
21 lineList = nil;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
22 priorButton = nil;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
23 [selectedField setNextText: selectedField];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
24 [selectedField setPreviousText: selectedField];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
25 currScale = 1.0;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
26
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
27 [self registerForDragging];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
28 [self setOpaque:YES];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
29
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
30 return self;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
31 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
32
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
33 - buildTreeFromNode:aNode bottom:(double)ybot
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
34 top:(double)ytop atX:(double)xpos parent:(NXPoint *)pos
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
35 { // add a button representing the node to the View
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
36 // This method is recursive.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
37 NXRect butFrame = {{(xpos + HORIZSPACING),
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
38 (ybot + (ytop - ybot) / 2 - BUTTONHEIGHT / 2)},
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
39 {BUTTONWIDTH, BUTTONHEIGHT}};
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
40 id newButton = [[[TreeButton alloc] initFrame:&butFrame]
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
41 setTreeNode:aNode];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
42 id kid, kids = [aNode branches];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
43 int numBranches = [kids count];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
44 int i, treeWidth; double diff, accum = ybot;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
45 NXPoint myCenter = {(NX_X(&butFrame)),
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
46 (NX_Y(&butFrame) + BUTTONHEIGHT / 2)};
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
47 id newLine;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
48
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
49 [newButton setTitle:[aNode label]];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
50 [self addSubview:newButton];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
51 // line to parent:
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
52 if (pos) { // NULL if root, so no line
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
53 NXPoint parentRight = { pos->x + BUTTONWIDTH, pos->y };
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
54 newLine = [[Line alloc] init];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
55 [newLine setStart:&parentRight end:&myCenter];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
56 [lineList addObject:newLine];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
57 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
58 // now add any children and the lines to them.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
59 for (i=numBranches - 1; i >= 0; i--) { // loop isn't entered if no kids.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
60 kid = [kids objectAt:i];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
61 treeWidth = [kid width];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
62 diff = (treeWidth * (BUTTONHEIGHT + VERTSPACING));
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
63 [self buildTreeFromNode:kid bottom:accum
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
64 top:(accum + diff + VERTSPACING)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
65 atX:(xpos + BUTTONWIDTH + HORIZSPACING)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
66 parent:&myCenter];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
67 accum += diff;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
68 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
69 return self;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
70 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
71
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
72 - attachTree:aTree
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
73 {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
74 int treeWidth = [aTree width];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
75 int treeDepth = [aTree depth];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
76 double height = (treeWidth * (BUTTONHEIGHT + VERTSPACING) + VERTSPACING);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
77 double width = (treeDepth * (BUTTONWIDTH + HORIZSPACING) + HORIZSPACING);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
78
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
79 treeRoot = aTree;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
80 if (lineList) [[lineList freeObjects] free];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
81 lineList = [[List alloc] init];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
82 // resize the View to accomodate the Buttons
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
83 [self sizeTo:width :height];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
84 [self buildTreeFromNode:aTree bottom:0.0 top:height atX:0.0 parent:NULL];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
85
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
86 return self;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
87 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
88
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
89 - drawSelf:(NXRect *)rects :(int)rectCount // standard rendering method
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
90 {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
91 NXColor color = [[self window] backgroundColor];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
92
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
93 if (NXEqualColor(color, NX_COLORLTGRAY))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
94 color = NX_COLORDKGRAY;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
95
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
96 // PSsetgray(NX_DKGRAY);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
97 NXSetColor(color);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
98 NXRectFill(&bounds);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
99 // PSsetgray(NX_BLACK);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
100 NXSetColor(NX_COLORBLACK);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
101 PSsetlinewidth(2.0);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
102
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
103 [lineList makeObjectsPerform:@selector(render)];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
104 [[self subviews] makeObjectsPerform:@selector(display)];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
105 return self;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
106 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
107
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
108 - scale:sender
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
109 {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
110 id popUp = [sender window];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
111 short index = [popUp indexOfItem:[popUp selectedItem]];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
112 // 25% 50% 75% 100% 125% 150% 200% SizeToFit
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
113 // 0 1 2 3 4 5 6 7
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
114 float factors[] = {0.25, 0.50, 0.75, 1.0, 1.25, 1.50, 2.0, 0.20};
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
115 NXPoint center;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
116 NXCoord scale = factors[index];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
117
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
118 // Initialize width and height bounds when view is not scaled.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
119 if (currScale == 1.0)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
120 {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
121 origWidth = NX_WIDTH(&bounds);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
122 origHeight = NX_HEIGHT(&bounds);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
123 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
124
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
125 // Remember the center to we can reset it after the scaling.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
126 center.x = NX_X(&bounds) + NX_WIDTH(&bounds) / 2;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
127 center.y = NX_Y(&bounds) + NX_HEIGHT(&bounds) / 2;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
128
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
129 // Scale the view to its new size
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
130 if (index == 3) // 100% (Normal Size)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
131 {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
132 [self setDrawSize:origWidth :origHeight];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
133 currScale = 1.0;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
134 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
135 else
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
136 {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
137 currScale *= scale;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
138 [self setDrawSize:NX_WIDTH(&bounds) / currScale
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
139 :NX_HEIGHT(&bounds) / currScale];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
140 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
141
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
142 // Reset the center point
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
143 [self setDrawOrigin:center.x - NX_WIDTH(&bounds) / 2
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
144 :center.y - NX_HEIGHT(&bounds) / 2];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
145
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
146 // Ensure that selected button, if any, is visible.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
147 [self displayBut:currentButton];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
148
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
149 [self update];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
150
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
151 return self;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
152 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
153
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
154 - setCurrentButton:but
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
155 {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
156 if (but)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
157 {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
158 priorButton = currentButton;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
159 if (priorButton)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
160 {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
161 [priorButton setType:NX_MOMENTARYPUSH];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
162 [priorButton setState:0];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
163 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
164 currentButton = but;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
165 [currentButton setType:NX_ONOFF]; [currentButton setState:1];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
166 // [selectedField setStringValueNoCopy: [but title]];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
167 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
168 return but;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
169 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
170
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
171 - setCurrButtonByName:sender
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
172 {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
173 id currBut = [self getButByName:[sender stringValue]];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
174
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
175 [self displayBut:[self setCurrentButton:currBut]];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
176 [treeRoot act:currBut];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
177 return currBut;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
178 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
179
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
180 - getButByName:(const char*)name
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
181 {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
182 id butList = [self subviews];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
183 id but = nil;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
184 id currBut = nil;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
185 int i = 0;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
186
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
187 while (!currBut && (but = [butList objectAt:i++]))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
188 {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
189 if (!strcmp([but title], name))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
190 currBut = but;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
191 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
192 return currBut;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
193 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
194
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
195 - displayButByName:sender
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
196 {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
197 id but = [self getButByName:[sender stringValue]];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
198
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
199 if (but)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
200 [self displayBut:but];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
201 return but;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
202 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
203
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
204 - displayBut:but
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
205 {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
206 NXRect butRect;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
207
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
208 if (but)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
209 {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
210 [[but getBounds:&butRect] convertRectToSuperview:&butRect];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
211 [self scrollRectToVisible:&butRect];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
212 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
213 return self;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
214 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
215
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
216 @end
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
217
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
218
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
219
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
220 // Color dragging support
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
221
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
222 BOOL includesType(const NXAtom *types, NXAtom type)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
223 {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
224 if (types)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
225 while (*types)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
226 if (*types++ == type)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
227 return YES;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
228 return NO;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
229 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
230
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
231 @implementation TreeView(Drag)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
232
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
233 - registerForDragging
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
234 {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
235 [self registerForDraggedTypes:&NXColorPboardType count:1];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
236 return self;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
237 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
238
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
239 - (NXDragOperation)draggingEntered:(id <NXDraggingInfo>)sender
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
240 {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
241 NXDragOperation sourceMask = [sender draggingSourceOperationMask];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
242 Pasteboard *pboard = [sender draggingPasteboard];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
243
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
244 return ((includesType([pboard types], NXColorPboardType))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
245 ? NX_DragOperationGeneric : NX_DragOperationNone);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
246 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
247
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
248 - (BOOL)prepareForDragOperation:(id <NXDraggingInfo>)sender
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
249 {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
250 return YES;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
251 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
252
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
253 - (BOOL)performDragOperation:(id <NXDraggingInfo>)sender
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
254 {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
255 Pasteboard *pboard = [sender draggingPasteboard];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
256
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
257 if (includesType([pboard types], NXColorPboardType))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
258 {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
259 NXColor color = NXReadColorFromPasteboard(pboard);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
260 [[self window] setBackgroundColor:color];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
261 [self display]; // reflect color change
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
262 return YES;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
263 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
264 else
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
265 return NO;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
266 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
267
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
268 - concludeDragOperation:(id <NXDraggingInfo>)sender
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
269 {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
270 // Return value ignored.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
271 return nil;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
272 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
273
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
274 @end