| 1 | # ---------------------------------------------------------------------- | ||||||||||||
| 2 | # Curses::UI::Window | ||||||||||||
| 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::Window; | ||||||||||||
| 14 | |||||||||||||
| 15 | 6 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 16 | 6 | ▶ | use Curses; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 17 | 6 | ▶ | use Curses::UI::Container; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 18 | 6 | ▶ | use Curses::UI::Common; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 19 | |||||||||||||
| 20 | 6 | ▶ | use vars qw( | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 21 | $VERSION | ||||||||||||
| 22 | @ISA | ||||||||||||
| 23 | 6 | ); | |||||||||||
| 24 | |||||||||||||
| 25 | 6 | $VERSION = '1.10'; | |||||||||||
| 26 | |||||||||||||
| 27 | 6 | @ISA = qw( | |||||||||||
| 28 | Curses::UI::Container | ||||||||||||
| 29 | ); | ||||||||||||
| 30 | |||||||||||||
| 31 | sub new () | ||||||||||||
| 32 | 13 | ▶ | { | ||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 33 | 13 | my $class = shift; | |||||||||||
| 34 | |||||||||||||
| 35 | 13 | my %userargs = @_; | |||||||||||
| 36 | 13 | keys_to_lowercase(\%userargs); | |||||||||||
| 37 | |||||||||||||
| 38 | # Create the window. | ||||||||||||
| 39 | 13 | my $this = $class->SUPER::new( | |||||||||||
| 40 | -width => undef, | ||||||||||||
| 41 | -height => undef, | ||||||||||||
| 42 | -x => 0, | ||||||||||||
| 43 | -y => 0, | ||||||||||||
| 44 | -centered => 0, # Center the window in the display? | ||||||||||||
| 45 | |||||||||||||
| 46 | %userargs, | ||||||||||||
| 47 | |||||||||||||
| 48 | -nocursor => 1, # This widget does not use a cursor | ||||||||||||
| 49 | -assubwin => 1, # Always constructed as a subwindow | ||||||||||||
| 50 | ); | ||||||||||||
| 51 | |||||||||||||
| 52 | 13 | return $this; | |||||||||||
| 53 | } | ||||||||||||
| 54 | |||||||||||||
| 55 | sub layout () | ||||||||||||
| 56 | 13 | ▶ | { | ||||||||||
|
Subroutine
layout: called CC=7 SCAR=32.6
Pod
documented
| |||||||||||||
| 57 | 13 | my $this = shift; | |||||||||||
| 58 | |||||||||||||
| 59 | # Compute the coordinates of the Window if | ||||||||||||
| 60 | # it has to be centered. | ||||||||||||
| 61 | 13 | ▶ | if ($this->{-centered}) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 62 | { | ||||||||||||
| 63 | # The maximum available space on the screen. | ||||||||||||
| 64 | 0 | my $avail_width = $ENV{COLS}; | |||||||||||
| 65 | 0 | my $avail_height = $ENV{LINES}; | |||||||||||
| 66 | |||||||||||||
| 67 | # Compute the coordinates for the widget. | ||||||||||||
| 68 | 0 | ▶ | my $w = $this->{-width} || 1; | ||||||||||
|
Condition0%0/2
$this->{'-width'} || 1
MC/DC0%0/1
$this->{'-width'} || 1
$this->{'-width'}
Truth table0%0/2
A
A= $this->{'-width'}
| |||||||||||||
| 69 | 0 | ▶ | my $h = $this->{-height} || 1; | ||||||||||
|
Condition0%0/2
$this->{'-height'} || 1
MC/DC0%0/1
$this->{'-height'} || 1
$this->{'-height'}
Truth table0%0/2
A
A= $this->{'-height'}
| |||||||||||||
| 70 | 0 | my $x = int(($avail_width - $w) / 2); | |||||||||||
| 71 | 0 | my $y = int(($avail_height - $h) / 2); | |||||||||||
| 72 | 0 | ▶ | $x = 0 if $x < 0; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 73 | 0 | ▶ | $y = 0 if $y < 0; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 74 | 0 | $this->{-x} = $x; | |||||||||||
| 75 | 0 | $this->{-y} = $y; | |||||||||||
| 76 | } | ||||||||||||
| 77 | |||||||||||||
| 78 | 13 | ▶ | $this->SUPER::layout or return; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 79 | |||||||||||||
| 80 | 9 | return $this; | |||||||||||
| 81 | } | ||||||||||||
| 82 | |||||||||||||
| 83 | |||||||||||||
| 84 | 6 | 1; | |||||||||||
| 85 | |||||||||||||
| 86 | =pod | ||||||||||||
| 87 | |||||||||||||
| 88 | =head1 NAME | ||||||||||||
| 89 | |||||||||||||
| 90 | Curses::UI::Window - Create and manipulate Window widgets | ||||||||||||
| 91 | |||||||||||||
| 92 | =head1 CLASS HIERARCHY | ||||||||||||
| 93 | |||||||||||||
| 94 | Curses::UI::Widget | ||||||||||||
| 95 | | | ||||||||||||
| 96 | +----Curses::UI::Container | ||||||||||||
| 97 | | | ||||||||||||
| 98 | +----Curses::UI::Window | ||||||||||||
| 99 | |||||||||||||
| 100 | |||||||||||||
| 101 | =head1 SYNOPSIS | ||||||||||||
| 102 | |||||||||||||
| 103 | use Curses::UI; | ||||||||||||
| 104 | my $cui = new Curses::UI; | ||||||||||||
| 105 | my $win = $cui->add( | ||||||||||||
| 106 | 'window_id', 'Window', | ||||||||||||
| 107 | %options, | ||||||||||||
| 108 | ); | ||||||||||||
| 109 | |||||||||||||
| 110 | |||||||||||||
| 111 | =head1 DESCRIPTION | ||||||||||||
| 112 | |||||||||||||
| 113 | Curses::UI::Window is a window widget. It can be added to | ||||||||||||
| 114 | a Curses::UI instance. After that the window can be filled | ||||||||||||
| 115 | with other widgets to create an application window. For | ||||||||||||
| 116 | information on how to fill the window with widgets, see | ||||||||||||
| 117 | L<Curses::UI::Container|Curses::UI::Container>. | ||||||||||||
| 118 | |||||||||||||
| 119 | |||||||||||||
| 120 | |||||||||||||
| 121 | =head1 STANDARD OPTIONS | ||||||||||||
| 122 | |||||||||||||
| 123 | B<-parent>, B<-x>, B<-y>, B<-width>, B<-height>, | ||||||||||||
| 124 | B<-pad>, B<-padleft>, B<-padright>, B<-padtop>, B<-padbottom>, | ||||||||||||
| 125 | B<-ipad>, B<-ipadleft>, B<-ipadright>, B<-ipadtop>, B<-ipadbottom>, | ||||||||||||
| 126 | B<-title>, B<-titlefullwidth>, B<-titlereverse>, B<-onfocus>, | ||||||||||||
| 127 | B<-onblur> | ||||||||||||
| 128 | |||||||||||||
| 129 | For an explanation of these standard options, see | ||||||||||||
| 130 | L<Curses::UI::Widget|Curses::UI::Widget>. | ||||||||||||
| 131 | |||||||||||||
| 132 | |||||||||||||
| 133 | |||||||||||||
| 134 | =head1 WIDGET-SPECIFIC OPTIONS | ||||||||||||
| 135 | |||||||||||||
| 136 | =over 4 | ||||||||||||
| 137 | |||||||||||||
| 138 | =item * B<-centered> < BOOLEAN > | ||||||||||||
| 139 | |||||||||||||
| 140 | A window can automatically be drawn in the center of the screen. | ||||||||||||
| 141 | To enable this option use a true value and to disable it use a | ||||||||||||
| 142 | false value. The default is not to center a window. Example: | ||||||||||||
| 143 | |||||||||||||
| 144 | $cui->add('mywindow', 'Window', -centered => 1); | ||||||||||||
| 145 | |||||||||||||
| 146 | |||||||||||||
| 147 | =back | ||||||||||||
| 148 | |||||||||||||
| 149 | |||||||||||||
| 150 | =head1 METHODS | ||||||||||||
| 151 | |||||||||||||
| 152 | =over 4 | ||||||||||||
| 153 | |||||||||||||
| 154 | =item * B<new> ( OPTIONS ) | ||||||||||||
| 155 | |||||||||||||
| 156 | =item * B<layout> ( ) | ||||||||||||
| 157 | |||||||||||||
| 158 | =item * B<draw> ( BOOLEAN ) | ||||||||||||
| 159 | |||||||||||||
| 160 | =item * B<focus> ( ) | ||||||||||||
| 161 | |||||||||||||
| 162 | =item * B<onFocus> ( CODEREF ) | ||||||||||||
| 163 | |||||||||||||
| 164 | =item * B<onBlur> ( CODEREF ) | ||||||||||||
| 165 | |||||||||||||
| 166 | =item * B<intellidraw> ( ) | ||||||||||||
| 167 | |||||||||||||
| 168 | These are standard methods. See L<Curses::UI::Widget|Curses::UI::Widget> | ||||||||||||
| 169 | for an explanation of these. | ||||||||||||
| 170 | |||||||||||||
| 171 | =item * B<modalfocus> ( ) | ||||||||||||
| 172 | |||||||||||||
| 173 | If this method is called, the window will get modal focus. This means | ||||||||||||
| 174 | that all events will be sent to this window. By calling the | ||||||||||||
| 175 | B<loose_focus> method, the window will loose its focus. | ||||||||||||
| 176 | |||||||||||||
| 177 | =item * B<loose_focus> ( ) | ||||||||||||
| 178 | |||||||||||||
| 179 | This method will have the window loose its focus (using this method | ||||||||||||
| 180 | you can also let a modal focused window loose its focus). | ||||||||||||
| 181 | |||||||||||||
| 182 | =back | ||||||||||||
| 183 | |||||||||||||
| 184 | |||||||||||||
| 185 | =head1 SEE ALSO | ||||||||||||
| 186 | |||||||||||||
| 187 | L<Curses::UI|Curses::UI>, | ||||||||||||
| 188 | L<Curses::UI::Container|Curses::UI::Container>, | ||||||||||||
| 189 | L<Curses::UI::Widget|Curses::UI::Widget> | ||||||||||||
| 190 | |||||||||||||
| 191 | |||||||||||||
| 192 | |||||||||||||
| 193 | =head1 AUTHOR | ||||||||||||
| 194 | |||||||||||||
| 195 | Copyright (c) 2001-2002 Maurice Makaay. All rights reserved. | ||||||||||||
| 196 | |||||||||||||
| 197 | Maintained by Marcus Thiesen (marcus@cpan.thiesenweb.de) | ||||||||||||
| 198 | |||||||||||||
| 199 | |||||||||||||
| 200 | This package is free software and is provided "as is" without express | ||||||||||||
| 201 | or implied warranty. It may be used, redistributed and/or modified | ||||||||||||
| 202 | under the same terms as perl itself. | ||||||||||||
| 203 | |||||||||||||