void WTreeNode::setLabelIcon(WIconPair *labelIcon) { delete labelIcon_; labelIcon_ = labelIcon; if (labelIcon_) { if (labelText_) labelArea()->insertBefore(labelIcon_, labelText_); else labelArea()->addWidget(labelIcon_); labelIcon_->setState(isExpanded() ? 1 : 0); } }
void WTreeNode::setChildCountPolicy(ChildCountPolicy policy) { if (policy != Disabled && !childCountLabel_) { childCountLabel_ = new WText(); childCountLabel_->setMargin(WLength(7), Left); childCountLabel_->setStyleClass("Wt-childcount"); labelArea()->addWidget(childCountLabel_); } childCountPolicy_ = policy; if (childCountPolicy_ == Enabled) { WTreeNode *parent = parentNode(); if (parent && parent->isExpanded()) if (doPopulate()) update(); } if (childCountPolicy_ != Disabled) { for (unsigned i = 0; i < childNodes_.size(); ++i) childNodes_[i]->setChildCountPolicy(childCountPolicy_); } }
void WTreeTableNode::createExtraColumns(int numColumns) { if (!row_) { row_ = new WContainerWidget(); labelArea()->insertBefore(row_, labelArea()->children()[0]); row_->setFloatSide(Right); labelArea()->resize(WLength(100, WLength::Percentage), WLength::Auto); labelArea()->table()->resize(WLength(100, WLength::Percentage), WLength::Auto); } while (static_cast<int>(columnWidgets_.size()) < numColumns) { WText *w = new WText(WString::fromUTF8(" "), row_); w->setInline(false); columnWidgets_.push_back(ColumnWidget(w, false)); w->setFloatSide(Left); w->resize(columnWidth(columnWidgets_.size()), 1); } }
void BTextControl::Draw(BRect updateRect) { bool enabled = IsEnabled(); bool active = fText->IsFocus() && Window()->IsActive(); BRect rect = fText->Frame(); rect.InsetBy(-2, -2); if (be_control_look != NULL) { rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR); uint32 flags = 0; if (!enabled) flags |= BControlLook::B_DISABLED; if (active) flags |= BControlLook::B_FOCUSED; be_control_look->DrawTextControlBorder(this, rect, updateRect, base, flags); rect = Bounds(); rect.right = fDivider - kLabelInputSpacing; // rect.right = fText->Frame().left - 2; // rect.right -= 3;//be_control_look->DefaultLabelSpacing(); be_control_look->DrawLabel(this, Label(), rect, updateRect, base, flags, BAlignment(fLabelAlign, B_ALIGN_MIDDLE)); return; } // outer bevel rgb_color noTint = ui_color(B_PANEL_BACKGROUND_COLOR); rgb_color lighten1 = tint_color(noTint, B_LIGHTEN_1_TINT); rgb_color lighten2 = tint_color(noTint, B_LIGHTEN_2_TINT); rgb_color lightenMax = tint_color(noTint, B_LIGHTEN_MAX_TINT); rgb_color darken1 = tint_color(noTint, B_DARKEN_1_TINT); rgb_color darken2 = tint_color(noTint, B_DARKEN_2_TINT); rgb_color darken4 = tint_color(noTint, B_DARKEN_4_TINT); rgb_color navigationColor = ui_color(B_KEYBOARD_NAVIGATION_COLOR); if (enabled) SetHighColor(darken1); else SetHighColor(noTint); StrokeLine(rect.LeftBottom(), rect.LeftTop()); StrokeLine(rect.RightTop()); if (enabled) SetHighColor(lighten2); else SetHighColor(lighten1); StrokeLine(BPoint(rect.left + 1.0f, rect.bottom), rect.RightBottom()); StrokeLine(BPoint(rect.right, rect.top + 1.0f), rect.RightBottom()); // inner bevel rect.InsetBy(1.0f, 1.0f); if (active) { SetHighColor(navigationColor); StrokeRect(rect); } else { if (enabled) SetHighColor(darken4); else SetHighColor(darken2); StrokeLine(rect.LeftTop(), rect.LeftBottom()); StrokeLine(rect.LeftTop(), rect.RightTop()); SetHighColor(noTint); StrokeLine(BPoint(rect.left + 1.0f, rect.bottom), rect.RightBottom()); StrokeLine(BPoint(rect.right, rect.top + 1.0f)); } // label if (Label()) { _ValidateLayoutData(); font_height& fontHeight = fLayoutData->font_info; float y = Bounds().top + (Bounds().Height() + 1 - fontHeight.ascent - fontHeight.descent) / 2 + fontHeight.ascent; float x; float labelWidth = StringWidth(Label()); switch (fLabelAlign) { case B_ALIGN_RIGHT: x = fDivider - labelWidth - kLabelInputSpacing; break; case B_ALIGN_CENTER: x = fDivider - labelWidth / 2.0; break; default: x = 0.0; break; } BRect labelArea(x, Bounds().top, x + labelWidth, Bounds().bottom); if (x < fDivider && updateRect.Intersects(labelArea)) { labelArea.right = fText->Frame().left - kLabelInputSpacing; BRegion clipRegion(labelArea); ConstrainClippingRegion(&clipRegion); SetHighColor(IsEnabled() ? ui_color(B_CONTROL_TEXT_COLOR) : tint_color(noTint, B_DISABLED_LABEL_TINT)); DrawString(Label(), BPoint(x, y)); } } }
void WTreeNode::create() { setImplementation(layout_ = new WTemplate(tr("Wt.WTreeNode.template"))); setStyleClass("Wt-tree"); layout_->setSelectable(false); layout_->bindEmpty("cols-row"); layout_->bindEmpty("trunk-class"); implementStateless(&WTreeNode::doExpand, &WTreeNode::undoDoExpand); implementStateless(&WTreeNode::doCollapse, &WTreeNode::undoDoCollapse); WApplication *app = WApplication::instance(); /* * Children */ WContainerWidget *children = new WContainerWidget(); children->setList(true); children->hide(); layout_->bindWidget("children", children); /* * Expand icon */ if (WApplication::instance()->layoutDirection() == RightToLeft) expandIcon_ = new WIconPair(app->theme()->resourcesUrl() + imagePlusRtl_, app->theme()->resourcesUrl() + imageMinRtl_); else expandIcon_ = new WIconPair(app->theme()->resourcesUrl() + imagePlus_, app->theme()->resourcesUrl() + imageMin_); expandIcon_->setStyleClass("Wt-ctrl Wt-expand"); noExpandIcon_ = new WText(); noExpandIcon_->setStyleClass("Wt-ctrl Wt-noexpand"); layout_->bindWidget("expand", noExpandIcon_); addStyleClass("Wt-trunk"); /* * Label */ layout_->bindWidget("label-area", new WContainerWidget()); if (labelText_) labelText_->setStyleClass("Wt-label"); childCountLabel_ = 0; if (labelIcon_) { labelArea()->addWidget(labelIcon_); labelIcon_->setVerticalAlignment(AlignMiddle); } if (labelText_) labelArea()->addWidget(labelText_); childrenLoaded_ = false; setLoadPolicy(LazyLoading); }