]> git.lyx.org Git - features.git/blob - src/frontends/gtk/GTabular.C
bebf2e3f787fbefce9eb09355bb7625f1f43d31c
[features.git] / src / frontends / gtk / GTabular.C
1 /**
2  * \file GTabular.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author John Spray
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 // Too hard to make concept checks work with this file
14 #ifdef _GLIBCXX_CONCEPT_CHECKS
15 #undef _GLIBCXX_CONCEPT_CHECKS
16 #endif
17 #ifdef _GLIBCPP_CONCEPT_CHECKS
18 #undef _GLIBCPP_CONCEPT_CHECKS
19 #endif
20
21 #include "GTabular.h"
22 #include "ControlTabular.h"
23
24 #include "ghelpers.h"
25
26 #include "controllers/helper_funcs.h"
27
28 #include "debug.h"
29
30 using std::string;
31 using std::vector;
32
33
34 namespace lyx {
35 namespace frontend {
36
37 GTabular::GTabular(Dialog & parent)
38         : GViewCB<ControlTabular, GViewGladeB>(parent, _("Table Settings"), false)
39 {}
40
41
42 void GTabular::doBuild()
43 {
44         string const gladeName = findGladeFile("tabular");
45         xml_ = Gnome::Glade::Xml::create(gladeName);
46
47         Gtk::Button *button;
48         xml_->get_widget("Close", button);
49         setCancel(button);
50
51         // **** Current cell coords ****
52         xml_->get_widget("CurrentRow", cellrowspin_);
53         xml_->get_widget("CurrentColumn", cellcolspin_);
54
55         // **** Table tab ****
56         Gtk::HBox *box;
57         xml_->get_widget("HorizontalAlignment", box);
58         horzaligncombo_ = Gtk::manage (new Gtk::ComboBoxText);
59         box->add(*horzaligncombo_);
60         box->show_all();
61         xml_->get_widget("VerticalAlignment", vertaligncombo_);
62         xml_->get_widget("SpecifyWidth", specifywidthcheck_);
63         specifywidthcheck_->signal_toggled().connect(
64                 sigc::mem_fun(*this, &GTabular::updateSensitivity));
65
66         xml_->get_widget_derived ("Width", widthlength_);
67         xml_->get_widget("LaTeXArgument", latexargsentry_);
68         xml_->get_widget("RotateTable", rotatetablecheck_);
69
70         // **** This Cell tab ****
71         xml_->get_widget("UpperBorder", upperbordercheck_);
72         xml_->get_widget("LowerBorder", lowerbordercheck_);
73         xml_->get_widget("LeftBorder", leftbordercheck_);
74         xml_->get_widget("RightBorder", rightbordercheck_);
75         xml_->get_widget("RotateCell", rotatecellcheck_);
76         xml_->get_widget("MultiColumn", multicolcheck_);
77         multicolcheck_->signal_toggled().connect(
78                 sigc::mem_fun(*this, &GTabular::updateSensitivity));
79         xml_->get_widget("NoBorders", button);
80         button->signal_clicked().connect(
81                 sigc::bind(sigc::mem_fun(*this, &GTabular::allBorders), false));
82         xml_->get_widget("AllBorders", button);
83         button->signal_clicked().connect(
84                 sigc::bind(sigc::mem_fun(*this, &GTabular::allBorders), true));
85
86         // **** Longtable tab ****
87         xml_->get_widget("LongTable", longtablecheck_);
88
89         longtablecheck_->signal_toggled().connect(
90                 sigc::mem_fun(*this, &GTabular::updateSpecialRowsSensitivity));
91
92         xml_->get_widget("PageBreak", pagebreakcheck_);
93         
94         xml_->get_widget("SpecialRows", specialrowstable_);
95
96         xml_->get_widget("HeaderOn",headeroncheck_);
97         xml_->get_widget("FooterOn",footeroncheck_);
98         xml_->get_widget("FirstHeaderOn",firstheaderoncheck_);
99         xml_->get_widget("LastFooterOn",lastfooteroncheck_);
100         xml_->get_widget("FirstHeaderEmpty",firstheaderemptycheck_);
101         xml_->get_widget("LastFooterEmpty",lastfooteremptycheck_);
102         xml_->get_widget("HeaderUpperBorderDouble",headerupperborderdoublecheck_);
103         xml_->get_widget("FooterUpperBorderDouble",footerupperborderdoublecheck_);
104         xml_->get_widget("FirstHeaderUpperBorderDouble",firstheaderupperborderdoublecheck_);
105         xml_->get_widget("LastFooterUpperBorderDouble",lastfooterupperborderdoublecheck_);
106         xml_->get_widget("HeaderLowerBorderDouble",headerlowerborderdoublecheck_);
107         xml_->get_widget("FooterLowerBorderDouble",footerlowerborderdoublecheck_);
108         xml_->get_widget("FirstHeaderLowerBorderDouble",firstheaderlowerborderdoublecheck_);
109         xml_->get_widget("LastFooterLowerBorderDouble",lastfooterlowerborderdoublecheck_);
110
111         headeroncheck_->signal_toggled().connect(
112                 sigc::mem_fun(*this, &GTabular::updateSpecialRowsSensitivity));
113         footeroncheck_->signal_toggled().connect(
114                 sigc::mem_fun(*this, &GTabular::updateSpecialRowsSensitivity));
115         firstheaderoncheck_->signal_toggled().connect(
116                 sigc::mem_fun(*this, &GTabular::updateSpecialRowsSensitivity));
117         lastfooteroncheck_->signal_toggled().connect(
118                 sigc::mem_fun(*this, &GTabular::updateSpecialRowsSensitivity));
119         firstheaderemptycheck_->signal_toggled().connect(
120                 sigc::mem_fun(*this, &GTabular::updateSpecialRowsSensitivity));
121         lastfooteremptycheck_->signal_toggled().connect(
122                 sigc::mem_fun(*this, &GTabular::updateSpecialRowsSensitivity));
123         headerupperborderdoublecheck_->signal_toggled().connect(
124                 sigc::mem_fun(*this, &GTabular::updateSpecialRowsSensitivity));
125         footerupperborderdoublecheck_->signal_toggled().connect(
126                 sigc::mem_fun(*this, &GTabular::updateSpecialRowsSensitivity));
127         firstheaderupperborderdoublecheck_->signal_toggled().connect(
128                 sigc::mem_fun(*this, &GTabular::updateSpecialRowsSensitivity));
129         lastfooterupperborderdoublecheck_->signal_toggled().connect(
130                 sigc::mem_fun(*this, &GTabular::updateSpecialRowsSensitivity));
131         headerlowerborderdoublecheck_->signal_toggled().connect(
132                 sigc::mem_fun(*this, &GTabular::updateSpecialRowsSensitivity));
133         footerlowerborderdoublecheck_->signal_toggled().connect(
134                 sigc::mem_fun(*this, &GTabular::updateSpecialRowsSensitivity));
135         firstheaderlowerborderdoublecheck_->signal_toggled().connect(
136                 sigc::mem_fun(*this, &GTabular::updateSpecialRowsSensitivity));
137         lastfooterlowerborderdoublecheck_->signal_toggled().connect(
138                 sigc::mem_fun(*this, &GTabular::updateSpecialRowsSensitivity));
139
140 /*      headeroncheck_;
141         firstheaderoncheck_;
142         lastfooteroncheck_;
143         firstheaderemptycheck_;
144         lastfooteremptycheck_;
145         headerupperborderdoublecheck_;
146         footerupperborderdoublecheck_;
147         firstheaderupperborderdoublecheck_;
148         lastfooterupperborderdoublecheck_;
149         headerlowerborderdoublecheck_;
150         footerlowerborderdoublecheck_;
151         firstheaderlowerborderdoublecheck_;
152         lastfooterlowerborderdoublecheck_;*/
153
154         // Disable for read-only documents.
155 //      bcview().addReadOnly(browsebutton_);
156
157 }
158
159
160 void GTabular::apply()
161 {
162
163 }
164
165
166 void GTabular::update()
167 {
168         updating_ = true;
169
170         LyXTabular const & tabular = controller().tabular();
171         LyXTabular::idx_type const cell = controller().getActiveCell();
172         bool const multicol = tabular.isMultiColumn(cell);
173
174         cellcolspin_->get_adjustment()->set_value(tabular.column_of_cell (cell)+1);
175         cellrowspin_->get_adjustment()->set_value(tabular.row_of_cell (cell));
176
177         // **** Table tab ****
178
179         LyXLength pwidth;
180         string special;
181
182         if (multicol) {
183                 special = tabular.getAlignSpecial(cell, LyXTabular::SET_SPECIAL_MULTI);
184                 pwidth = tabular.getMColumnPWidth(cell);
185         } else {
186                 special = tabular.getAlignSpecial(cell, LyXTabular::SET_SPECIAL_COLUMN);
187                 pwidth = tabular.getColumnPWidth(cell);
188         }
189
190         updateHorzAlignCombo(!multicol && !pwidth.zero());
191         
192         int halign = tabular.getAlignment(cell);
193         if (halign == LYX_ALIGN_RIGHT)
194                 horzaligncombo_->set_active(2);
195         else if (halign == LYX_ALIGN_CENTER)
196                 horzaligncombo_->set_active(1);
197         else if (halign == LYX_ALIGN_BLOCK)
198                 horzaligncombo_->set_active(3);
199         else
200                 horzaligncombo_->set_active(0);
201
202         int valign = tabular.getVAlignment(cell);
203         if (valign == LyXTabular::LYX_VALIGN_BOTTOM)
204                 vertaligncombo_->set_active(2);
205         else if (valign == LyXTabular::LYX_VALIGN_MIDDLE)
206                 vertaligncombo_->set_active(1);
207         else
208                 vertaligncombo_->set_active(0);
209
210         latexargsentry_->set_text(special);
211         specifywidthcheck_->set_active(!pwidth.zero());
212         widthlength_->set_length(pwidth);
213         rotatetablecheck_->set_active(tabular.getRotateTabular());
214
215         // **** This Cell tab ****
216         multicolcheck_->set_active(multicol);
217         rotatecellcheck_->set_active(tabular.getRotateCell(cell));
218
219         upperbordercheck_->set_active(tabular.topLine(cell));
220         lowerbordercheck_->set_active(tabular.bottomLine(cell));
221         leftbordercheck_->set_active(tabular.leftLine(cell));
222         rightbordercheck_->set_active(tabular.rightLine(cell));
223
224         // **** Long-table tab ****
225         LyXTabular::row_type const row(tabular.row_of_cell(cell));
226         bool const longtable = tabular.isLongTabular();
227         longtablecheck_->set_active(longtable);
228         pagebreakcheck_->set_active(tabular.getLTNewPage(row));
229
230         if (longtable) {
231                 LyXTabular::ltType ltt;
232                 bool use_empty;
233                 bool row_set = tabular.getRowOfLTHead(row, ltt);
234
235                 headeroncheck_->set_active(row_set);
236                 lyxerr << "row_set for header = " << row_set << "\n";
237                 if (ltt.set) {
238                         headerupperborderdoublecheck_->set_active(ltt.topDL);
239                         headerlowerborderdoublecheck_->set_active(ltt.bottomDL);
240                         use_empty = true;
241                 } else {
242                         headerupperborderdoublecheck_->set_active(false);
243                         headerlowerborderdoublecheck_->set_active(false);
244                         /*headerupperborderdoublecheck_->set_sensitive(false);
245                         headerlowerborderdoublecheck_->set_sensitive(false);*/
246                         firstheaderemptycheck_->set_active(false);
247                         /*firstheaderemptycheck_->set_sensitive(false);*/
248                         use_empty = false;
249                 }
250
251                 row_set = tabular.getRowOfLTFirstHead(row, ltt);
252                 firstheaderoncheck_->set_active(row_set);
253                 if (ltt.set && (!ltt.empty || !use_empty)) {
254                         firstheaderupperborderdoublecheck_->set_active(ltt.topDL);
255                         firstheaderlowerborderdoublecheck_->set_active(ltt.bottomDL);
256                 } else {
257                         firstheaderupperborderdoublecheck_->set_active(false);
258                         firstheaderlowerborderdoublecheck_->set_active(false);
259                         /*firstheaderupperborderdoublecheck_->set_sensitive(false);
260                         firstheaderlowerborderdoublecheck_->set_sensitive(false);*/
261                         if (use_empty) {
262                                 firstheaderemptycheck_->set_active(ltt.empty);
263                                 //if (ltt.empty)
264                                         //firstheaderoncheck_->set_sensitive(false);
265                         }
266                 }
267
268                 row_set = tabular.getRowOfLTFoot(row, ltt);
269                 footeroncheck_->set_active(row_set);
270                 if (ltt.set) {
271                         footerupperborderdoublecheck_->set_active(ltt.topDL);
272                         footerlowerborderdoublecheck_->set_active(ltt.bottomDL);
273                         use_empty = true;
274                 } else {
275                         footerupperborderdoublecheck_->set_active(false);
276                         footerlowerborderdoublecheck_->set_active(false);
277                         //footerupperborderdoublecheck_->set_sensitive(false);
278                         //footerlowerborderdoublecheck_->set_sensitive(false);
279                         lastfooteremptycheck_->set_active(false);
280                         //lastfooteremptycheck_->set_sensitive(false);
281                         use_empty = false;
282                 }
283
284                 row_set = tabular.getRowOfLTLastFoot(row, ltt);
285                 lastfooteroncheck_->set_active(row_set);
286                 if (ltt.set && (!ltt.empty || !use_empty)) {
287                         lastfooterupperborderdoublecheck_->set_active(ltt.topDL);
288                         lastfooterlowerborderdoublecheck_->set_active(ltt.bottomDL);
289                 } else {
290                         lastfooterupperborderdoublecheck_->set_active(false);
291                         lastfooterlowerborderdoublecheck_->set_active(false);
292                         //lastfooterupperborderdoublecheck_->set_sensitive(false);
293                         //lastfooterlowerborderdoublecheck_->set_sensitive(false);
294                         if (use_empty) {
295                                 lastfooteremptycheck_->set_active(ltt.empty);
296                                 //if (ltt.empty)
297                                         //lastfooteroncheck_->set_sensitive(false);
298                         }
299                 }
300
301         }
302         
303         updating_ = false;
304         
305         updateSensitivity();
306         updateSpecialRowsSensitivity();
307 }
308
309
310 void GTabular::onInput()
311 {
312         updateSensitivity();
313 }
314
315
316 void GTabular::allBorders(bool borders)
317 {
318         if (upperbordercheck_->is_sensitive())
319                 upperbordercheck_->set_active(borders);
320         if (lowerbordercheck_->is_sensitive())
321                 lowerbordercheck_->set_active(borders);
322         if (leftbordercheck_->is_sensitive())
323                 leftbordercheck_->set_active(borders);
324         if (rightbordercheck_->is_sensitive())
325                 rightbordercheck_->set_active(borders);
326 }
327
328
329 void GTabular::updateSensitivity()
330 {
331         if (updating_)
332                 return;
333
334         bool const specifywidth = specifywidthcheck_->get_active();
335         bool const multicol = multicolcheck_->get_active();
336
337         widthlength_->set_sensitive(specifywidth);
338         vertaligncombo_->set_sensitive(specifywidth);   
339
340         updateHorzAlignCombo(!multicol && specifywidth);
341 }
342
343
344 void GTabular::updateHorzAlignCombo(bool extraoption)
345 {
346         if (updating_)
347                 return;
348
349         //FIXME: check if we really need to completely rewrite combo data
350         // Deprecated in favor of clear_items in gtkmm >= 2.8
351         int const oldselection = horzaligncombo_->get_active_row_number();
352         horzaligncombo_->clear();
353         horzaligncombo_->append_text(_("Left"));
354         horzaligncombo_->append_text(_("Center"));
355         horzaligncombo_->append_text(_("Right"));
356         if (extraoption)
357                 horzaligncombo_->append_text(_("Block"));
358         if (oldselection < horzaligncombo_->get_model()->children().size())
359                 horzaligncombo_->set_active(oldselection);
360         else
361                 horzaligncombo_->set_active(0);
362 }
363
364
365 void GTabular::updateSpecialRowsSensitivity()
366 {
367         if (updating_)
368                 return;
369
370         bool const header = headeroncheck_->get_active();
371         bool const footer = footeroncheck_->get_active();
372         bool const firstheader = firstheaderoncheck_->get_active();
373         bool const firstheaderempty = firstheaderemptycheck_->get_active();
374         bool const lastfooter = lastfooteroncheck_->get_active();
375         bool const lastfooterempty = lastfooteremptycheck_->get_active();
376         firstheaderemptycheck_->set_sensitive(!firstheader);
377         lastfooteremptycheck_->set_sensitive(!lastfooter);
378         headerupperborderdoublecheck_->set_sensitive(header);
379         headerlowerborderdoublecheck_->set_sensitive(header);
380         footerupperborderdoublecheck_->set_sensitive(footer);
381         footerlowerborderdoublecheck_->set_sensitive(footer);
382         
383         firstheaderoncheck_->set_sensitive(!firstheaderempty);
384         firstheaderupperborderdoublecheck_->set_sensitive(firstheaderempty || firstheader);
385         firstheaderlowerborderdoublecheck_->set_sensitive(firstheaderempty || firstheader);
386         lastfooteroncheck_->set_sensitive(!lastfooterempty);
387         lastfooterupperborderdoublecheck_->set_sensitive(lastfooterempty || lastfooter);
388         lastfooterlowerborderdoublecheck_->set_sensitive(lastfooterempty || lastfooter);
389         bool const longtable = longtablecheck_->get_active();
390         specialrowstable_->set_sensitive(longtable);
391         pagebreakcheck_->set_sensitive(longtable);
392 }
393
394 } // namespace frontend
395 } // namespace lyx