00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
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
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
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
00148
00149
00150
00151
00152
00153
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
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191 void CBGDDWxBitmapItem::DrawItem(wxDC& dc, const wxRect& rect, INT32 iFlags) const
00192 {
00193
00194
00195 if (iFlags & wxGridComboPopup::keDisabled)
00196 return;
00197
00198
00199
00200
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
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
00234
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
00272
00273
00274
00275
00276
00277
00278
00279
00280 BOOL CBGDDCachedItem::DoesCacheItemSizeMatch(const pair<wxSize, wxBitmap*>* poItem, wxSize szBitmap)
00281 {
00282 return poItem->first == szBitmap;
00283 }
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295 wxBitmap* CBGDDCachedItem::GetWxBitmap(wxSize szBitmap) const
00296 {
00297
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
00305 wxBitmap* pBitmap = RenderItemToBitmap(szBitmap);
00306
00307
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
00318 dc.DrawBitmap(*pBitmap, rcDraw.x, rcDraw.y, FALSE);
00319 }
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
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
00342 DialogView *pDialogView = new DialogView;
00343 pDialogView->Init();
00344 FIXED16 Scale(1);
00345
00346 Matrix oMatrix(1, 0, 0, 1, 0, 0);
00347
00348
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
00358 GRenderBitmap* pRenderRegion = new GRenderBitmap(drcDocClip, oMatrix, Scale, 24, iDPI, FALSE, 0, NULL, TRUE);
00359 pRenderRegion->AttachDevice(pDialogView, &dcMem, NULL, false);
00360
00361
00362 pRenderRegion->InitDevice();
00363 pRenderRegion->SaveContext();
00364 pRenderRegion->StartRender();
00365
00366
00367
00368 RenderItemToGRenderRegion(pRenderRegion, drcDocClip);
00369
00370
00371 pRenderRegion->StopRender();
00372 pRenderRegion->RestoreContext();
00373
00374
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
00381 delete pKernelBitmap;
00382 delete pRenderRegion;
00383 delete pDialogView;
00384
00385 dcMem.SelectObject(wxNullBitmap);
00386
00387 return pBitmap;
00388 }
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402 void CBGDDCachedItem::RenderItemToGRenderRegion(GRenderRegion* pRenderRegion, DocRect drcItem) const
00403 {
00404 ASSERT(FALSE);
00405
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
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441 wxBitmap* CBGDDKernelBitmapItem::RenderItemToBitmap(wxSize szBitmap) const
00442 {
00443
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
00484
00485
00486
00487
00488
00489
00490
00491
00492 void CBGDDStrokeItem::RenderItemToGRenderRegion(GRenderRegion* pRenderRegion, DocRect drcItem) const
00493 {
00494
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
00518
00519
00520
00521
00522
00523
00524
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
00536 INT32 iWidth = drcItem.Width();
00537 INT32 iHeight = drcItem.Height();
00538 INT32 iBorderX = (INT32)(0.025 * iWidth);
00539
00540
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
00595
00596
00597
00598
00599
00600
00601
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
00611
00612
00613
00614
00615
00616
00617
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
00627
00628
00629
00630
00631
00632
00633
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
00644
00645
00646
00647
00648
00649
00650
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
00661
00662
00663
00664
00665
00666
00667
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
00678
00679
00680
00681
00682
00683
00684
00685
00686 void CBitmapGridDropDown::SetUnselectedItem(UINT32 uiBitmapResID, String_256 strLabel)
00687 {
00688 m_poUnselectedItem = new CBGDDResourceItem(uiBitmapResID, strLabel);
00689 }
00690
00691
00692
00693
00694
00695
00696
00697
00698
00699
00700
00701
00702 void CBitmapGridDropDown::SetUnselectedItem(wxBitmap* pBitmap, String_256 strLabel)
00703 {
00704 m_poUnselectedItem = new CBGDDWxBitmapItem(pBitmap, TRUE, strLabel);
00705 }
00706
00707
00708
00709
00710
00711
00712
00713
00714
00715
00716
00717
00718
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
00731
00732
00733
00734
00735
00736
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
00748
00749
00750
00751
00752
00753
00754
00755
00756 void CBitmapGridDropDown::SelectByLabel(String_256 strLabel)
00757 {
00758
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
00782
00783
00784
00785
00786
00787
00788
00789 KernelBitmap* CBitmapGridDropDown::PreviewStroke(LineAttrItem* plaiStroke)
00790 {
00791 wxMemoryDC dcMem;
00792
00793
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
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
00821 GRenderBitmap* pRenderRegion = new GRenderBitmap(rcDocClip, oMatrix, Scale, 24, iDPI, FALSE, 0, NULL, TRUE);
00822 pRenderRegion->AttachDevice(pDialogView, &dcMem, NULL, false);
00823
00824
00825 pRenderRegion->InitDevice();
00826 pRenderRegion->SaveContext();
00827 pRenderRegion->StartRender();
00828
00829
00830 plaiStroke->Render(pRenderRegion, rcDocClip, LineAttrItem::NO_LABEL);
00831
00832 pRenderRegion->StopRender();
00833 pRenderRegion->RestoreContext();
00834
00835
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 }