1 //
2 // "$Id: Fl_Wizard.cxx 5190 2006-06-09 16:16:34Z mike $"
3 //
4 // Fl_Wizard widget routines.
5 //
6 // Copyright 1997-2005 by Easy Software Products.
7 //
8 // This library is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU Library General Public
10 // License as published by the Free Software Foundation; either
11 // version 2 of the License, or (at your option) any later version.
12 //
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 // Library General Public License for more details.
17 //
18 // You should have received a copy of the GNU Library General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
21 // USA.
22 //
23 // Please report all bugs and problems on the following page:
24 //
25 //     http://www.fltk.org/str.php
26 //
27 // Contents:
28 //
29 //   Fl_Wizard::Fl_Wizard() - Create an Fl_Wizard widget.
30 //   Fl_Wizard::draw()      - Draw the wizard border and visible child.
31 //   Fl_Wizard::next()      - Show the next child.
32 //   Fl_Wizard::prev()      - Show the previous child.
33 //   Fl_Wizard::value()     - Return the current visible child.
34 //   Fl_Wizard::value()     - Set the visible child.
35 //
36 
37 //
38 // Include necessary header files...
39 //
40 
41 #include <FL/Fl_Wizard.H>
42 #include <FL/Fl_Window.H>
43 #include <FL/fl_draw.H>
44 
45 
46 //
47 // 'Fl_Wizard::Fl_Wizard()' - Create an Fl_Wizard widget.
48 //
49 
Fl_Wizard(int xx,int yy,int ww,int hh,const char * l)50 Fl_Wizard::Fl_Wizard(int        xx,	// I - Lefthand position
51                      int        yy,	// I - Upper position
52 		     int        ww,	// I - Width
53 		     int        hh,	// I - Height
54 		     const char *l) :	// I - Label
55     Fl_Group(xx, yy, ww, hh, l)
56 {
57   box(FL_THIN_UP_BOX);
58 
59   value_ = (Fl_Widget *)0;
60 }
61 
62 
63 //
64 // 'Fl_Wizard::draw()' - Draw the wizard border and visible child.
65 //
66 
67 void
draw()68 Fl_Wizard::draw()
69 {
70   Fl_Widget	*kid;	// Visible child
71 
72 
73   kid = value();
74 
75   if (damage() & FL_DAMAGE_ALL)
76   {
77     // Redraw everything...
78     if (kid)
79     {
80       draw_box(box(), x(), y(), w(), h(), kid->color());
81       draw_child(*kid);
82     }
83     else
84       draw_box(box(), x(), y(), w(), h(), color());
85 
86   }
87   else if (kid)
88     update_child(*kid);
89 }
90 
91 
92 //
93 // 'Fl_Wizard::next()' - Show the next child.
94 //
95 
96 void
next()97 Fl_Wizard::next()
98 {
99   int			num_kids;
100   Fl_Widget	* const *kids;
101 
102 
103   if ((num_kids = children()) == 0)
104     return;
105 
106   for (kids = array(); num_kids > 0; kids ++, num_kids --)
107     if ((*kids)->visible())
108       break;
109 
110   if (num_kids > 1)
111     value(kids[1]);
112 }
113 
114 
115 //
116 // 'Fl_Wizard::prev()' - Show the previous child.
117 //
118 
119 
120 void
prev()121 Fl_Wizard::prev()
122 {
123   int			num_kids;
124   Fl_Widget	* const *kids;
125 
126 
127   if ((num_kids = children()) == 0)
128     return;
129 
130   for (kids = array(); num_kids > 0; kids ++, num_kids --)
131     if ((*kids)->visible())
132       break;
133 
134   if (num_kids > 0 && num_kids < children())
135     value(kids[-1]);
136 }
137 
138 
139 //
140 // 'Fl_Wizard::value()' - Return the current visible child.
141 //
142 
143 Fl_Widget *
value()144 Fl_Wizard::value()
145 {
146   int			num_kids;
147   Fl_Widget	* const *kids;
148   Fl_Widget		*kid;
149 
150 
151   if ((num_kids = children()) == 0)
152     return ((Fl_Widget *)0);
153 
154   for (kids = array(), kid = (Fl_Widget *)0; num_kids > 0; kids ++, num_kids --)
155   {
156     if ((*kids)->visible())
157     {
158       if (kid)
159         (*kids)->hide();
160       else
161         kid = *kids;
162     }
163   }
164 
165   if (!kid)
166   {
167     kids --;
168     kid = *kids;
169     kid->show();
170   }
171 
172   return (kid);
173 }
174 
175 
176 //
177 // 'Fl_Wizard::value()' - Set the visible child.
178 //
179 
180 void
value(Fl_Widget * kid)181 Fl_Wizard::value(Fl_Widget *kid)
182 {
183   int			num_kids;
184   Fl_Widget	* const *kids;
185 
186 
187   if ((num_kids = children()) == 0)
188     return;
189 
190   for (kids = array(); num_kids > 0; kids ++, num_kids --)
191   {
192     if (*kids == kid)
193     {
194       if (!kid->visible())
195         kid->show();
196     }
197     else
198       (*kids)->hide();
199   }
200 
201   // This will restore the mouse pointer to the window's default cursor
202   // whenever the wizard pane is changed.  Otherwise text widgets that
203   // show the next pane may leave the cursor set to the I beam, etc...
204   if (window()) window()->cursor(FL_CURSOR_DEFAULT);
205 }
206 
207 
208 //
209 // End of "$Id: Fl_Wizard.cxx 5190 2006-06-09 16:16:34Z mike $".
210 //
211