[wx-dev] Fwd: CVS: [RD] wxWidgets/src/mac/carbon renderer.cpp,1.34,1.35

Alan Shouls alan at softpress.com
Wed Nov 1 06:32:27 PST 2006


Hi

>KO> Out of curiosity, are there any sort of rules about where the
>KO> LogicalToDevice adjustments should be performed? Looking in src/mac/
>KO> carbon/renderer.cpp, I see that other wxRendererNative functions do
>KO> the LogicalToRelative conversions internally, and I'm a bit concerned
>KO> that the discrepancy could cause confusion down the line. (In fact,
>KO> in src/generic/treectlg.cpp, x and y are adjusted values, while width
>KO> and height are not.)

I had some problems with this a while back - getting disclosure 
triangles to draw using the appearance manager. It is not work that I 
have checked in - but is backed for I finish with the wxIcons and 
friends, also I have to look at the new drawing and how it will fit 
with that. Anyhow the upshot was that things draw a few px out.

I append my original e-mail

Alan

======================

Hi

I am trying to get the disclosure Triangles in the tree-control to be 
drawn with the appearance manager. I am doing this because the tree 
control is very similar to the Mac lists but looks a little 
different. There are a few things I am trying to tweak - this is the 
first one. I have worked with this sort of thing in other frameworks 
and am using it as a way to learn about wx.

There is some old commented out code in 
wxRendererMac::DrawTreeItemButton that almost does the job. The thing 
that has got me stumped is getting the disclosure to draw in the 
correct place. The code to calculate the correct rectangle to draw in 
is quite straight-forward. However the issue that I am stumbling on 
is the correct rectangle to draw in the device context. The problem 
is that the drawing is based on a rectangle which is positioned 
through

   MacWindowToRootWindow( & loc_x , & loc_y ) ;

If I look at how rectangles are drawn in the device context it is 
quite different

	wxCoord xx = XLOG2DEVMAC(x);
	wxCoord yy = YLOG2DEVMAC(y);
	wxCoord ww = m_signX * XLOG2DEVREL(width);
	wxCoord hh = m_signY * YLOG2DEVREL(height);
	// CMB: draw nothing if transformed w or h is 0
	if (ww == 0 || hh == 0)
	    return;
	// CMB: handle -ve width and/or height
	if (ww < 0)
	{
	    ww = -ww;
	    xx = xx - ww;
	}
	if (hh < 0)
	{
	    hh = -hh;
	    yy = yy - hh;
	}
	Rect rect = { yy , xx , yy + hh , xx + ww } ;

The difference is that a rectangle is positioned differently (by a 
few px) under these two different ways of positioning things.

On the one hand it feels kind of wrong to be doing this calculation 
in wxRendererMac, but also it is impossible because m_signX and 
m_signY are not public and have no accessors. The best I can think of 
is to add a couple of getters for these two member variables and to 
add a static function Rect2DEVMAC to wxRendererMac.

static bool Rect2DEVMAC(const wxDC &dc, wxCoord x, wxCoord y, wxCoord 
w, wxCoord h, Rect *r)
{
     wxCoord xx = dc.XLOG2DEVMAC(x);
     wxCoord yy = dc.YLOG2DEVMAC(y);
     wxCoord ww = dc.GetSignX() * dc.XLOG2DEVREL(w);
     wxCoord hh = dc.GetSignY() * dc.YLOG2DEVREL(h);
     // CMB: draw nothing if transformed w or h is 0
     if (ww == 0 || hh == 0)
         return false;
     // CMB: handle -ve width and/or height
     if (ww < 0)
     {
         ww = -ww;
         xx = xx - ww;
     }
     if (hh < 0)
     {
         hh = -hh;
         yy = yy - hh;
     }

     r->top = yy;
     r->left = xx;
     r->bottom = yy + hh;
     r->right = xx + ww;
     return true;
}

I would be grateful for any thoughts.

Alan Shouls




More information about the wx-dev mailing list