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

Re: [MacPerl] Fun with Dialogs and Lists



Jim Burton wrote on Tue, 3 Mar 1998 16:46:37 -0700

>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?

I don't think you can use the sequence:
         ...
>     [ kUserDialogItem, new Rect(10, 60, 300, 200), "dummy" ],
         ...
>     SetDialogItemProc ($dlg, 4, &BuildList);

since 'kUserDialogItem' expects a pocedure to draw the dialog item I think,
although it must be said I am far from sure about its intended use.

However the script at the end works. I'm not sure if it will quite do what
you want but it might give you some ideas.

Tinkering with it this morning I found that you need to alter line 469 of
Controls.pm to read as follows:

        my($ctrl) = $win->{controls}->{$$control} if defined $control;

Without the condition an error occurs if the window is clicked outside a
control area. That may be, at least in part, why you got the "not a scalar
reference" error message.

I am not sure if there are any drawbacks with this modification, but it
seems to resolve the problem. Perhaps Matthias might give a ruling here?

Alan Fry

======================================================================

#!perl

use Mac::Events;
use Mac::Windows;
use Mac::Lists;
use Mac::Controls;


$bounds = new Rect 50, 50, 320, 290;
$win = new MacWindow $bounds, "List", 1, 4, 1;
$win->sethook("drawgrowicon", sub{});

$b1r = new Rect 210, 210, 260, 230;
$b1  = new_control $win $b1r, "List 1", 1, 0, 0, 1, pushButProc;

$b2r = new Rect 140, 210, 190, 230;
$b2  = new_control $win $b2r, "List 2", 1, 0, 0, 1, pushButProc;

$b1->sethook("hit", \&doList1);
$b2->sethook("hit", \&doList2);

$n = 24; # maximum number of lines in list
$list= $win->new_list(
    new Rect(10, 10, 250, 200),
    new Rect(0, 0, 1, $n),
    new Point(250, 20),
    0, 1, 1
);


WaitNextEvent while $win->window;
dispose $win;

sub doList1 {
    for (0..$n) { $list->set(0, $_, '') }
    $list->set(0, 0, "List item 1");
    $list->set(0, 1, "List item 2");
    $list->set(0, 2, "List item 3");
    $list->set(0, 3, "List item 4");

    LSetSelect 1, new Point(0, 0), $list->list;
    LSetSelect 0, new Point(0, 3), $list->list;
    LScroll 0, -$n, $list->list;
}

sub doList2 {
    for (0..$n-1) { $list->set(0, $_, "this is line $_") }

    LSetSelect 0, new Point(0, 0), $list->list;
    LSetSelect 1, new Point(0, 3), $list->list;
    LScroll 0, -$n, $list->list;
}

======================================================================





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