box_data_calendar_related.cc 21.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/* Glom
 *
 * Copyright (C) 2001-2004 Murray Cumming
 *
 * 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; either version 2 of the
 * License, or (at your option) any later version.
 *
 * 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., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

21
#include <glom/mode_data/box_data_calendar_related.h>
22
#include <glom/mode_design/layout/dialog_layout_calendar_related.h>
23
#include <glom/utils_ui.h>
24
#include <glom/application.h>
25
#include <libglom/data_structure/glomconversions.h>
26 27 28 29 30 31
#include <glom/frame_glom.h> //For show_ok_dialog()
#include <glibmm/i18n.h>

namespace Glom
{

32
Box_Data_Calendar_Related::Box_Data_Calendar_Related()
33 34
: m_pMenuPopup(0),
  m_query_column_date_field(-1)
35 36 37
{
  set_size_request(400, -1); //An arbitrary default.

38 39 40
  m_Alignment.add(m_calendar);
  m_calendar.show();
  
41 42 43 44
  //m_calendar.set_show_details();
  m_calendar.set_detail_width_chars(7);
  m_calendar.set_detail_height_rows(2); 
  
45 46 47
  //Tell the calendar how to get the record details to show:
  m_calendar.set_detail_func( sigc::mem_fun(*this, &Box_Data_Calendar_Related::on_calendar_details) );
  
48 49
  m_calendar.signal_month_changed().connect( sigc::mem_fun(*this, &Box_Data_Calendar_Related::on_calendar_month_changed) );
  
50 51 52
  setup_menu();
  //m_calendar.add_events(Gdk::BUTTON_PRESS_MASK); //Allow us to catch button_press_event and button_release_event
  m_calendar.signal_button_press_event().connect_notify( sigc::mem_fun(*this, &Box_Data_Calendar_Related::on_calendar_button_press_event) );
53

54
  m_layout_name = "list_related_calendar"; //TODO: We need a unique name when 2 portals use the same table.
55 56
}

57 58 59 60 61
Box_Data_Calendar_Related::~Box_Data_Calendar_Related()
{
  clear_cached_database_values();
}

62
void Box_Data_Calendar_Related::enable_buttons()
63
{
64 65
  //const bool view_details_possible = get_has_suitable_record_to_view_details();
  //m_calendar.set_allow_view_details(view_details_possible); //Don't allow the user to go to a record in a hidden table.
66 67
}

68
bool Box_Data_Calendar_Related::init_db_details(const sharedptr<const LayoutItem_Portal>& portal, bool show_title)
69
{
70 71 72
  //This calls the other method overload:
  return Box_Data_Portal::init_db_details(portal, show_title);
}
73

74 75 76
bool Box_Data_Calendar_Related::init_db_details(const Glib::ustring& parent_table, bool show_title)
{
  //std::cout << "DEBUG: Box_Data_Calendar_Related::init_db_details(): " << parent_table << std::endl;
77

78 79 80 81 82 83 84 85 86 87
  m_parent_table = parent_table;

  if(m_portal)
    LayoutWidgetBase::m_table_name = m_portal->get_table_used(Glib::ustring() /* parent table_name, not used. */); 
  else
    LayoutWidgetBase::m_table_name = Glib::ustring();

  Base_DB_Table::m_table_name = LayoutWidgetBase::m_table_name;

  //TODO: This is duplicated in box_data_related_list.cc and box_data_portal.cc. Just use code from the base class?
88 89
  if(show_title)
  {
90 91 92 93 94 95 96 97 98
    Glib::ustring relationship_title;
    if(m_portal && m_portal->get_has_relationship_name())
      relationship_title = m_portal->get_title_used(Glib::ustring() /* parent title - not relevant */);
    else
    {
      //Note to translators: This text is shown instead of a table title, when the table has not yet been chosen.
      relationship_title = _("Undefined Table");
    }

Murray Cumming's avatar
Murray Cumming committed
99
    m_Label.set_markup(Utils::bold_message(relationship_title));
100 101 102 103 104 105 106 107 108 109 110 111
    m_Label.show();

    m_Alignment.set_padding(Utils::DEFAULT_SPACING_SMALL /* top */, 0, Utils::DEFAULT_SPACING_LARGE /* left */, 0);
  }
  else
  {
    m_Label.set_markup(Glib::ustring());
    m_Label.hide();

    m_Alignment.set_padding(0, 0, 0, 0); //The box itself has padding of 6.
  }

112 113 114 115
  if(m_portal)
    m_key_field = get_fields_for_table_one_field(LayoutWidgetBase::m_table_name, m_portal->get_to_field_used());
  else
    m_key_field.clear();
116 117 118 119 120

  enable_buttons();

  FoundSet found_set;
  found_set.m_table_name = LayoutWidgetBase::m_table_name;
121
  return Box_Data::init_db_details(found_set, "" /* layout_platform */); //Calls create_layout() and fill_from_database().
122 123
}

124
bool Box_Data_Calendar_Related::fill_from_database()
125
{
126 127 128
  if(!m_portal)
    return false;
  
129 130 131 132 133 134
  bool result = false;

  if(m_key_field && m_found_set.m_where_clause.empty()) //There's a key field, but no value.
  {
    //No Foreign Key value, so just show the field names:

135
    result = Base_DB_Table_Data::fill_from_database();
136 137 138 139 140

    //create_layout();
  }
  else
  {
141 142 143 144 145 146 147 148 149 150 151 152
    if(m_query_column_date_field == -1)
      return false; //This is useless without the date in the result.
       
    //Create a date range from the beginning to end of the selected month:
    Glib::Date calendar_date;
    m_calendar.get_date(calendar_date);
    const Glib::Date date_start(1, calendar_date.get_month(), calendar_date.get_year());
    Glib::Date date_end = date_start;
    date_end.add_months(1);
    
    Gnome::Gda::Value date_start_value(date_start);
    Gnome::Gda::Value date_end_value(date_end);
153

154 155 156 157 158 159 160 161 162
    //Add a WHERE clause for this date range:
    sharedptr<Relationship> relationship = m_portal->get_relationship();
    Glib::ustring where_clause_to_table_name = relationship->get_to_table();
  
    sharedptr<LayoutItem_CalendarPortal> derived_portal = sharedptr<LayoutItem_CalendarPortal>::cast_dynamic(m_portal);
    const Glib::ustring date_field_name = derived_portal->get_date_field()->get_name();
    
    sharedptr<const Relationship> relationship_related = m_portal->get_related_relationship();
    if(relationship_related)
163
    {
164 165 166 167
      //Adjust the WHERE clause appropriately for the extra JOIN:
      sharedptr<UsesRelationship> uses_rel_temp = sharedptr<UsesRelationship>::create();
      uses_rel_temp->set_relationship(relationship);
      where_clause_to_table_name = uses_rel_temp->get_sql_join_alias_name();
168 169
    }

170 171
    //Add an AND to the existing where clause, to get only records within these dates, if any:
    sharedptr<const Field> date_field = derived_portal->get_date_field();
172
    //TODO: Use a SQL parameter instead of using sql().
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
    const Glib::ustring extra_where_clause = "\"" + where_clause_to_table_name + "\".\"" + date_field->get_name() + "\""
      " BETWEEN DATE " + date_field->sql(date_start_value) + 
      " AND DATE " + date_field->sql(date_end_value);
    
    Glib::ustring where_clause;
    if(m_found_set.m_where_clause.empty())
      where_clause = extra_where_clause;
    else
      where_clause = "( " + m_found_set.m_where_clause + " ) AND ( " + extra_where_clause + " )";
    
    
    //Do one SQL query for the whole month and store the cached values here:
    clear_cached_database_values();
    
    const Glib::ustring sql_query = Utils::build_sql_select_with_where_clause(m_found_set.m_table_name, m_FieldsShown, where_clause, m_found_set.m_extra_join, m_found_set.m_sort_clause, m_found_set.m_extra_group_by);
    //std::cout << "DEBUG: sql_query=" << sql_query << std::endl;
189
    Glib::RefPtr<Gnome::Gda::DataModel> datamodel = query_execute_select(sql_query);
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
    if(!(datamodel))
      return true;
    
    const int rows_count = datamodel->get_n_rows();
    if(!(rows_count > 0))
      return true;
    
    //Get the data:
    for(int row_index = 0; row_index < rows_count; ++row_index)
    {
      const int columns_count = datamodel->get_n_columns();
      if(m_query_column_date_field > columns_count)
       continue;
       
      //Get the date value for this row:
205 206 207 208 209 210
#ifdef GLIBMM_EXCEPTIONS_ENABLED      
      Gnome::Gda::Value value_date = datamodel->get_value_at(m_query_column_date_field, row_index);
#else
      std::auto_ptr<Glib::Error> error;      
      Gnome::Gda::Value value_date = datamodel->get_value_at(m_query_column_date_field, row_index, error);
#endif      
211 212 213 214 215 216
      const Glib::Date date = value_date.get_date();
      
      //Get all the values for this row:
      type_vector_values* pVector = new type_vector_values(m_FieldsShown.size());
      for(int column_index = 0; column_index < columns_count; ++column_index)
      {
217
#ifdef GLIBMM_EXCEPTIONS_ENABLED 
218
        (*pVector)[column_index] = datamodel->get_value_at(column_index, row_index);
219 220 221 222 223 224
#else
        std::auto_ptr<Glib::Error> error;      
          (*pVector)[column_index] = datamodel->get_value_at(column_index, row_index, error);
        if (error.get())
          break;
#endif 
225 226 227 228
      }
      
      m_map_values[date].push_back(pVector);
    }
229 230
  }

231
 
232 233 234
  return result;
}

235 236 237 238 239 240 241 242 243 244 245 246 247 248 249
void Box_Data_Calendar_Related::clear_cached_database_values()
{
  for(type_map_values::iterator iter = m_map_values.begin(); iter != m_map_values.end(); ++iter)
  {
    type_list_vectors vec = iter->second;
    for(type_list_vectors::iterator iter = vec.begin(); iter != vec.end(); ++iter)
    {
      type_vector_values* pValues = *iter;
      if(pValues)
        delete pValues;
    }
  }
  
  m_map_values.clear(); 
}
250 251

//TODO: Make this generic in Box_Data_Portal:
252
void Box_Data_Calendar_Related::on_record_added(const Gnome::Gda::Value& primary_key_value, const Gtk::TreeModel::iterator& row)
253 254 255 256 257 258 259 260 261 262 263 264 265 266
{
  //primary_key_value is a new autogenerated or human-entered key for the row.
  //It has already been added to the database.

  if(!row)
    return;

  Gnome::Gda::Value key_value;

  if(m_key_field)
  {
    //m_key_field is the field in this table that must match another field in the parent table.
    sharedptr<LayoutItem_Field> layout_item = sharedptr<LayoutItem_Field>::create();
    layout_item->set_full_field_details(m_key_field);
267
    //TODO: key_value = m_calendar.get_value(row, layout_item);
268 269 270 271 272 273 274 275 276 277 278 279
  }

  //Make sure that the new related record is related,
  //by setting the foreign key:
  //If it's not auto-generated.
  if(!Conversions::value_is_empty(key_value)) //If there is already a value.
  {
    //It was auto-generated. Tell the parent about it, so it can make a link.
    signal_record_added.emit(key_value);
  }
  else if(Conversions::value_is_empty(m_key_value))
  {
280
    g_warning("Box_Data_Calendar_Related::on_record_added(): m_key_value is NULL.");
281 282 283
  }
  else
  {
284
    sharedptr<Field> field_primary_key; //TODO: = m_calendar.get_key_field();
285 286

    //Create the link by setting the foreign key
287
    if(m_key_field && m_portal)
288
    {
289 290 291
      Glib::RefPtr<Gnome::Gda::Set> params = Gnome::Gda::Set::create();
      params->add_holder(m_key_field->get_holder(m_key_value));
      params->add_holder(field_primary_key->get_holder(primary_key_value));
292
      Glib::ustring strQuery = "UPDATE \"" + m_portal->get_table_used(Glib::ustring() /* not relevant */) + "\"";
293 294 295
      strQuery += " SET \"" +  /* get_table_name() + "." +*/ m_key_field->get_name() + "\" = " + m_key_field->get_gda_holder_string();
      strQuery += " WHERE \"" + get_table_name() + "\".\"" + field_primary_key->get_name() + "\" = " + field_primary_key->get_gda_holder_string();
      const bool test = query_execute(strQuery, params);
296 297 298 299 300 301
      if(test)
      {
        //Show it on the view, if it's visible:
        sharedptr<LayoutItem_Field> layout_item = sharedptr<LayoutItem_Field>::create();
        layout_item->set_full_field_details(field_primary_key);

302
        //TODO: m_calendar.set_value(row, layout_item, m_key_value);
303 304 305 306 307 308 309
      }
    }

    //on_adddel_user_changed(row, iKey); //Update the database.
  }
}

310
Box_Data_Calendar_Related::type_vecLayoutFields Box_Data_Calendar_Related::get_fields_to_show() const
311
{
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327
  type_vecLayoutFields layout_fields = Box_Data_Portal::get_fields_to_show();
  
  sharedptr<LayoutItem_CalendarPortal> derived_portal = sharedptr<LayoutItem_CalendarPortal>::cast_dynamic(m_portal);
  if(!derived_portal)
    return layout_fields;
  
  sharedptr<const Field> date_field = derived_portal->get_date_field();
  if(!date_field)
    return layout_fields;
  
  //Add it to the list to ensure that we request the date (though it will not really be shown in the calendar):
  sharedptr<LayoutItem_Field> layout_item_date_field = sharedptr<LayoutItem_Field>::create();
  layout_item_date_field->set_full_field_details(date_field);
  layout_fields.push_back(layout_item_date_field);
  m_query_column_date_field = layout_fields.size() - 1;
  return layout_fields;
328 329 330
}

#ifndef GLOM_ENABLE_CLIENT_ONLY
331
void Box_Data_Calendar_Related::on_dialog_layout_hide()
332
{
333
  Dialog_Layout_Calendar_Related* dialog_related = dynamic_cast<Dialog_Layout_Calendar_Related*>(m_pDialogLayout);
334
  g_assert(dialog_related);
335
  m_portal = dialog_related->get_portal_layout();
336 337 338


  //Update the UI:
339 340
  sharedptr<LayoutItem_CalendarPortal> derived_portal = sharedptr<LayoutItem_CalendarPortal>::cast_dynamic(m_portal);
  init_db_details(derived_portal); 
341 342 343

  Box_Data::on_dialog_layout_hide();

344
  sharedptr<LayoutItem_CalendarPortal> pLayoutItem = sharedptr<LayoutItem_CalendarPortal>::cast_dynamic(get_layout_item());
345 346
  if(pLayoutItem)
  {
347 348 349 350
    sharedptr<LayoutItem_CalendarPortal> derived_portal = sharedptr<LayoutItem_CalendarPortal>::cast_dynamic(m_portal);
    if(derived_portal)
      *pLayoutItem = *derived_portal;
    
351 352 353 354 355
    signal_layout_changed().emit(); //TODO: Check whether it has really changed.
  }
}
#endif // !GLOM_ENABLE_CLIENT_ONLY

356
#ifndef GLOM_ENABLE_CLIENT_ONLY
357
Dialog_Layout* Box_Data_Calendar_Related::create_layout_dialog() const
358
{
359 360 361
  Glib::RefPtr<Gtk::Builder> refXml = Gtk::Builder::create_from_file(
      GLOM_PKGDATADIR G_DIR_SEPARATOR_S "glade" G_DIR_SEPARATOR_S "glom_developer.glade",
      "window_data_layout");
362 363
  if(refXml)
  {
364
    Dialog_Layout_Calendar_Related* dialog = 0;
365 366
    refXml->get_widget_derived("window_data_layout", dialog);
    return dialog;
367 368
  }

369
  return 0;
370 371 372 373 374
}

void Box_Data_Calendar_Related::prepare_layout_dialog(Dialog_Layout* dialog)
{
  Dialog_Layout_Calendar_Related* related_dialog = dynamic_cast<Dialog_Layout_Calendar_Related*>(dialog);
375
  g_assert(related_dialog);
376 377
  
  sharedptr<LayoutItem_CalendarPortal> derived_portal = sharedptr<LayoutItem_CalendarPortal>::cast_dynamic(m_portal);
378 379
  if(derived_portal && derived_portal->get_has_relationship_name())
  {
380
    related_dialog->set_document(m_layout_name, m_layout_platform, get_document(), derived_portal);
381 382 383
  }
  else
  {
384
    related_dialog->set_document(m_layout_name, m_layout_platform, get_document(), m_parent_table);
385
  }
386
}
387
#endif // !GLOM_ENABLE_CLIENT_ONLY
388

389 390 391 392 393 394
void Box_Data_Calendar_Related::on_calendar_month_changed()
{
  //Update the cached values for the new month:
  fill_from_database();
}

395 396 397
Glib::ustring Box_Data_Calendar_Related::on_calendar_details(guint year, guint month, guint day)
{
  sharedptr<LayoutItem_CalendarPortal> derived_portal = sharedptr<LayoutItem_CalendarPortal>::cast_dynamic(m_portal);
398
  if(!derived_portal)
399
  {
400
    //std::cout << "DEBUG: Box_Data_Calendar_Related::on_calendar_details(): date_field is NULL" << std::endl;
401 402 403
    return Glib::ustring();
  }
  
404 405 406 407
  sharedptr<const Field> date_field = derived_portal->get_date_field();
  if(!date_field)
    return Glib::ustring();
  
408 409 410 411 412 413 414 415
  //TODO: month seems to be 143710360 sometimes, which seems to be a GtkCalendar bug:
  //std::cout << "Box_Data_Calendar_Related::on_calendar_details(): year=" << year << ", month=" << month << " day=" << day << std::endl;

  //Glib::Date is 1-indexed:
  Glib::Date::Month datemonth = (Glib::Date::Month)(month +1);
  if(datemonth > Glib::Date::DECEMBER)
    datemonth = Glib::Date::JANUARY;
  Glib::Date date(day, datemonth, year);
416
  
417 418 419 420 421
  //Examine the cached data:
  type_map_values::const_iterator iter_find = m_map_values.find(date);
  if(iter_find == m_map_values.end())
    return Glib::ustring(); //No data was found for this date.
  
422 423
  
  Glib::ustring result;
424 425 426 427
  
  //Look at each row for this date:
  const type_list_vectors& rows = iter_find->second;
  for(type_list_vectors::const_iterator iter = rows.begin(); iter != rows.end(); ++iter)
428
  {
429 430 431
    type_vector_values* pRow = *iter;
    if(!pRow)
      continue;
432
    
433 434 435
    //Get the data for each column in the row:
    Glib::ustring row_text;
    int column_index = 0;
436
    
437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453
    //We iterate over the original list of items from the portal,
    //instead of the ones used by the query (m_FieldsShown),
    //because we really don't want to show the extra fields (at the end) to the user:
    LayoutGroup::type_list_items items = m_portal->get_items();
    for(LayoutGroup::type_list_items::const_iterator iter = items.begin(); iter != items.end(); ++iter)
    {   
      sharedptr<const LayoutItem> layout_item = *iter;
      if(!layout_item)
        continue;
            
      Glib::ustring text;
      
      //Text for a text item:
      sharedptr<const LayoutItem_Text> layout_item_text = sharedptr<const LayoutItem_Text>::cast_dynamic(layout_item);
      if(layout_item_text)
        text = layout_item_text->get_text();
      else
454
      {
455 456 457 458
        //Text for a field:
        sharedptr<const LayoutItem_Field> layout_item_field = sharedptr<const LayoutItem_Field>::cast_dynamic(layout_item);
        
        const Gnome::Gda::Value value = (*pRow)[column_index];
459
        text = Conversions::get_text_for_gda_value(layout_item_field->get_glom_type(), value, layout_item_field->get_formatting_used().m_numeric_format);
460
        
461 462
        ++column_index;
      }
463 464 465 466 467 468 469 470 471
      
      //Add the field text to the row:
      if(!text.empty())
      {
        if(!row_text.empty())
          row_text += ", "; //TODO: Internationalization?
      
        row_text += text;
      }
472 473
    }
    
474 475
    //Add the row text to the result:
    if(!row_text.empty())
476 477
    {
      if(!result.empty())
478
        result += "\n";
479
      
480
      result += row_text;
481 482 483
    }
  }
  
484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543
  return result;
}

void Box_Data_Calendar_Related::setup_menu()
{
  m_refActionGroup = Gtk::ActionGroup::create();

  m_refActionGroup->add(Gtk::Action::create("ContextMenu", "Context Menu") );

  m_refContextEdit =  Gtk::Action::create("ContextEdit", Gtk::Stock::EDIT);

  m_refActionGroup->add(m_refContextEdit,
    sigc::mem_fun(*this, &Box_Data_Calendar_Related::on_MenuPopup_activate_Edit) );

#ifndef GLOM_ENABLE_CLIENT_ONLY
  // Don't add ContextLayout in client only mode because it would never
  // be sensitive anyway
  m_refContextLayout =  Gtk::Action::create("ContextLayout", _("Layout"));
  m_refActionGroup->add(m_refContextLayout,
    sigc::mem_fun(*this, &Box_Data_Calendar_Related::on_MenuPopup_activate_layout) );

  //TODO: This does not work until this widget is in a container in the window:
  App_Glom* pApp = get_application();
  if(pApp)
  {
    pApp->add_developer_action(m_refContextLayout); //So that it can be disabled when not in developer mode.
    pApp->update_userlevel_ui(); //Update our action's sensitivity. 
  }
#endif // !GLOM_ENABLE_CLIENT_ONLY

  m_refUIManager = Gtk::UIManager::create();

  m_refUIManager->insert_action_group(m_refActionGroup);

  //TODO: add_accel_group(m_refUIManager->get_accel_group());

#ifdef GLIBMM_EXCEPTIONS_ENABLED
  try
  {
#endif
    Glib::ustring ui_info = 
        "<ui>"
        "  <popup name='ContextMenu'>"
        "    <menuitem action='ContextEdit'/>"
#ifndef GLOM_ENABLE_CLIENT_ONLY
        "    <menuitem action='ContextLayout'/>"
#endif
        "  </popup>"
        "</ui>";

#ifdef GLIBMM_EXCEPTIONS_ENABLED
    m_refUIManager->add_ui_from_string(ui_info);
  }
  catch(const Glib::Error& ex)
  {
    std::cerr << "building menus failed: " <<  ex.what();
  }
#else
  std::auto_ptr<Glib::Error> error;
  m_refUIManager->add_ui_from_string(ui_info, error);
544
  if(error.get())
545 546 547 548 549 550 551 552 553 554 555 556 557 558
  {
    std::cerr << "building menus failed: " << error->what();
  }
#endif //GLIBMM_EXCEPTIONS_ENABLED

  //Get the menu:
  m_pMenuPopup = dynamic_cast<Gtk::Menu*>( m_refUIManager->get_widget("/ContextMenu") ); 
  if(!m_pMenuPopup)
    g_warning("menu not found");

 
#ifndef GLOM_ENABLE_CLIENT_ONLY
  if(pApp)
    m_refContextLayout->set_sensitive(pApp->get_userlevel() == AppState::USERLEVEL_DEVELOPER);
559 560 561
#endif // !GLOM_ENABLE_CLIENT_ONLY
}

562
void Box_Data_Calendar_Related::on_calendar_button_press_event(GdkEventButton *event)
563
{
564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596
#ifndef GLOM_ENABLE_CLIENT_ONLY
  //Enable/Disable items.
  //We did this earlier, but get_application is more likely to work now:
  App_Glom* pApp = get_application();
  if(pApp)
  {
    pApp->add_developer_action(m_refContextLayout); //So that it can be disabled when not in developer mode.
    pApp->update_userlevel_ui(); //Update our action's sensitivity. 
  }
#endif

  GdkModifierType mods;
  gdk_window_get_pointer( Gtk::Widget::gobj()->window, 0, 0, &mods );
  if(mods & GDK_BUTTON3_MASK)
  {
    //Give user choices of actions on this item:
    m_pMenuPopup->popup(event->button, event->time);
    return; //handled.
  }
  else
  {
    if(event->type == GDK_2BUTTON_PRESS)
    {
      //Double-click means edit.
      //Don't do this usually, because users sometimes double-click by accident when they just want to edit a cell.

      //TODO: If the cell is not editable, handle the double-click as an edit/selection.
      //on_MenuPopup_activate_Edit();
      return; //Not handled.
    }
  }

  return; //Not handled. TODO: Call base class?
597 598
}

599 600 601 602 603 604 605 606 607 608 609 610 611 612 613
void
Box_Data_Calendar_Related::on_MenuPopup_activate_Edit()
{
  const Gnome::Gda::Value primary_key_value; //TODO: = m_AddDel.get_value_key(row); //The primary key is in the key.

  signal_user_requested_details().emit(primary_key_value);
}

#ifndef GLOM_ENABLE_CLIENT_ONLY
void Box_Data_Calendar_Related::on_MenuPopup_activate_layout()
{
  show_layout_dialog();
}
#endif // !GLOM_ENABLE_CLIENT_ONLY

614
Gnome::Gda::Value Box_Data_Calendar_Related::get_primary_key_value(const Gtk::TreeModel::iterator& /* row */) const
615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630
{
  return Gnome::Gda::Value(); //TODO: m_AddDel.get_value_key(row);
}

Gnome::Gda::Value Box_Data_Calendar_Related::get_primary_key_value_selected() const
{
  return Gnome::Gda::Value(); //TODO: m_AddDel.get_value_key_selected();
}

void Box_Data_Calendar_Related::set_primary_key_value(const Gtk::TreeModel::iterator& /* row */, const Gnome::Gda::Value& /* value */)
{
  //TODO
}
    


631

632
} //namespace Glom