| 1 | # ---------------------------------------------------------------------- | ||
| 2 | # Curses::UI::Dialog::Status | ||
| 3 | # | ||
| 4 | # (c) 2001-2002 by Maurice Makaay. All rights reserved. | ||
| 5 | # This file is part of Curses::UI. Curses::UI is free software. | ||
| 6 | # You can redistribute it and/or modify it under the same terms | ||
| 7 | # as perl itself. | ||
| 8 | # | ||
| 9 | # Currently maintained by Marcus Thiesen | ||
| 10 | # e-mail: marcus@cpan.thiesenweb.de | ||
| 11 | # ---------------------------------------------------------------------- | ||
| 12 | |||
| 13 | package Curses::UI::Dialog::Status; | ||
| 14 | |||
| 15 | use strict; | ||
| 16 | use Curses; | ||
| 17 | use Curses::UI::Common; | ||
| 18 | use Curses::UI::Window; | ||
| 19 | |||
| 20 | use vars qw( | ||
| 21 | $VERSION | ||
| 22 | @ISA | ||
| 23 | ); | ||
| 24 | |||
| 25 | @ISA = qw( | ||
| 26 | Curses::UI::Window | ||
| 27 | Curses::UI::Common | ||
| 28 | ); | ||
| 29 | |||
| 30 | $VERSION = '1.10'; | ||
| 31 | |||
| 32 | sub new () | ||
| 33 | { | ||
| 34 | my $class = shift; | ||
| 35 | |||
| 36 | my %userargs = @_; | ||
| 37 | keys_to_lowercase(\%userargs); | ||
| 38 | |||
| 39 | my %args = ( | ||
| 40 | -message => undef, # The message to show | ||
| 41 | -ipad => 1, | ||
| 42 | -border => 1, | ||
| 43 | -width => undef, | ||
| 44 | -height => undef, | ||
| 45 | -fg => -1, | ||
| 46 | -bg => -1, | ||
| 47 | |||
| 48 | %userargs, | ||
| 49 | |||
| 50 | -centered => 1, | ||
| 51 | ); | ||
| 52 | |||
| 53 | my $this = $class->SUPER::new(%args); | ||
| 54 | $args{-message} = 'no message' unless defined $args{-message}; | ||
| 55 | |||
| 56 | my $l = $this->add( | ||
| 57 | 'label', 'Label', | ||
| 58 | -text => $this->{-message}, | ||
| 59 | -fg => $this->{-fg}, | ||
| 60 | -bg => $this->{-bg}, | ||
| 61 | ); | ||
| 62 | |||
| 63 | $this->layout(); | ||
| 64 | |||
| 65 | bless $this, $class; | ||
| 66 | } | ||
| 67 | |||
| 68 | # There is no need to focus a status dialog | ||
| 69 | sub focus() {} ; | ||
| 70 | |||
| 71 | sub layout() | ||
| 72 | { | ||
| 73 | my $this = shift; | ||
| 74 | |||
| 75 | my $label = $this->getobj('label'); | ||
| 76 | |||
| 77 | # The label might not be added at this point. | ||
| 78 | if (defined $label) | ||
| 79 | { | ||
| 80 | # Compute the width the dialog window needs. | ||
| 81 | if (not defined $this->{-width}) | ||
| 82 | { | ||
| 83 | $this->{-width} = $this->width_by_windowscrwidth( | ||
| 84 | $label->{-width} + 1, # +1 for visible cursor | ||
| 85 | %$this | ||
| 86 | ); | ||
| 87 | } | ||
| 88 | |||
| 89 | # Compute the height the dialog window needs. | ||
| 90 | if (not defined $this->{-height}) | ||
| 91 | { | ||
| 92 | $this->{-height} = $this->height_by_windowscrheight( | ||
| 93 | $label->{-height}, | ||
| 94 | %$this | ||
| 95 | ); | ||
| 96 | } | ||
| 97 | |||
| 98 | } | ||
| 99 | |||
| 100 | $this->SUPER::layout or return; | ||
| 101 | |||
| 102 | return $this; | ||
| 103 | } | ||
| 104 | |||
| 105 | sub message($;) | ||
| 106 | { | ||
| 107 | my $this = shift; | ||
| 108 | my $message = shift; | ||
| 109 | $message = 'no message' unless defined $message; | ||
| 110 | $this->getobj('label')->text($message); | ||
| 111 | return $this; | ||
| 112 | } | ||
| 113 | |||
| 114 | 1; | ||
| 115 | |||
| 116 | |||
| 117 | =pod | ||
| 118 | |||
| 119 | =head1 NAME | ||
| 120 | |||
| 121 | Curses::UI::Dialog::Status - Create and manipulate status dialogs | ||
| 122 | |||
| 123 | =head1 CLASS HIERARCHY | ||
| 124 | |||
| 125 | Curses::UI::Widget | ||
| 126 | | | ||
| 127 | +----Curses::UI::Container | ||
| 128 | | | ||
| 129 | +----Curses::UI::Window | ||
| 130 | | | ||
| 131 | +----Curses::UI::Dialog::Status | ||
| 132 | |||
| 133 | |||
| 134 | =head1 SYNOPSIS | ||
| 135 | |||
| 136 | use Curses::UI; | ||
| 137 | my $cui = new Curses::UI; | ||
| 138 | my $win = $cui->add('window_id', 'Window'); | ||
| 139 | |||
| 140 | # The hard way. | ||
| 141 | # ------------- | ||
| 142 | my $dialog = $win->add( | ||
| 143 | 'mydialog', 'Dialog::Status', | ||
| 144 | -message => 'Hello, world!', | ||
| 145 | ); | ||
| 146 | |||
| 147 | $dialog->draw(); | ||
| 148 | |||
| 149 | $win->delete('mydialog'); | ||
| 150 | |||
| 151 | # The easy way (see Curses::UI documentation). | ||
| 152 | # -------------------------------------------- | ||
| 153 | $cui->status( -message => 'Some message' ); | ||
| 154 | |||
| 155 | # or even: | ||
| 156 | $cui->status( 'Some message' ); | ||
| 157 | |||
| 158 | $cui->nostatus; | ||
| 159 | |||
| 160 | |||
| 161 | |||
| 162 | |||
| 163 | =head1 DESCRIPTION | ||
| 164 | |||
| 165 | Curses::UI::Dialog::Status is not really a dialog, since | ||
| 166 | the user has no way of interacting with it. It is merely | ||
| 167 | a way of presenting status information to the user of | ||
| 168 | your program. | ||
| 169 | |||
| 170 | |||
| 171 | See exampes/demo-Curses::UI::Dialog::Status in the | ||
| 172 | distribution for a short demo. | ||
| 173 | |||
| 174 | |||
| 175 | |||
| 176 | =head1 OPTIONS | ||
| 177 | |||
| 178 | =over 4 | ||
| 179 | |||
| 180 | =item * B<-title> < TEXT > | ||
| 181 | |||
| 182 | Set the title of the dialog window to TEXT. | ||
| 183 | |||
| 184 | =item * B<-message> < TEXT > | ||
| 185 | |||
| 186 | This option sets the initial message to show to TEXT. | ||
| 187 | |||
| 188 | =back | ||
| 189 | |||
| 190 | |||
| 191 | |||
| 192 | |||
| 193 | =head1 METHODS | ||
| 194 | |||
| 195 | =over 4 | ||
| 196 | |||
| 197 | =item * B<new> ( OPTIONS ) | ||
| 198 | |||
| 199 | =item * B<layout> ( ) | ||
| 200 | |||
| 201 | =item * B<draw> ( BOOLEAN ) | ||
| 202 | |||
| 203 | These are standard methods. See L<Curses::UI::Container|Curses::UI::Container> | ||
| 204 | for an explanation of these. | ||
| 205 | |||
| 206 | =item * B<message> ( TEXT ) | ||
| 207 | |||
| 208 | This method will update the message of the status dialog | ||
| 209 | to TEXT. For this update to show, you will have to call the | ||
| 210 | B<draw> method of the progress dialog. | ||
| 211 | |||
| 212 | =back | ||
| 213 | |||
| 214 | |||
| 215 | |||
| 216 | |||
| 217 | =head1 SEE ALSO | ||
| 218 | |||
| 219 | L<Curses::UI|Curses::UI>, | ||
| 220 | L<Curses::UI::Container|Curses::UI::Container> | ||
| 221 | |||
| 222 | |||
| 223 | |||
| 224 | |||
| 225 | =head1 AUTHOR | ||
| 226 | |||
| 227 | Copyright (c) 2001-2002 Maurice Makaay. All rights reserved. | ||
| 228 | |||
| 229 | Maintained by Marcus Thiesen (marcus@cpan.thiesenweb.de) | ||
| 230 | |||
| 231 | |||
| 232 | This package is free software and is provided "as is" without express | ||
| 233 | or implied warranty. It may be used, redistributed and/or modified | ||
| 234 | under the same terms as perl itself. | ||
| 235 |