18.10.2014 Views

Object-oriented Software in Ada 95

Object-oriented Software in Ada 95

Object-oriented Software in Ada 95

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

TUI the implementation 349<br />

with Pack_Constants, Class_Root_W<strong>in</strong>dow, Class_W<strong>in</strong>dow;<br />

use Pack_Constants, Class_Root_W<strong>in</strong>dow, Class_W<strong>in</strong>dow;<br />

package Class_Dialog is<br />

type Dialog is new W<strong>in</strong>dow with private;<br />

procedure Framework ( The:<strong>in</strong> out Dialog;<br />

Abs_X, Abs_Y:<strong>in</strong> Positive;<br />

Max_X: <strong>in</strong> Positive;<br />

Name:<strong>in</strong> Str<strong>in</strong>g; Cb:<strong>in</strong> P_Cbf );<br />

procedure Send_To( The:<strong>in</strong> out Dialog; Ch:<strong>in</strong> Character );<br />

private<br />

subtype Message is Str<strong>in</strong>g( 1 .. W<strong>in</strong>dow_Max_X );<br />

type Dialog is new W<strong>in</strong>dow with record<br />

Dialog_Pos: Positive := 1; --Position <strong>in</strong> <strong>in</strong>put message<br />

Dialog_Len: Positive := 1; --Length of dialogue message<br />

Dialog_Mes: Message := ( others => ' '); --Input message<br />

end record;<br />

end Class_Dialog;<br />

23.7.1 Implementation of the class Dialog<br />

The implementation of the class dialog is:<br />

package body Class_Dialog is<br />

The procedure Framework constructs the style of the dialog w<strong>in</strong>dow and registers the w<strong>in</strong>dow with the <strong>in</strong>put<br />

manager so that user <strong>in</strong>put may be directed to the w<strong>in</strong>dow:<br />

procedure Framework( The:<strong>in</strong> out Dialog;<br />

Abs_X, Abs_Y:<strong>in</strong> Positive;<br />

Max_X:<strong>in</strong> Positive;<br />

Name:<strong>in</strong> Str<strong>in</strong>g; Cb:<strong>in</strong> P_Cbf ) is<br />

Dashes : Str<strong>in</strong>g( 1 .. Max_X ) := (others=>'-');<br />

beg<strong>in</strong><br />

Create( The, Abs_X, Abs_Y, Max_X, 5 );<br />

The.Dialog_Len := Max_X-2; --User <strong>in</strong>put<br />

The.Dialog_Pos := 1;<br />

--In Dialog<br />

Set_Call_Back( The, Cb ); --Call back fun<br />

Put( The, "Dialog| " ); Put( The, Name ); --Dialog title<br />

Position( The, 1, 2 ); Put( The, Dashes ); --L<strong>in</strong>e<br />

Position( The, 1, 3 ); Put( The, C_Cursor );--Cursor<br />

Make_W<strong>in</strong>dow( The, Visible );<br />

Register( The'Unchecked_Access, C_Switch ); --Activation Chr<br />

end Framework;<br />

For example, the fragment of code:<br />

declare<br />

Input : Dialog;<br />

--Input W<strong>in</strong>dow<br />

beg<strong>in</strong><br />

Framework( Input, 5, 10, 22, --Input W<strong>in</strong>dow<br />

"Miles", User_Input'access );<br />

end;<br />

would produce the follow<strong>in</strong>g dialog box whose top left-hand corner on the screen is at position (5,10):<br />

© M A Smith - May not be reproduced without permission

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!