static int edition_cb(Ihandle *self, int lin, int col, int mode, int update) { if (mode == 0) { char* value = IupGetAttribute(self, "VALUE"); #ifndef BIG_MATRIX if (value && strcmp(value, data[lin-1][col-1])!=0) #else char* cell = IupGetAttributeId2(self, "", lin, col); if (value && cell && strcmp(value, cell)!=0) #endif return IUP_IGNORE; } return IUP_DEFAULT; }
static char* get_nc(Ihandle *n) { if (type(n) == TEXT_ || (type(n) == LIST_ && iupCheck(n, "EDITBOX")==YES)) { char *nc = getBuffer(); int max; Widget w = (Widget)handle(n); if (type(n) == LIST_) w = (Widget)IupGetAttribute(n, "_IUPMOT_EDITBOX"); XtVaGetValues(w, XmNmaxLength, &max, NULL); sprintf(nc, "%d", max); return nc; } return NULL; }
static void GetAttribute(void) { char *name = luaL_check_string(2); Ihandle* ih = iuplua_checkihandle(1); char *value = IupGetAttribute(ih, name); if (!value || iupATTRIB_ISINTERNAL(name)) lua_pushnil(); else { if (iupAttribIsPointer(ih, name)) lua_pushuserdata((void*)value); else lua_pushstring(value); } }
static void new_font(void) { Ihandle* dlg = IupFontDlg(); IupSetAttribute(dlg, "PARENTDIALOG", "_MAIN_DIALOG_TEST_"); IupSetAttribute(dlg, "COLOR", "128 0 255"); // IupSetAttribute(dlg, "BGCOLOR", "173 177 194"); // Motif BGCOLOR for documentation IupSetAttribute(dlg, "VALUE", "Times, Bold 20"); IupSetAttribute(dlg, "TITLE", "IupFontDlg Test"); IupSetCallback(dlg, "HELP_CB", (Icallback)help_cb); IupPopup(dlg, IUP_CENTERPARENT, IUP_CENTERPARENT); if (IupGetInt(dlg, "STATUS")) { printf("OK\n"); printf(" VALUE(%s)\n", IupGetAttribute(dlg, "VALUE")); printf(" COLOR(%s)\n", IupGetAttribute(dlg, "COLOR")); } else printf("CANCEL\n"); IupDestroy(dlg); }
void iupdrvDialogGetDecoration(Ihandle* ih, int *border, int *caption, int *menu) { if (ih->data->menu) *menu = iupdrvMenuGetMenuBarSize(ih->data->menu); else *menu = 0; if (ih->handle) { winDialogGetWindowDecor(ih, border, caption); if (*menu) *caption -= *menu; } else { int has_titlebar = iupAttribGetBoolean(ih, "MAXBOX") || iupAttribGetBoolean(ih, "MINBOX") || iupAttribGetBoolean(ih, "MENUBOX") || IupGetAttribute(ih, "TITLE"); /* must use IupGetAttribute to check from the native implementation */ *caption = 0; if (has_titlebar) { if (iupAttribGetBoolean(ih, "TOOLBOX") && iupAttribGet(ih, "PARENTDIALOG")) *caption = GetSystemMetrics(SM_CYSMCAPTION); /* tool window */ else *caption = GetSystemMetrics(SM_CYCAPTION); /* normal window */ } *border = 0; if (iupAttribGetBoolean(ih, "RESIZE")) { /* has_border */ *border = GetSystemMetrics(SM_CXFRAME); /* Thickness of the sizing border around the perimeter of a window */ } /* that can be resized, in pixels. */ else if (has_titlebar) { /* has_border */ *border = GetSystemMetrics(SM_CXFIXEDFRAME); /* Thickness of the frame around the perimeter of a window */ } /* that has a caption but is not sizable, in pixels. */ else if (iupAttribGetBoolean(ih, "BORDER")) { /* has_border */ *border = GetSystemMetrics(SM_CXBORDER); } } }
int IupGetFile(char* file) { Ihandle *dlg = 0; int i,ret,n; char filter[4096] = "*.*"; char dir[4096]; if (!file) return -1; dlg = IupFileDlg(); n = strlen(file); /* Look for last folder separator and split filter from directory */ for (i=n-1;i>=0; i--) { if (file[i] == '\\' || file[i] == '/') { strncpy(dir, file, i+1); dir[i+1] = 0; strcpy(filter, file+i+1); filter[n-i] = 0; break; } } IupSetAttribute(dlg, "FILTER", filter); IupSetAttribute(dlg, "DIRECTORY", dir); IupSetAttribute(dlg, "ALLOWNEW", "YES"); IupSetAttribute(dlg, "NOCHANGEDIR", "YES"); IupSetAttribute(dlg, "PARENTDIALOG", IupGetGlobal("PARENTDIALOG")); IupSetAttribute(dlg, "ICON", IupGetGlobal("ICON")); IupPopup(dlg, IUP_CENTER, IUP_CENTER); ret = IupGetInt(dlg, "STATUS"); if (ret != -1) { char* value = IupGetAttribute(dlg, "VALUE"); if (value) strcpy(file, value); } IupDestroy(dlg); return ret; }
/* Verifies which scrolling bars have been defined sbv: =0 doesn't have vertical scrolling bar =1 has vertical scrolling bar sbh: =0 doesn't have horizontal scrolling bar =1 has horizontal scrolling bar */ static void iTreeGetSB(Ihandle* ih, int* sbh, int* sbv) { char* sb = IupGetAttribute(ih, "SCROLLBAR"); if(sb == NULL) sb = "YES"; *sbh = *sbv = 0; if(iupStrEqualNoCase(sb, "YES") || iupStrEqualNoCase(sb, "ON")) *sbh = *sbv = 1; else if(iupStrEqualNoCase (sb, "VERTICAL")) *sbv = 1; else if(iupStrEqualNoCase (sb, "HORIZONTAL")) *sbh = 1; }
static int iDialRedraw_CB(Ihandle* ih) { if (!ih->data->cd_canvas) return IUP_DEFAULT; /* update display */ cdCanvasFlush(ih->data->cd_canvas); if (ih->data->has_focus) { cdCanvas* cd_canvas_front = (cdCanvas*)IupGetAttribute(ih, "_CD_CANVAS"); /* front buffer canvas */ IupCdDrawFocusRect(ih, cd_canvas_front, 0, 0, ih->data->w - 1, ih->data->h - 1); } return IUP_DEFAULT; }
static int k_any(Ihandle *ih, int c) { if (iup_isprint(c)) printf("K_ANY(%d = %s \'%c\')\n", c, iupKeyCodeToName(c), (char)c); else printf("K_ANY(%d = %s)\n", c, iupKeyCodeToName(c)); printf(" CARET(%s)\n", IupGetAttribute(ih, "CARET")); if (c == K_cA) return IUP_IGNORE; // Sound a beep in Windows if (c == K_cP) { file_open(); return IUP_IGNORE; // Sound a beep in Windows } return IUP_CONTINUE; }
static void wGLCanvasUnMapMethod(Ihandle* ih) { if (ih->data->context) { if (ih->data->context == wglGetCurrentContext()) wglMakeCurrent(NULL, NULL); wglDeleteContext(ih->data->context); } if (ih->data->palette) DeleteObject((HGDIOBJ)ih->data->palette); if (ih->data->device) ReleaseDC((HWND)IupGetAttribute(ih, "HWND"), ih->data->device); /* can not use ih->handle, because it should work with GTK also */ }
static int cbAddTab(Ihandle* ih) { Ihandle* tabs = (Ihandle*)IupGetAttribute(ih, "APP_TABS"); Ihandle *vbox; vbox = IupFrame(IupVbox(IupLabel("Label XXX"), IupButton("Button XXX", "cbChildButton"), NULL)); IupSetAttribute(vbox, "TABTITLE", "XXX"); IupSetAttribute(vbox, "TITLE", "TABS XXX"); IupAppend(tabs, vbox); IupMap(vbox); IupRefresh(tabs); /* update children layout */ return IUP_DEFAULT; }
void IupGLPalette (Ihandle* self, int index, float r, float g, float b) { GLData* d = (GLData*)IupGetAttribute(self,"_IUPGL_DATA"); if (d && d->palette) { PALETTEENTRY entry; entry.peRed = (BYTE)(r*255); entry.peGreen = (BYTE)(g*255); entry.peBlue = (BYTE)(b*255); entry.peFlags = PC_NOCOLLAPSE; SetPaletteEntries(d->palette,index,1,&entry); UnrealizeObject(d->device); SelectPalette(d->device,d->palette,FALSE); RealizePalette(d->device); } }
static void ShowImage(char* file_name, Ihandle* iup_dialog) { int error; imImage* image = (imImage*)IupGetAttribute(iup_dialog, "imImage"); if (image) imImageDestroy(image); IupSetAttribute(iup_dialog, "imImage", NULL); image = imFileImageLoadBitmap(file_name, 0, &error); if (error) PrintError(error); if (!image) return; IupSetAttribute(iup_dialog, "imImage", (char*)image); IupStoreAttribute(iup_dialog, "TITLE", file_name); cbCanvasRepaint(iup_dialog); /* we can do this because canvas inherit attributes from the dialog */ }
int app_open_cb(Ihandle* self) { imFile* ifile; /* file input */ int ret, error; unsigned char* gl_data = (unsigned char*)IupGetAttribute(self, "APP_GL_DATA"); char filename[1024] = ".\\*.*"; /* get a file name */ ret = IupGetFile(filename); if (ret == -1) return IUP_DEFAULT; ifile = imFileOpen(filename, &error); if (!ifile) { IupMessage("Error", "Error reading image file."); return IUP_DEFAULT; } { int width = 0, height = 0, file_color_mode, color_space; Ihandle* dialog = IupGetDialog(self); imFileReadImageInfo(ifile, 0, &width, &height, &file_color_mode, NULL); /* alocates the buffers */ if (gl_data) free(gl_data); gl_data = malloc(width*height*3); IupSetAttribute(dialog, "APP_GL_DATA", gl_data); IupSetfAttribute(dialog, "APP_GL_WIDTH", "%d", width); IupSetfAttribute(dialog, "APP_GL_HEIGHT", "%d", height); imFileReadImageData(ifile, gl_data, 1, IM_PACKED); color_space = imColorModeSpace(file_color_mode); if (color_space == IM_MAP || color_space == IM_GRAY || color_space == IM_BINARY) { long palette[256]; int palette_count; imFileGetPalette(ifile, palette, &palette_count); ConvertMapToGLData(gl_data, width*height, 3, palette, palette_count); } } imFileClose(ifile); return IUP_DEFAULT; }
static void motDialogSetWindowManagerStyle(Ihandle* ih) { MwmHints hints; static Atom xwmhint = 0; if (!xwmhint) xwmhint = XmInternAtom(iupmot_display, "_MOTIF_WM_HINTS", False); hints.flags = (MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS); hints.functions = 0; hints.decorations = 0; hints.input_mode = 0; hints.status = 0; if (IupGetAttribute(ih, "TITLE")) { /* must use IupGetAttribute to check from the native implementation */ hints.functions |= MWM_FUNC_MOVE; hints.decorations |= MWM_DECOR_TITLE; } if (iupAttribGetInt(ih, "MENUBOX")) { hints.functions |= MWM_FUNC_CLOSE; hints.decorations |= MWM_DECOR_MENU; } if (iupAttribGetInt(ih, "MINBOX")) { hints.functions |= MWM_FUNC_MINIMIZE; hints.decorations |= MWM_DECOR_MINIMIZE; } if (iupAttribGetInt(ih, "MAXBOX")) { hints.functions |= MWM_FUNC_MAXIMIZE; hints.decorations |= MWM_DECOR_MAXIMIZE; } if (iupAttribGetInt(ih, "RESIZE")) { hints.functions |= MWM_FUNC_RESIZE; hints.decorations |= MWM_DECOR_RESIZEH; } if (iupAttribGetInt(ih, "BORDER")) hints.decorations |= MWM_DECOR_BORDER; XChangeProperty(iupmot_display, XtWindow(ih->handle), xwmhint, xwmhint, 32, PropModeReplace, (const unsigned char *) &hints, PROP_MOTIF_WM_HINTS_ELEMENTS); }
int IupGetFile( char* file ) { Ihandle *gf = 0; int i,ret,n; char *value; char filter[4096] = "*.*"; char dir[4096]; if (!file) return -3; gf = IupFileDlg(); if (!gf) return -2; n = strlen(file); /* Look for last folder separator and split filter from directory */ for(i=n-1;i>=0; i--) { if (file[i] == '\\' || file[i] == '/') { strncpy(dir, file, i+1); dir[i+1] = 0; strcpy(filter, file+i+1); filter[n-i] = 0; break; } } IupSetAttribute(gf, IUP_FILTER, filter); IupSetAttribute(gf, IUP_DIRECTORY, dir); IupSetAttribute(gf, IUP_ALLOWNEW, IUP_YES ); IupSetAttribute(gf, IUP_NOCHANGEDIR, IUP_YES); IupSetAttribute(gf, IUP_PARENTDIALOG, IupGetGlobal(IUP_PARENTDIALOG)); IupSetAttribute(gf, IUP_ICON, IupGetGlobal(IUP_ICON)); IupPopup( gf, IUP_CENTER, IUP_CENTER ); value = IupGetAttribute( gf, IUP_VALUE ); if (value) strcpy( file, value ); ret = IupGetInt( gf, IUP_STATUS ); IupDestroy(gf); return ret; }
int iupdrvBaseSetTipVisibleAttrib(Ihandle* ih, const char* value) { GtkWidget* widget = (GtkWidget*)iupAttribGet(ih, "_IUP_EXTRAPARENT"); if (!widget) widget = ih->handle; (void)value; /* must use IupGetAttribute to use inheritance */ if (!IupGetAttribute(ih, "TIP")) return 0; #if GTK_CHECK_VERSION(2, 12, 0) gtk_widget_trigger_tooltip_query(widget); #endif return 0; }
IdrawCanvas* iupdrvDrawCreateCanvas(Ihandle* ih) { IdrawCanvas* dc = calloc(1, sizeof(IdrawCanvas)); dc->ih = ih; dc->wnd = (GdkWindow*)IupGetAttribute(ih, "DRAWABLE"); dc->gc = gdk_gc_new(dc->wnd); gdk_drawable_get_size(dc->wnd, &dc->w, &dc->h); dc->pixmap = gdk_pixmap_new(dc->wnd, dc->w, dc->h, gdk_drawable_get_depth(dc->wnd)); dc->pixmap_gc = gdk_gc_new(dc->pixmap); iupAttribSet(ih, "DRAWDRIVER", "GDK"); return dc; }
static void print_value(Ihandle *ih, double a) { char *type = IupGetAttribute(ih, "TYPE"); switch(type[0]) { case 'V': IupSetfAttribute(lbl_v, "TITLE", "VALUE=%.2f", a); break; case 'H': IupSetfAttribute(lbl_h, "TITLE", "VALUE=%.2f", a); break; } IupSetfAttribute(ih, "TIP", "%.2f", a); IupSetfAttribute(ih, "TIPVISIBLE", "Yes"); }
static int cbTabRightButton(Ihandle* ih, int pos) { Ihandle* menu = IupMenu(IupItem("Add Tab", "cbAddTab"), IupItem("Insert Tab", "cbInsertTab"), IupItem("Remove Current Tab", "cbRemoveTab"), IupItem("Remove This", "cbRemoveThisTab"), IupItem("Hide This", "cbHideThisTab"), NULL); IupSetAttribute(menu, "APP_TABS", IupGetAttribute(ih, "APP_TABS")); IupSetInt(menu, "APP_THISTAB", pos); IupPopup(menu, IUP_MOUSEPOS, IUP_MOUSEPOS); IupDestroy(menu); return IUP_DEFAULT; }
void iFlatButtonDrawText(Ihandle* ih, IdrawCanvas* dc, int x, int y, const char* str, const char* color, const char* bgcolor, int active) { unsigned char r = 0, g = 0, b = 0; if (!color || !str || str[0] == 0) return; iupStrToRGB(color, &r, &g, &b); if (!active) { unsigned char bg_r = 0, bg_g = 0, bg_b = 0; iupStrToRGB(bgcolor, &bg_r, &bg_g, &bg_b); iupImageColorMakeInactive(&r, &g, &b, bg_r, bg_g, bg_b); } iupDrawText(dc, str, (int)strlen(str), x, y, r, g, b, IupGetAttribute(ih, "FONT")); }
int iupdrvBaseSetTipVisibleAttrib(Ihandle* ih, const char* value) { HWND tips_hwnd = (HWND)iupAttribGet(ih, "_IUPWIN_TIPSWIN"); if (!tips_hwnd) return 0; /* must use IupGetAttribute to use inheritance */ if (!IupGetAttribute(ih, "TIP")) return 0; if (iupStrBoolean(value)) SendMessage(tips_hwnd, TTM_POPUP, 0, 0); /* XP Only */ else SendMessage(tips_hwnd, TTM_POP, 0, 0); return 0; }
static int uiStartCb(Ihandle *ih) { char buf[MSG_BUFSIZE]; UNREFERENCED_PARAMETER(ih); if (divertStart(IupGetAttribute(filterText, "VALUE"), buf) == 0) { showStatus(buf); return IUP_DEFAULT; } // successfully started showStatus("Started filtering. Enable functionalities to take effect."); IupSetAttribute(filterText, "ACTIVE", "NO"); IupSetAttribute(filterButton, "TITLE", "Stop"); IupSetCallback(filterButton, "ACTION", uiStopCb); IupSetAttribute(timer, "RUN", "YES"); return IUP_DEFAULT; }
static int wGLCanvasMapMethod(Ihandle* ih) { IGlControlData* gldata = (IGlControlData*)iupAttribGet(ih, "_IUP_GLCONTROLDATA"); /* get a device context */ gldata->window = (HWND)iupAttribGet(ih, "HWND"); /* check first in the hash table, can be defined by the IupFileDlg */ if (!gldata->window) gldata->window = (HWND)IupGetAttribute(ih, "HWND"); /* works for Win32 and GTK, only after mapping the IupCanvas */ if (!gldata->window) return IUP_NOERROR; { LONG style = GetClassLong(gldata->window, GCL_STYLE); gldata->is_owned_dc = (int) ((style & CS_OWNDC) || (style & CS_CLASSDC)); } return wGLCreateContext(ih, gldata); }
/* Callback called when the tree is scrolled. */ static int iTreeScrollCB(Ihandle* ih) { if (ih->data->cddbuffer) { cdCanvasActivate(ih->data->cddbuffer); iupTreeEditCheckHidden(ih); cdCanvasNativeFont(ih->data->cddbuffer, IupGetAttribute(ih, "FONT")); iupTreeDrawTree(ih); cdCanvasFlush(ih->data->cddbuffer); } if(ih && ih->data->selected && ih->data->selected->visible == NO) iupTreeGSSetValue(ih, "PREVIOUS", 0); return IUP_DEFAULT; }
static int cbUnHideAllTabs(Ihandle* ih) { Ihandle* tabs = (Ihandle*)IupGetAttribute(ih, "APP_TABS"); int i, count = IupGetInt(tabs, "COUNT"); for (i = 0; i < count; i++) { if (!IupGetIntId(tabs, "TABVISIBLE", i)) { IupSetAttributeId(tabs, "TABVISIBLE", i, "Yes"); printf("tab %d = was hidden\n", i); } else printf("tab %d = is visible\n", i); } return IUP_DEFAULT; }
static void drawTest(Ihandle* ih) { RECT rect; HDC hDC = (HDC)IupGetAttribute(ih, "PREVIEWDC"); int w = IupGetInt(ih, "PREVIEWWIDTH"); int h = IupGetInt(ih, "PREVIEWHEIGHT"); SetRect(&rect, 0, 0, w, h); FillRect(hDC, &rect, GetStockObject(WHITE_BRUSH)); SelectObject(hDC, GetStockObject(DC_PEN)); SetDCPenColor(hDC, RGB(255, 0, 0)); MoveToEx(hDC, 0, 0, NULL); LineTo(hDC, w-1, h-1); MoveToEx(hDC, 0, h-1, NULL); LineTo(hDC, w-1, 0); }
void open_file(Ihandle* ih, const char* filename) { char* str = read_file(filename); if (str) { Ihandle* dlg = IupGetDialog(ih); Ihandle* multitext = IupGetDialogChild(dlg, "MULTITEXT"); Ihandle* config = (Ihandle*)IupGetAttribute(multitext, "CONFIG"); IupSetfAttribute(dlg, "TITLE", "%s - Simple Notepad", str_filetitle(filename)); IupSetStrAttribute(multitext, "FILENAME", filename); IupSetAttribute(multitext, "DIRTY", "NO"); IupSetStrAttribute(multitext, "VALUE", str); IupConfigRecentUpdate(config, filename); free(str); } }
int app_repaint_cb(Ihandle* self) { unsigned char* gl_data = (unsigned char*)IupGetAttribute(self, "APP_GL_DATA"); int width = IupGetInt(self, "APP_GL_WIDTH"); int height = IupGetInt(self, "APP_GL_HEIGHT"); IupGLMakeCurrent(self); /* activates this GL Canvas as the current drawing area. */ glClear(GL_COLOR_BUFFER_BIT); /* clears the back buffer */ if (gl_data) { /* Draws the captured image at (0,0) */ glRasterPos2f(0.f, 0.f); glDrawPixels(width, height, GL_RGB, GL_UNSIGNED_BYTE, gl_data); } IupGLSwapBuffers(self); /* swap data from back buffer to front buffer */ return IUP_DEFAULT; }
static int cbEnableAllTabs(Ihandle* ih) { Ihandle* tabs = (Ihandle*)IupGetAttribute(ih, "APP_TABS"); int i, count = IupGetInt(tabs, "COUNT"); for (i = 0; i < count; i++) { if (!IupGetIntId(tabs, "TABACTIVE", i)) { IupSetAttributeId(tabs, "TABACTIVE", i, "Yes"); printf("tab %d = was inactive\n", i); } else printf("tab %d = is active\n", i); } return IUP_DEFAULT; }