aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-11-11 17:23:40 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-11-11 17:23:40 +0000
commitc2c4ec5e8e44b82e329dcec15f32ae6480e66634 (patch)
tree533c11215252a9759634f6d59e72a14aab2f4305
parent8f27e941a16cc0bada04630c3d915aa89d181e85 (diff)
downloadpaludis-c2c4ec5e8e44b82e329dcec15f32ae6480e66634.tar.gz
paludis-c2c4ec5e8e44b82e329dcec15f32ae6480e66634.tar.xz
More work on CellRendererButton
-rw-r--r--src/gtkpaludis/cellrendererbutton/cellrendererbutton.cc71
-rw-r--r--src/gtkpaludis/cellrendererbutton/cellrendererbutton.hh39
-rw-r--r--src/gtkpaludis/queue_list.cc6
-rw-r--r--src/gtkpaludis/queue_options.cc18
-rw-r--r--src/gtkpaludis/tasks_page.cc3
5 files changed, 120 insertions, 17 deletions
diff --git a/src/gtkpaludis/cellrendererbutton/cellrendererbutton.cc b/src/gtkpaludis/cellrendererbutton/cellrendererbutton.cc
index c7a6ab1..4104663 100644
--- a/src/gtkpaludis/cellrendererbutton/cellrendererbutton.cc
+++ b/src/gtkpaludis/cellrendererbutton/cellrendererbutton.cc
@@ -38,12 +38,26 @@ namespace
}
}
-CellRendererButton::CellRendererButton() :
+CellRendererButton::CellRendererButton(Gtk::TreeView & owner) :
Glib::ObjectBase(typeid(CellRendererButton)),
- Gtk::CellRendererText()
+ Gtk::CellRendererText(),
+ _owner(&owner),
+ _column(0),
+ _temporary_highlight_hack(false),
+ _property_text_x_pad(*this, "text-x-pad", 4),
+ _property_text_y_pad(*this, "text-y-pad", 4)
{
property_alignment() = Pango::ALIGN_CENTER;
property_xalign() = 0.5;
+
+ _owner->add_events(Gdk::POINTER_MOTION_MASK | Gdk::BUTTON_MOTION_MASK |
+ Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK | Gdk::ENTER_NOTIFY_MASK |
+ Gdk::LEAVE_NOTIFY_MASK);
+
+ _owner->signal_button_press_event().connect(sigc::mem_fun(
+ this, &CellRendererButton::_button_pressed), false);
+ _owner->signal_motion_notify_event().connect(sigc::mem_fun(
+ this, &CellRendererButton::_motion_notify), false);
}
CellRendererButton::~CellRendererButton()
@@ -57,8 +71,8 @@ CellRendererButton::get_size_vfunc(Gtk::Widget & widget, const Gdk::Rectangle *
Gtk::CellRendererText::get_size_vfunc(widget, cell_area, x_offset, y_offset,
width, height);
- const unsigned int x_pad = 4;
- const unsigned int y_pad = 4;
+ const unsigned int x_pad = _property_text_x_pad.get_value();
+ const unsigned int y_pad = _property_text_y_pad.get_value();
const float x_align = property_xalign();
const float y_align = property_yalign();
@@ -102,14 +116,13 @@ CellRendererButton::render_vfunc(const Glib::RefPtr<Gdk::Drawable> & window,
if (flags & Gtk::CELL_RENDERER_SELECTED)
state = widget.has_focus() ? Gtk::STATE_SELECTED : Gtk::STATE_ACTIVE;
#else
- Gtk::StateType state(Gtk::STATE_ACTIVE);
+ Gtk::StateType state(_temporary_highlight_hack ? Gtk::STATE_SELECTED : Gtk::STATE_ACTIVE);
#endif
- const Gtk::ShadowType shadow = Gtk::SHADOW_OUT;
Glib::RefPtr<Gdk::Window> window_casted = Glib::RefPtr<Gdk::Window>::cast_dynamic<>(window);
if (window_casted)
{
- widget.get_style()->paint_box(window_casted, state, shadow, cell_area,
+ widget.get_style()->paint_box(window_casted, state, Gtk::SHADOW_OUT, cell_area,
widget, "button", cell_area.get_x() + x_offset + cell_x_pad,
cell_area.get_y() + y_offset + cell_y_pad, width - 1, height - 1);
@@ -130,3 +143,47 @@ CellRendererButton::activate_vfunc(GdkEvent *, Gtk::Widget &,
return false;
}
+bool
+CellRendererButton::_button_pressed(GdkEventButton * event)
+{
+ if (! (event->type & GDK_BUTTON_PRESS && event->button == 1))
+ return false;
+
+ return true;
+}
+
+bool
+CellRendererButton::_motion_notify(GdkEventMotion * event)
+{
+ Gtk::TreeModel::Path path, old_focused_path(_focused_path);
+ Gtk::TreeViewColumn * column;
+ int cell_x, cell_y;
+ if (_owner->get_path_at_pos(static_cast<int>(event->x), static_cast<int>(event->y),
+ path, column, cell_x, cell_y)
+ && (_column && column == _column))
+ _focused_path = path;
+ else
+ _focused_path = Gtk::TreePath();
+
+ _temporary_highlight_hack = ! _focused_path.empty();
+
+ /* path comparisons are a bit weird */
+ if (old_focused_path.empty() && ! _focused_path.empty())
+ _owner->queue_draw();
+ else if (_focused_path.empty() && ! old_focused_path.empty())
+ _owner->queue_draw();
+ else if (_focused_path.empty() && old_focused_path.empty())
+ {
+ /* nothing */
+ }
+ else if (old_focused_path != _focused_path)
+ _owner->queue_draw();
+ return false;
+}
+
+void
+CellRendererButton::set_column(Gtk::TreeViewColumn * const column)
+{
+ _column = column;
+}
+
diff --git a/src/gtkpaludis/cellrendererbutton/cellrendererbutton.hh b/src/gtkpaludis/cellrendererbutton/cellrendererbutton.hh
index 3da4791..7aec3dd 100644
--- a/src/gtkpaludis/cellrendererbutton/cellrendererbutton.hh
+++ b/src/gtkpaludis/cellrendererbutton/cellrendererbutton.hh
@@ -21,6 +21,7 @@
#define PALUDIS_GUARD_SRC_GTKPALUDIS_CELLRENDERERBUTTON_HH 1
#include <gtkmm/cellrenderertext.h>
+#include <gtkmm/treeview.h>
namespace gtkpaludis
{
@@ -32,6 +33,19 @@ namespace gtkpaludis
class CellRendererButton :
public Gtk::CellRendererText
{
+ private:
+ bool _button_pressed(GdkEventButton *);
+ bool _motion_notify(GdkEventMotion *);
+
+ Gtk::TreeView * const _owner;
+ Gtk::TreeModel::Path _focused_path;
+ Gtk::TreeViewColumn * _column;
+
+ bool _temporary_highlight_hack;
+
+ Glib::Property<unsigned int> _property_text_x_pad;
+ Glib::Property<unsigned int> _property_text_y_pad;
+
protected:
virtual void get_size_vfunc(Gtk::Widget & widget, const Gdk::Rectangle * cell_area,
int * x_offset, int * y_offset, int * width, int * height) const;
@@ -46,8 +60,31 @@ namespace gtkpaludis
const Gdk::Rectangle & cell_area, Gtk::CellRendererState flags);
public:
- CellRendererButton();
+ CellRendererButton(Gtk::TreeView & owner);
virtual ~CellRendererButton();
+ void set_column(Gtk::TreeViewColumn * const column);
+
+ Glib::PropertyProxy<unsigned int> property_text_x_pad()
+ {
+ return _property_text_x_pad.get_proxy();
+ }
+
+ Glib::PropertyProxy_ReadOnly<unsigned int> property_text_x_pad() const
+ {
+ return Glib::PropertyProxy_ReadOnly<unsigned int>(this,
+ "text-x-pad");
+ }
+
+ Glib::PropertyProxy<unsigned int> property_text_y_pad()
+ {
+ return _property_text_y_pad.get_proxy();
+ }
+
+ Glib::PropertyProxy_ReadOnly<unsigned int> property_text_y_pad() const
+ {
+ return Glib::PropertyProxy_ReadOnly<unsigned int>(this,
+ "text-y-pad");
+ }
};
}
diff --git a/src/gtkpaludis/queue_list.cc b/src/gtkpaludis/queue_list.cc
index dd79238..d520df0 100644
--- a/src/gtkpaludis/queue_list.cc
+++ b/src/gtkpaludis/queue_list.cc
@@ -192,10 +192,14 @@ QueueList::set_model_show_dep_columns(Glib::RefPtr<Gtk::ListStore> new_model)
append_column("Use", _imp->columns.col_use);
append_column("Tags", _imp->columns.col_tags);
{
- CellRendererButton * const renderer = new CellRendererButton;
+ CellRendererButton * const renderer = new CellRendererButton(*this);
+ renderer->property_text_x_pad() = 0;
+ renderer->property_text_y_pad() = 0;
+
Gtk::TreeViewColumn * const column = new Gtk::TreeViewColumn("Why",
*Gtk::manage(renderer));
column->add_attribute(renderer->property_text(), _imp->columns.col_why);
+ renderer->set_column(column);
append_column(*column);
}
diff --git a/src/gtkpaludis/queue_options.cc b/src/gtkpaludis/queue_options.cc
index cf8749c..5b18d43 100644
--- a/src/gtkpaludis/queue_options.cc
+++ b/src/gtkpaludis/queue_options.cc
@@ -89,13 +89,14 @@ namespace paludis
namespace
{
void
- populate_deps_box(Gtk::ComboBoxText & box)
+ populate_deps_box(Gtk::ComboBoxText & box, const std::string & def)
{
box.append_text("Pre");
box.append_text("Pre or post");
box.append_text("Post");
box.append_text("Try post");
box.append_text("Discard");
+ box.set_active_text(def);
}
}
@@ -129,12 +130,15 @@ QueueOptions::QueueOptions() :
_imp->reinstall_box.append_text("Never");
_imp->reinstall_box.append_text("Always");
_imp->reinstall_box.append_text("If USE changed");
+ _imp->reinstall_box.set_active_text("Never");
_imp->circular_box.append_text("Error");
_imp->circular_box.append_text("Discard");
+ _imp->circular_box.set_active_text("Error");
_imp->upgrade_box.append_text("Always");
_imp->upgrade_box.append_text("As needed");
+ _imp->upgrade_box.set_active_text("Always");
append_page(_imp->dependencies_page, "Dependencies");
_imp->dependencies_page.attach(_imp->uninstalled_deps_frame, 0, 1, 0, 1);
@@ -180,13 +184,13 @@ QueueOptions::QueueOptions() :
_imp->installed_deps_table.attach(_imp->installed_deps_post_box, 1, 2, 2, 3,
Gtk::EXPAND | Gtk::FILL, Gtk::AttachOptions(0));
- populate_deps_box(_imp->installed_deps_pre_box);
- populate_deps_box(_imp->installed_deps_runtime_box);
- populate_deps_box(_imp->installed_deps_post_box);
+ populate_deps_box(_imp->installed_deps_pre_box, "Discard");
+ populate_deps_box(_imp->installed_deps_runtime_box, "Try post");
+ populate_deps_box(_imp->installed_deps_post_box, "Try post");
- populate_deps_box(_imp->uninstalled_deps_pre_box);
- populate_deps_box(_imp->uninstalled_deps_runtime_box);
- populate_deps_box(_imp->uninstalled_deps_post_box);
+ populate_deps_box(_imp->uninstalled_deps_pre_box, "Pre");
+ populate_deps_box(_imp->uninstalled_deps_runtime_box, "Pre or post");
+ populate_deps_box(_imp->uninstalled_deps_post_box, "Post");
}
QueueOptions::~QueueOptions()
diff --git a/src/gtkpaludis/tasks_page.cc b/src/gtkpaludis/tasks_page.cc
index 737910f..6870bdc 100644
--- a/src/gtkpaludis/tasks_page.cc
+++ b/src/gtkpaludis/tasks_page.cc
@@ -72,11 +72,12 @@ namespace
set_fixed_size(40, 40);
get_column(append_column("Text", columns.col_text) - 1)->set_expand(true);
- CellRendererButton * const renderer = new CellRendererButton;
+ CellRendererButton * const renderer = new CellRendererButton(*this);
Gtk::TreeViewColumn * const column = new Gtk::TreeViewColumn("Button",
*Gtk::manage(renderer));
column->add_attribute(renderer->property_text(), columns.col_button);
renderer->property_width_chars() = 10;
+ renderer->set_column(column);
append_column(*column);
}