// Centre a list of strings in the given box void oglCentreTextNoClipping(wxDC &dc, wxList *text_list, double m_xpos, double m_ypos, double width, double height) { int n = text_list->GetCount(); if (!text_list || (n == 0)) return; // First, get maximum dimensions of box enclosing text #if wxCHECK_VERSION(2, 9, 0) wxCoord char_height = 0; wxCoord max_width = 0; wxCoord current_width = 0; #else long char_height = 0; long max_width = 0; long current_width = 0; #endif // Store text extents for speed double *widths = new double[n]; wxNode *current = text_list->GetFirst(); int i = 0; while (current) { wxShapeTextLine *line = (wxShapeTextLine *)current->GetData(); dc.GetTextExtent(line->GetText(), ¤t_width, &char_height); widths[i] = current_width; if (current_width > max_width) max_width = current_width; current = current->GetNext(); i ++; } double max_height = n * char_height; double yoffset = (double)(m_ypos - (height / 2.0) + (height - max_height) / 2.0); double xoffset = (double)(m_xpos - width / 2.0); current = text_list->GetFirst(); i = 0; while (current) { wxShapeTextLine *line = (wxShapeTextLine *)current->GetData(); double x = (double)((width - widths[i]) / 2.0 + xoffset); double y = (double)(i * char_height + yoffset); line->SetX( x - m_xpos ); line->SetY( y - m_ypos ); current = current->GetNext(); i ++; } delete[] widths; }
void ExplainShape::OnDraw(wxDC &dc) { wxBitmap &bmp = GetBitmap(); if (!bmp.Ok()) return; // We do not draw the root shape if (m_rootShape) return; int x, y; x = WXROUND(m_xpos - bmp.GetWidth() / 2.0); y = WXROUND(m_ypos - GetHeight() / 2.0); dc.DrawBitmap(bmp, x, y, true); int w, h; dc.SetFont(GetCanvas()->GetFont()); dc.GetTextExtent(label, &w, &h); x = WXROUND(m_xpos - w / 2.0); y += bmp.GetHeight() + BMP_BORDER; dc.DrawText(label, x, y); }
wxSize wxGridCellAutoWrapStringRenderer::GetBestSize(wxGrid& grid, wxGridCellAttr& attr, wxDC& dc, int row, int col) { wxCoord x,y, height , width = grid.GetColSize(col) -10; int count = 250; //Limit iterations.. wxRect rect(0,0,width,10); // M is a nice large character 'y' gives descender!. dc.GetTextExtent(wxT("My"), &x, &y); do { width+=10; rect.SetWidth(width); height = y * (wx_truncate_cast(wxCoord, GetTextLines(grid,dc,attr,rect,row,col).GetCount())); count--; // Search for a shape no taller than the golden ratio. } while (count && (width < (height*1.68)) ); return wxSize(width,height); }
void GroupVisual::Draw ( wxDC& dc, InstanceCtrl* parent, wxRect limitingRect, bool hasSelection, int selectionIndex, bool hasFocus, int focusIndex, bool highlight ) { int i; int count = items.size(); int style = 0; wxRect rect; // Draw the header if(!no_header) { wxColour textColor = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT); if (highlight) { textColor = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT); } wxBrush brush(textColor); wxPen pen(textColor); dc.SetBrush(brush); dc.SetPen(pen); wxSize sz = dc.GetTextExtent(GetName()); dc.SetTextForeground(textColor); dc.DrawText( GetName() , 20, y_position + 5 ); int atheight = y_position + header_height / 2; if(sz.x + 30 < limitingRect.width - 10) dc.DrawLine(sz.x + 30,atheight, limitingRect.width - 10, atheight); dc.SetBrush(*wxTRANSPARENT_BRUSH); dc.SetPen(textColor); // Ungrouped can't be hidden, so don't draw the box. if (m_group) { dc.DrawRectangle(5,atheight -5, 10,10); dc.DrawRectangle(7,atheight -1, 6,2); if(!IsExpanded()) { dc.DrawRectangle(9,atheight -3, 2,6); } } } if(IsExpanded()) for (i = 0; i < count; i++) { parent->GetItemRect(VisualCoord(index,i), rect, false); if (!limitingRect.Intersects(rect)) continue; style = 0; if (hasSelection && selectionIndex == i) style |= wxINST_SELECTED; if (hasFocus && i == focusIndex) style |= wxINST_IS_FOCUS; InstanceVisual& item = items[i]; item.Draw(dc, parent, rect, style); } }
wxHtmlWordCell::wxHtmlWordCell(const wxString& word, wxDC& dc) : wxHtmlCell() { m_Word = word; dc.GetTextExtent(m_Word, &m_Width, &m_Height, &m_Descent); SetCanLiveOnPagebreak(false); m_allowLinebreak = true; }
// draw text centered around x (though still at y down) void DrawCenteredText(wxDC& dc, const wxString& text, const wxPoint& pt) { wxCoord w, h; dc.GetTextExtent(text, &w, &h); w = std::max(0, pt.x - w/2); dc.DrawText(text, w, pt.y); }
void wxStatusBarMac::DrawFieldText(wxDC& dc, int i) { int leftMargin = 2; wxRect rect; GetFieldRect(i, rect); if ( !IsWindowHilited( MAC_WXHWND( MacGetRootWindow() ) ) ) { dc.SetTextForeground( wxColour( 0x80 , 0x80 , 0x80 ) ) ; } wxString text(GetStatusText(i)); long x, y; dc.GetTextExtent(text, &x, &y); int xpos = rect.x + leftMargin + 1 ; int ypos = 1 ; dc.SetClippingRegion(rect.x, 0, rect.width, m_height); dc.DrawText(text, xpos, ypos); dc.DestroyClippingRegion(); }
void wxStatusBarMac::DrawFieldText(wxDC& dc, int i) { int leftMargin = 2; int w, h ; GetSize( &w , &h ) ; wxRect rect; GetFieldRect(i, rect); if ( !MacIsReallyHilited() ) { dc.SetTextForeground( wxColour( 0x80 , 0x80 , 0x80 ) ) ; } wxString text(GetStatusText(i)); long x, y; dc.GetTextExtent(text, &x, &y); int xpos = rect.x + leftMargin + 1 ; int ypos = 1 ; if ( MacGetTopLevelWindow()->MacGetMetalAppearance() ) ypos++ ; dc.SetClippingRegion(rect.x, 0, rect.width, h); dc.DrawText(text, xpos, ypos); dc.DestroyClippingRegion(); }
void AudioDisplay::PaintLabels(wxDC &dc, TimeRange updtime) { std::vector<AudioLabelProvider::AudioLabel> labels; controller->GetTimingController()->GetLabels(updtime, labels); if (labels.empty()) return; wxDCFontChanger fc(dc); wxFont font = dc.GetFont(); font.SetWeight(wxFONTWEIGHT_BOLD); dc.SetFont(font); dc.SetTextForeground(*wxWHITE); for (auto const& label : labels) { wxSize extent = dc.GetTextExtent(label.text); int left = RelativeXFromTime(label.range.begin()); int width = AbsoluteXFromTime(label.range.length()); // If it doesn't fit, truncate if (width < extent.GetWidth()) { dc.SetClippingRegion(left, audio_top + 4, width, extent.GetHeight()); dc.DrawText(label.text, left, audio_top + 4); dc.DestroyClippingRegion(); } // Otherwise center in the range else { dc.DrawText(label.text, left + (width - extent.GetWidth()) / 2, audio_top + 4); } } }
void Port::Draw(wxDC& dc) const { Shape::Draw(dc); wxColor fill = m_parent->GetMember(wxT("Fill_color"))->GetColor(); dc.SetPen(*wxBLACK_PEN); dc.SetBrush(wxBrush(fill)); dc.DrawRectangle(m_bbox); dc.SetFont(Node::GetFont()); dc.SetTextForeground(Util::TextColorFromBG(fill)); wxString name = GetMember(wxT("Name"))->GetString(); wxRect text(dc.GetTextExtent(name)); text = text.CentreIn(m_bbox); dc.DrawText(name, text.GetX(), text.GetY()); wxColor color; switch (GetStatus()) { case Ok: color.Set(0, 255, 0); break; case Disconnected: color.Set(255, 255, 0); break; case Required: case TypeMismatch: color.Set(255, 0, 0); break; } wxPoint pos = GetConnPoint(); wxPoint points[3] = { wxPoint(pos.x - 3, pos.y - 4), wxPoint(pos.x + 4, pos.y), wxPoint(pos.x - 3, pos.y + 4) }; dc.SetBrush(wxBrush(color)); dc.DrawPolygon(3, points); }
void FloorTruss::drawGuides(wxDC &dc, unsigned left, unsigned top, unsigned right, unsigned bottom) { float six_inches = (right-left) / (60.0f*2); float one_inch = (right-left) / 60.0f / 12.0f; unsigned px_width = one_inch * width; unsigned px_height = one_inch * height; wxCoord line_height, unused; dc.GetTextExtent(wxT("X"), &unused, &line_height); // height drawGuide(dc, left + six_inches + px_width/2 - line_height / 2, bottom - px_height, px_height, height, true, line_height); // base drawGuide(dc, left + six_inches, bottom + line_height / 10, px_width, width, false, line_height); // base to back of truck drawGuide(dc, left + six_inches + px_width, bottom + line_height / 10, right - left - six_inches - px_width, 60*12 - 6 - width, false, line_height); }
wxSize wxRibbonAUIArtProvider::GetPanelClientSize( wxDC& dc, const wxRibbonPanel* wnd, wxSize size, wxPoint* client_offset) { dc.SetFont(m_panel_label_font); wxSize label_size = dc.GetTextExtent(wnd->GetLabel()); int label_height = label_size.GetHeight() + 5; if(m_flags & wxRIBBON_BAR_FLOW_VERTICAL) { size.DecBy(4, label_height + 6); if(client_offset) *client_offset = wxPoint(2, label_height + 3); } else { size.DecBy(6, label_height + 4); if(client_offset) *client_offset = wxPoint(3, label_height + 2); } if (size.x < 0) size.x = 0; if (size.y < 0) size.y = 0; return size; }
/** * Render the event in the bitmap */ void LinkEvent::Render(wxDC & dc, int x, int y, unsigned int width, gd::EventsEditorItemsAreas & areas, gd::EventsEditorSelection & selection, const gd::Platform & platform) { #if !defined(GD_NO_WX_GUI) dc.SetBrush( wxBrush( wxColour( 255, 255, 255 ) ) ); dc.SetPen( wxPen( wxColour( 0, 0, 0 ), 1) ); wxRect rect(x+1, y, width, GetRenderedHeight(width, platform)-2); dc.DrawRectangle(rect); dc.DrawBitmap( gd::SkinHelper::GetIcon("events", 24), x+4, y + 1, true); dc.SetTextBackground( wxColour( 255, 255, 255 ) ); if ( !IsDisabled() ) dc.SetTextForeground( wxColour( 0, 0, 0 ) ); else dc.SetTextForeground( wxColour( 160, 160, 160 ) ); dc.SetFont( wxFont( 12, wxDEFAULT, wxNORMAL, wxNORMAL ) ); dc.DrawText( _("Link to ")+GetTarget(), x+32, y + 3 ); wxRect lien = dc.GetTextExtent(_("Link to ")+GetTarget()); dc.SetFont( wxFont( 10, wxDEFAULT, wxNORMAL, wxNORMAL ) ); if ( IncludeAllEvents() ) dc.DrawText( _("Include all events"), x+lien.GetWidth()+32+10, y + 5 ); else dc.DrawText( _("Include events ")+ToString(GetIncludeStart()+1)+_(" to ")+ToString(GetIncludeEnd()+1), x+lien.GetWidth()+32+10, y + 5 ); #endif }
void wxJigsawInputParameter::GetSize(wxDC & dc, wxCoord * w, wxCoord * h, double scale) { wxCoord shapeWidth(0), shapeHeight(0); if(m_NeedCalcLabelSize) { dc.GetTextExtent(m_Label, &m_LabelSize.x, &m_LabelSize.y, 0, 0, (wxFont *)&dc.GetFont()); m_NeedCalcLabelSize = false; } if(m_Shape) { m_Shape->GetSize(dc, &shapeWidth, &shapeHeight, scale); } else { wxSize defaultSize = wxJigsawInputParameter::GetDefaultParameterSize(); shapeWidth = defaultSize.GetWidth()*scale; shapeHeight = defaultSize.GetHeight()*scale; } if(w) { *w = m_LabelSize.GetWidth() + wxJigsawInputParameter::ParameterSpacing*scale + shapeWidth; } if(h) { *h = wxMax(m_LabelSize.GetHeight(), shapeHeight); } }
int wxRibbonAUIArtProvider::GetTabCtrlHeight( wxDC& dc, wxWindow* WXUNUSED(wnd), const wxRibbonPageTabInfoArray& pages) { int text_height = 0; int icon_height = 0; if(pages.GetCount() <= 1 && (m_flags & wxRIBBON_BAR_ALWAYS_SHOW_TABS) == 0) { // To preserve space, a single tab need not be displayed. We still need // one pixel of border though. return 1; } if(m_flags & wxRIBBON_BAR_SHOW_PAGE_LABELS) { dc.SetFont(m_tab_active_label_font); text_height = dc.GetTextExtent(wxT("ABCDEFXj")).GetHeight(); } if(m_flags & wxRIBBON_BAR_SHOW_PAGE_ICONS) { size_t numpages = pages.GetCount(); for(size_t i = 0; i < numpages; ++i) { const wxRibbonPageTabInfo& info = pages.Item(i); if(info.page->GetIcon().IsOk()) { icon_height = wxMax(icon_height, info.page->GetIcon().GetHeight()); } } } return wxMax(text_height, icon_height) + 10; }
int SurfaceImpl::Ascent(Font &font) { SetFont(font); int w, h, d, e; hdc->GetTextExtent(EXTENT_TEST, &w, &h, &d, &e); font.ascent = h - d; return font.ascent; }
void LineShape::draw(wxDC& dc) { if (isSelected()) { dc.SetPen(wxPen(WXSTRING("RED"), lineWidth, wxSOLID)); } else { dc.SetPen(wxPen(WXSTRING("BLACK"), lineWidth, wxSOLID)); } dc.DrawLine(node1->getCentre().x, node1->getCentre().y, node2->getCentre().x, node2->getCentre().y); if (arrowHeadSize > 0) { drawHead(dc); } if (title == "" && node1->getTitle() != "" && node2->getTitle() != "") { title = node1->getTitle() + " to " + node2->getTitle(); } Size textSize = dc.GetTextExtent(WXSTRING(title)); Point textPoint = getBegin(); // double angle = getAngle(); double angle = Shape2DUtils::getAngle(node1->getCentre(), node2->getCentre()); double dX = (getLength() / 2 - textSize.x / 2) * sin(angle); double dY = (getLength() / 2 - textSize.x / 2) * cos(angle); textPoint.x += dX; textPoint.y -= dY; double degreeAngle = angle * (180.0 / PI); double rotationAngle = 90 - degreeAngle; dc.DrawRotatedText(WXSTRING(title), textPoint, rotationAngle); }
wxSize wxCstmTabArt::GetTabSize(wxDC& dc, wxWindow* WXUNUSED(wnd), const wxString& caption, const wxBitmap& WXUNUSED(bitmap), bool WXUNUSED(active), int close_button_state, int* x_extent) { wxCoord measured_textx, measured_texty; dc.SetFont(m_measuringFont); dc.GetTextExtent(caption, &measured_textx, &measured_texty); wxCoord tab_height = measured_texty + 5; wxCoord tab_width = measured_textx + tab_height + 18; if (close_button_state != wxAUI_BUTTON_STATE_HIDDEN) tab_width += m_activeCloseBmp.GetWidth(); if (m_flags & wxAUI_NB_TAB_FIXED_WIDTH) { tab_width = m_fixedTabWidth; } *x_extent = tab_width - (tab_height/2) - 1; return wxSize(tab_width, tab_height); }
void oglGetCentredTextExtent(wxDC& dc, wxList *text_list, double WXUNUSED(m_xpos), double WXUNUSED(m_ypos), double WXUNUSED(width), double WXUNUSED(height), double *actual_width, double *actual_height) { int n = text_list->GetCount(); if (!text_list || (n == 0)) { *actual_width = 0; *actual_height = 0; return; } // First, get maximum dimensions of box enclosing text long char_height = 0; long max_width = 0; long current_width = 0; wxObjectList::compatibility_iterator current = text_list->GetFirst(); while (current) { wxShapeTextLine *line = (wxShapeTextLine *)current->GetData(); dc.GetTextExtent(line->GetText(), ¤t_width, &char_height); if (current_width > max_width) max_width = current_width; current = current->GetNext(); } *actual_height = n*char_height; *actual_width = max_width; }
/** * Render the event in the bitmap */ void LinkEvent::Render(wxDC & dc, int x, int y, unsigned int width, gd::EventsEditorItemsAreas & areas, gd::EventsEditorSelection & selection, const gd::Platform & platform) { #if !defined(GD_NO_WX_GUI) gd::EventsRenderingHelper * renderingHelper = gd::EventsRenderingHelper::Get(); dc.SetBrush( wxBrush( wxColour( 255, 255, 255 ) ) ); dc.SetPen( wxPen( wxColour( 0, 0, 0 ), 1) ); wxRect rect(x+1, y, width-2, GetRenderedHeight(width, platform)-2); dc.DrawRectangle(rect); dc.DrawBitmap( gd::SkinHelper::GetIcon("events", 24), x+4, y + 1, true); dc.SetTextBackground( wxColour( 255, 255, 255 ) ); if ( !IsDisabled() ) dc.SetTextForeground( wxColour( 0, 0, 0 ) ); else dc.SetTextForeground( wxColour( 160, 160, 160 ) ); dc.SetFont(renderingHelper->GetNiceFont()); dc.DrawText( _("Link to ")+GetTarget(), x+32, y + 3 ); if ( !IncludeAllEvents() ) { wxRect textRect = dc.GetTextExtent(_("Link to ")+GetTarget()); dc.DrawText( _("Include only events ")+gd::String::From(GetIncludeStart()+1)+_(" to ")+gd::String::From(GetIncludeEnd()+1), x+textRect.GetWidth()+32+10, y + 5 ); } #endif }
void wxStatusBarGeneric::DrawFieldText(wxDC& dc, int i) { int leftMargin = 2; wxRect rect; GetFieldRect(i, rect); wxString text(GetStatusText(i)); long x, y; dc.GetTextExtent(text, &x, &y); int xpos = rect.x + leftMargin; int ypos = (int) (((rect.height - y) / 2 ) + rect.y + 0.5) ; #if defined( __WXGTK__ ) || defined(__WXMAC__) xpos++; ypos++; #endif dc.SetClippingRegion(rect.x, rect.y, rect.width, rect.height); dc.DrawText(text, xpos, ypos); dc.DestroyClippingRegion(); }
wxArrayString wxGridCellAutoWrapStringRenderer::GetTextLines(wxGrid& grid, wxDC& dc, const wxGridCellAttr& attr, const wxRect& rect, int row, int col) { dc.SetFont(attr.GetFont()); const wxCoord maxWidth = rect.GetWidth(); // Transform logical lines into physical ones, wrapping the longer ones. const wxArrayString logicalLines = wxSplit(grid.GetCellValue(row, col), '\n', '\0'); wxArrayString physicalLines; for ( wxArrayString::const_iterator it = logicalLines.begin(); it != logicalLines.end(); ++it ) { const wxString& line = *it; if ( dc.GetTextExtent(line).x > maxWidth ) { // Line does not fit, break it up. BreakLine(dc, line, maxWidth, physicalLines); } else // The entire line fits as is { physicalLines.push_back(line); } } return physicalLines; }
void oglGetCentredTextExtent(wxDC& dc, wxList *text_list, double m_xpos, double m_ypos, double width, double height, double *actual_width, double *actual_height) { size_t n = text_list->GetCount(); if (!text_list || (n == 0)) { *actual_width = 0; *actual_height = 0; return; } // First, get maximum dimensions of box enclosing text long char_height = 0; long max_width = 0; long current_width = 0; wxNode *current = text_list->GetFirst(); int i = 0; while (current) { wxShapeTextLine *line = (wxShapeTextLine *)current->GetData(); dc.GetTextExtent(line->GetText(), ¤t_width, &char_height); if (current_width > max_width) max_width = current_width; current = current->GetNext(); i ++; } *actual_height = n*char_height; *actual_width = max_width; }
void WayPointShape::draw(wxDC& dc) { // The minimum size of the RectangleShape is the size of the title titleSize = dc.GetTextExtent(WXSTRING(title)); if (size.x < (titleSize.x + 2 * spacing + 2 * borderWidth)) { size.x = titleSize.x + 2 * spacing + 2 * borderWidth; } if (size.y < (titleSize.y + 2 * spacing + 2 * borderWidth)) { size.y = titleSize.y + 2 * spacing + 2 * borderWidth; } if (getWayPoint()->getSize() != size) { getWayPoint()->setSize(size, false); } // Draws a rectangle with the given top left corner, and with the given // size. dc.SetBrush(*wxWHITE_BRUSH); if (isSelected()) { dc.SetPen(wxPen(WXSTRING(getSelectionColour()), borderWidth, wxSOLID)); } else { dc.SetPen(wxPen(WXSTRING(getNormalColour()), borderWidth, wxSOLID)); } int x = centre.x - (size.x / 2); int y = centre.y - (size.y / 2); dc.DrawRectangle(x, y, size.x, size.y); dc.SetPen(wxPen(WXSTRING("BLACK"), borderWidth, wxSOLID)); dc.DrawText(WXSTRING(title), centre.x - titleSize.x / 2, y + spacing + borderWidth); }
wxSize wxGridCellAutoWrapStringRenderer::GetBestSize(wxGrid& grid, wxGridCellAttr& attr, wxDC& dc, int row, int col) { wxCoord x,y, height , width = grid.GetColSize(col) -20; // for width, subtract 20 because ColSize includes a magin of 10 pixels // that we do not want here and because we always start with an increment // by 10 in the loop below. int count = 250; //Limit iterations.. wxRect rect(0,0,width,10); // M is a nice large character 'y' gives descender!. dc.GetTextExtent(wxT("My"), &x, &y); do { width+=10; rect.SetWidth(width); height = y * (wx_truncate_cast(wxCoord, GetTextLines(grid,dc,attr,rect,row,col).GetCount())); count--; // Search for a shape no taller than the golden ratio. } while (count && (width < (height*1.68)) ); return wxSize(width,height); }
// ----------------------------------------------------------------------------- // Draws function description text [desc] at [left,top]. // Returns a rect of the bounds of the drawn text // ----------------------------------------------------------------------------- wxRect SCallTip::drawFunctionDescription(wxDC& dc, const wxString& desc, int left, int top) const { auto italic = font_.Italic(); wxRect rect(left, top, 0, 0); dc.SetFont(italic); int max_right = 0; if (dc.GetTextExtent(desc).x > MAX_WIDTH) { // Description is too long, split into multiple lines vector<wxString> desc_lines; wxString line = desc; wxArrayInt extents; while (true) { dc.GetPartialTextExtents(line, extents); bool split = false; for (unsigned a = 0; a < extents.size(); a++) { if (extents[a] > MAX_WIDTH) { // Try to split in phrases first. size_t eol = (size_t)line.SubString(0, a).Last('.') + 1; eol = line[eol] == ' ' ? eol : -1; if (eol <= 0 || eol > MAX_WIDTH) eol = (size_t)line.SubString(0, a).Last(',') + 1; if (eol <= 0 || eol > MAX_WIDTH) eol = (size_t)line.SubString(0, a).Last(' '); desc_lines.push_back(line.SubString(0, eol)); line = line.SubString(eol + 1, line.Length()); split = true; break; } } if (!split) { desc_lines.push_back(line); break; } } int bottom = rect.GetBottom() + UI::scalePx(font_.GetPixelSize().GetHeight()); for (const auto& desc_line : desc_lines) { drawText(dc, desc_line, 0, bottom, &rect); bottom = rect.GetBottom(); if (rect.GetRight() > max_right) max_right = rect.GetRight(); } } else { drawText(dc, desc, 0, rect.GetBottom() + UI::scalePx(font_.GetPixelSize().GetHeight()), &rect); if (rect.GetRight() > max_right) max_right = rect.GetRight(); } return { left, top, max_right - left, rect.GetBottom() - top }; }
void wxJigsawShape::GetHeaderSize(wxDC & dc, wxCoord * w, wxCoord * h, double scale) { //wxFAIL_MSG(_("wxJigsawShape::GetHeaderSize not implemented")); wxSize paramSize(0, 0); m_HeaderSize.Set(0,0); if(m_NeedCalcLabelSize) { dc.GetTextExtent(m_Name, &m_LabelSize.x, &m_LabelSize.y, 0, 0, &labelFont); m_NeedCalcLabelSize = false; } //dc.GetTextExtent(m_Name, &labelWidth, &labelHeight, 0, 0, &labelFont); if(m_InputParameters.GetCount() && (w || h)) { paramSize = GetInputParametersSize(dc, scale); } int & width = m_HeaderSize.x; // Reset the width width = 0; // Add an offset width += wxJigsawShape::ShapeLabelOffset.GetWidth()*scale; // If shape has an icon then increment by width of icon + spacing if(m_Bitmap.IsOk()) { width += m_Bitmap.GetWidth(); width += wxJigsawShape::HeaderElementSpacing*scale; } // Add the width of string label + spacing width += m_LabelSize.GetWidth(); width += wxJigsawShape::HeaderElementSpacing*scale; // Add the width of input parameters width += paramSize.GetWidth(); // Add an offset on the right side width += wxJigsawShape::ShapeLabelOffset.GetWidth()*scale; width = wxMax(width, m_MinSize.GetWidth()*scale); int & height = m_HeaderSize.y; // Height should have the maximum value of: // Height of icon if(m_Bitmap.IsOk()) { height = wxMax(height, m_Bitmap.GetHeight()); } // height of string label height = wxMax(height, m_LabelSize.GetHeight()); // height of imput parameters height = wxMax(height, paramSize.GetHeight()); // Add an spacing on top and on bottom height += 2 * wxJigsawShape::ShapeLabelOffset.GetHeight()*scale; height = wxMax(height, m_MinSize.GetHeight()*scale); if(w) { *w = width; } if(h) { *h = height; } }
/* static */ wxString wxControlBase::Ellipsize(const wxString& label, const wxDC& dc, wxEllipsizeMode mode, int maxFinalWidth, int flags) { wxString ret; // these cannot be cached between different Ellipsize() calls as they can // change because of e.g. a font change; however we calculate them only once // when ellipsizing multiline labels: int replacementWidth = dc.GetTextExtent(wxELLIPSE_REPLACEMENT).GetWidth(); // NB: we must handle correctly labels with newlines: wxString curLine; for ( wxString::const_iterator pc = label.begin(); ; ++pc ) { if ( pc == label.end() || *pc == wxS('\n') ) { curLine = DoEllipsizeSingleLine(curLine, dc, mode, maxFinalWidth, replacementWidth); // add this (ellipsized) row to the rest of the label ret << curLine; if ( pc == label.end() ) { // NOTE: this is the return which always exits the function return ret; } else { ret << *pc; curLine.clear(); } } // we need to remove mnemonics from the label for correct calculations else if ( *pc == wxS('&') && (flags & wxELLIPSIZE_FLAGS_PROCESS_MNEMONICS) ) { // pc+1 is safe: at worst we'll be at end() wxString::const_iterator next = pc + 1; if ( next != label.end() && *next == wxS('&') ) curLine += wxS('&'); // && becomes & //else: remove this ampersand } // we need also to expand tabs to properly calc their size else if ( *pc == wxS('\t') && (flags & wxELLIPSIZE_FLAGS_EXPAND_TABS) ) { // Windows natively expands the TABs to 6 spaces. Do the same: curLine += wxS(" "); } else { curLine += *pc; } } // this return would generate a // warning C4702: unreachable code // with MSVC since the function always exits from inside the loop //return ret; }
void wxRibbonMetroArtProvider::DrawMinimisedPanelCommon( wxDC& dc, wxRibbonPanel* wnd, const wxRect& true_rect, wxRect* preview_rect) { wxRect preview(0, 0, 32, 32); if(m_flags & wxRIBBON_BAR_FLOW_VERTICAL) { preview.x = true_rect.x + 4; preview.y = true_rect.y + (true_rect.height - preview.height) / 2; } else { preview.x = true_rect.x + (true_rect.width - preview.width) / 2; preview.y = true_rect.y + 4; } if(preview_rect) *preview_rect = preview; wxCoord label_width, label_height; dc.SetFont(m_panel_label_font); dc.GetTextExtent(wnd->GetLabel(), &label_width, &label_height); int xpos = true_rect.x + (true_rect.width - label_width + 1) / 2; int ypos = preview.y + preview.height + 5; if(m_flags & wxRIBBON_BAR_FLOW_VERTICAL) { xpos = preview.x + preview.width + 5; ypos = true_rect.y + (true_rect.height - label_height) / 2; } dc.SetTextForeground(m_panel_minimised_label_colour); dc.DrawText(wnd->GetLabel(), xpos, ypos); wxPoint arrow_points[3]; if(m_flags & wxRIBBON_BAR_FLOW_VERTICAL) { xpos += label_width; arrow_points[0] = wxPoint(xpos + 5, ypos + label_height / 2); arrow_points[1] = arrow_points[0] + wxPoint(-3, 3); arrow_points[2] = arrow_points[0] + wxPoint(-3, -3); } else { ypos += label_height; arrow_points[0] = wxPoint(true_rect.width / 2, ypos + 5); arrow_points[1] = arrow_points[0] + wxPoint(-3, -3); arrow_points[2] = arrow_points[0] + wxPoint( 3, -3); } dc.SetPen(*wxTRANSPARENT_PEN); wxBrush B(m_panel_minimised_label_colour); dc.SetBrush(B); dc.DrawPolygon(sizeof(arrow_points)/sizeof(wxPoint), arrow_points, true_rect.x, true_rect.y); }
wxString CBOINCGridCtrl::FormatTextWithEllipses(wxDC& dc,const wxString &text,int width) { wxString retText; wxString drawntext, ellipsis; wxCoord w, h, base_w; wxListItem item; // determine if the string can fit inside the current width dc.GetTextExtent(text, &w, &h); if (w <= width) { retText = text; } else // otherwise, truncate and add an ellipsis if possible { // determine the base width ellipsis = wxString(wxT("...")); dc.GetTextExtent(ellipsis, &base_w, &h); // continue until we have enough space or only one character left wxCoord w_c, h_c; size_t len = text.Length(); drawntext = text.Left(len); while (len > 1) { dc.GetTextExtent(drawntext.Last(), &w_c, &h_c); drawntext.RemoveLast(); len--; w -= w_c; if (w + base_w <= width) break; } // if still not enough space, remove ellipsis characters while (ellipsis.Length() > 0 && w + base_w > width) { ellipsis = ellipsis.Left(ellipsis.Length() - 1); dc.GetTextExtent(ellipsis, &base_w, &h); } // now draw the text retText = drawntext + ellipsis; } return retText; }