static int gtkCanvasMapMethod(Ihandle* ih) { GtkWidget* sb_win; #if !GTK_CHECK_VERSION(3, 0, 0) void* visual; #endif if (!ih->parent) return IUP_ERROR; ih->data->sb = iupBaseGetScrollbar(ih); #if !GTK_CHECK_VERSION(3, 0, 0) visual = (void*)IupGetAttribute(ih, "VISUAL"); /* defined by the OpenGL Canvas in X11 or NULL */ if (visual) iupgtkPushVisualAndColormap(visual, (void*)iupAttribGet(ih, "COLORMAP")); #endif ih->handle = iupgtkNativeContainerNew(); /* canvas is also a container */ #if !GTK_CHECK_VERSION(3, 0, 0) if (visual) gtk_widget_pop_colormap(); #endif if (!ih->handle) return IUP_ERROR; /* CD will NOT work properly without this, must use always the CD-GDK driver */ iupgtkNativeContainerSetHasWindow(ih->handle, TRUE); sb_win = iupgtkNativeContainerNew(); if (!sb_win) return IUP_ERROR; iupgtkNativeContainerAdd(sb_win, ih->handle); gtk_widget_show(sb_win); iupAttribSetStr(ih, "_IUP_EXTRAPARENT", (char*)sb_win); /* add to the parent, all GTK controls must call this. */ iupgtkAddToParent(ih); g_signal_connect(G_OBJECT(ih->handle), "focus-in-event", G_CALLBACK(iupgtkFocusInOutEvent), ih); g_signal_connect(G_OBJECT(ih->handle), "focus-out-event", G_CALLBACK(iupgtkFocusInOutEvent), ih); g_signal_connect(G_OBJECT(ih->handle), "key-press-event", G_CALLBACK(iupgtkKeyPressEvent), ih); g_signal_connect(G_OBJECT(ih->handle), "key-release-event", G_CALLBACK(iupgtkKeyReleaseEvent), ih); g_signal_connect(G_OBJECT(ih->handle), "enter-notify-event", G_CALLBACK(iupgtkEnterLeaveEvent), ih); g_signal_connect(G_OBJECT(ih->handle), "leave-notify-event", G_CALLBACK(iupgtkEnterLeaveEvent), ih); g_signal_connect(G_OBJECT(ih->handle), "show-help", G_CALLBACK(iupgtkShowHelp), ih); #if GTK_CHECK_VERSION(3, 0, 0) g_signal_connect(G_OBJECT(ih->handle), "draw", G_CALLBACK(gtkCanvasDraw), ih); #else g_signal_connect(G_OBJECT(ih->handle), "expose-event", G_CALLBACK(gtkCanvasExposeEvent), ih); #endif g_signal_connect(G_OBJECT(ih->handle), "button-press-event", G_CALLBACK(gtkCanvasButtonEvent), ih); g_signal_connect(G_OBJECT(ih->handle), "button-release-event",G_CALLBACK(gtkCanvasButtonEvent), ih); g_signal_connect(G_OBJECT(ih->handle), "motion-notify-event",G_CALLBACK(iupgtkMotionNotifyEvent), ih); g_signal_connect(G_OBJECT(ih->handle), "scroll-event",G_CALLBACK(gtkCanvasScrollEvent), ih); g_signal_connect(G_OBJECT(ih->handle), "size-allocate", G_CALLBACK(gtkCanvasSizeAllocate), ih); /* To receive mouse events on a drawing area, you will need to enable them. */ gtk_widget_add_events(ih->handle, GDK_EXPOSURE_MASK| GDK_POINTER_MOTION_MASK|GDK_POINTER_MOTION_HINT_MASK| GDK_BUTTON_PRESS_MASK|GDK_BUTTON_RELEASE_MASK|GDK_BUTTON_MOTION_MASK| GDK_KEY_PRESS_MASK|GDK_KEY_RELEASE_MASK| GDK_ENTER_NOTIFY_MASK|GDK_LEAVE_NOTIFY_MASK| GDK_FOCUS_CHANGE_MASK|GDK_STRUCTURE_MASK); /* To receive keyboard events, you will need to set the GTK_CAN_FOCUS flag on the drawing area. */ if (ih->iclass->is_interactive) { if (iupAttribGetBoolean(ih, "CANFOCUS")) iupgtkSetCanFocus(ih->handle, 1); } if (iupAttribGetBoolean(ih, "BORDER")) { iupAttribSetInt(ih, "BORDERWIDTH", 1); #if GTK_CHECK_VERSION(3, 0, 0) g_signal_connect(G_OBJECT(sb_win), "draw", G_CALLBACK(gtkCanvasBorderDraw), NULL); #else g_signal_connect(G_OBJECT(sb_win), "expose-event", G_CALLBACK(gtkCanvasBorderExposeEvent), NULL); #endif } gtk_widget_realize(sb_win); if (ih->data->sb & IUP_SB_HORIZ) { #if GTK_CHECK_VERSION(3, 0, 0) GtkWidget* sb_horiz = gtk_scrollbar_new(GTK_ORIENTATION_HORIZONTAL, NULL); #else GtkWidget* sb_horiz = gtk_hscrollbar_new(NULL); #endif iupgtkNativeContainerAdd(sb_win, sb_horiz); gtk_widget_show(sb_horiz); gtk_widget_realize(sb_horiz); g_signal_connect(G_OBJECT(sb_horiz), "change-value",G_CALLBACK(gtkCanvasScrollHorizChangeValue), ih); g_signal_connect(G_OBJECT(gtk_range_get_adjustment(GTK_RANGE(sb_horiz))), "value-changed",G_CALLBACK(gtkCanvasAdjustHorizValueChanged), ih); iupAttribSetStr(ih, "_IUPGTK_SBHORIZ", (char*)sb_horiz); } if (ih->data->sb & IUP_SB_VERT) { #if GTK_CHECK_VERSION(3, 0, 0) GtkWidget* sb_vert = gtk_scrollbar_new(GTK_ORIENTATION_VERTICAL, NULL); #else GtkWidget* sb_vert = gtk_vscrollbar_new(NULL); #endif iupgtkNativeContainerAdd(sb_win, sb_vert); gtk_widget_show(sb_vert); gtk_widget_realize(sb_vert); g_signal_connect(G_OBJECT(sb_vert), "change-value",G_CALLBACK(gtkCanvasScrollVertChangeValue), ih); g_signal_connect(G_OBJECT(gtk_range_get_adjustment(GTK_RANGE(sb_vert))), "value-changed",G_CALLBACK(gtkCanvasAdjustVertValueChanged), ih); iupAttribSetStr(ih, "_IUPGTK_SBVERT", (char*)sb_vert); } gtk_widget_realize(ih->handle); /* configure for DRAG&DROP */ if (IupGetCallback(ih, "DROPFILES_CB")) iupAttribSetStr(ih, "DROPFILESTARGET", "YES"); /* update a mnemonic in a label if necessary */ iupgtkUpdateMnemonic(ih); /* force the update of BGCOLOR here, to let derived classes ignore it if ACTION is defined */ gtkCanvasSetBgColorAttrib(ih, iupAttribGetStr(ih, "BGCOLOR")); return IUP_NOERROR; }
static int gtkButtonMapMethod(Ihandle* ih) { int impress; char* value; value = iupAttribGet(ih, "IMAGE"); if (value) { ih->data->type = IUP_BUTTON_IMAGE; value = iupAttribGet(ih, "TITLE"); if (value && *value!=0) ih->data->type |= IUP_BUTTON_TEXT; } else ih->data->type = IUP_BUTTON_TEXT; if (ih->data->type == IUP_BUTTON_IMAGE && iupAttribGet(ih, "IMPRESS") && !iupAttribGetBoolean(ih, "IMPRESSBORDER")) { GtkWidget *img = gtk_image_new(); ih->handle = gtk_event_box_new(); gtk_container_add((GtkContainer*)ih->handle, img); gtk_widget_show(img); iupAttribSetStr(ih, "_IUPGTK_EVENTBOX", "1"); } else ih->handle = gtk_button_new(); if (!ih->handle) return IUP_ERROR; if (ih->data->type & IUP_BUTTON_IMAGE) { if (!iupAttribGet(ih, "_IUPGTK_EVENTBOX")) { gtk_button_set_image((GtkButton*)ih->handle, gtk_image_new()); if (ih->data->type & IUP_BUTTON_TEXT) { GtkSettings* settings = gtk_widget_get_settings(ih->handle); g_object_set(settings, "gtk-button-images", (int)TRUE, NULL); gtk_button_set_label((GtkButton*)ih->handle, iupgtkStrConvertToUTF8(iupAttribGet(ih, "TITLE"))); #if GTK_CHECK_VERSION(2, 10, 0) gtk_button_set_image_position((GtkButton*)ih->handle, ih->data->img_position); /* IUP and GTK have the same Ids */ #endif } } } else { char* title = iupAttribGet(ih, "TITLE"); if (!title) { if (iupAttribGet(ih, "BGCOLOR")) { int x=0, y=0; GtkWidget* frame = gtk_frame_new(NULL); #if GTK_CHECK_VERSION(2, 18, 0) GtkWidget* drawarea = gtk_drawing_area_new(); gtk_widget_set_has_window(drawarea, TRUE); #else GtkWidget* drawarea = gtk_fixed_new(); gtk_fixed_set_has_window(GTK_FIXED(drawarea), TRUE); #endif gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_IN); iupdrvButtonAddBorders(&x, &y); gtk_widget_set_size_request (frame, ih->currentwidth-x, ih->currentheight-y); gtk_container_add(GTK_CONTAINER(frame), drawarea); gtk_widget_show(drawarea); gtk_button_set_image((GtkButton*)ih->handle, frame); } else gtk_button_set_label((GtkButton*)ih->handle, ""); } else gtk_button_set_label((GtkButton*)ih->handle, iupgtkStrConvertToUTF8(title)); } /* add to the parent, all GTK controls must call this. */ iupgtkAddToParent(ih); if (!iupAttribGetBoolean(ih, "CANFOCUS")) iupgtkSetCanFocus(ih->handle, 0); value = iupAttribGet(ih, "IMPRESS"); impress = (ih->data->type & IUP_BUTTON_IMAGE && value)? 1: 0; if (!impress && iupAttribGetBoolean(ih, "FLAT")) { gtk_button_set_relief((GtkButton*)ih->handle, GTK_RELIEF_NONE); g_signal_connect(G_OBJECT(ih->handle), "enter-notify-event", G_CALLBACK(gtkButtonEnterLeaveEvent), ih); g_signal_connect(G_OBJECT(ih->handle), "leave-notify-event", G_CALLBACK(gtkButtonEnterLeaveEvent), ih); } else { if (!iupAttribGet(ih, "_IUPGTK_EVENTBOX")) { if (impress && !iupAttribGetStr(ih, "IMPRESSBORDER")) gtk_button_set_relief((GtkButton*)ih->handle, GTK_RELIEF_NONE); else gtk_button_set_relief((GtkButton*)ih->handle, GTK_RELIEF_NORMAL); } g_signal_connect(G_OBJECT(ih->handle), "enter-notify-event", G_CALLBACK(iupgtkEnterLeaveEvent), ih); g_signal_connect(G_OBJECT(ih->handle), "leave-notify-event", G_CALLBACK(iupgtkEnterLeaveEvent), ih); } g_signal_connect(G_OBJECT(ih->handle), "focus-in-event", G_CALLBACK(iupgtkFocusInOutEvent), ih); g_signal_connect(G_OBJECT(ih->handle), "focus-out-event", G_CALLBACK(iupgtkFocusInOutEvent), ih); g_signal_connect(G_OBJECT(ih->handle), "key-press-event", G_CALLBACK(iupgtkKeyPressEvent), ih); g_signal_connect(G_OBJECT(ih->handle), "show-help", G_CALLBACK(iupgtkShowHelp), ih); if (!iupAttribGet(ih, "_IUPGTK_EVENTBOX")) g_signal_connect(G_OBJECT(ih->handle), "clicked", G_CALLBACK(gtkButtonClicked), ih); g_signal_connect(G_OBJECT(ih->handle), "button-press-event", G_CALLBACK(gtkButtonEvent), ih); g_signal_connect(G_OBJECT(ih->handle), "button-release-event",G_CALLBACK(gtkButtonEvent), ih); gtk_widget_realize(ih->handle); /* update a mnemonic in a label if necessary */ iupgtkUpdateMnemonic(ih); return IUP_NOERROR; }
/* ------------------------------------------------------------------------- */ static void gtkTabsChildAddedMethod(Ihandle* ih, Ihandle* child) { /* make sure it has at least one name */ if (!iupAttribGetHandleName(child)) iupAttribSetHandleName(child); if (ih->handle) { GtkWidget *evtBox, *tab_page, *tab_container, *box = NULL; GtkWidget *tab_label = NULL, *tab_image = NULL, *tab_close = NULL; char *tabtitle, *tabimage; int pos; unsigned char r, g, b; pos = IupGetChildPos(ih, child); /* Can not hide the tab_page, or the tab will be automatically hidden. So create a secondary container to hide its child instead. */ #if GTK_CHECK_VERSION(3, 0, 0) tab_page = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); #else tab_page = gtk_vbox_new(FALSE, 0); #endif gtk_widget_show(tab_page); tab_container = gtk_fixed_new(); /* can not use iupgtkNativeContainerNew in GTK3 */ gtk_widget_show(tab_container); gtk_container_add((GtkContainer*)tab_page, tab_container); tabtitle = iupAttribGet(child, "TABTITLE"); if (!tabtitle) { tabtitle = iupAttribGetId(ih, "TABTITLE", pos); if (tabtitle) iupAttribSetStr(child, "TABTITLE", tabtitle); } tabimage = iupAttribGet(child, "TABIMAGE"); if (!tabimage) { tabimage = iupAttribGetId(ih, "TABIMAGE", pos); if (tabimage) iupAttribSetStr(child, "TABIMAGE", tabimage); } if (!tabtitle && !tabimage) tabtitle = " "; if (tabtitle) { tab_label = gtk_label_new(NULL); iupgtkSetMnemonicTitle(ih, (GtkLabel*)tab_label, tabtitle); #if GTK_CHECK_VERSION(2, 6, 0) if (ih->data->orientation == ITABS_VERTICAL) gtk_label_set_angle((GtkLabel*)tab_label, 90); #endif } if (tabimage) { GdkPixbuf* pixbuf = iupImageGetImage(tabimage, ih, 0); tab_image = gtk_image_new(); if (pixbuf) gtk_image_set_from_pixbuf((GtkImage*)tab_image, pixbuf); } if(ih->data->show_close) { #if GTK_CHECK_VERSION(3, 10, 0) GtkWidget* image = gtk_image_new_from_icon_name("window-close", GTK_ICON_SIZE_MENU); #else GtkWidget* image = gtk_image_new_from_stock(GTK_STOCK_CLOSE, GTK_ICON_SIZE_MENU); #endif tab_close = gtk_button_new(); gtk_button_set_image((GtkButton*)tab_close, image); gtk_button_set_relief((GtkButton*)tab_close, GTK_RELIEF_NONE); gtk_button_set_focus_on_click((GtkButton*)tab_close, FALSE); iupgtkSetCanFocus(tab_close, FALSE); g_signal_connect(G_OBJECT(tab_close), "clicked", G_CALLBACK(gtkTabsCloseButtonClicked), child); } iupAttribSet(ih, "_IUPGTK_IGNORE_CHANGE", "1"); if ((tabimage && tabtitle) || ih->data->show_close) { #if GTK_CHECK_VERSION(3, 0, 0) if (ih->data->orientation == ITABS_VERTICAL) box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 2); else box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 2); #else if (ih->data->orientation == ITABS_VERTICAL) box = gtk_vbox_new(FALSE, 2); else box = gtk_hbox_new(FALSE, 2); #endif gtk_widget_show(box); } /* RIGHTCLICK_CB will not work without the eventbox */ evtBox = gtk_event_box_new(); gtk_widget_add_events(evtBox, GDK_BUTTON_PRESS_MASK); g_signal_connect(G_OBJECT(evtBox), "button-press-event", G_CALLBACK(gtkTabsButtonPressEvent), child); if (tabimage && tabtitle) { gtk_container_add((GtkContainer*)box, tab_image); gtk_container_add((GtkContainer*)box, tab_label); if(ih->data->show_close) gtk_container_add((GtkContainer*)box, tab_close); gtk_container_add((GtkContainer*)evtBox, box); gtk_notebook_insert_page((GtkNotebook*)ih->handle, tab_page, evtBox, pos); gtk_notebook_set_menu_label_text((GtkNotebook*)ih->handle, tab_page, gtk_label_get_text((GtkLabel*)tab_label)); } else if(tabimage && ih->data->show_close) { gtk_container_add((GtkContainer*)box, tab_image); gtk_container_add((GtkContainer*)box, tab_close); gtk_container_add((GtkContainer*)evtBox, box); gtk_notebook_insert_page((GtkNotebook*)ih->handle, tab_page, evtBox, pos); } else if(tabtitle && ih->data->show_close) { gtk_container_add((GtkContainer*)box, tab_label); gtk_container_add((GtkContainer*)box, tab_close); gtk_container_add((GtkContainer*)evtBox, box); gtk_notebook_insert_page((GtkNotebook*)ih->handle, tab_page, evtBox, pos); gtk_notebook_set_menu_label_text((GtkNotebook*)ih->handle, tab_page, gtk_label_get_text((GtkLabel*)tab_label)); } else if (tabimage) { gtk_container_add((GtkContainer*)evtBox, tab_image); gtk_notebook_insert_page((GtkNotebook*)ih->handle, tab_page, evtBox, pos); } else { gtk_container_add((GtkContainer*)evtBox, tab_label); gtk_notebook_insert_page((GtkNotebook*)ih->handle, tab_page, evtBox, pos); } gtk_widget_realize(tab_page); iupAttribSet(child, "_IUPGTK_TABCLOSE", (char*)tab_close); iupAttribSet(child, "_IUPGTK_TABIMAGE", (char*)tab_image); /* store it even if its NULL */ iupAttribSet(child, "_IUPGTK_TABLABEL", (char*)tab_label); iupAttribSet(child, "_IUPTAB_CONTAINER", (char*)tab_container); iupAttribSet(child, "_IUPTAB_PAGE", (char*)tab_page); iupStrToRGB(IupGetAttribute(ih, "BGCOLOR"), &r, &g, &b); iupgtkSetBgColor(tab_container, r, g, b); if (tabtitle) { iupgtkUpdateWidgetFont(ih, tab_label); iupgtkSetBgColor(tab_label, r, g, b); iupStrToRGB(IupGetAttribute(ih, "FGCOLOR"), &r, &g, &b); iupgtkSetFgColor(tab_label, r, g, b); gtk_widget_show(tab_label); gtk_widget_realize(tab_label); } if (tabimage) { gtk_widget_show(tab_image); gtk_widget_realize(tab_image); } if (ih->data->show_close) { gtk_widget_show(tab_close); gtk_widget_realize(tab_close); } iupAttribSet(ih, "_IUPGTK_IGNORE_CHANGE", NULL); if (pos != iupdrvTabsGetCurrentTab(ih)) gtk_widget_hide(tab_container); } }
static int gtkToggleMapMethod(Ihandle* ih) { Ihandle* radio = iupRadioFindToggleParent(ih); char *value; int is3state = 0; if (!ih->parent) return IUP_ERROR; value = iupAttribGet(ih, "IMAGE"); if (value) ih->data->type = IUP_TOGGLE_IMAGE; else ih->data->type = IUP_TOGGLE_TEXT; if (radio) { GtkRadioButton* last_tg = (GtkRadioButton*)iupAttribGet(radio, "_IUPGTK_LASTRADIOBUTTON"); if (last_tg) ih->handle = gtk_radio_button_new_from_widget(last_tg); else ih->handle = gtk_radio_button_new(NULL); iupAttribSet(radio, "_IUPGTK_LASTRADIOBUTTON", (char*)ih->handle); /* make sure it has at least one name */ if (!iupAttribGetHandleName(ih)) iupAttribSetHandleName(ih); ih->data->is_radio = 1; } else { if (ih->data->type == IUP_TOGGLE_TEXT) { ih->handle = gtk_check_button_new(); if (iupAttribGetBoolean(ih, "3STATE")) is3state = 1; } else ih->handle = gtk_toggle_button_new(); } if (!ih->handle) return IUP_ERROR; if (ih->data->type == IUP_TOGGLE_TEXT) { gtk_button_set_image((GtkButton*)ih->handle, gtk_label_new(NULL)); gtk_toggle_button_set_mode((GtkToggleButton*)ih->handle, TRUE); } else { gtk_button_set_image((GtkButton*)ih->handle, gtk_image_new()); gtk_toggle_button_set_mode((GtkToggleButton*)ih->handle, FALSE); } iupgtkClearSizeStyleCSS(ih->handle); /* add to the parent, all GTK controls must call this. */ iupgtkAddToParent(ih); if (!iupAttribGetBoolean(ih, "CANFOCUS")) iupgtkSetCanFocus(ih->handle, 0); if (ih->data->type == IUP_TOGGLE_IMAGE && ih->data->flat) { gtk_button_set_relief((GtkButton*)ih->handle, GTK_RELIEF_NONE); g_signal_connect(G_OBJECT(ih->handle), "enter-notify-event", G_CALLBACK(gtkToggleEnterLeaveEvent), ih); g_signal_connect(G_OBJECT(ih->handle), "leave-notify-event", G_CALLBACK(gtkToggleEnterLeaveEvent), ih); } else { g_signal_connect(G_OBJECT(ih->handle), "enter-notify-event", G_CALLBACK(iupgtkEnterLeaveEvent), ih); g_signal_connect(G_OBJECT(ih->handle), "leave-notify-event", G_CALLBACK(iupgtkEnterLeaveEvent), ih); } g_signal_connect(G_OBJECT(ih->handle), "focus-in-event", G_CALLBACK(iupgtkFocusInOutEvent), ih); g_signal_connect(G_OBJECT(ih->handle), "focus-out-event", G_CALLBACK(iupgtkFocusInOutEvent), ih); g_signal_connect(G_OBJECT(ih->handle), "key-press-event", G_CALLBACK(iupgtkKeyPressEvent), ih); g_signal_connect(G_OBJECT(ih->handle), "show-help", G_CALLBACK(iupgtkShowHelp), ih); g_signal_connect(G_OBJECT(ih->handle), "toggled", G_CALLBACK(gtkToggleToggled), ih); if (ih->data->type == IUP_TOGGLE_IMAGE || is3state) { g_signal_connect(G_OBJECT(ih->handle), "button-press-event", G_CALLBACK(gtkToggleButtonEvent), ih); g_signal_connect(G_OBJECT(ih->handle), "button-release-event",G_CALLBACK(gtkToggleButtonEvent), ih); } if (is3state) { g_signal_connect(G_OBJECT(ih->handle), "key-press-event", G_CALLBACK(gtkToggleKeyEvent), ih); g_signal_connect(G_OBJECT(ih->handle), "key-release-event", G_CALLBACK(gtkToggleKeyEvent), ih); } gtk_widget_realize(ih->handle); /* update a mnemonic in a label if necessary */ iupgtkUpdateMnemonic(ih); return IUP_NOERROR; }
static int gtkCanvasMapMethod(Ihandle* ih) { GtkScrolledWindow* scrolled_window; void* visual; if (!ih->parent) return IUP_ERROR; ih->data->sb = iupBaseGetScrollbar(ih); visual = (void*)IupGetAttribute(ih, "VISUAL"); /* defined by the OpenGL Canvas in X11 or NULL */ if (visual) iupgtkPushVisualAndColormap(visual, (void*)iupAttribGet(ih, "COLORMAP")); ih->handle = gtk_drawing_area_new(); if (visual) gtk_widget_pop_colormap(); if (!ih->handle) return IUP_ERROR; #if GTK_CHECK_VERSION(2, 18, 0) /* CD will NOT work properly without this, must use always the CD-GDK driver */ gtk_widget_set_has_window(ih->handle, TRUE); #endif scrolled_window = (GtkScrolledWindow*)gtk_scrolled_window_new(NULL, NULL); if (!scrolled_window) return IUP_ERROR; { /* to avoid the "cannot add non scrollable widget" warning */ #if GTK_CHECK_VERSION(2, 6, 0) GLogFunc def_func = g_log_set_default_handler(gtkCanvasDummyLogFunc, NULL); #endif gtk_container_add((GtkContainer*)scrolled_window, ih->handle); #if GTK_CHECK_VERSION(2, 6, 0) g_log_set_default_handler(def_func, NULL); #endif } gtk_widget_show((GtkWidget*)scrolled_window); iupAttribSetStr(ih, "_IUP_EXTRAPARENT", (char*)scrolled_window); /* add to the parent, all GTK controls must call this. */ iupgtkBaseAddToParent(ih); g_signal_connect(G_OBJECT(ih->handle), "focus-in-event", G_CALLBACK(iupgtkFocusInOutEvent), ih); g_signal_connect(G_OBJECT(ih->handle), "focus-out-event", G_CALLBACK(iupgtkFocusInOutEvent), ih); g_signal_connect(G_OBJECT(ih->handle), "key-press-event", G_CALLBACK(iupgtkKeyPressEvent), ih); g_signal_connect(G_OBJECT(ih->handle), "key-release-event", G_CALLBACK(iupgtkKeyReleaseEvent), ih); g_signal_connect(G_OBJECT(ih->handle), "enter-notify-event", G_CALLBACK(iupgtkEnterLeaveEvent), ih); g_signal_connect(G_OBJECT(ih->handle), "leave-notify-event", G_CALLBACK(iupgtkEnterLeaveEvent), ih); g_signal_connect(G_OBJECT(ih->handle), "show-help", G_CALLBACK(iupgtkShowHelp), ih); g_signal_connect(G_OBJECT(ih->handle), "expose-event", G_CALLBACK(gtkCanvasExposeEvent), ih); g_signal_connect(G_OBJECT(ih->handle), "button-press-event", G_CALLBACK(gtkCanvasButtonEvent), ih); g_signal_connect(G_OBJECT(ih->handle), "button-release-event",G_CALLBACK(gtkCanvasButtonEvent), ih); g_signal_connect(G_OBJECT(ih->handle), "motion-notify-event",G_CALLBACK(iupgtkMotionNotifyEvent), ih); g_signal_connect(G_OBJECT(ih->handle), "scroll-event",G_CALLBACK(gtkCanvasScrollEvent), ih); #if GTK_CHECK_VERSION(2, 8, 0) g_signal_connect(G_OBJECT(gtk_scrolled_window_get_hscrollbar(scrolled_window)), "change-value",G_CALLBACK(gtkCanvasHChangeValue), ih); g_signal_connect(G_OBJECT(gtk_scrolled_window_get_vscrollbar(scrolled_window)), "change-value",G_CALLBACK(gtkCanvasVChangeValue), ih); #endif /* To receive mouse events on a drawing area, you will need to enable them. */ gtk_widget_add_events(ih->handle, GDK_EXPOSURE_MASK| GDK_POINTER_MOTION_MASK|GDK_POINTER_MOTION_HINT_MASK| GDK_BUTTON_PRESS_MASK|GDK_BUTTON_RELEASE_MASK|GDK_BUTTON_MOTION_MASK| GDK_KEY_PRESS_MASK|GDK_KEY_RELEASE_MASK| GDK_ENTER_NOTIFY_MASK|GDK_LEAVE_NOTIFY_MASK| GDK_FOCUS_CHANGE_MASK|GDK_STRUCTURE_MASK); /* To receive keyboard events, you will need to set the GTK_CAN_FOCUS flag on the drawing area. */ if (ih->iclass->is_interactive) { if (iupAttribGetBoolean(ih, "CANFOCUS")) iupgtkSetCanFocus(ih->handle, 1); } if (iupAttribGetBoolean(ih, "BORDER")) gtk_scrolled_window_set_shadow_type(scrolled_window, GTK_SHADOW_IN); else gtk_scrolled_window_set_shadow_type(scrolled_window, GTK_SHADOW_NONE); gtk_widget_realize((GtkWidget*)scrolled_window); gtk_widget_realize(ih->handle); /* must be connected after realize or a RESIZE_CB will happen before MAP_CB works only for the GtkDrawingArea. */ g_signal_connect(G_OBJECT(ih->handle), "configure-event", G_CALLBACK(gtkCanvasConfigureEvent), ih); iupAttribSetStr(ih, "_IUP_GTK_FIRST_RESIZE", "1"); /* configure for DRAG&DROP */ if (IupGetCallback(ih, "DROPFILES_CB")) iupAttribSetStr(ih, "DRAGDROP", "YES"); /* update a mnemonic in a label if necessary */ iupgtkUpdateMnemonic(ih); /* configure scrollbar */ if (ih->data->sb) { GtkPolicyType hscrollbar_policy = GTK_POLICY_NEVER, vscrollbar_policy = GTK_POLICY_NEVER; if (ih->data->sb & IUP_SB_HORIZ) hscrollbar_policy = GTK_POLICY_AUTOMATIC; if (ih->data->sb & IUP_SB_VERT) vscrollbar_policy = GTK_POLICY_AUTOMATIC; gtk_scrolled_window_set_policy(scrolled_window, hscrollbar_policy, vscrollbar_policy); } else gtk_scrolled_window_set_policy(scrolled_window, GTK_POLICY_NEVER, GTK_POLICY_NEVER); /* force the update of BGCOLOR here, to let derived classes ignore it if ACTION is defined */ gtkCanvasSetBgColorAttrib(ih, iupAttribGetStr(ih, "BGCOLOR")); return IUP_NOERROR; }