summaryrefslogtreecommitdiff
path: root/FS/FS/UI/Gtk.pm
blob: 507a293616a09fb2d21ef8f3f6362dc1c106f61e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
package FS::UI::Gtk;

use strict;
use Gtk;
use FS::UID qw(adminsuidsetup);

die "Can't initialize Gtk interface; $FS::UI::Base::_lock used"
  if $FS::UI::Base::_lock;
$FS::UI::Base::_lock = "FS::UI::Gtk";

=head1 NAME

FS::UI::Gtk - Base class for Gtk user-interface objects

=head1 SYNOPSIS

  use FS::UI::Gtk;
  use FS::UI::some_table;

  $interface = new FS::UI::some_table;

  $error = $interface->browse;
  $error = $interface->search;
  $error = $interface->view;
  $error = $interface->edit;
  $error = $interface->process;

=head1 DESCRIPTION

An FS::UI::Gtk object represents a Gtk user interface object.

=head1 METHODS

=over 4

=item new

=cut

sub new {
  my $proto = shift;
  my $class = ref($proto) || $proto;
  my $self = { @_ };

  bless ( $self, $class );

  $self->{'_user'} = 'ivan'; #Pop up login window?
  $self->{'_dbh'} = FS::UID::adminsuidsetup $self->{'_user'};



  $self;
}

sub activate {
  my $self = shift;

  my $vbox = new Gtk::VBox ( 0, 4 );

  foreach my $widget ( @{ $self->{'Widgets'} } ) {
    $widget->_gtk->show;
    $vbox->pack_start ( $widget->_gtk, 1, 1, 4 );
  }
  $vbox->show;

  my $window = new Gtk::Window "toplevel";
  $self->{'_gtk'} = $window;
  $window->set_title( $self->title );
  $window->add ( $vbox );
  $window->show;
  main Gtk;
}

=item interface

Returns the string `Gtk'.  Useful for the author of a table-specific UI class
to conditionally specify certain behaviour.

=cut 

sub interface { 'Gtk'; }

=back

=cut

package FS::UI::_Widget;

use vars qw( $AUTOLOAD );

sub new {
  my $proto = shift;
  my $class = ref($proto) || $proto;
  my $self = { @_ };
  bless ( $self, $class );
}

sub _gtk {
  my $self = shift;
  $self->{'_gtk'};
}

sub AUTOLOAD {
  my $self = shift;
  my $value = shift;
  my($field)=$AUTOLOAD;
  $field =~ s/.*://;
  if ( defined($value) ) {
    $self->{$field} = $value;
  } else {
    $self->{$field};
  }    
}

package FS::UI::_Text;

use vars qw ( @ISA );

@ISA = qw ( FS::UI::_Widget );

sub new {
  my $proto = shift;
  my $class = ref($proto) || $proto;
  my $self = {};
  $self->{'_gtk'} = new Gtk::Label ( shift );
  bless ( $self, $class );
}

package FS::UI::_Link;

use vars qw ( @ISA );

@ISA = qw ( FS::UI::_Widget );

sub new {
  my $proto = shift;
  my $class = ref($proto) || $proto;
  my $self = { @_ };
  $self->{'_gtk'} = new_with_label Gtk::Button ( $self->{'text'} );
  $self->{'_gtk'}->signal_connect( 'clicked', sub {
      print "STUB: (Gtk) FS::UI::_Link";
    }, "hi", "there" );
  bless ( $self, $class );
}


package FS::UI::_Table;

use vars qw ( @ISA );

@ISA = qw ( FS::UI::_Widget );

sub new {
  my $proto = shift;
  my $class = ref($proto) || $proto;
  my $self = { @_ };
  bless ( $self, $class );

  $self->{'_gtk'} = new Gtk::Table (
    $self->rows,
    $self->columns,
    0, #homogeneous
  );

  $self;
}

sub attach {
  my $self = shift;
  my ( $row, $column, $widget, $rowspan, $colspan ) = @_;
  $rowspan ||= 1;
  $colspan ||= 1;
  $self->_gtk->attach_defaults(
    $widget->_gtk,
    $column,
    $column + $colspan,
    $row,
    $row + $rowspan,
  );
  $widget->_gtk->show;
}

package FS::UI::_Tableborder;

use vars qw ( @ISA );

@ISA = qw ( FS::UI::_Table );

=head1 VERSION

$Id: Gtk.pm,v 1.1 1999-08-04 09:03:53 ivan Exp $

=head1 BUGS

This documentation is incomplete.

_Tableborder is just a _Table now.  _Tableborders should scroll (but not the
headers) and need and need more decoration. (data in white section ala gtksql
and sliding field widths) headers should be buttons that callback to sort on
their fields.

There should be a persistant, per-(freeside)-user store for window positions
and sizes and sort fields etc (see L<FS::UI::CGI/BUGS>.

Still some small bits of widget code same as FS::UI::CGI.

=head1 SEE ALSO

L<FS::UI::Base>

=head1 HISTORY

$Log: Gtk.pm,v $
Revision 1.1  1999-08-04 09:03:53  ivan
initial checkin of module files for proper perl installation

Revision 1.1  1999/01/20 09:30:36  ivan
skeletal cross-UI UI code.


=cut

1;