Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

[r8500]: ooDialog / trunk / examples / propertySheet.tabs / oodListViews.rex Maximize Restore History

Download this file

oodListViews.rex    755 lines (613 with data), 25.8 kB

  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
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
/*----------------------------------------------------------------------------*/
/* */
/* Copyright (c) 1995, 2004 IBM Corporation. All rights reserved. */
/* Copyright (c) 2005-2012 Rexx Language Association. All rights reserved. */
/* */
/* This program and the accompanying materials are made available under */
/* the terms of the Common Public License v1.0 which accompanies this */
/* distribution. A copy is also available at the following address: */
/* http://www.oorexx.org/license.html */
/* */
/* Redistribution and use in source and binary forms, with or */
/* without modification, are permitted provided that the following */
/* conditions are met: */
/* */
/* Redistributions of source code must retain the above copyright */
/* notice, this list of conditions and the following disclaimer. */
/* Redistributions in binary form must reproduce the above copyright */
/* notice, this list of conditions and the following disclaimer in */
/* the documentation and/or other materials provided with the distribution. */
/* */
/* Neither the name of Rexx Language Association nor the names */
/* of its contributors may be used to endorse or promote products */
/* derived from this software without specific prior written permission. */
/* */
/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS */
/* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT */
/* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS */
/* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT */
/* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED */
/* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, */
/* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY */
/* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING */
/* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */
/* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
/* */
/*----------------------------------------------------------------------------*/
/**
* Name: oodListViews.rex
* Type: Open Object Rexx (ooRexx) example
* Resources: oodListViews.rc, oodListViews1.bmp, oodListViews2.bmp
*
* Description:
*
* Demonstrates the different views possible in the list-view control. Shows
* how to use the ControlDialog class to populate each page in a tab
* control. Demonstrates some other list-view features, such as info tips,
* etc..
*
*/
-- A directory manager saves the current directory and can later go back to
-- that directory. The class itself is located in DirectoryManaager.cls
mgr = .DirectoryManager~new()
.application~useGlobalConstDir("O", 'rc\oodListViews.h')
dlg = .ListsDialog~new("rc\oodListViews.rc", IDD_LISTVIEWS)
if dlg~initCode <> 0 then do
say "Error instantiating the ListsDialog, aborting"
return 99
end
dlg~execute("SHOWTOP")
mgr~goBack
return 0
::requires "ooDialog.cls"
::requires "DirectoryManager.cls"
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*\
ListsDialog Class - the main (top-level) dialog.
\* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
::class 'ListsDialog' subclass RcDialog
::method init
forward class (super) continue
if self~initCode <> 0 then return self~initCode
self~createImageLists
self~initRecords
self~connectButtonEvent(IDC_PB_ADDRECORD, "CLICKED", "onAdd")
self~connectButtonEvent(IDC_PB_FORWARD, "CLICKED", "onForward")
self~connectButtonEvent(IDC_PB_BACKWARD, "CLICKED", "onBackward")
self~connectButtonEvent(IDC_CK_INFOTIPS, "CLICKED", onCheckClicked)
self~connectTabEvent(IDC_TAB, 'SELCHANGE', 'onNewTab')
::method initDialog
expose tabControl pageDialog smallIcons normalIcons records pbBackward pbForward ckInfoTips
-- Set the Use Info Tips check box.
ckInfoTips = self~newCheckBox(IDC_CK_INFOTIPS)
ckInfoTips~check
-- Save a reference to the push buttons.
pbBackward = self~newPushButton(IDC_PB_BACKWARD)
pbForward = self~newPushButton(IDC_PB_Forward)
-- We start on the first page, so going backwards is not possible.
pbBackward~disable
-- Add the tabs to the tab control.
tabControl = self~newTab(IDC_TAB)
tabControl~addSequence("List", "Report", "Icon", "Small Icon")
-- Get the display rectangle of the tab control.
displayRect = self~calculateDisplayArea(tabControl)
-- The tab control is quite wide in relation to the default space the 4 tabs
-- occupy. Make the tabs wide enough to take up a little over 1/2 of the width
-- of the tab control.
w = (displayRect~right * (7 / 12)) % 4
tabControl~setMinTabWidth(w)
pageDialog = .PageDialog~new("rc\oodListViews.rc", IDD_PAGE, , , , , self)
pageDialog~useInfoTips = .true
pageDialog~initialize(smallIcons, normalIcons, records)
-- Use execute() to properly start a ControlDialog.
pageDialog~execute
self~positionAndShow(pageDialog, tabControl, displayRect)
/** calculateDisplayArea()
*
* Tab controls contain two areas, the tabs themselves and the display area.
* The display area is where the content for each tab is drawn.
*
* We need to match the control dialog(s) size and position with the display
* area size and position. There are two approaches here:
*
* We could calculate the size of the largest dialog, resize the tab control to
* match, and position the control dialog over the display area.
*
* We can get the size and position of the tab control's display area and resize
* and reposition the control dialog(s) to match. This is the approach we use
* here.
*/
::method calculateDisplayArea private
use strict arg tabControl
-- Given a rectangle describing the tab control's size and position, the tab
-- control itself will calculate the display area's size and position.
r = tabControl~windowRect
tabControl~calcDisplayRect(r)
-- Save the size of the display area, we need it later.
s = .Size~new(r~right - r~left, r~bottom - r~top)
-- Now we need to map the display area's position on the screen, to the client
-- co-ordinates of the main dialog. The control dialog(s) are children windows
-- of the main dialog, which is why we need to use the client-area of the
-- dialog, not the client area of the tab control.
p = .Point~new(r~left, r~top)
self~screen2client(p)
-- Create our display rectangle. This is used in setWindowPosition(), which
-- takes a point / size rectangle. ooDialog defines a point / size rectangle
-- as using the left and top attributes for the position of the upper left
-- corner of a rectangle, using the right attribute for the width of the
-- rectangle, and using the bottom attribute for the height of the rectangle.
return .Rect~new(p~x, p~y, s~width, s~height)
/** positionAndShow()
*
* Used to resize and reposition the control dialog (PageDialog so it occupies
* the display area of the tab control.
*/
::method positionAndShow private
use strict arg dlg, tabControl, displayRect
-- We can not position the control dialog until the underlying Windows dialog
-- is created and we have a valid window handle. This takes a small but
-- disecernable amount of time. The actual amount of time can vary widely and
-- depends on both the amount of concurrency going on in the interpreter and
-- the amount of multi-tasking going on in the operating system.
--
-- We don't want to spin forever if there is some error in creating the
-- dialog, so we set a timeout here. However, it is very short and may not be
-- long enough. If it is not long enough, it is better to increase the time
-- sleeping rather than the loop counter.
do i = 1 to 10
if dlg~hwnd <> 0 then leave
z = SysSleep(.005)
end
if dlg~hwnd == 0 then do
say "Error creating dialog for the tab with index:" 1", aborting"
return self~cancel:super
end
-- Now resize and reposition the control dialog to the tab control's display
-- area. We need to position the control dialog *above* the tab control in
-- the Z-order so that it shows.
dlg~setWindowPos(tabControl~hwnd, displayRect, "SHOWWINDOW NOOWNERZORDER")
/** onCheckClicked()
*
* This is the event handler for the CLICKED event of the Use Info Tips check
* box. Each time it is clicked, we update the Page dialog with its state.
*/
::method onCheckClicked unguarded
expose ckInfoTips pageDialog
if ckInfoTips~checked then pageDialog~useInfoTips = .true
else pageDialog~useInfoTips = .false
/** onNewTab()
*
* This is the method we connected to the SELCHANGE event of the tab control.
*
* It is invoked when the user changes to a new tab using the tab control's
* interface. I.e. by clicking on a tab or by using the keyboard when the
* tab control has the focus.
*
* In general, there is usually a different control dialog for each page of
* the tab. In that usage, the programmer would hide the dialog of the old
* page and show the dialog of the new page. However, in this application we
* only use one control dialog. When the page is changed, we tell the page
* dialog to change the view style of the list view to produce the effect of
* changing pages.
*/
::method onNewTab unguarded
expose tabControl pageDialog
use arg ignore1, ignore2
pageDialog~refreshView(tabControl~selectedIndex + 1)
self~checkButtons
/** onForward()
*
* The event handle for the 'Forward' button's CLICKED event. We select the
* next tab in the tab control and then force the page to update by calling the
* 'onNewTab' method ourselfs.
*
* Note that we do not need to check that the selected index plus 1 is valid
* because the Forward button is disabled when we are on the last page.
*/
::method onForward
expose tabControl
tabControl~selectIndex(tabControl~selectedIndex + 1)
self~onNewTab
/** onBackward()
*
* The event handle for the 'Backward' button's CLICKED event. Coments are the
* same as for the onForward() method above.
*/
::method onBackward
expose tabControl
tabControl~selectIndex(tabControl~selectedIndex - 1)
self~onNewTab
/** onAdd()
*
* The event handle for the 'Add' button's CLICKED event. Here we display the
* address dialog which allows the user add a new record, which in turn will
* show up as a new item in the list-view.
*/
::method onAdd unguarded
expose pageDialog
dlg = .AddressDialog~new('rc\oodListViews.rc', IDD_ADDRESS)
if dlg~initCode = 0 then do
if dlg~execute("SHOWTOP") == self~IDOK then do
rec = .directory~new
rec~FirstName = dlg~IDC_EDIT_FNAME
rec~Lastname = dlg~IDC_EDIT_LNAME
rec~Street = dlg~IDC_EDIT_STREET
rec~City = dlg~IDC_EDIT_CITY
rec~State = dlg~IDC_EDIT_STATE
rec~ZipCode = dlg~IDC_EDIT_ZIPCODE
rec~Age = dlg~IDC_EDIT_AGE
if dlg~IDC_RB_MALE = 1 then rec~Sex = "M"
else rec~Sex = "F"
-- Have the page dialog add the record to the list-view.
pageDialog~addRecord(rec)
end
end
/** cancel()
*
* The user can not end a ControlDialog, so we need to end the page dialog
* here during cancel. Passing .false to endExecution() says the user
* canceled the main dialog.
*/
::method cancel
expose pageDialog
-- Always use endExecution() to close a ControlDialog.
pageDialog~endExecution(.false)
return self~cancel:super
/** ok()
*
* The user can not end a ControlDialog, so we need to end the page dialog
* here during ok. Passing .true to endExecution() says the user closed the
* main dialog with ok.
*/
::method ok
expose pageDialog
-- Always use endExecution() to close a ControlDialog.
pageDialog~endExecution(.true)
return self~ok:super
/** initAutoDetection()
*
* We turn off auto detection for this dialog.
*/
::method initAutoDetection
self~noAutoDetection
/** checkButtons()
*
* Enables or disables the forwards / backwards buttons to fit the current
* page. I.e., if we are on the first page, the backwards button should be
* disabled, etc..
*/
::method checkButtons private
expose tabControl pbForward pbBackward
index = tabControl~selectedIndex + 1
if index == 1 then do
pbBackward~disable
pbForward~enable
end
else if index == 4 then do
pbBackward~enable
pbForward~disable
end
else do
pbBackward~enable
pbForward~enable
end
/** createImageLists()
*
* Create the small and large icon image lists. These will be used in the
* report, small icon, and icon views of the list-view. The small icon image
* list is used by both the report and the small icon views, normal icon image
* list is used by the icon view.
*
* In this program we create the initial records and image lists here, in the
* main dialog, and then pass the objects to the page dialog. The creation
* could just as well have been done in the page dialog itself. The example
* program does it this way to try and show that how you use a ControlDialog is
* very flexible.
*/
::method createImageLists private
expose smallIcons normalIcons
small = .Image~getImage("rc\oodListViews1.bmp")
tmpIL = .ImageList~create(.Size~new(16, 12), .Image~toID(ILC_COLOR4), 4, 0)
if \small~isNull, \tmpIL~isNull then do
tmpIL~add(small)
small~release
smallIcons = tmpIL
end
else do
smallIcons = .nil
end
normal = .Image~getImage("rc\oodListViews2.bmp")
tmpIL = .ImageList~create(.Size~new(32, 32), .Image~toID(ILC_COLOR4), 4, 0)
if \normal~isNull, \tmpIL~isNull then do
tmpIL~add(normal)
normal~release
normalIcons = tmpIL
end
else do
normalIcons = .nil
end
/** initRecords()
*
* Create 3 records to start with. The records could be pulled from a database.
* Here we just fake it. Each 'record' is put into an array and then the array
* is passed to the page dialog where is record is used to insert a single item
* into the list-view.
*/
::method initRecords private
expose records
records = .array~new(3)
rec = .directory~new
rec~FirstName = "Mike"
rec~Lastname = "Miller"
rec~Street = "432 Fifth Ave"
rec~City = "New York"
rec~State = "NY"
rec~ZipCode = "12897"
rec~Age = "35"
rec~Sex = "M"
records[1] = rec
rec = .directory~new
rec~FirstName = "Sue"
rec~Lastname = "Thaxton"
rec~Street = "5179 Bellevue St"
rec~City = "Tucson"
rec~State = "AZ"
rec~ZipCode = "87340"
rec~Age = "30"
rec~Sex = "F"
records[2] = rec
rec = .directory~new
rec~FirstName = "Dave"
rec~Lastname = "Hewitt"
rec~Street = "4932 Texas St"
rec~City = "San Diego"
rec~State = "CA"
rec~ZipCode = "92110"
rec~Age = "49"
rec~Sex = "M"
records[3] = rec
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*\
PageDialog Class
\* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
::class 'PageDialog' subclass RcControlDialog
-- This attribute allows the parent dialog to notify us if the Use Info Tips
-- check box is checked or not. When it is not checked, we don't display any
-- info tips.
::attribute useInfoTips
::method initialize
expose smallIcons normalIcons records
use strict arg smallIcons, normalIcons, records
self~connectListViewEvent(IDC_LISTVIEW, "COLUMNCLICK")
self~connectListViewEvent(IDC_LISTVIEW, "ACTIVATE", "onDoubleClick")
self~connectListViewEvent(IDC_LISTVIEW, "BEGINDRAG", "DefListDragHandler")
self~connectListViewEvent(IDC_LISTVIEW, "DEFAULTEDIT")
self~connectListViewEvent(IDC_LISTVIEW, "GETINFOTIP")
self~initUpdateListView(IDC_LISTVIEW)
::method initDialog
expose lv smallIcons normalIcons records ckInfoTips useInfoTips
lv = self~newListView(IDC_LISTVIEW)
if smallIcons <> .nil then lv~setImageList(smallIcons, .Image~toID(LVSIL_SMALL))
if normalIcons <> .nil then lv~setImageList(normalIcons, .Image~toID(LVSIL_NORMAL))
lv~insertColumn(0, "Name", 50)
lv~insertColumn(1, "Street", 60)
lv~insertColumn(2, "City", 50)
lv~insertColumn(3, "State", 20)
lv~insertColumn(4, "Zip Code", 30)
lv~insertColumn(5, "Age", 20)
do r over records
self~addRecord(r, .false)
end
lv~addExtendedStyle("FULLROWSELECT DOUBLEBUFFER GRIDLINES INFOTIP")
/** refreshView()
*
* Invoked by the main dialog when the user has switched to a new tab in the tab
* control.
*
* Typically an application uses a different dialog for each page of a tab
* control. In this example program however, the different pages just show the
* different view types of a list-view. Therefore the same dialog, (and the same
* list-view,) are used for each page. When a new page is to be displayed,
* rather than switching to a different dialog, the current view of the list-
* view is simply changed to the correct view for that page.
*/
::method refreshView unguarded
expose lv
use strict arg index
select
when index == 1 then do
oldStyle = "REPORT ICON SMALLICON"
newStyle = "LIST"
end
when index == 2 then do
oldStyle = "LIST ICON SMALLICON"
newStyle = "REPORT"
end
when index == 3 then do
oldStyle = "LIST REPORT SMALLICON"
newStyle = "ICON"
end
when index == 4 then do
oldStyle = "LIST REPORT ICON"
newStyle = "SMALLICON"
end
otherwise return .false
end
-- End select
lv~replaceStyle(oldStyle, newStyle)
return .true
/** onColumnClick()
*
* The event handler for a column click event, invoked when the user clicks on a
* column header when the list-view is in Report view.
*
* We use the event to demonstrate some of the list-view methods.
*/
::method onColumnClick unguarded
expose lv
use arg id, column
-- Get the current width, in pixels, of the column clicked and then set its
-- width to 10 pixels more.
lv~setColumnWidthPx(column, lv~columnWidthPx(column) + 10)
-- Display information about the column clicked.
d = .Directory~new
if lv~getColumnInfo(column, d) then do
tab = '09'x
msg = "Column Title:"tab d~text || .endOfLine || -
"Subitem index:"tab d~subitem || .endOfLine || -
"Column Width:"tab d~width || .endOfLine || -
"Allignment:"tab d~fmt || .endOfLine~copies(2) || -
"Note: each time you click on a column" || .endOfLine || -
"its width is increased."
j = MessageDialog(msg, self~hwnd, "Column Click Detected")
end
else do
msg = "An error ocurred getting the column information."
j = MessageDialog(msg, self~hwnd, "Windows API Error", "OK", "ERROR")
end
/** onDoubleClick()
*
* The event handler for a double click, invoked when a list-view item is double
* clicked.
*
* We use the event to demonstrate some of the list-view methods.
*/
::method onDoubleClick unguarded
expose lv
use arg id
-- Get the index of the item with the focus, use the index to retriev the item
-- information and the text associated with it
index = lv~focused
-- The item's information is returned in the .directory object passed in to
-- the getItemInfo() method.
d = .directory~new
lv~getItemInfo(index, d)
parse value d~text with lastName ', ' firstName
pronoun = 'his'
if d~image == 1 then pronoun = "her"
age = lv~itemText(index, 5)
msg = "You have doubled clicked on" firstName lastName || "0d0a0d0a"x ,
"Should" pronoun "age be increased by 1?"
ret = MessageDialog(msg, self~hwnd, "Age Increment", YESNO, INFORMATION)
if ret == self~IDYES then do
age = age + 1
lv~setItemText(index, 5, age)
end
-- Deselect the focused item and move the focus to the first item
lv~deselect(index)
lv~focus(0)
/** onGetInfoTip()
*
* This is the event handler for the INFOTIP event. This method is invoked when
* the list-view wants the text for an info tip.
*
* If this method returns the empty string then no info tip will be shown.
* Otherwise, the info tip will contain the text sent back.
*
* The maxLen argument will be the maximum length allowed for the returned text.
* You should never assume what this lenght is, although it appears to usually
* be 1023. If the text sent back is longer than maxLen, it will automatically
* be truncated.
*/
::method onGetInfoTip unguarded
expose lv records useInfoTips
use arg id, item, text, maxLen
text = ''
if useInfoTips then do
r = records[item + 1]
text = r~firstName r~lastName '('r~age')' || .endOfLine || -
r~street || .endOfLine || -
r~city',' r~state r~zipcode
end
return text
/** addRecord()
*
* Used to add an item to the list view.
*
* Note that it does not matter what view the list-view is in. When the list-
* view is in report view, then all the information will be visible to the user.
* When it is in other views, only some of the information is visible to the
* user.
*/
::method addRecord unguarded
expose lv records counter
use strict arg rec, newRecord = .true
iconSex = 0
if rec~sex = "F" then iconSex = 1
index = lv~addRow(, iconSex, rec~lastName', 'rec~firstName, rec~street, rec~city, rec~state, rec~ZipCode, rec~age)
lv~setItemData(index, rec~firstName rec~lastName)
if newRecord then records~append(rec)
/** leaving()
*
* The ooDialog framework invokes the leaving method automatically when a dialog
* is being ended. The default implementation does nothing. The method is
* intended to be over-ridden by the programmer, if desired, to provide the
* proper place to clean up resources.
*
* We use it here to release the image lists resources. This is not needed in
* this stand alone program. When the interpreter process ends, (which will
* happen now that the dialog is ending,) the operating system will free all the
* resources. The example program does this because ... because it is an
* example and this makes a good place to explain about the leaving() method.
*/
::method leaving
expose smallIcons normalIcons
if smallIcons \== .nil then smallIcons~release
if normalIcons \== .nil then normalIcons~release
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*\
AddressDialog Class
\* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
::class 'AddressDialog' subclass RcDialog
::method init
forward class (super) continue
if self~initCode <> 0 then return self~initCode
-- Initialize the data attributes. These attributes are added automatically
-- to this dialog by the ooDialog framework. The attributes are used to
-- reflect the state of the underlying dialog controls.
self~IDC_RB_MALE=1
self~IDC_RB_FEMALE=0
self~IDC_EDIT_FNAME= ''
self~IDC_EDIT_LNAME= ''
self~IDC_EDIT_STREET= ''
self~IDC_EDIT_CITY= ''
self~IDC_EDIT_STATE= ''
self~IDC_EDIT_ZIPCODE= ''
self~IDC_EDIT_AGE= ''
return self~initCode
::method initDialog
-- To help with data validation, restrict the number of characters the user
-- can type into these edit controls. Note that in the resource script, the
-- zip code and age edit controls are defined as numeric only. The state edit
-- control is defined as upper-case only.
self~newEdit(IDC_EDIT_STATE)~setLimit(2)
self~newEdit(IDC_EDIT_ZIPCODE)~setLimit(5)
self~newEdit(IDC_EDIT_AGE)~setLimit(3)
/** validate()
*
* The validate() method is invoked automatically by the ooDialog framework when
* the user closes a dialog with 'ok'. The default implementation simply
* returns true. The method is meant to be over-ridden by the programmer, if
* desired, to validate the user input is correct. The method must return .true
* or .false. When .true is returned, the dialog continues to close. If .false
* is returned, the dialog will not be closed.
*
* Here we do a bare minimum of validation. We just check that something has
* been entered for the first and last names.
*/
::method validate
if self~namesEnteredOkay then return .true
-- It's not very user friendly to prevent the user from closing the dialog
-- without letting him know why.
msg = "The last and first names must be specified for each new record."
title = "New Record Input Error"
j = MessageDialog(msg, self~hwnd, title, , "WARNING")
-- Place the focus on the first edit control that has invalid data:
if self~newEdit(IDC_EDIT_FNAME)~getText~strip == "" then
self~focusControl(IDC_EDIT_FNAME)
else
self~focusControl(IDC_EDIT_LNAME)
return .false
/* Simple convenience function to make validate() more readable */
::method namesEnteredOkay private
if self~newEdit(IDC_EDIT_LNAME)~getText~strip == "" then return .false
if self~newEdit(IDC_EDIT_FNAME)~getText~strip == "" then return .false
return .true