WS_DATA_ITEM* PL_EDITOR_FRAME::AddPageLayoutItem( int aType )
{
    WS_DATA_ITEM * item = NULL;

    switch( aType )
    {
    case WS_DATA_ITEM::WS_TEXT:
        item = new WS_DATA_ITEM_TEXT( wxT( "Text") );
        break;

    case WS_DATA_ITEM::WS_SEGMENT:
        item = new WS_DATA_ITEM( WS_DATA_ITEM::WS_SEGMENT );
        break;

    case WS_DATA_ITEM::WS_RECT:
        item = new WS_DATA_ITEM( WS_DATA_ITEM::WS_RECT );
        break;

    case WS_DATA_ITEM::WS_POLYPOLYGON:
        item = new WS_DATA_ITEM_POLYGONS();
        break;

    case WS_DATA_ITEM::WS_BITMAP:
    {
        wxFileDialog fileDlg( this, _( "Choose Image" ), wxEmptyString, wxEmptyString,
                              _( "Image Files " ) + wxImage::GetImageExtWildcard(), wxFD_OPEN );

        if( fileDlg.ShowModal() != wxID_OK )
            return NULL;

        wxString fullFilename = fileDlg.GetPath();

        if( !wxFileExists( fullFilename ) )
        {
            wxMessageBox( _( "Couldn't load image from \"%s\"" ), fullFilename );
            break;
        }

        BITMAP_BASE* image = new BITMAP_BASE();

        if( !image->ReadImageFile( fullFilename ) )
        {
            wxMessageBox( _( "Couldn't load image from \"%s\"" ), fullFilename );
            delete image;
            break;
        }

        item = new WS_DATA_ITEM_BITMAP( image );
    }
    break;
    }

    if( item == NULL )
        return NULL;

    WS_DATA_MODEL::GetTheInstance().Append( item );
    item->SyncDrawItems( nullptr, GetGalCanvas()->GetView() );

    return item;
}
/* Add a new item to the page layout item list.
 * aType = WS_TEXT, WS_SEGMENT, WS_RECT, WS_POLYPOLYGON
 */
WORKSHEET_DATAITEM * PL_EDITOR_FRAME::AddPageLayoutItem( int aType, int aIdx )
{
    WORKSHEET_DATAITEM * item = NULL;

    switch( aType )
    {
        case WORKSHEET_DATAITEM::WS_TEXT:
            item = new WORKSHEET_DATAITEM_TEXT( wxT("Text") );
            break;

        case WORKSHEET_DATAITEM::WS_SEGMENT:
            item = new WORKSHEET_DATAITEM( WORKSHEET_DATAITEM::WS_SEGMENT );
            break;

        case WORKSHEET_DATAITEM::WS_RECT:
            item = new WORKSHEET_DATAITEM( WORKSHEET_DATAITEM::WS_RECT );
            break;

        case WORKSHEET_DATAITEM::WS_POLYPOLYGON:
            item = new WORKSHEET_DATAITEM_POLYPOLYGON();
            break;

        case WORKSHEET_DATAITEM::WS_BITMAP:
        {
            wxFileDialog fileDlg( this, _( "Choose Image" ), wxEmptyString, wxEmptyString,
                                  _( "Image Files " ) + wxImage::GetImageExtWildcard(),
                                  wxFD_OPEN );

            if( fileDlg.ShowModal() != wxID_OK )
                return NULL;

            wxString fullFilename = fileDlg.GetPath();

            if( !wxFileExists( fullFilename ) )
            {
                wxMessageBox( _( "Couldn't load image from <%s>" ), GetChars( fullFilename ) );
                break;
            }
            BITMAP_BASE* image = new BITMAP_BASE();

            if( !image->ReadImageFile( fullFilename ) )
            {
                wxMessageBox( _( "Couldn't load image from <%s>" ),
                                 GetChars( fullFilename ) );
                delete image;
                break;
            }
            item = new WORKSHEET_DATAITEM_BITMAP( image );
        }
            break;
    }

    if( item == NULL )
        return NULL;

    WORKSHEET_LAYOUT& pglayout = WORKSHEET_LAYOUT::GetTheInstance();
    pglayout.Insert( item, aIdx );
    RebuildDesignTree();

    return item;
}