line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Kephra::App::Window; # Main application window
|
2
|
|
|
|
|
|
|
our $VERSION = '0.11';
|
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
1287
|
use strict;
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
43
|
|
5
|
1
|
|
|
1
|
|
7
|
use warnings;
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
2038
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
my $frame;
|
8
|
0
|
0
|
|
0
|
|
|
sub _ref { if (ref $_[0] eq 'Wx::Frame'){ $frame = $_[0] } else { $frame } }
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
9
|
0
|
|
|
0
|
|
|
sub _config { Kephra::API::settings()->{app}{window} }
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub create {
|
12
|
0
|
|
|
0
|
0
|
|
my $win = Wx::Frame->new
|
13
|
|
|
|
|
|
|
(undef, -1, '', [-1,-1], [-1,-1], &Wx::wxDEFAULT_FRAME_STYLE);
|
14
|
0
|
0
|
|
|
|
|
Wx::Window::SetWindowVariant($win, &Wx::wxWINDOW_VARIANT_SMALL) if Wx::wxMAC();
|
15
|
0
|
|
|
|
|
|
_ref($win);
|
16
|
0
|
|
|
|
|
|
connect_events($win);
|
17
|
0
|
|
|
|
|
|
$win;
|
18
|
|
|
|
|
|
|
}
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub connect_events {
|
21
|
0
|
|
0
|
0
|
0
|
|
my $win = shift || _ref();
|
22
|
0
|
|
|
|
|
|
my $trigger = \&Kephra::EventTable::trigger;
|
23
|
0
|
|
|
0
|
|
|
Wx::Event::EVT_MENU_OPEN ($win, sub {&$trigger('menu.open')});
|
|
0
|
|
|
|
|
|
|
24
|
0
|
|
|
|
|
|
Wx::Event::EVT_DROP_FILES($win, \&Kephra::File::add_dropped);
|
25
|
|
|
|
|
|
|
Wx::Event::EVT_CLOSE ($win, sub {
|
26
|
0
|
|
|
0
|
|
|
&$trigger('app.close');
|
27
|
0
|
|
|
|
|
|
Kephra::App::exit()
|
28
|
0
|
|
|
|
|
|
});
|
29
|
|
|
|
|
|
|
#Wx::Event::EVT_IDLE ($win, sub { } );
|
30
|
|
|
|
|
|
|
}
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub apply_settings {
|
33
|
0
|
|
0
|
0
|
0
|
|
my $win = shift || _ref();
|
34
|
0
|
0
|
|
|
|
|
$win->DragAcceptFiles(1) if Wx::wxMSW();
|
35
|
0
|
|
|
|
|
|
my $icon_file = Kephra::Config::existing_filepath( _config()->{icon} );
|
36
|
0
|
|
|
|
|
|
load_icon( $win, $icon_file );
|
37
|
0
|
|
|
|
|
|
restore_positions();
|
38
|
0
|
|
|
|
|
|
eval_fullscreen_flag();
|
39
|
0
|
|
|
|
|
|
eval_on_top_flag();
|
40
|
0
|
|
|
|
|
|
eval_transparency_flag();
|
41
|
0
|
|
|
|
|
|
eval_max_editpanel_flag();
|
42
|
|
|
|
|
|
|
}
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub load_icon {
|
45
|
0
|
|
|
0
|
0
|
|
my $frame = shift;
|
46
|
0
|
|
|
|
|
|
my $icon_file = shift;
|
47
|
0
|
0
|
|
|
|
|
return unless -e $icon_file;
|
48
|
0
|
|
|
|
|
|
my $type ;
|
49
|
0
|
0
|
|
|
|
|
if ($icon_file =~ /.ico$/) { $type = &Wx::wxBITMAP_TYPE_ICO }
|
|
0
|
0
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
elsif ($icon_file =~ /.xpm$/) { $type = &Wx::wxBITMAP_TYPE_XPM }
|
51
|
0
|
|
|
|
|
|
my $icon;
|
52
|
0
|
0
|
|
|
|
|
$icon = Wx::Icon->new( $icon_file, $type ) if $type;
|
53
|
0
|
0
|
|
|
|
|
$frame->SetIcon( $icon ) if defined $icon;
|
54
|
|
|
|
|
|
|
}
|
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub set_title {
|
57
|
0
|
|
|
0
|
0
|
|
my $title = shift;
|
58
|
0
|
|
|
|
|
|
_ref()->SetTitle($title);
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
}
|
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub refresh_title {
|
63
|
0
|
|
|
0
|
0
|
|
my $appname = $Kephra::NAME;
|
64
|
0
|
|
|
|
|
|
my $version = $Kephra::VERSION;
|
65
|
0
|
|
|
|
|
|
my $untitled = Kephra::Config::Localisation::strings()->{app}{general}{untitled};
|
66
|
0
|
|
0
|
|
|
|
my $filepath = Kephra::Document::Data::get_file_path() || "<$untitled>";
|
67
|
0
|
|
0
|
|
|
|
my $filename = Kephra::Document::Data::file_name() || "<$untitled>";
|
68
|
0
|
|
|
|
|
|
my $docnr = Kephra::Document::Data::current_nr() + 1;
|
69
|
0
|
|
|
|
|
|
my $doccount = Kephra::Document::Data::last_nr();
|
70
|
0
|
|
|
|
|
|
my $title = _config()->{title};
|
71
|
0
|
|
|
|
|
|
set_title( eval qq/"$title"/ );
|
72
|
|
|
|
|
|
|
}
|
73
|
|
|
|
|
|
|
|
74
|
0
|
|
|
0
|
0
|
|
sub get_fullscreen_mode { _config()->{fullscreen} }
|
75
|
|
|
|
|
|
|
sub switch_fullscreen_mode {
|
76
|
0
|
|
|
0
|
0
|
|
_config()->{fullscreen} ^= 1;
|
77
|
0
|
|
|
|
|
|
eval_fullscreen_flag();
|
78
|
|
|
|
|
|
|
}
|
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub eval_fullscreen_flag {
|
81
|
0
|
|
|
0
|
0
|
|
_ref->ShowFullScreen(
|
82
|
|
|
|
|
|
|
get_fullscreen_mode(),
|
83
|
|
|
|
|
|
|
&Wx::wxFULLSCREEN_NOCAPTION | &Wx::wxFULLSCREEN_NOBORDER
|
84
|
|
|
|
|
|
|
);
|
85
|
|
|
|
|
|
|
}
|
86
|
|
|
|
|
|
|
|
87
|
0
|
|
|
0
|
0
|
|
sub get_on_top_mode { _config()->{stay_on_top} }
|
88
|
|
|
|
|
|
|
sub switch_on_top_mode {
|
89
|
0
|
|
|
0
|
0
|
|
_config()->{stay_on_top} ^= 1;
|
90
|
0
|
|
|
|
|
|
eval_on_top_flag();
|
91
|
|
|
|
|
|
|
}
|
92
|
|
|
|
|
|
|
sub eval_on_top_flag {
|
93
|
0
|
|
|
0
|
0
|
|
my $win = _ref();
|
94
|
0
|
|
|
|
|
|
my $style = $win->GetWindowStyleFlag();
|
95
|
0
|
0
|
|
|
|
|
if ( get_on_top_mode() ) { $style |= &Wx::wxSTAY_ON_TOP }
|
|
0
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
else { $style &= ~&Wx::wxSTAY_ON_TOP }
|
97
|
0
|
|
|
|
|
|
$win->SetWindowStyle($style);
|
98
|
0
|
|
|
|
|
|
Kephra::EventTable::trigger('app.window.ontop');
|
99
|
|
|
|
|
|
|
}
|
100
|
|
|
|
|
|
|
|
101
|
0
|
|
|
0
|
0
|
|
sub get_transparency_mode { _config()->{transparent} }
|
102
|
|
|
|
|
|
|
sub switch_transparency_mode {
|
103
|
0
|
|
|
0
|
0
|
|
_config()->{transparent} ^= 1;
|
104
|
0
|
|
|
|
|
|
eval_transparency_flag();
|
105
|
|
|
|
|
|
|
}
|
106
|
|
|
|
|
|
|
sub eval_transparency_flag {
|
107
|
0
|
|
|
0
|
0
|
|
_ref->SetTransparent(
|
108
|
|
|
|
|
|
|
255 - int( _config()->{transparency} * 255 * get_transparency_mode() )
|
109
|
|
|
|
|
|
|
);
|
110
|
|
|
|
|
|
|
}
|
111
|
|
|
|
|
|
|
sub switch_top_and_transparency_mode {
|
112
|
0
|
|
|
0
|
0
|
|
switch_transparency_mode();
|
113
|
0
|
0
|
|
|
|
|
switch_on_top_mode if get_on_top_mode() != get_transparency_mode();
|
114
|
|
|
|
|
|
|
}
|
115
|
|
|
|
|
|
|
|
116
|
0
|
|
|
0
|
0
|
|
sub get_max_editpanel_mode { _config()->{maximize_editpanel} }
|
117
|
|
|
|
|
|
|
sub switch_max_editpanel_mode {
|
118
|
0
|
|
|
0
|
0
|
|
_config()->{maximize_editpanel} ^= 1;
|
119
|
0
|
|
|
|
|
|
eval_max_editpanel_flag();
|
120
|
|
|
|
|
|
|
}
|
121
|
|
|
|
|
|
|
sub eval_max_editpanel_flag {
|
122
|
0
|
|
|
0
|
0
|
|
my $v = get_max_editpanel_mode();
|
123
|
0
|
0
|
|
|
|
|
Kephra::App::MenuBar::switch_visibility()
|
124
|
|
|
|
|
|
|
if Kephra::App::MenuBar::get_visibility() == $v;
|
125
|
0
|
0
|
|
|
|
|
Kephra::App::MainToolBar::switch_visibility()
|
126
|
|
|
|
|
|
|
if Kephra::App::MainToolBar::get_visibility() == $v;
|
127
|
0
|
0
|
0
|
|
|
|
Kephra::App::TabBar::switch_visibility()
|
128
|
|
|
|
|
|
|
if Kephra::App::TabBar::get_visibility() == $v and not $v;
|
129
|
0
|
0
|
|
|
|
|
Kephra::App::SearchBar::switch_visibility()
|
130
|
|
|
|
|
|
|
if Kephra::App::SearchBar::get_visibility() == $v;
|
131
|
0
|
0
|
|
|
|
|
Kephra::App::StatusBar::switch_visibility()
|
132
|
|
|
|
|
|
|
if Kephra::App::StatusBar::get_visibility() == $v;
|
133
|
|
|
|
|
|
|
}
|
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
sub restore_normal_mode {
|
136
|
0
|
0
|
|
0
|
0
|
|
switch_fullscreen_mode if _config()->{fullscreen};
|
137
|
0
|
0
|
|
|
|
|
switch_on_top_mode if _config()->{stay_on_top};
|
138
|
0
|
0
|
|
|
|
|
switch_transparency_mode if _config()->{transparent};
|
139
|
0
|
0
|
|
|
|
|
switch_max_editpanel_mode if _config()->{maximize_editpanel};
|
140
|
|
|
|
|
|
|
}
|
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
sub save_positions {
|
143
|
0
|
|
|
0
|
0
|
|
my $app_win = Kephra::App::Window::_ref();
|
144
|
0
|
|
|
|
|
|
my $config = _config();
|
145
|
0
|
0
|
|
|
|
|
if ($config->{save_position}){
|
146
|
0
|
|
|
|
|
|
($config->{position_x},$config->{position_y}) = $app_win->GetPositionXY;
|
147
|
0
|
|
|
|
|
|
($config->{size_x}, $config->{size_y}) = $app_win->GetSizeWH;
|
148
|
|
|
|
|
|
|
}
|
149
|
|
|
|
|
|
|
}
|
150
|
|
|
|
|
|
|
sub restore_positions {
|
151
|
|
|
|
|
|
|
# main window: resize when its got lost
|
152
|
0
|
|
|
0
|
0
|
|
my $config = _config();
|
153
|
0
|
|
|
|
|
|
my $default = $config->{default};
|
154
|
0
|
|
|
|
|
|
my $screen = Wx::GetDisplaySize();
|
155
|
0
|
|
|
|
|
|
my ($screen_x, $screen_y ) = ( $screen->GetWidth, $screen->GetHeight );
|
156
|
0
|
0
|
|
|
|
|
if ($config->{save_position}){
|
157
|
0
|
0
|
0
|
|
|
|
if ( ( 0 > $config->{position_x} + $config->{size_x} )
|
158
|
|
|
|
|
|
|
or ( 0 > $config->{position_y} + $config->{size_y} ) ) {
|
159
|
0
|
|
|
|
|
|
$config->{position_x} = 0;
|
160
|
0
|
|
|
|
|
|
$config->{position_y} = 0;
|
161
|
0
|
0
|
|
|
|
|
if ( int $default->{size_x} == 0 )
|
162
|
0
|
|
|
|
|
|
{ $config->{size_x} = $screen_x }
|
163
|
0
|
|
|
|
|
|
else{ $config->{size_x} = $default->{size_x} }
|
164
|
0
|
0
|
|
|
|
|
if ( int $default->{size_y} == 0 )
|
165
|
0
|
|
|
|
|
|
{ $config->{size_y} = $screen_y - 55}
|
166
|
0
|
|
|
|
|
|
else{ $config->{size_y} = $default->{size_y} }
|
167
|
|
|
|
|
|
|
}
|
168
|
0
|
0
|
|
|
|
|
if (Wx::wxMAC()) {$config->{size_y}-=23; if ($config->{position_y}<21) {$config->{position_y}=21;}}
|
|
0
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
169
|
0
|
0
|
|
|
|
|
$config->{position_x} = 0 if $screen_x < $config->{position_x};
|
170
|
0
|
0
|
|
|
|
|
$config->{position_y} = 0 if $screen_y < $config->{position_y};
|
171
|
|
|
|
|
|
|
} else {
|
172
|
0
|
|
|
|
|
|
$config->{position_x} = $default->{position_x};
|
173
|
0
|
|
|
|
|
|
$config->{position_y} = $default->{position_y};
|
174
|
0
|
|
|
|
|
|
$config->{size_x} = $default->{size_x};
|
175
|
0
|
|
|
|
|
|
$config->{size_y} = $default->{size_y};
|
176
|
|
|
|
|
|
|
}
|
177
|
0
|
|
|
|
|
|
_ref()->SetSize(
|
178
|
|
|
|
|
|
|
$config->{position_x}, $config->{position_y},
|
179
|
|
|
|
|
|
|
$config->{size_x}, $config->{size_y}
|
180
|
|
|
|
|
|
|
);
|
181
|
|
|
|
|
|
|
}
|
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
sub OnPaint {
|
184
|
0
|
|
|
0
|
0
|
|
my ( $self, $event ) = @_;
|
185
|
0
|
|
|
|
|
|
my $dc = Wx::PaintDC->new($self); # create a device context (DC)
|
186
|
|
|
|
|
|
|
}
|
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
sub OnQuit {
|
189
|
0
|
|
|
0
|
0
|
|
my ( $self, $event ) = @_;
|
190
|
0
|
|
|
|
|
|
$self->Close(1);
|
191
|
|
|
|
|
|
|
}
|
192
|
|
|
|
|
|
|
|
193
|
0
|
|
|
0
|
0
|
|
sub destroy { _ref()->Destroy() }
|
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
1;
|
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=head1 NAME
|
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
Kephra::App::Window - frame of the main window
|
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=head1 DESCRIPTION
|
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=cut
|
204
|
|
|
|
|
|
|
|