[Date Prev][Date Next][Thread Prev][Thread Next][Thread Index]
[XaraXtreme-commits] Commit Complete
Commit by : alex
Repository : xara
Revision : 799
Date : Tue Apr 11 10:11:16 BST 2006
Changed paths:
M /Trunk/XaraLX/wxOil/dlgmgr.cpp
M /Trunk/XaraLX/wxOil/dlgview.cpp
M /Trunk/XaraLX/wxOil/drawctl.cpp
M /Trunk/XaraLX/wxOil/drawctl.h
M /Trunk/XaraLX/wxOil/osrndrgn.cpp
Fix up mouse handling in owner drawn controls (risk of SEGV)
Fix up broken DPI handling in dlgview.cpp
Add OSRenderRegion functions to render text and resource bitmaps
Diff:
Index: Trunk/XaraLX/wxOil/drawctl.h
===================================================================
--- Trunk/XaraLX/wxOil/drawctl.h (revision 798)
+++ Trunk/XaraLX/wxOil/drawctl.h (revision 799)
@@ -192,6 +192,7 @@
// EventHandlers
void OnPaint(wxPaintEvent & event);
+ void OnMouseEvent(wxMouseEvent & event);
void OnInvoke(wxCamDrawControlEvent& event);
virtual void SetStyle(wxCamDrawControlStyle style) { m_CamDrawControlStyle=style; }
Index: Trunk/XaraLX/wxOil/dlgview.cpp
===================================================================
--- Trunk/XaraLX/wxOil/dlgview.cpp (revision 798)
+++ Trunk/XaraLX/wxOil/dlgview.cpp (revision 799)
@@ -105,6 +105,7 @@
#include "dlgview.h"
#include "vstate.h"
#include "errors.h"
+#include "osrndrgn.h"
DECLARE_SOURCE("$Revision$");
@@ -131,7 +132,10 @@
{
// Get pixel size from screen DC.
INT32 pixwidth, pixheight;
- wxScreenDC().GetSize( &pixwidth, &pixheight ); // NB wxScreenDC() creates temp. wxScreenDC object
+ wxScreenDC dc;
+ wxSize ppi = OSRenderRegion::GetFixedDCPPI(dc);
+ pixwidth=ppi.GetWidth();
+ pixheight=ppi.GetHeight();
// Set up our pixel size
PixelWidth = FIXED16(72000.0 / pixwidth);
Index: Trunk/XaraLX/wxOil/drawctl.cpp
===================================================================
--- Trunk/XaraLX/wxOil/drawctl.cpp (revision 798)
+++ Trunk/XaraLX/wxOil/drawctl.cpp (revision 799)
@@ -117,6 +117,7 @@
BEGIN_EVENT_TABLE(wxCamDrawControl, wxControl)
EVT_CAMDRAWCONTROL_INVOKE(wxID_ANY, wxCamDrawControl::OnInvoke)
EVT_PAINT(wxCamDrawControl::OnPaint)
+ EVT_MOUSE_EVENTS(wxCamDrawControl::OnMouseEvent)
END_EVENT_TABLE();
IMPLEMENT_DYNAMIC_CLASS( wxCamDrawControlXmlHandler, wxXmlResourceHandler)
@@ -184,7 +185,44 @@
pParent->GetEventHandler()->ProcessEvent(RedrawEvent);
}
+/********************************************************************************************
+> void wxCamDrawControl::OnMouseEvent(wxMouseEvent & event)
+
+
+ Author: Alex_Bligh <alex@xxxxxxxxxxx>
+ Created: 30/12/2005
+ Inputs: event - the event
+ Outputs: -
+ Returns: -
+ Purpose: Handles mouse events
+ Errors: -
+ SeeAlso: -
+
+********************************************************************************************/
+
+void wxCamDrawControl::OnMouseEvent(wxMouseEvent & event)
+{
+ // Irritatingly wxMouseEvent does not propagate to the parent, but we expect it to.
+ // so we have to fake it (sigh)
+ // event.Skip(); // pretend we did not handle it, so it falls through to the dialog
+
+ if ( !(GetExtraStyle() & wxWS_EX_BLOCK_EVENTS) )
+ {
+ wxWindow * pParent = GetParent();
+ if (pParent && !pParent->IsBeingDeleted())
+ {
+ wxEvtHandler *pHandler = pParent->GetEventHandler();
+ if (pHandler && pHandler->IsKindOf(CLASSINFO(DialogEventHandler))) // Only propagate to our own dialogs
+ {
+ pHandler->ProcessEvent(event);
+ }
+ }
+ }
+}
+
+
+
/********************************************************************************************
> void wxCamDrawControl::OnInvoke(wxCamDrawControlEvent & event)
Index: Trunk/XaraLX/wxOil/dlgmgr.cpp
===================================================================
--- Trunk/XaraLX/wxOil/dlgmgr.cpp (revision 798)
+++ Trunk/XaraLX/wxOil/dlgmgr.cpp (revision 799)
@@ -992,9 +992,69 @@
//case wxEVT_COMMAND_TOOL_RCLICKED:
//case wxEVT_COMMAND_TOOL_ENTER:
+
+ // Handle filling in ExtraInfo on redraw events
+ if ((msg.DlgMsg != DIM_NONE) && pGadget && pGadget->IsKindOf(CLASSINFO(wxCamDrawControl)) && event.IsKindOf(CLASSINFO(wxMouseEvent)))
+ {
+ switch (msg.DlgMsg)
+ {
+ case DIM_LFT_BN_DOWN:
+ case DIM_LFT_BN_UP:
+ case DIM_RGT_BN_DOWN:
+ case DIM_RGT_BN_UP:
+ case DIM_MOUSE_DRAG:
+ case DIM_MOUSE_MOVE:
+ case DIM_MOUSEWHEEL_UP:
+ case DIM_MOUSEWHEEL_DOWN:
+ {
+
+ // HDC hDC = pInfo->PaintInfo.hdc;
+ // HPALETTE OldPalette = PaletteManager::StartPaintPalette(hDC);
+
+ ReDrawInfoType ExtraInfo;
+
+ ExtraInfo.pMousePos = NULL; // No mouse position info for redraw events
+
+
+ // Build a CC dc out of it for rendering to the screen
+ // Get a MFC CDC to put the DC in
+ CCPaintDC MyDc(pGadget);
+
+ ExtraInfo.pDC = NULL;
+
+ // The devices DPI
+ ExtraInfo.Dpi = OSRenderRegion::GetFixedDCPPI(MyDc).GetHeight();
+
+ // How big the window is
+ wxSize WindowSize = pGadget->GetClientSize();
+ ExtraInfo.dx = (((INT32)WindowSize.GetWidth())*72000) / ExtraInfo.Dpi;
+ ExtraInfo.dy = (((INT32)WindowSize.GetHeight())*72000) / ExtraInfo.Dpi;
+
+ // Work out the MILLIPOINT coordinates of the mouse position
+ // Note that the Y value is flipped, as the kernel-origin is at the bottom left
+ INT32 XPos = ((wxMouseEvent *)(&event))->GetX();
+ INT32 YPos = ((wxMouseEvent *)(&event))->GetY();
+
+ DocCoord MousePos;
+ MousePos.x = (XPos * 72000) / ExtraInfo.Dpi;
+ MousePos.y = ExtraInfo.dy - ((YPos * 72000) / ExtraInfo.Dpi);
+ ExtraInfo.pMousePos = &MousePos;
+
+ BROADCAST_TO_CLASS(DialogMsg(pEvtHandler->pwxWindow, msg.DlgMsg, id, (UINT_PTR)(void *)&ExtraInfo, PageID), DialogOp);
+
+ msg.DlgMsg = DIM_NONE; // Stop further processing
+ }
+
+ default:
+ break;
+ }
+ }
+
+
// If we have a message to send, then send it (or defer it for later)
if (msg.DlgMsg != DIM_NONE)
{
+
if (Defer)
{
// We should send the message out later - we use the same ID
Index: Trunk/XaraLX/wxOil/osrndrgn.cpp
===================================================================
--- Trunk/XaraLX/wxOil/osrndrgn.cpp (revision 798)
+++ Trunk/XaraLX/wxOil/osrndrgn.cpp (revision 799)
@@ -2200,17 +2200,22 @@
void OSRenderRegion::DrawFixedSystemText(StringBase *TheText, DocRect &BoundsRect, UINT32 uFormat /* = FORMAT_SINGLELINE | FORMAT_NOPREFIX | FORMAT_VCENTER */)
{
- PORTNOTETRACE("text","OSRenderRegion::DrawFixedSystemText - do nothing");
-#ifndef EXCLUDE_FROM_XARALX
- WinRect Rect(0,0,0,0);
+ wxString Text = (wxString)(TCHAR *)(*TheText);
+ wxRect Rect(0,0,0,0);
if (uFormat & FORMAT_CALCRECT) // just calculate the rect needed to draw the text and return
{
INT32 LineHeight = 0;
// This won't actually draw the text, instead it returns a rectangle in 'Rect'
- LineHeight = RenderDC->DrawText((TCHAR *) (*TheText), -1, &Rect, uFormat);
+ // LineHeight = RenderDC->DrawText((TCHAR *) (*TheText), -1, &Rect, uFormat);
+ LineHeight = RenderDC->GetCharHeight();
+ wxCoord w, h;
+ RenderDC->GetTextExtent(Text, &w, &h);
+ Rect = wxRect(0, 0, w, h);
- INT32 XDPI = GetDeviceCaps(RenderDC->m_hDC, LOGPIXELSX);
- INT32 YDPI = GetDeviceCaps(RenderDC->m_hDC, LOGPIXELSY);
+ wxDC * pDC = RenderDC;
+ wxSize DPI = GetFixedDCPPI(*pDC);
+ INT32 XDPI = DPI.GetWidth();
+ INT32 YDPI = DPI.GetHeight();
if(XDPI == 0 || YDPI == 0 || LineHeight == 0)
{
@@ -2226,24 +2231,24 @@
return;
}
-
- Rect = DocRectToWin(BoundsRect, 0,-1,1,0, TRUE);
+ Rect = DocRectToWin(BoundsRect, 0,0,0,0, TRUE);
+ // Rect = DocRectToWin(BoundsRect, 0,-1,1,0, TRUE);
// Small 'fix' - If we DrawRect the 'BoundsRect' then windows draws the text 1 pixel
// further to the right than the rectangle. This just ensures that the text is always
// clipped inside the rectangle rather than outside (at worst, a pixel too far inside)
if (Rect.width>0) // Still a valid rectangle?
{
- Rect.x--;
- INT32 LineHeight;
+// Rect.x--;
+// INT32 LineHeight;
RenderDC->SetBackgroundMode(wxTRANSPARENT);
+ RenderDC->DrawText(Text, Rect.GetLeft(), Rect.GetTop());
- LineHeight = RenderDC->DrawText((TCHAR *) (*TheText), -1, &Rect, uFormat);
+// LineHeight = RenderDC->DrawText((TCHAR *) (*TheText), -1, &Rect, uFormat);
- ENSURE(LineHeight > 0, "OSRenderRegion::DrawFixedSystemText failed");
+// ENSURE(LineHeight > 0, "OSRenderRegion::DrawFixedSystemText failed");
}
-#endif
}
@@ -2328,37 +2333,39 @@
void OSRenderRegion::GetFixedSystemTextSize(StringBase *TheText, DocRect *BoundsRect, double* atDpi)
{
- PORTNOTETRACE("text","OSRenderRegion::GetFixedSystemTextSize - do nothing");
-#ifndef EXCLUDE_FROM_XARALX
+ wxString Text = (wxString)(TCHAR *)(*TheText);
+
ERROR3IF(TheText == NULL, "OSRenderRegion::GetFixedSystemTextSize given a null text pointer");
ERROR3IF(BoundsRect == NULL, "OSRenderRegion::GetFixedSystemTextSize given a null bounds rect pointer");
if(TheText == NULL || BoundsRect == NULL)
return;
- WinRect Rect(0,0,0,0);
INT32 LineHeight = 0;
-
// This won't actually draw the text, instead it returns a rectangle in 'Rect'
- LineHeight = RenderDC->DrawText((TCHAR *) (*TheText), -1, &Rect,
- DT_SINGLELINE | DT_NOPREFIX | DT_CALCRECT);
+ // LineHeight = RenderDC->DrawText((TCHAR *) (*TheText), -1, &Rect, uFormat);
+ LineHeight = RenderDC->GetCharHeight();
+ wxCoord w, h;
+ RenderDC->GetTextExtent(Text, &w, &h);
+ wxRect Rect(0, 0, w, h);
- INT32 XDPI = GetDeviceCaps(RenderDC->m_hDC, LOGPIXELSX);
- INT32 YDPI = GetDeviceCaps(RenderDC->m_hDC, LOGPIXELSY);
+ wxDC * pDC = RenderDC;
+ wxSize DPI = GetFixedDCPPI(*pDC);
+ INT32 XDPI = DPI.GetWidth();
+ INT32 YDPI = DPI.GetHeight();
if(XDPI == 0 || YDPI == 0 || LineHeight == 0)
{
- ERROR3("OSRenderRegion::GetFixedSystemTextSize failed");
- *BoundsRect = DocRect(0, 0, 0, 0);
+ ERROR3("Can not calculate text size");
+ *BoundsRect = DocRect(0, 0, 0, 0);
return;
}
-
// For some reason, Rect.bottom and Rect.top seem to be incorrect, so we have
// to use the returned LineHeight value
-
*BoundsRect = DocRect(0, 0,
- (INT32)(((double)Rect.width * IN_MP_VAL) / XDPI),
- (INT32)(((double)LineHeight * IN_MP_VAL) / YDPI) );
-#endif
+ (INT32)(((double)Rect.width * IN_MP_VAL) / XDPI),
+ (INT32)(((double)LineHeight * IN_MP_VAL) / YDPI) );
+ return;
+
}
@@ -3355,105 +3362,25 @@
void OSRenderRegion::DrawBitmap(const DocCoord &Point, UINT32 BitmapID, UINT32 ToolID)
{
- PORTNOTETRACE("other","OSRenderRegion::DrawBitmap - do nothing");
-#ifndef EXCLUDE_FROM_XARALX
// If we are not drawing complex shapes and this shape is, then return
if ((!RenderComplexShapes) && (TestForComplexShape(&Caps)))
return;
- HBITMAP hBmp;
+ wxBitmap * pBitmap=CamArtProvider::Get()->FindBitmap((ResourceID)BitmapID);
- if (ToolID != NULL)
- {
- // Find the tool that contains our Bitmap
- OILTool* pTheTool = Tool::GetOILTool(ToolID);
-
- if (pTheTool == NULL)
- {
- TRACE( _T("Couldn't find the tool in DrawBitmapBlob
"));
- return;
- }
-
- // Ask the Tool to load the bitmap and return a Handle
- hBmp = pTheTool->LoadBitmap(BitmapID);
- }
- else
- {
- // No tool was specified, so we'll try the Kernel
- hBmp = ::LoadBitmap(AfxGetResourceHandle(), MAKEINTRESOURCE(BitmapID));
- }
-
- if (hBmp == 0)
- {
- TRACE( _T("Bitmap failed to Load in DrawBitmapBlob
"));
+ if (!pBitmap)
return;
- }
-
- // Make a Bitmap Object
- CBitmap Bitmap;
- BOOL ok = Bitmap.Attach(hBmp);
- if (!ok)
- {
- TRACE( _T("CBitmap failed to create in DrawBitmapBlob
"));
- return;
- }
-
- // Find out how big the Bitmap Info is
- INT32 NumBytes = GetObject(hBmp, 0, NULL);
-
- // Make a Info Structure big enough to hold it
- BITMAPINFOHEADER* pBmpInfo = (BITMAPINFOHEADER*)new BYTE[NumBytes];
-
- if (pBmpInfo == NULL)
- {
- TRACE( _T("Not enough memory for BitmapInfo in DrawBitmapBlob
"));
- return;
- }
-
- // Get Info on the Bitmap
- GetObject(hBmp, NumBytes, pBmpInfo);
-
// Extract the Width and Height
- INT32 Width = pBmpInfo->biWidth;
- INT32 Height = pBmpInfo->biHeight;
+ // INT32 Width = pBitmap->GetWidth();
+ INT32 Height = pBitmap->GetHeight();
- delete pBmpInfo; // Don't need this any more
-
// Convert the DocCoord into a windows coord
- POINT Origin = DocCoordToWin(Point);
+ wxPoint Origin = DocCoordToWin(Point);
Origin.y = Origin.y - Height; // Translate bottom left to top left
- CDC MemDC;
- // Create a Memory DC based on this render region
- MemDC.CreateCompatibleDC(RenderDC);
- // And select the Bitmap into it
- CBitmap* OldBmp = MemDC.SelectObject(&Bitmap);
+ RenderDC->DrawBitmap(*pBitmap, Origin.x, Origin.y, TRUE);
- if (OldBmp == NULL)
- {
- TRACE( _T("Couldn't select Bitmap into CDC in DrawBitmapBlob
"));
- return;
- }
-
- // Plot the bitmap onto this render region
- RenderDC->BitBlt( Origin.x, Origin.y,
- Width,
- Height,
- &MemDC,
- 0,0,
- SRCCOPY
- );
-
- // Unselect our bitmap and delete it
- MemDC.SelectObject(OldBmp);
-
- ok = Bitmap.DeleteObject();
- if (!ok)
- {
- TRACE( _T("Delete Bitmap failed in DrawBitmapBlob
"));
- }
-#endif
}
BOOL OSRenderRegion::DrawTransformedBitmap(NodeBitmap *pNodeBitmap)
Xara