#include <notepad_doc.h>
Public Member Functions | |
CNotepadDoc () | |
~CNotepadDoc () | |
np_result | open (const gchar *filename) |
np_result | create (const gchar *filename) |
np_result | save_page (const int pageno, bool update_last_read=false) |
np_result | rename (const gchar *filename) |
void | close () |
int | get_num_pages () |
gchar * | get_full_filename () |
gchar * | get_filename_without_dir_and_ext () |
CFileStore * | getFileStore () |
gboolean | get_page_dirty () |
void | insert_page (const int pageno) |
void | add_page (const int pageno) |
void | delete_page (const int pageno) |
void | clear_page (const int pageno) |
gboolean | set_last_read (gint value) |
gint | get_last_read (void) |
void | on_scribble_begin (const int pageno, GCtx &gctx, GdkImage *image, CNPoint &apoint) |
void | on_scribble_move (const int pageno, GCtx &gctx, GdkImage *image, CNPoint &apoint) |
void | on_scribble_end (const int pageno, GCtx &gctx, GdkImage *image, CNPoint &apoint) |
void | on_erase_begin (const int pageno, GCtx &gctx, GdkImage *image, CNPoint &apoint) |
void | on_erase_move (const int pageno, GCtx &gctx, GdkImage *image, CNPoint &apoint) |
void | on_erase_end (const int pageno, GCtx &gctx, GdkImage *image, CNPoint &apoint) |
void | draw_scribble_page (const int pageno, GCtx &gctx, GdkImage *image) |
Definition at line 40 of file notepad_doc.h.
notepad::CNotepadDoc::CNotepadDoc | ( | ) |
Definition at line 39 of file notepad_doc.cpp.
References erscribble_doc_disable_autodelete(), and erscribble_init().
00040 : doc(0) 00041 , page(0) 00042 , stroke(0) 00043 , dirty(FALSE) 00044 , file_store( new CFileStore() ) 00045 { 00046 erscribble_init(); 00047 erscribble_doc_disable_autodelete(TRUE); 00048 }
notepad::CNotepadDoc::~CNotepadDoc | ( | ) |
Definition at line 50 of file notepad_doc.cpp.
References erscribble_uninit().
00051 { 00052 erscribble_uninit(); 00053 delete file_store; 00054 }
void notepad::CNotepadDoc::add_page | ( | const int | pageno | ) |
Definition at line 222 of file notepad_doc.cpp.
References _ScbPage::attributes, erscribble_doc_add_page(), erscribble_page_copy_id(), erscribble_page_new(), _ScbPage::id, LOGPRINTF, _ScbPageStyle::orientation, and _ScbPageAttributes::style.
Referenced by notepad::CNotepadWindow::pageflip_or_create().
00223 { 00224 LOGPRINTF("Append Empty Page!!"); 00225 00226 page = 0; 00227 page = erscribble_page_new(); 00228 ScbPageId pid; 00229 generate_page_id(pid, pageno); 00230 erscribble_page_copy_id(&page->id, &pid); 00231 page->attributes.style.orientation = 0; 00232 erscribble_doc_add_page(doc, page); 00233 page = 0; 00234 stroke = 0; 00235 dirty = TRUE; // changes must be saved 00236 }
void notepad::CNotepadDoc::clear_page | ( | const int | pageno | ) |
Definition at line 265 of file notepad_doc.cpp.
References erscribble_doc_get_page(), erscribble_page_clear_strokes(), and LOGPRINTF.
Referenced by notepad::CNotepadWindow::delete_current_page_impl().
00266 { 00267 ScbPageId pid; 00268 generate_page_id(pid, pageno); 00269 ScbPagePtr thispage = erscribble_doc_get_page(doc, &pid); 00270 if (thispage == 0) 00271 { 00272 LOGPRINTF("no page to erase"); 00273 return; 00274 } 00275 erscribble_page_clear_strokes(thispage); 00276 dirty = TRUE; // changes must be saved 00277 }
void notepad::CNotepadDoc::close | ( | ) |
Definition at line 140 of file notepad_doc.cpp.
References notepad::CFileStore::closeFile(), erscribble_doc_free(), and LOGPRINTF.
Referenced by notepad::CNotepadWindow::~CNotepadWindow().
00141 { 00142 LOGPRINTF("entry"); 00143 00144 if (doc) 00145 { 00146 erscribble_doc_free(doc); 00147 file_store->closeFile(); 00148 doc = 0; 00149 memset(&path, 0, sizeof(path)); 00150 page = 0; 00151 stroke = 0; 00152 } 00153 00154 LOGPRINTF("exit"); 00155 }
np_result notepad::CNotepadDoc::create | ( | const gchar * | filename | ) |
Definition at line 77 of file notepad_doc.cpp.
References notepad::CFileStore::createFile(), erscribble_doc_new_with_database(), notepad::CFileStore::getFile(), LOGPRINTF, notepad::NP_NO_DOCUMENT, and notepad::NP_OK.
Referenced by notepad::CNotepadWindow::init().
00078 { 00079 LOGPRINTF("entry filename='%s'", filename); 00080 00081 g_assert(doc == 0); 00082 00083 np_result result = file_store->createFile(filename); 00084 if (result == NP_OK) 00085 { 00086 doc = erscribble_doc_new_with_database(".", file_store->getFile()); 00087 00088 if (!doc) 00089 { 00090 result = NP_NO_DOCUMENT; 00091 } 00092 } 00093 LOGPRINTF("exit"); 00094 return result; 00095 }
void notepad::CNotepadDoc::delete_page | ( | const int | pageno | ) |
Definition at line 254 of file notepad_doc.cpp.
References erscribble_doc_delete_page(), and LOGPRINTF.
Referenced by notepad::CNotepadWindow::delete_current_page_impl().
00255 { 00256 LOGPRINTF("Deleting page: %d", pageno); 00257 00258 ScbPageId pid; 00259 generate_page_id(pid, pageno); 00260 erscribble_doc_delete_page(doc, &pid); 00261 page = 0; 00262 stroke = 0; 00263 }
void notepad::CNotepadDoc::draw_scribble_page | ( | const int | pageno, | |
GCtx & | gctx, | |||
GdkImage * | image | |||
) |
Definition at line 607 of file notepad_doc.cpp.
References erscribble_doc_get_page(), erscribble_page_get_strokes(), _ScbPageId::id, notepad::ipc_sys_bg_busy(), LOGPRINTF, and _ScbStrokes::strokes.
Referenced by notepad::CNotepadPages::execRenderPage().
00608 { 00609 LOGPRINTF("entry"); 00610 00611 g_assert(image); 00612 00613 // page from page id 00614 ScbPageId pid; 00615 generate_page_id(pid, pageno); 00616 00617 ScbPagePtr thispage = erscribble_doc_get_page(doc, &pid); 00618 if (thispage == 0) 00619 { 00620 LOGPRINTF("page %s not found!", pid.id); 00621 return; 00622 } 00623 00624 // drawing can take a while, dont let device go idle 00625 ipc_sys_bg_busy(TRUE); 00626 00627 ScbStrokesPtr strokes = erscribble_page_get_strokes(thispage); 00628 00629 if (strokes) 00630 { 00631 ScbStrokePtr stroke = NULL; 00632 GList *pstroke = g_list_first(strokes->strokes); 00633 while (pstroke) 00634 { 00635 stroke = (ScbStrokePtr)pstroke->data; 00636 if (stroke) 00637 { 00638 draw_stroke(gctx, image, stroke); 00639 00640 // NOTE zoom not used in notepad, but if do transform with: 00641 // float ratio = z / stroke->attributes.zoom; 00642 // int x1 = (int)(ratio * pts[i].x); 00643 // and scale linesize with gctx.set_line_attributes(calc_line_size(stroke->attributes.size_id, gctx.realzoom, stroke->attributes.zoom)); 00644 // where linesize = (int)(penSize * strokeZoom / dispZoom); 00645 } 00646 pstroke = g_list_next(pstroke); 00647 } 00648 } 00649 00650 ipc_sys_bg_busy(FALSE); 00651 00652 LOGPRINTF("exit"); 00653 }
gchar * notepad::CNotepadDoc::get_filename_without_dir_and_ext | ( | ) |
Definition at line 204 of file notepad_doc.cpp.
References notepad::CFileStore::getFileNameFilePartNoExt().
Referenced by notepad::CNotepadWindow::rename().
gchar * notepad::CNotepadDoc::get_full_filename | ( | ) |
Definition at line 199 of file notepad_doc.cpp.
References notepad::CFileStore::getFilename().
gint notepad::CNotepadDoc::get_last_read | ( | void | ) |
Definition at line 181 of file notepad_doc.cpp.
References notepad::CFileStore::get_last_read_location().
Referenced by notepad::CNotepadWindow::init().
00182 { 00183 if (doc) 00184 { 00185 return file_store->get_last_read_location(); 00186 } 00187 return -1; 00188 }
gint notepad::CNotepadDoc::get_num_pages | ( | ) |
Definition at line 171 of file notepad_doc.cpp.
References erscribble_doc_get_pages().
Referenced by notepad::CNotepadWindow::delete_current_page_impl(), notepad::CNotepadWindow::goto_page(), notepad::CNotepadWindow::init(), notepad::CNotepadWindow::pageflip_or_create(), and notepad::CNotepadWindow::update_page_counter().
00172 { 00173 gint num_pages = 0; 00174 if (doc) 00175 { 00176 num_pages = g_list_length((erscribble_doc_get_pages(doc))->pages); 00177 } 00178 return num_pages; 00179 }
gboolean notepad::CNotepadDoc::get_page_dirty | ( | ) |
Definition at line 97 of file notepad_doc.cpp.
Referenced by notepad::CNotepadWindow::save().
CFileStore * notepad::CNotepadDoc::getFileStore | ( | ) |
Definition at line 209 of file notepad_doc.cpp.
Referenced by notepad::CNotepadWindow::getFilename(), notepad::CNotepadWindow::getLabel(), notepad::CNotepadWindow::quit(), and notepad::CNotepadWindow::save().
void notepad::CNotepadDoc::insert_page | ( | const int | pageno | ) |
Definition at line 238 of file notepad_doc.cpp.
References _ScbPage::attributes, erscribble_doc_insert_page(), erscribble_page_copy_id(), erscribble_page_new(), _ScbPage::id, LOGPRINTF, _ScbPageStyle::orientation, and _ScbPageAttributes::style.
Referenced by notepad::CNotepadWindow::init(), and notepad::CNotepadWindow::insert_page().
00239 { 00240 LOGPRINTF("Insert Empty Page!!"); 00241 00242 page = 0; 00243 page = erscribble_page_new(); 00244 ScbPageId pid; 00245 generate_page_id(pid, pageno); 00246 erscribble_page_copy_id(&page->id, &pid); 00247 page->attributes.style.orientation = 0; 00248 erscribble_doc_insert_page(doc, page); 00249 page = 0; 00250 stroke = 0; 00251 dirty = TRUE; // changes must be saved 00252 }
void notepad::CNotepadDoc::on_erase_begin | ( | const int | pageno, | |
GCtx & | gctx, | |||
GdkImage * | image, | |||
CNPoint & | apoint | |||
) |
Definition at line 509 of file notepad_doc.cpp.
References erscribble_doc_get_page(), erscribble_page_erase_hit_test(), erscribble_page_erase_init(), erscribble_strokes_free(), LOGPRINTF, _ScbDevPoint::point, notepad::CNPoint::storageView(), and _ScbPageEraseCtx::zoom.
Referenced by notepad::CNotepadWindow::erase().
00514 { 00515 LOGPRINTF("entry"); 00516 00517 g_assert(image); 00518 00519 if (pageno > 0) 00520 { 00521 00522 ScbPageId pid; 00523 generate_page_id(pid, pageno); 00524 00525 page = erscribble_doc_get_page(doc, &pid); 00526 if (page == 0) 00527 { 00528 return; 00529 } 00530 00531 // prepare for erasing. 00532 erscribble_page_erase_init(&erase_context); 00533 00534 ScbDevPoint point; 00535 point.point = apoint.storageView(); 00536 erase_context.zoom = 100.0; //notused 00537 ScbStrokesPtr strokes = erscribble_page_erase_hit_test(page, &point, &erase_context); 00538 if (strokes) 00539 { 00540 LOGPRINTF("Erase strokes!"); 00541 00542 // draw 00543 draw_erased_strokes(gctx, image, strokes); 00544 00545 // free 00546 erscribble_strokes_free(strokes); 00547 00548 dirty = TRUE; // changes must be saved 00549 } 00550 } 00551 }
void notepad::CNotepadDoc::on_erase_end | ( | const int | pageno, | |
GCtx & | gctx, | |||
GdkImage * | image, | |||
CNPoint & | apoint | |||
) |
Definition at line 580 of file notepad_doc.cpp.
References erscribble_page_erase_hit_test(), erscribble_strokes_free(), LOGPRINTF, _ScbDevPoint::point, and notepad::CNPoint::storageView().
Referenced by notepad::CNotepadWindow::erase().
00585 { 00586 g_assert(image); 00587 00588 ScbDevPoint point; 00589 point.point = apoint.storageView(); 00590 ScbStrokesPtr strokes = erscribble_page_erase_hit_test(page, &point, &erase_context); 00591 00592 // reset 00593 page = 0; 00594 if (strokes) 00595 { 00596 LOGPRINTF("Erase strokes!"); 00597 //draw 00598 draw_erased_strokes(gctx, image, strokes); 00599 00600 // free 00601 erscribble_strokes_free(strokes); 00602 00603 dirty = TRUE; // changes must be saved 00604 } 00605 }
void notepad::CNotepadDoc::on_erase_move | ( | const int | pageno, | |
GCtx & | gctx, | |||
GdkImage * | image, | |||
CNPoint & | apoint | |||
) |
Definition at line 553 of file notepad_doc.cpp.
References erscribble_page_erase_hit_test(), erscribble_strokes_free(), LOGPRINTF, _ScbDevPoint::point, and notepad::CNPoint::storageView().
Referenced by notepad::CNotepadWindow::erase().
00558 { 00559 g_assert(image); 00560 00561 ScbDevPoint point; 00562 point.point = apoint.storageView(); 00563 00564 //Note: Compares current point with existing lines, so crossings can be missed, 00565 // although comparing linesize is big (5) 00566 ScbStrokesPtr strokes = erscribble_page_erase_hit_test(page, &point, &erase_context); 00567 if (strokes) 00568 { 00569 LOGPRINTF("Erase strokes!"); 00570 // draw 00571 draw_erased_strokes(gctx, image, strokes); 00572 00573 // free 00574 erscribble_strokes_free(strokes); 00575 00576 dirty = TRUE; // changes must be saved 00577 } 00578 }
void notepad::CNotepadDoc::on_scribble_begin | ( | const int | pageno, | |
GCtx & | gctx, | |||
GdkImage * | image, | |||
CNPoint & | apoint | |||
) |
Definition at line 407 of file notepad_doc.cpp.
References _ScbStroke::attributes, _ScbPage::attributes, notepad::CNPoint::deviceView(), ERSCRIBBLE_DEV_COLOR_BLACK, erscribble_doc_get_current_stroke_attributes(), erscribble_doc_get_page(), erscribble_page_add_stroke(), erscribble_page_copy_id(), erscribble_page_new(), erscribble_stroke_add_point(), erscribble_stroke_driver_draw_point(), erscribble_stroke_new_with_attributes(), _ScbPageId::id, _ScbPage::id, notepad::ipc_get_pensize(), LOGPRINTF, _ScbPageStyle::orientation, _ScbDevPoint::point, _ScbDevPoint::pressure, notepad::CNPoint::storageView(), and _ScbPageAttributes::style.
Referenced by notepad::CNotepadWindow::scribble().
00412 { 00413 LOGPRINTF("entry"); 00414 g_assert(image); 00415 00416 if ((pageno > 0) && (page == 0) && (stroke == 0)) 00417 { 00418 ScbPageId pid; 00419 generate_page_id(pid, pageno); 00420 00421 // check page 00422 page = erscribble_doc_get_page(doc, &pid); 00423 if (page == 0) 00424 { 00425 // does not exist, needs to create a new one 00426 page = erscribble_page_new(); 00427 erscribble_page_copy_id(&page->id, &pid); 00428 page->attributes.style.orientation = 0; // portrait, no orientation stored by Notepad app. 00429 LOGPRINTF("created new page %s", pid.id); 00430 } 00431 00432 // check stroke 00433 if (stroke == 0) 00434 { 00435 stroke = erscribble_stroke_new_with_attributes(erscribble_doc_get_current_stroke_attributes(doc)); 00436 stroke->attributes.zoom = 100.0; //notused 00437 stroke->attributes.size_id = ipc_get_pensize(); // pen_size from gconf 00438 stroke->attributes.color = ERSCRIBBLE_DEV_COLOR_BLACK; 00439 erscribble_page_add_stroke(page, stroke); 00440 LOGPRINTF("Created new stroke"); 00441 } 00442 00443 // Add to drawing 00444 ScbDevPoint point; 00445 point.point = apoint.storageView(); 00446 point.pressure = 0; 00447 erscribble_stroke_add_point(stroke, &point); 00448 00449 // draw in display 00450 point.point = apoint.deviceView(); 00451 erscribble_stroke_driver_draw_point(stroke, &point, FALSE); 00452 } 00453 }
void notepad::CNotepadDoc::on_scribble_end | ( | const int | pageno, | |
GCtx & | gctx, | |||
GdkImage * | image, | |||
CNPoint & | apoint | |||
) |
Definition at line 475 of file notepad_doc.cpp.
References notepad::CNPoint::deviceView(), erscribble_doc_add_page(), erscribble_stroke_add_point(), erscribble_stroke_driver_draw_point(), LOGPRINTF, _ScbDevPoint::point, and notepad::CNPoint::storageView().
Referenced by notepad::CNotepadWindow::scribble().
00480 { 00481 LOGPRINTF("End stroke!"); 00482 00483 g_assert(image); 00484 00485 if ( (pageno > 0) && stroke && doc && page) 00486 { 00487 // add to drawing 00488 ScbDevPoint point; 00489 point.point = apoint.storageView(); 00490 erscribble_stroke_add_point(stroke, &point); 00491 00492 // draw on display 00493 point.point = apoint.deviceView(); 00494 erscribble_stroke_driver_draw_point(stroke, &point, TRUE); 00495 00496 // also update gtk drawing to let lines stay after local display update 00497 // because then only the damaged area is redrawn. 00498 // point data 00499 draw_stroke(gctx, image, stroke); 00500 00501 // add & reset 00502 erscribble_doc_add_page(doc, page); 00503 page = 0; 00504 stroke = 0; 00505 } 00506 dirty = TRUE; // changes must be saved 00507 }
void notepad::CNotepadDoc::on_scribble_move | ( | const int | pageno, | |
GCtx & | gctx, | |||
GdkImage * | image, | |||
CNPoint & | apoint | |||
) |
Definition at line 455 of file notepad_doc.cpp.
References notepad::CNPoint::deviceView(), erscribble_stroke_add_point(), erscribble_stroke_driver_draw_point(), _ScbDevPoint::point, and notepad::CNPoint::storageView().
Referenced by notepad::CNotepadWindow::scribble().
00460 { 00461 g_assert(image); 00462 00463 if (stroke) 00464 { 00465 // Add to drawing 00466 ScbDevPoint point; 00467 point.point = apoint.storageView(); 00468 erscribble_stroke_add_point(stroke, &point); 00469 00470 point.point = apoint.deviceView(); 00471 erscribble_stroke_driver_draw_point(stroke, &point, FALSE); 00472 } 00473 }
np_result notepad::CNotepadDoc::open | ( | const gchar * | filename | ) |
Definition at line 56 of file notepad_doc.cpp.
References erscribble_doc_open_with_database(), notepad::CFileStore::getFile(), LOGPRINTF, notepad::NP_NO_DOCUMENT, notepad::NP_OK, and notepad::CFileStore::openFile().
Referenced by notepad::CNotepadWindow::init().
00057 { 00058 LOGPRINTF("entry"); 00059 00060 g_assert(doc == 0); 00061 00062 np_result result = file_store->openFile(filename); 00063 if (result == NP_OK) 00064 { 00065 doc = erscribble_doc_open_with_database(".", file_store->getFile()); 00066 00067 if (!doc) 00068 { 00069 result = NP_NO_DOCUMENT; 00070 } 00071 } 00072 00073 LOGPRINTF("exit"); 00074 return result; 00075 }
np_result notepad::CNotepadDoc::rename | ( | const gchar * | filename | ) |
Definition at line 157 of file notepad_doc.cpp.
References notepad::CFileStore::getFilename(), notepad::CFileStore::getFileNameFilePartNoExt(), notepad::ipc_change_filename(), LOGPRINTF, notepad::NP_NO_FILENAME, and notepad::CFileStore::renameFile().
00158 { 00159 LOGPRINTF("entry"); 00160 g_return_val_if_fail( (new_shortfilename != 0) && (new_shortfilename[0] != '\0'), NP_NO_FILENAME); 00161 00162 np_result result = file_store->renameFile(new_shortfilename); 00163 gchar* my_filename = file_store->getFileNameFilePartNoExt(); 00164 ipc_change_filename(file_store->getFilename(), my_filename); 00165 g_free(my_filename); 00166 00167 LOGPRINTF("exit"); 00168 return result; 00169 }
np_result notepad::CNotepadDoc::save_page | ( | const int | pageno, | |
bool | update_last_read = false | |||
) |
Definition at line 102 of file notepad_doc.cpp.
References ER_OK, erscribble_doc_get_page(), erscribble_doc_save_page(), LOGPRINTF, notepad::NP_NO_DOCUMENT, notepad::NP_OK, notepad::NP_SAVE_FAILED, and set_last_read().
Referenced by notepad::CNotepadWindow::save().
00103 { 00104 LOGPRINTF("entry"); 00105 g_return_val_if_fail(doc != 0, NP_NO_DOCUMENT); 00106 00107 if (dirty == FALSE) 00108 { 00109 LOGPRINTF("exit No changes to save"); 00110 return NP_OK; 00111 } 00112 00113 ScbPageId pid; 00114 generate_page_id(pid, pageno); 00115 ScbPagePtr thispage = erscribble_doc_get_page(doc, &pid); 00116 if (NULL == thispage) 00117 { 00118 LOGPRINTF("exit No page"); 00119 return NP_OK; // no pages yet 00120 } 00121 if (ER_OK != erscribble_doc_save_page(doc, thispage)) 00122 { 00123 LOGPRINTF("exit Saving page failed"); 00124 return NP_SAVE_FAILED; 00125 } 00126 00127 if ( update_last_read ) 00128 { 00129 (void) set_last_read(pageno); 00130 } 00131 00132 //TODO size and date are not updated in global.db here 00133 00134 dirty = FALSE; // changes are saved 00135 00136 LOGPRINTF("exit"); 00137 return NP_OK; 00138 }
gboolean notepad::CNotepadDoc::set_last_read | ( | gint | value | ) |
Definition at line 190 of file notepad_doc.cpp.
References notepad::CFileStore::set_last_read_location().
Referenced by save_page(), and notepad::CNotepadWindow::~CNotepadWindow().
00191 { 00192 if (doc) 00193 { 00194 return file_store->set_last_read_location(value); 00195 } 00196 return FALSE; 00197 }