int iupDialogShowXY(Ihandle* ih, int x, int y) { int was_visible; /* Calling IupShow for a visible dialog shown with IupPopup does nothing. */ if (iupAttribGetBoolean(ih, "MODAL")) /* already a popup */ return IUP_NOERROR; if (ih->data->popup_level != 0) { /* was disabled by a Popup, re-enable it */ iupdrvSetActive(ih, 1); ih->data->popup_level = 0; /* Now it is at the current popup level */ } /* save visible state before iupdrvDialogSetPlacement */ /* because it can also show the window when changing placement. */ was_visible = iupdrvDialogIsVisible(ih); /* Update the position and placement */ if (!iupdrvDialogSetPlacement(ih)) { iDialogAdjustPos(ih, &x, &y); iupdrvDialogSetPosition(ih, x, y); } if (was_visible) /* already visible */ { /* only re-show to raise the window */ iupdrvDialogSetVisible(ih, 1); /* flush, then process show_cb and startfocus */ iDialogAfterShow(ih); return IUP_NOERROR; } ih->data->first_show = 1; /* actually show the window */ /* test if placement turn the dialog visible */ if (!iupdrvDialogIsVisible(ih)) iupdrvDialogSetVisible(ih, 1); /* increment visible count */ iupDlgListVisibleInc(); /* flush, then process show_cb and startfocus */ iDialogAfterShow(ih); return IUP_NOERROR; }
void iupdrvDialogGetDecoration(Ihandle* ih, int *border, int *caption, int *menu) { static int native_border = 0; static int native_caption = 0; int has_caption = iupAttribGetInt(ih, "MAXBOX") || iupAttribGetInt(ih, "MINBOX") || iupAttribGetInt(ih, "MENUBOX") || IupGetAttribute(ih, "TITLE"); /* must use IupGetAttribute to check from the native implementation */ int has_border = has_caption || iupAttribGetInt(ih, "RESIZE") || iupAttribGetInt(ih, "BORDER"); *menu = motDialogGetMenuSize(ih); if (ih->handle && iupdrvDialogIsVisible(ih)) { int win_border, win_caption; if (iupdrvGetWindowDecor((void*)XtWindow(ih->handle), &win_border, &win_caption)) { *border = 0; if (has_border) *border = win_border; *caption = 0; if (has_caption) *caption = win_caption; if (!native_border && *border) native_border = win_border; if (!native_caption && *caption) native_caption = win_caption; return; } } /* I could not set the size of the window including the decorations when the dialog is hidden */ /* So we have to estimate the size of borders and caption when the dialog is hidden */ *border = 0; if (has_border) { if (native_border) *border = native_border; else *border = 5; } *caption = 0; if (has_caption) { if (native_caption) *caption = native_caption; else *caption = 20; } }
void iupDialogHide(Ihandle* ih) { /* hidden at the system and marked hidden in IUP */ if (!iupdrvDialogIsVisible(ih) && ih->data->show_state == IUP_HIDE) return; /* marked hidden in IUP */ ih->data->show_state = IUP_HIDE; /* if called IupHide for a Popup window */ if (iupAttribGetBoolean(ih, "MODAL")) { iDialogUnSetModal(ih); IupExitLoop(); } ih->data->ignore_resize = 1; /* actually hide the window */ iupdrvDialogSetVisible(ih, 0); ih->data->ignore_resize = 0; /* decrement visible count */ iupDlgListVisibleDec(); /* process flush and process show_cb */ iDialogAfterHide(ih); iDialogListCheckLastVisible(); }
void iupDialogHide(Ihandle* ih) { /* hidden at the system and marked hidden in IUP */ if (!iupdrvDialogIsVisible(ih) && ih->data->show_state == IUP_HIDE) return; /* marked hidden in IUP */ ih->data->show_state = IUP_HIDE; /* if called IupHide for a Popup window */ if (iupAttribGetInt(ih, "MODAL")) { iDialogUnSetModal(ih); IupExitLoop(); } /* actually hide the window */ iupdrvDialogSetVisible(ih, 0); /* decrement visible count */ iupDlgListVisibleDec(); if (iupDlgListVisibleCount() <= 0) { /* if this is the last window visible, exit message loop except when LOCKLOOP==YES */ if (!iupStrBoolean(IupGetGlobal("LOCKLOOP"))) IupExitLoop(); } iDialogCallShowCb(ih); }
static void motDialogChangeWMState(Ihandle* ih, Atom state1, Atom state2, int operation) { static Atom wmstate = 0; if (!wmstate) wmstate = XmInternAtom(iupmot_display, "_NET_WM_STATE", False); if (iupdrvDialogIsVisible(ih)) { XEvent evt; evt.type = ClientMessage; evt.xclient.type = ClientMessage; evt.xclient.serial = 0; evt.xclient.send_event = True; evt.xclient.display = iupmot_display; evt.xclient.window = XtWindow(ih->handle); evt.xclient.message_type = wmstate; evt.xclient.format = 32; evt.xclient.data.l[0] = operation; evt.xclient.data.l[1] = state1; evt.xclient.data.l[2] = state2; evt.xclient.data.l[3] = 0; evt.xclient.data.l[4] = 0; XSendEvent(iupmot_display, RootWindow(iupmot_display, iupmot_screen), False, SubstructureRedirectMask | SubstructureNotifyMask, &evt); } else { if (operation) { if (state1 && state2) { Atom atoms[2]; atoms[0] = state1; atoms[0] = state2; XChangeProperty(iupmot_display, XtWindow(ih->handle), wmstate, XA_ATOM, 32, PropModeReplace, (const unsigned char *)&atoms, 2); } else { XChangeProperty(iupmot_display, XtWindow(ih->handle), wmstate, XA_ATOM, 32, PropModeReplace, (const unsigned char *)&state1, 1); } } else { /* TODO: This is not working. The property is not correctly removed. */ /* XDeleteProperty(iupmot_display, XtWindow(ih->handle), wmstate); */ /* Maybe the right way to do it is to retrieve all the atoms */ /* and change again with all atoms except the one to remove */ } } }
int iupDialogShowXY(Ihandle* ih, int x, int y) { int was_visible; if (iupAttribGetInt(ih, "MODAL")) /* already a popup */ return IUP_NOERROR; if (ih->data->popup_level != 0) { /* was disabled by a Popup, re-enable it */ iupdrvSetActive(ih, 1); ih->data->popup_level = 0; /* Now it is at the current popup level */ } /* save visible state before iupdrvDialogSetPlacement */ /* because it can also show the window when changing placement. */ was_visible = iupdrvDialogIsVisible(ih); /* Update the position and placement */ if (!iupdrvDialogSetPlacement(ih, x, y)) { iupDialogAdjustPos(ih, &x, &y); iupdrvDialogSetPosition(ih, x, y); } if (was_visible) /* already visible */ { /* only re-show to raise the window */ iupdrvDialogSetVisible(ih, 1); iDialogCallShowCb(ih); return IUP_NOERROR; } /* actually show the window */ /* test if placement turn the dialog visible */ if (!iupdrvDialogIsVisible(ih)) iupdrvDialogSetVisible(ih, 1); /* increment visible count */ iupDlgListVisibleInc(); iDialogCallShowCb(ih); return IUP_NOERROR; }
void iupdrvDialogSetVisible(Ihandle* ih, int visible) { if (visible) { XtMapWidget(ih->handle); XRaiseWindow(iupmot_display, XtWindow(ih->handle)); while (!iupdrvDialogIsVisible(ih)); /* waits until window get mapped */ } else { /* if iupdrvIsVisible reports hidden, then it should be minimized */ if (!iupdrvIsVisible(ih)) /* can NOT hide a minimized window, so map it first. */ { XtMapWidget(ih->handle); XRaiseWindow(iupmot_display, XtWindow(ih->handle)); while (!iupdrvDialogIsVisible(ih)); /* waits until window get mapped */ } XtUnmapWidget(ih->handle); while (iupdrvDialogIsVisible(ih)); /* waits until window gets unmapped */ } }
int iupDialogPopup(Ihandle* ih, int x, int y) { int ret = iupClassObjectDlgPopup(ih, x, y); if (ret != IUP_INVALID) /* IUP_INVALID means it is not implemented */ return ret; ih->data->show_state = IUP_SHOW; /* Update only the position */ iupDialogAdjustPos(ih, &x, &y); iupdrvDialogSetPosition(ih, x, y); if (iupdrvDialogIsVisible(ih)) /* already visible */ { /* only re-show to raise the window */ iupdrvDialogSetVisible(ih, 1); iDialogCallShowCb(ih); return IUP_NOERROR; } if (iupAttribGetInt(ih, "MODAL")) /* already a popup */ return IUP_NOERROR; iDialogSetModal(ih); /* actually show the window */ iupdrvDialogSetVisible(ih, 1); /* increment visible count */ iupDlgListVisibleInc(); iDialogCallShowCb(ih); /* interrupt processing here */ IupMainLoop(); /* if window is still valid (IupDestroy not called), hide the dialog if still visible. */ if (iupObjectCheck(ih)) { iDialogUnSetModal(ih); IupHide(ih); } return IUP_NOERROR; }
static void iDialogSetModal(Ihandle* ih_popup) { Ihandle *ih; iupAttribSetStr(ih_popup, "MODAL", "YES"); /* disable all visible dialogs, and mark popup level */ for (ih = iupDlgListFirst(); ih; ih = iupDlgListNext()) { if (ih != ih_popup && ih->handle && iupdrvDialogIsVisible(ih) && ih->data->popup_level == 0) { iupdrvSetActive(ih, 0); ih->data->popup_level = dlg_popup_level; } } dlg_popup_level++; }
void iupDialogEnterModal(Ihandle* ih_popup, int popup_level) { Ihandle *ih; assert(popup_level == dlg_popup_level); /* disable all visible dialogs, and mark popup level */ for (ih = iupDlgListFirst(); ih; ih = iupDlgListNext()) { if (ih != ih_popup && ih->handle && iupdrvDialogIsVisible(ih) && ih->data->popup_level == 0) { iupdrvSetActive(ih, 0); ih->data->popup_level = dlg_popup_level; } } dlg_popup_level++; }
static int motDialogSetFullScreenAttrib(Ihandle* ih, const char* value) { if (iupStrBoolean(value)) { if (!iupAttribGet(ih, "_IUPMOT_FS_STYLE")) { int visible = iupdrvDialogIsVisible(ih); if (visible) iupAttribSetStr(ih, "_IUPMOT_FS_STYLE", "VISIBLE"); else iupAttribSetStr(ih, "_IUPMOT_FS_STYLE", "HIDDEN"); /* save the previous decoration attributes */ /* during fullscreen these attributes can be consulted by the application */ iupAttribStoreStr(ih, "_IUPMOT_FS_MAXBOX", iupAttribGet(ih, "MAXBOX")); iupAttribStoreStr(ih, "_IUPMOT_FS_MINBOX", iupAttribGet(ih, "MINBOX")); iupAttribStoreStr(ih, "_IUPMOT_FS_MENUBOX",iupAttribGet(ih, "MENUBOX")); iupAttribStoreStr(ih, "_IUPMOT_FS_RESIZE", iupAttribGet(ih, "RESIZE")); iupAttribStoreStr(ih, "_IUPMOT_FS_BORDER", iupAttribGet(ih, "BORDER")); iupAttribStoreStr(ih, "_IUPMOT_FS_TITLE", IupGetAttribute(ih, "TITLE")); /* must use IupGetAttribute to check from the native implementation */ /* remove the decorations attributes */ iupAttribSetStr(ih, "MAXBOX", "NO"); iupAttribSetStr(ih, "MINBOX", "NO"); iupAttribSetStr(ih, "MENUBOX", "NO"); IupSetAttribute(ih, "TITLE", NULL); iupAttribSetStr(ih, "TITLE", NULL); /* remove from the hash table if we are during IupMap */ iupAttribSetStr(ih, "RESIZE", "NO"); iupAttribSetStr(ih, "BORDER", "NO"); /* use WM fullscreen support */ if (!motDialogSetFullScreen(ih, 1)) { /* or configure fullscreen manually */ int decor; int width, height; /* hide before changing decorations */ if (visible) { iupAttribSetStr(ih, "_IUPMOT_SHOW_STATE", NULL); /* To avoid a SHOW_CB notification */ XtUnmapWidget(ih->handle); } /* save the previous position and size */ iupAttribStoreStr(ih, "_IUPMOT_FS_X", IupGetAttribute(ih, "X")); /* must use IupGetAttribute to check from the native implementation */ iupAttribStoreStr(ih, "_IUPMOT_FS_Y", IupGetAttribute(ih, "Y")); iupAttribStoreStr(ih, "_IUPMOT_FS_SIZE", IupGetAttribute(ih, "RASTERSIZE")); /* save the previous decoration */ XtVaGetValues(ih->handle, XmNmwmDecorations, &decor, NULL); iupAttribSetStr(ih, "_IUPMOT_FS_DECOR", (char*)decor); /* remove the decorations */ XtVaSetValues(ih->handle, XmNmwmDecorations, (XtArgVal)0, NULL); motDialogSetWindowManagerStyle(ih); /* get full screen size */ iupdrvGetFullSize(&width, &height); /* set position and size */ XtVaSetValues(ih->handle, XmNwidth, (XtArgVal)width, XmNheight, (XtArgVal)height, XmNx, (XtArgVal)0, XmNy, (XtArgVal)0, NULL); /* layout will be updated in motDialogConfigureNotify */ if (visible) XtMapWidget(ih->handle); } } } else { char* fs_style = iupAttribGet(ih, "_IUPMOT_FS_STYLE"); if (fs_style) { /* can only switch back from full screen if window was visible */ /* when fullscreen was set */ if (iupStrEqualNoCase(fs_style, "VISIBLE")) { iupAttribSetStr(ih, "_IUPMOT_FS_STYLE", NULL); /* restore the decorations attributes */ iupAttribStoreStr(ih, "MAXBOX", iupAttribGet(ih, "_IUPMOT_FS_MAXBOX")); iupAttribStoreStr(ih, "MINBOX", iupAttribGet(ih, "_IUPMOT_FS_MINBOX")); iupAttribStoreStr(ih, "MENUBOX",iupAttribGet(ih, "_IUPMOT_FS_MENUBOX")); IupSetAttribute(ih, "TITLE", iupAttribGet(ih, "_IUPMOT_FS_TITLE")); /* TITLE is not stored in the HashTable */ iupAttribStoreStr(ih, "RESIZE", iupAttribGet(ih, "_IUPMOT_FS_RESIZE")); iupAttribStoreStr(ih, "BORDER", iupAttribGet(ih, "_IUPMOT_FS_BORDER")); if (!motDialogSetFullScreen(ih, 0)) { int border, caption, menu, x, y; int visible = iupdrvDialogIsVisible(ih); if (visible) XtUnmapWidget(ih->handle); /* restore the decorations */ XtVaSetValues(ih->handle, XmNmwmDecorations, (XtArgVal)(int)iupAttribGet(ih, "_IUPMOT_FS_DECOR"), NULL); motDialogSetWindowManagerStyle(ih); /* the dialog decoration will not be considered yet in the next XtVaSetValues */ /* so compensate the decoration when restoring the position and size */ iupdrvDialogGetDecoration(ih, &border, &caption, &menu); x = iupAttribGetInt(ih, "_IUPMOT_FS_X") - (border); y = iupAttribGetInt(ih, "_IUPMOT_FS_Y") - (border+caption+menu); /* restore position and size */ XtVaSetValues(ih->handle, XmNx, (XtArgVal)x, XmNy, (XtArgVal)y, XmNwidth, (XtArgVal)(IupGetInt(ih, "_IUPMOT_FS_SIZE") - (2*border)), XmNheight, (XtArgVal)(IupGetInt2(ih, "_IUPMOT_FS_SIZE") - (2*border+caption)), NULL); /* layout will be updated in motDialogConfigureNotify */ if (visible) XtMapWidget(ih->handle); /* remove auxiliar attributes */ iupAttribSetStr(ih, "_IUPMOT_FS_X", NULL); iupAttribSetStr(ih, "_IUPMOT_FS_Y", NULL); iupAttribSetStr(ih, "_IUPMOT_FS_SIZE", NULL); iupAttribSetStr(ih, "_IUPMOT_FS_DECOR", NULL); } /* remove auxiliar attributes */ iupAttribSetStr(ih, "_IUPMOT_FS_MAXBOX", NULL); iupAttribSetStr(ih, "_IUPMOT_FS_MINBOX", NULL); iupAttribSetStr(ih, "_IUPMOT_FS_MENUBOX",NULL); iupAttribSetStr(ih, "_IUPMOT_FS_RESIZE", NULL); iupAttribSetStr(ih, "_IUPMOT_FS_BORDER", NULL); iupAttribSetStr(ih, "_IUPMOT_FS_TITLE", NULL); } } } return 1; }
int iupdrvDialogSetPlacement(Ihandle* ih, int x, int y) { char* placement; if (iupAttribGetInt(ih, "FULLSCREEN")) return 1; placement = iupAttribGet(ih, "PLACEMENT"); if (!placement) return 0; if (iupStrEqualNoCase(placement, "MINIMIZED")) { if (iupdrvDialogIsVisible(ih)) XIconifyWindow(iupmot_display, XtWindow(ih->handle), iupmot_screen); else { /* TODO: This is not working, so force a minimize after visible. */ /*XWMHints wm_hints; */ /*wm_hints.flags = StateHint; */ /*wm_hints.initial_state = IconicState; */ /*XSetWMHints(iupmot_display, XtWindow(ih->handle), &wm_hints); */ XtMapWidget(ih->handle); XIconifyWindow(iupmot_display, XtWindow(ih->handle), iupmot_screen); } } else if (iupStrEqualNoCase(placement, "MAXIMIZED")) { static Atom maxatoms[2] = {0, 0}; if (!(maxatoms[0])) { maxatoms[0] = XmInternAtom(iupmot_display, "_NET_WM_STATE_MAXIMIZED_VERT", False); maxatoms[1] = XmInternAtom(iupmot_display, "_NET_WM_STATE_MAXIMIZED_HORZ", False); } motDialogChangeWMState(ih, maxatoms[0], maxatoms[1], 1); } else if (iupStrEqualNoCase(placement, "FULL")) { int width, height; int border, caption, menu; iupdrvDialogGetDecoration(ih, &border, &caption, &menu); /* position the decoration outside the screen */ x = -(border); y = -(border+caption+menu); /* the dialog client area will cover the task bar */ iupdrvGetFullSize(&width, &height); height += menu; /* the menu is included in the client area size in Motif. */ /* set the new size and position */ /* The resize event will update the layout */ XtVaSetValues(ih->handle, XmNx, (XtArgVal)x, /* outside border */ XmNy, (XtArgVal)y, XmNwidth, (XtArgVal)width, /* client size */ XmNheight, (XtArgVal)height, NULL); } iupAttribSetStr(ih, "PLACEMENT", NULL); /* reset to NORMAL */ return 1; }
int iupDialogPopup(Ihandle* ih, int x, int y) { int was_visible; int ret = iupClassObjectDlgPopup(ih, x, y); if (ret != IUP_INVALID) /* IUP_INVALID means it is not implemented */ return ret; ih->data->show_state = IUP_SHOW; /* save visible state before iupdrvDialogSetPlacement */ /* because it can also show the window when changing placement. */ was_visible = iupdrvDialogIsVisible(ih); /* Update the position and placement */ if (!iupdrvDialogSetPlacement(ih)) { iDialogAdjustPos(ih, &x, &y); iupdrvDialogSetPosition(ih, x, y); } if (was_visible) /* already visible */ { /* only re-show to raise the window */ iupdrvDialogSetVisible(ih, 1); /* flush, then process show_cb and startfocus */ iDialogAfterShow(ih); return IUP_NOERROR; } if (iupAttribGetBoolean(ih, "MODAL")) /* already a popup */ return IUP_NOERROR; iDialogSetModal(ih); ih->data->first_show = 1; /* actually show the window */ /* test if placement turn the dialog visible */ if (!iupdrvDialogIsVisible(ih)) iupdrvDialogSetVisible(ih, 1); /* increment visible count */ iupDlgListVisibleInc(); /* flush, then process show_cb and startfocus */ iDialogAfterShow(ih); /* interrupt processing here */ IupMainLoop(); /* if window is still valid (IupDestroy not called), hide the dialog if still visible. */ if (iupObjectCheck(ih)) { iDialogUnSetModal(ih); IupHide(ih); } return IUP_NOERROR; }