static int iMatrixSetVisibleColAttribId(Ihandle *ih, int col, const char* value) { char* old_width; if (!iupStrBoolean(value)) { old_width = iupAttribGetId(ih, "WIDTH", col); if (old_width) iupAttribSetStrId(ih, "_IUP_SHOWCOL_WIDTH", col, old_width); else { old_width = iupAttribGetId(ih, "RASTERWIDTH", col); if (old_width) iupAttribSetStrId(ih, "_IUP_SHOWCOL_RASTERWIDTH", col, old_width); } IupSetAttributeId(ih, "WIDTH", col, "0"); /* this is enough */ } else { iupAttribSetId(ih, "WIDTH", col, NULL); /* this may be insufficient */ iupAttribSetId(ih, "RASTERWIDTH", col, NULL); old_width = iupAttribGetId(ih, "_IUP_SHOWCOL_WIDTH", col); if (old_width) IupSetStrAttributeId(ih, "WIDTH", col, old_width); else { old_width = iupAttribGetId(ih, "_IUP_SHOWCOL_RASTERWIDTH", col); if (old_width) IupSetStrAttributeId(ih, "RASTERWIDTH", col, old_width); else IupSetAttributeId(ih, "RASTERWIDTH", col, NULL); } } return 0; }
static int iTabsGetMaxWidth(Ihandle* ih) { int max_width = 0, width, pos; char *tabtitle, *tabimage; Ihandle* child; for (pos = 0, child = ih->firstchild; child; child = child->brother, pos++) { tabtitle = iupAttribGetId(ih, "TABTITLE", pos); if (!tabtitle) tabtitle = iupAttribGet(child, "TABTITLE"); tabimage = iupAttribGetId(ih, "TABIMAGE", pos); if (!tabimage) tabimage = iupAttribGet(child, "TABIMAGE"); if (!tabtitle && !tabimage) tabtitle = " "; width = 0; if (tabtitle) width += iupdrvFontGetStringWidth(ih, tabtitle); if (tabimage) { void* img = iupImageGetImage(tabimage, ih, 0); if (img) { int w; iupdrvImageGetInfo(img, &w, NULL, NULL); width += w; } } if (width > max_width) max_width = width; } return max_width; }
static int iMatrixListSetItemActiveAttrib(Ihandle* ih, int lin, const char* value) { int itemactive = iupStrBoolean(value); iMatrixListUpdateItemBgColor(ih, lin, iupAttribGetId(ih, "ITEMBGCOLOR", lin), itemactive); iMatrixListUpdateItemFgColor(ih, lin, iupAttribGetId(ih, "ITEMFGCOLOR", lin), itemactive); return 1; }
int iupMatrixExIsColumnVisible(Ihandle* ih, int col) { int width = 0; char* value; if (col==0) return (IupGetIntId(ih, "RASTERWIDTH", 0) != 0); /* to be invisible must exist the attribute and must be set to 0 (zero), or else is visible */ value = iupAttribGetId(ih, "WIDTH", col); if (!value) { value = iupAttribGetId(ih, "RASTERWIDTH", col); if (!value) return 1; } if (iupStrToInt(value, &width)==1) { if (width==0) return 0; } return 1; }
static int iMatrixSetVisibleLinAttribId(Ihandle *ih, int lin, const char* value) { char* old_height; if (!iupStrBoolean(value)) { old_height = iupAttribGetId(ih, "HEIGHT", lin); if (old_height) iupAttribSetStrId(ih, "_IUP_SHOWCOL_HEIGHT", lin, old_height); else { old_height = iupAttribGetId(ih, "RASTERHEIGHT", lin); if (old_height) iupAttribSetStrId(ih, "_IUP_SHOWCOL_RASTERHEIGHT", lin, old_height); } IupSetAttributeId(ih, "HEIGHT", lin, "0"); /* this is enough */ } else { iupAttribSetId(ih, "HEIGHT", lin, NULL); /* this may be insufficient */ iupAttribSetId(ih, "RASTERHEIGHT", lin, NULL); old_height = iupAttribGetId(ih, "_IUP_SHOWCOL_HEIGHT", lin); if (old_height) IupSetStrAttributeId(ih, "HEIGHT", lin, old_height); else { old_height = iupAttribGetId(ih, "_IUP_SHOWCOL_RASTERHEIGHT", lin); if (old_height) IupSetStrAttributeId(ih, "RASTERHEIGHT", lin, old_height); else IupSetAttributeId(ih, "RASTERHEIGHT", lin, NULL); } } return 0; }
static void iGLExpanderDrawExtraButton(Ihandle* ih, int button, int x, int y, int height) { char* image = iupAttribGetId(ih, "IMAGEEXTRA", button); int active = IupGetInt(ih, "ACTIVE"); int img_height; if (!image) return; if (ih->data->extra_buttons_state[button] == 1) { char* impress = iupAttribGetId(ih, "IMAGEEXTRAPRESS", button); if (impress) image = impress; } else if (ih->data->extra_buttons_state[button] == -1) { char* imhighlight = iupAttribGetId(ih, "IMAGEEXTRAHIGHLIGHT", button); if (imhighlight) image = imhighlight; } iupGLImageGetInfo(image, NULL, &img_height, NULL); if (height > img_height) y += (height - img_height) / 2; iupGLDrawImage(ih, x, y, image, !active); }
static void iMatrixListInitSize(Ihandle* ih, ImatrixListData* mtxList) { char str[30]; int num_col = 0; if (mtxList->label_col != 0) num_col++; if (mtxList->color_col != 0) num_col++; if (mtxList->image_col != 0) num_col++; sprintf(str, "%d", num_col); iupMatrixSetNumColAttrib(ih, str); /* "NUMCOL" */ IupSetStrAttribute(ih, "NUMCOL_VISIBLE", str); if (mtxList->color_col != 0) { if (!iupAttribGetId(ih, "WIDTH", mtxList->color_col)) IupSetIntId(ih, "WIDTH", mtxList->color_col, IMTXL_COLOR_WIDTH); } if (mtxList->image_col != 0) { if (!iupAttribGetId(ih, "WIDTH", mtxList->image_col)) IupSetIntId(ih, "WIDTH", mtxList->image_col, IMTXL_IMAGE_WIDTH); } }
static int iTabsGetMaxHeight(Ihandle* ih) { int max_height = 0, h, pos; char *tabimage; Ihandle* child; for (pos = 0, child = ih->firstchild; child; child = child->brother, pos++) { tabimage = iupAttribGetId(ih, "TABIMAGE", pos); if (!tabimage) tabimage = iupAttribGet(child, "TABIMAGE"); if (tabimage) { void* img = iupImageGetImage(tabimage, ih, 0); if (img) { iupdrvImageGetInfo(img, NULL, &h, NULL); if (h > max_height) max_height = h; } } } iupdrvFontGetCharSize(ih, NULL, &h); if (h > max_height) max_height = h; return max_height; }
static int iMatrixDrawSortSign(Ihandle* ih, int x2, int y1, int y2, int col, int active) { int yc; char* sort = iupAttribGetId(ih, "SORTSIGN", col); 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 */ iMatrixDrawSetFgColor(ih, 0, col, 0, active); yc = (int)( (y1 + y2 ) / 2.0 - .5); cdCanvasBegin(ih->data->cd_canvas, 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 /* UP */ { iupMATRIX_VERTEX(ih, x2 - 1, yc + 2); iupMATRIX_VERTEX(ih, x2 - 9, yc + 2); iupMATRIX_VERTEX(ih, x2 - 5, yc - 2); } cdCanvasEnd(ih->data->cd_canvas); return 1; }
static int iMatrixListSetFocusColorAttrib(Ihandle* ih, const char* value) { int lin = ih->data->lines.focus_cell; int itemactive = IupGetIntId(ih, "ITEMACTIVE", lin); iupAttribSetStr(ih, "FOCUSCOLOR", value); iMatrixListUpdateItemBgColor(ih, lin, iupAttribGetId(ih, "ITEMBGCOLOR", lin), itemactive); return 1; }
static char* iMatrixListGetItemActiveAttrib(Ihandle* ih, int lin) { char* value = iupAttribGetId(ih, "ITEMACTIVE", lin); if (!value) return "Yes"; /* default is Yes for all lines */ else return value; }
static int iMatrixListEnterItem_CB(Ihandle *ih, int lin, int col) { IFnii cb = (IFnii)IupGetCallback(ih, "LISTACTION_CB"); int itemactive = IupGetIntId(ih, "ITEMACTIVE", lin); iMatrixListUpdateItemBgColor(ih, lin, iupAttribGetId(ih, "ITEMBGCOLOR", lin), itemactive); IupSetfAttribute(ih, "REDRAW", "L%d", lin); if (cb) cb(ih, lin, 1); (void)col; return IUP_DEFAULT; }
void iupListSetInitialItems(Ihandle* ih) { char *value; int i = 1; while ((value = iupAttribGetId(ih, "", i))!=NULL) { iupdrvListAppendItem(ih, value); iupAttribSetId(ih, "", i, NULL); i++; } }
static void iMatrixListSetFocusItem(Ihandle* ih, ImatrixListData* mtxList, int lin) { if (lin != ih->data->lines.focus_cell) { int old_lin = ih->data->lines.focus_cell; int itemactive = IupGetIntId(ih, "ITEMACTIVE", old_lin); ih->data->lines.focus_cell = -1; iMatrixListUpdateItemBgColor(ih, old_lin, iupAttribGetId(ih, "ITEMBGCOLOR", old_lin), itemactive); IupSetfAttribute(ih, "REDRAW", "L%d", old_lin); itemactive = IupGetIntId(ih, "ITEMACTIVE", lin); ih->data->lines.focus_cell = lin; iMatrixListUpdateItemBgColor(ih, lin, iupAttribGetId(ih, "ITEMBGCOLOR", lin), itemactive); IupSetfAttribute(ih, "REDRAW", "L%d", lin); } if (mtxList->label_col) IupSetfAttribute(ih, "FOCUSCELL", "%d:%d", lin, mtxList->label_col); else IupSetfAttribute(ih, "FOCUSCELL", "%d:1", lin); }
static int iListGetCount(Ihandle* ih) { int count; if (ih->handle) count = iupdrvListGetCount(ih); else { count = 0; while (iupAttribGetId(ih, "", count+1)) count++; } return count; }
static int iMatrixDrawGetLinAlignment(Ihandle* ih, int lin) { char* align = iupAttribGetId(ih, "LINEALIGNMENT", lin); if (!align) align = iupAttribGet(ih, "LINEALIGNMENT"); if (!align) return IMAT_ALIGN_CENTER; else if (iupStrEqualNoCase(align, "ABOTTOM")) return IMAT_ALIGN_END; else if (iupStrEqualNoCase(align, "ATOP")) return IMAT_ALIGN_START; else return IMAT_ALIGN_CENTER; }
int iupMatrixExIsLineVisible(Ihandle* ih, int lin) { int height = 0; char* value; if (lin==0) return (IupGetIntId(ih, "RASTERHEIGHT", 0) != 0); value = iupAttribGetId(ih, "HEIGHT", lin); if(!value) { value = iupAttribGetId(ih, "RASTERHEIGHT", lin); if(!value) return 1; } if (iupStrToInt(value, &height)==1) { if (height==0) return 0; } return 1; }
static int iGridBoxGetAlignmentCol(Ihandle* ih, int col) { int alignment_col = ih->data->alignment_col; char *value; value = iupAttribGetId(ih, "ALIGNMENTCOL", col); if (value) { if (iupStrEqualNoCase(value, "ARIGHT")) alignment_col = IUP_ALIGN_ARIGHT; else if (iupStrEqualNoCase(value, "ACENTER")) alignment_col = IUP_ALIGN_ACENTER; else if (iupStrEqualNoCase(value, "ALEFT")) alignment_col = IUP_ALIGN_ALEFT; } return alignment_col; }
static int iGridBoxGetAlignmentLin(Ihandle* ih, int lin) { int alignment_lin = ih->data->alignment_lin; char *value; value = iupAttribGetId(ih, "ALIGNMENTLIN", lin); if (value) { if (iupStrEqualNoCase(value, "ABOTTOM")) alignment_lin = IUP_ALIGN_ABOTTOM; else if (iupStrEqualNoCase(value, "ACENTER")) alignment_lin = IUP_ALIGN_ACENTER; else alignment_lin = IUP_ALIGN_ATOP; } return alignment_lin; }
static char* iMatrixGetNumericFormatPrecisionAttrib(Ihandle* ih, int col) { int precision; char* value = iupAttribGetId(ih, "NUMERICFORMAT", col); if (!value) value = iupMatrixGetNumericFormatDef(ih); if (!value) return NULL; precision = iupStrGetFormatPrecision(value); if (precision == -1) return NULL; return iupStrReturnInt(precision); }
static int iMatrixDrawSortSign(Ihandle* ih, int x2, int y1, int y2, int col, int active) { int x1; char* sort = iupAttribGetId(ih, "SORTSIGN", col); if (!sort || iupStrEqualNoCase(sort, "NO")) return 0; /* feedback area */ iupMatrixDrawSetDropFeedbackArea(&x1, &y1, &x2, &y2); if (iupStrEqualNoCase(sort, "DOWN")) iMatrixDrawFeedbackImage(ih, x1, x2, y1, y2, 0, col, active, 0, iupAttribGet(ih, "SORTIMAGEDOWN"), imatrix_sortdown_alpha); else iMatrixDrawFeedbackImage(ih, x1, x2, y1, y2, 0, col, active, 0, iupAttribGet(ih, "SORTIMAGEUP"), imatrix_sortup_alpha); return 1; }
static int iMatrixDrawGetColAlignment(Ihandle* ih, int col) { char* align = iupAttribGetId(ih, "ALIGNMENT", col); if (!align) align = iupAttribGet(ih, "ALIGNMENT"); if (!align) { if (col == 0) return IMAT_ALIGN_START; else return IMAT_ALIGN_CENTER; } else if (iupStrEqualNoCase(align, "ARIGHT")) return IMAT_ALIGN_END; else if(iupStrEqualNoCase(align, "ACENTER")) return IMAT_ALIGN_CENTER; else return IMAT_ALIGN_START; }
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 iListGetItemImageInfo(Ihandle *ih, int id, int *img_w, int *img_h) { *img_w = 0; *img_h = 0; if (!ih->handle) { char *value = iupAttribGetId(ih, "IMAGE", id); if (value) iupImageGetInfo(value, img_w, img_h, NULL); } else { void* handle = iupdrvListGetImageHandle(ih, id); if (handle) { int bpp; iupdrvImageGetInfo(handle, img_w, img_h, &bpp); } } }
/* ------------------------------------------------------------------------- */ 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 char* iMatrixExGetCellFormat(Ihandle *ih, int lin, int col, char* format) { char* value, *init = "style=\""; #define _STRCATFORMAT {if (value) { if (init) {strcpy(format, init); init=NULL;} strcat(format, value); }} *format = 0; value = iupAttribGetId(ih, "ALIGNMENT", col); if (value) { if (iupStrEqualNoCase(value, "ARIGHT")) value = "text-align: right; "; else if(iupStrEqualNoCase(value, "ACENTER")) value = "text-align: center; "; else if(iupStrEqualNoCase(value, "ALEFT")) value = "text-align: left; "; else value = NULL; _STRCATFORMAT; } value = iMatrixExGetCellAttrib(ih, "BGCOLOR", lin, col); if (value) { char rgb[50]; unsigned char r, g, b; iupStrToRGB(value, &r, &g, &b); sprintf(rgb, "background-color: #%02X%02X%02X; ", (int)r, (int)g, (int)b); value = rgb; _STRCATFORMAT; } value = iMatrixExGetCellAttrib(ih, "FGCOLOR", lin, col); if (value) { char rgb[50]; unsigned char r, g, b; iupStrToRGB(value, &r, &g, &b); sprintf(rgb, "color: #%02X%02X%02X; ", (int)r, (int)g, (int)b); value = rgb; _STRCATFORMAT; } value = iMatrixExGetCellAttrib(ih, "FONT", lin, col); if (value) { if (strstr(value, "Bold")||strstr(value, "BOLD")) { value = "font-weight: bold; "; _STRCATFORMAT; } if (strstr(value, "Italic")||strstr(value, "ITALIC")) { value = "font-weight: bold; "; _STRCATFORMAT; } /* Leave this out for now: font-size: %dpt; font-family: %s; */ } if (format[0]!=0) strcat(format, "\""); return format; }
static int iMatrixListDrawImageCol(Ihandle *ih, ImatrixListData* mtxList, int lin, int col, int x1, int x2, int y1, int y2, cdCanvas *cnv) { char* image_name; int make_inactive = 0, itemactive, imageactive, imagevalue, showdelete, active = iupdrvIsActive(ih), linedelete; int lines_num = ih->data->lines.num; Ihandle* image; itemactive = IupGetIntId(ih, "ITEMACTIVE", lin); imageactive = IupGetIntId(ih, "IMAGEACTIVE", lin); imagevalue = IupGetIntId(ih, "IMAGEVALUE", lin); showdelete = IupGetInt(ih, "SHOWDELETE"); linedelete = IupGetIntId(ih, "LINEDELETE", lin); if (!active || !itemactive || !imageactive) make_inactive = 1; image_name = iupAttribGetId(ih, "IMAGE", lin); if (!image_name) { char* attrib_name; if (mtxList->editable) { if (lin == lines_num-1) attrib_name = "IMAGEADD"; else { if (showdelete || linedelete) attrib_name = "IMAGEDEL"; else { if (imagevalue) attrib_name = "IMAGECHECK"; else attrib_name = "IMAGEUNCHECK"; } } } else { if (imagevalue) attrib_name = "IMAGECHECK"; else attrib_name = "IMAGEUNCHECK"; } image_name = iupAttribGetStr(ih, attrib_name); /* this will check for the default values also */ } image = iupImageGetHandle(image_name); if (image) { int width = IupGetInt(image, "WIDTH"); int height = IupGetInt(image, "HEIGHT"); long bgcolor = cdIupConvertColor(IupGetAttributeId2(ih, "CELLBGCOLOR", lin, col)); /* Calc the image_name position */ int x = x2 - x1 - width; int y = y1 - y2 - 1 - height; x /= 2; x += x1; y /= 2; y += y2; cdIupDrawImage(cnv, image, x, y, 0, 0, make_inactive, bgcolor); } return IUP_DEFAULT; /* draw nothing more */ }
void IupSaveClassAttributes(Ihandle* ih) { int has_attrib_id, start_id = 0; Iclass* ic; char *name; iupASSERT(iupObjectCheck(ih)); if (!iupObjectCheck(ih)) return; ic = ih->iclass; has_attrib_id = ic->has_attrib_id; if (iupClassMatch(ic, "tree") || /* tree can only set id attributes after map, so they can not be saved */ iupClassMatch(ic, "cells")) /* cells does not have any saveable id attributes */ has_attrib_id = 0; if (iupClassMatch(ic, "list")) start_id = 1; name = iupTableFirst(ic->attrib_func); while (name) { IattribFunc* afunc = (IattribFunc*)iupTableGet(ic->attrib_func, name); if (afunc && !(afunc->flags & IUPAF_NO_STRING) && /* is a string */ !(afunc->flags & IUPAF_READONLY) && /* not read-only */ !(afunc->flags & IUPAF_WRITEONLY) && /* not write-only */ !(afunc->flags & IUPAF_CALLBACK)) /* not a callback */ { if ((afunc->flags&IUPAF_NO_SAVE) && iupBaseNoSaveCheck(ih, name)) /* can not be saved */ { name = iupTableNext(ic->attrib_func); continue; } if (!(afunc->flags & IUPAF_HAS_ID)) /* no ID */ { int inherit; char *def_value; char *value = iupClassObjectGetAttribute(ih, name, &def_value, &inherit); if (value && value[0]) /* NOT NULL and not empty */ { if ((def_value && iupStrEqualNoCase(def_value, value)) || /* equal to the default value */ (!def_value && iupStrFalse(value))) /* default=NULL and value=NO */ { name = iupTableNext(ic->attrib_func); continue; } if (!iupStrEqualNoCase(value, iupAttribGet(ih, name))) /* NOT already stored */ iupAttribSetStr(ih, name, value); } } else if (has_attrib_id) { char *value; if (iupStrEqual(name, "IDVALUE")) name = ""; if (afunc->flags&IUPAF_HAS_ID2) { int lin, col, numcol = IupGetInt(ih, "NUMCOL")+1, numlin = IupGetInt(ih, "NUMLIN")+1; for (lin=0; lin<numlin; lin++) { for (col=0; col<numcol; col++) { value = iupClassObjectGetAttributeId2(ih, name, lin, col); if (value && value[0]) /* NOT NULL and not empty */ { if (!iupStrEqualNoCase(value, iupAttribGetId2(ih, name, lin, col))) /* NOT already stored */ iupAttribSetStrId2(ih, name, lin, col, value); } } } } else { int id, count = IupGetInt(ih, "COUNT"); for (id=start_id; id<count+start_id; id++) { value = iupClassObjectGetAttributeId(ih, name, id); if (value && value[0]) /* NOT NULL and not empty */ { if (!iupStrEqualNoCase(value, iupAttribGetId(ih, name, id))) /* NOT already stored */ iupAttribSetStrId(ih, name, id, value); } } } } } name = iupTableNext(ic->attrib_func); } }
static int iMatrixSetSortColumnAttrib(Ihandle* ih, int col, const char* value) { int lines_num = ih->data->lines.num; int lin, lin1=1, lin2=lines_num-1; /* ALL */ int ascending; int* sort_line_index; IFniii sort_cb; /* Notice that sort_line_index[0] is always 0 */ if (!ih->data->sort_line_index) ih->data->sort_line_index = (int*)calloc(ih->data->lines.num_alloc, sizeof(int)); sort_line_index = ih->data->sort_line_index; if (!ih->data->sort_has_index) { for (lin = 0; lin < lines_num; lin++) sort_line_index[lin] = lin; } if (iupStrEqualNoCase(value, "RESET")) { ih->data->sort_has_index = 0; iupAttribSetId(ih, "SORTSIGN", ih->data->last_sort_col, NULL); ih->data->last_sort_col = 0; iupMatrixDraw(ih, 1); iupAttribSet(ih, "SORTCOLUMNINTERVAL", NULL); return 0; } if (iupStrEqualNoCase(value, "INVERT")) { int l1, l2; if (!ih->data->sort_has_index) return 0; IupGetIntInt(ih, "SORTCOLUMNINTERVAL", &lin1, &lin2); for (l1=lin1,l2=lin2; l1<l2; ++l1,--l2) { int tmp = sort_line_index[l1]; sort_line_index[l1] = sort_line_index[l2]; sort_line_index[l2] = tmp; } if (iupStrEqualNoCase(iupAttribGetId(ih, "SORTSIGN", ih->data->last_sort_col), "UP")) iupAttribSetId(ih, "SORTSIGN", ih->data->last_sort_col, "DOWN"); else iupAttribSetId(ih, "SORTSIGN", ih->data->last_sort_col, "UP"); iupMatrixDraw(ih, 1); return 0; } if (!iupMATRIX_CHECK_COL(ih, col)) return 0; if (!iupStrEqualNoCase(value, "ALL")) iupStrToIntInt(value, &lin1, &lin2, '-'); iupAttribSetStrf(ih, "SORTCOLUMNINTERVAL", "%d,%d", lin1, lin2); if (lin1 < 1) lin1 = 1; if (lin2 < lin1) lin2 = lin1; ascending = iupStrEqualNoCase(iupAttribGetStr(ih, "SORTCOLUMNORDER"), "ASCENDING"); sort_cb = (IFniii)IupGetCallback(ih, "SORTCOLUMNCOMPARE_CB"); if (sort_cb) { iMatrixQSort_sort_cb = sort_cb; iMatrixQSort_ih = ih; iMatrixQSort_col = col; qsort(sort_line_index+lin1,lin2-lin1+1,sizeof(int),iMatrixCompareCallbackFunc); } else { if (ih->data->numeric_columns && ih->data->numeric_columns[col].flags & IMAT_IS_NUMERIC) { ImatSortNumber* sort_line_number = (ImatSortNumber*)malloc((lin2-lin1+1)*sizeof(ImatSortNumber)); for (lin=lin1; lin<=lin2; lin++) { sort_line_number[lin-lin1].lin = sort_line_index[lin]; sort_line_number[lin-lin1].number = iupMatrixGetValueNumeric(ih, lin, col); } qsort(sort_line_number,lin2-lin1+1,sizeof(ImatSortNumber), iMatrixCompareNumberFunc); for (lin=lin1; lin<=lin2; lin++) { if (ascending) sort_line_index[lin] = sort_line_number[lin-lin1].lin; else sort_line_index[lin2 - (lin-lin1)] = sort_line_number[lin-lin1].lin; } free(sort_line_number); } else { ImatSortText* sort_line_text = (ImatSortText*)malloc((lin2-lin1+1)*sizeof(ImatSortText)); for (lin=lin1; lin<=lin2; lin++) { sort_line_text[lin-lin1].lin = sort_line_index[lin]; sort_line_text[lin-lin1].text = iupMatrixGetValueDisplay(ih, lin, col); if (ih->data->callback_mode) sort_line_text[lin-lin1].text = iupStrDup(sort_line_text[lin-lin1].text); } iMatrixQSort_utf8 = IupGetInt(NULL, "UTF8MODE"); iMatrixQSort_casesensitive = iupAttribGetInt(ih, "SORTCOLUMNCASESENSITIVE"); qsort(sort_line_text,lin2-lin1+1,sizeof(ImatSortText), iMatrixCompareTextFunc); for (lin=lin1; lin<=lin2; lin++) { if (ascending) sort_line_index[lin] = sort_line_text[lin-lin1].lin; else sort_line_index[lin2 - (lin-lin1)] = sort_line_text[lin-lin1].lin; if (ih->data->callback_mode && sort_line_text[lin-lin1].text) free(sort_line_text[lin-lin1].text); } free(sort_line_text); } } iupAttribSetId(ih, "SORTSIGN", ih->data->last_sort_col, NULL); if (ascending) iupAttribSetId(ih, "SORTSIGN", col, "DOWN"); else iupAttribSetId(ih, "SORTSIGN", col, "UP"); ih->data->sort_has_index = 1; ih->data->last_sort_col = col; iupMatrixDraw(ih, 1); return 0; }
static void iMatrixListCopyLinAttrib(Ihandle* ih, const char* name, int lin1, int lin2) { char* value = iupAttribGetId(ih, name, lin1); /* from lin1 to lin2 */ iupAttribSetStrId(ih, name, lin2, value); }