test_main_window.h

Go to the documentation of this file.
00001 /*
00002  * File Name: test_main_window.h
00003  */
00004 
00005 /*
00006  * This file is part of uds-plugin-pdf.
00007  *
00008  * uds-plugin-pdf is free software: you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation, either version 2 of the License, or
00011  * (at your option) any later version.
00012  *
00013  * uds-plugin-pdf is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with this program. If not, see <http://www.gnu.org/licenses/>.
00020  */
00021 
00022 /**
00023  * Copyright (C) 2008 iRex Technologies B.V.
00024  * All rights reserved.
00025  */
00026 
00027 #ifndef TEST_MAIN_WINDOW_H_
00028 #define TEST_MAIN_WINDOW_H_
00029 
00030 #include <gtk/gtk.h>
00031 #include <gdk-pixbuf/gdk-pixbuf.h>
00032 #include <gdk-pixbuf/gdk-pixbuf-core.h>
00033 #include "test_gtk_source.h"
00034 #include "test_output_device.h"
00035 #include "pdf_doc_controller.h"
00036 #include "pdf_page.h"
00037 #include "pdf_collection.h"
00038 #include "pdf_searcher.h"
00039 
00040 namespace test
00041 {
00042 
00043 using namespace pdf;
00044 
00045 struct BoundingRectangles
00046 {
00047     std::vector<GdkRectangle*> rects;
00048 
00049     BoundingRectangles(): rects() {}
00050     ~BoundingRectangles() 
00051     {
00052         release();
00053     }
00054 
00055     void release()
00056     {
00057        typedef std::vector<GdkRectangle*>::iterator Iter;
00058        for(Iter i = rects.begin(); i != rects.end(); ++i)
00059        {
00060            delete *i;
00061        }
00062        rects.clear();
00063     }
00064 };
00065 
00066 /// @brief The main window of the UDS. It's the parent window of 
00067 /// all ViewCtrls' windows.
00068 class MainWindow
00069 {
00070 public:
00071     MainWindow();
00072     ~MainWindow();
00073 
00074     /// @brief Retrieve Gtk widget directly. It serves as parent widget for all 
00075     /// sub views.
00076     inline GtkWidget *get_main_window() { return main_window; }
00077 
00078 private:
00079     /// @brief Create the main widget. The main widget will be 
00080     /// used as container for all ViewCtrl and the sub views.
00081     void create();
00082 
00083     /// @brief Destory the main widget and related resouce.
00084     void destory();
00085 
00086     /// @brief Enable main window to handle events.
00087     void connect_event_handlers(GtkWidget *widget);
00088 
00089     void update_window();
00090 
00091     void update_output_device();
00092 
00093     /// @brief Handler of rendering page
00094     void handle_page_ready(PagePtr cur_page, unsigned int ref_id);
00095 
00096     /// @brief Handler of searching ready
00097     void handle_searching_done(SearchResult ret, PDFSearchCollection* results
00098         , unsigned int ref_id);
00099 
00100     /// @brief Expose event handler.
00101     gboolean on_expose(GtkWidget *widget, GdkEvent *event);
00102 
00103     /// @brief Configure event handler, such as resize
00104     gboolean on_configure(GtkWidget *widget, GdkEvent *event);
00105 
00106     /// @brief Button press event handler.
00107     gboolean on_button_press(GtkWidget *widget, GdkEvent *event);
00108 
00109     /// @brief Button release event handler.
00110     gboolean on_button_release(GtkWidget *widget, GdkEvent *event);
00111 
00112     /// @brief Button move event handler.
00113     gboolean on_motion_notify(GtkWidget *widget, GdkEvent *event);
00114 
00115     /// @brief Key press event handler.
00116     gboolean on_key_press(GtkWidget *widget, GdkEvent *event);
00117 
00118     /// @brief Key release event handler.
00119     gboolean on_key_release(GtkWidget *widget, GdkEvent *event);
00120 
00121     /// @brief Widget delete event handler.
00122     gboolean on_delete(GtkWidget *widget, GdkEvent *event);
00123 
00124     //Test function 
00125 private:
00126     void open_document(const std::string &filename);
00127 
00128     void search_next(bool forward = true);
00129 
00130     void search_all();
00131 
00132     void draw();
00133 
00134     void draw_page_bitmap(const PagePtr page);
00135 
00136     void draw_search_results();
00137 
00138 private:
00139     struct TestBitmap
00140     {
00141         int width;
00142         int height;
00143         int row_stride;
00144         unsigned char *data;
00145 
00146         TestBitmap() : width(0), height(0), row_stride(0), data(0) {}
00147         ~TestBitmap() {}
00148     };
00149 
00150     typedef PDFCollection<PDFSearchDocument*> PDFSearchDocuments;
00151 
00152     struct SearchResultsContext
00153     {
00154         //The data of the search results
00155         PDFSearchCollection *data;
00156 
00157         //The bounding rectangles
00158         BoundingRectangles rects;
00159 
00160         //Flag indicating the searching status
00161         bool b_searching;
00162 
00163         //Flag indicating whether display the searching results
00164         bool b_display;
00165 
00166         //Anchor of current search result
00167         //ONLY for search next
00168         std::string cur_pos;
00169 
00170         //Current reference id
00171         unsigned int ref_id;
00172 
00173         //Forward?
00174         bool b_forward;
00175 
00176         SearchResultsContext() 
00177             : rects()
00178             , b_searching(false)
00179             , b_display(true)
00180             , cur_pos() 
00181             , ref_id(-1)
00182             , b_forward(false) {}
00183         ~SearchResultsContext() {}
00184     };
00185 
00186 private:
00187     //The GTK window.
00188     GtkWidget *main_window;
00189 
00190     //The event source which receives all of the gtk event.
00191     typedef gtk::GtkEventSource<MainWindow> EventSource;
00192     EventSource source;
00193 
00194     // The graphics context.
00195     GdkGC *gc;
00196 
00197     // The buffering pixmap.
00198     GdkDrawable *pixmap;
00199 
00200     // The output device
00201     OutputDevice output_dev;
00202 
00203     // PDF Document
00204     PDFController document;
00205 
00206     // Number of current page
00207     int current_page;
00208 
00209     // Page data of current page
00210     PagePtr current_page_data;
00211 
00212     // The set of search results
00213     SearchResultsContext search_results;
00214 
00215 };
00216 
00217 }; //namespace test
00218 
00219 #endif
00220 
Generated by  doxygen 1.6.2-20100208