sgdfonts.cpp

Go to the documentation of this file.
00001 // $Id: sgdfonts.cpp 1282 2006-06-09 09:46:49Z 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 // SGDFonts.cpp - Fonts SuperGallery Dragging classes
00099 
00100 /* The below code is riddled with DC's and OIL-specifc Font calls... Hence the location */
00101 
00102 #include "camtypes.h"
00103 #include "sgdfonts.h"
00104 #include "sgfonts.h"
00105 #include "sgfonts.h"
00106 
00107 #ifndef EXCLUDE_GALS
00108 
00109 //#include "app.h"      // For GetApplication() - in camtypes.h [AUTOMATICALLY REMOVED]
00110 //#include "galstr.h"
00111 //#include "convert.h"  // For Millipoint convs - in camtypes.h [AUTOMATICALLY REMOVED]
00112 //#include "fillval.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00113 #include "grnddib.h"
00114 //#include "bitmap.h"       // For bitmap stuff ! - in camtypes.h [AUTOMATICALLY REMOVED]
00115 #include "bitmpinf.h"   // For more bitmap stuff
00116 #include "nodebmp.h"    // For bitmap drawing stuff
00117 //#include "galres.h"
00118 //#include "sgallery.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00119 //#include "fixmem.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00120 #include "wbitmap.h"
00121 //#include "richard.h"  
00122 //#include "sgscan.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00123 #include "sgscanf.h"
00124 #include "sglib.h"
00125 //#include "thumb.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00126 #include "fontpgen.h"   // For Font thumbnail generation
00127 //#include "basestr.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00128 //#include "resource.h"
00129 #include "sgliboil.h"   // For various stuff
00130 #include "dlgmgr.h"
00131 #include "camelot.h"
00132 #include "keypress.h"
00133 //#include "sgindgen.h"
00134 
00135 // For apply
00136 //#include "txtattr.h"
00137 //#include "attrmgr.h"  
00138 //#include "textinfo.h"
00139 #include "nodetext.h"   // For status line stuff
00140 
00141 #include "dragmgr.h"
00142 #include "scrcamvw.h"
00143 //#include "viewrc.h"       // FOR _R(IDC_CANDROPONPAGE)
00144 //#include "docview.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00145 //#include "spread.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00146 
00147 // For drag masks
00148 #include "grndbmp.h"
00149 
00150 // For LibraryGallery
00151 #include "sglbase.h"
00152 
00153 //#include "richard2.h"
00154 //#include "richard3.h"
00155 
00156 // Implement the dynamic class bits...
00157 CC_IMPLEMENT_DYNCREATE(GalleryFontsDragInfo, BitmapDragInformation)
00158 CC_IMPLEMENT_DYNCREATE(GalleryLibFontsDragInfo, BitmapDragInformation)
00159 CC_IMPLEMENT_DYNAMIC(SGFontsDragTarget, SGListDragTarget)
00160 
00161 // This line mustn't go before any CC_IMPLEMENT_... macros
00162 #define new CAM_DEBUG_NEW
00163 
00164 
00165 /********************************************************************************************
00166 
00167 >   SGFontsDragTarget::SGFontsDragTarget(DialogOp *TheDialog, CGadgetID TheGadget = NULL)
00168      
00169     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
00170     Created:    25/3/95
00171     Inputs:     TheDialog - The kernel dialog in which the target exists
00172                 TheGadget - The gadget within that dialogue which is the target
00173 
00174     Purpose:    Constructor
00175 
00176 ********************************************************************************************/
00177 
00178 SGFontsDragTarget::SGFontsDragTarget(DialogOp *TheDialog, CGadgetID TheGadget)
00179                     : SGListDragTarget(TheDialog, TheGadget)
00180 {
00181     ERROR3IF(!TheDialog->IsKindOf(CC_RUNTIME_CLASS(FontsSGallery)),
00182             "You can only use SGFontsDragTargets with LibFontsSGallery dialogues!");
00183 }
00184 
00185 
00186 
00187 /********************************************************************************************
00188 
00189     BOOL SGFontsDragTarget::ProcessEvent(DragEventType Event, DragInformation *pDragInfo,
00190                                             OilCoord *pMousePos, KeyPress* pKeyPress)
00191 
00192     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
00193     Created:    25/3/95
00194     Inputs:     Event - Indicates what has happened
00195                 pDragInfo - points to drag information describing this drag. This
00196                 should be a FontsDragInformation or derivation thereof
00197                 pMousePos - points to information on the current mouse position, in OIL coords
00198                 pKeyPress - NULL, or if for a keypress event, keypress information
00199 
00200     Returns:    TRUE to claim the event, FALSE to let it through to other targets
00201 
00202     Purpose:    Event Handler for SuperGallery listitem drag events. Overrides the
00203                 base class handler to enable it to sort out the node being dragged
00204                 for Fonts drags.
00205 
00206 ********************************************************************************************/
00207 
00208 BOOL SGFontsDragTarget::ProcessEvent(DragEventType Event, DragInformation *pDragInfo,
00209                                         OilCoord *pMousePos, KeyPress* pKeyPress)
00210 {
00211     SGDisplayNode *DraggedNode = NULL;
00212     BOOL IsSimpleBitmapDrag = TRUE;
00213 
00214     if (IS_A(pDragInfo, GalleryFontsDragInfo))
00215     {
00216         // We must be dragging an Installed Font
00217         DraggedNode = ((GalleryFontsDragInfo *)pDragInfo)->GetDraggedFont();
00218         TRACEUSER( "Richard", _T("We're Dragging an installed font\n"));
00219         IsSimpleBitmapDrag = FALSE;
00220     }
00221     else if (IS_A(pDragInfo, GalleryLibFontsDragInfo))
00222     {
00223         // We must be dragging an Un-installed Font
00224         DraggedNode = ((GalleryLibFontsDragInfo *)pDragInfo)->GetDraggedFont();
00225         TRACEUSER( "Richard", _T("We're Dragging a library font\n"));
00226         IsSimpleBitmapDrag = FALSE;
00227     }
00228     else
00229         return(FALSE);      // We only accept font drags
00230 
00231     if (DraggedNode != NULL)
00232     {
00233         switch(Event)
00234         {
00235             case DRAGEVENT_COMPLETED:
00236                 HandleDragCompleted((SuperGallery *) TargetDialog,
00237                                     DraggedNode, pMousePos, IsSimpleBitmapDrag);
00238                 return(TRUE);
00239 
00240 
00241             case DRAGEVENT_MOUSESTOPPED:
00242             case DRAGEVENT_MOUSEMOVED:
00243             case DRAGEVENT_MOUSEIDLE:
00244                 {
00245                     // Specialised cursor changing code
00246 
00247                     SuperGallery *ParentGallery = (SuperGallery *) TargetDialog;
00248                     if (ParentGallery != NULL && pMousePos != NULL && DraggedNode != NULL)
00249                     {
00250                         // Convert the OilCoords into DocCoords
00251                         DocCoord MousePos(pMousePos->x, pMousePos->y);
00252                         SGDisplayNode *DestNode = ParentGallery->FindNodeUnderPointer(&MousePos);
00253 
00254                         if(DestNode != NULL)
00255                         {
00256                             SGDisplayNode *DestGroup = DestNode->GetParent();
00257                             SGDisplayNode *SourceGroup = DraggedNode->GetParent();
00258 
00259                             if(DestGroup != NULL && SourceGroup != NULL)
00260                             {   
00261                                 // We're dragging within a group - that's ok
00262                                 if(SourceGroup == DestGroup)
00263                                     return(DetermineCursorShape(ParentGallery, DraggedNode, pMousePos));
00264 
00265                                 // We're dragging a library font onto the installed section - that's ok
00266                                 if(SourceGroup->IS_KIND_OF(SGLibGroup) && DestGroup->IS_KIND_OF(SGFontsGroup))
00267                                     return(DetermineCursorShape(ParentGallery, DraggedNode, pMousePos));
00268                             }
00269                         }       
00270                     }
00271                 }
00272 
00273                 // If we can't drag a font item into this group, set the default cursor...
00274                 CurrentCursorID = _R(IDC_DRAGGING_COLOUR);      // No-can-drop cursor shape
00275                 return TRUE;
00276         }
00277     }
00278 
00279     // Otherwise, we aren't interested in the event, so we don't claim it
00280     return(FALSE);
00281 }
00282 
00283 /********************************************************************************************
00284 
00285 >   void GalleryFontsDragInfo::GalleryFontsDragInfo() 
00286      
00287     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
00288     Created:    19/3/95       
00289 
00290     Purpose:    Default constructor - do not call this constructor
00291 
00292 ********************************************************************************************/
00293 
00294 GalleryFontsDragInfo::GalleryFontsDragInfo()
00295 {
00296     ERROR3("Default GalleryFontsDragInfo constructor called");  
00297 }
00298 
00299 /********************************************************************************************
00300 
00301 >   void GalleryFontsDragInfo::~GalleryFontsDragInfo() 
00302      
00303     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
00304     Created:    27/4/95       
00305 
00306     Purpose:    Destructor - reclaim temporary bitmap memory
00307 
00308 ********************************************************************************************/
00309 
00310 GalleryFontsDragInfo::~GalleryFontsDragInfo()
00311 {
00312     if(LibraryGallery::TmpDraggingBitmap != NULL)
00313     {
00314         delete LibraryGallery::TmpDraggingBitmap;
00315         LibraryGallery::TmpDraggingBitmap = NULL;
00316     }
00317 }
00318 
00319 
00320 
00321 /********************************************************************************************
00322 
00323 >   GalleryFontsDragInfo::GalleryFontsDragInfo(SGDisplayPreviewFonts *pSourceItem,
00324                                             SGMouseInfo *pMouseInfo, SGMiscInfo *pMiscInfo,
00325                                             BOOL IsAdjust = FALSE,  INT32 XSize, INT32 YSize)
00326      
00327     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
00328     Created:    19/3/95       
00329 
00330     Inputs:     pSourceItem - The gallery item from which the drag originated
00331                 pMouseInfo  - The mouse info which made the item start the drag
00332                 pMiscInfo   - The MiscInfo which accompanied the mouse event
00333                 IsAdjust    - TRUE if this is an adjust (line-Bitmap) drag
00334                 XSize       - Width in pixels of bmp to drag
00335                 YSize       - Height in pixels of bmp to drag
00336 
00337     Purpose:    Constructor
00338 
00339 ********************************************************************************************/
00340 
00341 GalleryFontsDragInfo::GalleryFontsDragInfo(SGDisplayPreviewFonts *pSourceItem,
00342                                             SGMouseInfo *pMouseInfo, SGMiscInfo *pMiscInfo,
00343                                             BOOL IsAdjust, INT32 XSize, INT32 YSize)
00344                       : BitmapDragInformation(LibraryGallery::TmpDraggingBitmap, XSize, YSize,
00345                             FontsSGallery::GetDragFontOffset(LibraryGallery::TmpDraggingBitmap), 0,
00346                             IsAdjust)
00347 {
00348     SourceItem  = pSourceItem;  // Copy the source item pointer
00349 
00350     MouseInfo   = *pMouseInfo;  // Duplicate the structures (they may cease to exist
00351     MiscInfo    = *pMiscInfo;   // soon after the drag is started)
00352 }
00353 
00354 
00355 
00356 /********************************************************************************************
00357 
00358 >   void GalleryFontsDragInfo::OnClick(INT32 Flags,POINT Point) 
00359      
00360     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
00361     Created:    19/3/95       
00362     Inputs:     -
00363     Outputs:    -
00364     Returns:    -
00365     Purpose:    This is called if a drag was attempted but never started because it was a 
00366                 click all along. It calls back the SourceItem SGDisplayBitmap, to get it
00367                 to handle the click.
00368     Errors:     -
00369     SeeAlso:    -
00370 
00371 ********************************************************************************************/
00372 
00373 void GalleryFontsDragInfo::OnClick(INT32 Flags ,POINT Point)
00374 {
00375     if (SourceItem != NULL)
00376         SourceItem->DragWasReallyAClick(&MouseInfo, &MiscInfo);
00377 }
00378 
00379 /********************************************************************************************
00380 
00381 >   void GalleryFontsDragInfo::GetCursorID(DragTarget* pDragTarget)
00382 
00383     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
00384     Created:    25/3/95
00385     Purpose:    Set cursor over this target
00386 
00387 
00388 ********************************************************************************************/
00389 
00390 UINT32 GalleryFontsDragInfo::GetCursorID(DragTarget* pDragTarget)
00391 {
00392     if (pDragTarget && pDragTarget->IS_KIND_OF(ViewDragTarget))
00393     {
00394         PageDropInfo PageDropInfo;
00395         ((ViewDragTarget*)pDragTarget)->GetDropInfo(&PageDropInfo);
00396 
00397         NodeRenderableInk* pObjectHit   = PageDropInfo.pObjectHit;
00398         ObjectDragTarget TargetHit      = PageDropInfo.TargetHit;
00399 
00400         // if (pObjectHit && pObjectHit->IS_KIND_OF(TextChar))
00401         if (pObjectHit && pObjectHit->RequiresAttrib(CC_RUNTIME_CLASS(AttrTxtFontTypeface)))
00402             TargetHit = FILL_TARGET;
00403         else
00404             TargetHit = NO_TARGET;
00405 
00406         switch (TargetHit)
00407         {
00408             case FILL_TARGET:
00409                 return _R(IDC_CANDROPONFILL);
00410 
00411             case NO_TARGET:
00412                 return _R(IDC_CANDROPONPAGE);
00413         };
00414 
00415         return _R(IDC_CANDROPONPAGE);
00416     }
00417 
00418     return _R(IDC_CANTDROP);
00419 }
00420 
00421 /********************************************************************************************
00422 
00423 >   virtual BOOL GalleryFontsDragInfo::GetStatusLineText(String_256 * TheText, DragTarget* pDragTarget)
00424 
00425     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
00426     Created:    25/3/95
00427     Returns:    Whether String is valid
00428     Purpose:    provide status line text for this target
00429    
00430 ********************************************************************************************/
00431 
00432 BOOL GalleryFontsDragInfo::GetStatusLineText(String_256 * TheText, DragTarget* pDragTarget)
00433 {
00434 #ifdef STANDALONE
00435     return FALSE;
00436 #else
00437     ERROR2IF(TheText==NULL,FALSE,"NULL string in GetStatusLineText()");
00438 
00439     if (TheBitmap == NULL || TheBitmap->ActualBitmap == NULL)
00440         return FALSE;
00441 
00442     // "Dragging font '#1%s'"
00443     String_256 DragString;
00444     String_256 ItemName;
00445     SourceItem->GetNameText(&ItemName);
00446 //  DragString += *SourceItem->GetDisplayedTextDescription();
00447 
00448     DragString.MakeMsg(_R(IDS_FONTS_DRAGGING), (TCHAR *)ItemName);
00449 
00450 
00451     if (pDragTarget && pDragTarget->IS_KIND_OF(ViewDragTarget))
00452     {
00453         DragString += String_8(_R(IDS_SGDFONTS_STAT_COLON_SEP)); //" : ";
00454     
00455         PageDropInfo PageDropInfo;
00456         ((ViewDragTarget*)pDragTarget)->GetDropInfo(&PageDropInfo);
00457 
00458         NodeRenderableInk* pObjectHit   = PageDropInfo.pObjectHit;
00459         ObjectDragTarget TargetHit      = PageDropInfo.TargetHit;
00460 
00461         // if (pObjectHit && pObjectHit->IS_KIND_OF(TextChar))
00462         if (pObjectHit && pObjectHit->RequiresAttrib(CC_RUNTIME_CLASS(AttrTxtFontTypeface)))
00463             TargetHit = FILL_TARGET;
00464         else
00465             TargetHit = NO_TARGET;
00466 
00467         switch (TargetHit)
00468         {
00469             case FILL_TARGET:
00470                 if (IS_A(pObjectHit,CaretNode))
00471                 {
00472                     // + "Drop to apply this font to the caret";
00473                     String_64 DropToCaret(_R(IDS_FONTS_DROP_TO_APPLY_CARET));
00474                     DragString += DropToCaret;
00475                 }
00476                 else
00477                 {
00478                     if(pObjectHit->IsSelected())
00479                     {
00480                         // + "Drop to apply this font to the text selection";
00481                         String_64 DropToText(_R(IDS_FONTS_DROP_TO_APPLY_SEL));
00482                         DragString += DropToText;
00483                     }
00484                     else
00485                     if (KeyPress::IsConstrainPressed())
00486                     {
00487                         // + "Drop to apply this font to this character";
00488                         String_64 DropToText(_R(IDS_FONTS_DROP_TO_APPLY_CHAR));
00489                         DragString += DropToText;
00490                     }
00491                     else
00492                     {
00493                         // + "Drop to apply this font to the text story";
00494                         String_64 DropToText(_R(IDS_FONTS_DROP_TO_APPLY_TEXT));
00495                         DragString += DropToText;
00496                     }
00497                 }
00498                 break;
00499 
00500             case NO_TARGET:
00501                 {
00502                     // + "Drop to set the current font style";
00503                     String_64 DropToCurrent(_R(IDS_FONTS_DROP_TO_APPLY_CURRENT));
00504                     DragString += DropToCurrent;
00505                 }
00506                 break;
00507         };
00508 
00509         *TheText = DragString;
00510         return TRUE;
00511     }
00512 
00513     *TheText = DragString;
00514     return TRUE;
00515 #endif
00516 }
00517 
00518 /********************************************************************************************
00519 
00520 >   BOOL GalleryFontsDragInfo::OnPageDrop(ViewDragTarget* pDragTarget)
00521  
00522     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
00523     Created:    19/3/95       
00524     Inputs:     -
00525     Outputs:    -
00526     Returns:    -
00527     Purpose:    Called when a Fill is dropped onto the page.
00528     Errors:     -
00529     SeeAlso:    -
00530 
00531 ********************************************************************************************/
00532 
00533 BOOL GalleryFontsDragInfo::OnPageDrop(ViewDragTarget* pDragTarget)
00534 {
00535 #ifdef STANDALONE
00536     return FALSE;
00537 #else
00538     PageDropInfo PageDropInfo;
00539     ((ViewDragTarget*)pDragTarget)->GetDropInfo(&PageDropInfo);
00540     NodeRenderableInk* pObjectHit = PageDropInfo.pObjectHit;
00541     SGDisplayPreviewFonts* SelectedNode = SourceItem;
00542 
00543     return(FontsSGallery::ApplyFont(TRUE, (SGDisplayNode *)SourceItem, pObjectHit));
00544 #endif
00545 }
00546 
00547 
00548 
00549 /********************************************************************************************
00550 
00551 >   INT32 GalleryFontsDragInfo::GetDragTransparency()
00552 
00553     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
00554     Created:    19/4/95     
00555     Returns:    The drag tranparency to use for a Font Drag.
00556     Purpose:    Determines how transparent the dragged font will be.
00557 
00558 ********************************************************************************************/
00559 
00560 INT32 GalleryFontsDragInfo::GetDragTransparency()
00561 {
00562     // If there's no preview, it looks best if the rectangle is transparent
00563     if(TheBitmap == NULL)
00564         return 50;
00565 
00566     // Font drags look better as solid masked bmps
00567     return 0;
00568 }
00569 
00570 /********************************************************************************************
00571 
00572 >   KernelBitmap* GalleryFontsDragInfo::GetSolidDragMask()
00573 
00574     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
00575     Created:    19/4/95     
00576     Returns:    A pointer to the 1bpp Mask bitmap.
00577     Purpose:    Makes a 1bpp KernelBitmap mask for the Font preview solid drag.
00578 
00579                 This version makes use of the fact that it knows the Font Bitmaps are
00580                 8bpp, and so it can alter the palette (temporarily) to make the
00581                 Anti-Aliased pixels render as solid black.
00582 
00583     SeeAlso:    -
00584 
00585 ********************************************************************************************/
00586 
00587 KernelBitmap* GalleryFontsDragInfo::GetSolidDragMask()
00588 {
00589     if(TheBitmap == NULL)
00590     {
00591         DragMask = NULL;
00592         return NULL;
00593     }
00594 
00595     if (DragMask == NULL)
00596     {
00597         // First set up a 1bpp Gavin Bitmap to render into
00598         Matrix ConvertMatrix;
00599         FIXED16 ViewScale = 1;
00600 
00601         CDC* pDisplayDC = new CDC();
00602         if (pDisplayDC == NULL)
00603             return NULL;
00604 
00605         pDisplayDC->CreateDC("DISPLAY", NULL, NULL, NULL);
00606 
00607         double dpi   = (double) GetDeviceCaps( pDisplayDC->m_hDC, LOGPIXELSX );
00608 
00609         // Make life easy by making the Redraw Rectangle start at 0,0
00610         INT32 PixelSize = (INT32)(72000.0/dpi); //.MakeLong();
00611         DocRect ClipRegion(0,0, SolidDragSize.cx*PixelSize, SolidDragSize.cy*PixelSize);
00612 
00613         GRenderBitmap* pMaskRegion  = new GRenderBitmap(ClipRegion, ConvertMatrix, ViewScale,
00614                                                         1, dpi);
00615         if (pMaskRegion == NULL)
00616         {
00617             delete pDisplayDC;
00618             return NULL;
00619         }
00620 
00621         // Make a Dummy view and spread to attach, just to keep it happy
00622         DocView *View = DocView::GetCurrent();
00623         if (View == NULL)
00624         {
00625             delete pMaskRegion;
00626             delete pDisplayDC;
00627             return NULL;    // Must have a DocView
00628         }
00629 
00630         Spread *pSpread = View->FindEnclosingSpread(OilCoord(0,0));
00631         if (pSpread == NULL)
00632         {
00633             delete pMaskRegion;
00634             delete pDisplayDC;
00635             return NULL;    // Must have a Spread
00636         }
00637 
00638         pMaskRegion->AttachDevice(View, pDisplayDC, pSpread);
00639 
00640 // ****** Start of Bodge *******
00641 
00642 // To make the font mask look correct, we'll make use of the fact
00643 // that we know it's an 8bpp grey scale bitmap.
00644 // First we'll copy the existing palette, then temporarily set the
00645 // palette so all the colours are Black.
00646 // This should mean that everything except the White background of the
00647 // font bitmap will be rendered as Black.
00648 
00649 // This hopefully won't be needed when 'Proper' mask render regions are done
00650 
00651         WinBitmap* WinBM = (WinBitmap*)TheBitmap->ActualBitmap;
00652 
00653         RGBQUAD* Palette = WinBM->BMInfo->bmiColors;
00654         RGBQUAD OldPalette[256];
00655         
00656         // Make a copy of the existing palette
00657         for (INT32 i=0; i<256; i++)
00658         {
00659             OldPalette[i] = Palette[i];
00660         }
00661 
00662         // Now set all but the last few palette entries to 0
00663         // (The font bitmaps seems to use 253 for the background colour)
00664         for (i=0; i<256; i++)
00665         {
00666             Palette[i].rgbBlue  = ((i < 253) ? 0 : 255);
00667             Palette[i].rgbGreen = ((i < 253) ? 0 : 255);
00668             Palette[i].rgbRed   = ((i < 253) ? 0 : 255);
00669         }
00670 
00671 // ****** End of Bodge *******
00672 
00673         // Render the bitmap into the MaskRegion to create the 1bpp mask
00674         pMaskRegion->StartRender();
00675         pMaskRegion->DrawBitmap(DocCoord(0,0), TheBitmap);
00676         pMaskRegion->StopRender();
00677 
00678         // Restore the Proper Palatte values, so the bitmap can be
00679         // rendered properly
00680         for (i=0; i<256; i++)
00681         {
00682             Palette[i] = OldPalette[i];
00683         }
00684 
00685         // Get the 1bpp Mask bitmap out of the Render Region
00686         OILBitmap* pOilMaskBmp = pMaskRegion->ExtractBitmap();
00687         DragMask = new KernelBitmap(pOilMaskBmp, TRUE); 
00688 
00689         // Tidy up
00690         delete pMaskRegion;
00691         delete pDisplayDC;
00692     }
00693 
00694     return DragMask;
00695 }
00696 
00697 
00698 
00699 
00700 
00701 
00702 /********************************************************************************************
00703 
00704 >   void GalleryLibFontsDragInfo::GalleryLibFontsDragInfo() 
00705      
00706     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
00707     Created:    19/3/95       
00708 
00709     Purpose:    Default constructor - do not call this constructor
00710 
00711 ********************************************************************************************/
00712 
00713 GalleryLibFontsDragInfo::GalleryLibFontsDragInfo()
00714 {
00715     ERROR3("Default GalleryLibFontsDragInfo constructor called");   
00716 }
00717 
00718 /********************************************************************************************
00719 
00720 >   void GalleryLibFontsDragInfo::~GalleryLibFontsDragInfo() 
00721      
00722     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
00723     Created:    27/4/95       
00724 
00725     Purpose:    Destructor - reclaim temporary bitmap memory
00726 
00727 ********************************************************************************************/
00728 
00729 GalleryLibFontsDragInfo::~GalleryLibFontsDragInfo()
00730 {
00731     if(LibraryGallery::TmpDraggingBitmap != NULL)
00732     {
00733         delete LibraryGallery::TmpDraggingBitmap;
00734         LibraryGallery::TmpDraggingBitmap = NULL;
00735     }
00736 }
00737 
00738 
00739 
00740 /********************************************************************************************
00741 
00742 >   GalleryLibFontsDragInfo::GalleryLibFontsDragInfo(SGLibFontItem *pSourceItem,
00743                                             SGMouseInfo *pMouseInfo, SGMiscInfo *pMiscInfo,
00744                                             BOOL IsAdjust = FALSE, INT32 XSize = 0, INT32 YSize = 0)
00745      
00746     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
00747     Created:    19/3/95       
00748 
00749     Inputs:     pSourceItem - The gallery item from which the drag originated
00750                 pMouseInfo  - The mouse info which made the item start the drag
00751                 pMiscInfo   - The MiscInfo which accompanied the mouse event
00752                 IsAdjust    - TRUE if this is an adjust (line-Bitmap) drag
00753                 XSize       - Width of dragging bmp
00754                 YSize       - Height of dragging bmp
00755 
00756     Purpose:    Constructor
00757 
00758 ********************************************************************************************/
00759 
00760 GalleryLibFontsDragInfo::GalleryLibFontsDragInfo(SGLibFontItem *pSourceItem,
00761                                             SGMouseInfo *pMouseInfo, SGMiscInfo *pMiscInfo,
00762                                             BOOL IsAdjust, INT32 XSize, INT32 YSize)
00763                       : BitmapDragInformation(LibraryGallery::TmpDraggingBitmap, XSize, YSize,
00764                             FontsSGallery::GetDragFontOffset(LibraryGallery::TmpDraggingBitmap), 0,
00765                             IsAdjust)
00766 {
00767     SourceItem  = pSourceItem;  // Copy the source item pointer
00768 
00769     MouseInfo   = *pMouseInfo;  // Duplicate the structures (they may cease to exist
00770     MiscInfo    = *pMiscInfo;   // soon after the drag is started)
00771 }
00772 
00773 /********************************************************************************************
00774 
00775 >   void GalleryLibFontsDragInfo::OnClick(INT32 Flags,POINT Point) 
00776      
00777     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
00778     Created:    19/3/95       
00779     Inputs:     -
00780     Outputs:    -
00781     Returns:    -
00782     Purpose:    This is called if a drag was attempted but never started because it was a 
00783                 click all along. It calls back the SourceItem SGDisplayBitmap, to get it
00784                 to handle the click.
00785     Errors:     -
00786     SeeAlso:    -
00787 
00788 ********************************************************************************************/
00789 
00790 void GalleryLibFontsDragInfo::OnClick(INT32 Flags ,POINT Point)
00791 {
00792     if (SourceItem != NULL)
00793         SourceItem->DragWasReallyAClick(&MouseInfo, &MiscInfo);
00794 }
00795 
00796 /********************************************************************************************
00797 
00798 >   void GalleryLibFontsDragInfo::GetCursorID(DragTarget* pDragTarget)
00799 
00800     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
00801     Created:    25/3/95
00802     Purpose:    Set cursor over this target
00803 
00804 
00805 ********************************************************************************************/
00806 
00807 UINT32 GalleryLibFontsDragInfo::GetCursorID(DragTarget* pDragTarget)
00808 {
00809     if (pDragTarget && pDragTarget->IS_KIND_OF(ViewDragTarget))
00810     {
00811         PageDropInfo PageDropInfo;
00812         ((ViewDragTarget*)pDragTarget)->GetDropInfo(&PageDropInfo);
00813 
00814         NodeRenderableInk* pObjectHit   = PageDropInfo.pObjectHit;
00815         ObjectDragTarget TargetHit      = PageDropInfo.TargetHit;
00816         
00817         String_256 Desc256;
00818         SourceItem->GetNameText(&Desc256);
00819         if (pObjectHit && !FontsSGallery::IsFontAlreadyInstalled(&Desc256, SourceItem->GetType()) && SourceItem->GetParentLibrary() && SourceItem->GetParentLibrary()->IsWebLibrary())
00820             return _R(IDC_CANTDROP);
00821 
00822 
00823         // if (pObjectHit && pObjectHit->IS_KIND_OF(TextChar))
00824         if (pObjectHit && pObjectHit->RequiresAttrib(CC_RUNTIME_CLASS(AttrTxtFontTypeface)))
00825             TargetHit = FILL_TARGET;
00826         else
00827             TargetHit = NO_TARGET;
00828 
00829         switch (TargetHit)
00830         {
00831             case FILL_TARGET:
00832                 return _R(IDC_CANDROPONFILL);
00833 
00834             case NO_TARGET:
00835                 return _R(IDC_CANDROPONPAGE);
00836         };
00837 
00838         return _R(IDC_CANDROPONPAGE);
00839     }
00840 
00841     return _R(IDC_CANTDROP);
00842 }
00843 
00844 /********************************************************************************************
00845 
00846 >   virtual BOOL GalleryLibFontsDragInfo::GetStatusLineText(String_256 * TheText, DragTarget* pDragTarget)
00847 
00848     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
00849     Created:    25/3/95
00850     Returns:    Whether String is valid
00851     Purpose:    provide status line text for this target
00852    
00853 ********************************************************************************************/
00854 
00855 BOOL GalleryLibFontsDragInfo::GetStatusLineText(String_256 * TheText, DragTarget* pDragTarget)
00856 {
00857 #ifdef STANDALONE
00858     return FALSE;
00859 #else
00860     ERROR2IF(TheText==NULL,FALSE,"NULL string in GetStatusLineText()");
00861 
00862     if (TheBitmap == NULL || TheBitmap->ActualBitmap == NULL)
00863         return FALSE;
00864 
00865     String_256 DragString;
00866     String_256 ItemName;
00867     SourceItem->GetNameText(&ItemName);
00868     NodeRenderableInk* pObjectHit = NULL;
00869     PageDropInfo PageDropInfo;
00870     ObjectDragTarget TargetHit;
00871     if (pDragTarget && pDragTarget->IS_KIND_OF(ViewDragTarget))
00872     {
00873         ((ViewDragTarget*)pDragTarget)->GetDropInfo(&PageDropInfo);
00874         pObjectHit  = PageDropInfo.pObjectHit;
00875         TargetHit       = PageDropInfo.TargetHit;
00876     }
00877     if (pObjectHit && !FontsSGallery::IsFontAlreadyInstalled(&ItemName, SourceItem->GetType()) && SourceItem->GetParentLibrary() && SourceItem->GetParentLibrary()->IsWebLibrary())
00878         DragString = String_256(_R(IDS_MUST_DOWNLOAD));
00879     else
00880     {
00881         // "Dragging font '#1%s'"
00882         DragString.MakeMsg(_R(IDS_FONTS_DRAGGING), (TCHAR *)ItemName);
00883 
00884         if (pDragTarget && pDragTarget->IS_KIND_OF(SGFontsDragTarget))
00885         {
00886             DragString += String_8(_R(IDS_SGDFONTS_STAT_COLON_SEP)); //" : ";
00887         
00888             // + "Drop to Install this font"
00889             String_64 DropToInstall(_R(IDS_FONTS_DROP_TO_INSTALL));
00890             DragString += DropToInstall;
00891 
00892             *TheText = DragString;
00893             return TRUE;
00894         }
00895 
00896         if (pDragTarget && pDragTarget->IS_KIND_OF(ViewDragTarget))
00897         {
00898             DragString += String_8(_R(IDS_SGDFONTS_STAT_COLON_SEP)); //" : ";
00899         
00900 
00901             if (pObjectHit && pObjectHit->RequiresAttrib(CC_RUNTIME_CLASS(AttrTxtFontTypeface)))
00902                 TargetHit = FILL_TARGET;
00903             else
00904                 TargetHit = NO_TARGET;
00905 
00906             switch (TargetHit)
00907             {
00908                 case FILL_TARGET:
00909 
00910                     if (IS_A(pObjectHit,CaretNode))
00911                     {
00912                         // + "Drop to apply this font to the caret";
00913                         String_64 DropToCaret(_R(IDS_FONTS_DROP_TO_APPLY_CARET));
00914                         DragString += DropToCaret;
00915                     }
00916                     else
00917                     {
00918                         if(pObjectHit->IsSelected())
00919                         {
00920                             // + "Drop to apply this font to the text selection";
00921                             String_64 DropToText(_R(IDS_FONTS_DROP_TO_APPLY_SEL));
00922                             DragString += DropToText;
00923                         }
00924                         else
00925                         if (KeyPress::IsConstrainPressed())
00926                         {
00927                             // + "Drop to apply this font to this character";
00928                             String_64 DropToText(_R(IDS_FONTS_DROP_TO_APPLY_CHAR));
00929                             DragString += DropToText;
00930                         }
00931                         else
00932                         {
00933                             // + "Drop to apply this font to the text story";
00934                             String_64 DropToText(_R(IDS_FONTS_DROP_TO_APPLY_TEXT));
00935                             DragString += DropToText;
00936                         }
00937                     }
00938                     break;
00939 
00940                 case NO_TARGET:
00941                     {
00942                         // + "Drop to set the current font style";
00943                         String_64 DropToCurrent(_R(IDS_FONTS_DROP_TO_APPLY_CURRENT));
00944                         DragString += DropToCurrent;
00945                     }
00946                     break;
00947             };
00948 
00949             *TheText = DragString;
00950             return TRUE;
00951         }
00952     }
00953 
00954     *TheText = DragString;
00955     return TRUE;
00956 #endif
00957 }
00958 
00959 
00960 /********************************************************************************************
00961 
00962 >   BOOL GalleryLibFontsDragInfo::OnPageDrop(ViewDragTarget* pDragTarget)
00963  
00964     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
00965     Created:    20/4/95       
00966     Inputs:     -
00967     Outputs:    -
00968     Returns:    -
00969     Purpose:    Called when a library font is dropped onto the page.
00970     Errors:     -
00971     SeeAlso:    -
00972 
00973 ********************************************************************************************/
00974 
00975 BOOL GalleryLibFontsDragInfo::OnPageDrop(ViewDragTarget* pDragTarget)
00976 {
00977 #ifdef STANDALONE
00978     return FALSE;
00979 #else
00980     PageDropInfo PageDropInfo;
00981     ((ViewDragTarget*)pDragTarget)->GetDropInfo(&PageDropInfo);
00982     NodeRenderableInk* pObjectHit = PageDropInfo.pObjectHit;
00983     SGLibFontItem *FontItem = SourceItem;
00984 
00985     // Install the font then apply it
00986     return(FontsSGallery::ApplyFont(TRUE, (SGDisplayNode *)FontItem, pObjectHit));
00987 #endif
00988 }
00989 
00990 
00991 
00992 /********************************************************************************************
00993 
00994 >   INT32 GalleryLibFontsDragInfo::GetDragTransparency()
00995 
00996     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
00997     Created:    19/4/95     
00998     Returns:    The drag tranparency to use for a Font Drag.
00999     Purpose:    Determines how transparent the dragged font will be.
01000 
01001 ********************************************************************************************/
01002 
01003 INT32 GalleryLibFontsDragInfo::GetDragTransparency()
01004 {
01005     // If there's no preview, it looks best if the rectangle is transparent
01006     if(TheBitmap == NULL)
01007         return 50;
01008 
01009     // Font drags look better as solid masked bmps
01010     return 0;
01011 }
01012 
01013 /********************************************************************************************
01014 
01015 >   KernelBitmap* GalleryLibFontsDragInfo::GetSolidDragMask()
01016 
01017     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
01018     Created:    19/4/95     
01019     Returns:    A pointer to the 1bpp Mask bitmap.
01020     Purpose:    Makes a 1bpp KernelBitmap mask for the Font preview solid drag.
01021 
01022                 This version makes use of the fact that it knows the Font Bitmaps are
01023                 8bpp, and so it can alter the palette (temporarily) to make the
01024                 Anti-Aliased pixels render as solid black.
01025 
01026     SeeAlso:    -
01027 
01028 ********************************************************************************************/
01029 
01030 KernelBitmap* GalleryLibFontsDragInfo::GetSolidDragMask()
01031 {
01032     if(TheBitmap == NULL)
01033     {
01034         DragMask = NULL;
01035         return NULL;
01036     }
01037 
01038     if (DragMask == NULL)
01039     {
01040         // First set up a 1bpp Gavin Bitmap to render into
01041         Matrix ConvertMatrix;
01042         FIXED16 ViewScale = 1;
01043 
01044         CDC* pDisplayDC = new CDC();
01045         if (pDisplayDC == NULL)
01046             return NULL;
01047 
01048         pDisplayDC->CreateDC("DISPLAY", NULL, NULL, NULL);
01049 
01050         INT32 dpi   = GetDeviceCaps( pDisplayDC->m_hDC, LOGPIXELSX );
01051 
01052         // Make life easy by making the Redraw Rectangle start at 0,0
01053         INT32 PixelSize = 72000/dpi;
01054         DocRect ClipRegion(0,0, SolidDragSize.cx*PixelSize, SolidDragSize.cy*PixelSize);
01055 
01056         GRenderBitmap* pMaskRegion  = new GRenderBitmap(ClipRegion, ConvertMatrix, ViewScale,
01057                                                         1, dpi);
01058         if (pMaskRegion == NULL)
01059         {
01060             delete pDisplayDC;
01061             return NULL;
01062         }
01063 
01064         // Make a Dummy view and spread to attach, just to keep it happy
01065         DocView *View = DocView::GetCurrent();
01066         if (View == NULL)
01067         {
01068             delete pMaskRegion;
01069             delete pDisplayDC;
01070             return NULL;    // Must have a DocView
01071         }
01072 
01073         Spread *pSpread = View->FindEnclosingSpread(OilCoord(0,0));
01074         if (pSpread == NULL)
01075         {
01076             delete pMaskRegion;
01077             delete pDisplayDC;
01078             return NULL;    // Must have a Spread
01079         }
01080 
01081         pMaskRegion->AttachDevice(View, pDisplayDC, pSpread);
01082 
01083 // ****** Start of Bodge *******
01084 
01085 // To make the font mask look correct, we'll make use of the fact
01086 // that we know it's an 8bpp grey scale bitmap.
01087 // First we'll copy the existing palette, then temporarily set the
01088 // palette so all the colours are Black.
01089 // This should mean that everything except the White background of the
01090 // font bitmap will be rendered as Black.
01091 
01092 // This hopefully won't be needed when 'Proper' mask render regions are done
01093         WinBitmap* WinBM = (WinBitmap*)TheBitmap->ActualBitmap;
01094 
01095         RGBQUAD* Palette = WinBM->BMInfo->bmiColors;
01096         RGBQUAD OldPalette[256];
01097         
01098         // Make a copy of the existing palette
01099         for (INT32 i=0; i<256; i++)
01100         {
01101             OldPalette[i] = Palette[i];
01102         }
01103 
01104         // Now set all but the last few palette entries to 0
01105         // (The font bitmaps seems to use 253 for the background colour)
01106         for (i=0; i<256; i++)
01107         {
01108             Palette[i].rgbBlue  = ((i < 253) ? 0 : 255);
01109             Palette[i].rgbGreen = ((i < 253) ? 0 : 255);
01110             Palette[i].rgbRed   = ((i < 253) ? 0 : 255);
01111         }
01112 
01113 // ****** End of Bodge *******
01114 
01115         // Render the bitmap into the MaskRegion to create the 1bpp mask
01116         pMaskRegion->StartRender();
01117         pMaskRegion->DrawBitmap(DocCoord(0,0), TheBitmap);
01118         pMaskRegion->StopRender();
01119 
01120         // Restore the Proper Palatte values, so the bitmap can be
01121         // rendered properly
01122         for (i=0; i<256; i++)
01123         {
01124             Palette[i] = OldPalette[i];
01125         }
01126 
01127         // Get the 1bpp Mask bitmap out of the Render Region
01128         OILBitmap* pOilMaskBmp = pMaskRegion->ExtractBitmap();
01129         DragMask = new KernelBitmap(pOilMaskBmp, TRUE); 
01130 
01131         // Tidy up
01132         delete pMaskRegion;
01133         delete pDisplayDC;
01134     }
01135 
01136     return DragMask;
01137 }
01138 #endif

Generated on Sat Nov 10 03:48:52 2007 for Camelot by  doxygen 1.4.4