Initial base with a PageList widget.
authorviric@mandarina
Wed, 02 Apr 2008 21:47:47 +0200
changeset 0 97dd4d2c08b6
child 1 5b075fa903ae
Initial base with a PageList widget.
CMakeLists.txt
MainWindow.cpp
MainWindow.hpp
PageList.cpp
PageList.hpp
main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/CMakeLists.txt	Wed Apr 02 21:47:47 2008 +0200
@@ -0,0 +1,14 @@
+PROJECT(djvumaker)
+
+FIND_PACKAGE(wxWidgets)
+
+IF (wxWidgets_FOUND)
+    INCLUDE(${wxWidgets_USE_FILE})
+ENDIF (wxWidgets_FOUND)
+
+
+ADD_EXECUTABLE(djvumaker 
+    main.cpp
+    MainWindow.cpp
+    PageList.cpp)
+TARGET_LINK_LIBRARIES(djvumaker ${wxWidgets_LIBRARIES})
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MainWindow.cpp	Wed Apr 02 21:47:47 2008 +0200
@@ -0,0 +1,57 @@
+#include <wx/wx.h>
+#include "MainWindow.hpp"
+#include "PageList.hpp"
+
+BEGIN_EVENT_TABLE(MainWindow, wxFrame)
+    EVT_MENU(wxID_OPEN, MainWindow::on_open)
+    EVT_MENU(wxID_CLOSE, MainWindow::on_quit)
+END_EVENT_TABLE()
+
+MainWindow::MainWindow()
+    :wxFrame(0, wxID_ANY, _("wxDjvuMaker"), wxDefaultPosition,
+            wxSize(200,200))
+{
+    create_menus();
+
+    wxBoxSizer *s = new wxBoxSizer(wxVERTICAL);
+
+    _pagelist = new PageList(this);
+
+    s->Add(_pagelist);
+}
+
+
+void
+MainWindow::create_menus()
+{
+    _menubar = new wxMenuBar();
+    _menufile = new wxMenu();
+
+    _menufile->Append(wxID_OPEN, _("&Open"));
+    _menufile->Append(wxID_CLOSE, _("&Quit"));
+
+    _menubar->Append(_menufile, _("&File"));
+
+    SetMenuBar(_menubar);
+}
+
+void
+MainWindow::on_open(wxCommandEvent &event)
+{
+    wxFileDialog fd(this, _("Add pages"), wxT(""),
+            wxT(""), wxT("*.jpg"), wxFD_OPEN | wxFD_MULTIPLE | wxFD_FILE_MUST_EXIST
+            | wxFD_PREVIEW);
+
+    if (fd.ShowModal() == wxID_OK)
+    {
+        wxArrayString files;
+        fd.GetFilenames(files);
+        _pagelist->add_files(files);
+    }
+}
+
+void
+MainWindow::on_quit(wxCommandEvent &event)
+{
+    Close();
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MainWindow.hpp	Wed Apr 02 21:47:47 2008 +0200
@@ -0,0 +1,23 @@
+#include <wx/wx.h>
+
+class PageList;
+
+class MainWindow : public wxFrame
+{
+public:
+    MainWindow();
+
+
+private:
+    void create_menus();
+
+    void on_open(wxCommandEvent &event);
+    void on_quit(wxCommandEvent &event);
+
+    wxMenuBar *_menubar;
+    wxMenu *_menufile;
+
+    PageList *_pagelist;
+
+    DECLARE_EVENT_TABLE()
+};
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PageList.cpp	Wed Apr 02 21:47:47 2008 +0200
@@ -0,0 +1,59 @@
+#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);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PageList.hpp	Wed Apr 02 21:47:47 2008 +0200
@@ -0,0 +1,14 @@
+#include <wx/wx.h>
+
+class PageList : public wxListCtrl
+{
+public:
+    PageList(wxWindow *parent);
+
+    void add_files(const wxArrayString &filenames);
+    void on_context_menu(wxContextMenuEvent &event);
+
+private:
+
+    DECLARE_EVENT_TABLE()
+};
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Apr 02 21:47:47 2008 +0200
@@ -0,0 +1,19 @@
+#include <wx/wx.h>
+
+#include "MainWindow.hpp"
+
+class MyApp : public wxApp
+{
+    public:
+        virtual bool OnInit();
+};
+
+IMPLEMENT_APP(MyApp)
+
+bool MyApp::OnInit()
+{
+    MainWindow *mw = new MainWindow();
+    mw->Show();
+
+    return true;
+}