| 1 | package Tk::AppWindow::BaseClasses::ContentManager; | ||
| 2 | |||
| 3 | =head1 NAME | ||
| 4 | |||
| 5 | Tk::AppWindow::BaseClasses::ContentManager - baseclass for content handling | ||
| 6 | |||
| 7 | =cut | ||
| 8 | |||
| 9 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 10 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 11 | 1 | ▶ | use Carp; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 12 | |||
| 13 | 1 | ▶ | use vars qw($VERSION); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 14 | $VERSION="0.20"; | ||
| 15 | |||
| 16 | 0 | ▶ | use Tk; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 17 | use base qw(Tk::Derived Tk::Frame); | ||
| 18 | Construct Tk::Widget 'ContentManager'; | ||
| 19 | |||
| 20 | use File::Basename; | ||
| 21 | |||
| 22 | |||
| 23 | =head1 SYNOPSIS | ||
| 24 | |||
| 25 | #This is useless | ||
| 26 | require Tk::AppWindow::BaseClasses::ContentManager; | ||
| 27 | my $handlerplug = $app->ContentManager->pack; | ||
| 28 | |||
| 29 | #This is what you should do | ||
| 30 | package MyContentHandler | ||
| 31 | use base qw(Tk::Derived Tk::AppWindow::BaseClasses::ContentManager); | ||
| 32 | Construct Tk::Widget 'MyContentHandler'; | ||
| 33 | |||
| 34 | =head1 DESCRIPTION | ||
| 35 | |||
| 36 | This is an opaque base class to help you create a content manager for your application. | ||
| 37 | |||
| 38 | It is Tk::Frame based and you can inherit it as a Tk mega widget; | ||
| 39 | |||
| 40 | The methods below are used by the extensions MDI and SDI. It is for you to make | ||
| 41 | them do the right stuff by overriding them. | ||
| 42 | |||
| 43 | =head1 OPTIONS | ||
| 44 | |||
| 45 | =over 4 | ||
| 46 | |||
| 47 | =item B<-extension> | ||
| 48 | |||
| 49 | Reference to the document interface extension (MDI, SDI or other) that is creating the | ||
| 50 | content handler. | ||
| 51 | |||
| 52 | This option is mandatory! | ||
| 53 | |||
| 54 | =back | ||
| 55 | |||
| 56 | =head1 METHODS | ||
| 57 | |||
| 58 | =over 4 | ||
| 59 | |||
| 60 | =cut | ||
| 61 | |||
| 62 | sub Populate { | ||
| 63 | my ($self,$args) = @_; | ||
| 64 | |||
| 65 | my $ext = delete $args->{'-extension'}; | ||
| 66 | carp "Option -extension mustt be specified" unless defined $ext; | ||
| 67 | |||
| 68 | $self->SUPER::Populate($args); | ||
| 69 | $self->{EXT} = $ext; | ||
| 70 | |||
| 71 | $self->ConfigSpecs( | ||
| 72 | DEFAULT => ['SELF'], | ||
| 73 | ); | ||
| 74 | $self->after(20, ['ConfigureCM', $self]); | ||
| 75 | } | ||
| 76 | |||
| 77 | =item B<Close> | ||
| 78 | |||
| 79 | In the current form it makes a call to B<doclear> and returns 1. | ||
| 80 | Override it to do the things neede to close your content. | ||
| 81 | Return a boolean for succes or failure. | ||
| 82 | |||
| 83 | =cut | ||
| 84 | |||
| 85 | sub Close { | ||
| 86 | my $self = shift; | ||
| 87 | $self->doClear; | ||
| 88 | return 1 | ||
| 89 | } | ||
| 90 | |||
| 91 | sub ConfigureCM { | ||
| 92 | my $self = shift; | ||
| 93 | my $ext = $self->Extension; | ||
| 94 | my $cmopt = $ext->configGet('-contentmanageroptions'); | ||
| 95 | my @o = @$cmopt; #hack, i do not know why this is needed. | ||
| 96 | for (@o) { | ||
| 97 | my $val = $ext->configGet($_); | ||
| 98 | $self->configure($_, $val) if ((defined $val) and ($val ne '')); | ||
| 99 | } | ||
| 100 | } | ||
| 101 | |||
| 102 | =item B<CWidg>I<(?$widget?)> | ||
| 103 | |||
| 104 | Set or return the widget that is directly responsible | ||
| 105 | for holding your content. | ||
| 106 | |||
| 107 | Do not override this. | ||
| 108 | |||
| 109 | =cut | ||
| 110 | |||
| 111 | sub CWidg { | ||
| 112 | my $self = shift; | ||
| 113 | $self->{WIDGET} = shift if @_; | ||
| 114 | return $self->{WIDGET}; | ||
| 115 | } | ||
| 116 | |||
| 117 | =item B<doClear> | ||
| 118 | |||
| 119 | Override this to clear all content in your B<CWidg>. | ||
| 120 | |||
| 121 | =cut | ||
| 122 | |||
| 123 | sub doClear{ | ||
| 124 | } | ||
| 125 | |||
| 126 | =item B<doLoad>I(<$file)> | ||
| 127 | |||
| 128 | Override this to load a file from disk. | ||
| 129 | Make it return a boolean on succes or failure. | ||
| 130 | |||
| 131 | =cut | ||
| 132 | |||
| 133 | sub doLoad { | ||
| 134 | return 1 | ||
| 135 | } | ||
| 136 | |||
| 137 | =item B<doSave>I(<$file)> | ||
| 138 | |||
| 139 | Override this to save the content to disk. | ||
| 140 | Make it return a boolean on succes or failure. | ||
| 141 | |||
| 142 | =cut | ||
| 143 | |||
| 144 | sub doSave { | ||
| 145 | return 1 | ||
| 146 | } | ||
| 147 | |||
| 148 | =item B<doSelect> | ||
| 149 | |||
| 150 | Override this to do what needs to be done | ||
| 151 | when this content is selected. | ||
| 152 | |||
| 153 | =cut | ||
| 154 | |||
| 155 | sub doSelect { | ||
| 156 | } | ||
| 157 | |||
| 158 | =item B<Extension> | ||
| 159 | |||
| 160 | Returns a reference to the document interface (MDI, SDI or derivative). | ||
| 161 | |||
| 162 | Do not override this. | ||
| 163 | |||
| 164 | =cut | ||
| 165 | |||
| 166 | sub Extension { | ||
| 167 | my $self = shift; | ||
| 168 | if (@_) { $self->{EXT} = shift; } | ||
| 169 | return $self->{EXT}; | ||
| 170 | } | ||
| 171 | |||
| 172 | =item B<IsModified> | ||
| 173 | |||
| 174 | Override this for checking if the content has been modified. | ||
| 175 | |||
| 176 | =cut | ||
| 177 | |||
| 178 | sub IsModified { | ||
| 179 | my $self = shift; | ||
| 180 | return 0 | ||
| 181 | } | ||
| 182 | |||
| 183 | =item B<Load>I<($file)> | ||
| 184 | |||
| 185 | Makes a call to B<doLoad> | ||
| 186 | |||
| 187 | =cut | ||
| 188 | |||
| 189 | sub Load { | ||
| 190 | my ($self, $file) = @_; | ||
| 191 | return $self->doLoad($file); | ||
| 192 | } | ||
| 193 | |||
| 194 | =item B<Save>I<($file)> | ||
| 195 | |||
| 196 | Makes a call to B<doSave> | ||
| 197 | |||
| 198 | =cut | ||
| 199 | |||
| 200 | sub Save { | ||
| 201 | my ($self, $file) = @_; | ||
| 202 | return $self->doSave($file); | ||
| 203 | } | ||
| 204 | |||
| 205 | =back | ||
| 206 | |||
| 207 | =head1 AUTHOR | ||
| 208 | |||
| 209 | Hans Jeuken (hanje at cpan dot org) | ||
| 210 | |||
| 211 | =head1 BUGS | ||
| 212 | |||
| 213 | Unknown. If you find any, please contact the author. | ||
| 214 | |||
| 215 | =head1 SEE ALSO | ||
| 216 | |||
| 217 | =over 4 | ||
| 218 | |||
| 219 | =item L<Tk::Frame> | ||
| 220 | |||
| 221 | =item L<Tk::AppWindow::Ext::MDI> | ||
| 222 | |||
| 223 | =back | ||
| 224 | |||
| 225 | =cut | ||
| 226 | |||
| 227 | 1; | ||
| 228 | |||
| 229 | |||
| 230 | |||
| 231 | |||
| 232 | |||
| 233 | |||