At 7:53 pm +0000 19/05/00, Sveinbjorn Thordarson wrote: >I'm playing around a lot with the MacPerl MacOS toolbox modules, and >I've encountered a problem that I cannot understand. Here's the >relevant code: > >FSpOpenResFile('myRes.rsrc', '') or CouldNotLoadResources; >$myPic = RGetResource("PICT", 128); >$pic = new PicHandle($myPic); > > >$dialog = MacColorDialog->new >( >$rect, >$title, >1, >movableDBoxProc(), >0, >[kPictureDialogItem(), Rect->new(0, 0, 425, 325), $myPic], >[kButtonDialogItem(), Rect->new(250, 280, 320, 300), 'Cancel'], >[kButtonDialogItem(), Rect->new(340, 280, 400, 300), 'OK'] >) As written above you have not defined '$rect' and '$title' so the script won't run properly for that reason, but maybe that's just a trivial omission from your posting? You will also need a 'WaitNextEvent' loop at the end, terminated by some window closing condition. As the window type hasn't got a 'goaway' box you need to define a variable (say $OK) which is set when one or other of the buttons gets a hit. You need therefore also to set up routines to handle a clicks on the buttons such as: $dlg->item_hit(2, sub { $OK = 1 }); $dlg->item_hit(3, sub { $OK = 1 }); WaitNextEvent until $OK; dispose $dlg; MacPerl cleans up pointers but handles have to be disposed of by the programmer, so you need the line 'dispose $dlg' after the window closes. The question of the picture is more difficult. One thing is for sure: the line: [kPictureDialogItem(), Rect->new(0, 0, 425, 325), $myPic] will not work. I haven't got a '.rscs' file handy so used MacPerl's PICT resource ID == 128. From this you can get the 'picHandle' from GetPicture() (in QuickDraw) and the rectangle from picFrame() (also in QuickDraw). However the first snag is that MacDialog looks for a reference of type "Handle" and will jib at a "picHandle". It is possible to work round this problem by re-blessing the 'picHandle' as a simple 'Handle' which will then be acceptable to: SetDialogItem($dlg->{port},1, kPictureDialogItem, $pic, $pic_r); The next problem is to get the picture dialog item properly inserted into the dialog item list. The only way I can think of to do this is to insert a dummy 'place-holder' as the first item in the list of references given to MacColorDialog in the first instance. The dialog item 'set' as above will then slip into place as number 1 in the list. I feel there must be a less clunky way to do this, and maybe someone else will have some thoughts on the matter. The version below (which works for OK here) brings all these things together. I hope this is some help. Alan Fry #------------------------------------------------------------------------------# #!perl -w use Mac::Events; use Mac::Windows; use Mac::Dialogs; use Mac::QuickDraw; use strict; my $title = 'paladeen'; my $rect = Rect->new(16, 52, 436, 362); my $OK; my $pic = GetPicture(128); my $pic_r = OffsetRect($pic->picFrame, 60, 80); bless $pic, "Handle"; my $dlg = MacColorDialog->new ( $rect, $title, 1, movableDBoxProc(), 0, ( [0, Rect->new(0, 0, 0, 0), ''], [kButtonDialogItem, Rect->new(250, 280, 320, 300), 'Cancel'], [kButtonDialogItem, Rect->new(340, 280, 400, 300), 'OK'], ) ); SetDialogItem($dlg->{port},1, kPictureDialogItem, $pic, $pic_r); $dlg->item_hit(2, sub { print "OK, quitting\n"; $OK = 1 }); $dlg->item_hit(3, sub { print "That's OK\n" }); WaitNextEvent until $OK; dispose $dlg; #------------------------------------------------------------------------------# # ===== Want to unsubscribe from this list? # ===== Send mail with body "unsubscribe" to macperl-request@macperl.org