[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] Fun with Dialogs and Lists



Well, I'm trying to get the hang of using dialogs with MacPerl. I would 
like to create a dialog with a couple of buttons, an editable text field, 
and (here's the hard part) a list.

So I'm tring to plug in a list using SetDialogItemProc, but it just isn't 
working for me. At this point, I'm getting a "not a Scalar reference" 
error. Could some kind ToolBox expert take a look at the following and 
tell me what I'm scrwing up?

Thanks!

Jim

------------------

use Mac::Events;
use Mac::Windows;
use Mac::Dialogs;
use Mac::Lists;
use Mac::QuickDraw;

$bounds = new Rect 50, 50, 640, 400;
$dlg = 
	new MacDialog 
		$bounds,"Image Alter",1, documentProc,1, (
			[ kButtonDialogItem,     new Rect( 10, 30,  90, 50), "OK"	],
			[ kButtonDialogItem,     new Rect(115, 30, 195, 50), "Cancel"	],
			[ kStaticTextDialogItem, new Rect( 10,  10, 190, 20), "Click a button" 
],
			[ kEditTextDialogItem, new Rect( 10,  270, 190, 290), "test" ],
			[ kUserDialogItem, new Rect(10, 60, 300, 200), "dummy" ] #just a 
holder, list goes here
  );

SetDialogDefaultItem $dlg->window, 1; # make the OK button the default
SetDialogCancelItem  $dlg->window, 2; # make the cancel button, well, 
cancel

$dlg->item_hit(1 => sub { $OK = 1; });	# make the responses returned by 
the buttons
$dlg->item_hit(2 => sub { $OK = 0; });

SetDialogItemProc ($dlg, 4, &BuildList); #make the fourth item point to 
my list procedure...
# Except it doesn't work!

while ($dlg->window) { # just loop until the dialog is closed
   WaitNextEvent;
}



print "You clicked ", ($OK ? "OK" : "Cancel"), "\n";

dispose $dlg; # get rid of the dialog


# END MAIN

sub BuildList {

@imgpaths=("this is a test 1","this is a test 2","this is a test 3"); 
#make a list

$imgpathslength=@imgpaths; # get the length of the list

$img_list= $dlg->new_list(

        new Rect(10, 60, 300, 200), # x1,y1,x2,y2 coords of box holding 
the list
        new Rect(0, 0, 1, $imgpathslength), # set the vertical length of 
the list
        new Point(280, 15), #set the cell size in width, heighth
        0,
        1,
        0);

SetPort($dlg->window); # not sure why this is here

foreach $i (@imgpaths) {
$img_list->set(0, $k, $i);

	$k++;
	}

$img_list->list->selFlags($img_list->list->selFlags | lNoExtend | 
lOnlyOne);
LSetSelect(1, new Point(0,0), $img_list->list); 
#  show it flag, which cell to select (row,col), which list

return(0);

} # end sub buildlist

***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch