📄 nxaddress.cxx
字号:
/* * Copyright (c) 2003 Century Software, Inc. All Rights Reserved. * * This file is part of the PIXIL Operating Environment * * The use, copying and distribution of this file is governed by one * of two licenses, the PIXIL Commercial License, or the GNU General * Public License, version 2. * * Licensees holding a valid PIXIL Commercial License may use this file * in accordance with the PIXIL Commercial License Agreement provided * with the Software. Others are governed under the terms of the GNU * General Public License version 2. * * This file may be distributed and/or modified under the terms of the * GNU General Public License version 2 as published by the Free * Software Foundation and appearing in the file LICENSE.GPL included * in the packaging of this file. * * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE. * * RESTRICTED RIGHTS LEGEND * * Use, duplication, or disclosure by the government is subject to * restriction as set forth in paragraph (b)(3)(b) of the Rights in * Technical Data and Computer Software clause in DAR 7-104.9(a). * * See http://www.pixil.org/gpl/ for GPL licensing * information. * * See http://www.pixil.org/license.html or * email cetsales@centurysoftware.com for information about the PIXIL * Commercial License Agreement, or if any conditions of this licensing * are not clear to you. */#include <pixil_config.h>#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <pixil_config.h>#include "nxaddress.h"#include <nxbutton.h>#include <nxmultilineoutput.h>#include <icons/address.xpm>#define DEBUG#ifdef DEBUG#define DPRINT(str, args...) printf("NXADDRESS DEBUG: " str, ## args)#else#define DPRINT(args...)#endif#define COLS 2#define CONTACTS "add"#define INFO "add_info"#define CATEGORY "add_category"#define CUSTFIELDS "add_custfields"#define NX_INIFILE "add_"#define APP "Address Book"#define NXINPUT_H 21extern int exit_flag;about about_address = { "About Address Book", "(c) 2001, Century Software.", "jeffm@censoft.com", "08/24/01", "1.0"};////////////////////////////////////////////////////////////////////////////////// Database Table Definitions// Field References#define RECNO 0#define CAT 1#define SHOW 2#define LASTNAME 3#define FIRSTNAME 4#define COMPANY 5#define TITLE 6#define DEP1ID 7#define DEP2ID 8#define DEP3ID 9#define DEP4ID 10#define DEP5ID 11#define DEP6ID 12#define DEP7ID 13#define DEP1 14#define DEP2 15#define DEP3 16#define DEP4 17#define DEP5 18#define DEP6 19#define DEP7 20#define ADDRESS 21#define CITY 22#define REGION 23 // State, Province, Town, etc.#define POSTALCODE 24 // ZIP, Postal Code, etc.#define COUNTRY 25#define BDAY 26#define ANNIV 27#define CUST1 28#define CUST2 29#define CUST3 30#define CUST4 31#define NOTE 32// Contacts Fieldsfield cFields[] = { {'i', 1, 0}, // Field 0:RECNO {'i', 1, 0}, // 1:CAT {'i', 1, 0}, // 3:SHOW {'c', TEXT, 0}, // 4:LASTNAME {'c', TEXT, 0}, // 5:FIRSTNAME {'c', TEXT, 0}, // 6:COMPANY {'c', TEXT, 0}, // 7:TITLE {'i', 1, 0}, // 8:DEP1ID {'i', 1, 0}, // 9:DEP2ID {'i', 1, 0}, // 10:DEP3ID {'i', 1, 0}, // 11:DEP4ID {'i', 1, 0}, // 12:DEP5ID {'i', 1, 0}, // 13:DEP6ID {'i', 1, 0}, // 14:DEP7ID {'c', TEXT, 0}, // 15:DEP1 {'c', TEXT, 0}, // 16:DEP2 {'c', TEXT, 0}, // 17:DEP3 {'c', TEXT, 0}, // 18:DEP4 {'c', TEXT, 0}, // 19:DEP5 {'c', TEXT, 0}, // 20:DEP6 {'c', TEXT, 0}, // 21:DEP7 {'c', DBL_TEXT, 0}, // 22:ADDRESS {'c', TEXT, 0}, // 23:CITY {'c', TEXT, 0}, // 24:REGION {'c', TEXT, 0}, // 25:POSTALCODE {'c', TEXT, 0}, // 26:COUNTRY {'c', DATE, 0}, // 27:BDAY {'c', DATE, 0}, // 28:ANNIV {'c', TEXT, 0}, // 29:CUST1 {'c', TEXT, 0}, // 30:CUST2 {'c', TEXT, 0}, // 31:CUST3 {'c', TEXT, 0}, // 32:CUST4 {'c', NOTEDB, 0}, // 33:NOTE {0}};// Databasefildes cFile = { // system file 0, 0, 0, // database file "dbf", // extension 33, // nfields &cFields[0] // fieldlist};#define INFO_TYPE 10// Infofield iFields[] = { {'i', 1, 0}, // Field 0:infoid {'c', INFO_TYPE, 0}, // 1:info_type {0}};// Databasefildes iFile = { 0, 0, 0, "dbf", 2, &iFields[0]};#define CAT_NAME 10// Category Listfield catFields[] = { {'i', 1, 0}, // Field 0:catid {'c', CAT_NAME, 0}, // 1:cat_name {0}};// Databasefildes catFile = { 0, 0, 0, "dbf", 2, &catFields[0]};#define CUSTOM_NAME 10// Custom Fieldsfield custFields[] = { {'i', 1, 0}, // Field 0: custid {'c', CUSTOM_NAME, 0}, // 1: custom name {0}};// Databasefildes custFile = { 0, 0, 0, "dbf", 2, &custFields[0]};////////////////////////////////////////////////////////////////////////////////// Menus DefinitionsFl_Menu_Item addrMenuItems[] = { {"Record", 0, 0, 0, FL_SUBMENU}, {"Duplicate Contact", 0, NxAddress::dup_callback, 0, FL_MENU_DIVIDER}, {"Exit Address Book", 0, NxAddress::exit_callback}, {0}, {"Edit", 0, 0, 0, FL_SUBMENU}, {"Undo", 0, NxApp::undo_callback}, {"Cut", 0, NxApp::cut_callback}, {"Copy", 0, NxApp::copy_callback}, {"Paste", 0, NxApp::paste_callback}, //{ "Keyboard",0, NxApp::keyboard_callback}, {0}, {"Options", 0, 0, 0, FL_SUBMENU}, // { "Font"}, // { "Preferences"}, {"Search", 0, NxAddress::lookup_callback}, {"About Address Book", 0, NxApp::show_about}, {0}, {0}};Fl_Menu_Item addrViewMenuItems[] = { {"Record", 0, 0, 0, FL_SUBMENU}, {"Delete Contact", 0, NxAddress::delView_callback}, {"Duplicate Contact", 0, NxAddress::dup_callback, 0, FL_MENU_DIVIDER}, {"Exit Address Book", 0, NxAddress::exit_callback}, {0}, {"Options", 0, 0, 0, FL_SUBMENU}, // { "Font"}, // { "Rename Custom Fields"}, {"About Address Book", 0, NxApp::show_about}, {0}, {0},};Fl_Menu_Item addrEditMenuItems[] = { {"Edit", 0, 0, 0, FL_SUBMENU}, {"Undo", 0, NxApp::undo_callback}, {"Cut", 0, NxApp::cut_callback}, {"Copy", 0, NxApp::copy_callback}, {"Paste", 0, NxApp::paste_callback, 0, FL_MENU_DIVIDER}, // { "Select All"}, //{ "Keyboard", 0, NxApp::keyboard_callback}, {"Exit Address Book", 0, NxAddress::exit_callback}, {0}, {"Options", 0, 0, 0, FL_SUBMENU}, // { "Font"}, {"Contact Details", 0, NxAddress::details_callback}, {"Rename Custom Fields", 0, NxAddress::custom_callback}, {"About Address Book", 0, NxApp::show_about}, {0}, {0},};////////////////////////////////////////////////////////////////////////////////// Static Data MembersNxDb * NxAddress::db;int NxAddress::id;int NxAddress::g_EditFlag;int NxAddress::g_SearchFlag;char * NxAddress::nx_inidir;NxWindow * NxAddress::main_window;NxPimWindow * NxAddress::addr_list_window;NxPimWindow * NxAddress::addr_view_window;NxPimWindow * NxAddress::addr_edit_window;NxPimPopWindow * NxAddress::addr_details_window;NxPimPopWindow * NxAddress::addr_note_window;NxPimPopWindow * NxAddress::addr_dellist_window;NxPimPopWindow * NxAddress::addr_deledit_window;NxPimPopWindow * NxAddress::addr_delview_window;NxPimPopWindow * NxAddress::addr_lookup_window;NxPimPopWindow * NxAddress::addr_results_window;NxPimPopWindow * NxAddress::addr_custom_window;NxCategoryList * NxAddress::note_category;NxCategoryList * NxAddress::edit_category_list;NxCategoryList * NxAddress::view_category_list;Fl_Editor * NxAddress::g_editor;NxInput * NxAddress::lookup_input;Flv_Table_Child * NxAddress::results_table;NxOutput * NxAddress::results_message;Flv_Table_Child * NxAddress::table;NxCategoryList * NxAddress::cat_list[CAT_NUM];bool NxAddress::AllFlag;// edit windowNxInput * NxAddress::edit_lastname;NxInput * NxAddress::edit_firstname;NxInput * NxAddress::edit_company;NxInput * NxAddress::edit_title;NxMiscList * NxAddress::edit_misc_list1;NxMiscList * NxAddress::edit_misc_list2;NxMiscList * NxAddress::edit_misc_list3;NxMiscList * NxAddress::edit_misc_list4;NxMiscList * NxAddress::edit_misc_list5;NxMiscList * NxAddress::edit_misc_list6;NxMiscList * NxAddress::edit_misc_list7;NxInput * NxAddress::edit_misc1;NxInput * NxAddress::edit_misc2;NxInput * NxAddress::edit_misc3;NxInput * NxAddress::edit_misc4;NxInput * NxAddress::edit_misc5;NxInput * NxAddress::edit_misc6;NxInput * NxAddress::edit_misc7;NxInput * NxAddress::editAddress;NxInput * NxAddress::editCity;NxInput * NxAddress::editRegion;NxInput * NxAddress::editPostalCode;NxInput * NxAddress::editCountry;NxInput * NxAddress::edit_bday;NxInput * NxAddress::edit_anniv;NxInput * NxAddress::edit_custom1;NxInput * NxAddress::edit_custom2;NxInput * NxAddress::edit_custom3;NxInput * NxAddress::edit_custom4;char * NxAddress::szNoteFile;NxMiscList * NxAddress::details_show_list;// view windowNxOutput * NxAddress::viewName;NxOutput * NxAddress::viewBusTitle;NxOutput * NxAddress::viewCompany;NxOutput * NxAddress::viewAddress;NxOutput * NxAddress::viewCityRegionPC;NxOutput * NxAddress::viewCountry;NxOutput * NxAddress::viewWorkPhone;NxOutput * NxAddress::viewEMail;// custom windowNxInput * NxAddress::custom1Input;NxInput * NxAddress::custom2Input;NxInput * NxAddress::custom3Input;NxInput * NxAddress::custom4Input;//NxMiscList * NxAddress::details_misc_list;Fl_Pixmap * NxAddress::address_pixmap;////////////////////////////////////////////////////////////////////////////////// ConstructorNxAddress::NxAddress(int argc, char *argv[]) :NxApp(APP){ db = new NxDb(argc, argv); optind = 1; NxApp::Instance()->set_keyboard(argc, argv); nx_inidir = db->GetPath(); szNoteFile = new char[NOTEDB]; strcpy(szNoteFile, "^"); NxApp::Instance()->set_about(about_address); g_EditFlag = 0; // Open or Create contacts database if (!db->Open((string) CONTACTS, &cFile, cFields, 0)) { if (db->Create((string) CONTACTS, &cFile, cFields, 0)) { if (!db->Open((string) CONTACTS, &cFile, cFields, 0)) { exit(-1); } /* Install some sample records if we have selected as such */#ifdef CONFIG_SAMPLES for (int i = 0; i < 1; i++) { char *record = 0; record = Record(i, // Id 0, // CategoryId 0, // ShowDisplayId "Baggins", // Last Name "Frodo ", // First Name "Middle Earth, Inc.", // Company Name "CEO", // Title 0, 1, 2, 3, 4, 5, 6, // Dep Indexes "555.555.0001", // Home Dep "555.555.0002 x123", // Work Dep "555.555-0003", // Fax Dep "555.555.0004", // Mobile Dep "555.555.0005", // Pager Dep "frodo@middleearth.net", // E-Mail Dep "http://onering.net", // Web Page "Bagend #1", // Address "Hobbitten", // City "Shire", // Region "00001", // Postal Code "Middele Earth", // Country "04/04/1940", // Birthday "06/06/1960", // Anniversary "Custom Value", // Custom Value 1 "Custom Value", // Custom Value 2 "Custom Value", // Custom Value 3 "Custom Value", // Custom Value 4 "^"); // Note File Name (^ = empty) db->Insert(CONTACTS, record); delete[]record; }#endif } else { exit(-1); } } // Database opened or created successfully, get number of records. //int recno = db->NumRecs(CONTACTS); //id = recno; //if ( recno > 1) { // char buf[4]; // db->Extract(CONTACTS, recno, 0, buf); // id = atoi(buf); //} id = GetKey(db, CONTACTS, RECNO); // Register DB for Synchronization // int file_fields[1];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -