00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include <gdk/gdkkeysyms.h>
00033 #include <liberdm/display.h>
00034 #include <unistd.h>
00035 #include <signal.h>
00036
00037 #include "ScribbleUI.h"
00038 #include "ScribbleCore.h"
00039 #include "ScribbleIPC.h"
00040 #include "ScribbleLog.h"
00041 #include "ScribbleSignalDeal.h"
00042 #include "ScribbleSaveThread.h"
00043
00044 #include "FileMgr_page.h"
00045 #include "displayUpdate.h"
00046 #include "erbusy.h"
00047 #include "ink_draw.h"
00048
00049
00050 static gboolean g_slideshow_enable = FALSE;
00051 static gint g_slideshow_interval = 10;
00052
00053
00054 static void flushPageBar(PFileManager pFM);
00055 static gboolean on_slideshow_nextpage(gpointer data);
00056
00057
00058 void jump_to_page (PScribbleUICtx pScribbleUICtx)
00059 {
00060 SB_LOGPRINTF("__start__...\n");
00061 erbusy_blink();
00062 if ( 0!= loadPageAndResultImg(pScribbleUICtx) )
00063 {
00064 erbusy_off();
00065 SB_ERRORPRINTF("Error loading page and result image\n");
00066 }
00067 else
00068 {
00069 gtk_widget_queue_draw(pScribbleUICtx->drawing_area);
00070 }
00071 SB_LOGPRINTF("__finish__...\n");
00072 }
00073
00074
00075 void resetCurrentPage(PScribbleUICtx pScribbleUICtx,
00076 const int iNewPageNum)
00077 {
00078 SB_LOGPRINTF("__start__\n");
00079 PFileManager pFM=&pScribbleUICtx->fileManager;
00080 int iOldCurrPage=getCurrPageNo(pFM);
00081 SB_LOGPRINTF("\nold current=%d,wanto=%d\n",iOldCurrPage,iNewPageNum);
00082 if( iNewPageNum==iOldCurrPage )
00083 {
00084 SB_LOGPRINTF("no need to chage page,curr==%d\n",iNewPageNum);
00085 return;
00086 }
00087
00088 savePageAndResultImg(pScribbleUICtx,FALSE);
00089
00090 jumptoScribPage(pFM,iNewPageNum);
00091 int iNewCurrPage=getCurrPageNo(pFM);
00092 SB_LOGPRINTF("\nnew current=%d\n",iNewCurrPage);
00093 if( iOldCurrPage==iNewCurrPage )
00094 {
00095 SB_LOGPRINTF("no need to chage page,last curr==%d\n",iNewCurrPage);
00096 return;
00097 }
00098
00099 SB_LOGPRINTF("will jump to %d\n",getCurrPageNo(pFM));
00100 flushPageBar(pFM);
00101
00102 toolbar_reinit( getTotalPage(pFM) );
00103 jump_to_page(pScribbleUICtx);
00104 SB_LOGPRINTF("__finish__\n");
00105 }
00106
00107
00108 gboolean addOnepage(PScribbleUICtx pScribbleUICtx)
00109 {
00110 PFileManager pFM=&pScribbleUICtx->fileManager;
00111 insertNewPageAfterCurr(pFM);
00112 SB_LOGPRINTF("after insert[total=%d,curropen=%d]\n",
00113 getTotalPage(pFM),getCurrPageNo(pFM));
00114
00115
00116 resetCurrentPage(pScribbleUICtx,getCurrPageNo(pFM)+1);
00117 return TRUE;
00118 }
00119
00120
00121 gboolean delOnepage(PScribbleUICtx pScribbleUICtx)
00122 {
00123 PFileManager pFM=&pScribbleUICtx->fileManager;
00124 if( 0!=deleteCurrPage(pFM) )
00125 {
00126 SB_ERRORPRINTF("del fail\n");
00127 return FALSE;
00128 }
00129 SB_LOGPRINTF("after del[total=%d,curropen=%d]\n",
00130 getTotalPage(pFM),getCurrPageNo(pFM));
00131
00132 flushPageBar(pFM);
00133
00134 toolbar_reinit( getTotalPage(pFM) );
00135
00136 jump_to_page(pScribbleUICtx);
00137 return TRUE;
00138 }
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160 gboolean initPixMap(PScribbleUICtx pScribbleUICtx )
00161 {
00162 SB_LOGPRINTF("____start____\n");
00163 if(pScribbleUICtx->pixmap)
00164 g_object_unref (pScribbleUICtx->pixmap);
00165
00166 GtkWidget* widget=pScribbleUICtx->drawing_area;
00167 pScribbleUICtx->pixmap = gdk_pixmap_new (widget->window,
00168 widget->allocation.width,
00169 widget->allocation.height,
00170 -1);
00171 SB_LOGPRINTF("\nwidth:%d,height=%d\n",
00172 widget->allocation.width,
00173 widget->allocation.height);
00174
00175
00176
00177 ink_setDrawable(pScribbleUICtx->pixmap);
00178 SB_LOGPRINTF("__finish___\n");
00179 return TRUE;
00180 }
00181
00182
00183 static gboolean expose_event( GtkWidget *widget1,
00184 GdkEventExpose *event,
00185 gpointer callback_data )
00186 {
00187 SB_LOGPRINTF("____start____\n");
00188 erbusy_blink();
00189 PScribbleUICtx pScribbleUICtx=(PScribbleUICtx)callback_data;
00190
00191 flushPixMap(pScribbleUICtx);
00192 display_update_request_screen_refresh(MAIN_WINDOW_EXPOSE_LEVEL,NULL);
00193 SB_LOGPRINTF("__finish___\n");
00194 return FALSE;
00195 }
00196
00197 static gboolean button_press_event (GtkWidget *widget,
00198 GdkEventButton *event,
00199 gpointer data)
00200 {
00201
00202 erbusy_blink();
00203 PScribbleUICtx pScribbleUICtx=(PScribbleUICtx)data;
00204 if ((event->button == 1) && (pScribbleUICtx->pixmap != NULL))
00205 {
00206
00207
00208 pScribbleUICtx->pen_down = TRUE;
00209
00210 if( toolbar_is_drawing() && !g_slideshow_enable )
00211 {
00212 core_add_point(pScribbleUICtx,event->x, event->y);
00213 }
00214 else if ( toolbar_is_erasing() )
00215 {
00216
00217 pScribbleUICtx->lastPoint.x=event->x;
00218 pScribbleUICtx->lastPoint.y=event->y;
00219
00220 }
00221 else if( toolbar_is_waitconfirmdel() )
00222 {
00223 toolbar_confirm_delpage();
00224 }
00225 }
00226
00227 return TRUE;
00228 }
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254 void eraseStrokes(PScribbleUICtx pScribbleUICtx,GdkPoint *pcurPoint)
00255 {
00256 PtrInk pdelink=pScribbleUICtx->scribbleCoreCtx.pDelInk;
00257 if( pdelink==NULL) SB_WARNPRINTF("NULL before erase\n");
00258 core_eraseStrokes(pScribbleUICtx,pcurPoint);
00259 }
00260
00261 static gboolean button_release_event (GtkWidget *widget,
00262 GdkEventButton *event,
00263 gpointer data)
00264 {
00265
00266 PScribbleUICtx pScribbleUICtx=(PScribbleUICtx)data;
00267
00268
00269 pScribbleUICtx->pen_down = FALSE;
00270
00271 if( toolbar_is_drawing() && !g_slideshow_enable )
00272 {
00273 core_add_point(pScribbleUICtx,event->x, event->y);
00274 }
00275 else if ( toolbar_is_erasing() )
00276 {
00277 GdkPoint curPoint;
00278 curPoint.x=event->x;
00279 curPoint.y=event->y;
00280 eraseStrokes(pScribbleUICtx,&curPoint);
00281
00282 core_redrawBgAndStrks(pScribbleUICtx);
00283 }
00284 erbusy_off();
00285
00286 return TRUE;
00287 }
00288
00289 static gboolean motion_notify_event (GtkWidget *widget,
00290 GdkEventMotion *event,
00291 gpointer data)
00292 {
00293
00294 PScribbleUICtx pScribbleUICtx=(PScribbleUICtx)data;
00295 if ( ! (event->is_hint)
00296 && (pScribbleUICtx->pen_down)
00297 && (event->x < widget->allocation.width)
00298 && (event->y < widget->allocation.height) )
00299 {
00300 if( toolbar_is_drawing() && !g_slideshow_enable )
00301 {
00302 core_add_point(pScribbleUICtx,event->x, event->y);
00303 }
00304 else if ( toolbar_is_erasing() )
00305 {
00306 GdkPoint curPoint;
00307 curPoint.x=event->x;
00308 curPoint.y=event->y;
00309 eraseStrokes(pScribbleUICtx,&curPoint);
00310 pScribbleUICtx->lastPoint.x=event->x;
00311 pScribbleUICtx->lastPoint.y=event->y;
00312 }
00313 }
00314
00315 return TRUE;
00316 }
00317
00318
00319
00320 guint on_mainWindow_keypress(GtkWidget * widget,
00321 GdkEventKey * event,
00322 gpointer data)
00323 {
00324 SB_LOGPRINTF("on_mainWindow_keypress - event 0x%x\n", event->keyval);
00325
00326 PScribbleUICtx pScribbleUICtx=(PScribbleUICtx)data;
00327 int iCurrPage=getCurrPageNo(&pScribbleUICtx->fileManager);
00328 switch (event->keyval)
00329 {
00330 case GDK_Page_Down:
00331 SB_LOGPRINTF("jumping to the next page\n");
00332 iCurrPage++;
00333 break;
00334 case GDK_F1:
00335 SB_LOGPRINTF("PAGETURN_FORWARD LONG\n");
00336 iCurrPage+=5;
00337 break;
00338 case GDK_Page_Up:
00339 iCurrPage--;
00340 break;
00341 case GDK_F2:
00342 SB_LOGPRINTF("PAGETURN_BACK LONG\n");
00343 iCurrPage-=5;
00344 break;
00345 case GDK_F5:
00346 case GDK_Home:
00347 SB_LOGPRINTF("PAGETURN_HOME,For quitting...\n");
00348 quit(pScribbleUICtx);
00349 return 1;
00350
00351 default:
00352
00353 erbusy_off();
00354 return 1;
00355 }
00356
00357 resetCurrentPage(pScribbleUICtx,iCurrPage);
00358 erbusy_off();
00359 return 1;
00360 }
00361
00362
00363
00364 static gboolean on_slideshow_nextpage(gpointer data)
00365 {
00366 PScribbleUICtx pScribbleUICtx=(PScribbleUICtx)data;
00367 int iCurrPage = getCurrPageNo(&pScribbleUICtx->fileManager);
00368
00369 SB_LOGPRINTF("current page [%d]", iCurrPage);
00370
00371 if (iCurrPage < getTotalPage(&pScribbleUICtx->fileManager))
00372 {
00373 iCurrPage++;
00374 }
00375 else
00376 {
00377 iCurrPage = 1;
00378 }
00379
00380 SB_LOGPRINTF("new page [%d]", iCurrPage);
00381 resetCurrentPage(pScribbleUICtx,iCurrPage);
00382
00383 return TRUE;
00384 }
00385
00386
00398
00399 void quit (gpointer data)
00400 {
00401 SB_LOGPRINTF("__start__\n");
00402
00403
00404 erbusy_blink();
00405 gtk_main_quit();
00406 }
00407
00408
00409 static gboolean flush_points (gpointer data)
00410 {
00411 PScribbleUICtx pScribbleUICtx=(PScribbleUICtx)data;
00412
00413 if( toolbar_is_erasing() )
00414 {
00415 if( pScribbleUICtx->scribbleCoreCtx.pDelInk==NULL)
00416 SB_WARNPRINTF("NULL before flush screen\n");
00417
00418 core_flush_delstroke_onscreen(pScribbleUICtx);
00419 }
00420 else
00421 {
00422 core_process_points ( pScribbleUICtx );
00423 }
00424 return TRUE;
00425 }
00426
00427 static void flushPageBar(PFileManager pFM)
00428 {
00429 SB_LOGPRINTF("totalpage=%d,currentpage=%d\n",getTotalPage(pFM),getCurrPageNo(pFM));
00430 pagebar_set_pagecount(getTotalPage(pFM));
00431 pagebar_goto_page(getCurrPageNo(pFM));
00432 pagebar_redraw();
00433 }
00434
00435 static void initPageBarAndToolBar(ScribbleUICtx *pScribbleUICtx)
00436 {
00437 SB_LOGPRINTF("__start___\n");
00438 erbusy_init();
00439 erbusy_blink();
00440
00441 toolbar_init();
00442 PFileManager pFM=&pScribbleUICtx->fileManager;
00443 toolbar_firstinit( getTotalPage(pFM) );
00444
00445
00446 SB_LOGPRINTF("ER_SCRIBBLE_UA_ID=%d,total page=%d,currpage=%d\n",
00447 ER_SCRIBBLE_UA_ID,
00448 getTotalPage(pFM),
00449 getCurrPageNo(pFM));
00450 pagebar_init();
00451 flushPageBar(pFM);
00452
00453 erbusy_off();
00454 SB_LOGPRINTF("__finish___\n");
00455 }
00456
00457 void printarg(const int argc,char* argv[])
00458 {
00459 printf("\n======paralist========\n");
00460 int i;
00461 for(i=0;i<argc;i++)
00462 {
00463 printf("argv[%d]=%s\n", i,argv[i]);
00464 }
00465 printf("\n======================\n");
00466 }
00467
00468 int parse_args (int argc,
00469 char* argv[],
00470 ScribbleUICtx *pScribbleUICtx)
00471 {
00472 int i, j;
00473
00474
00475 for (i = 1 ; i < argc ; )
00476 {
00477 if (strcmp(argv[i], "--slideshow") == 0)
00478 {
00479 g_slideshow_enable = TRUE;
00480 for (j = i ; j < argc - 1 ; j++)
00481 {
00482 argv[j] = argv[j + 1];
00483 }
00484 argc = argc - 1;
00485 }
00486 else if ( i < argc - 1
00487 && strcmp(argv[i], "--interval") == 0 )
00488 {
00489 j = atoi(argv[i + 1]);
00490 if (j >= 2)
00491 {
00492 g_slideshow_interval = j;
00493 }
00494 for (j = i ; j < argc - 2 ; j++)
00495 {
00496 argv[j] = argv[j + 2];
00497 }
00498 argc = argc - 2;
00499 }
00500 else
00501 {
00502 i++;
00503 }
00504 }
00505
00506
00507 PFileManager pFM=&pScribbleUICtx->fileManager;
00508
00509 if( (3!=argc )
00510 || ( isStrEmpty(argv[1]) && isStrEmpty(argv[2])) )
00511 {
00512 SB_ERRORPRINTF("Usage:%s [manifest] |[tmpimagename]\n", argv[0]);
00513 return -1;
00514 }
00515
00516 if( isStrEmpty(argv[1]) )
00517 {
00518 return initFileManagerByTmpl(pFM,argv[2]);
00519 }
00520
00521 return initFileManagerByManifest(pFM,argv[1]);
00522 }
00523
00524 gboolean initScribbleUICtx(ScribbleUICtx *pScribbleUICtx)
00525 {
00526
00527 memset(pScribbleUICtx,0,sizeof(ScribbleUICtx));
00528 pScribbleUICtx->pen_down= FALSE;
00529 pScribbleUICtx->lastPoint.x=-1;
00530 pScribbleUICtx->lastPoint.y=-1;
00531 return TRUE;
00532 }
00533
00534 int main (int argc, char *argv[])
00535 {
00536 GtkWidget *window;
00537 GtkWidget *vbox;
00538
00539 ScribbleUICtx scribbleUICtx;
00540 guint g_timeout_handler_id = 0;
00541
00542 if(!initScribbleUICtx(&scribbleUICtx))
00543 return -1;
00544
00545
00546 if ( 0!=parse_args(argc, argv,&scribbleUICtx))
00547 return -1;
00548
00549 dealTermSignal(&scribbleUICtx);
00550
00551 g_thread_init(NULL);
00552 gdk_threads_init();
00553
00554 scribbleUICtx.fbdev = open("/dev/fb0", O_RDWR);
00555 if ( -1 == scribbleUICtx.fbdev)
00556 {
00557 SB_ERRORPRINTF("Error opening fb. # mknod /dev/fb0 c 29 0\n");
00558 return -1;
00559 }
00560
00561 SB_LOGPRINTF("version %d\n", 1);
00562 gtk_init (&argc, &argv);
00563
00564 window= gtk_window_new (GTK_WINDOW_TOPLEVEL);
00565 gtk_widget_set_name (window, "Test Input");
00566 if (g_slideshow_enable)
00567 {
00568 gtk_window_fullscreen(GTK_WINDOW(window));
00569 g_timeout_add(g_slideshow_interval * 1000, on_slideshow_nextpage, &scribbleUICtx);
00570 }
00571
00572 vbox = gtk_vbox_new (FALSE, 0);
00573 gtk_container_add (GTK_CONTAINER (window), vbox);
00574 gtk_widget_show (vbox);
00575
00576
00577 scribbleUICtx.drawing_area = gtk_drawing_area_new ();
00578 if (g_slideshow_enable)
00579 {
00580 gtk_widget_set_size_request (GTK_WIDGET (scribbleUICtx.drawing_area),
00581 SCREEN_WIDTH, SCREEN_HEIGHT);
00582 }
00583 else
00584 {
00585 gtk_widget_set_size_request (GTK_WIDGET (scribbleUICtx.drawing_area),
00586 SCREEN_WIDTH, SCREEN_HEIGHT - TOOLBAR_HEIGHT - PAGEBAR_HEIGHT);
00587 }
00588 gtk_box_pack_start (GTK_BOX (vbox), scribbleUICtx.drawing_area, TRUE,
00589 TRUE, 0);
00590 gtk_widget_show (scribbleUICtx.drawing_area);
00591
00592
00593 g_signal_connect (G_OBJECT (scribbleUICtx.drawing_area),
00594 "expose_event",
00595 G_CALLBACK (expose_event),
00596 &scribbleUICtx);
00597
00598
00599 g_signal_connect (G_OBJECT (scribbleUICtx.drawing_area),
00600 "motion_notify_event",
00601 G_CALLBACK (motion_notify_event),
00602 &scribbleUICtx);
00603 g_signal_connect (G_OBJECT (scribbleUICtx.drawing_area),
00604 "button_press_event",
00605 G_CALLBACK (button_press_event),
00606 &scribbleUICtx);
00607 g_signal_connect (G_OBJECT (scribbleUICtx.drawing_area),
00608 "button_release_event",
00609 G_CALLBACK (button_release_event),
00610 &scribbleUICtx);
00611
00612
00613
00614 g_signal_connect (G_OBJECT (window),
00615 "key_press_event",
00616 G_CALLBACK(on_mainWindow_keypress),
00617 &scribbleUICtx);
00618
00619 gtk_widget_set_events (scribbleUICtx.drawing_area,
00620 GDK_EXPOSURE_MASK |
00621 GDK_LEAVE_NOTIFY_MASK |
00622 GDK_BUTTON_PRESS_MASK |
00623 GDK_BUTTON_RELEASE_MASK |
00624 GDK_POINTER_MOTION_MASK );
00625
00626 gtk_widget_set_events (window, GDK_KEY_PRESS_MASK);
00627
00628 g_timeout_handler_id =
00629 g_timeout_add (100, flush_points, &scribbleUICtx);
00630 if (g_timeout_handler_id)
00631 {
00632 gtk_widget_show(window);
00633 installIpcServer(&scribbleUICtx);
00634
00635
00636 initPageBarAndToolBar(&scribbleUICtx);
00637 initPixMap(&scribbleUICtx);
00638
00639 if( 0!=initSaveThread(&scribbleUICtx) )
00640 {
00641 SB_ERRORPRINTF("Error when create save thread\n");
00642 return (-1);
00643 }
00644 jump_to_page(&scribbleUICtx);
00645
00646 gdk_threads_enter();
00647 gtk_main ();
00648 gdk_threads_leave();
00649
00650
00651 stopIpcServer();
00652
00653
00654 savePageAndResultImg(&scribbleUICtx,TRUE);
00655 exitSaveThread();
00656
00657 g_source_remove (g_timeout_handler_id);
00658 }
00659 close (scribbleUICtx.fbdev);
00660 SB_TIMEDISPLAY("main quit...\n");
00661 return (0);
00662 }