notepad_pages.h

Go to the documentation of this file.
00001 #ifndef __NOTEPAD_PAGES_H__
00002 #define __NOTEPAD_PAGES_H__
00003 
00004 /**
00005  * File Name  : notepad_pages.h
00006  *
00007  * Description: notepad pages cache class
00008  */
00009 
00010 /*
00011  * This file is part of notepad.
00012  *
00013  * notepad is free software: you can redistribute it and/or modify
00014  * it under the terms of the GNU General Public License as published by
00015  * the Free Software Foundation, either version 2 of the License, or
00016  * (at your option) any later version.
00017  *
00018  * notepad is distributed in the hope that it will be useful,
00019  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00021  * GNU General Public License for more details.
00022  *
00023  * You should have received a copy of the GNU General Public License
00024  * along with this program. If not, see <http://www.gnu.org/licenses/>.
00025  */
00026 
00027 /**
00028  * Copyright (C) 2010 IREX Technologies B.V.
00029  * All rights reserved.
00030  */
00031  
00032 #include <glib.h>
00033 #include <gtk/gtk.h> 
00034 #include <gdk/gdk.h> 
00035 
00036 #include "notepad_utils.h"
00037 #include "notepad_point.h"
00038 #include "notepad_doc.h"
00039 #include "notepad_commandqueue.h"
00040 #include <liberscribble/scb.h>
00041 
00042 
00043 namespace notepad 
00044 {
00045 
00046 #define NPAGES    11 // odd, currentpage +5 and -5
00047 #define NOTFOUND (-1)
00048 
00049     // Context/parameters for rendering scribble page.
00050     struct RenderPageCtx
00051     {
00052         int     pageno;
00053         bool    isCurrent;
00054     };
00055 
00056 
00057     class CNotepadPages
00058     {
00059         private: 
00060 
00061             typedef struct
00062             {
00063                 GdkImage*   image;
00064                 gint        pageno;
00065                 gboolean    dirty;
00066             } NpPage;
00067 
00068 
00069         public:
00070             // object lifecycle
00071             CNotepadPages(); // constructor is not initializing, see init() -- construction of window 
00072             ~CNotepadPages();
00073 
00074             void init(CNotepadDoc* aDoc, GCtx* aCtx, int pageno, GdkVisual* visual = 0);
00075             void stop(); // to end prerenderthread before destruction
00076 
00077         private:
00078             CNotepadPages(const CNotepadPages&);            // no copy 
00079             CNotepadPages& operator=(const CNotepadPages&); // no assignment
00080 
00081         public:
00082             // page functions
00083             void insert_page(const int pageno);
00084             void delete_page(const int pageno);
00085             void clear_page(const int pageno);
00086             void mark_dirty(const int pageno);
00087             void mark_all_dirty();
00088             GdkImage*   get_page(const int pageno);
00089 
00090         private: 
00091             // internals
00092             gint        find_page(const int pageno);
00093             gint        make_room(const int pageno);
00094             gint        remove_from_cache(const gint index);
00095             gint        remove_page_from_cache(const int pageno);
00096             gint        replace_page_at_index(const gint index, const int pageno);
00097             bool        stop_flag;
00098 
00099         private:
00100             // member variables
00101             GdkVisual*      visual;         //< visual for creation of images
00102             NpPage          pages[NPAGES];  //< Page Image cache
00103             CNotepadDoc*    doc;            //< document class
00104             GCtx*           gctx;           //< scribble graphic context
00105             int             current_page;   //< Page currently used.
00106 
00107             // working thread used for executing tasks
00108             CmdQueue        cmd_queue;
00109             CSemaphore      drawsem;
00110             CSemaphore      pages_rw_sem;   //< guards writing in the datastruct
00111 
00112             // executed by thread
00113         public:
00114             bool execRenderPage(RenderPageCtx* ctx);
00115     };
00116 
00117 } // namespace
00118 
00119 #endif // __NOTEPAD_PAGES_H__
Generated by  doxygen 1.6.2-20100208