home *** CD-ROM | disk | FTP | other *** search
/ PC Direkt 1995 March / PCD_395.iso / starview / wntmsci / german / prvdlg.cx_ / PRVDLG.CXX
Encoding:
C/C++ Source or Header  |  1994-08-10  |  10.0 KB  |  346 lines

  1. /*******************************************************************
  2. *  PRVDLG.CXX
  3. *  (c) 1992-1994 STAR DIVISION
  4. *******************************************************************/
  5.  
  6. #include "sv.hxx"
  7.  
  8. #include "prvdlg.hrc"
  9. #include "prvdlg.hxx"
  10.  
  11. // --- PreviewBox::PreviewBox() ------------------------------------
  12.  
  13. PreviewBox::PreviewBox( Window* pParent, const ResId& rResId ) :
  14.                 Control( pParent, rResId )
  15. {
  16.     ChangeBackgroundBrush( Brush( Color( COL_GRAY ) ) );
  17. }
  18.  
  19. // --- PreviewDialog::PreviewDialog() ------------------------------
  20.  
  21. PreviewDialog::PreviewDialog( Window* pParent, JobSetup* pSetup ) :
  22.                    ModalDialog( pParent, ResId( DLG_PREVIEW ) ),
  23.                    aPVBox( this, ResId( DP_BOX ) ),
  24.                    aVScroll( this, ResId( DP_VSCROLL ) ),
  25.                    aHScroll( this, ResId( DP_HSCROLL ) ),
  26.                    aZoomIn( this, ResId( DP_ZOOMIN ) ),
  27.                    aZoomOut( this, ResId( DP_ZOOMOUT ) ),
  28.                    aNormalPage( this, ResId( DP_NORMALPAGE ) ),
  29.                    aFullPage( this, ResId( DP_FULLPAGE ) ),
  30.                    aDoublePage( this, ResId( DP_DOUBLEPAGE ) ),
  31.                    aPrevPage( this, ResId( DP_PREVPAGE ) ),
  32.                    aNextPage( this, ResId( DP_NEXTPAGE ) ),
  33.                    aCancel( this, ResId( DP_CANCEL ) ),
  34.                    aZoom( 0, 1 )
  35. {
  36.     FreeResource();
  37.  
  38.     aVScroll.ChangeEndScrollHdl(
  39.         LINK( this, PreviewDialog, VScrollEndHdl ) );
  40.     aHScroll.ChangeEndScrollHdl(
  41.         LINK( this, PreviewDialog, HScrollEndHdl ) );
  42.  
  43.     aZoomIn.ChangeClickHdl(
  44.         LINK( this, PreviewDialog, ZoomInHdl ) );
  45.     aZoomOut.ChangeClickHdl(
  46.         LINK( this, PreviewDialog, ZoomOutHdl ) );
  47.     aNormalPage.ChangeClickHdl(
  48.         LINK( this, PreviewDialog, NormalPageHdl ) );
  49.     aFullPage.ChangeClickHdl(
  50.         LINK( this, PreviewDialog, FullPageHdl ) );
  51.     aDoublePage.ChangeClickHdl(
  52.         LINK( this, PreviewDialog, DoublePageHdl ) );
  53.     aPrevPage.ChangeClickHdl(
  54.         LINK( this, PreviewDialog, PrevPageHdl ) );
  55.     aNextPage.ChangeClickHdl(
  56.         LINK( this, PreviewDialog, NextPageHdl ) );
  57.  
  58.     nPage              = 1;
  59.     pPreview           = new Preview( &aPVBox, 0 );
  60.     pSecondPreview     = NULL;
  61.     aMaxSize           = aPVBox.GetSizePixel();
  62.     PreviewDialog::pSetup = pSetup;
  63.     pPreview->SetJobSetup( pSetup );
  64.     ((Window*)pPreview)->ChangeBackgroundBrush(
  65.         Brush( Color( COL_WHITE ) ) );
  66.  
  67.     pPreview->SetPageQueueSize( 10 );
  68.     pPreview->ChangeRequestPageHdl(
  69.         LINK( this, PreviewDialog, PrintPage ) );
  70.     CalcPreviewSize();
  71.     CheckScrollRange();
  72.  
  73.     pPreview->Show();
  74. }
  75.  
  76. // --- PreviewDialog::~PreviewDialog() -----------------------------
  77.  
  78. PreviewDialog::~PreviewDialog()
  79. {
  80.     if ( pPreview != NULL )
  81.         delete pPreview;
  82.  
  83.     if ( pSecondPreview != NULL )
  84.         delete pSecondPreview;
  85. }
  86.  
  87. // --- PreviewDialog::CalcPreviewSize() ----------------------------
  88.  
  89. Size PreviewDialog::CalcPreviewSize()
  90. {
  91.     Size    aPreviewSize;
  92.     Point   aPreviewPos;
  93.  
  94.     aPreviewSize = pPreview->CalcWindowSizePixel( aMaxSize );
  95.  
  96.     if ( aPreviewSize.Width() < aMaxSize.Width() )
  97.         aPreviewPos.X() = (aMaxSize.Width()>>1) - (aPreviewSize.Width()>>1);
  98.     if ( aPreviewSize.Height() < aMaxSize.Height() )
  99.         aPreviewPos.Y() = (aMaxSize.Height()>>1) - (aPreviewSize.Height()>>1);
  100.  
  101.     pPreview->SetPosSizePixel( aPreviewPos, aPreviewSize );
  102.  
  103.     return aPreviewSize;
  104. }
  105.  
  106. // --- PreviewDialog::CheckScrollRange() ---------------------------
  107.  
  108. void PreviewDialog::CheckScrollRange()
  109. {
  110.     if ( aZoom.GetNumerator() == 0 )
  111.     {
  112.         aHScroll.Hide();
  113.         aVScroll.Hide();
  114.         aHScroll.ChangeThumbPos( 0 );
  115.         aVScroll.ChangeThumbPos( 0 );
  116.         pPreview->ChangePageOffset( Point( 0, 0 ) );
  117.         return;
  118.     }
  119.  
  120.     Size aPaperSize   = pPreview->GetPaperSize();
  121.     Size aViewSize    = pPreview->GetVisibleSize();
  122.     Size aPreviewSize = pPreview->GetSizePixel();
  123.  
  124.     if ( aPreviewSize.Width() == aMaxSize.Width() )
  125.     {
  126.         short nThumbPos = aHScroll.GetThumbPos();
  127.  
  128.         aHScroll.ChangeRange( Range( 0, aPaperSize.Width() ) );
  129.         aHScroll.ChangeLineSize( aViewSize.Width() / 10 );
  130.         aHScroll.ChangePageSize( aViewSize.Width() / 3  );
  131.         aHScroll.ChangeVisibleSize(    aViewSize.Width()  );
  132.  
  133.         aHScroll.ChangeThumbPos( nThumbPos );
  134.         aHScroll.Show();
  135.     }
  136.     else
  137.     {
  138.         aHScroll.Hide();
  139.         aHScroll.ChangeThumbPos( 0 );
  140.     }
  141.  
  142.     if ( aPreviewSize.Height() == aMaxSize.Height() )
  143.     {
  144.         short nThumbPos = aVScroll.GetThumbPos();
  145.  
  146.         aVScroll.ChangeRange( Range( 0, aPaperSize.Height() ) );
  147.         aVScroll.ChangeLineSize( aViewSize.Height() / 10 );
  148.         aVScroll.ChangePageSize( aViewSize.Height() / 3  );
  149.         aVScroll.ChangeVisibleSize(    aViewSize.Height()   );
  150.  
  151.         aVScroll.ChangeThumbPos( nThumbPos );
  152.         aVScroll.Show();
  153.     }
  154.     else
  155.     {
  156.         aVScroll.Hide();
  157.         aVScroll.ChangeThumbPos( 0 );
  158.     }
  159.  
  160.     pPreview->ChangePageOffset( Point( aHScroll.GetThumbPos(),
  161.                                        aVScroll.GetThumbPos() ) );
  162. }
  163.  
  164. // --- PreviewDialog::ChangeRequestPageHdl() -----------------------
  165.  
  166. Link PreviewDialog::ChangeRequestPageHdl( const Link& rLink )
  167. {
  168.     Link aOldLink = aRequestPageHdl;
  169.     aRequestPageHdl = rLink;
  170.     return aOldLink;
  171. }
  172.  
  173. // --- PreviewDialog::VScrollEndHdl() ------------------------------
  174.  
  175. void PreviewDialog::VScrollEndHdl( ScrollBar* )
  176. {
  177.     aOffset = Point( aHScroll.GetThumbPos(),
  178.                      aVScroll.GetThumbPos() );
  179.     pPreview->ChangePageOffset( aOffset );
  180.     pPreview->Update();
  181. }
  182.  
  183. // --- PreviewDialog::HScrollEndHdl() ------------------------------
  184.  
  185. void PreviewDialog::HScrollEndHdl( ScrollBar* )
  186. {
  187.     aOffset = Point( aHScroll.GetThumbPos(),
  188.                      aVScroll.GetThumbPos() );
  189.     pPreview->ChangePageOffset( aOffset );
  190.     pPreview->Update();
  191. }
  192.  
  193. // --- PreviewDialog::ZoomInHdl() ----------------------------------
  194.  
  195. void PreviewDialog::ZoomInHdl( Button* )
  196. {
  197.     if ( pSecondPreview != NULL )
  198.         pSecondPreview->Hide();
  199.  
  200.     if ( aZoom.GetNumerator() == 0 )
  201.         aZoom = Fraction( 1, 4 );
  202.     else
  203.         aZoom *= Fraction( 3, 2 );
  204.  
  205.     if ( aZoom > Fraction( 16, 1 ) )
  206.         aZoom = Fraction( 16, 1 );
  207.  
  208.     pPreview->ChangeZoomFactor( aZoom );
  209.     CalcPreviewSize();
  210.     CheckScrollRange();
  211. }
  212.  
  213. // --- PreviewDialog::ZoomOutHdl() ---------------------------------
  214.  
  215. void PreviewDialog::ZoomOutHdl( Button* )
  216. {
  217.     if ( pSecondPreview != NULL )
  218.         pSecondPreview->Hide();
  219.  
  220.     if ( aZoom.GetNumerator() == 0 )
  221.         aZoom = Fraction ( 1, 4 );
  222.     else
  223.         aZoom *= Fraction( 2, 3 );
  224.  
  225.     if( aZoom < Fraction( 1, 16 ) )
  226.         aZoom = Fraction( 1, 16 );
  227.  
  228.     pPreview->ChangeZoomFactor( aZoom );
  229.     CalcPreviewSize();
  230.     CheckScrollRange();
  231. }
  232.  
  233. // --- PreviewDialog::NormalPageHdl() ------------------------------
  234.  
  235. void PreviewDialog::NormalPageHdl( Button* )
  236. {
  237.     if ( pSecondPreview != NULL )
  238.         pSecondPreview->Hide();
  239.  
  240.     aZoom = Fraction( 1, 1 );
  241.     pPreview->ChangeZoomFactor( aZoom );
  242.     CalcPreviewSize();
  243.     CheckScrollRange();
  244. }
  245.  
  246. // --- PreviewDialog::FullPageHdl() --------------------------------
  247.  
  248. void PreviewDialog::FullPageHdl( Button* )
  249. {
  250.     aVScroll.Hide();
  251.     aHScroll.Hide();
  252.  
  253.     if ( pSecondPreview != NULL )
  254.         pSecondPreview->Hide();
  255.  
  256.     aZoom = Fraction( 0, 1 );
  257.     pPreview->ChangeZoomFactor( aZoom );
  258.     CalcPreviewSize();
  259.     CheckScrollRange();
  260. }
  261.  
  262. // --- PreviewDialog::DoublePageHdl() ------------------------------
  263.  
  264. void PreviewDialog::DoublePageHdl( Button* )
  265. {
  266.     short X, Y;
  267.     Size  aHalfSize;
  268.  
  269.     aZoom = Fraction( 0, 1 );
  270.     pPreview->ChangeZoomFactor( aZoom );
  271.     CheckScrollRange();
  272.  
  273.     if ( pSecondPreview == NULL )
  274.     {
  275.         pSecondPreview = new Preview( &aPVBox, 0 );
  276.         pSecondPreview->SetJobSetup( pSetup );
  277.         ((Window*)pSecondPreview)->ChangeBackgroundBrush(
  278.             Brush( Color( COL_WHITE ) ) );
  279.         pSecondPreview->ChangeRequestPageHdl(
  280.             LINK( this, PreviewDialog, PrintPage ) );
  281.         pSecondPreview->ChangeCurPage( nPage + 1 );
  282.     }
  283.     pSecondPreview->ChangeZoomFactor( aZoom );
  284.     pSecondPreview->ChangePageOffset( Point( 0, 0 ) );
  285.     pSecondPreview->Invalidate();
  286.  
  287.     aHalfSize = Size( (aMaxSize.Width() / 2) - 7,
  288.                       aMaxSize.Height() - 10 );
  289.     aHalfSize = pPreview->CalcWindowSizePixel( aHalfSize );
  290.     aHalfSize = pSecondPreview->CalcWindowSizePixel( aHalfSize );
  291.  
  292.     Y = (aMaxSize.Height() - aHalfSize.Height()) / 2;
  293.     X = aMaxSize.Width() / 2 - aHalfSize.Width() - 2;
  294.     pPreview->SetPosSizePixel( Point( X, Y ), aHalfSize );
  295.     X = aMaxSize.Width() / 2 + 2;
  296.     pSecondPreview->SetPosSizePixel( Point( X, Y ), aHalfSize );
  297.     pSecondPreview->Show();
  298. }
  299.  
  300. // --- PreviewDialog::PrevPageHdl() --------------------------------
  301.  
  302. void PreviewDialog::PrevPageHdl( Button* )
  303. {
  304.     if ( nPage > 1 )
  305.     {
  306.         pPreview->ChangeCurPage( --nPage );
  307.  
  308.         if ( pSecondPreview != NULL )
  309.         {
  310.             pPreview->Update();
  311.             pSecondPreview->ChangeCurPage( nPage + 1 );
  312.             if ( pSecondPreview->IsVisible() )
  313.                 pSecondPreview->Update();
  314.         }
  315.         else
  316.             pPreview->Update();
  317.     }
  318. }
  319.  
  320. // --- PreviewDialog::NextPageHdl() --------------------------------
  321.  
  322. void PreviewDialog::NextPageHdl( Button* )
  323. {
  324.     if ( nPage < 0xFFFF )
  325.     {
  326.         pPreview->ChangeCurPage( ++nPage );
  327.  
  328.         if ( pSecondPreview != NULL )
  329.         {
  330.             pPreview->Update();
  331.             pSecondPreview->ChangeCurPage( nPage + 1 );
  332.             if ( pSecondPreview->IsVisible() )
  333.                 pSecondPreview->Update();
  334.         }
  335.         else
  336.             pPreview->Update();
  337.     }
  338. }
  339.  
  340. // --- PreviewDialog::PrintPage() ----------------------------------
  341.  
  342. void PreviewDialog::PrintPage( Preview* pPrev )
  343. {
  344.     aRequestPageHdl.Call( pPrev );
  345. }
  346.