?? memopad_edit.c
字號:
#include <string.h>#include "glib.h"#include "mwtypes.h"#include "emtk.h"#ifndef FILEMODE#include "date_chooser.h"#include "pivotal_gmtime_r.h"#endif#include "memopad.h"#include "memopad_record.h"#ifdef LAUNCHER_SUPPORT#include "deskmsg.h"#endif#ifdef FONT_TABLE#include "font_table.h"#else #define lookupFont(a, b) (FONT1)#endif#include "laf/laf.h"#ifdef FILEMODE#undef ENABLE_ZOOM#endif#if !defined(FILEMODE) && !defined(NOGDBM)#include "db.h"#endif#include "i18n.h"//#define EDITOR_BUFFER_SIZE 0x40000 /* 256k byte buffer */#define EDITOR_BUFFER_SIZE 0x10000 /* 64k byte buffer */typedef enum { SHORTCUT_SMALL_FONT, SHORTCUT_MEDIUM_FONT, SHORTCUT_LARGE_FONT, SHORTCUT_IME, SHORTCUT_IME_ENG, SHORTCUT_IME_THAI } ShortcutAction;enum { NEW_MEMO, DELETE_MEMO, ACTION_SMALL_FONT, ACTION_MEDIUM_FONT, ACTION_LARGE_FONT };static int memo_edit_window, text_id, done_id, client_window;#ifndef FILEMODEstatic int delete_id, dialog_id;#endifstatic Memo *current_memo;static int database;static MemopadCallBack *callbacks;static WindowRect clientWindowRect;#ifndef FILEMODEstatic int large_shortcut, medium_shortcut, small_shortcut, ime_shortcut, eng_shortcut, thai_shortcut;static int calendar_btn;static int date_entry, title_entry;static int lastShortcutButton;static int toolbar;static int ime_state = 0;static int ime_heights[3] = { 60, 55, 75 };#endif/* Points to LC_ALL environment variable */extern char *lc_all;static int current_font;static void memo_ime_activate (int flag){/* For Noahtech only */#ifdef __uClinux__ DESKTOP_CHANNEL channel; MSG msg; int msgLen; printf("***** Launching IME = %d\n", flag); msgLen = msg_command_input_control( (flag) ? MSG_COMMAND_INPUT_ACTIVATE : MSG_COMMAND_INPUT_DEACTIVATE, &msg); desktop_channel_connect_specified_channel_name(&channel, "/tmp/ime"); desktop_channel_send(&channel, &msg, msgLen); desktop_channel_disconnect(&channel);#endif}static void memoModified(int text, void *data, void *userData) { current_memo->dirty = TRUE;}static void close_editor(int window, void *data) { int *feedback = (int *) data;#ifndef FILEMODE char *buf; DESKTOP_CHANNEL channel; MSG msg; int msgLen; desktop_channel_connect(&channel); msgLen = msg_command_input(0, &msg); desktop_channel_send(&channel, &msg, msgLen); desktop_channel_disconnect(&channel); if (current_memo) { buf = g_new0(char, EDITOR_BUFFER_SIZE); emtk_text_get_value(text_id, buf, EDITOR_BUFFER_SIZE); if (current_memo->content) g_free(current_memo->content); current_memo->content = g_strdup(buf); emtk_entry_get_value(title_entry, current_memo->title, 40); g_free(buf); if (current_memo->dirty) { // only save when it is modified if (!current_memo->new) { memopad_record_save(database, current_memo); callbacks->modified(current_memo->memo_id, current_memo); } else { if (strlen(current_memo->content) != 0) { memopad_record_save(database, current_memo); callbacks->new(current_memo->memo_id, current_memo); } } } if (current_memo) { memopad_record_destroy(current_memo); } } *feedback = EMTK_APP_WINDOW_DESTROY_ONLY;#else *feedback = EMTK_APP_WINDOW_DESTROY_WITH_EMTK_CLOSE;#endif emtk_object_remove(text_id); text_id = 0; #ifndef FILEMODE ime_state = 0; *feedback = EMTK_APP_WINDOW_DESTROY_ONLY;#else *feedback = EMTK_APP_WINDOW_DESTROY_WITH_EMTK_CLOSE;#endif //memo_ime_activate (FALSE);}static void done_handler(int bid, void *data) { memo_ime_activate (FALSE); emtk_app_close_window(memo_edit_window);}#ifndef FILEMODEstatic void deleteMemo() { memopad_record_delete(database, current_memo); callbacks->deleted(current_memo->memo_id); if (current_memo->content) g_free(current_memo->content); g_free(current_memo); current_memo = NULL; emtk_app_close_window(memo_edit_window);}static void confirm_response(int dialog, int response) { switch(response) { case EMTK_DIALOG_OK: deleteMemo(); break; case EMTK_DIALOG_CANCEL: break; // do nothing }}static void draw_confirm(int win, WindowRect *clientRect) { emtk_window_add_object(win, emtk_label_new(win, 10, 20, FONT2, FALSE, _("Delete current memo?")));}static void show_confirm_dialog(int id, void *data) { WindowRect rect = { APP_WINDOW_X, APP_WINDOW_Y+APP_WINDOW_H-116, APP_WINDOW_W, 100}; dialog_id = emtk_app_dialog_new(_("Delete Memo"), FONT2, FONT1, draw_confirm, EMTK_DIALOG_OK | EMTK_DIALOG_CANCEL, &rect, confirm_response, NULL);}#endif/* content NULL assumes text exists in current text widget */static void editorSetFont(int window, int font, WindowRect *clientRect, char *content, int content_len) { int ascent, descent, row_height; int nrp; row_height = emtk_get_font_height(font, &ascent, &descent); #ifndef FILEMODE if (ime_state) { /* TODO: modify index */ switch(ime_state & INPUT_LANG_MASK) { case INPUT_ENGLISH: nrp = (clientRect->h - ime_heights[0]) / row_height; break; case INPUT_CHINESE: nrp = (clientRect->h - ime_heights[1]) / row_height; break; case INPUT_THAI: nrp = (clientRect->h - ime_heights[2]) / row_height; break; } } else { nrp = (clientRect->h - 20 - 40) / row_height; }#else nrp = (clientRect->h - 20) / row_height;#endif if (text_id == 0) {#ifndef FILEMODE text_id = emtk_text_new(window, 0, 40, clientRect->w - SCROLLBAR_WIDTH, row_height, nrp, KEY_TYPE_ANY, EDITOR_BUFFER_SIZE, font);#else text_id = emtk_text_new(window, 0, 0, clientRect->w - SCROLLBAR_WIDTH, row_height, nrp, KEY_TYPE_ANY, content_len, font);#endif emtk_text_set_value(text_id, content, content_len); emtk_text_set_border_width(text_id, 0); emtk_text_set_value_change_callback(text_id, memoModified, NULL); emtk_window_add_object(window, text_id); emtk_text_add_vscrollbar_new(text_id, SCROLLBAR_WIDTH, VSCROLLBAR_ALIGN_RIGHT); } else { emtk_text_set_height_info (text_id, row_height, nrp); emtk_text_set_font (text_id, font); } emtk_text_show(text_id);}#ifndef FILEMODEstatic void launchIME(int code) { DESKTOP_CHANNEL channel; MSG msg; int msgLen; msgLen = msg_command_input(code, &msg); desktop_channel_connect(&channel); desktop_channel_send(&channel, &msg, msgLen); desktop_channel_disconnect(&channel);}static void toolbar_handler(int shortcut_button, int action, void *data) { int font = FONT1; if (shortcut_button != ime_shortcut && shortcut_button != eng_shortcut && shortcut_button != thai_shortcut) { if (lastShortcutButton) emtk_app_set_shortcut_button_toggle_state(lastShortcutButton, FALSE); emtk_app_set_shortcut_button_toggle_state(shortcut_button, TRUE); lastShortcutButton = shortcut_button; } switch (action) {
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -