static char* iBoxGetCGapAttrib(Ihandle* ih) { if (IupClassMatch(ih, "vbox")) { int charheight; iupdrvFontGetCharSize(ih, NULL, &charheight); return iupStrReturnInt(iupRASTER2HEIGHT(ih->data->gap, charheight)); } else { int charwidth; iupdrvFontGetCharSize(ih, &charwidth, NULL); return iupStrReturnInt(iupRASTER2WIDTH(ih->data->gap, charwidth)); } }
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 = iupAttribGet(child, "TABIMAGE"); if (!tabimage) tabimage = iupTabsAttribGetStrId(ih, "TABIMAGE", pos); 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; }
/* Finish the interactive resize of columns. Call ChangeMatrixWidth to truly change the column size (x : x mouse coordinate (canvas coordinate)). */ void iupMatrixColResFinish(Ihandle* ih, int x) { int charwidth, charheight, width; int y1, y2; iupdrvFontGetCharSize(ih, &charwidth, &charheight); width = x - DragColStartPos - IMAT_DECOR_X; if(width < charwidth) width = charwidth ; /* min size to the cell */ /* delete feedback */ if(Lastxpos != -1) { y1 = ih->data->lin.titlewh; y2 = ih->data->YmaxC; cdCanvasWriteMode(ih->data->cdcanvas, CD_XOR); cdCanvasForeground(ih->data->cdcanvas, IMAT_RESIZE_COLOR); cdCanvasLine(ih->data->cdcanvas, Lastxpos, (ih->data->YmaxC - (y1)), Lastxpos, (ih->data->YmaxC - (y2))); cdCanvasWriteMode(ih->data->cdcanvas, CD_REPLACE); } iMatrixColResChangeMatrixWH(ih, DragCol, width + IMAT_DECOR_X, IMAT_MAT_COL); Dragging = 0; }
/* Change the column width interactively, just change the line in the screen. When the user finishes the drag, the iupMatrixColResFinish function is called to truly change the column width (x : x mouse coordinate (canvas coordinate)). */ void iupMatrixColResMove(Ihandle* ih, int x) { int y1, y2, charwidth, charheight; iupdrvFontGetCharSize(ih, &charwidth, &charheight); /* If the size column was tiny, no change the size column */ if(x < DragColStartPos + charwidth + IMAT_DECOR_X) return; y1 = ih->data->lin.titlewh; y2 = ih->data->YmaxC; cdCanvasWriteMode(ih->data->cdcanvas, CD_XOR); cdCanvasForeground(ih->data->cdcanvas, IMAT_RESIZE_COLOR); /* If it is not the first time, move old line */ if(Lastxpos != -1) cdCanvasLine(ih->data->cdcanvas, Lastxpos, (ih->data->YmaxC - (y1)), Lastxpos, (ih->data->YmaxC - (y2))); cdCanvasLine(ih->data->cdcanvas, x, (ih->data->YmaxC - (y1)), x, (ih->data->YmaxC - (y2))); Lastxpos = x; cdCanvasWriteMode(ih->data->cdcanvas, CD_REPLACE); }
/* Change the width/height of a column/line. Call when the WIDTHx or HEIGHTx attributes are changed. Get the nes size of column/line, pass of the IUP unit to pixels and call the iMatrixColResChangeMatrixWH function -> col : column/ line that will take its width changed. col = 1 is the first column/line. col = 0 is the column/line of titles. -> m : indicate if it is acting on a column (IMAT_MAT_COL) or line (IMAT_MAT_LIN). */ void iupMatrixColResSet(Ihandle* ih, const char* value, int col, int m, int pixels) { int largura = 0; if(iupStrToInt(value, &largura)) { col--; /* the left top cell is 1:1 to the user, internally is 0:0 */ if(largura) { if(pixels) { if(m == IMAT_MAT_COL) largura = (int)(largura + IMAT_DECOR_X); else largura = (int)(largura + IMAT_DECOR_Y); } else { int charwidth, charheight; iupdrvFontGetCharSize(ih, &charwidth, &charheight); /* Transform in pixels */ if(m == IMAT_MAT_COL) largura = (int)((largura / 4.) * charwidth ) + IMAT_DECOR_X; else largura = (int)((largura / 8.) * charheight) + IMAT_DECOR_Y; } } iMatrixColResChangeMatrixWH(ih, col, largura, m); } }
static void winListLayoutUpdateMethod(Ihandle *ih) { if (ih->data->is_dropdown) { /* Must add the dropdown area, or it will not be visible */ RECT rect; int charheight, calc_h, win_h, win_w, voptions; voptions = iupAttribGetInt(ih, "VISIBLE_ITEMS"); if (voptions <= 0) voptions = 1; iupdrvFontGetCharSize(ih, NULL, &charheight); calc_h = ih->currentheight + voptions*charheight; SendMessage(ih->handle, CB_GETDROPPEDCONTROLRECT, 0, (LPARAM)&rect); win_h = rect.bottom-rect.top; win_w = rect.right-rect.left; if (ih->currentwidth != win_w || calc_h != win_h) SetWindowPos(ih->handle, HWND_TOP, ih->x, ih->y, ih->currentwidth, calc_h, SWP_NOACTIVATE|SWP_NOZORDER|SWP_NOOWNERZORDER); else SetWindowPos(ih->handle, HWND_TOP, ih->x, ih->y, 0, 0, SWP_NOSIZE|SWP_NOACTIVATE|SWP_NOZORDER|SWP_NOOWNERZORDER); } else iupdrvBaseLayoutUpdateMethod(ih); }
char* iupBaseGetSizeAttrib(Ihandle* ih) { char* str; int charwidth, charheight, width, height; if (ih->handle) { width = ih->currentwidth; height = ih->currentheight; } else { width = ih->userwidth; height = ih->userheight; } iupdrvFontGetCharSize(ih, &charwidth, &charheight); if (charwidth == 0 || charheight == 0) return NULL; /* if font failed get from the hash table */ str = iupStrGetMemory(50); sprintf(str, "%dx%d", iupRASTER2WIDTH(width, charwidth), iupRASTER2HEIGHT(height, charheight)); return str; }
static int iGridBoxSetCGapColAttrib(Ihandle* ih, const char* value) { int cgap, charheight; iupStrToInt(value, &cgap); iupdrvFontGetCharSize(ih, NULL, &charheight); ih->data->gap_col = iupHEIGHT2RASTER(cgap, charheight); return 0; }
static char* iBoxGetCMarginAttrib(Ihandle* ih) { char *str = iupStrGetMemory(50); int charwidth, charheight; iupdrvFontGetCharSize(ih, &charwidth, &charheight); sprintf(str, "%dx%d", iupRASTER2WIDTH(ih->data->margin_x, charwidth), iupRASTER2HEIGHT(ih->data->margin_y, charheight)); return str; }
static int iGridBoxSetCGapLinAttrib(Ihandle* ih, const char* value) { int cgap, charwidth; iupStrToInt(value, &cgap); iupdrvFontGetCharSize(ih, &charwidth, NULL); ih->data->gap_lin = iupWIDTH2RASTER(cgap, charwidth); return 0; }
static void iTextComputeNaturalSizeMethod(Ihandle* ih, int *w, int *h, int *expand) { int natural_w = 0, natural_h = 0, visiblecolumns = iupAttribGetInt(ih, "VISIBLECOLUMNS"), visiblelines = iupAttribGetInt(ih, "VISIBLELINES"); (void)expand; /* unset if not a container */ /* Since the contents can be changed by the user, the size can not be dependent on it. */ if (ih->data->is_multiline) { iupdrvFontGetCharSize(ih, NULL, &natural_h); /* one line height */ natural_w = iupdrvFontGetStringWidth(ih, "WWWWWWWWWW"); natural_w = (visiblecolumns*natural_w)/10; natural_h = visiblelines*natural_h; } else { iupdrvFontGetCharSize(ih, NULL, &natural_h); /* one line height */ natural_w = iupdrvFontGetStringWidth(ih, "WWWWWWWWWW"); natural_w = (visiblecolumns*natural_w)/10; } /* compute the borders space */ if (iupAttribGetBoolean(ih, "BORDER")) iupdrvTextAddBorders(&natural_w, &natural_h); if (iupAttribGetBoolean(ih, "SPIN")) iupdrvTextAddSpin(&natural_w, natural_h); natural_w += 2*ih->data->horiz_padding; natural_h += 2*ih->data->vert_padding; /* add scrollbar */ if (ih->data->is_multiline && ih->data->sb) { int sb_size = iupdrvGetScrollbarSize(); if (ih->data->sb & IUP_SB_HORIZ) natural_w += sb_size; if (ih->data->sb & IUP_SB_VERT) natural_h += sb_size; } *w = natural_w; *h = natural_h; }
static char* iBoxGetCGapAttrib(Ihandle* ih) { char *str = iupStrGetMemory(50); if (iupStrEqual(ih->iclass->name, "vbox")) { int charheight; iupdrvFontGetCharSize(ih, NULL, &charheight); sprintf(str, "%d", iupRASTER2HEIGHT(ih->data->gap, charheight)); } else { int charwidth; iupdrvFontGetCharSize(ih, &charwidth, NULL); sprintf(str, "%d", iupRASTER2WIDTH(ih->data->gap, charwidth)); } return str; }
static int iDialogSetSizeAttrib(Ihandle* ih, const char* value) { if (!value) { ih->userwidth = 0; ih->userheight = 0; } else { char *sh, sw[40]; strcpy(sw, value); sh = strchr(sw, 'x'); if (!sh) sh = ""; else { *sh = '\0'; /* to mark the end of sw */ ++sh; } { int charwidth, charheight; int screen_width, screen_height; int wscale = iDialogSizeGetScale(sw); int hscale = iDialogSizeGetScale(sh); int width = 0, height = 0; iupStrToIntInt(value, &width, &height, 'x'); if (width < 0) width = 0; if (height < 0) height = 0; iupdrvFontGetCharSize(ih, &charwidth, &charheight); /* desktop size, excluding task bars and menu bars */ iupdrvGetScreenSize(&screen_width, &screen_height); if (wscale) width = screen_width/wscale; else width = iupWIDTH2RASTER(width, charwidth); if (hscale) height = screen_height/hscale; else height = iupHEIGHT2RASTER(height, charheight); ih->userwidth = width; ih->userheight = height; } } /* must reset the current size, */ /* so the user or the natural size will be used to resize the dialog */ ih->currentwidth = 0; ih->currentheight = 0; return 0; }
static int iBoxSetCGapAttrib(Ihandle* ih, const char* value) { int cgap; iupStrToInt(value, &cgap); if (IupClassMatch(ih, "vbox")) { int charheight; iupdrvFontGetCharSize(ih, NULL, &charheight); ih->data->gap = iupHEIGHT2RASTER(cgap, charheight); } else { int charwidth; iupdrvFontGetCharSize(ih, &charwidth, NULL); ih->data->gap = iupWIDTH2RASTER(cgap, charwidth); } return 0; }
int iupdrvMenuGetMenuBarSize(Ihandle* ih) { int ch; iupdrvFontGetCharSize(ih, NULL, &ch); #ifdef WIN32 return 3 + ch + 3; #else return 4 + ch + 4; #endif }
char* iupBaseGetCharSizeAttrib(Ihandle* ih) { int charwidth, charheight; iupdrvFontGetCharSize(ih, &charwidth, &charheight); if (charwidth == 0 || charheight == 0) return NULL; return iupStrReturnIntInt(charwidth, charheight, 'x'); }
static void gtkWebBrowserComputeNaturalSizeMethod(Ihandle* ih, int *w, int *h, int *children_expand) { int natural_w = 0, natural_h = 0; (void)children_expand; /* unset if not a container */ /* natural size is 1 character */ iupdrvFontGetCharSize(ih, &natural_w, &natural_h); *w = natural_w; *h = natural_h; }
static void iCanvasComputeNaturalSizeMethod(Ihandle* ih, int *w, int *h, int *expand) { int natural_w = 0, natural_h = 0; (void)expand; /* unset if not a container */ /* canvas natural size is 1 character */ iupdrvFontGetCharSize(ih, &natural_w, &natural_h); *w = natural_w; *h = natural_h; }
static int iBoxSetCMarginAttrib(Ihandle* ih, const char* value) { int cmargin_x=-1, cmargin_y=-1; int charwidth, charheight; iupdrvFontGetCharSize(ih, &charwidth, &charheight); iupStrToIntInt(value, &cmargin_x, &cmargin_y, 'x'); if (cmargin_x!=-1) ih->data->margin_horiz = iupWIDTH2RASTER(cmargin_x, charwidth); if (cmargin_y!=-1) ih->data->margin_vert = iupHEIGHT2RASTER(cmargin_y, charheight); return 0; }
char* iupBaseGetCharSizeAttrib(Ihandle* ih) { char* str; int charwidth, charheight; iupdrvFontGetCharSize(ih, &charwidth, &charheight); if (charwidth == 0 || charheight == 0) return NULL; str = iupStrGetMemory(50); sprintf(str, "%dx%d", charwidth, charheight); return str; }
static int iExpanderGetBarSize(Ihandle* ih) { int bar_size; if (ih->data->barSize == -1) { iupdrvFontGetCharSize(ih, NULL, &bar_size); if (bar_size < IEXPAND_HANDLE_SIZE) bar_size = IEXPAND_HANDLE_SIZE; } else bar_size = ih->data->barSize; return bar_size; }
static void gtkWebBrowserComputeNaturalSizeMethod(Ihandle* ih, int *w, int *h, int *expand) { int natural_w = 0, natural_h = 0; int sb_size = iupdrvGetScrollbarSize(); (void)expand; /* unset if not a container */ iupdrvFontGetCharSize(ih, &natural_w, &natural_h); if (ih->data->sb & IUP_SB_HORIZ) natural_h += sb_size; /* sb horizontal affects vertical size */ if (ih->data->sb & IUP_SB_VERT) natural_w += sb_size; /* sb vertical affects horizontal size */ *w = natural_w; *h = natural_h; }
static int iMatrixEditTextAction_CB(Ihandle* ih_text, int c, char* after) { Ihandle* ih = ih_text->parent; IFniiiis cb = (IFniiiis) IupGetCallback(ih, "ACTION_CB"); if (iupAttribGetBoolean(ih, "EDITFITVALUE")) { int value_w, value_h, resize = 0; value_w = iupdrvFontGetStringWidth(ih_text, after); iupdrvFontGetCharSize(ih_text, NULL, &value_h); if (iupAttribGetBoolean(ih_text, "BORDER")) { value_w += 2 * 4; value_h += 2 * 4; } if (value_w > ih_text->currentwidth) { ih_text->currentwidth = value_w; resize = 1; } if (value_h > ih_text->currentheight) { ih_text->currentheight = value_h; resize = 1; } if (resize) iupClassObjectLayoutUpdate(ih_text); } if (cb && iup_isprint(c)) /* only for keys that ARE ASCii characters */ { int oldc = c; c = cb(ih, c, ih->data->edit_lin, ih->data->edit_col, 1, after); if (c == IUP_IGNORE || c == IUP_CLOSE || c == IUP_CONTINUE) return c; else if(c == IUP_DEFAULT) c = oldc; return c; } return IUP_DEFAULT; }
/* Get the width/height of a column/line. The WIDTH and HEIGHT attributes can't be collected because when the width/height of the column/line are changed dinamically, the value of the attribute was out-of-date. Moreover, not all columns/lines has its WIDTH and HEIGHT attributes defined (widht and height default) -> col : column/ line that will take its width collected. col = 1 is the first column/line. col = 0 is the column/line of titles. -> m : indicate if it is acting on a column (IMAT_MAT_COL) or line (IMAT_MAT_LIN). */ char *iupMatrixColResGet(Ihandle* ih, int col, int m, int pixels) { char* width = iupStrGetMemory(100); int w; ImatLinColData *p; if(m == IMAT_MAT_LIN) p = &(ih->data->lin); else p = &(ih->data->col); if(col > p->num || col < 0) return NULL; if(col == 0) w = p->titlewh; else { col--; /* the left top cell is 1:1 to the user, internally is 0:0 */ w = p->wh[col]; } if(w) { if(pixels) { if(m == IMAT_MAT_COL) sprintf(width, "%d", (int)(w - IMAT_DECOR_X)); else sprintf(width, "%d", (int)(w - IMAT_DECOR_Y)); } else { int charwidth, charheight; iupdrvFontGetCharSize(ih, &charwidth, &charheight); if(m == IMAT_MAT_COL) sprintf(width, "%d", (int)((w - IMAT_DECOR_X) * 4 / charwidth)); else sprintf(width, "%d", (int)((w - IMAT_DECOR_Y) * 8 / charheight)); } } else strcpy(width, "0"); return width; }
static int winListSetSpacingAttrib(Ihandle* ih, const char* value) { if (ih->data->is_dropdown) return 0; if (!iupStrToInt(value, &ih->data->spacing)) ih->data->spacing = 0; if (ih->handle) { int txt_h; iupdrvFontGetCharSize(ih, NULL, &txt_h); txt_h += 2*ih->data->spacing; /* set for all items */ if (!ih->data->show_image) SendMessage(ih->handle, WIN_SETITEMHEIGHT(ih), 0, txt_h); else { /* must manually set for each item */ int img_h, i, count = SendMessage(ih->handle, WIN_GETCOUNT(ih), 0, 0); for (i=0; i<count; i++) { winListItemData* itemdata = winListGetItemData(ih, i); if (itemdata->hBitmap) { iupdrvImageGetInfo(itemdata->hBitmap, NULL, &img_h, NULL); img_h += 2*ih->data->spacing; if (img_h > txt_h) SendMessage(ih->handle, WIN_SETITEMHEIGHT(ih), i, img_h); else SendMessage(ih->handle, WIN_SETITEMHEIGHT(ih), i, txt_h); } else SendMessage(ih->handle, WIN_SETITEMHEIGHT(ih), i, txt_h); } } return 0; } else return 1; /* store until not mapped, when mapped will be set again */ }
char *iupMatrixGetSize(Ihandle* ih, int index, int m, int pixels) { char* str; int size; ImatLinColData *lincol_data; if(m == IMAT_PROCESS_LIN) lincol_data = &(ih->data->lines); else lincol_data = &(ih->data->columns); if (index < 0 || index > lincol_data->num-1) return NULL; if (m == IMAT_PROCESS_LIN) size = iupMatrixAuxGetLineHeight(ih, index); else size = iupMatrixAuxGetColumnWidth(ih, index); str = iupStrGetMemory(100); if (size) { /* remove the decoration added in iupMatrixAuxGet */ if (m == IMAT_PROCESS_COL) size -= IMAT_PADDING_W + IMAT_FRAME_W; else size -= IMAT_PADDING_H + IMAT_FRAME_H; if (!pixels) { int charwidth, charheight; iupdrvFontGetCharSize(ih, &charwidth, &charheight); if (m == IMAT_PROCESS_COL) size = iupRASTER2WIDTH(size, charwidth); else size = iupRASTER2HEIGHT(size, charheight); } } sprintf(str, "%d", size); return str; }
static int winListSetSpacingAttrib(Ihandle* ih, const char* value) { if (ih->data->is_dropdown) return 0; if (!iupStrToInt(value, &ih->data->spacing)) ih->data->spacing = 0; if (ih->handle) { int height; iupdrvFontGetCharSize(ih, NULL, &height); height += 2*ih->data->spacing; SendMessage(ih->handle, WIN_SETITEMHEIGHT(ih), 0, height); return 0; } else return 1; /* store until not mapped, when mapped will be set again */ }
static void iCanvasComputeNaturalSizeMethod(Ihandle* ih) { /* always initialize the natural size using the user size */ ih->naturalwidth = ih->userwidth; ih->naturalheight = ih->userheight; /* if user size is not defined, then calculate the natural size */ if (ih->naturalwidth <= 0 || ih->naturalheight <= 0) { int natural_w = 0, natural_h = 0; /* canvas natural size is 1 character */ iupdrvFontGetCharSize(ih, &natural_w, &natural_h); /* only update the natural size if user size is not defined. */ if (ih->naturalwidth <= 0) ih->naturalwidth = natural_w; if (ih->naturalheight <= 0) ih->naturalheight = natural_h; } }
char* iupBaseGetSizeAttrib(Ihandle* ih) { int charwidth, charheight, width, height; if (ih->handle) { width = ih->currentwidth; height = ih->currentheight; } else { width = ih->userwidth; height = ih->userheight; } iupdrvFontGetCharSize(ih, &charwidth, &charheight); if (charwidth == 0 || charheight == 0) return NULL; /* if font failed get from the hash table */ return iupStrReturnIntInt(iupRASTER2WIDTH(width, charwidth), iupRASTER2HEIGHT(height, charheight), 'x'); }
static char* iDialogGetSizeAttrib(Ihandle* ih) { int charwidth, charheight, width, height; if (ih->handle) { /* ih->currentwidth and/or ih->currentheight could have been reset in SetSize */ iupdrvDialogGetSize(ih, NULL, &width, &height); } else { width = ih->userwidth; height = ih->userheight; } iupdrvFontGetCharSize(ih, &charwidth, &charheight); if (charwidth == 0 || charheight == 0) return NULL; /* if font failed get from the hash table */ return iupStrReturnIntInt(iupRASTER2WIDTH(width, charwidth), iupRASTER2HEIGHT(height, charheight), 'x'); }