PageList.cpp
author viric@mandarina
Thu, 03 Apr 2008 00:16:12 +0200
changeset 1 5b075fa903ae
parent 0 97dd4d2c08b6
permissions -rw-r--r--
Adding a Generate menu item.

#include <wx/wx.h>

#include "PageList.hpp"

BEGIN_EVENT_TABLE(PageList, wxListCtrl)
    EVT_CONTEXT_MENU(PageList::on_context_menu)
END_EVENT_TABLE()


PageList::PageList(wxWindow *parent)
    :wxListCtrl(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize,
            wxLC_REPORT)
{
    InsertColumn(0, _("File"));
    InsertColumn(1, _("Crop area"));
    InsertColumn(2, _("Binarizer"));
    InsertColumn(3, _("Packing"));
}

void
PageList::add_files(const wxArrayString &filenames)
{
    for(unsigned int i=0; i < filenames.GetCount(); ++i)
    {
        wxListItem item;
        item.SetText(filenames[i]);
        item.SetColumn(0);
        long pos = InsertItem(item);
        /* Test */
        SetItem(pos, 1, wxT("test"));
    }
    SetColumnWidth(0, wxLIST_AUTOSIZE);
}

void
PageList::on_context_menu(wxContextMenuEvent &event)
{
    wxString title;

    /* Try to guess what we should apply actions to. */
    if (GetSelectedItemCount() == 0)
    {
        return;
    }
    else if (GetSelectedItemCount() == 1)
    {
        title = GetItemText(GetNextItem(-1, wxLIST_NEXT_ALL,
                    wxLIST_STATE_SELECTED));
    }
    else
    {
        title = _("Selection");
    }
    wxMenu *menu = new wxMenu(title);

    menu->Append(wxID_CLOSE, wxT("Hello"));

    PopupMenu(menu);
}

void
PageList::generate(const wxString &outputfile)
{
    wxMessageDialog w(this, outputfile);
    w.ShowModal();
}