1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
|
/*
* Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; version 2 of the
* License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*/
#include "table_figure_idef1x.h"
using namespace mdc;
using namespace wbfig;
using namespace base;
void Separator::draw_contents(mdc::CairoCtx *cr)
{
cr->translate(get_position());
if (_top_empty)
{
cr->move_to(0, 20.5);
cr->line_to(get_size().width, 20.5);
}
else
{
cr->move_to(0, 0.5);
cr->line_to(get_size().width, 0.5);
}
cr->set_line_width(1);
cr->set_color(Color::Black());
cr->stroke();
}
Size Separator::calc_min_size()
{
if (_top_empty && _bottom_empty)
return Size(80, 40);
else if (_top_empty || _bottom_empty)
return Size(80, 20);
else
return Size(80, 2);
}
void Separator::set_top_empty(bool flag)
{
_top_empty= flag;
set_needs_relayout();
}
void Separator::set_bottom_empty(bool flag)
{
_bottom_empty= flag;
set_needs_relayout();
}
Idef1xTable::Idef1xTable(mdc::Layer *layer, FigureEventHub *hub, const model_ObjectRef &self)
: Table(layer, hub, self, false), _column_box(layer, mdc::Box::Vertical), _separator(layer)
{
set_allowed_resizing(true, true);
set_accepts_focus(true);
set_accepts_selection(true);
magnetize_bounds();
add(&_title, false, true, true);
_title.set_font(mdc::FontSpec(_title.get_font().family, mdc::SNormal, mdc::WNormal, 12));
_column_box.set_spacing(1);
_column_box.set_border_color(Color::Black());
_column_box.set_background_color(Color::White());
_column_box.set_draw_background(true);
set_background_color(Color::White());
set_draw_background(true);
add(&_column_box, true, true, true);
}
void Idef1xTable::set_color(const Color &color)
{
_column_box.set_background_color(color);
set_background_color(color);
set_needs_render();
}
void Idef1xTable::set_dependant(bool flag)
{
if (flag)
_column_box.set_background_corners(mdc::CAll, 8.0);
else
_column_box.set_background_corners(mdc::CNone, 0.0);
set_needs_render();
}
Table::ItemList::iterator Idef1xTable::begin_columns_sync()
{
_unique_oids.clear();
return begin_sync(_column_box, _columns);
}
Table::ItemList::iterator Idef1xTable::sync_next_column(ItemList::iterator iter,
const std::string &id,
ColumnFlags flags,
const std::string &text)
{
if (flags & wbfig::ColumnPK)
{
_unique_oids.insert(id);
if (flags & wbfig::ColumnFK)
return sync_next(_column_box, _columns, iter, id, NULL, text+" (FK)",
boost::bind(&Idef1xTable::create_column_item, this, _1, _2),
boost::bind(&Idef1xTable::update_column_item, this, _1, flags));
else
return sync_next(_column_box, _columns, iter, id, NULL, text,
boost::bind(&Idef1xTable::create_column_item, this, _1, _2),
boost::bind(&Idef1xTable::update_column_item, this, _1, flags));
}
else if (flags & wbfig::ColumnFK)
return sync_next(_column_box, _columns, iter, id, NULL, text+" (FK)",
boost::bind(&Idef1xTable::create_column_item, this, _1, _2),
boost::bind(&Idef1xTable::update_column_item, this, _1, flags));
else
return sync_next(_column_box, _columns, iter, id, NULL, text,
boost::bind(&Idef1xTable::create_column_item, this, _1, _2),
boost::bind(&Idef1xTable::update_column_item, this, _1, flags));
}
void Idef1xTable::end_columns_sync(ItemList::iterator iter)
{
end_sync(_column_box, _columns, iter);
}
void Idef1xTable::end_sync(mdc::Box &box, ItemList &list, ItemList::iterator iter)
{
// everything after iter is outdated, so just delete everything
while (iter != list.end())
{
ItemList::iterator next= iter;
++next;
delete *iter;
list.erase(iter);
iter= next;
}
// resync box
box.remove_all();
// first add PK columns
for (ItemList::const_iterator i= list.begin(); i!=list.end(); ++i)
{
if (_unique_oids.find((*i)->get_id()) != _unique_oids.end())
box.add(*i, false, true, true);
}
_separator.set_top_empty(_unique_oids.empty());
_separator.set_bottom_empty(_unique_oids.size() == list.size());
// add separator
box.add(&_separator, false, true, true);
// then add rest
for (ItemList::const_iterator i= list.begin(); i!=list.end(); ++i)
{
if (_unique_oids.find((*i)->get_id()) == _unique_oids.end())
box.add(*i, false, true, true);
}
box.set_needs_relayout();
get_layer()->get_view()->unlock_redraw();
get_layer()->get_view()->unlock();
}
|