3
* Copyright (C) 2001-2004 Murray Cumming
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License as
7
* published by the Free Software Foundation; either version 2 of the
8
* License, or (at your option) any later version.
10
* This program is distributed in the hope that it will be useful, but
11
* WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
* General Public License for more details.
15
* You should have received a copy of the GNU General Public
16
* License along with this program; if not, write to the
17
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18
* Boston, MA 02111-1307, USA.
21
#include "dialog_field_layout.h"
22
#include <libglom/data_structure/glomconversions.h>
23
#include <glom/glade_utils.h>
24
#include <glibmm/i18n.h>
29
Dialog_FieldLayout::Dialog_FieldLayout(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& builder)
30
: Gtk::Dialog(cobject),
31
m_label_field_name(0),
32
m_checkbutton_editable(0),
33
m_radiobutton_title_default(0),
34
m_label_title_default(0),
35
m_radiobutton_title_custom(0),
36
m_entry_title_custom(0),
37
m_box_formatting_placeholder(0),
38
m_radiobutton_custom_formatting(0),
41
builder->get_widget("label_field_name", m_label_field_name);
42
builder->get_widget("checkbutton_editable", m_checkbutton_editable);
44
builder->get_widget("radiobutton_use_title_default", m_radiobutton_title_default);
45
builder->get_widget("label_title_default", m_label_title_default);
46
builder->get_widget("radiobutton_use_title_custom", m_radiobutton_title_custom);
47
builder->get_widget("entry_title_custom", m_entry_title_custom);
49
//Get the place to put the Formatting stuff:
50
builder->get_widget("radiobutton_use_custom", m_radiobutton_custom_formatting);
51
builder->get_widget("box_formatting_placeholder", m_box_formatting_placeholder);
53
//GtkBuilder can't find top-level objects (GtkAdjustments in this case),
54
//that one top-level object references.
55
//See http://bugzilla.gnome.org/show_bug.cgi?id=575714
56
//so we need to this silliness. murrayc.
57
std::list<Glib::ustring> builder_ids;
58
builder_ids.push_back("box_formatting");
59
builder_ids.push_back("adjustment2");
61
//Get the formatting stuff:
64
Glib::RefPtr<Gtk::Builder> refXmlFormatting = Gtk::Builder::create_from_file(Utils::get_glade_file_path("glom_developer.glade"), builder_ids);
65
refXmlFormatting->get_widget_derived("box_formatting", m_box_formatting);
67
catch(const Gtk::BuilderError& ex)
69
std::cerr << ex.what() << std::endl;
72
m_box_formatting_placeholder->pack_start(*m_box_formatting);
73
add_view(m_box_formatting);
75
m_radiobutton_custom_formatting->signal_toggled().connect(sigc::mem_fun(*this, &Dialog_FieldLayout::on_radiobutton_custom_formatting));
80
Dialog_FieldLayout::~Dialog_FieldLayout()
82
remove_view(m_box_formatting);
85
void Dialog_FieldLayout::set_field(const sharedptr<const LayoutItem_Field>& field, const Glib::ustring& table_name)
87
m_layout_item = glom_sharedptr_clone(field);
89
m_table_name = table_name;
91
m_label_field_name->set_text( field->get_layout_display_name() );
93
m_checkbutton_editable->set_active( field->get_editable() );
95
//Calculated fields can never be edited:
96
sharedptr<const Field> field_details = field->get_full_field_details();
97
const bool editable_allowed = field_details && !field_details->get_has_calculation();
98
m_checkbutton_editable->set_sensitive(editable_allowed);
101
Glib::ustring title_custom;
102
if(field->get_title_custom())
103
title_custom = field->get_title_custom()->get_title();
105
m_radiobutton_title_custom->set_active( field->get_title_custom() && field->get_title_custom()->get_use_custom_title() );
106
m_entry_title_custom->set_text(title_custom);
107
m_label_title_default->set_text(field->get_title_or_name_no_custom());
110
m_radiobutton_custom_formatting->set_active( !field->get_formatting_use_default() );
111
m_box_formatting->set_formatting(field->m_formatting, table_name, field->get_full_field_details());
113
enforce_constraints();
116
sharedptr<LayoutItem_Field> Dialog_FieldLayout::get_field_chosen() const
120
double width, height;
121
m_layout_item->get_print_layout_position(x, y, width, height);
122
std::cout << "DEBUGDialog_FieldLayout::get_field_chosen1(): m_layout_item: x=" << x << std::endl;
124
m_layout_item->set_editable( m_checkbutton_editable->get_active() );
126
m_layout_item->set_formatting_use_default( !m_radiobutton_custom_formatting->get_active() );
127
m_box_formatting->get_formatting(m_layout_item->m_formatting);
129
sharedptr<CustomTitle> title_custom = sharedptr<CustomTitle>::create();
130
title_custom->set_use_custom_title(m_radiobutton_title_custom->get_active()); //For instance, tell it to really use a blank title.
131
title_custom->set_title(m_entry_title_custom->get_text());
133
m_layout_item->set_title_custom(title_custom);
138
double width, height;
139
m_layout_item->get_print_layout_position(x, y, width, height);
140
std::cout << "DEBUGDialog_FieldLayout::get_field_chosen2(): m_layout_item: x=" << x << std::endl;
143
return glom_sharedptr_clone(m_layout_item);
146
void Dialog_FieldLayout::on_radiobutton_custom_formatting()
148
enforce_constraints();
151
void Dialog_FieldLayout::enforce_constraints()
153
//Enable/Disable the custom formatting widgets:
154
const bool custom = m_radiobutton_custom_formatting->get_active();
155
m_box_formatting->set_sensitive(custom);