1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401
|
-----------------------------------------------------------------------
-- GtkAda - Ada95 binding for the Gimp Toolkit --
-- --
-- Copyright (C) 1998-2000 E. Briot, J. Brobecker and A. Charlet --
-- Copyright (C) 2000-2006 AdaCore --
-- --
-- This library is free software; you can redistribute it and/or --
-- modify it under the terms of the GNU General Public --
-- License as published by the Free Software Foundation; either --
-- version 2 of the License, or (at your option) any later version. --
-- --
-- This library is distributed in the hope that it will be useful, --
-- but WITHOUT ANY WARRANTY; without even the implied warranty of --
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU --
-- General Public License for more details. --
-- --
-- You should have received a copy of the GNU General Public --
-- License along with this library; if not, write to the --
-- Free Software Foundation, Inc., 59 Temple Place - Suite 330, --
-- Boston, MA 02111-1307, USA. --
-- --
-----------------------------------------------------------------------
with Glib; use Glib;
with Gtk.Adjustment; use Gtk.Adjustment;
with Gtk.Alignment; use Gtk.Alignment;
with Gtk.Box; use Gtk.Box;
with Gtk.Check_Button; use Gtk.Check_Button;
with Gtk.Enums; use Gtk.Enums;
with Gtk.GEntry; use Gtk.GEntry;
with Gtk.Label; use Gtk.Label;
with Glib.Main; use Glib.Main;
with Gtk.Option_Menu; use Gtk.Option_Menu;
with Gtk.Progress_Bar; use Gtk.Progress_Bar;
with Gtk.Radio_Menu_Item; use Gtk.Radio_Menu_Item;
with Gtk.Spin_Button; use Gtk.Spin_Button;
with Gtk.Table; use Gtk.Table;
with Gtk.Widget; use Gtk.Widget;
with Gtk; use Gtk;
with Gtkada.Types; use Gtkada.Types;
with Common; use Common;
package body Create_Progress is
package Time_Cb is new Glib.Main.Generic_Sources (Gtk_Progress_Bar);
Items1 : constant Chars_Ptr_Array :=
"Left-Right" + "Right-Left" + "Bottom-Top" + "Top-Bottom";
type ProgressData is record
Pbar : Gtk_Progress_Bar;
Block_Spin : Gtk_Spin_Button;
X_Align_Spin : Gtk_Spin_Button;
Y_Align_Spin : Gtk_Spin_Button;
Step_Spin : Gtk_Spin_Button;
Act_Blocks_Spin : Gtk_Spin_Button;
Label : Gtk_Label;
Omenu1 : Gtk_Option_Menu;
Omenu1_Group : Widget_SList.GSlist;
Gentry : Gtk_Entry;
Timer : G_Source_Id;
end record;
Pdata : ProgressData;
----------
-- Help --
----------
function Help return String is
begin
return "A @bGtk_Progress_Bar@B is a widget that you can use to display"
& " the status of an operation. In this example, the progress bar is"
& " associated with a @bTimeout@B, and thus updates itself"
& " periodically.";
end Help;
----------------------
-- Progress_Timeout --
----------------------
function Progress_Timeout (Pbar : Gtk_Progress_Bar) return Boolean is
pragma Warnings (Off, Pbar);
New_Val : Gdouble;
Adj : constant Gtk_Adjustment := Get_Adjustment (Pdata.Pbar);
begin
New_Val := Get_Value (Adj) + 5.0;
if New_Val > Get_Upper (Adj) then
New_Val := Get_Lower (Adj);
end if;
Set_Value (Adj, New_Val);
return True;
end Progress_Timeout;
----------------------
-- Destroy_Progress --
----------------------
procedure Destroy_Progress (Window : access Gtk_Widget_Record'Class) is
pragma Warnings (Off, Window);
begin
Remove (Pdata.Timer);
Pdata.Omenu1_Group := Widget_SList.Null_List;
Pdata.Timer := 0;
-- Note: we are in a callback for destroy, so the window will be
-- destroyed elsewhere. No need to do that here.
end Destroy_Progress;
------------------------
-- Toggle_Orientation --
------------------------
procedure Toggle_Orientation (Widget : access Gtk_Widget_Record'Class) is
pragma Warnings (Off, Widget);
I : constant Natural := Selected_Button (Pdata.Omenu1_Group);
begin
Set_Orientation (Pdata.Pbar,
Gtk_Progress_Bar_Orientation'Val (3 - I));
end Toggle_Orientation;
----------------------
-- Toggle_Show_Text --
----------------------
procedure Toggle_Show_Text (Widget : access Gtk_Check_Button_Record'Class)
is
begin
Set_Show_Text (Progress => Pdata.Pbar,
Show_Text => Get_Active (Widget));
Set_Sensitive (Pdata.Gentry, Get_Active (Widget));
Set_Sensitive (Pdata.X_Align_Spin, Get_Active (Widget));
Set_Sensitive (Pdata.Y_Align_Spin, Get_Active (Widget));
end Toggle_Show_Text;
------------------
-- Adjust_Align --
------------------
procedure Adjust_Align (Adj : access Gtk_Adjustment_Record'Class) is
pragma Warnings (Off, Adj);
begin
Set_Text_Alignment
(Pdata.Pbar,
Gfloat (Get_Value (Pdata.X_Align_Spin)),
Gfloat (Get_Value (Pdata.Y_Align_Spin)));
end Adjust_Align;
--------------------------
-- Toggle_Activity_Mode --
--------------------------
procedure Toggle_Activity_Mode
(Widget : access Gtk_Check_Button_Record'Class)
is
begin
Set_Activity_Mode (Pdata.Pbar, Get_Active (Widget));
Set_Sensitive (Pdata.Step_Spin, Get_Active (Widget));
Set_Sensitive (Pdata.Act_Blocks_Spin, Get_Active (Widget));
end Toggle_Activity_Mode;
-------------------
-- Entry_Changed --
-------------------
procedure Entry_Changed (Widget : access Gtk_Widget_Record'Class) is
pragma Warnings (Off, Widget);
begin
Set_Format_String (Pdata.Pbar, Get_Text (Pdata.Gentry));
end Entry_Changed;
---------
-- Run --
---------
procedure Run (Frame : access Gtk.Frame.Gtk_Frame_Record'Class) is
Vbox : Gtk_Box;
Vbox2 : Gtk_Box;
Hbox : Gtk_Box;
Frame2 : Gtk_Frame;
Align : Gtk_Alignment;
Adj : Gtk_Adjustment;
Label : Gtk_Label;
Tab : Gtk_Table;
Check : Gtk_Check_Button;
begin
Set_Label (Frame, "Progress Bar");
Pdata.Timer := 0;
Gtk_New_Vbox (Vbox, False, 5);
Set_Border_Width (Vbox, 10);
Add (Frame, Vbox);
Widget_Handler.Connect
(Vbox, "destroy",
Widget_Handler.To_Marshaller (Destroy_Progress'Access));
Gtk_New (Frame2, "Progress");
Pack_Start (Vbox, Frame2, False, True, 0);
Gtk_New_Vbox (Vbox2, False, 5);
Add (Frame2, Vbox2);
Gtk_New (Align,
Xalign => 0.5,
Yalign => 0.5,
Xscale => 0.0,
Yscale => 0.0);
Pack_Start (Vbox2, Align, False, False, 5);
Gtk_New (Pdata.Pbar);
Configure (Pdata.Pbar, 1.0, 1.0, 300.0);
Set_Format_String (Pdata.Pbar, "%v from [%l,%u] (=%p%%)");
Add (Align, Pdata.Pbar);
Pdata.Timer := Time_Cb.Timeout_Add
(100, Progress_Timeout'Access, Pdata.Pbar);
Gtk_New (Align,
Xalign => 0.5,
Yalign => 0.5,
Xscale => 0.0,
Yscale => 0.0);
Pack_Start (Vbox2, Align, False, False, 5);
Gtk_New_Hbox (Hbox, False, 5);
Add (Align, Hbox);
Gtk_New (Label, "Label updated by user :");
Pack_Start (Hbox, Label, False, True, 0);
Gtk_New (Pdata.Label, "");
Pack_Start (Hbox, Pdata.Label, False, True, 0);
Gtk_New (Frame2, "Options");
Pack_Start (Vbox, Frame2, False, True, 0);
Gtk_New_Vbox (Vbox2, False, 5);
Add (Frame2, Vbox2);
Gtk_New (Tab,
Rows => 7,
Columns => 2,
Homogeneous => False);
Pack_Start (Vbox2, Tab, False, True, 0);
Gtk_New (Label, "Orientation :");
Attach (Tab, Label, 0, 1, 0, 1, Enums.Expand or Enums.Fill,
Enums.Expand or Enums.Fill, 5, 5);
Set_Alignment (Label, 0.0, 0.5);
Build_Option_Menu (Pdata.Omenu1, Pdata.Omenu1_Group,
Items1, 0, Toggle_Orientation'Access);
Gtk_New_Hbox (Hbox, False, 0);
Attach (Tab, Hbox, 1, 2, 0, 1, Enums.Expand or Enums.Fill,
Enums.Expand or Enums.Fill, 5, 5);
Pack_Start (Hbox, Pdata.Omenu1, True, True, 0);
Gtk_New (Check, "Show Text");
Check_Handler.Connect
(Check, "clicked",
Check_Handler.To_Marshaller (Toggle_Show_Text'Access));
Attach (Tab, Check, 0, 1, 1, 2, Enums.Expand or Enums.Fill,
Enums.Expand or Enums.Fill, 5, 5);
Gtk_New_Hbox (Hbox, False, 0);
Attach (Tab, Hbox, 1, 2, 1, 2, Enums.Expand or Enums.Fill,
Enums.Expand or Enums.Fill, 5, 5);
Gtk_New (Label, "Format : ");
Pack_Start (Hbox, Label, False, True, 0);
Gtk_New (Pdata.Gentry);
Widget_Handler.Object_Connect
(Pdata.Gentry, "changed",
Widget_Handler.To_Marshaller (Entry_Changed'Access),
Slot_Object => Pdata.Gentry);
Pack_Start (Hbox, Pdata.Gentry, True, True, 0);
Set_Text (Pdata.Gentry, "%v from [%l,%u] (=%p%%)");
Set_USize (Pdata.Gentry, 100, -1);
Set_Sensitive (Pdata.Gentry, False);
Gtk_New (Label, "Text align :");
Attach (Tab, Label, 0, 1, 2, 3, Enums.Expand or Enums.Fill,
Enums.Expand or Enums.Fill, 5, 5);
Set_Alignment (Label, 0.0, 0.5);
Gtk_New_Hbox (Hbox, False, 0);
Attach (Tab, Hbox, 1, 2, 2, 3, Enums.Expand or Enums.Fill,
Enums.Expand or Enums.Fill, 5, 5);
Gtk_New (Label, "x :");
Pack_Start (Hbox, Label, False, True, 5);
Gtk_New (Adj,
Value => 0.5,
Lower => 0.0,
Upper => 1.0,
Step_Increment => 0.1,
Page_Increment => 0.1,
Page_Size => 0.0);
Gtk_New (Pdata.X_Align_Spin, Adj, Climb_Rate => 0.0, The_Digits => 1);
Pack_Start (Hbox, Pdata.X_Align_Spin, False, True, 0);
Set_Sensitive (Pdata.X_Align_Spin, False);
Adj_Handler.Connect
(Adj, "value_changed",
Adj_Handler.To_Marshaller (Adjust_Align'Access));
Gtk_New (Label, "y :");
Pack_Start (Hbox, Label, False, True, 5);
Gtk_New (Adj,
Value => 0.5,
Lower => 0.0,
Upper => 1.0,
Step_Increment => 0.1,
Page_Increment => 0.1,
Page_Size => 0.0);
Gtk_New (Pdata.Y_Align_Spin, Adj, Climb_Rate => 0.0, The_Digits => 1);
Pack_Start (Hbox, Pdata.Y_Align_Spin, False, True, 0);
Set_Sensitive (Pdata.Y_Align_Spin, False);
Adj_Handler.Connect
(Adj, "value_changed",
Adj_Handler.To_Marshaller (Adjust_Align'Access));
Gtk_New (Label, "Block count :");
Attach (Tab, Label, 0, 1, 4, 5, Enums.Expand or Enums.Fill,
Enums.Expand or Enums.Fill, 5, 5);
Set_Alignment (Label, 0.0, 0.5);
Gtk_New_Hbox (Hbox, False, 0);
Attach (Tab, Hbox, 1, 2, 4, 5, Enums.Expand or Enums.Fill,
Enums.Expand or Enums.Fill, 5, 5);
Gtk_New (Adj,
Value => 10.0,
Lower => 2.0,
Upper => 20.0,
Step_Increment => 1.0,
Page_Increment => 5.0,
Page_Size => 0.0);
Gtk_New (Pdata.Block_Spin, Adj, Climb_Rate => 0.0, The_Digits => 0);
Pack_Start (Hbox, Pdata.Block_Spin, False, True, 0);
Set_Sensitive (Pdata.Block_Spin, False);
Gtk_New (Check, "Activity mode");
Check_Handler.Connect
(Check, "clicked",
Check_Handler.To_Marshaller (Toggle_Activity_Mode'Access));
Attach (Tab, Check, 0, 1, 5, 6, Enums.Expand or Enums.Fill,
Enums.Expand or Enums.Fill, 5, 5);
Gtk_New_Hbox (Hbox, False, 0);
Attach (Tab, Hbox, 1, 2, 5, 6, Enums.Expand or Enums.Fill,
Enums.Expand or Enums.Fill, 5, 5);
Gtk_New (Label, "Step size :");
Pack_Start (Hbox, Label, False, True, 0);
Gtk_New (Adj,
Value => 3.0,
Lower => 1.0,
Upper => 20.0,
Step_Increment => 1.0,
Page_Increment => 5.0,
Page_Size => 0.0);
Gtk_New (Pdata.Step_Spin, Adj, Climb_Rate => 0.0, The_Digits => 0);
Pack_Start (Hbox, Pdata.Step_Spin, False, True, 0);
Set_Sensitive (Pdata.Step_Spin, False);
Gtk_New_Hbox (Hbox, False, 0);
Attach (Tab, Hbox, 1, 2, 6, 7, Enums.Expand or Enums.Fill,
Enums.Expand or Enums.Fill, 5, 5);
Gtk_New (Label, "Blocks :");
Pack_Start (Hbox, Label, False, True, 0);
Gtk_New (Adj,
Value => 5.0,
Lower => 2.0,
Upper => 10.0,
Step_Increment => 1.0,
Page_Increment => 5.0,
Page_Size => 0.0);
Gtk_New (Pdata.Act_Blocks_Spin, Adj, Climb_Rate => 0.0,
The_Digits => 0);
Pack_Start (Hbox, Pdata.Act_Blocks_Spin, False, True, 0);
Set_Sensitive (Pdata.Act_Blocks_Spin, False);
Show_All (Vbox);
end Run;
end Create_Progress;
|