📄 nxnotepad.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 <signal.h>#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <pixil_config.h>#include "nxnotepad.h"#include <icons/folder_small.xpm>#ifdef DEBUG#include <assert.h>#define DPRINT(str, args...) printf("NXNOTEPAD DEBUG: " str, ## args)#else#define DPRINT(args...)#endif#define MAX_RECS 255#define NX_INIFILE "not"extern int exit_flag;about about_notes = { "About Notes", "Century Software, 2001", "trumanl@censoft.com", "08/24/01", "1.0"};// Note databasefield noteFields[] = { {'i', 1, 0}, {'i', 1, 0}, /* note category */ {'c', FILE_LEN, 0}, /* key note name */ {'c', TITLE_LEN, 0}, /* note title */ {'i', 1, 0}, /* archive 1=yes 0=no */ {0}};fildes noteFile = { /* system file */ 0, 0, 0, /* database file */ "dbf", /* extension */ NOTE_NUM_FIELDS, /* nfields */ ¬eFields[0] /* fieldlist */};// Cat databasefield catFields[] = { {'i', 1, 0}, {'c', CAT_LEN, 0}, {0}};fildes catFile = { /* system file */ 0, 0, 0, /* database file */ "dbf", /* extension */ CAT_NUM_FIELDS, /* nfields */ &catFields[0] /* field list */};//MenusFl_Menu_Item list_window_menu[] = { {"Record", 0, 0, 0, FL_SUBMENU}, {"New Note", 0, NxNotepad::new_callback}, {"Delete Note", 0, NxNotepad::delete_note_callback, 0, FL_MENU_DIVIDER}, {"Exit Notes", 0, NxNotepad::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}, //{"Select All"},// {"Keyboard", 0, NxApp::keyboard_callback}, {0}, {"Options", 0, 0, 0, FL_SUBMENU}, //{"Font"}, {"Search", 0, NxNotepad::lookup_callback}, {"About Notes", 0, NxApp::show_about}, {0}, {0}, {0}};Fl_Menu_Item new_note_menu[] = { {"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, 0, FL_MENU_DIVIDER}, {"Exit Notes", 0, NxNotepad::exit_callback}, {0}, {"Options", 0, 0, 0, FL_SUBMENU}, //{"Font"}, {"About Notes", 0, NxApp::show_about}, {0}, {0}, {0}};Fl_Menu_Item note_edit_menu[] = { {"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 Notes", 0, NxNotepad::exit_callback}, {0}, {"Options", 0, 0, 0, FL_SUBMENU}, //{"Font"}, {"About Notes", 0, NxApp::show_about}, {0}, {0}, {0}};NxWindow * NxNotepad::main_window;NxDb * NxNotepad::note_db;char * NxNotepad::nx_inidir;NxPimWindow * NxNotepad::note_list_window;NxPimWindow * NxNotepad::note_edit_window;NxPimPopWindow * NxNotepad::note_delete_window;NxPimPopWindow * NxNotepad::note_lookup_window;NxPimPopWindow * NxNotepad::note_results_window;NxCategoryList * NxNotepad::note_category;NxCategoryList * NxNotepad::edit_category;NxCategoryList * NxNotepad::cat_list[CAT_NUM];Fl_Editor * NxNotepad::g_editor;Fl_Toggle_Tree * NxNotepad::tree;NxScroll * NxNotepad::note_list;Fl_Pixmap * NxNotepad::folderSmall;bool NxNotepad::AllFlag;bool NxNotepad::new_note_;bool NxNotepad::g_SearchFlag;bool NxNotepad::save_archive_;int NxNotepad::note_key;NxInput * NxNotepad::lookup_input;Flv_Table_Child * NxNotepad::results_table;NxOutput * NxNotepad::results_message;NxNotepad::NxNotepad(int argc, char *argv[]) :NxApp(){ NxApp::Instance()->set_about(about_notes); note_db = new NxDb(argc, argv); optind = 1; NxApp::Instance()->set_keyboard(argc, argv); nx_inidir = note_db->GetPath(); open_note_database(); open_cat_database(); main_window = new NxWindow(W_W, W_H, APP_NAME); make_list_window(); make_edit_window(); make_delete_window(); make_lookup_window(); make_results_window(); main_window->end(); set_shown_window(note_list_window->GetWindowPtr()); note_category = note_list_window->category_list; edit_category = note_edit_window->category_list; cat_list[0] = note_category; cat_list[1] = edit_category; fill_categories(); folderSmall = new Fl_Pixmap(folder_small); add_items(tree, note_category->label()); note_category->select(category_callback); edit_category->select(list_callback); save_archive_ = false; new_note_ = false; note_key = GetKey(note_db, NOTE_DATABASE, NOTE_INDEX); DPRINT("Note key is [%d]\n", note_key); set_catlist_window((Fl_Window *) note_list_window-> GetEditCategoryWindowPtr()); // Register databases for PIM Synchronization ////////////////////////////////////////////// int file_fields[1]; file_fields[0] = 2; // Column of file name. SyncRegisterDB(note_db, noteFields, NOTE_DATABASE, 1, file_fields, 1); SyncRegisterDB(note_db, catFields, CAT_DATABASE, 0, NULL, 0);#ifdef CONFIG_COLOSSEUM Add_Fd("nxnotepad", _ClientIPCHandler);#else ExecuteShow();#endif}NxNotepad::~NxNotepad(){ note_db->Close(NOTE_DATABASE); note_db->Close(CAT_DATABASE); delete note_db; note_db = 0;}voidNxNotepad::Refresh(){ set_category(note_category->label());}//// FLNX-Colosseum IPC Methods//#ifdef CONFIG_COLOSSEUMvoidNxNotepad::ClientIPCHandler(int fd, void *o, int ipc_id){ // DPRINT("\n"); // DPRINT("ClientIPCHandler has now been started.\n"); char *tokenMsg = new char[MAX_LENGTH]; memset(tokenMsg, 0, MAX_LENGTH); char *passMsg = new char[MAX_LENGTH]; memset(passMsg, 0, MAX_LENGTH); // int ipc_id = -1; // DPRINT("And this is the message... %s.\n", msg); if (o == NULL) { int length = MAX_LENGTH - 1; ipc_id = NxApp::Instance()->Read_Fd(passMsg, &length); if ((passMsg == NULL) || (passMsg[0] == 0)) return; else strcpy(tokenMsg, passMsg); } else if (ipc_id == -1) { strcpy(tokenMsg, (char *) o); strcpy(passMsg, (char *) o); ipc_id = NxApp::Instance()->Find_Fd("nxnotepad"); } else { strcpy(tokenMsg, (char *) o); strcpy(passMsg, (char *) o); } // Explode Message char *service = new char[MAX_LENGTH]; char *msg_cmd = new char[MAX_LENGTH]; char *data_item = new char[MAX_LENGTH]; // SERVICE char *tmp = strtok(tokenMsg, TOKEN); if (tmp != NULL) strcpy(service, tmp); // MSG_CMD tmp = strtok(NULL, TOKEN); if (tmp != NULL) strcpy(msg_cmd, tmp); // DATA_ITEM tmp = strtok(NULL, TOKEN); if (tmp != NULL) strcpy(data_item, tmp); //DPRINT("Expoding Message... %s, %s, %s.\n", service, msg_cmd, data_item); if (strcmp(msg_cmd, "EXECUTE") == 0) { // DPRINT("EXECUTE message command recv.\n"); if (!NxApp::Instance()->VerifyClient(service)) return; if (strcmp(data_item, "search") == 0) { DPRINT("%s, %s, %s\n", service, msg_cmd, data_item); char *searchStr = new char[MAX_LENGTH]; char *width = new char[4]; char *data = strtok(NULL, TOKEN); strcpy(searchStr, data); data = strtok(NULL, TOKEN); strcpy(width, data); ExecuteSearch(ipc_id, searchStr, atoi(width)); delete[]searchStr; delete[]width; searchStr = width = NULL; } if (strcmp(data_item, "showrecord") == 0) { char *data = new char[255]; tmp = strtok(NULL, TOKEN); strcpy(data, tmp); viewRecord(data); delete[]data; data = NULL; } } // Memory Mangement delete[]service; delete[]msg_cmd; delete[]data_item; delete[]tokenMsg; service = msg_cmd = data_item = tokenMsg = NULL; NxApp::Instance()->ServerIPCHandler(fd, ipc_id, (char *) passMsg); delete[]passMsg; passMsg = NULL;}voidNxNotepad::ExecuteSearch(int ipc_id, char *searchStr, int width){ if (searchStr == NULL) return; char *msg = new char[MAX_LENGTH]; NxNote *note; while ((note = search(searchStr)) != NULL) { char *result = formatString(note, width); // Send DATA message to client // (e.g. "nxnotepad^DATA^1^Century *Software* is neato^") strcpy(msg, "nxnotepad^DATA^search^"); strcat(msg, "-2^"); // means show on filename strcat(msg, note->szFile); strcat(msg, "^"); strcat(msg, result); strcat(msg, "^"); NxApp::Instance()->Write_Fd(ipc_id, msg, MAX_LENGTH); } strcpy(msg, "nxnotepad^ACK^DATA^search^"); NxApp::Instance()->Write_Fd(ipc_id, msg, MAX_LENGTH); delete[]msg; msg = NULL;}#endif//// Window Methods//voidNxNotepad::exit_callback(Fl_Widget * fl, void *l){ exit_flag = 1; main_window->hide();}Fl_Window *NxNotepad::get_main_window(){ if (main_window) return main_window; else return 0;}voidNxNotepad::show_default_window(){ show_window(note_list_window->GetWindowPtr());}voidNxNotepad::make_list_window(){ note_list_window = new NxPimWindow(APP_NAME, list_window_menu, note_db, CAT_DATABASE, NOTE_DATABASE, (void (*)(const char *)) set_category); add_window((Fl_Window *) note_list_window->GetWindowPtr()); { NxScroll *o = note_list = new NxScroll(-1, 31, W_W + 2, BUTTON_Y - 33); o->movable(false); { tree = new Fl_Toggle_Tree(0, 31, W_W, 10); tree->callback(note_tree_callback); NxApp::Instance()->def_font(tree); } o->end(); note_list_window->add((Fl_Widget *) o); } { NxBox *o = new NxBox(5, 5, 85, 25, ""); note_list_window->add((Fl_Widget *) o); } { NxButton *o = new NxButton(BUTTON_X, BUTTON_Y, BUTTON_WIDTH - 5, BUTTON_HEIGHT, "Add"); o->callback(new_callback); note_list_window->add((Fl_Widget *) o); } { NxButton *o = new NxButton(BUTTON_X + 58, BUTTON_Y, BUTTON_WIDTH - 5, BUTTON_HEIGHT, "Edit"); o->callback(edit_callback);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -