void IupGLMakeCurrent(Ihandle* ih) { IGlControlData* gldata; iupASSERT(iupObjectCheck(ih)); if (!iupObjectCheck(ih)) return; /* must be an IupGLCanvas */ if (ih->iclass->nativetype != IUP_TYPECANVAS || !IupClassMatch(ih, "glcanvas")) return; /* must be mapped */ gldata = (IGlControlData*)iupAttribGet(ih, "_IUP_GLCONTROLDATA"); if (!gldata->window) return; if (wglMakeCurrent(gldata->device, gldata->context)==FALSE) { iupAttribSetStr(ih, "ERROR", "Failed to set new current context"); iupAttribStoreStr(ih, "LASTERROR", IupGetGlobal("LASTERROR")); } else { iupAttribSetStr(ih, "ERROR", NULL); iupAttribSetStr(ih, "LASTERROR", NULL); } }
void IupSetAttribute(Ihandle *ih, const char* name, const char *value) { int inherit; iupASSERT(name!=NULL); if (!name) return; if (!ih) { IupSetGlobal(name, value); return; } iupASSERT(iupObjectCheck(ih)); if (!iupObjectCheck(ih)) return; if (iupATTRIB_ISINTERNAL(name)) iupAttribSetStr(ih, name, value); else { if (iupClassObjectSetAttribute(ih, name, value, &inherit)!=0) /* store strings and pointers */ iupAttribSetStr(ih, name, value); if (inherit) iAttribNotifyChildren(ih, name, value); } }
static void motTabsChildRemovedMethod(Ihandle* ih, Ihandle* child) { if (ih->handle) { Widget child_manager = (Widget)iupAttribGet(child, "_IUPTAB_CONTAINER"); if (child_manager) { int cur_pos, pos; Widget tab_button = (Widget)iupAttribGet(child, "_IUPMOT_TABBUTTON"); cur_pos = iupdrvTabsGetCurrentTab(ih); pos = iupAttribGetInt(child, "_IUPMOT_TABNUMBER"); /* did not work when using XtVaGetValues(child_manager, XmNpageNumber) */ if (cur_pos == pos) { if (cur_pos == 0) cur_pos = 1; else cur_pos--; iupdrvTabsSetCurrentTab(ih, cur_pos); } XtDestroyWidget(tab_button); XtDestroyWidget(child_manager); /* compact the tab number usage */ motTabsUpdatePageNumber(ih); iupAttribSetStr(child, "_IUPTAB_CONTAINER", NULL); iupAttribSetStr(child, "_IUPMOT_TABBUTTON", NULL); iupAttribSetStr(child, "_IUPMOT_TABNUMBER", NULL); } } }
static int winToggleSetActiveAttrib(Ihandle* ih, const char* value) { /* update the inactive image if necessary */ if (ih->data->type == IUP_TOGGLE_IMAGE) { if (iupwin_comctl32ver6) { iupBaseSetActiveAttrib(ih, value); iupdrvDisplayRedraw(ih); return 0; } else { int active = iupStrBoolean(value); int check = SendMessage(ih->handle, BM_GETCHECK, 0, 0L); if (active) iupAttribSetStr(ih, "_IUPWIN_ACTIVE", "YES"); else iupAttribSetStr(ih, "_IUPWIN_ACTIVE", "NO"); winToggleUpdateImage(ih, active, check); return 0; } } return iupBaseSetActiveAttrib(ih, value); }
static void motMessageDlgCallback(Widget w, Ihandle* ih, XmAnyCallbackStruct* call_data) { (void)w; if (call_data->reason == XmCR_OK) iupAttribSetStr(ih, "BUTTONRESPONSE", "1"); else if (call_data->reason == XmCR_CANCEL) iupAttribSetStr(ih, "BUTTONRESPONSE", "2"); }
static int iItemCreateMethod(Ihandle* ih, void** params) { if (params) { if (params[0]) iupAttribSetStr(ih, "TITLE", (char*)(params[0])); if (params[1]) iupAttribSetStr(ih, "ACTION", (char*)(params[1])); } return IUP_NOERROR; }
static void motFileDlgCBclose(Widget w, XtPointer client_data, XtPointer call_data) { Ihandle *ih = (Ihandle*)client_data; if (!ih) return; (void)call_data; (void)w; iupAttribSetStr(ih, "VALUE", NULL); iupAttribSetStr(ih, "STATUS", "-1"); iupAttribSetStr(ih, "_IUP_WM_DELETE", "1"); }
static int iToggleCreateMethod(Ihandle* ih, void** params) { if (params) { if (params[0]) iupAttribSetStr(ih, "TITLE", (char*)(params[0])); if (params[1]) iupAttribSetStr(ih, "ACTION", (char*)(params[1])); } ih->data = iupALLOCCTRLDATA(); return IUP_NOERROR; }
static int motTextSetValueAttrib(Ihandle* ih, const char* value) { if (!value) value = ""; motTextSetSpinValueAttrib(ih, value); /* disable callbacks */ iupAttribSetStr(ih, "_IUPMOT_DISABLE_TEXT_CB", "1"); XmTextSetString(ih->handle, (char*)value); iupAttribSetStr(ih, "_IUPMOT_DISABLE_TEXT_CB", NULL); return 0; }
static int winListSetValueAttrib(Ihandle* ih, const char* value) { if (ih->data->has_editbox) { if (!value) value = ""; SetWindowText(ih->handle, value); } else { if (ih->data->is_dropdown || !ih->data->is_multiple) { int pos; if (iupStrToInt(value, &pos)==1) { SendMessage(ih->handle, WIN_SETCURSEL(ih), pos-1, 0); /* IUP starts at 1 */ iupAttribSetInt(ih, "_IUPLIST_OLDVALUE", pos); } else { SendMessage(ih->handle, WIN_SETCURSEL(ih), (WPARAM)-1, 0); /* no selection */ iupAttribSetStr(ih, "_IUPLIST_OLDVALUE", NULL); } } else { /* User has changed a multiple selection on a simple list. */ int i, len, count; /* Clear all selections */ SendMessage(ih->handle, LB_SETSEL, FALSE, -1); if (!value) { iupAttribSetStr(ih, "_IUPLIST_OLDVALUE", NULL); return 0; } count = SendMessage(ih->handle, LB_GETCOUNT, 0, 0L); len = strlen(value); if (len < count) count = len; /* update selection list */ for (i = 0; i<count; i++) { if (value[i]=='+') SendMessage(ih->handle, LB_SETSEL, TRUE, i); } iupAttribStoreStr(ih, "_IUPLIST_OLDVALUE", value); } } return 0; }
static void iSpinRunTimer(Ihandle* ih, char* status, char* dir) { Ihandle* spin_timer = IupGetHandle("IupSpinTimer"); iupAttribSet(spin_timer, "_IUPSPIN_BUTTON", (char*)ih); iupAttribSetStr(spin_timer, "_IUPSPIN_STATUS", status); iupAttribSetStr(spin_timer, "_IUPSPIN_DIR", dir); iupAttribSet(spin_timer, "_IUPSPIN_COUNT", "0"); IupSetAttribute(spin_timer, "TIME", "400"); IupSetAttribute(spin_timer, "RUN", "YES"); }
static int gtkListSetAppendAttrib(Ihandle* ih, const char* value) { if (ih->data->has_editbox) { GtkEntry* entry = (GtkEntry*)iupAttribGet(ih, "_IUPGTK_ENTRY"); gint pos = strlen(gtk_entry_get_text(entry))+1; iupAttribSetStr(ih, "_IUPGTK_DISABLE_TEXT_CB", "1"); /* disable callbacks */ gtk_editable_insert_text(GTK_EDITABLE(entry), iupgtkStrConvertToUTF8(value), -1, &pos); iupAttribSetStr(ih, "_IUPGTK_DISABLE_TEXT_CB", NULL); } return 0; }
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 winColorDlgPopup(Ihandle* ih, int x, int y) { InativeHandle* parent = iupDialogGetNativeParent(ih); CHOOSECOLOR choosecolor; unsigned char r, g, b; COLORREF lpCustColors[16]; char* value; iupAttribSetInt(ih, "_IUPDLG_X", x); iupAttribSetInt(ih, "_IUPDLG_Y", y); if (!parent) parent = GetActiveWindow(); iupStrToRGB(iupAttribGet(ih, "VALUE"), &r, &g, &b); ZeroMemory(lpCustColors, 16*sizeof(COLORREF)); value = iupAttribGetStr(ih, "COLORTABLE"); if (value) winColorDlgStringToColors(value, lpCustColors); ZeroMemory(&choosecolor, sizeof(CHOOSECOLOR)); choosecolor.lStructSize = sizeof(CHOOSECOLOR); choosecolor.hwndOwner = parent; choosecolor.rgbResult = RGB(r, g, b); choosecolor.lpCustColors = lpCustColors; choosecolor.lCustData = (LPARAM)ih; choosecolor.Flags = CC_RGBINIT|CC_FULLOPEN; if (IupGetCallback(ih, "HELP_CB")) choosecolor.Flags |= CC_SHOWHELP; choosecolor.Flags |= CC_ENABLEHOOK; choosecolor.lpfnHook = (LPCCHOOKPROC)winColorDlgHookProc; if (!ChooseColor(&choosecolor)) { iupAttribSetStr(ih, "VALUE", NULL); iupAttribSetStr(ih, "COLORTABLE", NULL); iupAttribSetStr(ih, "STATUS", NULL); return IUP_NOERROR; } iupAttribSetStrf(ih, "VALUE", "%d %d %d", GetRValue(choosecolor.rgbResult), GetGValue(choosecolor.rgbResult), GetBValue(choosecolor.rgbResult)); iupAttribSetStr(ih, "COLORTABLE", winColorDlgColorsToString(lpCustColors)); iupAttribSetStr(ih, "STATUS", "1"); return IUP_NOERROR; }
static void motFileDlgHelpCallback(Widget w, Ihandle *ih, XtPointer call_data) { Icallback cb = IupGetCallback(ih, "HELP_CB"); if (cb && cb(ih) == IUP_CLOSE) { iupAttribSetStr(ih, "VALUE", NULL); iupAttribSetStr(ih, "FILEEXIST", NULL); iupAttribSetStr(ih, "STATUS", "-1"); } (void)call_data; (void)w; }
static void gtkFileDlgPreviewRealize(GtkWidget *widget, Ihandle *ih) { iupAttribSetStr(ih, "PREVIEWDC", iupgtkGetNativeGraphicsContext(widget)); iupAttribSetStr(ih, "WID", (char*)widget); #ifdef WIN32 iupAttribSetStr(ih, "HWND", (char*)GDK_WINDOW_HWND(widget->window)); #else iupAttribSetStr(ih, "XWINDOW", (char*)GDK_WINDOW_XID(widget->window)); iupAttribSetStr(ih, "XDISPLAY", (char*)iupdrvGetDisplay()); #endif gtkFileDlgUpdatePreviewGLCanvas(ih); }
static void gtkFileDlgUpdatePreviewGLCanvas(Ihandle* ih) { Ihandle* glcanvas = IupGetAttributeHandle(ih, "PREVIEWGLCANVAS"); if (glcanvas) { #ifdef WIN32 iupAttribSetStr(glcanvas, "HWND", iupAttribGet(ih, "HWND")); #else iupAttribSetStr(glcanvas, "XWINDOW", iupAttribGet(ih, "XWINDOW")); #endif glcanvas->iclass->Map(glcanvas); } }
static ImotFont* motFontCreateNativeFont(Ihandle* ih, const char* value) { ImotFont *motfont = motFindFont(iupAttribGetStr(ih, "FOUNDRY"), value); if (!motfont) { iupERROR1("Failed to create Font: %s", value); return NULL; } iupAttribSetStr(ih, "_IUPMOT_FONT", (char*)motfont); iupAttribSetStr(ih, "XLFD", motfont->xlfd); return motfont; }
static int iLinkCreateMethod(Ihandle* ih, void **params) { if (params) { if (params[0]) iupAttribSetStr(ih, "URL", (char*)(params[0])); if (params[1]) iupAttribSetStr(ih, "TITLE", (char*)(params[1])); } IupSetCallback(ih, "BUTTON_CB", (Icallback)iLinkButton_CB); IupSetCallback(ih, "ENTERWINDOW_CB", iLinkEnterWindow_CB); IupSetCallback(ih, "LEAVEWINDOW_CB", iLinkLeaveWindow_CB); return IUP_NOERROR; }
static void motFileDlgCallback(Widget w, Ihandle* ih, XmFileSelectionBoxCallbackStruct* call_data) { (void)w; if (call_data->reason == XmCR_OK) { int dialogtype = iupAttribGetInt(ih, "_IUPDLG_DIALOGTYPE"); char* filename; XmStringGetLtoR(call_data->value, XmSTRING_DEFAULT_CHARSET, &filename); iupAttribStoreStr(ih, "VALUE", filename); XtFree(filename); if (!motFileDlgCheckValue(ih, w)) return; if (dialogtype == IUP_DIALOGDIR) { iupAttribSetStr(ih, "STATUS", "0"); iupAttribSetStr(ih, "FILEEXIST", NULL); } else { IFnss file_cb = (IFnss)IupGetCallback(ih, "FILE_CB"); if (file_cb && file_cb(ih, iupAttribGet(ih, "VALUE"), "OK") == IUP_IGNORE) return; if (iupdrvIsFile(iupAttribGet(ih, "VALUE"))) /* check if file exists */ { iupAttribSetStr(ih, "FILEEXIST", "YES"); iupAttribSetStr(ih, "STATUS", "0"); } else { iupAttribSetStr(ih, "FILEEXIST", "NO"); iupAttribSetStr(ih, "STATUS", "1"); } } if (!iupAttribGetInt(ih, "NOCHANGEDIR")) /* do change the current directory */ { /* XmFileSelection does not change the current directory */ XmString xm_dir; char* dir; XtVaGetValues(w, XmNdirectory, &xm_dir, NULL); XmStringGetLtoR(xm_dir, XmSTRING_DEFAULT_CHARSET, &dir); iupdrvSetCurrentDirectory(dir); XtFree(dir); } } else if (call_data->reason == XmCR_CANCEL) { iupAttribSetStr(ih, "VALUE", NULL); iupAttribSetStr(ih, "FILEEXIST", NULL); iupAttribSetStr(ih, "STATUS", "-1"); } }
static int motListSetAppendAttrib(Ihandle* ih, const char* value) { if (value && ih->data->has_editbox) { XmTextPosition pos; Widget cbedit; XtVaGetValues(ih->handle, XmNtextField, &cbedit, NULL); pos = XmTextFieldGetLastPosition(cbedit); iupAttribSetStr(ih, "_IUPMOT_DISABLE_TEXT_CB", "1"); /* disable callbacks */ XmTextFieldInsert(cbedit, pos+1, (char*)value); iupAttribSetStr(ih, "_IUPMOT_DISABLE_TEXT_CB", NULL); } return 0; }
static int motTextSetSpinIncAttrib(Ihandle* ih, const char* value) { Widget spinbox = (Widget)iupAttribGet(ih, "_IUP_EXTRAPARENT"); if (spinbox && XmIsSpinBox(spinbox)) { int inc; if (iupStrToInt(value, &inc)) { iupAttribSetStr(ih, "_IUPMOT_DISABLE_TEXT_CB", "1"); XtVaSetValues(ih->handle, XmNincrementValue, inc, NULL); iupAttribSetStr(ih, "_IUPMOT_DISABLE_TEXT_CB", NULL); } } return 1; }
static int motTextSetSpinMinAttrib(Ihandle* ih, const char* value) { Widget spinbox = (Widget)iupAttribGet(ih, "_IUP_EXTRAPARENT"); if (spinbox && XmIsSpinBox(spinbox)) { int min; if (iupStrToInt(value, &min)) { iupAttribSetStr(ih, "_IUPMOT_DISABLE_TEXT_CB", "1"); XtVaSetValues(ih->handle, XmNminimumValue, min, NULL); iupAttribSetStr(ih, "_IUPMOT_DISABLE_TEXT_CB", NULL); } } return 1; }
static int motTextSetAppendAttrib(Ihandle* ih, const char* value) { XmTextPosition pos; if (!ih->handle) /* do not store the action before map */ return 0; pos = XmTextGetLastPosition(ih->handle); /* disable callbacks */ iupAttribSetStr(ih, "_IUPMOT_DISABLE_TEXT_CB", "1"); if (ih->data->is_multiline && ih->data->append_newline) XmTextInsert(ih->handle, pos, "\n"); if (value) XmTextInsert(ih->handle, pos+1, (char*)value); iupAttribSetStr(ih, "_IUPMOT_DISABLE_TEXT_CB", NULL); return 0; }
static int motTextSetInsertAttrib(Ihandle* ih, const char* value) { if (!ih->handle) /* do not store the action before map */ return 0; if (!value) return 0; /* disable callbacks */ iupAttribSetStr(ih, "_IUPMOT_DISABLE_TEXT_CB", "1"); XmTextRemove(ih->handle); XmTextInsert(ih->handle, XmTextGetInsertionPosition(ih->handle), (char*)value); iupAttribSetStr(ih, "_IUPMOT_DISABLE_TEXT_CB", NULL); return 0; }
static void motMessageDlgHelpCallback(Widget w, XtPointer client_data, XtPointer call_data) { Ihandle *ih = (Ihandle*)client_data; Icallback cb = (Icallback)IupGetCallback(ih, "HELP_CB"); if (cb && cb(ih) == IUP_CLOSE) { if (iupStrEqualNoCase(iupAttribGetStr(ih, "BUTTONS"), "OK")) iupAttribSetStr(ih, "BUTTONRESPONSE", "1"); else iupAttribSetStr(ih, "BUTTONRESPONSE", "2"); } (void)call_data; (void)w; }
static int iScrollBoxButton_CB(Ihandle *ih, int but, int pressed, int x, int y, char* status) { if (but==IUP_BUTTON1 && pressed) { iupAttribSetInt(ih, "_IUP_START_X", x); iupAttribSetInt(ih, "_IUP_START_Y", y); iupAttribSetInt(ih, "_IUP_START_POSX", (int)IupGetFloat(ih, "POSX")); iupAttribSetInt(ih, "_IUP_START_POSY", (int)IupGetFloat(ih, "POSY")); iupAttribSetStr(ih, "_IUP_DRAG_SB", "1"); } if (but==IUP_BUTTON1 && !pressed) iupAttribSetStr(ih, "_IUP_DRAG_SB", NULL); (void)status; return IUP_DEFAULT; }
static void motFileDlgPreviewCanvasInit(Ihandle *ih, Widget w) { XSetWindowAttributes attrs; GC gc = XCreateGC(iupmot_display, XtWindow(w), 0, NULL); iupAttribSetStr(ih, "PREVIEWDC", (char*)gc); iupAttribSetStr(ih, "WID", (char*)w); iupAttribSetStr(ih, "XWINDOW", (char*)XtWindow(w)); iupAttribSetStr(ih, "XDISPLAY", (char*)iupmot_display); motFileDlgUpdatePreviewGLCanvas(ih); attrs.bit_gravity = ForgetGravity; /* For the DrawingArea widget gets Expose events when you resize it to be smaller. */ attrs.background_pixmap = None; XChangeWindowAttributes(iupmot_display, XtWindow(w), CWBitGravity|CWBackPixmap, &attrs); }
void iupmotSetMnemonicTitle(Ihandle *ih, Widget w, const char* value) { char c; char* str; if (!value) value = ""; if (!w) w = ih->handle; str = iupStrProcessMnemonic(value, &c, -1); /* remove & and return in c */ if (str != value) { KeySym keysym = iupmotKeyCharToKeySym(c); XtVaSetValues(w, XmNmnemonic, keysym, NULL); /* works only for menus, but underlines the letter */ if (ih->iclass->nativetype != IUP_TYPEMENU) { Ihandle* dialog = IupGetDialog(ih); char attrib[22] = "_IUPMOT_MNEMONIC_ \0CB"; attrib[17] = (char)toupper(c); /* used by motActivateMnemonic */ if (IupClassMatch(ih, "label")) iupAttribSetStr(dialog, attrib, (char*)iupFocusNextInteractive(ih)); else { iupAttribSetStr(dialog, attrib, (char*)ih); if (ih->handle != w) iupAttribSetStr(ih, attrib, (char*)w); } /* used by iupmotKeyPressEvent */ attrib[18] = '_'; IupSetCallback(dialog, attrib, (Icallback)motActivateMnemonic); } iupmotSetString(w, XmNlabelString, str); free(str); } else { XtVaSetValues (w, XmNmnemonic, NULL, NULL); iupmotSetString(w, XmNlabelString, str); } }
void iupListUpdateOldValue(Ihandle* ih, int pos, int removed) { if (!ih->data->has_editbox) { char* old_value = iupAttribGet(ih, "_IUPLIST_OLDVALUE"); if (old_value) { int old_pos = atoi(old_value)-1; /* was in IUP reference, starting at 1 */ if (ih->data->is_dropdown || !ih->data->is_multiple) { if (old_pos >= pos) { if (removed && old_pos == pos) { /* when the current item is removed nothing remains selected */ iupAttribSet(ih, "_IUPLIST_OLDVALUE", NULL); } else iupAttribSetInt(ih, "_IUPLIST_OLDVALUE", removed? old_pos-1: old_pos+1); } } else { /* multiple selection on a non drop-down list. */ char* value = IupGetAttribute(ih, "VALUE"); iupAttribSetStr(ih, "_IUPLIST_OLDVALUE", value); } } } }