char* iupdrvGetGlobal(const char *name) { if (iupStrEqual(name, "CURSORPOS")) { int x, y; char* str = iupStrGetMemory(50); iupdrvGetCursorPos(&x, &y); sprintf(str, "%dx%d", x, y); return str; } if (iupStrEqual(name, "SHIFTKEY")) { char key[5]; iupdrvGetKeyState(key); if (key[0] == 'S') return "ON"; return "OFF"; } if (iupStrEqual(name, "CONTROLKEY")) { char key[5]; iupdrvGetKeyState(key); if (key[1] == 'C') return "ON"; return "OFF"; } if (iupStrEqual(name, "MODKEYSTATE")) { char *str = iupStrGetMemory(5); iupdrvGetKeyState(str); return str; } if (iupStrEqual(name, "SCREENSIZE")) { char *str = iupStrGetMemory(50); int w, h; iupdrvGetScreenSize(&w, &h); sprintf(str, "%dx%d", w, h); return str; } if (iupStrEqual(name, "FULLSIZE")) { char *str = iupStrGetMemory(50); int w, h; iupdrvGetFullSize(&w, &h); sprintf(str, "%dx%d", w, h); return str; } if (iupStrEqual(name, "SCREENDEPTH")) { char *str = iupStrGetMemory(50); int bpp = iupdrvGetScreenDepth(); sprintf(str, "%d", bpp); return str; } return NULL; }
static char* gtkListGetValueAttrib(Ihandle* ih) { if (ih->data->has_editbox) { GtkEntry* entry = (GtkEntry*)iupAttribGet(ih, "_IUPGTK_ENTRY"); return iupStrGetMemoryCopy(iupgtkStrConvertFromUTF8(gtk_entry_get_text(entry))); } else { if (ih->data->is_dropdown) { int pos = gtk_combo_box_get_active((GtkComboBox*)ih->handle); char* str = iupStrGetMemory(50); sprintf(str, "%d", pos+1); /* IUP starts at 1 */ return str; } else { GtkTreeSelection* selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(ih->handle)); if (!ih->data->is_multiple) { GtkTreeIter iter; GtkTreeModel* tree_model; if (gtk_tree_selection_get_selected(selection, &tree_model, &iter)) { char* str; GtkTreePath *path = gtk_tree_model_get_path(tree_model, &iter); int* indices = gtk_tree_path_get_indices(path); str = iupStrGetMemory(50); sprintf(str, "%d", indices[0]+1); /* IUP starts at 1 */ gtk_tree_path_free (path); return str; } } else { GList *il, *list = gtk_tree_selection_get_selected_rows(selection, NULL); int count = iupdrvListGetCount(ih); char* str = iupStrGetMemory(count+1); memset(str, '-', count); str[count]=0; for (il=list; il; il=il->next) { GtkTreePath* path = (GtkTreePath*)il->data; int* indices = gtk_tree_path_get_indices(path); str[indices[0]] = '+'; gtk_tree_path_free(path); } g_list_free(list); return str; } } } return NULL; }
static char* motListGetValueAttrib(Ihandle* ih) { if (ih->data->has_editbox) { char *str, *xstr; Widget cbedit; XtVaGetValues(ih->handle, XmNtextField, &cbedit, NULL); xstr = XmTextFieldGetString(cbedit); str = iupStrGetMemoryCopy(xstr); XtFree(xstr); return str; } else { if (ih->data->is_dropdown) { char* str; int pos; XtVaGetValues(ih->handle, XmNselectedPosition, &pos, NULL); str = iupStrGetMemory(50); sprintf(str, "%d", pos+1); /* IUP starts at 1 */ return str; } else { int *pos, sel_count; if (XmListGetSelectedPos(ih->handle, &pos, &sel_count)) /* XmListGetSelectedPos starts at 1 */ { if (!ih->data->is_multiple) { char* str = iupStrGetMemory(50); sprintf(str, "%d", pos[0]); XtFree((char*)pos); return str; } else { int i, count; char* str; XtVaGetValues(ih->handle, XmNitemCount, &count, NULL); str = iupStrGetMemory(count+1); memset(str, '-', count); str[count]=0; for (i=0; i<sel_count; i++) str[pos[i]-1] = '+'; XtFree((char*)pos); return str; } } } } return NULL; }
static char* iMatrixListGetColumnOrderAttrib(Ihandle *ih) { ImatrixListData* mtxList = (ImatrixListData*)iupAttribGet(ih, "_IUPMTXLIST_DATA"); char* str = iupStrGetMemory(30); if (mtxList->label_col == 1) strcat(str, "LABEL"); else if (mtxList->color_col == 1) strcat(str, "COLOR"); else if (mtxList->image_col == 1) strcat(str, "IMAGE"); if (mtxList->label_col == 2) strcat(str, ":LABEL"); else if (mtxList->color_col == 2) strcat(str, ":COLOR"); else if (mtxList->image_col == 2) strcat(str, ":IMAGE"); else return str; if (mtxList->label_col == 3) strcat(str, ":LABEL"); else if (mtxList->color_col == 3) strcat(str, ":COLOR"); else if (mtxList->image_col == 3) strcat(str, ":IMAGE"); return str; }
static char* iExpanderGetBarSizeAttrib(Ihandle* ih) { char* str = iupStrGetMemory(30); int bar_size = iExpanderGetBarSize(ih); sprintf(str, "%d", bar_size); return str; }
static char* winListGetSelectedTextAttrib(Ihandle* ih) { int nc; HWND cbedit; if (!ih->data->has_editbox) return 0; cbedit = (HWND)iupAttribGet(ih, "_IUPWIN_EDITBOX"); nc = GetWindowTextLength(cbedit); if (nc) { int start = 0, end = 0; char* str; SendMessage(cbedit, EM_GETSEL, (WPARAM)&start, (LPARAM)&end); if (start == end) return NULL; str = iupStrGetMemory(nc+1); GetWindowText(cbedit, str, nc+1); str[end] = 0; /* returns only the selected text */ str += start; return str; } else return NULL; }
static char* iScintillaGetPropertyNamessAttrib(Ihandle* ih) { int len = (int)IupScintillaSendMessage(ih, SCI_PROPERTYNAMES, 0, 0); char *str = iupStrGetMemory(len+1); IupScintillaSendMessage(ih, SCI_PROPERTYNAMES, 0, (sptr_t)str); return str; }
static char* iScintillaGetDescribeKeywordSetsAttrib(Ihandle* ih) { int len = (int)IupScintillaSendMessage(ih, SCI_DESCRIBEKEYWORDSETS, 0, 0); char *str = iupStrGetMemory(len+1); IupScintillaSendMessage(ih, SCI_DESCRIBEKEYWORDSETS, 0, (sptr_t)str); return str; }
static char* iBoxGetClientSizeAttrib(Ihandle* ih) { char* str; int width, height; if (ih->handle) { width = ih->currentwidth; height = ih->currentheight; } else { width = ih->userwidth; height = ih->userheight; } if (!width && !height) return NULL; str = iupStrGetMemory(50); width -= 2*ih->data->margin_x; height -= 2*ih->data->margin_y; sprintf(str, "%dx%d", width, height); return str; }
static char* iScintillaGetValueAttrib(Ihandle* ih) { int len = (int)IupScintillaSendMessage(ih, SCI_GETTEXTLENGTH, 0, 0); char* str = iupStrGetMemory(len+1); IupScintillaSendMessage(ih, SCI_GETTEXT, len+1, (sptr_t)str); /* include also the terminator */ return str; }
static char* gtkColorDlgPaletteToString(const char* palette) { char iup_str[20], *gtk_str, *palette_p; char* str = iupStrGetMemory(300); int off = 0, inc; GdkColor color; gtk_str = iupStrDup(palette); iupStrReplace(gtk_str, ':', 0); while (palette && *palette) { if (!gdk_color_parse (gtk_str, &color)) return NULL; inc = sprintf(iup_str, "%d %d %d;", (int)iupCOLOR16TO8(color.red), (int)iupCOLOR16TO8(color.green), (int)iupCOLOR16TO8(color.blue)); memcpy(str+off, iup_str, inc); off += inc; palette_p = strchr(palette, ':'); if (palette_p) { palette_p++; gtk_str += palette_p-palette; } palette = palette_p; } str[off-1] = 0; /* remove last separator */ return str; }
static char* gtkDialogGetClientOffsetAttrib(Ihandle *ih) { char* str = iupStrGetMemory(20); /* remove the menu because it is placed inside the client area */ sprintf(str, "0x%d", -gtkDialogGetMenuSize(ih)); return str; }
static char* gtkWebBrowserGetBackCountAttrib(Ihandle* ih) { WebKitWebBackForwardList *back_forward_list = webkit_web_view_get_back_forward_list ((WebKitWebView*)ih->handle); char* str = iupStrGetMemory(30); sprintf(str, "%d", webkit_web_back_forward_list_get_back_length(back_forward_list)); return str; }
static char* motTextGetSelectionAttrib(Ihandle* ih) { XmTextPosition start = 0, end = 0; char* str; if (!XmTextGetSelectionPosition(ih->handle, &start, &end) || start==end) return NULL; str = iupStrGetMemory(100); /* end is inside the selection, in IUP is outside */ end++; if (ih->data->is_multiline) { int start_col, start_lin, end_col, end_lin; char *value = XmTextGetString(ih->handle); motTextGetLinColFromPosition(value, start, &start_lin, &start_col); motTextGetLinColFromPosition(value, end, &end_lin, &end_col); XtFree(value); sprintf(str,"%d,%d:%d,%d", start_lin, start_col, end_lin, end_col); } else { start++; /* IUP starts at 1 */ end++; sprintf(str, "%d:%d", (int)start, (int)end); } return str; }
char* iupDialogGetChildIdStr(Ihandle* ih) { char *str = iupStrGetMemory(50); Ihandle* dialog = IupGetDialog(ih); sprintf(str, "iup-%s-%d", ih->iclass->name, dialog->data->child_id); return str; }
char *iupdrvGetComputerName(void) { DWORD size = MAX_COMPUTERNAME_LENGTH + 1; char* str = iupStrGetMemory(size); GetComputerNameA((LPSTR)str, &size); return str; }
char *iupdrvGetUserName(void) { DWORD size = 256; char* str = iupStrGetMemory(size); GetUserNameA((LPSTR)str, &size); return (char*)str; }
static char* motTextGetCaretPosAttrib(Ihandle* ih) { XmTextPosition pos = XmTextGetInsertionPosition(ih->handle); char* str = iupStrGetMemory(50); sprintf(str, "%d", (int)pos); return str; }
char *iupdrvGetSystemVersion(void) { char *str = iupStrGetMemory(256); OSVERSIONINFOEXA osvi; SYSTEM_INFO si; ZeroMemory(&si, sizeof(SYSTEM_INFO)); GetSystemInfo(&si); ZeroMemory(&osvi, sizeof(OSVERSIONINFOEXA)); osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXA); GetVersionExA((OSVERSIONINFOA*)&osvi); sprintf(str, "%d.%d.%d", (int)osvi.dwMajorVersion, (int)osvi.dwMinorVersion, (int)osvi.dwBuildNumber); /* Display service pack (if any). */ if (osvi.szCSDVersion && osvi.szCSDVersion[0]!=0) { strcat(str, " "); strcat(str, osvi.szCSDVersion); } if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64) strcat(str, " (IA64)"); else if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) strcat(str, " (x64)"); else strcat(str, " (x86)"); return str; }
static char* iScintillaGetCurrentLineAttrib(Ihandle* ih) { int textLen = iupScintillaSendMessage(ih, SCI_GETLINECOUNT, 0, 0); char* str = iupStrGetMemory(textLen+1); iupScintillaSendMessage(ih, SCI_GETCURLINE, textLen, (sptr_t)str); return str; }
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; }
char* iupScintillaGetMarkerLineFromHandleAttribId(Ihandle* ih, int markerHandle) { int line = iupScintillaSendMessage(ih, SCI_MARKERLINEFROMHANDLE, markerHandle, 0); char* str = iupStrGetMemory(15); sprintf(str, "%d", line); return str; }
char* iupScintillaGetMarkerGetAttribId(Ihandle* ih, int line) { int markers = iupScintillaSendMessage(ih, SCI_MARKERGET, line, 0); char* str = iupStrGetMemory(15); sprintf(str, "%d", markers); return str; }
static char* iScintillaGetLineAttribId(Ihandle* ih, int line) { int len = (int)IupScintillaSendMessage(ih, SCI_LINELENGTH, line, 0); char* str = iupStrGetMemory(len+1); IupScintillaSendMessage(ih, SCI_GETLINE, line, (sptr_t)str); str[len] = 0; return str; }
static char* winDialogGetClientSizeAttrib(Ihandle* ih) { char* str = iupStrGetMemory(20); RECT rect; GetClientRect(ih->handle, &rect); sprintf(str, "%dx%d", (int)(rect.right-rect.left), (int)(rect.bottom-rect.top)); return str; }
static char* gtkWebBrowserGetItemHistoryAttrib(Ihandle* ih, int id) { WebKitWebBackForwardList *back_forward_list = webkit_web_view_get_back_forward_list ((WebKitWebView*)ih->handle); WebKitWebHistoryItem* item = webkit_web_back_forward_list_get_nth_item(back_forward_list, id); char* str = iupStrGetMemory(1024); sprintf(str, "%s", webkit_web_history_item_get_uri(item)); return str; }
static char* winButtonGetAlignmentAttrib(Ihandle *ih) { char* horiz_align2str[3] = {"ALEFT", "ACENTER", "ARIGHT"}; char* vert_align2str[3] = {"ATOP", "ACENTER", "ABOTTOM"}; char *str = iupStrGetMemory(50); sprintf(str, "%s:%s", horiz_align2str[ih->data->horiz_alignment], vert_align2str[ih->data->vert_alignment]); return str; }
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; }
char *iupwinGetSystemVersion(void) { char *str; #ifndef OSVERSIONINFOEX OSVERSIONINFO osvi; osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFO); if (! GetVersionEx ( (OSVERSIONINFO *) &osvi) ) return FALSE; #else OSVERSIONINFOEX osvi; BOOL bOsVersionInfoEx; ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX)); osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); if( !(bOsVersionInfoEx = GetVersionEx ((OSVERSIONINFO *) &osvi)) ) { /* If OSVERSIONINFOEX doesn't work, try OSVERSIONINFO. */ osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFO); if (! GetVersionEx ( (OSVERSIONINFO *) &osvi) ) return FALSE; } #endif str = iupStrGetMemory(sizeof(char)*(IUP_MAX_SYSTEM_NAME+1)); memset(str, 0, IUP_MAX_SYSTEM_NAME); sprintf(str, "%d.%d.%d", osvi.dwMajorVersion, osvi.dwMinorVersion, osvi.dwBuildNumber); /* Display service pack (if any). */ if(osvi.szCSDVersion != NULL && !iupStrEqual(osvi.szCSDVersion, "")) { strcat(str, " "); strcat(str, osvi.szCSDVersion); } #ifdef OSVERSIONINFOEX if (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT && osvi.dwOSVersionInfoSize == sizeof (OSVERSIONINFOEX)) { OSVERSIONINFOEX* osviex = (OSVERSIONINFOEX*)&osvi; if ( osviex->wProductType == VER_NT_WORKSTATION ) { if( osviex->wSuiteMask & VER_SUITE_PERSONAL ) strcat(str, " Home Edition"); else strcat(str, " Professional" ); } else strcat(str, " Server" ); } #endif return str; }
char* iupmotGetBgColorAttrib(Ihandle* ih) { unsigned char r, g, b; Pixel color; char* str = iupStrGetMemory(20); XtVaGetValues(ih->handle, XmNbackground, &color, NULL); iupmotColorGetRGB(color, &r, &g, &b); sprintf(str, "%d %d %d", (int)r, (int)g, (int)b); return str; }