wxIScan
wxIViewCanvas Class Reference

The canvas window. More...

#include <wxiviewcanvas.h>

List of all members.

Public Types

enum  {
  wxICANVAS_MOUSE_SELECTION = 1,
  wxICANVAS_MOUSE_SCROLL = 2,
  wxICANVAS_MOUSEWHEEL_SCROLL = 4
}
 wxIViewCanvas options (use SetOptions() function to set). More...

Public Member Functions

 wxIViewCanvas (wxWindow *poParent, wxWindowID nId=wxID_ANY, const wxPoint &oPos=wxDefaultPosition, const wxSize &oSize=wxDefaultSize, long nStyle=wxHSCROLL|wxVSCROLL|wxSUNKEN_BORDER, const wxString &strName=wxT("wxIViewCanvas"))
 Standard constructor.
virtual ~wxIViewCanvas ()
 Virtual destructor.
void OnPaint (wxPaintEvent &oEvent)
 Handler for window (re)painting.
virtual void Paint (wxDC &oDc)
 Repaints the image (using an internal bitmap).
virtual wxBitmap & GetBitmap ()
 Returns the internal bitmap.
virtual void SetBitmap (const wxBitmap &oBitmap)
 Sets the internal bitmap.
void OnSize (wxSizeEvent &oEvent)
 Handle resizing.
void OnTimer (wxTimerEvent &oEvent)
 Handle timer events.
void OnMouse_ (wxMouseEvent &oEvent)
 Handle mouse events (non virtual part, only calls the virtual part, see OnMouse() instead).
virtual void OnMouse (wxMouseEvent &oEvent)
 Handle mouse events (the virtual, customizable part).
virtual void SetOptions (int nOptions)
 Set options for the wxIViewCanvas.
virtual void ClearSelection ()
 Clears up (deletes) the current selection.
virtual wxRect & GetSelection ()
 Gets the selection rectangle.
virtual bool IsSelected ()
 Checks if a selection area exists.

Protected Attributes

int m_nOptions
 Holds extended style info (options).
wxBitmap m_oBitmap
 Internal bitmap object for repainting.
wxTimer m_oTimer
 Timer for delay before sending resizing event to parent window.
wxPoint m_oMousePosBegin
 Save the starting point of a mouse movement.
wxPoint m_oMousePosOld
 Save former mouse position.
wxRect m_oSelection
 Holds the selection.

Detailed Description

The canvas window.

...

Definition at line 109 of file wxiviewcanvas.h.


Member Enumeration Documentation

anonymous enum

wxIViewCanvas options (use SetOptions() function to set).

Enumerator:
wxICANVAS_MOUSE_SELECTION 

Enable selecting a rectangular image region. (Default is OFF.)

wxICANVAS_MOUSE_SCROLL 

Enable scrolling following mouse cursor on right mouse key pressed. (Default is ON.)

wxICANVAS_MOUSEWHEEL_SCROLL 

Enable selecting a rectangular image region. (Default is ON)

Definition at line 199 of file wxiviewcanvas.h.

    {
        wxICANVAS_MOUSE_SELECTION= 1,   ///< Enable selecting a rectangular image region. (Default is OFF.)
        wxICANVAS_MOUSE_SCROLL=  2,     ///< Enable scrolling following mouse cursor on right mouse key pressed. (Default is ON.)
        wxICANVAS_MOUSEWHEEL_SCROLL= 4  ///< Enable selecting a rectangular image region. (Default is ON)
    };

Constructor & Destructor Documentation

wxIViewCanvas::wxIViewCanvas ( wxWindow *  poParent,
wxWindowID  nId = wxID_ANY,
const wxPoint &  oPos = wxDefaultPosition,
const wxSize &  oSize = wxDefaultSize,
long  nStyle = wxHSCROLL | wxVSCROLL | wxSUNKEN_BORDER,
const wxString &  strName = wxT( "wxIViewCanvas" ) 
)

Standard constructor.

Parameters:
poParenta pointer to the dialog windows's parent window.
nIdthe window id, default: 1
oPosthe window position, default: wxDefaultPosition
oSizethe window size, default: wxDefaultSize
nStylewindow style (default: wxHSCROLL | wxVSCROLL | wxSUNKEN_BORDER)
strNameclass name (default: wxT( "wxIViewCanvas" ))

Definition at line 47 of file wxiviewcanvas.cpp.

  : wxScrolledWindow( poParent, nId, oPos, oSize, nStyle, strName ),
    m_nOptions( wxICANVAS_MOUSE_SCROLL | wxICANVAS_MOUSEWHEEL_SCROLL )
{
    // Initialization.
    m_oTimer.SetOwner( this );

    // Reset selection.
    ClearSelection();
}
virtual wxIViewCanvas::~wxIViewCanvas ( ) [inline, virtual]

Virtual destructor.

Definition at line 129 of file wxiviewcanvas.h.

{}

Member Function Documentation

virtual void wxIViewCanvas::ClearSelection ( ) [inline, virtual]

Clears up (deletes) the current selection.

Definition at line 178 of file wxiviewcanvas.h.

References m_oSelection.

Referenced by OnMouse(), and SetBitmap().

    {
//        RefreshRect( m_oSelection );
        Refresh();
        m_oSelection= wxRect( -1, -1, 0, 0 );
    }
virtual wxBitmap& wxIViewCanvas::GetBitmap ( ) [inline, virtual]

Returns the internal bitmap.

Definition at line 142 of file wxiviewcanvas.h.

References m_oBitmap.

{ return m_oBitmap; }
virtual wxRect& wxIViewCanvas::GetSelection ( ) [inline, virtual]

Gets the selection rectangle.

Definition at line 186 of file wxiviewcanvas.h.

References m_oSelection.

Referenced by wxIScanFrame::GetImageSelection(), and wxIScanFrame::OnDocumentZoom().

{ return m_oSelection; };
virtual bool wxIViewCanvas::IsSelected ( ) [inline, virtual]

Checks if a selection area exists.

Definition at line 189 of file wxiviewcanvas.h.

References m_oSelection.

Referenced by wxIScanFrame::GetImageSelection(), wxIScanFrame::OnDocumentZoom(), and Paint().

    {
        return    ( m_oSelection.x >= 0 )
               && ( m_oSelection.y >= 0 )
               && ( m_oSelection.width > 1 )
               && ( m_oSelection.height > 1 );
    }
void wxIViewCanvas::OnMouse ( wxMouseEvent &  oEvent) [virtual]

Handle mouse events (the virtual, customizable part).

Parameters:
oEventContains the mouse event to handle.

OnMouse() handles the following events depending on the options set by a previous call to SetOptions():

  • Scrolling while moving the mouse keeping the right mouse button pressed (wxICANVAS_MOUSE_SCROLL).
  • Scrolling vertically using the mouse wheel. (wxICANVAS_MOUSEWHEEL_SCROLL)
  • Setting a selection rectangle by using a rubber band while keeping the left mouse button pressed. (wxICANVAS_MOUSE_SELECTION)

Definition at line 110 of file wxiviewcanvas.cpp.

References ClearSelection(), wxIViewCanvasSelectedEvent::m_bAlt, wxIViewCanvasSelectedEvent::m_bCtrl, wxIViewCanvasSelectedEvent::m_bMeta, wxIViewCanvasSelectedEvent::m_bShift, m_nOptions, m_oMousePosBegin, m_oMousePosOld, wxIViewCanvasSelectedEvent::m_oSelection, m_oSelection, wxICANVAS_MOUSE_SCROLL, wxICANVAS_MOUSE_SELECTION, and wxICANVAS_MOUSEWHEEL_SCROLL.

Referenced by OnMouse_().

{
    if( m_nOptions & wxICANVAS_MOUSE_SCROLL )
    {
        // Process right mouse button events.
        if( oEvent.RightDown() )
        {
            // Change mouse cursor.
            SetCursor( wxCursor( wxCURSOR_HAND ) );

            // Remember former mouse position.
            m_oMousePosOld= wxPoint( oEvent.GetX(), oEvent.GetY() );
        }
        else if ( oEvent.RightUp() )
        {
            // Reset mouse cursor.
            SetCursor( wxNullCursor );
        }
        else if ( oEvent.Dragging() && oEvent.RightIsDown() )
        {
            // Get mouse position.
            wxPoint oMousePos( oEvent.GetX(), oEvent.GetY() );

            // Get the virtual position of upper left corner
            // (the view start).
            wxPoint nViewStart;

            GetViewStart( &nViewStart.x, &nViewStart.y );

            // Calculate scrolling parameters and scroll image.
            //
            // NOTE: This only works because scroll unit size ist set to
            //       1 pixel per horizontal/vertikal scroll unit in
            //       void wxIViewCanvas::SetBitmap( const wxBitmap &oBitmap ).
            //
            Scroll( nViewStart.x - ( oMousePos.x - m_oMousePosOld.x ),
                    nViewStart.y - ( oMousePos.y - m_oMousePosOld.y ) );

            // Save the mouse position for further use.
            m_oMousePosOld= oMousePos;
        }
    }
    if( m_nOptions & wxICANVAS_MOUSEWHEEL_SCROLL )
    {
        if( oEvent.GetWheelRotation() != 0 )
        {
            // Get the virtual position of upper left corner
            // (the view start).
            wxPoint nViewStart;

            GetViewStart( &nViewStart.x, &nViewStart.y );

            // Calculate scrolling parameters and scroll image.
            //
            // NOTE: This only works because scroll unit size ist set to
            //       1 pixel per horizontal/vertikal scroll unit in
            //       void wxIViewCanvas::SetBitmap( const wxBitmap &oBitmap ).
            //
            Scroll( nViewStart.x,
                    nViewStart.y - oEvent.GetWheelRotation() / 5 );
        }
    }
    if( m_nOptions & wxICANVAS_MOUSE_SELECTION )
    {
        // Process left mouse button events
        if( oEvent.LeftDown() )
        {
            // Clear a posible selection.
            ClearSelection();

            // Change mouse cursor.
            SetCursor( wxCursor( wxCURSOR_CROSS ) );

            // Remember former mouse position.
            m_oMousePosOld= wxPoint( oEvent.GetX(), oEvent.GetY() );

            // Save starting point of the mouse movement.
            m_oMousePosBegin= m_oMousePosOld;
        }
        else if ( oEvent.LeftUp() )
        {
            // Reset mouse cursor.
            SetCursor( wxNullCursor );

            // Get mouse position.
            wxPoint oMousePos( oEvent.GetX(), oEvent.GetY() );

            // Get the virtual position of upper left corner
            // (the view start).
            wxPoint nViewStart;

            GetViewStart( &nViewStart.x, &nViewStart.y );

            // Remember selection.
            m_oSelection= wxRect( nViewStart.x + m_oMousePosBegin.x, nViewStart.y + m_oMousePosBegin.y,
                                  oMousePos.x - m_oMousePosBegin.x + 1, oMousePos.y - m_oMousePosBegin.y + 1 );

            // Do some coordinate corrections.
            if( m_oSelection.width < 0 )
            {
                m_oSelection.x += m_oSelection.width;
                m_oSelection.width= -m_oSelection.width;
            }
            if( m_oSelection.height < 0 )
            {
                m_oSelection.y += m_oSelection.height;
                m_oSelection.height= -m_oSelection.height;
            }
            if( m_oSelection.x < 0 )
            {
                m_oSelection.width += m_oSelection.x;
                m_oSelection.x= 0;
            }
            if( m_oSelection.y < 0 )
            {
                m_oSelection.height += m_oSelection.y;
                m_oSelection.y= 0;
            }

            // Notify the next window in the parent chain that there
            // is a new selection.
            //
            // Note: An event of type wxIViewCanvasSelectedEvent is
            //       propageted to the parent window chain by default.
            wxIViewCanvasSelectedEvent oIViewCanvasSelectedEvent;

            oIViewCanvasSelectedEvent.m_bShift= oEvent.ShiftDown();
            oIViewCanvasSelectedEvent.m_bAlt  = oEvent.AltDown();
            oIViewCanvasSelectedEvent.m_bCtrl = oEvent.ControlDown();
            oIViewCanvasSelectedEvent.m_bMeta = oEvent.MetaDown();
            oIViewCanvasSelectedEvent.m_oSelection= m_oSelection;

            ProcessEvent( oIViewCanvasSelectedEvent );
        }
        else if ( oEvent.Dragging() && oEvent.LeftIsDown() )
        {
            // Get mouse position.
            wxPoint oMousePos( oEvent.GetX(), oEvent.GetY() );

            // ..
            wxClientDC oDc( this );

            oDc.SetPen( *wxBLACK_DASHED_PEN );
            oDc.SetBrush( *wxTRANSPARENT_BRUSH );
            oDc.SetLogicalFunction( wxINVERT );
            oDc.DrawRectangle( m_oMousePosBegin.x, m_oMousePosBegin.y,
                               m_oMousePosOld.x - m_oMousePosBegin.x + 1, m_oMousePosOld.y - m_oMousePosBegin.y + 1 );
            oDc.DrawRectangle( m_oMousePosBegin.x, m_oMousePosBegin.y,
                               oMousePos.x - m_oMousePosBegin.x + 1, oMousePos.y - m_oMousePosBegin.y + 1 );

            // Save the mouse position for further use.
            m_oMousePosOld= oMousePos;
        }
    }
}
void wxIViewCanvas::OnMouse_ ( wxMouseEvent &  oEvent) [inline]

Handle mouse events (non virtual part, only calls the virtual part, see OnMouse() instead).

Parameters:
oEventContains the mouse event to handle.

Definition at line 157 of file wxiviewcanvas.h.

References OnMouse().

{ OnMouse( oEvent ); }
void wxIViewCanvas::OnPaint ( wxPaintEvent &  oEvent)

Handler for window (re)painting.

Creates and prepares a device context and calls Paint( wxDC& oDc ).

Definition at line 64 of file wxiviewcanvas.cpp.

References Paint().

{
    // Create a device context...
    //
    wxPaintDC oDc( this );

    // ... and prepare it even if there is not a bitmap to paint
    // for to repaint at least the window background etc.
    //
    PrepareDC( oDc );

    // Paint (the bitmap).
    Paint( oDc );
}
void wxIViewCanvas::OnSize ( wxSizeEvent &  oEvent)

Handle resizing.

Definition at line 81 of file wxiviewcanvas.cpp.

References m_oTimer, and WXIVIEWCANVASDELAY.

{
    // Check if the timer is running, and...
    if( m_oTimer.IsRunning() )
    {
        // ... stop it.
        m_oTimer.Stop();
    }

    // Create a one shot timer event in 50ms.
    m_oTimer.Start( WXIVIEWCANVASDELAY, wxTIMER_ONE_SHOT );
}
void wxIViewCanvas::OnTimer ( wxTimerEvent &  oEvent)

Handle timer events.

Definition at line 96 of file wxiviewcanvas.cpp.

{
    // Notify the next window in the parent chain that the canvas size
    // has changed.
    //
    // Note: An event of type wxIViewCanvasSizeEvent is propageted
    //       to the parent window chain by default.
    wxIViewCanvasSizeEvent oEvent;

    ProcessEvent( oEvent );
}
void wxIViewCanvas::Paint ( wxDC &  oDc) [virtual]

Repaints the image (using an internal bitmap).

Definition at line 268 of file wxiviewcanvas.cpp.

References IsSelected(), m_oBitmap, and m_oSelection.

Referenced by OnPaint().

{
#if wxCHECK_VERSION( 2, 9, 0 )
    if( oDc.IsOk() )
#else
    if( oDc.Ok() )
#endif // wxCHECK_VERSION( 2, 9, 0 )
    {
        // If there is a bitmap connected to this canvas window (re)paint it.
        if( m_oBitmap.Ok() )
        {
            // Repaint the bitmap.
            oDc.DrawBitmap( m_oBitmap, 0, 0 );

        }

        // If there is a selection repaint the surrounding rectangle.
        if( IsSelected() )
        {
            oDc.SetPen( *wxBLACK_DASHED_PEN );
            oDc.SetBrush( *wxTRANSPARENT_BRUSH );
            oDc.SetLogicalFunction( wxINVERT );
            oDc.DrawRectangle( m_oSelection.x, m_oSelection.y, m_oSelection.width, m_oSelection.height );
        }
    }
}
void wxIViewCanvas::SetBitmap ( const wxBitmap &  oBitmap) [virtual]

Sets the internal bitmap.

Definition at line 297 of file wxiviewcanvas.cpp.

References ClearSelection(), and m_oBitmap.

Referenced by wxIScanFrame::UpdateBitmap().

{
    // Save the (new) bitmap,...
    m_oBitmap= oBitmap;

    // ... adjust the scrollbars, ...
    SetScrollbars( 1, 1, m_oBitmap.GetWidth(), m_oBitmap.GetHeight() );

    // ... clear a posible selection, ...
    ClearSelection();

    // .. and refresh (repaint) the windown content.
    Refresh();
}
virtual void wxIViewCanvas::SetOptions ( int  nOptions) [inline, virtual]

Set options for the wxIViewCanvas.

Definition at line 175 of file wxiviewcanvas.h.

References m_nOptions.

{ m_nOptions= nOptions; }

Member Data Documentation

int wxIViewCanvas::m_nOptions [protected]

Holds extended style info (options).

Definition at line 208 of file wxiviewcanvas.h.

Referenced by OnMouse(), and SetOptions().

wxBitmap wxIViewCanvas::m_oBitmap [protected]

Internal bitmap object for repainting.

Definition at line 209 of file wxiviewcanvas.h.

Referenced by GetBitmap(), Paint(), and SetBitmap().

wxPoint wxIViewCanvas::m_oMousePosBegin [protected]

Save the starting point of a mouse movement.

Definition at line 211 of file wxiviewcanvas.h.

Referenced by OnMouse().

wxPoint wxIViewCanvas::m_oMousePosOld [protected]

Save former mouse position.

Definition at line 212 of file wxiviewcanvas.h.

Referenced by OnMouse().

wxRect wxIViewCanvas::m_oSelection [protected]

Holds the selection.

Definition at line 213 of file wxiviewcanvas.h.

Referenced by ClearSelection(), GetSelection(), IsSelected(), OnMouse(), and Paint().

wxTimer wxIViewCanvas::m_oTimer [protected]

Timer for delay before sending resizing event to parent window.

Definition at line 210 of file wxiviewcanvas.h.

Referenced by OnSize().


The documentation for this class was generated from the following files: