static int iMatrixListDrawColorCol(Ihandle *ih, int lin, int x1, int x2, int y1, int y2, cdCanvas *cnv) { unsigned char red, green, blue; char* color = iupAttribGetId(ih, "COLOR", lin); if (iupStrToRGB(color, &red, &green, &blue)) { static const int DX_BORDER = 2; static const int DY_BORDER = 3; static const int DX_FILL = 3; static const int DY_FILL = 4; int active = iupdrvIsActive(ih); int itemactive = IupGetIntId(ih, "ITEMACTIVE", lin); long framecolor; if (!itemactive) { red = IMAT_LIGHTER(red); green = IMAT_LIGHTER(green); blue = IMAT_LIGHTER(blue); } if (!active) { unsigned char bg_r, bg_g, bg_b; iupStrToRGB(ih->data->bgcolor, &bg_r, &bg_g, &bg_b); iupImageColorMakeInactive(&red, &green, &blue, bg_r, bg_g, bg_b); } /* Fill the box with the color */ cdCanvasForeground(cnv, cdEncodeColor(red, green, blue)); cdCanvasBox(cnv, x1 + DX_FILL, x2 - DX_FILL, y1 - DY_FILL, y2 + DY_FILL); /* Draw the border */ framecolor = cdIupConvertColor(iupAttribGetStr(ih, "FRAMECOLOR")); cdCanvasForeground(cnv, framecolor); cdCanvasRect(cnv, x1 + DX_BORDER, x2 - DX_BORDER, y1 - DY_BORDER, y2 + DY_BORDER); } return IUP_DEFAULT; /* draw nothing more */ }
static void winToggleGetAlignment(Ihandle* ih, int *horiz_alignment, int *vert_alignment) { char value1[30], value2[30]; iupStrToStrStr(iupAttribGetStr(ih, "ALIGNMENT"), value1, value2, ':'); if (iupStrEqualNoCase(value1, "ARIGHT")) *horiz_alignment = IUP_ALIGN_ARIGHT; else if (iupStrEqualNoCase(value1, "ALEFT")) *horiz_alignment = IUP_ALIGN_ALEFT; else /* "ACENTER" */ *horiz_alignment = IUP_ALIGN_ACENTER; if (iupStrEqualNoCase(value2, "ABOTTOM")) *vert_alignment = IUP_ALIGN_ABOTTOM; else if (iupStrEqualNoCase(value2, "ATOP")) *vert_alignment = IUP_ALIGN_ATOP; else /* "ACENTER" */ *vert_alignment = IUP_ALIGN_ACENTER; }
void* iupdrvImageCreateMask(Ihandle *ih) { int bpp; GdkPixmap *mask; char *bits, *sb; int y, x, line_size = (ih->currentwidth+7)/8; int size_bytes = line_size*ih->currentheight; unsigned char* imgdata = (unsigned char*)iupAttribGetStr(ih, "WID"); unsigned char colors[256]; bpp = iupAttribGetInt(ih, "BPP"); if (bpp > 8) return NULL; bits = (char*)malloc(size_bytes); if (!bits) return NULL; memset(bits, 0, size_bytes); iupImageInitNonBgColors(ih, colors); sb = bits; for (y=0; y<ih->currentheight; y++) { for (x=0; x<ih->currentwidth; x++) { int byte = x/8; int bit = x%8; int index = (int)imgdata[y*ih->currentwidth+x]; if (colors[index]) sb[byte] = (char)(sb[byte] | (1<<bit)); } sb += line_size; } mask = gdk_bitmap_create_from_data(NULL, bits, ih->currentwidth, ih->currentheight); free(bits); return mask; }
static char* iZboxGetValuePosAttrib(Ihandle* ih) { Ihandle* child; int pos; Ihandle* curr_handle = (Ihandle*)iupAttribGetStr(ih, "VALUE_HANDLE"); if (!iupObjectCheck(curr_handle)) return NULL; for (pos=0, child = ih->firstchild; child; child = child->brother, pos++) { if (child == curr_handle) /* found child */ { char *str = iupStrGetMemory(50); sprintf(str, "%d", pos); return str; } } return NULL; }
void iupNormalizeSizeBoxChild(Ihandle *ih, int children_natural_maxwidth, int children_natural_maxheight) { Ihandle* child; int normalize = iNormalizeGetNormalizeSize(iupAttribGetStr(ih, "NORMALIZESIZE")); if (!normalize) return; /* It is called from Vbox and Hbox ComputeNaturalSizeMethod after the natural size is calculated */ /* reset the natural width and/or height */ for (child = ih->firstchild; child; child = child->brother) { if (!child->floating && (child->iclass->nativetype != IUP_TYPEVOID || !iupStrEqual(child->iclass->name, "fill"))) { if (normalize & NORMALIZE_WIDTH) child->naturalwidth = children_natural_maxwidth; if (normalize & NORMALIZE_HEIGHT) child->naturalheight = children_natural_maxheight; } } }
static void gtkCanvasLayoutUpdateMethod(Ihandle *ih) { GdkWindow* window = iupgtkGetWindow(ih->handle); iupdrvBaseLayoutUpdateMethod(ih); /* Force GdkWindow size update when not visible, so when mapped before show the function gdk_drawable_get_size returns the correct value. */ if (!iupdrvIsVisible(ih)) gdk_window_resize(window, ih->currentwidth, ih->currentheight); if (iupAttribGetStr(ih, "_IUP_GTK_FIRST_RESIZE")) { /* GTK is nor calling gtkCanvasConfigureEvent on the first resize */ IFnii cb = (IFnii)IupGetCallback(ih,"RESIZE_CB"); iupAttribSetStr(ih, "_IUP_GTK_FIRST_RESIZE", NULL); if (cb) { int sb_w = 0, sb_h = 0; if (ih->data->sb) { int sb_size = iupdrvGetScrollbarSize(); if (ih->data->sb & IUP_SB_HORIZ) sb_h += sb_size; /* sb horizontal affects vertical size */ if (ih->data->sb & IUP_SB_VERT) sb_w += sb_size; /* sb vertical affects horizontal size */ } if (iupAttribGetBoolean(ih, "BORDER")) { sb_w += 4; sb_h += 4; } cb(ih, ih->currentwidth-sb_w, ih->currentheight-sb_h); } } }
static char* motClipboardGetFormatDataAttrib(Ihandle *ih) { unsigned long size; void* data; Window window = motClipboardGetWindow(); char* format = iupAttribGetStr(ih, "FORMAT"); if (!format) return 0; /* number of bytes of data */ if (XmClipboardInquireLength(iupmot_display, window, format, &size)!=ClipboardSuccess) return NULL; data = iupStrGetMemory(size); if (XmClipboardRetrieve(iupmot_display, window, format, data, size, NULL, NULL)!=ClipboardSuccess) return NULL; iupAttribSetStrf(ih, "FORMATDATASIZE", "%d", size); return data; }
static HBITMAP winButtonGetBitmap(Ihandle* ih, UINT itemState, int *shift, int *w, int *h, int *bpp, HBITMAP *hMask) { char *name; int make_inactive = 0; HBITMAP hBitmap; *hMask = NULL; if (itemState & ODS_DISABLED) { name = iupAttribGet(ih, "IMINACTIVE"); if (!name) { name = iupAttribGet(ih, "IMAGE"); make_inactive = 1; } } else { name = iupAttribGet(ih, "IMPRESS"); if (itemState & ODS_SELECTED && name) { if (shift && !iupAttribGetStr(ih, "IMPRESSBORDER")) *shift = 0; } else name = iupAttribGet(ih, "IMAGE"); } hBitmap = iupImageGetImage(name, ih, make_inactive); /* must use this info, since image can be a driver image loaded from resources */ iupdrvImageGetInfo(hBitmap, w, h, bpp); if (*bpp == 8) *hMask = iupdrvImageCreateMask(IupGetHandle(name)); return hBitmap; }
static int motToggleSetValueAttrib(Ihandle* ih, const char* value) { Ihandle *radio; unsigned char check; if (iupStrEqualNoCase(value,"NOTDEF")) check = XmINDETERMINATE; else if (iupStrBoolean(value)) check = XmSET; else check = XmUNSET; /* This is necessary because Motif toggle does not have support for radio. It is implemented using an external RadioBox that we do not use. */ radio = iupRadioFindToggleParent(ih); if (radio) { Ihandle* last_tg; unsigned char oldcheck; XtVaGetValues(ih->handle, XmNset, &oldcheck, NULL); last_tg = (Ihandle*)iupAttribGetStr(radio, "_IUPMOT_LASTTOGGLE"); if (check) { if (iupObjectCheck(last_tg) && last_tg != ih) XtVaSetValues(last_tg->handle, XmNset, XmUNSET, NULL); iupAttribSetStr(radio, "_IUPMOT_LASTTOGGLE", (char*)ih); } if (last_tg != ih && oldcheck != check) XtVaSetValues(ih->handle, XmNset, check, NULL); } else XtVaSetValues(ih->handle, XmNset, check, NULL); return 0; }
static void iGLValComputeNaturalSizeMethod(Ihandle* ih, int *w, int *h, int *children_expand) { int natural_w = 0, natural_h = 0; int fit2backimage = iupAttribGetBoolean(ih, "FITTOBACKIMAGE"); char* bgimage = iupAttribGet(ih, "BACKIMAGE"); if (fit2backimage && bgimage) { iupAttribSet(ih, "BORDERWIDTH", "0"); iupGLImageGetInfo(bgimage, &natural_w, &natural_h, NULL); } else { int charwidth, charheight; int is_horizontal = iupStrEqualNoCase(iupAttribGetStr(ih, "ORIENTATION"), "HORIZONTAL"); iupGLFontGetCharSize(ih, &charwidth, &charheight); if (is_horizontal) { natural_h = charheight; if (ih->userwidth <= 0) natural_w = 15 * charwidth; } else { natural_w = charheight; if (ih->userheight <= 0) natural_h = 15 * charwidth; } } *w = natural_w; *h = natural_h; (void)children_expand; /* unset if not a container */ }
static int motProgressBarSetBgColorAttrib(Ihandle* ih, const char* value) { if (!iupAttribGetStr(ih, "FGCOLOR")) { Pixel color; unsigned char r, g, b; if (!iupStrToRGB(value, &r, &g, &b)) return 0; r = (r*8)/10; g = (g*8)/10; b = (b*8)/10; color = iupmotColorGetPixel(r, g, b); if (color != (Pixel)-1) { Widget w = XtNameToWidget(ih->handle, "*Scrollbar"); XtVaSetValues(w, XmNtroughColor, color, NULL); } } return iupdrvBaseSetBgColorAttrib(ih, value); }
static char* iTabsGetValuePosAttrib(Ihandle* ih) { if (ih->handle) { int pos = iupdrvTabsGetCurrentTab(ih); char *str = iupStrGetMemory(50); sprintf(str, "%d", pos); return str; } else { Ihandle* child = (Ihandle*)iupAttribGetStr(ih, "_IUPTABS_VALUE_HANDLE"); int pos = IupGetChildPos(ih, child); if (pos != -1) /* found child */ { char *str = iupStrGetMemory(50); sprintf(str, "%d", pos); return str; } } return NULL; }
static int iLinkButton_CB(Ihandle* ih, int button, int pressed, int x, int y, char* status) { if (button==IUP_BUTTON1 && pressed) { IFns cb = (IFns)IupGetCallback(ih, "ACTION"); char* url = iupAttribGetStr(ih, "URL"); if (cb) { int ret = cb(ih, url); if (ret == IUP_CLOSE) IupExitLoop(); else if (ret == IUP_DEFAULT && url) IupHelp(url); } else IupHelp(url); } (void)x; (void)y; (void)status; return IUP_DEFAULT; }
void iupdrvValGetMinSize(Ihandle* ih, int *w, int *h) { int ticks_size = 0; if (iupAttribGetInt(ih, "SHOWTICKS")) { char* tickspos = iupAttribGetStr(ih, "TICKSPOS"); if(iupStrEqualNoCase(tickspos, "BOTH")) ticks_size = 2*8; else ticks_size = 8; } if (ih->data->type == IVAL_HORIZONTAL) { *w = 35; *h = 30+ticks_size; } else { *w = 30+ticks_size; *h = 35; } }
static int iGLSeparatorACTION(Ihandle* ih) { int x1, y1, x2, y2; int active = iupAttribGetInt(ih, "ACTIVE"); char* color = iupAttribGetStr(ih, "BORDERCOLOR"); float bwidth = iupAttribGetFloat(ih, "BORDERWIDTH"); if (iGLSeparatorIsVertical(ih)) { y1 = 0; y2 = ih->currentheight-1; x1 = x2 = ih->currentwidth / 2; } else { x1 = 0; x2 = ih->currentwidth-1; y1 = y2 = ih->currentheight / 2; } iupGLDrawLine(ih, x1, y1, x2, y2, bwidth, color, active); return IUP_DEFAULT; }
static void motDialogLayoutUpdateMethod(Ihandle *ih) { int border, caption, menu; if (ih->data->ignore_resize || iupAttribGetStr(ih, "_IUPMOT_FS_STYLE")) return; /* for dialogs the position is not updated here */ ih->data->ignore_resize = 1; iupdrvDialogGetDecoration(ih, &border, &caption, &menu); if (!iupAttribGetIntDefault(ih, "RESIZE")) { int width = ih->currentwidth - 2*border; int height = ih->currentheight - 2*border - caption; XtVaSetValues(ih->handle, XmNwidth, width, XmNheight, height, XmNminWidth, width, XmNminHeight, height, XmNmaxWidth, width, XmNmaxHeight, height, NULL); } else { XtVaSetValues(ih->handle, XmNwidth, (XtArgVal)(ih->currentwidth - 2*border), /* excluding the border */ XmNheight, (XtArgVal)(ih->currentheight - 2*border - caption), NULL); } ih->data->ignore_resize = 0; }
void iupdrvValGetMinSize(Ihandle* ih, int *w, int *h) { /* LAYOUT_DECORATION_ESTIMATE */ int ticks_size = 0; if (iupAttribGetInt(ih, "SHOWTICKS")) { char* tickspos = iupAttribGetStr(ih, "TICKSPOS"); if(iupStrEqualNoCase(tickspos, "BOTH")) ticks_size = 2*8; else ticks_size = 8; } if (ih->data->orientation == IVAL_HORIZONTAL) { *w = 35; *h = 30+ticks_size; } else { *w = 30+ticks_size; *h = 35; } }
static int winProgressBarMapMethod(Ihandle* ih) { DWORD dwStyle = WS_CHILD|WS_CLIPSIBLINGS; if (!ih->parent) return IUP_ERROR; if (iupStrEqualNoCase(iupAttribGetStr(ih, "ORIENTATION"), "VERTICAL")) { dwStyle |= PBS_VERTICAL; if (ih->currentheight < ih->currentwidth) { int tmp = ih->currentheight; ih->currentheight = ih->currentwidth; ih->currentwidth = tmp; } } if (!iupwin_comctl32ver6 && !iupAttribGetBoolean(ih, "DASHED")) dwStyle |= PBS_SMOOTH; if (iupwin_comctl32ver6 && iupAttribGetBoolean(ih, "MARQUEE")) { dwStyle |= PBS_MARQUEE; ih->data->marquee = 1; } if (!iupwinCreateWindow(ih, PROGRESS_CLASS, 0, dwStyle, NULL)) return IUP_ERROR; /* configure the native range */ SendMessage(ih->handle, PBM_SETRANGE, 0, MAKELPARAM(0, IUP_PB_MAX)); return IUP_NOERROR; }
static int motClipboardSetFormatDataAttrib(Ihandle *ih, const char *value) { int size; long item_id = 0; Window window = motClipboardGetWindow(); XmString clip_label; char* format; if (!value) { XmClipboardUndoCopy(iupmot_display, window); return 0; } size = iupAttribGetInt(ih, "FORMATDATASIZE"); if (!size) return 0; format = iupAttribGetStr(ih, "FORMAT"); if (!format) return 0; clip_label = XmStringCreateLocalized ("IupClipboard"); if (XmClipboardStartCopy(iupmot_display, window, clip_label, CurrentTime, NULL, NULL, &item_id)!=ClipboardSuccess) { XmStringFree(clip_label); return 0; } XmClipboardCopy(iupmot_display, window, item_id, format, (char*)value, (long)size, 0, NULL); XmClipboardEndCopy(iupmot_display, window, item_id); XmStringFree(clip_label); return 0; }
static int winValMapMethod(Ihandle* ih) { DWORD dwStyle = WS_CHILD | WS_CLIPSIBLINGS | TBS_AUTOTICKS; int show_ticks; if (!ih->parent) return IUP_ERROR; /* Track bar Orientation */ if (ih->data->type == IVAL_HORIZONTAL) dwStyle |= TBS_HORZ; else dwStyle |= TBS_VERT; if (iupAttribGetBoolean(ih, "CANFOCUS")) dwStyle |= WS_TABSTOP; /* Track bar Ticks */ show_ticks = iupAttribGetInt(ih, "SHOWTICKS"); if (!show_ticks) { dwStyle |= TBS_NOTICKS; /* No show_ticks */ } else { char* tickspos; if (show_ticks<2) show_ticks=2; ih->data->show_ticks = show_ticks; /* non zero value, can be changed later, but not to zero */ /* Defines the position of tick marks */ tickspos = iupAttribGetStr(ih, "TICKSPOS"); if(iupStrEqualNoCase(tickspos, "BOTH")) dwStyle |= TBS_BOTH; else if(iupStrEqualNoCase(tickspos, "REVERSE")) dwStyle |= TBS_BOTTOM; /* same as TBS_RIGHT */ else /* NORMAL */ dwStyle |= TBS_TOP; /* same as TBS_LEFT */ } if (!iupwinCreateWindowEx(ih, TRACKBAR_CLASS, 0, dwStyle)) return IUP_ERROR; /* Process Keyboard */ IupSetCallback(ih, "_IUPWIN_CTRLPROC_CB", (Icallback)winValProc); /* Process Val Scroll commands */ IupSetCallback(ih, "_IUPWIN_CUSTOMSCROLL_CB", (Icallback)winValCustomScroll); /* Process background color */ IupSetCallback(ih, "_IUPWIN_CTLCOLOR_CB", (Icallback)winValCtlColor); /* configure the native range */ SendMessage(ih->handle, TBM_SETRANGEMIN, FALSE, 0); SendMessage(ih->handle, TBM_SETRANGEMAX, FALSE, SHRT_MAX); if (ih->data->inverted) SendMessage(ih->handle, TBM_SETPOS, FALSE, SHRT_MAX); /* default initial position is at MIN */ return IUP_NOERROR; }
static int motFrameMapMethod(Ihandle* ih) { char *title; int num_args = 0; Arg args[20]; Widget child_manager; if (!ih->parent) return IUP_ERROR; title = iupAttribGet(ih, "TITLE"); if (title) iupAttribSetStr(ih, "_IUPFRAME_HAS_TITLE", "1"); else { char* value = iupAttribGetStr(ih, "SUNKEN"); if (iupStrBoolean(value)) iupMOT_SETARG(args, num_args, XmNshadowType, XmSHADOW_IN); else iupMOT_SETARG(args, num_args, XmNshadowType, XmSHADOW_ETCHED_IN); if (iupAttribGet(ih, "BGCOLOR")) iupAttribSetStr(ih, "_IUPFRAME_HAS_BGCOLOR", "1"); } /* Core */ iupMOT_SETARG(args, num_args, XmNmappedWhenManaged, False); /* not visible when managed */ iupMOT_SETARG(args, num_args, XmNx, 0); /* x-position */ iupMOT_SETARG(args, num_args, XmNy, 0); /* y-position */ iupMOT_SETARG(args, num_args, XmNwidth, 10); /* default width to avoid 0 */ iupMOT_SETARG(args, num_args, XmNheight, 10); /* default height to avoid 0 */ /* Manager */ iupMOT_SETARG(args, num_args, XmNshadowThickness, 2); /* Frame */ iupMOT_SETARG(args, num_args, XmNmarginHeight, 0); /* no shadow margins */ iupMOT_SETARG(args, num_args, XmNmarginWidth, 0); /* no shadow margins */ ih->handle = XtCreateManagedWidget( iupDialogGetChildIdStr(ih), /* child identifier */ xmFrameWidgetClass, /* widget class */ iupChildTreeGetNativeParentHandle(ih), /* widget parent */ args, num_args); if (!ih->handle) return IUP_ERROR; ih->serial = iupDialogGetChildId(ih); /* must be after using the string */ if (title) { Widget title_label; num_args = 0; /* Label */ iupMOT_SETARG(args, num_args, XmNlabelType, XmSTRING); iupMOT_SETARG(args, num_args, XmNmarginHeight, 0); /* default padding */ iupMOT_SETARG(args, num_args, XmNmarginWidth, 0); /* Frame Constraint */ iupMOT_SETARG(args, num_args, XmNchildType, XmFRAME_TITLE_CHILD); title_label = XtCreateManagedWidget("title_label", xmLabelWidgetClass, ih->handle, args, num_args); iupmotSetString(title_label, XmNlabelString, title); iupAttribSetStr(ih, "_IUPMOT_FRAMELABEL", (char*)title_label); } child_manager = XtVaCreateManagedWidget( "child_manager", xmBulletinBoardWidgetClass, ih->handle, /* Core */ XmNborderWidth, 0, /* Manager */ XmNshadowThickness, 0, XmNnavigationType, XmTAB_GROUP, /* BulletinBoard */ XmNmarginWidth, 0, XmNmarginHeight, 0, XmNresizePolicy, XmRESIZE_NONE, /* no automatic resize of children */ /* Frame Constraint */ XmNchildType, XmFRAME_WORKAREA_CHILD, NULL); iupAttribSetStr(ih, "_IUPMOT_FRAMECONTAINER", (char*)child_manager); if (iupStrBoolean(IupGetGlobal("INPUTCALLBACKS"))) XtAddEventHandler(child_manager, PointerMotionMask, False, (XtEventHandler)iupmotDummyPointerMotionEvent, NULL); /* initialize the widget */ XtRealizeWidget(ih->handle); return IUP_NOERROR; }
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 winFileDlgPopup(Ihandle *ih, int x, int y) { InativeHandle* parent = iupDialogGetNativeParent(ih); OPENFILENAME openfilename; int result, dialogtype; char *value; iupAttribSetInt(ih, "_IUPDLG_X", x); /* used in iupDialogUpdatePosition */ iupAttribSetInt(ih, "_IUPDLG_Y", y); value = iupAttribGetStr(ih, "DIALOGTYPE"); if (iupStrEqualNoCase(value, "SAVE")) dialogtype = IUP_DIALOGSAVE; else if (iupStrEqualNoCase(value, "DIR")) dialogtype = IUP_DIALOGDIR; else dialogtype = IUP_DIALOGOPEN; if (dialogtype == IUP_DIALOGDIR) { winFileDlgGetFolder(ih); return IUP_NOERROR; } if (!parent) parent = GetActiveWindow(); /* if NOT set will NOT be Modal */ /* anyway it will be modal only relative to its parent */ ZeroMemory(&openfilename, sizeof(OPENFILENAME)); openfilename.lStructSize = sizeof(OPENFILENAME); openfilename.hwndOwner = parent; value = iupAttribGet(ih, "EXTFILTER"); if (value) { int index; openfilename.lpstrFilter = winFileDlgStrReplaceSeparator(value); value = iupAttribGet(ih, "FILTERUSED"); if (iupStrToInt(value, &index)) openfilename.nFilterIndex = index; else openfilename.nFilterIndex = 1; } else { value = iupAttribGet(ih, "FILTER"); if (value) { int sz1, sz2; char* info = iupAttribGet(ih, "FILTERINFO"); if (!info) info = value; /* concat FILTERINFO+FILTER */ sz1 = strlen(info)+1; sz2 = strlen(value)+1; openfilename.lpstrFilter = (char*)malloc(sz1+sz2+1); memcpy((char*)openfilename.lpstrFilter, info, sz1); memcpy((char*)openfilename.lpstrFilter+sz1, value, sz2); ((char*)openfilename.lpstrFilter)[sz1+sz2] = 0; /* additional 0 at the end */ openfilename.nFilterIndex = 1; } } openfilename.lpstrFile = (char*)malloc(IUP_MAX_FILENAME_SIZE+1); value = iupAttribGet(ih, "FILE"); if (value) { strncpy(openfilename.lpstrFile, value, IUP_MAX_FILENAME_SIZE); winFileDlgStrReplacePathSlash(openfilename.lpstrFile); } else openfilename.lpstrFile[0] = 0; openfilename.nMaxFile = IUP_MAX_FILENAME_SIZE; openfilename.lpstrInitialDir = iupStrDup(iupAttribGet(ih, "DIRECTORY")); if (openfilename.lpstrInitialDir) winFileDlgStrReplacePathSlash((char*)openfilename.lpstrInitialDir); openfilename.lpstrTitle = iupAttribGet(ih, "TITLE"); openfilename.Flags = OFN_PATHMUSTEXIST | OFN_HIDEREADONLY; if (!iupAttribGetBoolean(ih, "NOOVERWRITEPROMPT")) openfilename.Flags |= OFN_OVERWRITEPROMPT; if (iupAttribGetBoolean(ih, "SHOWHIDDEN")) openfilename.Flags |= OFN_FORCESHOWHIDDEN; value = iupAttribGet(ih, "ALLOWNEW"); if (!value) { if (dialogtype == IUP_DIALOGSAVE) value = "YES"; else value = "NO"; } if (iupStrBoolean(value)) openfilename.Flags |= OFN_CREATEPROMPT; else openfilename.Flags |= OFN_FILEMUSTEXIST; if (iupAttribGetBoolean(ih, "NOCHANGEDIR")) openfilename.Flags |= OFN_NOCHANGEDIR; if (iupAttribGetBoolean(ih, "MULTIPLEFILES")) openfilename.Flags |= OFN_ALLOWMULTISELECT; openfilename.lpfnHook = winFileDlgSimpleHook; openfilename.Flags |= OFN_ENABLEHOOK | OFN_EXPLORER | OFN_ENABLESIZING; openfilename.lCustData = (LPARAM)ih; if (iupAttribGetBoolean(ih, "SHOWPREVIEW") && IupGetCallback(ih, "FILE_CB")) { openfilename.Flags |= OFN_ENABLETEMPLATE; openfilename.hInstance = iupwin_dll_hinstance? iupwin_dll_hinstance: iupwin_hinstance; openfilename.lpTemplateName = "iupPreviewDlg"; openfilename.lpfnHook = winFileDlgPreviewHook; } if (IupGetCallback(ih, "HELP_CB")) openfilename.Flags |= OFN_SHOWHELP; if (dialogtype == IUP_DIALOGOPEN) result = GetOpenFileName(&openfilename); else result = GetSaveFileName(&openfilename); if (result) { if (iupAttribGetBoolean(ih, "MULTIPLEFILES")) { int i = 0; char* dir = iupStrFileGetPath(openfilename.lpstrFile); /* the first part is the directory already */ iupAttribStoreStr(ih, "DIRECTORY", dir); free(dir); /* If there is more than one file, replace terminator by the separator */ if (openfilename.lpstrFile[openfilename.nFileOffset-1] == 0 && openfilename.nFileOffset>0) { while (openfilename.lpstrFile[i] != 0 || openfilename.lpstrFile[i+1] != 0) { if (openfilename.lpstrFile[i]==0) openfilename.lpstrFile[i] = '|'; i++; } openfilename.lpstrFile[i] = '|'; } iupAttribSetStr(ih, "STATUS", "0"); iupAttribSetStr(ih, "FILEEXIST", "YES"); } else { if (iupdrvIsFile(openfilename.lpstrFile)) /* check if file exists */ { char* dir = iupStrFileGetPath(openfilename.lpstrFile); iupAttribStoreStr(ih, "DIRECTORY", dir); free(dir); iupAttribSetStr(ih, "FILEEXIST", "YES"); iupAttribSetStr(ih, "STATUS", "0"); } else { iupAttribSetStr(ih, "FILEEXIST", "NO"); iupAttribSetStr(ih, "STATUS", "1"); } } iupAttribStoreStr(ih, "VALUE", openfilename.lpstrFile); iupAttribSetInt(ih, "FILTERUSED", (int)openfilename.nFilterIndex); } else { iupAttribSetStr(ih, "FILTERUSED", NULL); iupAttribSetStr(ih, "VALUE", NULL); iupAttribSetStr(ih, "FILEEXIST", NULL); iupAttribSetStr(ih, "STATUS", "-1"); } if (openfilename.lpstrFilter) free((char*)openfilename.lpstrFilter); if (openfilename.lpstrInitialDir) free((char*)openfilename.lpstrInitialDir); if (openfilename.lpstrFile) free(openfilename.lpstrFile); return IUP_NOERROR; }
/* Draw the line titles, visible, between lin and lastlin, include it. Line titles marked will be draw with the appropriate feedback. -> lin1 - First line to have its title drawn -> lin2 - Last line to have its title drawn */ void iupMatrixDrawTitleLines(Ihandle* ih, int lin1, int lin2) { int x1, y1, x2, y2, first_lin; int lin, alignment, active, framehighlight; long framecolor; IFniiiiiiC draw_cb; if (!ih->data->columns.dt[0].size) return; if (ih->data->lines.num_noscroll>1 && lin1==1 && lin2==ih->data->lines.num_noscroll-1) { first_lin = 0; y1 = 0; } else { if (lin1 > ih->data->lines.last || lin2 < ih->data->lines.first) return; if (lin1 < ih->data->lines.first) lin1 = ih->data->lines.first; if (lin2 > ih->data->lines.last) lin2 = ih->data->lines.last; first_lin = ih->data->lines.first; y1 = 0; for (lin = 0; lin< ih->data->lines.num_noscroll; lin++) y1 += ih->data->lines.dt[lin].size; } /* Start the position of the line title */ x1 = 0; x2 = ih->data->columns.dt[0].size; iupMATRIX_CLIPAREA(ih, x1, x2, y1, ih->data->h-1); cdCanvasClip(ih->data->cd_canvas, CD_CLIPAREA); /* Find the initial position of the first line */ if (first_lin == ih->data->lines.first) y1 -= ih->data->lines.first_offset; for(lin = first_lin; lin < lin1; lin++) y1 += ih->data->lines.dt[lin].size; framecolor = cdIupConvertColor(iupAttribGetStr(ih, "FRAMECOLOR")); framehighlight = iupAttribGetInt(ih, "FRAMETITLEHIGHLIGHT"); active = iupdrvIsActive(ih); draw_cb = (IFniiiiiiC)IupGetCallback(ih, "DRAW_CB"); alignment = iMatrixDrawGetColAlignment(ih, 0); /* Draw the titles */ for(lin = lin1; lin <= lin2; lin++) { /* If it is a hidden line (size = 0), don't draw the title */ if(ih->data->lines.dt[lin].size == 0) continue; y2 = y1 + ih->data->lines.dt[lin].size; /* If it doesn't have title, the loop just calculate the final position */ if (ih->data->columns.dt[0].size) { int marked = iupMatrixLineIsMarked(ih, lin); iMatrixDrawBackground(ih, x1, x2, y1, y2, marked, active, lin, 0); iMatrixDrawFrameRectTitle(ih, lin, 0, x1, x2, y1, y2, framecolor, framehighlight); iMatrixDrawCellValue(ih, x1, x2, y1, y2, alignment, marked, active, lin, 0, draw_cb, framecolor); } y1 = y2; } cdCanvasClip(ih->data->cd_canvas, CD_CLIPOFF); }
/* Draw the column titles, visible, between col and lastcol, include it. Column titles marked will be draw with the appropriate feedback. -> col1 - First column to have its title drawn -> col2 - Last column to have its title drawn */ void iupMatrixDrawTitleColumns(Ihandle* ih, int col1, int col2) { int x1, y1, x2, y2, first_col; int col, active, alignment, framehighlight; long framecolor; IFniiiiiiC draw_cb; if (!ih->data->lines.dt[0].size) return; if (ih->data->columns.num_noscroll>1 && col1==1 && col2==ih->data->columns.num_noscroll-1) { first_col = 0; x1 = 0; } else { if (col1 > ih->data->columns.last || col2 < ih->data->columns.first) return; if (col1 < ih->data->columns.first) col1 = ih->data->columns.first; if (col2 > ih->data->columns.last) col2 = ih->data->columns.last; first_col = ih->data->columns.first; x1 = 0; for (col = 0; col< ih->data->columns.num_noscroll; col++) x1 += ih->data->columns.dt[col].size; } /* Start the position of the first column title */ y1 = 0; y2 = ih->data->lines.dt[0].size; iupMATRIX_CLIPAREA(ih, x1, ih->data->w-1, y1, y2); cdCanvasClip(ih->data->cd_canvas, CD_CLIPAREA); /* Find the initial position of the first column */ if (first_col==ih->data->columns.first) x1 -= ih->data->columns.first_offset; for(col = first_col; col < col1; col++) x1 += ih->data->columns.dt[col].size; framecolor = cdIupConvertColor(iupAttribGetStr(ih, "FRAMECOLOR")); framehighlight = iupAttribGetInt(ih, "FRAMETITLEHIGHLIGHT"); active = iupdrvIsActive(ih); draw_cb = (IFniiiiiiC)IupGetCallback(ih, "DRAW_CB"); alignment = iMatrixDrawGetAlignmentLin0(ih); /* Draw the titles */ for(col = col1; col <= col2; col++) { /* If it is an hide column (size = 0), no draw the title */ if(ih->data->columns.dt[col].size == 0) continue; x2 = x1 + ih->data->columns.dt[col].size; /* If it doesn't have title, the loop just calculate the final position */ if (ih->data->lines.dt[0].size) { int sort = 0; int marked = iupMatrixColumnIsMarked(ih, col); iMatrixDrawBackground(ih, x1, x2, y1, y2, marked, active, 0, col); iMatrixDrawFrameRectTitle(ih, 0, col, x1, x2, y1, y2, framecolor, framehighlight); if (iMatrixDrawSortSign(ih, x2, y1, y2, col, active)) sort = IMAT_DROPBOX_W; /* same space is used by the sort sign */ iMatrixDrawCellValue(ih, x1, x2-sort, y1, y2, alignment, marked, active, 0, col, draw_cb, framecolor); } x1 = x2; } cdCanvasClip(ih->data->cd_canvas, CD_CLIPOFF); }
/* Redraw a block of cells of the matrix. Handle marked cells, change automatically the background color of them. - lin1, col1 : cell coordinates that mark the left top corner of the area to be redrawn - lin2, col2 : cell coordinates that mark the right bottom corner of the area to be redrawn */ void iupMatrixDrawCells(Ihandle* ih, int lin1, int col1, int lin2, int col2) { int x1, y1, x2, y2, old_x2, old_y1, old_y2; int alignment, lin, col, active, first_col, first_lin; long framecolor, emptyarea_color = -1; IFnii mark_cb; IFnii dropcheck_cb; IFniiiiiiC draw_cb; x2 = ih->data->w-1; y2 = ih->data->h-1; old_x2 = x2; old_y1 = 0; old_y2 = y2; if (ih->data->lines.num <= 1 || ih->data->columns.num <= 1) return; if (ih->data->columns.num_noscroll>1 && col1==1 && col2==ih->data->columns.num_noscroll-1) { first_col = 0; x1 = 0; } else { if (col1 > ih->data->columns.last || col2 < ih->data->columns.first) return; if (col1 < ih->data->columns.first) col1 = ih->data->columns.first; if (col2 > ih->data->columns.last) col2 = ih->data->columns.last; first_col = ih->data->columns.first; x1 = 0; for (col = 0; col< ih->data->columns.num_noscroll; col++) x1 += ih->data->columns.dt[col].size; } if (ih->data->lines.num_noscroll>1 && lin1==1 && lin2==ih->data->lines.num_noscroll-1) { first_lin = 0; y1 = 0; } else { if (lin1 > ih->data->lines.last || lin2 < ih->data->lines.first) return; if (lin1 < ih->data->lines.first) lin1 = ih->data->lines.first; if (lin2 > ih->data->lines.last) lin2 = ih->data->lines.last; first_lin = ih->data->lines.first; y1 = 0; for (lin = 0; lin< ih->data->lines.num_noscroll; lin++) y1 += ih->data->lines.dt[lin].size; } iupMATRIX_CLIPAREA(ih, x1, x2, y1, y2); cdCanvasClip(ih->data->cd_canvas, CD_CLIPOFF); /* wait for background */ /* Find the initial position of the first column */ if (first_col==ih->data->columns.first) x1 -= ih->data->columns.first_offset; for(col = first_col; col < col1; col++) x1 += ih->data->columns.dt[col].size; /* Find the initial position of the first line */ if (first_lin == ih->data->lines.first) y1 -= ih->data->lines.first_offset; for(lin = first_lin; lin < lin1; lin++) y1 += ih->data->lines.dt[lin].size; /* Find the final position of the last column */ x2 = x1; for( ; col <= col2; col++) x2 += ih->data->columns.dt[col].size; /* Find the final position of the last line */ y2 = y1; for( ; lin <= lin2; lin++) y2 += ih->data->lines.dt[lin].size; if ((col2 == ih->data->columns.num-1) && (old_x2 > x2)) { emptyarea_color = cdIupConvertColor(ih->data->bgcolor_parent); cdCanvasForeground(ih->data->cd_canvas, emptyarea_color); /* If it was drawn until the last column and remains space in the right of it, then delete this area with the the background color. */ iupMATRIX_BOX(ih, x2, old_x2, old_y1, old_y2); } if ((lin2 == ih->data->lines.num-1) && (old_y2 > y2)) { if (emptyarea_color == -1) emptyarea_color = cdIupConvertColor(ih->data->bgcolor_parent); cdCanvasForeground(ih->data->cd_canvas, emptyarea_color); /* If it was drawn until the last line visible and remains space below it, then delete this area with the the background color. */ iupMATRIX_BOX(ih, 0, old_x2, y2, old_y2); } /* after the background */ cdCanvasClip(ih->data->cd_canvas, CD_CLIPAREA); /***** Draw the cell values and frame */ old_y1 = y1; framecolor = cdIupConvertColor(iupAttribGetStr(ih, "FRAMECOLOR")); active = iupdrvIsActive(ih); mark_cb = (IFnii)IupGetCallback(ih, "MARK_CB"); dropcheck_cb = (IFnii)IupGetCallback(ih, "DROPCHECK_CB"); draw_cb = (IFniiiiiiC)IupGetCallback(ih, "DRAW_CB"); for(col = col1; col <= col2; col++) /* For all the columns in the region */ { if (ih->data->columns.dt[col].size == 0) continue; alignment = iMatrixDrawGetColAlignment(ih, col); x2 = x1 + ih->data->columns.dt[col].size; for(lin = lin1; lin <= lin2; lin++) /* For all lines in the region */ { int drop = 0; int marked = 0; if (ih->data->lines.dt[lin].size == 0) continue; y2 = y1 + ih->data->lines.dt[lin].size; /* If the cell is marked, then draw it with attenuation color */ marked = iupMatrixMarkCellGet(ih, lin, col, mark_cb); iMatrixDrawBackground(ih, x1, x2, y1, y2, marked, active, lin, col); iMatrixDrawFrameRectCell(ih, lin, col, x1, x2, y1, y2, framecolor); if (dropcheck_cb) { int ret = dropcheck_cb(ih, lin, col); if (ret == IUP_DEFAULT) { drop = IMAT_DROPBOX_W+IMAT_PADDING_W/2; iMatrixDrawDropFeedback(ih, x2, y1, y2, active, framecolor); } else if (ret == IUP_CONTINUE) { drop = IMAT_TOGGLE_SIZE + IMAT_PADDING_W; iMatrixDrawToggle(ih, x2, y1, y2, lin, col, marked, active); } } /* draw the cell contents */ iMatrixDrawCellValue(ih, x1, x2-drop, y1, y2, alignment, marked, active, lin, col, draw_cb, framecolor); y1 = y2; } x1 = x2; y1 = old_y1; /* must reset also y */ } cdCanvasClip(ih->data->cd_canvas, CD_CLIPOFF); }
static int motTextMapMethod(Ihandle* ih) { int num_args = 0; Arg args[30]; Widget parent = iupChildTreeGetNativeParentHandle(ih); char* child_id = iupDialogGetChildIdStr(ih); int spin = 0; WidgetClass widget_class = xmTextWidgetClass; if (ih->data->is_multiline) { Widget sb_win; int wordwrap = 0; if (iupAttribGetBoolean(ih, "WORDWRAP")) { wordwrap = 1; ih->data->sb &= ~IUP_SB_HORIZ; /* must remove the horizontal scroolbar */ } /******************************/ /* Create the scrolled window */ /******************************/ iupmotSetArg(args, num_args, XmNmappedWhenManaged, False); /* not visible when managed */ iupmotSetArg(args, num_args, XmNscrollingPolicy, XmAPPLICATION_DEFINED); iupmotSetArg(args, num_args, XmNvisualPolicy, XmVARIABLE); iupmotSetArg(args, num_args, XmNscrollBarDisplayPolicy, XmSTATIC); /* can NOT be XmAS_NEEDED because XmAPPLICATION_DEFINED */ iupmotSetArg(args, num_args, XmNspacing, 0); /* no space between scrollbars and text */ iupmotSetArg(args, num_args, XmNborderWidth, 0); iupmotSetArg(args, num_args, XmNshadowThickness, 0); sb_win = XtCreateManagedWidget( child_id, /* child identifier */ xmScrolledWindowWidgetClass, /* widget class */ parent, /* widget parent */ args, num_args); if (!sb_win) return IUP_ERROR; parent = sb_win; child_id = "text"; num_args = 0; iupmotSetArg(args, num_args, XmNeditMode, XmMULTI_LINE_EDIT); if (wordwrap) iupmotSetArg(args, num_args, XmNwordWrap, True); } else { widget_class = xmTextFieldWidgetClass; if (iupAttribGetBoolean(ih, "SPIN")) { Widget spinbox; num_args = 0; iupmotSetArg(args, num_args, XmNmappedWhenManaged, False); /* not visible when managed */ iupmotSetArg(args, num_args, XmNspacing, 0); /* no space between spin and text */ iupmotSetArg(args, num_args, XmNborderWidth, 0); iupmotSetArg(args, num_args, XmNshadowThickness, 0); iupmotSetArg(args, num_args, XmNmarginHeight, 0); iupmotSetArg(args, num_args, XmNmarginWidth, 0); iupmotSetArg(args, num_args, XmNarrowSize, 8); if (iupStrEqualNoCase(iupAttribGetStr(ih, "SPINALIGN"), "LEFT")) iupmotSetArg(args, num_args, XmNarrowLayout, XmARROWS_BEGINNING); else iupmotSetArg(args, num_args, XmNarrowLayout, XmARROWS_END); spinbox = XtCreateManagedWidget( child_id, /* child identifier */ xmSpinBoxWidgetClass, /* widget class */ parent, /* widget parent */ args, num_args); if (!spinbox) return IUP_ERROR; XtAddCallback(spinbox, XmNmodifyVerifyCallback, (XtCallbackProc)motTextSpinModifyVerifyCallback, (XtPointer)ih); parent = spinbox; child_id = "text"; spin = 1; if (!iupAttribGetBoolean(ih, "SPINAUTO")) iupAttribSetStr(ih, "_IUPMOT_SPIN_NOAUTO", "1"); } num_args = 0; iupmotSetArg(args, num_args, XmNeditMode, XmSINGLE_LINE_EDIT); if (spin) { /* Spin Constraints */ iupmotSetArg(args, num_args, XmNspinBoxChildType, XmNUMERIC); iupmotSetArg(args, num_args, XmNminimumValue, 0); iupmotSetArg(args, num_args, XmNmaximumValue, 100); iupmotSetArg(args, num_args, XmNposition, 0); if (iupAttribGetBoolean(ih, "SPINWRAP")) iupmotSetArg(args, num_args, XmNwrap, TRUE); else iupmotSetArg(args, num_args, XmNwrap, FALSE); } else { iupmotSetArg(args, num_args, XmNmappedWhenManaged, False); /* not visible when managed */ } } iupmotSetArg(args, num_args, XmNx, 0); /* x-position */ iupmotSetArg(args, num_args, XmNy, 0); /* y-position */ iupmotSetArg(args, num_args, XmNwidth, 10); /* default width to avoid 0 */ iupmotSetArg(args, num_args, XmNheight, 10); /* default height to avoid 0 */ iupmotSetArg(args, num_args, XmNmarginHeight, 0); /* default padding */ iupmotSetArg(args, num_args, XmNmarginWidth, 0); if (iupAttribGetBoolean(ih, "CANFOCUS")) iupmotSetArg(args, num_args, XmNtraversalOn, True); else iupmotSetArg(args, num_args, XmNtraversalOn, False); iupmotSetArg(args, num_args, XmNnavigationType, XmTAB_GROUP); iupmotSetArg(args, num_args, XmNhighlightThickness, 2); iupmotSetArg(args, num_args, XmNverifyBell, False); iupmotSetArg(args, num_args, XmNspacing, 0); if (iupAttribGetBoolean(ih, "BORDER")) iupmotSetArg(args, num_args, XmNshadowThickness, 2); else iupmotSetArg(args, num_args, XmNshadowThickness, 0); if (ih->data->is_multiline) { if (ih->data->sb & IUP_SB_HORIZ) iupmotSetArg(args, num_args, XmNscrollHorizontal, True); else iupmotSetArg(args, num_args, XmNscrollHorizontal, False); if (ih->data->sb & IUP_SB_VERT) iupmotSetArg(args, num_args, XmNscrollVertical, True); else iupmotSetArg(args, num_args, XmNscrollVertical, False); } ih->handle = XtCreateManagedWidget( child_id, /* child identifier */ widget_class, /* widget class */ parent, /* widget parent */ args, num_args); if (!ih->handle) return IUP_ERROR; ih->serial = iupDialogGetChildId(ih); /* must be after using the string */ if (ih->data->is_multiline) { iupAttribSetStr(ih, "_IUP_EXTRAPARENT", (char*)parent); XtVaSetValues(parent, XmNworkWindow, ih->handle, NULL); } else if (spin) iupAttribSetStr(ih, "_IUP_EXTRAPARENT", (char*)parent); XtAddCallback(ih->handle, XmNhelpCallback, (XtCallbackProc)iupmotHelpCallback, (XtPointer)ih); XtAddEventHandler(ih->handle, EnterWindowMask, False, (XtEventHandler)iupmotEnterLeaveWindowEvent, (XtPointer)ih); XtAddEventHandler(ih->handle, LeaveWindowMask, False, (XtEventHandler)iupmotEnterLeaveWindowEvent, (XtPointer)ih); XtAddEventHandler(ih->handle, FocusChangeMask, False, (XtEventHandler)iupmotFocusChangeEvent, (XtPointer)ih); XtAddEventHandler(ih->handle, KeyPressMask, False, (XtEventHandler)motTextKeyPressEvent, (XtPointer)ih); XtAddEventHandler(ih->handle, PointerMotionMask, False, (XtEventHandler)iupmotPointerMotionEvent, (XtPointer)ih); XtAddEventHandler(ih->handle, ButtonPressMask|ButtonReleaseMask, False, (XtEventHandler)iupmotButtonPressReleaseEvent, (XtPointer)ih); XtAddCallback(ih->handle, XmNmodifyVerifyCallback, (XtCallbackProc)motTextModifyVerifyCallback, (XtPointer)ih); XtAddCallback(ih->handle, XmNmotionVerifyCallback, (XtCallbackProc)motTextMotionVerifyCallback, (XtPointer)ih); XtAddCallback(ih->handle, XmNvalueChangedCallback, (XtCallbackProc)motTextValueChangedCallback, (XtPointer)ih); /* Disable Drag Source */ iupmotDisableDragSource(ih->handle); /* initialize the widget */ if (ih->data->is_multiline || spin) XtRealizeWidget(parent); else XtRealizeWidget(ih->handle); if (IupGetGlobal("_IUP_RESET_TXTCOLORS")) { iupmotSetGlobalColorAttrib(ih->handle, XmNbackground, "TXTBGCOLOR"); iupmotSetGlobalColorAttrib(ih->handle, XmNforeground, "TXTFGCOLOR"); IupSetGlobal("_IUP_RESET_TXTCOLORS", NULL); } IupSetCallback(ih, "_IUP_XY2POS_CB", (Icallback)motTextConvertXYToPos); 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 int gtkToggleMapMethod(Ihandle* ih) { Ihandle* radio = iupRadioFindToggleParent(ih); char *value; int is3state = 0; if (!ih->parent) return IUP_ERROR; if (radio) ih->data->radio = 1; 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); iupAttribSetStr(radio, "_IUPGTK_LASTRADIOBUTTON", (char*)ih->handle); } else { if (ih->data->type == IUP_TOGGLE_TEXT) { ih->handle = gtk_check_button_new(); if (iupAttribGetInt(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); } /* add to the parent, all GTK controls must call this. */ iupgtkBaseAddToParent(ih); if (!iupStrBoolean(iupAttribGetStr(ih, "CANFOCUS"))) GTK_WIDGET_FLAGS(ih->handle) &= ~GTK_CAN_FOCUS; 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); return IUP_NOERROR; }
static int gtkMessageDlgPopup(Ihandle* ih, int x, int y) { InativeHandle* parent = iupDialogGetNativeParent(ih); GtkMessageType type = GTK_MESSAGE_INFO; GtkWidget* dialog; char *icon, *buttons, *title; int response, num_but = 2; iupAttribSetInt(ih, "_IUPDLG_X", x); iupAttribSetInt(ih, "_IUPDLG_Y", y); icon = iupAttribGetStr(ih, "DIALOGTYPE"); if (iupStrEqualNoCase(icon, "ERROR")) type = GTK_MESSAGE_ERROR; else if (iupStrEqualNoCase(icon, "WARNING")) type = GTK_MESSAGE_WARNING; else if (iupStrEqualNoCase(icon, "INFORMATION")) type = GTK_MESSAGE_INFO; else if (iupStrEqualNoCase(icon, "QUESTION")) type = GTK_MESSAGE_QUESTION; dialog = gtk_message_dialog_new((GtkWindow*)parent, 0, type, GTK_BUTTONS_NONE, iupgtkStrConvertToUTF8(iupAttribGetStr(ih, "VALUE"))); if (!dialog) return IUP_ERROR; title = iupAttribGetStr(ih, "TITLE"); if (title) gtk_window_set_title(GTK_WINDOW(dialog), iupgtkStrConvertToUTF8(title)); buttons = iupAttribGetStr(ih, "BUTTONS"); if (iupStrEqualNoCase(buttons, "OKCANCEL")) { gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_OK, IUP_RESPONSE_1); gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_CANCEL, IUP_RESPONSE_2); } else if (iupStrEqualNoCase(buttons, "YESNO")) { gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_YES, IUP_RESPONSE_1); gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_NO, IUP_RESPONSE_2); } else /* OK */ { gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_OK, IUP_RESPONSE_1); num_but = 1; } if (IupGetCallback(ih, "HELP_CB")) gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_HELP, IUP_RESPONSE_HELP); if (num_but == 2 && iupAttribGetInt(ih, "BUTTONDEFAULT") == 2) gtk_dialog_set_default_response(GTK_DIALOG(dialog), IUP_RESPONSE_2); else gtk_dialog_set_default_response(GTK_DIALOG(dialog), IUP_RESPONSE_1); /* initialize the widget */ gtk_widget_realize(dialog); ih->handle = dialog; iupDialogUpdatePosition(ih); ih->handle = NULL; do { response = gtk_dialog_run(GTK_DIALOG(dialog)); if (response == IUP_RESPONSE_HELP) { Icallback cb = IupGetCallback(ih, "HELP_CB"); if (cb && cb(ih) == IUP_CLOSE) response = (num_but == 2)? IUP_RESPONSE_2: IUP_RESPONSE_1; } } while (response == IUP_RESPONSE_HELP); if (response == IUP_RESPONSE_1) IupSetAttribute(ih, "BUTTONRESPONSE", "1"); else IupSetAttribute(ih, "BUTTONRESPONSE", "2"); gtk_widget_destroy(dialog); return IUP_NOERROR; }