void iupdrvFontGetMultiLineStringSize(Ihandle* ih, const char* str, int *w, int *h) { int max_w = 0; IwinFont* winfont = winFontGet(ih); if (!winfont) { if (w) *w = 0; if (h) *h = 0; return; } if (!str) { if (w) *w = 0; if (h) *h = winfont->charheight * 1; return; } if (str[0]) { SIZE size; int len, wlen; const char *nextstr; const char *curstr = str; HDC hdc = winFontGetDC(ih); HFONT oldhfont = (HFONT)SelectObject(hdc, winfont->hFont); TCHAR* wstr = iupwinStrToSystem(str); do { nextstr = iupStrNextLine(curstr, &len); if (len) { #ifdef UNICODE wlen = MultiByteToWideChar(iupwinStrGetUTF8Mode()? CP_UTF8: CP_ACP, 0, curstr, len, 0, 0); #else wlen = len; #endif size.cx = 0; GetTextExtentPoint32(hdc, wstr, wlen, &size); max_w = iupMAX(max_w, size.cx); wstr += wlen+1; } curstr = nextstr; } while(*nextstr); SelectObject(hdc, oldhfont); winFontReleaseDC(ih, hdc); } if (w) *w = max_w; if (h) *h = winfont->charheight * iupStrLineCount(str); }
static void iMatrixExPasteSetData(Ihandle *ih, const char* data, int data_num_lin, int data_num_col, char sep, int start_lin, int start_col, int num_lin, int num_col, const char* busyname) { ImatExData* matex_data = (ImatExData*)iupAttribGet(ih, "_IUP_MATEX_DATA"); int lin, col, len, l, c; char* value = NULL; int value_max_size = 0, value_len; iupMatrixExBusyStart(matex_data, data_num_lin*data_num_col, busyname); lin = start_lin; l = 0; while (lin <= num_lin && l<data_num_lin) { if (iupMatrixExIsLineVisible(ih, lin)) { const char* next_line = iupStrNextLine(data, &len); l++; col = start_col; c = 0; while (col <= num_col && c<data_num_col) { if (iupMatrixExIsColumnVisible(ih, col)) { const char* next_value = iupStrNextValue(data, len, &value_len, sep); c++; value = iMatrixExStrCopyValue(value, &value_max_size, data, value_len); iupMatrixExSetCellValue(matex_data->ih, lin, col, value); data = next_value; len -= value_len+1; if (!iupMatrixExBusyInc(matex_data)) { if (value) free(value); return; } } col++; } data = next_line; } lin++; } iupMatrixExBusyEnd(matex_data); if (value) free(value); iupBaseCallValueChangedCb(matex_data->ih); }
void iupdrvFontGetMultiLineStringSize(Ihandle* ih, const char* str, int *w, int *h) { int num_lin, max_w; IwinFont* winfont = winFontGet(ih); if (!winfont) { if (w) *w = 0; if (h) *h = 0; return; } if (!str) { if (w) *w = 0; if (h) *h = winfont->charheight * 1; return; } max_w = 0; num_lin = 1; if (str[0]) { SIZE size; int len; const char *nextstr; const char *curstr = str; HDC hdc = winFontGetDC(ih); HFONT oldhfont = SelectObject(hdc, winfont->hFont); do { nextstr = iupStrNextLine(curstr, &len); GetTextExtentPoint32(hdc, curstr, len, &size); max_w = iupMAX(max_w, size.cx); curstr = nextstr; if (*nextstr) num_lin++; } while(*nextstr); SelectObject(hdc, oldhfont); winFontReleaseDC(ih, hdc); } if (w) *w = max_w; if (h) *h = winfont->charheight*num_lin; }
void iupdrvFontGetMultiLineStringSize(Ihandle* ih, const char* str, int *w, int *h) { int num_lin, max_w; ImotFont* motfont = motGetFont(ih); if (!motfont) { if (w) *w = 0; if (h) *h = 0; return; } if (!str) { if (w) *w = 0; if (h) *h = motfont->charheight * 1; return; } max_w = 0; num_lin = 1; if (str[0]) { int len, lw; const char *nextstr; const char *curstr = str; do { nextstr = iupStrNextLine(curstr, &len); lw = XTextWidth(motfont->fontstruct, curstr, len); max_w = iupMAX(max_w, lw); curstr = nextstr; if (*nextstr) num_lin++; } while(*nextstr); } if (w) *w = max_w; if (h) *h = motfont->charheight * num_lin; }
static void iMatrixExPasteData(Ihandle *ih, const char* data, int lin, int col, const char* busyname) { int num_lin, num_col, skip_lines, data_num_lin, data_num_col; char sep=0, *str_sep; IFnii pastesize_cb; /* reset error state */ iupAttribSet(ih, "LASTERROR", NULL); if (!data || data[0]==0) { iupAttribSet(ih, "LASTERROR", "IUP_ERRORNOTEXT"); return; } skip_lines = IupGetInt(ih, "TEXTSKIPLINES"); if (skip_lines) { int i, len; const char *next_line; for (i=0; i<skip_lines; i++) { next_line = iupStrNextLine(data, &len); if (next_line==data) /* no next line */ { iupAttribSet(ih, "LASTERROR", "IUP_ERRORNOTEXT"); return; } data = (char*)next_line; } } str_sep = IupGetAttribute(ih, "TEXTSEPARATOR"); if (str_sep) sep = *str_sep; if (!iMatrixExStrGetDataSize(data, &data_num_lin, &data_num_col, &sep)) { iupAttribSet(ih, "LASTERROR", "IUP_ERRORINVALIDDATA"); return; } num_lin = IupGetInt(ih, "NUMLIN"); num_col = IupGetInt(ih, "NUMCOL"); pastesize_cb = (IFnii)IupGetCallback(ih, "PASTESIZE_CB"); if (pastesize_cb) { int vis_num_lin = iMatrixExGetVisibleNumLin(ih, lin, data_num_lin); int vis_num_col = iMatrixExGetVisibleNumCol(ih, col, data_num_col); if (lin+vis_num_lin>num_lin || col+vis_num_col>num_col) { int ret = pastesize_cb(ih, lin+vis_num_lin, col+vis_num_col); if (ret == IUP_IGNORE) return; else if (ret == IUP_CONTINUE) { if (lin+vis_num_lin>num_lin) IupSetInt(ih, "NUMLIN", lin+vis_num_lin); if (col+vis_num_col>num_col) IupSetInt(ih, "NUMCOL", col+vis_num_col); } } } iMatrixExPasteSetData(ih, data, data_num_lin, data_num_col, sep, lin, col, num_lin, num_col, busyname); }
static int iExpanderAction_CB(Ihandle* bar) { Ihandle *ih = bar->parent; IdrawCanvas *dc = iupDrawCreateCanvas(bar); unsigned char r=0, g=0, b=0; unsigned char bg_r=0, bg_g=0, bg_b=0; char* title = iupAttribGetStr(ih, "TITLE"); iupStrToRGB(iupBaseNativeParentGetBgColorAttrib(ih), &bg_r, &bg_g, &bg_b); iupStrToRGB(IupGetAttribute(ih, "FGCOLOR"), &r, &g, &b); iupDrawParentBackground(dc); if (ih->data->position == IEXPANDER_TOP && title) { /* left align everything */ int len; iupStrNextLine(title, &len); /* get the length of the first line */ iupDrawText(dc, title, len, IEXPAND_HANDLE_SIZE, 0, r, g, b, IupGetAttribute(ih, "FONT")); if (ih->data->highlight) iExpanderHighligh(&r, &g, &b); if (ih->data->state == IEXPANDER_CLOSE) iExpanderDrawArrow(dc, 1, 0, r, g, b, bg_r, bg_g, bg_b, IEXPANDER_RIGHT); else iExpanderDrawArrow(dc, 0, 0, r, g, b, bg_r, bg_g, bg_b, IEXPANDER_BOTTOM); } else { /* center align the arrow */ int x, y; if (ih->data->highlight) iExpanderHighligh(&r, &g, &b); switch(ih->data->position) { case IEXPANDER_LEFT: x = 0; y = (bar->currentheight - IEXPAND_HANDLE_SIZE)/2; if (ih->data->state == IEXPANDER_CLOSE) iExpanderDrawArrow(dc, x, y, r, g, b, bg_r, bg_g, bg_b, IEXPANDER_RIGHT); else iExpanderDrawArrow(dc, x, y, r, g, b, bg_r, bg_g, bg_b, IEXPANDER_LEFT); break; case IEXPANDER_TOP: x = (bar->currentwidth - IEXPAND_HANDLE_SIZE)/2; y = 0; if (ih->data->state == IEXPANDER_CLOSE) iExpanderDrawArrow(dc, x, y, r, g, b, bg_r, bg_g, bg_b, IEXPANDER_BOTTOM); else iExpanderDrawArrow(dc, x, y, r, g, b, bg_r, bg_g, bg_b, IEXPANDER_TOP); break; case IEXPANDER_RIGHT: x = 0; y = (bar->currentheight - IEXPAND_HANDLE_SIZE)/2; if (ih->data->state == IEXPANDER_CLOSE) iExpanderDrawArrow(dc, x, y, r, g, b, bg_r, bg_g, bg_b, IEXPANDER_LEFT); else iExpanderDrawArrow(dc, x, y, r, g, b, bg_r, bg_g, bg_b, IEXPANDER_RIGHT); break; case IEXPANDER_BOTTOM: x = (bar->currentwidth - IEXPAND_HANDLE_SIZE)/2; y = 0; if (ih->data->state == IEXPANDER_CLOSE) iExpanderDrawArrow(dc, x, y, r, g, b, bg_r, bg_g, bg_b, IEXPANDER_TOP); else iExpanderDrawArrow(dc, x, y, r, g, b, bg_r, bg_g, bg_b, IEXPANDER_BOTTOM); break; } } iupDrawFlush(dc); iupDrawKillCanvas(dc); return IUP_DEFAULT; }