00001 // $Id: dragbmp.cpp 1658 2006-08-03 14:50:05Z alex $ 00002 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE 00003 ================================XARAHEADERSTART=========================== 00004 00005 Xara LX, a vector drawing and manipulation program. 00006 Copyright (C) 1993-2006 Xara Group Ltd. 00007 Copyright on certain contributions may be held in joint with their 00008 respective authors. See AUTHORS file for details. 00009 00010 LICENSE TO USE AND MODIFY SOFTWARE 00011 ---------------------------------- 00012 00013 This file is part of Xara LX. 00014 00015 Xara LX is free software; you can redistribute it and/or modify it 00016 under the terms of the GNU General Public License version 2 as published 00017 by the Free Software Foundation. 00018 00019 Xara LX and its component source files are distributed in the hope 00020 that it will be useful, but WITHOUT ANY WARRANTY; without even the 00021 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00022 See the GNU General Public License for more details. 00023 00024 You should have received a copy of the GNU General Public License along 00025 with Xara LX (see the file GPL in the root directory of the 00026 distribution); if not, write to the Free Software Foundation, Inc., 51 00027 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00028 00029 00030 ADDITIONAL RIGHTS 00031 ----------------- 00032 00033 Conditional upon your continuing compliance with the GNU General Public 00034 License described above, Xara Group Ltd grants to you certain additional 00035 rights. 00036 00037 The additional rights are to use, modify, and distribute the software 00038 together with the wxWidgets library, the wxXtra library, and the "CDraw" 00039 library and any other such library that any version of Xara LX relased 00040 by Xara Group Ltd requires in order to compile and execute, including 00041 the static linking of that library to XaraLX. In the case of the 00042 "CDraw" library, you may satisfy obligation under the GNU General Public 00043 License to provide source code by providing a binary copy of the library 00044 concerned and a copy of the license accompanying it. 00045 00046 Nothing in this section restricts any of the rights you have under 00047 the GNU General Public License. 00048 00049 00050 SCOPE OF LICENSE 00051 ---------------- 00052 00053 This license applies to this program (XaraLX) and its constituent source 00054 files only, and does not necessarily apply to other Xara products which may 00055 in part share the same code base, and are subject to their own licensing 00056 terms. 00057 00058 This license does not apply to files in the wxXtra directory, which 00059 are built into a separate library, and are subject to the wxWindows 00060 license contained within that directory in the file "WXXTRA-LICENSE". 00061 00062 This license does not apply to the binary libraries (if any) within 00063 the "libs" directory, which are subject to a separate license contained 00064 within that directory in the file "LIBS-LICENSE". 00065 00066 00067 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS 00068 ---------------------------------------------- 00069 00070 Subject to the terms of the GNU Public License (see above), you are 00071 free to do whatever you like with your modifications. However, you may 00072 (at your option) wish contribute them to Xara's source tree. You can 00073 find details of how to do this at: 00074 http://www.xaraxtreme.org/developers/ 00075 00076 Prior to contributing your modifications, you will need to complete our 00077 contributor agreement. This can be found at: 00078 http://www.xaraxtreme.org/developers/contribute/ 00079 00080 Please note that Xara will not accept modifications which modify any of 00081 the text between the start and end of this header (marked 00082 XARAHEADERSTART and XARAHEADEREND). 00083 00084 00085 MARKS 00086 ----- 00087 00088 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara 00089 designs are registered or unregistered trademarks, design-marks, and/or 00090 service marks of Xara Group Ltd. All rights in these marks are reserved. 00091 00092 00093 Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK. 00094 http://www.xara.com/ 00095 00096 =================================XARAHEADEREND============================ 00097 */ 00098 // DragBmp.cpp - Bitmap DragInformation base class 00099 00100 /* 00101 */ 00102 00103 00104 #include "camtypes.h" 00105 00106 #include "dragbmp.h" 00107 #include "dragmgr.h" 00108 #include "keypress.h" 00109 #include "camframe.h" 00110 //#include "bitmap.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00111 #include "bitmpinf.h" 00112 #include "oilbitmap.h" 00113 00114 #include "grndrgn.h" 00115 #include "gdrawcon.h" 00116 //#include "dibutil.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00117 00118 #include "gbrush.h" 00119 #include "camelot.h" // for IsWin32s() 00120 //#include "app.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00121 00122 //#include "sgtree.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00123 #include "grndbmp.h" 00124 //#include "docview.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00125 //#include "spread.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00126 #include "palman.h" 00127 00128 DECLARE_SOURCE("$Revision: 1658 $"); 00129 00130 CC_IMPLEMENT_DYNCREATE(BitmapDragInformation, DragInformation) 00131 00132 #define new CAM_DEBUG_NEW 00133 00134 const INT32 CellSize = 180; 00135 const INT32 NullSize = 112; 00136 00137 // Default to 50% transparent drags 00138 INT32 BitmapDragInformation::DragTransparency = 50; 00139 00140 /******************************************************************************************** 00141 00142 > void BitmapDragInformation::BitmapDragInformation() 00143 00144 Author: Will_Cowling (Xara Group Ltd) <camelotdev@xara.com> 00145 Created: 12/1/95 00146 00147 Purpose: Conmstructor - do not call this default constructor. 00148 00149 ********************************************************************************************/ 00150 00151 BitmapDragInformation::BitmapDragInformation() 00152 { 00153 // ERROR3("Default BitmapDragInformation constructor called"); 00154 } 00155 00156 00157 00158 /******************************************************************************************** 00159 00160 > void BitmapDragInformation::BitmapDragInformation(KernelBitmap * Bitmap, 00161 INT32 xSize, 00162 INT32 ySize, 00163 INT32 xOffset, 00164 INT32 yOffset, 00165 BOOL IsAdjust) 00166 00167 Author: Will_Cowling (Xara Group Ltd) <camelotdev@xara.com> 00168 Created: 12/1/95 00169 00170 Inputs: Bitmap - The KernelBitmap being dragged 00171 xSize - The Width (in Pixels) of the Drag Rectangle. 00172 ySize - The Height (in Pixels) of the Drag Rectangle. 00173 xOffset - The offset (in Pixels) from the mouse to the top of the bitmap. 00174 yOffset - The offset (in Pixels) from the mouse to the left edge of the bitmap. 00175 IsAdjust - TRUE if this is an adjust-drag 00176 00177 Purpose: Constructor 00178 00179 ********************************************************************************************/ 00180 00181 BitmapDragInformation::BitmapDragInformation( KernelBitmap * DragBitmap, 00182 INT32 xSize, 00183 INT32 ySize, 00184 INT32 xOffset, 00185 INT32 yOffset, 00186 BOOL IsAdjust) 00187 :DragInformation(IsAdjust) 00188 { 00189 // The Kernel Bitmap we are dragging 00190 TheBitmap = DragBitmap; 00191 00192 TempInfo = NULL; 00193 TempBits = NULL; 00194 00195 MemDC = NULL; 00196 Bitmap = NULL; 00197 DragMask = NULL; 00198 MaskBitmap = NULL; 00199 00200 // Set up a few things about this drag 00201 DoesSolidDrag = TRUE; 00202 00203 // offset of Bitmap swatch from the pointer 00204 SolidDragOffset.x = 0; 00205 SolidDragOffset.y = 16; 00206 00207 BitmapInfo Info; 00208 00209 INT32 BitmapWidth = (TheBitmap != NULL) ? CellSize : NullSize; 00210 INT32 BitmapHeight = (TheBitmap != NULL) ? CellSize : NullSize; 00211 00212 // The aspect ratio of the bitmap 00213 double Ratio = 1.0; 00214 00215 if (ySize == 0 && 00216 TheBitmap != NULL && 00217 TheBitmap->ActualBitmap != NULL && 00218 TheBitmap->ActualBitmap->GetInfo( &Info )) 00219 { 00220 BitmapWidth = Info.PixelWidth; 00221 BitmapHeight = Info.PixelHeight; 00222 00223 // Calculate the aspect ratio of the bitmap 00224 Ratio = double(Info.RecommendedWidth)/double(Info.RecommendedHeight); 00225 } 00226 00227 // If the user supplied the sizes, keep their aspect 00228 if(xSize > 0 && ySize > 0) 00229 Ratio = double(xSize) / double(ySize); 00230 00231 // size of the solid drag redraw 00232 SolidDragSize.x = (xSize > 0) ? xSize : BitmapWidth; 00233 SolidDragSize.y = (ySize > 0) ? ySize : BitmapHeight; 00234 00235 if (xSize > 0 && ySize == 0) 00236 SolidDragSize.y = INT32(SolidDragSize.x / Ratio); 00237 00238 if (SolidDragSize.x > CellSize) 00239 { 00240 SolidDragSize.x = CellSize; 00241 SolidDragSize.y = INT32(SolidDragSize.x / Ratio); 00242 } 00243 00244 if (SolidDragSize.y > CellSize) 00245 { 00246 SolidDragSize.y = CellSize; 00247 SolidDragSize.x = INT32(SolidDragSize.y * Ratio); 00248 } 00249 00250 // Offset relative to bitmap centre 00251 SolidDragOffset.x += (xOffset - SolidDragSize.x/2); 00252 SolidDragOffset.y += (yOffset - SolidDragSize.y/2); 00253 00254 DragRect.x = SolidDragSize.x; 00255 DragRect.y = SolidDragSize.y; 00256 } 00257 00258 /******************************************************************************************** 00259 00260 > void BitmapDragInformation::~BitmapDragInformation() 00261 00262 Author: Will_Cowling (Xara Group Ltd) <camelotdev@xara.com> 00263 Created: 12/1/95 00264 00265 Purpose: Destructor 00266 00267 ********************************************************************************************/ 00268 00269 BitmapDragInformation::~BitmapDragInformation() 00270 { 00271 if (Bitmap) 00272 { 00273 // Bitmap->DeleteObject(); 00274 delete Bitmap; 00275 } 00276 00277 if (MaskBitmap) 00278 { 00279 delete MaskBitmap; 00280 } 00281 00282 if (DragMask) 00283 { 00284 // DragMask->ActualBitmap->IsTemp = TRUE; 00285 // DragMask->ActualBitmap->Detach(); 00286 delete DragMask; 00287 } 00288 } 00289 00290 /******************************************************************************************** 00291 00292 > virtual UINT32 BitmapDragInformation::ApplyBitmapToSelection() 00293 00294 Author: Will_Cowling (Xara Group Ltd) <camelotdev@xara.com> 00295 Created: 15/1/95 00296 Returns: Apply current drag Bitmap to selection - set current fill/stroke attributes 00297 Purpose: Applies the dragged Bitmap to the current selection 00298 00299 ********************************************************************************************/ 00300 00301 void BitmapDragInformation::ApplyBitmapToSelection() 00302 { 00303 } 00304 00305 00306 00307 /******************************************************************************************** 00308 00309 > virtual UINT32 BitmapDragInformation::GetCursorID() 00310 00311 Author: Will_Cowling (Xara Group Ltd) <camelotdev@xara.com> 00312 Created: 15/1/95 00313 Returns: a cursor ID to set during this drag 00314 Purpose: Determines what cursor to display during a Bitmap drag 00315 00316 ********************************************************************************************/ 00317 00318 UINT32 BitmapDragInformation::GetCursorID() 00319 { 00320 return GetCursorID(NULL); 00321 } 00322 00323 00324 00325 /******************************************************************************************** 00326 00327 > virtual BOOL BitmapDragInformation::GetStatusLineText(String_256 * TheText) 00328 00329 Author: Will_Cowling (Xara Group Ltd) <camelotdev@xara.com> 00330 Created: 15/1/95 00331 00332 Outputs: TheText - If it returns TRUE, this is filled in with status line text 00333 Returns: Whether String is valid 00334 00335 Purpose: provide status line text for this drag 00336 00337 ********************************************************************************************/ 00338 00339 BOOL BitmapDragInformation::GetStatusLineText(String_256 * TheText) 00340 { 00341 if (TheBitmap == NULL || TheBitmap->ActualBitmap == NULL) 00342 return FALSE; 00343 00344 ERROR2IF(TheText==NULL,FALSE,"NULL string in GetStatusLineText()"); 00345 00346 return GetStatusLineText(TheText, NULL); 00347 } 00348 00349 /******************************************************************************************** 00350 00351 > virtual UINT32 BitmapDragInformation::GetCursorID(DragTarget* pDragTarget) 00352 00353 Author: Will_Cowling (Xara Group Ltd) <camelotdev@xara.com> 00354 Created: 15/1/95 00355 Returns: a cursor ID to set during this drag 00356 Purpose: Determines what cursor to display during a Bitmap drag 00357 00358 ********************************************************************************************/ 00359 00360 UINT32 BitmapDragInformation::GetCursorID(DragTarget* pDragTarget) 00361 { 00362 return 0; 00363 } 00364 00365 /******************************************************************************************** 00366 00367 > virtual BOOL BitmapDragInformation::GetStatusLineText(String_256 * TheText, DragTarget* pDragTarget) 00368 00369 Author: Will_Cowling (Xara Group Ltd) <camelotdev@xara.com> 00370 Created: 15/1/95 00371 00372 Outputs: TheText - If it returns TRUE, this is filled in with status line text 00373 Returns: Whether String is valid 00374 00375 Purpose: provide status line text for this drag 00376 00377 ********************************************************************************************/ 00378 00379 BOOL BitmapDragInformation::GetStatusLineText(String_256 * TheText, DragTarget* pDragTarget) 00380 { 00381 if (TheBitmap == NULL || TheBitmap->ActualBitmap == NULL) 00382 return FALSE; 00383 00384 ERROR2IF(TheText==NULL,FALSE,"NULL string in GetStatusLineText()"); 00385 00386 return FALSE; 00387 } 00388 00389 00390 /******************************************************************************************** 00391 00392 > void BitmapDragInformation::OnClick(INT32 Flags,POINT Point) 00393 00394 Author: Will_Cowling (Xara Group Ltd) <camelotdev@xara.com> 00395 Created: 12/1/95 00396 Inputs: 00397 Outputs: - 00398 Returns: - 00399 00400 Purpose: This is called if a drag was attempted but never started because it was a 00401 click all along. In the base class, the default action is to make the 00402 Bitmap bar think that the dragged Bitmap has been clicked. 00403 00404 Errors: - 00405 SeeAlso: - 00406 00407 ********************************************************************************************/ 00408 00409 void BitmapDragInformation::OnClick(INT32 Flags, POINT Point) 00410 { 00411 if(KeyPress::IsAdjustPressed()) 00412 Flags = -1; 00413 } 00414 00415 BOOL BitmapDragInformation::StartGalleryItemDrag(SGDisplayItem* pGalleryItem) 00416 { 00417 /* 00418 // pGalleryItem->CalculateMyRect(&FormatInfo, &MiscInfo); 00419 00420 DocRect ClipRegion(0,0, 100*750,100*750); 00421 00422 Matrix ConvertMatrix; 00423 FIXED16 ViewScale = 1; 00424 00425 CDC* pDisplayDC = new CDC(); 00426 pDisplayDC->CreateDC("DISPLAY", NULL, NULL, NULL); 00427 00428 UINT32 Depth = GetDeviceCaps( pDisplayDC->m_hDC, BITSPIXEL ) * 00429 GetDeviceCaps( pDisplayDC->m_hDC, PLANES ); 00430 00431 INT32 dpi = GetDeviceCaps( pDisplayDC->m_hDC, LOGPIXELSX ); 00432 00433 GRenderBitmap* pRegion = new GRenderBitmap(ClipRegion, ConvertMatrix, ViewScale, 00434 Depth, dpi); 00435 00436 GRenderBitmap* pMaskRegion = new GRenderBitmap(ClipRegion, ConvertMatrix, ViewScale, 00437 1, dpi); 00438 00439 DocView *View = DocView::GetCurrent(); 00440 Spread *pSpread = View->FindEnclosingSpread(OilCoord(0,0)); 00441 00442 pRegion->AttachDevice(View, pDisplayDC, pSpread); 00443 pMaskRegion->AttachDevice(View, pDisplayDC, pSpread); 00444 00445 // Make a Mask Bitmap 00446 pMaskRegion->StartRender(); 00447 ((SGDisplayLineAttrItem*)pGalleryItem)->Render(pMaskRegion, ClipRegion); 00448 00449 // Make the Drag Bitmap 00450 pRegion->StartRender(); 00451 ((SGDisplayLineAttrItem*)pGalleryItem)->Render(pRegion, ClipRegion); 00452 00453 OILBitmap* pOilMaskBmp = pMaskRegion->ExtractBitmap(); 00454 DragMask = new KernelBitmap(pOilMaskBmp); 00455 00456 OILBitmap* pOilDragBmp = pRegion->ExtractBitmap(); 00457 TheBitmap = new KernelBitmap(pOilDragBmp); 00458 00459 delete pMaskRegion; 00460 delete pRegion; 00461 delete pDisplayDC; 00462 00463 */ 00464 return TRUE; 00465 } 00466 00467 /******************************************************************************************** 00468 00469 > void BitmapDragInformation::OnDrawSolidDrag(wxPoint Origin, wxDC * TheDC, DragTarget* pDragTarget) 00470 00471 Author: Will_Cowling (Xara Group Ltd) <camelotdev@xara.com> 00472 Created: 12/1/95 00473 Inputs: TheDC - pointer to a DC ready to draw into. 00474 Outputs: - 00475 Returns: - 00476 Purpose: allows the drag to draw into a Device Context - DragManager will look after 00477 painting the background etc. 00478 Errors: - 00479 SeeAlso: - 00480 00481 ********************************************************************************************/ 00482 00483 BOOL BitmapDragInformation::OnDrawSolidDrag(wxPoint Origin, wxDC * TheDC, DragTarget* pDragTarget) 00484 { 00485 return OnDrawSolidDrag(Origin, TheDC); 00486 } 00487 00488 /******************************************************************************************** 00489 00490 > void BitmapDragInformation::OnDrawSolidDrag(wxPoint Origin, wxDC* TheDC) 00491 00492 Author: Will_Cowling (Xara Group Ltd) <camelotdev@xara.com> 00493 Created: 12/1/95 00494 Inputs: TheDC - pointer to a DC ready to draw into. 00495 Outputs: - 00496 Returns: - 00497 Purpose: allows the drag to draw into a Device Context - DragManager will look after 00498 painting the background etc. 00499 Errors: - 00500 SeeAlso: - 00501 00502 ********************************************************************************************/ 00503 00504 BOOL BitmapDragInformation::OnDrawSolidDrag(wxPoint Origin, wxDC* TheDC) 00505 { 00506 // CPalette * OldPal = NULL; 00507 00508 // if (PaletteManager::UsePalette()) 00509 // { 00510 // OldPal = PaletteManager::StartPaintPalette( TheDC); 00511 // } 00512 00513 if (TheBitmap != NULL && TheBitmap->ActualBitmap != NULL) 00514 { 00515 PlotBitmap((CWxBitmap*)TheBitmap->ActualBitmap, Origin, DragRect, TheDC); 00516 } 00517 else 00518 { 00519 // get a gbrush brush 00520 GBrush GDrawBrush; 00521 GDrawBrush.Init(TheDC); 00522 GDrawBrush.Start(); 00523 00524 DWORD ScreenWord = 0x007F7F7F; 00525 00526 wxBrush *pDragBrush = NULL; 00527 00528 pDragBrush = new wxBrush; 00529 00530 BOOL BrushCreate = TRUE; 00531 00532 if (pDragBrush != NULL ) 00533 { 00534 // create the Brush and Pen 00535 if (GDrawBrush.Available()) 00536 { 00537 GDrawBrush.GetLogBrush((COLORREF)(ScreenWord), pDragBrush); 00538 } 00539 else 00540 *pDragBrush=wxBrush(wxColour(0x7F,0x7F,0x7F)); 00541 00542 wxPen MyPen(*wxBLACK); 00543 00544 //the rectangle to draw into 00545 wxRect DrawRect; 00546 00547 if(DragRect.GetWidth() == 0 || DragRect.GetHeight() == 0) 00548 DrawRect = wxRect(Origin.x,Origin.y, NullSize, NullSize); 00549 else 00550 DrawRect = wxRect(Origin.x,Origin.y, DragRect.GetWidth(), DragRect.GetHeight()); 00551 00552 // select brushes and pens .. 00553 TheDC->SetBrush(*pDragBrush); 00554 TheDC->SetPen(MyPen); 00555 00556 // draw an ellipse 00557 // TheDC->Ellipse(&DrawRect); 00558 00559 // draw some text 00560 // String_256 Str("Blobby"); 00561 // TheDC->TextOut(Origin.x, Origin.y, (TCHAR *)Str, Str.Length()); 00562 00563 // draw a rectangle 00564 TheDC->DrawRectangle(DrawRect); 00565 00566 TheDC->SetBrush(*wxTRANSPARENT_BRUSH); 00567 TheDC->SetPen(*wxTRANSPARENT_PEN); 00568 00569 delete pDragBrush; 00570 } 00571 else 00572 BrushCreate = FALSE; 00573 00574 // Finish with GBrush 00575 GDrawBrush.Stop(); 00576 } 00577 00578 // if (OldPal) 00579 // PaletteManager::StopPaintPalette(TheDC, OldPal); 00580 00581 return TRUE; 00582 } 00583 00584 00585 /******************************************************************************************** 00586 00587 > BOOL BitmapDragInformation::PlotBitmap( CWxBitmap *wxBM, 00588 CPoint Origin, CSize Size, 00589 CDC * RenderDC) 00590 00591 Author: Will_Cowling (Xara Group Ltd) <camelotdev@xara.com> 00592 Created: 19/3/95 00593 Inputs: RenderDC - pointer to a DC ready to draw into. 00594 Outputs: - 00595 Returns: FALSE, if the plot failed. 00596 Purpose: Plots the specified Bitmap into the DC, during a solid drag. 00597 Errors: - 00598 SeeAlso: - 00599 00600 ********************************************************************************************/ 00601 00602 BOOL BitmapDragInformation::PlotBitmap( CWxBitmap *wxBM, 00603 wxPoint Origin, wxSize Size, 00604 wxDC* RenderDC) 00605 { 00606 if ((wxBM == NULL) || 00607 (wxBM->BMInfo==NULL) || 00608 (wxBM->BMBytes==NULL) 00609 ) 00610 return FALSE; 00611 00612 wxPoint TopLeft = Origin; 00613 00614 wxPoint BottomLeft; 00615 BottomLeft.x = TopLeft.x; 00616 BottomLeft.y = TopLeft.y + Size.y; 00617 00618 wxPoint BottomRight; 00619 BottomRight.x = TopLeft.x + Size.x; 00620 BottomRight.y = TopLeft.y + Size.y; 00621 00622 INT32 DestWidth = BottomRight.x - BottomLeft.x; 00623 INT32 DestHeight = BottomLeft.y - TopLeft.y; 00624 00625 // This has been commented out because the hPal is only used inside a comment 00626 // If it is needed then just use *(pPal) and let MFC sort it out... 00627 00628 // get the HPALETTE to pass to the plot bitmap call - crucial for quality Win32s DDB plotting 00629 // uses sneaky HPALETTE operator 00630 // HPALETTE hPal = NULL; 00631 // if (PaletteManager::UsePalette()) 00632 // hPal = *(PaletteManager::GetPalette()); 00633 00634 wxMemoryDC MemDC; 00635 00636 // Get the palette to use (will be NULL if palette not needed) 00637 wxPalette* pPal = PaletteManager::GetPalette(); 00638 00639 // If this is the first time, then we need to create the Cached Bitmap 00640 if (Bitmap == NULL) 00641 { 00642 Bitmap = new wxBitmap(DestWidth, DestHeight); 00643 if (Bitmap == NULL) 00644 { 00645 return FALSE; 00646 } 00647 00648 INT32 bpp = wxBM->GetBPP(); 00649 00650 if (MaskBitmap) 00651 { 00652 delete MaskBitmap; 00653 MaskBitmap = NULL; 00654 } 00655 00656 // For now, only do the mask bitmap where we have a 32bpp representation 00657 // as I haven't tested whether Gavin works OK with (say) a palette with 00658 // transparency in it 00659 if ((bpp==32) && TheBitmap->IsTransparent()) 00660 { 00661 // If this fails, we simply treat it as non-transparent. Hey ho 00662 MaskBitmap = new wxBitmap(DestWidth, DestHeight); 00663 } 00664 00665 MemDC.SelectObject(*Bitmap); 00666 00667 PORTNOTE("other", "disabled palettes in dragbmp") 00668 #ifndef EXCLUDE_FROM_XARALX 00669 if (PaletteManager::UsePalette()) 00670 MemDC.SelectPalette(pPal, FALSE); 00671 #endif 00672 00673 // Since the GDI cannot cope with anything other than very simple bitmaps, 00674 // we will get GDraw to render the bitmap into a screen compatible DIB, and 00675 // then get the GDI to plot that 00676 00677 GDrawContext* GD = GRenderRegion::GetStaticDrawContext(); 00678 00679 // Setup a default matrix (we'll do everything in pixel-speak) 00680 00681 GMATRIX GMatrix; 00682 00683 GMatrix.AX = 1<<(16 + FX); 00684 GMatrix.AY = 0; 00685 GMatrix.BX = 0; 00686 GMatrix.BY = 1<<(16 + FX); 00687 00688 GMatrix.CX = 0; 00689 GMatrix.CY = 0; 00690 00691 // Create a Tempory bitmap compatible with the output device 00692 00693 INT32 DeviceDepth; 00694 00695 PORTNOTE("other", "Assume 24bpp intermediate bitmap in DragBmp"); 00696 #ifndef EXCLUDE_FROM_XARALX 00697 DeviceDepth = GetDeviceCaps( RenderDC->m_hDC, BITSPIXEL ) * 00698 GetDeviceCaps( RenderDC->m_hDC, PLANES ); 00699 #else 00700 DeviceDepth = 24; 00701 #endif 00702 00703 if (DeviceDepth == 24) 00704 DeviceDepth = 32; // GDraw cannot plot to 24-bit bitmaps 00705 00706 TempInfo = AllocDIB(DestWidth, DestHeight, DeviceDepth, &TempBits); 00707 if (TempInfo==NULL) 00708 { 00709 TRACEALL( _T("Out of memory during BitmapDragInformation::PlotBitmap")); 00710 return FALSE; 00711 } 00712 00713 #ifdef _DEBUG 00714 *((DWORD *)(void *)(TempBits))=0xDEADBEEF; 00715 #endif 00716 00717 // We may need to get a palette for the DIB. 00718 00719 DIBPal = DIB_RGB_COLORS; 00720 00721 if (DeviceDepth <= 8) // We only need a palette for 256 colours or less. 00722 { 00723 DIBPal = GRenderRegion::SetPaletteEntries( TempInfo, RenderDC ); 00724 } 00725 00726 // Setup GDraw with our Tempory Bitmap and Identity Matrix 00727 00728 GD->SetupBitmap(TempInfo->bmiHeader.biWidth, 00729 TempInfo->bmiHeader.biHeight, 00730 TempInfo->bmiHeader.biBitCount, 00731 TempBits ); 00732 00733 GD->SetMatrix( &GMatrix ); 00734 00735 COLORREF DefaultColour = 0xFFFFFFFF; 00736 00737 RGBQUAD TempPalette[256]; 00738 RGBQUAD* Palette = wxBM->BMInfo->bmiColors; 00739 00740 if (bpp <= 8) 00741 { 00742 INT32 NumCols; 00743 switch (bpp) 00744 { 00745 case 1: 00746 NumCols = 2; 00747 break; 00748 00749 case 2: 00750 NumCols = 4; 00751 break; 00752 00753 case 4: 00754 NumCols = 16; 00755 break; 00756 00757 case 8: 00758 NumCols = 256; 00759 break; 00760 00761 default: 00762 NumCols = 256; 00763 break; 00764 } 00765 00766 for (INT32 i=0; i<NumCols; i++) 00767 { 00768 if (Palette[i].rgbReserved == 0xFF) 00769 { 00770 // We'll use a copy of the palette ... 00771 memcpy(TempPalette, Palette, NumCols*sizeof(RGBQUAD)); 00772 00773 // so we can force this entry to be white 00774 TempPalette[i].rgbRed = 0xFF; 00775 TempPalette[i].rgbGreen = 0xFF; 00776 TempPalette[i].rgbBlue = 0xFF; 00777 00778 Palette = TempPalette; 00779 break; 00780 } 00781 } 00782 } 00783 00784 // Now set the bitmap fill 00785 00786 POINT PGram[3]; 00787 PGram[0].x = 0; PGram[0].y = 0; 00788 PGram[1].x = DestWidth; PGram[1].y = 0; 00789 PGram[2].x = 0; PGram[2].y = DestHeight; 00790 00791 GD->SetDefaultBitmapParameters(); 00792 GD->SetTileSmoothingFlag(TRUE/*FALSE*/); 00793 GD->SetTileFilteringFlag(TRUE/*FALSE*/); 00794 00795 00796 GD->SetBitmapFill( &(wxBM->BMInfo->bmiHeader), 00797 wxBM->BMBytes, 00798 1, 00799 PGram, 00800 DefaultColour, 00801 Palette, 00802 NULL, NULL, NULL, 00803 NULL, 00804 0 00805 ); 00806 00807 // Now plot a filled rectangle 00808 00809 RECT BmpRect; 00810 BmpRect.left = 0; 00811 BmpRect.top = DestHeight; 00812 BmpRect.right = DestWidth; 00813 BmpRect.bottom = 0; 00814 00815 GD->FillRectangle(&BmpRect); 00816 00817 // Now we use GRenderRegion to plot it (far easier than farting about 00818 // with conversion which was the previous technique...) 00819 00820 GRenderRegion::StaticPlotBitmap(&MemDC, DIBPal, TempInfo, TempBits, 0, 0, DestWidth, DestHeight, pPal, 0, 0); 00821 00822 if (MaskBitmap) 00823 { 00824 // Make the rectangle black 00825 MemDC.SelectObject(*MaskBitmap); 00826 GD->SetColour(0); 00827 GD->FillRectangle(&BmpRect); 00828 00829 // Contone between white and white, but use the transparency values 00830 GD->SetColour(0xFFFFFF); 00831 GD->SetContone(1, 0xFFFFFF, 0xFFFFFF); 00832 GD->SetBias(3, 0.0); 00833 GD->SetGain(3, 0.0); 00834 GD->SetTileSmoothingFlag(TRUE/*FALSE*/); 00835 GD->SetTileFilteringFlag(TRUE/*FALSE*/); 00836 GD->SetBitmapFill( &(wxBM->BMInfo->bmiHeader), 00837 wxBM->BMBytes, 00838 0x4000, 00839 PGram, 00840 DefaultColour, 00841 Palette, 00842 NULL, NULL, NULL, 00843 NULL, 00844 0 00845 ); 00846 GD->FillRectangle(&BmpRect); 00847 00848 GRenderRegion::StaticPlotBitmap(&MemDC, DIBPal, TempInfo, TempBits, 0, 0, DestWidth, DestHeight, pPal, 0, 0); 00849 } 00850 00851 GD->SetDefaultBitmapParameters(); // restore this, as else it upsets things 00852 00853 FreeDIB(TempInfo, TempBits); 00854 00855 } 00856 // Finally plot the Bitmap onto the output RenderDC 00857 if (RenderDC) 00858 RenderDC->DrawBitmap(*Bitmap, TopLeft.x, TopLeft.y, true); 00859 00860 // Yipeee !! We done it 00861 return TRUE; 00862 } 00863 00864 /******************************************************************************************** 00865 00866 > KernelBitmap* BitmapDragInformation::GetSolidDragMask() 00867 00868 Author: Will_Cowling (Xara Group Ltd) <camelotdev@xara.com> 00869 Created: 10/4/95 00870 Returns: - 00871 Purpose: Get a 1 bpp mask to use for the solid drag. 00872 SeeAlso: - 00873 00874 We (ab)use this call to ensure an initial plot is done, which in turn sets up the mask, 00875 which has to be done before the first plot (on setup) 00876 00877 ********************************************************************************************/ 00878 00879 KernelBitmap* BitmapDragInformation::GetSolidDragMask() 00880 { 00881 if (TheBitmap != NULL && TheBitmap->ActualBitmap != NULL) 00882 { 00883 wxBitmap bitmap(1,1); 00884 wxMemoryDC DC; 00885 DC.SelectObject(bitmap); 00886 PlotBitmap((CWxBitmap*)TheBitmap->ActualBitmap, wxPoint(0,0), DragRect, &DC); 00887 } 00888 00889 return DragMask; 00890 } 00891 00892 /******************************************************************************************** 00893 00894 > INT32 BitmapDragInformation::GetDragTransparency() 00895 00896 Author: Will_Cowling (Xara Group Ltd) <camelotdev@xara.com> 00897 Created: 19/3/95 00898 Returns: - 00899 Purpose: Specifies how transparent a drag should be. 00900 A value of 0, will cause a normal solid blit. 00901 Any other value (between 0 and 100), will cause a masked blit. 00902 SeeAlso: - 00903 00904 ********************************************************************************************/ 00905 00906 INT32 BitmapDragInformation::GetDragTransparency() 00907 { 00908 return BitmapDragInformation::DragTransparency; 00909 } 00910 00911 /******************************************************************************************** 00912 00913 > static BOOL BitmapDragInformation::Init() 00914 00915 Author: Will_Cowling (Xara Group Ltd) <camelotdev@xara.com> 00916 Created: 19/3/95 00917 Returns: - 00918 Purpose: Initialise any Bitmap Drag stuff. (eg. ini file preferences). 00919 SeeAlso: - 00920 00921 ********************************************************************************************/ 00922 00923 BOOL BitmapDragInformation::Init() 00924 { 00925 // Setup preference for drag transparency 00926 if (GetApplication()->DeclareSection(_T("Dragging"), 1)) 00927 { 00928 GetApplication()->DeclarePref( NULL, _T("BitmapDragTransparency"), 00929 &DragTransparency, 0, 100); 00930 } 00931 00932 return TRUE; 00933 } 00934