Example #1
0
WWidget *WToolBar::widget(int index) const
{
  if (compact_)
    return impl_->widget(index);
  else {
    int current = 0;
    for (int i = 0; i < impl_->count(); ++i) {
      WWidget *w = impl_->widget(i);

      if (dynamic_cast<WSplitButton *>(w)) {
	if (index == current)
	  return w;
	++current;
      } else {
	WContainerWidget *group = dynamic_cast<WContainerWidget *>(w);

	if (index < current + group->count())
	  return group->widget(index - current);

	current += group->count();
      }
    }

    return 0;
  }
}
Example #2
0
WImage *WItemDelegate::iconWidget(WidgetRef& w, bool autoCreate)
{
  WImage *image = dynamic_cast<WImage *>(w.w->find("i"));
  if (image || !autoCreate)
    return image;

  WContainerWidget *wc = dynamic_cast<WContainerWidget *>(w.w->find("a"));

  if (!wc)
    wc = dynamic_cast<WContainerWidget *>(w.w->find("o"));

  if (!wc) {
    wc = new WContainerWidget();
    wc->setObjectName("o");
    wc->addWidget(w.w);
    w.w = wc;
  }

  image = new WImage();
  image->setObjectName("i");
  image->setStyleClass("icon");
  wc->insertWidget(wc->count() - 1, image);

  // IE does not want to center vertically without this:
  if (wApp->environment().agentIsIE()) {
    WImage *inv = new WImage(wApp->onePixelGifUrl());
    inv->setStyleClass("rh w0 icon");
    inv->resize(0, WLength::Auto);
    wc->insertWidget(wc->count() -1, inv);
  }

  return image;
}
Example #3
0
int WToolBar::count() const
{
  if (compact_)
    return impl_->count();
  else {
    int result = 0;
    for (int i = 0; i < impl_->count(); ++i) {
      WWidget *w = impl_->widget(i);

      if (dynamic_cast<WSplitButton *>(w))
	++result;
      else {
	WContainerWidget *group = dynamic_cast<WContainerWidget *>(w);

	result += group->count();
      }
    }

    return result;
  }
}
Example #4
0
WAnchor *WItemDelegate::anchorWidget(WidgetRef& w)
{
  WAnchor *anchor = dynamic_cast<WAnchor *>(w.w->find("a"));
  if (anchor)
    return anchor;

  anchor = new WAnchor();
  anchor->setObjectName("a");

  WContainerWidget *wc = dynamic_cast<WContainerWidget *>(w.w->find("o"));
  if (wc) {
    /*
     * Convert (2) -> (4)
     */
    int firstToMove = 0;

    WCheckBox *cb = dynamic_cast<WCheckBox *>(wc->widget(0));
    if (cb)
      firstToMove = 1;

    wc->insertWidget(firstToMove, anchor);

    while (wc->count() > firstToMove + 1) { 
      WWidget *c = wc->widget(firstToMove + 1);
      wc->removeWidget(c);
      anchor->addWidget(c);
    }
  } else {
    /*
     * Convert (1) -> (3)
     */
    anchor->addWidget(w.w);
    w.w = anchor;
  }

  return anchor;
}