File: HtmlViewer.pm

package info (click to toggle)
eekboek 2.04-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, trixie
  • size: 3,232 kB
  • sloc: perl: 19,733; sql: 370; ansic: 124; makefile: 35; lisp: 26
file content (185 lines) | stat: -rw-r--r-- 4,782 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#! perl

package main;

package EB::Wx::Shell::HtmlViewer;

use base qw(Wx::Dialog);
use base qw(EB::Wx::Shell::Window);
use strict;

# begin wxGlade: ::dependencies
use Wx::Locale gettext => '_T';
# end wxGlade

use Wx::Html;

use Wx qw[
          wxADJUST_MINSIZE
          wxALL
          wxDEFAULT_DIALOG_STYLE
          wxDefaultPosition
          wxDefaultSize
          wxEXPAND
          wxHORIZONTAL
          wxID_CLOSE
          wxID_OK
          wxID_PRINT
          wxID_SAVE
          wxLEFT
          wxMAXIMIZE_BOX
          wxMINIMIZE_BOX
          wxFD_OVERWRITE_PROMPT
          wxRESIZE_BORDER
          wxFD_SAVE
          wxTHICK_FRAME
          wxVERTICAL
       ];

sub new {
	my( $self, $parent, $id, $title, $pos, $size, $style, $name ) = @_;
	$parent = undef              unless defined $parent;
	$id     = -1                 unless defined $id;
	$title  = ""                 unless defined $title;
	$pos    = wxDefaultPosition  unless defined $pos;
	$size   = wxDefaultSize      unless defined $size;
	$name   = ""                 unless defined $name;

# begin wxGlade: EB::Wx::Shell::HtmlViewer::new

	$style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER|wxMAXIMIZE_BOX|wxMINIMIZE_BOX|wxTHICK_FRAME 
		unless defined $style;

	$self = $self->SUPER::new( $parent, $id, $title, $pos, $size, $style, $name );
	$self->{b_print} = Wx::Button->new($self, wxID_PRINT, "");
	$self->{b_save} = Wx::Button->new($self, wxID_SAVE, "");
	$self->{p_close} = Wx::Button->new($self, wxID_CLOSE, "");
	$self->{p_htmlview} = Wx::HtmlWindow->new($self, -1, wxDefaultPosition, wxDefaultSize, );

	$self->__set_properties();
	$self->__do_layout();

	Wx::Event::EVT_BUTTON($self, $self->{b_print}->GetId, \&OnPrint);
	Wx::Event::EVT_BUTTON($self, $self->{b_save}->GetId, \&OnSave);
	Wx::Event::EVT_BUTTON($self, $self->{p_close}->GetId, \&OnClose);

# end wxGlade

	Wx::Event::EVT_HTML_LINK_CLICKED($self->{p_htmlview}, $self->{p_htmlview}->GetId, \&OnLinkClicked);

	$self->{_PRINTER} =  Wx::HtmlEasyPrinting->new('Print');

	$self->sizepos_restore(lc($title));

	return $self;

}

sub info_only {
    my ( $self ) = @_;
    $self->{b_print}->Hide;
    $self->{b_save}->Hide;
}

sub html     { $_[0]->{p_htmlview}  }
sub htmltext :lvalue { $_[0]->{_HTMLTEXT} }
sub printer  { $_[0]->{_PRINTER}  }

sub __set_properties {
	my $self = shift;

# begin wxGlade: EB::Wx::Shell::HtmlViewer::__set_properties

	$self->SetTitle(_T("HTML Uitvoer"));
	$self->SetSize(Wx::Size->new(618, 522));
	$self->{p_close}->SetFocus();
	$self->{p_close}->SetDefault();

# end wxGlade
}

sub __do_layout {
	my $self = shift;

# begin wxGlade: EB::Wx::Shell::HtmlViewer::__do_layout

	$self->{sz_htmlview} = Wx::BoxSizer->new(wxVERTICAL);
	$self->{sz_htmlviewbuttons} = Wx::BoxSizer->new(wxHORIZONTAL);
	$self->{sz_htmlviewbuttons}->Add($self->{b_print}, 0, wxADJUST_MINSIZE, 0);
	$self->{sz_htmlviewbuttons}->Add($self->{b_save}, 0, wxLEFT|wxADJUST_MINSIZE, 5);
	$self->{sz_htmlviewbuttons}->Add(5, 1, 1, wxADJUST_MINSIZE, 0);
	$self->{sz_htmlviewbuttons}->Add($self->{p_close}, 0, wxADJUST_MINSIZE, 0);
	$self->{sz_htmlview}->Add($self->{sz_htmlviewbuttons}, 0, wxALL|wxEXPAND, 5);
	$self->{sz_htmlview}->Add($self->{p_htmlview}, 1, wxEXPAND, 0);
	$self->SetSizer($self->{sz_htmlview});
	$self->Layout();

# end wxGlade
}

sub OnPrint {
    my ($self, $event) = @_;
# wxGlade: EB::Wx::Shell::HtmlViewer::OnPrint <event_handler>
    $self->printer->SetFooter(' - @PAGENUM@ - ');
    $self->printer->PrintText($self->htmltext);
# end wxGlade
}


sub OnSave {
    my ($self, $event) = @_;
# wxGlade: EB::Wx::Shell::HtmlViewer::OnSave <event_handler>
    my $d = Wx::FileDialog->new($self, _T("Opslaan als..."),
				"", _T("raport.html"),
				_T("HTML bestanden (*.html)|*.html"),
				wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
    my $result = $d->ShowModal;
    if ( $result == wxID_OK ) {
	my $file = $d->GetPath;
	open(my $fd, ">", $file);
	print { $fd } $self->htmltext;
	close($fd);
    }
# end wxGlade
}


sub OnClose {
    my ($self, $event) = @_;
# wxGlade: EB::Wx::Shell::HtmlViewer::OnClose <event_handler>
    $self->sizepos_save;
    $self->Show(0);
# end wxGlade
}

sub OnLinkClicked {
    my ($self, $event) = @_;

    my $link = $event->GetLinkInfo->GetHref;

    if ( $link =~ m;^([^:]+)://(.+)$;
	 && (my $rep = EB::Wx::Shell::MainFrame->can("ShowR" . ucfirst(lc($1)))) ) {
	my @a = split(/[?&]/, $2);
	my $args = { select => shift(@a) };
	foreach ( @a ) {
	    if ( /^([^=]+)=(.*)/ ) {
		$args->{$1} = $2;
	    }
	    else {
		$args->{$_} = 1;
	    }
	}
	$rep->($self->GetParent->GetParent, $args);
    }
    elsif ( $link =~ m;^(https?|mailto):; ) {
	Wx::LaunchDefaultBrowser($link);
    }
    else {
	Wx::LogMessage('Link: "%s"', $1);
    }
}

# end of class EB::Wx::Shell::HtmlViewer

1;