Property value images are no longer shrinked horizontally
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@59374 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -2093,6 +2093,11 @@ public:
|
|||||||
// Puts correct indexes to children
|
// Puts correct indexes to children
|
||||||
void FixIndicesOfChildren( unsigned int starthere = 0 );
|
void FixIndicesOfChildren( unsigned int starthere = 0 );
|
||||||
|
|
||||||
|
/**
|
||||||
|
Converts image width into full image offset, with margins.
|
||||||
|
*/
|
||||||
|
int GetImageOffset( int imageWidth ) const;
|
||||||
|
|
||||||
#ifndef SWIG
|
#ifndef SWIG
|
||||||
// Returns wxPropertyGridPageState in which this property resides.
|
// Returns wxPropertyGridPageState in which this property resides.
|
||||||
wxPropertyGridPageState* GetParentState() const { return m_parentState; }
|
wxPropertyGridPageState* GetParentState() const { return m_parentState; }
|
||||||
|
@@ -201,6 +201,9 @@
|
|||||||
#define wxCC_CUSTOM_IMAGE_MARGIN1 4 // before image
|
#define wxCC_CUSTOM_IMAGE_MARGIN1 4 // before image
|
||||||
#define wxCC_CUSTOM_IMAGE_MARGIN2 5 // after image
|
#define wxCC_CUSTOM_IMAGE_MARGIN2 5 // after image
|
||||||
|
|
||||||
|
#define DEFAULT_IMAGE_OFFSET_INCREMENT \
|
||||||
|
(wxCC_CUSTOM_IMAGE_MARGIN1 + wxCC_CUSTOM_IMAGE_MARGIN2)
|
||||||
|
|
||||||
#define wxPG_DRAG_MARGIN 30
|
#define wxPG_DRAG_MARGIN 30
|
||||||
|
|
||||||
#if wxPG_NO_CHILD_EVT_MOTION
|
#if wxPG_NO_CHILD_EVT_MOTION
|
||||||
|
@@ -1531,6 +1531,21 @@ void FormMain::PopulateWithExamples ()
|
|||||||
// Set value after limiting so that it will be applied
|
// Set value after limiting so that it will be applied
|
||||||
pg->SetPropertyValue( wxT("StringProperty"), wxT("some text") );
|
pg->SetPropertyValue( wxT("StringProperty"), wxT("some text") );
|
||||||
|
|
||||||
|
// Add string property with arbitrarily wide bitmap in front of it. We
|
||||||
|
// intentionally lower-than-typical row height here so that the ugly
|
||||||
|
// scaling code wont't be run.
|
||||||
|
pg->Append( new wxStringProperty( wxT("StringPropertyWithBitmap"),
|
||||||
|
wxPG_LABEL,
|
||||||
|
wxT("Test Text")) );
|
||||||
|
wxBitmap myTestBitmap(60, 15, 32);
|
||||||
|
wxMemoryDC mdc;
|
||||||
|
mdc.SelectObject(myTestBitmap);
|
||||||
|
mdc.Clear();
|
||||||
|
mdc.SetPen(*wxBLACK);
|
||||||
|
mdc.DrawLine(0, 0, 60, 15);
|
||||||
|
mdc.SelectObject(wxNullBitmap);
|
||||||
|
pg->SetPropertyImage( wxT("StringPropertyWithBitmap"), myTestBitmap );
|
||||||
|
|
||||||
|
|
||||||
// this value array would be optional if values matched string indexes
|
// this value array would be optional if values matched string indexes
|
||||||
//long flags_prop_values[] = { wxICONIZE, wxCAPTION, wxMINIMIZE_BOX, wxMAXIMIZE_BOX };
|
//long flags_prop_values[] = { wxICONIZE, wxCAPTION, wxMINIMIZE_BOX, wxMAXIMIZE_BOX };
|
||||||
|
@@ -94,8 +94,6 @@ wxSize wxPGCellRenderer::GetImageSize( const wxPGProperty* WXUNUSED(property),
|
|||||||
void wxPGCellRenderer::DrawText( wxDC& dc, const wxRect& rect,
|
void wxPGCellRenderer::DrawText( wxDC& dc, const wxRect& rect,
|
||||||
int xOffset, const wxString& text ) const
|
int xOffset, const wxString& text ) const
|
||||||
{
|
{
|
||||||
if ( xOffset )
|
|
||||||
xOffset += wxCC_CUSTOM_IMAGE_MARGIN1 + wxCC_CUSTOM_IMAGE_MARGIN2;
|
|
||||||
dc.DrawText( text,
|
dc.DrawText( text,
|
||||||
rect.x+xOffset+wxPG_XBEFORETEXT,
|
rect.x+xOffset+wxPG_XBEFORETEXT,
|
||||||
rect.y+((rect.height-dc.GetCharHeight())/2) );
|
rect.y+((rect.height-dc.GetCharHeight())/2) );
|
||||||
@@ -106,9 +104,6 @@ void wxPGCellRenderer::DrawEditorValue( wxDC& dc, const wxRect& rect,
|
|||||||
wxPGProperty* property,
|
wxPGProperty* property,
|
||||||
const wxPGEditor* editor ) const
|
const wxPGEditor* editor ) const
|
||||||
{
|
{
|
||||||
if ( xOffset )
|
|
||||||
xOffset += wxCC_CUSTOM_IMAGE_MARGIN1 + wxCC_CUSTOM_IMAGE_MARGIN2;
|
|
||||||
|
|
||||||
int yOffset = ((rect.height-dc.GetCharHeight())/2);
|
int yOffset = ((rect.height-dc.GetCharHeight())/2);
|
||||||
|
|
||||||
if ( editor )
|
if ( editor )
|
||||||
@@ -135,7 +130,7 @@ void wxPGCellRenderer::DrawCaptionSelectionRect( wxDC& dc, int x, int y, int w,
|
|||||||
|
|
||||||
int wxPGCellRenderer::PreDrawCell( wxDC& dc, const wxRect& rect, const wxPGCell& cell, int flags ) const
|
int wxPGCellRenderer::PreDrawCell( wxDC& dc, const wxRect& rect, const wxPGCell& cell, int flags ) const
|
||||||
{
|
{
|
||||||
int imageOffset = 0;
|
int imageWidth = 0;
|
||||||
|
|
||||||
// If possible, use cell colours
|
// If possible, use cell colours
|
||||||
if ( !(flags & DontUseCellBgCol) )
|
if ( !(flags & DontUseCellBgCol) )
|
||||||
@@ -164,10 +159,10 @@ int wxPGCellRenderer::PreDrawCell( wxDC& dc, const wxRect& rect, const wxPGCell&
|
|||||||
rect.x + wxPG_CONTROL_MARGIN + wxCC_CUSTOM_IMAGE_MARGIN1,
|
rect.x + wxPG_CONTROL_MARGIN + wxCC_CUSTOM_IMAGE_MARGIN1,
|
||||||
rect.y + wxPG_CUSTOM_IMAGE_SPACINGY,
|
rect.y + wxPG_CUSTOM_IMAGE_SPACINGY,
|
||||||
true );
|
true );
|
||||||
imageOffset = bmp.GetWidth();
|
imageWidth = bmp.GetWidth();
|
||||||
}
|
}
|
||||||
|
|
||||||
return imageOffset;
|
return imageWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
@@ -196,12 +191,12 @@ void wxPGDefaultRenderer::Render( wxDC& dc, const wxRect& rect,
|
|||||||
const wxPGCell* cell = NULL;
|
const wxPGCell* cell = NULL;
|
||||||
|
|
||||||
wxString text;
|
wxString text;
|
||||||
int imageOffset = 0;
|
int imageWidth = 0;
|
||||||
int preDrawFlags = flags;
|
int preDrawFlags = flags;
|
||||||
|
|
||||||
property->GetDisplayInfo(column, item, flags, &text, &cell);
|
property->GetDisplayInfo(column, item, flags, &text, &cell);
|
||||||
|
|
||||||
imageOffset = PreDrawCell( dc, rect, *cell, preDrawFlags );
|
imageWidth = PreDrawCell( dc, rect, *cell, preDrawFlags );
|
||||||
|
|
||||||
if ( column == 1 )
|
if ( column == 1 )
|
||||||
{
|
{
|
||||||
@@ -231,7 +226,7 @@ void wxPGDefaultRenderer::Render( wxDC& dc, const wxRect& rect,
|
|||||||
|
|
||||||
property->OnCustomPaint( dc, imageRect, paintdata );
|
property->OnCustomPaint( dc, imageRect, paintdata );
|
||||||
|
|
||||||
imageOffset = paintdata.m_drawnWidth;
|
imageWidth = paintdata.m_drawnWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
text = property->GetValueAsString();
|
text = property->GetValueAsString();
|
||||||
@@ -257,6 +252,8 @@ void wxPGDefaultRenderer::Render( wxDC& dc, const wxRect& rect,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int imageOffset = property->GetImageOffset(imageWidth);
|
||||||
|
|
||||||
DrawEditorValue( dc, rect, imageOffset, text, property, editor );
|
DrawEditorValue( dc, rect, imageOffset, text, property, editor );
|
||||||
|
|
||||||
// active caption gets nice dotted rectangle
|
// active caption gets nice dotted rectangle
|
||||||
@@ -264,8 +261,11 @@ void wxPGDefaultRenderer::Render( wxDC& dc, const wxRect& rect,
|
|||||||
{
|
{
|
||||||
if ( flags & Selected )
|
if ( flags & Selected )
|
||||||
{
|
{
|
||||||
if ( imageOffset > 0 )
|
if ( imageWidth > 0 )
|
||||||
imageOffset += wxCC_CUSTOM_IMAGE_MARGIN2 + 4;
|
{
|
||||||
|
imageOffset -= DEFAULT_IMAGE_OFFSET_INCREMENT;
|
||||||
|
imageWidth += wxCC_CUSTOM_IMAGE_MARGIN2 + 4;
|
||||||
|
}
|
||||||
|
|
||||||
DrawCaptionSelectionRect( dc,
|
DrawCaptionSelectionRect( dc,
|
||||||
rect.x+wxPG_XBEFORETEXT-wxPG_CAPRECTXMARGIN+imageOffset,
|
rect.x+wxPG_XBEFORETEXT-wxPG_CAPRECTXMARGIN+imageOffset,
|
||||||
@@ -1170,6 +1170,22 @@ wxSize wxPGProperty::OnMeasureImage( int WXUNUSED(item) ) const
|
|||||||
return wxSize(0,0);
|
return wxSize(0,0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int wxPGProperty::GetImageOffset( int imageWidth ) const
|
||||||
|
{
|
||||||
|
int imageOffset = 0;
|
||||||
|
|
||||||
|
if ( imageWidth )
|
||||||
|
{
|
||||||
|
// Do not increment offset too much for wide images
|
||||||
|
if ( imageWidth <= (wxPG_CUSTOM_IMAGE_WIDTH+5) )
|
||||||
|
imageOffset = imageWidth + DEFAULT_IMAGE_OFFSET_INCREMENT;
|
||||||
|
else
|
||||||
|
imageOffset = imageWidth + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return imageOffset;
|
||||||
|
}
|
||||||
|
|
||||||
wxPGCellRenderer* wxPGProperty::GetCellRenderer( int WXUNUSED(column) ) const
|
wxPGCellRenderer* wxPGProperty::GetCellRenderer( int WXUNUSED(column) ) const
|
||||||
{
|
{
|
||||||
return wxPGGlobalVars->m_defaultRenderer;
|
return wxPGGlobalVars->m_defaultRenderer;
|
||||||
@@ -1903,7 +1919,7 @@ void wxPGProperty::SetValueImage( wxBitmap& bmp )
|
|||||||
wxSize maxSz = GetGrid()->GetImageSize();
|
wxSize maxSz = GetGrid()->GetImageSize();
|
||||||
wxSize imSz(bmp.GetWidth(),bmp.GetHeight());
|
wxSize imSz(bmp.GetWidth(),bmp.GetHeight());
|
||||||
|
|
||||||
if ( imSz.x != maxSz.x || imSz.y != maxSz.y )
|
if ( imSz.y != maxSz.y )
|
||||||
{
|
{
|
||||||
// Create a memory DC
|
// Create a memory DC
|
||||||
wxBitmap* bmpNew = new wxBitmap(maxSz.x,maxSz.y,bmp.GetDepth());
|
wxBitmap* bmpNew = new wxBitmap(maxSz.x,maxSz.y,bmp.GetDepth());
|
||||||
@@ -1913,12 +1929,11 @@ void wxPGProperty::SetValueImage( wxBitmap& bmp )
|
|||||||
|
|
||||||
// Scale
|
// Scale
|
||||||
// FIXME: This is ugly - use image or wait for scaling patch.
|
// FIXME: This is ugly - use image or wait for scaling patch.
|
||||||
double scaleX = (double)maxSz.x / (double)imSz.x;
|
|
||||||
double scaleY = (double)maxSz.y / (double)imSz.y;
|
double scaleY = (double)maxSz.y / (double)imSz.y;
|
||||||
|
|
||||||
dc.SetUserScale(scaleX,scaleY);
|
dc.SetUserScale(scaleY, scaleY);
|
||||||
|
|
||||||
dc.DrawBitmap( bmp, 0, 0 );
|
dc.DrawBitmap(bmp, 0, 0);
|
||||||
|
|
||||||
m_valueBitmap = bmpNew;
|
m_valueBitmap = bmpNew;
|
||||||
}
|
}
|
||||||
|
@@ -2978,24 +2978,25 @@ wxRect wxPropertyGrid::GetEditorWidgetRect( wxPGProperty* p, int column ) const
|
|||||||
{
|
{
|
||||||
int itemy = p->GetY2(m_lineHeight);
|
int itemy = p->GetY2(m_lineHeight);
|
||||||
int vy = 0;
|
int vy = 0;
|
||||||
int cust_img_space = 0;
|
|
||||||
int splitterX = m_pState->DoGetSplitterPosition(column-1);
|
int splitterX = m_pState->DoGetSplitterPosition(column-1);
|
||||||
int colEnd = splitterX + m_pState->m_colWidths[column];
|
int colEnd = splitterX + m_pState->m_colWidths[column];
|
||||||
|
int imageOffset = 0;
|
||||||
|
|
||||||
// TODO: If custom image detection changes from current, change this.
|
// TODO: If custom image detection changes from current, change this.
|
||||||
if ( m_iFlags & wxPG_FL_CUR_USES_CUSTOM_IMAGE /*p->m_flags & wxPG_PROP_CUSTOMIMAGE*/ )
|
if ( m_iFlags & wxPG_FL_CUR_USES_CUSTOM_IMAGE )
|
||||||
{
|
{
|
||||||
//m_iFlags |= wxPG_FL_CUR_USES_CUSTOM_IMAGE;
|
//m_iFlags |= wxPG_FL_CUR_USES_CUSTOM_IMAGE;
|
||||||
int imwid = p->OnMeasureImage().x;
|
int iw = p->OnMeasureImage().x;
|
||||||
if ( imwid < 1 ) imwid = wxPG_CUSTOM_IMAGE_WIDTH;
|
if ( iw < 1 )
|
||||||
cust_img_space = imwid + wxCC_CUSTOM_IMAGE_MARGIN1 + wxCC_CUSTOM_IMAGE_MARGIN2;
|
iw = wxPG_CUSTOM_IMAGE_WIDTH;
|
||||||
|
imageOffset = p->GetImageOffset(iw);
|
||||||
}
|
}
|
||||||
|
|
||||||
return wxRect
|
return wxRect
|
||||||
(
|
(
|
||||||
splitterX+cust_img_space+wxPG_XBEFOREWIDGET+wxPG_CONTROL_MARGIN+1,
|
splitterX+imageOffset+wxPG_XBEFOREWIDGET+wxPG_CONTROL_MARGIN+1,
|
||||||
itemy-vy,
|
itemy-vy,
|
||||||
colEnd-splitterX-wxPG_XBEFOREWIDGET-wxPG_CONTROL_MARGIN-cust_img_space-1,
|
colEnd-splitterX-wxPG_XBEFOREWIDGET-wxPG_CONTROL_MARGIN-imageOffset-1,
|
||||||
m_lineHeight-1
|
m_lineHeight-1
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user