1. Stewart Mackenzie
  2. cappuccino-docs

Source

cappuccino-docs / cappuccino docs / cappuccino.org / learn / documentation / _c_p_pop_up_button_8j_source.html

  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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<!-- Mirrored from cappuccino.org/learn/documentation/_c_p_pop_up_button_8j_source.html by HTTrack Website Copier/3.x [XR&CO'2006], Mon, 20 Sep 2010 02:19:30 GMT -->
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>Cappuccino API: AppKit/CPPopUpButton.j Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- Generated by Doxygen 1.6.1 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="main.html"><span>Main&nbsp;Page</span></a></li>
      <li><a href="pages.html"><span>Related&nbsp;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div class="tabs">
    <ul>
      <li><a href="files.html"><span>File&nbsp;List</span></a></li>
      <li><a href="globals.html"><span>File&nbsp;Members</span></a></li>
    </ul>
  </div>
<h1>AppKit/CPPopUpButton.j</h1><a href="_c_p_pop_up_button_8j.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
<a name="l00002"></a>00002 <span class="comment"> * CPPopUpButton.j</span>
<a name="l00003"></a>00003 <span class="comment"> * AppKit</span>
<a name="l00004"></a>00004 <span class="comment"> *</span>
<a name="l00005"></a>00005 <span class="comment"> * Created by Francisco Tolmasky.</span>
<a name="l00006"></a>00006 <span class="comment"> * Copyright 2008, 280 North, Inc.</span>
<a name="l00007"></a>00007 <span class="comment"> *</span>
<a name="l00008"></a>00008 <span class="comment"> * This library is free software; you can redistribute it and/or</span>
<a name="l00009"></a>00009 <span class="comment"> * modify it under the terms of the GNU Lesser General Public</span>
<a name="l00010"></a>00010 <span class="comment"> * License as published by the Free Software Foundation; either</span>
<a name="l00011"></a>00011 <span class="comment"> * version 2.1 of the License, or (at your option) any later version.</span>
<a name="l00012"></a>00012 <span class="comment"> *</span>
<a name="l00013"></a>00013 <span class="comment"> * This library is distributed in the hope that it will be useful,</span>
<a name="l00014"></a>00014 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<a name="l00015"></a>00015 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</span>
<a name="l00016"></a>00016 <span class="comment"> * Lesser General Public License for more details.</span>
<a name="l00017"></a>00017 <span class="comment"> *</span>
<a name="l00018"></a>00018 <span class="comment"> * You should have received a copy of the GNU Lesser General Public</span>
<a name="l00019"></a>00019 <span class="comment"> * License along with this library; if not, write to the Free Software</span>
<a name="l00020"></a>00020 <span class="comment"> * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA</span>
<a name="l00021"></a>00021 <span class="comment"> */</span>
<a name="l00022"></a>00022 
<a name="l00023"></a>00023 @<span class="keyword">import</span> <span class="stringliteral">&quot;CPButton.j&quot;</span>
<a name="l00024"></a>00024 @<span class="keyword">import</span> <span class="stringliteral">&quot;CPGeometry.j&quot;</span>
<a name="l00025"></a>00025 @<span class="keyword">import</span> <span class="stringliteral">&quot;CPMenu.j&quot;</span>
<a name="l00026"></a>00026 @<span class="keyword">import</span> <span class="stringliteral">&quot;CPMenuItem.j&quot;</span>
<a name="l00027"></a>00027 
<a name="l00028"></a>00028 <span class="preprocessor">#include &quot;<a class="code" href="_c_g_geometry_8h.html">CoreGraphics/CGGeometry.h</a>&quot;</span>
<a name="l00029"></a>00029 
<a name="l00030"></a>00030 
<a name="l00031"></a><a class="code" href="_c_p_pop_up_button_8j.html#a248e0856d3f7cd747f6bfa07c0a2317e">00031</a> var <a class="code" href="_c_p_pop_up_button_8j.html#a248e0856d3f7cd747f6bfa07c0a2317e">VISIBLE_MARGIN</a>  = 7.0;
<a name="l00032"></a>00032 
<a name="l00033"></a><a class="code" href="_c_p_pop_up_button_8j.html#a9cf1d567c5310b91a081f2c38d146645">00033</a> <a class="code" href="_c_p_pop_up_button_8j.html#a9cf1d567c5310b91a081f2c38d146645">CPPopUpButtonStatePullsDown</a> = <a class="code" href="_c_p_theme_8j.html#ad6e2552ced62697350961183fed236ac">CPThemeState</a>(<span class="stringliteral">&quot;pulls-down&quot;</span>);
<a name="l00034"></a>00034 
<a name="l00041"></a><a class="code" href="class_c_p_pop_up_button.html">00041</a> <span class="keyword">@implementation </span><a class="code" href="class_c_p_pop_up_button.html">CPPopUpButton</a> : <a class="code" href="class_c_p_button.html">CPButton</a>
<a name="l00042"></a>00042 {
<a name="l00043"></a>00043     <span class="keywordtype">int</span>         _selectedIndex;
<a name="l00044"></a>00044     CPRectEdge  _preferredEdge;
<a name="l00045"></a>00045     
<a name="l00046"></a>00046     <a class="code" href="class_c_p_menu.html">CPMenu</a>      _menu;
<a name="l00047"></a>00047 }
<a name="l00048"></a>00048 
<a name="l00049"></a><a class="code" href="class_c_p_pop_up_button.html#a633bce60280359e0530367f60e71e300">00049</a> + (<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)themeClass
<a name="l00050"></a>00050 {
<a name="l00051"></a>00051     <span class="keywordflow">return</span> <span class="stringliteral">&quot;popup-button&quot;</span>;
<a name="l00052"></a>00052 }
<a name="l00053"></a>00053 
<a name="l00060"></a><a class="code" href="class_c_p_pop_up_button.html#adbd72de0e2ee3902bfdd0e78b63b5f99">00060</a> - (id)initWithFrame:(CGRect)aFrame pullsDown:(BOOL)shouldPullDown
<a name="l00061"></a>00061 {
<a name="l00062"></a>00062     <span class="keyword">self</span> = [<span class="keyword">super</span> initWithFrame:aFrame];
<a name="l00063"></a>00063     
<a name="l00064"></a>00064     <span class="keywordflow">if</span> (<span class="keyword">self</span>)
<a name="l00065"></a>00065     {
<a name="l00066"></a>00066         _selectedIndex = <a class="code" href="_c_p_obj_j_runtime_8j.html#a84e3be579b365cc2c1559e1a1f469238">CPNotFound</a>;
<a name="l00067"></a>00067         _preferredEdge = <a class="code" href="_c_p_geometry_8j.html#a14fcdaddd46fdeaabc38c72e5353b262">CPMaxYEdge</a>;
<a name="l00068"></a>00068         
<a name="l00069"></a>00069         [<span class="keyword">self</span> setValue:CPImageLeft forThemeAttribute:@&quot;image-position&quot;];
<a name="l00070"></a>00070         [<span class="keyword">self</span> setValue:CPLeftTextAlignment forThemeAttribute:@&quot;alignment&quot;];
<a name="l00071"></a>00071         [<span class="keyword">self</span> setValue:CPLineBreakByTruncatingTail forThemeAttribute:@&quot;line-break-mode&quot;];
<a name="l00072"></a>00072         
<a name="l00073"></a>00073         [<span class="keyword">self</span> <a class="code" href="class_c_p_pop_up_button.html#ab624b4dbe0f0d4d74dd24852c51596ca">setMenu</a>:[[<a class="code" href="class_c_p_menu.html">CPMenu</a> alloc] initWithTitle:@&quot;&quot;]];
<a name="l00074"></a>00074 
<a name="l00075"></a>00075         [<span class="keyword">self</span> <a class="code" href="class_c_p_pop_up_button.html#a87b4171aad5ff36f3c8930ccabbd3c4e">setPullsDown</a>:shouldPullDown];
<a name="l00076"></a>00076     }
<a name="l00077"></a>00077     
<a name="l00078"></a>00078     <span class="keywordflow">return</span> <span class="keyword">self</span>;
<a name="l00079"></a>00079 }
<a name="l00080"></a>00080 
<a name="l00081"></a><a class="code" href="class_c_p_pop_up_button.html#a31704b2de44fceb5b901212aa957ef24">00081</a> - (id)initWithFrame:(CGRect)aFrame
<a name="l00082"></a>00082 {
<a name="l00083"></a>00083     <span class="keywordflow">return</span> [<span class="keyword">self</span> <a class="code" href="class_c_p_pop_up_button.html#adbd72de0e2ee3902bfdd0e78b63b5f99">initWithFrame</a>:aFrame <a class="code" href="class_c_p_pop_up_button.html#adbd72de0e2ee3902bfdd0e78b63b5f99">pullsDown</a>:NO];
<a name="l00084"></a>00084 }
<a name="l00085"></a>00085 
<a name="l00086"></a>00086 <span class="comment">// Setting the Type of Menu</span>
<a name="l00087"></a>00087 
<a name="l00093"></a><a class="code" href="class_c_p_pop_up_button.html#a87b4171aad5ff36f3c8930ccabbd3c4e">00093</a> - (void)setPullsDown:(BOOL)shouldPullDown
<a name="l00094"></a>00094 {
<a name="l00095"></a>00095     <span class="keywordflow">if</span> (shouldPullDown)
<a name="l00096"></a>00096         var changed = [<span class="keyword">self</span> setThemeState:CPPopUpButtonStatePullsDown];
<a name="l00097"></a>00097     <span class="keywordflow">else</span>
<a name="l00098"></a>00098         var changed = [<span class="keyword">self</span> unsetThemeState:CPPopUpButtonStatePullsDown];
<a name="l00099"></a>00099 
<a name="l00100"></a>00100     <span class="keywordflow">if</span> (!changed)
<a name="l00101"></a>00101         <span class="keywordflow">return</span>;
<a name="l00102"></a>00102 
<a name="l00103"></a>00103     var items = [_menu itemArray];
<a name="l00104"></a>00104 
<a name="l00105"></a>00105     <span class="keywordflow">if</span> ([items count] &lt;= 0)
<a name="l00106"></a>00106         <span class="keywordflow">return</span>;
<a name="l00107"></a>00107 
<a name="l00108"></a>00108     [items[0] setHidden:[<span class="keyword">self</span> <a class="code" href="class_c_p_pop_up_button.html#ad9bb96002b55a9d2586220fa639403eb">pullsDown</a>]];
<a name="l00109"></a>00109 
<a name="l00110"></a>00110     [<span class="keyword">self</span> <a class="code" href="class_c_p_pop_up_button.html#a1a87b068bba6026b2da793954d2aa50e">synchronizeTitleAndSelectedItem</a>];
<a name="l00111"></a>00111 }
<a name="l00112"></a>00112 
<a name="l00116"></a><a class="code" href="class_c_p_pop_up_button.html#ad9bb96002b55a9d2586220fa639403eb">00116</a> - (BOOL)pullsDown
<a name="l00117"></a>00117 {
<a name="l00118"></a>00118     <span class="keywordflow">return</span> [<span class="keyword">self</span> hasThemeState:CPPopUpButtonStatePullsDown];
<a name="l00119"></a>00119 }
<a name="l00120"></a>00120 
<a name="l00121"></a>00121 <span class="comment">// Inserting and Deleting Items</span>
<a name="l00122"></a>00122 
<a name="l00126"></a><a class="code" href="class_c_p_pop_up_button.html#ad01657814461d30fc0cc77a7bf769bbd">00126</a> - (void)addItem:(<a class="code" href="class_c_p_menu_item.html">CPMenuItem</a>)anItem
<a name="l00127"></a>00127 {
<a name="l00128"></a>00128     [_menu addItem:anItem];
<a name="l00129"></a>00129 }
<a name="l00130"></a>00130 
<a name="l00135"></a><a class="code" href="class_c_p_pop_up_button.html#a4ab730893bf6bcc81bf5858df170054f">00135</a> - (void)addItemWithTitle:(<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)aTitle
<a name="l00136"></a>00136 {
<a name="l00137"></a>00137     [_menu addItemWithTitle:aTitle action:NULL keyEquivalent:nil];
<a name="l00138"></a>00138 }
<a name="l00139"></a>00139 
<a name="l00144"></a><a class="code" href="class_c_p_pop_up_button.html#a48c67ff9fc25072060de96b90eba1920">00144</a> - (void)addItemsWithTitles:(<a class="code" href="class_c_p_array.html" title="A mutable array backed by a JavaScript Array.A mutable array class backed by a JavaScript...">CPArray</a>)titles
<a name="l00145"></a>00145 {
<a name="l00146"></a>00146     var index = 0,
<a name="l00147"></a>00147         count = [titles <a class="code" href="class_c_p_array.html#ae8abed7c67002d9a883005aa40e4fb55">count</a>];
<a name="l00148"></a>00148     
<a name="l00149"></a>00149     <span class="keywordflow">for</span> (; index &lt; count; ++index)
<a name="l00150"></a>00150         [<span class="keyword">self</span> addItemWithTitle:titles[index]];
<a name="l00151"></a>00151 }
<a name="l00152"></a>00152 
<a name="l00158"></a><a class="code" href="class_c_p_pop_up_button.html#a793a58910bd71b6ac21881af97fde771">00158</a> - (void)insertItemWithTitle:(<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)aTitle atIndex:(<span class="keywordtype">int</span>)anIndex
<a name="l00159"></a>00159 {
<a name="l00160"></a>00160     var items = [<span class="keyword">self</span> <a class="code" href="class_c_p_pop_up_button.html#ad325c5f9733a6026a6681b5da9d055dc">itemArray</a>],
<a name="l00161"></a>00161         count = [items count];
<a name="l00162"></a>00162     
<a name="l00163"></a>00163     <span class="keywordflow">while</span> (count--)
<a name="l00164"></a>00164         <span class="keywordflow">if</span> ([items[count] title] == aTitle)
<a name="l00165"></a>00165             [<span class="keyword">self</span> <a class="code" href="class_c_p_pop_up_button.html#a1421206900cc96d2154f90d3accf1070">removeItemAtIndex</a>:count];
<a name="l00166"></a>00166         
<a name="l00167"></a>00167     [_menu insertItemWithTitle:aTitle action:NULL keyEquivalent:nil atIndex:anIndex];
<a name="l00168"></a>00168 }
<a name="l00169"></a>00169 
<a name="l00173"></a><a class="code" href="class_c_p_pop_up_button.html#ac8b1233f173d5c8afc4313c0e9877a6e">00173</a> - (void)removeAllItems
<a name="l00174"></a>00174 {
<a name="l00175"></a>00175     var count = [_menu numberOfItems];
<a name="l00176"></a>00176     
<a name="l00177"></a>00177     <span class="keywordflow">while</span> (count--)
<a name="l00178"></a>00178         [_menu removeItemAtIndex:0];
<a name="l00179"></a>00179 }
<a name="l00180"></a>00180 
<a name="l00185"></a><a class="code" href="class_c_p_pop_up_button.html#abbe5bf8827ee78676b76a4e5b8b29a2c">00185</a> - (void)removeItemWithTitle:(<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)aTitle
<a name="l00186"></a>00186 {
<a name="l00187"></a>00187     [<span class="keyword">self</span> <a class="code" href="class_c_p_pop_up_button.html#a1421206900cc96d2154f90d3accf1070">removeItemAtIndex</a>:[<span class="keyword">self</span> <a class="code" href="class_c_p_pop_up_button.html#a0dc36ceac0edcdb150d97eabecc83af2">indexOfItemWithTitle</a>:aTitle]];
<a name="l00188"></a>00188     [<span class="keyword">self</span> <a class="code" href="class_c_p_pop_up_button.html#a1a87b068bba6026b2da793954d2aa50e">synchronizeTitleAndSelectedItem</a>];
<a name="l00189"></a>00189 }
<a name="l00190"></a>00190 
<a name="l00195"></a><a class="code" href="class_c_p_pop_up_button.html#a1421206900cc96d2154f90d3accf1070">00195</a> - (void)removeItemAtIndex:(<span class="keywordtype">int</span>)anIndex
<a name="l00196"></a>00196 {
<a name="l00197"></a>00197     [_menu removeItemAtIndex:anIndex];
<a name="l00198"></a>00198     [<span class="keyword">self</span> <a class="code" href="class_c_p_pop_up_button.html#a1a87b068bba6026b2da793954d2aa50e">synchronizeTitleAndSelectedItem</a>];
<a name="l00199"></a>00199 }
<a name="l00200"></a>00200 
<a name="l00201"></a>00201 <span class="comment">// Getting the User&apos;s Selection</span>
<a name="l00205"></a><a class="code" href="class_c_p_pop_up_button.html#a7f08283cc7b5a18924095c79a0ef8907">00205</a> <span class="comment"></span>- (<a class="code" href="class_c_p_menu_item.html">CPMenuItem</a>)selectedItem
<a name="l00206"></a>00206 {
<a name="l00207"></a>00207     <span class="keywordflow">if</span> (_selectedIndex &lt; 0 || _selectedIndex &gt; [<span class="keyword">self</span> numberOfItems] - 1)
<a name="l00208"></a>00208         <span class="keywordflow">return</span> nil;
<a name="l00209"></a>00209     
<a name="l00210"></a>00210     <span class="keywordflow">return</span> [_menu itemAtIndex:_selectedIndex];
<a name="l00211"></a>00211 }
<a name="l00212"></a>00212 
<a name="l00216"></a><a class="code" href="class_c_p_pop_up_button.html#a1509721848b484eb50630a62945ea9bc">00216</a> - (<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)titleOfSelectedItem
<a name="l00217"></a>00217 {
<a name="l00218"></a>00218     <span class="keywordflow">return</span> [[<span class="keyword">self</span> <a class="code" href="class_c_p_pop_up_button.html#a7f08283cc7b5a18924095c79a0ef8907">selectedItem</a>] <a class="code" href="class_c_p_menu_item.html#a72bd9c12033795adc8ba03a1a05aeb1a">title</a>];
<a name="l00219"></a>00219 }
<a name="l00220"></a>00220 
<a name="l00224"></a><a class="code" href="class_c_p_pop_up_button.html#a6cd669fafecc2a43b7f16b289a268b9d">00224</a> - (int)indexOfSelectedItem
<a name="l00225"></a>00225 {
<a name="l00226"></a>00226     <span class="keywordflow">return</span> _selectedIndex;
<a name="l00227"></a>00227 }
<a name="l00228"></a>00228 
<a name="l00229"></a>00229 <span class="comment">// For us, CPNumber is toll-free bridged to Number, so just return the selected index.</span>
<a name="l00233"></a><a class="code" href="class_c_p_pop_up_button.html#ac07e8c01a27c01b6e35c10bc8d88c1b3">00233</a> <span class="comment"></span>- (id)objectValue
<a name="l00234"></a>00234 {
<a name="l00235"></a>00235     <span class="keywordflow">return</span> _selectedIndex;
<a name="l00236"></a>00236 }
<a name="l00237"></a>00237 
<a name="l00238"></a>00238 <span class="comment">// Setting the Current Selection</span>
<a name="l00243"></a><a class="code" href="class_c_p_pop_up_button.html#afc4df2e7e3f31afab23219c88395f077">00243</a> <span class="comment"></span>- (void)selectItem:(<a class="code" href="class_c_p_menu_item.html">CPMenuItem</a>)aMenuItem
<a name="l00244"></a>00244 {
<a name="l00245"></a>00245     [<span class="keyword">self</span> <a class="code" href="class_c_p_pop_up_button.html#aade3f2bd654caf51e04feb4631db2bac">selectItemAtIndex</a>:[<span class="keyword">self</span> <a class="code" href="class_c_p_pop_up_button.html#a2b7aa1681eb3daff36b09753782899e1">indexOfItem</a>:aMenuItem]];
<a name="l00246"></a>00246 }
<a name="l00247"></a>00247 
<a name="l00252"></a><a class="code" href="class_c_p_pop_up_button.html#aade3f2bd654caf51e04feb4631db2bac">00252</a> - (void)selectItemAtIndex:(<span class="keywordtype">int</span>)anIndex
<a name="l00253"></a>00253 {
<a name="l00254"></a>00254     <span class="keywordflow">if</span> (_selectedIndex == anIndex)
<a name="l00255"></a>00255         <span class="keywordflow">return</span>;
<a name="l00256"></a>00256     
<a name="l00257"></a>00257     <span class="keywordflow">if</span> (_selectedIndex &gt;= 0 &amp;&amp; ![<span class="keyword">self</span> pullsDown])
<a name="l00258"></a>00258         [[<span class="keyword">self</span> <a class="code" href="class_c_p_pop_up_button.html#a7f08283cc7b5a18924095c79a0ef8907">selectedItem</a>] <a class="code" href="class_c_p_menu_item.html#a16d075e27ef6f98ffb3bd7c883de4e80">setState</a>:CPOffState];
<a name="l00259"></a>00259     
<a name="l00260"></a>00260     _selectedIndex = anIndex;
<a name="l00261"></a>00261 
<a name="l00262"></a>00262     <span class="keywordflow">if</span> (_selectedIndex &gt;= 0 &amp;&amp; ![<span class="keyword">self</span> pullsDown])
<a name="l00263"></a>00263         [[<span class="keyword">self</span> <a class="code" href="class_c_p_pop_up_button.html#a7f08283cc7b5a18924095c79a0ef8907">selectedItem</a>] <a class="code" href="class_c_p_menu_item.html#a16d075e27ef6f98ffb3bd7c883de4e80">setState</a>:CPOnState];
<a name="l00264"></a>00264     
<a name="l00265"></a>00265     [<span class="keyword">self</span> <a class="code" href="class_c_p_pop_up_button.html#a1a87b068bba6026b2da793954d2aa50e">synchronizeTitleAndSelectedItem</a>];
<a name="l00266"></a>00266 }
<a name="l00267"></a>00267 
<a name="l00272"></a><a class="code" href="class_c_p_pop_up_button.html#a2a6fe100f20df6d9f58cdab34c909c4e">00272</a> - (void)selectItemWithTag:(<span class="keywordtype">int</span>)aTag
<a name="l00273"></a>00273 {
<a name="l00274"></a>00274     [<span class="keyword">self</span> <a class="code" href="class_c_p_pop_up_button.html#aade3f2bd654caf51e04feb4631db2bac">selectItemAtIndex</a>:[<span class="keyword">self</span> <a class="code" href="class_c_p_pop_up_button.html#a9f59ce0623a571fc55c56ad43e49a777">indexOfItemWithTag</a>:aTag]];
<a name="l00275"></a>00275 }
<a name="l00276"></a>00276 
<a name="l00281"></a><a class="code" href="class_c_p_pop_up_button.html#a3d3c9fd9e06d2c9c29c76e4865a76334">00281</a> - (void)selectItemWithTitle:(<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)aTitle
<a name="l00282"></a>00282 {
<a name="l00283"></a>00283     [<span class="keyword">self</span> <a class="code" href="class_c_p_pop_up_button.html#aade3f2bd654caf51e04feb4631db2bac">selectItemAtIndex</a>:[<span class="keyword">self</span> <a class="code" href="class_c_p_pop_up_button.html#a0dc36ceac0edcdb150d97eabecc83af2">indexOfItemWithTitle</a>:aTitle]];
<a name="l00284"></a>00284 }
<a name="l00285"></a>00285 
<a name="l00290"></a><a class="code" href="class_c_p_pop_up_button.html#add6ffd6c6a28912bb3da9e482e463c0a">00290</a> - (void)setObjectValue:(<span class="keywordtype">id</span>)aValue
<a name="l00291"></a>00291 {
<a name="l00292"></a>00292     [<span class="keyword">self</span> <a class="code" href="class_c_p_pop_up_button.html#aade3f2bd654caf51e04feb4631db2bac">selectItemAtIndex</a>:[aValue intValue]];
<a name="l00293"></a>00293 }
<a name="l00294"></a>00294 
<a name="l00295"></a>00295 <span class="comment">// Getting Menu Items</span>
<a name="l00299"></a><a class="code" href="class_c_p_pop_up_button.html#a2a660b0d6182450e5ea5f49e88baf3ca">00299</a> <span class="comment"></span>- (<a class="code" href="class_c_p_menu.html">CPMenu</a>)<a class="code" href="_c_p_segmented_control_8j.html#a013c594489b43812712541b68420b137">menu</a>
<a name="l00300"></a>00300 {
<a name="l00301"></a>00301     <span class="keywordflow">return</span> _menu;
<a name="l00302"></a>00302 }
<a name="l00303"></a>00303 
<a name="l00307"></a><a class="code" href="class_c_p_pop_up_button.html#ab624b4dbe0f0d4d74dd24852c51596ca">00307</a> - (void)setMenu:(<a class="code" href="class_c_p_menu.html">CPMenu</a>)aMenu
<a name="l00308"></a>00308 {
<a name="l00309"></a>00309     <span class="keywordflow">if</span> (_menu === aMenu)
<a name="l00310"></a>00310         <span class="keywordflow">return</span>;
<a name="l00311"></a>00311 
<a name="l00312"></a>00312     var defaultCenter = [<a class="code" href="class_c_p_notification_center.html" title="Sends messages (CPNotification) between objects.">CPNotificationCenter</a> <a class="code" href="class_c_p_notification_center.html#a5abe725f1a1a48ac4cb1e45b6d9d50a8">defaultCenter</a>];
<a name="l00313"></a>00313     
<a name="l00314"></a>00314     <span class="keywordflow">if</span> (_menu)
<a name="l00315"></a>00315     {
<a name="l00316"></a>00316         [defaultCenter
<a name="l00317"></a>00317             removeObserver:self
<a name="l00318"></a>00318                       name:CPMenuDidAddItemNotification
<a name="l00319"></a>00319                     object:_menu];
<a name="l00320"></a>00320 
<a name="l00321"></a>00321         [defaultCenter
<a name="l00322"></a>00322             removeObserver:self
<a name="l00323"></a>00323                       name:CPMenuDidChangeItemNotification
<a name="l00324"></a>00324                     object:_menu];
<a name="l00325"></a>00325 
<a name="l00326"></a>00326         [defaultCenter
<a name="l00327"></a>00327             removeObserver:self
<a name="l00328"></a>00328                       name:CPMenuDidRemoveItemNotification
<a name="l00329"></a>00329                     object:_menu];
<a name="l00330"></a>00330     }
<a name="l00331"></a>00331 
<a name="l00332"></a>00332     _menu = aMenu;
<a name="l00333"></a>00333     
<a name="l00334"></a>00334     <span class="keywordflow">if</span> (_menu)
<a name="l00335"></a>00335     {
<a name="l00336"></a>00336         [defaultCenter
<a name="l00337"></a>00337             addObserver:self
<a name="l00338"></a>00338               selector:@selector(menuDidAddItem:)
<a name="l00339"></a>00339                   name:CPMenuDidAddItemNotification
<a name="l00340"></a>00340                 object:_menu];
<a name="l00341"></a>00341     
<a name="l00342"></a>00342         [defaultCenter
<a name="l00343"></a>00343             addObserver:self
<a name="l00344"></a>00344               selector:@selector(menuDidChangeItem:)
<a name="l00345"></a>00345                   name:CPMenuDidChangeItemNotification
<a name="l00346"></a>00346                 object:_menu];
<a name="l00347"></a>00347                 
<a name="l00348"></a>00348         [defaultCenter
<a name="l00349"></a>00349             addObserver:self
<a name="l00350"></a>00350               selector:@selector(menuDidRemoveItem:)
<a name="l00351"></a>00351                   name:CPMenuDidRemoveItemNotification
<a name="l00352"></a>00352                 object:_menu];
<a name="l00353"></a>00353     }
<a name="l00354"></a>00354     
<a name="l00355"></a>00355     [<span class="keyword">self</span> <a class="code" href="class_c_p_pop_up_button.html#a1a87b068bba6026b2da793954d2aa50e">synchronizeTitleAndSelectedItem</a>];
<a name="l00356"></a>00356 }
<a name="l00357"></a>00357 
<a name="l00361"></a><a class="code" href="class_c_p_pop_up_button.html#a3a63956d266e7e2bfc4c59b00b44e9d9">00361</a> - (int)numberOfItems
<a name="l00362"></a>00362 {
<a name="l00363"></a>00363     <span class="keywordflow">return</span> [_menu numberOfItems];
<a name="l00364"></a>00364 }
<a name="l00365"></a>00365 
<a name="l00369"></a><a class="code" href="class_c_p_pop_up_button.html#ad325c5f9733a6026a6681b5da9d055dc">00369</a> - (<a class="code" href="class_c_p_array.html" title="A mutable array backed by a JavaScript Array.A mutable array class backed by a JavaScript...">CPArray</a>)itemArray
<a name="l00370"></a>00370 {
<a name="l00371"></a>00371     <span class="keywordflow">return</span> [_menu itemArray];
<a name="l00372"></a>00372 }
<a name="l00373"></a>00373 
<a name="l00378"></a><a class="code" href="class_c_p_pop_up_button.html#a8e4e9a64e83071923dc728436200edd5">00378</a> - (<a class="code" href="class_c_p_menu_item.html">CPMenuItem</a>)itemAtIndex:(<span class="keywordtype">unsigned</span>)anIndex
<a name="l00379"></a>00379 {
<a name="l00380"></a>00380     <span class="keywordflow">return</span> [_menu itemAtIndex:anIndex];
<a name="l00381"></a>00381 }
<a name="l00382"></a>00382 
<a name="l00387"></a><a class="code" href="class_c_p_pop_up_button.html#a627b4e93c5337763908c2219cc2a8a5f">00387</a> - (<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)itemTitleAtIndex:(<span class="keywordtype">unsigned</span>)anIndex
<a name="l00388"></a>00388 {
<a name="l00389"></a>00389     <span class="keywordflow">return</span> [[_menu itemAtIndex:anIndex] title];
<a name="l00390"></a>00390 }
<a name="l00391"></a>00391 
<a name="l00395"></a><a class="code" href="class_c_p_pop_up_button.html#a4fb8306b17a06dbfdb1996f607fe320f">00395</a> - (<a class="code" href="class_c_p_array.html" title="A mutable array backed by a JavaScript Array.A mutable array class backed by a JavaScript...">CPArray</a>)itemTitles
<a name="l00396"></a>00396 {
<a name="l00397"></a>00397     var titles = [],
<a name="l00398"></a>00398         items = [<span class="keyword">self</span> <a class="code" href="class_c_p_pop_up_button.html#ad325c5f9733a6026a6681b5da9d055dc">itemArray</a>],
<a name="l00399"></a>00399         
<a name="l00400"></a>00400         index = 0,
<a name="l00401"></a>00401         count = [items count];
<a name="l00402"></a>00402     
<a name="l00403"></a>00403     <span class="keywordflow">for</span> (; index &lt; count; ++index)
<a name="l00404"></a>00404         items.push([items[index] title]);
<a name="l00405"></a>00405 }
<a name="l00406"></a>00406 
<a name="l00411"></a><a class="code" href="class_c_p_pop_up_button.html#a8260326b5c24c351ce89461380247fed">00411</a> - (<a class="code" href="class_c_p_menu_item.html">CPMenuItem</a>)itemWithTitle:(<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)aTitle
<a name="l00412"></a>00412 {
<a name="l00413"></a>00413     <span class="keywordflow">return</span> [_menu itemAtIndex:[_menu indexOfItemWithTitle:aTitle]];
<a name="l00414"></a>00414 }
<a name="l00415"></a>00415 
<a name="l00419"></a><a class="code" href="class_c_p_pop_up_button.html#a34afb6b0eb92855cd1cede8fd124004d">00419</a> - (<a class="code" href="class_c_p_menu_item.html">CPMenuItem</a>)lastItem
<a name="l00420"></a>00420 {
<a name="l00421"></a>00421     <span class="keywordflow">return</span> [[_menu itemArray] lastObject];
<a name="l00422"></a>00422 }
<a name="l00423"></a>00423 
<a name="l00424"></a>00424 <span class="comment">// Getting the Indices of Menu Items</span>
<a name="l00429"></a><a class="code" href="class_c_p_pop_up_button.html#a2b7aa1681eb3daff36b09753782899e1">00429</a> <span class="comment"></span>- (int)indexOfItem:(<a class="code" href="class_c_p_menu_item.html">CPMenuItem</a>)aMenuItem
<a name="l00430"></a>00430 {
<a name="l00431"></a>00431     <span class="keywordflow">return</span> [_menu indexOfItem:aMenuItem];
<a name="l00432"></a>00432 }
<a name="l00433"></a>00433 
<a name="l00438"></a><a class="code" href="class_c_p_pop_up_button.html#a9f59ce0623a571fc55c56ad43e49a777">00438</a> - (int)indexOfItemWithTag:(<span class="keywordtype">int</span>)aTag
<a name="l00439"></a>00439 {
<a name="l00440"></a>00440     <span class="keywordflow">return</span> [_menu indexOfItemWithTag:aTag];
<a name="l00441"></a>00441 }
<a name="l00442"></a>00442 
<a name="l00447"></a><a class="code" href="class_c_p_pop_up_button.html#a0dc36ceac0edcdb150d97eabecc83af2">00447</a> - (int)indexOfItemWithTitle:(<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)aTitle
<a name="l00448"></a>00448 {
<a name="l00449"></a>00449     <span class="keywordflow">return</span> [_menu indexOfItemWithTitle:aTitle];
<a name="l00450"></a>00450 }
<a name="l00451"></a>00451 
<a name="l00458"></a><a class="code" href="class_c_p_pop_up_button.html#a777649f3cd36300ccf63ec9746a3ff47">00458</a> - (int)indexOfItemWithRepresentedObject:(<span class="keywordtype">id</span>)anObject
<a name="l00459"></a>00459 {
<a name="l00460"></a>00460     <span class="keywordflow">return</span> [_menu indexOfItemWithRepresentedObject:anObject];
<a name="l00461"></a>00461 }
<a name="l00462"></a>00462 
<a name="l00470"></a><a class="code" href="class_c_p_pop_up_button.html#a0c416626de07d7b7761b97934335da4d">00470</a> - (int)indexOfItemWithTarget:(<span class="keywordtype">id</span>)aTarget action:(<span class="keywordtype">SEL</span>)anAction
<a name="l00471"></a>00471 {
<a name="l00472"></a>00472     <span class="keywordflow">return</span> [_menu indexOfItemWithTarget:aTarget action:anAction];
<a name="l00473"></a>00473 }
<a name="l00474"></a>00474 
<a name="l00475"></a>00475 <span class="comment">// Setting the Cell Edge to Pop out in Restricted Situations</span>
<a name="l00481"></a><a class="code" href="class_c_p_pop_up_button.html#a954ea3ff172992f7a8da19b163fe7d0e">00481</a> <span class="comment"></span>- (CPRectEdge)preferredEdge
<a name="l00482"></a>00482 {
<a name="l00483"></a>00483     <span class="keywordflow">return</span> _preferredEdge;
<a name="l00484"></a>00484 }
<a name="l00485"></a>00485 
<a name="l00491"></a><a class="code" href="class_c_p_pop_up_button.html#a1e42eb0a922f7e4d38efcdbce4760ce7">00491</a> - (void)setPreferredEdge:(CPRectEdge)aRectEdge
<a name="l00492"></a>00492 {
<a name="l00493"></a>00493     _preferredEdge = aRectEdge;
<a name="l00494"></a>00494 }
<a name="l00495"></a>00495 
<a name="l00496"></a>00496 <span class="comment">// Setting the Title</span>
<a name="l00501"></a><a class="code" href="class_c_p_pop_up_button.html#a55322dff7e35270e62f13f5e9b22b510">00501</a> <span class="comment"></span>- (void)setTitle:(<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)aTitle
<a name="l00502"></a>00502 {
<a name="l00503"></a>00503     <span class="keywordflow">if</span> ([<span class="keyword">self</span> title] === aTitle)
<a name="l00504"></a>00504         <span class="keywordflow">return</span>;
<a name="l00505"></a>00505 
<a name="l00506"></a>00506     <span class="keywordflow">if</span> ([<span class="keyword">self</span> pullsDown])
<a name="l00507"></a>00507     {
<a name="l00508"></a>00508         var items = [_menu itemArray];
<a name="l00509"></a>00509 
<a name="l00510"></a>00510         <span class="keywordflow">if</span> ([items count] &lt;= 0)
<a name="l00511"></a>00511             [<span class="keyword">self</span> <a class="code" href="class_c_p_pop_up_button.html#a4ab730893bf6bcc81bf5858df170054f">addItemWithTitle</a>:aTitle];
<a name="l00512"></a>00512 
<a name="l00513"></a>00513         <span class="keywordflow">else</span>
<a name="l00514"></a>00514         {
<a name="l00515"></a>00515             [items[0] setTitle:aTitle];
<a name="l00516"></a>00516             [<span class="keyword">self</span> <a class="code" href="class_c_p_pop_up_button.html#a1a87b068bba6026b2da793954d2aa50e">synchronizeTitleAndSelectedItem</a>];
<a name="l00517"></a>00517         }
<a name="l00518"></a>00518     }
<a name="l00519"></a>00519     <span class="keywordflow">else</span>
<a name="l00520"></a>00520     {
<a name="l00521"></a>00521         var index = [<span class="keyword">self</span> <a class="code" href="class_c_p_pop_up_button.html#a0dc36ceac0edcdb150d97eabecc83af2">indexOfItemWithTitle</a>:aTitle];
<a name="l00522"></a>00522         
<a name="l00523"></a>00523         <span class="keywordflow">if</span> (index &lt; 0)
<a name="l00524"></a>00524         {
<a name="l00525"></a>00525             [<span class="keyword">self</span> <a class="code" href="class_c_p_pop_up_button.html#a4ab730893bf6bcc81bf5858df170054f">addItemWithTitle</a>:aTitle];
<a name="l00526"></a>00526             
<a name="l00527"></a>00527             index = [<span class="keyword">self</span> <a class="code" href="class_c_p_pop_up_button.html#a3a63956d266e7e2bfc4c59b00b44e9d9">numberOfItems</a>] - 1;
<a name="l00528"></a>00528         }
<a name="l00529"></a>00529         
<a name="l00530"></a>00530         [<span class="keyword">self</span> <a class="code" href="class_c_p_pop_up_button.html#aade3f2bd654caf51e04feb4631db2bac">selectItemAtIndex</a>:index];
<a name="l00531"></a>00531     }
<a name="l00532"></a>00532 }
<a name="l00533"></a>00533 
<a name="l00534"></a>00534 <span class="comment">// Setting the Image</span>
<a name="l00540"></a><a class="code" href="class_c_p_pop_up_button.html#a3d1733dac78d689e2180cda5284580a4">00540</a> <span class="comment"></span>- (void)setImage:(<a class="code" href="class_c_p_image.html">CPImage</a>)anImage
<a name="l00541"></a>00541 {
<a name="l00542"></a>00542     <span class="comment">// The Image is set by the currently selected item.</span>
<a name="l00543"></a>00543 }
<a name="l00544"></a>00544 
<a name="l00545"></a>00545 <span class="comment">// Setting the State</span>
<a name="l00550"></a><a class="code" href="class_c_p_pop_up_button.html#a1a87b068bba6026b2da793954d2aa50e">00550</a> <span class="comment"></span>- (void)synchronizeTitleAndSelectedItem
<a name="l00551"></a>00551 {
<a name="l00552"></a>00552     var item = nil;
<a name="l00553"></a>00553 
<a name="l00554"></a>00554     <span class="keywordflow">if</span> ([<span class="keyword">self</span> pullsDown])
<a name="l00555"></a>00555     {
<a name="l00556"></a>00556         var items = [_menu itemArray];
<a name="l00557"></a>00557         
<a name="l00558"></a>00558         <span class="keywordflow">if</span> ([items count] &gt; 0)
<a name="l00559"></a>00559             item = items[0];
<a name="l00560"></a>00560     }
<a name="l00561"></a>00561     <span class="keywordflow">else</span>
<a name="l00562"></a>00562         item = [<span class="keyword">self</span> <a class="code" href="class_c_p_pop_up_button.html#a7f08283cc7b5a18924095c79a0ef8907">selectedItem</a>];
<a name="l00563"></a>00563 
<a name="l00564"></a>00564     [<span class="keyword">super</span> setImage:[item image]];
<a name="l00565"></a>00565     [<span class="keyword">super</span> setTitle:[item title]];
<a name="l00566"></a>00566 }
<a name="l00567"></a>00567 
<a name="l00568"></a>00568 <span class="comment">//</span>
<a name="l00573"></a><a class="code" href="class_c_p_pop_up_button.html#a6a916ad368d784ad5b50388db07aa3b3">00573</a> <span class="comment"></span>- (void)menuDidAddItem:(<a class="code" href="class_c_p_notification.html" title="A notification that can be posted to a CPNotificationCenter.">CPNotification</a>)aNotification
<a name="l00574"></a>00574 {
<a name="l00575"></a>00575     var index = [[aNotification <a class="code" href="class_c_p_notification.html#a2c441e9231e4d97445571728cc4117c6">userInfo</a>] <a class="code" href="class_c_p_dictionary.html#ab4aaab7d240d27cf2f32c60bffc13d9e">objectForKey</a>:@&quot;CPMenuItemIndex&quot;];
<a name="l00576"></a>00576     
<a name="l00577"></a>00577     <span class="keywordflow">if</span> (_selectedIndex &lt; 0)
<a name="l00578"></a>00578         [<span class="keyword">self</span> <a class="code" href="class_c_p_pop_up_button.html#aade3f2bd654caf51e04feb4631db2bac">selectItemAtIndex</a>:0];
<a name="l00579"></a>00579     
<a name="l00580"></a>00580     <span class="keywordflow">else</span> <span class="keywordflow">if</span> (index == _selectedIndex)
<a name="l00581"></a>00581         [<span class="keyword">self</span> <a class="code" href="class_c_p_pop_up_button.html#a1a87b068bba6026b2da793954d2aa50e">synchronizeTitleAndSelectedItem</a>];
<a name="l00582"></a>00582         
<a name="l00583"></a>00583     <span class="keywordflow">else</span> <span class="keywordflow">if</span> (index &lt; _selectedIndex)
<a name="l00584"></a>00584         ++_selectedIndex;
<a name="l00585"></a>00585         
<a name="l00586"></a>00586     <span class="keywordflow">if</span> (index == 0 &amp;&amp; [<span class="keyword">self</span> pullsDown])
<a name="l00587"></a>00587     {
<a name="l00588"></a>00588         var items = [_menu itemArray];
<a name="l00589"></a>00589         
<a name="l00590"></a>00590         [items[0] setHidden:YES];
<a name="l00591"></a>00591         
<a name="l00592"></a>00592         <span class="keywordflow">if</span> (items.length &gt; 0)
<a name="l00593"></a>00593             [items[1] setHidden:NO];
<a name="l00594"></a>00594     }
<a name="l00595"></a>00595 
<a name="l00596"></a>00596     var item = [_menu itemArray][index],
<a name="l00597"></a>00597         action = [item action];
<a name="l00598"></a>00598 
<a name="l00599"></a>00599     <span class="keywordflow">if</span> (!action || (action === <span class="keyword">@selector</span>(_popUpItemAction:)))
<a name="l00600"></a>00600     {
<a name="l00601"></a>00601         [item setTarget:self];
<a name="l00602"></a>00602         [item setAction:@selector(_popUpItemAction:)];
<a name="l00603"></a>00603     }
<a name="l00604"></a>00604 }
<a name="l00605"></a>00605 
<a name="l00610"></a><a class="code" href="class_c_p_pop_up_button.html#a56f25d98fb5e531b96a26fea496424c4">00610</a> - (void)menuDidChangeItem:(<a class="code" href="class_c_p_notification.html" title="A notification that can be posted to a CPNotificationCenter.">CPNotification</a>)aNotification
<a name="l00611"></a>00611 {
<a name="l00612"></a>00612     var index = [[aNotification <a class="code" href="class_c_p_notification.html#a2c441e9231e4d97445571728cc4117c6">userInfo</a>] <a class="code" href="class_c_p_dictionary.html#ab4aaab7d240d27cf2f32c60bffc13d9e">objectForKey</a>:@&quot;CPMenuItemIndex&quot;];
<a name="l00613"></a>00613 
<a name="l00614"></a>00614     <span class="keywordflow">if</span> ([<span class="keyword">self</span> pullsDown] &amp;&amp; index != 0)
<a name="l00615"></a>00615         <span class="keywordflow">return</span>;
<a name="l00616"></a>00616     
<a name="l00617"></a>00617     <span class="keywordflow">if</span> (![<span class="keyword">self</span> pullsDown] &amp;&amp; index != _selectedIndex)
<a name="l00618"></a>00618         <span class="keywordflow">return</span>;
<a name="l00619"></a>00619     
<a name="l00620"></a>00620     [<span class="keyword">self</span> <a class="code" href="class_c_p_pop_up_button.html#a1a87b068bba6026b2da793954d2aa50e">synchronizeTitleAndSelectedItem</a>];
<a name="l00621"></a>00621 }
<a name="l00622"></a>00622 
<a name="l00627"></a><a class="code" href="class_c_p_pop_up_button.html#aa82d7271c32e9a06e30e8bd86d157cd2">00627</a> - (void)menuDidRemoveItem:(<a class="code" href="class_c_p_notification.html" title="A notification that can be posted to a CPNotificationCenter.">CPNotification</a>)aNotification
<a name="l00628"></a>00628 {
<a name="l00629"></a>00629     var numberOfItems = [<span class="keyword">self</span> <a class="code" href="class_c_p_pop_up_button.html#a3a63956d266e7e2bfc4c59b00b44e9d9">numberOfItems</a>];
<a name="l00630"></a>00630     
<a name="l00631"></a>00631     <span class="keywordflow">if</span> (numberOfItems &lt;= _selectedIndex &amp;&amp; numberOfItems &gt; 0)
<a name="l00632"></a>00632         [<span class="keyword">self</span> <a class="code" href="class_c_p_pop_up_button.html#aade3f2bd654caf51e04feb4631db2bac">selectItemAtIndex</a>:numberOfItems - 1];
<a name="l00633"></a>00633     <span class="keywordflow">else</span>
<a name="l00634"></a>00634         [<span class="keyword">self</span> <a class="code" href="class_c_p_pop_up_button.html#a1a87b068bba6026b2da793954d2aa50e">synchronizeTitleAndSelectedItem</a>];
<a name="l00635"></a>00635 }
<a name="l00636"></a>00636 
<a name="l00637"></a><a class="code" href="class_c_p_pop_up_button.html#a826c2c4824e11e16ff0ea7296e03f42d">00637</a> - (void)mouseDown:(<a class="code" href="class_c_p_event.html">CPEvent</a>)anEvent
<a name="l00638"></a>00638 {
<a name="l00639"></a>00639     <span class="keywordflow">if</span> (![<span class="keyword">self</span> isEnabled] || ![<span class="keyword">self</span> numberOfItems])
<a name="l00640"></a>00640         <span class="keywordflow">return</span>;
<a name="l00641"></a>00641 
<a name="l00642"></a>00642     [<span class="keyword">self</span> highlight:YES];
<a name="l00643"></a>00643 
<a name="l00644"></a>00644     var <a class="code" href="_c_p_segmented_control_8j.html#a013c594489b43812712541b68420b137">menu</a> = [<span class="keyword">self</span> <a class="code" href="class_c_p_pop_up_button.html#a2a660b0d6182450e5ea5f49e88baf3ca">menu</a>],
<a name="l00645"></a>00645         bounds = [<span class="keyword">self</span> bounds],
<a name="l00646"></a>00646         minimumWidth = <a class="code" href="_c_g_geometry_8j.html#aa310af239f2108c573299b35776996fa">CGRectGetWidth</a>(bounds);
<a name="l00647"></a>00647 
<a name="l00648"></a>00648     <span class="comment">// FIXME: setFont: should set the font on the menu.</span>
<a name="l00649"></a>00649     [<a class="code" href="class_c_p_pop_up_button.html#a2a660b0d6182450e5ea5f49e88baf3ca">menu</a> <a class="code" href="class_c_p_menu.html#a01f6323c872a4f89c13f903b4223a92d">setFont</a>:[<span class="keyword">self</span> font]];
<a name="l00650"></a>00650 
<a name="l00651"></a>00651     <span class="keywordflow">if</span> ([<span class="keyword">self</span> pullsDown])
<a name="l00652"></a>00652     {
<a name="l00653"></a>00653         var positionedItem = nil,
<a name="l00654"></a>00654             location = <a class="code" href="_c_g_geometry_8j.html#a06c96cb5931220da52ff44b8ce9b603e">CGPointMake</a>(0.0, <a class="code" href="_c_g_geometry_8j.html#ab0a24500a256a6e58aab6ae4f19d7a77">CGRectGetMaxY</a>(bounds));
<a name="l00655"></a>00655     }
<a name="l00656"></a>00656     <span class="keywordflow">else</span>
<a name="l00657"></a>00657     {
<a name="l00658"></a>00658         var contentRect = [<span class="keyword">self</span> contentRectForBounds:bounds],
<a name="l00659"></a>00659             positionedItem = [<span class="keyword">self</span> <a class="code" href="class_c_p_pop_up_button.html#a7f08283cc7b5a18924095c79a0ef8907">selectedItem</a>],
<a name="l00660"></a>00660             standardLeftMargin = [_CPMenuWindow _standardLeftMargin] + [_CPMenuItemStandardView _standardLeftMargin],
<a name="l00661"></a>00661             location = <a class="code" href="_c_g_geometry_8j.html#a06c96cb5931220da52ff44b8ce9b603e">CGPointMake</a>(<a class="code" href="_c_g_geometry_8j.html#a7c1a8fe081097d577b441f6b7b553421">CGRectGetMinX</a>(contentRect) - standardLeftMargin, 0.0);
<a name="l00662"></a>00662 
<a name="l00663"></a>00663         minimumWidth += standardLeftMargin;
<a name="l00664"></a>00664     }
<a name="l00665"></a>00665 
<a name="l00666"></a>00666     [<a class="code" href="class_c_p_pop_up_button.html#a2a660b0d6182450e5ea5f49e88baf3ca">menu</a> <a class="code" href="class_c_p_menu.html#a24a90c0b9f8fa4e1f30505a14e926d7a">setMinimumWidth</a>:minimumWidth];
<a name="l00667"></a>00667 
<a name="l00668"></a>00668     [<a class="code" href="class_c_p_pop_up_button.html#a2a660b0d6182450e5ea5f49e88baf3ca">menu</a>
<a name="l00669"></a>00669         _popUpMenuPositioningItem:positionedItem
<a name="l00670"></a>00670                        atLocation:location
<a name="l00671"></a>00671                              topY:CGRectGetMinY(bounds)
<a name="l00672"></a>00672                           bottomY:CGRectGetMaxY(bounds)
<a name="l00673"></a>00673                            inView:self
<a name="l00674"></a>00674                          callback:function(aMenu)
<a name="l00675"></a>00675         {
<a name="l00676"></a>00676             [<span class="keyword">self</span> highlight:NO];
<a name="l00677"></a>00677 
<a name="l00678"></a>00678             var highlightedItem = [aMenu <a class="code" href="class_c_p_menu.html#a4678d712872da85b990640a50678add8">highlightedItem</a>];
<a name="l00679"></a>00679 
<a name="l00680"></a>00680             if ([highlightedItem _isSelectable])
<a name="l00681"></a>00681                 [<span class="keyword">self</span> <a class="code" href="class_c_p_pop_up_button.html#afc4df2e7e3f31afab23219c88395f077">selectItem</a>:highlightedItem];
<a name="l00682"></a>00682         }];
<a name="l00683"></a>00683 <span class="comment">/*</span>
<a name="l00684"></a>00684 <span class="comment">    else</span>
<a name="l00685"></a>00685 <span class="comment">    {</span>
<a name="l00686"></a>00686 <span class="comment">        // This is confusing, I KNOW, so let me explain it to you.</span>
<a name="l00687"></a>00687 <span class="comment">        // We want the *content* of the selected menu item to overlap the *content* of our pop up.</span>
<a name="l00688"></a>00688 <span class="comment">        // 1. So calculate where our content is, then calculate where the menu item is.</span>
<a name="l00689"></a>00689 <span class="comment">        // 2. Move LEFT by whatever indentation we have (offsetWidths, aka, window margin, item margin, etc).</span>
<a name="l00690"></a>00690 <span class="comment">        // 3. MOVE UP by the difference in sizes of the content and menu item, this will only work if the content is vertically centered.</span>
<a name="l00691"></a>00691 <span class="comment">        var contentRect = [self convertRect:[self contentRectForBounds:bounds] toView:nil],</span>
<a name="l00692"></a>00692 <span class="comment">            menuOrigin = [theWindow convertBaseToGlobal:contentRect.origin],</span>
<a name="l00693"></a>00693 <span class="comment">            menuItemRect = [menuWindow rectForItemAtIndex:_selectedIndex];</span>
<a name="l00694"></a>00694 <span class="comment"></span>
<a name="l00695"></a>00695 <span class="comment">        menuOrigin.x -= CGRectGetMinX(menuItemRect) + [menuWindow overlapOffsetWidth] + [[[menu itemAtIndex:_selectedIndex] _menuItemView] overlapOffsetWidth];</span>
<a name="l00696"></a>00696 <span class="comment">        menuOrigin.y -= CGRectGetMinY(menuItemRect) + (CGRectGetHeight(menuItemRect) - CGRectGetHeight(contentRect)) / 2.0;</span>
<a name="l00697"></a>00697 <span class="comment">    }</span>
<a name="l00698"></a>00698 <span class="comment">*/</span>
<a name="l00699"></a>00699 }
<a name="l00700"></a>00700 
<a name="l00701"></a>00701 - (void)_popUpItemAction:(<span class="keywordtype">id</span>)aSender
<a name="l00702"></a>00702 {
<a name="l00703"></a>00703     [<span class="keyword">self</span> sendAction:[<span class="keyword">self</span> action] to:[<span class="keyword">self</span> target]];
<a name="l00704"></a>00704 }
<a name="l00705"></a>00705 
<a name="l00706"></a>00706 <span class="keyword">@end</span>
<a name="l00707"></a>00707 
<a name="l00708"></a><a class="code" href="_c_p_pop_up_button_8j.html#ad0b5e5bb94823daff43e7d9785be94d9">00708</a> var <a class="code" href="_c_p_pop_up_button_8j.html#ad0b5e5bb94823daff43e7d9785be94d9">CPPopUpButtonMenuKey</a>            = <span class="stringliteral">@&quot;CPPopUpButtonMenuKey&quot;</span>,
<a name="l00709"></a><a class="code" href="_c_p_pop_up_button_8j.html#a1e43122701ee7362d43045d4729442b8">00709</a>     <a class="code" href="_c_p_pop_up_button_8j.html#a1e43122701ee7362d43045d4729442b8">CPPopUpButtonSelectedIndexKey</a>   = <span class="stringliteral">@&quot;CPPopUpButtonSelectedIndexKey&quot;</span>,
<a name="l00710"></a><a class="code" href="_c_p_pop_up_button_8j.html#ad77f43a9ee30ba11868340cadf3b2c41">00710</a>     <a class="code" href="_c_p_pop_up_button_8j.html#ad77f43a9ee30ba11868340cadf3b2c41">CPPopUpButtonPullsDownKey</a>       = <span class="stringliteral">@&quot;CPPopUpButtonPullsDownKey&quot;</span>;
<a name="l00711"></a>00711 
<a name="l00712"></a>00712 <span class="keyword">@implementation </span><a class="code" href="class_c_p_pop_up_button.html">CPPopUpButton</a> (CPCoding)
<a name="l00720"></a><a class="code" href="class_c_p_pop_up_button.html#aad1c3b43837d687539f8c44ed85502da">00720</a> - (id)initWithCoder:(<a class="code" href="class_c_p_coder.html" title="Defines methods for use when archiving &amp;amp; restoring (enc/decoding).">CPCoder</a>)aCoder
<a name="l00721"></a>00721 {
<a name="l00722"></a>00722     <span class="keyword">self</span> = [<span class="keyword">super</span> initWithCoder:aCoder];
<a name="l00723"></a>00723     
<a name="l00724"></a>00724     <span class="keywordflow">if</span> (<span class="keyword">self</span>)
<a name="l00725"></a>00725     {
<a name="l00726"></a>00726         <span class="comment">// Nothing is currently selected</span>
<a name="l00727"></a>00727         _selectedIndex = -1;
<a name="l00728"></a>00728 
<a name="l00729"></a>00729         [<span class="keyword">self</span> <a class="code" href="class_c_p_pop_up_button.html#ab624b4dbe0f0d4d74dd24852c51596ca">setMenu</a>:[aCoder decodeObjectForKey:CPPopUpButtonMenuKey]];
<a name="l00730"></a>00730         [<span class="keyword">self</span> <a class="code" href="class_c_p_pop_up_button.html#aade3f2bd654caf51e04feb4631db2bac">selectItemAtIndex</a>:[aCoder decodeObjectForKey:CPPopUpButtonSelectedIndexKey]];
<a name="l00731"></a>00731     }
<a name="l00732"></a>00732     
<a name="l00733"></a>00733     <span class="keywordflow">return</span> <span class="keyword">self</span>;
<a name="l00734"></a>00734 }
<a name="l00735"></a>00735 
<a name="l00741"></a><a class="code" href="class_c_p_pop_up_button.html#a42f5d26d856eeeed44dda2fe6b7cd092">00741</a> - (void)encodeWithCoder:(<a class="code" href="class_c_p_coder.html" title="Defines methods for use when archiving &amp;amp; restoring (enc/decoding).">CPCoder</a>)aCoder
<a name="l00742"></a>00742 {
<a name="l00743"></a>00743     [<span class="keyword">super</span> encodeWithCoder:aCoder];
<a name="l00744"></a>00744     
<a name="l00745"></a>00745     [aCoder encodeObject:_menu forKey:CPPopUpButtonMenuKey];
<a name="l00746"></a>00746     [aCoder encodeInt:_selectedIndex forKey:CPPopUpButtonSelectedIndexKey];
<a name="l00747"></a>00747 }
<a name="l00748"></a>00748 
<a name="l00749"></a>00749 <span class="keyword">@end</span>
</pre></div></div>
<hr size="1"/><address style="text-align: right;"><small>Generated on Tue Apr 6 10:32:55 2010 for Cappuccino API by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
</body>

<!-- Mirrored from cappuccino.org/learn/documentation/_c_p_pop_up_button_8j_source.html by HTTrack Website Copier/3.x [XR&CO'2006], Mon, 20 Sep 2010 02:19:30 GMT -->
</html>