summaryrefslogtreecommitdiff
path: root/libs/gtkmm2ext
diff options
context:
space:
mode:
Diffstat (limited to 'libs/gtkmm2ext')
-rw-r--r--libs/gtkmm2ext/dndtreeview.cc4
-rw-r--r--libs/gtkmm2ext/gtk_ui.cc15
-rw-r--r--libs/gtkmm2ext/gtkmm2ext/dndtreeview.h107
-rw-r--r--libs/gtkmm2ext/gtkmm2ext/gtk_ui.h6
-rw-r--r--libs/gtkmm2ext/gtkmm2ext/tearoff.h3
-rw-r--r--libs/gtkmm2ext/popup.cc9
-rw-r--r--libs/gtkmm2ext/tearoff.cc33
7 files changed, 113 insertions, 64 deletions
diff --git a/libs/gtkmm2ext/dndtreeview.cc b/libs/gtkmm2ext/dndtreeview.cc
index 2c2e69f6b6..0695dd3281 100644
--- a/libs/gtkmm2ext/dndtreeview.cc
+++ b/libs/gtkmm2ext/dndtreeview.cc
@@ -29,6 +29,8 @@ using namespace Gtk;
using namespace Glib;
using namespace Gtkmm2ext;
+DnDTreeViewBase::DragData DnDTreeViewBase::drag_data;
+
DnDTreeViewBase::DnDTreeViewBase ()
: TreeView ()
{
@@ -47,6 +49,7 @@ DnDTreeViewBase::add_drop_targets (list<TargetEntry>& targets)
for (list<TargetEntry>::iterator i = targets.begin(); i != targets.end(); ++i) {
draggable.push_back (*i);
}
+
enable_model_drag_source (draggable);
enable_model_drag_dest (draggable);
}
@@ -56,6 +59,7 @@ DnDTreeViewBase::add_object_drag (int column, string type_name)
{
draggable.push_back (TargetEntry (type_name, TargetFlags(0)));
data_column = column;
+ object_type = type_name;
enable_model_drag_source (draggable);
enable_model_drag_dest (draggable);
diff --git a/libs/gtkmm2ext/gtk_ui.cc b/libs/gtkmm2ext/gtk_ui.cc
index 4ca23b0240..e15a3524db 100644
--- a/libs/gtkmm2ext/gtk_ui.cc
+++ b/libs/gtkmm2ext/gtk_ui.cc
@@ -65,6 +65,9 @@ UI::UI (string namestr, int *argc, char ***argv)
: AbstractUI<UIRequest> (namestr, true)
{
theMain = new Main (argc, argv);
+#ifndef GTK_NEW_TOOLTIP_API
+ tips = new Tooltips;
+#endif
_active = false;
@@ -95,6 +98,7 @@ UI::UI (string namestr, int *argc, char ***argv)
errors->dismiss_button().set_name ("ErrorLogCloseButton");
errors->signal_delete_event().connect (bind (sigc::ptr_fun (just_hide_it), (Window *) errors));
+ errors->set_type_hint (Gdk::WINDOW_TYPE_HINT_UTILITY);
register_thread (pthread_self(), X_("GUI"));
@@ -372,7 +376,16 @@ UI::do_request (UIRequest* req)
} else if (req->type == SetTip) {
- /* XXX need to figure out how this works */
+#ifdef GTK_NEW_TOOLTIP_API
+ /* even if the installed GTK is up to date,
+ at present (November 2008) our included
+ version of gtkmm is not. so use the GTK
+ API that we've verified has the right function.
+ */
+ gtk_widget_set_tooltip_text (req->widget->gobj(), req->msg);
+#else
+ tips->set_tip (*req->widget, req->msg, "");
+#endif
} else {
diff --git a/libs/gtkmm2ext/gtkmm2ext/dndtreeview.h b/libs/gtkmm2ext/gtkmm2ext/dndtreeview.h
index fbc5ea90ef..085e500f21 100644
--- a/libs/gtkmm2ext/gtkmm2ext/dndtreeview.h
+++ b/libs/gtkmm2ext/gtkmm2ext/dndtreeview.h
@@ -62,6 +62,21 @@ class DnDTreeViewBase : public Gtk::TreeView
std::list<Gtk::TargetEntry> draggable;
Gdk::DragAction suggested_action;
int data_column;
+ std::string object_type;
+
+ struct DragData {
+ Gtk::TreeView* source;
+ int data_column;
+ std::string object_type;
+ };
+
+ static DragData drag_data;
+
+ void start_object_drag () {
+ drag_data.source = this;
+ drag_data.data_column = data_column;
+ drag_data.object_type = object_type;
+ }
};
template<class DataType>
@@ -71,21 +86,26 @@ class DnDTreeView : public DnDTreeViewBase
DnDTreeView() {}
~DnDTreeView() {}
- sigc::signal<void,std::string,uint32_t,const DataType*> signal_object_drop;
+ sigc::signal<void,const std::list<DataType>& > signal_drop;
void on_drag_data_get(const Glib::RefPtr<Gdk::DragContext>& context, Gtk::SelectionData& selection_data, guint info, guint time) {
if (selection_data.get_target() == "GTK_TREE_MODEL_ROW") {
-
+
TreeView::on_drag_data_get (context, selection_data, info, time);
-
- } else if (data_column >= 0) {
-
- Gtk::TreeSelection::ListHandle_Path selection = get_selection()->get_selected_rows ();
- SerializedObjectPointers<DataType>* sr = serialize_pointers (get_model(), &selection, selection_data.get_target());
- selection_data.set (8, (guchar*)sr, sr->size);
+
+ } else if (selection_data.get_target() == object_type) {
+
+ start_object_drag ();
+
+ /* we don't care about the data passed around by DnD, but
+ we have to provide something otherwise it will stop.
+ */
+
+ guchar c;
+ selection_data.set (8, (guchar*)&c, 1);
}
}
-
+
void on_drag_data_received(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, const Gtk::SelectionData& selection_data, guint info, guint time) {
if (suggested_action) {
/* this is a drag motion callback. just update the status to
@@ -100,64 +120,39 @@ class DnDTreeView : public DnDTreeViewBase
TreeView::on_drag_data_received (context, x, y, selection_data, info, time);
- } else if (data_column >= 0) {
-
- /* object D-n-D */
-
- const void* data = selection_data.get_data();
- const SerializedObjectPointers<DataType>* sr = reinterpret_cast<const SerializedObjectPointers<DataType> *>(data);
-
- if (sr) {
- signal_object_drop (sr->type, sr->cnt, sr->data);
- }
+
+ } else if (selection_data.get_target() == object_type) {
+ end_object_drag ();
+
} else {
/* some kind of target type added by the app, which will be handled by a signal handler */
}
}
- private:
-
- SerializedObjectPointers<DataType>* serialize_pointers (Glib::RefPtr<Gtk::TreeModel> model,
- Gtk::TreeSelection::ListHandle_Path* selection,
- Glib::ustring type) {
-
- /* this nasty chunk of code is here because X's DnD protocol (probably other graphics UI's too)
- requires that we package up the entire data collection for DnD in a single contiguous region
- (so that it can be trivially copied between address spaces). We don't know the type of DataType so
- we have to mix-and-match C and C++ programming techniques here to get the right result.
-
- The C trick is to use the "someType foo[0];" declaration trick to create a zero-sized array at the
- end of a SerializedObjectPointers<DataType object. Then we allocate a raw memory buffer that extends
- past that array and thus provides space for however many DataType items we actually want to pass
- around.
-
- The C++ trick is to use the placement operator new() syntax to initialize that extra
- memory properly.
- */
-
- uint32_t cnt = selection->size();
- uint32_t sz = (sizeof (DataType) * cnt) + sizeof (SerializedObjectPointers<DataType>);
-
- char* buf = new char[sz];
- SerializedObjectPointers<DataType>* sr = (SerializedObjectPointers<DataType>*) buf;
+ /**
+ * this can be called by the Treeview itself or by some other
+ * object that wants to get the list of dragged items.
+ */
- for (uint32_t i = 0; i < cnt; ++i) {
- new ((void *) &sr->data[i]) DataType ();
- }
-
- sr->cnt = cnt;
- sr->size = sz;
- snprintf (sr->type, sizeof (sr->type), "%s", type.c_str());
+ void get_object_drag_data (std::list<DataType>& l) {
+ Glib::RefPtr<Gtk::TreeModel> model = drag_data.source->get_model();
+ DataType v;
+ Gtk::TreeSelection::ListHandle_Path selection = drag_data.source->get_selection()->get_selected_rows ();
- cnt = 0;
-
- for (Gtk::TreeSelection::ListHandle_Path::iterator x = selection->begin(); x != selection->end(); ++x, ++cnt) {
- model->get_iter (*x)->get_value (data_column, sr->data[cnt]);
+ for (Gtk::TreeSelection::ListHandle_Path::iterator x = selection.begin(); x != selection.end(); ++x) {
+ model->get_iter (*x)->get_value (drag_data.data_column, v);
+ l.push_back (v);
}
+ }
- return sr;
+ private:
+ void end_object_drag () {
+ std::list<DataType> l;
+ get_object_drag_data (l);
+ signal_drop (l);
}
+
};
} // namespace
diff --git a/libs/gtkmm2ext/gtkmm2ext/gtk_ui.h b/libs/gtkmm2ext/gtkmm2ext/gtk_ui.h
index 22ac517672..89f3413435 100644
--- a/libs/gtkmm2ext/gtkmm2ext/gtk_ui.h
+++ b/libs/gtkmm2ext/gtkmm2ext/gtk_ui.h
@@ -29,6 +29,9 @@
#include <pthread.h>
#include <gtkmm/widget.h>
#include <gtkmm/style.h>
+#ifndef GTK_NEW_TOOLTIP_API
+#include <gtkmm/tooltips.h>
+#endif
#include <gtkmm/textbuffer.h>
#include <gtkmm/main.h>
#include <gdkmm/color.h>
@@ -149,6 +152,9 @@ class UI : public Receiver, public AbstractUI<UIRequest>
static pthread_t gui_thread;
bool _active;
Gtk::Main *theMain;
+#ifndef GTK_NEW_TOOLTIP_API
+ Gtk::Tooltips *tips;
+#endif
TextViewer *errors;
Glib::RefPtr<Gtk::TextBuffer::Tag> error_ptag;
Glib::RefPtr<Gtk::TextBuffer::Tag> error_mtag;
diff --git a/libs/gtkmm2ext/gtkmm2ext/tearoff.h b/libs/gtkmm2ext/gtkmm2ext/tearoff.h
index 5e80892b98..737a6ddd03 100644
--- a/libs/gtkmm2ext/gtkmm2ext/tearoff.h
+++ b/libs/gtkmm2ext/gtkmm2ext/tearoff.h
@@ -34,6 +34,8 @@ class TearOff : public Gtk::HBox
virtual ~TearOff ();
void set_visible (bool yn);
+ void set_can_be_torn_off (bool);
+ bool can_be_torn_off () const { return _can_be_torn_off; }
sigc::signal<void> Detach;
sigc::signal<void> Attach;
@@ -55,6 +57,7 @@ class TearOff : public Gtk::HBox
double drag_y;
bool dragging;
bool _visible;
+ bool _can_be_torn_off;
gint tearoff_click (GdkEventButton*);
gint close_click (GdkEventButton*);
diff --git a/libs/gtkmm2ext/popup.cc b/libs/gtkmm2ext/popup.cc
index 0b150eefe1..2d586d0317 100644
--- a/libs/gtkmm2ext/popup.cc
+++ b/libs/gtkmm2ext/popup.cc
@@ -22,6 +22,7 @@
#include <gtkmm2ext/popup.h>
#include <gtkmm2ext/utils.h>
+#include <gtkmm2ext/gtk_ui.h>
using namespace std;
using namespace Gtk;
@@ -83,9 +84,17 @@ PopUp::remove ()
}
}
+#define ENSURE_GUI_THREAD(slot) \
+ if (!Gtkmm2ext::UI::instance()->caller_is_ui_thread()) {\
+ Gtkmm2ext::UI::instance()->call_slot ((slot));\
+ return;\
+ }
+
void
PopUp::touch ()
{
+ ENSURE_GUI_THREAD (mem_fun (*this, &PopUp::touch));
+
if (is_visible ()) {
remove ();
} else {
diff --git a/libs/gtkmm2ext/tearoff.cc b/libs/gtkmm2ext/tearoff.cc
index 92bde5541e..be3bfe4113 100644
--- a/libs/gtkmm2ext/tearoff.cc
+++ b/libs/gtkmm2ext/tearoff.cc
@@ -36,6 +36,7 @@ TearOff::TearOff (Widget& c, bool allow_resize)
{
dragging = false;
_visible = true;
+ _can_be_torn_off = true;
tearoff_event_box.add (tearoff_arrow);
tearoff_event_box.set_events (BUTTON_PRESS_MASK|BUTTON_RELEASE_MASK);
@@ -79,6 +80,21 @@ TearOff::~TearOff ()
}
void
+TearOff::set_can_be_torn_off (bool yn)
+{
+ if (yn != _can_be_torn_off) {
+ if (yn) {
+ tearoff_arrow.set_no_show_all (false);
+ tearoff_arrow.show ();
+ } else {
+ tearoff_arrow.set_no_show_all (true);
+ tearoff_arrow.hide ();
+ }
+ _can_be_torn_off = yn;
+ }
+}
+
+void
TearOff::set_visible (bool yn)
{
/* don't change visibility if torn off */
@@ -102,13 +118,16 @@ TearOff::set_visible (bool yn)
gint
TearOff::tearoff_click (GdkEventButton* ev)
{
- remove (contents);
- window_box.pack_start (contents);
- own_window.set_name (get_name());
- close_event_box.set_name (get_name());
- own_window.show_all ();
- hide ();
- Detach ();
+ if (_can_be_torn_off) {
+ remove (contents);
+ window_box.pack_start (contents);
+ own_window.set_name (get_name());
+ close_event_box.set_name (get_name());
+ own_window.show_all ();
+ hide ();
+ Detach ();
+ }
+
return true;
}