Example #1
0
static INT CALLBACK winFileDlgBrowseCallback(HWND hWnd, UINT uMsg, LPARAM lParam, LPARAM lpData)
{
  (void)lParam;
  if (uMsg == BFFM_INITIALIZED)
  {
    char* value;
    Ihandle* ih = (Ihandle*)lpData;
    ih->handle = hWnd;
    iupDialogUpdatePosition(ih);
    ih->handle = NULL;  /* reset handle */
    value = iupStrDup(iupAttribGet(ih, "DIRECTORY"));
    if (value)
    {
      winFileDlgStrReplacePathSlash(value);
      SendMessage(hWnd, BFFM_SETSELECTION, TRUE, (LPARAM)value);
      free(value);
    }
  }
  else if (uMsg == BFFM_SELCHANGED)
  {
    char buffer[IUP_MAX_FILENAME_SIZE];
    ITEMIDLIST* selecteditem = (ITEMIDLIST*)lParam;
    buffer[0] = 0;
    SHGetPathFromIDList(selecteditem, buffer);
    if (buffer[0] == 0)
      SendMessage(hWnd, BFFM_ENABLEOK, 0, (LPARAM)FALSE);
    else
      SendMessage(hWnd, BFFM_ENABLEOK, 0, (LPARAM)TRUE);
  }
  return 0;
}
Example #2
0
static UINT_PTR CALLBACK winFileDlgSimpleHook(HWND hWnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
{
  (void)wParam;
  switch(uiMsg)
  {
  case WM_INITDIALOG:
    {
      OPENFILENAME* openfilename = (OPENFILENAME*)lParam;
      Ihandle* ih = (Ihandle*)openfilename->lCustData;
      ih->handle = GetParent(hWnd);
      iupDialogUpdatePosition(ih);
      ih->handle = NULL;  /* reset handle */
      SetWindowLongPtr(hWnd, DWLP_USER, (LONG_PTR)ih);
      break;
    }
  case WM_DESTROY:
    {
      Ihandle* ih = (Ihandle*)GetWindowLongPtr(hWnd, DWLP_USER);
      IFnss cb = (IFnss)IupGetCallback(ih, "FILE_CB");
      if (cb) cb(ih, NULL, "FINISH");
      break;
    }
  case WM_NOTIFY:
    return winFileDlgWmNotify(hWnd, (LPOFNOTIFY)lParam);
  }
  return 0;
}
Example #3
0
static UINT_PTR winColorDlgHookProc(HWND hWnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
{
  (void)wParam;
  if (uiMsg == WM_INITDIALOG)
  {
    HWND hWndItem;
    CHOOSECOLOR* choosecolor = (CHOOSECOLOR*)lParam;
    Ihandle* ih = (Ihandle*)choosecolor->lCustData;

    char* value = iupAttribGet(ih, "TITLE");
    if (value)
      SetWindowText(hWnd, value);

    ih->handle = hWnd;
    iupDialogUpdatePosition(ih);
    ih->handle = NULL;  /* reset handle */
    iupAttribSetStr(ih, "HWND", (char*)hWnd);  /* used by HELP_CB in winDialogBaseProc */

    hWndItem = GetDlgItem(hWnd, IUP_COLOR_RED);
    SetFocus(hWndItem);
  }
  return 0;
}
Example #4
0
static UINT_PTR CALLBACK winFileDlgPreviewHook(HWND hWnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
{
  /* hWnd here is a handle to the child window that contains the template,
     NOT the file dialog. Only the preview canvas is a child of this window. */

  switch(uiMsg)
  {
  case WM_INITDIALOG:
    {
      OPENFILENAME* openfilename = (OPENFILENAME*)lParam;
      Ihandle* ih = (Ihandle*)openfilename->lCustData;
      HWND hWndPreview = GetDlgItem(hWnd, IUP_PREVIEWCANVAS);

      ih->handle = GetParent(hWnd);
      iupDialogUpdatePosition(ih);
      ih->handle = NULL;  /* reset handle */

      if (hWndPreview)
      {
        RECT rect;

        winFileDlgSetPreviewCanvasPos(hWnd, hWndPreview);

        GetClientRect(hWndPreview, &rect);
        iupAttribSetInt(ih, "PREVIEWWIDTH", rect.right - rect.left);
        iupAttribSetInt(ih, "PREVIEWHEIGHT", rect.bottom - rect.top);
      }
      SetWindowLongPtr(hWnd, DWLP_USER, (LONG_PTR)ih);
      iupAttribSetStr(ih, "WID", (char*)hWndPreview);
      iupAttribSetStr(ih, "HWND", (char*)hWndPreview);
      winFileDlgUpdatePreviewGLCanvas(ih);
      break;
    }
  case WM_DRAWITEM:
    {
      if (wParam == IUP_PREVIEWCANVAS)
      {
        LPDRAWITEMSTRUCT lpDrawItem = (LPDRAWITEMSTRUCT)lParam;
        Ihandle* ih = (Ihandle*)GetWindowLongPtr(hWnd, DWLP_USER);
        /* callback here always exists */
        IFnss cb = (IFnss)IupGetCallback(ih, "FILE_CB");
        char filename[IUP_MAX_FILENAME_SIZE];
        iupAttribSetStr(ih, "PREVIEWDC", (char*)lpDrawItem->hDC);
        if (winFileDlgGetSelectedFile(ih, hWnd, filename))
        {
          if (iupdrvIsFile(filename))
            cb(ih, filename, "PAINT");
          else
            cb(ih, NULL, "PAINT");
        }
        else
          cb(ih, NULL, "PAINT");
        iupAttribSetStr(ih, "PREVIEWDC", NULL);
      }
      break;
    }
  case WM_SIZE:
    {
      HWND hWndPreview = GetDlgItem(hWnd, IUP_PREVIEWCANVAS);
      if (hWndPreview)
      {
        Ihandle* ih = (Ihandle*)GetWindowLongPtr(hWnd, DWLP_USER);
        RECT rect;

        winFileDlgSetPreviewCanvasPos(hWnd, hWndPreview);

        GetClientRect(hWndPreview, &rect);
        iupAttribSetInt(ih, "PREVIEWWIDTH", rect.right-rect.left);

        RedrawWindow(hWndPreview, NULL, NULL, RDW_INVALIDATE|RDW_UPDATENOW);
      }
      break;
    }
  case WM_DESTROY:
    {
      Ihandle* ih = (Ihandle*)GetWindowLongPtr(hWnd, DWLP_USER);
      /* callback here always exists */
      IFnss cb = (IFnss)IupGetCallback(ih, "FILE_CB");
      cb(ih, NULL, "FINISH");
      break;
    }
  case WM_NOTIFY:
      return winFileDlgWmNotify(hWnd, (LPOFNOTIFY)lParam);
  }
  return 0;
}
Example #5
0
static int gtkMessageDlgPopup(Ihandle* ih, int x, int y)
{
  InativeHandle* parent = iupDialogGetNativeParent(ih);
  GtkMessageType type = GTK_MESSAGE_INFO;
  GtkWidget* dialog;
  char *icon, *buttons, *title;
  int response, num_but = 2;

  iupAttribSetInt(ih, "_IUPDLG_X", x);
  iupAttribSetInt(ih, "_IUPDLG_Y", y);

  icon = iupAttribGetStr(ih, "DIALOGTYPE");
  if (iupStrEqualNoCase(icon, "ERROR"))
    type = GTK_MESSAGE_ERROR;
  else if (iupStrEqualNoCase(icon, "WARNING"))
    type = GTK_MESSAGE_WARNING;
  else if (iupStrEqualNoCase(icon, "INFORMATION"))
    type = GTK_MESSAGE_INFO;
  else if (iupStrEqualNoCase(icon, "QUESTION"))
    type = GTK_MESSAGE_QUESTION;

  dialog = gtk_message_dialog_new((GtkWindow*)parent,
                                  0,
                                  type,
                                  GTK_BUTTONS_NONE,
                                  iupgtkStrConvertToUTF8(iupAttribGetStr(ih, "VALUE")));
  if (!dialog)
    return IUP_ERROR;

  title = iupAttribGetStr(ih, "TITLE");
  if (title)
    gtk_window_set_title(GTK_WINDOW(dialog), iupgtkStrConvertToUTF8(title));

  buttons = iupAttribGetStr(ih, "BUTTONS");
  if (iupStrEqualNoCase(buttons, "OKCANCEL"))
  {
    gtk_dialog_add_button(GTK_DIALOG(dialog),
                          GTK_STOCK_OK,
                          IUP_RESPONSE_1);
    gtk_dialog_add_button(GTK_DIALOG(dialog),
                          GTK_STOCK_CANCEL,
                          IUP_RESPONSE_2);
  }
  else if (iupStrEqualNoCase(buttons, "YESNO"))
  {
    gtk_dialog_add_button(GTK_DIALOG(dialog),
                          GTK_STOCK_YES,
                          IUP_RESPONSE_1);
    gtk_dialog_add_button(GTK_DIALOG(dialog),
                          GTK_STOCK_NO,
                          IUP_RESPONSE_2);
  }
  else /* OK */
  {
    gtk_dialog_add_button(GTK_DIALOG(dialog),
                          GTK_STOCK_OK,
                          IUP_RESPONSE_1);
    num_but = 1;
  }

  if (IupGetCallback(ih, "HELP_CB"))
    gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_HELP, IUP_RESPONSE_HELP);

  if (num_but == 2 && iupAttribGetInt(ih, "BUTTONDEFAULT") == 2)
    gtk_dialog_set_default_response(GTK_DIALOG(dialog), IUP_RESPONSE_2);
  else
    gtk_dialog_set_default_response(GTK_DIALOG(dialog), IUP_RESPONSE_1);
  
  /* initialize the widget */
  gtk_widget_realize(dialog);
  
  ih->handle = dialog;
  iupDialogUpdatePosition(ih);
  ih->handle = NULL;

  do 
  {
    response = gtk_dialog_run(GTK_DIALOG(dialog));

    if (response == IUP_RESPONSE_HELP)
    {
      Icallback cb = IupGetCallback(ih, "HELP_CB");
      if (cb && cb(ih) == IUP_CLOSE)
        response = (num_but == 2)? IUP_RESPONSE_2: IUP_RESPONSE_1;
    }
  } while (response == IUP_RESPONSE_HELP);

  if (response == IUP_RESPONSE_1)
    IupSetAttribute(ih, "BUTTONRESPONSE", "1");
  else
    IupSetAttribute(ih, "BUTTONRESPONSE", "2");

  gtk_widget_destroy(dialog);  

  return IUP_NOERROR;
}
Example #6
0
static int gtkMessageDlgPopup(Ihandle* ih, int x, int y)
{
  InativeHandle* parent = iupDialogGetNativeParent(ih);
  GtkMessageType type = GTK_MESSAGE_OTHER;
  GtkWidget* dialog;
  char *icon, *buttons, *title;
  const char *ok, *cancel, *yes, *no, *help, *retry = IupGetLanguageString("IUP_RETRY");
  int response, button_def;

  iupAttribSetInt(ih, "_IUPDLG_X", x);   /* used in iupDialogUpdatePosition */
  iupAttribSetInt(ih, "_IUPDLG_Y", y);

  icon = iupAttribGetStr(ih, "DIALOGTYPE");
  if (iupStrEqualNoCase(icon, "ERROR"))
    type = GTK_MESSAGE_ERROR;
  else if (iupStrEqualNoCase(icon, "WARNING"))
    type = GTK_MESSAGE_WARNING;
  else if (iupStrEqualNoCase(icon, "INFORMATION"))
    type = GTK_MESSAGE_INFO;
  else if (iupStrEqualNoCase(icon, "QUESTION"))
    type = GTK_MESSAGE_QUESTION;

  dialog = gtk_message_dialog_new((GtkWindow*)parent,
                                  0,
                                  type,
                                  GTK_BUTTONS_NONE,
                                  "%s",
                                  iupgtkStrConvertToSystem(iupAttribGet(ih, "VALUE")));
  if (!dialog)
    return IUP_ERROR;

  title = iupAttribGet(ih, "TITLE");
  if (title)
    gtk_window_set_title(GTK_WINDOW(dialog), iupgtkStrConvertToSystem(title));

#if GTK_CHECK_VERSION(3, 10, 0)
  ok = "_OK";
  cancel = "_Cancel";
  yes = "_Yes";
  no = "_No";
  help = "_Help";
#else
  ok = GTK_STOCK_OK;
  cancel = GTK_STOCK_CANCEL;
  yes = GTK_STOCK_YES;
  no = GTK_STOCK_NO;
  help = GTK_STOCK_HELP;
#endif

  buttons = iupAttribGetStr(ih, "BUTTONS");
  if (iupStrEqualNoCase(buttons, "OKCANCEL"))
  {
    gtk_dialog_add_button(GTK_DIALOG(dialog),
                          ok,
                          IUP_RESPONSE_1);
    gtk_dialog_add_button(GTK_DIALOG(dialog),
                          cancel,
                          IUP_RESPONSE_2);
  }
  if (iupStrEqualNoCase(buttons, "RETRYCANCEL"))
  {
    gtk_dialog_add_button(GTK_DIALOG(dialog),
                          retry,
                          IUP_RESPONSE_1);
    gtk_dialog_add_button(GTK_DIALOG(dialog),
                          cancel,
                          IUP_RESPONSE_2);
  }
  else if (iupStrEqualNoCase(buttons, "YESNO"))
  {
    gtk_dialog_add_button(GTK_DIALOG(dialog),
                          yes,
                          IUP_RESPONSE_1);
    gtk_dialog_add_button(GTK_DIALOG(dialog),
                          no,
                          IUP_RESPONSE_2);
  }
  else if (iupStrEqualNoCase(buttons, "YESNOCANCEL"))
  {
    gtk_dialog_add_button(GTK_DIALOG(dialog),
                          yes,
                          IUP_RESPONSE_1);
    gtk_dialog_add_button(GTK_DIALOG(dialog),
                          no,
                          IUP_RESPONSE_2);
    gtk_dialog_add_button(GTK_DIALOG(dialog),
                          cancel,
                          IUP_RESPONSE_3);
  }
  else /* OK */
  {
    gtk_dialog_add_button(GTK_DIALOG(dialog),
                          ok,
                          IUP_RESPONSE_1);
  }

  if (IupGetCallback(ih, "HELP_CB"))
    gtk_dialog_add_button(GTK_DIALOG(dialog), help, IUP_RESPONSE_HELP);

  button_def = iupAttribGetInt(ih, "BUTTONDEFAULT");
  if (button_def == 3)
    gtk_dialog_set_default_response(GTK_DIALOG(dialog), IUP_RESPONSE_3);
  else if (button_def == 2)
    gtk_dialog_set_default_response(GTK_DIALOG(dialog), IUP_RESPONSE_2);
  else
    gtk_dialog_set_default_response(GTK_DIALOG(dialog), IUP_RESPONSE_1);
  
  /* initialize the widget */
  gtk_widget_realize(dialog);
  
  ih->handle = dialog;
  iupDialogUpdatePosition(ih);
  ih->handle = NULL;

  do 
  {
    response = gtk_dialog_run(GTK_DIALOG(dialog));

    if (response == IUP_RESPONSE_HELP)
    {
      Icallback cb = IupGetCallback(ih, "HELP_CB");
      if (cb && cb(ih) == IUP_CLOSE)
      {
        if (iupStrEqualNoCase(buttons, "YESNOCANCEL"))
          response = IUP_RESPONSE_3;
        else if(iupStrEqualNoCase(buttons, "OK"))
          response = IUP_RESPONSE_1;
        else
          response = IUP_RESPONSE_2;
      }
    }
  } while (response == IUP_RESPONSE_HELP);

  if (response == IUP_RESPONSE_3)
    IupSetAttribute(ih, "BUTTONRESPONSE", "3");
  else if (response == IUP_RESPONSE_2)
    IupSetAttribute(ih, "BUTTONRESPONSE", "2");
  else
    IupSetAttribute(ih, "BUTTONRESPONSE", "1");

  gtk_widget_destroy(dialog);  

  return IUP_NOERROR;
}
Example #7
0
static int gtkFontDlgPopup(Ihandle* ih, int x, int y)
{
  InativeHandle* parent = iupDialogGetNativeParent(ih);
  GtkFontSelectionDialog* dialog;
  int response;
  char* preview_text, *standardfont;

  iupAttribSetInt(ih, "_IUPDLG_X", x);   /* used in iupDialogUpdatePosition */
  iupAttribSetInt(ih, "_IUPDLG_Y", y);

  dialog = (GtkFontSelectionDialog*)gtk_font_selection_dialog_new(iupgtkStrConvertToUTF8(iupAttribGet(ih, "TITLE")));
  if (!dialog)
    return IUP_ERROR;

  if (parent)
    gtk_window_set_transient_for((GtkWindow*)dialog, (GtkWindow*)parent);

  standardfont = iupAttribGet(ih, "VALUE");
  if (!standardfont)
    standardfont = IupGetGlobal("DEFAULTFONT");
  gtk_font_selection_dialog_set_font_name(dialog, standardfont);

  preview_text = iupAttribGet(ih, "PREVIEWTEXT");
  if (preview_text)
    gtk_font_selection_dialog_set_preview_text(dialog, preview_text);

  if (IupGetCallback(ih, "HELP_CB"))
    gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_HELP, GTK_RESPONSE_HELP);
  
  /* initialize the widget */
  gtk_widget_realize(GTK_WIDGET(dialog));
  
  ih->handle = GTK_WIDGET(dialog);
  iupDialogUpdatePosition(ih);
  ih->handle = NULL;
                                    
  do 
  {
    response = gtk_dialog_run(GTK_DIALOG(dialog));

    if (response == GTK_RESPONSE_HELP)
    {
      Icallback cb = IupGetCallback(ih, "HELP_CB");
      if (cb && cb(ih) == IUP_CLOSE)
        response = GTK_RESPONSE_CANCEL;
    }
  } while (response == GTK_RESPONSE_HELP);

  if (response == GTK_RESPONSE_OK)
  {
    char* fontname = gtk_font_selection_dialog_get_font_name(dialog);
    iupAttribStoreStr(ih, "VALUE", fontname);
    g_free(fontname);
    iupAttribSetStr(ih, "STATUS", "1");
  }
  else
  {
    iupAttribSetStr(ih, "VALUE", NULL);
    iupAttribSetStr(ih, "STATUS", NULL);
  }

  gtk_widget_destroy(GTK_WIDGET(dialog));  

  return IUP_NOERROR;
}
Example #8
0
static int gtkColorDlgPopup(Ihandle* ih, int x, int y)
{
  InativeHandle* parent = iupDialogGetNativeParent(ih);
  GtkColorSelectionDialog* dialog;
  GtkColorSelection* colorsel;
  GdkColor color;
  char *value;
  unsigned char r = 0, g = 0, b = 0, a = 255;
  int response, ret;

  iupAttribSetInt(ih, "_IUPDLG_X", x);   /* used in iupDialogUpdatePosition */
  iupAttribSetInt(ih, "_IUPDLG_Y", y);

  dialog = (GtkColorSelectionDialog*)gtk_color_selection_dialog_new(iupgtkStrConvertToUTF8(iupAttribGet(ih, "TITLE")));
  if (!dialog)
    return IUP_ERROR;

  if (parent)
    gtk_window_set_transient_for((GtkWindow*)dialog, (GtkWindow*)parent);

  ret = iupStrToRGBA(iupAttribGet(ih, "VALUE"), &r, &g, &b, &a);

  colorsel = (GtkColorSelection*)dialog->colorsel;
  iupgdkColorSet(&color, r, g, b);
  gtk_color_selection_set_current_color(colorsel, &color);

  value = iupAttribGetStr(ih, "ALPHA");
  if (value)
  {
    int alpha;
    if (iupStrToInt(value, &alpha))
    {
      if (alpha<0) alpha=0;
      if (alpha>255) alpha=255;
      gtk_color_selection_set_has_opacity_control(colorsel, TRUE);
      gtk_color_selection_set_current_alpha(colorsel, iupCOLOR8TO16(alpha));
    }
  }
  else if (iupAttribGetBoolean(ih, "SHOWALPHA") || ret == 4)
  {
    gtk_color_selection_set_has_opacity_control(colorsel, TRUE);
    gtk_color_selection_set_current_alpha(colorsel, iupCOLOR8TO16(a));
  }
  else
    gtk_color_selection_set_has_opacity_control(colorsel, FALSE);

  value = iupAttribGetStr(ih, "COLORTABLE");
  if (value)
  {
    gtk_color_selection_set_has_palette (colorsel, TRUE);
    gtkColorDlgSetPalette(colorsel, value);
  }
  else if (iupAttribGetBoolean(ih, "SHOWCOLORTABLE"))
    gtk_color_selection_set_has_palette (colorsel, TRUE);
  else
    gtk_color_selection_set_has_palette (colorsel, FALSE);

  if (IupGetCallback(ih, "HELP_CB"))
    gtk_widget_show(dialog->help_button);
  
  /* initialize the widget */
  gtk_widget_realize(GTK_WIDGET(dialog));
  
  ih->handle = GTK_WIDGET(dialog);
  iupDialogUpdatePosition(ih);
  ih->handle = NULL;

  do 
  {
    response = gtk_dialog_run(GTK_DIALOG(dialog));

    if (response == GTK_RESPONSE_HELP)
    {
      Icallback cb = IupGetCallback(ih, "HELP_CB");
      if (cb && cb(ih) == IUP_CLOSE)
        response = GTK_RESPONSE_CANCEL;
    }
  } while (response == GTK_RESPONSE_HELP);

  if (response == GTK_RESPONSE_OK)
  {
    GdkColor color;
    gtk_color_selection_get_current_color(colorsel, &color);
    IupSetAttribute(ih, "STATUS", "1");

    if (gtk_color_selection_get_has_opacity_control(colorsel))
    {
      int alpha = gtk_color_selection_get_current_alpha(colorsel);
      iupAttribSetInt(ih, "ALPHA", (int)iupCOLOR16TO8(alpha));
      iupAttribSetStrf(ih, "VALUE", "%d %d %d %d", (int)iupCOLOR16TO8(color.red), (int)iupCOLOR16TO8(color.green), (int)iupCOLOR16TO8(color.blue), (int)iupCOLOR16TO8(alpha));
    }
    else
      iupAttribSetStrf(ih, "VALUE", "%d %d %d", (int)iupCOLOR16TO8(color.red), (int)iupCOLOR16TO8(color.green), (int)iupCOLOR16TO8(color.blue));

    if (gtk_color_selection_get_has_palette(colorsel))
      gtkColorDlgGetPalette(ih, colorsel);
  }
  else
  {
    iupAttribSetStr(ih, "ALPHA", NULL);
    iupAttribSetStr(ih, "VALUE", NULL);
    iupAttribSetStr(ih, "COLORTABLE", NULL);
    iupAttribSetStr(ih, "STATUS", NULL);
  }

  gtk_widget_destroy(GTK_WIDGET(dialog));  

  return IUP_NOERROR;
}
Example #9
0
static int motFileDlgPopup(Ihandle* ih, int x, int y)
{
  InativeHandle* parent = iupDialogGetNativeParent(ih);
  Widget filebox, dialog;
  int dialogtype, style = XmDIALOG_FULL_APPLICATION_MODAL;
  IFnss file_cb = NULL;
  Widget preview_canvas = NULL;
  char* value;

  iupAttribSetInt(ih, "_IUPDLG_X", x);   /* used in iupDialogUpdatePosition */
  iupAttribSetInt(ih, "_IUPDLG_Y", y);

  value = iupAttribGetStr(ih, "DIALOGTYPE");
  if (iupStrEqualNoCase(value, "SAVE"))
    dialogtype = IUP_DIALOGSAVE;
  else if (iupStrEqualNoCase(value, "DIR"))
    dialogtype = IUP_DIALOGDIR;
  else
    dialogtype = IUP_DIALOGOPEN;
  iupAttribSetInt(ih, "_IUPDLG_DIALOGTYPE", dialogtype);

  if (parent)
  {
    filebox = XmCreateFileSelectionDialog(parent, "filedialog", NULL, 0);
    dialog = XtParent(filebox);
  }
  else
  {
    dialog = XtAppCreateShell(NULL, "filedialog", topLevelShellWidgetClass, iupmot_display, NULL, 0);
    filebox = XmCreateFileSelectionBox(dialog, "filebox", NULL, 0);
    style = XmDIALOG_MODELESS;
    XtVaSetValues(dialog,
      XmNmwmInputMode, MWM_INPUT_FULL_APPLICATION_MODAL,
      XmNmappedWhenManaged, False,
      XmNsaveUnder, True,
      NULL);
  }
  if (!filebox)
    return IUP_NOERROR;

  if (!iupAttribGetBoolean(ih, "SHOWHIDDEN"))
    XtVaSetValues(filebox, XmNfileFilterStyle, XmFILTER_HIDDEN_FILES, NULL);

  value = iupAttribGet(ih, "TITLE");
  if (!value)
  {
    if (dialogtype == IUP_DIALOGSAVE)
      value = "IUP_SAVEAS";
    else if (dialogtype == IUP_DIALOGOPEN)
      value = "IUP_OPEN";
    else
      value = "IUP_SELECTDIR";
    iupAttribSetStr(ih, "TITLE", iupStrMessageGet(value));
  }
  iupmotSetString(filebox, XmNdialogTitle, value);

  XtVaSetValues(filebox,
                XmNdialogStyle, style,
                XmNautoUnmanage, False,
                XmNresizePolicy, XmRESIZE_GROW,
                NULL);

  if (dialogtype == IUP_DIALOGDIR)
    XtVaSetValues(filebox, XmNfileTypeMask, XmFILE_DIRECTORY, NULL);

  /* just check for the path inside FILE */
  value = iupAttribGet(ih, "FILE");
  if (value && value[0] == '/')
  {
    char* dir = iupStrFileGetPath(value);
    iupAttribStoreStr(ih, "DIRECTORY", dir);
    free(dir);
  }

  /* set XmNdirectory before XmNpattern and before XmNdirSpec */

  value = iupAttribGet(ih, "DIRECTORY");
  if (value)
    iupmotSetString(filebox, XmNdirectory, value);

  value = iupAttribGet(ih, "FILTER");
  if (value)
  {
    char *filter = value;
    char *p = strchr(value, ';');
    if (p) 
    {
      /* Use only the first filter */
      int size = p-value;
      filter = (char*)malloc(size+1);
      memcpy(filter, value, size);
      filter[size] = 0;
    }

    iupmotSetString(filebox, XmNpattern, filter);

    if (filter != value) 
      free(filter);
  }

  value = iupAttribGet(ih, "FILE");
  if (value)
  {
    char* file = value;

    if (value[0] != '/')  /* if does not contains a full path, then add the directory */
    {
      char* cur_dir = NULL;
      char* dir = iupAttribGet(ih, "DIRECTORY");
      if (!dir)
      {
        cur_dir = iupdrvGetCurrentDirectory();
        dir = cur_dir;
      }

      file = iupStrFileMakeFileName(dir, value);

      if (cur_dir)
        free(cur_dir);
    }

  /* clear value before setting. Do not know why we have to do this, 
     but if not cleared it will fail to set the XmNdirSpec value. */
    iupmotSetString(filebox, XmNdirSpec, "");
    iupmotSetString(filebox, XmNdirSpec, file);

    if (file != value)
      free(file);
  }

  if (!IupGetCallback(ih, "HELP_CB"))
    XtUnmanageChild(XmFileSelectionBoxGetChild(filebox, XmDIALOG_HELP_BUTTON));

  XtAddCallback(filebox, XmNokCallback, (XtCallbackProc)motFileDlgCallback, (XtPointer)ih);
  XtAddCallback(filebox, XmNcancelCallback, (XtCallbackProc)motFileDlgCallback, (XtPointer)ih);
  XtAddCallback(filebox, XmNhelpCallback, (XtCallbackProc)motFileDlgHelpCallback, (XtPointer)ih);

  if (dialogtype == IUP_DIALOGDIR)
  {
    Widget new_folder = XtVaCreateManagedWidget("new_folder", xmPushButtonWidgetClass, filebox, 
                                                XmNlabelType, XmSTRING, 
                                                NULL);
    iupmotSetString(new_folder, XmNlabelString, iupStrMessageGet("IUP_CREATEFOLDER"));
    XtAddCallback(new_folder, XmNactivateCallback, (XtCallbackProc)motFileDlgNewFolderCallback, (XtPointer)filebox);
  }
  else
  {
    file_cb = (IFnss)IupGetCallback(ih, "FILE_CB");
    if (file_cb)
    {
      Widget list = XmFileSelectionBoxGetChild(filebox, XmDIALOG_LIST);
      XtAddCallback(list, XmNbrowseSelectionCallback, (XtCallbackProc)motFileDlgBrowseSelectionCallback, (XtPointer)ih);
      list = XmFileSelectionBoxGetChild(filebox, XmDIALOG_DIR_LIST);
      XtAddCallback(list, XmNbrowseSelectionCallback, (XtCallbackProc)motFileDlgBrowseSelectionCallback, (XtPointer)ih);

      if (iupAttribGetBoolean(ih, "SHOWPREVIEW"))
      {
        Widget frame = XtVaCreateManagedWidget("preview_canvas", xmFrameWidgetClass, filebox, 
                                                        XmNshadowType, XmSHADOW_ETCHED_IN,
                                                        NULL);

        preview_canvas = XtVaCreateManagedWidget("preview_canvas", xmDrawingAreaWidgetClass, frame, 
                                                        XmNwidth, 180, 
                                                        XmNheight, 150,
                                                        XmNresizePolicy, XmRESIZE_GROW,
                                                        NULL);

        XtAddCallback(preview_canvas, XmNexposeCallback, (XtCallbackProc)motFileDlgPreviewCanvasExposeCallback, (XtPointer)ih);
        XtAddCallback(preview_canvas, XmNresizeCallback, (XtCallbackProc)motFileDlgPreviewCanvasResizeCallback,  (XtPointer)ih);

        iupAttribSetStr(ih, "_IUPDLG_FILEBOX", (char*)filebox);
      }
    }

    if (iupAttribGetBoolean(ih, "MULTIPLEFILES"))
    {
      Widget wList = XmFileSelectionBoxGetChild(filebox, XmDIALOG_LIST);
      XtVaSetValues(wList, XmNselectionPolicy, XmEXTENDED_SELECT, NULL);

      if (file_cb)
        XtAddCallback(wList, XmNextendedSelectionCallback, (XtCallbackProc)motFileDlgBrowseSelectionCallback, (XtPointer)ih);
    }
  }

  XmAddWMProtocolCallback(dialog, iupmot_wm_deletewindow, motFileDlgCBclose, (XtPointer)ih);
  XtManageChild(filebox);

  XtRealizeWidget(dialog);
  ih->handle = dialog;
  iupDialogUpdatePosition(ih);
  ih->handle = NULL;  /* reset handle */

  if (file_cb)
  {
    if (preview_canvas)
      motFileDlgPreviewCanvasInit(ih, preview_canvas);

    file_cb(ih, NULL, "INIT");
  }

  if (ih->userwidth && ih->userheight)
  {
    XtVaSetValues(dialog,
      XmNwidth, (XtArgVal)(ih->userwidth),
      XmNheight, (XtArgVal)(ih->userheight),
      NULL);
  }

  if (style == XmDIALOG_MODELESS)
    XtPopup(dialog, XtGrabExclusive);

  /* while the user hasn't provided an answer, simulate main loop.
  ** The answer changes as soon as the user selects one of the
  ** buttons and the callback routine changes its value. */
  iupAttribSetStr(ih, "STATUS", NULL);
  while (iupAttribGet(ih, "STATUS") == NULL)
    XtAppProcessEvent(iupmot_appcontext, XtIMAll);

  if (file_cb)
  {
    if (preview_canvas)
      XFreeGC(iupmot_display, (GC)iupAttribGet(ih, "PREVIEWDC"));

    file_cb(ih, NULL, "FINISH");
  }

  if (!iupAttribGet(ih, "_IUP_WM_DELETE"))
  {
    XtUnmanageChild(filebox);

    if (style == XmDIALOG_MODELESS)
    {
      XtPopdown(dialog);
      XtDestroyWidget(dialog);
    }
  }

  return IUP_NOERROR;
}
static int gtkFontDlgPopup(Ihandle* ih, int x, int y)
{
  InativeHandle* parent = iupDialogGetNativeParent(ih);
  GtkWidget* dialog;
  int response;
  char* preview_text, *standardfont;

  iupAttribSetInt(ih, "_IUPDLG_X", x);   /* used in iupDialogUpdatePosition */
  iupAttribSetInt(ih, "_IUPDLG_Y", y);

#if GTK_CHECK_VERSION(3, 2, 0)
  dialog = gtk_font_chooser_dialog_new(iupgtkStrConvertToSystem(iupAttribGet(ih, "TITLE")), GTK_WINDOW(parent));
#else
  dialog = gtk_font_selection_dialog_new(iupgtkStrConvertToSystem(iupAttribGet(ih, "TITLE")));
#endif
  if (!dialog)
    return IUP_ERROR;

#if !GTK_CHECK_VERSION(3, 2, 0)
  if (parent)
    gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(parent));
#endif

  standardfont = iupAttribGet(ih, "VALUE");
  if (!standardfont)
    standardfont = IupGetGlobal("DEFAULTFONT");
#if GTK_CHECK_VERSION(3, 2, 0)
  gtk_font_chooser_set_font(GTK_FONT_CHOOSER(dialog), standardfont);
#else
  gtk_font_selection_dialog_set_font_name(GTK_FONT_SELECTION_DIALOG(dialog), standardfont);
#endif

  preview_text = iupAttribGet(ih, "PREVIEWTEXT");
  if (preview_text)
  {
    preview_text = iupgtkStrConvertToSystem(preview_text);
#if GTK_CHECK_VERSION(3, 2, 0)
    if (iupStrEqualNoCase(preview_text, "NONE"))
      gtk_font_chooser_set_show_preview_entry(GTK_FONT_CHOOSER(dialog), FALSE);
    else
      gtk_font_chooser_set_preview_text(GTK_FONT_CHOOSER(dialog), preview_text);
#else
    gtk_font_selection_dialog_set_preview_text(GTK_FONT_SELECTION_DIALOG(dialog), preview_text);
#endif
  }

  if (IupGetCallback(ih, "HELP_CB"))
  {
#if GTK_CHECK_VERSION(3, 10, 0)
    const char* help = "_Help";
#else
    const char* help = GTK_STOCK_HELP;
#endif

    gtk_dialog_add_button(GTK_DIALOG(dialog), help, GTK_RESPONSE_HELP);
  }
  
  /* initialize the widget */
  gtk_widget_realize(GTK_WIDGET(dialog));
  
  ih->handle = GTK_WIDGET(dialog);
  iupDialogUpdatePosition(ih);
  ih->handle = NULL;
                                    
  do 
  {
    response = gtk_dialog_run(GTK_DIALOG(dialog));

    if (response == GTK_RESPONSE_HELP)
    {
      Icallback cb = IupGetCallback(ih, "HELP_CB");
      if (cb && cb(ih) == IUP_CLOSE)
        response = GTK_RESPONSE_CANCEL;
    }
  } while (response == GTK_RESPONSE_HELP);

  if (response == GTK_RESPONSE_OK)
  {
#if GTK_CHECK_VERSION(3, 2, 0)
    char* fontname = gtk_font_chooser_get_font(GTK_FONT_CHOOSER(dialog));
#else
    char* fontname = gtk_font_selection_dialog_get_font_name(GTK_FONT_SELECTION_DIALOG(dialog));
#endif
    iupAttribSetStr(ih, "VALUE", fontname);
    g_free(fontname);
    iupAttribSet(ih, "STATUS", "1");
  }
  else
  {
    iupAttribSet(ih, "VALUE", NULL);
    iupAttribSet(ih, "STATUS", NULL);
  }

  gtk_widget_destroy(GTK_WIDGET(dialog));  

  return IUP_NOERROR;
}
Example #11
0
static int gtkFileDlgPopup(Ihandle* ih, int x, int y)
{
  InativeHandle* parent = iupDialogGetNativeParent(ih);
  GtkWidget* dialog;
  GtkWidget* preview_canvas = NULL;
  GtkFileChooserAction action;
  IFnss file_cb;
  char* value;
  int response, filter_count = 0;

  iupAttribSetInt(ih, "_IUPDLG_X", x);   /* used in iupDialogUpdatePosition */
  iupAttribSetInt(ih, "_IUPDLG_Y", y);

  value = iupAttribGetStr(ih, "DIALOGTYPE");
  if (iupStrEqualNoCase(value, "SAVE"))
    action = GTK_FILE_CHOOSER_ACTION_SAVE;
  else if (iupStrEqualNoCase(value, "DIR"))
    action = GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER;
  else
    action = GTK_FILE_CHOOSER_ACTION_OPEN;

  value = iupAttribGet(ih, "TITLE");
  if (!value)
  {
    GtkStockItem item;

    if (action == GTK_FILE_CHOOSER_ACTION_SAVE)
      value = GTK_STOCK_SAVE_AS;
    else
      value = GTK_STOCK_OPEN;

    gtk_stock_lookup(value, &item);
    value = item.label;

    iupAttribStoreStr(ih, "TITLE", iupgtkStrConvertFromUTF8(value));
    value = iupAttribGet(ih, "TITLE");
    iupStrRemoveChar(value, '_');
  }

  dialog = gtk_file_chooser_dialog_new(iupgtkStrConvertToUTF8(value), (GtkWindow*)parent, action, 
                                       GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, 
                                       NULL);
  if (!dialog)
    return IUP_ERROR;

  if (action == GTK_FILE_CHOOSER_ACTION_SAVE)
    gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_SAVE, GTK_RESPONSE_OK);
  else if (action == GTK_FILE_CHOOSER_ACTION_OPEN)
    gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_OPEN, GTK_RESPONSE_OK);
  else
    gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_OK, GTK_RESPONSE_OK);

  if (IupGetCallback(ih, "HELP_CB"))
    gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_HELP, GTK_RESPONSE_HELP);

#if GTK_CHECK_VERSION(2, 6, 0)
  if (iupAttribGetBoolean(ih, "SHOWHIDDEN"))
    gtk_file_chooser_set_show_hidden(GTK_FILE_CHOOSER(dialog), TRUE);
#endif

  if (iupAttribGetBoolean(ih, "MULTIPLEFILES") && action == GTK_FILE_CHOOSER_ACTION_OPEN)
    gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), TRUE);

#if GTK_CHECK_VERSION(2, 8, 0)
  if (!iupAttribGetBoolean(ih, "NOOVERWRITEPROMPT") && action == GTK_FILE_CHOOSER_ACTION_SAVE)
    gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), TRUE);
#endif

  /* just check for the path inside FILE */
  value = iupAttribGet(ih, "FILE");
  if (value && (value[0] == '/' || value[1] == ':'))
  {
    char* dir = iupStrFileGetPath(value);
    int len = strlen(dir);
    iupAttribStoreStr(ih, "DIRECTORY", dir);
    free(dir);
    iupAttribStoreStr(ih, "FILE", value+len);
  }

  value = iupAttribGet(ih, "DIRECTORY");
  if (value)
    gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), iupgtkStrConvertToFilename(value));

  value = iupAttribGet(ih, "FILE");
  if (value)
  {
    if (action == GTK_FILE_CHOOSER_ACTION_SAVE)
      gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), iupgtkStrConvertToFilename(value));
    else
    {
      if (iupdrvIsFile(value))  /* check if file exists */
        gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog), iupgtkStrConvertToFilename(value));
    }
  }

  value = iupAttribGet(ih, "EXTFILTER");
  if (value)
  {
    char *name, *pattern, *filters = iupStrDup(value), *p;
    char atrib[30];
    int i;
    int filter_index = iupAttribGetInt(ih, "FILTERUSED");
    if (!filter_index)
      filter_index = 1;

    filter_count = iupStrReplace(filters, '|', 0) / 2;

    p = filters;
    for (i=0; i<filter_count; i++)
    {
      GtkFileFilter *filter = gtk_file_filter_new();

      gtkFileDlgGetNextFilter(&p, &name, &pattern);

      gtk_file_filter_set_name(filter, iupgtkStrConvertToUTF8(name));
      gtk_file_filter_add_pattern(filter, pattern);
      gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter);

      sprintf(atrib, "_IUPDLG_FILTER%d", i+1);
      iupAttribSetStr(ih, atrib, (char*)filter);

      if (i+1 == filter_index)
        gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(dialog), filter);
    }

    free(filters);
  }
  else 
  {
    value = iupAttribGet(ih, "FILTER");
    if (value)
    {
      GtkFileFilter *filter = gtk_file_filter_new();
      char* info = iupAttribGet(ih, "FILTERINFO");
      if (!info)
        info = value;

      gtk_file_filter_set_name(filter, iupgtkStrConvertToUTF8(info));
      gtk_file_filter_add_pattern(filter, value);
      gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter);
    }
  }

  file_cb = (IFnss)IupGetCallback(ih, "FILE_CB");
  if (file_cb && action != GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
  {
    g_signal_connect(GTK_FILE_CHOOSER(dialog), "update-preview", G_CALLBACK(gtkFileDlgUpdatePreview), ih);
    g_signal_connect(dialog, "realize", G_CALLBACK(gtkFileDlgRealize), ih);

    if (iupAttribGetBoolean(ih, "SHOWPREVIEW"))
    {
      GtkWidget* frame = gtk_frame_new(NULL);
      gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_ETCHED_IN);
      gtk_widget_set_size_request(frame, 180, 150);

      preview_canvas = gtk_drawing_area_new();
      gtk_widget_set_double_buffered(preview_canvas, FALSE);
      gtk_container_add(GTK_CONTAINER(frame), preview_canvas);
      gtk_widget_show(preview_canvas);

      g_signal_connect(preview_canvas, "configure-event", G_CALLBACK(gtkFileDlgPreviewConfigureEvent), ih);
      g_signal_connect(preview_canvas, "expose-event", G_CALLBACK(gtkFileDlgPreviewExposeEvent), ih);
      g_signal_connect(preview_canvas, "realize", G_CALLBACK(gtkFileDlgPreviewRealize), ih);

      iupAttribSetStr(ih, "_IUPDLG_FILE_CHOOSER", (char*)dialog);

      gtk_file_chooser_set_preview_widget(GTK_FILE_CHOOSER(dialog), frame);
    }
  }
  
  /* initialize the widget */
  gtk_widget_realize(GTK_WIDGET(dialog));
  
  ih->handle = GTK_WIDGET(dialog);
  iupDialogUpdatePosition(ih);
  ih->handle = NULL;  /* reset handle */

  do 
  {
    response = gtk_dialog_run(GTK_DIALOG(dialog));

    if (response == GTK_RESPONSE_HELP)
    {
      Icallback cb = IupGetCallback(ih, "HELP_CB");
      if (cb && cb(ih) == IUP_CLOSE)
        response = GTK_RESPONSE_CANCEL;
    }
    else if (response == GTK_RESPONSE_OK)
    {
      char *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
      int file_exist = iupdrvIsFile(filename);
      int dir_exist = iupdrvIsDirectory(filename);
      g_free(filename);

      if (action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
      {
        if (!dir_exist)
        {
          iupStrMessageShowError(ih, "IUP_INVALIDDIR");
          response = GTK_RESPONSE_HELP; /* to leave the dialog open */
          continue;
        }
      }
      else if (!iupAttribGetBoolean(ih, "MULTIPLEFILES"))
      {
        if (dir_exist)
        {
          iupStrMessageShowError(ih, "IUP_FILEISDIR");
          response = GTK_RESPONSE_HELP; /* to leave the dialog open */
          continue;
        }

        if (!file_exist)  /* if do not exist check ALLOWNEW */
        {
          value = iupAttribGet(ih, "ALLOWNEW");
          if (!value)
          {
            if (action == GTK_FILE_CHOOSER_ACTION_SAVE)
              value = "YES";
            else
              value = "NO";
          }

          if (!iupStrBoolean(value))
          {
            iupStrMessageShowError(ih, "IUP_FILENOTEXIST");
            response = GTK_RESPONSE_HELP; /* to leave the dialog open */
            continue;
          }
        }

        if (file_cb)
        {
          char *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
          int ret = file_cb(ih, iupgtkStrConvertFromFilename(filename), "OK");
          g_free(filename);
          
          if (ret == IUP_IGNORE)
          {
            response = GTK_RESPONSE_HELP; /* to leave the dialog open */
            continue;
          }
        }
      }
    }
  } while (response == GTK_RESPONSE_HELP);

  if (file_cb)
  {
    if (iupAttribGetBoolean(ih, "SHOWPREVIEW"))
      iupgtkReleaseNativeGraphicsContext(preview_canvas, (void*)iupAttribGet(ih, "PREVIEWDC"));

    file_cb(ih, NULL, "FINISH");
  }

  if (response == GTK_RESPONSE_OK)
  {
    int file_exist, dir_exist;

    if (filter_count)
    {
      int i;
      char atrib[30];
      GtkFileFilter* filter = gtk_file_chooser_get_filter(GTK_FILE_CHOOSER(dialog));

      for (i=0; i<filter_count; i++)
      {
        sprintf(atrib, "_IUPDLG_FILTER%d", i+1);
        if (filter == (GtkFileFilter*)iupAttribGet(ih, atrib))
          iupAttribSetInt(ih, "FILTERUSED", i+1);
      }
    }

    if (iupAttribGetBoolean(ih, "MULTIPLEFILES"))
    {
      GSList* file_list = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(dialog));

      if (file_list->next) /* if more than one file */
        gtkFileDlgGetMultipleFiles(ih, file_list);
      else
      {
        char* filename = (char*)file_list->data;
        iupAttribStoreStr(ih, "VALUE", iupgtkStrConvertFromFilename(filename));
        g_free(filename);
      }

      g_slist_free(file_list);
      file_exist = 1;
      dir_exist = 0;
    }
    else
    {
      char *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
      iupAttribStoreStr(ih, "VALUE", iupgtkStrConvertFromFilename(filename));
      file_exist = iupdrvIsFile(filename);
      dir_exist = iupdrvIsDirectory(filename);
      g_free(filename);
    }

    if (dir_exist)
    {
      iupAttribSetStr(ih, "FILEEXIST", NULL);
      iupAttribSetStr(ih, "STATUS", "0");
    }
    else
    {
      if (file_exist)  /* check if file exists */
      {
        iupAttribSetStr(ih, "FILEEXIST", "YES");
        iupAttribSetStr(ih, "STATUS", "0");
      }
      else
      {
        iupAttribSetStr(ih, "FILEEXIST", "NO");
        iupAttribSetStr(ih, "STATUS", "1");
      }
    }

    if (action != GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER && !iupAttribGetBoolean(ih, "NOCHANGEDIR"))  /* do change the current directory */
    {
      /* GtkFileChooser does not change the current directory */
      char* dir = gtk_file_chooser_get_current_folder(GTK_FILE_CHOOSER(dialog));
      if (dir) iupdrvSetCurrentDirectory(dir);
      g_free(dir);
    }
  }
  else
  {
    iupAttribSetStr(ih, "FILTERUSED", NULL);
    iupAttribSetStr(ih, "VALUE", NULL);
    iupAttribSetStr(ih, "FILEEXIST", NULL);
    iupAttribSetStr(ih, "STATUS", "-1");
  }

  gtk_widget_destroy(GTK_WIDGET(dialog));  

  return IUP_NOERROR;
}
Example #12
0
static int motMessageDlgPopup(Ihandle* ih, int x, int y)
{
  InativeHandle* parent = iupDialogGetNativeParent(ih);
  Widget msgbox, dialog;
  int style = XmDIALOG_FULL_APPLICATION_MODAL;
  int type = XmDIALOG_MESSAGE;
  int num_but = 2;
  char *value;

  iupAttribSetInt(ih, "_IUPDLG_X", x);   /* used in iupDialogUpdatePosition */
  iupAttribSetInt(ih, "_IUPDLG_Y", y);

  if (parent)
  {
    msgbox = XmCreateMessageDialog(parent, "messagedialog", NULL, 0);
    dialog = XtParent(msgbox);
  }
  else
  {
    dialog = XtAppCreateShell(NULL, "messagedialog", topLevelShellWidgetClass, iupmot_display, NULL, 0);
    msgbox = XmCreateMessageBox(dialog, "messagebox", NULL, 0);
    style = XmDIALOG_MODELESS;
    XtVaSetValues(dialog,
      XmNmwmInputMode, MWM_INPUT_FULL_APPLICATION_MODAL,
      XmNmappedWhenManaged, False,
      XmNsaveUnder, True,
      NULL);
  }
  if (!msgbox)
    return IUP_NOERROR;

  value = iupAttribGetStr(ih, "DIALOGTYPE");
  if (iupStrEqualNoCase(value, "ERROR"))
    type = XmDIALOG_ERROR;
  else if (iupStrEqualNoCase(value, "WARNING"))
    type = XmDIALOG_WARNING;
  else if (iupStrEqualNoCase(value, "INFORMATION"))
    type = XmDIALOG_INFORMATION;
  else if (iupStrEqualNoCase(value, "QUESTION"))
    type = XmDIALOG_QUESTION;


  value = iupAttribGet(ih, "TITLE");
  if (value)
    iupmotSetString(msgbox, XmNdialogTitle, value);
  else
  {
    if (parent)
    {
      XmString title;
      XtVaGetValues(parent, XmNdialogTitle, &title, NULL);
      XtVaSetValues(msgbox, XmNdialogTitle, title, NULL);
    }
  }

  value = iupAttribGet(ih, "VALUE");
  if (value)
    iupmotSetString(msgbox, XmNmessageString, value);

  XtVaSetValues(msgbox,
                XmNdialogType, type,
                XmNdialogStyle, style,
                XmNautoUnmanage, False,
                XmNnoResize, True,
                NULL);

  value = iupAttribGetStr(ih, "BUTTONS");
  if (iupStrEqualNoCase(value, "OK"))
  {
    XtUnmanageChild(XmMessageBoxGetChild(msgbox, XmDIALOG_CANCEL_BUTTON));
    num_but = 1;
  }
  else if (iupStrEqualNoCase(value, "YESNO"))
  {
    iupmotSetString(msgbox, XmNokLabelString, iupStrMessageGet("IUP_YES"));
    iupmotSetString(msgbox, XmNcancelLabelString, iupStrMessageGet("IUP_NO"));
  }

  if (!IupGetCallback(ih, "HELP_CB"))
    XtUnmanageChild(XmMessageBoxGetChild(msgbox, XmDIALOG_HELP_BUTTON));

  if (num_but == 2 && iupAttribGetInt(ih, "BUTTONDEFAULT") == 2)
    XtVaSetValues(msgbox, XmNdefaultButtonType, XmDIALOG_CANCEL_BUTTON, NULL);
  else
    XtVaSetValues(msgbox, XmNdefaultButtonType, XmDIALOG_OK_BUTTON, NULL);

  XtAddCallback(msgbox, XmNokCallback, (XtCallbackProc)motMessageDlgCallback, (XtPointer)ih);
  XtAddCallback(msgbox, XmNcancelCallback, (XtCallbackProc)motMessageDlgCallback, (XtPointer)ih);
  XtAddCallback(msgbox, XmNhelpCallback, (XtCallbackProc)motMessageDlgHelpCallback, (XtPointer)ih);

  XmAddWMProtocolCallback(dialog, iupmot_wm_deletewindow, motMessageDlgDeleteWindowCallback, (XtPointer)ih);
  XtManageChild(msgbox);

  XtRealizeWidget(dialog);
  ih->handle = dialog;
  iupDialogUpdatePosition(ih);
  ih->handle = NULL;  /* reset handle */

  if (style == XmDIALOG_MODELESS)
    XtPopup(dialog, XtGrabExclusive);

  /* while the user hasn't provided an answer, simulate main loop.
  ** The answer changes as soon as the user selects one of the
  ** buttons and the callback routine changes its value. */
  iupAttribSetStr(ih, "BUTTONRESPONSE", NULL);
  while (iupAttribGet(ih, "BUTTONRESPONSE") == NULL)
    XtAppProcessEvent(iupmot_appcontext, XtIMAll);

  if (!iupAttribGet(ih, "_IUP_WM_DELETE"))
  {
    XtUnmanageChild(msgbox);

    if (style == XmDIALOG_MODELESS)
    {
      XtPopdown(dialog);
      XtDestroyWidget(dialog);
    }
  }

  return IUP_NOERROR;
}