=head1 NAME

CFX5::Output::Win32Dialog - Output routines for Windows dialog boxes

=head1 SYNOPSIS

  use CFX5::Output;

=head1 DESCRIPTION

The C<CFX5::Output::Win32Dialog> class is a type of output object
which uses L<Win32::GUI> to display Windows dialog boxes.  It is used
by L<CFX5::Output> when running without a console.  It is based on the
routines from L<CFX5::Win32::Output>.

=cut

package CFX5::Output::Win32Dialog;
@ISA=qw(CFX5::Output::Base);
use strict;

use CFX5::Output::Base;
use CFX5::Win32::Output;
use CFX5::Output::Utils qw(wraptext);

=head2 STANDARD METHODS

=head3 init

The C<init> routine here simply calls the C<init> routine from
L<CFX5::Win32::Output> to load the required functions from the system
DLLs.

=cut

sub init {
  my $self=shift;
  
  unless (exists $self->{settings}) {
    # The default on/off settings
    #    1 => display
    #    0 => do not display
    $self->{settings}=
      {
       'internal' => 1,
       'abort'    => 1,
       'error'    => 1,
       'warn'     => 1,
       'info'     => 0,
       'moreinfo' => 0,
       'trace'    => 0,
       'debug'    => 0,
       'stack'    => 0,
       'print'    => 0,
      };
  }

  1;
}

=head3 output

This version of the C<output> function shows dialog boxes for each
error, and waits for the user to press OK.  (What if it is not OK?
Tough! ;-)

=cut

sub output {
  my $self=shift;
  my $type=shift;
  my $severity=shift;
  my $title=shift;
  my $text=shift;
  my $optional=shift;

  $self->internal_error("Unknown output type $type") 
    unless exists $self->{settings}{$type};
  
  return unless $self->{settings}{$type};

  $title = $self->progname(). ": $severity" unless defined $title;

  my $icon='none';
  if    ($severity eq "fatal" 
	 or $severity eq "error") { $icon = 'error'; }
  elsif ($severity eq "warn")     { $icon = 'warning'; }
  elsif ($severity eq "info")     { $icon = 'information'; }
  elsif ($severity eq "debug")    { $icon = 'none'; }

  # expand and space paragraphs, for consistency
  $text=wraptext(0,$text);
    
  CFX5::Win32::Output::show_message($text,$title,$icon);

  return 1;
}

=head2 CUSTOM METHODS

=cut

1;
