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

Re: [MacPerl-Toolbox] forwarding events



Jan Hofmann writes Fri, 09 Jul 1999 11:32:08 +0200:

>Of course it was your idea to take a look at the soubroutine key(). I
>tried
>so many different things out; maybe I got a little confused late at
>night. #-)
>I'm sorry. Thanks for your help.

Not at all -- I hadn't got in mind what you actually did here. It does the
trick.

I have done a few tweaks to your script below, which I hope might be useful.

Firstly it occurs to me you relly want to preserve the 'normal' function of
the arrow keys otherwise you lose the ability to handle strings longer than
will fit in the box. So I suggest Cmd-ArrowKeys to step around the window.

The problem of machine crashes with 'Cut', 'Copy' and 'Paste' is
temporarily avoided by disabling the 'Edit' menu. The key equivalents work
as expected however.

I will try tomorrow to get the MenuBar 'Cut', 'Copy' and 'Paste' working as
well. I think it should be possible.

Alan Fry

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

#!perl

use Mac::Events;
use Mac::Events qw(@Event);
use Mac::Windows;
use Mac::Dialogs;
use Mac::QuickDraw;
use Mac::Menus;

$box = Rect->new(0, 0, 50, 15);
$win = Rect->new(20, 50, 230, 145);
my $field;

$dlg = MacDialog->new($win,"", 1, 4, 1, (
    [ kEditTextDialogItem, OffsetRect($box,  10, 10), '' ],
    [ kEditTextDialogItem, OffsetRect($box,  80, 10), '' ],
    [ kEditTextDialogItem, OffsetRect($box, 150, 10), '' ],
    [ kEditTextDialogItem, OffsetRect($box,  10, 40), '' ],
    [ kEditTextDialogItem, OffsetRect($box,  80, 40), '' ],
    [ kEditTextDialogItem, OffsetRect($box, 150, 40), '' ],
    [ kEditTextDialogItem, OffsetRect($box,  10, 70), '' ],
    [ kEditTextDialogItem, OffsetRect($box,  80, 70), '' ],
    [ kEditTextDialogItem, OffsetRect($box, 150, 70), '' ],
  )
);

$mnu = GetMenu(130);
DisableItem($mnu, 0);

$Event[keyDown] = \&changeEditField;

WaitNextEvent while $dlg->window;

END {
    dispose $dlg if defined $dlg;
    EnableItem($mnu, 0)
}

sub  changeEditField {
    my $ev    =  $_[0];
    $field =  $dlg->window->editField + 1;
    my $char  =  $ev->character;

    if ($ev->modifiers & 256) {
        if    ($char == 31 ) {$field = ($field + 2) % 9 + 1; move_caret() }
        elsif ($char == 30 ) {$field = ($field - 4) % 9 + 1; move_caret() }
        elsif ($char == 29 ) {
            if ($field % 3 == 0) {$field -= 2; move_caret() }
            else {$field = $field  % 9 + 1; move_caret() }
        }
        elsif ($char == 28 ) {
            if ($field % 3 == 1) { $field += 2; move_caret()}
            else {$field = ($field -2) % 9 + 1; move_caret() }
        }
    }
    $dlg->key($ev->key)
}

sub move_caret {
    my $len=length($dlg->item_text($field) );
    SelectDialogItemText($dlg->window, $field,0,$len);
}

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=



==== Want to unsubscribe from this list?
==== Send mail with body "unsubscribe" to macperl-toolbox-request@macperl.org