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

[MacPerl-Toolbox] window/Mac::TextEdit question



I'm porting a program to the Mac, trying to replace the command line args
with a settings box that pops up when the program is run.  I'm having trouble
dealing with the text input boxes, they pop up fine, but I can't set them or
get the user input value out.  

The problem seems to be that I don't understand where the reference is coming
out of the call to make the text box using Mac::TextEdit.
Can someone point out where I lost my handle?


Thanks,

Jim Lund
jsl21053@welch.jhu.edu, jsl21053@jhmi.edu
------------------------------------

#!perl -w
use strict;

 
use Mac::QuickDraw;
use Mac::Windows;
use Mac::Controls;
use Mac::Events;
use Mac::Fonts;
use Mac::TextEdit;

#
#Declare subroutines and global variables.
#
sub RADIO;

my $x_margin=36;
my $y_margin=36;
my $font="Times-Roman";
my $font_size=9;
my $landscape=0;
my $scale=1.0;
my $html_frame_rows=0;
my $frames=0;
my $x_size=612;
my $y_size=792;
my $html_output=1;
my ($win,$w1,$w2,$w3,$w4,$w5,$w6,$w7,$w8,$w9,$w10,$w11,$w12);
my ($w1r,$w2r,$w3r,$w4r,$w5r,$w6r,$w7r,$w8r,$w9r,$w10r,$w11r,$w12r);
my ($OK,$cancel,$style,$helvetica);


END { $win->dispose() if (defined($win)) }


#
#MacPerl window gets options.
#

#
#Open window.
#
$style=noGrowDocProc();
$win = new MacWindow (new Rect(20, 50, 400, 835), "Fplot, ver .99", 1, $style,
1);
$win->sethook(drawgrowicon => sub {}); # eliminate fake grow box


#
#Fill window with settings.
#
$w1r = new Rect (160, 755,  270, 775);
$w1  = new_control $win $w1r, "Generate graph", 1, 0, 0, 1, pushButProc;
$w1->sethook("hit", sub { $OK=1; });

$w2r = new Rect (100, 755, 150, 775);
$w2  = new_control $win $w2r, "Cancel", 1, 0, 0, 1, pushButProc;
$w2->sethook("hit", sub { $cancel=1; });


#
#HTML only options
#
$w3r = new Rect (10,  10, 150, 30);
$w3  = new_control $win $w3r, "HTML output", 1, 1, 0, 1, radioButProc();
$w3->sethook("hit", sub {&RADIO('w3','w3','w7');$html_output=1; });

$w7r = new Rect (10,  145, 150, 165);
$w7  = new_control $win $w7r, "Postscript output", 1, 0, 0, 1, radioButProc();
$w7->sethook("hit", sub {&RADIO('w7','w3','w7');$html_output=0; });


#
#Frames check box and dependant rows/columns pair of radio buttons
#
my @dlg_frames=(1,0);

$w4r = new Rect (50,  60, 150, 80);
$w4 = new_control $win $w4r, "Frames", 1, 0, 0, 1, checkBoxProc(); 
$w4->sethook("hit", sub {
	SetControlValue($w4->{control}, !GetControlValue($w4->{control}));
	if (!GetControlValue($w4->{control})) {

@dlg_frames=(GetControlValue($w5->{control}),GetControlValue($w6->{control}));
		SetControlValue($w5->{control},0);
		SetControlValue($w6->{control},0);
		}
	else {
		SetControlValue($w5->{control},$dlg_frames[0]);
		SetControlValue($w6->{control},$dlg_frames[1]);
		}
	$frames=GetControlValue($w4->{control});
	});

$w5r = new Rect (70, 85, 160, 105);
$w5  = new_control $win $w5r, "Vertical", 1, 0, 0, 1, radioButProc();
$w5->sethook("hit", sub {
	return if (!GetControlValue($w4->{control}));
	&RADIO('w5','w5','w6');
	$html_frame_rows=0;
	});

$w6r = new Rect (70, 110, 160, 130);
$w6  = new_control $win $w6r, "Horizontal", 1, 0, 0, 1, radioButProc();
$w6->sethook("hit", sub {
	return if (!GetControlValue($w4->{control}));
	&RADIO('w6','w5','w6');
	$html_frame_rows=1;
	});


#
#PS only options
#
#8-14
#
$w8r = new Rect (50,  220, 170, 240);
$w8  = new_control $win $w8r, "Portrait", 1, 0, 0, 1, radioButProc();
$w8->sethook("hit", sub {
	return if (!GetControlValue($w7->{control}));
	&RADIO('w8','w8','w9');
	$landscape=0;
	});

$w9r = new Rect (50,  245, 170, 265);
$w9  = new_control $win $w9r, "Landscape", 1, 1, 0, 1, radioButProc();
$w9->sethook("hit", sub {
	return if (!GetControlValue($w7->{control}));
	&RADIO('w9','w8','w9');
	$landscape=1;
	});



#
#<------Text fields which are giving me problems---->
#
#
$w10r = new Rect (50,  270, 200, 285);
$w10 = $win->new_textedit($w10r,$w10r);

#None of these 3 lines work:
#TESetText("Times-Roman",$win);
#$w10->sethook("hit", sub { $font=$w10->TEGetText; });
#$font=TEGetText($w10);


$w11r = new Rect (50,  295, 80, 310);
$w11 = $win->new_textedit($w11r,$w11r);

$w12r = new Rect (50,  320, 80, 335);
$w12 = $win->new_textedit($w12r,$w12r);
#
#
#
#<-------End problem area.---->
#


#
#Adds the static text and separator lines to the window.
#
$win->sethook('redraw' => \&DRAW_IT);

$helvetica = GetFNum "Helvetica" or die $^E;

sub DRAW_IT {
TextFont($helvetica);
TextSize(12);
TextFace(bold);
MoveTo (30, 45);
DrawString "HTML options";
MoveTo (30,  180);
DrawString "PS options";
MoveTo (50, 205);
DrawString "Orienation";
MoveTo (205,  280);
DrawString "Font";
MoveTo ( 85,  305);
DrawString "X-margin in points";
MoveTo (85,  330);
DrawString "Y-margin in points";
MoveTo (10,  365);
DrawString "General options";


#
#Draw box dividers.
#
MoveTo(0, 137);
LineTo(380, 137); 
MoveTo(0, 348);
LineTo(380, 348); 
}



#
#Window loop.
#
while ($win->window) {
	WaitNextEvent;
	if ($OK || $cancel) {last;}
	}


#
#Done with settings box, dispose of it.
#
$win->dispose() if (defined($win));



#
#Check what came out:
#
print <<EOM;
Options:
	HTML: $html_output
	
	HTML opts:
		Frames: $frames
			Divided: 		$html_frame_rows

		PS opts:
			Orient: 		$landscape
			Font:			$font
			Margs:			$x_margin, $y_margin
			scale:			$scale
			font_size:		$font_size
			x_size:			$x_size
			y_size:			$y_size

EOM

exit;




#
#$hit is button pressed.  @buttons is list of all buttons in this group.
#All the buttons are turned off, then the hit button is turned on.
#
sub RADIO {
my ($hit,@buttons)=@_;
my ($but);

#
#Strict doesn't like my refs.
#
no strict 'vars';

if (!GetControlValue($$hit->{control})) {
	foreach $but (@buttons) {
		SetControlValue($$but->{control},0);
		}
    SetControlValue($$hit->{control},1);
    }
}

#-----------------------------------------------------------





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