wxIScan
wxImagePanel Class Reference

A panel that can display a list of images (e. g. pages) and scroll. More...

#include <wximagepanel.h>

List of all members.

Public Member Functions

 wxImagePanel (wxWindow *poParent, wxWindowID nId=wxID_ANY, const wxPoint &oPos=wxDefaultPosition, const wxSize &oSize=wxDefaultSize, long nStyle=wxHSCROLL|wxVSCROLL|wxSUNKEN_BORDER, const wxString &strName=wxT("wxImagePanel"))
 Standard constructor.
virtual ~wxImagePanel ()
 Virtual destructor.
virtual void Reset ()
 Empty the panel.
virtual void AddImage (wxImage oImage)
 Add images to the panel.
virtual void OnThreadEntry (int nId)
 Create a thumbnail from the corresponding image in another thread.

Protected Attributes

int m_nPanelPagesCount
 The number of the pages in the pages panel.
wxImageHash m_oImageHash
 A hash map to get the image corresponding to event ID in OnThreadEntry().
int m_nPanelPagesBitmapSize
 Side ot the square that the image should fit to after resizing in pixels.
int m_nPanelPagesBitmapSpace
 Space to surround the thumb nail image (padding).

Private Member Functions

void OnThreadExit (wxCommandEvent &oEvent)
 Handle the exit of another thread.

Detailed Description

A panel that can display a list of images (e. g. pages) and scroll.

...

Definition at line 30 of file wximagepanel.h.


Constructor & Destructor Documentation

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

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 34 of file wximagepanel.cpp.

: wxScrolledWindow( poParent, nId, oPos, oSize, nStyle, strName )
{
    // Empty the panel.
    Reset();

    // Reset window settings.
    wxConfigBase *poConfig = wxConfigBase::Get();
    poConfig->SetRecordDefaults();
    poConfig->SetPath( wxT( "/" )  );
    poConfig->SetPath( GetName() );

    // Reset bitmap and spacer size.
    m_nPanelPagesBitmapSize= poConfig->Read(  wxT( "PanelPagesBitmapSize" ),  160 );
    m_nPanelPagesBitmapSpace= poConfig->Read( wxT( "PanelPagesBitmapSpace" ),   6 );
}
wxImagePanel::~wxImagePanel ( ) [virtual]

Virtual destructor.

Definition at line 55 of file wximagepanel.cpp.

References m_nPanelPagesBitmapSize, and m_nPanelPagesBitmapSpace.

{
    // Save configuration data.
    wxConfigBase *poConfig= wxConfigBase::Get();

    poConfig->SetPath( wxT( "/" ) );
    poConfig->SetPath( GetName() );

    // Save bitmap and spacer size.
    poConfig->Write( wxT( "PanelPagesBitmapSize" ), (long)m_nPanelPagesBitmapSize );
    poConfig->Write( wxT( "PanelPagesBitmapSpace" ), (long)m_nPanelPagesBitmapSpace );
}

Member Function Documentation

void wxImagePanel::AddImage ( wxImage  oImage) [virtual]

Add images to the panel.

Parameters:
oImagean image to convert to a thumbnail

Note: I moved all GUI functions from AddImage() to OnThreadExit(). It should therefore be possible to call AddImage() from another (non-GUI-)thread.

Definition at line 70 of file wximagepanel.cpp.

References m_nPanelPagesCount, and m_oImageHash.

Referenced by wxIScanFrame::AddPdfPage().

{
    m_oImageHash[m_nPanelPagesCount]= oImage;
    wxImagePanelThread * poThread=new wxImagePanelThread( this, m_nPanelPagesCount );

    poThread->Create();             // Create the thread instance.
    poThread->SetPriority( 0 );     // Set the thread to the lowest possible priority.
    poThread->Run();                // Run the the thread.
    m_nPanelPagesCount++;
}
void wxImagePanel::OnThreadEntry ( int  nId) [virtual]

Create a thumbnail from the corresponding image in another thread.

Parameters:
nIdID of the to image (in the hash map) to rescale.

Definition at line 83 of file wximagepanel.cpp.

References m_nPanelPagesBitmapSize, and m_oImageHash.

{
    wxImage oImage= m_oImageHash[nId];

    double xfactor= (double)m_nPanelPagesBitmapSize
                    / (double)( ( oImage.GetWidth() > oImage.GetHeight() ) ? oImage.GetWidth() : oImage.GetHeight() );

    if( xfactor < 1.0 )
    {
        oImage.Rescale( (int)( (double)oImage.GetWidth()  * xfactor ),
                        (int)( (double)oImage.GetHeight() * xfactor ),
                        wxIMAGE_QUALITY_HIGH );
        m_oImageHash[nId]= oImage;
    }
}
void wxImagePanel::OnThreadExit ( wxCommandEvent &  oEvent) [private]

Handle the exit of another thread.

Parameters:
oEventEvent containing the ID of the corresponding image.

Delete the corresponding image and adjust the scroll bar(s).

Definition at line 101 of file wximagepanel.cpp.

References m_nPanelPagesBitmapSize, m_nPanelPagesBitmapSpace, m_nPanelPagesCount, and m_oImageHash.

{
    int nId= oEvent.GetInt();

    wxImage oImage= m_oImageHash[nId];

    m_oImageHash.erase( nId );

    wxPoint oStartingPoint( m_nPanelPagesBitmapSpace,
                            m_nPanelPagesBitmapSpace + ( m_nPanelPagesBitmapSpace + m_nPanelPagesBitmapSize ) * nId );

    SetScrollbars( 1, 1,
                   m_nPanelPagesBitmapSpace + m_nPanelPagesBitmapSize + m_nPanelPagesBitmapSpace,
                   m_nPanelPagesBitmapSpace + ( m_nPanelPagesBitmapSpace + m_nPanelPagesBitmapSize ) * m_nPanelPagesCount );

    new wxStaticBitmap( this, wxID_ANY, wxBitmap( oImage ), oStartingPoint );
//    new wxBitmapButton( this, wxID_ANY, wxBitmap( oImage ), oStartingPoint );

#if wxCHECK_VERSION( 2, 9, 0 )
#else  // wxCHECK_VERSION( 2, 9, 0 )
    Scroll( 0, m_nPanelPagesBitmapSpace + ( m_nPanelPagesBitmapSpace + m_nPanelPagesBitmapSize ) * ( m_nPanelPagesCount - 1 ) );
#endif // wxCHECK_VERSION( 2, 9, 0 )
}
virtual void wxImagePanel::Reset ( ) [inline, virtual]

Empty the panel.

Definition at line 53 of file wximagepanel.h.

References m_nPanelPagesCount.

Referenced by wxIScanFrame::OnPdfBeginPdf().

        {
            DestroyChildren();
            SetScrollbars( 1, 1, 1, 1 );
            m_nPanelPagesCount= 0;
        }

Member Data Documentation

Side ot the square that the image should fit to after resizing in pixels.

Definition at line 95 of file wximagepanel.h.

Referenced by OnThreadEntry(), OnThreadExit(), and ~wxImagePanel().

Space to surround the thumb nail image (padding).

Definition at line 96 of file wximagepanel.h.

Referenced by OnThreadExit(), and ~wxImagePanel().

The number of the pages in the pages panel.

Definition at line 91 of file wximagepanel.h.

Referenced by AddImage(), OnThreadExit(), and Reset().

wxImageHash wxImagePanel::m_oImageHash [protected]

A hash map to get the image corresponding to event ID in OnThreadEntry().

Definition at line 92 of file wximagepanel.h.

Referenced by AddImage(), OnThreadEntry(), and OnThreadExit().


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