Exemplo n.º 1
0
static int gtkCanvasSetBgColorAttrib(Ihandle* ih, const char* value)
{
  GtkScrolledWindow* scrolled_window = gtkCanvasGetScrolledWindow(ih);
  unsigned char r, g, b;

  /* ignore given value, must use only from parent for the scrollbars */
  char* parent_value = iupBaseNativeParentGetBgColor(ih);

  if (iupStrToRGB(parent_value, &r, &g, &b))
  {
    GtkWidget* sb;

    iupgtkBaseSetBgColor((GtkWidget*)scrolled_window, r, g, b);

#if GTK_CHECK_VERSION(2, 8, 0)
    sb = gtk_scrolled_window_get_hscrollbar(scrolled_window);
    if (sb) iupgtkBaseSetBgColor(sb, r, g, b);
    sb = gtk_scrolled_window_get_vscrollbar(scrolled_window);
    if (sb) iupgtkBaseSetBgColor(sb, r, g, b);
#endif
  }

  if (!IupGetCallback(ih, "ACTION")) 
  {
    /* enable automatic double buffering */
    gtk_widget_set_double_buffered(ih->handle, TRUE);
    gtk_widget_set_double_buffered((GtkWidget*)scrolled_window, TRUE);
    return iupdrvBaseSetBgColorAttrib(ih, value);
  }
  else
  {
    /* disable automatic double buffering */
    gtk_widget_set_double_buffered(ih->handle, FALSE);
    gtk_widget_set_double_buffered((GtkWidget*)scrolled_window, FALSE);
    gdk_window_set_back_pixmap(iupgtkGetWindow(ih->handle), NULL, FALSE);
    iupAttribSetStr(ih, "_IUPGTK_NO_BGCOLOR", "1");
    return 1;
  }
}
Exemplo n.º 2
0
static int motProgressBarSetBgColorAttrib(Ihandle* ih, const char* value)
{
  if (!iupAttribGetStr(ih, "FGCOLOR"))
  {
    Pixel color;
    unsigned char r, g, b;
    if (!iupStrToRGB(value, &r, &g, &b))
      return 0;

    r = (r*8)/10;
    g = (g*8)/10;
    b = (b*8)/10;

    color = iupmotColorGetPixel(r, g, b);
    if (color != (Pixel)-1)
    {
      Widget w = XtNameToWidget(ih->handle, "*Scrollbar");
      XtVaSetValues(w, XmNtroughColor, color, NULL);
    }
  }

  return iupdrvBaseSetBgColorAttrib(ih, value);
}
Exemplo n.º 3
0
static void iMatrixDrawFrameHorizLineCell(Ihandle* ih, int lin, int col, int x1, int x2, int y, long framecolor, char* str)
{
    if (ih->data->checkframecolor && (ih->data->callback_mode ||
                                      ih->data->cells[lin][col].flags & IMAT_HAS_FRAMEHCOLOR ||
                                      ih->data->lines.flags[col] & IMAT_HAS_FRAMEHCOLOR))
    {
        char* color;
        unsigned char r,g,b;
        sprintf(str, "FRAMEHORIZCOLOR%d:%d", lin, col);
        color = iupAttribGet(ih, str);
        if (!color)
        {
            sprintf(str, "FRAMEHORIZCOLOR%d:*", lin);
            color = iupAttribGet(ih, str);
        }
        if (iupStrEqual(color, "BGCOLOR"))
            return;
        if (iupStrToRGB(color, &r, &g, &b))
            framecolor = cdEncodeColor(r, g, b);
    }

    cdCanvasForeground(ih->data->cddbuffer, framecolor);
    iupMATRIX_LINE(ih, x1, y, x2, y);   /* bottom horizontal line */
}
Exemplo n.º 4
0
static void iMatrixDrawFrameVertLineCell(Ihandle* ih, int lin, int col, int x, int y1, int y2, long framecolor, char* str)
{
    if (ih->data->checkframecolor && (ih->data->callback_mode ||
                                      ih->data->cells[lin][col].flags & IMAT_HAS_FRAMEVCOLOR ||
                                      ih->data->columns.flags[col] & IMAT_HAS_FRAMEVCOLOR))
    {
        char* color;
        unsigned char r,g,b;
        sprintf(str, "FRAMEVERTCOLOR%d:%d", lin, col);
        color = iupAttribGet(ih, str);
        if (!color)
        {
            sprintf(str, "FRAMEVERTCOLOR*:%d", col);
            color = iupAttribGet(ih, str);
        }
        if (iupStrEqual(color, "BGCOLOR"))
            return;
        if (iupStrToRGB(color, &r, &g, &b))
            framecolor = cdEncodeColor(r, g, b);
    }

    cdCanvasForeground(ih->data->cddbuffer, framecolor);
    iupMATRIX_LINE(ih, x, y1, x, y2);    /* right vertical line */
}
Exemplo n.º 5
0
static void winFrameDrawItem(Ihandle* ih, DRAWITEMSTRUCT *drawitem)
{ 
  iupwinBitmapDC bmpDC;
  HDC hDC = iupwinDrawCreateBitmapDC(&bmpDC, drawitem->hDC, drawitem->rcItem.right-drawitem->rcItem.left, 
                                                            drawitem->rcItem.bottom-drawitem->rcItem.top);

  iupwinDrawParentBackground(ih, hDC, &drawitem->rcItem);

  if (iupAttribGet(ih, "_IUPFRAME_HAS_TITLE"))
  {
    int x, y;
    HFONT hOldFont, hFont = (HFONT)iupwinGetHFontAttrib(ih);
    int txt_height = iupFrameGetTitleHeight(ih);
    COLORREF fgcolor;
    SIZE size;

    char* title = iupdrvBaseGetTitleAttrib(ih);
    if (!title) title = "";

    x = drawitem->rcItem.left+7;
    y = drawitem->rcItem.top;

    hOldFont = SelectObject(hDC, hFont);
    GetTextExtentPoint32(hDC, title, strlen(title), &size);
    ExcludeClipRect(hDC, x-2, y, x+size.cx+2, y+size.cy);

    drawitem->rcItem.top += txt_height/2;
    if (iupwin_comctl32ver6)
      iupwinDrawThemeFrameBorder(ih->handle, hDC, &drawitem->rcItem, drawitem->itemState);
    else
      DrawEdge(hDC, &drawitem->rcItem, EDGE_ETCHED, BF_RECT);

    SelectClipRgn(hDC, NULL);

    if (drawitem->itemState & ODS_DISABLED)
      fgcolor = GetSysColor(COLOR_GRAYTEXT);
    else
    {
      unsigned char r, g, b;
      char* color = iupAttribGetInherit(ih, "FGCOLOR");
      if (!color)
      {
        if (!iupwinDrawGetThemeFrameFgColor(ih->handle, &fgcolor))
          fgcolor = 0;  /* black */
      }
      else
      {
        if (iupStrToRGB(color, &r, &g, &b))
          fgcolor = RGB(r,g,b);
        else
          fgcolor = 0;  /* black */
      }
    }

    winFrameDrawText(hDC, title, x, y, fgcolor);

    SelectObject(hDC, hOldFont);
  }
  else
  {
    char* value = iupAttribGetStr(ih, "SUNKEN");
    if (iupStrBoolean(value))
      DrawEdge(hDC, &drawitem->rcItem, EDGE_SUNKEN, BF_RECT);
    else
      DrawEdge(hDC, &drawitem->rcItem, EDGE_ETCHED, BF_RECT);
  }

  iupwinDrawDestroyBitmapDC(&bmpDC);
}
Exemplo n.º 6
0
/* Redraw a block of cells of the matrix. Handle marked cells, change
   automatically the background color of them.
   - l1, c1 : cell coordinates that mark the left top corner of the
              area to be redrawn
   - l2, c2 : cell coordinates that mark the right bottom corner of the
              area to be redrawn
*/
void iupMatrixDrawCells(Ihandle* ih, int l1, int c1, int l2, int c2)
{
  int x1, y1, x2, y2, oldx2, oldy1, oldy2;
  int yc1, yc2, xc1, xc2, i, j;
  int align;
  long framecolor;
  char str[30];
  unsigned char r,g,b;

  /* If there are no cells in the matrix, returns */
  if(ih->data->lin.num == 0 || ih->data->col.num == 0)
   return;

  /* Adjust parameters */
  if(c1 < ih->data->col.first)
    c1 = ih->data->col.first;
  if(c2 > ih->data->col.last)
    c2 = ih->data->col.last;

  if(l1 < ih->data->lin.first)
    l1 = ih->data->lin.first;
  if(l2 > ih->data->lin.last)
    l2 = ih->data->lin.last;

  if(c1 > c2 || l1 > l2)
    return;

  ih->data->redraw = 1;

  if(l1 <= l2)
    iupMatrixDrawLineTitle(ih, l1, l2);
  if(c1<=c2)
    iupMatrixDrawColumnTitle(ih, c1, c2);

  x1 = 0;
  x2 = ih->data->XmaxC;
  y1 = 0;
  y2 = ih->data->YmaxC;

  oldx2 = x2;
  oldy1 = y1;
  oldy2 = y2;

  /* Find the initial position of the first column */
  x1 += ih->data->col.titlewh;
  for(j = ih->data->col.first; j < c1; j++)
    x1 += ih->data->col.wh[j];

  /* Find the final position of the last column */
  x2 = x1;
  for( ; j < c2; j++)
    x2 += ih->data->col.wh[j];
  x2 += (c2 == ih->data->col.last ? ih->data->col.lastwh : ih->data->col.wh[c2]);

  /* Find the initial position of the first line */
  y1 += ih->data->lin.titlewh;
  for(j = ih->data->lin.first; j < l1; j++)
    y1 += ih->data->lin.wh[j];

  /* Find the final position of the last line */
  y2 = y1;
  for( ; j < l2; j++)
    y2 += ih->data->lin.wh[j];
  y2 += (l2 == ih->data->lin.last ? ih->data->lin.lastwh : ih->data->lin.wh[l2]);

  if((c2 == ih->data->col.num-1) && (oldx2 > x2))
  {
    /* If it was drawn until the last column and remains space in the right of it,
       then delete this area with the the background color.
    */
    iupMatrixDrawEmptyArea(ih, x2, oldx2, oldy1, oldy2);
  }

  if((l2 == ih->data->lin.num-1) && (oldy2 > y2))
  {
    /* If it was drawn until the last line visible and remains space below it,
       then delete this area with the the background color.
    */
    iupMatrixDrawEmptyArea(ih, 0, oldx2, y2, oldy2);
  }

  /***** Show the cell values */
  xc1 = x1;
  yc1 = y1;
  iupStrToRGB(IupGetAttribute(ih, "FRAMECOLOR"), &r, &g, &b);
  framecolor = cdEncodeColor((unsigned char) r, (unsigned char) g, (unsigned char) b);

  for(j = c1; j <= c2; j++)  /* For all the columns in the region */
  {
    if(ih->data->col.wh[j] == 0)
      continue;

    align = iMatrixDrawGetColAlignment(ih, j + 1);

    xc2 = xc1 + (j == ih->data->col.last ? ih->data->col.lastwh : ih->data->col.wh[j]);

    for(i = l1; i <= l2; i++)     /* For all lines in the region */
    {
      if(ih->data->lin.wh[i] == 0)
        continue;

      yc2 = yc1 + ih->data->lin.wh[i]-1;

      if(!(IupGetInt(ih->data->datah, "VISIBLE") && i == ih->data->lin.active && j == ih->data->col.active))
      {
        int drop = 0;
        int cor  = IMAT_ELEM_COLOR;
        char *cell_value;

        if(iMatrixDrawCallDropDownCheckCb(ih, i, j))
          drop = IMAT_BOXW;

        /* If the cell is marked, then draw it in reverse color */
        if(iupMatrixMarkCellGet(ih, i, j))
          cor = IMAT_REVERSE_COLOR;

        cell_value = iupMatrixAuxGetCellValue(ih, i, j);
        iMatrixDrawText(ih, xc1, xc1+ih->data->col.wh[j]-1-drop, yc1, yc2-1, cell_value, align, xc2, cor, i+1, j+1);

        if(drop)
          iMatrixDrawComboFeedback(ih, xc1+ih->data->col.wh[j]-1, yc1, yc2, i+1, j+1, cor);
      }

      if (ih->data->checkframecolor)
      {
        sprintf(str, "FRAMEHORIZCOLOR%d:%d", i, j);
        if (iupStrToRGB(IupGetAttribute(ih, str), &r, &g, &b))
          cdCanvasForeground(ih->data->cddbuffer, cdEncodeColor((unsigned char) r, (unsigned char) g, (unsigned char) b));
        else
          cdCanvasForeground(ih->data->cddbuffer, framecolor);
      }
      else
        cdCanvasForeground(ih->data->cddbuffer, framecolor);
    
      /* horizontal line (only for this column) */
      CdLine(xc1, yc2, xc2-1, yc2);
      
      if (ih->data->checkframecolor)
      {
        sprintf(str, "FRAMEVERTCOLOR%d:%d", i+1, j+1);
        if (iupStrToRGB(IupGetAttribute(ih, str), &r, &g, &b))
          cdCanvasForeground(ih->data->cddbuffer, cdEncodeColor((unsigned char) r, (unsigned char) g, (unsigned char) b));
        else
          cdCanvasForeground(ih->data->cddbuffer, framecolor);
      }
      else
        cdCanvasForeground(ih->data->cddbuffer, framecolor);

      /* vertical line (only for this line) */
      CdLine(xc2-1,yc1,xc2-1,yc2-1);

      yc1  = yc2+1;
    }

    xc1 = xc2;
    yc1 = y1;
  }
}
Exemplo n.º 7
0
void iupMatrixCDSetCdFrameColor(Ihandle* ih)
{
  unsigned char r, g, b;
  iupStrToRGB(IupGetAttribute(ih, "FRAMECOLOR"), &r, &g, &b);
  cdCanvasForeground(ih->data->cddbuffer, cdEncodeColor(r, g, b));
}
Exemplo n.º 8
0
static char* iMatrixExGetCellFormat(Ihandle *ih, int lin, int col, char* format)
{
  char* value, *init = "style=\"";

#define _STRCATFORMAT {if (value) { if (init) {strcpy(format, init); init=NULL;} strcat(format, value); }}

  *format = 0;

  value = iupAttribGetId(ih, "ALIGNMENT", col);
  if (value)
  {
    if (iupStrEqualNoCase(value, "ARIGHT"))
      value = "text-align: right; ";
    else if(iupStrEqualNoCase(value, "ACENTER"))
      value = "text-align: center; ";
    else if(iupStrEqualNoCase(value, "ALEFT"))
      value = "text-align: left; ";
    else
      value = NULL;

    _STRCATFORMAT;
  }

  value = iMatrixExGetCellAttrib(ih, "BGCOLOR", lin, col);
  if (value)
  {
    char rgb[50];
    unsigned char r, g, b;
    iupStrToRGB(value, &r, &g, &b);
    sprintf(rgb, "background-color: #%02X%02X%02X; ", (int)r, (int)g, (int)b);

    value = rgb;
    _STRCATFORMAT;
  }

  value = iMatrixExGetCellAttrib(ih, "FGCOLOR", lin, col);
  if (value)
  {
    char rgb[50];
    unsigned char r, g, b;
    iupStrToRGB(value, &r, &g, &b);
    sprintf(rgb, "color: #%02X%02X%02X; ", (int)r, (int)g, (int)b);

    value = rgb;
    _STRCATFORMAT;
  }

  value = iMatrixExGetCellAttrib(ih, "FONT", lin, col);
  if (value)
  {
    if (strstr(value, "Bold")||strstr(value, "BOLD"))
    {
      value = "font-weight: bold; ";
      _STRCATFORMAT;
    }

    if (strstr(value, "Italic")||strstr(value, "ITALIC"))
    {
      value = "font-weight: bold; ";
      _STRCATFORMAT;
    }

    /* Leave this out for now:
       font-size: %dpt; 
       font-family: %s; */
  }

  if (format[0]!=0)
    strcat(format, "\"");

  return format;
}
Exemplo n.º 9
0
void* iupdrvImageCreateImage(Ihandle *ih, const char* bgcolor, int make_inactive)
{
  GdkPixbuf* pixbuf;
  guchar *pixdata, *pixline_data;
  int rowstride, channels;
  unsigned char *imgdata, *line_data, bg_r=0, bg_g=0, bg_b=0;
  int x, y, i, bpp, colors_count = 0, has_alpha = 0;
  iupColor colors[256];

  bpp = iupAttribGetInt(ih, "BPP");

  if (bpp == 8)
    has_alpha = iupImageInitColorTable(ih, colors, &colors_count);
  else if (bpp == 32)
    has_alpha = 1;

  pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, has_alpha, 8, ih->currentwidth, ih->currentheight);
  if (!pixbuf)
    return NULL;

  pixdata = gdk_pixbuf_get_pixels(pixbuf);
  rowstride = gdk_pixbuf_get_rowstride(pixbuf);
  channels = gdk_pixbuf_get_n_channels(pixbuf);
  imgdata = (unsigned char*)iupAttribGetStr(ih, "WID");

  if (make_inactive)  
    iupStrToRGB(bgcolor, &bg_r, &bg_g, &bg_b);

  if (bpp == 8)
  {
    if (make_inactive)
    {
      for (i=0;i<colors_count;i++)
      {
        if (colors[i].a == 0)
        {
          colors[i].r = bg_r;
          colors[i].g = bg_g;
          colors[i].b = bg_b;
          colors[i].a = 255;
        }

        iupImageColorMakeInactive(&(colors[i].r), &(colors[i].g), &(colors[i].b), 
                                  bg_r, bg_g, bg_b);
      }
    }

    for (y=0; y<ih->currentheight; y++)
    {
      pixline_data = pixdata + y * rowstride;
      line_data = imgdata + y * ih->currentwidth;

      for (x=0; x<ih->currentwidth; x++)
      {
        unsigned char index = line_data[x];
        iupColor* c = &colors[index];
        guchar *r = &pixline_data[channels*x],
               *g = r+1,
               *b = g+1,
               *a = b+1;

        *r = c->r;
        *g = c->g;
        *b = c->b;

        if (has_alpha)
          *a = c->a;
      }
    }
  }
  else /* bpp == 32 or bpp == 24 */
  {
    for (y=0; y<ih->currentheight; y++)
    {
      pixline_data = pixdata + y * rowstride;
      line_data = imgdata + y * ih->currentwidth*channels;

      memcpy(pixline_data, line_data, ih->currentwidth*channels);

      if (make_inactive)
      {
        for (x=0; x<ih->currentwidth; x++)
        {
          guchar *r = &pixline_data[channels*x],
                 *g = r+1,
                 *b = g+1,
                 *a = b+1;

          if (has_alpha)
          {
            if (*a != 255)
            {
              *r = iupALPHABLEND(*r, bg_r, *a);
              *g = iupALPHABLEND(*g, bg_g, *a);
              *b = iupALPHABLEND(*b, bg_b, *a);
            }
            else
              *a = 255;
          }

          iupImageColorMakeInactive(r, g, b, 
                                    bg_r, bg_g, bg_b);
        }
      }
    }
  }

  return pixbuf;
}
Exemplo n.º 10
0
void* iupdrvImageCreateCursor(Ihandle *ih)
{
  GdkCursor *cursor;
  int hx, hy, bpp;

  hx=0; hy=0;
  iupStrToIntInt(iupAttribGet(ih, "HOTSPOT"), &hx, &hy, ':');

  bpp = iupAttribGetInt(ih, "BPP");

  if (bpp == 8 && !iupAttribGet(ih, "3"))
  {
    GdkPixmap *source, *mask;
    GdkColor fg, bg;
    unsigned char r, g, b;
    char *sbits, *mbits, *sb, *mb;
    int y, x, line_size = (ih->currentwidth+7)/8;
    int size_bytes = line_size*ih->currentheight;
    unsigned char* imgdata = (unsigned char*)iupAttribGetStr(ih, "WID");

    r = 255; g = 255; b = 255;
    iupStrToRGB(iupAttribGet(ih, "1"), &r, &g, &b );
    iupgdkColorSet(&fg, r, g, b);

    r = 0; g = 0; b = 0;
    iupStrToRGB(iupAttribGet(ih, "2"), &r, &g, &b );
    iupgdkColorSet(&bg, r, g, b);

    sbits = (char*)malloc(2*size_bytes);
    if (!sbits) return NULL;
    memset(sbits, 0, 2*size_bytes);
    mbits = sbits + size_bytes;

    sb = sbits;
    mb = mbits;
    for (y=0; y<ih->currentheight; y++)
    {
      for (x=0; x<ih->currentwidth; x++)
      {
        int byte = x/8;
        int bit = x%8;
        int index = (int)imgdata[y*ih->currentwidth+x];
        /* index==0 is transparent */
        if (index == 1)
          sb[byte] = (char)(sb[byte] | (1<<bit));
        if (index != 0)
          mb[byte] = (char)(mb[byte] | (1<<bit));
      }

      sb += line_size;
      mb += line_size;
    }
  
    source = gdk_bitmap_create_from_data(NULL, sbits, ih->currentwidth, ih->currentheight);
    mask = gdk_bitmap_create_from_data(NULL, mbits, ih->currentwidth, ih->currentheight);

    cursor = gdk_cursor_new_from_pixmap(source, mask, &fg, &bg, hx, hy);

    gdk_pixmap_unref(source);
    gdk_pixmap_unref(mask);
    free(sbits);
  }
  else
  {
    GdkPixbuf* pixbuf = iupdrvImageCreateImage(ih, NULL, 0);
    cursor = gdk_cursor_new_from_pixbuf(gdk_display_get_default(), pixbuf, hx, hy);
    g_object_unref(pixbuf);
  }

  return cursor;
}
Exemplo n.º 11
0
int iupImageInitColorTable(Ihandle *ih, iupColor* colors, int *colors_count)
{
  char attr[6], *value;
  unsigned char red, green, blue;
  int i, has_alpha = 0;
  static iupColor default_colors[] = {
    { 0,0,0,255 }, { 128,0,0,255 }, { 0,128,0,255 }, { 128,128,0,255 },    
    { 0,0,128,255 }, { 128,0,128,255 }, { 0,128,128,255 }, { 192,192,192,255 },    
    { 128,128,128,255 }, { 255,0,0,255 }, { 0,255,0,255 }, { 255,255,0,255 },
    { 0,0,255,255 }, { 255,0,255,255 }, { 0,255,255,255 }, { 255,255,255,255 } };

  memset(colors, 0, sizeof(iupColor)*256);

  for (i=0;i<16;i++)
  {
    sprintf(attr, "%d", i);
    value = iupAttribGetStr(ih, attr);

    if (value)
    {
      if (iupStrEqual(value, "BGCOLOR"))
      {
        iupColorSet(&colors[i], 0, 0, 0, 0);
        has_alpha = 1;
      }
      else
      {
        if (!iupStrToRGB(value, &red, &green, &blue))
          iupColorSet(&colors[i], default_colors[i].r, default_colors[i].g, default_colors[i].b, 255);
        else
          iupColorSet(&colors[i], red, green, blue, 255);
      }
    }
    else
    {
      iupColorSet(&colors[i], default_colors[i].r, default_colors[i].g, default_colors[i].b, 255);
    }
  }

  for (;i<256;i++)
  {
    sprintf(attr, "%d", i);
    value = iupAttribGetStr(ih, attr);
    if (!value)
      break;

    if (iupStrEqual(value, "BGCOLOR"))
    {
      iupColorSet(&colors[i], 0, 0, 0, 0);
      has_alpha = 1;
    }
    else
    {
      if (!iupStrToRGB(value, &red, &green, &blue))
        break;

      iupColorSet(&colors[i], red, green, blue, 255);
    }
  }

  if (colors_count) *colors_count = i;

  return has_alpha;
}
Exemplo n.º 12
0
static int winFontDlgPopup(Ihandle* ih, int x, int y)
{
  InativeHandle* parent = iupDialogGetNativeParent(ih);
  unsigned char r, g, b;
  CHOOSEFONT choosefont;
  LOGFONT logfont;
  char* standardfont;
  int height_pixels;
  char typeface[50] = "";
  int height = 8;
  int is_bold = 0,
    is_italic = 0, 
    is_underline = 0,
    is_strikeout = 0;
  int res = iupwinGetScreenRes();

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

  if (!parent)
    parent = GetActiveWindow();

  standardfont = iupAttribGet(ih, "VALUE");
  if (!standardfont)
    return IUP_ERROR;

  /* parse the old format first */
  if (!iupFontParseWin(standardfont, typeface, &height, &is_bold, &is_italic, &is_underline, &is_strikeout))
  {
    if (!iupFontParsePango(standardfont, typeface, &height, &is_bold, &is_italic, &is_underline, &is_strikeout))
      return IUP_ERROR;
  }

  /* get size in pixels */
  if (height < 0)
    height_pixels = height;  /* already in pixels */
  else
    height_pixels = -IUPWIN_PT2PIXEL(height, res);

  if (height_pixels == 0)
    return IUP_ERROR;

  ZeroMemory(&choosefont, sizeof(CHOOSEFONT));
  choosefont.lStructSize = sizeof(CHOOSEFONT);

  if (iupStrToRGB(iupAttribGet(ih, "COLOR"), &r, &g, &b))
    choosefont.rgbColors = RGB(r, g, b);
  
  choosefont.hwndOwner = parent;
  choosefont.lpLogFont = &logfont;
  choosefont.Flags = CF_SCREENFONTS | CF_EFFECTS | CF_INITTOLOGFONTSTRUCT | CF_ENABLEHOOK;
  choosefont.lCustData = (LPARAM)ih;
  choosefont.lpfnHook = (LPCFHOOKPROC)winFontDlgHookProc;

  if (IupGetCallback(ih, "HELP_CB"))
    choosefont.Flags |= CF_SHOWHELP;

  strcpy(logfont.lfFaceName, typeface);
  logfont.lfHeight = height_pixels;
  logfont.lfWeight = (is_bold)? FW_BOLD: FW_NORMAL;
  logfont.lfItalic = (BYTE)is_italic;
  logfont.lfUnderline = (BYTE)is_underline;
  logfont.lfStrikeOut = (BYTE)is_strikeout;

  logfont.lfCharSet = DEFAULT_CHARSET;
  logfont.lfEscapement = 0; 
  logfont.lfOrientation = 0;
  logfont.lfWidth = 0; 
  logfont.lfOutPrecision = OUT_TT_PRECIS; 
  logfont.lfClipPrecision = CLIP_DEFAULT_PRECIS; 
  logfont.lfQuality = DEFAULT_QUALITY; 
  logfont.lfPitchAndFamily = FF_DONTCARE|DEFAULT_PITCH; 

  if (!ChooseFont(&choosefont))
  {
    iupAttribSetStr(ih, "VALUE", NULL);
    iupAttribSetStr(ih, "COLOR", NULL);
    iupAttribSetStr(ih, "STATUS", NULL);
    return IUP_NOERROR;
  }

  is_bold = (logfont.lfWeight == FW_NORMAL)? 0: 1;
  is_italic = logfont.lfItalic;
  is_underline = logfont.lfUnderline;
  is_strikeout = logfont.lfStrikeOut;
  height_pixels = logfont.lfHeight;

  if (height < 0) /* not an error, use old value as reference of units */
    height = height_pixels;   /* return in pixels */
  else
    height = IUPWIN_PIXEL2PT(-height_pixels, res);   /* return in points */

  iupAttribSetStrf(ih, "VALUE", "%s, %s%s%s%s %d", logfont.lfFaceName, 
                                                    is_bold?"Bold ":"", 
                                                    is_italic?"Italic ":"", 
                                                    is_underline?"Underline ":"", 
                                                    is_strikeout?"Strikeout ":"", 
                                                    height);

  iupAttribSetStrf(ih, "COLOR", "%d %d %d", GetRValue(choosefont.rgbColors),
                                            GetGValue(choosefont.rgbColors),
                                            GetBValue(choosefont.rgbColors));
  iupAttribSetStr(ih, "STATUS", "1");

  return IUP_NOERROR;
}
Exemplo n.º 13
0
static void gtkTabsChildAddedMethod(Ihandle* ih, Ihandle* child)
{
  if (IupGetName(child) == NULL)
    iupAttribSetHandleName(child);

  if (ih->handle)
  {
    GtkWidget* tab_page;
    GtkWidget *tab_label = NULL, *tab_image = NULL;
    char *tabtitle, *tabimage;
    int pos;
    unsigned char r, g, b;

    pos = IupGetChildPos(ih, child);

    tab_page = gtk_fixed_new();
    gtk_widget_show(tab_page);

    tabtitle = iupAttribGet(child, "TABTITLE");
    if (!tabtitle) tabtitle = iupTabsAttribGetStrId(ih, "TABTITLE", pos);
    tabimage = iupAttribGet(child, "TABIMAGE");
    if (!tabimage) tabimage = iupTabsAttribGetStrId(ih, "TABIMAGE", pos);
    if (!tabtitle && !tabimage)
      tabtitle = "     ";

    if (tabtitle)
    {
      tab_label = gtk_label_new(iupgtkStrConvertToUTF8(tabtitle));

#if GTK_CHECK_VERSION(2, 6, 0)
      if (ih->data->orientation == ITABS_VERTICAL)
        gtk_label_set_angle((GtkLabel*)tab_label, 90);
#endif
    }

    if (tabimage)
    {
      GdkPixbuf* pixbuf = iupImageGetImage(tabimage, ih, 0, "TABIMAGE");

      tab_image = gtk_image_new();

      if (pixbuf)
        gtk_image_set_from_pixbuf((GtkImage*)tab_image, pixbuf);
    }

    iupAttribSetStr(ih, "_IUPGTK_IGNORE_CHANGE", "1");

    if (tabimage && tabtitle)
    {
      GtkWidget* box;
      if (ih->data->orientation == ITABS_VERTICAL)
        box = gtk_vbox_new(FALSE, 2);
      else
        box = gtk_hbox_new(FALSE, 2);
      gtk_widget_show(box);

      gtk_container_add((GtkContainer*)box, tab_image);
      gtk_container_add((GtkContainer*)box, tab_label);

      gtk_notebook_insert_page((GtkNotebook*)ih->handle, tab_page, box, pos);
      gtk_notebook_set_menu_label_text((GtkNotebook*)ih->handle, tab_page, gtk_label_get_text((GtkLabel*)tab_label));
    }
    else if (tabimage)
      gtk_notebook_insert_page((GtkNotebook*)ih->handle, tab_page, tab_image, pos);
    else
      gtk_notebook_insert_page((GtkNotebook*)ih->handle, tab_page, tab_label, pos);

    gtk_widget_realize(tab_page);

    iupAttribSetStr(child, "_IUPGTK_TABIMAGE", (char*)tab_image);  /* store it even if its NULL */
    iupAttribSetStr(child, "_IUPGTK_TABLABEL", (char*)tab_label);
    iupAttribSetStr(child, "_IUPTAB_CONTAINER", (char*)tab_page);
    iupStrToRGB(IupGetAttribute(ih, "BGCOLOR"), &r, &g, &b);
    iupgtkBaseSetBgColor(tab_page, r, g, b);

    if (tabtitle)
    {
      PangoFontDescription* fontdesc = (PangoFontDescription*)iupgtkGetPangoFontDescAttrib(ih);
      gtk_widget_modify_font(tab_label, fontdesc);
      iupgtkFontUpdatePangoLayout(ih, gtk_label_get_layout((GtkLabel*)tab_label));

      iupgtkBaseSetBgColor(tab_label, r, g, b);

      iupStrToRGB(IupGetAttribute(ih, "FGCOLOR"), &r, &g, &b);
      iupgtkBaseSetFgColor(tab_label, r, g, b);

      gtk_widget_show(tab_label);
      gtk_widget_realize(tab_label);
    }

    if (tabimage)
    {
      gtk_widget_show(tab_image);
      gtk_widget_realize(tab_image);
    }

    iupAttribSetStr(ih, "_IUPGTK_IGNORE_CHANGE", NULL);
  }
}
Exemplo n.º 14
0
static int iDetachBoxAction_CB(Ihandle* bar)
{
  Ihandle* ih = bar->parent;
  IdrawCanvas* dc = iupDrawCreateCanvas(bar);

  iupDrawParentBackground(dc);

  if (ih->data->showgrip)
  {
    int i, w, h, x, y, count;
    unsigned char r = 160, g = 160, b = 160, bg_r, bg_g, bg_b;
    iupDrawGetSize(dc, &w, &h);

    iupStrToRGB(IupGetAttribute(ih, "COLOR"), &r, &g, &b);
    if (r+g+b > 3*190)
      { bg_r = 100; bg_g = 100; bg_b = 100; }
    else
      { bg_r = 255; bg_g = 255; bg_b = 255; }

    if (ih->data->orientation == IDBOX_VERT)
    {
      x = ih->data->barsize/2-1;
      y = 2;
      count = (h-2)/4;
    }
    else
    {
      x = 2;
      y = ih->data->barsize/2-1;
      count = (w-2)/4;
    }

    for (i = 0; i < count; i++)
    {
      iupDrawRectangle(dc, x+1, y+1, x+2, y+2, bg_r, bg_g, bg_b, IUP_DRAW_FILL);
      iupDrawRectangle(dc, x, y, x+1, y+1, r, g, b, IUP_DRAW_FILL);

      if(i < count - 1)
      {
        iupDrawRectangle(dc, x+3, y+3, x+4, y+4, bg_r, bg_g, bg_b, IUP_DRAW_FILL);
        iupDrawRectangle(dc, x+2, y+2, x+3, y+3, r, g, b, IUP_DRAW_FILL);
      }

      iupDrawRectangle(dc, x+5, y+1, x+6, y+2, bg_r, bg_g, bg_b, IUP_DRAW_FILL);
      iupDrawRectangle(dc, x+4, y, x+5, y+1, r, g, b, IUP_DRAW_FILL);

      if (ih->data->orientation == IDBOX_VERT)
        y += 4;
      else
        x += 4;
    }
  }
  else
  {
    int w, h, x, y;
    unsigned char r = 160, g = 160, b = 160;
    iupDrawGetSize(dc, &w, &h);

    iupStrToRGB(IupGetAttribute(ih, "COLOR"), &r, &g, &b);

    if (ih->data->orientation == IDBOX_VERT)
    {
      x = ih->data->barsize/2-1;
      y = 2;
    }
    else
    {
      x = 2;
      y = ih->data->barsize/2-1;
    }

    iupDrawRectangle(dc, x, y, x+w, y+h, r, g, b, IUP_DRAW_FILL);
  }
  
  iupDrawFlush(dc);

  iupDrawKillCanvas(dc);

  return IUP_DEFAULT;
}
Exemplo n.º 15
0
/* ------------------------------------------------------------------------- */
static void gtkTabsChildAddedMethod(Ihandle* ih, Ihandle* child)
{
  /* make sure it has at least one name */
  if (!iupAttribGetHandleName(child))
    iupAttribSetHandleName(child);

  if (ih->handle)
  {
    GtkWidget *evtBox, *tab_page, *tab_container, *box = NULL;
    GtkWidget *tab_label = NULL, *tab_image = NULL, *tab_close = NULL;
    char *tabtitle, *tabimage;
    int pos;
    unsigned char r, g, b;

    pos = IupGetChildPos(ih, child);

    /* Can not hide the tab_page, 
       or the tab will be automatically hidden.
       So create a secondary container to hide its child instead. */
#if GTK_CHECK_VERSION(3, 0, 0)
    tab_page = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
#else
    tab_page = gtk_vbox_new(FALSE, 0);
#endif
    gtk_widget_show(tab_page);

    tab_container = gtk_fixed_new(); /* can not use iupgtkNativeContainerNew in GTK3 */
    gtk_widget_show(tab_container);
    gtk_container_add((GtkContainer*)tab_page, tab_container);

    tabtitle = iupAttribGet(child, "TABTITLE");
    if (!tabtitle)
    {
      tabtitle = iupAttribGetId(ih, "TABTITLE", pos);
      if (tabtitle)
        iupAttribSetStr(child, "TABTITLE", tabtitle);
    }
    tabimage = iupAttribGet(child, "TABIMAGE");
    if (!tabimage)
    {
      tabimage = iupAttribGetId(ih, "TABIMAGE", pos);
      if (tabimage)
        iupAttribSetStr(child, "TABIMAGE", tabimage);
    }
    if (!tabtitle && !tabimage)
      tabtitle = "     ";

    if (tabtitle)
    {
      tab_label = gtk_label_new(NULL);
      iupgtkSetMnemonicTitle(ih, (GtkLabel*)tab_label, tabtitle);

#if GTK_CHECK_VERSION(2, 6, 0)
      if (ih->data->orientation == ITABS_VERTICAL)
        gtk_label_set_angle((GtkLabel*)tab_label, 90);
#endif
    }

    if (tabimage)
    {
      GdkPixbuf* pixbuf = iupImageGetImage(tabimage, ih, 0);

      tab_image = gtk_image_new();

      if (pixbuf)
        gtk_image_set_from_pixbuf((GtkImage*)tab_image, pixbuf);
    }

    if(ih->data->show_close)
    {
#if GTK_CHECK_VERSION(3, 10, 0)
      GtkWidget* image = gtk_image_new_from_icon_name("window-close", GTK_ICON_SIZE_MENU);
#else
      GtkWidget* image = gtk_image_new_from_stock(GTK_STOCK_CLOSE, GTK_ICON_SIZE_MENU);
#endif

      tab_close = gtk_button_new();
      gtk_button_set_image((GtkButton*)tab_close, image);
      gtk_button_set_relief((GtkButton*)tab_close, GTK_RELIEF_NONE);
      gtk_button_set_focus_on_click((GtkButton*)tab_close, FALSE);
      iupgtkSetCanFocus(tab_close, FALSE);

      g_signal_connect(G_OBJECT(tab_close), "clicked", G_CALLBACK(gtkTabsCloseButtonClicked), child);
    }

    iupAttribSet(ih, "_IUPGTK_IGNORE_CHANGE", "1");

    if ((tabimage && tabtitle) || ih->data->show_close)
    { 
#if GTK_CHECK_VERSION(3, 0, 0)
      if (ih->data->orientation == ITABS_VERTICAL)
        box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 2);
      else
        box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 2);
#else
      if (ih->data->orientation == ITABS_VERTICAL)
        box = gtk_vbox_new(FALSE, 2);
      else
        box = gtk_hbox_new(FALSE, 2);
#endif
      gtk_widget_show(box);
    }

    /* RIGHTCLICK_CB will not work without the eventbox */
    evtBox = gtk_event_box_new();
    gtk_widget_add_events(evtBox, GDK_BUTTON_PRESS_MASK);
    g_signal_connect(G_OBJECT(evtBox), "button-press-event", G_CALLBACK(gtkTabsButtonPressEvent), child);

    if (tabimage && tabtitle)
    {
      gtk_container_add((GtkContainer*)box, tab_image);
      gtk_container_add((GtkContainer*)box, tab_label);
      
      if(ih->data->show_close)
        gtk_container_add((GtkContainer*)box, tab_close);

      gtk_container_add((GtkContainer*)evtBox, box);
      gtk_notebook_insert_page((GtkNotebook*)ih->handle, tab_page, evtBox, pos);
      gtk_notebook_set_menu_label_text((GtkNotebook*)ih->handle, tab_page, gtk_label_get_text((GtkLabel*)tab_label));
    }
    else if(tabimage && ih->data->show_close)
    {
      gtk_container_add((GtkContainer*)box, tab_image);
      gtk_container_add((GtkContainer*)box, tab_close);
      gtk_container_add((GtkContainer*)evtBox, box);
      gtk_notebook_insert_page((GtkNotebook*)ih->handle, tab_page, evtBox, pos);
    }
    else if(tabtitle && ih->data->show_close)
    {
      gtk_container_add((GtkContainer*)box, tab_label);
      gtk_container_add((GtkContainer*)box, tab_close);
      gtk_container_add((GtkContainer*)evtBox, box);
      gtk_notebook_insert_page((GtkNotebook*)ih->handle, tab_page, evtBox, pos);
      gtk_notebook_set_menu_label_text((GtkNotebook*)ih->handle, tab_page, gtk_label_get_text((GtkLabel*)tab_label));
    }
    else if (tabimage)
    {
      gtk_container_add((GtkContainer*)evtBox, tab_image);
      gtk_notebook_insert_page((GtkNotebook*)ih->handle, tab_page, evtBox, pos);
    }
    else
    {
      gtk_container_add((GtkContainer*)evtBox, tab_label);
      gtk_notebook_insert_page((GtkNotebook*)ih->handle, tab_page, evtBox, pos);
    }

    gtk_widget_realize(tab_page);

    iupAttribSet(child, "_IUPGTK_TABCLOSE", (char*)tab_close);
    iupAttribSet(child, "_IUPGTK_TABIMAGE", (char*)tab_image);  /* store it even if its NULL */
    iupAttribSet(child, "_IUPGTK_TABLABEL", (char*)tab_label);
    iupAttribSet(child, "_IUPTAB_CONTAINER", (char*)tab_container);
    iupAttribSet(child, "_IUPTAB_PAGE", (char*)tab_page);
    iupStrToRGB(IupGetAttribute(ih, "BGCOLOR"), &r, &g, &b);
    iupgtkSetBgColor(tab_container, r, g, b);

    if (tabtitle)
    {
      iupgtkUpdateWidgetFont(ih, tab_label);

      iupgtkSetBgColor(tab_label, r, g, b);

      iupStrToRGB(IupGetAttribute(ih, "FGCOLOR"), &r, &g, &b);
      iupgtkSetFgColor(tab_label, r, g, b);

      gtk_widget_show(tab_label);
      gtk_widget_realize(tab_label);
    }

    if (tabimage)
    {
      gtk_widget_show(tab_image);
      gtk_widget_realize(tab_image);
    }

    if (ih->data->show_close)
    {
      gtk_widget_show(tab_close);
      gtk_widget_realize(tab_close);
    }

    iupAttribSet(ih, "_IUPGTK_IGNORE_CHANGE", NULL);

    if (pos != iupdrvTabsGetCurrentTab(ih))
      gtk_widget_hide(tab_container);
  }
}
Exemplo n.º 16
0
void* iupdrvImageCreateCursor(Ihandle *ih)
{
  int bpp,y,x,hx,hy,
      width = ih->currentwidth,
      height = ih->currentheight,
      line_size = (width+7)/8,
      size_bytes = line_size*height;
  unsigned char *imgdata = (unsigned char*)iupAttribGetStr(ih, "WID");
  char *sbits, *mbits, *sb, *mb;
  Pixmap source, mask;
  XColor fg, bg;
  unsigned char r, g, b;
  Cursor cursor;

  bpp = iupAttribGetInt(ih, "BPP");
  if (bpp > 8)
    return NULL;

  sbits = (char*)malloc(2*size_bytes);
  if (!sbits) return NULL;
  memset(sbits, 0, 2*size_bytes);
  mbits = sbits + size_bytes;

  sb = sbits;
  mb = mbits;
  for (y=0; y<height; y++)
  {
    for (x=0; x<width; x++)
    {
      int byte = x/8;
      int bit = x%8;
      int index = (int)imgdata[y*width+x];
      /* index==0 is transparent */
      if (index == 1)
        sb[byte] = (char)(sb[byte] | (1<<bit));
      if (index != 0)
        mb[byte] = (char)(mb[byte] | (1<<bit));
    }

    sb += line_size;
    mb += line_size;
  }

  r = 255; g = 255; b = 255;
  iupStrToRGB(iupAttribGet(ih, "1"), &r, &g, &b );
  fg.red   = iupCOLOR8TO16(r);
  fg.green = iupCOLOR8TO16(g);
  fg.blue  = iupCOLOR8TO16(b);
  fg.flags = DoRed | DoGreen | DoBlue;

  r = 0; g = 0; b = 0;
  iupStrToRGB(iupAttribGet(ih, "2"), &r, &g, &b );
  bg.red   = iupCOLOR8TO16(r);
  bg.green = iupCOLOR8TO16(g);
  bg.blue  = iupCOLOR8TO16(b);
  bg.flags = DoRed | DoGreen | DoBlue;

  hx=0; hy=0;
  iupStrToIntInt(iupAttribGet(ih, "HOTSPOT"), &hx, &hy, ':');

  source = XCreateBitmapFromData(iupmot_display, 
             RootWindow(iupmot_display,iupmot_screen),
             sbits, width, height);
  mask   = XCreateBitmapFromData(iupmot_display, 
             RootWindow(iupmot_display,iupmot_screen),
             mbits, width, height);

  cursor = XCreatePixmapCursor(iupmot_display, source, mask, &fg, &bg, hx, hy);

  free(sbits);
  return (void*)cursor;
}
Exemplo n.º 17
0
void* iupdrvImageCreateImage(Ihandle *ih, const char* bgcolor, int make_inactive)
{
  int y, x, bpp, bgcolor_depend = 0,
      width = ih->currentwidth,
      height = ih->currentheight;
  unsigned char *imgdata = (unsigned char*)iupAttribGetStr(ih, "WID");
  Pixmap pixmap;
  unsigned char bg_r=0, bg_g=0, bg_b=0;
  GC gc;
  Pixel color2pixel[256];

  bpp = iupAttribGetInt(ih, "BPP");

  iupStrToRGB(bgcolor, &bg_r, &bg_g, &bg_b);

  if (bpp == 8)
  {
    int i, colors_count = 0;
    iupColor colors[256];

    iupImageInitColorTable(ih, colors, &colors_count);

    for (i=0;i<colors_count;i++)
    {
      if (colors[i].a == 0)
      {
        colors[i].r = bg_r;
        colors[i].g = bg_g;
        colors[i].b = bg_b;
        colors[i].a = 255;
        bgcolor_depend = 1;
      }

      if (make_inactive)
        iupImageColorMakeInactive(&(colors[i].r), &(colors[i].g), &(colors[i].b), bg_r, bg_g, bg_b);

      color2pixel[i] = iupmotColorGetPixel(colors[i].r, colors[i].g, colors[i].b);
    }
  }

  pixmap = XCreatePixmap(iupmot_display,
          RootWindow(iupmot_display,iupmot_screen),
          width, height, iupdrvGetScreenDepth());
  if (!pixmap)
    return NULL;

  gc = XCreateGC(iupmot_display,pixmap,0,NULL);
  for (y=0;y<height;y++)
  {
    for(x=0;x<width;x++)
    {
      unsigned long p;
      if (bpp == 8)
        p = color2pixel[imgdata[y*width+x]];
      else
      {
        int channels = (bpp==24)? 3: 4;
        unsigned char *pixel_data = imgdata + y*width*channels + x*channels;
        unsigned char r = *(pixel_data),
                      g = *(pixel_data+1),
                      b = *(pixel_data+2);

        if (bpp == 32)
        {
          unsigned char a = *(pixel_data+3);
          if (a != 255)
          {
            /* flat alpha */
            r = iupALPHABLEND(r, bg_r, a);
            g = iupALPHABLEND(g, bg_g, a);
            b = iupALPHABLEND(b, bg_b, a);
            bgcolor_depend = 1;
          }
        }

        if (make_inactive)
          iupImageColorMakeInactive(&r, &g, &b, bg_r, bg_g, bg_b);

        p = iupmotColorGetPixel(r, g, b);
      }

      XSetForeground(iupmot_display,gc,p);
      XDrawPoint(iupmot_display,pixmap,gc,x,y);
    }
  }
  XFreeGC(iupmot_display,gc);

  if (bgcolor_depend || make_inactive)
    iupAttribSet(ih, "_IUP_BGCOLOR_DEPEND", "1");

  return (void*)pixmap;
}
Exemplo n.º 18
0
static int iExpanderAction_CB(Ihandle* bar)
{
  Ihandle *ih = bar->parent;
  IdrawCanvas *dc = iupDrawCreateCanvas(bar);
  unsigned char r=0, g=0, b=0;
  unsigned char bg_r=0, bg_g=0, bg_b=0;
  char* title = iupAttribGetStr(ih, "TITLE");
  
  iupStrToRGB(iupBaseNativeParentGetBgColorAttrib(ih), &bg_r, &bg_g, &bg_b);
  iupStrToRGB(IupGetAttribute(ih, "FGCOLOR"), &r, &g, &b);

  iupDrawParentBackground(dc);

  if (ih->data->position == IEXPANDER_TOP && title)
  {
    /* left align everything */
    int len;
    iupStrNextLine(title, &len);  /* get the length of the first line */
    iupDrawText(dc, title, len, IEXPAND_HANDLE_SIZE, 0, r, g, b, IupGetAttribute(ih, "FONT"));

    if (ih->data->highlight)
      iExpanderHighligh(&r, &g, &b);

    if (ih->data->state == IEXPANDER_CLOSE)
      iExpanderDrawArrow(dc, 1, 0, r, g, b, bg_r, bg_g, bg_b, IEXPANDER_RIGHT);
    else
      iExpanderDrawArrow(dc, 0, 0, r, g, b, bg_r, bg_g, bg_b, IEXPANDER_BOTTOM);
  }
  else
  {
    /* center align the arrow */
    int x, y;

    if (ih->data->highlight)
      iExpanderHighligh(&r, &g, &b);

    switch(ih->data->position)
    {
    case IEXPANDER_LEFT:
      x = 0;
      y = (bar->currentheight - IEXPAND_HANDLE_SIZE)/2;
      if (ih->data->state == IEXPANDER_CLOSE)
        iExpanderDrawArrow(dc, x, y, r, g, b, bg_r, bg_g, bg_b, IEXPANDER_RIGHT);
      else
        iExpanderDrawArrow(dc, x, y, r, g, b, bg_r, bg_g, bg_b, IEXPANDER_LEFT);
      break;
    case IEXPANDER_TOP:
      x = (bar->currentwidth - IEXPAND_HANDLE_SIZE)/2;
      y = 0;
      if (ih->data->state == IEXPANDER_CLOSE)
        iExpanderDrawArrow(dc, x, y, r, g, b, bg_r, bg_g, bg_b, IEXPANDER_BOTTOM);
      else
        iExpanderDrawArrow(dc, x, y, r, g, b, bg_r, bg_g, bg_b, IEXPANDER_TOP);
      break;
    case IEXPANDER_RIGHT:
      x = 0;
      y = (bar->currentheight - IEXPAND_HANDLE_SIZE)/2;
      if (ih->data->state == IEXPANDER_CLOSE)
        iExpanderDrawArrow(dc, x, y, r, g, b, bg_r, bg_g, bg_b, IEXPANDER_LEFT);
      else
        iExpanderDrawArrow(dc, x, y, r, g, b, bg_r, bg_g, bg_b, IEXPANDER_RIGHT);
      break;
    case IEXPANDER_BOTTOM:
      x = (bar->currentwidth - IEXPAND_HANDLE_SIZE)/2;
      y = 0;
      if (ih->data->state == IEXPANDER_CLOSE)
        iExpanderDrawArrow(dc, x, y, r, g, b, bg_r, bg_g, bg_b, IEXPANDER_TOP);
      else
        iExpanderDrawArrow(dc, x, y, r, g, b, bg_r, bg_g, bg_b, IEXPANDER_BOTTOM);
      break;
    }
  }

  iupDrawFlush(dc);

  iupDrawKillCanvas(dc);

  return IUP_DEFAULT;
}
Exemplo n.º 19
0
static void gtkTabsChildAddedMethod(Ihandle* ih, Ihandle* child)
{
  if (IupGetName(child) == NULL)
    iupAttribSetHandleName(child);

  if (ih->handle)
  {
    GtkWidget *tab_page, *tab_container;
    GtkWidget *tab_label = NULL, *tab_image = NULL;
    char *tabtitle, *tabimage;
    int pos;
    unsigned char r, g, b;

    pos = IupGetChildPos(ih, child);

    /* Can not hide the tab_page, 
       or the tab will be automatically hidden.
       So create a secondary container to hide its child instead. */
#if GTK_CHECK_VERSION(3, 0, 0)
    tab_page = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
#else
    tab_page = gtk_vbox_new(FALSE, 0);
#endif
    gtk_widget_show(tab_page);

    tab_container = gtk_fixed_new(); /* can not use iupgtkNativeContainerNew in GTK3 */
    gtk_widget_show(tab_container);
    gtk_container_add((GtkContainer*)tab_page, tab_container);

    tabtitle = iupTabsAttribGetStrId(ih, "TABTITLE", pos);
    if (!tabtitle) 
    {
      tabtitle = iupAttribGet(child, "TABTITLE");
      if (tabtitle)
        iupTabsAttribSetStrId(ih, "TABTITLE", pos, tabtitle);
    }
    tabimage = iupTabsAttribGetStrId(ih, "TABIMAGE", pos);
    if (!tabimage) 
    {
      tabimage = iupAttribGet(child, "TABIMAGE");
      if (tabimage)
        iupTabsAttribSetStrId(ih, "TABIMAGE", pos, tabimage);
    }
    if (!tabtitle && !tabimage)
      tabtitle = "     ";

    if (tabtitle)
    {
      tab_label = gtk_label_new(NULL);
      iupgtkSetMnemonicTitle(ih, (GtkLabel*)tab_label, tabtitle);

#if GTK_CHECK_VERSION(2, 6, 0)
      if (ih->data->orientation == ITABS_VERTICAL)
        gtk_label_set_angle((GtkLabel*)tab_label, 90);
#endif
    }

    if (tabimage)
    {
      GdkPixbuf* pixbuf = iupImageGetImage(tabimage, ih, 0);

      tab_image = gtk_image_new();

      if (pixbuf)
        gtk_image_set_from_pixbuf((GtkImage*)tab_image, pixbuf);
    }

    iupAttribSetStr(ih, "_IUPGTK_IGNORE_CHANGE", "1");

    if (tabimage && tabtitle)
    {
      GtkWidget* box;
#if GTK_CHECK_VERSION(3, 0, 0)
      if (ih->data->orientation == ITABS_VERTICAL)
        box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 2);
      else
        box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 2);
#else
      if (ih->data->orientation == ITABS_VERTICAL)
        box = gtk_vbox_new(FALSE, 2);
      else
        box = gtk_hbox_new(FALSE, 2);
#endif
      gtk_widget_show(box);

      gtk_container_add((GtkContainer*)box, tab_image);
      gtk_container_add((GtkContainer*)box, tab_label);

      gtk_notebook_insert_page((GtkNotebook*)ih->handle, tab_page, box, pos);
      gtk_notebook_set_menu_label_text((GtkNotebook*)ih->handle, tab_page, gtk_label_get_text((GtkLabel*)tab_label));
    }
    else if (tabimage)
      gtk_notebook_insert_page((GtkNotebook*)ih->handle, tab_page, tab_image, pos);
    else
      gtk_notebook_insert_page((GtkNotebook*)ih->handle, tab_page, tab_label, pos);

    gtk_widget_realize(tab_page);

    iupAttribSetStr(child, "_IUPGTK_TABIMAGE", (char*)tab_image);  /* store it even if its NULL */
    iupAttribSetStr(child, "_IUPGTK_TABLABEL", (char*)tab_label);
    iupAttribSetStr(child, "_IUPTAB_CONTAINER", (char*)tab_container);
    iupAttribSetStr(child, "_IUPTAB_PAGE", (char*)tab_page);
    iupStrToRGB(IupGetAttribute(ih, "BGCOLOR"), &r, &g, &b);
    iupgtkSetBgColor(tab_container, r, g, b);

    if (tabtitle)
    {
      PangoFontDescription* fontdesc = (PangoFontDescription*)iupgtkGetPangoFontDescAttrib(ih);
#if GTK_CHECK_VERSION(3, 0, 0)
      gtk_widget_override_font(tab_label, fontdesc);
#else
      gtk_widget_modify_font(tab_label, fontdesc);
#endif
      iupgtkFontUpdatePangoLayout(ih, gtk_label_get_layout((GtkLabel*)tab_label));

      iupgtkSetBgColor(tab_label, r, g, b);

      iupStrToRGB(IupGetAttribute(ih, "FGCOLOR"), &r, &g, &b);
      iupgtkSetFgColor(tab_label, r, g, b);

      gtk_widget_show(tab_label);
      gtk_widget_realize(tab_label);
    }

    if (tabimage)
    {
      gtk_widget_show(tab_image);
      gtk_widget_realize(tab_image);
    }

    iupAttribSetStr(ih, "_IUPGTK_IGNORE_CHANGE", NULL);

    if (pos != iupdrvTabsGetCurrentTab(ih))
      gtk_widget_hide(tab_container);
  }
}
Exemplo n.º 20
0
static int winDialogBaseProc(Ihandle* ih, UINT msg, WPARAM wp, LPARAM lp, LRESULT *result)
{
    if (iupwinBaseContainerProc(ih, msg, wp, lp, result))
        return 1;

    iupwinMenuDialogProc(ih, msg, wp, lp);

    switch (msg)
    {
    case WM_GETMINMAXINFO:
    {
        if (winDialogCheckMinMaxInfo(ih, (MINMAXINFO*)lp))
        {
            *result = 0;
            return 1;
        }
        break;
    }
    case WM_MOVE:
    {
        IFnii cb = (IFnii)IupGetCallback(ih, "MOVE_CB");
        int x, y;
        /* ignore LPARAM because they are the clientpos */
        iupdrvDialogGetPosition(ih, NULL, &x, &y);
        if (cb) cb(ih, x, y);
        break;
    }
    case WM_SIZE:
    {
        if (ih->data->ignore_resize)
            break;

        switch(wp)
        {
        case SIZE_MINIMIZED:
        {
            if (ih->data->show_state != IUP_MINIMIZE)
            {
                IFni show_cb = (IFni)IupGetCallback(ih, "SHOW_CB");
                ih->data->show_state = IUP_MINIMIZE;
                if (show_cb && show_cb(ih, IUP_MINIMIZE) == IUP_CLOSE)
                    IupExitLoop();
            }
            break;
        }
        case SIZE_MAXIMIZED:
        {
            if (ih->data->show_state != IUP_MAXIMIZE)
            {
                IFni show_cb = (IFni)IupGetCallback(ih, "SHOW_CB");
                ih->data->show_state = IUP_MAXIMIZE;
                if (show_cb && show_cb(ih, IUP_MAXIMIZE) == IUP_CLOSE)
                    IupExitLoop();
            }

            winDialogResize(ih, LOWORD(lp), HIWORD(lp));

            if (iupAttribGetBoolean(ih, "MDICHILD"))
            {
                /* WORKAROUND: when a child MDI dialog is maximized,
                   its title is displayed inside the MDI client area.
                   So we force a MDI client size update */
                RECT rect;
                Ihandle* client = (Ihandle*)iupAttribGet(ih, "MDICLIENT_HANDLE");
                GetClientRect(client->handle, &rect);
                PostMessage(client->handle, WM_SIZE, (WPARAM)SIZE_RESTORED, MAKELPARAM(rect.right-rect.left, rect.bottom-rect.top));
            }
            break;
        }
        case SIZE_RESTORED:
        {
            if (ih->data->show_state == IUP_MAXIMIZE || ih->data->show_state == IUP_MINIMIZE)
            {
                IFni show_cb = (IFni)IupGetCallback(ih, "SHOW_CB");
                ih->data->show_state = IUP_RESTORE;
                if (show_cb && show_cb(ih, IUP_RESTORE) == IUP_CLOSE)
                    IupExitLoop();
            }

            winDialogResize(ih, LOWORD(lp), HIWORD(lp));
            break;
        }
        }

        if (iupAttribGetBoolean(ih, "MDIFRAME"))
        {
            /* We are going to manually position the MDI client,
               so abort MDI frame processing. */
            *result = 0;
            return 1;
        }
        else
            break;
    }
    case WM_USER+IUPWIN_TRAY_NOTIFICATION:
    {
        int dclick  = 0;
        int button  = 0;
        int pressed = 0;

        switch (lp)
        {
        case WM_LBUTTONDOWN:
            pressed = 1;
            button  = 1;
            break;
        case WM_MBUTTONDOWN:
            pressed = 1;
            button  = 2;
            break;
        case WM_RBUTTONDOWN:
            pressed = 1;
            button  = 3;
            break;
        case WM_LBUTTONDBLCLK:
            dclick = 1;
            button = 1;
            break;
        case WM_MBUTTONDBLCLK:
            dclick = 1;
            button = 2;
            break;
        case WM_RBUTTONDBLCLK:
            dclick = 1;
            button = 3;
            break;
        case WM_LBUTTONUP:
            button = 1;
            break;
        case WM_MBUTTONUP:
            button = 2;
            break;
        case WM_RBUTTONUP:
            button = 3;
            break;
        }

        if (button != 0)
        {
            IFniii cb = (IFniii)IupGetCallback(ih, "TRAYCLICK_CB");
            if (cb && cb(ih, button, pressed, dclick) == IUP_CLOSE)
                IupExitLoop();
        }

        break;
    }
    case WM_CLOSE:
    {
        Icallback cb = IupGetCallback(ih, "CLOSE_CB");
        if (cb)
        {
            int ret = cb(ih);
            if (ret == IUP_IGNORE)
            {
                *result = 0;
                return 1;
            }
            if (ret == IUP_CLOSE)
                IupExitLoop();
        }

        /* child mdi is automatically destroyed */
        if (iupAttribGetBoolean(ih, "MDICHILD"))
            IupDestroy(ih);
        else
        {
            if (!winDialogMDICloseChildren(ih))
            {
                *result = 0;
                return 1;
            }

            IupHide(ih); /* IUP default processing */
        }

        *result = 0;
        return 1;
    }
    case WM_COPYDATA:  /* usually from SetGlobal("SINGLEINSTANCE") */
    {
        COPYDATASTRUCT* cds = (COPYDATASTRUCT*)lp;
        IFnsi cb = (IFnsi)IupGetCallback(ih, "COPYDATA_CB");
        if (cb) cb(ih, cds->lpData, cds->cbData);
        break;
    }
    case WM_SETCURSOR:
    {
        if (ih->handle == (HWND)wp && LOWORD(lp)==HTCLIENT)
        {
            HCURSOR hCur = (HCURSOR)iupAttribGet(ih, "_IUPWIN_HCURSOR");
            if (hCur)
            {
                SetCursor(hCur);
                *result = 1;
                return 1;
            }
            else if (iupAttribGet(ih, "CURSOR"))
            {
                SetCursor(NULL);
                *result = 1;
                return 1;
            }
        }
        break;
    }
    case WM_ERASEBKGND:
    {
        HBITMAP hBitmap = (HBITMAP)iupAttribGet(ih, "_IUPWIN_BACKGROUND_BITMAP");
        if (hBitmap)
        {
            RECT rect;
            HDC hdc = (HDC)wp;

            HBRUSH hBrush = CreatePatternBrush(hBitmap);
            GetClientRect(ih->handle, &rect);
            FillRect(hdc, &rect, hBrush);
            DeleteObject(hBrush);

            /* return non zero value */
            *result = 1;
            return 1;
        }
        else
        {
            unsigned char r, g, b;
            char* color = iupAttribGet(ih, "_IUPWIN_BACKGROUND_COLOR");
            if (iupStrToRGB(color, &r, &g, &b))
            {
                RECT rect;
                HDC hdc = (HDC)wp;

                SetDCBrushColor(hdc, RGB(r,g,b));
                GetClientRect(ih->handle, &rect);
                FillRect(hdc, &rect, (HBRUSH)GetStockObject(DC_BRUSH));

                /* return non zero value */
                *result = 1;
                return 1;
            }
        }
        break;
    }
    case WM_DESTROY:
    {
        /* Since WM_CLOSE changed the Windows default processing                            */
        /* WM_DESTROY is NOT received by IupDialogs                                         */
        /* Except when they are children of other IupDialogs and the parent is destroyed.   */
        /* So we have to destroy the child dialog.                                          */
        /* The application is responsable for destroying the children before this happen.   */
        IupDestroy(ih);
        break;
    }
    }

    if (msg == (UINT)WM_HELPMSG)
    {
        Ihandle* child = NULL;
        DWORD* struct_ptr = (DWORD*)lp;
        if (*struct_ptr == sizeof(CHOOSECOLOR))
        {
            CHOOSECOLOR* choosecolor = (CHOOSECOLOR*)lp;
            child = (Ihandle*)choosecolor->lCustData;
        }
        if (*struct_ptr == sizeof(CHOOSEFONT))
        {
            CHOOSEFONT* choosefont = (CHOOSEFONT*)lp;
            child = (Ihandle*)choosefont->lCustData;
        }

        if (child)
        {
            Icallback cb = IupGetCallback(child, "HELP_CB");
            if (cb && cb(child) == IUP_CLOSE)
                EndDialog((HWND)iupAttribGet(child, "HWND"), IDCANCEL);
        }
    }

    return 0;
}
Exemplo n.º 21
0
static int winDialogBaseProc(Ihandle* ih, UINT msg, WPARAM wp, LPARAM lp, LRESULT *result)
{
  if (iupwinBaseContainerProc(ih, msg, wp, lp, result))
    return 1;

  iupwinMenuDialogProc(ih, msg, wp, lp);

  switch (msg)
  {
  case WM_GETDLGCODE:
    *result = DLGC_WANTALLKEYS;
    return 1;
  case WM_GETMINMAXINFO:
    {
      if (winDialogCheckMinMaxInfo(ih, (MINMAXINFO*)lp))
      {
        *result = 0;
        return 1;
      }
      break;
    }
  case WM_SIZE:
    {
      if (ih->data->ignore_resize)
        break;

      switch(wp)
      {
      case SIZE_MINIMIZED:
        {
          if (ih->data->show_state != IUP_MINIMIZE)
          {
            IFni show_cb = (IFni)IupGetCallback(ih, "SHOW_CB");
            if (show_cb && show_cb(ih, IUP_MINIMIZE) == IUP_CLOSE)
              IupExitLoop();
            ih->data->show_state = IUP_MINIMIZE;
          }
          break;
        }
      case SIZE_MAXIMIZED:
        {
          if (ih->data->show_state != IUP_MAXIMIZE)
          {
            IFni show_cb = (IFni)IupGetCallback(ih, "SHOW_CB");
            if (show_cb && show_cb(ih, IUP_MAXIMIZE) == IUP_CLOSE)
              IupExitLoop();
            ih->data->show_state = IUP_MAXIMIZE;
          }

          winDialogResize(ih, LOWORD(lp), HIWORD(lp));
          break;
        }
      case SIZE_RESTORED:
        {
          if (ih->data->show_state == IUP_MAXIMIZE || ih->data->show_state == IUP_MINIMIZE)
          {
            IFni show_cb = (IFni)IupGetCallback(ih, "SHOW_CB");
            if (show_cb && show_cb(ih, IUP_RESTORE) == IUP_CLOSE)
              IupExitLoop();
            ih->data->show_state = IUP_RESTORE;
          }

          winDialogResize(ih, LOWORD(lp), HIWORD(lp));
          break;
        }
      }

      break;
    }
  case WM_USER+IWIN_TRAY_NOTIFICATION:
    {
      int dclick  = 0;
      int button  = 0;
      int pressed = 0;

      switch (lp)
      {
      case WM_LBUTTONDOWN:
        pressed = 1;
        button  = 1;
        break;
      case WM_MBUTTONDOWN:
        pressed = 1;
        button  = 2;
        break;
      case WM_RBUTTONDOWN:
        pressed = 1;
        button  = 3;
        break;
      case WM_LBUTTONDBLCLK:
        dclick = 1;
        button = 1;
        break;
      case WM_MBUTTONDBLCLK:
        dclick = 1;
        button = 2;
        break;
      case WM_RBUTTONDBLCLK:
        dclick = 1;
        button = 3;
        break;
      case WM_LBUTTONUP:
        button = 1;
        break;
      case WM_MBUTTONUP:
        button = 2;
        break;
      case WM_RBUTTONUP:
        button = 3;
        break;
      }

      if (button != 0)
      {
        IFniii cb = (IFniii)IupGetCallback(ih, "TRAYCLICK_CB");
        if (cb && cb(ih, button, pressed, dclick) == IUP_CLOSE)
          IupExitLoop();
      }

      break;
    }
  case WM_CLOSE:
    {
      Icallback cb = IupGetCallback(ih, "CLOSE_CB");
      if (cb)
      {
        int ret = cb(ih);
        if (ret == IUP_IGNORE)
        {
          *result = 0;
          return 1;
        }
        if (ret == IUP_CLOSE)
          IupExitLoop();
      }

      /* child mdi is automatically destroyed */
      if (iupAttribGetInt(ih, "MDICHILD"))
        IupDestroy(ih);
      else
      {
        if (!winDialogMDICloseChildren(ih))
        {
          *result = 0;
          return 1;
        }

        IupHide(ih); /* IUP default processing */
      }

      *result = 0;
      return 1;
    }
  case WM_SETCURSOR: 
    { 
      if (ih->handle == (HWND)wp && LOWORD(lp)==HTCLIENT)
      {
        HCURSOR hCur = (HCURSOR)iupAttribGet(ih, "_IUPWIN_HCURSOR");
        if (hCur)
        {
          SetCursor(hCur); 
          *result = 1;
          return 1;
        }
        else if (iupAttribGet(ih, "CURSOR"))
        {
          SetCursor(NULL); 
          *result = 1;
          return 1;
        }
      }
      break; 
    } 
  case WM_ERASEBKGND:
    {
      HBITMAP hBitmap = (HBITMAP)iupAttribGet(ih, "_IUPWIN_BACKGROUND_BITMAP");
      if (hBitmap) 
      {
        RECT rect;
        HDC hdc = (HDC)wp;

        HBRUSH hBrush = CreatePatternBrush(hBitmap);
        GetClientRect(ih->handle, &rect); 
        FillRect(hdc, &rect, hBrush); 
        DeleteObject(hBrush);

        /* return non zero value */
        *result = 1;
        return 1; 
      }
      else
      {
        unsigned char r, g, b;
        char* color = iupAttribGet(ih, "_IUPWIN_BACKGROUND_COLOR");
        if (iupStrToRGB(color, &r, &g, &b))
        {
          RECT rect;
          HDC hdc = (HDC)wp;

          SetDCBrushColor(hdc, RGB(r,g,b));
          GetClientRect(ih->handle, &rect); 
          FillRect(hdc, &rect, (HBRUSH)GetStockObject(DC_BRUSH)); 

          /* return non zero value */
          *result = 1;
          return 1;
        }
      }
      break;
    }
  case WM_DESTROY:
    {
      /* Since WM_CLOSE changed the Windows default processing                            */
      /* WM_DESTROY is NOT received by IupDialogs                                         */
      /* Except when they are children of other IupDialogs and the parent is destroyed.   */
      /* So we have to destroy the child dialog.                                          */
      /* The application is responsable for destroying the children before this happen.   */
      IupDestroy(ih);
      break;
    }
  }

  if (msg == (UINT)WM_HELPMSG)
  {
    Ihandle* child = NULL;
    DWORD* struct_ptr = (DWORD*)lp;
    if (*struct_ptr == sizeof(CHOOSECOLOR))
    {
      CHOOSECOLOR* choosecolor = (CHOOSECOLOR*)lp;
      child = (Ihandle*)choosecolor->lCustData;
    }
    if (*struct_ptr == sizeof(CHOOSEFONT))
    {
      CHOOSEFONT* choosefont = (CHOOSEFONT*)lp;
      child = (Ihandle*)choosefont->lCustData;
    }

    if (child)
    {
      Icallback cb = IupGetCallback(child, "HELP_CB");
      if (cb && cb(child) == IUP_CLOSE)
        EndDialog((HWND)iupAttribGet(child, "HWND"), IDCANCEL);
    }
  }

  return 0;
}