⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nxtodo.cxx

📁 PIXIL is a small footprint operating environment, complete with PDA PIM applications, a browser and
💻 CXX
📖 第 1 页 / 共 4 页
字号:
voidNxTodoList::doneLookup_callback(Fl_Widget * fl, void *l){    NxApp::Instance()->show_window(todo_list_window->GetWindowPtr(),				   ACTIVATE);}voidNxTodoList::cancelLookup_callback(Fl_Widget * fl, void *l){    NxApp::Instance()->show_window(todo_list_window->GetWindowPtr(),				   ACTIVATE);}char *NxTodoList::formatLabel(const NxTodo * note, int pixels, bool fullpix){    int width = 0;    int dot_width = 0;    int idx = 0;    int tmp_pix;    unsigned int jdx = 0;    int date_len = 0;    static char temp_date[33];    static char date[33];    char title[TITLE + 3];    char temp_title[TITLE + 3];    char *new_string = new char[TITLE + 33];    char temp_string[TITLE + 33];    tm *tt = localtime(&note->time);    NxTodoList *pThis = (NxTodoList *) (NxApp::Instance());    fl_font(DEFAULT_TEXT_FONT, DEFAULT_TEXT_SIZE);    dot_width = (int) fl_width("...");    memset(temp_title, 0, sizeof(temp_title));    memset(title, 0, sizeof(title));    memset(new_string, 0, TITLE + 33);    if (true == fullpix)	sprintf(temp_title, "%s", note->szTitle);    else	sprintf(temp_title, "%d %s", note->nPriority, note->szTitle);    idx = 0;    strcpy(title, temp_title);    width = (int) fl_width(title);    if (width >= (pixels / 2)) {	while (width > (pixels / 2)) {	    idx++;	    memset(title, 0, sizeof(title));	    strncpy(title, temp_title, strlen(temp_title) - idx);	    width = (int) fl_width(title) + dot_width;	}	sprintf(title, "%s...", title);    } else {	while (width < (pixels / 2)) {	    if (strlen(title) >= TITLE + 3)		break;	    sprintf(title, "%s ", title);	    width = (int) fl_width(title);	}    }    if (NO_TIME == note->time)	strcpy(date, "No Date");    else	//strftime(date, 29,"%b %d", tt);	pThis->GetDateString(date, tt, sizeof(date), SHORT_YEAR);    date_len = strlen(date);    memset(temp_date, 0, sizeof(temp_date));    if (true == fullpix)	tmp_pix = pixels / 2;    else	tmp_pix = (pixels / 2) - 20;    width = (int) fl_width(date);    if (width >= (tmp_pix)) {	sprintf(temp_date, "%*.*s", 30, date_len, date);	strcpy(date, temp_date);    }    if (NO_TIME == note->time)	strcpy(date, "No Date");    else	//strftime(date, 29,"%b %d", tt);	pThis->GetDateString(date, tt, sizeof(date), SHORT_YEAR);    idx = 0;    jdx = 0;    width = (int) fl_width(date);    while (width >= (tmp_pix)) {	if (isspace(date[0])) {	    idx++;	    memmove(date, date + 1, sizeof(date) - idx);	    width = (int) fl_width(date);	} else {	    jdx++;	    memset(date, 0, sizeof(date));	    strncpy(date, temp_date, strlen(temp_date) - jdx);	    width = (int) fl_width(date) + dot_width;	}    }    if (0 != jdx)	sprintf(date, "%s...", date);    sprintf(new_string, "%s%s", title, date);    char *pStr = strstr(new_string, date);    int len = strlen(new_string) - strlen(pStr);    memset(temp_string, 0, sizeof(temp_string));    strncpy(temp_string, new_string, len);    width = (int) fl_width(temp_string);    while (width <= (pixels / 2 - 1)) {	sprintf(temp_string, "%s ", temp_string);	width = (int) fl_width(temp_string);    }    sprintf(new_string, "%s%s", temp_string, date);    return (char *) new_string;}char *NxTodoList::formatString(const NxTodo * note, int pixels){    int width = 0;    int dot_width = 0;    int idx = 0;    char *new_string = new char[TITLE + 3];    fl_font(DEFAULT_TEXT_FONT, DEFAULT_TEXT_SIZE);    width = (int) fl_width(note->szTitle);    dot_width = (int) fl_width("...");    if (width <= pixels) {	return (char *) note->szTitle;    } else {	while (width > pixels) {	    idx++;	    memset(new_string, 0, TITLE + 3);	    strncpy(new_string, note->szTitle, strlen(note->szTitle) - idx);	    width = (int) fl_width(new_string) + dot_width;	}	sprintf(new_string, "%s...", new_string);	return new_string;    }    return (char *) note->szTitle;}NxTodo *NxTodoList::searchString(const char *searchVal){    static int cur_record = 0;    static int rec_array[255];    int jdx;    char *needle = strup(searchVal, strlen(searchVal));    if (0 == cur_record) {	for (int idx = 0; idx < 255; idx++) {	    rec_array[idx] = -1;	}	//Select all records	db->Select(TODO, rec_array, 255);    }    if (255 == cur_record) {	cur_record = 0;	delete[]needle;	needle = 0;	return NULL;    }    bool found = false;    NxTodo *note = new NxTodo;    while (cur_record < 255) {	int catid_array[1];	char catid[8];	found = false;	catid_array[0] = -1;	jdx = rec_array[cur_record];	if (-1 == jdx) {	    cur_record++;	    continue;	}	db->Extract(TODO, jdx, 1, catid);	db->Select(CATEGORY, catid, 0, catid_array, 1);	if (-1 != catid_array[0])	    db->Extract(CATEGORY, catid_array[0], 1, note->szCategory);	else	    strcpy(note->szCategory, "Unfiled");	// id	char id[4];	sprintf(id, "%d", note->nId);	db->Extract(TODO, jdx, 0, id);	char buf1[4];	db->Extract(TODO, jdx, 2, buf1);	note->nComplete = atoi(buf1);	char buf2[4];	db->Extract(TODO, jdx, 3, buf2);	note->nPriority = atoi(buf2);	db->Extract(TODO, jdx, 4, note->szTitle);	char *haystack = strup(note->szTitle, TITLE);	if (strstr(haystack, needle))	    found = true;	delete[]haystack;	haystack = 0;	db->Extract(TODO, jdx, 5, note->szFile);	char buf3[8];	db->Extract(TODO, jdx, 6, buf3);	note->time = strtol(buf3, NULL, 10);	//haystack = strup(note->szFile, DESC);	//if (strstr(haystack, needle))	//      found = true;	//delete[] haystack;	//haystack = 0;	found |= searchFile(searchVal, note->szFile);	if (found) {	    cur_record++;	    delete[]needle;	    needle = 0;	    return note;	} else {	    cur_record++;	    continue;	}    }    cur_record = 0;    delete[]note;    note = 0;    delete[]needle;    needle = 0;    return NULL;}bool NxTodoList::checkDate(NxTodo * note, time_t fromTime, time_t toTime){    struct tm *	from_tm =	localtime(&fromTime);    int	fd =	from_tm->	tm_mday;    int	fm =	from_tm->	tm_mon;    int	fy =	from_tm->	tm_year;    struct tm *	to_tm =	localtime(&toTime);    int	td =	to_tm->	tm_mday;    int	tm =	to_tm->	tm_mon;    int	ty =	to_tm->	tm_year;    struct tm *	tt =	localtime(&note->time);    int	d =	tt->	tm_mday;    int	m =	tt->	tm_mon;    int	y =	tt->	tm_year;    if (((fd <= d) && (fm <= m) && (fy <= y))	&& ((td >= d) && (tm >= m) && (ty >= y))) {	return true;    }    return false;}NxTodo *NxTodoList::searchDate(time_t fromTime, time_t toTime){    static int cur_record = 0;    static int rec_array[255];    int jdx;    if (0 == cur_record) {	for (int idx = 0; idx < 255; idx++) {	    rec_array[idx] = -1;	}	db->Select(TODO, rec_array, 255);    }    if (255 == cur_record) {	cur_record = 0;	return NULL;    }    NxTodo *note = new NxTodo;    while (cur_record < 255) {	jdx = rec_array[cur_record];	if (-1 == jdx) {	    cur_record++;	    continue;	}	int catid_array[1];	char catid[8];	catid_array[0] = -1;	db->Extract(TODO, jdx, 1, catid);	db->Select(CATEGORY, catid, 0, catid_array, 1);	if (-1 != catid_array[0])	    db->Extract(CATEGORY, catid_array[0], 1, note->szCategory);	else	    strcpy(note->szCategory, "Unfiled");	// id	char id[4];	sprintf(id, "%d", note->nId);	db->Extract(TODO, jdx, 0, id);	char buf1[4];	db->Extract(TODO, jdx, 2, buf1);	note->nComplete = atoi(buf1);	char buf2[4];	db->Extract(TODO, jdx, 3, buf2);	note->nPriority = atoi(buf2);	db->Extract(TODO, jdx, 4, note->szTitle);	db->Extract(TODO, jdx, 5, note->szFile);	char buf3[8];	db->Extract(TODO, jdx, 6, buf3);	note->time = strtol(buf3, NULL, 10);	if (true == checkDate(note, fromTime, toTime)) {	    cur_record++;	    return note;	} else {	    cur_record++;	    continue;	}    }    cur_record = 0;    delete[]note;    note = 0;    return NULL;}voidNxTodoList::UpdateFromButton(){    static char buf[30];    tm *tt = localtime(&fromTime);    //strftime(buf, 29, "%b %d, %y", tt);    GetDateString(buf, tt, sizeof(buf), SHORT_YEAR);    fromDateButton->label(buf);    fromDateButton->redraw();}voidNxTodoList::UpdateToButton(){    static char buf[30];    tm *tt = localtime(&toTime);    //strftime(buf, 29, "%b %d, %y", tt);    GetDateString(buf, tt, sizeof(buf), SHORT_YEAR);    toDateButton->label(buf);    toDateButton->redraw();}voidNxTodoList::fromDate_callback(Fl_Widget * fl, void *l){    NxTodoList *pThis = (NxTodoList *) l;    pThis->date_window->GetWindowPtr()->hide();    NxApp::Instance()->show_window(todo_lookup_window->GetWindowPtr(),				   DEACTIVATE,				   todo_edit_window->GetWindowPtr());    if (pThis->GetPickedDate()) {	pThis->fromTime = pThis->GetPickedDate();	pThis->UpdateFromButton();    }}voidNxTodoList::toDate_callback(Fl_Widget * fl, void *l){    NxTodoList *pThis = (NxTodoList *) l;    pThis->date_window->GetWindowPtr()->hide();    NxApp::Instance()->show_window(todo_lookup_window->GetWindowPtr(),				   DEACTIVATE,				   todo_edit_window->GetWindowPtr());    if (pThis->GetPickedDate()) {	pThis->toTime = pThis->GetPickedDate();	pThis->UpdateToButton();    }}voidNxTodoList::fromCalendar_callback(Fl_Widget * fl, void *l){    NxTodoList *pThis = (NxTodoList *) l;    pThis->SetPickedDate(pThis->fromTime);    NxApp::Instance()->show_window(date_window->GetWindowPtr(),				   DEACTIVATE,				   todo_lookup_window->GetWindowPtr());    pThis->DateCallback(fromDate_callback);}voidNxTodoList::toCalendar_callback(Fl_Widget * fl, void *l){    NxTodoList *pThis = (NxTodoList *) l;    pThis->SetPickedDate(pThis->toTime);    NxApp::Instance()->show_window(date_window->GetWindowPtr(),				   DEACTIVATE,				   todo_lookup_window->GetWindowPtr());    pThis->DateCallback(toDate_callback);}voidNxTodoList::searchLookup_callback(Fl_Widget * fl, void *l){    if ((0 == stringCheck->value()) && (0 == dateCheck->value())) {	NxApp::Instance()->show_window(error_window->GetWindowPtr(),				       DEACTIVATE,				       todo_lookup_window->GetWindowPtr());	return;    }    g_SearchFlag = false;    int total_found = 0;    char *needle = 0;    NxTodo *note = 0;    results_table->Init(255);    if (true == stringCheck->value() && false == dateCheck->value()) {	char *searchVal = (char *) lookup_input->value();	needle = strup(searchVal, strlen(searchVal));	while ((note = searchString(searchVal)) != NULL) {	    results_table->Add(total_found, note);	    char *label =		formatLabel(note, results_table->text_width(), true);	    results_table->set_value(total_found, 0, label);	    total_found++;	}    }    if (false == stringCheck->value() && true == dateCheck->value()) {	while ((note = searchDate(fromTime, toTime)) != NULL) {	    results_table->Add(total_found, note);	    char *label =		formatLabel(note, results_table->text_width(), true);	    results_table->set_value(total_found, 0, label);	    total_found++;	}    }    if (true == stringCheck->value() && true == dateCheck->value()) {	char *searchVal = (char *) lookup_input->value();	needle = strup(searchVal, strlen(searchVal));	while ((note = searchString(searchVal)) != NULL) {	    if (true == checkDate(note, fromTime, toTime)) {		results_table->Add(total_found, note);		char *label =		    formatLabel(note, results_table->text_width(), true);		results_table->set_value(total_found, 0, label);		total_found++;	    }	}    }    delete[]needle;    needle = 0;    if (total_found == 0) {	results_message->show();	results_table->hide();    } else {	results_message->hide();	results_message->show();    }    results_table->rows(total_found);    NxApp::Instance()->show_window(todo_list_window->GetWindowPtr());    NxApp::Instance()->show_window(todo_results_window->GetWindowPtr(),				   DEACTIVATE,				   todo_list_window->GetWindowPtr());}voidNxTodoList::lookup_callback(Fl_Widget * fl, void *l){    NxApp::Instance()->show_window(todo_lookup_window->GetWindowPtr(),				   DEACTIVATE,				   todo_list_window->GetWindowPtr());    lookup_input->value("");    stringCheck->value(false);    dateCheck->value(false);    Fl::focus((Fl_Widget *) lookup_input);}voidNxTodoList::select_note(NxTodo * note){    Fl_Toggle_Node *n = tree->traverse_start();    int note_id = note->nId;    int n_id;    while (NULL != n) {	n_id = ((NxTodo *) n->user_data())->nId;	if (n_id == note_id) {	    tree->select_range(n, n, 0);	    break;	}	n = tree->traverse_forward();    }}voidNxTodoList::viewRecord(int recno){    DPRINT("recno: [%d]\n", recno);    NxApp::Instance()->set_catlist_window((Fl_Window *) todo_edit_window->					  GetEditCategoryWindowPtr());    NxTodo *note = new NxTodo;    int rec_array[1];    rec_array[0] = -1;    char c_recno[8];    sprintf(c_recno, "%d", recno);    db->Select(TODO, c_recno, 0, rec_array, 1);    recno = rec_array[0];    int catid_array[1];    char catid[8];    catid_array[0] = -1;    db->Extract(TODO, recno, 1, catid);    db->Select(CATEGORY, catid, 0, catid_array, 1);    if (-1 != catid_array[0])	db->Extract(CATEGORY, catid_array[0], 1, note->szCategory);    else	strcpy(note->szCategory, "Unfiled");    char id[4];    sprintf(id, "%d", note->nId);    db->Extract(TODO, recno, 0, id);    char buf1[4];    db->Extract(TODO, recno, 2, buf1);    note->nComplete = atoi(buf1);    db->Extract(TODO, recno, 3, buf1);    note->nPriority = atoi(buf1);    db->Extract(TODO, recno, 4, note->szTitle);    db->Extract(TODO, recno, 5, note->szFile);    char buf3[8];    db->Extract(TODO, recno, 6, buf3);    note->time = strtol(buf3, NULL, 10);    FILE *fd = fopen(note->szFile, "r");    g_editor->Clear();    g_editor->LoadFrom(fd);    g_editor->MoveTo(0, 0);    fclose(fd);    _fill_form(note);    g_SearchFlag = false;    g_EditFlag = true;    select_note(note);    edit_category_list->label(note->szCategory);    NxApp::Instance()->show_window(todo_edit_window->GetWindowPtr());    delete note;}voidNxTodoList::view_callback(Fl_Widget * fl, void *l){    NxTodo *n = 0;    if (Fl::event_clicks()) {	g_SearchFlag = false;	g_EditFlag = true;	NxApp::Instance()->set_catlist_window((Fl_Window *) todo_edit_window->					      GetEditCategoryWindowPtr());	n = (NxTodo *) results_table->selected();	if (n) {	    char tempCat[CATEGORYS];	    memset(tempCat, 0, CATEGORYS);	    strcpy(tempCat, n->szCategory);	    if (!tempCat[0]) {		strcpy(tempCat, "Unfiled");	    }	    g_editor->Clear();	    if (n->szFile[0] != '^') {		FILE *fd = fopen(n->szFile, "r");		g_editor->LoadFrom(fd);		g_editor->MoveTo(0, 0);		fclose(fd);	    }	    select_note(n);	    _fill_form(n);	    edit_category_list->label(tempCat);	}	NxApp::Instance()->show_window(todo_edit_window->GetWindowPtr());    }}voidNxTodoList::fill_categories(){    char ret_buf[CAT_NAME];    int rec_count = db->NumRecs(CATEGORY);    for (int idx = 0; idx < CAT_NUM; idx++) {	cat_list[idx]->clear();	cat_list[idx]->add("All");	for (int jdx = 1; jdx <= rec_count; jdx++) {	    db->Extract(CATEGORY, jdx, 1, ret_buf);	    cat_list[idx]->add(ret_buf);	}	cat_list[idx]->label(const_cast <			     char *>((char *) cat_list[idx]->text(0)));    }    todo_list_window->GetEditCategoryPtr()->clear_tree();    todo_list_window->GetEditCategoryPtr()->add_items(todo_list_window->						      GetEditCategoryPtr()->						      get_category_tree());    todo_edit_window->GetEditCategoryPtr()->clear_tree();    todo_edit_window->GetEditCategoryPtr()->add_items(todo_edit_window->						      GetEditCategoryPtr()->						      get_category_tree());}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -