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 #include "camtypes.h"
00105 #include "grndbrsh.h"
00106 #include "grnddib.h"
00107 #include "grndrgn.h"
00108
00109 #include "osrndrgn.h"
00110
00111 #include "palman.h"
00112
00113
00114
00115 #include "progress.h"
00116 #include "freehand.h"
00117 #include "freeinfo.h"
00118
00119 #include "offscrn.h"
00120
00121 #include "oilruler.h"
00122
00123 static RealLogPalette StandardPalette =
00124 {
00125 0x300,
00126 256
00127 };
00128
00129 static BYTE NoTransTable[256];
00130
00131 static BOOL ClippedPathIsValid;
00132
00133
00134
00135
00136
00137 static INT32 LargeGradTables = 0;
00138
00139
00140 #define FILL_BITMAP 0
00141
00142 CC_IMPLEMENT_DYNAMIC( GRenderBrush, GRenderDIB )
00143
00144 #define new CAM_DEBUG_NEW
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163 GRenderBrush::GRenderBrush(DocRect ClipRegion, Matrix ConvertMatrix, FIXED16 ViewScale, UINT32 Depth, double dpi)
00164 : GRenderDIB( ClipRegion, ConvertMatrix, ViewScale, Depth, dpi)
00165 {
00166 lpPreConvertBrushBitmapInfo = NULL;
00167 lpPostConvertBrushBitmapInfo = NULL;
00168 lpPreConvertBrushBits = NULL;
00169 lpPostConvertBrushBits = NULL;
00170 lpBrushBitmapInfo = NULL;
00171 lpBrushBits = NULL;
00172 m_pPalette = NULL;
00173
00174
00175 m_pView = NULL;
00176 m_pCCamView = NULL;
00177 PORTNOTE("other", "Disable HDC stuff")
00178 #ifndef EXCLUDE_FROM_XARALX
00179 m_pDevContext = NULL;
00180 m_DeviceHdc = NULL;
00181 #endif
00182
00183 }
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201 GRenderBrush::~GRenderBrush()
00202 {
00203 if (lpPreConvertBrushBitmapInfo != NULL && lpPreConvertBrushBits != NULL)
00204 FreeLPBits(lpPreConvertBrushBitmapInfo, lpPreConvertBrushBits);
00205
00206
00207 if (lpPostConvertBrushBitmapInfo != NULL && lpPostConvertBrushBits != NULL)
00208 FreeLPBits(lpPostConvertBrushBitmapInfo, lpPostConvertBrushBits);
00209
00210
00211 if (lpBrushBitmapInfo != NULL && lpBrushBits != NULL)
00212 FreeLPBits(lpBrushBitmapInfo, lpBrushBits);
00213
00214 if (pBits != NULL && pBitmapInfo != NULL)
00215 {
00216 FreeLPBits( pBitmapInfo, pBits );
00217 SetBitmapPointers(NULL, NULL);
00218 }
00219 TRACEUSER( "Gavin", _T("GRenderBrush::~GRenderBrush - RenderFlags.Rendering = FALSE;\n"));
00220 RenderFlags.Rendering = FALSE;
00221
00222 }
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239 void GRenderBrush::DrawToScreenNow()
00240 {
00241
00242
00243
00244 INT32 DestX = WRect.GetLeft();
00245 INT32 DestY = WRect.GetTop();
00246 INT32 ViewWidth = WRect.GetWidth();
00247 INT32 ViewHeight= WRect.GetHeight();
00248 INT32 Width = 0;
00249 INT32 Height = 0;
00250 INT32 SourceX = WRect.GetLeft();
00251 INT32 SourceY = WRect.GetTop();
00252
00253
00254 RECT UsedRect;
00255
00256 if (GetDrawContext()->GetChangedBBox( &UsedRect ))
00257 {
00258 if ((UsedRect.right < UsedRect.left) ||
00259 (UsedRect.bottom< UsedRect.top ))
00260 {
00261
00262 return;
00263 }
00264 else
00265 {
00266 View* pView = NULL;
00267 CCamView* pCCamView = NULL;
00268 PORTNOTE("other", "Disable HDC stuff")
00269 #ifndef EXCLUDE_FROM_XARALX
00270 CDC* pDevContext = NULL;
00271 HDC DeviceHdc = NULL;
00272 #endif
00273
00274 if (m_pView)
00275 pView = m_pView;
00276 else
00277 m_pView = View::GetCurrent();
00278
00279 if (m_pCCamView)
00280 pCCamView = m_pCCamView;
00281 else
00282 pCCamView = pView->GetConnectionToOilView();
00283
00284 PORTNOTE("other", "Disable HDC stuff")
00285 #ifndef EXCLUDE_FROM_XARALX
00286 if (m_pDevContext)
00287 pDevContext = m_pDevContext;
00288 else
00289 pDevContext = ((ScreenCamView*)pCCamView)->GetRenderDC();
00290
00291 if (m_DeviceHdc)
00292 DeviceHdc = m_DeviceHdc;
00293 else
00294 DeviceHdc = pDevContext->GetSafeHdc();
00295 #endif
00296
00297 if (ScreenDepth < 24)
00298 {
00299 INT32 OldHeight = -1;
00300 OldHeight = lpPreConvertBrushBitmapInfo->bmiHeader.biHeight;
00301
00302 Width = UsedRect.right - UsedRect.left;
00303 Height = UsedRect.bottom - UsedRect.top;
00304
00305 if (!ClipBrushBitmaps(&UsedRect, &Height))
00306 return;
00307 SourceX = UsedRect.left;
00308 DestX = UsedRect.left;
00309 DestY = UsedRect.top;
00310
00311
00312 SourceY = ViewHeight - UsedRect.bottom;
00313
00314 if (Height > 0)
00315 {
00316
00317 if (!DIBUtil::CopyBitmapSection(pBitmapInfo, pBits,
00318 lpPreConvertBrushBitmapInfo, lpPreConvertBrushBits,
00319 SourceY, SourceX))
00320 {
00321 ERROR3("Failed to copy bitmap section");
00322 return;
00323 }
00324
00325
00326 ConvertBrushBitmap();
00327
00328 if (ScreenDepth == 8)
00329 SetPaletteEntries(lpPostConvertBrushBitmapInfo, RenderDC);
00330
00331
00332
00333 INT32 res = SetDIBitsToDevice( DeviceHdc,
00334 DestX , DestY,
00335 Width,
00336 Height,
00337 0, 0,
00338 0, Height,
00339 lpPostConvertBrushBits,
00340 lpPostConvertBrushBitmapInfo,
00341 DIB_RGB_COLORS);
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355 if (!res)
00356 {
00357 TRACEUSER( "Diccon", _T("SetDIB Failed. DestY = %d, Height = %d\n"), DestY, Height);
00358
00359 DWORD error = GetLastError();
00360 TRACEUSER( "Diccon", _T("Failed to set Bits in DrawToScreen Now, Error %d\n"), error);
00361 }
00362 }
00363 else
00364 TRACEUSER( "Diccon", _T("SetDIB Failed. DestY = %d, Height = %d\n"), DestY, Height);
00365
00366
00367 lpPreConvertBrushBitmapInfo->bmiHeader.biHeight = OldHeight;
00368 lpPostConvertBrushBitmapInfo->bmiHeader.biHeight = OldHeight;
00369 return;
00370 }
00371 else
00372 {
00373
00374 SourceX += UsedRect.left;
00375 DestX += UsedRect.left;
00376 SourceY += UsedRect.top;
00377 DestY += UsedRect.top;
00378
00379 Width = UsedRect.right - UsedRect.left;
00380 Height = UsedRect.bottom - UsedRect.top;
00381
00382 DWORD *rgb = (DWORD *)lpBitmapInfo->bmiColors ;
00383 *rgb++ = 0x00ff0000 ;
00384 *rgb++ = 0x0000ff00 ;
00385 *rgb++ = 0x000000ff ;
00386
00387 CanDoDeepDIBs = TRUE;
00388 const UINT32 TotalHeight = (UINT32)lpBitmapInfo->bmiHeader.biHeight;
00389
00390
00391 const INT32 DIBSourceY = TotalHeight - (Height + SourceY);
00392
00393 INT32 res = SetDIBitsToDevice( DeviceHdc,
00394 DestX, DestY,
00395
00396 Width,
00397 Height,
00398 SourceX, DIBSourceY,
00399 0, TotalHeight,
00400 lpBits,
00401 lpBitmapInfo,
00402 DIB_RGB_COLORS);
00403
00404 if (res == 0)
00405 {
00406 TRACEUSER( "Diccon", _T("SetDIB Failed. DestY = %d, Height = %d\n"), DestY, Height);
00407
00408 DWORD error = GetLastError();
00409 TRACEUSER( "Diccon", _T("Failed to set Bits in DrawToScreen Now, Error %d\n"), error);
00410 }
00411 #if 0
00412 static DWORD startCount = 0;
00413 static INT32 fps = 0;
00414 if (startCount != 0)
00415 {
00416 if ((GetTickCount () - startCount) <= 100)
00417 {
00418 fps++;
00419 }
00420 else
00421 {
00422 TRACEUSER( "ChrisS", _T("%i, "), fps);
00423
00424 startCount = 0;
00425 fps = 0;
00426 }
00427 }
00428 else
00429 {
00430 startCount = GetTickCount ();
00431 }
00432
00433
00434
00435
00436
00437
00438
00439
00440 #endif
00441
00442
00443
00444
00445 }
00446
00447 }
00448 }
00449
00450 }
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467 BOOL GRenderBrush::InitialiseBrushBitmaps(DocRect BrushRect)
00468 {
00469 if (BrushRect.IsEmpty())
00470 {
00471 ERROR3("Rect is empty");
00472 return FALSE;
00473 }
00474
00475 RECT WinRect = OSRenderRegion::DocRectToWin(RenderMatrix, BrushRect, PixelsPerInch);
00476 INT32 Height = WinRect.bottom - WinRect.top;
00477 INT32 Width = WinRect.right - WinRect.left;
00478 INT32 RenderDepth = 32;
00479 INT32 DeviceDepth = ScreenDepth;
00480
00481 return InitialiseBrushBitmaps(Width, Height, RenderDepth, DeviceDepth);
00482 }
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504 BOOL GRenderBrush::InitialiseBrushBitmaps(INT32 Width, INT32 Height, INT32 RenderDepth, INT32 DeviceDepth)
00505 {
00506
00507 if (Width <=0 || Height <= 0)
00508 {
00509 ERROR3("illegal height or width value");
00510 return FALSE;
00511 }
00512
00513
00514
00515
00516 if ((lpPreConvertBrushBits != NULL) && (lpPreConvertBrushBitmapInfo != NULL))
00517 FreeLPBits(lpPreConvertBrushBitmapInfo, lpPreConvertBrushBits);
00518
00519
00520 if ((lpPostConvertBrushBits != NULL) && (lpPostConvertBrushBitmapInfo != NULL))
00521 FreeLPBits(lpPostConvertBrushBitmapInfo, lpPostConvertBrushBits);
00522
00523
00524 lpPreConvertBrushBitmapInfo = GetLPBits(Width, Height, RenderDepth, &lpPreConvertBrushBits);
00525
00526 if (lpPreConvertBrushBitmapInfo == NULL)
00527 {
00528 ERROR3("Unable to allocate pre-convert bitmap");
00529 return FALSE;
00530 }
00531
00532
00533 lpPostConvertBrushBitmapInfo = GetLPBits(Width, Height, DeviceDepth, &lpPostConvertBrushBits);
00534
00535 if (lpPostConvertBrushBitmapInfo == NULL)
00536 {
00537 ERROR3("Unable to allocate post-convert bitmap");
00538 return FALSE;
00539 }
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550
00551 LPRGBQUAD pSourcePalette = &(lpBitmapInfo->bmiColors[0]);
00552 LPRGBQUAD pDestPalette = &(lpPreConvertBrushBitmapInfo->bmiColors[0]);
00553
00554 if (!DIBUtil::CopyPalette(pSourcePalette, pDestPalette, lpBitmapInfo->bmiHeader.biClrUsed))
00555 {
00556 ERROR3("Failed to copy palette");
00557 FreeLPBits(lpPreConvertBrushBitmapInfo, lpPreConvertBrushBits);
00558 FreeLPBits(lpPostConvertBrushBitmapInfo, lpPostConvertBrushBits);
00559 return FALSE;
00560 }
00561
00562 return TRUE;
00563 }
00564
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582
00583 BOOL GRenderBrush::ClipBrushBitmaps(RECT* pUsedRect, INT32* pHeight)
00584 {
00585
00586 INT32 ViewWidth = WRect.right - WRect.left;
00587 INT32 ViewHeight= WRect.bottom - WRect.top;
00588
00589
00590
00591 if (pUsedRect->top >= ViewHeight || pUsedRect->bottom <= 0
00592 || pUsedRect->left >= ViewWidth || pUsedRect->right <= 0)
00593 return FALSE;
00594
00595 INT32 TopAdjust = 0;
00596 INT32 BottomAdjust = 0;
00597
00598 if (pUsedRect->bottom > ViewHeight)
00599 {
00600 BottomAdjust = pUsedRect->bottom - ViewHeight;
00601 pUsedRect->bottom = ViewHeight;
00602 }
00603
00604 if (pUsedRect->top < 0)
00605 {
00606 TopAdjust = pUsedRect->top;
00607 pUsedRect->top = 0;
00608 }
00609
00610 if (pUsedRect->right > ViewWidth)
00611 pUsedRect->right = ViewWidth;
00612 if ( pUsedRect->left < 0)
00613 pUsedRect->left = 0;
00614
00615 INT32 SourceY = ViewHeight - pUsedRect->bottom;
00616
00617
00618 if (SourceY + *pHeight >= ViewHeight)
00619 {
00620
00621
00622
00623 INT32 Adjuster = (ViewHeight - (SourceY+*pHeight));
00624 TRACEUSER( "Diccon", _T("Adjust = %d\n"), Adjuster);
00625 *pHeight += Adjuster;
00626 lpPreConvertBrushBitmapInfo->bmiHeader.biHeight = *pHeight;
00627 lpPostConvertBrushBitmapInfo->bmiHeader.biHeight = *pHeight;
00628
00629
00630 }
00631 else if (TopAdjust != 0)
00632 {
00633 *pHeight -= TopAdjust;
00634 lpPreConvertBrushBitmapInfo->bmiHeader.biHeight = *pHeight;
00635 lpPostConvertBrushBitmapInfo->bmiHeader.biHeight = *pHeight;
00636 }
00637 else if (BottomAdjust != 0)
00638 {
00639 *pHeight -= BottomAdjust;
00640 lpPreConvertBrushBitmapInfo->bmiHeader.biHeight = *pHeight;
00641 lpPostConvertBrushBitmapInfo->bmiHeader.biHeight = *pHeight;
00642 }
00643 return TRUE;
00644 }
00645
00646
00647
00648
00649
00650
00651
00652
00653
00654
00655
00656
00657
00658
00659
00660
00661
00662
00663 BOOL GRenderBrush::PlotBrushIntoBigBitmap(DocRect BrushRect)
00664 {
00665 if (BrushRect.IsEmpty())
00666 {
00667 ERROR3("Brush rect is empty");
00668 return FALSE;
00669 }
00670
00671 if (lpBitmapInfo == NULL || lpBits == NULL
00672 || lpBrushBitmapInfo == NULL || lpBrushBits == NULL)
00673 {
00674 ERROR3("Bitmaps not initialised");
00675 return FALSE;
00676 }
00677
00678 INT32 PixelSize = CalcPixelWidth();
00679
00680
00681 INT32 Width = lpBrushBitmapInfo->bmiHeader.biWidth * PixelSize;
00682 INT32 Height = lpBrushBitmapInfo->bmiHeader.biHeight * PixelSize;
00683
00684 POINT Plot[3];
00685 Plot[0].x = BrushRect.lox; Plot[0].y = BrushRect.loy;
00686 Plot[1].x = BrushRect.lox + Width; Plot[1].y = BrushRect.loy;
00687 Plot[2].x = BrushRect.lox; Plot[2].y = BrushRect.loy + Height;
00688
00689 INT32 Style = 1;
00690 LPRGBQUAD pRGB = &(lpBitmapInfo->bmiColors[0]);
00691 if (!GetDrawContext()->PlotBitmap(&(lpBrushBitmapInfo->bmiHeader), lpBrushBits,
00692 Style, Plot, pRGB, NULL, NULL, NULL,
00693 NoTransTable))
00694 {
00695 ERROR3("Failed to plot bitmap");
00696 return FALSE;
00697 }
00698
00699 return TRUE;
00700 }
00701
00702
00703
00704
00705
00706
00707
00708
00709
00710
00711
00712
00713
00714
00715
00716
00717
00718
00719 BOOL GRenderBrush::ConvertBrushBitmap()
00720 {
00721 if (lpPreConvertBrushBitmapInfo == NULL || lpPreConvertBrushBits == NULL
00722 || lpPostConvertBrushBitmapInfo == NULL || lpPostConvertBrushBits == NULL)
00723 {
00724 ERROR3("Bitmaps not initialised");
00725 return FALSE;
00726 }
00727
00728 GDrawContext *GDC = GetDrawContext();
00729
00730 INT32 ColourFlag = DIB_RGB_COLORS;
00731
00732 INT32 result = GDC->ConvertBitmap(&(lpPreConvertBrushBitmapInfo->bmiHeader), lpPreConvertBrushBits,
00733 &(lpPostConvertBrushBitmapInfo->bmiHeader), lpPostConvertBrushBits, DitherStyle8Bit);
00734
00735
00736 if (ScreenDepth == 8)
00737 ColourFlag = SetPaletteEntries(lpPostConvertBrushBitmapInfo, RenderDC);
00738 else
00739 ColourFlag = DIB_RGB_COLORS;
00740 if (result == -1)
00741 {
00742 ERROR3("Failed to convert bitmap");
00743 return FALSE;
00744 }
00745 return TRUE;
00746
00747 }
00748
00749 BOOL GRenderBrush::TestConvertBitmap()
00750 {
00751 if (lpTestInfo == NULL || lpTestBits == NULL || lpBitmapInfo == NULL || lpBits == NULL)
00752 {
00753 ERROR3("bitmaps not initialised");
00754 return FALSE;
00755 }
00756
00757
00758 GDrawContext *GDC = GetDrawContext();
00759
00760 INT32 ColourFlag = DIB_RGB_COLORS;
00761
00762 INT32 result = GDC->ConvertBitmap(&(lpBitmapInfo->bmiHeader), lpBits, &(lpTestInfo->bmiHeader),
00763 lpTestBits, DitherStyle8Bit);
00764
00765
00766 if (result == -1)
00767 {
00768 ERROR3("Failed to convert bitmap");
00769 return FALSE;
00770 }
00771 return TRUE;
00772
00773 }
00774
00775
00776
00777
00778
00779
00780
00781
00782
00783
00784
00785
00786
00787
00788
00789
00790
00791 void GRenderBrush::SetupMainBitmap()
00792 {
00793 if (lpBitmapInfo == NULL || lpBits == NULL)
00794 {
00795 ERROR3("Bitmaps are unititialised in GRenderBrush::SetupMainBitmap");
00796 return;
00797 }
00798
00799 lpBitmapInfo->bmiHeader.biCompression = 0;
00800 SetupBitmap(lpBitmapInfo, lpBits);
00801 }
00802
00803
00804
00805
00806
00807
00808
00809
00810
00811
00812
00813
00814
00815
00816
00817
00818
00819 void GRenderBrush::SetupBitmap(LPBITMAPINFO pBitmapInfo, LPBYTE pBits)
00820 {
00821 if (pBitmapInfo == NULL || pBits == NULL)
00822 {
00823 ERROR3("invalid parameters passed into GRenderBrush::SetupBitmap");
00824 return;
00825 }
00826
00827
00828
00829
00830
00831
00832
00833
00834 GetDrawContext()->SetBitmap( &pBitmapInfo->bmiHeader, pBits );
00835
00836 if (RenderDC != NULL)
00837 {
00838 if (ScreenDepth == 8)
00839 {
00840
00841 if (PaletteManager::UsePalette())
00842 hPalette = *(PaletteManager::GetPalette());
00843 }
00844
00845 if (hPalette != NULL)
00846 hPrevPalette = PaletteManager::StartPaintPalette(RenderDC->m_hDC);
00847
00848 if (BitmapDepth == 8)
00849 {
00850
00851 if ((DitherStyle8Bit != 0) && (DitherStyle8Bit != 3))
00852 GetDrawContext()->SetDitherStyle((DitherStyle) DitherStyle8Bit);
00853 }
00854
00855 if (ScreenDepth == 8)
00856 {
00857
00858 GRenderRegion::GColInit(RenderDC->m_hDC);
00859 }
00860 }
00861
00862
00863 ResetMatrix();
00864
00865
00866 Spread* pSpread = Document::GetSelectedSpread();
00867 if (pSpread != NULL)
00868 {
00869
00870 DocView* pDocView = DocView::GetCurrent();
00871 DocRect ViewRect = pDocView->GetDocViewRect(pSpread);
00872 pSpread->DocCoordToSpreadCoord(&ViewRect);
00873
00874 RECT WinRect = OSRenderRegion::DocRectToWin(RenderMatrix, ViewRect, PixelsPerInch);
00875 GetDrawContext()->DeviceClipRectangle(&WinRect);
00876 }
00877
00878
00879
00880
00881 SetQualityLevel();
00882 GetDrawContext()->SetHintingFlag(TRUE);
00883
00884 GetDrawContext()->SetDashAdjustmentFlag(FALSE);
00885
00886
00887
00888 POINT DocOrigin, OSOrigin;
00889 DocOrigin.x = 0;
00890 DocOrigin.y = 0;
00891
00892
00893 GetDrawContext()->TransformPath( &DocOrigin, &OSOrigin, 1, &CurrentGMatrix );
00894
00895
00896
00897 const INT32 BrushX = OSOrigin.x >> FX;
00898 const INT32 BrushY = -(OSOrigin.y >> FX);
00899
00900 GetDrawContext()->SetHalftoneOrigin( BrushX, BrushY );
00901
00902 }
00903
00904
00905 BOOL GRenderBrush::MoveWindowToFront()
00906 {
00907
00908
00909 CMainFrame* pMainFrame = GetMainFrame();
00910 ERROR2IF(pMainFrame == NULL, FALSE, "Wheres our mainframe gone!!??");
00911 HWND OurHWnd = pMainFrame->GetSafeHwnd();
00912 SetWindowPos(OurHWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
00913
00914 CWnd* pFirst = pMainFrame->GetWindow(GW_HWNDFIRST);
00915 HWND HWFirst = pFirst->GetSafeHwnd();
00916
00917
00918
00919
00920 CWnd* pNextWnd = pFirst;
00921 UINT32 Counter = 0;
00922 HWND hTaskBar = FindWindow("Shell_TrayWnd", NULL);
00923
00924 CWnd* pLast = pNextWnd;
00925 while (pNextWnd != NULL)
00926 {
00927 pLast = NULL;
00928 if (pNextWnd->GetExStyle() & WS_EX_TOPMOST)
00929 {
00930 if (pNextWnd->IsWindowVisible() && (pNextWnd->GetSafeHwnd() != hTaskBar))
00931 {
00932 Counter++;
00933 pLast = pNextWnd;
00934 }
00935 }
00936
00937 pNextWnd = pNextWnd->GetNextWindow();
00938
00939
00940 }
00941
00942 pMainFrame->SetActiveWindow();
00943 pMainFrame->UpdateWindow();
00944
00945 if (Counter == 0)
00946 return TRUE;
00947
00948 return FALSE;
00949 }
00950
00951
00952 BOOL GRenderBrush::ResetMatrix()
00953 {
00954 View* pView = View::GetCurrent();
00955 Spread* pSpread = Document::GetSelectedSpread();
00956 if (pSpread != NULL)
00957 {
00958 Matrix RenderMat = pView->ConstructRenderingMatrix(pSpread);
00959 GMATRIX GMat;
00960 GMat = MakeGavinMatrix(RenderMat, CurrentClipRect, PixelsPerInch, FALSE);
00961
00962 SetGavinMatrix(&GMat);
00963 }
00964
00965 return TRUE;
00966 }
00967
00968
00969
00970
00971
00972
00973
00974
00975
00976
00977
00978
00979
00980 BOOL GRenderBrush::CaptureView(Spread* pSpread)
00981 {
00982 ERROR3IF(!MasterCaptureIsCurrent() && GetCaptureDepth()>0, "Can't 'CaptureView' while Captures are running");
00983
00984
00985
00986 String_32 ProgString = "Preparing for brush stroke, please wait..";
00987 Progress Prog(&ProgString, -1, FALSE);
00988
00989
00990 BOOL DoCapture = MoveWindowToFront();
00991
00992
00993 if (lpBitmapInfo!=NULL && lpBits != NULL)
00994 {
00995 FreeLPBits(lpBitmapInfo, lpBits);
00996 lpBitmapInfo = NULL;
00997 lpBits = NULL;
00998 }
00999
01000
01001 HDC hDCScreen = CreateDC("DISPLAY", NULL, NULL, NULL);
01002 ScreenDepth = GetDeviceCaps(hDCScreen, BITSPIXEL);
01003
01004
01005
01006 if (ScreenDepth == 8 || !DoCapture)
01007 {
01008 DeleteDC(hDCScreen);
01009 CaptureViewByRendering();
01010
01011 return TRUE;
01012 }
01013
01014
01015 lpBitmapInfo = GetLPBits(WRect.right-WRect.left, WRect.bottom-WRect.top,
01016 32, &lpBits);
01017
01018
01019 if (lpBitmapInfo==NULL)
01020 return FALSE;
01021
01022
01023
01024 HDC hDCCompatible = CreateCompatibleDC(hDCScreen);
01025
01026
01027
01028
01029
01030 View* pView = View::GetCurrent();
01031 if (pView == NULL)
01032 {
01033 ERROR3("No view in GRenderBrush::CaptureView");
01034 DeleteDC(hDCScreen);
01035 DeleteDC(hDCCompatible);
01036 return FALSE;
01037 }
01038 CCamView *pRenderWindow = pView->GetConnectionToOilView();
01039 if (pRenderWindow == NULL)
01040 {
01041 ERROR3("No window in GRenderBrush::CaptureView");
01042 DeleteDC(hDCScreen);
01043 DeleteDC(hDCCompatible);
01044 return FALSE;
01045 }
01046
01047 RECT Rect = CalculateWinRect(RenderMatrix, CurrentClipRect, PixelsPerInch );
01048 pRenderWindow->ClientToScreen( &Rect );
01049
01050
01051 INT32 ViewHeight = Rect.bottom - Rect.top ;
01052 INT32 ViewWidth = Rect.right - Rect.left;
01053 INT32 ViewTop = Rect.top;
01054 INT32 ViewLeft = Rect.left;
01055
01056
01057 DocView* pDocView = DocView::GetCurrent();
01058
01059 if (pDocView->AreRulersVisible())
01060 {
01061 INT32 RulerSize = OILRuler::GetRenderWidth();
01062 ViewTop += RulerSize+1;
01063 ViewLeft += RulerSize+1;
01064 }
01065
01066
01067 HBITMAP hBMScreen = CreateCompatibleBitmap(hDCScreen, ViewWidth, ViewHeight);
01068
01069 ERROR2IF(hBMScreen == NULL, FALSE, "unable to allocate bitmap for the view");
01070
01071
01072 if (!SelectObject(hDCCompatible, hBMScreen))
01073 {
01074 ERROR3("Error selecting bitmap into DC");
01075 DeleteDC(hDCScreen);
01076 DeleteDC(hDCCompatible);
01077 DeleteObject(hBMScreen);
01078 return FALSE;
01079 }
01080
01081 hPrevPalette = PaletteManager::StartPaintPalette(hDCScreen);
01082
01083
01084
01085
01086
01087
01088
01089 if (!Blit(hDCCompatible, hDCScreen, ViewHeight, ViewWidth, ViewLeft, ViewTop))
01090 {
01091 ERROR3("Error selecting bitmap into DC");
01092 DeleteDC(hDCScreen);
01093 DeleteDC(hDCCompatible);
01094 DeleteObject(hBMScreen);
01095 return FALSE;
01096 }
01097
01098
01099
01100
01101
01102
01103 INT32 BitmapSize = ViewHeight * ViewWidth * ScreenDepth;
01104
01105 LPBYTE lpScreenBits = NULL;
01106
01107 LPBITMAPINFO lpScreenInfo = GetLPBits(Rect.right-Rect.left, Rect.bottom-Rect.top,
01108 ScreenDepth, &lpScreenBits);
01109 if (lpScreenBits == NULL)
01110 {
01111 ERROR3("error getting screen bits");
01112 DeleteDC(hDCScreen);
01113 DeleteDC(hDCCompatible);
01114 DeleteObject(hBMScreen);
01115 return FALSE;
01116 }
01117
01118
01119
01120 if (lpScreenInfo == NULL)
01121 {
01122 ERROR3("error getting bitmapinfo");
01123 CCFree((LPVOID)lpScreenBits);
01124 DeleteDC(hDCScreen);
01125 DeleteDC(hDCCompatible);
01126 DeleteObject(hBMScreen);
01127 return FALSE;
01128 }
01129
01130 INT32 Colours = 0;
01131
01132 switch (ScreenDepth)
01133 {
01134 case 1:
01135 Colours = 2;
01136 break;
01137 case 4:
01138 Colours = 16;
01139 break;
01140 case 8:
01141 Colours = 256;
01142 break;
01143 case 16:
01144 Colours = 0;
01145 break;
01146 case 24:
01147 Colours = 0;
01148 break;
01149 case 32:
01150 Colours = 0;
01151 break;
01152 default:
01153 ERROR3("Illegal screen depth");
01154 break;
01155 }
01156
01157
01158 lpScreenInfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
01159 lpScreenInfo->bmiHeader.biWidth = ViewWidth;
01160 lpScreenInfo->bmiHeader.biHeight = ViewHeight;
01161 lpScreenInfo->bmiHeader.biPlanes = 1;
01162 lpScreenInfo->bmiHeader.biBitCount = ScreenDepth;
01163 lpScreenInfo->bmiHeader.biCompression = BI_RGB;
01164 lpScreenInfo->bmiHeader.biXPelsPerMeter = 3780;
01165 lpScreenInfo->bmiHeader.biYPelsPerMeter = 3780;
01166 lpScreenInfo->bmiHeader.biClrUsed = Colours;
01167 lpScreenInfo->bmiHeader.biClrImportant = 0;
01168 lpScreenInfo->bmiHeader.biSizeImage = BitmapSize;
01169
01170
01171
01172
01173
01174 INT32 num = (GetDIBits(hDCCompatible, hBMScreen,
01175 0, ViewHeight,
01176 lpScreenBits, lpScreenInfo,
01177 DIB_RGB_COLORS));
01178
01179 if (num ==0 )
01180 {
01181 ERROR3("Failed to get bitmap bits");
01182 DeleteDC(hDCScreen);
01183 DeleteDC(hDCCompatible);
01184 DeleteObject(hBMScreen);
01185 delete lpScreenInfo;
01186 CCFree((LPVOID)lpScreenBits);
01187 return FALSE;
01188 }
01189
01190
01191 if (lpBitmapInfo == NULL)
01192 ERROR3("What the *?!& is going on with my bitmaps!?");
01193
01194 GDrawContext *GDC = GetDrawContext();
01195
01196 INT32 result = 0;
01197 if (ScreenDepth == 8)
01198 {
01199 SetPaletteEntries(lpScreenInfo);
01200
01201
01202
01203
01204
01205
01206
01207
01208
01209
01210
01211
01212
01213
01214
01215
01216
01217
01218
01219
01220
01221
01222
01223
01224 result = DIBUtil::Convert8to32(lpScreenInfo, lpScreenBits, lpScreenInfo->bmiColors,
01225 lpBitmapInfo, lpBits);
01226
01227
01228
01229
01230 }
01231 if (ScreenDepth == 16)
01232 {
01233 RGBQUAD* pPalette = lpScreenInfo->bmiColors;
01234 result = Convert16to32(lpScreenInfo, lpScreenBits, pPalette,
01235 lpBitmapInfo, lpBits);
01236 SetupMainBitmap();
01237
01238
01239
01240
01241
01242
01243
01244
01245
01246
01247
01248
01249
01250
01251
01252
01253
01254
01255
01256
01257
01258 }
01259 if (ScreenDepth == 24)
01260 {
01261 result = GDC->ConvertBitmap(&(lpScreenInfo->bmiHeader), lpScreenBits,
01262 &(lpBitmapInfo->bmiHeader), lpBits, DitherStyle8Bit);
01263 }
01264 if (ScreenDepth == 32)
01265 {
01266
01267
01268
01269
01270
01271
01272
01273
01274
01275
01276
01277 FreeLPBits(lpBitmapInfo, lpBits);
01278 lpBitmapInfo = lpScreenInfo;
01279 lpBits = lpScreenBits;
01280 lpScreenInfo = NULL;
01281 lpScreenBits = NULL;
01282
01283 }
01284
01285
01286 Capture* pMasterCapture = GetMasterCapture();
01287 pMasterCapture->lpBitmapInfo = lpBitmapInfo;
01288 pMasterCapture->lpBits = lpBits;
01289
01290
01291 DeleteDC(hDCScreen);
01292 DeleteDC(hDCCompatible);
01293 DeleteObject(hBMScreen);
01294 if (lpScreenBits != NULL)
01295 FreeLPBits(lpScreenInfo, lpScreenBits);
01296 lpScreenInfo = NULL;
01297 lpScreenBits = NULL;
01298 if (hPrevPalette)
01299 PaletteManager::StopPaintPalette(hDCScreen, hPrevPalette);
01300 if (result == -1)
01301 {
01302 ERROR3("Failed to convert bitmap");
01303 return FALSE;
01304 }
01305 else
01306 return TRUE;
01307 }
01308
01309
01310
01311 BOOL GRenderBrush::GetBits(HDC hMemDC, HBITMAP hBitmap, INT32 Height, LPBYTE lpbits, LPBITMAPINFO lpInfo)
01312 {
01313
01314 INT32 num = (GetDIBits(hMemDC, hBitmap,
01315 0, Height,
01316 lpBits, lpInfo,
01317 DIB_RGB_COLORS));
01318 return (num != 0);
01319 }
01320
01321 BOOL GRenderBrush::Blit(HDC DestDC, HDC SourceDC, INT32 Height, INT32 Width, INT32 Left, INT32 Top)
01322 {
01323 if (BitBlt(DestDC,
01324 0, 0,
01325 Width, Height,
01326 SourceDC,
01327 Left , Top,
01328 SRCCOPY))
01329 return TRUE;
01330 else
01331 return FALSE;
01332
01333 }
01334
01335
01336
01337
01338
01339
01340
01341
01342
01343
01344
01345
01346
01347
01348
01349
01350
01351
01352
01353
01354
01355 BOOL GRenderBrush::CaptureViewByRendering()
01356 {
01357
01358 DocView* pDocView = DocView::GetCurrent();
01359 View* pView = View::GetCurrent();
01360 Spread* pSpread = Document::GetSelectedSpread();
01361 Document* pDoc = Document::GetCurrent();
01362 if (pSpread == NULL || pDocView == NULL || pView == NULL || pDoc == NULL)
01363 {
01364 ERROR3("Invalid entry conditions to GRenderBrush::CaptureViewByRendering");
01365 return FALSE;
01366 }
01367
01368 ERROR3IF(!MasterCaptureIsCurrent() && GetCaptureDepth()>0, "Can't 'CaptureView' while Captures are running");
01369
01370
01371
01372 WinRect WinRect(WRect.left, WRect.top, WRect.right, WRect.bottom);
01373 OilRect ORect = WinRect.ToOil(pView);
01374
01375 DocRect ViewRect = ORect.ToDoc(pSpread, pView);
01376
01377 pSpread->DocCoordToSpreadCoord(&ViewRect);
01378
01379
01380
01381 ConcurrentRenderer* pRendWrap = NULL;
01382
01383
01384
01385
01386
01387 pRendWrap = GRenderRegionWrapper::GetConcurrentRenderer(this,
01388 1.0,
01389 ViewRect,
01390 32,
01391 FALSE);
01392 if (pRendWrap == NULL)
01393 return FALSE;
01394
01395 GRenderRegion* pOffscreenRR = pRendWrap->GetRenderRegion();
01396
01397
01398 pOffscreenRR->SaveContext();
01399
01400
01401 pDocView->RenderEntireView(pOffscreenRR, pSpread);
01402
01403
01404 pOffscreenRR->RestoreContext();
01405
01406
01407
01408
01409 KernelBitmap * pBitmap = pRendWrap->GetKernelBitmap();
01410
01411 if (pBitmap == NULL)
01412 {
01413 ERROR3("Bitmap is NULL in GRenderBrush::CaptureViewByRendering");
01414 delete pOffscreenRR;
01415 return FALSE;
01416 }
01417 WinBitmap* pWinBitmap = (WinBitmap*)pBitmap->GetActualBitmap();
01418 if (pWinBitmap == NULL)
01419 {
01420 ERROR3("Bitmap is NULL in GRenderBrush::CaptureViewByRendering");
01421 delete pOffscreenRR;
01422 delete pBitmap;
01423 return FALSE;
01424 }
01425 LPBYTE pBits = NULL;
01426 LPBITMAPINFO pBitmapInfo = NULL;
01427 pWinBitmap->ExtractBitsAndInfo(&pBits, &pBitmapInfo);
01428
01429 if (pBits == NULL || pBitmapInfo == NULL)
01430 {
01431 ERROR3("Bitmap is NULL in GRenderBrush::CaptureViewByRendering");
01432 delete pOffscreenRR;
01433 delete pBitmap;
01434 delete pWinBitmap;
01435 return FALSE;
01436 }
01437
01438
01439 if (lpBitmapInfo!=NULL && lpBits != NULL)
01440 {
01441 FreeLPBits(lpBitmapInfo, lpBits);
01442 lpBitmapInfo = NULL;
01443 lpBits = NULL;
01444 }
01445 lpBits = pBits;
01446 lpBitmapInfo = pBitmapInfo;
01447
01448
01449 Capture* pMasterCapture = GetMasterCapture();
01450 pMasterCapture->lpBitmapInfo = lpBitmapInfo;
01451 pMasterCapture->lpBits = lpBits;
01452
01453
01454 delete pBitmap;
01455
01456
01457 pRendWrap->RestorePreviousRendererState();
01458
01459
01460 return TRUE;
01461 }
01462
01463
01464
01465
01466
01467
01468
01469
01470
01471
01472
01473
01474
01475
01476
01477
01478 void GRenderBrush::FreeLPBits( LPBITMAPINFO lpBMI, LPBYTE lpB )
01479 {
01480
01481 FreeDIB(lpBMI, lpB, NULL, FALSE);
01482 }
01483
01484
01485
01486
01487
01488
01489
01490
01491
01492
01493
01494
01495
01496
01497
01498
01499
01500
01501
01502
01503
01504
01505
01506
01507
01508 #define EXPAND(x) ( (x<<3) | (x>>2) )
01509
01510 BOOL GRenderBrush::Convert16to32(LPBITMAPINFO pSourceInfo, LPBYTE pSourceBits, RGBQUAD* pPalette,
01511 LPBITMAPINFO pDestInfo, LPBYTE pDestBits)
01512 {
01513 ERROR2IF(pSourceBits == NULL, FALSE, "NULL source bitmap");
01514 ERROR2IF(pSourceInfo == NULL, FALSE, "NULL source info");
01515 ERROR2IF(pDestInfo == NULL, FALSE, "NULL destination info");
01516 ERROR2IF(pDestBits == NULL, FALSE, "Null destination bitmap");
01517
01518
01519
01520
01521
01522 pDestInfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
01523 pDestInfo->bmiHeader.biWidth = pSourceInfo->bmiHeader.biWidth;
01524 pDestInfo->bmiHeader.biHeight = pSourceInfo->bmiHeader.biHeight;
01525 pDestInfo->bmiHeader.biPlanes = pSourceInfo->bmiHeader.biPlanes;
01526 pDestInfo->bmiHeader.biCompression = pSourceInfo->bmiHeader.biCompression;
01527 pDestInfo->bmiHeader.biXPelsPerMeter = pSourceInfo->bmiHeader.biXPelsPerMeter;
01528 pDestInfo->bmiHeader.biYPelsPerMeter = pSourceInfo->bmiHeader.biYPelsPerMeter;
01529 pDestInfo->bmiHeader.biClrImportant = 0;
01530
01531
01532 INT32 size = pDestInfo->bmiHeader.biWidth * pDestInfo->bmiHeader.biHeight * 4;
01533
01534
01535 pDestInfo->bmiHeader.biBitCount = 32;
01536 pDestInfo->bmiHeader.biSizeImage = size;
01537 pDestInfo->bmiHeader.biClrUsed = 0;
01538
01539
01540
01541 INT32 bmpsize = pSourceInfo->bmiHeader.biWidth * pSourceInfo->bmiHeader.biHeight;
01542
01543
01544 INT32 padding = pSourceInfo->bmiHeader.biWidth % 2;
01545 if (padding)
01546 padding = 2 - padding;
01547
01548
01549 LPBYTE pSourceEnd = pSourceBits;
01550 LPBYTE pDestEnd = pDestBits;
01551
01552 for (INT32 j = 0; j < bmpsize; j++)
01553 {
01554 pSourceEnd++;
01555 pDestEnd++;
01556 }
01557
01558 LPWORD pSource = (LPWORD)pSourceBits;
01559 LPBYTE pDest = pDestBits;
01560 for (INT32 i = 0; i < bmpsize; i ++)
01561 {
01562 if (i && i % pSourceInfo->bmiHeader.biWidth == 0)
01563 pSource += padding;
01564
01565 const WORD Data = *pSource;
01566
01567 const BYTE Blue = Data & 0x1F;
01568 *pDest++ = EXPAND(Blue);
01569
01570 const BYTE Green = (Data>>5) & 0x1F;
01571 *pDest++ = EXPAND(Green);
01572
01573 const BYTE Red = (Data>>10) & 0x1F;
01574 *pDest++ = EXPAND(Red);
01575
01576 *pDest = 0;
01577 pDest++;
01578
01579
01580 pSource++;
01581
01582
01583
01584 }
01585 return TRUE;
01586
01587 }
01588
01589
01590
01591
01592
01593
01594
01595
01596
01597
01598
01599
01600
01601
01602
01603
01604 void GRenderBrush::SetChangedBBox(DocRect Rect)
01605 {
01606 RECT WinRect = OSRenderRegion::DocRectToWin(RenderMatrix, Rect, PixelsPerInch);
01607 GetDrawContext()->SetChangedBBox(&WinRect);
01608 }
01609
01610