checkbutton.cc 2.87 KB
Newer Older
1 2
/* Glom
 *
3
 * Copyright (C) 2008 Openismus GmbH
4 5 6 7 8 9 10 11 12 13 14 15 16
 *
 * 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
17 18
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301 USA.
19 20
 */

21
#include "checkbutton.h"
22
#include <gtkmm/messagedialog.h>
23
#include <glom/dialog_invalid_data.h>
24
#include <glom/appwindow.h>
25 26 27 28

namespace Glom
{

29 30 31 32
namespace DataWidgetChildren
{

CheckButton::CheckButton(const Glib::ustring& title)
33 34 35
  : Gtk::CheckButton(title)
{
#ifndef GLOM_ENABLE_CLIENT_ONLY
36
  setup_menu(this);
37 38 39 40
#endif // !GLOM_ENABLE_CLIENT_ONLY
}

#ifndef GLOM_ENABLE_CLIENT_ONLY
41
bool CheckButton::on_button_press_event(GdkEventButton *button_event)
42 43
{
  //Enable/Disable items.
44
  //We did this earlier, but get_appwindow is more likely to work now:
Murray Cumming's avatar
Murray Cumming committed
45
  auto pApp = get_appwindow();
46 47
  if(pApp)
  {
48 49 50 51
    pApp->add_developer_action(m_context_layout); //So that it can be disabled when not in developer mode.
    pApp->add_developer_action(m_context_add_field);
    pApp->add_developer_action(m_context_add_related_records);
    pApp->add_developer_action(m_context_add_group);
52

Murray Cumming's avatar
Murray Cumming committed
53
    pApp->update_userlevel_ui(); //Update our action's sensitivity.
54

55
    //Only show this popup in developer mode, so operators still see the default GtkCheckButton context menu.
56
    //TODO: It would be better to add it somehow to the standard context menu.
57
    if(pApp->get_userlevel() == AppState::userlevels::DEVELOPER)
58 59
    {
      GdkModifierType mods;
Murray Cumming's avatar
Murray Cumming committed
60
      gdk_window_get_device_position( gtk_widget_get_window (Gtk::Widget::gobj()), button_event->device, nullptr, nullptr, &mods );
61 62 63
      if(mods & GDK_BUTTON3_MASK)
      {
        //Give user choices of actions on this item:
64
        m_menu_popup->popup_at_pointer((GdkEvent*)button_event);
65 66 67 68
        return true; //We handled this event.
      }
    }
  }
69
  return Gtk::CheckButton::on_button_press_event(button_event);
70 71 72
}
#endif // !GLOM_ENABLE_CLIENT_ONLY

73
AppWindow* CheckButton::get_appwindow() const
74
{
Murray Cumming's avatar
Murray Cumming committed
75
  auto pWindow = const_cast<Gtk::Container*>(get_toplevel());
76 77
  //TODO: This only works when the child widget is already in its parent.

78
  return dynamic_cast<AppWindow*>(pWindow);
79 80
}

81
void CheckButton::set_value(const Gnome::Gda::Value& value)
82 83 84 85
{
  set_active (value.get_boolean());
}

86
Gnome::Gda::Value CheckButton::get_value() const
87 88 89 90
{
  return Gnome::Gda::Value(get_active());
}

91
} //namespace DataWidetChildren
92
} //namespace Glom