Kaydet (Commit) d6eeb8a4 authored tarafından Caolán McNamara's avatar Caolán McNamara

extract Scan Preview code into a preview widget

instead of scribbling over the parent dialog directly. Doing is this way allows
the .ui-ification to work right.

Change-Id: Ia0c33eae4cd5a4c94896436fe5a5afad8d60a577
üst f188c982
...@@ -21,9 +21,9 @@ ...@@ -21,9 +21,9 @@
#include <stdlib.h> #include <stdlib.h>
#include <tools/config.hxx> #include <tools/config.hxx>
#include <vcl/dibtools.hxx> #include <vcl/dibtools.hxx>
#include <vcl/layout.hxx>
#include <vcl/msgbox.hxx> #include <vcl/msgbox.hxx>
#include <sanedlg.hxx> #include <sanedlg.hxx>
#include <sanedlg.hrc>
#include <grid.hxx> #include <grid.hxx>
#include <math.h> #include <math.h>
#include <sal/macros.h> #include <sal/macros.h>
...@@ -36,15 +36,128 @@ ResId SaneResId( sal_uInt32 nID ) ...@@ -36,15 +36,128 @@ ResId SaneResId( sal_uInt32 nID )
return ResId( nID, *pResMgr ); return ResId( nID, *pResMgr );
} }
#define PREVIEW_WIDTH 113
#define PREVIEW_HEIGHT 160
class ScanPreview : public Window
{
private:
enum DragDirection { TopLeft, Top, TopRight, Right, BottomRight, Bottom,
BottomLeft, Left };
Bitmap maPreviewBitmap;
Rectangle maPreviewRect;
Point maTopLeft, maBottomRight;
Point maMinTopLeft, maMaxBottomRight;
SaneDlg* mpParentDialog;
DragDirection meDragDirection;
bool mbDragEnable;
bool mbDragDrawn;
bool mbIsDragging;
void DrawRectangles(Point& rUL, Point& rBR);
public:
ScanPreview(Window* pParent, WinBits nStyle)
: Window(pParent, nStyle)
, maMaxBottomRight(PREVIEW_WIDTH, PREVIEW_HEIGHT)
, mpParentDialog(NULL)
, meDragDirection(TopLeft)
, mbDragEnable(false)
, mbDragDrawn(false)
, mbIsDragging(false)
{
}
void Init(SaneDlg *pParent)
{
mpParentDialog = pParent;
}
void EnableDrag() { mbDragEnable = true; }
void DisableDrag() { mbDragEnable = false; }
bool IsDragEnabled() { return mbDragEnable; }
virtual void Paint(const Rectangle& rRect) SAL_OVERRIDE;
virtual void MouseButtonDown(const MouseEvent& rMEvt) SAL_OVERRIDE;
virtual void MouseMove(const MouseEvent& rMEvt) SAL_OVERRIDE;
virtual void MouseButtonUp(const MouseEvent& rMEvt) SAL_OVERRIDE;
Point GetPixelPos(const Point& rIn) const;
Point GetLogicPos(const Point& rIn) const;
void GetPreviewLogicRect(Point& rTopLeft, Point &rBottomRight) const
{
rTopLeft = GetLogicPos(maTopLeft);
rBottomRight = GetLogicPos(maBottomRight);
}
void GetMaxLogicRect(Point& rTopLeft, Point &rBottomRight) const
{
rTopLeft = maMinTopLeft;
rBottomRight = maMaxBottomRight;
}
void ChangePreviewLogicTopLeftY(long Y)
{
Point aPoint(0, Y);
aPoint = GetPixelPos(aPoint);
maTopLeft.Y() = aPoint.Y();
}
void ChangePreviewLogicTopLeftX(long X)
{
Point aPoint(X, 0);
aPoint = GetPixelPos(aPoint);
maTopLeft.X() = aPoint.X();
}
void ChangePreviewLogicBottomRightY(long Y)
{
Point aPoint(0, Y);
aPoint = GetPixelPos(aPoint);
maBottomRight.Y() = aPoint.Y();
}
void ChangePreviewLogicBottomRightX(long X)
{
Point aPoint(X, 0);
aPoint = GetPixelPos(aPoint);
maBottomRight.X() = aPoint.X();
}
void SetPreviewLogicRect(const Point& rTopLeft, const Point &rBottomRight)
{
maTopLeft = GetPixelPos(rTopLeft);
maBottomRight = GetPixelPos(rBottomRight);
maPreviewRect = Rectangle( maTopLeft,
Size( maBottomRight.X() - maTopLeft.X(),
maBottomRight.Y() - maTopLeft.Y() )
);
}
void SetPreviewMaxRect(const Point& rTopLeft, const Point &rBottomRight)
{
maMinTopLeft = rTopLeft;
maMaxBottomRight = rBottomRight;
}
void DrawDrag();
void UpdatePreviewBounds();
void SetBitmap(SvStream &rStream)
{
ReadDIB(maPreviewBitmap, rStream, true);
}
virtual Size GetOptimalSize() const SAL_OVERRIDE
{
Size aSize(LogicToPixel(Size(PREVIEW_WIDTH, PREVIEW_HEIGHT), MAP_APPFONT));
aSize.setWidth(aSize.getWidth()+1);
aSize.setHeight(aSize.getHeight()+1);
return aSize;
}
};
extern "C" SAL_DLLPUBLIC_EXPORT Window* SAL_CALL makeScanPreview(Window *pParent, VclBuilder::stringmap &rMap)
{
WinBits nWinStyle = 0;
OString sBorder = VclBuilder::extractCustomProperty(rMap);
if (!sBorder.isEmpty())
nWinStyle |= WB_BORDER;
ScanPreview *pWindow = new ScanPreview(pParent, nWinStyle);
return pWindow;
}
SaneDlg::SaneDlg( Window* pParent, Sane& rSane, bool bScanEnabled ) : SaneDlg::SaneDlg( Window* pParent, Sane& rSane, bool bScanEnabled ) :
ModalDialog(pParent, "SaneDialog", "modules/scanner/ui/sanedialog.ui"), ModalDialog(pParent, "SaneDialog", "modules/scanner/ui/sanedialog.ui"),
mrSane( rSane ), mrSane( rSane ),
mbDragEnable( false ),
mbIsDragging( false ),
mbScanEnabled( bScanEnabled ), mbScanEnabled( bScanEnabled ),
mbDragDrawn( false ),
meDragDirection( TopLeft ),
maMapMode( MAP_APPFONT ),
mnCurrentOption(0), mnCurrentOption(0),
mnCurrentElement(0), mnCurrentElement(0),
mpRange(0), mpRange(0),
...@@ -82,9 +195,7 @@ SaneDlg::SaneDlg( Window* pParent, Sane& rSane, bool bScanEnabled ) : ...@@ -82,9 +195,7 @@ SaneDlg::SaneDlg( Window* pParent, Sane& rSane, bool bScanEnabled ) :
mpOptionBox->set_height_request(aSize.Height()); mpOptionBox->set_height_request(aSize.Height());
get(mpBoolCheckBox, "boolCheckbutton"); get(mpBoolCheckBox, "boolCheckbutton");
get(mpPreview, "preview"); get(mpPreview, "preview");
aSize = LogicToPixel(Size(PREVIEW_WIDTH, PREVIEW_HEIGHT), MAP_APPFONT); mpPreview->Init(this);
mpPreview->set_width_request(aSize.Width());
mpPreview->set_height_request(aSize.Height());
if( Sane::IsSane() ) if( Sane::IsSane() )
{ {
InitDevices(); // opens first sane device InitDevices(); // opens first sane device
...@@ -180,10 +291,12 @@ void SaneDlg::InitFields() ...@@ -180,10 +291,12 @@ void SaneDlg::InitFields()
"preview" "preview"
}; };
mbDragEnable = true; mpPreview->EnableDrag();
mpReslBox->Clear(); mpReslBox->Clear();
maMinTopLeft = Point( 0, 0 ); Point aTopLeft, aBottomRight;
maMaxBottomRight = Point( PREVIEW_WIDTH, PREVIEW_HEIGHT ); mpPreview->GetPreviewLogicRect(aTopLeft, aBottomRight);
Point aMinTopLeft, aMaxBottomRight;
mpPreview->GetMaxLogicRect(aMinTopLeft, aMaxBottomRight);
mpScanButton->Show( mbScanEnabled ); mpScanButton->Show( mbScanEnabled );
if( ! mrSane.IsOpen() ) if( ! mrSane.IsOpen() )
...@@ -285,10 +398,10 @@ void SaneDlg::InitFields() ...@@ -285,10 +398,10 @@ void SaneDlg::InitFields()
pField->SetCustomUnitText(OUString("Pixel")); pField->SetCustomUnitText(OUString("Pixel"));
} }
switch( i ) { switch( i ) {
case 0: maTopLeft.X() = (int)fValue;break; case 0: aTopLeft.X() = (int)fValue;break;
case 1: maTopLeft.Y() = (int)fValue;break; case 1: aTopLeft.Y() = (int)fValue;break;
case 2: maBottomRight.X() = (int)fValue;break; case 2: aBottomRight.X() = (int)fValue;break;
case 3: maBottomRight.Y() = (int)fValue;break; case 3: aBottomRight.Y() = (int)fValue;break;
} }
} }
double *pDouble = NULL; double *pDouble = NULL;
...@@ -305,49 +418,49 @@ void SaneDlg::InitFields() ...@@ -305,49 +418,49 @@ void SaneDlg::InitFields()
delete [] pDouble; delete [] pDouble;
} }
switch( i ) { switch( i ) {
case 0: maMinTopLeft.X() = pField->GetMin();break; case 0: aMinTopLeft.X() = pField->GetMin();break;
case 1: maMinTopLeft.Y() = pField->GetMin();break; case 1: aMinTopLeft.Y() = pField->GetMin();break;
case 2: maMaxBottomRight.X() = pField->GetMax();break; case 2: aMaxBottomRight.X() = pField->GetMax();break;
case 3: maMaxBottomRight.Y() = pField->GetMax();break; case 3: aMaxBottomRight.Y() = pField->GetMax();break;
} }
} }
else else
{ {
switch( i ) { switch( i ) {
case 0: maMinTopLeft.X() = (int)fValue;break; case 0: aMinTopLeft.X() = (int)fValue;break;
case 1: maMinTopLeft.Y() = (int)fValue;break; case 1: aMinTopLeft.Y() = (int)fValue;break;
case 2: maMaxBottomRight.X() = (int)fValue;break; case 2: aMaxBottomRight.X() = (int)fValue;break;
case 3: maMaxBottomRight.Y() = (int)fValue;break; case 3: aMaxBottomRight.Y() = (int)fValue;break;
} }
} }
pField->Enable( true ); pField->Enable( true );
} }
else else
{ {
mbDragEnable = false; mpPreview->DisableDrag();
pField->SetMin( 0 ); pField->SetMin( 0 );
switch( i ) { switch( i ) {
case 0: case 0:
maMinTopLeft.X() = 0; aMinTopLeft.X() = 0;
maTopLeft.X() = 0; aTopLeft.X() = 0;
pField->SetMax( PREVIEW_WIDTH ); pField->SetMax( PREVIEW_WIDTH );
pField->SetValue( 0 ); pField->SetValue( 0 );
break; break;
case 1: case 1:
maMinTopLeft.Y() = 0; aMinTopLeft.Y() = 0;
maTopLeft.Y() = 0; aTopLeft.Y() = 0;
pField->SetMax( PREVIEW_HEIGHT ); pField->SetMax( PREVIEW_HEIGHT );
pField->SetValue( 0 ); pField->SetValue( 0 );
break; break;
case 2: case 2:
maMaxBottomRight.X() = PREVIEW_WIDTH; aMaxBottomRight.X() = PREVIEW_WIDTH;
maBottomRight.X() = PREVIEW_WIDTH; aBottomRight.X() = PREVIEW_WIDTH;
pField->SetMax( PREVIEW_WIDTH ); pField->SetMax( PREVIEW_WIDTH );
pField->SetValue( PREVIEW_WIDTH ); pField->SetValue( PREVIEW_WIDTH );
break; break;
case 3: case 3:
maMaxBottomRight.Y() = PREVIEW_HEIGHT; aMaxBottomRight.Y() = PREVIEW_HEIGHT;
maBottomRight.Y() = PREVIEW_HEIGHT; aBottomRight.Y() = PREVIEW_HEIGHT;
pField->SetMax( PREVIEW_HEIGHT ); pField->SetMax( PREVIEW_HEIGHT );
pField->SetValue( PREVIEW_HEIGHT ); pField->SetValue( PREVIEW_HEIGHT );
break; break;
...@@ -355,12 +468,11 @@ void SaneDlg::InitFields() ...@@ -355,12 +468,11 @@ void SaneDlg::InitFields()
pField->Enable( false ); pField->Enable( false );
} }
} }
maTopLeft = GetPixelPos( maTopLeft );
maBottomRight = GetPixelPos( maBottomRight ); mpPreview->SetPreviewMaxRect(aMinTopLeft, aMaxBottomRight);
maPreviewRect = Rectangle( maTopLeft, mpPreview->SetPreviewLogicRect(aTopLeft, aBottomRight);
Size( maBottomRight.X() - maTopLeft.X(), mpPreview->Invalidate();
maBottomRight.Y() - maTopLeft.Y() )
);
// fill OptionBox // fill OptionBox
mpOptionBox->Clear(); mpOptionBox->Clear();
SvTreeListEntry* pParentEntry = 0; SvTreeListEntry* pParentEntry = 0;
...@@ -470,7 +582,7 @@ IMPL_LINK( SaneDlg, ClickBtnHdl, Button*, pButton ) ...@@ -470,7 +582,7 @@ IMPL_LINK( SaneDlg, ClickBtnHdl, Button*, pButton )
{ {
double fRes = (double)mpReslBox->GetValue(); double fRes = (double)mpReslBox->GetValue();
SetAdjustedNumericalValue( "resolution", fRes ); SetAdjustedNumericalValue( "resolution", fRes );
UpdateScanArea( true ); UpdateScanArea(true);
SaveState(); SaveState();
EndDialog( mrSane.IsOpen() ? 1 : 0 ); EndDialog( mrSane.IsOpen() ? 1 : 0 );
doScan = (pButton == mpScanButton); doScan = (pButton == mpScanButton);
...@@ -651,31 +763,23 @@ IMPL_LINK( SaneDlg, ModifyHdl, Edit*, pEdit ) ...@@ -651,31 +763,23 @@ IMPL_LINK( SaneDlg, ModifyHdl, Edit*, pEdit )
} }
else if( pEdit == mpTopField ) else if( pEdit == mpTopField )
{ {
Point aPoint( 0, mpTopField->GetValue() ); mpPreview->ChangePreviewLogicTopLeftY(mpTopField->GetValue());
aPoint = GetPixelPos( aPoint ); mpPreview->DrawDrag();
maTopLeft.Y() = aPoint.Y();
DrawDrag();
} }
else if( pEdit == mpLeftField ) else if( pEdit == mpLeftField )
{ {
Point aPoint( mpLeftField->GetValue(), 0 ); mpPreview->ChangePreviewLogicTopLeftX(mpLeftField->GetValue());
aPoint = GetPixelPos( aPoint ); mpPreview->DrawDrag();
maTopLeft.X() = aPoint.X();
DrawDrag();
} }
else if( pEdit == mpBottomField ) else if( pEdit == mpBottomField )
{ {
Point aPoint( 0, mpBottomField->GetValue() ); mpPreview->ChangePreviewLogicBottomRightY(mpBottomField->GetValue());
aPoint = GetPixelPos( aPoint ); mpPreview->DrawDrag();
maBottomRight.Y() = aPoint.Y();
DrawDrag();
} }
else if( pEdit == mpRightField ) else if( pEdit == mpRightField )
{ {
Point aPoint( mpRightField->GetValue(), 0 ); mpPreview->ChangePreviewLogicBottomRightX(mpRightField->GetValue());
aPoint = GetPixelPos( aPoint ); mpPreview->DrawDrag();
maBottomRight.X() = aPoint.X();
DrawDrag();
} }
} }
return 0; return 0;
...@@ -686,13 +790,8 @@ IMPL_LINK( SaneDlg, ReloadSaneOptionsHdl, Sane*, /*pSane*/ ) ...@@ -686,13 +790,8 @@ IMPL_LINK( SaneDlg, ReloadSaneOptionsHdl, Sane*, /*pSane*/ )
mnCurrentOption = -1; mnCurrentOption = -1;
mnCurrentElement = 0; mnCurrentElement = 0;
DisableOption(); DisableOption();
// #92024# preserve preview rect, should only be set
// initially or in AcquirePreview
Rectangle aPreviewRect = maPreviewRect;
InitFields(); InitFields();
maPreviewRect = aPreviewRect; mpPreview->Invalidate();
Rectangle aDummyRect( Point( 0, 0 ), GetSizePixel() );
Paint( aDummyRect );
return 0; return 0;
} }
...@@ -731,12 +830,18 @@ void SaneDlg::AcquirePreview() ...@@ -731,12 +830,18 @@ void SaneDlg::AcquirePreview()
fprintf( stderr, "Previewbitmapstream contains %d bytes\n", (int)aTransporter.getStream().Tell() ); fprintf( stderr, "Previewbitmapstream contains %d bytes\n", (int)aTransporter.getStream().Tell() );
#endif #endif
aTransporter.getStream().Seek( STREAM_SEEK_TO_BEGIN ); aTransporter.getStream().Seek( STREAM_SEEK_TO_BEGIN );
ReadDIB(maPreviewBitmap, aTransporter.getStream(), true); mpPreview->SetBitmap(aTransporter.getStream());
} }
SetAdjustedNumericalValue( "resolution", fResl ); SetAdjustedNumericalValue( "resolution", fResl );
mpReslBox->SetValue( (sal_uLong)fResl ); mpReslBox->SetValue( (sal_uLong)fResl );
mpPreview->UpdatePreviewBounds();
mpPreview->Invalidate();
}
void ScanPreview::UpdatePreviewBounds()
{
if( mbDragEnable ) if( mbDragEnable )
{ {
maPreviewRect = Rectangle( maTopLeft, maPreviewRect = Rectangle( maTopLeft,
...@@ -762,16 +867,15 @@ void SaneDlg::AcquirePreview() ...@@ -762,16 +867,15 @@ void SaneDlg::AcquirePreview()
maBottomRight.Y() - maTopLeft.Y() ) ); maBottomRight.Y() - maTopLeft.Y() ) );
} }
} }
Paint( Rectangle( Point( 0, 0 ), GetSizePixel() ) );
} }
void SaneDlg::Paint( const Rectangle& rRect ) void ScanPreview::Paint(const Rectangle& rRect)
{ {
SetMapMode( maMapMode ); Window::Paint(rRect);
SetMapMode(MAP_APPFONT);
SetFillColor( Color( COL_WHITE ) ); SetFillColor( Color( COL_WHITE ) );
SetLineColor( Color( COL_WHITE ) ); SetLineColor( Color( COL_WHITE ) );
DrawRect( Rectangle( Point( PREVIEW_UPPER_LEFT, PREVIEW_UPPER_TOP ), DrawRect( Rectangle( Point( 0, 0 ),
Size( PREVIEW_WIDTH, PREVIEW_HEIGHT ) ) ); Size( PREVIEW_WIDTH, PREVIEW_HEIGHT ) ) );
SetMapMode( MapMode( MAP_PIXEL ) ); SetMapMode( MapMode( MAP_PIXEL ) );
// check for sane values // check for sane values
...@@ -780,8 +884,6 @@ void SaneDlg::Paint( const Rectangle& rRect ) ...@@ -780,8 +884,6 @@ void SaneDlg::Paint( const Rectangle& rRect )
mbDragDrawn = false; mbDragDrawn = false;
DrawDrag(); DrawDrag();
ModalDialog::Paint( rRect );
} }
void SaneDlg::DisableOption() void SaneDlg::DisableOption()
...@@ -915,7 +1017,7 @@ void SaneDlg::EstablishButtonOption() ...@@ -915,7 +1017,7 @@ void SaneDlg::EstablishButtonOption()
#define RECT_SIZE_PIX 7 #define RECT_SIZE_PIX 7
void SaneDlg::MouseMove( const MouseEvent& rMEvt ) void ScanPreview::MouseMove(const MouseEvent& rMEvt)
{ {
if( mbIsDragging ) if( mbIsDragging )
{ {
...@@ -955,12 +1057,12 @@ void SaneDlg::MouseMove( const MouseEvent& rMEvt ) ...@@ -955,12 +1057,12 @@ void SaneDlg::MouseMove( const MouseEvent& rMEvt )
maBottomRight.Y() = nSwap; maBottomRight.Y() = nSwap;
} }
DrawDrag(); DrawDrag();
UpdateScanArea( false ); mpParentDialog->UpdateScanArea(false);
} }
ModalDialog::MouseMove( rMEvt ); Window::MouseMove( rMEvt );
} }
void SaneDlg::MouseButtonDown( const MouseEvent& rMEvt ) void ScanPreview::MouseButtonDown( const MouseEvent& rMEvt )
{ {
Point aMousePixel = rMEvt.GetPosPixel(); Point aMousePixel = rMEvt.GetPosPixel();
...@@ -1042,21 +1144,21 @@ void SaneDlg::MouseButtonDown( const MouseEvent& rMEvt ) ...@@ -1042,21 +1144,21 @@ void SaneDlg::MouseButtonDown( const MouseEvent& rMEvt )
SetPointerPosPixel( aMousePixel ); SetPointerPosPixel( aMousePixel );
DrawDrag(); DrawDrag();
} }
ModalDialog::MouseButtonDown( rMEvt ); Window::MouseButtonDown( rMEvt );
} }
void SaneDlg::MouseButtonUp( const MouseEvent& rMEvt ) void ScanPreview::MouseButtonUp( const MouseEvent& rMEvt )
{ {
if( mbIsDragging ) if( mbIsDragging )
{ {
UpdateScanArea( true ); mpParentDialog->UpdateScanArea(true);
} }
mbIsDragging = false; mbIsDragging = false;
ModalDialog::MouseButtonUp( rMEvt ); Window::MouseButtonUp( rMEvt );
} }
void SaneDlg::DrawRectangles( Point& rUL, Point& rBR ) void ScanPreview::DrawRectangles( Point& rUL, Point& rBR )
{ {
int nMiddleX, nMiddleY; int nMiddleX, nMiddleY;
Point aBL, aUR; Point aBL, aUR;
...@@ -1080,7 +1182,7 @@ void SaneDlg::DrawRectangles( Point& rUL, Point& rBR ) ...@@ -1080,7 +1182,7 @@ void SaneDlg::DrawRectangles( Point& rUL, Point& rBR )
DrawRect( Rectangle( Point( rBR.X(), nMiddleY - RECT_SIZE_PIX/2 ), Size( -RECT_SIZE_PIX, RECT_SIZE_PIX ) ) ); DrawRect( Rectangle( Point( rBR.X(), nMiddleY - RECT_SIZE_PIX/2 ), Size( -RECT_SIZE_PIX, RECT_SIZE_PIX ) ) );
} }
void SaneDlg::DrawDrag() void ScanPreview::DrawDrag()
{ {
static Point aLastUL, aLastBR; static Point aLastUL, aLastBR;
...@@ -1100,27 +1202,25 @@ void SaneDlg::DrawDrag() ...@@ -1100,27 +1202,25 @@ void SaneDlg::DrawDrag()
mbDragDrawn = true; mbDragDrawn = true;
SetRasterOp( eROP ); SetRasterOp( eROP );
SetMapMode( maMapMode ); SetMapMode(MAP_APPFONT);
} }
Point SaneDlg::GetPixelPos( const Point& rIn ) Point ScanPreview::GetPixelPos( const Point& rIn) const
{ {
Point aConvert( Point aConvert(
( ( rIn.X() * PREVIEW_WIDTH ) / ( ( rIn.X() * PREVIEW_WIDTH ) /
( maMaxBottomRight.X() - maMinTopLeft.X() ) ) ( maMaxBottomRight.X() - maMinTopLeft.X() ) )
+ PREVIEW_UPPER_LEFT, ,
( ( rIn.Y() * PREVIEW_HEIGHT ) ( ( rIn.Y() * PREVIEW_HEIGHT )
/ ( maMaxBottomRight.Y() - maMinTopLeft.Y() ) ) / ( maMaxBottomRight.Y() - maMinTopLeft.Y() ) )
+ PREVIEW_UPPER_TOP ); );
return LogicToPixel( aConvert, maMapMode ); return LogicToPixel(aConvert, MAP_APPFONT);
} }
Point SaneDlg::GetLogicPos( const Point& rIn ) Point ScanPreview::GetLogicPos(const Point& rIn) const
{ {
Point aConvert = PixelToLogic( rIn, maMapMode ); Point aConvert = PixelToLogic(rIn, MAP_APPFONT);
aConvert.X() -= PREVIEW_UPPER_LEFT;
aConvert.Y() -= PREVIEW_UPPER_TOP;
if( aConvert.X() < 0 ) if( aConvert.X() < 0 )
aConvert.X() = 0; aConvert.X() = 0;
if( aConvert.X() >= PREVIEW_WIDTH ) if( aConvert.X() >= PREVIEW_WIDTH )
...@@ -1137,20 +1237,20 @@ Point SaneDlg::GetLogicPos( const Point& rIn ) ...@@ -1137,20 +1237,20 @@ Point SaneDlg::GetLogicPos( const Point& rIn )
return aConvert; return aConvert;
} }
void SaneDlg::UpdateScanArea( bool bSend ) void SaneDlg::UpdateScanArea(bool bSend)
{ {
if( ! mbDragEnable ) if (!mpPreview->IsDragEnabled())
return; return;
Point aUL = GetLogicPos( maTopLeft ); Point aUL, aBR;
Point aBR = GetLogicPos( maBottomRight ); mpPreview->GetPreviewLogicRect(aUL, aBR);
mpLeftField->SetValue( aUL.X() ); mpLeftField->SetValue( aUL.X() );
mpTopField->SetValue( aUL.Y() ); mpTopField->SetValue( aUL.Y() );
mpRightField->SetValue( aBR.X() ); mpRightField->SetValue( aBR.X() );
mpBottomField->SetValue( aBR.Y() ); mpBottomField->SetValue( aBR.Y() );
if( ! bSend ) if (!bSend)
return; return;
if( mrSane.IsOpen() ) if( mrSane.IsOpen() )
......
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#ifndef _SVT_SANEDLG_HRC
#define _SVT_SANEDLG_HRC
#define SCAN_AREA_TOP 17
#define SCAN_AREA_LEFT 8
#define PREVIEW_UPPER_LEFT SCAN_AREA_LEFT
#define PREVIEW_UPPER_TOP SCAN_AREA_TOP + 80
#define PREVIEW_WIDTH 113
#define PREVIEW_HEIGHT 160
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -30,24 +30,13 @@ ...@@ -30,24 +30,13 @@
#include <sane.hxx> #include <sane.hxx>
class ScanPreview;
class SaneDlg : public ModalDialog class SaneDlg : public ModalDialog
{ {
private: private:
enum DragDirection { TopLeft, Top, TopRight, Right, BottomRight, Bottom,
BottomLeft, Left };
Sane& mrSane; Sane& mrSane;
Bitmap maPreviewBitmap;
Rectangle maPreviewRect;
Point maTopLeft, maBottomRight;
Point maMinTopLeft, maMaxBottomRight;
bool mbDragEnable;
bool mbIsDragging;
bool mbScanEnabled; bool mbScanEnabled;
bool mbDragDrawn;
DragDirection meDragDirection;
MapMode maMapMode;
Link maOldLink; Link maOldLink;
...@@ -82,7 +71,7 @@ private: ...@@ -82,7 +71,7 @@ private:
SvTreeListBox* mpOptionBox; SvTreeListBox* mpOptionBox;
Window* mpPreview; ScanPreview* mpPreview;
int mnCurrentOption; int mnCurrentOption;
int mnCurrentElement; int mnCurrentElement;
...@@ -111,24 +100,14 @@ private: ...@@ -111,24 +100,14 @@ private:
void EstablishNumericOption(); void EstablishNumericOption();
void EstablishButtonOption(); void EstablishButtonOption();
void DrawRectangles( Point&, Point& );
void DrawDrag();
Point GetPixelPos( const Point& );
Point GetLogicPos( const Point& );
void UpdateScanArea( bool );
// helper // helper
bool SetAdjustedNumericalValue( const char* pOption, double fValue, int nElement = 0 ); bool SetAdjustedNumericalValue( const char* pOption, double fValue, int nElement = 0 );
virtual void Paint( const Rectangle& ) SAL_OVERRIDE;
virtual void MouseMove( const MouseEvent& rMEvt ) SAL_OVERRIDE;
virtual void MouseButtonDown( const MouseEvent& rMEvt ) SAL_OVERRIDE;
virtual void MouseButtonUp( const MouseEvent& rMEvt ) SAL_OVERRIDE;
public: public:
SaneDlg( Window*, Sane&, bool ); SaneDlg( Window*, Sane&, bool );
virtual ~SaneDlg(); virtual ~SaneDlg();
virtual short Execute() SAL_OVERRIDE; virtual short Execute() SAL_OVERRIDE;
void UpdateScanArea( bool );
bool getDoScan() { return doScan;} bool getDoScan() { return doScan;}
}; };
......
...@@ -190,9 +190,11 @@ ...@@ -190,9 +190,11 @@
<property name="top_padding">6</property> <property name="top_padding">6</property>
<property name="left_padding">12</property> <property name="left_padding">12</property>
<child> <child>
<object class="GtkDrawingArea" id="preview"> <object class="scnlo-ScanPreview" id="preview">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="halign">center</property>
<property name="valign">start</property>
<property name="hexpand">True</property> <property name="hexpand">True</property>
<property name="vexpand">True</property> <property name="vexpand">True</property>
</object> </object>
......
...@@ -248,6 +248,10 @@ ...@@ -248,6 +248,10 @@
</properties> </properties>
</glade-widget-class> </glade-widget-class>
<glade-widget-class title="Scan Preview" name="scnlo-ScanPreview"
generic-name="Scan Preview Window" parent="GtkDrawingArea"
icon-name="widget-gtk-drawingarea"/>
<glade-widget-class title="Token Window" name="swuilo-SwTokenWindow" <glade-widget-class title="Token Window" name="swuilo-SwTokenWindow"
generic-name="Token Window" parent="GtkDrawingArea" generic-name="Token Window" parent="GtkDrawingArea"
icon-name="widget-gtk-drawingarea"/> icon-name="widget-gtk-drawingarea"/>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment