#include "insets/insettabular.h"
#include "buffer.h"
#include "xforms_helpers.h"
+#include "lyxrc.h" // to set the default length values
#include "helper_funcs.h"
#include "input_validators.h"
#include "support/lstrings.h"
FormTabular::FormTabular(LyXView * lv, Dialogs * d)
: FormInset(lv, d, _("Tabular Layout")),
- inset_(0), actCell_(-1)
+ inset_(0), actCell_(-1), closing_(false)
{
// let the dialog be shown
// This is a permanent connection so we won't bother
void FormTabular::update()
{
+ if (closing_)
+ return;
+
if (!inset_ || !inset_->tabular.get())
return;
fl_set_button(cell_options_->radio_align_right, 1);
else
fl_set_button(cell_options_->radio_align_center, 1);
- setEnabled(cell_options_->radio_align_left, true);
- setEnabled(cell_options_->radio_align_right, true);
- setEnabled(cell_options_->radio_align_center, true);
+
align = tabular->GetVAlignment(cell);
fl_set_button(cell_options_->radio_valign_top, 0);
fl_set_button(cell_options_->radio_valign_bottom, 0);
fl_set_button(cell_options_->radio_valign_bottom, 1);
else
fl_set_button(cell_options_->radio_valign_top, 1);
- setEnabled(cell_options_->radio_valign_top, true);
- setEnabled(cell_options_->radio_valign_bottom, true);
- setEnabled(cell_options_->radio_valign_center, true);
+
special = tabular->GetAlignSpecial(cell, LyXTabular::SET_SPECIAL_MULTI);
fl_set_input(cell_options_->input_special_multialign, special.c_str());
- string const default_unit = "cm";
+ bool const metric = lyxrc.default_papersize > 3;
+ string const default_unit = metric ? "cm" : "in";
updateWidgetsFromLength(cell_options_->input_mcolumn_width,
cell_options_->choice_value_mcolumn_width,
pwidth, default_unit);
setEnabled(column_options_->input_special_alignment, !isReadonly);
pwidth = tabular->GetColumnPWidth(cell);
- string const default_unit = "cm";
+ bool const metric = lyxrc.default_papersize > 3;
+ string const default_unit = metric ? "cm" : "in";
updateWidgetsFromLength(column_options_->input_column_width,
column_options_->choice_value_column_width,
pwidth, default_unit);
if (enable) {
LyXTabular::ltType ltt;
- fl_set_button(longtable_options_->radio_lt_firsthead,
- tabular->GetRowOfLTFirstHead(row, ltt));
- if (ltt.row && !ltt.empty) {
- fl_set_button(longtable_options_->check_1head_2border_above,
- ltt.topDL);
- fl_set_button(longtable_options_->check_1head_2border_above,
- ltt.topDL);
- } else {
- setEnabled(longtable_options_->check_1head_2border_above, 0);
- setEnabled(longtable_options_->check_1head_2border_below, 0);
- fl_set_button(longtable_options_->check_1head_2border_above,0);
- fl_set_button(longtable_options_->check_1head_2border_above,0);
- fl_set_button(longtable_options_->check_1head_empty,ltt.empty);
- if (ltt.empty)
- setEnabled(longtable_options_->radio_lt_firsthead, 0);
- }
- fl_set_button(longtable_options_->radio_lt_head,
- tabular->GetRowOfLTHead(row, ltt));
- if (ltt.row) {
+ bool use_empty;
+ bool row_set = tabular->GetRowOfLTHead(row, ltt);
+ fl_set_button(longtable_options_->radio_lt_head, row_set);
+ if (ltt.set) {
fl_set_button(longtable_options_->check_head_2border_above,
ltt.topDL);
fl_set_button(longtable_options_->check_head_2border_above,
ltt.topDL);
+ use_empty = true;
} else {
setEnabled(longtable_options_->check_head_2border_above, 0);
setEnabled(longtable_options_->check_head_2border_below, 0);
fl_set_button(longtable_options_->check_head_2border_above,0);
fl_set_button(longtable_options_->check_head_2border_above,0);
+ fl_set_button(longtable_options_->check_1head_empty,0);
+ setEnabled(longtable_options_->check_1head_empty, 0);
+ use_empty = false;
}
- fl_set_button(longtable_options_->radio_lt_foot,
- tabular->GetRowOfLTFoot(row, ltt));
- if (ltt.row) {
+ //
+ row_set = tabular->GetRowOfLTFirstHead(row, ltt);
+ fl_set_button(longtable_options_->radio_lt_firsthead, row_set);
+ if (ltt.set && (!ltt.empty || !use_empty)) {
+ fl_set_button(longtable_options_->check_1head_2border_above,
+ ltt.topDL);
+ fl_set_button(longtable_options_->check_1head_2border_above,
+ ltt.topDL);
+ } else {
+ setEnabled(longtable_options_->check_1head_2border_above, 0);
+ setEnabled(longtable_options_->check_1head_2border_below, 0);
+ fl_set_button(longtable_options_->check_1head_2border_above,0);
+ fl_set_button(longtable_options_->check_1head_2border_above,0);
+ if (use_empty) {
+ fl_set_button(longtable_options_->check_1head_empty,ltt.empty);
+ if (ltt.empty)
+ setEnabled(longtable_options_->radio_lt_firsthead, 0);
+ }
+ }
+ //
+ row_set = tabular->GetRowOfLTFoot(row, ltt);
+ fl_set_button(longtable_options_->radio_lt_foot, row_set);
+ if (ltt.set) {
fl_set_button(longtable_options_->check_foot_2border_above,
ltt.topDL);
fl_set_button(longtable_options_->check_foot_2border_above,
ltt.topDL);
+ use_empty = true;
} else {
setEnabled(longtable_options_->check_foot_2border_above, 0);
setEnabled(longtable_options_->check_foot_2border_below, 0);
fl_set_button(longtable_options_->check_foot_2border_above,0);
fl_set_button(longtable_options_->check_foot_2border_above,0);
+ fl_set_button(longtable_options_->check_lastfoot_empty, 0);
+ setEnabled(longtable_options_->check_lastfoot_empty, 0);
+ use_empty = false;
}
- fl_set_button(longtable_options_->radio_lt_lastfoot,
- tabular->GetRowOfLTLastFoot(row, ltt));
- if (ltt.row && !ltt.empty) {
+ //
+ row_set = tabular->GetRowOfLTLastFoot(row, ltt);
+ fl_set_button(longtable_options_->radio_lt_lastfoot, row_set);
+ if (ltt.set && (!ltt.empty || !use_empty)) {
fl_set_button(longtable_options_->check_lastfoot_2border_above,
ltt.topDL);
fl_set_button(longtable_options_->check_lastfoot_2border_above,
setEnabled(longtable_options_->check_lastfoot_2border_below,0);
fl_set_button(longtable_options_->check_lastfoot_2border_above, 0);
fl_set_button(longtable_options_->check_lastfoot_2border_above, 0);
- fl_set_button(longtable_options_->check_lastfoot_empty, ltt.empty);
- if (ltt.empty)
- setEnabled(longtable_options_->radio_lt_lastfoot, 0);
+ if (use_empty) {
+ fl_set_button(longtable_options_->check_lastfoot_empty,
+ ltt.empty);
+ if (ltt.empty)
+ setEnabled(longtable_options_->radio_lt_lastfoot, 0);
+ }
}
fl_set_button(longtable_options_->radio_lt_newpage,
tabular->GetLTNewPage(row));
string special;;
int cell = inset_->getActCell();
-
+
+ // ugly hack to auto-apply the stuff that hasn't been
+ // yet. don't let this continue to exist ...
+ if (ob == dialog_->button_close) {
+ closing_ = true;
+ input(column_options_->input_column_width, 0);
+ input(cell_options_->input_mcolumn_width, 0);
+ input(column_options_->input_special_alignment, 0);
+ input(cell_options_->input_special_multialign, 0);
+ closing_ = false;
+ ok();
+ return true;
+ }
+
if (actCell_ != cell) {
update();
fl_set_object_label(dialog_->text_warning,
if ((ob == column_options_->input_column_width) ||
(ob == column_options_->choice_value_column_width))
{
- string const str =
- getLengthFromWidgets(column_options_->input_column_width,
- column_options_->choice_value_column_width);
- inset_->tabularFeatures(lv_->view(), LyXTabular::SET_PWIDTH, str);
+ string const str =
+ getLengthFromWidgets(column_options_->input_column_width,
+ column_options_->choice_value_column_width);
+ inset_->tabularFeatures(lv_->view(), LyXTabular::SET_PWIDTH, str);
+
+ //check if the input is valid
+ string const input =
+ fl_get_input(column_options_->input_column_width);
+ if (!input.empty() && !isValidLength(input) && !isStrDbl(input)) {
+ fl_set_object_label(dialog_->text_warning,
+ _("Warning: Invalid Length (valid example: 10mm)"));
+ fl_show_object(dialog_->text_warning);
+ return false;
+ }
update(); // update for alignment
return true;
}
if ((ob == cell_options_->input_mcolumn_width) ||
(ob == cell_options_->choice_value_mcolumn_width))
{
- string const str =
- getLengthFromWidgets(cell_options_->input_mcolumn_width,
- cell_options_->choice_value_mcolumn_width);
- inset_->tabularFeatures(lv_->view(), LyXTabular::SET_MPWIDTH, str);
+ string const str =
+ getLengthFromWidgets(cell_options_->input_mcolumn_width,
+ cell_options_->choice_value_mcolumn_width);
+ inset_->tabularFeatures(lv_->view(), LyXTabular::SET_MPWIDTH, str);
+
+ //check if the input is valid
+ string const input =
+ fl_get_input(cell_options_->input_mcolumn_width);
+ if (!input.empty() && !isValidLength(input) && !isStrDbl(input)) {
+ fl_set_object_label(dialog_->text_warning,
+ _("Warning: Invalid Length (valid example: 10mm)"));
+ fl_show_object(dialog_->text_warning);
+ return false;
+ }
update(); // update for alignment
return true;
}