예제 #1
0
static void iCboxComputeNaturalSizeMethod(Ihandle* ih, int *w, int *h, int *expand)
{
  Ihandle* child;
  int children_expand, 
      children_naturalwidth, children_naturalheight;
  int cx, cy;

  /* calculate total children natural size (even for hidden children) */
  children_expand = 0;
  children_naturalwidth = 0;
  children_naturalheight = 0;

  for (child = ih->firstchild; child; child = child->brother)
  {
    /* update child natural size first */
    iupBaseComputeNaturalSize(child);

    cx = iupAttribGetInt(child, "CX");
    cy = iupAttribGetInt(child, "CY");

    children_expand |= child->expand;
    children_naturalwidth = iupMAX(children_naturalwidth, cx+child->naturalwidth);
    children_naturalheight = iupMAX(children_naturalheight, cy+child->naturalheight);
  }

  *expand = children_expand;
  *w = children_naturalwidth;
  *h = children_naturalheight;
}
예제 #2
0
static void iTabsComputeNaturalSizeMethod(Ihandle* ih, int *w, int *h, int *expand)
{
  Ihandle* child;
  int children_expand, 
      children_naturalwidth, children_naturalheight;
  int decorwidth, decorheight;

  /* calculate total children natural size (even for hidden children) */
  children_expand = 0;
  children_naturalwidth = 0;
  children_naturalheight = 0;

  for (child = ih->firstchild; child; child = child->brother)
  {
    /* update child natural size first */
    iupBaseComputeNaturalSize(child);

    children_expand |= child->expand;
    children_naturalwidth = iupMAX(children_naturalwidth, child->naturalwidth);
    children_naturalheight = iupMAX(children_naturalheight, child->naturalheight);
  }

  iTabsGetDecorSize(ih, &decorwidth, &decorheight);

  *expand = children_expand;
  *w = children_naturalwidth + decorwidth;
  *h = children_naturalheight + decorheight;
}
예제 #3
0
파일: iup_zbox.c 프로젝트: defdef/iup
static void iZboxComputeNaturalSizeMethod(Ihandle* ih, int *w, int *h, int *children_expand)
{
  Ihandle* child;
  int children_naturalwidth, children_naturalheight;

  /* calculate total children natural size (even for hidden children) */
  children_naturalwidth = 0;
  children_naturalheight = 0;

  for (child = ih->firstchild; child; child = child->brother)
  {
    /* update child natural size first */
    if (!(child->flags & IUP_FLOATING_IGNORE))
      iupBaseComputeNaturalSize(child);

    if (!(child->flags & IUP_FLOATING))
    {
      *children_expand |= child->expand;
      children_naturalwidth = iupMAX(children_naturalwidth, child->naturalwidth);
      children_naturalheight = iupMAX(children_naturalheight, child->naturalheight);
    }
  }

  *w = children_naturalwidth;
  *h = children_naturalheight;
}
예제 #4
0
void iupBaseSetCurrentSize(Ihandle* ih, int w, int h, int shrink)
{
  if (ih->iclass->nativetype == IUP_TYPEDIALOG)
  {
    /* w and h parameters here are ignored, because they are always 0 for the dialog. */

    /* current size is zero before map and when reset by the application */
    /* after that the current size must follow the actual size of the dialog */
    if (!ih->currentwidth)  ih->currentwidth  = ih->naturalwidth;
    if (!ih->currentheight) ih->currentheight = ih->naturalheight;
  }
  else
  {
    if (ih->iclass->childtype != IUP_CHILDNONE && !shrink)
    {
      /* shrink is only used by containers, usually is 0 */
      /* for non containers is always 1, so they always can be smaller than the natural size */
      w = iupMAX(ih->naturalwidth, w);
      h = iupMAX(ih->naturalheight, h);
    }

    /* if expand use the given size, else use the natural size */
    ih->currentwidth = (ih->expand & IUP_EXPAND_WIDTH || ih->expand & IUP_EXPAND_WFREE) ? w : ih->naturalwidth;
    ih->currentheight = (ih->expand & IUP_EXPAND_HEIGHT || ih->expand & IUP_EXPAND_HFREE) ? h : ih->naturalheight;
  }

  /* crop also the current size if some expanded */
  if (ih->expand & IUP_EXPAND_WIDTH || ih->expand & IUP_EXPAND_HEIGHT ||
      ih->expand & IUP_EXPAND_WFREE || ih->expand & IUP_EXPAND_HFREE)
    iupLayoutApplyMinMaxSize(ih, &(ih->currentwidth), &(ih->currentheight));

  if (ih->firstchild)
    iupClassObjectSetChildrenCurrentSize(ih, shrink);
}
예제 #5
0
static int iNormalizerSetNormalizeAttrib(Ihandle* ih, const char* value)
{
  int i, count;
  Ihandle** ih_list;
  Ihandle* ih_control;
  int natural_maxwidth = 0, natural_maxheight = 0;
  int normalize = iNormalizeGetNormalizeSize(value);
  if (!normalize)
    return 1;

  count = iupArrayCount(ih->data->ih_array);
  ih_list = (Ihandle**)iupArrayGetData(ih->data->ih_array);

  for (i = 0; i < count; i++)
  {
    ih_control = ih_list[i];
    iupClassObjectComputeNaturalSize(ih_control);
    natural_maxwidth = iupMAX(natural_maxwidth, ih_control->naturalwidth);
    natural_maxheight = iupMAX(natural_maxheight, ih_control->naturalheight);
  }

  for (i = 0; i < count; i++)
  {
    ih_control = ih_list[i];
    if (!ih_control->floating && (ih_control->iclass->nativetype != IUP_TYPEVOID || !iupStrEqual(ih_control->iclass->name, "fill")))
    {
      if (normalize & NORMALIZE_WIDTH)
        ih_control->userwidth = natural_maxwidth;
      if (normalize & NORMALIZE_HEIGHT)
        ih_control->userheight = natural_maxheight;
    }
  }
  return 1;
}
예제 #6
0
static void iDetachBoxComputeNaturalSizeMethod(Ihandle* ih, int *w, int *h, int *children_expand)
{
  int natural_w = 0, 
      natural_h = 0;

  /* bar */
  if (ih->data->orientation == IDBOX_VERT)
    natural_w += ih->data->barsize;
  else
    natural_h += ih->data->barsize;

  if (ih->firstchild->brother)
  {
    Ihandle* child = ih->firstchild->brother;

    /* update child natural size first */
    iupBaseComputeNaturalSize(child);

    if (ih->data->orientation == IDBOX_VERT)
    {
      natural_w += child->naturalwidth;
      natural_h = iupMAX(natural_h, child->naturalheight);
    }
    else  /* IDBOX_HORIZ */
    {
      natural_w = iupMAX(natural_w, child->naturalwidth);
      natural_h += child->naturalheight;
    }

    *children_expand |= child->expand;
  }

  *w = natural_w;
  *h = natural_h;
}
예제 #7
0
static void iExpanderComputeNaturalSizeMethod(Ihandle* ih, int *w, int *h, int *expand)
{
  int child_expand = 0,
      natural_w, natural_h;
  Ihandle *child = ih->firstchild->brother;
  int bar_size = iExpanderGetBarSize(ih);

  /* bar */
  if (ih->data->position == IEXPANDER_LEFT || ih->data->position == IEXPANDER_RIGHT)
  {
    natural_w = bar_size;
    natural_h = IEXPAND_HANDLE_SIZE;
  }
  else
  {
    natural_w = IEXPAND_HANDLE_SIZE;
    natural_h = bar_size;

    if (ih->data->position == IEXPANDER_TOP)
    {
      char* title = iupAttribGetStr(ih, "TITLE");
      if (title)
      {
        int title_size = 0;
        iupdrvFontGetMultiLineStringSize(ih, title, &title_size, NULL);
        natural_w += title_size;
        natural_h += 2*IEXPAND_HANDLE_SPC;
      }
    }
  }

  if (child)
  {
    /* update child natural bar_size first */
    iupBaseComputeNaturalSize(child);

    if (ih->data->position == IEXPANDER_LEFT || ih->data->position == IEXPANDER_RIGHT)
    {
      if (ih->data->state == IEXPANDER_OPEN)  /* only open, not float */
        natural_w += child->naturalwidth;
      natural_h = iupMAX(natural_h, child->naturalheight);
    }
    else
    {
      natural_w = iupMAX(natural_w, child->naturalwidth);
      if (ih->data->state == IEXPANDER_OPEN)  /* only open, not float */
        natural_h += child->naturalheight;
    }

    child_expand = child->expand;
  }

  *expand = child_expand;
  *w = natural_w;
  *h = natural_h;
}
예제 #8
0
void iupBaseComputeNaturalSize(Ihandle* ih)
{
  /* always initialize the natural size using the user size */
  ih->naturalwidth = ih->userwidth;
  ih->naturalheight = ih->userheight;

  if (ih->iclass->childtype != IUP_CHILDNONE || 
      ih->iclass->nativetype == IUP_TYPEDIALOG)  /* pre-defined dialogs can restrict the number of children */
  {
    int w=0, h=0, children_expand=0;  /* if there is no children will not expand, when not a dialog */

    /* If a container then update the "expand" member from the EXPAND attribute.
       The ih->expand member can not be used for the container attribute because
       it is used to combine the container value with the children value. */
    iupBaseContainerUpdateExpand(ih);

    /* for containers always compute */
    iupClassObjectComputeNaturalSize(ih, &w, &h, &children_expand);

    if (ih->iclass->nativetype == IUP_TYPEDIALOG)
    {
      /* only update the natural size if user size is not defined. */
      /* IupDialog is the only container where this must be done */ 
      /* if the natural size is bigger than the actual dialog size then
         the dialog will be resized, if smaller then the dialog remains with the same size. */
      ih->expand |= children_expand;
      if (ih->naturalwidth <= 0) ih->naturalwidth = iupMAX(ih->currentwidth, w);
      if (ih->naturalheight <= 0) ih->naturalheight = iupMAX(ih->currentheight, h);
    }
    else
    {
      /* combine to only expand if the children can expand */
      ih->expand &= children_expand; 
      ih->naturalwidth = iupMAX(ih->naturalwidth, w);
      ih->naturalheight = iupMAX(ih->naturalheight, h);
    }
  }
  else 
  {
    /* for non-container only compute if user size is not defined */
    if (ih->naturalwidth <= 0 || ih->naturalheight <= 0)
    {
      int w=0, h=0, 
          children_expand;  /* unused if not a container */
      iupClassObjectComputeNaturalSize(ih, &w, &h, &children_expand);

      if (ih->naturalwidth <= 0) ih->naturalwidth = w;
      if (ih->naturalheight <= 0) ih->naturalheight = h;
    }
  }

  /* crop the natural size */
  iupLayoutApplyMinMaxSize(ih, &(ih->naturalwidth), &(ih->naturalheight));
}
예제 #9
0
static void iSboxComputeNaturalSizeMethod(Ihandle* ih, int *w, int *h, int *children_expand)
{
  int natural_w = ih->naturalwidth, 
      natural_h = ih->naturalheight;

  /* only allow expand in the oposite direction, complement iupBaseContainerUpdateExpand */
  if (ih->data->direction == ISBOX_EAST || ih->data->direction == ISBOX_WEST)
      ih->expand &= ~IUP_EXPAND_WIDTH;
  else 
      ih->expand &= ~IUP_EXPAND_HEIGHT;

  /* always has at least one child, the bar */

  /* This is an unusual element, the iupBaseComputeNaturalSize logic is done twice, one here and one back there. */

  if (ih->firstchild->brother)
  {
    Ihandle* child = ih->firstchild->brother;

    /* update child natural size first */
    iupBaseComputeNaturalSize(child);

    *children_expand = child->expand;

    /* calculate as in iupBaseComputeNaturalSize */
    natural_w = iupMAX(natural_w, child->naturalwidth  + iSboxGetXborder(ih));
    natural_h = iupMAX(natural_h, child->naturalheight + iSboxGetYborder(ih));
  }

  /* update control to fit its children according to direction */

  /* bar */
  if (ih->data->direction == ISBOX_EAST || ih->data->direction == ISBOX_WEST)
  {
    ih->data->w = iupMAX(natural_w, ih->data->w);
    ih->data->h = natural_h;
  }
  else  /* ISBOX_NORTH || ISBOX_SOUTH */
  {
    ih->data->w = natural_w;
    ih->data->h = iupMAX(natural_h, ih->data->h);
  }

  /* child */
  if (ih->firstchild->brother)
  {
    Ihandle* child = ih->firstchild->brother;
    child->naturalwidth  = ih->data->w - iSboxGetXborder(ih);
    child->naturalheight = ih->data->h - iSboxGetYborder(ih);
  }

  *w = ih->data->w;
  *h = ih->data->h;
}
예제 #10
0
static void iFlatButtonDrawIcon(Ihandle* ih, IdrawCanvas* dc, int icon_x, int icon_y, int icon_width, int icon_height,
                                const char *baseattrib, const char* imagename, const char* title, const char* fgcolor, const char* bgcolor, int active)
{
  int x, y, width, height;

  if (imagename)
  {
    if (title)
    {
      int img_x, img_y, txt_x, txt_y;
      int txt_width, txt_height;
      int img_width, img_height;

      iupdrvFontGetMultiLineStringSize(ih, title, &txt_width, &txt_height);
      iupImageGetInfo(imagename, &img_width, &img_height, NULL);

      if (ih->data->img_position == IUP_IMGPOS_RIGHT || ih->data->img_position == IUP_IMGPOS_LEFT)
      {
        width = img_width + txt_width + ih->data->spacing;
        height = iupMAX(img_height, txt_height);
      }
      else
      {
        width = iupMAX(img_width, txt_width);
        height = img_height + txt_height + ih->data->spacing;
      }

      iFlatButtonGetIconPosition(ih, icon_width, icon_height, &x, &y, width, height);

      iFlatButtonGetImageTextPosition(x, y, ih->data->img_position, ih->data->spacing,
                                      img_width, img_height, txt_width, txt_height,
                                      &img_x, &img_y, &txt_x, &txt_y);

      iFlatButtonDrawImage(ih, dc, img_x + icon_x, img_y + icon_y, baseattrib, imagename, active);
      iFlatButtonDrawText(ih, dc, txt_x + icon_x, txt_y + icon_y, title, fgcolor, bgcolor, active);
    }
    else
    {
      iupImageGetInfo(imagename, &width, &height, NULL);

      iFlatButtonGetIconPosition(ih, icon_width, icon_height, &x, &y, width, height);

      iFlatButtonDrawImage(ih, dc, x + icon_x, y + icon_y, baseattrib, imagename, active);
    }
  }
  else if (title)
  {
    iupdrvFontGetMultiLineStringSize(ih, title, &width, &height);

    iFlatButtonGetIconPosition(ih, icon_width, icon_height, &x, &y, width, height);

    iFlatButtonDrawText(ih, dc, x + icon_x, y + icon_y, title, fgcolor, bgcolor, active);
  }
}
예제 #11
0
static void iVboxComputeNaturalSizeMethod(Ihandle* ih, int *w, int *h, int *children_expand)
{
  Ihandle* child;
  int total_natural_width, total_natural_height;

  /* calculate total children natural size */
  int children_count = 0;
  int children_natural_maxwidth = 0;
  int children_natural_maxheight = 0;
  int children_natural_height = 0;

  for (child = ih->firstchild; child; child = child->brother)
  {
    /* update child natural size first */
    if (!(child->flags & IUP_FLOATING_IGNORE))
      iupBaseComputeNaturalSize(child);

    if (!(child->flags & IUP_FLOATING))
    {
      *children_expand |= child->expand;
      children_natural_maxwidth = iupMAX(children_natural_maxwidth, child->naturalwidth);
      children_natural_maxheight = iupMAX(children_natural_maxheight, child->naturalheight);
      children_count++;
    }
  }

  /* reset to max natural width and/or height if NORMALIZESIZE is defined */
  if (ih->data->normalize_size)
    iupNormalizeSizeBoxChild(ih, ih->data->normalize_size, children_natural_maxwidth, children_natural_maxheight);

  /* must be done after normalize */
  for (child = ih->firstchild; child; child = child->brother)
  {
    if (!(child->flags & IUP_FLOATING))
      children_natural_height += child->naturalheight;
  }

  /* leave room at the element for the maximum natural size of the children when is_homogeneous */
  if (ih->data->is_homogeneous)
    children_natural_height = children_natural_maxheight*children_count;

  /* compute the Vbox contents natural size */
  total_natural_width  = children_natural_maxwidth + 2*ih->data->margin_x;
  total_natural_height = children_natural_height + (children_count-1)*ih->data->gap + 2*ih->data->margin_y;

  /* Store to be used in iVboxCalcEmptyHeight */
  ih->data->total_natural_size = total_natural_height;

  *w = total_natural_width;
  *h = total_natural_height;
}
예제 #12
0
void iupBaseContainerSetCurrentSizeMethod(Ihandle* ih, int w, int h, int shrink)
{
  if (shrink)
  {
    /* if expand use the given size, else use the natural size */
    ih->currentwidth  = (ih->expand & IUP_EXPAND_WIDTH)  ? w : ih->naturalwidth;
    ih->currentheight = (ih->expand & IUP_EXPAND_HEIGHT) ? h : ih->naturalheight;
  }
  else
  {
    /* if expand use the given size (if greater than natural size), else use the natural size */
    ih->currentwidth  = (ih->expand & IUP_EXPAND_WIDTH)  ? iupMAX(ih->naturalwidth, w)  : ih->naturalwidth;
    ih->currentheight = (ih->expand & IUP_EXPAND_HEIGHT) ? iupMAX(ih->naturalheight, h) : ih->naturalheight;
  }
}
예제 #13
0
static void iFlatButtonComputeNaturalSizeMethod(Ihandle* ih, int *w, int *h, int *children_expand)
{
  int fit2backimage = iupAttribGetBoolean(ih, "FITTOBACKIMAGE");
  char* bgimage = iupAttribGet(ih, "BACKIMAGE");
  if (fit2backimage && bgimage)
    iupImageGetInfo(bgimage, w, h, NULL);
  else
  {
    char* image = iupAttribGet(ih, "IMAGE");
    char* title = iupAttribGet(ih, "TITLE");

    *w = 0,
    *h = 0;

    if (image)
    {
      iupImageGetInfo(image, w, h, NULL);

      if (title)
      {
        int text_w, text_h;
        iupdrvFontGetMultiLineStringSize(ih, title, &text_w, &text_h);

        if (ih->data->img_position == IUP_IMGPOS_RIGHT ||
            ih->data->img_position == IUP_IMGPOS_LEFT)
        {
          *w += text_w + ih->data->spacing;
          *h = iupMAX(*h, text_h);
        }
        else
        {
          *w = iupMAX(*w, text_w);
          *h += text_h + ih->data->spacing;
        }
      }
    }
    else if (title)
      iupdrvFontGetMultiLineStringSize(ih, title, w, h);

    *w += 2 * ih->data->horiz_padding;
    *h += 2 * ih->data->vert_padding;

    *w += 2 * ih->data->border_width;
    *h += 2 * ih->data->border_width;
  }

  (void)children_expand; /* unset if not a container */
}
예제 #14
0
파일: iup_glexpander.c 프로젝트: defdef/iup
static int iGLExpanderGetBarSize(Ihandle* ih)
{
  int bar_size;
  if (ih->data->barSize == -1)
  {
    iupGLFontGetCharSize(ih, NULL, &bar_size); 

    /* define a minimum size only when estimating one from charsize */
    if (bar_size < IEXPAND_HANDLE_SIZE)
      bar_size = IEXPAND_HANDLE_SIZE;

    if (ih->data->position == IEXPANDER_TOP)
    {
      char* title = iupAttribGetStr(ih, "TITLE");
      char* image = iupAttribGetStr(ih, "IMAGE");
      if (image)
      {
        int image_h = 0;
        iupGLImageGetInfo(image, NULL, &image_h, NULL);
        bar_size = iupMAX(bar_size, image_h);
      }

      if (title || image || ih->data->extra_buttons != 0)
        bar_size += 2 * IEXPAND_BACK_MARGIN;
    }
  }
  else
    bar_size = ih->data->barSize;

  return bar_size;
}
예제 #15
0
void iupdrvFontGetMultiLineStringSize(Ihandle* ih, const char* str, int *w, int *h)
{
  int max_w = 0;

  IwinFont* winfont = winFontGet(ih);
  if (!winfont)
  {
    if (w) *w = 0;
    if (h) *h = 0;
    return;
  }

  if (!str)
  {
    if (w) *w = 0;
    if (h) *h = winfont->charheight * 1;
    return;
  }

  if (str[0])
  {
    SIZE size;
    int len, wlen;
    const char *nextstr;
    const char *curstr = str;

    HDC hdc = winFontGetDC(ih);
    HFONT oldhfont = (HFONT)SelectObject(hdc, winfont->hFont);
    TCHAR* wstr = iupwinStrToSystem(str);

    do
    {
      nextstr = iupStrNextLine(curstr, &len);
      if (len)
      {
#ifdef UNICODE
        wlen = MultiByteToWideChar(iupwinStrGetUTF8Mode()? CP_UTF8: CP_ACP, 0, curstr, len, 0, 0);
#else
        wlen = len;
#endif

        size.cx = 0;
        GetTextExtentPoint32(hdc, wstr, wlen, &size);
        max_w = iupMAX(max_w, size.cx);

        wstr += wlen+1;
      }

      curstr = nextstr;
    } while(*nextstr);

    SelectObject(hdc, oldhfont);
    winFontReleaseDC(ih, hdc);
  }

  if (w) *w = max_w;
  if (h) *h = winfont->charheight * iupStrLineCount(str);
}
예제 #16
0
파일: iup_glexpander.c 프로젝트: defdef/iup
static int iGLExpanderIsInsideHandler(Ihandle* ih, int x, int y, int bar_size)
{
  char *image = iupAttribGet(ih, "IMAGE");
  char* title = iupAttribGet(ih, "TITLE");

  if (ih->data->position == IEXPANDER_TOP && (title || image || ih->data->extra_buttons != 0))
  {
    /* always left aligned */

    if (y >= IEXPAND_SPACING + IEXPAND_BACK_MARGIN && y <= bar_size - IEXPAND_SPACING - IEXPAND_BACK_MARGIN)
    {
      int icon_width = IEXPAND_HANDLE_SIZE;
      if (image)
      {
        int width;
        iupGLImageGetInfo(image, &width, NULL, NULL);
        icon_width = iupMAX(icon_width, width);
      }
      if (title)
      {
        int width;
        iupGLFontGetMultiLineStringSize(ih, title, &width, NULL);
        icon_width += width;
      }

      if (x >= IEXPAND_BACK_MARGIN && 
          x < IEXPAND_BACK_MARGIN + icon_width)
        return 1;
    }
  }
  else
  {
    /* always centered */

    if (ih->data->position == IEXPANDER_TOP || ih->data->position == IEXPANDER_BOTTOM)
    {
      if (y >= IEXPAND_SPACING && y <= bar_size - IEXPAND_SPACING)
      {
        int half = ih->currentwidth / 2;
        if (x >= half - IEXPAND_HANDLE_SIZE / 2 && x <= half + IEXPAND_HANDLE_SIZE/2)
            return 1;
      }
    }
    else /* IEXPANDER_LEFT or IEXPANDER_RIGHT */
    {
      if (x >= IEXPAND_SPACING && x <= bar_size - IEXPAND_SPACING)
      {
        int half = ih->currentheight / 2;
        if (y >= half - IEXPAND_HANDLE_SIZE / 2 && y <= half + IEXPAND_HANDLE_SIZE / 2)
          return 1;
      }
    }
  }

  return 0;
}
예제 #17
0
static void iRadioComputeNaturalSizeMethod(Ihandle* ih)
{
  iupBaseContainerUpdateExpand(ih);

  /* always initialize the natural size using the user size */
  ih->naturalwidth = ih->userwidth;
  ih->naturalheight = ih->userheight;

  if (ih->firstchild)
  {
    Ihandle* child = ih->firstchild;

    /* update child natural size first */
    iupClassObjectComputeNaturalSize(child);

    ih->expand &= child->expand; /* compose but only expand where the box can expand */

    ih->naturalwidth = iupMAX(ih->naturalwidth, child->naturalwidth);
    ih->naturalheight = iupMAX(ih->naturalheight, child->naturalheight);
  }
}
예제 #18
0
static void iDialogSetCurrentSizeMethod(Ihandle* ih, int w, int h, int shrink)
{
  /* width and height parameters here are ignored, because they are always 0 for the dialog. */
  (void)w;
  (void)h;

  /* current size is zero before map and when reset by the application */
  /* after that the current size must follow the actual size of the dialog */

  if (!ih->currentwidth)
    ih->currentwidth = ih->naturalwidth;

  if (!ih->currentheight)
    ih->currentheight = ih->naturalheight;

  if (ih->firstchild)
  {
    int decorwidth, decorheight, client_width, client_height;

    if (shrink)
    {
      client_width = ih->currentwidth;
      client_height = ih->currentheight;
    }
    else
    {
      client_width = iupMAX(ih->naturalwidth, ih->currentwidth);
      client_height = iupMAX(ih->naturalheight, ih->currentheight);
    }

    iupDialogGetDecorSize(ih, &decorwidth, &decorheight);
    client_width -= decorwidth;
    client_height -= decorheight;

    iupClassObjectSetCurrentSize(ih->firstchild, client_width, client_height, shrink);
  }
}
예제 #19
0
void iupdrvFontGetMultiLineStringSize(Ihandle* ih, const char* str, int *w, int *h)
{
  int num_lin, max_w;

  IwinFont* winfont = winFontGet(ih);
  if (!winfont)
  {
    if (w) *w = 0;
    if (h) *h = 0;
    return;
  }

  if (!str)
  {
    if (w) *w = 0;
    if (h) *h = winfont->charheight * 1;
    return;
  }

  max_w = 0;
  num_lin = 1;
  if (str[0])
  {
    SIZE size;
    int len;
    const char *nextstr;
    const char *curstr = str;

    HDC hdc = winFontGetDC(ih);
    HFONT oldhfont = SelectObject(hdc, winfont->hFont);

    do
    {
      nextstr = iupStrNextLine(curstr, &len);
      GetTextExtentPoint32(hdc, curstr, len, &size);
      max_w = iupMAX(max_w, size.cx);

      curstr = nextstr;
      if (*nextstr)
        num_lin++;
    } while(*nextstr);

    SelectObject(hdc, oldhfont);
    winFontReleaseDC(ih, hdc);
  }

  if (w) *w = max_w;
  if (h) *h = winfont->charheight*num_lin;
}
예제 #20
0
static void iDialogSetChildrenCurrentSizeMethod(Ihandle* ih, int shrink)
{
  int decorwidth, decorheight, client_width, client_height;

  if (shrink)
  {
    client_width = ih->currentwidth;
    client_height = ih->currentheight;
  }
  else
  {
    client_width = iupMAX(ih->naturalwidth, ih->currentwidth);
    client_height = iupMAX(ih->naturalheight, ih->currentheight);
  }

  iupDialogGetDecorSize(ih, &decorwidth, &decorheight);

  client_width  -= decorwidth;
  client_height -= decorheight;
  if (client_width < 0) client_width = 0;
  if (client_height < 0) client_height = 0;

  iupBaseSetCurrentSize(ih->firstchild, client_width, client_height, shrink);
}
예제 #21
0
static void iTabsComputeNaturalSizeMethod(Ihandle* ih)
{
  iupBaseContainerUpdateExpand(ih);

  /* always initialize the natural size using the user size */
  ih->naturalwidth  = ih->userwidth;
  ih->naturalheight = ih->userheight;

  if (ih->firstchild)
  {
    Ihandle* child;
    int children_expand, 
        children_naturalwidth, children_naturalheight;
    int decorwidth, decorheight;

    /* calculate total children natural size (even for hidden children) */
    children_expand = 0;
    children_naturalwidth = 0;
    children_naturalheight = 0;
    for (child = ih->firstchild; child; child = child->brother)
    {
      /* update child natural size first */
      iupClassObjectComputeNaturalSize(child);

      children_expand |= child->expand;
      children_naturalwidth = iupMAX(children_naturalwidth, child->naturalwidth);
      children_naturalheight = iupMAX(children_naturalheight, child->naturalheight);
    }

    iTabsGetDecorSize(ih, &decorwidth, &decorheight);

    ih->expand &= children_expand; /* compose but only expand where the box can expand */
    ih->naturalwidth = iupMAX(ih->naturalwidth, children_naturalwidth + decorwidth);
    ih->naturalheight = iupMAX(ih->naturalheight, children_naturalheight + decorheight);
  }
}
예제 #22
0
static void iFrameComputeNaturalSizeMethod(Ihandle* ih)
{
  iupBaseContainerUpdateExpand(ih);

  /* always initialize the natural size using the user size */
  ih->naturalwidth = ih->userwidth;
  ih->naturalheight = ih->userheight;

  /* Frame has only one child */
  if (ih->firstchild)
  {
    int decorwidth, decorheight;
    Ihandle* child = ih->firstchild;

    /* update child natural size first */
    iupClassObjectComputeNaturalSize(child);

    iFrameGetDecorSize(ih, &decorwidth, &decorheight);

    ih->expand &= child->expand; /* compose but only expand where the box can expand */
    ih->naturalwidth = iupMAX(ih->naturalwidth, child->naturalwidth + decorwidth);
    ih->naturalheight = iupMAX(ih->naturalheight, child->naturalheight + decorheight);
  }
}
예제 #23
0
static void iDialogComputeNaturalSizeMethod(Ihandle* ih)
{
  iupBaseContainerUpdateExpand(ih);

  /* always initialize the natural size using the user size */
  ih->naturalwidth = ih->userwidth;
  ih->naturalheight = ih->userheight;

  /* the dialog has only one child      */
  if (ih->firstchild)
  {
    int decorwidth, decorheight;
    Ihandle* child = ih->firstchild;

    iupDialogGetDecorSize(ih, &decorwidth, &decorheight);

    /* update child natural size first */
    iupClassObjectComputeNaturalSize(child);

    ih->expand |= child->expand;
    ih->naturalwidth = iupMAX(ih->naturalwidth, child->naturalwidth + decorwidth);
    ih->naturalheight = iupMAX(ih->naturalheight, child->naturalheight + decorheight);
  }
}
예제 #24
0
void iupdrvFontGetMultiLineStringSize(Ihandle* ih, const char* str, int *w, int *h)
{
  int num_lin, max_w;

  ImotFont* motfont = motGetFont(ih);
  if (!motfont)
  {
    if (w) *w = 0;
    if (h) *h = 0;
    return;
  }

  if (!str)
  {
    if (w) *w = 0;
    if (h) *h = motfont->charheight * 1;
    return;
  }
  
  max_w = 0;
  num_lin = 1;
  if (str[0])
  {
    int len, lw;
    const char *nextstr;
    const char *curstr = str;
    do
    {
      nextstr = iupStrNextLine(curstr, &len);
      lw = XTextWidth(motfont->fontstruct, curstr, len);
      max_w = iupMAX(max_w, lw);

      curstr = nextstr;
      if (*nextstr)
        num_lin++;
    } while(*nextstr);
  }

  if (w) *w = max_w;
  if (h) *h = motfont->charheight * num_lin;
}
예제 #25
0
static void iGLFrameComputeNaturalSizeMethod(Ihandle* ih, int *w, int *h, int *children_expand)
{
    int decorwidth, decorheight, title_width;
    Ihandle* child = ih->firstchild;

    iGLFrameGetDecorSize(ih, &decorwidth, &decorheight, &title_width);
    *w = decorwidth;
    *h = decorheight;

    if (child)
    {
        /* update child natural size first */
        iupBaseComputeNaturalSize(child);

        *children_expand = child->expand;
        *w += iupMAX(child->naturalwidth, title_width);  /* make room for title always */
        *h += child->naturalheight;
    }
    else
        *w += title_width;
}
예제 #26
0
static void iSpinboxComputeNaturalSizeMethod(Ihandle* ih, int *w, int *h, int *children_expand)
{
  /* update spin natural size */
  iupBaseComputeNaturalSize(ih->firstchild);

  if (ih->firstchild->brother)
  {
    /* update child natural size */
    iupBaseComputeNaturalSize(ih->firstchild->brother);

    *children_expand = ih->firstchild->brother->expand;

    *w = ih->firstchild->brother->naturalwidth + ih->firstchild->naturalwidth;
    *h = iupMAX(ih->firstchild->brother->naturalheight, ih->firstchild->naturalheight);
  }
  else
  {
    *w = ih->firstchild->naturalwidth;
    *h = ih->firstchild->naturalheight;
  }
}
예제 #27
0
파일: iup_glexpander.c 프로젝트: defdef/iup
static int iGLExpanderACTION_CB(Ihandle* ih)
{
  int x1, y1, x2, y2;
  char *image = iupAttribGet(ih, "IMAGE");
  char* title = iupAttribGet(ih, "TITLE");
  int active = iupAttribGetInt(ih, "ACTIVE");
  char* fgcolor = iupAttribGetStr(ih, "FORECOLOR");
  char* bgcolor = iupAttribGetStr(ih, "BACKCOLOR");
  int highlight = iupAttribGetInt(ih, "HIGHLIGHT");
  int pressed = iupAttribGetInt(ih, "PRESSED");
  int bar_size = iGLExpanderGetBarSize(ih);

  /* calc bar position */
  if (ih->data->position == IEXPANDER_LEFT)
  {
    x1 = 0;
    x2 = bar_size;
    y1 = 0;
    y2 = ih->currentheight - 1;
  }
  else if (ih->data->position == IEXPANDER_RIGHT)
  {
    x1 = ih->currentwidth-1 - bar_size;
    x2 = ih->currentwidth-1;
    y1 = 0;
    y2 = ih->currentheight - 1;
  }
  else if (ih->data->position == IEXPANDER_BOTTOM)
  {
    x1 = 0;
    x2 = ih->currentwidth - 1;
    y1 = ih->currentheight-1 - bar_size;
    y2 = ih->currentheight-1;
  }
  else /* IEXPANDER_TOP */
  {
    x1 = 0;
    x2 = ih->currentwidth - 1;
    y1 = 0;
    y2 = bar_size;
  }

  /* draw bar box */
  iupGLDrawBox(ih, x1, x2, y1, y2, bgcolor, 1);

  if (ih->data->position == IEXPANDER_TOP && (title || image || ih->data->extra_buttons != 0))
  {
    /* left align image/handler+title */
    int txt_offset = IEXPAND_HANDLE_SIZE;

    if (image)
    {
      int active = IupGetInt(ih, "ACTIVE");
      int img_width = 0, img_height = 0;
      int y_offset = 0;

      if (ih->data->state != IEXPANDER_CLOSE)
      {
        char* imopen = iupAttribGetStr(ih, "IMAGEOPEN");
        if (imopen) image = imopen;

        if (highlight)
        {
          char* imhighlight = iupAttribGetStr(ih, "IMAGEOPENHIGHLIGHT");
          if (imhighlight) image = imhighlight;
        }
      }
      else if (highlight)
      {
        char* imhighlight = iupAttribGetStr(ih, "IMAGEHIGHLIGHT");
        if (imhighlight) image = imhighlight;
      }

      iupGLImageGetInfo(image, &img_width, &img_height, NULL);
      if (bar_size > img_height)
        y_offset = (bar_size - img_height) / 2;

      iupGLDrawImage(ih, IEXPAND_BACK_MARGIN, y_offset, image, !active);

      txt_offset = iupMAX(txt_offset, img_width);
    }
    else
    {
      int y_offset = 0;
      if (bar_size > IEXPAND_HANDLE_SIZE + 2 * IEXPAND_BACK_MARGIN)
        y_offset = (bar_size - IEXPAND_HANDLE_SIZE - 2 * IEXPAND_BACK_MARGIN) / 2;

      if (pressed)
      {
        char* presscolor = iupAttribGetStr(ih, "PRESSCOLOR");
        if (presscolor)
          fgcolor = presscolor;
      }
      else if (highlight)
      {
        char* hlcolor = iupAttribGetStr(ih, "HIGHCOLOR");
        if (hlcolor)
          fgcolor = hlcolor;
      }

      if (ih->data->state == IEXPANDER_CLOSE)
        iGLExpanderDrawSmallArrow(ih, fgcolor, active, IEXPANDER_RIGHT, y_offset);
      else
        iGLExpanderDrawSmallArrow(ih, fgcolor, active, IEXPANDER_BOTTOM, y_offset);
    }

    if (title)
    {
      int height;
      iupGLFontGetMultiLineStringSize(ih, title, NULL, &height);
      iupGLDrawText(ih, txt_offset, (bar_size - height) / 2 - 1, title, fgcolor, active);
    }

    if (ih->data->extra_buttons != 0)
    {
      /* right align extra buttons */
      int y = IEXPAND_SPACING + IEXPAND_BACK_MARGIN;
      int height = bar_size - 2 * (IEXPAND_SPACING + IEXPAND_BACK_MARGIN);

      iGLExpanderDrawExtraButton(ih, 1, ih->currentwidth - (IEXPAND_BUTTON_SIZE + IEXPAND_SPACING) - IEXPAND_BACK_MARGIN, y, height);

      if (ih->data->extra_buttons > 1)
        iGLExpanderDrawExtraButton(ih, 2, ih->currentwidth - 2 * (IEXPAND_BUTTON_SIZE + IEXPAND_SPACING) - IEXPAND_BACK_MARGIN, y, height);

      if (ih->data->extra_buttons == 3)
        iGLExpanderDrawExtraButton(ih, 3, ih->currentwidth - 3 * (IEXPAND_BUTTON_SIZE + IEXPAND_SPACING) - IEXPAND_BACK_MARGIN, y, height);
    }
  }
  else
  {
    /* center align the handler */
    int x = x1, 
        y = y1, 
        width = x2 - x1 + 1,
        height = y2 - y1 + 1;

    if (pressed)
    {
      char* presscolor = iupAttribGetStr(ih, "PRESSCOLOR");
      if (presscolor)
        fgcolor = presscolor;
    }
    else if (highlight)
    {
      char* hlcolor = iupAttribGetStr(ih, "HIGHCOLOR");
      if (hlcolor)
        fgcolor = hlcolor;
    }

    switch (ih->data->position)
    {
    case IEXPANDER_LEFT:
      x += 0;
      y += (height - IEXPAND_HANDLE_SIZE) / 2;
      if (ih->data->state == IEXPANDER_CLOSE)
        iGLExpanderDrawArrow(ih, x, y, fgcolor, active, IEXPANDER_RIGHT);
      else
        iGLExpanderDrawArrow(ih, x, y, fgcolor, active, IEXPANDER_LEFT);
      break;
    case IEXPANDER_RIGHT:
      x += 0;
      y += (height - IEXPAND_HANDLE_SIZE) / 2;
      if (ih->data->state == IEXPANDER_CLOSE)
        iGLExpanderDrawArrow(ih, x, y, fgcolor, active, IEXPANDER_LEFT);
      else
        iGLExpanderDrawArrow(ih, x, y, fgcolor, active, IEXPANDER_RIGHT);
      break;
    case IEXPANDER_TOP:
      x += (width - IEXPAND_HANDLE_SIZE) / 2;
      y += 0;
      if (ih->data->state == IEXPANDER_CLOSE)
        iGLExpanderDrawArrow(ih, x, y, fgcolor, active, IEXPANDER_BOTTOM);
      else
        iGLExpanderDrawArrow(ih, x, y, fgcolor, active, IEXPANDER_TOP);
      break;
    case IEXPANDER_BOTTOM:
      x += (width - IEXPAND_HANDLE_SIZE) / 2;
      y += 0;
      if (ih->data->state == IEXPANDER_CLOSE)
        iGLExpanderDrawArrow(ih, x, y, fgcolor, active, IEXPANDER_TOP);
      else
        iGLExpanderDrawArrow(ih, x, y, fgcolor, active, IEXPANDER_BOTTOM);
      break;
    }
  }

  return IUP_DEFAULT;
}
예제 #28
0
파일: iup_glexpander.c 프로젝트: defdef/iup
static void iGLExpanderComputeNaturalSizeMethod(Ihandle* ih, int *w, int *h, int *children_expand)
{
  int child_expand = 0,
      natural_w, natural_h;
  Ihandle *child = ih->firstchild;
  int bar_size = iGLExpanderGetBarSize(ih);

  /* bar */
  if (ih->data->position == IEXPANDER_LEFT || ih->data->position == IEXPANDER_RIGHT)
  {
    natural_w = bar_size;
    natural_h = IEXPAND_HANDLE_SIZE;  /* just a minimum size */
  }
  else
  {
    natural_w = IEXPAND_HANDLE_SIZE;  /* just a minimum size */
    natural_h = bar_size;

    if (ih->data->position == IEXPANDER_TOP)
    {
      char* title, *image;

      /* if IMAGE is defined assume that will cover all the canvas area */
      image = iupAttribGetStr(ih, "IMAGE");
      if (image)
      {
        int image_w = 0;
        iupGLImageGetInfo(image, &image_w, NULL, NULL);
        natural_w = iupMAX(natural_w, image_w);
      }

      /* if TITLE and IMAGE are both defined then 
         IMAGE is only the handle */

      title = iupAttribGetStr(ih, "TITLE");
      if (title)
      {
        int title_size = 0;
        iupGLFontGetMultiLineStringSize(ih, title, &title_size, NULL);
        natural_w += title_size;
      }

      if (ih->data->extra_buttons != 0)
        natural_w += ih->data->extra_buttons * (IEXPAND_BUTTON_SIZE + IEXPAND_SPACING);

      if (image || title || ih->data->extra_buttons != 0)
        natural_w += 2 * IEXPAND_BACK_MARGIN;
    }
  }

  if (child)
  {
    /* update child natural bar_size first */
    iupBaseComputeNaturalSize(child);

    if (ih->data->position == IEXPANDER_LEFT || ih->data->position == IEXPANDER_RIGHT)
    {
      if (ih->data->state == IEXPANDER_OPEN)  /* only open, not float */
        natural_w += child->naturalwidth;
      natural_h = iupMAX(natural_h, child->naturalheight);
    }
    else
    {
      natural_w = iupMAX(natural_w, child->naturalwidth);
      if (ih->data->state == IEXPANDER_OPEN)  /* only open, not float */
        natural_h += child->naturalheight;
    }

    if (ih->data->state == IEXPANDER_OPEN)
      child_expand = child->expand;
    else
    {
      if (ih->data->position == IEXPANDER_LEFT || ih->data->position == IEXPANDER_RIGHT)
        child_expand = child->expand & IUP_EXPAND_HEIGHT;  /* only vertical allowed */
      else
        child_expand = child->expand & IUP_EXPAND_WIDTH;  /* only horizontal allowed */
    }
  }

  *children_expand = child_expand;
  *w = natural_w;
  *h = natural_h;
}
예제 #29
0
파일: iupwin_button.c 프로젝트: defdef/iup
static void winButtonDrawImageText(Ihandle* ih, HDC hDC, int rect_width, int rect_height, int border, UINT itemState)
{
  int xpad = ih->data->horiz_padding + border, 
      ypad = ih->data->vert_padding + border;
  int x, y, width, height, 
      txt_x, txt_y, txt_width, txt_height, 
      img_x, img_y, img_width, img_height, 
      bpp, shift = 0, style = 0;
  HFONT hFont = (HFONT)iupwinGetHFontAttrib(ih);
  HBITMAP hBitmap, hMask;
  COLORREF fgcolor;

  char* title = iupAttribGet(ih, "TITLE");
  char* str = iupStrProcessMnemonic(title, NULL, 0);   /* remove & */
  iupdrvFontGetMultiLineStringSize(ih, str, &txt_width, &txt_height);
  if (str && str!=title) free(str);

  if (itemState & ODS_DISABLED)
    fgcolor = GetSysColor(COLOR_GRAYTEXT);
  else
    fgcolor = ih->data->fgcolor;

  hBitmap = winButtonGetBitmap(ih, itemState, NULL, &img_width, &img_height, &bpp, &hMask);
  if (!hBitmap)
    return;

  if (ih->data->img_position == IUP_IMGPOS_RIGHT ||
      ih->data->img_position == IUP_IMGPOS_LEFT)
  {
    width  = img_width + txt_width + ih->data->spacing;
    height = iupMAX(img_height, txt_height);
  }
  else
  {
    width = iupMAX(img_width, txt_width);
    height = img_height + txt_height + ih->data->spacing;
  }

  if (itemState & ODS_SELECTED && !iupwin_comctl32ver6)
    shift = 1;

  if (itemState & ODS_NOACCEL && !iupwinGetKeyBoardCues())
    style |= DT_HIDEPREFIX;

  x = winButtonCalcAlignPosX(ih->data->horiz_alignment, rect_width, width, xpad, shift);
  y = winButtonCalcAlignPosY(ih->data->vert_alignment, rect_height, height, ypad, shift);

  switch(ih->data->img_position)
  {
  case IUP_IMGPOS_TOP:
    img_y = y;
    txt_y = y + img_height + ih->data->spacing;
    if (img_width > txt_width)
    {
      img_x = x;
      txt_x = x + (img_width-txt_width)/2;
    }
    else
    {
      img_x = x + (txt_width-img_width)/2;
      txt_x = x;
    }
    break;
  case IUP_IMGPOS_BOTTOM:
    img_y = y + txt_height + ih->data->spacing;
    txt_y = y;
    if (img_width > txt_width)
    {
      img_x = x;
      txt_x = x + (img_width-txt_width)/2;
    }
    else
    {
      img_x = x + (txt_width-img_width)/2;
      txt_x = x;
    }
    break;
  case IUP_IMGPOS_RIGHT:
    img_x = x + txt_width + ih->data->spacing;
    txt_x = x;
    if (img_height > txt_height)
    {
      img_y = y;
      txt_y = y + (img_height-txt_height)/2;
    }
    else
    {
      img_y = y + (txt_height-img_height)/2;
      txt_y = y;
    }
    break;
  default: /* IUP_IMGPOS_LEFT */
    img_x = x;
    txt_x = x + img_width + ih->data->spacing;
    if (img_height > txt_height)
    {
      img_y = y;
      txt_y = y + (img_height-txt_height)/2;
    }
    else
    {
      img_y = y + (txt_height-img_height)/2;
      txt_y = y;
    }
    break;
  }

  if (ih->data->horiz_alignment == IUP_ALIGN_ACENTER)
    style |= DT_CENTER;  /* let DrawText do the internal horizontal alignment, usefull for multiple lines */
  else if (ih->data->horiz_alignment == IUP_ALIGN_ARIGHT)
    style |= DT_RIGHT;

  iupwinDrawBitmap(hDC, hBitmap, hMask, img_x, img_y, img_width, img_height, bpp);
  iupwinDrawText(hDC, title, txt_x, txt_y, txt_width, txt_height, hFont, fgcolor, style);

  if (hMask)
    DeleteObject(hMask);
}
예제 #30
0
static void iButtonComputeNaturalSizeMethod(Ihandle* ih, int *w, int *h, int *children_expand)
{
  int natural_w = 0, 
      natural_h = 0, 
      type = ih->data->type;
  (void)children_expand; /* unset if not a container */

  if (!ih->handle)
  {
    /* if not mapped must initialize the internal values */
    char* value = iupAttribGet(ih, "IMAGE");
    if (value)
    {
      char* title = iupAttribGet(ih, "TITLE");
      type = IUP_BUTTON_IMAGE;
      if (title && *title!=0)
        type |= IUP_BUTTON_TEXT;
    }
    else
      type = IUP_BUTTON_TEXT;
  }

  if (type & IUP_BUTTON_IMAGE)
  {
    iupImageGetInfo(iupAttribGet(ih, "IMAGE"), &natural_w, &natural_h, NULL);

    if (type & IUP_BUTTON_TEXT)
    {
      int text_w, text_h;
      /* must use IupGetAttribute to check from the native implementation */
      char* title = IupGetAttribute(ih, "TITLE");
      iupdrvFontGetMultiLineStringSize(ih, title, &text_w, &text_h);

      if (ih->data->img_position == IUP_IMGPOS_RIGHT ||
          ih->data->img_position == IUP_IMGPOS_LEFT)
      {
        natural_w += text_w + ih->data->spacing;
        natural_h = iupMAX(natural_h, text_h);
      }
      else
      {
        natural_w = iupMAX(natural_w, text_w);
        natural_h += text_h + ih->data->spacing;
      }
    }
  }
  else /* IUP_BUTTON_TEXT only */
  {
    /* must use IupGetAttribute to check from the native implementation */
    char* title = IupGetAttribute(ih, "TITLE");
    char* str = iupStrProcessMnemonic(title, NULL, 0);   /* remove & */
    iupdrvFontGetMultiLineStringSize(ih, str, &natural_w, &natural_h);
    if (str && str!=title) free(str);
  }

  /* if IMPRESS is set, do NOT compute the borders space */
  if (!((type == IUP_BUTTON_IMAGE) &&
        iupAttribGet(ih, "IMPRESS") && 
        !iupAttribGetBoolean(ih, "IMPRESSBORDER")))
    iupdrvButtonAddBorders(&natural_w, &natural_h);

  natural_w += 2*ih->data->horiz_padding;
  natural_h += 2*ih->data->vert_padding;

  *w = natural_w;
  *h = natural_h;
}