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

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