static int iMatrixDrawGetColAlignment(Ihandle* ih, int col) { char* align; align = iupAttribGetId(ih, "ALIGNMENT", col); if (!align) align = iupAttribGet(ih, "ALIGNMENT"); if (!align) { if (col == 0) return IMAT_ALIGN_LEFT; else return IMAT_ALIGN_CENTER; } else if (iupStrEqualNoCase(align, "ARIGHT")) return IMAT_ALIGN_RIGHT; else if(iupStrEqualNoCase(align, "ACENTER")) return IMAT_ALIGN_CENTER; else return IMAT_ALIGN_LEFT; }
static int motToggleSetAlignmentAttrib(Ihandle* ih, const char* value) { unsigned char align; char value1[30], value2[30]; if (ih->data->type == IUP_TOGGLE_TEXT) return 0; iupStrToStrStr(value, value1, value2, ':'); /* value2 is ignored, NOT supported in Motif */ if (iupStrEqualNoCase(value1, "ARIGHT")) align = XmALIGNMENT_END; else if (iupStrEqualNoCase(value1, "ACENTER")) align = XmALIGNMENT_CENTER; else /* "ALEFT" */ align = XmALIGNMENT_BEGINNING; XtVaSetValues (ih->handle, XmNalignment, align, NULL); return 1; }
static int iMatrixSetMarkModeAttrib(Ihandle* ih, const char* value) { if (iupStrEqualNoCase(value, "CELL")) ih->data->mark_mode = IMAT_MARK_CELL; else if (iupStrEqualNoCase(value, "LIN")) ih->data->mark_mode = IMAT_MARK_LIN; else if (iupStrEqualNoCase(value, "COL")) ih->data->mark_mode = IMAT_MARK_COL; else if(iupStrEqualNoCase(value, "LINCOL")) ih->data->mark_mode = IMAT_MARK_LINCOL; else ih->data->mark_mode = IMAT_MARK_NO; if (ih->handle) { iupMatrixMarkClearAll(ih, 0); iupMatrixDraw(ih, 1); } return 0; }
static ImotFont* motFindFont(const char* foundry, const char *standardfont) { char xlfd[1024]; XFontStruct* fontstruct; int i, count = iupArrayCount(mot_fonts); int is_underline = 0, is_strikeout = 0; ImotFont* fonts = (ImotFont*)iupArrayGetData(mot_fonts); /* Check if the standardfont already exists in cache */ for (i = 0; i < count; i++) { if (iupStrEqualNoCase(standardfont, fonts[i].standardfont)) return &fonts[i]; } /* not found, create a new one */ if (standardfont[0] == '-') { fontstruct = XLoadQueryFont(iupmot_display, standardfont); if (!fontstruct) return NULL; strcpy(xlfd, standardfont); } else { int size, is_bold = 0, is_italic = 0; char typeface[1024]; const char* mapped_name; if (!iupFontParsePango(standardfont, typeface, &size, &is_bold, &is_italic, &is_underline, &is_strikeout)) return NULL; mapped_name = iupFontGetXName(typeface); if (mapped_name) strcpy(typeface, mapped_name); fontstruct = motLoadFont(foundry, typeface, size, is_bold, is_italic, xlfd); if (!fontstruct) return NULL; } /* create room in the array */ fonts = (ImotFont*)iupArrayInc(mot_fonts); strcpy(fonts[i].standardfont, standardfont); strcpy(fonts[i].xlfd, xlfd); fonts[i].fontstruct = fontstruct; fonts[i].fontlist = motFontCreateRenderTable(fontstruct, is_underline, is_strikeout); fonts[i].charwidth = motFontCalcCharWidth(fontstruct); fonts[i].charheight = fontstruct->ascent + fontstruct->descent; return &fonts[i]; }
static int iTextSetScrollbarAttrib(Ihandle* ih, const char* value) { /* valid only before map */ if (ih->handle || !ih->data->is_multiline) return 0; if (!value) value = "YES"; /* default, if multiline, is YES */ if (iupStrEqualNoCase(value, "YES")) ih->data->sb = IUP_SB_HORIZ | IUP_SB_VERT; else if (iupStrEqualNoCase(value, "HORIZONTAL")) ih->data->sb = IUP_SB_HORIZ; else if (iupStrEqualNoCase(value, "VERTICAL")) ih->data->sb = IUP_SB_VERT; else ih->data->sb = IUP_SB_NONE; return 0; }
static void iLabelComputeNaturalSizeMethod(Ihandle* ih, int *w, int *h, int *expand) { int natural_w = 0, natural_h = 0, type = ih->data->type; (void)expand; /* unset if not a container */ if (!ih->handle) { /* if not mapped must initialize the internal values */ char* value = iupAttribGet(ih, "SEPARATOR"); if (value) { if (iupStrEqualNoCase(value, "HORIZONTAL")) type = IUP_LABEL_SEP_HORIZ; else /* "VERTICAL" */ type = IUP_LABEL_SEP_VERT; } else { value = iupAttribGet(ih, "IMAGE"); if (value) type = IUP_LABEL_IMAGE; else type = IUP_LABEL_TEXT; } } if (type == IUP_LABEL_SEP_HORIZ) natural_h = 2; else if (type == IUP_LABEL_SEP_VERT) natural_w = 2; else if (type == IUP_LABEL_IMAGE) { iupImageGetInfo(iupAttribGet(ih, "IMAGE"), &natural_w, &natural_h, NULL); natural_w += 2*ih->data->horiz_padding; natural_h += 2*ih->data->vert_padding; } else /* IUP_LABEL_TEXT */ { /* must use IupGetAttribute to check from the native implementation */ char* title = IupGetAttribute(ih, "TITLE"); char* str = iupStrProcessMnemonic(title, NULL, 0); /* remove & */ iupdrvFontGetMultiLineStringSize(ih, str, &natural_w, &natural_h); if (str && str!=title) free(str); natural_w += 2*ih->data->horiz_padding; natural_h += 2*ih->data->vert_padding; } *w = natural_w; *h = natural_h; }
int iupClassMatch(Iclass* ic, const char* classname) { /* check for all classes in the hierarchy */ while (ic) { if (iupStrEqualNoCase(ic->name, classname)) return 1; ic = ic->parent; } return 0; }
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; }
static void winMessageDlgHelpCallback(HELPINFO* HelpInfo) { Ihandle* ih = (Ihandle*)HelpInfo->dwContextId; Icallback cb = (Icallback)IupGetCallback(ih, "HELP_CB"); if (cb && cb(ih) == IUP_CLOSE) { if (iupStrEqualNoCase(iupAttribGetStr(ih, "BUTTONS"), "OK")) /* only one button */ EndDialog((HWND)HelpInfo->hItemHandle, IDOK); else EndDialog((HWND)HelpInfo->hItemHandle, IDCANCEL); } }
static int winLabelMapMethod(Ihandle* ih) { char* value; DWORD dwStyle = WS_CHILD | WS_CLIPSIBLINGS | SS_NOTIFY; /* SS_NOTIFY is necessary because of the base messages */ if (!ih->parent) return IUP_ERROR; value = iupAttribGet(ih, "SEPARATOR"); if (value) { if (iupStrEqualNoCase(value, "HORIZONTAL")) { ih->data->type = IUP_LABEL_SEP_HORIZ; dwStyle |= SS_ETCHEDHORZ; } else /* "VERTICAL" */ { ih->data->type = IUP_LABEL_SEP_VERT; dwStyle |= SS_ETCHEDVERT; } } else { /* The lack for good alignment support in STATIC control forces IUP to draw its own label, but uses the Windows functions to draw text and images in native format. */ dwStyle |= SS_OWNERDRAW; value = iupAttribGet(ih, "IMAGE"); if (value) ih->data->type = IUP_LABEL_IMAGE; else ih->data->type = IUP_LABEL_TEXT; } if (!iupwinCreateWindowEx(ih, "STATIC", 0, dwStyle)) return IUP_ERROR; if (ih->data->type != IUP_LABEL_SEP_HORIZ && ih->data->type != IUP_LABEL_SEP_VERT) { /* replace the WinProc to handle other messages */ IupSetCallback(ih, "_IUPWIN_CTRLPROC_CB", (Icallback)winLabelProc); IupSetCallback(ih, "_IUPWIN_DRAWITEM_CB", (Icallback)winLabelDrawItem); } /* configure for DRAG&DROP of files */ if (IupGetCallback(ih, "DROPFILES_CB")) iupAttribSetStr(ih, "DRAGDROP", "YES"); return IUP_NOERROR; }
static void motMessageDlgDeleteWindowCallback(Widget w, XtPointer client_data, XtPointer call_data) { Ihandle *ih = (Ihandle*)client_data; if (!ih) return; (void)call_data; (void)w; if (iupStrEqualNoCase(iupAttribGetStr(ih, "BUTTONS"), "OK")) iupAttribSetStr(ih, "BUTTONRESPONSE", "1"); else iupAttribSetStr(ih, "BUTTONRESPONSE", "2"); iupAttribSetStr(ih, "_IUP_WM_DELETE", "1"); }
static int iGridBoxSetNumDivAttrib(Ihandle* ih, const char* value) { if (iupStrEqualNoCase(value, "AUTO")) ih->data->num_div = -1; else { iupStrToInt(value, &ih->data->num_div); if (ih->data->num_div <= 0) ih->data->num_div = 1; } return 0; }
static int iScintillaSetCharSetStyleAttrib(Ihandle* ih, int style, const char* value) { if(style == IUP_INVALID_ID) style = 0; /* Lexer style default */ /* These character sets are supported both on Windows as on GTK */ if (iupStrEqualNoCase(value, "EASTEUROPE")) IupScintillaSendMessage(ih, SCI_STYLESETCHARACTERSET, style, SC_CHARSET_EASTEUROPE); else if (iupStrEqualNoCase(value, "RUSSIAN")) IupScintillaSendMessage(ih, SCI_STYLESETCHARACTERSET, style, SC_CHARSET_RUSSIAN); else if (iupStrEqualNoCase(value, "GB2312")) /* Chinese charset */ IupScintillaSendMessage(ih, SCI_STYLESETCHARACTERSET, style, SC_CHARSET_GB2312); else if (iupStrEqualNoCase(value, "HANGUL")) /* Korean charset */ IupScintillaSendMessage(ih, SCI_STYLESETCHARACTERSET, style, SC_CHARSET_HANGUL); else if (iupStrEqualNoCase(value, "SHIFTJIS")) /* Japanese charset */ IupScintillaSendMessage(ih, SCI_STYLESETCHARACTERSET, style, SC_CHARSET_SHIFTJIS); else IupScintillaSendMessage(ih, SCI_STYLESETCHARACTERSET, style, SC_CHARSET_ANSI); /* default */ return 0; }
int iupdrvBaseSetZorderAttrib(Ihandle* ih, const char* value) { if (iupdrvIsVisible(ih)) { if (iupStrEqualNoCase(value, "TOP")) XRaiseWindow(iupmot_display, XtWindow(ih->handle)); else XLowerWindow(iupmot_display, XtWindow(ih->handle)); } return 0; }
static int iColorbarSetBufferizeAttrib(Ihandle* ih, const char* value) { if (iupStrEqualNoCase(value, "NO")) { ih->data->bufferize = 0; iColorbarRepaint(ih); } else ih->data->bufferize = 1; return 0; }
static int iMatrixDrawGetColAlignment(Ihandle* ih, int col, char* str) { char* align; sprintf(str, "ALIGNMENT%d", col); align = iupAttribGet(ih, str); if (!align) align = iupAttribGet(ih, "ALIGNMENT"); if (!align) { if (col == 0) return IMAT_T_LEFT; else return IMAT_T_CENTER; } else if (iupStrEqualNoCase(align, "ARIGHT")) return IMAT_T_RIGHT; else if(iupStrEqualNoCase(align, "ACENTER")) return IMAT_T_CENTER; else return IMAT_T_LEFT; }
static int iSboxSetDirectionAttrib(Ihandle* ih, const char* value) { if (ih->handle) /* only before map */ return 0; if (iupStrEqualNoCase(value, "NORTH")) ih->data->direction = ISBOX_NORTH; else if(iupStrEqualNoCase(value, "SOUTH")) ih->data->direction = ISBOX_SOUTH; else if(iupStrEqualNoCase(value, "WEST")) ih->data->direction = ISBOX_WEST; else /* Default = EAST */ ih->data->direction = ISBOX_EAST; if (ih->data->direction == ISBOX_EAST || ih->data->direction == ISBOX_WEST) IupSetAttribute(ih->firstchild, "CURSOR", "RESIZE_WE"); else IupSetAttribute(ih->firstchild, "CURSOR", "RESIZE_NS"); return 0; /* do not store value in hash table */ }
static int gtkTabsSetTabOrientationAttrib(Ihandle* ih, const char* value) { if (ih->handle) /* allow to set only before mapping */ return 0; if(iupStrEqualNoCase(value, "VERTICAL")) ih->data->orientation = ITABS_VERTICAL; else /* HORIZONTAL */ ih->data->orientation = ITABS_HORIZONTAL; return 0; }
static int iDetachBoxSetOrientationAttrib(Ihandle* ih, const char* value) { if (ih->handle) /* only before map */ return 0; if (iupStrEqualNoCase(value, "HORIZONTAL")) ih->data->orientation = IDBOX_HORIZ; else /* Default = VERTICAL */ ih->data->orientation = IDBOX_VERT; return 0; /* do not store value in hash table */ }
static int iTreeSetMarkModeAttrib(Ihandle* ih, const char* value) { if (iupStrEqualNoCase(value, "MULTIPLE")) ih->data->mark_mode = ITREE_MARK_MULTIPLE; else ih->data->mark_mode = ITREE_MARK_SINGLE; if (ih->handle) iupdrvTreeUpdateMarkMode(ih); /* for this to work, must update during map */ return 0; }
static int iGLExpanderSetStateAttrib(Ihandle* ih, const char* value) { int state; if (iupStrEqualNoCase(value, "OPEN")) state = IEXPANDER_OPEN; else state = IEXPANDER_CLOSE; iGLExpanderOpenCloseChild(ih, 1, 0, state); return 0; /* do not store value in hash table */ }
static int motProgressBarMapMethod(Ihandle* ih) { int num_args = 0; Arg args[30]; /* Core */ 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 */ /* Primitive */ iupmotSetArg(args, num_args, XmNtraversalOn, False); iupmotSetArg(args, num_args, XmNhighlightThickness, 0); /* Scale */ iupmotSetArg(args, num_args, XmNminimum, 0); iupmotSetArg(args, num_args, XmNmaximum, SHRT_MAX); iupmotSetArg(args, num_args, XmNslidingMode, XmTHERMOMETER); /* thermometer effect */ iupmotSetArg(args, num_args, XmNsliderMark, XmNONE); iupmotSetArg(args, num_args, XmNeditable, False); iupmotSetArg(args, num_args, XmNshowValue, XmNONE); if (iupStrEqualNoCase(iupAttribGetStr(ih, "ORIENTATION"), "VERTICAL")) { iupmotSetArg(args, num_args, XmNorientation, XmVERTICAL); if (ih->currentheight < ih->currentwidth) { int tmp = ih->currentheight; ih->currentheight = ih->currentwidth; ih->currentwidth = tmp; } } else iupmotSetArg(args, num_args, XmNorientation, XmHORIZONTAL); ih->handle = XtCreateManagedWidget( iupDialogGetChildIdStr(ih), /* child identifier */ xmScaleWidgetClass, /* 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 */ /* initialize the widget */ XtRealizeWidget(ih->handle); return IUP_NOERROR; }
int iupdrvBaseSetZorderAttrib(Ihandle* ih, const char* value) { if (iupdrvIsVisible(ih)) { GdkWindow* window = ih->handle->window; if (iupStrEqualNoCase(value, "TOP")) gdk_window_raise(window); else gdk_window_lower(window); } return 0; }
static int iValSetTypeAttrib(Ihandle* ih, const char *value) { /* valid only before map */ if (ih->handle) return 0; if (iupStrEqualNoCase(value, "VERTICAL")) ih->data->type = IVAL_VERTICAL; else /* "HORIZONTAL" */ ih->data->type = IVAL_HORIZONTAL; return 0; /* do not store value in hash table */ }
static int iMatrixDrawSortSign(Ihandle* ih, int x2, int y1, int y2, int col, int active, char* str) { int yc; char* sort; sprintf(str, "SORTSIGN%d", col); sort = iupAttribGet(ih, str); if (!sort || iupStrEqualNoCase(sort, "NO")) return 0; /* Remove the space between text and cell frame */ x2 -= IMAT_PADDING_W/2 + IMAT_FRAME_W/2; /* Set the color used to draw the text */ if (active) cdCanvasForeground(ih->data->cddbuffer, IMAT_CD_INACTIVE_FGCOLOR); else iMatrixDrawSetFgColor(ih, 0, col, 0); yc = (int)( (y1 + y2 ) / 2.0 - .5); cdCanvasBegin(ih->data->cddbuffer, CD_FILL); if (iupStrEqualNoCase(sort, "DOWN")) { iupMATRIX_VERTEX(ih, x2 - 5, yc + 2); iupMATRIX_VERTEX(ih, x2 - 1, yc - 2); iupMATRIX_VERTEX(ih, x2 - 9, yc - 2); } else { iupMATRIX_VERTEX(ih, x2 - 1, yc + 2); iupMATRIX_VERTEX(ih, x2 - 9, yc + 2); iupMATRIX_VERTEX(ih, x2 - 5, yc - 2); } cdCanvasEnd(ih->data->cddbuffer); return 1; }
static int iScintillaSetRedoAttrib(Ihandle *ih, const char *value) { if (iupStrBoolean(value)) IupScintillaSendMessage(ih, SCI_REDO, 0, 0); else if (iupStrEqualNoCase(value, "ALL")) { while ((int)IupScintillaSendMessage(ih, SCI_CANREDO, 0, 0)) IupScintillaSendMessage(ih, SCI_REDO, 0, 0); } else IupScintillaSendMessage(ih, SCI_EMPTYUNDOBUFFER, 0, 0); return 0; }
char *iupdrvGetSystemName(void) { struct utsname un; char *str = iupStrGetMemory(50); uname(&un); if (iupStrEqualNoCase(un.sysname, "Darwin")) strcpy(str, "MacOS"); else strcpy(str, un.sysname); return str; }
int iupdrvBaseSetZorderAttrib(Ihandle* ih, const char* value) { if (iupdrvIsVisible(ih)) { Widget widget = (Widget)iupAttribGet(ih, "_IUP_EXTRAPARENT"); if (iupStrEqualNoCase(value, "TOP")) XRaiseWindow(iupmot_display, XtWindow(widget)); else XLowerWindow(iupmot_display, XtWindow(widget)); } return 0; }
static int motLabelSetAlignmentAttrib(Ihandle* ih, const char* value) { if (ih->data->type != IUP_LABEL_SEP_HORIZ && ih->data->type != IUP_LABEL_SEP_VERT) { unsigned char align; char value1[30]="", value2[30]=""; iupStrToStrStr(value, value1, value2, ':'); /* value2 is ignored, NOT supported in Motif */ if (iupStrEqualNoCase(value1, "ARIGHT")) align = XmALIGNMENT_END; else if (iupStrEqualNoCase(value1, "ACENTER")) align = XmALIGNMENT_CENTER; else /* "ALEFT" */ align = XmALIGNMENT_BEGINNING; XtVaSetValues(ih->handle, XmNalignment, align, NULL); return 1; } else return 0; }
static int motListSetSelectionAttrib(Ihandle* ih, const char* value) { int start=1, end=1; Widget cbedit; if (!ih->data->has_editbox) return 0; if (!value || iupStrEqualNoCase(value, "NONE")) { XtVaGetValues(ih->handle, XmNtextField, &cbedit, NULL); XmTextFieldClearSelection(cbedit, CurrentTime); return 0; } if (iupStrEqualNoCase(value, "ALL")) { XtVaGetValues(ih->handle, XmNtextField, &cbedit, NULL); XmTextFieldSetSelection(cbedit, (XmTextPosition)0, (XmTextPosition)XmTextFieldGetLastPosition(cbedit), CurrentTime); return 0; } if (iupStrToIntInt(value, &start, &end, ':')!=2) return 0; if(start<1 || end<1) return 0; start--; /* IUP starts at 1 */ end--; /* end is inside the selection, in IUP is outside */ end--; XtVaGetValues(ih->handle, XmNtextField, &cbedit, NULL); XmTextFieldSetSelection(cbedit, (XmTextPosition)start, (XmTextPosition)end, CurrentTime); return 0; }