00001 /* 00002 * This file is part of liberscribble. 00003 * 00004 * liberscribble is free software: you can redistribute it and/or modify 00005 * it under the terms of the GNU General Public License as published by 00006 * the Free Software Foundation, either version 2 of the License, or 00007 * (at your option) any later version. 00008 * 00009 * liberscribble is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00016 */ 00017 00023 #ifndef SCBDOC_H_ 00024 #define SCBDOC_H_ 00025 00027 // scribble library document definition 00029 00030 #include "scbpath.h" 00031 #include "scbpages.h" 00032 00033 #ifdef __cplusplus 00034 extern "C" 00035 { 00036 #endif 00037 00038 00039 // maintain current state, such as current color / pen size/ pen style 00040 // caller can update its UI widget according to doc state 00041 // 00042 // toolbar cmd ---> current state ---> new style 00043 // | 00044 // -------------> new state 00045 // | 00046 // -------------> update UI by macro 00047 // all platform related function is defined by macro 00048 00049 typedef enum _ScbTBState 00050 { 00051 SCB_TBS_NONE, 00052 SCB_TBS_SCRIBBLE, 00053 SCB_TBS_SELECT_PEN_SIZE, 00054 SCB_TBS_SELECT_LINE_COLOR, 00055 SCB_TBS_ERASE, 00056 SCB_TBS_INVALID 00057 }ScbTBState; 00058 00059 // map a icon to a scribble toolbar state, so that scribble library can handle 00060 // toolbar request 00061 typedef struct _ScbTBSItem 00062 { 00063 ScbTBState state; 00064 int iconId; 00065 }ScbTBSItem; 00066 typedef ScbTBSItem* ScbTBSItemPtr; 00067 00068 typedef struct _ScbDocContext 00069 { 00070 ScbStrokeStyle curStrokeStyle; // current style, in runtime 00071 ScbTBState curState; // current state 00072 GArray * table; // icon and action mapping table 00073 int appId; // current appid 00074 }ScbDocContext; 00075 00076 typedef struct _ScbDoc 00077 { 00078 ScbPath path; 00079 ScbPages pages; 00080 ScbDocContext context; 00081 }ScbDoc; 00082 typedef ScbDoc * ScbDocPtr; 00083 00084 // construct doc 00085 ScbDocPtr scb_doc_new(); 00086 00087 // free 00088 void scb_doc_free(ScbDocPtr doc); 00089 00090 // open the document 00091 ScbDocPtr scb_doc_open(ScbPathPtr ptr); 00092 00093 // make sure exist, try to open it, if not exist or fail, create a new one 00094 ScbDocPtr scb_doc_make_sure_exist(ScbPathPtr ptr); 00095 00096 // save 00097 gboolean scb_doc_save(ScbDocPtr doc); 00098 00099 // saveAs 00100 gboolean scb_doc_saveAs(ScbDocPtr doc, ScbPathPtr ptr); 00101 00102 // composite 00103 ScbPagesPtr scb_doc_get_pages(ScbDocPtr doc); 00104 ScbStrokeStylePtr scb_doc_get_current_stroke_style(ScbDocPtr doc); 00105 00106 // make caller easily to find a page 00107 ScbPagePtr scb_doc_get_page(ScbDocPtr doc, ScbPageIdPtr id); 00108 00109 // here, if duplicated id occurs, do nothing. so user can always 00110 // use add page operation 00111 gboolean scb_doc_add_page(ScbDocPtr doc, ScbPagePtr page); 00112 00113 // partially open/save. not necessary to open the whole file 00114 // From testing, it's not a good idea to open page directly. 00115 // Remove them 00116 // ScbPagePtr scb_doc_open_page_directly(ScbPathPtr ptr, ScbPageIdPtr id); 00117 // gboolean scb_doc_save_page_directly(ScbPathPtr ptr, ScbPagePtr page); 00118 00119 // dump 00120 void scb_doc_dump(ScbDocPtr ptr); 00121 00122 // context and state 00123 void scb_doc_init_context(ScbDocPtr ptr); 00124 void scb_doc_free_context(ScbDocPtr ptr); 00125 void scb_doc_add_map_item(ScbDocPtr doc, const ScbTBSItemPtr ptr); 00126 ScbTBState scb_doc_get_current_state(ScbDocPtr doc); 00127 gboolean scb_state_is_scribble(ScbDocPtr doc); 00128 gboolean scb_state_is_erase(ScbDocPtr doc); 00129 00130 00131 #ifdef __cplusplus 00132 } 00133 #endif 00134 00135 #endif
1.5.6