end of refactoring...
[falcomics:falcomics.git] / Sources / gui / FCBottombar.fal
1 /***************************************************\r
2 * Module Name : FCBottombar\r
3 * Author      : Lucone\r
4 * Create date : 2011-05-30\r
5 * Edit by     : --        in date   : ....-..-..\r
6 * Module Description -------------------------------\r
7 * the bottom bar\r
8 ***************************************************/\r
9 /***************************************************\r
10 --Classes, Object and functions:\r
11 *       28      class BottomToolbar() from GtkToolbar\r
12 *       46              function initialize( comicsName, currPage, numPages )\r
13 *       55              function get_currentPage_index()\r
14 *       62              function updateSpinImage( value )\r
15 *       76              function set_page_label( value )\r
16 *       80              function get_currentZoom()\r
17 *       84              function set_currentZoom( newValue )\r
18 *       91              function on_spinbuttonValue_changed()\r
19 *       104     >> --- Private methods!"----------------------------------------------<<\r
20 *       107             function _setSpinRange( firstPage, numPages)\r
21 *       129             function _createoBJ()\r
22 *       212             function _set_spinbuttonSensibleBackward( value )\r
23 *       219             function _set_spinbuttonSensibleForward( value )\r
24 ***************************************************/\r
25 load gtk\r
26 export\r
27 \r
28 class BottomToolbar() from GtkToolbar\r
29         _spinImageBtn   = nil           // It's a spinbutton with the current image idx\r
30         _btnFirst               = nil           // button to go to the first page of the Comics\r
31         _btnPrevious    = nil           // button to go to the previous page of the Comics\r
32         _btnNext                = nil           // button to go to the next page of the Comics\r
33         _btnLast                = nil           // button to go to the last page of the Comics\r
34         _lbComics       = nil       // Label for current folder\r
35         _lbPage                 = nil           // label for the name of the current image (=page)\r
36         _lbNumOfImg             = nil           // Label with the total number of images in Comics\r
37         _currentZoom    = nil           // the current zoom value\r
38 \r
39         _disableEvent   = nil           // to skip the event\r
40 \r
41         init\r
42                 self._createoBJ()\r
43                 self._disableEvent = false\r
44         end\r
45 \r
46         function initialize( comicsName, currPage, numPages )\r
47 \r
48                 self._lbComics.set_label( comicsName )\r
49                 self._lbPage.set_label( "--" )\r
50                 self._lbNumOfImg.set_label( numPages.toString() )\r
51                 self._setSpinRange( currPage, numPages )\r
52 \r
53         end\r
54 \r
55         function get_currentPage_index()\r
56                 return self._spinImageBtn.get_value()\r
57         end\r
58 \r
59         /*      This method is used by the four navigation buttons\r
60                 Receive the macro and translate it in current manga\r
61                 position                                                                                        */\r
62         function updateSpinImage( value )\r
63 \r
64                 actualVal = self._spinImageBtn.get_value()\r
65                 maxValue = self._spinImageBtn.get_range()[1]\r
66 \r
67                 if value == FCS_GOTOLAST: actualVal = maxValue\r
68                 if ( value == FCS_NEXT and actualVal < maxValue ): ++actualVal\r
69                 if ( value == FCS_BACK and actualVal ) > 1: --actualVal\r
70                 if value == FCS_GOTOFIRST: actualVal = 1\r
71 \r
72                 self._spinImageBtn.set_value( actualVal )\r
73 \r
74         end\r
75 \r
76         function set_page_label( value )\r
77                 self._lbPage.set_label( value )\r
78         end\r
79 \r
80         function get_currentZoom()\r
81                 return self._currentZoom.get_value()\r
82         end\r
83 \r
84         function set_currentZoom( newValue )\r
85                 if not newValue: newValue = 100\r
86                 if newValue > 400: newValue = 400\r
87                 if newValue < 10: newValue = 10\r
88                 self._currentZoom.get_value()\r
89         end\r
90 \r
91         function on_spinbuttonValue_changed()\r
92 \r
93                 if self._disableEvent : return\r
94 \r
95                 curValue = self._spinImageBtn.get_value()\r
96                 maxValue = self._spinImageBtn.get_range()[1]\r
97 \r
98                 self._set_spinbuttonSensibleBackward( curValue > 1 )\r
99                 self._set_spinbuttonSensibleForward( curValue < maxValue )\r
100                 broadcast("comics.changepage")\r
101 \r
102         end\r
103 \r
104 // REGION: Private methods!"\r
105 \r
106         // to update the spinbutton ranges and value\r
107         function _setSpinRange( firstPage, numPages)\r
108                 mySelf = self\r
109                 firstPage = int( firstPage ) \r
110 \r
111                 // disconnect the event from the spinbutton..\r
112                 self._disableEvent = true\r
113 \r
114                 self._spinImageBtn.set_range( 1, numPages )\r
115 \r
116                 self._spinImageBtn.set_sensitive( numPages > 1 )\r
117 \r
118                 // re-enable the event\r
119                 self._disableEvent = false\r
120 \r
121                 if firstPage > 1\r
122                         self._spinImageBtn.set_value( firstPage )\r
123                 else\r
124                         self.on_spinbuttonValue_changed( )\r
125                 end\r
126 \r
127         end\r
128 \r
129         // Creation various objects inside the toolbar\r
130         function _createoBJ()\r
131                 mySelf = self\r
132 \r
133                 self._lbComics = GtkLabel( "--" )\r
134                 self._lbPage = GtkLabel( "--" )\r
135                 h0 = GtkHBox( false, 10)\r
136                 h0.pack_start( GtkLabel(i"Current Comics:"),  false, false, 0 )\r
137                 h0.pack_start( self._lbComics, false, false, 0 )\r
138                 h0.pack_start( GtkLabel(i" Current page:"),  false, false, 0 )\r
139                 h0.pack_start( self._lbPage, false, false, 0 )\r
140 \r
141                 h1 = GtkHBox( false, 0)\r
142 \r
143                 self._btnFirst = GtkButton()\r
144                 self._btnFirst.set_use_stock( true )\r
145                 self._btnFirst.set_label("gtk-goto-first")\r
146                 self._btnFirst.signal_clicked().connect( {=> mySelf.updateSpinImage( FCS_GOTOFIRST )} )\r
147                 self._btnFirst.set_sensitive(false)\r
148 \r
149                 self._btnPrevious = GtkButton()\r
150                 self._btnPrevious.set_use_stock( true )\r
151                 self._btnPrevious.set_label("gtk-go-back")\r
152                 self._btnPrevious.signal_clicked().connect( {=> mySelf.updateSpinImage( FCS_BACK )} )\r
153                 self._btnPrevious.set_sensitive(false)\r
154 \r
155                 self._btnNext = GtkButton()\r
156                 self._btnNext.set_use_stock( true )\r
157                 self._btnNext.set_label("gtk-go-forward")\r
158                 self._btnNext.signal_clicked().connect( {=> mySelf.updateSpinImage( FCS_NEXT )} )\r
159                 self._btnNext.set_sensitive(false)\r
160 \r
161                 self._btnLast = GtkButton()\r
162                 self._btnLast.set_use_stock( true )\r
163                 self._btnLast.set_label("gtk-goto-last")\r
164                 self._btnLast.signal_clicked().connect( {=> mySelf.updateSpinImage( FCS_GOTOLAST )} )\r
165                 self._btnLast.set_sensitive(false)\r
166 \r
167                 h2 = GtkHBox(false, 10)\r
168                 h2.pack_start(GtkLabel("  "), false, false, 0)\r
169 \r
170                 h2.pack_start(GtkLabel(i"Page"), false, false, 0)\r
171 \r
172                 self._spinImageBtn = GtkSpinButton.new_with_range(0, 0, 1)\r
173                 self._spinImageBtn.set_digits(0)\r
174                 self._spinImageBtn.set_increments(1, 5)\r
175                 self._spinImageBtn.set_value( 0 )\r
176                 self._spinImageBtn.set_numeric(true)\r
177                 self._spinImageBtn.set_sensitive(false)\r
178                 self._spinImageBtn.signal_value_changed().connect( self.on_spinbuttonValue_changed )\r
179 \r
180                 h2.pack_start(self._spinImageBtn, false, false, 0)\r
181 \r
182                 h2.pack_start(GtkLabel(i"of"), false, false, 0)\r
183                 self._lbNumOfImg = GtkLabel("0")\r
184                 h2.pack_start(self._lbNumOfImg, false, false, 0)\r
185 \r
186                 h2.pack_start(GtkLabel("  "), false, false, 0)\r
187 \r
188                 h1.pack_start(self._btnFirst, false, false, 0)\r
189                 h1.pack_start(self._btnPrevious, false, false, 0)\r
190                 h1.pack_start(h2, false, false, 0)\r
191                 h1.pack_start(self._btnNext, false, false, 0)\r
192                 h1.pack_start(self._btnLast, false, false, 0)\r
193 \r
194                 h0.pack_start( h1, false, false, 0 )\r
195                 h0.pack_start(GtkLabel("  "), false, false, 0)\r
196 \r
197                 self._currentZoom = GtkScaleButton( GTK_ICON_SIZE_LARGE_TOOLBAR, 10, 400, 25, nil )\r
198                 self._currentZoom.set_orientation( GTK_ORIENTATION_HORIZONTAL )\r
199                 self._currentZoom.set_value( 100 )\r
200                 self._currentZoom.set_label( "100%" )\r
201                 self._currentZoom.set_image_position( GTK_POS_TOP )\r
202                 self._currentZoom.set_image( GtkImage.new_from_stock( "gtk-zoom-in", GTK_ICON_SIZE_LARGE_TOOLBAR ))\r
203                 h0.pack_start( self._currentZoom, false, false, 0 )\r
204 \r
205                 _toolItem = GtkToolItem()\r
206                 _toolItem.add( h0 )\r
207 \r
208                 self.insert( _toolItem, 0)\r
209                 self.set_style = GTK_TOOLBAR_BOTH\r
210 \r
211         end\r
212 \r
213         function _set_spinbuttonSensibleBackward( value )\r
214 \r
215                 self._btnFirst.set_sensitive( value  )\r
216                 self._btnPrevious.set_sensitive( value  )\r
217 \r
218         end\r
219 \r
220         function _set_spinbuttonSensibleForward( value )\r
221 \r
222                 self._btnNext.set_sensitive( value )\r
223                 self._btnLast.set_sensitive( value )\r
224 \r
225         end\r
226 \r
227 end