… | |
… | |
113 | } |
113 | } |
114 | |
114 | |
115 | if ($GRAB) { |
115 | if ($GRAB) { |
116 | if ($ev->{button} == 4 || $ev->{button} == 5) { |
116 | if ($ev->{button} == 4 || $ev->{button} == 5) { |
117 | # mousewheel |
117 | # mousewheel |
118 | $ev->{dx} = 0; |
|
|
119 | $ev->{dy} = $ev->{button} * 2 - 9; |
118 | my $delta = $ev->{button} * 2 - 9; |
|
|
119 | my $shift = $ev->{mod} & CFPlus::KMOD_SHIFT; |
|
|
120 | |
|
|
121 | $ev->{dx} = $shift ? $delta : 0; |
|
|
122 | $ev->{dy} = $shift ? 0 : $delta; |
|
|
123 | |
120 | $GRAB->emit (mouse_wheel => $ev); |
124 | $GRAB->emit (mouse_wheel => $ev); |
121 | } else { |
125 | } else { |
122 | $GRAB->emit (button_down => $ev) |
126 | $GRAB->emit (button_down => $ev) |
123 | } |
127 | } |
124 | } |
128 | } |
… | |
… | |
954 | sub size_request { |
958 | sub size_request { |
955 | my ($self) = @_; |
959 | my ($self) = @_; |
956 | |
960 | |
957 | my ($w, $h) = @{$self->child}{qw(req_w req_h)}; |
961 | my ($w, $h) = @{$self->child}{qw(req_w req_h)}; |
958 | |
962 | |
959 | $w = 10 if $self->{scroll_x}; |
963 | $w = 1 if $self->{scroll_x}; |
960 | $h = 10 if $self->{scroll_y}; |
964 | $h = 1 if $self->{scroll_y}; |
961 | |
965 | |
962 | ($w, $h) |
966 | ($w, $h) |
963 | } |
967 | } |
964 | |
968 | |
965 | sub invoke_size_allocate { |
969 | sub invoke_size_allocate { |
… | |
… | |
1133 | } |
1137 | } |
1134 | |
1138 | |
1135 | sub invoke_mouse_wheel { |
1139 | sub invoke_mouse_wheel { |
1136 | my ($self, $ev) = @_; |
1140 | my ($self, $ev) = @_; |
1137 | |
1141 | |
1138 | return 0 unless $ev->{dy}; # only vertical movements for now |
|
|
1139 | |
|
|
1140 | $self->{vslider}->emit (mouse_wheel => $ev); |
1142 | $self->{vslider}->emit (mouse_wheel => $ev) |
|
|
1143 | if $ev->{dy}; |
|
|
1144 | |
|
|
1145 | $self->{hslider}->emit (mouse_wheel => $ev) |
|
|
1146 | if $ev->{dx}; |
1141 | |
1147 | |
1142 | 1 |
1148 | 1 |
1143 | } |
1149 | } |
1144 | |
1150 | |
1145 | sub invoke_button_down { |
1151 | sub invoke_button_down { |
… | |
… | |
1610 | my $self = shift; |
1616 | my $self = shift; |
1611 | |
1617 | |
1612 | while (@_) { |
1618 | while (@_) { |
1613 | my ($col, $row, $child) = splice @_, 0, 3, (); |
1619 | my ($col, $row, $child) = splice @_, 0, 3, (); |
1614 | |
1620 | |
|
|
1621 | $child->{row} = $row; |
|
|
1622 | $child->{col} = $col; |
|
|
1623 | |
|
|
1624 | $child->{rowspan} ||= 1; |
|
|
1625 | $child->{colspan} ||= 1; |
|
|
1626 | |
1615 | $child->set_parent ($self); |
1627 | $child->set_parent ($self); |
1616 | $self->{children}[$row][$col] = $child; |
1628 | $self->{children}[$row][$col] = $child; |
1617 | } |
1629 | } |
1618 | |
1630 | |
1619 | $self->{force_realloc} = 1; |
1631 | $self->{force_realloc} = 1; |
… | |
… | |
1649 | sub get_wh { |
1661 | sub get_wh { |
1650 | my ($self) = @_; |
1662 | my ($self) = @_; |
1651 | |
1663 | |
1652 | my (@w, @h); |
1664 | my (@w, @h); |
1653 | |
1665 | |
1654 | for my $y (0 .. $#{$self->{children}}) { |
1666 | my @children = $self->children; |
1655 | my $row = $self->{children}[$y] |
|
|
1656 | or next; |
|
|
1657 | |
1667 | |
1658 | for my $x (0 .. $#$row) { |
1668 | for my $widget (sort { $b->{rowspan} * $b->{colspan} <=> $a->{rowspan} * $a->{colspan} } @children) { |
1659 | my $widget = $row->[$x] |
1669 | my ($r, $c, $w, $h, $rs, $cs) = @$widget{qw(row col req_w req_h rowspan colspan)}; |
1660 | or next; |
|
|
1661 | my ($w, $h) = @$widget{qw(req_w req_h)}; |
|
|
1662 | |
1670 | |
1663 | $w[$x] = max $w[$x], $w; |
1671 | my $sw = sum @w[$c .. $c + $cs - 1]; |
1664 | $h[$y] = max $h[$y], $h; |
1672 | my $sh = sum @h[$r .. $r + $rs - 1]; |
|
|
1673 | |
|
|
1674 | if ($w > $sw) { |
|
|
1675 | $_ += ($w - $sw) / $cs for @w[$c .. $c + $cs - 1]; |
|
|
1676 | } |
|
|
1677 | |
|
|
1678 | if ($h > $sh) { |
|
|
1679 | $_ += ($h - $sh) / $rs for @h[$r .. $r + $rs - 1]; |
1665 | } |
1680 | } |
1666 | } |
1681 | } |
1667 | |
1682 | |
1668 | (\@w, \@h) |
1683 | (\@w, \@h) |
1669 | } |
1684 | } |
… | |
… | |
1685 | my ($ws, $hs) = $self->get_wh; |
1700 | my ($ws, $hs) = $self->get_wh; |
1686 | |
1701 | |
1687 | my $req_w = (sum @$ws) || 1; |
1702 | my $req_w = (sum @$ws) || 1; |
1688 | my $req_h = (sum @$hs) || 1; |
1703 | my $req_h = (sum @$hs) || 1; |
1689 | |
1704 | |
1690 | # TODO: nicer code |
1705 | # now linearly scale the rows/columns to the allocated size |
1691 | my @col_expand = @{$self->{col_expand}}; |
1706 | my @col_expand = @{$self->{col_expand}}; |
1692 | @col_expand = (1) x @$ws unless @col_expand; |
1707 | @col_expand = (1) x @$ws unless @col_expand; |
1693 | my $col_expand = (sum @col_expand) || 1; |
1708 | my $col_expand = (sum @col_expand) || 1; |
1694 | |
1709 | |
1695 | $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws; |
1710 | $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws; |
… | |
… | |
1702 | |
1717 | |
1703 | $hs->[$_] += $row_expand[$_] / $row_expand * ($h - $req_h) for 0 .. $#$hs; |
1718 | $hs->[$_] += $row_expand[$_] / $row_expand * ($h - $req_h) for 0 .. $#$hs; |
1704 | |
1719 | |
1705 | CFPlus::UI::harmonize $hs; |
1720 | CFPlus::UI::harmonize $hs; |
1706 | |
1721 | |
1707 | my $y; |
1722 | my (@x, @y); |
1708 | |
1723 | |
|
|
1724 | for (0 .. $#$ws) { $x[$_ + 1] = $x[$_] + $ws->[$_] } |
|
|
1725 | for (0 .. $#$hs) { $y[$_ + 1] = $y[$_] + $hs->[$_] } |
|
|
1726 | |
1709 | for my $r (0 .. $#{$self->{children}}) { |
1727 | for my $widget ($self->children) { |
1710 | my $row = $self->{children}[$r] |
1728 | my ($r, $c, $w, $h, $rs, $cs) = @$widget{qw(row col req_w req_h rowspan colspan)}; |
1711 | or next; |
|
|
1712 | |
1729 | |
1713 | my $x = 0; |
1730 | $widget->configure ( |
1714 | my $row_h = $hs->[$r]; |
1731 | $x[$c], $y[$r], |
|
|
1732 | $x[$c + $cs] - $x[$c], $y[$r + $rs] - $y[$r], |
1715 | |
1733 | ); |
1716 | for my $c (0 .. $#$row) { |
|
|
1717 | my $col_w = $ws->[$c]; |
|
|
1718 | |
|
|
1719 | if (my $widget = $row->[$c]) { |
|
|
1720 | $widget->configure ($x, $y, $col_w, $row_h); |
|
|
1721 | } |
|
|
1722 | |
|
|
1723 | $x += $col_w; |
|
|
1724 | } |
|
|
1725 | |
|
|
1726 | $y += $row_h; |
|
|
1727 | } |
1734 | } |
1728 | |
1735 | |
1729 | 1 |
1736 | 1 |
1730 | } |
1737 | } |
1731 | |
1738 | |