Exemplo n.º 1
0
int item_saveas_action_cb(Ihandle* item_saveas)
{
  Ihandle* multitext = IupGetDialogChild(item_saveas, "MULTITEXT");
  Ihandle *filedlg = IupFileDlg();
  IupSetAttribute(filedlg, "DIALOGTYPE", "SAVE");
  IupSetAttribute(filedlg, "FILTER", "*.txt");
  IupSetAttribute(filedlg, "FILTERINFO", "Text Files");
  IupSetAttributeHandle(filedlg, "PARENTDIALOG", IupGetDialog(item_saveas));

  IupPopup(filedlg, IUP_CENTERPARENT, IUP_CENTERPARENT);

  if (IupGetInt(filedlg, "STATUS") != -1)
  {
    Ihandle* config = (Ihandle*)IupGetAttribute(multitext, "CONFIG");
    char* filename = IupGetAttribute(filedlg, "VALUE");
    char* str = IupGetAttribute(multitext, "VALUE");
    int count = IupGetInt(multitext, "COUNT");
    write_file(filename, str, count);

    IupConfigRecentUpdate(config, filename);
  }

  IupDestroy(filedlg);
  return IUP_DEFAULT;
}
Exemplo n.º 2
0
int select_file(Ihandle* parent_dlg, int is_open)
{
  Ihandle* config = (Ihandle*)IupGetAttribute(parent_dlg, "CONFIG");
  Ihandle* canvas = IupGetDialogChild(parent_dlg, "CANVAS");
  const char* dir = IupConfigGetVariableStr(config, "MainWindow", "LastDirectory");

  Ihandle* filedlg = IupFileDlg();
  if (is_open)
    IupSetAttribute(filedlg, "DIALOGTYPE", "OPEN");
  else
  {
    IupSetAttribute(filedlg, "DIALOGTYPE", "SAVE");
    IupSetStrAttribute(filedlg, "FILE", IupGetAttribute(canvas, "FILENAME"));
  }
  IupSetAttribute(filedlg, "EXTFILTER", "Image Files|*.bmp;*.jpg;*.png;*.tif;*.tga|All Files|*.*|");
  IupSetStrAttribute(filedlg, "DIRECTORY", dir);
  IupSetAttributeHandle(filedlg, "PARENTDIALOG", parent_dlg);

  IupPopup(filedlg, IUP_CENTERPARENT, IUP_CENTERPARENT);
  if (IupGetInt(filedlg, "STATUS") != -1)
  {
    char* filename = IupGetAttribute(filedlg, "VALUE");
    if (is_open)
      open_file(parent_dlg, filename);
    else
      saveas_file(canvas, filename);

    dir = IupGetAttribute(filedlg, "DIRECTORY");
    IupConfigSetVariableStr(config, "MainWindow", "LastDirectory", dir);
  }

  IupDestroy(filedlg);
  return IUP_DEFAULT;
}
Exemplo n.º 3
0
int item_open_action_cb(Ihandle* item_open)
{
  Ihandle* multitext = IupGetDialogChild(item_open, "MULTITEXT");
  Ihandle *filedlg = IupFileDlg();
  IupSetAttribute(filedlg, "DIALOGTYPE", "OPEN");
  IupSetAttribute(filedlg, "FILTER", "*.txt");
  IupSetAttribute(filedlg, "FILTERINFO", "Text Files");
  IupSetAttributeHandle(filedlg, "PARENTDIALOG", IupGetDialog(item_open));

  IupPopup(filedlg, IUP_CENTERPARENT, IUP_CENTERPARENT);

  if (IupGetInt(filedlg, "STATUS") != -1)
  {
    char* filename = IupGetAttribute(filedlg, "VALUE");
    char* str = read_file(filename);
    if (str)
    {
      IupSetStrAttribute(multitext, "VALUE", str);
      free(str);
    }
  }

  IupDestroy(filedlg);
  return IUP_DEFAULT;
}
Exemplo n.º 4
0
static void new_file(char* dialogtype, int preview)
{
  Ihandle *dlg = IupFileDlg(); 

  IupSetAttribute(dlg, "PARENTDIALOG", "_MAIN_DIALOG_TEST_");
  IupSetAttribute(dlg, "DIALOGTYPE", dialogtype);
  IupSetAttribute(dlg, "TITLE", "IupFileDlg Test");
  IupSetAttribute(dlg, "DIRECTORY", "/tecgraf/iup");
  if (strcmp(dialogtype, "DIR")!=0)
  {
    IupSetAttributes(dlg, "FILTER = \"*.bmp\", FILTERINFO = \"Bitmap Files\"");
    IupSetAttribute(dlg, "EXTFILTER", "Text files|*.txt;*.doc|Image files|*.jpg;*.bmp;*.gif|");
//    IupSetAttribute(dlg, "FILE", "/tecgraf/im/test.bmp");
    IupSetAttribute(dlg, "FILE", "test.bmp");
  }
  IupSetCallback(dlg, "HELP_CB", (Icallback)help_cb);
//  IupSetAttributes(dlg, "FILE = \"\\tecgraf\\iup\\test.bmp\""); // OK
//  IupSetAttributes(dlg, "FILE = \"/tecgraf/iup/test.bmp\""); // OK
//  IupSetAttributes(dlg, "FILE = \"test.bmp\", DIRECTORY = \"/tecgraf/iup\"");   // OK
//  IupSetAttributes(dlg, "FILE = \"test.bmp\", DIRECTORY = \"\\tecgraf\\iup\"");  // OK
//  IupSetAttribute(dlg, "NOCHANGEDIR", "NO");
//  IupSetAttribute(dlg, "MULTIPLEFILES", "YES");

  if (preview)
  {
    IupSetAttribute(dlg, "SHOWPREVIEW", "YES");
    IupSetCallback(dlg, "FILE_CB", (Icallback)file_cb);

#ifdef USE_OPENGL
    if (preview==2)
    {
      Ihandle* glcanvas = IupGLCanvas(NULL);
      IupSetAttribute(glcanvas, "BUFFER", "DOUBLE");
      IupSetAttributeHandle(dlg, "PREVIEWGLCANVAS", glcanvas);
    }
#endif
  }
  
  IupPopup(dlg, IUP_CURRENT, IUP_CURRENT); 

  switch(IupGetInt(dlg, "STATUS"))
  {
    case 1: 
      printf("OK\n");
      printf("  New file - VALUE(%s)\n", IupGetAttribute(dlg, "VALUE")); 
      break; 
    case 0 : 
      printf("OK\n");
      printf("  File exists - VALUE(%s)\n", IupGetAttribute(dlg, "VALUE"));
      break; 
    case -1 : 
      printf("CANCEL\n");
      break; 
  }

  IupDestroy(dlg);
}
Exemplo n.º 5
0
/* Dialogo de selecao de arquivo  */
static char * get_file_name( void )
{
  Ihandle* getfile = IupFileDlg();
  char* filename = NULL;

  IupSetAttribute(getfile, IUP_TITLE, "Abertura de arquivo"  );
  IupSetAttribute(getfile, IUP_DIALOGTYPE, IUP_OPEN);
  IupSetAttribute(getfile, IUP_FILTER, "*.rt4");
  IupSetAttribute(getfile, IUP_FILTERINFO, "Arquivo de cena (*.rt4)");
  IupPopup(getfile, IUP_CENTER, IUP_CENTER);  /* o posicionamento nao esta sendo respeitado no Windows */

  filename = IupGetAttribute(getfile, IUP_VALUE);
  return filename;
}
Exemplo n.º 6
0
/* captura um nome para um arquivo */
static char * get_new_file_name( void )
{
  Ihandle* getfile = IupFileDlg();
  char* filename = NULL;

  IupSetAttribute(getfile, IUP_TITLE, "Salva arquivo"  );
  IupSetAttribute(getfile, IUP_DIALOGTYPE, IUP_SAVE);
  IupSetAttribute(getfile, IUP_FILTER, "*.bmp");
  IupSetAttribute(getfile, IUP_FILTERINFO, "Arquivo de imagem (*.bmp)");
  IupPopup(getfile, IUP_CENTER, IUP_CENTER);  /* o posicionamento nao esta sendo respeitado no Windows */

  filename = IupGetAttribute(getfile, IUP_VALUE);
  return filename;
}
Exemplo n.º 7
0
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;
}
Exemplo n.º 8
0
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;
}
Exemplo n.º 9
0
int item_saveas_action_cb(Ihandle* item_saveas)
{
  Ihandle* multitext = IupGetDialogChild(item_saveas, "MULTITEXT");
  Ihandle *filedlg = IupFileDlg();
  IupSetAttribute(filedlg, "DIALOGTYPE", "SAVE");
  IupSetAttribute(filedlg, "EXTFILTER", "Text Files|*.txt|All Files|*.*|");
  IupSetAttributeHandle(filedlg, "PARENTDIALOG", IupGetDialog(item_saveas));
  IupSetStrAttribute(filedlg, "FILE", IupGetAttribute(multitext, "FILENAME"));

  IupPopup(filedlg, IUP_CENTERPARENT, IUP_CENTERPARENT);

  if (IupGetInt(filedlg, "STATUS") != -1)
  {
    char* filename = IupGetAttribute(filedlg, "VALUE");
    saveas_file(multitext, filename);
  }

  IupDestroy(filedlg);
  return IUP_DEFAULT;
}
Exemplo n.º 10
0
int item_open_action_cb(Ihandle* item_open)
{
  Ihandle *filedlg;

  if (!save_check(item_open))
    return IUP_DEFAULT;

  filedlg = IupFileDlg();
  IupSetAttribute(filedlg, "DIALOGTYPE", "OPEN");
  IupSetAttribute(filedlg, "EXTFILTER", "Text Files|*.txt|All Files|*.*|");
  IupSetAttributeHandle(filedlg, "PARENTDIALOG", IupGetDialog(item_open));

  IupPopup(filedlg, IUP_CENTERPARENT, IUP_CENTERPARENT);
  if (IupGetInt(filedlg, "STATUS") != -1)
  {
    char* filename = IupGetAttribute(filedlg, "VALUE");
    open_file(item_open, filename);
  }

  IupDestroy(filedlg);
  return IUP_DEFAULT;
}
Exemplo n.º 11
0
int IupGetFile(char* filename)
{
  Ihandle *dlg = 0;
  int ret;
  char filter[4096] = "*.*";
  static char dir[4096] = "";  /* static will make the dir persist from one call to another if not defined */

  if (!filename) return -1;

  dlg = IupFileDlg();

  iupStrSplitFileName(filename, dir, filter);

  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_CENTERPARENT, IUP_CENTERPARENT);

  ret = IupGetInt(dlg, "STATUS");
  if (ret != -1)
  {
    char* value = IupGetAttribute(dlg, "VALUE");
    if (value) 
    {
      strcpy(filename, value);
      iupStrSplitFileName(filename, dir, NULL);
    }
  }

  IupDestroy(dlg);

  return ret;
}
Exemplo n.º 12
0
static void CreateFileDlg(void)
{
  lua_pushusertag(IupFileDlg(), iuplua_tag);
}