Alex Harper <harper@misanthrope.net> writes Mon, 09 Oct 2000 15:44:48 -0500: >I'm attempting to put a Mac face on a existing Perl script. In order to do >this I'd like to use a dialog from Mac::Dialogs. The contents of the dialog >are dynamically generated from a list of available options and inserted into >the dialog using MacDialogItems->add_item which ultimately gets passed to >MacDialog->new. > >All of this is working fine for the standard dialog controls (edit fields, >checkboxes, etc.), but now I need to add a popup menu to the dialog. > >I haven't been able to find a sample of how to do this anywhere... Does >anyone have a working sample of a popup menu in a dialog? MPPE discusses >popups only briefly and then says they require a resource (I presume a CNTL >resource) which won't work for my purpose (because the menu is generated >from data inside the script). I see references from others in the list >archives with similar questions but the general claim seems to be that >popups are unstable and lists should be used instead. > >Am I looking at a rewrite to use standard windows with controls (losing the >benefits of the Dialog Manager)? Are popups usable with dynamic menus or >must I use a list? If I use a list am can I embed the list control into the >dialog, or is a regular window the way to go? The 'tutorial' script below gives an example with some notes. Two other details come to mind: a) the popup ID must be capable of representation by an ASCII character -- i.e. in the range 0-255 (taking care not to trample on some other existing ID) b) the need for the line "InsertMenu(HANDLE, -1)", which is not documented anywhere I think. HTH, Alan Fry ---------------------------------------------------------------------- #!perl -w # 21-May-2000 <ajf@afco.demon.co.uk> use Mac::Events; use Mac::Windows; use Mac::QuickDraw; use Mac::Controls; use Mac::Menus; use strict; my $OK; my @menu_text = ('Button', 'Static Text', 'Edit Text', 'Check Box', 'Radio Button'); my $pum = NewMenu(200,'myMenu'); map { AppendMenu($pum, $_) } @menu_text; InsertMenu($pum, -1); my $win_r = new Rect 50, 50, 285, 240; my $win = MacWindow->new($win_r, "POPUP", 1, 8, 1); $win->sethook('drawgrowicon', sub {1} ); my $c_r = Rect->new(10, 10, 230, 30); my $c = $win->new_control( $c_r, 'Type', 1, popupTitleLeftJust, 200, 60, popupMenuProc ); SetControlValue($c->{control}, 2); my $b_r = Rect->new(155, 160, 225, 180); my $b = $win->new_control($b_r, "ACCEPT", 1, 0, 0, 1, 32); $b->sethook('hit', sub { print GetControlValue($c->{control}), "\n"; DeleteMenu(200); $OK = 1; } ); while($win->window and !$OK) { WaitNextEvent } END { $win->dispose if defined $win; DisposeMenu($pum) if defined $pum; DisposeControl($c->{control}) if defined $c; } # NB The rectangle for the popup does not do quite what you'd expect: # the bottom determines the height position of "title"; # the top seems to do nothing, but presumably should allow enough room; # the left side determines the start of the "title" field; # the right side limits the rightmost end of the popup; # the end of the "title" field is determined by param 6; # the width of the popup is determined by the longest string. ---------------------------------------------------------------------- ==== Want to unsubscribe from this list? ==== Send mail with body "unsubscribe" to macperl-toolbox-request@macperl.org