blib/lib/App/Asciio/GTK/Asciio/stripes/ellipse.pm untested

filter: Statementstmt 0.0% 0 / 116 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 13 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 149 CC 4 SCAR 14.8
CC
4
Cov
0%
display_box_edit_dialog_for_mini_edit_mode
12.0
display_box_edit_dialog
6.0
create_model_for_ellipse
2.0
CRAP 4.4
1  
2 package App::Asciio::stripes::ellipse ;
3  
4 use base App::Asciio::stripes::stripes ;
5 use App::Asciio::GTK::Asciio::Boxfuncs ;
6 use App::Asciio::String ;
7  
8 use strict;
9 use warnings;
10  
11 use Pango ;
12 use Glib qw(TRUE FALSE);
13 use List::Util qw(max) ;
14  
15 #-----------------------------------------------------------------------------
16  
17 sub create_model_for_ellipse
18 {
19 my ($rows) = @_ ;
20  
21 my $model = Gtk3::ListStore->new(qw/Glib::Boolean Glib::String Glib::String Glib::String Glib::String Glib::String Glib::String Glib::String Glib::String Glib::Boolean/);
22  
23 foreach my $row (@{$rows})
24 {
25 my $iter = $model->append;
26
27 my $column = 0 ;
28 $model->set($iter, map {$column++, $_} @{$row}) ;
29 }
30  
31 return $model;
32 }
33  
34 #-----------------------------------------------------------------------------
35  
36 sub on_focus_out_event
37 {
38 my ($self, $event, $window) = @_;
39 $self->response(1) ;
40 }
41  
42 #-----------------------------------------------------------------------------
43  
44 sub display_box_edit_dialog
45 {
46 my ($self, $text, undef, $asciio, $X, $Y, $text_x, $text_y) = @_ ;
47 if(($asciio->{EDIT_TEXT_INLINE} != 0) && (defined $X) && (defined $Y))
48 {
49 return $self->display_box_edit_dialog_for_mini_edit_mode($text, undef, $asciio, $X, $Y, $text_x, $text_y) ;
50 }
51 else
52 {
53 return $self->display_box_edit_dialog_for_normal_mode($text, undef, $asciio) ;
54 }
55 }
56  
57  
58  
59 #-----------------------------------------------------------------------------
60  
61 sub display_box_edit_dialog_for_normal_mode
62 {
63 my ($self, $text, undef, $asciio) = @_ ;
64  
65 my $rows = $self->{BOX_TYPE} ;
66  
67 my $window = new Gtk3::Window() ;
68  
69 my $dialog = Gtk3::Dialog->new('Ellipse attributes', $window, 'destroy-with-parent') ;
70 $dialog->set_position("mouse");
71 $dialog->set_border_width(0);
72 $dialog->set_default_size(450, 605);
73 $dialog->add_button('gtk-ok' => 'ok');
74  
75 my $vbox = Gtk3::Box->new( 'vertical', 8 );
76 # my $vbox = Gtk3::VBox->new(FALSE, 5);
77 $vbox->add(Gtk3::Label->new (""));
78  
79 my $treeview = Gtk3::TreeView->new_with_model(create_model_for_ellipse($rows));
80 $treeview->set_rules_hint(TRUE);
81 $treeview->get_selection->set_mode('single');
82 add_columns($treeview, $rows, 'no show', 9, 'default', 'bottom', 'low', 'middle', 'high', 'fix', 'single');
83  
84 $vbox->add($treeview);
85  
86 # box text
87 my $textview = Gtk3::TextView->new;
88 $textview->modify_font(Pango::FontDescription->from_string($asciio->get_font_as_string()));
89  
90 my $text_buffer = $textview->get_buffer;
91 $text_buffer->insert($text_buffer->get_end_iter, $text);
92  
93 my $text_scroller = Gtk3::ScrolledWindow->new();
94 $text_scroller->set_hexpand(TRUE);
95 $text_scroller->set_vexpand(TRUE);
96 $text_scroller->add($textview);
97 $vbox->add($text_scroller);
98  
99 $textview->show();
100 $text_scroller->show();
101  
102 #Focus and select, code by Tian
103 $text_buffer->select_range($text_buffer->get_start_iter, $text_buffer->get_end_iter);
104 $textview->grab_focus() ;
105  
106 $treeview->show() ;
107 $vbox->show() ;
108  
109 $dialog->get_content_area()->add($vbox) ;
110 $dialog->run() ;
111  
112 my $new_text = $textview->get_buffer->get_text($text_buffer->get_start_iter, $text_buffer->get_end_iter, TRUE) ;
113  
114 $dialog->destroy ;
115  
116 return $new_text ;
117 }
118  
119 #-----------------------------------------------------------------------------
120  
121 sub display_box_edit_dialog_for_mini_edit_mode
122 {
123 my ($self, $text, undef, $asciio, $X, $Y, $text_x, $text_y) = @_ ;
124  
125 $text ='' unless defined $text ;
126 my @text_lines ;
127 if($text)
128 {
129 @text_lines = split("\n", $text) ;
130 }
131 else
132 {
133 @text_lines = ('') ;
134 }
135  
136 my $text_width = max(map {unicode_length $_} @text_lines);
137 my $text_heigh = @text_lines;
138 $text_width = max($text_width, 3) ;
139 $text_heigh =max($text_heigh, 3) ;
140  
141 my ($character_width, $character_height) = $asciio->get_character_size() ;
142 my ($root_x, $root_y) = $asciio->{root_window}->get_position();
143 my ($v_value, $h_value) = ($asciio->{sc_window}->get_vadjustment()->get_value(), $asciio->{sc_window}->get_hadjustment()->get_value());
144  
145 my $window = new Gtk3::Window() ;
146  
147 my $dialog = Gtk3::Dialog->new('Ellips attributes', $window, 'destroy-with-parent') ;
148 $dialog->set_default_size($text_width, $text_heigh);
149 $dialog->set_border_width(0);
150 $dialog->set_decorated(0);
151 $dialog->move($root_x+(($X+$text_x)*$character_width)-$h_value, $root_y+(($Y+$text_y)*$character_height)-$v_value);
152  
153 my $vbox = Gtk3::VBox->new(FALSE, 5);
154 $vbox->add(Gtk3::Label->new (""));
155  
156 # box text
157 my $textview = Gtk3::TextView->new;
158 $textview->modify_font(Pango::FontDescription->from_string($asciio->get_font_as_string()));
159  
160 my $text_buffer = $textview->get_buffer;
161 $text_buffer->insert($text_buffer->get_end_iter, $text);
162  
163  
164 $vbox->add($textview);
165 $textview->show();
166  
167 #Focus and select, code by Tian
168 $text_buffer->select_range($text_buffer->get_start_iter, $text_buffer->get_end_iter);
169 $textview->grab_focus() ;
170  
171 $vbox->show() ;
172  
173 $dialog->get_content_area()->add($vbox) ;
174  
175 $dialog->add_events('GDK_FOCUS_CHANGE_MASK') ;
176 $dialog->signal_connect(focus_out_event => \&on_focus_out_event, $window) ;
177  
178 $dialog->run() ;
179  
180 my $new_text = $textview->get_buffer->get_text($text_buffer->get_start_iter, $text_buffer->get_end_iter, TRUE) ;
181  
182 $dialog->destroy ;
183  
184 return $new_text ;
185 }
186  
187  
188 #-----------------------------------------------------------------------------
189  
190 1 ;