1 |
/* -*- c++ -*- |
/* -*- c++ -*- |
2 |
* Copyright (C) 2006, 2007 Andreas Persson |
* Copyright (C) 2006-2008 Andreas Persson |
3 |
* |
* |
4 |
* This program is free software; you can redistribute it and/or |
* This program is free software; you can redistribute it and/or |
5 |
* modify it under the terms of the GNU General Public License as |
* modify it under the terms of the GNU General Public License as |
186 |
scrolledWindow.add(treeView); |
scrolledWindow.add(treeView); |
187 |
vbox.pack_start(scrolledWindow); |
vbox.pack_start(scrolledWindow); |
188 |
scrolledWindow.show(); |
scrolledWindow.show(); |
189 |
vbox.pack_start(buttonBox); |
vbox.pack_start(buttonBox, Gtk::PACK_SHRINK); |
190 |
buttonBox.set_layout(Gtk::BUTTONBOX_END); |
buttonBox.set_layout(Gtk::BUTTONBOX_END); |
191 |
buttonBox.set_border_width(5); |
buttonBox.set_border_width(5); |
192 |
buttonBox.show(); |
buttonBox.show(); |
193 |
buttonBox.pack_start(addButton); |
buttonBox.pack_start(addButton, Gtk::PACK_SHRINK); |
194 |
buttonBox.pack_start(removeButton); |
buttonBox.pack_start(removeButton, Gtk::PACK_SHRINK); |
195 |
addButton.show(); |
addButton.show(); |
196 |
removeButton.show(); |
removeButton.show(); |
197 |
|
|
199 |
refTableModel = Gtk::ListStore::create(tableModel); |
refTableModel = Gtk::ListStore::create(tableModel); |
200 |
treeView.set_model(refTableModel); |
treeView.set_model(refTableModel); |
201 |
treeView.append_column("Dimension Type", tableModel.m_dim_type); |
treeView.append_column("Dimension Type", tableModel.m_dim_type); |
202 |
treeView.append_column_numeric("Bits", tableModel.m_bits, "%d"); |
treeView.append_column("Bits", tableModel.m_bits); |
203 |
treeView.append_column_numeric("Zones", tableModel.m_zones, "%d"); |
treeView.append_column("Zones", tableModel.m_zones); |
204 |
treeView.append_column("Description", tableModel.m_description); |
treeView.append_column("Description", tableModel.m_description); |
205 |
treeView.show(); |
treeView.show(); |
206 |
|
|
218 |
// update all GUI elements according to current gig::Region informations |
// update all GUI elements according to current gig::Region informations |
219 |
void DimensionManager::refreshManager() { |
void DimensionManager::refreshManager() { |
220 |
refTableModel->clear(); |
refTableModel->clear(); |
221 |
for (int i = 0; i < region->Dimensions; i++) { |
if (region) { |
222 |
gig::dimension_def_t* dim = ®ion->pDimensionDefinitions[i]; |
for (int i = 0; i < region->Dimensions; i++) { |
223 |
Gtk::TreeModel::Row row = *(refTableModel->append()); |
gig::dimension_def_t* dim = ®ion->pDimensionDefinitions[i]; |
224 |
row[tableModel.m_dim_type] = __dimTypeAsString(dim->dimension); |
Gtk::TreeModel::Row row = *(refTableModel->append()); |
225 |
row[tableModel.m_bits] = dim->bits; |
row[tableModel.m_dim_type] = __dimTypeAsString(dim->dimension); |
226 |
row[tableModel.m_zones] = 1 << dim->bits; //TODO: for now we calculate it here until libgig always ensures 'zones' to be correct |
row[tableModel.m_bits] = dim->bits; |
227 |
row[tableModel.m_description] = __dimDescriptionAsString(dim->dimension); |
row[tableModel.m_zones] = 1 << dim->bits; //TODO: for now we calculate it here until libgig always ensures 'zones' to be correct |
228 |
row[tableModel.m_definition] = dim; |
row[tableModel.m_description] = __dimDescriptionAsString(dim->dimension); |
229 |
|
row[tableModel.m_definition] = dim; |
230 |
|
} |
231 |
} |
} |
232 |
|
set_sensitive(region); |
233 |
} |
} |
234 |
|
|
235 |
void DimensionManager::show(gig::Region* region) { |
void DimensionManager::show(gig::Region* region) { |
239 |
deiconify(); |
deiconify(); |
240 |
} |
} |
241 |
|
|
242 |
|
void DimensionManager::set_region(gig::Region* region) { |
243 |
|
this->region = region; |
244 |
|
refreshManager(); |
245 |
|
} |
246 |
|
|
247 |
void DimensionManager::addDimension() { |
void DimensionManager::addDimension() { |
248 |
try { |
try { |
249 |
Gtk::Dialog dialog("New Dimension", true /*modal*/); |
Gtk::Dialog dialog("New Dimension", true /*modal*/); |
292 |
"Adding dimension (type=0x%x, bits=%d, zones=%d)\n", |
"Adding dimension (type=0x%x, bits=%d, zones=%d)\n", |
293 |
dim.dimension, dim.bits, dim.zones |
dim.dimension, dim.bits, dim.zones |
294 |
); |
); |
295 |
|
// notify everybody that we're going to update the region |
296 |
|
region_to_be_changed_signal.emit(region); |
297 |
// add the new dimension to the region |
// add the new dimension to the region |
298 |
// (implicitly creates new dimension regions) |
// (implicitly creates new dimension regions) |
299 |
region->AddDimension(&dim); |
region->AddDimension(&dim); |
300 |
// let everybody know there was a change |
// let everybody know there was a change |
301 |
articulation_changed_signal.emit(); |
region_changed_signal.emit(region); |
302 |
// update all GUI elements |
// update all GUI elements |
303 |
refreshManager(); |
refreshManager(); |
304 |
} |
} |
305 |
} catch (RIFF::Exception e) { |
} catch (RIFF::Exception e) { |
306 |
|
// notify that the changes are over (i.e. to avoid dead locks) |
307 |
|
region_changed_signal.emit(region); |
308 |
|
// show error message |
309 |
Glib::ustring txt = "Could not add dimension: " + e.Message; |
Glib::ustring txt = "Could not add dimension: " + e.Message; |
310 |
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
311 |
msg.run(); |
msg.run(); |
317 |
Gtk::TreeModel::iterator it = sel->get_selected(); |
Gtk::TreeModel::iterator it = sel->get_selected(); |
318 |
if (it) { |
if (it) { |
319 |
try { |
try { |
320 |
|
// notify everybody that we're going to update the region |
321 |
|
region_to_be_changed_signal.emit(region); |
322 |
// remove selected dimension |
// remove selected dimension |
323 |
Gtk::TreeModel::Row row = *it; |
Gtk::TreeModel::Row row = *it; |
324 |
gig::dimension_def_t* dim = row[tableModel.m_definition]; |
gig::dimension_def_t* dim = row[tableModel.m_definition]; |
325 |
region->DeleteDimension(dim); |
region->DeleteDimension(dim); |
|
// remove respective row from table |
|
|
refTableModel->erase(it); |
|
326 |
// let everybody know there was a change |
// let everybody know there was a change |
327 |
articulation_changed_signal.emit(); |
region_changed_signal.emit(region); |
328 |
|
// update all GUI elements |
329 |
|
refreshManager(); |
330 |
} catch (RIFF::Exception e) { |
} catch (RIFF::Exception e) { |
331 |
|
// notify that the changes are over (i.e. to avoid dead locks) |
332 |
|
region_changed_signal.emit(region); |
333 |
|
// show error message |
334 |
Glib::ustring txt = "Could not remove dimension: " + e.Message; |
Glib::ustring txt = "Could not remove dimension: " + e.Message; |
335 |
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
336 |
msg.run(); |
msg.run(); |