summaryrefslogtreecommitdiff
path: root/Master/tlpkg/tlperl.straw/lib/Tk/Panedwindow.pm
blob: d984b648897798be8228dbb76048b0c946b169b7 (plain)
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
package Tk::Panedwindow;
use strict;

use vars qw/$VERSION/;
$VERSION = sprintf '4.%03d', q$Revision: #3 $ =~ /#(\d+)/;

# A Panedwindow widget (similar to Adjuster).

use Tk qw/Ev/;
use base qw/Tk::Widget/;

Construct Tk::Widget 'Panedwindow';

sub Tk_cmd { \&Tk::panedwindow }

Tk::Methods('add', 'forget', 'identify', 'proxy', 'sash', 'panes');

use Tk::Submethods (
    'proxy' => [qw/coord forget place/],
    'sash'  => [qw/coord mark place/],
);

sub ClassInit {

    my ($class,$mw) = @_;

    $class->SUPER::ClassInit($mw);

    $mw->bind($class, '<Button-1>' => ['MarkSash' => Ev('x'), Ev('y'), 1]);
    $mw->bind($class, '<Button-2>' => ['MarkSash' => Ev('x'), Ev('y'), 0]);
    $mw->bind($class, '<B1-Motion>' => ['DragSash' => Ev('x'), Ev('y'), 1]);
    $mw->bind($class, '<B2-Motion>' => ['DragSash' => Ev('x'), Ev('y'), 0]);
    $mw->bind($class, '<ButtonRelease-1>' => ['ReleaseSash' => 1]);
    $mw->bind($class, '<ButtonRelease-2>' => ['ReleaseSash' => 0]);
    $mw->bind($class, '<Motion>' => ['Motion' => Ev('x'), Ev('y')]);
    $mw->bind($class, '<Leave>' => ['Leave']);

    return $class;

} # end ClassInit

sub MarkSash {

    # MarkSash
    #
    # Handle marking the correct sash for possible dragging
    #
    # Arguments:
    #   w	the widget
    #   x	widget local x coord
    #   y	widget local y coord
    #   proxy	whether this should be a proxy sash
    # Results:
    #   None

    my ($w, $x, $y, $proxy) = @_;

    my @what = $w->identify($x, $y);
    if ( @what == 2 ) {
	my ($index, $which) = @what[0 .. 1];
	if (not $Tk::strictMotif or $which eq 'handle') {
	    $w->sashMark($index, $x, $y) if not $proxy;
	    $w->{_sash} = $index;
	    my ($sx, $sy) = $w->sashCoord($index);
	    $w->{_dx} = $sx - $x;
	    $w->{_dy} = $sy - $y;
	}
    }

} # end MarkSash

sub DragSash {

    # DragSash
    #
    # Handle dragging of the correct sash
    #
    # Arguments:
    #   w	the widget
    #   x	widget local x coord
    #   y	widget local y coord
    #   proxy	whether this should be a proxy sash
    # Results:
    #   Moves sash

    my ($w, $x, $y, $proxy) = @_;

    if ( exists $w->{_sash} ) {
	if ($proxy) {
	    $w->proxyPlace($x + $w->{_dx}, $y + $w->{_dy});
	} else {
	    $w->sashPlace($w->{_sash}, $x + $w->{_dx}, $y + $w->{_dy});
	}
    }

} # end DragSash

sub ReleaseSash {

    # ReleaseSash
    #
    # Handle releasing of the sash
    #
    # Arguments:
    #   w	the widget
    #   proxy	whether this should be a proxy sash
    # Results:
    #   Returns ...

    my ($w, $proxy) = @_;

    if ( exists $w->{_sash} ) {
	if ($proxy) {
	    my ($x, $y) = $w->proxyCoord;
	    $w->sashPlace($w->{_sash}, $x, $y);
	    $w->proxyForget;
	}
	delete $w->{'_sash', '_dx', '_dy'};
    }

} # end ReleaseSash

sub Motion {

    # Motion
    #
    # Handle motion on the widget. This is used to change the cursor
    # when the user moves over the sash area.
    #
    # Arguments:
    #   w	the widget
    #   x	widget local x coord
    #   y	widget local y coord
    # Results:
    #   May change the cursor. Sets up a timer to verify that we are still
    #   over the widget.

    my ($w, $x, $y) = @_;

    my @id = $w->identify($x, $y);
    if ( (@id == 2) and
	 (not $Tk::strictMotif or $id[1] eq 'handle') ) {
	if ( not exists $w->{_panecursor} ) {
	    $w->{_panecursor} = $w->cget(-cursor);
	    if ( not defined $w->cget(-sashcursor) ) {
		if ( $w->cget(-orient) eq 'horizontal' ) {
		    $w->configure(-cursor => 'sb_h_double_arrow');
		} else {
		    $w->configure(-cursor => 'sb_v_double_arrow');
		}
	    } else {
		$w->configure(-cursor => $w->cget(-sashcursor));
	    }
	    if ( exists $w->{_pwAfterId} ) {
		$w->afterCancel($w->{_pwAfterId});
	    }
	    $w->{_pwAfterId} = $w->after(150 => ['Cursor' => $w]);
	}
	return
    }
    if ( exists $w->{_panecursor} ) {
	$w->configure(-cursor => $w->{_panecursor});
	delete $w->{_panecursor};
    }

} # end Motion

sub  Cursor {

    # Cursor
    #
    # Handles returning the normal cursor when we are no longer over the
    # sash area.  This needs to be done this way, because the panedwindow
    # won't see Leave events when the mouse moves from the sash to a
    # paned child, although the child does receive an Enter event.
    #
    # Arguments:
    #   w	the widget
    # Results:
    #   May restore the default cursor, or schedule a timer to do it.

    my ($w) = @_;

    if ( exists $w->{_panecursor} ) {
	if ( $w->containing($w->pointerx, $w->pointery) == $w ) {
	    $w->{_pwAfterId} = $w->after(150 => ['Cursor' => $w]);
	} else {
	    $w->configure(-cursor => $w->{_panecursor});
	    delete $w->{_panecursor};
	    if ( exists $w->{_pwAfterId} ) {
		$w->afterCancel($w->{_pwAfterId});
		delete $w->{_pwAfterId};
	    }
	}
    }

} # end Cursor

sub Leave {

    # Leave
    #
    # Return to default cursor when leaving the pw widget.
    #
    # Arguments:
    #   w	the widget
    # Results:
    #   Restores the default cursor

    my ($w) = @_;

    if ( exists $w->{_panecursor} ) {
        $w->configure(-cursor => $w->{_panecursor});
        delete $w->{_panecursor};
    }

} # end Leave


1;
__END__