Index: apps/plugins/calendar.c =================================================================== --- apps/plugins/calendar.c (revision 18281) +++ apps/plugins/calendar.c (working copy) @@ -27,12 +27,166 @@ PLUGIN_HEADER +#if CONFIG_KEYPAD == RECORDER_PAD +#define CALENDAR_QUIT BUTTON_OFF +#define CALENDAR_SELECT BUTTON_PLAY +#define CALENDAR_NEXT_WEEK BUTTON_DOWN +#define CALENDAR_PREV_WEEK BUTTON_UP +#define CALENDAR_NEXT_DAY BUTTON_RIGHT +#define CALENDAR_PREV_DAY BUTTON_LEFT +#define CALENDAR_NEXT_MONTH (BUTTON_ON|BUTTON_DOWN) +#define CALENDAR_PREV_MONTH (BUTTON_ON|BUTTON_UP) + +#elif CONFIG_KEYPAD == ARCHOS_AV300_PAD +#define CALENDAR_QUIT BUTTON_OFF +#define CALENDAR_SELECT BUTTON_SELECT +#define CALENDAR_NEXT_WEEK BUTTON_DOWN +#define CALENDAR_PREV_WEEK BUTTON_UP +#define CALENDAR_NEXT_DAY BUTTON_RIGHT +#define CALENDAR_PREV_DAY BUTTON_LEFT +#define CALENDAR_NEXT_MONTH (BUTTON_ON|BUTTON_DOWN) +#define CALENDAR_PREV_MONTH (BUTTON_ON|BUTTON_UP) + +#elif CONFIG_KEYPAD == ONDIO_PAD +#define CALENDAR_QUIT BUTTON_OFF +#define CALENDAR_SELECT (BUTTON_MENU|BUTTON_REL) +#define CALENDAR_NEXT_WEEK BUTTON_DOWN +#define CALENDAR_PREV_WEEK BUTTON_UP +#define CALENDAR_NEXT_DAY BUTTON_RIGHT +#define CALENDAR_PREV_DAY BUTTON_LEFT +#define CALENDAR_NEXT_MONTH (BUTTON_MENU|BUTTON_DOWN) +#define CALENDAR_PREV_MONTH (BUTTON_MENU|BUTTON_UP) + +#elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || \ + (CONFIG_KEYPAD == IRIVER_H300_PAD) +#define CALENDAR_QUIT BUTTON_OFF +#define CALENDAR_SELECT BUTTON_SELECT +#define CALENDAR_NEXT_WEEK BUTTON_DOWN +#define CALENDAR_PREV_WEEK BUTTON_UP +#define CALENDAR_NEXT_DAY BUTTON_RIGHT +#define CALENDAR_PREV_DAY BUTTON_LEFT +#define CALENDAR_NEXT_MONTH BUTTON_MODE +#define CALENDAR_PREV_MONTH BUTTON_REC + +#elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \ + (CONFIG_KEYPAD == IPOD_3G_PAD) || \ + (CONFIG_KEYPAD == IPOD_1G2G_PAD) +#define CALENDAR_QUIT (BUTTON_SELECT|BUTTON_MENU) +#define CALENDAR_SELECT (BUTTON_SELECT|BUTTON_PLAY) +#define CALENDAR_NEXT_WEEK BUTTON_SCROLL_FWD +#define CALENDAR_PREV_WEEK BUTTON_SCROLL_BACK +#define CALENDAR_NEXT_DAY BUTTON_RIGHT +#define CALENDAR_PREV_DAY BUTTON_LEFT +#define CALENDAR_NEXT_MONTH BUTTON_PLAY +#define CALENDAR_PREV_MONTH BUTTON_MENU + +#elif (CONFIG_KEYPAD == IAUDIO_X5M5_PAD) +#define CALENDAR_QUIT BUTTON_POWER +#define CALENDAR_SELECT BUTTON_SELECT +#define CALENDAR_NEXT_WEEK BUTTON_DOWN +#define CALENDAR_PREV_WEEK BUTTON_UP +#define CALENDAR_NEXT_DAY BUTTON_RIGHT +#define CALENDAR_PREV_DAY BUTTON_LEFT +#define CALENDAR_NEXT_MONTH (BUTTON_PLAY|BUTTON_DOWN) +#define CALENDAR_PREV_MONTH (BUTTON_PLAY|BUTTON_UP) + +#elif CONFIG_KEYPAD == GIGABEAT_PAD +#define CALENDAR_QUIT BUTTON_POWER +#define CALENDAR_SELECT BUTTON_SELECT +#define CALENDAR_NEXT_WEEK BUTTON_DOWN +#define CALENDAR_PREV_WEEK BUTTON_UP +#define CALENDAR_NEXT_DAY BUTTON_RIGHT +#define CALENDAR_PREV_DAY BUTTON_LEFT +#define CALENDAR_NEXT_MONTH BUTTON_VOL_DOWN +#define CALENDAR_PREV_MONTH BUTTON_VOL_UP + +#elif CONFIG_KEYPAD == SANSA_E200_PAD +#define CALENDAR_QUIT BUTTON_POWER +#define CALENDAR_SELECT BUTTON_SELECT +#define CALENDAR_NEXT_WEEK BUTTON_SCROLL_FWD +#define CALENDAR_PREV_WEEK BUTTON_SCROLL_BACK +#define CALENDAR_NEXT_DAY BUTTON_RIGHT +#define CALENDAR_PREV_DAY BUTTON_LEFT +#define CALENDAR_NEXT_MONTH BUTTON_DOWN +#define CALENDAR_PREV_MONTH BUTTON_UP + +#elif CONFIG_KEYPAD == SANSA_C200_PAD +#define CALENDAR_QUIT BUTTON_POWER +#define CALENDAR_SELECT BUTTON_SELECT +#define CALENDAR_NEXT_WEEK BUTTON_DOWN +#define CALENDAR_PREV_WEEK BUTTON_UP +#define CALENDAR_NEXT_DAY BUTTON_RIGHT +#define CALENDAR_PREV_DAY BUTTON_LEFT +#define CALENDAR_NEXT_MONTH BUTTON_VOL_UP +#define CALENDAR_PREV_MONTH BUTTON_VOL_DOWN + +#elif CONFIG_KEYPAD == IRIVER_H10_PAD +#define CALENDAR_QUIT BUTTON_POWER +#define CALENDAR_SELECT BUTTON_PLAY +#define CALENDAR_NEXT_WEEK BUTTON_SCROLL_DOWN +#define CALENDAR_PREV_WEEK BUTTON_SCROLL_UP +#define CALENDAR_NEXT_DAY BUTTON_RIGHT +#define CALENDAR_PREV_DAY BUTTON_LEFT +#define CALENDAR_NEXT_MONTH BUTTON_FF +#define CALENDAR_PREV_MONTH BUTTON_REW + +#elif CONFIG_KEYPAD == GIGABEAT_S_PAD +#define CALENDAR_QUIT BUTTON_BACK +#define CALENDAR_SELECT BUTTON_SELECT +#define CALENDAR_NEXT_WEEK BUTTON_DOWN +#define CALENDAR_PREV_WEEK BUTTON_UP +#define CALENDAR_NEXT_DAY BUTTON_RIGHT +#define CALENDAR_PREV_DAY BUTTON_LEFT +#define CALENDAR_NEXT_MONTH BUTTON_NEXT +#define CALENDAR_PREV_MONTH BUTTON_PREV + +#elif CONFIG_KEYPAD == MROBE100_PAD +#define CALENDAR_QUIT BUTTON_POWER +#define CALENDAR_SELECT BUTTON_SELECT +#define CALENDAR_NEXT_WEEK BUTTON_DOWN +#define CALENDAR_PREV_WEEK BUTTON_UP +#define CALENDAR_NEXT_DAY BUTTON_RIGHT +#define CALENDAR_PREV_DAY BUTTON_LEFT +#define CALENDAR_NEXT_MONTH (BUTTON_MENU|BUTTON_DOWN) +#define CALENDAR_PREV_MONTH (BUTTON_MENU|BUTTON_UP) + +#elif CONFIG_KEYPAD == IAUDIO_M3_PAD +#define CALENDAR_QUIT BUTTON_RC_REC +#define CALENDAR_SELECT BUTTON_RC_PLAY +#define CALENDAR_NEXT_WEEK BUTTON_RC_VOL_DOWN +#define CALENDAR_PREV_WEEK BUTTON_RC_VOL_UP +#define CALENDAR_NEXT_DAY BUTTON_RC_FF +#define CALENDAR_PREV_DAY BUTTON_RC_REW +#define CALENDAR_NEXT_MONTH BUTTON_RC_MODE +#define CALENDAR_PREV_MONTH BUTTON_RC_MENU + +#elif (CONFIG_KEYPAD == COWOND2_PAD) +#define CALENDAR_QUIT BUTTON_POWER +#define CALENDAR_SELECT BUTTON_CENTER +#define CALENDAR_NEXT_WEEK BUTTON_DOWN +#define CALENDAR_PREV_WEEK BUTTON_UP +#define CALENDAR_NEXT_DAY BUTTON_RIGHT +#define CALENDAR_PREV_DAY BUTTON_LEFT +#define CALENDAR_NEXT_MONTH BUTTON_BOTTOMRIGHT +#define CALENDAR_PREV_MONTH BUTTON_BOTTOMLEFT + +#else +#error "No keypad setting." +#endif + +#if (LCD_WIDTH >= 160) && (LCD_HEIGHT >= 128) +#define DRAW_LINES 1 +#endif + +#define X_OFFSET ((LCD_WIDTH%7)/2) +#define Y_OFFSET 5 + static const struct plugin_api* rb; static bool leap_year; static int days_in_month[2][13] = { - {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, - {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, + {31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, + {31, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, }; struct today { @@ -70,6 +224,8 @@ } +static char fonth, fontw; +static int hspace = LCD_WIDTH / 7, vspace = LCD_HEIGHT / 7; static void calendar_init(struct today *today, struct shown *shown) { int w,h; @@ -83,7 +239,15 @@ { rb->lcd_setfont(FONT_SYSFIXED); use_system_font = true; + fonth = 8; + fontw = 6; } + else + { + fonth = h; + fontw = w; + } + vspace = (LCD_HEIGHT-Y_OFFSET-3-fonth) / 6; rb->lcd_clear_display(); #if CONFIG_RTC tm = rb->get_time(); @@ -91,10 +255,6 @@ today->year = 2000+tm->tm_year%100; today->wday = tm->tm_wday-1; today->mday = tm->tm_mday; -#ifdef SIMULATOR - today->wday = 3; - today->mday = 13; -#endif shown->mday = today->mday; shown->mon = today->mon; shown->year = today->year; @@ -104,27 +264,32 @@ leap_year = is_leap_year(shown->year); } -static int space = LCD_WIDTH / 7; static void draw_headers(void) { - int i,w,h; + int i; +#if LCD_WIDTH >= 220 + char *Dayname[7] = {"Mon","Tue","Wed","Thu","Fri","Sat","Sun"}; +#else char *Dayname[7] = {"M","T","W","T","F","S","S"}; - int ws = 2; - rb->lcd_getstringsize("A",&w,&h); - for (i = 0; i < 8;) +#endif + int x = X_OFFSET; + for (i = 0; i < 7;) { - rb->lcd_putsxy(ws, 0 , Dayname[i++]); - ws += space; +#ifdef DRAW_LINES + if(i!=0) + rb->lcd_vline(x-1, 0, fonth); +#endif + rb->lcd_putsxy(x, 0 , Dayname[i++]); + x += hspace; } - rb->lcd_hline(0, LCD_WIDTH-1 ,h); + rb->lcd_hline(0, LCD_WIDTH-1, fonth); } -static bool day_has_memo[31]; -static bool wday_has_memo[6]; +static bool day_has_memo[32]; +static bool wday_has_memo[7]; static void draw_calendar(struct shown *shown) { - int w,h; - int ws,row,pos,days_per_month,j; + int x,y,pos,days_per_month,j; char buffer[9]; char *Monthname[] = { "Jan", @@ -140,42 +305,60 @@ "Nov", "Dec" }; - rb->lcd_getstringsize("A",&w,&h); + if(use_system_font) + rb->lcd_setfont(FONT_SYSFIXED); rb->lcd_clear_display(); draw_headers(); if (shown->firstday > 6) shown->firstday -= 7; - row = 1; pos = shown->firstday; days_per_month = days_in_month[leap_year][shown->mon]; - ws = 2 + (pos * space); + x = X_OFFSET + (pos * hspace); + y = Y_OFFSET + fonth; +#ifdef DRAW_LINES + if(pos > 0) + rb->lcd_vline(x-1, y, y+vspace-1); +#endif for (j = 0; j < days_per_month;) { if ( (day_has_memo[++j]) || (wday_has_memo[pos]) ) - rb->snprintf(buffer,4,"%02d.", j); + rb->snprintf(buffer,4,"%02d#", j); else rb->snprintf(buffer,4,"%02d", j); - rb->lcd_putsxy(ws, (row * h) + 5 ,buffer); + rb->lcd_putsxy(x, y, buffer); if (shown->mday == j) { rb->lcd_set_drawmode(DRMODE_COMPLEMENT); - rb->lcd_fillrect(ws, row*h+5, space, h); + rb->lcd_fillrect(x, y, hspace, vspace); rb->lcd_set_drawmode(DRMODE_SOLID); shown->wday = pos; } - ws += space; + x += hspace; pos++; if (pos >= 7) { - row++; pos = 0; - ws = 2; + x = X_OFFSET; + y += vspace; +#ifdef DRAW_LINES + rb->lcd_hline(0, LCD_WIDTH-1, y-1); +#endif } +#ifdef DRAW_LINES + else + { + rb->lcd_vline(x-1, y, y+vspace-1); + } +#endif } - rb->lcd_vline(60,LCD_HEIGHT-h-3,LCD_HEIGHT-1); - rb->lcd_hline(60,LCD_WIDTH-1,LCD_HEIGHT-h-3); - rb->snprintf(buffer,9,"%s %04d",Monthname[shown->mon-1],shown->year); - rb->lcd_putsxy(62,(LCD_HEIGHT-h-1),buffer); +#ifdef DRAW_LINES + if (pos != 0) + rb->lcd_hline(0, X_OFFSET+pos*hspace-1, y+vspace-1); +#endif + rb->lcd_vline(LCD_WIDTH-fontw*8-10, LCD_HEIGHT-fonth-3, LCD_HEIGHT-1); + rb->lcd_hline(LCD_WIDTH-fontw*8-10, LCD_WIDTH-1, LCD_HEIGHT-fonth-3); + rb->snprintf(buffer, 9, "%s %04d", Monthname[shown->mon-1], shown->year); + rb->lcd_putsxy(LCD_WIDTH-fontw*8-8, LCD_HEIGHT-fonth-1, buffer); shown->lastday = pos; rb->lcd_update(); } @@ -198,23 +381,12 @@ static void load_memo(struct shown *shown) { - int i, k, fp; + int k, fp; bool exit = false; - char temp_memo1[2]; - char temp_memo2[3]; - char temp_memo4[5]; + char temp_memo[5]; + temp_memo[4] = 0; for (k = 0; k < memos_in_memory; k++) - { - memos[k].day = 0; - memos[k].month = 0; - memos[k].file_pointer_start = 0; - memos[k].file_pointer_end = 0; - memos[k].year = 0; - memos[k].type = 0; - memos[k].wday = 0; - for (i = 0; i <= MAX_CHAR_MEMO_LEN; i++) - rb->strcpy(&memos[k].message[i],""); - } + rb->memset(&memos[k], 0, sizeof(memos[0])); for (k = 1; k < 32; k++) day_has_memo[k] = false; for (k = 0; k < 7; k++) @@ -229,35 +401,29 @@ { memos[memos_in_memory].file_pointer_start = rb->lseek(fp, 0, SEEK_CUR); - if (rb->read(fp, temp_memo2, 2) == 2) - memos[memos_in_memory].day = rb->atoi(&temp_memo2[0]); + if (rb->read(fp, temp_memo+2, 2) == 2) + memos[memos_in_memory].day = rb->atoi(temp_memo+2); else memos[memos_in_memory].day = 0; - if (rb->read(fp, temp_memo2, 2) == 2) - memos[memos_in_memory].month = rb->atoi(&temp_memo2[0]); + if (rb->read(fp, temp_memo+2, 2) == 2) + memos[memos_in_memory].month = rb->atoi(temp_memo+2); else memos[memos_in_memory].month = 0; - if (rb->read(fp, temp_memo4, 4) == 4) - memos[memos_in_memory].year = rb->atoi(&temp_memo4[0]); + if (rb->read(fp, temp_memo, 4) == 4) + memos[memos_in_memory].year = rb->atoi(temp_memo); else memos[memos_in_memory].year = 0; - /* as the year returned is sometimes yearmonth, ie if yr should = - 2003, and month = 06, then it returns 200306 */ - if (memos[memos_in_memory].year > (shown->year * 10)) - memos[memos_in_memory].year = (memos[memos_in_memory].year - - memos[memos_in_memory].month) / - 100; - if (rb->read(fp, temp_memo1, 1) == 1) - memos[memos_in_memory].wday = rb->atoi(&temp_memo1[0]); + if (rb->read(fp, temp_memo+3, 1) == 1) + memos[memos_in_memory].wday = rb->atoi(temp_memo+3); else memos[memos_in_memory].wday = 0; - if (rb->read(fp, temp_memo1, 1) == 1) - memos[memos_in_memory].type = rb->atoi(&temp_memo1[0]); + if (rb->read(fp, temp_memo+3, 1) == 1) + memos[memos_in_memory].type = rb->atoi(temp_memo+3); else memos[memos_in_memory].type = 0; for (k = 0; k <= count; k++) { - if (rb->read(fp, temp_memo1, 1) == 1) + if (rb->read(fp, temp_memo, 1) == 1) { if ( (memos[memos_in_memory].type < 2) @@ -266,7 +432,7 @@ (memos[memos_in_memory].type == 2) && (memos[memos_in_memory].month == shown->mon) - ) + ) || ( (memos[memos_in_memory].type > 2) @@ -274,10 +440,10 @@ (memos[memos_in_memory].month == shown->mon) && (memos[memos_in_memory].year == shown->year) - ) ) + ) { - if (temp_memo1[0] == '\n') + if (temp_memo[0] == '\n') { if (memos[memos_in_memory].type > 0) day_has_memo[memos[memos_in_memory].day] = @@ -288,23 +454,17 @@ memos[memos_in_memory++].file_pointer_end = rb->lseek(fp, 0, SEEK_CUR); } - else if ( (temp_memo1[0] != '\r') && - (temp_memo1[0] != '\t') ) - memos[memos_in_memory].message[k] = temp_memo1[0]; + else if ( (temp_memo[0] != '\r') && + (temp_memo[0] != '\t') && + k < MAX_CHAR_MEMO_LEN ) + memos[memos_in_memory].message[k] = temp_memo[0]; } - if (temp_memo1[0] == '\n') + if (temp_memo[0] == '\n') break; } else { - memos[memos_in_memory].day = 0; - memos[memos_in_memory].month = 0; - memos[memos_in_memory].file_pointer_start = 0; - memos[memos_in_memory].file_pointer_end = 0; - memos[memos_in_memory].year = 0; - memos[memos_in_memory].type = 0; - memos[memos_in_memory].wday = 0; - rb->strcpy(&memos[memos_in_memory].message[0], ""); + rb->memset(&memos[memos_in_memory], 0, sizeof(memos[0])); exit = true; break; } @@ -340,24 +500,14 @@ memos[changed].message); } rb->lseek(fp, memos[changed].file_pointer_end, SEEK_SET); - for (i = memos[changed].file_pointer_end; - i < rb->filesize(fp); i++) + while(rb->read(fp, temp, 1) == 1) { - rb->read(fp, temp, 1); rb->write(fq,temp,1); } rb->close(fp); - fp = rb->creat(ROCKBOX_DIR "/.memo"); - rb->lseek(fp, 0, SEEK_SET); - rb->lseek(fq, 0, SEEK_SET); - for (i = 0; i < rb->filesize(fq); i++) - { - rb->read(fq, temp, 1); - rb->write(fp,temp,1); - } - rb->close(fp); rb->close(fq); - rb->remove(ROCKBOX_DIR "/~temp"); + rb->remove(ROCKBOX_DIR "/.memo"); + rb->rename(ROCKBOX_DIR "/~temp", ROCKBOX_DIR "/.memo"); load_memo(shown); return true; } @@ -375,7 +525,7 @@ sizeof memos[memos_in_memory].message) != -1) { if (rb->strlen(memos[memos_in_memory].message)) - { + { memos[memos_in_memory].file_pointer_start = 0; memos[memos_in_memory].file_pointer_end = 0; memos[memos_in_memory].day = shown->mday; @@ -386,17 +536,10 @@ if (save_memo(memos_in_memory,true,shown)) { saved = true; - memos_in_memory++; } else { - memos[memos_in_memory].file_pointer_start = 0; - memos[memos_in_memory].file_pointer_end = 0; - memos[memos_in_memory].day = 0; - memos[memos_in_memory].month = 0; - memos[memos_in_memory].year = 0; - memos[memos_in_memory].type = 0; - memos[memos_in_memory].wday = 0; + rb->memset(&memos[memos_in_memory], 0, sizeof(memos[0])); } } } @@ -404,141 +547,158 @@ if(use_system_font) rb->lcd_setfont(FONT_SYSFIXED); if (saved) - rb->lcd_puts(0,0,"Event added"); + rb->splash(HZ,"Event added"); else - rb->lcd_puts(0,0,"Event not added"); - rb->lcd_update(); - rb->sleep(HZ/2); + rb->splash(HZ,"Event NOT added"); } +static int edit_menu_cb(int action, const struct menu_item_ex *this_item) +{ + (void) this_item; + if (action == ACTION_REQUEST_MENUITEM && memos_in_shown_memory <= 0) + return ACTION_EXIT_MENUITEM; + return action; +} + static bool edit_memo(int change, struct shown *shown) { bool exit = false; - int button; - + int selected = 0; + + MENUITEM_RETURNVALUE(edit_menu_remove, "remove", 0, + edit_menu_cb, Icon_NOICON); + MENUITEM_RETURNVALUE(edit_menu_edit, "edit", 1, + edit_menu_cb, Icon_NOICON); + MENUITEM_RETURNVALUE(edit_menu_new, "New", 2, + NULL, Icon_NOICON); + MENUITEM_RETURNVALUE(edit_menu_weekly, "weekly", 3, + NULL, Icon_NOICON); + MENUITEM_RETURNVALUE(edit_menu_monthly, "monthly", 4, + NULL, Icon_NOICON); + MENUITEM_RETURNVALUE(edit_menu_annually, "annually", 5, + NULL, Icon_NOICON); + MENUITEM_RETURNVALUE(edit_menu_oneoff, "one off", 6, + NULL, Icon_NOICON); + MENUITEM_RETURNVALUE(edit_menu_return, "Return", 7, + NULL, Icon_NOICON); + + MAKE_MENU(edit_menu, "Edit menu", + NULL, Icon_NOICON, + &edit_menu_remove, &edit_menu_edit, &edit_menu_new, + &edit_menu_weekly, &edit_menu_monthly, &edit_menu_annually, + &edit_menu_oneoff, &edit_menu_return); + while (!exit) { - rb->lcd_clear_display(); - if (memos_in_shown_memory > 0) + switch (rb->do_menu(&edit_menu, &selected, NULL, false)) { - rb->lcd_puts(0,0,"Remove : Up"); - rb->lcd_puts(0,1,"Edit : Down"); - rb->lcd_puts(0,2,"New :"); - rb->lcd_puts(2,3,"weekly : Left"); - rb->lcd_puts(2,4,"monthly : Play"); - rb->lcd_puts(2,5,"annually : Right"); - rb->lcd_puts(2,6,"one off : On"); - } - else - { - rb->lcd_puts(0,0,"New :"); - rb->lcd_puts(2,1,"weekly : Left"); - rb->lcd_puts(2,2,"monthly : Play"); - rb->lcd_puts(2,3,"anualy : Right"); - rb->lcd_puts(2,4,"one off : On"); - } - rb->lcd_update(); - button = rb->button_get(true); - switch (button) - { - case BUTTON_OFF: + case 0: /* remove */ + save_memo(pointer_array[change],false,shown); return false; - case BUTTON_LEFT: + case 1: /* edit */ + if(rb->kbd_input(memos[pointer_array[change]].message, + sizeof memos[pointer_array[change]].message) != -1) + save_memo(pointer_array[change],true,shown); + return false; + + case 3: add_memo(shown,0); return false; - case BUTTON_PLAY: + case 4: add_memo(shown,1); return false; - case BUTTON_RIGHT: + case 5: add_memo(shown,2); return false; - case BUTTON_ON: + case 6: add_memo(shown,3); return false; - case BUTTON_DOWN: - if (memos_in_shown_memory > 0) - { - if(rb->kbd_input(memos[pointer_array[change]].message, - sizeof memos[pointer_array[change]].message) != -1) - save_memo(pointer_array[change],true,shown); - if(use_system_font) - rb->lcd_setfont(FONT_SYSFIXED); - exit = true; - } - break; + case 7: + return false; - case BUTTON_UP: - if (memos_in_shown_memory > 0) - { - save_memo(pointer_array[change],false,shown); - exit = true; - } - break; + case GO_TO_PREVIOUS: + return false; - default: - if(rb->default_event_handler(button) == SYS_USB_CONNECTED) - been_in_usb_mode = true; + case MENU_ATTACHED_USB: + been_in_usb_mode = true; break; } } return false; } -static int start = 0; +static char * get_event_text(int selected, void *data, + char *buffer, size_t buffer_len) +{ + struct shown *shown = (struct shown *) data; + if (selected < 0 || memos_in_shown_memory <= selected) + { + return NULL; + } + if (memos[pointer_array[selected]].type == 2) + rb->snprintf(buffer, buffer_len, "%s (%d yrs)", + memos[pointer_array[selected]].message, + shown->year - memos[pointer_array[selected]].year); + else + rb->snprintf(buffer, buffer_len, "%s", + memos[pointer_array[selected]].message); + return buffer; +} -static void show_lines(int selected, struct shown *shown) +static bool view_events(int selected, struct shown *shown) { - int lines,j = 1,w,h,i,k = 0, pos = 1,m = 0; - char temp[MAX_CHAR_MEMO_LEN + 12]; - rb->lcd_getstringsize("A",&w,&h); - lines = (LCD_HEIGHT / h) - 1; - - rb->lcd_clear_display(); - rb->lcd_puts(0,0,"Events (play : menu)"); + struct gui_synclist gui_memos; + bool exit=false; + int button; + + rb->gui_synclist_init(&gui_memos, &get_event_text, shown, false, 1, NULL); + rb->gui_synclist_set_title(&gui_memos, "Events (play : menu)", NOICON); + rb->gui_synclist_set_nb_items(&gui_memos, memos_in_shown_memory); + rb->gui_synclist_select_item(&gui_memos, selected); + rb->gui_synclist_draw(&gui_memos); - while (selected >= (lines + start)) - start++; - while (selected < start) - start--; - i = start; - while ( (i < memos_in_shown_memory) && (k < lines) ) + while (!exit) { - if (memos[pointer_array[i]].type == 2) - rb->snprintf(temp, sizeof temp, "%s (%d yrs)", - memos[pointer_array[i]].message, - shown->year - memos[pointer_array[i]].year); - else - rb->snprintf(temp, sizeof temp, "%s", - memos[pointer_array[i]].message); - m = 0; - if (i == selected) + rb->gui_syncstatusbar_draw(rb->statusbars, true); + button = rb->get_action(CONTEXT_LIST,TIMEOUT_BLOCK); + rb->gui_synclist_do_button(&gui_memos,&button,LIST_WRAP_UNLESS_HELD); + + switch (button) { - pos = k + 1; - rb->lcd_puts_scroll(m,j++,temp); + case ACTION_STD_OK: + selected = rb->gui_synclist_get_sel_pos(&gui_memos); + return edit_memo(selected, shown); + break; + + case ACTION_STD_CANCEL: + return false; + break; + + default: + if(rb->default_event_handler(button) == SYS_USB_CONNECTED) + been_in_usb_mode = true; + break; } - else - rb->lcd_puts(m,j++,temp); - k++; - i++; } - rb->lcd_set_drawmode(DRMODE_COMPLEMENT); - rb->lcd_fillrect(0, (pos) * h, LCD_WIDTH, h); - rb->lcd_set_drawmode(DRMODE_SOLID); + return false; } static void update_memos_shown(struct shown *shown) { int i; memos_in_shown_memory = 0; - start = 0; for (i = 0; i < memos_in_memory; i++) if ( - (memos[i].day == shown->mday) + ( + (memos[i].type >= 1) + && + (memos[i].day == shown->mday) + ) || ( (memos[i].type < 1) @@ -551,59 +711,15 @@ static bool any_events(struct shown *shown, bool force) { - int lines_displayed = 0; - bool exit=false; - int button; - update_memos_shown(shown); + if (memos_in_shown_memory > 0) - show_lines(lines_displayed,shown); + return view_events(0, shown); else if (force) - return edit_memo(lines_displayed, shown); + return edit_memo(0, shown); else return false; - rb->lcd_update(); - while (!exit) - { - button = rb->button_get(true); - switch (button) - { - case BUTTON_DOWN: - if (memos_in_shown_memory > 0) - { - lines_displayed++; - if (lines_displayed >= memos_in_shown_memory) - lines_displayed = memos_in_shown_memory - 1; - show_lines(lines_displayed,shown); - rb->lcd_update(); - } - break; - case BUTTON_UP: - if (memos_in_shown_memory > 0) - { - lines_displayed--; - if (lines_displayed < 0) - lines_displayed = 0; - show_lines(lines_displayed,shown); - rb->lcd_update(); - } - break; - - case BUTTON_PLAY: - return edit_memo(lines_displayed, shown); - - case BUTTON_OFF: - return false; - - default: - if(rb->default_event_handler(button) == SYS_USB_CONNECTED) - been_in_usb_mode = true; - show_lines(lines_displayed,shown); - rb->lcd_update(); - break; - } - } return false; } @@ -616,7 +732,7 @@ shown->year++; leap_year = is_leap_year(shown->year); } - else if (step > 0) + if (step > 0) shown->mday = shown->mday - days_in_month[leap_year][shown->mon-1]; else if (shown->mday > days_in_month[leap_year][shown->mon]) shown->mday = days_in_month[leap_year][shown->mon]; @@ -681,40 +797,40 @@ button = rb->button_get(true); switch (button) { - case BUTTON_OFF: - return false; + case CALENDAR_QUIT: + return PLUGIN_OK; - case BUTTON_ON | BUTTON_DOWN: - case BUTTON_ON | BUTTON_DOWN | BUTTON_REPEAT: + case CALENDAR_NEXT_MONTH: + case CALENDAR_NEXT_MONTH | BUTTON_REPEAT: next_month(&shown, 0); break; - case BUTTON_ON | BUTTON_UP: - case BUTTON_ON | BUTTON_UP | BUTTON_REPEAT: + case CALENDAR_PREV_MONTH: + case CALENDAR_PREV_MONTH | BUTTON_REPEAT: prev_month(&shown, 0); break; - case BUTTON_DOWN: - case BUTTON_DOWN | BUTTON_REPEAT: + case CALENDAR_NEXT_WEEK: + case CALENDAR_NEXT_WEEK | BUTTON_REPEAT: next_day(&shown, 7); break; - case BUTTON_UP: - case BUTTON_UP | BUTTON_REPEAT: + case CALENDAR_PREV_WEEK: + case CALENDAR_PREV_WEEK | BUTTON_REPEAT: prev_day(&shown, 7); break; - case BUTTON_LEFT: - case BUTTON_LEFT | BUTTON_REPEAT: + case CALENDAR_PREV_DAY: + case CALENDAR_PREV_DAY | BUTTON_REPEAT: prev_day(&shown, 1); break; - case BUTTON_RIGHT: - case BUTTON_RIGHT | BUTTON_REPEAT: + case CALENDAR_NEXT_DAY: + case CALENDAR_NEXT_DAY | BUTTON_REPEAT: next_day(&shown, 1); break; - case BUTTON_PLAY: + case CALENDAR_SELECT: any_events(&shown, true); draw_calendar(&shown); break; Index: apps/plugins/SOURCES =================================================================== --- apps/plugins/SOURCES (revision 18281) +++ apps/plugins/SOURCES (working copy) @@ -92,9 +92,7 @@ wormlet.c #if CONFIG_RTC -#if CONFIG_KEYPAD == RECORDER_PAD /* Recorder models only for now */ calendar.c -#endif #endif /* CONFIG_RTC */ #if (MEMORYSIZE <= 8) && !defined(SIMULATOR) /* loaders, only needed for Archos */ Index: firmware/target/arm/s3c2440/gigabeat-fx/lcd-meg-fx.c =================================================================== --- firmware/target/arm/s3c2440/gigabeat-fx/lcd-meg-fx.c (revision 18281) +++ firmware/target/arm/s3c2440/gigabeat-fx/lcd-meg-fx.c (working copy) @@ -404,14 +404,14 @@ if (x + width > current_vp->width) width = current_vp->width - x; /* Clip right */ if (x < 0) - width += x, x = 0; /* Clip left */ + width += x, src_x -= x, x = 0; /* Clip left */ if (width <= 0) return; /* nothing left to do */ if (y + height > current_vp->height) height = current_vp->height - y; /* Clip bottom */ if (y < 0) - height += y, y = 0; /* Clip top */ + height += y, src_y -= y, y = 0; /* Clip top */ if (height <= 0) return; /* nothing left to do */