line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
############################################################################# |
2
|
|
|
|
|
|
|
## Name: lib/Wx/DemoModules/wxGrid.pm |
3
|
|
|
|
|
|
|
## Purpose: wxPerl demo helper for wxGrid |
4
|
|
|
|
|
|
|
## Author: Mattia Barbon |
5
|
|
|
|
|
|
|
## Modified by: |
6
|
|
|
|
|
|
|
## Created: 08/12/2001 |
7
|
|
|
|
|
|
|
## RCS-ID: $Id: wxGrid.pm 3118 2011-11-18 09:58:12Z mdootson $ |
8
|
|
|
|
|
|
|
## Copyright: (c) 2001, 2003, 2005-2006 Mattia Barbon |
9
|
|
|
|
|
|
|
## Licence: This program is free software; you can redistribute it and/or |
10
|
|
|
|
|
|
|
## modify it under the same terms as Perl itself |
11
|
|
|
|
|
|
|
############################################################################# |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
package Wx::DemoModules::wxGrid; |
14
|
|
|
|
|
|
|
|
15
|
1
|
|
|
1
|
|
1199
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
38
|
|
16
|
1
|
|
|
1
|
|
5
|
use base qw(Wx::Grid); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
617
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
use Wx::Event qw(EVT_GRID_CELL_LEFT_CLICK EVT_GRID_CELL_RIGHT_CLICK |
19
|
|
|
|
|
|
|
EVT_GRID_CELL_LEFT_DCLICK EVT_GRID_CELL_RIGHT_DCLICK |
20
|
|
|
|
|
|
|
EVT_GRID_LABEL_LEFT_CLICK EVT_GRID_LABEL_RIGHT_CLICK |
21
|
|
|
|
|
|
|
EVT_GRID_LABEL_LEFT_DCLICK EVT_GRID_LABEL_RIGHT_DCLICK |
22
|
|
|
|
|
|
|
EVT_GRID_ROW_SIZE EVT_GRID_COL_SIZE EVT_GRID_RANGE_SELECT |
23
|
|
|
|
|
|
|
EVT_GRID_SELECT_CELL); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# events changed names in version 2.9.x |
26
|
|
|
|
|
|
|
my $events29plus = ( defined(&Wx::Event::EVT_GRID_CELL_CHANGED) ); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
use Wx qw(wxRED wxBLUE wxGREEN); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub new { |
31
|
|
|
|
|
|
|
my $class = shift; |
32
|
|
|
|
|
|
|
my $this = $class->SUPER::new( $_[0], -1 ); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
$this->CreateGrid( 100, 100 ); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
my $attr1 = Wx::GridCellAttr->new; |
37
|
|
|
|
|
|
|
$attr1->SetBackgroundColour( wxRED ); |
38
|
|
|
|
|
|
|
my $attr2 = Wx::GridCellAttr->new; |
39
|
|
|
|
|
|
|
$attr2->SetTextColour( wxGREEN ); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
$this->SetColAttr( 2, $attr1 ); |
42
|
|
|
|
|
|
|
$this->SetRowAttr( 3, $attr2 ); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
$this->SetCellValue( 1, 1, "First" ); |
45
|
|
|
|
|
|
|
$this->SetCellValue( 2, 2, "Second" ); |
46
|
|
|
|
|
|
|
$this->SetCellValue( 3, 3, "Third" ); |
47
|
|
|
|
|
|
|
$this->SetCellValue( 3, 1, "I'm green" ); |
48
|
|
|
|
|
|
|
$this->SetCellValue( 5, 1, "I will overflow because the cells to my right are empty."); |
49
|
|
|
|
|
|
|
$this->SetCellValue( 6, 1, "I can stop overflow on an individual cell basis.."); |
50
|
|
|
|
|
|
|
$this->SetCellOverflow(6,1,0); |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
EVT_GRID_CELL_LEFT_CLICK( $this, c_log_skip( "Cell left click" ) ); |
54
|
|
|
|
|
|
|
EVT_GRID_CELL_RIGHT_CLICK( $this, c_log_skip( "Cell right click" ) ); |
55
|
|
|
|
|
|
|
EVT_GRID_CELL_LEFT_DCLICK( $this, c_log_skip( "Cell left double click" ) ); |
56
|
|
|
|
|
|
|
EVT_GRID_CELL_RIGHT_DCLICK( $this, c_log_skip( "Cell right double click" ) ); |
57
|
|
|
|
|
|
|
EVT_GRID_LABEL_LEFT_CLICK( $this, c_log_skip( "Label left click" ) ); |
58
|
|
|
|
|
|
|
EVT_GRID_LABEL_RIGHT_CLICK( $this, c_log_skip( "Label right click" ) ); |
59
|
|
|
|
|
|
|
EVT_GRID_LABEL_LEFT_DCLICK( $this, c_log_skip( "Label left double click" ) ); |
60
|
|
|
|
|
|
|
EVT_GRID_LABEL_RIGHT_DCLICK( $this, c_log_skip( "Label right double click" ) ); |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
EVT_GRID_ROW_SIZE( $this, sub { |
63
|
|
|
|
|
|
|
Wx::LogMessage( "%s %s", "Row size", GS2S( $_[1] ) ); |
64
|
|
|
|
|
|
|
$_[1]->Skip; |
65
|
|
|
|
|
|
|
} ); |
66
|
|
|
|
|
|
|
EVT_GRID_COL_SIZE( $this, sub { |
67
|
|
|
|
|
|
|
Wx::LogMessage( "%s %s", "Col size", GS2S( $_[1] ) ); |
68
|
|
|
|
|
|
|
$_[1]->Skip; |
69
|
|
|
|
|
|
|
} ); |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
EVT_GRID_RANGE_SELECT( $this, sub { |
72
|
|
|
|
|
|
|
Wx::LogMessage( "Range %sselect (%d, %d, %d, %d)", |
73
|
|
|
|
|
|
|
( $_[1]->Selecting ? '' : 'de' ), |
74
|
|
|
|
|
|
|
$_[1]->GetLeftCol, $_[1]->GetTopRow, |
75
|
|
|
|
|
|
|
$_[1]->GetRightCol, |
76
|
|
|
|
|
|
|
$_[1]->GetBottomRow ); |
77
|
|
|
|
|
|
|
$_[0]->ShowSelections; |
78
|
|
|
|
|
|
|
$_[1]->Skip; |
79
|
|
|
|
|
|
|
} ); |
80
|
|
|
|
|
|
|
if( $events29plus ) { |
81
|
|
|
|
|
|
|
Wx::Event::EVT_GRID_CELL_CHANGED( $this, c_log_skip( "Cell content changed" ) ); |
82
|
|
|
|
|
|
|
} else { |
83
|
|
|
|
|
|
|
Wx::Event::EVT_GRID_CELL_CHANGE( $this, c_log_skip( "Cell content changed" ) ); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
EVT_GRID_SELECT_CELL( $this, c_log_skip( "Cell select" ) ); |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
return $this; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub ShowSelections { |
91
|
|
|
|
|
|
|
my $this = shift; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
my @cells = $this->GetSelectedCells; |
94
|
|
|
|
|
|
|
if( @cells ) { |
95
|
|
|
|
|
|
|
Wx::LogMessage( "Cells %s selected", join ', ', |
96
|
|
|
|
|
|
|
map { "(" . $_->GetCol . |
97
|
|
|
|
|
|
|
", " . $_->GetRow . ")" |
98
|
|
|
|
|
|
|
} @cells ); |
99
|
|
|
|
|
|
|
} else { |
100
|
|
|
|
|
|
|
Wx::LogMessage( "No cells selected" ); |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
my @tl = $this->GetSelectionBlockTopLeft; |
104
|
|
|
|
|
|
|
my @br = $this->GetSelectionBlockBottomRight; |
105
|
|
|
|
|
|
|
if( @tl && @br ) { |
106
|
|
|
|
|
|
|
Wx::LogMessage( "Blocks %s selected", |
107
|
|
|
|
|
|
|
join ', ', |
108
|
|
|
|
|
|
|
map { "(" . $tl[$_]->GetCol . |
109
|
|
|
|
|
|
|
", " . $tl[$_]->GetRow . "-" . |
110
|
|
|
|
|
|
|
$br[$_]->GetCol . ", " . |
111
|
|
|
|
|
|
|
$br[$_]->GetRow . ")" |
112
|
|
|
|
|
|
|
} 0 .. $#tl ); |
113
|
|
|
|
|
|
|
} else { |
114
|
|
|
|
|
|
|
Wx::LogMessage( "No blocks selected" ); |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
my @rows = $this->GetSelectedRows; |
118
|
|
|
|
|
|
|
if( @rows ) { |
119
|
|
|
|
|
|
|
Wx::LogMessage( "Rows %s selected", join ', ', @rows ); |
120
|
|
|
|
|
|
|
} else { |
121
|
|
|
|
|
|
|
Wx::LogMessage( "No rows selected" ); |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
my @cols = $this->GetSelectedCols; |
125
|
|
|
|
|
|
|
if( @cols ) { |
126
|
|
|
|
|
|
|
Wx::LogMessage( "Columns %s selected", join ', ', @cols ); |
127
|
|
|
|
|
|
|
} else { |
128
|
|
|
|
|
|
|
Wx::LogMessage( "No columns selected" ); |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
# pretty printer for Wx::GridEvent |
133
|
|
|
|
|
|
|
sub G2S { |
134
|
|
|
|
|
|
|
my $event = shift; |
135
|
|
|
|
|
|
|
my( $x, $y ) = ( $event->GetCol, $event->GetRow ); |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
return "( $x, $y )"; |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
# prety printer for Wx::GridSizeEvent |
141
|
|
|
|
|
|
|
sub GS2S { |
142
|
|
|
|
|
|
|
my $event = shift; |
143
|
|
|
|
|
|
|
my $roc = $event->GetRowOrCol; |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
return "( $roc )"; |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
# creates an anonymous sub that logs and skips any grid event |
149
|
|
|
|
|
|
|
sub c_log_skip { |
150
|
|
|
|
|
|
|
my $text = shift; |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
return sub { |
153
|
|
|
|
|
|
|
Wx::LogMessage( "%s %s", $text, G2S( $_[1] ) ); |
154
|
|
|
|
|
|
|
$_[0]->ShowSelections; |
155
|
|
|
|
|
|
|
$_[1]->Skip; |
156
|
|
|
|
|
|
|
}; |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
sub tags { [ 'controls/grid' => 'wxGrid' ] } |
160
|
|
|
|
|
|
|
sub add_to_tags { 'controls/grid' } |
161
|
|
|
|
|
|
|
sub title { 'Simple' } |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
1; |