21 #include <cairo/cairo.h> 27 #define WIDGET_DRAGHIGHLIGHTSTATE_DATA "DragHighlightState" 51 GtkWidget *
ref(
void) {
59 g_object_unref(widget);
66 gtk_widget_show(widget);
73 gtk_widget_hide(widget);
81 #if GTK_MAJOR_VERSION==2 82 return GTK_WIDGET_VISIBLE(widget);
84 return gtk_widget_get_visible(widget);
99 return gtk_widget_get_sensitive(widget);
106 gtk_widget_set_sensitive(widget, sens);
114 #if GTK_MAJOR_VERSION>2 // if using GTK3 or more recent, then use get_preferred_size 115 GtkRequisition requisitionMin;
116 GtkRequisition naturalRequisition;
117 gtk_widget_get_preferred_size(widget, &requisitionMin, &naturalRequisition);
118 width=requisitionMin.width;
119 height=requisitionMin.height;
121 GtkAllocation allocation;
122 gtk_widget_get_allocation(widget, &allocation);
123 width=allocation.width;
124 height=allocation.height;
133 gtk_widget_set_size_request(widget, width, height);
144 gtk_widget_get_allocation(widget, &alloc);
154 gtk_widget_queue_draw(widget);
160 return gtk_widget_get_window(widget);
171 #ifdef gdk_cairo_set_source_window 176 int saveToPNGFile(
const char *fileName) {
177 return saveToPNGFile(
getWindow(), fileName);
185 int saveToPNGFile(GdkWindow *win,
const char *fileName) {
195 cairo_surface_t *cs=gdk_window_create_similar_surface(win, CAIRO_CONTENT_COLOR_ALPHA, width, height);
196 cairo_t *cr=cairo_create(cs);
197 gdk_cairo_set_source_window(cr, win, 0, 0);
200 cairo_status_t res=cairo_surface_write_to_png(cs, fileName);
206 if (cs) cairo_surface_destroy(cs);
207 if (res!=CAIRO_STATUS_SUCCESS) {
208 if (res==CAIRO_STATUS_NO_MEMORY)
209 std::cerr<<
"Widget::saveToPNGFile : memory could not be allocated for the operation"<<std::endl;
210 else if (res==CAIRO_STATUS_SURFACE_TYPE_MISMATCH)
211 std::cerr<<
"Widget::saveToPNGFile : the surface does not have pixel contents"<<std::endl;
212 else if (res==CAIRO_STATUS_WRITE_ERROR)
213 std::cerr<<
"Widget::saveToPNGFile : an I/O error occurs while attempting to write the file."<<std::endl;
224 void connect(
const char *event, GCallback callback, gpointer data) {
225 g_signal_connect(widget, event, callback, data);
233 void connectAfter(
const char *event, GCallback callback, gpointer data) {
234 g_signal_connect_after(widget, event, callback, data);
259 g_signal_connect_after(G_OBJECT(w),
"expose-event", callback, data);
284 g_signal_connect_after(G_OBJECT(w),
"configure-event", callback, data);
346 static void dragDataReceivedStatic(GtkWidget *w, GdkDragContext *dragContext, gint
x, gint
y, GtkSelectionData *selectionData, guint info, guint time, gpointer data) {
364 bool deleteSelectionData=
false;
365 if((selectionData != NULL) && (gtk_selection_data_get_length(selectionData) >= 0)) {
366 if (gdk_drag_context_get_suggested_action(dragContext) == GDK_ACTION_ASK) {
370 bool deleteSelectionData=
false;
371 if (gdk_drag_context_get_suggested_action(dragContext) == GDK_ACTION_COPY)
373 else if (gdk_drag_context_get_suggested_action(dragContext) == GDK_ACTION_MOVE)
374 deleteSelectionData=
true;
376 success=
static_cast<Widget*
>(data)->
dragDataReceived(w, gtk_drag_get_source_widget(dragContext), info, gtk_selection_data_get_data(selectionData), gtk_selection_data_get_length(selectionData));
378 gtk_drag_finish(dragContext, success, deleteSelectionData, time);
388 static void dragLeaveStatic(GtkWidget *w, GdkDragContext *dragContext, guint time, gpointer data) {
391 static_cast<Widget*
>(data)->
dragLeave(w, gtk_drag_get_source_widget(dragContext));
400 gtk_drag_unhighlight(w);
413 static gboolean
dragMotionStatic(GtkWidget *w, GdkDragContext *dragContext, gint
x, gint
y, guint time, gpointer data) {
425 bool success=
static_cast<Widget*
>(data)->
dragMotion(w, gtk_drag_get_source_widget(dragContext),
x,
y);
436 gtk_drag_highlight (w);
450 static bool dragDropStatic(GtkWidget *w, GdkDragContext *dragContext, gint
x, gint
y, guint time, gpointer data) {
453 gboolean validDropSite =
static_cast<Widget*
>(data)->
dragMotion(w, gtk_drag_get_source_widget(dragContext),
x,
y);
455 if (gdk_drag_context_list_targets(dragContext)) {
459 std::cout<<
"whichTarget "<<whichTarget<<std::endl;
461 validDropSite = FALSE;
463 GdkAtom targetType = GDK_POINTER_TO_ATOM(g_list_nth_data(gdk_drag_context_list_targets(dragContext), whichTarget));
466 gtk_drag_get_data(w, dragContext, targetType, time);
469 validDropSite = FALSE;
470 return validDropSite;
484 static void dragDataGetStatic(GtkWidget *w, GdkDragContext *dragContext, GtkSelectionData *selectionData, guint info, guint time, gpointer data) {
486 g_assert (selectionData != NULL);
506 static void dragBeginStatic(GtkWidget *w, GdkDragContext *dragContext, gpointer data) {
517 static void dragEndStatic(GtkWidget *w, GdkDragContext *dragContext, gpointer data) {
530 virtual bool checkDropValidity(GtkWidget *w, GtkWidget *sourceWidget,
int info,
const unsigned char *selectionStoredData) {
542 virtual bool dragDataReceived(GtkWidget *w, GtkWidget *sourceWidget,
int info,
const unsigned char *selectionStoredData,
int length) {
551 virtual void dragLeave(GtkWidget *w, GtkWidget *sourceWidget) {
562 virtual bool dragMotion(GtkWidget *w, GtkWidget *sourceWidget,
int x,
int y) {
587 std::cout<<
"Widget::chooseTheTargetToUse not overloaded, handling the empty and single target case"<<std::endl;
605 virtual void dragDataGet(GtkWidget *w, GtkSelectionData *selectionData, guint info) {
606 std::cout<<
"Widget::dragDataGet not overloaded, this is where you load in the data for sending"<<std::endl;
#define DND_WHICHTARGET_ERROR
void getModifierType(GdkModifierType modifierTypeIn)
GtkDestDefaults getDestDefaults()
virtual int evaluateError(int errorNum)
GdkDragAction getDragAction()
GtkTargetEntry * getTargetArray()