File: scrollable.adb

package info (click to toggle)
libtexttools 2.0.3-4
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 1,188 kB
  • ctags: 635
  • sloc: ada: 13,120; cpp: 1,679; ansic: 777; makefile: 156; sh: 2
file content (186 lines) | stat: -rw-r--r-- 5,803 bytes parent folder | download | duplicates (3)
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
with Ada.Text_IO;
use  Ada.Text_IO;

with Common, OS, Strings, UserIO, Controls, Windows;
use  Common, OS, Strings, UserIO, Controls, Windows;

procedure scrollable is

  procedure ScrollTest is
    line    : aliased aStaticLine;
    ok      : aliased aSimpleButton;
    up      : aliased aSimpleButton;
    down    : aliased aSimpleButton;
    left    : aliased aSimpleButton;
    right   : aliased aSimpleButton;
    list     : aliased aStaticList;

    DT    : aDialogTaskRecord;
    DisplayInfo : ADisplayInfoRec;    
  begin
    GetDisplayInfo( DisplayInfo );

    OpenWindow( To255( "Window Scrolling Test" ), 0, 0, DisplayInfo.H_Res-1, DisplayInfo.V_Res-1, normal, true );

    Init( line, 22, 18, 40, 18 );
    SetText( line, "Click OK to quit." );
    AddControl( line'unchecked_access );
       
    Init( ok, 2, 18, 10, 18, 'o' );
    SetText( ok, "OK" );
    AddControl( ok'unchecked_access );

    Init( up, 12, DisplayInfo.V_Res-4, 20, DisplayInfo.V_Res-4, 'u' );
    SetText( up, "Up" );
    Scrollable( up, false );
    AddControl( up'unchecked_access );

    Init( down, 22, DisplayInfo.V_Res-4, 30, DisplayInfo.V_Res-4, 'o' );
    SetText( down, "Down" );
    Scrollable( down, false );
    AddControl( down'unchecked_access );

    Init( left, 32, DisplayInfo.V_Res-4, 40, DisplayInfo.V_Res-4, 'l' );
    SetText( left, "Left" );
    Scrollable( left, false );
    AddControl( left'unchecked_access );

    Init( right, 42, DisplayInfo.V_Res-4, 50, DisplayInfo.V_Res-4, 'r' );
    SetText( right, "Right" );
    Scrollable( right, false );
    AddControl( right'unchecked_access );

    Init( list, 2, 1, 30, 16 );
    AddControl( list'unchecked_access );

    loop
      SetInfoText( "Offset:" & GetWindowXScroll( CurrentWindow )'img &
         "," & GetWindowYScroll( CurrentWindow )'img );
      DoDialog( DT );
      case DT.control is
      when 2 => exit;
      when 3 => ScrollWindow( 0, -1 );  -- move the control's up 1 vertically
                DrawWindow( whole );    -- erase and redraw whole window
      when 4 => ScrollWindow( 0, +1 );  -- move the control's down 1 vertically
                DrawWindow( whole );    -- erase and redraw whole window
      when 5 => ScrollWindow( -2, 0 );  -- move the control's left 2
                DrawWindow( whole );    -- erase and redraw whole window
      when 6 => ScrollWindow( +2, 0 );  -- move the control's right 2
                DrawWindow( whole );    -- erase and redraw whole window
      when others => null;
      end case;
    end loop;

    CloseWindow;

  end ScrollTest;

  procedure ScrollTest2 is
    line    : aliased aStaticLine;
    ok      : aliased aSimpleButton;
    hbar    : aliased aScrollBar;
    vbar    : aliased aScrollBar;
    list    : aliased aStaticList;

    DT          : aDialogTaskRecord;
    DisplayInfo : ADisplayInfoRec;    

    VirtualWidth  : constant long_integer := 20; -- amount of scrolling
    VirtualHeight : constant long_integer := 20; -- amount of scrolling
    NewScroll     : long_integer;

  begin
    GetDisplayInfo( DisplayInfo );

    OpenWindow( To255( "Window Scrolling Using Scroll Bars Test" ), 0, 0, DisplayInfo.H_Res-1, DisplayInfo.V_Res-1, normal, true );

    Init( line, 22, 18, 40, 18 );
    SetText( line, "Click OK to quit." );
    AddControl( line'unchecked_access );
       
    Init( ok, 2, 18, 10, 18, 'o' );
    SetText( ok, "OK" );
    AddControl( ok'unchecked_access );

    Init( hbar, 1, DisplayInfo.V_Res-4, DisplayInfo.H_Res-4, DisplayInfo.V_Res-4 );
    SetThumb( hbar, VirtualWidth/2 );
    SetMax( hbar, VirtualWidth );
    Scrollable( hbar, false );
    AddControl( hbar'unchecked_access );

    Init( vbar, DisplayInfo.H_Res-3, 1, DisplayInfo.H_Res-3, DisplayInfo.V_Res-5, 'u' );
    SetThumb( vbar, VirtualHeight/2 );
    SetMax( vbar, VirtualHeight );
    Scrollable( vbar, false );
    AddControl( vbar'unchecked_access );

    Init( list, 2, 1, 30, 16 );
    AddControl( list'unchecked_access );

    loop
      SetInfoText( "Offset:" & GetWindowXScroll( CurrentWindow )'img &
         "," & GetWindowYScroll( CurrentWindow )'img );
      DoDialog( DT );
      case DT.control is
      when 2 => exit;
      when 3 => -- move the control horizontally
                -- erase and redraw whole window
                NewScroll := GetThumb( hbar ) - VirtualWidth/2;
                NewScroll :=  NewScroll - long_integer( GetWindowXScroll( CurrentWindow ) );
                ScrollWindow( integer( NewScroll ), 0 );
                DrawWindow( whole );
      when 4 => -- move the control vertically
                -- erase and redraw whole window
                NewScroll := GetThumb( vbar ) - VirtualHeight/2;
                NewScroll :=  NewScroll - long_integer( GetWindowYScroll( CurrentWindow ) );
                ScrollWindow( 0,  integer( NewScroll ) );
                DrawWindow( whole );
      when others => null;
      end case;
    end loop;

    CloseWindow;

  end ScrollTest2;

  line1 : aliased AStaticLine;
  line2 : aliased AStaticLine;
  ok    : aliased ASimpleButton;
  DT    : aDialogTaskRecord;

begin
  StartupCommon( "TIA", "tia" );
  StartupOS;
  StartupUserIO;
  StartupControls;
  StartupWindows;

  OpenWindow( To255( "Window Scrolling Test" ), 0, 0, 60, 20, normal, false );

  Init( line1, 2, 2, 58, 2 );
  SetText( line1, "This a demonstration of ScrollWindow." );
  AddControl( line1'unchecked_access );

  Init( line2, 2, 3, 58, 3 );
  SetText( line2,  "It scrolls a window's controls." );
  AddControl( line2'unchecked_access );

  Init( ok, 2, 18, 30, 18, 'o' );
  SetText( ok, "OK" );
  AddControl( ok'unchecked_access );

  DoDialog( DT );

  ScrollTest;
  ScrollTest2;

  CloseWindow;

  ShutdownWindows;
  ShutdownControls;
  ShutdownUserIO;
  ShutdownOS;
  ShutdownCommon;

end scrollable;