Exemple #1
0
void Fl_Tool_Button::preferred_size(int &w, int &h) const
{
    TbTextPos tp = textpos();
    if(tp==POS_DEFAULT) tp = default_textpos();

    TbShowMode sm = showmode();
    if(sm==SHOW_DEFAULT) sm = default_showmode();

    if(sm==SHOW_AUTO) {
        if(image()) sm = SHOW_IMAGE;
        else        sm = SHOW_TEXT;
    }

    int H=0, W=0;
    if(sm&SHOW_TEXT) {
        measure_label(W, H);
    }

    if(sm&SHOW_IMAGE) {
        int bw, bh;
        m_bar->get_icon_size(m_bar->tb_size(), bw, bh);

        if(tp == POS_RIGHT) W += bw;
        else                H += bh;

        if(W < bw) W = bw;
        if(H < bh) H = bh;
    }

    W += box()->dw() + 4;
    H += box()->dh() + 4;

    if(W < H) W = H;

    w = W;
    h = H;
}
void Flu_Toggle_Group :: draw()
{
  int lblW = 0, lblH, X, i;

  if( label() == 0 )
    lblW = lblH = 0;
  else if( strlen( label() ) == 0 )
    lblW = lblH = 0;
  else
    {
      measure_label( lblW, lblH );
      lblW += 18;
      lblH += 2;
    }

  // align the label
  if( align() & FL_ALIGN_LEFT )
    X = 4;
  else if( align() & FL_ALIGN_RIGHT )
    X = w() - lblW - 8;
  else
    X = w()/2 - lblW/2 - 2;

  // draw the main group box
  if( damage() & ~FL_DAMAGE_CHILD )
    fl_draw_box( box(), x(), y()+lblH/2, w(), h()-lblH/2, color() );

  unsigned char *active = 0;
  if( !chkBtn->value() )
    {
      active = (unsigned char*)malloc( children() );
      for( i = 1; i < children(); i++ )
	{
	  active[i-1] = child(i)->active();
	  child(i)->deactivate();
	}
    }

  // clip and draw the children
  chkBtn->resize( chkBtn->x(), chkBtn->y(), 0, 0 );
  fl_clip( x()+2, y()+lblH+1, w()-4, h()-lblH-3 );
  draw_children();
  fl_pop_clip();

  // clear behind the button and draw it
  fl_color( color() );
  fl_rectf( x()+X, y(), lblW+4, lblH );
  fl_color( labelcolor() );
  chkBtn->label( label() );
  chkBtn->resize( x()+X+2, y(), lblW, lblH );
  draw_child( *chkBtn );

  if( !chkBtn->value() )
    {
      for( i = 1; i < children(); i++ )
	{
	  if( active[i-1] )
	    child(i)->activate();
	  else
	    child(i)->deactivate();
	}
      free( active );
    }
}