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

Re: [MacPerl-Toolbox] forwarding events



I think this fixes the 'Cut', Copy' and 'Paste' problem. However, some of
the other menu's are inappropriate and should probably be disabled or
revised.

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, $oldEdit, $newEdit);

$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), '' ],
  )
);

$oldEdit = GetMenu(130);
new_menu();
change_menubar();

$Event[keyDown] = \&changeEditField;

WaitNextEvent while $dlg->window;

END {
    dispose $dlg if defined $dlg;
    DeleteMenu(2048);
    InsertMenu($oldEdit, 133)
}

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 { SelectDialogItemText($dlg->window, $field) }

sub new_menu {
    $newEdit = MacMenu->new (
        2048, 'Edit', (
            ['Cut',   \&edit_menu, 'X'],
            ['Copy',  \&edit_menu, 'C'],
            ['Paste', \&edit_menu, 'V'],
        )
    )
}

sub change_menubar {
    DeleteMenu(130);
    InsertMenu($newEdit->{menu}, 133)
}

sub edit_menu {
    my($m, $v) = @_;
    if ($v == 1) { DialogCut($dlg->window) }
    if ($v == 2) { DialogCopy($dlg->window) }
    if ($v == 3) { DialogPaste($dlg->window) }
}

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



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