コード例 #1
0
ファイル: iup_list.c プロジェクト: defdef/iup
static int iListSetRemoveItemAttrib(Ihandle* ih, const char* value)
{
  if (!ih->handle)  /* do not do the action before map */
    return 0;
  if (!value || iupStrEqualNoCase(value, "ALL"))
  {
    iupdrvListRemoveAllItems(ih);
    iupAttribSet(ih, "_IUPLIST_OLDVALUE", NULL);
  }
  else
  {
    int id;
    if (iupStrToInt(value, &id))
    {
      int pos = iupListGetPosAttrib(ih, id);
      if (pos >= 0)
        iupdrvListRemoveItem(ih, pos);
    }
  }
  return 0;
}
コード例 #2
0
static int iMatrixListCheckDelete(Ihandle *ih)
{
  if (IupGetInt(ih, "SHOWDELETE"))
    return 1;
  else
  {
    char* value = iupAttribGet(ih, "_IUPMTXLIST_DELETE");
    if (value)
    {
      int t, diff;
      iupStrToInt(value, &t);
      diff = (int)clock() - t;

      iupAttribSet(ih, "_IUPMTXLIST_DELETE", NULL);

      if (diff < 200)
        return 1;
    }
    return 0;
  }
}
コード例 #3
0
ファイル: iup_list.c プロジェクト: gcfavorites/tastools
int iupListSetIdValueAttrib(Ihandle* ih, const char* name_id, const char* value)
{
  int pos;
  if (iupStrToInt(name_id, &pos))
  {
    int count = iupdrvListGetCount(ih);

    pos--; /* IUP starts at 1 */

    if (!value)
    {
      if (pos >= 0 && pos <= count-1)
      {
        if (pos == 0)
          iupdrvListRemoveAllItems(ih);
        else
        {
          int i = pos;
          while (i < count)
          {
            iupdrvListRemoveItem(ih, pos);
            i++;
          }
        }
      }
    }
    else
    {
      if (pos >= 0 && pos <= count-1)
      {
        iupdrvListRemoveItem(ih, pos);
        iupdrvListInsertItem(ih, pos, value);
      }
      else if (pos == count)
        iupdrvListAppendItem(ih, value);
    }
  }
  return 1;
}
コード例 #4
0
ファイル: iupwin_dialog.c プロジェクト: svn2github/iup-iup
static int winDialogSetLayerAlphaAttrib(Ihandle *ih, const char *value)
{
  if (value && iupAttribGetInt(ih, "LAYERED"))
  {
    static winSetLayeredWindowAttributes mySetLayeredWindowAttributes = NULL;

    int alpha;
    if (!iupStrToInt(value, &alpha))
      return 0;

    if (!mySetLayeredWindowAttributes)
    {
      HMODULE hinstDll = LoadLibrary("user32.dll");
      if (hinstDll)
        mySetLayeredWindowAttributes = (winSetLayeredWindowAttributes)GetProcAddress(hinstDll, "SetLayeredWindowAttributes");
    }

    if (mySetLayeredWindowAttributes)
      mySetLayeredWindowAttributes(ih->handle, 0, (BYTE)alpha, LWA_ALPHA);
  }
  return 1;
}
コード例 #5
0
ファイル: iupmot_list.c プロジェクト: Vulcanior/IUP
static int motListSetSpacingAttrib(Ihandle* ih, const char* value)
{
  if (ih->data->is_dropdown)
    return 0;

  if (!iupStrToInt(value, &ih->data->spacing))
    ih->data->spacing = 0;

  if (ih->handle)
  {
    Widget list = ih->handle;
    if (ih->data->has_editbox)
      XtVaGetValues(ih->handle, XmNlist, &list, NULL);

    XtVaSetValues(list, XmNlistSpacing, ih->data->spacing*2, 
                        XmNlistMarginWidth, ih->data->spacing, 
                        XmNlistMarginHeight, ih->data->spacing, 
                        NULL);
    return 0;
  }
  else
    return 1; /* store until not mapped, when mapped will be set again */
}
コード例 #6
0
static int iMatrixSetRedoAttrib(Ihandle* ih, const char* value)
{
  ImatExData* matex_data = (ImatExData*)iupAttribGet(ih, "_IUP_MATEX_DATA");
  int undo_stack_count = matex_data->undo_stack? iupArrayCount(matex_data->undo_stack): 0;
  if (undo_stack_count && matex_data->undo_stack_pos<undo_stack_count)
  {
    int i, count = 1, total_cell_count = 0, undo_stack_count = iupArrayCount(matex_data->undo_stack);
    IundoData* undo_stack_data = (IundoData*)iupArrayGetData(matex_data->undo_stack);

    iupStrToInt(value, &count);
    if (count > undo_stack_count - matex_data->undo_stack_pos)
      count = undo_stack_count - matex_data->undo_stack_pos;

    for (i=0; i<count; i++)
      total_cell_count += undo_stack_data[matex_data->undo_stack_pos + i].cell_count;

    iMatrixSetUndoRedoAttrib(ih, "NO");  /* Disable Undo/Redo systrem during restore */
    iupMatrixExBusyStart(matex_data, total_cell_count, "REDO");

    for (i=0; i<count; i++)
    {
      if (!iMatrixExUndoDataSwap(matex_data, &(undo_stack_data[matex_data->undo_stack_pos + i])))
      {
        matex_data->undo_stack_pos += i;
        iMatrixSetUndoRedoAttrib(ih, "Yes");
        return 0;
      }
    }

    iupMatrixExBusyEnd(matex_data);
    iMatrixSetUndoRedoAttrib(ih, "Yes");
    matex_data->undo_stack_pos += i;

    iupBaseCallValueChangedCb(ih);
  }
  return 0;
}
コード例 #7
0
ファイル: iup_mask.c プロジェクト: DavidPhillipOster/IupCocoa
int iupMaskCheck(Imask* mask, const char *val)
{
  int ret;

  /* empty text or no mask */
  if (!val || !(*val) || !mask) 
    return 1;

  ret = iupMaskMatch(val,mask->fsm,0,NULL,NULL,NULL,mask->casei);
  if (ret == IMASK_PARTIALMATCH)
    return -1;
  if (ret != (int)strlen(val))
    return 0;

  switch(mask->type)
  {
  case 'I':
    {
      int ival = 0;
      iupStrToInt(val, &ival);
      if(ival < mask->imin || ival > mask->imax)
        return 0;
      break;
    }
  case 'F':
    {
      float fval = 0;
      iupStrToFloat(val, &fval);
      if(fval < mask->fmin || fval > mask->fmax)
        return 0;
      break;
    }
  }

  return 1;
}
コード例 #8
0
ファイル: iupmat_numlc.c プロジェクト: Archs/iup-aio
int iupMatrixSetNumColAttrib(Ihandle* ih, const char* value)
{
  int num = 0;
  if (iupStrToInt(value, &num))
  {
    if (num < 0) num = 0;

    num++; /* add room for title column */

    /* can be set before map */
    if (ih->handle)
    {
      int base;  /* base is after the end */
      if (num >= ih->data->columns.num) /* add or alloc */
        base = ih->data->columns.num;
      else
        base = num;
      iupMatrixMemReAllocColumns(ih, ih->data->columns.num, num, base);
    }

    ih->data->columns.num = num;
    if (ih->data->columns.num_noscroll > ih->data->columns.num)
      ih->data->columns.num_noscroll = ih->data->columns.num;
    ih->data->need_calcsize = 1;

    if (ih->data->columns.focus_cell >= ih->data->columns.num)
      ih->data->columns.focus_cell = ih->data->columns.num-1;
    if (ih->data->columns.focus_cell <= 0)
      ih->data->columns.focus_cell = 1;

    if (ih->handle)
      iupMatrixDraw(ih, 1);
  }

  return 0;
}
コード例 #9
0
ファイル: iupmot_image.c プロジェクト: svn2github/iup-github
void* iupdrvImageLoad(const char* name, int type)
{
  if (type == IUPIMAGE_CURSOR)
  {
    Cursor cursor = 0;
    int id;
    if (iupStrToInt(name, &id))
      cursor = XCreateFontCursor(iupmot_display, id);
    return (void*)cursor;
  }
  else /* IUPIMAGE_IMAGE or IUPIMAGE_ICON */
  {
    Screen* screen = ScreenOfDisplay(iupmot_display, iupmot_screen);
  	Pixmap pixmap = XmGetPixmap(screen, (char*)name, BlackPixelOfScreen(screen), WhitePixelOfScreen(screen));
    if (pixmap == XmUNSPECIFIED_PIXMAP)
    {
	    unsigned int width, height;
	    int hotx, hoty;
      pixmap = 0;
    	XReadBitmapFile(iupmot_display, RootWindow(iupmot_display,iupmot_screen), name, &width, &height, &pixmap, &hotx, &hoty);
    }
  	return (void*)pixmap;
  }
}
コード例 #10
0
ファイル: iupmatex_visible.c プロジェクト: mwoz/Hildim.Source
int iupMatrixExIsLineVisible(Ihandle* ih, int lin)
{
  int height = 0;
  char* value;

  if (lin==0)
    return (IupGetIntId(ih, "RASTERHEIGHT", 0) != 0);

  value = iupAttribGetId(ih, "HEIGHT", lin);
  if(!value)
  {
    value = iupAttribGetId(ih, "RASTERHEIGHT", lin);
    if(!value)
      return 1;
  }

  if (iupStrToInt(value, &height)==1)
  {
    if (height==0)
      return 0;
  }

  return 1;
}
コード例 #11
0
ファイル: iupwin_filedlg.c プロジェクト: Vulcanior/IUP
static int winFileDlgPopup(Ihandle *ih, int x, int y)
{
  InativeHandle* parent = iupDialogGetNativeParent(ih);
  OPENFILENAME openfilename;
  int result, dialogtype;
  char *value, *initial_dir=NULL;
  TCHAR* extfilter = NULL;

  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;

  if (dialogtype == IUP_DIALOGDIR)
  {
    winFileDlgGetFolder(ih);
    return IUP_NOERROR;
  }

  /* if NOT set will NOT be Modal */
  /* anyway it will be modal only relative to its parent */
  if (!parent)
    parent = GetActiveWindow();

  ZeroMemory(&openfilename, sizeof(OPENFILENAME));
  openfilename.lStructSize = sizeof(OPENFILENAME);
  openfilename.hwndOwner = parent;

  value = iupAttribGet(ih, "EXTFILTER");
  if (value)
  {
    int index;
    extfilter = winFileDlgStrReplaceSeparator(iupwinStrToSystem(value));
    openfilename.lpstrFilter = extfilter;

    value = iupAttribGet(ih, "FILTERUSED");
    if (iupStrToInt(value, &index))
      openfilename.nFilterIndex = index;
    else
      openfilename.nFilterIndex = 1;
  }
  else 
  {
    value = iupAttribGet(ih, "FILTER");
    if (value)
    {
      TCHAR *winfo, *wvalue;
      int sz1, sz2;
      char* info = iupAttribGet(ih, "FILTERINFO");
      if (!info)
        info = value;

      winfo = iupwinStrToSystem(info);
      wvalue = iupwinStrToSystem(value);

      /* concat FILTERINFO+FILTER */
      sz1 = lstrlen(winfo)+1; /* each part has a terminator */
      sz2 = lstrlen(wvalue)+1;
      extfilter = (TCHAR*)malloc((sz1+sz2+1)*sizeof(TCHAR));
      memcpy(extfilter, winfo, sz1*sizeof(TCHAR)); /* copy also the terminator */
      memcpy(extfilter+sz1, wvalue, sz2*sizeof(TCHAR));
      extfilter[sz1+sz2] = 0;  /* additional terminator at the end */

      openfilename.lpstrFilter = extfilter;
      openfilename.nFilterIndex = 1;
    }
  }

  openfilename.lpstrFile = (TCHAR*)malloc((IUP_MAX_FILENAME_SIZE+1)*sizeof(TCHAR));
  value = iupAttribGet(ih, "FILE");
  if (value)
  {
    iupwinStrCopy(openfilename.lpstrFile, value, IUP_MAX_FILENAME_SIZE);
    winFileDlgStrReplacePathSlash(openfilename.lpstrFile);
  }
  else
    openfilename.lpstrFile[0] = 0;

  openfilename.nMaxFile = IUP_MAX_FILENAME_SIZE;

  /* only supports extensions with up to three characters, should NOT include the period */
  openfilename.lpstrDefExt = iupwinStrToSystem(iupAttribGet(ih, "EXTDEFAULT"));

  initial_dir = iupStrDup(iupAttribGet(ih, "DIRECTORY"));
  openfilename.lpstrInitialDir = iupwinStrToSystemFilename(initial_dir);
  if (openfilename.lpstrInitialDir)
    winFileDlgStrReplacePathSlash((TCHAR*)openfilename.lpstrInitialDir);

  openfilename.lpstrTitle = iupwinStrToSystem(iupAttribGet(ih, "TITLE"));
  openfilename.Flags = OFN_PATHMUSTEXIST | OFN_HIDEREADONLY;

  if (!iupAttribGetBoolean(ih, "NOOVERWRITEPROMPT"))
    openfilename.Flags |= OFN_OVERWRITEPROMPT;

  if (iupAttribGetBoolean(ih, "SHOWHIDDEN"))
    openfilename.Flags |= OFN_FORCESHOWHIDDEN;

  value = iupAttribGet(ih, "ALLOWNEW");
  if (!value)
  {
    if (dialogtype == IUP_DIALOGSAVE)
      value = "YES";
    else
      value = "NO";
  }
  if (iupStrBoolean(value))
    openfilename.Flags |= OFN_CREATEPROMPT;
  else
    openfilename.Flags |= OFN_FILEMUSTEXIST;

  if (iupAttribGetBoolean(ih, "NOCHANGEDIR"))
    openfilename.Flags |= OFN_NOCHANGEDIR;

  if (iupAttribGetBoolean(ih, "MULTIPLEFILES"))
     openfilename.Flags |= OFN_ALLOWMULTISELECT;

  openfilename.lpfnHook = winFileDlgSimpleHook;
  openfilename.Flags |= OFN_ENABLEHOOK | OFN_EXPLORER | OFN_ENABLESIZING;
  openfilename.lCustData = (LPARAM)ih;

  if (iupAttribGetBoolean(ih, "SHOWPREVIEW") && IupGetCallback(ih, "FILE_CB"))
  {
    openfilename.Flags |= OFN_ENABLETEMPLATE;
    openfilename.hInstance = iupwin_dll_hinstance? iupwin_dll_hinstance: iupwin_hinstance;
    openfilename.lpTemplateName = TEXT("iupPreviewDlg");
    openfilename.lpfnHook = winFileDlgPreviewHook;
  }

  if (IupGetCallback(ih, "HELP_CB"))
    openfilename.Flags |= OFN_SHOWHELP;

  if (dialogtype == IUP_DIALOGOPEN)
    result = GetOpenFileName(&openfilename);
  else
    result = GetSaveFileName(&openfilename);

  if (result)
  {
    if (iupAttribGetBoolean(ih, "MULTIPLEFILES"))
    {
      /* If there is more than one file, replace terminator by the separator */
      if (openfilename.lpstrFile[openfilename.nFileOffset-1] == 0 && 
          openfilename.nFileOffset>0) 
      {
        int i = 0;
        int count = 0;

        char* dir = iupwinStrFromSystemFilename(openfilename.lpstrFile);  /* already is the directory, but without the last separator */
        iupAttribSetStrf(ih, "DIRECTORY", "%s\\", dir);  /* add the last separator */

        /* first the path */
        iupAttribSetStrId(ih, "MULTIVALUE", count, iupAttribGet(ih, "DIRECTORY"));  /* here count=0 always */
        count++;

        while (openfilename.lpstrFile[i] != 0 || openfilename.lpstrFile[i + 1] != 0)
        {
          if (openfilename.lpstrFile[i] == 0)
          {
            iupAttribSetStrId(ih, "MULTIVALUE", count, iupwinStrFromSystemFilename(openfilename.lpstrFile + i + 1));
            count++;

            openfilename.lpstrFile[i] = TEXT('|');
          }

          i++;
        }

        iupAttribSetInt(ih, "MULTIVALUECOUNT", count);
        openfilename.lpstrFile[i] = TEXT('|');  /* one last at the end */

        iupAttribSetStr(ih, "VALUE", iupwinStrFromSystemFilename(openfilename.lpstrFile));  /* here file was already modified to match the IUP format */
      }
      else
      {
        /* if there is only one file selected the returned value is different 
           and includes just that file */
        char* filename = iupwinStrFromSystemFilename(openfilename.lpstrFile);
        char* dir = iupStrFileGetPath(filename);
        int dir_len = (int)strlen(dir);
        iupAttribSetStr(ih, "DIRECTORY", dir);

        iupAttribSetStrId(ih, "MULTIVALUE", 0, dir);
        iupAttribSetStrId(ih, "MULTIVALUE", 1, filename + dir_len);

        iupAttribSetStr(ih, "VALUE", filename);  /* here value is not separated by '|' */

        iupAttribSetInt(ih, "MULTIVALUECOUNT", 2);
        free(dir);
      }

      iupAttribSet(ih, "STATUS", "0");
      iupAttribSet(ih, "FILEEXIST", "YES");
    }
    else
    {
      char* filename = iupwinStrFromSystemFilename(openfilename.lpstrFile);
      char* dir = iupStrFileGetPath(filename);
      iupAttribSetStr(ih, "DIRECTORY", dir);
      free(dir);

      if (winIsFile(openfilename.lpstrFile))  /* check if file exists */
      {
        iupAttribSet(ih, "FILEEXIST", "YES");
        iupAttribSet(ih, "STATUS", "0");
      }
      else
      {
        iupAttribSet(ih, "FILEEXIST", "NO");
        iupAttribSet(ih, "STATUS", "1");
      }

      iupAttribSetStr(ih, "VALUE", filename);
    }

    iupAttribSetInt(ih, "FILTERUSED", (int)openfilename.nFilterIndex);
  }
  else
  {
    iupAttribSet(ih, "FILTERUSED", NULL);
    iupAttribSet(ih, "VALUE", NULL);
    iupAttribSet(ih, "DIRECTORY", NULL);
    iupAttribSet(ih, "FILEEXIST", NULL);
    iupAttribSet(ih, "STATUS", "-1");
  }

  if (extfilter) free(extfilter);
  if (initial_dir) free(initial_dir);
  if (openfilename.lpstrFile) free(openfilename.lpstrFile);

  return IUP_NOERROR;
}
コード例 #12
0
ファイル: iup_colorbar.c プロジェクト: Airr/iup_mac
static int iColorbarSetPreviewSizeAttrib(Ihandle* ih, const char* value)
{
  if (iupStrToInt(value, &ih->data->preview_size))
    iColorbarRepaint(ih);
  return 0;
}
コード例 #13
0
ファイル: iup_colorbar.c プロジェクト: Airr/iup_mac
static int iColorbarSetNumPartsAttrib(Ihandle* ih, const char* value)
{
  if (iupStrToInt(value, &ih->data->num_parts))
    iColorbarRepaint(ih);
  return 0;
}
コード例 #14
0
ファイル: iup_gridbox.c プロジェクト: defdef/iup
static int iGridBoxSetGapLinAttrib(Ihandle* ih, const char* value)
{
  iupStrToInt(value, &ih->data->gap_lin);
  return 0;
}
コード例 #15
0
ファイル: iupmat_aux.c プロジェクト: svn2github/iup-iup
int iupMatrixAuxGetColumnWidth(Ihandle* ih, int col)
{
  int width = 0, pixels = 0;
  char* str = iupStrGetMemory(100);
  char* value;

  sprintf(str, "WIDTH%d", col);
  value = iupAttribGet(ih, str);
  if (!value)
  {
    sprintf(str, "RASTERWIDTH%d", col);
    value = iupAttribGet(ih, str);
    if (value)
      pixels = 1;
  }

  if (!value)
  {
    if (col == 0)
    {
      /* find the largest title */
      int lin, max_width = 0;
      for(lin = 0; lin < ih->data->lines.num; lin++)
      {
        char* title_value = iupMatrixCellGetValue(ih, lin, 0);
        if (title_value)
        {
          iupdrvFontGetMultiLineStringSize(ih, title_value, &width, NULL);
          if (width > max_width)
            max_width = width;
        }
      }
      width = max_width;
    }
    else
    {
      char* title_value = iupMatrixCellGetValue(ih, 0, col);
      if (title_value)
        iupdrvFontGetMultiLineStringSize(ih, title_value, &width, NULL);
    }
    if (width)
      return width + IMAT_PADDING_W + IMAT_FRAME_W;

    if (col!=0)
      value = iupAttribGetStr(ih, "WIDTHDEF");
  }

  if (iupStrToInt(value, &width))
  {
    if (width <= 0)
      return 0;
    else
    {
      if (pixels)
        return width + IMAT_PADDING_W + IMAT_FRAME_W;
      else
      {
        int charwidth;
        iupdrvFontGetCharSize(ih, &charwidth, NULL);
        return iupWIDTH2RASTER(width, charwidth) + IMAT_PADDING_W + IMAT_FRAME_W;
      }
    }
  }
  return 0;
}
コード例 #16
0
ファイル: iupmot_text.c プロジェクト: gcfavorites/tastools
static void motTextModifyVerifyCallback(Widget w, Ihandle *ih, XmTextVerifyPtr text)
{
  int start, end, key = 0;
  char *value, *new_value, *insert_value;
  KeySym motcode = 0;
  IFnis cb;

  if (iupAttribGet(ih, "_IUPMOT_DISABLE_TEXT_CB"))
    return;

  if (iupAttribGet(ih, "_IUPMOT_SPIN_DISABLE_TEXT_CB"))
  {
    if (iupAttribGet(ih, "_IUPMOT_SPIN_NOAUTO"))
      text->doit = False;

    iupAttribSetStr(ih, "_IUPMOT_SPIN_DISABLE_TEXT_CB", NULL);
    return;
  }

  cb = (IFnis)IupGetCallback(ih, "ACTION");
  if (!cb && !ih->data->mask)
    return;

  if (text->event && text->event->type == KeyPress)
  {
    unsigned int state = ((XKeyEvent*)text->event)->state;
    if (state & ControlMask ||  /* Ctrl */
        state & Mod1Mask || 
        state & Mod5Mask ||  /* Alt */
        state & Mod4Mask) /* Apple/Win */
      return;

    motcode = XKeycodeToKeysym(iupmot_display, ((XKeyEvent*)text->event)->keycode, 0);
  }

  value = XmTextGetString(ih->handle);
  start = text->startPos;
  end = text->endPos;
  insert_value = text->text->ptr;

  if (motcode == XK_Delete)
  {
    new_value = value;
    iupStrRemove(value, start, end, 1);
  }
  else if (motcode == XK_BackSpace)
  {
    new_value = value;
    iupStrRemove(value, start, end, -1);
  }
  else
  {
    if (!value)
      new_value = iupStrDup(insert_value);
    else if (insert_value)
      new_value = iupStrInsert(value, insert_value, start, end);
    else
      new_value = value;
  }

  if (insert_value && insert_value[0]!=0 && insert_value[1]==0)
    key = insert_value[0];

  if (ih->data->mask && iupMaskCheck(ih->data->mask, new_value)==0)
  {
    if (new_value != value) free(new_value);
    XtFree(value);
    text->doit = False;     /* abort processing */
    return;
  }

  if (cb)
  {
    int cb_ret = cb(ih, key, (char*)new_value);
    if (cb_ret==IUP_IGNORE)
      text->doit = False;     /* abort processing */
    else if (cb_ret==IUP_CLOSE)
    {
      IupExitLoop();
      text->doit = False;     /* abort processing */
    }
    else if (cb_ret!=0 && key!=0 && 
             cb_ret != IUP_DEFAULT && cb_ret != IUP_CONTINUE)  
    {
      insert_value[0] = (char)cb_ret;  /* replace key */
    }
  }

  if (text->doit)
  {
    /* Spin is not automatically updated when you directly edit the text */
    Widget spinbox = (Widget)iupAttribGet(ih, "_IUP_EXTRAPARENT");
    if (spinbox && XmIsSpinBox(spinbox) && !iupAttribGet(ih, "_IUPMOT_SPIN_NOAUTO"))
    {
      int pos;
      if (iupStrToInt(new_value, &pos))
      {
        XmTextPosition caret_pos = text->currInsert;
        iupAttribSetStr(ih, "_IUPMOT_DISABLE_TEXT_CB", "1");
        XtVaSetValues(ih->handle, XmNposition, pos, NULL);
        iupAttribSetStr(ih, "_IUPMOT_DISABLE_TEXT_CB", NULL);
        /* do not handle all situations, but handle the basic ones */
        if (text->startPos == text->endPos) /* insert */
          caret_pos++;
        else if (text->startPos < text->endPos && text->startPos < text->currInsert)  /* backspace */
          caret_pos--;
        XmTextSetInsertionPosition(ih->handle, caret_pos);
        text->doit = False;
      }
    }
  }

  if (new_value != value) free(new_value);
  XtFree(value);
  (void)w;
}
コード例 #17
0
static int iButtonSetSpacingAttrib(Ihandle* ih, const char* value)
{
  if (!ih->handle)  /* set only before map */
    iupStrToInt(value, &ih->data->spacing);
  return 0;
}
コード例 #18
0
int iupMatrixGetColumnWidth(Ihandle* ih, int col, int use_value)
{
  int width = 0, pixels = 0;
  char str[100];
  char* value;

  /* can be called for invalid columns (col>numcol) */

  sprintf(str, "WIDTH%d", col);
  value = iupAttribGet(ih, str);
  if (!value)
  {
    sprintf(str, "RASTERWIDTH%d", col);
    value = iupAttribGet(ih, str);
    if (value)
      pixels = 1;
  }

  if (use_value && !value)
  {
    /* Use the titles to define the size */
    if (col == 0)
    {
      if (!ih->data->callback_mode || ih->data->use_title_size)
      {
        /* find the largest title */
        int lin, max_width = 0;
        for(lin = 0; lin < ih->data->lines.num; lin++)
        {
          char* title_value = iupMatrixCellGetValue(ih, lin, 0);
          if (title_value)
          {
            iupdrvFontGetMultiLineStringSize(ih, title_value, &width, NULL);
            if (width > max_width)
              max_width = width;
          }
        }
        width = max_width;
      }
    }
    else if (ih->data->use_title_size && (col>0 && col<ih->data->columns.num))
    {
      char* title_value = iupMatrixCellGetValue(ih, 0, col);
      if (title_value)
        iupdrvFontGetMultiLineStringSize(ih, title_value, &width, NULL);
    }
    if (width)
      return width + IMAT_PADDING_W + IMAT_FRAME_W;

    if (col != 0)
      value = iupAttribGetStr(ih, "WIDTHDEF");
  }

  if (iupStrToInt(value, &width))
  {
    if (width <= 0)
      return 0;
    else
    {
      if (pixels)
        return width + IMAT_PADDING_W + IMAT_FRAME_W;
      else
      {
        int charwidth;
        iupdrvFontGetCharSize(ih, &charwidth, NULL);
        return iupWIDTH2RASTER(width, charwidth) + IMAT_PADDING_W + IMAT_FRAME_W;
      }
    }
  }
  return 0;
}
コード例 #19
0
ファイル: iup_gridbox.c プロジェクト: defdef/iup
static int iGridBoxSetSizeColAttrib(Ihandle* ih, const char* value)
{
  iupStrToInt(value, &ih->data->size_col);
  return 0;
}
コード例 #20
0
ファイル: iupgtk_list.c プロジェクト: svn2github/iup-iup
static int gtkListSetValueAttrib(Ihandle* ih, const char* value)
{
  if (ih->data->has_editbox)
  {
    GtkEntry* entry = (GtkEntry*)iupAttribGet(ih, "_IUPGTK_ENTRY");
    if (!value) value = "";
    iupAttribSetStr(ih, "_IUPGTK_DISABLE_TEXT_CB", "1");
    gtk_entry_set_text(entry, iupgtkStrConvertToUTF8(value));
    iupAttribSetStr(ih, "_IUPGTK_DISABLE_TEXT_CB", NULL);
  }
  else 
  {
    if (ih->data->is_dropdown)
    {
      int pos;
      g_signal_handlers_block_by_func(G_OBJECT(ih->handle), G_CALLBACK(gtkListComboBoxChanged), ih);
      if (iupStrToInt(value, &pos)==1)
      {
        gtk_combo_box_set_active((GtkComboBox*)ih->handle, pos-1);    /* IUP starts at 1 */
        iupAttribSetInt(ih, "_IUPLIST_OLDVALUE", pos);
      }
      else
      {
        gtk_combo_box_set_active((GtkComboBox*)ih->handle, -1);    /* none */
        iupAttribSetStr(ih, "_IUPLIST_OLDVALUE", NULL);
      }
      g_signal_handlers_unblock_by_func(G_OBJECT(ih->handle), G_CALLBACK(gtkListComboBoxChanged), ih);
    }
    else
    {
      GtkTreeSelection* selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(ih->handle));
      if (!ih->data->is_multiple)
      {
        int pos;
        g_signal_handlers_block_by_func(G_OBJECT(selection), G_CALLBACK(gtkListSelectionChanged), ih);
        if (iupStrToInt(value, &pos)==1)
        {
          GtkTreePath* path = gtk_tree_path_new_from_indices(pos-1, -1);   /* IUP starts at 1 */
          gtk_tree_selection_select_path(selection, path);
          gtk_tree_path_free(path);
          iupAttribSetInt(ih, "_IUPLIST_OLDVALUE", pos);
        }
        else
        {
          gtk_tree_selection_unselect_all(selection);
          iupAttribSetStr(ih, "_IUPLIST_OLDVALUE", NULL);
        }
        g_signal_handlers_unblock_by_func(G_OBJECT(selection), G_CALLBACK(gtkListSelectionChanged), ih);
      }
      else
      {
        /* User has changed a multiple selection on a simple list. */
	      int i, len, count;

        g_signal_handlers_block_by_func(G_OBJECT(selection), G_CALLBACK(gtkListSelectionChanged), ih);

        /* Clear all selections */
        gtk_tree_selection_unselect_all(selection);

        if (!value)
        {
          iupAttribSetStr(ih, "_IUPLIST_OLDVALUE", NULL);
          return 0;
        }

	      len = strlen(value);
        count = iupdrvListGetCount(ih);
        if (len < count) 
          count = len;

        /* update selection list */
        for (i = 0; i<count; i++)
        {
          if (value[i]=='+')
          {
            GtkTreePath* path = gtk_tree_path_new_from_indices(i, -1);
            gtk_tree_selection_select_path(selection, path);
            gtk_tree_path_free(path);
          }
        }
        iupAttribStoreStr(ih, "_IUPLIST_OLDVALUE", value);
        g_signal_handlers_unblock_by_func(G_OBJECT(selection), G_CALLBACK(gtkListSelectionChanged), ih);
      }
    }
  }

  return 0;
}
コード例 #21
0
ファイル: iup_cells.c プロジェクト: Vulcanior/IUP
static int iCellsSetNonScrollableLinesAttrib(Ihandle* ih, const char* value)
{
  if (iupStrToInt(value, &ih->data->non_scrollable_lins))
    iCellsRepaint(ih);
  return 0;
}
コード例 #22
0
ファイル: iupmat_aux.c プロジェクト: svn2github/iup-iup
int iupMatrixAuxGetLineHeight(Ihandle* ih, int lin)
{
  int height = 0, pixels = 0;
  char* str = iupStrGetMemory(100);
  char* value;

  sprintf(str, "HEIGHT%d", lin);
  value = iupAttribGet(ih, str);
  if(!value)
  {
    sprintf(str, "RASTERHEIGHT%d", lin);
    value = iupAttribGet(ih, str);
    if(value)
      pixels = 1;
  }

  if (!value)
  {
    if (lin == 0)
    {
      /* find the highest title */
      int col, max_height = 0;
      for(col = 0; col < ih->data->columns.num; col++)
      {
        char* title_value = iupMatrixCellGetValue(ih, 0, col);
        if (title_value)
        {
          iupdrvFontGetMultiLineStringSize(ih, title_value, NULL, &height);
          if (height > max_height)
            max_height = height;
        }
      }
      height = max_height;
    }
    else
    {
      char* title_value = iupMatrixCellGetValue(ih, lin, 0);
      if (title_value)
        iupdrvFontGetMultiLineStringSize(ih, title_value, NULL, &height);
    }
    if (height)
      return height + IMAT_PADDING_H + IMAT_FRAME_H;

    if (lin != 0)
      value = iupAttribGetStr(ih, "HEIGHTDEF");
  }
  
  if (iupStrToInt(value, &height))
  {
    if (height <= 0)
      return 0;
    else
    {
      if (pixels)
        return height + IMAT_PADDING_H + IMAT_FRAME_H;
      else
      {
        int charheight;
        iupdrvFontGetCharSize(ih, NULL, &charheight);
        return iupHEIGHT2RASTER(height, charheight) + IMAT_PADDING_H + IMAT_FRAME_H;
      }
    }
  }
  return 0;
}
コード例 #23
0
ファイル: iup_box.c プロジェクト: mwoz/Hildim.Source
static int iBoxSetGapAttrib(Ihandle* ih, const char* value)
{
  iupStrToInt(value, &ih->data->gap);
  return 0;
}
コード例 #24
0
int iupMatrixGetLineHeight(Ihandle* ih, int lin, int use_value)
{
  int height = 0, pixels = 0;
  char str[100];
  char* value;

  /* can be called for invalid lines (lin>numlin) */

  sprintf(str, "HEIGHT%d", lin);
  value = iupAttribGet(ih, str);
  if(!value)
  {
    sprintf(str, "RASTERHEIGHT%d", lin);
    value = iupAttribGet(ih, str);
    if(value)
      pixels = 1;
  }

  if (use_value && !value)
  {
    /* Use the titles to define the size */
    if (lin == 0)
    {
      if (!ih->data->callback_mode || ih->data->use_title_size)
      {
        /* find the highest title */
        int col, max_height = 0;
        for(col = 0; col < ih->data->columns.num; col++)
        {
          char* title_value = iupMatrixCellGetValue(ih, 0, col);
          if (title_value && title_value[0])
          {
            iupdrvFontGetMultiLineStringSize(ih, title_value, NULL, &height);
            if (height > max_height)
              max_height = height;
          }
        }
        height = max_height;
      }
    }
    else if (ih->data->use_title_size && (lin>0 && lin<ih->data->lines.num))
    {
      char* title_value = iupMatrixCellGetValue(ih, lin, 0);
      if (title_value && title_value[0])
        iupdrvFontGetMultiLineStringSize(ih, title_value, NULL, &height);
    }
    if (height)
      return height + IMAT_PADDING_H + IMAT_FRAME_H;

    if (lin != 0)
      value = iupAttribGetStr(ih, "HEIGHTDEF");
  }
  
  if (iupStrToInt(value, &height))
  {
    if (height <= 0)
      return 0;
    else
    {
      if (pixels)
        return height + IMAT_PADDING_H + IMAT_FRAME_H;
      else
      {
        int charheight;
        iupdrvFontGetCharSize(ih, NULL, &charheight);
        return iupHEIGHT2RASTER(height, charheight) + IMAT_PADDING_H + IMAT_FRAME_H;
      }
    }
  }
  return 0;
}
コード例 #25
0
ファイル: iupgtk_colordlg.c プロジェクト: Airr/iup_mac
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;
}
コード例 #26
0
ファイル: iup_tree.c プロジェクト: LuaDist/iup
InodeHandle* iupTreeGetNodeFromString(Ihandle* ih, const char* name_id)
{
  int id = IUP_INVALID_ID;
  iupStrToInt(name_id, &id);
  return iupTreeGetNode(ih, id);
}
コード例 #27
0
char* iupClassObjectGetAttribute(Ihandle* ih, const char* name, char* *def_value, int *inherit)
{
  IattribFunc* afunc;

  if (ih->iclass->has_attrib_id!=0)
  {
    const char* name_id = iClassFindId(name);
    if (name_id)
    {
      const char* partial_name = iClassCutNameId(name, name_id);
      if (!partial_name)
        partial_name = "IDVALUE";  /* pure numbers are used as attributes in IupList and IupMatrix, 
                                      translate them into IDVALUE. */
      afunc = (IattribFunc*)iupTableGet(ih->iclass->attrib_func, partial_name);
      if (afunc && afunc->flags & IUPAF_HAS_ID)
      {
        *def_value = NULL;  /* id numbered attributes have default value NULL always */
        *inherit = 0;       /* id numbered attributes are NON inheritable always */

        if (afunc->flags & IUPAF_WRITEONLY)
          return NULL;

        if (afunc->get && (ih->handle || afunc->flags & IUPAF_NOT_MAPPED))
        {
          if (afunc->flags & IUPAF_HAS_ID2)
          {
            IattribGetId2Func id2_get = (IattribGetId2Func)afunc->get;
            int id1=IUP_INVALID_ID, id2=IUP_INVALID_ID;
            iupStrToIntInt(name_id, &id1, &id2, ':');
            return id2_get(ih, id1, id2);
          }
          else
          {
            IattribGetIdFunc id_get = (IattribGetIdFunc)afunc->get;
            int id=IUP_INVALID_ID;
            if (iupStrToInt(name_id, &id))
              return id_get(ih, id);
          }
        }
        else
          return NULL;      /* if the function exists, then must return here */
      }
    }
  }

  /* if not has_attrib_id, or not found an ID, or not found the partial name, check using the full name */

  afunc = (IattribFunc*)iupTableGet(ih->iclass->attrib_func, name);
  *def_value = NULL;
  *inherit = 1; /* default is inheritable */
  if (afunc)
  {
    *def_value = iClassGetDefaultValue(afunc);
    *inherit = !(afunc->flags & IUPAF_NO_INHERIT) &&   /* is inheritable */
               !(afunc->flags & IUPAF_NO_STRING);      /* is a string */

    if (afunc->flags & IUPAF_WRITEONLY)
      return NULL;

    if (afunc->get && (ih->handle || afunc->flags & IUPAF_NOT_MAPPED))
    {
      if (afunc->flags & IUPAF_HAS_ID2)
      {
        IattribGetId2Func id2_get = (IattribGetId2Func)afunc->get;
        return id2_get(ih, IUP_INVALID_ID, IUP_INVALID_ID);  /* empty Id */
      }
      else if (afunc->flags & IUPAF_HAS_ID)
      {
        IattribGetIdFunc id_get = (IattribGetIdFunc)afunc->get;
        return id_get(ih, IUP_INVALID_ID);  /* empty Id */
      }
      else
        return afunc->get(ih);
    }
  }
  return NULL;
}
コード例 #28
0
ファイル: iupmot_list.c プロジェクト: Vulcanior/IUP
static int motListSetValueAttrib(Ihandle* ih, const char* value)
{
  if (ih->data->has_editbox)
  {
    Widget cbedit;
    XtVaGetValues(ih->handle, XmNtextField, &cbedit, NULL);
    if (!value) value = "";

    iupAttribSet(ih, "_IUPMOT_DISABLE_TEXT_CB", "1"); /* disable callbacks */

    iupmotTextSetString(cbedit, value);

    iupAttribSet(ih, "_IUPMOT_DISABLE_TEXT_CB", NULL);
  }
  else 
  {
    if (ih->data->is_dropdown)
    {
      int pos;
      if (iupStrToInt(value, &pos)==1)
      {
        XtRemoveCallback(ih->handle, XmNselectionCallback, (XtCallbackProc)motListComboBoxSelectionCallback, (XtPointer)ih);

        XtVaSetValues(ih->handle, XmNselectedPosition, pos-1, NULL);  /* IUP starts at 1 */
        iupAttribSetInt(ih, "_IUPLIST_OLDVALUE", pos);

        XtAddCallback(ih->handle, XmNselectionCallback, (XtCallbackProc)motListComboBoxSelectionCallback, (XtPointer)ih);
      }
    }
    else
    {
      if (!ih->data->is_multiple)
      {
        int pos;
        if (iupStrToInt(value, &pos)==1)
        {
          XmListSelectPos(ih->handle, pos, FALSE);   /* XmListSelectPos starts at 1 */
          iupAttribSetInt(ih, "_IUPLIST_OLDVALUE", pos);
        }
        else
        {
          XmListDeselectAllItems(ih->handle);
          iupAttribSet(ih, "_IUPLIST_OLDVALUE", NULL);
        }
      }
      else
      {
        /* User has changed a multiple selection on a simple list. */
	      int i, count, len;

        /* Clear all selections */
        XmListDeselectAllItems(ih->handle);

        if (!value)
        {
          iupAttribSet(ih, "_IUPLIST_OLDVALUE", NULL);
          return 0;
        }

        XtVaGetValues(ih->handle, XmNitemCount, &count, NULL);
        len = strlen(value);
        if (len < count) 
          count = len;

        XtVaSetValues(ih->handle, XmNselectionPolicy, XmMULTIPLE_SELECT, NULL);

        /* update selection list */
        for (i = 0; i<count; i++)
        {
          if (value[i]=='+')
            XmListSelectPos(ih->handle, i+1, False);  /* XmListSelectPos starts at 1 */
        }

        XtVaSetValues(ih->handle, XmNselectionPolicy, XmEXTENDED_SELECT, 
                                  XmNselectionMode, XmNORMAL_MODE, NULL);  /* must also restore this */
        iupAttribSetStr(ih, "_IUPLIST_OLDVALUE", value);
      }
    }
  }

  return 0;
}
コード例 #29
0
ファイル: iupwin_filedlg.c プロジェクト: LuaDist/iup
static int winFileDlgPopup(Ihandle *ih, int x, int y)
{
  InativeHandle* parent = iupDialogGetNativeParent(ih);
  OPENFILENAME openfilename;
  int result, dialogtype;
  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;

  if (dialogtype == IUP_DIALOGDIR)
  {
    winFileDlgGetFolder(ih);
    return IUP_NOERROR;
  }

  if (!parent)
    parent = GetActiveWindow();  /* if NOT set will NOT be Modal */
                                 /* anyway it will be modal only relative to its parent */

  ZeroMemory(&openfilename, sizeof(OPENFILENAME));
  openfilename.lStructSize = sizeof(OPENFILENAME);
  openfilename.hwndOwner = parent;

  value = iupAttribGet(ih, "EXTFILTER");
  if (value)
  {
    int index;
    openfilename.lpstrFilter = winFileDlgStrReplaceSeparator(value);

    value = iupAttribGet(ih, "FILTERUSED");
    if (iupStrToInt(value, &index))
      openfilename.nFilterIndex = index;
    else
      openfilename.nFilterIndex = 1;
  }
  else 
  {
    value = iupAttribGet(ih, "FILTER");
    if (value)
    {
      int sz1, sz2;
      char* info = iupAttribGet(ih, "FILTERINFO");
      if (!info)
        info = value;

      /* concat FILTERINFO+FILTER */
      sz1 = strlen(info)+1;
      sz2 = strlen(value)+1;
      openfilename.lpstrFilter = (char*)malloc(sz1+sz2+1);
      memcpy((char*)openfilename.lpstrFilter, info, sz1);
      memcpy((char*)openfilename.lpstrFilter+sz1, value, sz2);
      ((char*)openfilename.lpstrFilter)[sz1+sz2] = 0; /* additional 0 at the end */

      openfilename.nFilterIndex = 1;
    }
  }

  openfilename.lpstrFile = (char*)malloc(IUP_MAX_FILENAME_SIZE+1);
  value = iupAttribGet(ih, "FILE");
  if (value)
  {
    strncpy(openfilename.lpstrFile, value, IUP_MAX_FILENAME_SIZE);
    winFileDlgStrReplacePathSlash(openfilename.lpstrFile);
  }
  else
    openfilename.lpstrFile[0] = 0;

  openfilename.nMaxFile = IUP_MAX_FILENAME_SIZE;

  openfilename.lpstrInitialDir = iupStrDup(iupAttribGet(ih, "DIRECTORY"));
  if (openfilename.lpstrInitialDir)
    winFileDlgStrReplacePathSlash((char*)openfilename.lpstrInitialDir);

  openfilename.lpstrTitle = iupAttribGet(ih, "TITLE");
  openfilename.Flags = OFN_PATHMUSTEXIST | OFN_HIDEREADONLY;

  if (!iupAttribGetBoolean(ih, "NOOVERWRITEPROMPT"))
    openfilename.Flags |= OFN_OVERWRITEPROMPT;

  if (iupAttribGetBoolean(ih, "SHOWHIDDEN"))
    openfilename.Flags |= OFN_FORCESHOWHIDDEN;

  value = iupAttribGet(ih, "ALLOWNEW");
  if (!value)
  {
    if (dialogtype == IUP_DIALOGSAVE)
      value = "YES";
    else
      value = "NO";
  }
  if (iupStrBoolean(value))
    openfilename.Flags |= OFN_CREATEPROMPT;
  else
    openfilename.Flags |= OFN_FILEMUSTEXIST;

  if (iupAttribGetBoolean(ih, "NOCHANGEDIR"))
    openfilename.Flags |= OFN_NOCHANGEDIR;

  if (iupAttribGetBoolean(ih, "MULTIPLEFILES"))
     openfilename.Flags |= OFN_ALLOWMULTISELECT;

  openfilename.lpfnHook = winFileDlgSimpleHook;
  openfilename.Flags |= OFN_ENABLEHOOK | OFN_EXPLORER | OFN_ENABLESIZING;
  openfilename.lCustData = (LPARAM)ih;

  if (iupAttribGetBoolean(ih, "SHOWPREVIEW") && IupGetCallback(ih, "FILE_CB"))
  {
    openfilename.Flags |= OFN_ENABLETEMPLATE;
    openfilename.hInstance = iupwin_dll_hinstance? iupwin_dll_hinstance: iupwin_hinstance;
    openfilename.lpTemplateName = "iupPreviewDlg";
    openfilename.lpfnHook = winFileDlgPreviewHook;
  }

  if (IupGetCallback(ih, "HELP_CB"))
    openfilename.Flags |= OFN_SHOWHELP;

  if (dialogtype == IUP_DIALOGOPEN)
    result = GetOpenFileName(&openfilename);
  else
    result = GetSaveFileName(&openfilename);

  if (result)
  {
    if (iupAttribGetBoolean(ih, "MULTIPLEFILES"))
    {
      int i = 0;

      char* dir = iupStrFileGetPath(openfilename.lpstrFile);  /* the first part is the directory already */
      iupAttribStoreStr(ih, "DIRECTORY", dir);
      free(dir);
    
      /* If there is more than one file, replace terminator by the separator */
      if (openfilename.lpstrFile[openfilename.nFileOffset-1] == 0 && 
          openfilename.nFileOffset>0) 
      {
        while (openfilename.lpstrFile[i] != 0 || openfilename.lpstrFile[i+1] != 0)
        {
          if (openfilename.lpstrFile[i]==0)
            openfilename.lpstrFile[i] = '|';
          i++;
        }
        openfilename.lpstrFile[i] = '|';
      }

      iupAttribSetStr(ih, "STATUS", "0");
      iupAttribSetStr(ih, "FILEEXIST", "YES");
    }
    else
    {
      if (iupdrvIsFile(openfilename.lpstrFile))  /* check if file exists */
      {
        char* dir = iupStrFileGetPath(openfilename.lpstrFile);
        iupAttribStoreStr(ih, "DIRECTORY", dir);
        free(dir);

        iupAttribSetStr(ih, "FILEEXIST", "YES");
        iupAttribSetStr(ih, "STATUS", "0");
      }
      else
      {
        iupAttribSetStr(ih, "FILEEXIST", "NO");
        iupAttribSetStr(ih, "STATUS", "1");
      }
    }

    iupAttribStoreStr(ih, "VALUE", openfilename.lpstrFile);
    iupAttribSetInt(ih, "FILTERUSED", (int)openfilename.nFilterIndex);
  }
  else
  {
    iupAttribSetStr(ih, "FILTERUSED", NULL);
    iupAttribSetStr(ih, "VALUE", NULL);
    iupAttribSetStr(ih, "FILEEXIST", NULL);
    iupAttribSetStr(ih, "STATUS", "-1");
  }

  if (openfilename.lpstrFilter) free((char*)openfilename.lpstrFilter);
  if (openfilename.lpstrInitialDir) free((char*)openfilename.lpstrInitialDir);
  if (openfilename.lpstrFile) free(openfilename.lpstrFile);

  return IUP_NOERROR;
}
コード例 #30
0
ファイル: iup_globalattrib.c プロジェクト: mwoz/Hildim.Source
static void iGlobalSet(const char *name, const char *value, int store)
{
  iupASSERT(name!=NULL);
  if (!name) return;

  if (iupStrEqual(name, "DEFAULTFONTSIZE"))
  {
    iupSetDefaultFontSizeGlobalAttrib(value);
    return;
  }
  if (iupStrEqual(name, "DEFAULTFONTSTYLE"))
  {
    iupSetDefaultFontStyleGlobalAttrib(value);
    return;
  }
  if (iupStrEqual(name, "DEFAULTFONTFACE"))
  {
    iupSetDefaultFontFaceGlobalAttrib(value);
    return;
  }
  if (iupStrEqual(name, "KEYPRESS"))
  {
    int key;
    if (iupStrToInt(value, &key))
      iupdrvSendKey(key, 0x01);
    return;
  }
  if (iupStrEqual(name, "KEYRELEASE"))
  {
    int key;
    if (iupStrToInt(value, &key))
      iupdrvSendKey(key, 0x02);
    return;
  }
  if (iupStrEqual(name, "KEY"))
  {
    int key;
    if (iupStrToInt(value, &key))
      iupdrvSendKey(key, 0x03);
    return;
  }
  if (iupStrEqual(name, "LANGUAGE"))
  {
    char* old_language = (char*)iupTableGet(iglobal_table, "LANGUAGE");
    if (!iupStrEqualNoCase(old_language, value))  /* if different than the current */
    {
      iGlobalTableSet(name, value, store);
      iupStrMessageUpdateLanguage(value);
    }
    return;
  }
  if (iupStrEqual(name, "CURSORPOS"))
  {
    int x, y;
    if (iupStrToIntInt(value, &x, &y, 'x') == 2)
      iupdrvWarpPointer(x, y);
    return;
  }
  if (iupStrEqual(name, "MOUSEBUTTON"))
  {
    int x, y, status;
    char bt; 
    if (sscanf(value, "%dx%d %c %d", &x, &y, &bt, &status) == 4)
      iupdrvSendMouse(x, y, bt, status);
    return;
  }

  if (iGlobalChangingDefaultColor(name) || 
      iupdrvSetGlobal(name, value))
    iGlobalTableSet(name, value, store);
}