File Coverage

blib/lib/Wx/Perl/RadioBoxDialog.pm
Criterion Covered Total %
statement 7 9 77.7
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 10 12 83.3


line stmt bran cond sub pod time code
1             package Wx::Perl::RadioBoxDialog;
2            
3 1     1   22100 use 5.12.0;
  1         3  
  1         58  
4 1     1   5 use warnings FATAL => 'all';
  1         3  
  1         69  
5            
6             =head1 NAME
7            
8             Wx::Perl::RadioBoxDialog - wxSingleChoiceDialog with RadioBox
9            
10             =head1 VERSION
11            
12             Version 0.02
13            
14             =cut
15            
16             our $VERSION = '0.02';
17            
18 0           use Wx qw( wxID_ANY wxDEFAULT_DIALOG_STYLE wxDefaultPosition wxDefaultSize wxVERTICAL
19             wxEXPAND wxBOTTOM wxALL wxOK wxCANCEL wxRESIZE_BORDER wxRA_SPECIFY_ROWS
20 1     1   6915 wxNOT_FOUND );
  0            
21            
22             use parent -norequire => qw( Wx::Dialog );
23            
24             =head1 SYNOPSIS
25            
26             Dialog like a wxSingleChoiceDialog, just with a RadioBox.
27            
28             use Wx::Perl::RadioBoxDialog;
29            
30             my $dlg = Wx::Perl::RadioBoxDialog->new(
31             undef,
32             "Testmessage",
33             'Testcaption',
34             [ qw( a b c d e ) ],
35             );
36             $dlg->ShowModal;
37             $dlg->Destroy;
38            
39             =head1 METHODS
40            
41             =head2 new
42            
43             Parameter:
44            
45             Wx::Window $parent
46             String $message
47             String $caption
48             Arrayref $choices = []
49             $style = wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER
50             Wx::Point $pos = undef
51             Wx::Size $size = undef
52             Int $id = wxID_ANY
53            
54             If pos is not defined, the Dialog is centered.
55            
56             If size is not defined, the Dialog try to Fit in Best Size
57            
58             =cut
59            
60             sub new {
61             my ( $class, $parent, $message, $caption, $choices, $style, $pos, $size, $id ) = @_;
62            
63             my $centre = defined $pos ? 0 : 1;
64             my $fit = defined $size ? 0 : 1;
65            
66             $style //= wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER;
67             $id //= wxID_ANY;
68             $pos //= wxDefaultPosition;
69             $size //= wxDefaultSize;
70            
71             my $this = $class->SUPER::new( $parent, $id, $caption, $pos, $size, $style );
72            
73             $this->{choices} = $choices;
74            
75             $this->initialize;
76             $this->SetMessage( $message );
77            
78             $this->Centre if $centre;
79            
80             $this->Fit if $fit;
81            
82             return $this;
83             }
84            
85             =head2 GetSelection
86            
87             Returns the index of the selected item or wxNOT_FOUND if no item is selected.
88            
89             =cut
90            
91             sub GetSelection {
92             my $this = shift;
93            
94             $this->{radioBox}->GetSelection;
95             }
96            
97             =head2 GetStringSelection
98            
99             Returns the selected string or undef, if no item is selected
100            
101             =cut
102            
103             sub GetStringSelection {
104             my $this = shift;
105            
106             my $selection = $this->GetSelection;
107             return undef if $selection == wxNOT_FOUND;
108             return $this->{choices}[ $selection ];
109             }
110            
111             =head2 SetSelection( $selection )
112            
113             Sets the selection to the given item.
114            
115             =cut
116            
117             sub SetSelection {
118             my ( $this, $selection ) = @_;
119            
120             return $this->{radioBox}->SetSelection( $selection );
121             }
122            
123             =head2 SetStringSelection( $string );
124            
125             Sets the selection to the given string. Does nothing if the string is not found
126            
127             =cut
128            
129             sub SetStringSelection {
130             my ( $this, $string ) = @_;
131            
132             my $i = 0;
133             for my $choice ( @{ $this->{choices} } ) {
134             if ( $choice eq $string ) {
135             return $this->SetSelection( $i );
136             }
137             $i++;
138             }
139            
140             return 0;
141             }
142            
143             =head2 ShowModal
144            
145             Shows the dialog, returning either wxID_OK or wxID_CANCEL.
146            
147             =cut
148            
149             sub ShowModal {
150             my $this = shift;
151            
152             return $this->SUPER::ShowModal( @_ );
153             }
154            
155             # TODO ..
156            
157             #sub ShowDialog {
158             # my $this = shift;
159             #
160             #
161             #}
162            
163             =head2 SetMessage( $message )
164            
165             =cut
166            
167             sub SetMessage {
168             my ( $this, $message ) = @_;
169            
170             $this->{message}->SetLabel( $message );
171             }
172            
173             =head1 INTERNAL METHODS
174            
175             =head2 initialize
176            
177             =cut
178            
179             sub initialize {
180             my $this = shift;
181            
182             $this->{message} = Wx::StaticText->new( $this, wxID_ANY, '' );
183             $this->{radioBox} = Wx::RadioBox->new(
184             $this, wxID_ANY, '',
185             wxDefaultPosition, wxDefaultSize,
186             $this->{choices},
187             0, wxRA_SPECIFY_ROWS
188             );
189            
190             my $sizerMain = Wx::BoxSizer->new( wxVERTICAL );
191             my $sizerRand = Wx::BoxSizer->new( wxVERTICAL );
192            
193             $sizerRand->Add( $this->{message}, 0, wxEXPAND | wxBOTTOM, 5 );
194             $sizerRand->Add( $this->{radioBox}, 0, wxBOTTOM | wxEXPAND, 10 );
195             $sizerRand->AddStretchSpacer( 1 );
196             $sizerRand->Add( $this->CreateSeparatedButtonSizer( wxOK | wxCANCEL ), 0, wxEXPAND );
197            
198             $sizerMain->Add( $sizerRand, 1, wxEXPAND | wxALL, 10 );
199            
200             $this->SetSizer( $sizerMain );
201             $this->SetAutoLayout( 1 );
202             1;
203            
204             }
205            
206            
207             =head1 AUTHOR
208            
209             Tarek Unger, C<< >>
210            
211             =head1 BUGS
212            
213             Please report any bugs or feature requests to C, or through
214             the web interface at L. I will be notified, and then you'll
215             automatically be notified of progress on your bug as I make changes.
216            
217            
218            
219            
220             =head1 SUPPORT
221            
222             You can find documentation for this module with the perldoc command.
223            
224             perldoc Wx::Perl::RadioBoxDialog
225            
226            
227             You can also look for information at:
228            
229             =over 4
230            
231             =item * RT: CPAN's request tracker (report bugs here)
232            
233             L
234            
235             =item * AnnoCPAN: Annotated CPAN documentation
236            
237             L
238            
239             =item * CPAN Ratings
240            
241             L
242            
243             =item * Search CPAN
244            
245             L
246            
247             =back
248            
249            
250             =head1 ACKNOWLEDGEMENTS
251            
252            
253             =head1 LICENSE AND COPYRIGHT
254            
255             Copyright 2013 Tarek Unger.
256            
257             This program is free software; you can redistribute it and/or modify it
258             under the terms of the the Artistic License (2.0). You may obtain a
259             copy of the full license at:
260            
261             L
262            
263             Any use, modification, and distribution of the Standard or Modified
264             Versions is governed by this Artistic License. By using, modifying or
265             distributing the Package, you accept this license. Do not use, modify,
266             or distribute the Package, if you do not accept this license.
267            
268             If your Modified Version has been derived from a Modified Version made
269             by someone other than you, you are nevertheless required to ensure that
270             your Modified Version complies with the requirements of this license.
271            
272             This license does not grant you the right to use any trademark, service
273             mark, tradename, or logo of the Copyright Holder.
274            
275             This license includes the non-exclusive, worldwide, free-of-charge
276             patent license to make, have made, use, offer to sell, sell, import and
277             otherwise transfer the Package with respect to any patent claims
278             licensable by the Copyright Holder that are necessarily infringed by the
279             Package. If you institute patent litigation (including a cross-claim or
280             counterclaim) against any party alleging that the Package constitutes
281             direct or contributory patent infringement, then this Artistic License
282             to you shall terminate on the date that such litigation is filed.
283            
284             Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER
285             AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
286             THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
287             PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY
288             YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
289             CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR
290             CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE,
291             EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
292            
293            
294             =cut
295            
296             1; # End of Wx::Perl::RadioBoxDialog