bitmapgriddropdown.cpp

Go to the documentation of this file.
00001 // $Id: coldrop.cpp 1052 2006-05-15 14:19:14Z 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 
00099 // coldrop.cpp - Colour drop-down list support
00100 
00101 /*
00102 */
00103 
00104 
00105 //-----------------------------------------------------------------------------------------
00106 // Include files
00107 
00108 #include "camtypes.h"
00109 #include "camelot.h"
00110 #include "errors.h"
00111 #include "palman.h"
00112 #include "cartprov.h"
00113 #include "bitmapgriddropdown.h"
00114 #include "dragbmp.h"
00115 //#include <wx/dcmemory.h>
00116 #include "grndbmp.h"
00117 #include "colcontx.h"
00118 
00119 #include "sgline.h"
00120 #include "ccdc.h"
00121 #include "dlgview.h"
00122 #include "grnddib.h"
00123 #include "ppbrush.h"
00124 #include "qualattr.h"
00125 
00126 
00127 
00128 
00129 //-----------------------------------------------------------------------------------------
00130 // This must be defined AFTER all CC_IMPLEMENT_DYNCREATE calls
00131 #define new CAM_DEBUG_NEW
00132 
00133 
00134 CBGDDItemInfo::CBGDDItemInfo(String_256 strLabel)
00135 {
00136     m_strLabel = strLabel;
00137 }
00138 
00139 
00140 CBGDDItemInfo::~CBGDDItemInfo()
00141 {
00142 }
00143 
00144 
00145 
00146 /******************************************************************************
00147 Function  : CBGDDItemInfo::GetLabel
00148 Author    : Mikhail Tatarnikov
00149 Purpose   : Gets the text assocciated with the item.
00150 Returns   : String_256 - the item label.
00151 Exceptions: 
00152 Parameters: None
00153 Notes     : 
00154 ******************************************************************************/
00155 String_256 CBGDDItemInfo::GetLabel()
00156 {
00157     return m_strLabel;
00158 }
00159 
00160 
00161 
00162 
00163 CBGDDWxBitmapItem::CBGDDWxBitmapItem(wxBitmap* pBitmap, BOOL bAutodelete,
00164                                      String_256 strLabel,
00165                                      BOOL bStretch)
00166     : CBGDDItemInfo(strLabel)
00167 {
00168     m_pBitmap  = pBitmap;
00169     m_bDelete  = bAutodelete;
00170     m_bStretch = bStretch;
00171 }
00172 
00173 CBGDDWxBitmapItem::~CBGDDWxBitmapItem()
00174 {
00175     if (m_bDelete)
00176         delete m_pBitmap;
00177 }
00178 
00179 
00180 /******************************************************************************
00181 Function  : CBGDDWxBitmapItem::DrawItem
00182 Author    : Mikhail Tatarnikov
00183 Purpose   : Draws this item into dc
00184 Returns   : void
00185 Exceptions: 
00186 Parameters: [in] wxDC&         dc     - device context to draw to;
00187             [in] const wxRect& rect   - area occupied by the item;
00188             [in] INT32         iFlags - drawing parameters.
00189 Notes     : 
00190 ******************************************************************************/
00191 void CBGDDWxBitmapItem::DrawItem(wxDC& dc, const wxRect& rect, INT32 iFlags) const
00192 {
00193     // If the item isn't enabled just don't draw it
00194     // TODO: grey out the current bitmap instead.
00195     if (iFlags & wxGridComboPopup::keDisabled)
00196         return;
00197 
00198 
00199     // Draw to the memory bitmap first (so we can be sure the borders
00200     // isn't eated by the scaling.
00201     wxMemoryDC dcMem;
00202     wxBitmap oMemBitmap(rect.width, rect.height);
00203     dcMem.SelectObject(oMemBitmap);
00204 
00205 
00206     static wxPen   penBackground(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE));
00207     static wxBrush brBackground(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE));
00208 
00209     // Erase with background (by default it's grey).
00210     dcMem.SetPen(penBackground);
00211     dcMem.SetBrush(brBackground);
00212 
00213     dcMem.DrawRectangle(0, 0, rect.width, rect.height);
00214 
00215     double dXScale = 1.0;
00216     double dYScale = 1.0;
00217 
00218     if (m_bStretch)
00219     {
00220         dXScale = (double)rect.width  / (double)m_pBitmap->GetWidth();
00221         dYScale = (double)rect.height / (double)m_pBitmap->GetHeight();
00222     }
00223 
00224     dcMem.SetUserScale(dXScale, dYScale);
00225 
00226     dcMem.DrawBitmap(*m_pBitmap, 0, 0, TRUE);
00227 
00228 
00229     dcMem.SetBrush(wxNullBrush);
00230     dcMem.SetPen(wxNullPen);
00231     dcMem.SelectObject(wxNullBitmap);
00232     
00233     // Now we can draw bitmap without scaling - it has been scaled while
00234     // drawing to the memory DC.
00235     dc.SetUserScale(1.0, 1.0);
00236     dc.DrawBitmap(oMemBitmap, rect.x, rect.y, false);
00237 }
00238 
00239 
00240 CBGDDResourceItem::CBGDDResourceItem(UINT32 uiBitmapResID, String_256 strLabel, BOOL bStretch)
00241     : CBGDDWxBitmapItem(NULL, FALSE, strLabel, bStretch)
00242 {
00243     m_pBitmap = CamArtProvider::Get()->FindBitmap(uiBitmapResID, CAF_DEFAULT);
00244     m_bDelete = FALSE;
00245 }
00246 
00247 CBGDDResourceItem::~CBGDDResourceItem()
00248 {
00249 }
00250 
00251 
00252 
00253 CBGDDCachedItem::CBGDDCachedItem(String_256 strLabel)
00254     : CBGDDItemInfo(strLabel)
00255 {
00256 }
00257 
00258 CBGDDCachedItem::~CBGDDCachedItem()
00259 {
00260     TDCacheCollection::const_iterator citCur;
00261     for (citCur = m_colCache.begin(); citCur != m_colCache.end(); ++citCur)
00262     {
00263         delete (*citCur)->second;
00264         delete *citCur;
00265     }
00266     
00267     m_colCache.clear();
00268 }
00269 
00270 /******************************************************************************
00271 Function  : CBGDDCachedItem::DoesCacheItemSizeMatch
00272 Author    : Mikhail Tatarnikov
00273 Purpose   : Checks whether a cache item corresponds to the specific size
00274 Returns   : BOOL -
00275 Exceptions: 
00276 Parameters: [in] const pair<wxSize, xBitmap*>* poItem - 
00277             [in] wxSize szBitmap - 
00278 Notes     : 
00279 ******************************************************************************/
00280 BOOL CBGDDCachedItem::DoesCacheItemSizeMatch(const pair<wxSize, wxBitmap*>* poItem, wxSize szBitmap)
00281 {
00282     return poItem->first == szBitmap;
00283 }
00284 
00285 
00286 /******************************************************************************
00287 Function  : CBGDDCachedItem::GetWxBitmap
00288 Author    : Mikhail Tatarnikov
00289 Purpose   : Retrieves a representation from the cache
00290 Returns   : wxBitmap* - the representation with the required size.
00291 Exceptions: 
00292 Parameters: [in] wxSize szBitmap - cached image size to look for.
00293 Notes     : Creates a new representation if it doesn't exist.
00294 ******************************************************************************/
00295 wxBitmap* CBGDDCachedItem::GetWxBitmap(wxSize szBitmap) const
00296 {
00297     // Try to locate the cache.
00298     TDCacheCollection::const_iterator citFound = find_if(m_colCache.begin(), m_colCache.end(),
00299         bind2nd(ptr_fun(DoesCacheItemSizeMatch), szBitmap));
00300 
00301     if (citFound != m_colCache.end())
00302         return (*citFound)->second;
00303 
00304     // No bitmap found in the cache. Ask the derivide class to render its content.
00305     wxBitmap* pBitmap = RenderItemToBitmap(szBitmap);
00306 
00307     // Now we have a resulting bitmap. We need to cache and return it.
00308     m_colCache.push_back(new pair<wxSize, wxBitmap*>(szBitmap, pBitmap));
00309 
00310     return pBitmap;
00311 }
00312 
00313 void CBGDDCachedItem::DrawItem(wxDC& dc, const wxRect& rcDraw, INT32 iFlags) const
00314 {
00315     wxBitmap* pBitmap = GetWxBitmap(rcDraw.GetSize());
00316 
00317     // We don't need to scale or do anything since we already have a bitmap of the right size.
00318     dc.DrawBitmap(*pBitmap, rcDraw.x, rcDraw.y, FALSE);
00319 }
00320 
00321 
00322 /******************************************************************************
00323 Function  : CBGDDCachedItem::RenderItemToBitmap
00324 Author    : Mikhail Tatarnikov
00325 Purpose   : Renders an item to bitmap.
00326 Returns   : wxBitmap* - bitmap with the rendered item.
00327 Exceptions: 
00328 Parameters: [in] wxSize szBitmap - size of the required bitmap.
00329 Notes     : The function prepares a GRenderRegion and asks the derived class to
00330             draw itself into it.
00331 ******************************************************************************/
00332 wxBitmap* CBGDDCachedItem::RenderItemToBitmap(wxSize szBitmap) const
00333 {
00334     wxMemoryDC dcMem;
00335     wxBitmap* pBitmap = new wxBitmap(szBitmap.x, szBitmap.y);
00336     dcMem.SelectObject(*pBitmap);
00337 
00338 
00339     INT32 iDPI = 96;
00340 
00341     // Since we don't have a view, we need a fake one.
00342     DialogView *pDialogView = new DialogView;
00343     pDialogView->Init();
00344     FIXED16 Scale(1);
00345 
00346     Matrix oMatrix(1, 0, 0, 1, 0, 0);
00347 
00348     // Convert the item area to millipoints
00349     DocRect drcDocClip;
00350     drcDocClip.lo.x = 0;
00351     drcDocClip.lo.y = 0;
00352 
00353     drcDocClip.hi.x = (szBitmap.x * 1000);
00354     drcDocClip.hi.y = (szBitmap.y * 1000);
00355 
00356 
00357     // Create a bitmap render region.
00358     GRenderBitmap* pRenderRegion = new GRenderBitmap(drcDocClip, oMatrix, Scale, 24, iDPI, FALSE, 0, NULL, TRUE);
00359     pRenderRegion->AttachDevice(pDialogView, &dcMem, NULL, false);
00360     
00361     // Prepare for the rendering.
00362     pRenderRegion->InitDevice();
00363     pRenderRegion->SaveContext();
00364     pRenderRegion->StartRender();
00365 
00366 
00367     // Ask the derived class to render itself into GRenderRegion.
00368     RenderItemToGRenderRegion(pRenderRegion, drcDocClip);
00369 
00370     // Finalize the rendering.
00371     pRenderRegion->StopRender();
00372     pRenderRegion->RestoreContext();
00373 
00374     // Extract bitmap from the render region. 
00375     KernelBitmap* pKernelBitmap = new KernelBitmap(pRenderRegion->ExtractBitmap(), FALSE);
00376 
00377     BitmapDragInformation oDragBitmap(pKernelBitmap, szBitmap.x, szBitmap.y, 0, 0);
00378     oDragBitmap.OnDrawSolidDrag(wxPoint(0, 0), &dcMem);
00379 
00380     // Free resourced and return the resulting bitmap.
00381     delete pKernelBitmap;
00382     delete pRenderRegion;
00383     delete pDialogView;
00384 
00385     dcMem.SelectObject(wxNullBitmap);
00386 
00387     return pBitmap;
00388 }
00389 
00390 
00391 /******************************************************************************
00392 Function  : CBGDDCachedItem::RenderItemToGRenderRegion
00393 Author    : Mikhail Tatarnikov
00394 Purpose   : Renders the item into GRenderRegion.
00395 Returns   : void
00396 Exceptions: 
00397 Parameters: [in] GRenderRegion* pRenderRegion - Render region to draw to;
00398             [in] DocRect        drcItem       - item size.
00399 Notes     : The derived classes should override this function if they don't
00400             override RenderItemToBitmap.
00401 ******************************************************************************/
00402 void CBGDDCachedItem::RenderItemToGRenderRegion(GRenderRegion* pRenderRegion, DocRect drcItem) const
00403 {
00404     ASSERT(FALSE);  // The derived classes should override this method
00405                     // Or the parent RenderItemToBitmap method.
00406 }
00407 
00408 
00409 
00410 
00411 
00412 
00413 CBGDDKernelBitmapItem::CBGDDKernelBitmapItem(KernelBitmap* pKernelBitmap, BOOL bAutodelete,
00414                                              String_256 strLabel, BOOL bStretch)
00415     : CBGDDCachedItem(strLabel)
00416 {
00417     m_pKernelBitmap       = pKernelBitmap;
00418     m_bDeleteKernelBitmap = bAutodelete;
00419     m_bStretch            = bStretch;
00420 }
00421 
00422 CBGDDKernelBitmapItem::~CBGDDKernelBitmapItem()
00423 {
00424     if (m_bDeleteKernelBitmap)
00425         delete m_pKernelBitmap;
00426 }
00427 
00428 
00429 
00430 /******************************************************************************
00431 Function  : CBGDDKernelBitmapItem::GetWxBitmap
00432 Author    : Mikhail Tatarnikov
00433 Purpose   : Gets the wxBitmap representation of the currently stored KernelBitmap
00434 Returns   : wxBitmap* - the required version of the KernelBitmap.
00435 Exceptions: 
00436 Parameters: [in] wxSize szBitmap - the size of representation.
00437 Notes     : Since the KernelBitmap stored in the item can be of considerable size,
00438             we have to speed up the drawing (and scaling). It's done by caching
00439             the bitmap representations.
00440 ******************************************************************************/
00441 wxBitmap* CBGDDKernelBitmapItem::RenderItemToBitmap(wxSize szBitmap) const
00442 {
00443     // NOTE: the maximum size of bitmap allowed by BitmapDragInformation is 180*??? pixels!!
00444     wxMemoryDC dcMem;
00445     wxBitmap* pBitmap = new wxBitmap(szBitmap.x, szBitmap.y);
00446     dcMem.SelectObject(*pBitmap);
00447     dcMem.SetUserScale(1.0, 1.0);
00448 
00449     wxSize szDragBitmap = szBitmap;
00450     if (!m_bStretch)
00451         szDragBitmap = wxSize(m_pKernelBitmap->GetWidth(), m_pKernelBitmap->GetHeight());
00452 
00453     BitmapDragInformation oDragBitmap(m_pKernelBitmap, szDragBitmap.x, szDragBitmap.y, 0, 0);
00454     oDragBitmap.OnDrawSolidDrag(wxPoint(0, 0), &dcMem);
00455 
00456     dcMem.SelectObject(wxNullBitmap);
00457 
00458     return pBitmap;
00459 }
00460 
00461 
00462 
00463 
00464 
00465 
00466 
00467 
00468 CBGDDStrokeItem::CBGDDStrokeItem(LineAttrItem* plaiStroke, BOOL bAutodelete, String_256 strLabel)
00469     : CBGDDCachedItem(strLabel)
00470 {
00471     m_plaiStroke = plaiStroke;
00472     m_bDelete    = bAutodelete;
00473 }
00474 
00475 CBGDDStrokeItem::~CBGDDStrokeItem()
00476 {
00477     if (m_bDelete)
00478         delete m_plaiStroke;
00479 }
00480 
00481 
00482 /******************************************************************************
00483 Function  : CBGDDStrokeItem::RenderItemToGRenderRegion
00484 Author    : Mikhail Tatarnikov
00485 Purpose   : Renders the stroke into GRenderRegion.
00486 Returns   : void
00487 Exceptions: 
00488 Parameters: [in] GRenderRegion* pRenderRegion - Render region to draw to;
00489             [in] DocRect        drcItem       - item size.
00490 Notes     : 
00491 ******************************************************************************/
00492 void CBGDDStrokeItem::RenderItemToGRenderRegion(GRenderRegion* pRenderRegion, DocRect drcItem) const
00493 {
00494     // Render the stroke.
00495     m_plaiStroke->Render(pRenderRegion, drcItem, LineAttrItem::NO_LABEL);
00496 }
00497 
00498 
00499 
00500 
00501 
00502 CBGDDBrushItem::CBGDDBrushItem(AttrBrushType* pabtBrush, BOOL bAutodelete, String_256 strLabel)
00503     : CBGDDCachedItem(strLabel)
00504 {
00505     m_pabtBrush  = pabtBrush;
00506     m_bDelete    = bAutodelete;
00507 }
00508 
00509 CBGDDBrushItem::~CBGDDBrushItem()
00510 {
00511     if (m_bDelete)
00512         delete m_pabtBrush;
00513 }
00514 
00515 
00516 /******************************************************************************
00517 Function  : CBGDDBrushItem::RenderItemToGRenderRegion
00518 Author    : Mikhail Tatarnikov
00519 Purpose   : Renders the brush into GRenderRegion.
00520 Returns   : void
00521 Exceptions: 
00522 Parameters: [in] GRenderRegion* pRenderRegion - Render region to draw to;
00523             [in] DocRect        drcItem       - item size.
00524 Notes     : 
00525 ******************************************************************************/
00526 void CBGDDBrushItem::RenderItemToGRenderRegion(GRenderRegion* pRenderRegion, DocRect drcItem) const
00527 {
00528     Path  pthBrush;
00529 
00530     pthBrush.Initialise(8);
00531     pthBrush.IsFilled  =  FALSE;
00532     pthBrush.IsStroked = TRUE;
00533     pthBrush.FindStartOfPath();
00534 
00535     // avoid overhead of allocation each time ....
00536     INT32 iWidth      = drcItem.Width();
00537     INT32 iHeight     = drcItem.Height();
00538     INT32 iBorderX    = (INT32)(0.025 * iWidth);
00539 //  INT32 iBorderY    = (INT32)(0.025 * iHeight);
00540 //  INT32 iHalfWidth  = iWidth  / 2;
00541     INT32 iHalfHeight = iHeight / 2;
00542 
00543     DocCoord dcrdStartPoint(iBorderX, iHalfHeight);
00544     DocCoord dcrdEndPoint(iWidth - iBorderX, iHalfHeight);
00545 
00546     pthBrush.InsertMoveTo(dcrdStartPoint);
00547     pthBrush.InsertLineTo(dcrdEndPoint);
00548 
00549 
00550     pRenderRegion->SetLineWidth(iHeight / 3);
00551 
00552     PathProcessorBrush* pPathProc = m_pabtBrush->GetPathProcessor();
00553     pPathProc->ScaleToValue(1);
00554     pRenderRegion->SetLineColour(COLOUR_BLACK);
00555 
00556     m_pabtBrush->Render(pRenderRegion);
00557     pRenderRegion->DrawPath (&pthBrush);
00558 }
00559 
00560 
00561 
00562 
00563 
00564 
00565 
00566 
00567 
00568 
00569 
00570 
00571 
00572 
00573 
00574 
00575 
00576 
00577 
00578 
00579 
00580 
00581 CBitmapGridDropDown::CBitmapGridDropDown()
00582 {
00583     m_poUnselectedItem  = NULL;
00584 }
00585 
00586 
00587 
00588 CBitmapGridDropDown::~CBitmapGridDropDown()
00589 {
00590 }
00591 
00592 
00593 /******************************************************************************
00594 Function  : CBitmapGridDropDown::AddItem
00595 Author    : Mikhail Tatarnikov
00596 Purpose   : Adds an item with an image from a resource
00597 Returns   : void
00598 Exceptions: 
00599 Parameters: [in] UINT32     uiBitmapResID - resource id with the image;
00600             [in] String_256 strLabel      - label for the item.
00601 Notes     : 
00602 ******************************************************************************/
00603 void CBitmapGridDropDown::AddItem(UINT32 uiBitmapResID, String_256 strLabel, BOOL bStretch)
00604 {
00605     CBGDDItemInfo* pData = new CBGDDResourceItem(uiBitmapResID, strLabel, bStretch);
00606     CGridDropDown::AddItem(pData);
00607 }
00608 
00609 /******************************************************************************
00610 Function  : CBitmapGridDropDown::AddItem
00611 Author    : Mikhail Tatarnikov
00612 Purpose   : Adds an item with an image
00613 Returns   : void
00614 Exceptions: 
00615 Parameters: [in] wxBitmap*  pBitmap  - the bitmap to be shown for the item;
00616             [in] String_256 strLabel - the item label.
00617 Notes     : 
00618 ******************************************************************************/
00619 void CBitmapGridDropDown::AddItem(wxBitmap* pBitmap, BOOL bDelete, String_256 strLabel, BOOL bStretch)
00620 {
00621     CBGDDItemInfo* pData = new CBGDDWxBitmapItem(pBitmap, bDelete, strLabel, bStretch);
00622     CGridDropDown::AddItem(pData);
00623 }
00624 
00625 /******************************************************************************
00626 Function  : CBitmapGridDropDown::AddItem
00627 Author    : Mikhail Tatarnikov
00628 Purpose   : Adds an item with a kernel bitmap
00629 Returns   : void
00630 Exceptions: 
00631 Parameters: [in] KernelBitmap* pKernelBitmap - the bitmap to be shown for the item;
00632             [in] String_256    strLabel      - the item label.
00633 Notes     : 
00634 ******************************************************************************/
00635 void CBitmapGridDropDown::AddItem(KernelBitmap* pKernelBitmap, BOOL bDelete, String_256 strLabel, BOOL bStretch)
00636 {
00637     CBGDDItemInfo* pData = new CBGDDKernelBitmapItem(pKernelBitmap, bDelete, strLabel, bStretch);
00638     CGridDropDown::AddItem(pData);
00639 }
00640 
00641 
00642 /******************************************************************************
00643 Function  : CBitmapGridDropDown::AddItem
00644 Author    : Mikhail Tatarnikov
00645 Purpose   : Adds an item and display a stroke in it.
00646 Returns   : void
00647 Exceptions: 
00648 Parameters: [in] LineAttrItem* plaiStroke - the stroke to display in the item;
00649             [in] String_256    strLabel   - the item label.
00650 Notes     : 
00651 ******************************************************************************/
00652 void CBitmapGridDropDown::AddItem(LineAttrItem* plaiStroke, BOOL bDelete, String_256 strLabel)
00653 {
00654     CBGDDStrokeItem* pStrokeItem = new CBGDDStrokeItem(plaiStroke, bDelete, strLabel);
00655     CGridDropDown::AddItem(pStrokeItem);
00656 }
00657 
00658 
00659 /******************************************************************************
00660 Function  : CBitmapGridDropDown::AddItem
00661 Author    : Mikhail Tatarnikov
00662 Purpose   : Adds an item and display a brush in it.
00663 Returns   : void
00664 Exceptions: 
00665 Parameters: [in] AttrBrushType* pabtBrush - the brush to be previewed in the item;
00666             [in] String_256     strLabel  - the item label.
00667 Notes     : 
00668 ******************************************************************************/
00669 void CBitmapGridDropDown::AddItem(AttrBrushType* pabtBrush, BOOL bDelete, String_256 strLabel)
00670 {
00671     CBGDDBrushItem* pBrushItem = new CBGDDBrushItem(pabtBrush, bDelete, strLabel);
00672     CGridDropDown::AddItem(pBrushItem);
00673 }
00674 
00675 
00676 /******************************************************************************
00677 Function  : CBitmapGridDropDown::SetUnselectedItem
00678 Author    : Mikhail Tatarnikov
00679 Purpose   : Sets an image to be used as "unselected" item
00680 Returns   : void
00681 Exceptions: 
00682 Parameters: [in] UINT32     uiBitmapResID - resource id with the image;
00683             [in] String_256 strLabel      - label for the item.
00684 Notes     : 
00685 ******************************************************************************/
00686 void CBitmapGridDropDown::SetUnselectedItem(UINT32 uiBitmapResID, String_256 strLabel)
00687 {
00688     m_poUnselectedItem = new CBGDDResourceItem(uiBitmapResID, strLabel);
00689 }
00690 
00691 
00692 /******************************************************************************
00693 Function  : CBitmapGridDropDown::SetUnselectedItem
00694 Author    : Mikhail Tatarnikov
00695 Purpose   : Sets an image to be used as "unselected" item
00696 Returns   : void
00697 Exceptions: 
00698 Parameters: [in] wxBitmap*  pBitmap  - the bitmap to be shown for the "unselected" item;
00699             [in] String_256 strLabel - the item label.
00700 Notes     : 
00701 ******************************************************************************/
00702 void CBitmapGridDropDown::SetUnselectedItem(wxBitmap* pBitmap, String_256 strLabel)
00703 {
00704     m_poUnselectedItem = new CBGDDWxBitmapItem(pBitmap, TRUE, strLabel);
00705 }
00706 
00707 
00708 /******************************************************************************
00709 Function  : CBitmapGridDropDown::DrawItemCore
00710 Author    : Mikhail Tatarnikov
00711 Purpose   : Draws the item core - the image itself
00712 Returns   : void
00713 Exceptions: 
00714 Parameters: [in] wxDC&   dc     - the device context to draw to;
00715             [in] wxRect& rect   - the area of the item;
00716             [in] INT32   iItem  - item index;
00717             [in] INT32   iFlags - additional flags (selected, highlighted, ...)
00718 Notes     : 
00719 ******************************************************************************/
00720 void CBitmapGridDropDown::DrawItemCore(wxDC& dc, const wxRect& rect, INT32 iItem, INT32 iFlags)
00721 {
00722     CBGDDItemInfo* pItemData = GetItemData(iItem);
00723 
00724     if (pItemData)
00725         pItemData->DrawItem(dc, rect, iFlags);
00726 }
00727 
00728 
00729 /******************************************************************************
00730 Function  : CBitmapGridDropDown::GetItemData
00731 Author    : Mikhail Tatarnikov
00732 Purpose   : Gets the item data
00733 Returns   : CBGDDItemInfo* - the user data associated with the item;
00734 Exceptions: 
00735 Parameters: [in] INT32 iItem - the item index;
00736 Notes     : 
00737 ******************************************************************************/
00738 CBGDDItemInfo* CBitmapGridDropDown::GetItemData(INT32 iItem)
00739 {
00740     if (iItem == -1)
00741         return m_poUnselectedItem;
00742 
00743     return (CBGDDItemInfo*)CGridDropDown::GetItemData(iItem);
00744 }
00745 
00746 /******************************************************************************
00747 Function  : CBitmapGridDropDown::SelectByLabel
00748 Author    : Mikhail Tatarnikov
00749 Purpose   : Selects the element by label.
00750 Returns   : void
00751 Exceptions: 
00752 Parameters: [in] String_256 strLabel - the label of the existing item to select;
00753 Notes     : If several items with the same label exist, the first one is to be selected.
00754             If no item's label match, the combobox is unselected.
00755 ******************************************************************************/
00756 void CBitmapGridDropDown::SelectByLabel(String_256 strLabel)
00757 {
00758     // Walk over all items, looking for the first exact match.
00759     INT32 iSelectedIndex = -1;
00760     INT32 iItemsNum = GetItemsNum();
00761     for (INT32 i = 0; i < iItemsNum; ++i)
00762     {
00763         CBGDDItemInfo* pData = GetItemData(i);
00764         
00765         if (pData->GetLabel() == strLabel)
00766         {
00767             iSelectedIndex = i;
00768             break;
00769         }
00770         
00771     }
00772     
00773     SetSelected(iSelectedIndex);
00774 }
00775 
00776 
00777 
00778 
00779 
00780 /******************************************************************************
00781 Function  : CBitmapGridDropDown::PreviewStroke
00782 Author    : Mikhail Tatarnikov
00783 Purpose   : Preview a stroke into a bitmap
00784 Returns   : KernelBitmap* - the stroke preview.
00785 Exceptions: 
00786 Parameters: [in] LineAttrItem* plaiStroke - stroke to render.
00787 Notes     : 
00788 ******************************************************************************/
00789 KernelBitmap* CBitmapGridDropDown::PreviewStroke(LineAttrItem* plaiStroke)
00790 {
00791     wxMemoryDC dcMem;
00792 
00793     // Setup a memory DC to draw into a bitmap.
00794     wxSize szItem =  GetItemSize();
00795     wxBitmap* pBitmap = new wxBitmap(szItem.x, szItem.y);
00796     dcMem.SelectObject(*pBitmap);
00797 
00798     dcMem.SetTextForeground(wxColour(0, 0, 0));
00799 
00800     INT32 iDPI = 96;
00801 
00802     DialogView *pDialogView = new DialogView;
00803     pDialogView->Init();
00804     FIXED16 Scale(1);
00805 
00806     Matrix oMatrix(1, 0, 0, 1, 0, 0);
00807 
00808 
00809 
00810 
00811     DocRect rcDocClip;
00812     // Convert the item area to millipoints
00813     rcDocClip.lo.x = 0;
00814     rcDocClip.lo.y = 0;
00815 
00816     rcDocClip.hi.x = (szItem.x * 1000);
00817     rcDocClip.hi.y = (szItem.y * 1000);
00818 
00819 
00820     // Create a bitmap render region.
00821     GRenderBitmap* pRenderRegion = new GRenderBitmap(rcDocClip, oMatrix, Scale, 24, iDPI, FALSE, 0, NULL, TRUE);
00822     pRenderRegion->AttachDevice(pDialogView, &dcMem, NULL, false);
00823 
00824     // Prepare for the rendering.
00825     pRenderRegion->InitDevice();
00826     pRenderRegion->SaveContext();
00827     pRenderRegion->StartRender();
00828 
00829     // Render the stroke.
00830     plaiStroke->Render(pRenderRegion, rcDocClip, LineAttrItem::NO_LABEL);
00831 
00832     pRenderRegion->StopRender();
00833     pRenderRegion->RestoreContext();
00834 
00835     // WinBM Now needs to be setup with the newly created bitmap
00836     KernelBitmap* pKernelBitmap = new KernelBitmap(pRenderRegion->ExtractBitmapCopy(), TRUE);
00837 
00838 
00839     delete pRenderRegion;
00840     delete pDialogView;
00841 
00842     dcMem.SelectObject(wxNullBitmap);
00843     delete pBitmap;
00844 
00845     return pKernelBitmap;
00846 }

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