test_main_window.h
Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
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 
00067 
00068 class MainWindow
00069 {
00070 public:
00071     MainWindow();
00072     ~MainWindow();
00073 
00074 
00075 
00076     inline GtkWidget *get_main_window() { return main_window; }
00077 
00078 private:
00079 
00080 
00081     void create();
00082 
00083 
00084     void destory();
00085 
00086 
00087     void connect_event_handlers(GtkWidget *widget);
00088 
00089     void update_window();
00090 
00091     void update_output_device();
00092 
00093 
00094     void handle_page_ready(PagePtr cur_page, unsigned int ref_id);
00095 
00096 
00097     void handle_searching_done(SearchResult ret, PDFSearchCollection* results
00098         , unsigned int ref_id);
00099 
00100 
00101     gboolean on_expose(GtkWidget *widget, GdkEvent *event);
00102 
00103 
00104     gboolean on_configure(GtkWidget *widget, GdkEvent *event);
00105 
00106 
00107     gboolean on_button_press(GtkWidget *widget, GdkEvent *event);
00108 
00109 
00110     gboolean on_button_release(GtkWidget *widget, GdkEvent *event);
00111 
00112 
00113     gboolean on_motion_notify(GtkWidget *widget, GdkEvent *event);
00114 
00115 
00116     gboolean on_key_press(GtkWidget *widget, GdkEvent *event);
00117 
00118 
00119     gboolean on_key_release(GtkWidget *widget, GdkEvent *event);
00120 
00121 
00122     gboolean on_delete(GtkWidget *widget, GdkEvent *event);
00123 
00124     
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         
00155         PDFSearchCollection *data;
00156 
00157         
00158         BoundingRectangles rects;
00159 
00160         
00161         bool b_searching;
00162 
00163         
00164         bool b_display;
00165 
00166         
00167         
00168         std::string cur_pos;
00169 
00170         
00171         unsigned int ref_id;
00172 
00173         
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     
00188     GtkWidget *main_window;
00189 
00190     
00191     typedef gtk::GtkEventSource<MainWindow> EventSource;
00192     EventSource source;
00193 
00194     
00195     GdkGC *gc;
00196 
00197     
00198     GdkDrawable *pixmap;
00199 
00200     
00201     OutputDevice output_dev;
00202 
00203     
00204     PDFController document;
00205 
00206     
00207     int current_page;
00208 
00209     
00210     PagePtr current_page_data;
00211 
00212     
00213     SearchResultsContext search_results;
00214 
00215 };
00216 
00217 }; 
00218 
00219 #endif
00220