int wxGridCellAutoWrapStringRenderer::GetBestWidth(wxGrid& grid, wxGridCellAttr& attr, wxDC& dc, int row, int col, int height) { const int lineHeight = dc.GetCharHeight(); // Maximal number of lines that fully fit but at least 1. const size_t maxLines = height - AUTOWRAP_Y_MARGIN < lineHeight ? 1 : (height - AUTOWRAP_Y_MARGIN)/lineHeight; // Increase width until all the text fits. // // TODO: this is not the most efficient to do it for the long strings. const int charWidth = dc.GetCharWidth(); int width = 2*charWidth; while ( GetTextLines(grid, dc, attr, wxSize(width, height), row, col).size() > maxLines ) width += charWidth; return width; }
static int LogProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2) { WINDOW cwnd = ControlWindow(&Log, ID_LOGLIST); char **mn = message; switch (msg) { case INITIATE_DIALOG: AddAttribute(cwnd, MULTILINE | VSCROLLBAR); while (*mn) { SendMessage(cwnd, ADDTEXT, (PARAM) (*mn), 0); mn++; } SendMessage(cwnd, SHOW_WINDOW, 0, 0); break; case COMMAND: if ((int) p1 == ID_OK) { int item; int tl = GetTextLines(cwnd); for (item = 0; item < tl; item++) if (ItemSelected(cwnd, item)) mn[item][0] = LISTSELECTOR; } break; default: break; } return DefaultWndProc(wnd, msg, p1, p2); }
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); }
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); }
int wxGridCellAutoWrapStringRenderer::GetBestHeight(wxGrid& grid, wxGridCellAttr& attr, wxDC& dc, int row, int col, int width) { const int lineHeight = dc.GetCharHeight(); // Use as many lines as we need for this width and add a small border to // improve the appearance. return GetTextLines(grid, dc, attr, wxSize(width, lineHeight), row, col).size() * lineHeight + AUTOWRAP_Y_MARGIN; }
void wxSheetCellAutoWrapStringRendererRefData::Draw(wxSheet& sheet, const wxSheetCellAttr& attr, wxDC& dc, const wxRect& rectCell, const wxSheetCoords& coords, bool isSelected) { wxSheetCellRendererRefData::Draw(sheet, attr, dc, rectCell, coords, isSelected); SetTextColoursAndFont(sheet, attr, dc, isSelected); int align = attr.GetAlignment(); int orient = attr.GetOrientation(); wxRect rect = rectCell; rect.Inflate(-1); sheet.DrawTextRectangle(dc, GetTextLines(sheet, dc, attr, rect, coords), rect, align, orient); }
void wxGridCellAutoWrapStringRenderer::Draw(wxGrid& grid, wxGridCellAttr& attr, wxDC& dc, const wxRect& rectCell, int row, int col, bool isSelected) { wxGridCellRenderer::Draw(grid, attr, dc, rectCell, row, col, isSelected); // now we only have to draw the text SetTextColoursAndFont(grid, attr, dc, isSelected); int horizAlign, vertAlign; attr.GetAlignment(&horizAlign, &vertAlign); wxRect rect = rectCell; rect.Inflate(-1); grid.DrawTextRectangle(dc, GetTextLines(grid,dc,attr,rect,row,col), rect, horizAlign, vertAlign); }
wxSize wxSheetCellAutoWrapStringRendererRefData::GetBestSize(wxSheet& sheet, const wxSheetCellAttr& attr, wxDC& dc, const wxSheetCoords& coords) { wxCoord x, y, height, width = sheet.GetColWidth(coords.GetCol()) -10; int count = 250; //Limit iterations.. wxRect rect(0, 0, width, 10); // M is a nice large character 'y' gives descender!. dc.SetFont(attr.GetFont()); dc.GetTextExtent(wxT("My"), &x, &y); do // Search for a shape no taller than the golden ratio. { width += 10; rect.SetWidth(width); height = y * GetTextLines(sheet,dc,attr,rect,coords).GetCount(); count--; } while (count && (width < (height*1.68)) ); return wxSize(width, height); }