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; }
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 void iMenuAdjustPos(int *x, int *y) { int cursor_x = 0, cursor_y = 0; int screen_width = 0, screen_height = 0; if (*x == IUP_CENTER || *y == IUP_CENTER || *x == IUP_RIGHT || *y == IUP_RIGHT || *x == IUP_CENTERPARENT || *y == IUP_CENTERPARENT) iupdrvGetScreenSize(&screen_width, &screen_height); if (*x == IUP_MOUSEPOS || *y == IUP_MOUSEPOS) iupdrvGetCursorPos(&cursor_x, &cursor_y); switch (*x) { case IUP_CENTER: *x = screen_width/2; break; case IUP_LEFT: *x = 0; break; case IUP_RIGHT: *x = screen_width; break; case IUP_MOUSEPOS: *x = cursor_x; break; } switch (*y) { case IUP_CENTER: *y = screen_height/2; break; case IUP_LEFT: *y = 0; break; case IUP_RIGHT: *y = screen_height; break; case IUP_MOUSEPOS: *y = cursor_y; break; } iupdrvAddScreenOffset(x, y, 1); }
static void iDialogAdjustPos(Ihandle *ih, int *x, int *y) { int cursor_x = 0, cursor_y = 0; int screen_width = 0, screen_height = 0; int current_x = 0, current_y = 0; int parent_x = 0, parent_y = 0; /* the dialog is already mapped here */ if (*x == IUP_CURRENT || *y == IUP_CURRENT) { /* if first time, there is no current position */ if (!ih->data->first_show) { int center = IUP_CENTER; InativeHandle* parent = iupDialogGetNativeParent(ih); if (parent) center = IUP_CENTERPARENT; if (*x == IUP_CURRENT) *x = center; if (*y == IUP_CURRENT) *y = center; } else iupdrvDialogGetPosition(ih, NULL, ¤t_x, ¤t_y); } if (*x == IUP_CENTER || *y == IUP_CENTER || *x == IUP_RIGHT || *y == IUP_RIGHT || *x == IUP_CENTERPARENT || *y == IUP_CENTERPARENT) iupdrvGetScreenSize(&screen_width, &screen_height); if (*x == IUP_CENTERPARENT || *y == IUP_CENTERPARENT) { InativeHandle* parent = iupDialogGetNativeParent(ih); if (parent) { Ihandle* ih_parent = IupGetAttributeHandle(ih, "PARENTDIALOG"); iupdrvDialogGetPosition(ih_parent, parent, &parent_x, &parent_y); if (*x == IUP_CENTERPARENT && *y == IUP_CENTERPARENT) iupdrvDialogGetSize(ih_parent, parent, &screen_width, &screen_height); else if (*x == IUP_CENTERPARENT) iupdrvDialogGetSize(ih_parent, parent, &screen_width, NULL); else if (*y == IUP_CENTERPARENT) iupdrvDialogGetSize(ih_parent, parent, NULL, &screen_height); } } if (*x == IUP_MOUSEPOS || *y == IUP_MOUSEPOS) iupdrvGetCursorPos(&cursor_x, &cursor_y); if (iupAttribGetBoolean(ih, "MDICHILD")) { Ihandle* client = (Ihandle*)iupAttribGet(ih, "MDICLIENT_HANDLE"); if (client) { /* position is relative to mdi client */ parent_x = 0; parent_y = 0; /* screen size is now the size of the mdi client */ screen_width = client->currentwidth; screen_height = client->currentheight; iupdrvScreenToClient(client, ¤t_x, ¤t_y); iupdrvScreenToClient(client, &cursor_x, &cursor_y); } } switch (*x) { case IUP_CENTERPARENT: *x = (screen_width - ih->currentwidth)/2 + parent_x; break; case IUP_CENTER: *x = (screen_width - ih->currentwidth)/2; break; case IUP_LEFT: *x = 0; break; case IUP_RIGHT: *x = screen_width - ih->currentwidth; break; case IUP_MOUSEPOS: *x = cursor_x; break; case IUP_CURRENT: *x = current_x; break; } switch (*y) { case IUP_CENTERPARENT: *y = (screen_height - ih->currentheight)/2 + parent_y; break; case IUP_CENTER: *y = (screen_height - ih->currentheight)/2; break; case IUP_LEFT: *y = 0; break; case IUP_RIGHT: *y = screen_height - ih->currentheight; break; case IUP_MOUSEPOS: *y = cursor_y; break; case IUP_CURRENT: *y = current_y; break; } iupdrvAddScreenOffset(x, y, 1); }
char* IupGetGlobal(const char *name) { char* value; iupASSERT(name!=NULL); if (!name) return NULL; if (iupStrEqual(name, "DEFAULTFONTSIZE")) return iupGetDefaultFontSizeGlobalAttrib(); if (iupStrEqual(name, "DEFAULTFONTSTYLE")) return iupGetDefaultFontStyleGlobalAttrib(); if (iupStrEqual(name, "DEFAULTFONTFACE")) return iupGetDefaultFontFaceGlobalAttrib(); if (iupStrEqual(name, "CURSORPOS")) { int x, y; iupdrvGetCursorPos(&x, &y); return iupStrReturnIntInt(x, y, 'x'); } if (iupStrEqual(name, "SHIFTKEY")) { char key[5]; iupdrvGetKeyState(key); return iupStrReturnChecked(key[0] == 'S'); } if (iupStrEqual(name, "CONTROLKEY")) { char key[5]; iupdrvGetKeyState(key); return iupStrReturnChecked(key[1] == 'C'); } if (iupStrEqual(name, "MODKEYSTATE")) { char *str = iupStrGetMemory(5); iupdrvGetKeyState(str); return str; } if (iupStrEqual(name, "SCREENSIZE")) { int w, h; iupdrvGetScreenSize(&w, &h); return iupStrReturnIntInt(w, h, 'x'); } if (iupStrEqual(name, "FULLSIZE")) { int w, h; iupdrvGetFullSize(&w, &h); return iupStrReturnIntInt(w, h, 'x'); } if (iupStrEqual(name, "SCREENDEPTH")) { int bpp = iupdrvGetScreenDepth(); return iupStrReturnInt(bpp); } if (iupStrEqual(name, "SCREENDPI")) { double dpi = iupdrvGetScreenDpi(); return iupStrReturnDouble(dpi); } if (iupStrEqual(name, "SYSTEMLOCALE")) return iupdrvLocaleInfo(); if (iupStrEqual(name, "SCROLLBARSIZE")) return iupStrReturnInt(iupdrvGetScrollbarSize()); value = iupdrvGetGlobal(name); if (!value) value = (char*)iupTableGet(iglobal_table, name); return value; }
void iupDialogAdjustPos(Ihandle *ih, int *x, int *y) { int cursor_x = 0, cursor_y = 0; int screen_width = 0, screen_height = 0; int current_x = 0, current_y = 0; int parent_x = 0, parent_y = 0; if (*x == IUP_CURRENT || *y == IUP_CURRENT) iupdrvDialogGetPosition(ih->handle, ¤t_x, ¤t_y); if (*x == IUP_CENTER || *y == IUP_CENTER || *x == IUP_RIGHT || *y == IUP_RIGHT || *x == IUP_CENTERPARENT || *y == IUP_CENTERPARENT) iupdrvGetScreenSize(&screen_width, &screen_height); if (*x == IUP_CENTERPARENT || *y == IUP_CENTERPARENT) { InativeHandle* parent = iupDialogGetNativeParent(ih); if (parent) { iupdrvDialogGetPosition(parent, &parent_x, &parent_y); if (*x == IUP_CENTERPARENT && *y == IUP_CENTERPARENT) iupdrvDialogGetSize(parent, &screen_width, &screen_height); else if (*x == IUP_CENTERPARENT) iupdrvDialogGetSize(parent, &screen_width, NULL); else if (*y == IUP_CENTERPARENT) iupdrvDialogGetSize(parent, NULL, &screen_height); } } if (*x == IUP_MOUSEPOS || *y == IUP_MOUSEPOS) iupdrvGetCursorPos(&cursor_x, &cursor_y); if (IupGetInt(ih, "MDICHILD")) { Ihandle* client = (Ihandle*)iupAttribGetStr(ih, "MDICLIENT_HANDLE"); if (client) { /* position is relative to mdi client */ parent_x = 0; parent_y = 0; /* screen size is now the size of the mdi client */ screen_width = client->currentwidth; screen_height = client->currentheight; iupdrvScreenToClient(client, ¤t_x, ¤t_y); iupdrvScreenToClient(client, &cursor_x, &cursor_y); } } switch (*x) { case IUP_CENTERPARENT: *x = (screen_width - ih->currentwidth)/2 + parent_x; break; case IUP_CENTER: *x = (screen_width - ih->currentwidth)/2; break; case IUP_LEFT: *x = 0; break; case IUP_RIGHT: *x = screen_width - ih->currentwidth; break; case IUP_MOUSEPOS: *x = cursor_x; break; case IUP_CURRENT: *x = current_x; break; } switch (*y) { case IUP_CENTERPARENT: *y = (screen_height - ih->currentheight)/2 + parent_y; break; case IUP_CENTER: *y = (screen_height - ih->currentheight)/2; break; case IUP_LEFT: *y = 0; break; case IUP_RIGHT: *y = screen_height - ih->currentheight; break; case IUP_MOUSEPOS: *y = cursor_y; break; case IUP_CURRENT: *y = current_y; break; } }