📄 nxaddress.cxx
字号:
voidNxAddress::doneView_callback(Fl_Widget * fl, long l){ NxTodo *n = 0; if (g_SearchFlag) { n = (NxTodo *) results_table->selected(); set_category("All"); g_SearchFlag = 0; } else { n = (NxTodo *) table->selected(); if (AllFlag) { set_category("All"); AllFlag = false; } else set_category(view_category_list->label()); } NxApp::Instance()->show_window(addr_list_window->GetWindowPtr());}voidNxAddress::doneNote_callback(Fl_Widget * fl, long l){ char tplate[128]; int tfd = 0; FILE *fd = 0; NxTodo *n = (NxTodo *) table->selected(); char *f = 0; snprintf(tplate, sizeof(tplate), "%s/%sXXXXXX", nx_inidir, NX_INIFILE); if (n && g_EditFlag) { f = n->szNoteFile; if (f[0] == '^') { tfd = mkstemp(tplate); if (tfd > 0) { strcpy(n->szNoteFile, tplate); fd = fdopen(tfd, "w+"); } } else fd = fopen(f, "w+"); } else { tfd = mkstemp(tplate); if (tfd > 0) { set_szNoteFile(tplate); fd = fdopen(tfd, "w+"); } } if (fd) { g_editor->SaveTo(fd); fclose(fd); } NxApp::Instance()->show_window(addr_edit_window->GetWindowPtr(), ACTIVATE);}voidNxAddress::category_callback(Fl_Widget * fl, void *l){ set_category((char *) l);}voidNxAddress::list_callback(Fl_Widget * fl, void *l){ reset_category((char *) l);}voidNxAddress::details_callback(Fl_Widget * fl, void *l){ NxApp::Instance()->show_window(addr_details_window->GetWindowPtr(), DEACTIVATE, addr_edit_window->GetWindowPtr());}voidNxAddress::doneDetails_callback(Fl_Widget * fl, void *o){ NxTodo *n = (NxTodo *) table->selected(); n->nShowDisplay = details_show_list->value(); int recno[1]; recno[0] = -1; char szId[4]; sprintf(szId, "%d", n->nId); db->Select(CONTACTS, szId, RECNO, recno, 1); if (recno[0] != -1) edit_note(n, recno[0]); NxApp::Instance()->show_window(addr_edit_window->GetWindowPtr(), ACTIVATE);}voidNxAddress::cancelDetails_callback(Fl_Widget * fl, void *l){ NxApp::Instance()->show_window(addr_edit_window->GetWindowPtr(), ACTIVATE);}/*void NxAddress::delDetails_callback(Fl_Widget * fl, void *l) { // Delete current record NxApp::Instance()->show_window(addr_edit_window->GetWindowPtr(), ACTIVATE);}*/voidNxAddress::cancelEdit_callback(Fl_Widget * fl, void *l){ g_SearchFlag = 0; NxApp::Instance()->show_window(addr_list_window->GetWindowPtr());}voidNxAddress::notes_callback(Fl_Widget * fl, void *l){ g_editor->Clear(); NxTodo *n = (NxTodo *) table->selected(); char *f = 0; //cout << "notes_callback(): g_EditFlag = " << g_EditFlag << endl; if (n && g_EditFlag) { //cout << "notes_callback(): table->selected()\n"; f = n->szNoteFile; } else { //cout << "notes_callback(): !table->selected()\n"; f = get_szNoteFile(); } //cout << "notes_callback(): f = " << f << endl; if (f[0] != '^') { FILE *fd = fopen(f, "r"); if (fd) { g_editor->LoadFrom(fd); g_editor->MoveTo(0, 0); fclose(fd); } } NxApp::Instance()->show_window(addr_note_window->GetWindowPtr(), DEACTIVATE, addr_edit_window->GetWindowPtr());}voidNxAddress::custom_callback(Fl_Widget * fl, void *o){ int rec_array[4]; char *custlabel1 = new char[CUSTOM_NAME]; char *custlabel2 = new char[CUSTOM_NAME]; char *custlabel3 = new char[CUSTOM_NAME]; char *custlabel4 = new char[CUSTOM_NAME]; for (int idx = 0; idx < 4; idx++) { rec_array[idx] = -1; } db->Select(CUSTFIELDS, rec_array, 4); if ((rec_array[0] >= 0)) { db->Extract(CUSTFIELDS, rec_array[0], 1, custlabel1); db->Extract(CUSTFIELDS, rec_array[1], 1, custlabel2); db->Extract(CUSTFIELDS, rec_array[2], 1, custlabel3); db->Extract(CUSTFIELDS, rec_array[3], 1, custlabel4); custom1Input->value(custlabel1); custom2Input->value(custlabel2); custom3Input->value(custlabel3); custom4Input->value(custlabel4); } NxApp::Instance()->show_window(addr_custom_window->GetWindowPtr(), DEACTIVATE, addr_edit_window->GetWindowPtr());}voidNxAddress::doneCustom_callback(Fl_Widget * fl, void *o){ int recno[4]; for (int i = 0; i < 4; i++) recno[i] = -1; db->Select(CUSTFIELDS, recno, 4); char buffer[4]; int id; // Custom1 db->Extract(CUSTFIELDS, recno[0], 0, buffer); id = atoi(buffer); char *record1 = CustRecord(id, custom1Input->value()); db->Edit(CUSTFIELDS, recno[0], record1); edit_custom1->label(custom1Input->value()); delete record1; // Custom2 db->Extract(CUSTFIELDS, recno[1], 0, buffer); id = atoi(buffer); char *record2 = CustRecord(id, custom2Input->value()); db->Edit(CUSTFIELDS, recno[1], record2); edit_custom2->label(custom2Input->value()); delete record2; // Custom3 db->Extract(CUSTFIELDS, recno[2], 0, buffer); id = atoi(buffer); char *record3 = CustRecord(id, custom3Input->value()); db->Edit(CUSTFIELDS, recno[2], record3); edit_custom3->label(custom3Input->value()); delete record3; // Custom4 db->Extract(CUSTFIELDS, recno[3], 0, buffer); id = atoi(buffer); char *record4 = CustRecord(id, custom4Input->value()); db->Edit(CUSTFIELDS, recno[3], record4); edit_custom4->label(custom4Input->value()); delete record4; NxApp::Instance()->show_window(addr_edit_window->GetWindowPtr(), ACTIVATE);}voidNxAddress::cancelCustom_callback(Fl_Widget * fl, void *l){ NxApp::Instance()->show_window(addr_edit_window->GetWindowPtr(), ACTIVATE);}char *NxAddress::formatString(const NxTodo * note, int pixels){ int width = 0; int dot_width = 0; int idx = 0; int jdx = 0; int num_len = 0; char *new_string = new char[DBL_TEXT + DBL_TEXT + TEXT + 3]; char new_temp_string[DBL_TEXT + DBL_TEXT + TEXT + 3]; char name_string[TEXT + TEXT + 3]; char temp_name_string[TEXT + TEXT + 3]; char num_string[TEXT + 3]; char temp_string[TEXT + 3]; dot_width = (int) fl_width("..."); fl_font(DEFAULT_TEXT_FONT, DEFAULT_TEXT_SIZE); memset(name_string, 0, TEXT + TEXT + 3); sprintf(name_string, "%s,%s", note->szLastName, note->szFirstName); memset(new_string, 0, TEXT + TEXT + TEXT + 3); strcpy(temp_name_string, name_string); width = (int) fl_width(name_string); if (width >= (pixels / 2)) { while (width > (pixels / 2)) { idx++; memset(name_string, 0, TEXT + TEXT + 3); strncpy(name_string, temp_name_string, strlen(temp_name_string) - idx); width = (int) fl_width(name_string) + dot_width; } sprintf(name_string, "%s...", name_string); } else { while (width < (pixels / 2)) { if (strlen(name_string) >= TEXT + TEXT + 3) break; sprintf(name_string, "%s ", name_string); width = (int) fl_width(name_string); } } num_len = strlen(note->szDep1); memset(temp_string, 0, sizeof(temp_string)); memset(num_string, 0, sizeof(num_string)); width = (int) fl_width(note->szDep1); if (width >= (pixels / 2)) { sprintf(temp_string, "%*.*s", TEXT, num_len, note->szDep1); strcpy(num_string, temp_string); } else strcpy(num_string, note->szDep1); idx = 0; jdx = 0; width = (int) fl_width(num_string); while (width >= (pixels / 2)) { if (isspace(num_string[0])) { idx++; memmove(num_string, num_string + 1, TEXT + 3 - idx); width = (int) fl_width(num_string); } else { jdx++; memset(num_string, 0, sizeof(num_string)); strncpy(num_string, note->szDep1, strlen(note->szDep1) - jdx); width = (int) fl_width(num_string) + dot_width; } } if (jdx != 0) sprintf(num_string, "%s...", num_string); sprintf(new_string, "%s%s", name_string, num_string); char *pStr = strstr(new_string, num_string); int len = strlen(new_string) - strlen(pStr); memset(new_temp_string, 0, sizeof(new_temp_string)); strncpy(new_temp_string, new_string, len); width = (int) fl_width(new_temp_string); while (width <= (pixels / 2)) { sprintf(new_temp_string, "%s ", new_temp_string); width = (int) fl_width(new_temp_string); } sprintf(new_string, "%s%s", new_temp_string, num_string); return (char *) new_string;}NxTodo *NxAddress::search(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; } db->Select(CONTACTS, 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(CONTACTS, jdx, CAT, catid); db->Select(CATEGORY, catid, RECNO, catid_array, 1); if (-1 != catid_array[0]) db->Extract(CATEGORY, catid_array[0], CAT, note->szCategory); else strcpy(note->szCategory, "Unfiled"); // last_name db->Extract(CONTACTS, jdx, LASTNAME, note->szLastName); char *haystack = strup(note->szLastName, TEXT); if (strstr(haystack, needle)) found = true; delete[]haystack; haystack = 0; // id char szId[4]; db->Extract(CONTACTS, jdx, RECNO, szId); note->nId = atoi(szId); // first_name db->Extract(CONTACTS, jdx, FIRSTNAME, note->szFirstName); haystack = strup(note->szFirstName, TEXT); if (strstr(haystack, needle)) found = true; delete[]haystack; haystack = 0; // title db->Extract(CONTACTS, jdx, TITLE, note->szJobTitle); haystack = strup(note->szJobTitle, TEXT); if (strstr(haystack, needle)) found = true; delete[]haystack; haystack = 0; // company db->Extract(CONTACTS, jdx, COMPANY, note->szCompany); haystack = strup(note->szCompany, TEXT); if (strstr(haystack, needle)) found = true; delete[]haystack; haystack = 0; // Address db->Extract(CONTACTS, jdx, ADDRESS, note->szAddress); haystack = strup(note->szAddress, DBL_TEXT); if (strstr(haystack, needle)) found = true; delete[]haystack; haystack = 0; // City db->Extract(CONTACTS, jdx, CITY, note->szCity); haystack = strup(note->szCity, TEXT); if (strstr(haystack, needle)) found = true; delete[]haystack; haystack = 0; // Region db->Extract(CONTACTS, jdx, REGION, note->szRegion); haystack = strup(note->szRegion, TEXT); if (strstr(haystack, needle)) found = true; delete[]haystack; haystack = 0; // Postal Code db->Extract(CONTACTS, jdx, POSTALCODE, note->szPostalCode); haystack = strup(note->szPostalCode, TEXT); if (strstr(haystack, needle)) found = true; delete[]haystack; haystack = 0; // Country db->Extract(CONTACTS, jdx, COUNTRY, note->szCountry); haystack = strup(note->szCountry, TEXT); if (strstr(haystack, needle)) found = true; delete[]haystack; haystack = 0; // info1id char buf1[4]; db->Extract(CONTACTS, jdx, DEP1ID, buf1); note->nDep1 = atoi(buf1); // info2id db->Extract(CONTACTS, jdx, DEP2ID, buf1); note->nDep2 = atoi(buf1); // info3id db->Extract(CONTACTS, jdx, DEP3ID, buf1); note->nDep3 = atoi(buf1); // info4id db->Extract(CONTACTS, jdx, DEP4ID, buf1); note->nDep4 = atoi(buf1); // info5id db->Extract(CONTACTS, jdx, DEP5ID, buf1); note->nDep5 = atoi(buf1); // info6id db->Extract(CONTACTS, jdx, DEP6ID, buf1); note->nDep6 = atoi(buf1); // info7id db->Extract(CONTACTS, jdx, DEP7ID, buf1); note->nDep7 = atoi(buf1); // info1 db->Extract(CONTACTS, jdx, DEP1, note->szDep1); haystack = strup(note->szDep1, TEXT); if (strstr(haystack, needle)) found = true; delete[]haystack; haystack = 0; // info2 db->Extract(CONTACTS, jdx, DEP2, note->szDep2); haystack = strup(note->szDep2, TEXT); if (strstr(haystack, needle)) found = true; delete[]haystack; haystack = 0; // info3 db->Extract(CONTACTS, jdx, DEP3, note->szDep3); haystack = strup(note->szDep3, TEXT); if (strstr(haystack, needle)) found = true
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -