Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / tools / perl-5.8.0 / lib / site_perl / 5.8.0 / sun4-solaris / Tk / demos / widget_lib / mkTextWind.pl
CommitLineData
86530b38
AT
1
2
3sub textWindOn {
4
5 $mkTextWind::w_s2->destroy if Exists($mkTextWind::w_s2);
6 $mkTextWind::w_s2 = $mkTextWind->Scrollbar(-orient => 'horizontal', -command => ['xview', $mkTextWind::w_t]);
7 $mkTextWind::w_s2->pack('-after' => $mkTextWind_ok, -side => 'bottom', -fill => 'x');
8 $mkTextWind::w_t->configure(-xscrollcommand => ['set', $mkTextWind::w_s2], -wrap => 'none');
9
10} # end textWindOn
11
12
13sub textWindOff {
14
15 $mkTextWind::w_s2->destroy if Exists($mkTextWind::w_s2);
16 $mkTextWind::w_t->configure(-xscrollcommand => undef, -wrap => 'word');
17
18} # end textWindOff
19
20
21sub textWindPlot {
22
23 return if Exists($mkTextWind_c);
24 $mkTextWind_c = $mkTextWind::w_t->Canvas(-relief => 'sunken', -width => '450', -height => '300',
25 -cursor => 'top_left_arrow');
26
27 $font = '-Adobe-Helvetica-Medium-R-Normal--*-180-*-*-*-*-*-*';
28
29 $mkTextWind_c->create('line', qw(100 250 400 250 -width 2));
30 $mkTextWind_c->create('line', qw(100 250 100 50 -width 2));
31 $mkTextWind_c->create('text', 225, 20, -text => 'A Simple Plot', -fill => 'brown', -font => $font);
32
33 my($i, $x, $y, $point, $item);
34 for ($i = 0; $i <= 10; $i++) {
35 $x = 100 + ($i*30);
36 $mkTextWind_c->create('line', $x, 250, $x, 245, -width => 2);
37 $mkTextWind_c->create('text', $x, 254, -text => 10*$i, -anchor => 'n', -font => $font);
38 }
39 for ($i = 0; $i <= 5; $i++) {
40 $y = 250 - ($i*40);
41 $mkTextWind_c->create('line', 100, $y, 105, $y, -width => 2);
42 $mkTextWind_c->create('text', 96, $y, -text => $i*50.0, -anchor => 'e', -font => $font);
43 }
44
45 foreach $point ([12, 56], [20, 94], [33, 98], [32, 120], [61, 180], [75, 160], [98, 223]) {
46 $x = 100 + (3 * $point->[0]);
47 $y = 250 - (4 * $point->[1]) / 5;
48 $item = $mkTextWind_c->create('oval', $x-6, $y-6, $x+6, $y+6, qw(-width 1 -outline black -fill SkyBlue2));
49 $mkTextWind_c->addtag('point', 'withtag', $item);
50 }
51
52 $mkTextWind_c->bind('point', '<Any-Enter>' => [sub {
53 shift->itemconfigure(@_);
54 }, qw(current -fill red)]);
55 $mkTextWind_c->bind('point', '<Any-Leave>' => [sub {
56 shift->itemconfigure(@_);
57 }, qw(current -fill SkyBlue2)]);
58 $mkTextWind_c->bind('point', '<1>' => sub {
59 my($c, $e) = @_;
60 my $e = $c->XEvent;
61 embPlotDown($c, $e->x, $e->y);
62 });
63 $mkTextWind_c->bind('point', '<ButtonRelease-1>' => sub {
64 shift->dtag('selected');
65 });
66 $mkTextWind_c->Tk::bind('<B1-Motion>' => sub {
67 my($c, $e) = @_;
68 my $e = $c->XEvent;
69 embPlotMove($c, $e->x, $e->y);
70 });
71
72 while ($mkTextWind::w_t->get('plot') =~ / |\t|\n/) {
73 $mkTextWind::w_t->delete('plot');
74 }
75 $mkTextWind::w_t->insert('plot', "\n");
76 $mkTextWind::w_t->window('create', 'plot', -window => $mkTextWind_c);
77 $mkTextWind::w_t->tag('add', 'center', 'plot');
78 $mkTextWind::w_t->insert('plot', "\n");
79
80} # end textWindPlot
81
82
83sub textWindDel {
84
85 if (Exists($mkTextWind_c)) {
86 $mkTextWind::w_t->delete($mkTextWind_c);
87 while ($mkTextWind::w_t->get('plot') =~ / |\t|\n/) {
88 $mkTextWind::w_t->delete('plot');
89 }
90 $mkTextWind::w_t->insert('plot', ' ');
91 }
92
93} # end textWindDel
94
95
96$mkTextWind::embPlot{'lastX'} = 0;
97$mkTextWind::embPlot{'lastY'} = 0;
98
99
100sub embPlotDown {
101
102 my($w, $x, $y) = @_;
103
104 $w->dtag('selected');
105 $w->addtag('selected', 'withtag', 'current');
106 $w->raise('current');
107 $mkTextWind::embPlot{'lastX'} = $x;
108 $mkTextWind::embPlot{'lastY'} = $y;
109
110} # end embPlotDown
111
112
113sub embPlotMove {
114
115 my($w, $x, $y) = @_;
116
117 $w->move('selected', $x - $mkTextWind::embPlot{'lastX'}, $y - $mkTextWind::embPlot{'lastY'});
118 $mkTextWind::embPlot{'lastX'} = $x;
119 $mkTextWind::embPlot{'lastY'} = $y;
120
121} # end embPlotMove
122
123
124sub embDefBg {
125
126 my($t) = @_;
127
128 $t->configure(-background => ($t->configure(-background))[3]);
129
130} # end embDefBg
131
132sub mkTextWind {
133
134 # Create a top-level window with a text widget that demonstrates the use of embedded windows in texts.
135
136 $mkTextWind->destroy if Exists($mkTextWind);
137 $mkTextWind = $top->Toplevel();
138 dpos $mkTextWind;
139 $mkTextWind->title('Text Demonstration - Embedded Windows');
140 $mkTextWind->iconname('Embedded Windows');
141
142 $mkTextWind_ok = $mkTextWind->Button(-text => 'OK', -command => ['destroy', $mkTextWind], -width => 8);
143 $mkTextWind::w_t = $mkTextWind->Text(-setgrid => 'true', -width => 70, -height => 35, -wrap => 'word');
144 my $w_s = $mkTextWind->Scrollbar(-command => ['yview', $mkTextWind::w_t]);
145 $mkTextWind::w_t->configure(-yscrollcommand => ['set', $w_s]);
146 $mkTextWind_ok->pack(-side => 'bottom');
147 $w_s->pack(-side => 'right', -fill => 'y');
148 $mkTextWind::w_t->pack(-expand => 'yes', -fill => 'both');
149 $mkTextWind::w_t->tag('configure', 'bold', -font => '-Adobe-Courier-Bold-O-Normal--*-120-*-*-*-*-*-*');
150 $mkTextWind::w_t->tag('configure', 'center', -justify => 'center', -spacing1 => '5m', -spacing3 => '5m');
151 $mkTextWind::w_t->tag('configure', 'buttons', -lmargin1 => '1c', -lmargin2 =>'1c', -rmargin => '1c', -spacing1 => '3m',
152 -spacing2 => 0, -spacing3 => 0);
153
154 my $w_t_on = $mkTextWind::w_t->Button(-text => 'Turn On', -command => \&textWindOn, -cursor => 'top_left_arrow');
155 my $w_t_off = $mkTextWind::w_t->Button(-text => 'Turn Off', -command => \&textWindOff, -cursor => 'top_left_arrow');
156 my $w_t_click = $mkTextWind::w_t->Button(-text => 'Click Here', -command => \&textWindPlot, -cursor => 'top_left_arrow');
157 my $w_t_delete = $mkTextWind::w_t->Button(-text => 'Delete', -command => \&textWindDel, -cursor => 'top_left_arrow');
158
159 $mkTextWind::w_t->insert('end', "A text widget can contain other widgets embedded ");
160 $mkTextWind::w_t->insert('end', "it. These are called ");
161 $mkTextWind::w_t->insert('end', "embedded windows", 'bold');
162 $mkTextWind::w_t->insert('end', ", and they can consist of arbitrary widgets. ");
163 $mkTextWind::w_t->insert('end', "For example, here are two embedded button ");
164 $mkTextWind::w_t->insert('end', "widgets. You can click on the first button to ");
165 $mkTextWind::w_t->window('create', 'end', -window => $w_t_on);
166 $mkTextWind::w_t->insert('end', " horizontal scrolling, which also turns off ");
167 $mkTextWind::w_t->insert('end', "word wrapping. Or, you can click on the second ");
168 $mkTextWind::w_t->insert('end', "button to\n");
169 $mkTextWind::w_t->window('create', 'end', -window => $w_t_off);
170 $mkTextWind::w_t->insert('end', " horizontal scrolling and turn back on word wrapping.\n\n");
171
172 $mkTextWind::w_t->insert('end', "Or, here is another example. If you ");
173 $mkTextWind::w_t->window('create', 'end', -window => $w_t_click);
174 $mkTextWind::w_t->insert('end', " a canvas displaying an x-y plot will appear right here.");
175 $mkTextWind::w_t->mark('set', 'plot', 'insert');
176 $mkTextWind::w_t->mark('gravity', 'plot', 'left');
177 $mkTextWind::w_t->insert('end', " You can drag the data points around with the mouse, ");
178 $mkTextWind::w_t->insert('end', "or you can click here to ");
179 $mkTextWind::w_t->window('create', 'end', -window => $w_t_delete);
180 $mkTextWind::w_t->insert('end', " the plot again.\n\n");
181
182 $mkTextWind::w_t->insert('end', "You may also find it useful to put embedded windows in ");
183 $mkTextWind::w_t->insert('end', "a text without any actual text. In this case the ");
184 $mkTextWind::w_t->insert('end', "text widget acts like a geometry manager. For ");
185 $mkTextWind::w_t->insert('end', "example, here is a collection of buttons laid out ");
186 $mkTextWind::w_t->insert('end', "neatly into rows by the text widget. These buttons ");
187 $mkTextWind::w_t->insert('end', "can be used to change the background color of the ");
188 $mkTextWind::w_t->insert('end', "text widget (\"Default\" restores the color to ");
189 $mkTextWind::w_t->insert('end', "its default). If you click on the button labeled ");
190 $mkTextWind::w_t->insert('end', "\"Short\", it changes to a longer string so that ");
191 $mkTextWind::w_t->insert('end', "you can see how the text widget automatically ");
192 $mkTextWind::w_t->insert('end', "changes the layout. Click on the button again ");
193 $mkTextWind::w_t->insert('end', "to restore the short string.\n");
194
195 my $w_t_default = $mkTextWind::w_t->Button(-text => 'Default', -command => [\&embDefBg, $mkTextWind::w_t],
196 -cursor => 'top_left_arrow');
197 $mkTextWind::w_t->window('create', 'end', -window => $w_t_default, -padx => 3);
198 $embToggle = 'Short';
199 my $w_t_toggle = $mkTextWind::w_t->Checkbutton(-textvariable => \$embToggle, -indicatoron => 0, -variable => \$embToggle,
200 -onvalue => 'A much longer string', -offvalue => 'Short', -cursor => 'top_left_arrow');
201 $mkTextWind::w_t->window('create', 'end', -window => $w_t_toggle, -padx => 3, -pady => 2);
202 my($i, $color) = (1, '');
203 foreach $color (qw(AntiqueWhite3 Bisque1 Bisque2 Bisque3 Bisque4 SlateBlue3 RoyalBlue1 SteelBlue2 DeepSkyBlue3 LightBlue1
204 DarkSlateGray1 Aquamarine2 DarkSeaGreen2 SeaGreen1 Yellow1 IndianRed1 IndianRed2 Tan1 Tan4)) {
205 my $color_name = "w_t_color${i}";
206 ${$color_name} = $mkTextWind::w_t->Button(-text => "$color", -cursor => 'top_left_arrow');
207 ${$color_name}->configure(-command => [sub {
208 shift->configure(@_);
209 }, $mkTextWind::w_t, -background => $color]);
210 $mkTextWind::w_t->window('create', 'end', -window => ${$color_name}, -padx => 3, -pady => 2);
211 $i++;
212 }
213 $mkTextWind::w_t->tag('add', 'buttons', $w_t_default, 'end');
214
215} # end mkTextWind
216
217
218
219
220
2211;