| 1 | package DBIx::Perform::UserInterface; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | use POSIX; | ||
| 6 | use Carp; | ||
| 7 | use Curses; # to get KEY_* | ||
| 8 | use Curses::Application; | ||
| 9 | use DBIx::Perform::DButils; | ||
| 10 | use DBIx::Perform::Forms; | ||
| 11 | use DBIx::Perform::Widgets::ButtonSet; | ||
| 12 | use DBIx::Perform::SimpleList; | ||
| 13 | use DBIx::Perform::FieldList; | ||
| 14 | use DBIx::Perform::Messages; | ||
| 15 | use base 'Exporter'; | ||
| 16 | use Data::Dumper; | ||
| 17 | |||
| 18 | our $VERSION = '0.695'; | ||
| 19 | |||
| 20 | use constant 'KEY_DEL' => '330'; | ||
| 21 | |||
| 22 | # $UserInterface methods | ||
| 23 | our @EXPORT_OK = qw( | ||
| 24 | &new | ||
| 25 | &parse_per_file | ||
| 26 | &parse_xml_file | ||
| 27 | &parse_yml_file | ||
| 28 | &load_internal | ||
| 29 | &run | ||
| 30 | &capture_file_data | ||
| 31 | &display_help_screen | ||
| 32 | &clear_comment_and_error_display | ||
| 33 | &display_comment | ||
| 34 | &clear_display_comment | ||
| 35 | &display_status | ||
| 36 | &clear_display_status | ||
| 37 | &display_error | ||
| 38 | &clear_display_error | ||
| 39 | &set_field | ||
| 40 | &change_field_focus_on_screen | ||
| 41 | ®ister_button_handler | ||
| 42 | &button_push | ||
| 43 | &change_buttons_to_label | ||
| 44 | &change_label_to_buttons | ||
| 45 | &change_modename | ||
| 46 | &update_info_message | ||
| 47 | &update_subform | ||
| 48 | &set_field_display_bounds | ||
| 49 | &set_field_bounds_on_screen | ||
| 50 | &init_rowlists | ||
| 51 | &get_current_rowlist | ||
| 52 | &increment_global_rowlist | ||
| 53 | &get_field_list | ||
| 54 | &capture_master_detail | ||
| 55 | &get_master_detail_table_names | ||
| 56 | &go_to_table | ||
| 57 | &get_number_of_tables | ||
| 58 | &get_primary_table_name | ||
| 59 | &get_current_table_name | ||
| 60 | &get_table_number | ||
| 61 | &increment_global_tablelist | ||
| 62 | &update_table | ||
| 63 | &update_table_number | ||
| 64 | &update_table_name | ||
| 65 | &get_current_form | ||
| 66 | &get_screen_value | ||
| 67 | &get_screen_subform_widget | ||
| 68 | &old_set_screen_value | ||
| 69 | &set_screen_value | ||
| 70 | &change_mode_display | ||
| 71 | &change_focus_to_button | ||
| 72 | &change_focus_to_field_in_current_table | ||
| 73 | &add_field_list_to_screens | ||
| 74 | &redraw_subform | ||
| 75 | ); | ||
| 76 | |||
| 77 | # LEGEND - the layout and names for the perform user interface | ||
| 78 | # | ||
| 79 | # mode line: mode name | mode label or mode buttons | ||
| 80 | # info line: Info_messages | table number | table name | ||
| 81 | # blank line | ||
| 82 | # form area: DBForm - multiple lines | ||
| 83 | # comment line: next to last from bottom of screen | ||
| 84 | # error line: bottom of screen | ||
| 85 | |||
| 86 | # default column values for user interface lines | ||
| 87 | |||
| 88 | our $MAXX = 80; | ||
| 89 | our $MAXY = 24; | ||
| 90 | |||
| 91 | our $MODENAME_SIZE = 8; | ||
| 92 | our $MODENAME_START = 0; | ||
| 93 | |||
| 94 | our $MODELABEL_SIZE = $MAXX - $MODENAME_SIZE - 3; | ||
| 95 | our $MODELABEL_START = $MODENAME_SIZE + 2; | ||
| 96 | |||
| 97 | our $MODEBUTTON_SIZE = 3; # see your creartor - it's magic | ||
| 98 | our $MODEBUTTON_START = $MODENAME_SIZE + 2; | ||
| 99 | |||
| 100 | our $INFOMSG_SIZE = 46; | ||
| 101 | our $INFOMSG_START = 0; | ||
| 102 | |||
| 103 | our $TABLENUM_SIZE = 6; | ||
| 104 | our $TABLENUM_START = $INFOMSG_SIZE + 2; | ||
| 105 | |||
| 106 | our $TABLENAME_SIZE = $MAXX - $INFOMSG_SIZE - $TABLENUM_SIZE - 2; | ||
| 107 | our $TABLENAME_START = $TABLENUM_START + $TABLENUM_SIZE; | ||
| 108 | |||
| 109 | our $Global_app_ref; | ||
| 110 | our %Button_handlers; | ||
| 111 | |||
| 112 | our $lang = $DBIx::Perform::Messages::languages{$ENV{LANG} || 'en_US'}; | ||
| 113 | our $msgs = $DBIx::Perform::Messages::messages[$lang]; | ||
| 114 | our $msgs_en = $DBIx::Perform::Messages::messages[0]; | ||
| 115 | our @Button_names = @$msgs_en[3..16]; | ||
| 116 | our @Button_labels = @$msgs[3..16]; | ||
| 117 | our @Button_yn_names = @$msgs_en[17..18]; | ||
| 118 | our @Buttons_yn = @$msgs[17..18]; | ||
| 119 | |||
| 120 | our %Button_messages = ( | ||
| 121 | query => $msgs->[19], | ||
| 122 | add => $msgs->[20], | ||
| 123 | update => $msgs->[21], | ||
| 124 | output => $msgs->[22], | ||
| 125 | ); | ||
| 126 | our %Info_messages; | ||
| 127 | our %Runtime_error_messages; | ||
| 128 | |||
| 129 | our @Help_screens = @$msgs[0..1]; | ||
| 130 | |||
| 131 | # When the user hits ESC from the subform, run one of the following | ||
| 132 | # based on the value of the button set. | ||
| 133 | #use vars '%MODESUBS'; | ||
| 134 | |||
| 135 | our %Form = ( | ||
| 136 | TABORDER => [ 'ModeButtons', 'DBForm' ], | ||
| 137 | TYPE => '', # but from DBIx::Perform::Forms | ||
| 138 | # There is some bug in the alt[f]base stuff in Curses::Forms. | ||
| 139 | ALTFBASE => [ 'DBIx::Perform::Forms', 'DBIx::Perform::Widgets' ], | ||
| 140 | ALTBASE => [ 'DBIx::Perform::Forms', 'DBIx::Perform::Widgets' ], | ||
| 141 | FOCUSED => 'ModeButtons', | ||
| 142 | WIDGETS => { | ||
| 143 | ModeName => { | ||
| 144 | TYPE => 'Label', | ||
| 145 | COLUMNS => $MODENAME_SIZE, | ||
| 146 | LINES => 1, | ||
| 147 | VALUE => 'PERFORM: ', | ||
| 148 | BORDER => 0, | ||
| 149 | X => $MODENAME_START, | ||
| 150 | Y => 0, | ||
| 151 | }, | ||
| 152 | ModeLabel => { | ||
| 153 | TYPE => 'Label', | ||
| 154 | COLUMNS => $MODELABEL_SIZE, | ||
| 155 | LINES => 1, | ||
| 156 | VALUE => '', | ||
| 157 | BORDER => 0, | ||
| 158 | X => $MODELABEL_START, | ||
| 159 | Y => 0, | ||
| 160 | }, | ||
| 161 | ModeButtons => { | ||
| 162 | TYPE => 'ButtonSet', | ||
| 163 | LENGTH => $MODEBUTTON_SIZE, | ||
| 164 | PADDING => 0, | ||
| 165 | BORDER => 0, | ||
| 166 | X => $MODEBUTTON_START, | ||
| 167 | Y => 0, | ||
| 168 | FOCUSSWITCH => "\t\n", | ||
| 169 | OnExit => \&button_push, | ||
| 170 | OnEntry => \&button_push, | ||
| 171 | LABELS => \@Button_labels, | ||
| 172 | NAMES => \@Button_names, | ||
| 173 | VALUE => 0, | ||
| 174 | }, | ||
| 175 | InfoMsg => { | ||
| 176 | TYPE => 'Label', | ||
| 177 | COLUMNS => $INFOMSG_SIZE, | ||
| 178 | LINES => 1, | ||
| 179 | VALUE => $msgs->[23], #'query' translated to $LANG | ||
| 180 | BORDER => 0, | ||
| 181 | X => $INFOMSG_START, | ||
| 182 | Y => 1, | ||
| 183 | }, | ||
| 184 | TableNumber => { | ||
| 185 | TYPE => 'Label', | ||
| 186 | COLUMNS => $TABLENUM_SIZE, | ||
| 187 | LINES => 1, | ||
| 188 | VALUE => '', | ||
| 189 | BORDER => 0, | ||
| 190 | X => $TABLENUM_START, | ||
| 191 | Y => 1, | ||
| 192 | }, | ||
| 193 | TableName => { | ||
| 194 | TYPE => 'Label', | ||
| 195 | COLUMNS => $TABLENAME_SIZE, | ||
| 196 | LINES => 1, | ||
| 197 | VALUE => '', | ||
| 198 | BORDER => 0, | ||
| 199 | X => $TABLENAME_START, | ||
| 200 | Y => 1, | ||
| 201 | }, | ||
| 202 | Comment => { | ||
| 203 | TYPE => 'TextField', | ||
| 204 | COLUMNS => $MAXX, | ||
| 205 | LINES => 1, | ||
| 206 | VALUE => '', | ||
| 207 | BORDER => 0, | ||
| 208 | X => 0, | ||
| 209 | Y => $MAXY - 2, | ||
| 210 | }, | ||
| 211 | Error => { | ||
| 212 | TYPE => 'Label', | ||
| 213 | COLUMNS => $MAXX, | ||
| 214 | LINES => 1, | ||
| 215 | VALUE => '', | ||
| 216 | BORDER => 0, | ||
| 217 | |||
| 218 | #FOREGROUND => 'white', | ||
| 219 | #BACKGROUND => 'black', | ||
| 220 | X => 0, | ||
| 221 | Y => $MAXY - 1, | ||
| 222 | }, | ||
| 223 | }, | ||
| 224 | ); | ||
| 225 | |||
| 226 | our %Modesubs = ( | ||
| 227 | query => \&DBIx::Perform::do_query, | ||
| 228 | add => \&DBIx::Perform::do_add, | ||
| 229 | update => \&DBIx::Perform::do_update, | ||
| 230 | ); | ||
| 231 | |||
| 232 | our %App = ( | ||
| 233 | FOREGROUND => 'white', | ||
| 234 | BACKGROUND => 'black', | ||
| 235 | MAINFORM => { Dummy => 'DummyDef' }, # changed at runtime | ||
| 236 | TITLEBAR => 0, | ||
| 237 | STATUSBAR => 0, | ||
| 238 | EXIT => 0, | ||
| 239 | form_name => 'Run0', | ||
| 240 | form_names => [ 'Run0', 'Run1' ], # set later | ||
| 241 | form_name_indexes => { Run0 => 0 }, # also set later | ||
| 242 | md_mode => 'm', # master/detail mode, "m" or "d". | ||
| 243 | resume_command => undef, # do the specified command after switching | ||
| 244 | # master/detail context or screens. | ||
| 245 | ); | ||
| 246 | |||
| 247 | # UserInterface ctor | ||
| 248 | sub new { | ||
| 249 | my $class = shift; | ||
| 250 | |||
| 251 | { | ||
| 252 | my $i = 23; | ||
| 253 | foreach my $k ( | ||
| 254 | qw( query next previous view add update remove table screen | ||
| 255 | current master detail output exit yes no) | ||
| 256 | ) | ||
| 257 | { | ||
| 258 | $Info_messages{$k} = @$msgs[$i]; | ||
| 259 | $i++; | ||
| 260 | } | ||
| 261 | foreach my $k ( | ||
| 262 | qw( no41. th26d th15. no47. no48. db16e er11d no16. da11r | ||
| 263 | se09. se10. se11. no11d 1_8d ro7d ro7d2 ro6d ro8d | ||
| 264 | no14d ro10d ad21e fa39e th44s th47w ro54. so34. so35. | ||
| 265 | th55e in61e th41. ) | ||
| 266 | ) | ||
| 267 | { | ||
| 268 | $Runtime_error_messages{$k} = @$msgs[$i]; | ||
| 269 | $i++; | ||
| 270 | } | ||
| 271 | } | ||
| 272 | |||
| 273 | bless my $self = { | ||
| 274 | file_hash => undef, # may not need this | ||
| 275 | app_hash => \%App, | ||
| 276 | app_object => undef, | ||
| 277 | form_hash => \%Form, | ||
| 278 | form_object => undef, | ||
| 279 | number_of_forms => undef, | ||
| 280 | global_field_list => undef, | ||
| 281 | taborder => undef, | ||
| 282 | file_string => undef, | ||
| 283 | focus => undef, # tag we are focused on | ||
| 284 | master_detail_list => new DBIx::Perform::SimpleList, | ||
| 285 | composite_join_list => new DBIx::Perform::SimpleList, | ||
| 286 | defined_table_names => undef, | ||
| 287 | attribute_table_names => undef, | ||
| 288 | current_table_num => 0, | ||
| 289 | current_rowlist => undef, # current rowlist | ||
| 290 | screens => undef, # array of hashes | ||
| 291 | current_screen_index => undef, # index of current screen in array | ||
| 292 | rowlists => undef, # list of rowlists | ||
| 293 | mode_subs => \%Modesubs, # bullshit | ||
| 294 | button_handlers => \%Button_handlers, | ||
| 295 | button_messages => \%Button_messages, | ||
| 296 | error_messages => \%Runtime_error_messages, | ||
| 297 | info_messages => \%Info_messages, | ||
| 298 | button_labels => \@Button_labels, | ||
| 299 | buttons_yn => \@Buttons_yn, | ||
| 300 | } => ( ref $class || $class ); | ||
| 301 | |||
| 302 | return $self; | ||
| 303 | } | ||
| 304 | |||
| 305 | # methods ----- | ||
| 306 | |||
| 307 | sub parse_per_file { | ||
| 308 | my $self = shift; | ||
| 309 | my $filename = shift; | ||
| 310 | |||
| 311 | if ( !( $filename =~ /\.per$/ ) ) { | ||
| 312 | die "Unknown file name extension on '$filename'"; | ||
| 313 | } | ||
| 314 | open( PER_IN, "< $filename" ) | ||
| 315 | || die "Unable to open '$filename' for reading: $!"; | ||
| 316 | require "DBIx/Perform/DigestPer.pm"; | ||
| 317 | |||
| 318 | my ( $digest, $field_list ) = DBIx::Perform::DigestPer::digest( \*PER_IN ); | ||
| 319 | |||
| 320 | #die "File did not digest to a DBIx::Perform Spec: @{$digest}" | ||
| 321 | # unless $digest =~ /^\$form\s*=/; | ||
| 322 | |||
| 323 | warn "In userinterface: finished digest" if $::TRACE; | ||
| 324 | |||
| 325 | #exit; | ||
| 326 | |||
| 327 | $self->{file_hash} = $self->load_internal( sub { eval $digest } ); | ||
| 328 | $self->{global_field_list} = $field_list; | ||
| 329 | |||
| 330 | return $self->{file_hash}; | ||
| 331 | } | ||
| 332 | |||
| 333 | sub parse_xml_file { | ||
| 334 | my $self = shift; | ||
| 335 | my $filename = shift; | ||
| 336 | |||
| 337 | if ( !( $filename =~ /\.xml$/ ) ) { | ||
| 338 | $filename .= '.xml'; | ||
| 339 | |||
| 340 | # die "Unknown file name extension on '$filename'"; | ||
| 341 | } | ||
| 342 | require "DBIx/Perform/DigestPer.pm"; | ||
| 343 | |||
| 344 | my $retval = DBIx::Perform::DigestPer::digest_xml_file($filename); | ||
| 345 | my @array = @{$retval}; | ||
| 346 | |||
| 347 | my $digest = $array[0]->[0]; | ||
| 348 | my $field_list = $array[0]->[1]; | ||
| 349 | |||
| 350 | die "File did not digest to a DBIx::Perform Spec" | ||
| 351 | unless $digest =~ /\$form\s*=/; | ||
| 352 | |||
| 353 | $self->{file_hash} = $self->load_internal( sub { eval $digest } ); | ||
| 354 | |||
| 355 | $self->{screens} = $self->{file_hash}->{'screens'}; | ||
| 356 | $self->{defined_table_names} = $self->{file_hash}->{'tables'}; | ||
| 357 | |||
| 358 | my $fl = $self->{global_field_list} = $field_list; | ||
| 359 | $self->{attribute_table_names} = $fl->get_attribute_table_names; | ||
| 360 | $fl->init_displayonly_table_names; | ||
| 361 | |||
| 362 | my $primary_table_name = $self->get_primary_table_name; | ||
| 363 | |||
| 364 | $self->init_rowlists; | ||
| 365 | |||
| 366 | my @taborder = $field_list->get_field_tags($primary_table_name); | ||
| 367 | $self->{taborder} = \@taborder; | ||
| 368 | |||
| 369 | return $self->{file_hash}; | ||
| 370 | } | ||
| 371 | |||
| 372 | sub parse_yml_file { | ||
| 373 | my $self = shift; | ||
| 374 | my $filename = shift; | ||
| 375 | |||
| 376 | if ( !( $filename =~ /\.yml$/ ) ) { | ||
| 377 | $filename .= '.yml'; | ||
| 378 | |||
| 379 | # die "Unknown file name extension on '$filename'"; | ||
| 380 | } | ||
| 381 | require "DBIx/Perform/DigestPer.pm"; | ||
| 382 | |||
| 383 | my $retval = DBIx::Perform::DigestPer::digest_yml_file($filename); | ||
| 384 | my @array = @{$retval}; | ||
| 385 | |||
| 386 | my $digest = $array[0]->[0]; | ||
| 387 | my $field_list = $array[0]->[1]; | ||
| 388 | |||
| 389 | die "File did not digest to a DBIx::Perform Spec" | ||
| 390 | unless $digest =~ /\$form\s*=/; | ||
| 391 | |||
| 392 | $self->{file_hash} = $self->load_internal( sub { eval $digest } ); | ||
| 393 | |||
| 394 | $self->{screens} = $self->{file_hash}->{'screens'}; | ||
| 395 | $self->{defined_table_names} = $self->{file_hash}->{'tables'}; | ||
| 396 | |||
| 397 | my $fl = $self->{global_field_list} = $field_list; | ||
| 398 | $self->{attribute_table_names} = $fl->get_attribute_table_names; | ||
| 399 | $fl->init_displayonly_table_names; | ||
| 400 | |||
| 401 | my $primary_table_name = $self->get_primary_table_name; | ||
| 402 | |||
| 403 | $self->init_rowlists; | ||
| 404 | |||
| 405 | my @taborder = $field_list->get_field_tags($primary_table_name); | ||
| 406 | $self->{taborder} = \@taborder; | ||
| 407 | |||
| 408 | return $self->{file_hash}; | ||
| 409 | } | ||
| 410 | |||
| 411 | sub load_internal { | ||
| 412 | my $self = shift; | ||
| 413 | my $sub = shift; | ||
| 414 | |||
| 415 | our $form; | ||
| 416 | local ($form); | ||
| 417 | &$sub(); | ||
| 418 | &$sub(); | ||
| 419 | |||
| 420 | return $form; | ||
| 421 | } | ||
| 422 | |||
| 423 | sub run { | ||
| 424 | my $self = shift; | ||
| 425 | |||
| 426 | my $file_hash = $self->{file_hash}; | ||
| 427 | if ( !defined($file_hash) ) { | ||
| 428 | die "invalid \"form\" hash reference"; | ||
| 429 | } | ||
| 430 | my %appdef = %{ $self->{app_hash} }; | ||
| 431 | if ( defined( my $minsize = $file_hash->{'screen'}{'MINSIZE'} ) ) { | ||
| 432 | @appdef{ 'MINX', 'MINY' } = @$minsize; | ||
| 433 | } | ||
| 434 | $appdef{'instrs'} = $file_hash->{'instrs'}; | ||
| 435 | my $instrs = $appdef{'instrs'}; | ||
| 436 | |||
| 437 | # capture master and detail table names from instructions | ||
| 438 | my $masters = $instrs && $$instrs{'MASTERS'}; | ||
| 439 | $self->capture_master_detail($masters); | ||
| 440 | |||
| 441 | # capture composite join information from instructions | ||
| 442 | # my $composites = $instrs && $$instrs{'COMPOSITES'}; | ||
| 443 | |||
| 444 | $appdef{'BACKGROUND'} = $ENV{'BGCOLOR'} | ||
| 445 | if $ENV{'BGCOLOR'}; | ||
| 446 | $appdef{'FOREGROUND'} = $ENV{'FGCOLOR'} | ||
| 447 | if $ENV{'FGCOLOR'}; | ||
| 448 | |||
| 449 | $self->{app_object} = new Curses::Application( \%appdef ) | ||
| 450 | or die "Unable to create application object"; | ||
| 451 | my $app = $self->{app_object}; | ||
| 452 | |||
| 453 | # sorry... see button_push | ||
| 454 | $Global_app_ref = $app; | ||
| 455 | |||
| 456 | my $field_list = $self->get_field_list; | ||
| 457 | |||
| 458 | my $database = $DBIx::Perform::DB; | ||
| 459 | $field_list->set_db_type_values( $database, $self ); | ||
| 460 | |||
| 461 | my $mwh = $app->mwh(); # main window handle. | ||
| 462 | my ( $maxy, $maxx ) = $app->maxyx(); | ||
| 463 | |||
| 464 | #warn "max screen size = $maxx, $maxy\n"; | ||
| 465 | Curses::leaveok( curscr, 1 ); | ||
| 466 | Curses::raw(); | ||
| 467 | my $i = 0; | ||
| 468 | |||
| 469 | # parse per file data into an array of form hashes - multiple forms occur | ||
| 470 | my $array_of_forms = | ||
| 471 | $self->capture_file_data( $file_hash, $maxy - 2, $maxx, \%appdef ); | ||
| 472 | |||
| 473 | my @formnames; | ||
| 474 | foreach my $sfd ( @{$array_of_forms} ) { | ||
| 475 | warn Data::Dumper->Dump( [$sfd], ['sfd'] ) if $::TRACE_DATA; | ||
| 476 | my %runformdef = %{ $self->{form_hash} }; | ||
| 477 | my $defname = "RunDef$i"; | ||
| 478 | my $formname = "Run$i"; | ||
| 479 | |||
| 480 | @runformdef{qw(X Y LINES COLUMNS DERIVED SUBFORMS )} = | ||
| 481 | ( 0, 0, $maxy, $maxx, 1, { 'DBForm' => $sfd } ); | ||
| 482 | push( @formnames, $formname ); | ||
| 483 | $app->addFormDef( $defname, {%runformdef} ); | ||
| 484 | $app->createForm( $formname, $defname ); | ||
| 485 | $i++; | ||
| 486 | } | ||
| 487 | $self->{number_of_forms} = $i; | ||
| 488 | |||
| 489 | $app->setField( MAINFORM => { Run0 => 'RunDef0' } ); | ||
| 490 | $app->setField( form_names => [@formnames] ); | ||
| 491 | $app->setField( form_name_indexes => | ||
| 492 | +{ map { ( $formnames[$_], $_ ) } 0 .. $#formnames } ); | ||
| 493 | $app->draw(); | ||
| 494 | $app->{'number'} = 0; | ||
| 495 | $self->update_table(0); | ||
| 496 | |||
| 497 | $self->add_field_list_to_screens; | ||
| 498 | |||
| 499 | $self->compute_joins_by_tag; | ||
| 500 | |||
| 501 | #optimization idea | ||
| 502 | # $i--; | ||
| 503 | # for (; $i >= 0; $i--) { | ||
| 504 | # my $form = $app->getForm("Run$i"); | ||
| 505 | # my $subform = $form->getSubform('DBForm'); | ||
| 506 | # $self->{subforms}->[$i] = $subform; | ||
| 507 | # } | ||
| 508 | |||
| 509 | # runtime loop | ||
| 510 | |||
| 511 | while ( !$app->getField('EXIT') ) { # run until user exits. | ||
| 512 | my $fname = $app->getField('form_name'); | ||
| 513 | my $form = $self->{form_object} = $app->getForm($fname); | ||
| 514 | $self->set_field_bounds_on_screen; | ||
| 515 | warn "run loop, form :$fname:\n" if $::TRACE; | ||
| 516 | die "unable to create form" unless defined($form); | ||
| 517 | |||
| 518 | my $resumecmd = $app->getField('resume_command'); | ||
| 519 | if ($resumecmd) { | ||
| 520 | &$resumecmd($form); | ||
| 521 | $app->setField( 'resume_command', undef ); | ||
| 522 | } | ||
| 523 | |||
| 524 | $app->execForm($fname); | ||
| 525 | } | ||
| 526 | } | ||
| 527 | |||
| 528 | # returns an array ref of forms; in a form with master/detail defined, | ||
| 529 | # the master form is assumed to be first. | ||
| 530 | sub capture_file_data # previously cursese_formdefs | ||
| 531 | { | ||
| 532 | my $self = shift; | ||
| 533 | my $formspec = shift; # input file contents | ||
| 534 | my $maxy = shift; | ||
| 535 | my $maxx = shift; | ||
| 536 | my $appdef = shift; | ||
| 537 | |||
| 538 | my $attrs = $formspec->{'attrs'}; | ||
| 539 | |||
| 540 | my $lineoffset = 0; # used for combining screens | ||
| 541 | my @formdefs = (); | ||
| 542 | my $appbg = $$appdef{'BACKGROUND'}; | ||
| 543 | my $deffldbg = $ENV{'FIELDBGCOLOR'} || 'black'; | ||
| 544 | |||
| 545 | my $fl = | ||
| 546 | $self->get_field_list; # full list of field objects from the per file | ||
| 547 | #my $primary_table_name = $self->get_primary_table_name; | ||
| 548 | |||
| 549 | foreach my $screen ( @{ $self->{screens} } ) { | ||
| 550 | my $widgets = $$screen{'WIDGETS'}; | ||
| 551 | my $fields = $$screen{'FIELDS'}; | ||
| 552 | |||
| 553 | # lists of field_objects for each screen | ||
| 554 | # may need to be ordered by taborder | ||
| 555 | my $screen_list = $fl->create_subset($fields); | ||
| 556 | my @taborder = $self->{taborder}; | ||
| 557 | |||
| 558 | my %def = ( | ||
| 559 | X => 0, | ||
| 560 | Y => 2, | ||
| 561 | COLUMNS => $maxx, | ||
| 562 | LINES => $maxy - 2, | ||
| 563 | DERIVED => 1, | ||
| 564 | ALTFBASE => 'DBIx::Perform::Forms', | ||
| 565 | ALTBASE => 'DBIx::Perform::Widgets', | ||
| 566 | TABORDER => \@taborder, # TBD | ||
| 567 | md_mode => 'm', # master/detail mode. | ||
| 568 | editmode => '', | ||
| 569 | ); | ||
| 570 | |||
| 571 | $screen_list->reset; | ||
| 572 | while ( my $f = $screen_list->iterate_list ) { | ||
| 573 | my ( $tag, $table, $col ) = $f->get_names; | ||
| 574 | my $w = $widgets->{$tag}; | ||
| 575 | my $comments = $f->{comments}; | ||
| 576 | |||
| 577 | # This "trampoline" function gives field name to the real OnExit fcn. | ||
| 578 | $w->{'OnExit'} = sub { &DBIx::Perform::OnFieldExit( $tag, @_ ); }; | ||
| 579 | $w->{'OnEnter'} = sub { | ||
| 580 | &DBIx::Perform::OnFieldEnter( | ||
| 581 | $comments | ||
| 582 | ? sub { $self->display_comment($comments); } | ||
| 583 | : $self->display_comment(''), | ||
| 584 | $tag, @_ | ||
| 585 | ); | ||
| 586 | }; | ||
| 587 | |||
| 588 | # keys | ||
| 589 | $w->{'FOCUSSWITCH'} = "\t\n\cp\cw\cc\ck\c[\cf\cb"; | ||
| 590 | $w->{'FOCUSSWITCH_MACROKEYS'} = [ KEY_UP, KEY_DOWN, KEY_DEL ]; | ||
| 591 | |||
| 592 | my $color = $f->{color} || $deffldbg; | ||
| 593 | $w->{'BACKGROUND'} = $color; | ||
| 594 | |||
| 595 | # setup the open/close brackets for the field | ||
| 596 | $$widgets{"$tag.openbracket"} = +{ | ||
| 597 | TYPE => 'Label', | ||
| 598 | COLUMNS => 1, | ||
| 599 | ROWS => 1, | ||
| 600 | Y => $w->{'Y'}, | ||
| 601 | X => $w->{'X'} - 1, | ||
| 602 | VALUE => "[", | ||
| 603 | }; | ||
| 604 | |||
| 605 | $$widgets{"$tag.closebracket"} = +{ | ||
| 606 | TYPE => 'Label', | ||
| 607 | COLUMNS => 1, | ||
| 608 | ROWS => 1, | ||
| 609 | Y => $w->{'Y'}, | ||
| 610 | X => $w->{'X'} + $w->{'COLUMNS'}, | ||
| 611 | VALUE => "]", | ||
| 612 | }; | ||
| 613 | } | ||
| 614 | |||
| 615 | $def{'WIDGETS'} = {%$widgets}, push( @formdefs, {%def} ); | ||
| 616 | } | ||
| 617 | return \@formdefs; | ||
| 618 | } | ||
| 619 | |||
| 620 | # display_help_screen _should_ use STDOUT, not STDERR, but STDOUT didn't | ||
| 621 | # work well. | ||
| 622 | sub display_help_screen { | ||
| 623 | my $self = shift; | ||
| 624 | my $textkey = shift; | ||
| 625 | my $text = $Help_screens[$textkey]; | ||
| 626 | my $app = $self->{app_object}; | ||
| 627 | my ( $maxy, $maxx ) = $app->maxyx(); | ||
| 628 | my $y = $maxy - 2; | ||
| 629 | my $key; | ||
| 630 | |||
| 631 | Curses::endwin; | ||
| 632 | Curses::raw; | ||
| 633 | print STDERR "\n" x ($maxy+$maxy); | ||
| 634 | $text .= "\n" x $y; | ||
| 635 | do { | ||
| 636 | print STDERR "\r\n\n"; | ||
| 637 | $text =~ s/(([^\n]*\n){$y})//; | ||
| 638 | my $scr_of_text = $1; | ||
| 639 | if ($text =~ /[^\n]/) { | ||
| 640 | $scr_of_text .= | ||
| 641 | "\nPress SPACE for more or any other key to leave help"; | ||
| 642 | } | ||
| 643 | else { | ||
| 644 | $scr_of_text .= "Press a key to leave help"; | ||
| 645 | } | ||
| 646 | print STDERR "$scr_of_text"; | ||
| 647 | $key = getc(STDIN); | ||
| 648 | } while ( $text =~ /[^\n]/ && $key eq " " ); | ||
| 649 | |||
| 650 | #make Curses redraw the screen | ||
| 651 | Curses::refresh(curscr); | ||
| 652 | } | ||
| 653 | |||
| 654 | # clear the two status lines at the bottom | ||
| 655 | # of the screen: i.e. comment and error/status | ||
| 656 | sub clear_comment_and_error_display { | ||
| 657 | my $self = shift; | ||
| 658 | |||
| 659 | $self->clear_display_error; | ||
| 660 | $self->clear_display_comment; | ||
| 661 | |||
| 662 | return undef; | ||
| 663 | } | ||
| 664 | |||
| 665 | sub display_comment { | ||
| 666 | my $self = shift; | ||
| 667 | my $message = shift; | ||
| 668 | |||
| 669 | my $form = $self->{form_object}; | ||
| 670 | my $wid = $form->getWidget('Comment'); | ||
| 671 | my $mwh = $form->{MWH}; | ||
| 672 | |||
| 673 | $wid->setField( 'VALUE', $message ); | ||
| 674 | $wid->draw($mwh) if $mwh; | ||
| 675 | |||
| 676 | return undef; | ||
| 677 | } | ||
| 678 | |||
| 679 | sub clear_display_comment { | ||
| 680 | my $self = shift; | ||
| 681 | |||
| 682 | my $message = ""; | ||
| 683 | |||
| 684 | my $form = $self->{form_object}; | ||
| 685 | my $wid = $form->getWidget('Comment'); | ||
| 686 | my $mwh = $form->{MWH}; | ||
| 687 | |||
| 688 | $wid->setField( 'VALUE', $message ); | ||
| 689 | $wid->draw($mwh) if $mwh; | ||
| 690 | |||
| 691 | return undef; | ||
| 692 | } | ||
| 693 | |||
| 694 | sub display_status { | ||
| 695 | my $self = shift; | ||
| 696 | my $message = shift; | ||
| 697 | |||
| 698 | $message = $self->{error_messages}->{$message} | ||
| 699 | if defined $message && length($message) <= 5; | ||
| 700 | |||
| 701 | # don't draw if there is no message | ||
| 702 | return if !defined $message; | ||
| 703 | return if length($message) == 0; | ||
| 704 | |||
| 705 | # $message = ' ' . $message . ' '; | ||
| 706 | |||
| 707 | my $len = length($message); | ||
| 708 | $len = $MAXX if $len > $MAXX; | ||
| 709 | my $form = $self->{form_object}; | ||
| 710 | my $wid = $form->getWidget('Error'); | ||
| 711 | my $mwh = $form->{MWH}; | ||
| 712 | |||
| 713 | my $bg = lc $ENV{'BGCOLOR'} || 'black'; | ||
| 714 | my $fg = $bg =~ /black|blue/i ? 'white' : 'black'; | ||
| 715 | |||
| 716 | $wid->setField( 'VALUE', $message ); | ||
| 717 | $wid->setField( 'COLUMNS', $len ); | ||
| 718 | $wid->setField( 'FOREGROUND', $fg ); | ||
| 719 | $wid->setField( 'BACKGROUND', $bg ); | ||
| 720 | |||
| 721 | $wid->draw($mwh) if $mwh; | ||
| 722 | |||
| 723 | return undef; | ||
| 724 | } | ||
| 725 | |||
| 726 | sub clear_display_status { | ||
| 727 | my $self = shift; | ||
| 728 | |||
| 729 | my $message = ""; | ||
| 730 | my $bg = lc $ENV{'BGCOLOR'} || 'black'; | ||
| 731 | my $fg = $bg; | ||
| 732 | |||
| 733 | my $form = $self->{form_object}; | ||
| 734 | my $wid = $form->getWidget('Error'); | ||
| 735 | my $mwh = $form->{MWH}; | ||
| 736 | |||
| 737 | my $ov = $wid->getField('VALUE'); | ||
| 738 | |||
| 739 | # don't redraw if there is no message | ||
| 740 | return if length($ov) == 0; | ||
| 741 | |||
| 742 | $wid->setField( 'VALUE', $message ); | ||
| 743 | $wid->setField( 'COLUMNS', 0 ); | ||
| 744 | $wid->setField( 'FOREGROUND', $fg ); | ||
| 745 | $wid->setField( 'BACKGROUND', $bg ); | ||
| 746 | |||
| 747 | $wid->draw($mwh) if $mwh; | ||
| 748 | |||
| 749 | return undef; | ||
| 750 | } | ||
| 751 | |||
| 752 | sub display_error { | ||
| 753 | my $self = shift; | ||
| 754 | my $message = shift; | ||
| 755 | my $dontrev = shift; | ||
| 756 | |||
| 757 | warn "entering display_error\n" if $::TRACE; | ||
| 758 | |||
| 759 | $message = $self->{error_messages}->{$message} | ||
| 760 | if defined $message && length($message) <= 5; | ||
| 761 | |||
| 762 | # don't draw if there is no message | ||
| 763 | return if !defined $message; | ||
| 764 | return if length($message) == 0; | ||
| 765 | |||
| 766 | # $message = ' ' . $message . ' '; | ||
| 767 | |||
| 768 | my $len = length($message); | ||
| 769 | $len = $MAXX if $len > $MAXX; | ||
| 770 | my $form = $self->{form_object}; | ||
| 771 | my $wid = $form->getWidget('Error'); | ||
| 772 | my $mwh = $form->{MWH}; | ||
| 773 | |||
| 774 | $wid->setField( 'VALUE', $message ); | ||
| 775 | $wid->setField( 'COLUMNS', $len ); | ||
| 776 | my $env = lc $ENV{'BGCOLOR'} || 'black'; | ||
| 777 | my $bg = $env; | ||
| 778 | unless ($dontrev) { | ||
| 779 | $bg = $env =~ /black|blue/i ? 'white' : 'black'; | ||
| 780 | } | ||
| 781 | my $fg = $bg =~ /black|blue/i ? 'white' : 'black'; | ||
| 782 | |||
| 783 | $wid->setField( 'FOREGROUND', $fg ); | ||
| 784 | $wid->setField( 'BACKGROUND', $bg ); | ||
| 785 | |||
| 786 | $wid->draw($mwh) if $mwh; | ||
| 787 | |||
| 788 | warn "leaving display_error\n" if $::TRACE; | ||
| 789 | return undef; | ||
| 790 | } | ||
| 791 | |||
| 792 | sub clear_display_error { | ||
| 793 | warn "entering clear_display_error\n" if $::TRACE; | ||
| 794 | my $self = shift; | ||
| 795 | |||
| 796 | my $message = ""; | ||
| 797 | my $bg = lc $ENV{'BGCOLOR'} || 'black'; | ||
| 798 | my $fg = $bg; | ||
| 799 | |||
| 800 | my $form = $self->{form_object}; | ||
| 801 | my $wid = $form->getWidget('Error'); | ||
| 802 | my $mwh = $form->{MWH}; | ||
| 803 | |||
| 804 | my $ov = $wid->getField('VALUE'); | ||
| 805 | |||
| 806 | # don't redraw if there is no message | ||
| 807 | return if length($ov) == 0; | ||
| 808 | |||
| 809 | $wid->setField( 'VALUE', $message ); | ||
| 810 | $wid->setField( 'COLUMNS', 0 ); | ||
| 811 | $wid->setField( 'FOREGROUND', $fg ); | ||
| 812 | $wid->setField( 'BACKGROUND', $bg ); | ||
| 813 | |||
| 814 | $wid->draw($mwh) if $mwh; | ||
| 815 | |||
| 816 | return undef; | ||
| 817 | } | ||
| 818 | |||
| 819 | sub set_field { | ||
| 820 | my $self = shift; | ||
| 821 | my $name = shift; | ||
| 822 | my $value = shift; | ||
| 823 | my $app = $self->{app_object}; | ||
| 824 | |||
| 825 | return $app->setfield( $name, $value ); | ||
| 826 | } | ||
| 827 | |||
| 828 | sub change_field_focus_on_screen { | ||
| 829 | my $self = shift; | ||
| 830 | my $fo = shift; | ||
| 831 | my $index = shift; # can be empty | ||
| 832 | |||
| 833 | warn "entering change_field_focus_on_screen" if $::TRACE; | ||
| 834 | |||
| 835 | my ( $tag, $table, $col ) = $fo->get_names; | ||
| 836 | |||
| 837 | my $l = $self->get_field_list; | ||
| 838 | my $fl = $l->clone_list; | ||
| 839 | |||
| 840 | my $ct = $self->get_current_table_name; | ||
| 841 | my $form = $self->get_current_form; | ||
| 842 | |||
| 843 | my $subform = $form->getSubform('DBForm'); | ||
| 844 | my $mode = $subform->getField('editmode'); | ||
| 845 | |||
| 846 | my @taborder = $fl->get_field_tags($ct); | ||
| 847 | |||
| 848 | $index = 0 if !defined($index); | ||
| 849 | my $match = undef; | ||
| 850 | |||
| 851 | $fl->reset; | ||
| 852 | while ( my $fvar = $fl->iterate_list ) { | ||
| 853 | my $tg = $fvar->get_names; | ||
| 854 | if ( defined($match) ) { | ||
| 855 | if ( $fvar->allows_focus($mode) ) { | ||
| 856 | $subform->setField( 'FOCUSED', $taborder[$index] ); | ||
| 857 | $self->{focus} = $taborder[$index]; | ||
| 858 | return $index; | ||
| 859 | } | ||
| 860 | } | ||
| 861 | $match = 1 if $tg eq $tag; | ||
| 862 | return undef if $index++ > $#taborder; # or not | ||
| 863 | } | ||
| 864 | |||
| 865 | warn "leaving change_field_focus_on_screen" if $::TRACE; | ||
| 866 | return undef; # no match or focus | ||
| 867 | } | ||
| 868 | |||
| 869 | sub register_button_handler { | ||
| 870 | my $self = shift; | ||
| 871 | my $button = shift; | ||
| 872 | my $handler = shift; | ||
| 873 | |||
| 874 | my $bhandler = $self->{button_handlers}->{$button} = $handler; | ||
| 875 | } | ||
| 876 | |||
| 877 | sub update_text { | ||
| 878 | my $form = shift; | ||
| 879 | my $GlobalUi = $DBIx::Perform::GlobalUi; | ||
| 880 | my $wid = $form->getWidget('ModeButtons'); | ||
| 881 | my $val = $wid->getField('VALUE'); | ||
| 882 | my $names = $wid->getField('NAMES'); | ||
| 883 | # my $labels = $wid->getField('LABELS'); | ||
| 884 | my $thisname = lc( $$names[$val] ); | ||
| 885 | # my $thislabel = lc( $$labels[$val] ); | ||
| 886 | my $btn_handler = $Button_handlers{$thisname}; | ||
| 887 | |||
| 888 | $GlobalUi->display_comment(""); | ||
| 889 | $GlobalUi->clear_display_error; | ||
| 890 | my $m = $Info_messages{$thisname}; | ||
| 891 | my $wmm = $form->getWidget('InfoMsg'); | ||
| 892 | $wmm->setField( 'VALUE', $m ); | ||
| 893 | $wmm->setField( 'COLUMNS', length $m ); | ||
| 894 | return $btn_handler; | ||
| 895 | } | ||
| 896 | |||
| 897 | sub button_push { | ||
| 898 | my $form = shift; | ||
| 899 | my $key = shift; | ||
| 900 | |||
| 901 | my $GlobalUi = $DBIx::Perform::GlobalUi; | ||
| 902 | my $app = $Global_app_ref; # sorry | ||
| 903 | |||
| 904 | warn "TRACE: entering button_push\n" if $::TRACE; | ||
| 905 | if ( $key eq KEY_RIGHT || $key eq KEY_LEFT || $key eq ' ' | ||
| 906 | || $key eq KEY_UP || $key eq KEY_DOWN ) { | ||
| 907 | $form->setField( 'DONTSWITCH', 1 ); | ||
| 908 | update_text($form); | ||
| 909 | return; | ||
| 910 | } | ||
| 911 | elsif ( $key =~ /\d/ ) { | ||
| 912 | warn "TRACE: button_push, number key\n" if $::TRACE; | ||
| 913 | $app->{'number'} *= 10; | ||
| 914 | $app->{'number'} += $key; | ||
| 915 | $form->setField( 'DONTSWITCH', 1 ); | ||
| 916 | return; | ||
| 917 | } | ||
| 918 | elsif ( $key eq "\cw" ) { | ||
| 919 | $GlobalUi->display_help_screen(0); | ||
| 920 | $form->setField( 'DONTSWITCH', 1 ); | ||
| 921 | return; | ||
| 922 | } | ||
| 923 | my $btn_handler = update_text($form); | ||
| 924 | if ( $btn_handler && ref($btn_handler) eq 'CODE' ) { | ||
| 925 | &$btn_handler( lc($key), $form ); | ||
| 926 | $app->{'number'} = 0; | ||
| 927 | } | ||
| 928 | warn "TRACE: leaving button_push\n" if $::TRACE; | ||
| 929 | } | ||
| 930 | |||
| 931 | # replace the buttons with a mode label | ||
| 932 | sub change_buttons_to_label { | ||
| 933 | my $self = shift; | ||
| 934 | my $str = shift; | ||
| 935 | |||
| 936 | warn "entering change_buttons_to_label\n" if $::TRACE; | ||
| 937 | |||
| 938 | my $form = $self->{form_object}; | ||
| 939 | my $wid = $form->getWidget('ModeButtons'); | ||
| 940 | |||
| 941 | $wid->setField( 'COLUMNS', 0 ); | ||
| 942 | |||
| 943 | $wid = $form->getWidget('ModeLabel'); | ||
| 944 | $str = substr($str, 0, 70); | ||
| 945 | $wid->setField( 'VALUE', $str ); | ||
| 946 | $wid->setField( 'COLUMNS', length $str ); | ||
| 947 | |||
| 948 | warn "leaving change_buttons_to_label\n" if $::TRACE; | ||
| 949 | return undef; | ||
| 950 | } | ||
| 951 | |||
| 952 | # replace a mode label with mode buttons | ||
| 953 | sub change_label_to_buttons { | ||
| 954 | my $self = shift; | ||
| 955 | |||
| 956 | warn "entering change_label_to_buttons\n" if $::TRACE; | ||
| 957 | |||
| 958 | my $form = $self->{form_object}; | ||
| 959 | my $wid = $form->getWidget('ModeLabel'); | ||
| 960 | |||
| 961 | $wid->setField( 'VALUE', '' ); | ||
| 962 | $wid->setField( 'COLUMNS', 0 ); | ||
| 963 | |||
| 964 | $self->change_modename($msgs->[2]); #msgs->[2]='perform' if LANG=en | ||
| 965 | warn "leaving change_label_to_buttons\n" if $::TRACE; | ||
| 966 | return undef; | ||
| 967 | } | ||
| 968 | |||
| 969 | sub switch_buttons { | ||
| 970 | my $self = shift; | ||
| 971 | my $form = shift; | ||
| 972 | |||
| 973 | warn "entering switch_buttons\n" if $::TRACE; | ||
| 974 | |||
| 975 | my $wid = $form->getWidget('ModeButtons'); | ||
| 976 | |||
| 977 | $wid->setField( 'NAMES', \@Button_yn_names ); | ||
| 978 | $wid->setField( 'LABELS', \@Buttons_yn ); | ||
| 979 | $self->change_modename( $msgs->[9] ); # 9 = 'remove' | ||
| 980 | |||
| 981 | $wid = $form->getWidget('InfoMsg'); | ||
| 982 | $wid->setField( 'VALUE', $msgs->[37] ); | ||
| 983 | warn "leaving switch_buttons\n" if $::TRACE; | ||
| 984 | } | ||
| 985 | |||
| 986 | sub change_modename { | ||
| 987 | my $self = shift; | ||
| 988 | my $name = shift; | ||
| 989 | |||
| 990 | warn "entering change_modename\n" if $::TRACE; | ||
| 991 | |||
| 992 | my $form = $self->{form_object}; | ||
| 993 | |||
| 994 | $name = $name . ': '; | ||
| 995 | $name = uc($name); | ||
| 996 | |||
| 997 | my $wid = $form->getWidget('ModeName'); | ||
| 998 | $wid->setField( 'VALUE', $name ); | ||
| 999 | $wid = $form->getWidget('ModeLabel'); | ||
| 1000 | $wid->setField( 'X', length $name ); | ||
| 1001 | |||
| 1002 | warn "leaving change_modename\n" if $::TRACE; | ||
| 1003 | return undef; | ||
| 1004 | } | ||
| 1005 | |||
| 1006 | sub update_info_message { | ||
| 1007 | return; | ||
| 1008 | my $self = shift; | ||
| 1009 | my $form = shift; | ||
| 1010 | my $message = shift; | ||
| 1011 | |||
| 1012 | warn "entering update_info_message\n" if $::TRACE; | ||
| 1013 | |||
| 1014 | my %info_msgs = %{ $self->{info_messages} }; | ||
| 1015 | my $msg = $info_msgs{$message}; | ||
| 1016 | my $wid = $form->getWidget('InfoMsg'); | ||
| 1017 | |||
| 1018 | $wid->setField( 'VALUE', $msg ); | ||
| 1019 | |||
| 1020 | warn "leaving update_info_message\n" if $::TRACE; | ||
| 1021 | return undef; | ||
| 1022 | } | ||
| 1023 | |||
| 1024 | sub update_subform { | ||
| 1025 | my $self = shift; | ||
| 1026 | my $subform = shift; | ||
| 1027 | |||
| 1028 | my $mwh = $subform->{MWH}; | ||
| 1029 | $subform->draw($mwh); | ||
| 1030 | |||
| 1031 | return undef; | ||
| 1032 | } | ||
| 1033 | |||
| 1034 | # setup bracket values for a tag widget | ||
| 1035 | sub set_field_display_bounds { | ||
| 1036 | my $self = shift; | ||
| 1037 | my $tag = shift; | ||
| 1038 | my $lchar = shift; | ||
| 1039 | my $rchar = shift; | ||
| 1040 | |||
| 1041 | #warn "TRACE: entering set_field_display_bounds for $lchar $tag $rchar\n" | ||
| 1042 | # if $::TRACE; | ||
| 1043 | |||
| 1044 | my $form = $self->get_current_form; | ||
| 1045 | my $subform = $form->getSubform('DBForm'); | ||
| 1046 | |||
| 1047 | my $ostr = $tag . ".openbracket"; | ||
| 1048 | my $cstr = $tag . ".closebracket"; | ||
| 1049 | |||
| 1050 | my $ow = $subform->getWidget($ostr); | ||
| 1051 | my $cw = $subform->getWidget($cstr); | ||
| 1052 | |||
| 1053 | return if !defined($ow) || !defined($cw); | ||
| 1054 | |||
| 1055 | $ow->setField( 'VALUE', $lchar ); | ||
| 1056 | $cw->setField( 'VALUE', $rchar ); | ||
| 1057 | |||
| 1058 | # warn "TRACE: leaving set_field_display_bounds\n" if $::TRACE; | ||
| 1059 | return undef; | ||
| 1060 | } | ||
| 1061 | |||
| 1062 | sub set_field_bounds_on_screen { | ||
| 1063 | my $self = shift; | ||
| 1064 | |||
| 1065 | warn "TRACE: entering set_field_bounds_on_screen\n" if $::TRACE; | ||
| 1066 | |||
| 1067 | my $current_table = $self->get_current_table_name; | ||
| 1068 | |||
| 1069 | my $app = $self->{app_object}; | ||
| 1070 | my $form = $self->get_current_form; | ||
| 1071 | my $subform = $form->getSubform('DBForm'); | ||
| 1072 | my $mode = $subform->getField('editmode'); | ||
| 1073 | |||
| 1074 | my $pl = $self->get_field_list; | ||
| 1075 | my $fl = $pl->clone_list; | ||
| 1076 | |||
| 1077 | $fl->reset; | ||
| 1078 | while ( my $f = $fl->iterate_list ) { | ||
| 1079 | my ( $tag, $table, $column ) = $f->get_names; | ||
| 1080 | $self->set_field_display_bounds( $tag, ' ', ' ' ); | ||
| 1081 | } | ||
| 1082 | |||
| 1083 | $fl->reset; | ||
| 1084 | while ( my $f = $fl->iterate_list ) { | ||
| 1085 | my ( $tag, $table, $column ) = $f->get_names; | ||
| 1086 | if ( $table eq $current_table ) { | ||
| 1087 | $self->set_field_display_bounds( $tag, '[', ']' ) | ||
| 1088 | if $f->allows_focus($mode); | ||
| 1089 | } | ||
| 1090 | } | ||
| 1091 | warn "TRACE: leaving set_field_bounds_on_screen\n" if $::TRACE; | ||
| 1092 | return undef; | ||
| 1093 | } | ||
| 1094 | |||
| 1095 | # rowlist support | ||
| 1096 | |||
| 1097 | sub init_rowlists { | ||
| 1098 | my $self = shift; | ||
| 1099 | |||
| 1100 | warn "entering init_rowlists\n" if $::TRACE; | ||
| 1101 | |||
| 1102 | my %tables = (); | ||
| 1103 | |||
| 1104 | # $self->{rowlists} = new DBIx::Perform::SimpleList; | ||
| 1105 | |||
| 1106 | # one rowlist per table | ||
| 1107 | my @tnames = @{ $self->{attribute_table_names} }; | ||
| 1108 | for (my $i = 0; $i < @tnames; $i++) { | ||
| 1109 | my $t = $tnames[$i]; | ||
| 1110 | my $r = new DBIx::Perform::SimpleList; | ||
| 1111 | # $self->{rowlists}->add_row($r); | ||
| 1112 | $tables{$t} = [$r, $i]; | ||
| 1113 | } | ||
| 1114 | # $self->{current_rowlist} = $self->{rowlists}->current_row; | ||
| 1115 | |||
| 1116 | $self->{rowlists} = \%tables; | ||
| 1117 | $self->{current_table_number} = 0; | ||
| 1118 | $self->{current_rowlist} = $self->{rowlists}->{$tnames[0]}[0]; | ||
| 1119 | |||
| 1120 | warn "leaving init_rowlists\n" if $::TRACE; | ||
| 1121 | return undef; | ||
| 1122 | } | ||
| 1123 | |||
| 1124 | sub get_current_rowlist { | ||
| 1125 | my $self = shift; | ||
| 1126 | |||
| 1127 | my $tbl = $self->get_current_table_name; | ||
| 1128 | return $self->{rowlists}->{$tbl}[0]; | ||
| 1129 | } | ||
| 1130 | |||
| 1131 | sub increment_global_rowlist { | ||
| 1132 | my $self = shift; | ||
| 1133 | |||
| 1134 | my @tnames = @{ $self->{attribute_table_names} }; | ||
| 1135 | my $n = $self->{current_table_number}; | ||
| 1136 | $n++; | ||
| 1137 | $n = 0 if ($n >= @tnames); | ||
| 1138 | |||
| 1139 | $self->{current_rowlist} = $self->{rowlists}->{$tnames[$n]}[0]; | ||
| 1140 | } | ||
| 1141 | |||
| 1142 | # field list wrapper | ||
| 1143 | |||
| 1144 | # we may want to isolate access someday | ||
| 1145 | |||
| 1146 | sub get_field_list { | ||
| 1147 | my $self = shift; | ||
| 1148 | |||
| 1149 | return $self->{global_field_list}; | ||
| 1150 | } | ||
| 1151 | |||
| 1152 | # master and detail tables are associated with the runtime | ||
| 1153 | # active table | ||
| 1154 | |||
| 1155 | sub capture_master_detail { | ||
| 1156 | my $self = shift; | ||
| 1157 | my $masters = shift; | ||
| 1158 | |||
| 1159 | return if !defined($masters); # undef is okay | ||
| 1160 | |||
| 1161 | foreach my $ma ($masters) { | ||
| 1162 | foreach my $ta (@$ma) { | ||
| 1163 | my $m = $ta->[0]; | ||
| 1164 | my $d = $ta->[1]; | ||
| 1165 | my %h; | ||
| 1166 | $h{$m} = $d; | ||
| 1167 | $self->{master_detail_list}->add_row_to_end( \%h ); | ||
| 1168 | } | ||
| 1169 | } | ||
| 1170 | } | ||
| 1171 | |||
| 1172 | sub get_master_detail_table_names { | ||
| 1173 | my $self = shift; | ||
| 1174 | my $table = shift; | ||
| 1175 | |||
| 1176 | my $tl = $self->{master_detail_list}; | ||
| 1177 | my ( @masters, @details ); | ||
| 1178 | |||
| 1179 | $tl->reset; | ||
| 1180 | while ( my $hr = $tl->iterate_list ) { | ||
| 1181 | |||
| 1182 | my %h = %$hr; | ||
| 1183 | my @a = keys(%h); | ||
| 1184 | my $master = $a[0]; | ||
| 1185 | my $detail = $h{$master}; | ||
| 1186 | |||
| 1187 | # there may be multiple matches in $tl | ||
| 1188 | if ( $master eq $table || $detail eq $table ) { | ||
| 1189 | push @masters, $master; | ||
| 1190 | push @details, $detail; | ||
| 1191 | } | ||
| 1192 | } | ||
| 1193 | return ( \@masters, \@details ); | ||
| 1194 | } | ||
| 1195 | |||
| 1196 | # only call this if table exists | ||
| 1197 | # beef this up if better is required. | ||
| 1198 | sub go_to_table { | ||
| 1199 | my $self = shift; | ||
| 1200 | my $table = shift; | ||
| 1201 | |||
| 1202 | $self->{current_rowlist} = $self->{rowlists}->{$table}[0]; | ||
| 1203 | $self->{current_table_number} = $self->{rowlists}->{$table}[1]; | ||
| 1204 | $self->update_table($self->{current_table_number}); | ||
| 1205 | return $table; | ||
| 1206 | |||
| 1207 | my @tables = @{ $self->{attribute_table_names} }; | ||
| 1208 | my $tab0 = $tables[0]; | ||
| 1209 | my $ct = $self->get_current_table_name; | ||
| 1210 | |||
| 1211 | # sync global data to start of @tables | ||
| 1212 | foreach my $tab (@tables) { | ||
| 1213 | last if $ct eq $tab0; | ||
| 1214 | $self->increment_global_tablelist; | ||
| 1215 | $self->increment_global_rowlist; | ||
| 1216 | $ct = $self->get_current_table_name; | ||
| 1217 | } | ||
| 1218 | foreach my $tab (@tables) { | ||
| 1219 | return $tab | ||
| 1220 | if $tab eq $table; # return on a match | ||
| 1221 | # otherwise increment the global ds | ||
| 1222 | $self->increment_global_tablelist; | ||
| 1223 | $self->increment_global_rowlist; | ||
| 1224 | } | ||
| 1225 | return undef; | ||
| 1226 | } | ||
| 1227 | |||
| 1228 | # tables are ordered by their appearance in the attribute section | ||
| 1229 | # in the ".per" file | ||
| 1230 | |||
| 1231 | sub get_number_of_tables { | ||
| 1232 | my $self = shift; | ||
| 1233 | my $form = shift; | ||
| 1234 | |||
| 1235 | my @tables = @{ $self->{attribute_table_names} }; | ||
| 1236 | return $#tables; | ||
| 1237 | } | ||
| 1238 | |||
| 1239 | sub get_primary_table_name { | ||
| 1240 | my $self = shift; | ||
| 1241 | my $form = shift; | ||
| 1242 | |||
| 1243 | my @tnames = @{ $self->{attribute_table_names} }; | ||
| 1244 | |||
| 1245 | return $tnames[0]; | ||
| 1246 | } | ||
| 1247 | |||
| 1248 | sub get_current_table_name { | ||
| 1249 | my $self = shift; | ||
| 1250 | my $form = shift; | ||
| 1251 | |||
| 1252 | my @tnames = @{ $self->{attribute_table_names} }; | ||
| 1253 | my $tnum = $self->{current_table_number}; | ||
| 1254 | |||
| 1255 | return $tnames[$tnum]; | ||
| 1256 | } | ||
| 1257 | |||
| 1258 | sub get_table_number { | ||
| 1259 | my $self = shift; | ||
| 1260 | my $form = shift; | ||
| 1261 | |||
| 1262 | return $self->{current_table_number}; | ||
| 1263 | } | ||
| 1264 | |||
| 1265 | sub increment_global_tablelist { | ||
| 1266 | my $self = shift; | ||
| 1267 | |||
| 1268 | my $form = $self->get_current_form; | ||
| 1269 | |||
| 1270 | my $num = $self->get_table_number; | ||
| 1271 | my $max = $self->get_number_of_tables; | ||
| 1272 | |||
| 1273 | ++$num; | ||
| 1274 | $num = 0 if $num > $max; | ||
| 1275 | |||
| 1276 | # updates class and display | ||
| 1277 | $self->update_table($num); | ||
| 1278 | } | ||
| 1279 | |||
| 1280 | sub update_table { | ||
| 1281 | my $self = shift; | ||
| 1282 | my $num = shift; | ||
| 1283 | |||
| 1284 | $self->update_table_number($num); | ||
| 1285 | $self->update_table_name($num); | ||
| 1286 | } | ||
| 1287 | |||
| 1288 | # these two subs update the form | ||
| 1289 | |||
| 1290 | sub update_table_number { | ||
| 1291 | my $self = shift; | ||
| 1292 | my $table_number = shift; | ||
| 1293 | |||
| 1294 | my $form = $self->get_current_form; | ||
| 1295 | |||
| 1296 | $self->{current_table_number} = $table_number; | ||
| 1297 | |||
| 1298 | $table_number++; | ||
| 1299 | my $str = '** ' . $table_number . ': '; | ||
| 1300 | |||
| 1301 | my $wid = $form->getWidget('TableNumber'); | ||
| 1302 | $wid->setField( 'VALUE', $str ); | ||
| 1303 | } | ||
| 1304 | |||
| 1305 | sub update_table_name { | ||
| 1306 | my $self = shift; | ||
| 1307 | my $table_number = shift; | ||
| 1308 | |||
| 1309 | my $form = $self->get_current_form; | ||
| 1310 | my @tnames = @{ $self->{attribute_table_names} }; | ||
| 1311 | my $name = $tnames[$table_number]; | ||
| 1312 | |||
| 1313 | $name = $name . ' table**'; | ||
| 1314 | |||
| 1315 | $self->{current_table_name} = $name; | ||
| 1316 | |||
| 1317 | # I don't know??? | ||
| 1318 | #$self->set_field_bounds_on_screen; | ||
| 1319 | |||
| 1320 | my $wid = $form->getWidget('TableName'); | ||
| 1321 | $wid->setField( 'VALUE', $name ); | ||
| 1322 | } | ||
| 1323 | |||
| 1324 | sub get_current_form { | ||
| 1325 | my $self = shift; | ||
| 1326 | |||
| 1327 | my $app = $self->{app_object}; | ||
| 1328 | my $fn = $app->getField('form_name'); | ||
| 1329 | |||
| 1330 | return $app->getForm($fn); | ||
| 1331 | } | ||
| 1332 | |||
| 1333 | # screen support | ||
| 1334 | |||
| 1335 | # This assumes that any duplicate field tags | ||
| 1336 | # are defined to always have the same value | ||
| 1337 | # returns the value of the first instance of | ||
| 1338 | # the field_tag parameter found in the global field_list. | ||
| 1339 | |||
| 1340 | sub get_screen_value { | ||
| 1341 | my $self = shift; | ||
| 1342 | my $field_tag = shift; | ||
| 1343 | |||
| 1344 | my $app = $self->{app_object}; | ||
| 1345 | my $formn = $app->getField('form_names'); | ||
| 1346 | |||
| 1347 | my $i = 0; | ||
| 1348 | for (my $i = 0; $i < @$formn; $i++) { | ||
| 1349 | my $form = $app->getForm( 'Run' . $i ); | ||
| 1350 | last if !defined($form); | ||
| 1351 | |||
| 1352 | my $subform = $form->getSubform('DBForm'); | ||
| 1353 | # my $subform = $self->{subforms}->[$i]; | ||
| 1354 | # last if !defined $subform; | ||
| 1355 | my $w = $subform->getWidget($field_tag); | ||
| 1356 | |||
| 1357 | return $w->getField('VALUE') | ||
| 1358 | if defined($w); | ||
| 1359 | } | ||
| 1360 | return undef; | ||
| 1361 | } | ||
| 1362 | |||
| 1363 | sub get_screen_subform_widget { | ||
| 1364 | my $self = shift; | ||
| 1365 | my $field_tag = shift; | ||
| 1366 | |||
| 1367 | # warn "entering get_screen_subform_widget\n" if $::TRACE; | ||
| 1368 | |||
| 1369 | my $app = $self->{app_object}; | ||
| 1370 | my $formn = $app->getField('form_names'); | ||
| 1371 | my @w; | ||
| 1372 | my $subform; | ||
| 1373 | |||
| 1374 | for (my $i = 0; $i < @$formn; $i++) { | ||
| 1375 | my $form = $app->getForm( 'Run' . $i ); | ||
| 1376 | $subform = $form->getSubform('DBForm'); | ||
| 1377 | my $wid = $subform->getWidget($field_tag); | ||
| 1378 | push @w, $wid if defined $wid; | ||
| 1379 | } | ||
| 1380 | |||
| 1381 | # warn "leaving get_screen_subform_widget 2\n" if $::TRACE; | ||
| 1382 | return @w if @w; | ||
| 1383 | return undef; | ||
| 1384 | } | ||
| 1385 | |||
| 1386 | =pod | ||
| 1387 | # This assumes that any duplicate field tags | ||
| 1388 | # are defined to always have the same value | ||
| 1389 | # returns the assigned value of the first instance of | ||
| 1390 | # the fiedl_tag parameter found in the global field_list. | ||
| 1391 | |||
| 1392 | sub old_set_screen_value { | ||
| 1393 | my $self = shift; | ||
| 1394 | my $field_tag = shift; | ||
| 1395 | my $val = shift; | ||
| 1396 | |||
| 1397 | warn "entering set_screen_value\n" if $::TRACE; | ||
| 1398 | |||
| 1399 | my $app = $self->{app_object}; | ||
| 1400 | my $fl = $self->{global_field_list}->clone_list; | ||
| 1401 | |||
| 1402 | $fl->reset; | ||
| 1403 | while ( my $f = $fl->iterate_list ) { | ||
| 1404 | |||
| 1405 | my $nof = $self->{number_of_forms}; | ||
| 1406 | my $i = 0; | ||
| 1407 | while ( $i < $nof ) { | ||
| 1408 | |||
| 1409 | my $form = $app->getForm( "Run" . $i ); | ||
| 1410 | |||
| 1411 | my $subform = $form->getSubform('DBForm'); | ||
| 1412 | my $w = $subform->getWidget($field_tag); | ||
| 1413 | |||
| 1414 | if ( defined($w) ) { | ||
| 1415 | $w->setField( 'VALUE', $val ); | ||
| 1416 | warn "leaving set_screen_value 1\n" if $::TRACE; | ||
| 1417 | return; | ||
| 1418 | } | ||
| 1419 | $i++; | ||
| 1420 | } | ||
| 1421 | } | ||
| 1422 | warn "leaving set_screen_value 2\n" if $::TRACE; | ||
| 1423 | return undef; | ||
| 1424 | } | ||
| 1425 | =cut | ||
| 1426 | |||
| 1427 | sub set_screen_value { | ||
| 1428 | my $self = shift; | ||
| 1429 | my $field_tag = shift; | ||
| 1430 | my $val = shift; | ||
| 1431 | my $app = $self->{app_object}; | ||
| 1432 | |||
| 1433 | #warn "set_screen_val :$val:\n"; | ||
| 1434 | my $scrns = DBIx::Perform::get_screen_from_tag($field_tag); | ||
| 1435 | |||
| 1436 | # warn join (' , ', @$scrns) . "\n" if $::TRACE_DATA; | ||
| 1437 | foreach my $scr (@$scrns) { | ||
| 1438 | my $form = $app->getForm("Run$scr"); | ||
| 1439 | my $subform = $form->getSubform('DBForm'); | ||
| 1440 | # my $subform = $self->{subforms}->[$scr]; | ||
| 1441 | my $w = $subform->getWidget($field_tag); | ||
| 1442 | $w->setField( 'VALUE', $val ); | ||
| 1443 | } | ||
| 1444 | } | ||
| 1445 | |||
| 1446 | sub redraw_subform { | ||
| 1447 | warn "Entering redraw_subform\n" if $::TRACE; | ||
| 1448 | my $app = $DBIx::Perform::GlobalUi->{app_object}; | ||
| 1449 | my $cf = $app->getField('form_name'); | ||
| 1450 | my $form = $app->getForm($cf); | ||
| 1451 | my $subform = $form->getSubform('DBForm'); | ||
| 1452 | my $mwh = $subform->{MWH}; | ||
| 1453 | $subform->draw($mwh) if $mwh; | ||
| 1454 | } | ||
| 1455 | |||
| 1456 | sub change_mode_display { | ||
| 1457 | my $self = shift; | ||
| 1458 | my $form = shift; | ||
| 1459 | my $mode = shift; | ||
| 1460 | |||
| 1461 | warn "entering change_mode_display\n" if $::TRACE; | ||
| 1462 | |||
| 1463 | die "Trouble changing mode display" if !defined($mode) || !defined($form); | ||
| 1464 | |||
| 1465 | $mode = lc($mode); | ||
| 1466 | |||
| 1467 | if ( $mode eq 'perform' ) # switching back to main form | ||
| 1468 | { | ||
| 1469 | $form->setField( 'EXIT', 1 ); | ||
| 1470 | $self->change_modename($msgs->[2]); | ||
| 1471 | $self->change_label_to_buttons( $form, $mode ); | ||
| 1472 | warn "leaving change_mode_display\n" if $::TRACE; | ||
| 1473 | return undef; | ||
| 1474 | } | ||
| 1475 | $form->setField( 'DONTSWITCH', 0 ); | ||
| 1476 | my $str = $self->{button_messages}->{$mode}; | ||
| 1477 | my %translate_mode = ( query => 0, add => 4, update => 5 ); | ||
| 1478 | my $i = $translate_mode{$mode} + 3; | ||
| 1479 | my $m = substr($msgs->[$i], 0, 8); | ||
| 1480 | |||
| 1481 | $self->change_modename($m); | ||
| 1482 | $self->change_buttons_to_label($str); | ||
| 1483 | |||
| 1484 | warn "leaving change_mode_display\n" if $::TRACE; | ||
| 1485 | return undef; | ||
| 1486 | } | ||
| 1487 | |||
| 1488 | sub change_focus_to_button { | ||
| 1489 | my $self = shift; | ||
| 1490 | my $form = shift; | ||
| 1491 | my $button = shift; | ||
| 1492 | |||
| 1493 | warn "entering change_focus_to_button\n" if $::TRACE; | ||
| 1494 | |||
| 1495 | die "missing button parameter" if ( !defined($button) ); | ||
| 1496 | |||
| 1497 | $self->{form_object}->setField( 'EXIT', 1 ); | ||
| 1498 | $self->{form_object}->setField( 'DONTSWITCH', 0 ); | ||
| 1499 | $self->clear_display_error; | ||
| 1500 | $self->clear_display_comment; | ||
| 1501 | |||
| 1502 | $self->change_mode_display( $form, $button ); | ||
| 1503 | |||
| 1504 | my $wid = $form->getWidget('ModeButtons'); | ||
| 1505 | $wid->setField( 'LABELS', $self->{button_labels} ); | ||
| 1506 | $wid->setField( 'NAMES', \@Button_names ); | ||
| 1507 | |||
| 1508 | $wid = $form->getWidget('InfoMsg'); | ||
| 1509 | my $m = $self->{info_messages}->{remove}; | ||
| 1510 | $wid->setField('VALUE', $m ); | ||
| 1511 | |||
| 1512 | warn "leaving change_focus_to_button\n" if $::TRACE; | ||
| 1513 | return undef; | ||
| 1514 | } | ||
| 1515 | |||
| 1516 | sub change_focus_to_field_in_current_table { | ||
| 1517 | my $self = shift; | ||
| 1518 | my $tag = shift; | ||
| 1519 | |||
| 1520 | warn "entering change_focus_to_field_in_current_table\n" if $::TRACE; | ||
| 1521 | |||
| 1522 | my $form = $self->get_current_form; | ||
| 1523 | my $subform = $form->getSubform('DBForm'); | ||
| 1524 | my $ct = $self->get_current_table_name; | ||
| 1525 | my $mode = $subform->getField('editmode'); | ||
| 1526 | |||
| 1527 | #my @taborder = DBIx::Perform::Forms::generate_form_taborder($ct, $mode); | ||
| 1528 | my @taborder = DBIx::Perform::Forms::temp_generate_taborder( $ct, $mode ); | ||
| 1529 | my $limit = $#taborder; | ||
| 1530 | my $i; | ||
| 1531 | for ( $i = 0 ; $i <= $limit ; $i++ ) { | ||
| 1532 | if ( $tag eq $taborder[$i] ) { | ||
| 1533 | $self->{'focus'} = $taborder[$i]; | ||
| 1534 | $self->{'newfocus'} = $taborder[$i]; | ||
| 1535 | $subform->setField( 'FOCUSED', $taborder[$i] ); | ||
| 1536 | warn "leaving change_focus_to_field_in_current_table\n" if $::TRACE; | ||
| 1537 | return $self->{focus}; | ||
| 1538 | } | ||
| 1539 | } | ||
| 1540 | warn "Unable to find field to change focus to in current table" if $::TRACE; | ||
| 1541 | |||
| 1542 | warn "leaving change_focus_to_field_in_current_table\n" if $::TRACE; | ||
| 1543 | return undef; | ||
| 1544 | } | ||
| 1545 | |||
| 1546 | sub add_field_list_to_screens { | ||
| 1547 | my $self = shift; | ||
| 1548 | my @scrns = @{ $self->{screens} }; | ||
| 1549 | my $field_list = $self->{global_field_list}; | ||
| 1550 | |||
| 1551 | foreach my $scr (@scrns) { | ||
| 1552 | my $sf = $scr->{WIDGETS}; | ||
| 1553 | |||
| 1554 | $field_list->reset; | ||
| 1555 | while ( my $fo = $field_list->iterate_list ) { | ||
| 1556 | my ( $tag, $tab, $col ) = $fo->get_names; | ||
| 1557 | my @wid = | ||
| 1558 | $self->get_screen_subform_widget($tag); | ||
| 1559 | |||
| 1560 | if ( defined( $sf->{$tag} ) ) { | ||
| 1561 | for (my $i = $#wid; $i >= 0; $i--) { | ||
| 1562 | $sf->{$tag}->{'NAME'} = $tag; | ||
| 1563 | $wid[$i]->setField( 'NAME', $tag ); | ||
| 1564 | |||
| 1565 | # add "one-time" attribute info | ||
| 1566 | |||
| 1567 | # SIZE | ||
| 1568 | $fo->{size} = $sf->{$tag}->{COLUMNS} | ||
| 1569 | if !defined $fo->{subscript_ceiling} | ||
| 1570 | || !defined $fo->{format} | ||
| 1571 | || !defined $fo->{picture}; | ||
| 1572 | |||
| 1573 | # REVERSE | ||
| 1574 | my $reverse = $fo->{reverse}; | ||
| 1575 | if ( defined $reverse ) { | ||
| 1576 | my $env = lc $ENV{'BGCOLOR'} || 'black'; | ||
| 1577 | my $bg = $env =~ /black|blue/i ? 'white' : 'black'; | ||
| 1578 | my $fg = $bg =~ /black|blue/i ? 'white' : 'black'; | ||
| 1579 | |||
| 1580 | $wid[$i]->setField( 'FOREGROUND', $fg ); | ||
| 1581 | $wid[$i]->setField( 'BACKGROUND', $bg ); | ||
| 1582 | } | ||
| 1583 | } | ||
| 1584 | } | ||
| 1585 | } | ||
| 1586 | } | ||
| 1587 | |||
| 1588 | warn Data::Dumper->Dump( [@scrns], ['scrns'] ) if $::TRACE_DATA; | ||
| 1589 | return undef; | ||
| 1590 | } | ||
| 1591 | |||
| 1592 | #make a hash recording all the joins by field_tag. | ||
| 1593 | sub compute_joins_by_tag { | ||
| 1594 | my $self = shift; | ||
| 1595 | my $app = $self->{app_object}; | ||
| 1596 | my $fl = $self->{global_field_list}; | ||
| 1597 | my %hash; | ||
| 1598 | my %joins_by_tag; | ||
| 1599 | |||
| 1600 | $fl->reset; | ||
| 1601 | while ( my $fo = $fl->iterate_list ) { | ||
| 1602 | my ( $tag, $tab, $col ) = $fo->get_names; | ||
| 1603 | |||
| 1604 | if ($hash{$tag}) { | ||
| 1605 | $joins_by_tag{$tag} = 1; | ||
| 1606 | } | ||
| 1607 | $hash{$tag} = 1; | ||
| 1608 | } | ||
| 1609 | $app->{joins_by_tag} = \%joins_by_tag; | ||
| 1610 | # return %joins_by_tag; | ||
| 1611 | } | ||
| 1612 | |||
| 1613 | 1; |