summaryrefslogtreecommitdiffstats
path: root/src/Editor.h
blob: 6e0bbbb27e59f1b691e5621a964cc17a756e9d8f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/* vim:set et ts=4 sts=4:
 *
 * ibus-pinyin - The Chinese PinYin engine for IBus
 *
 * Copyright (c) 2008-2010 Peng Huang <shawn.p.huang@gmail.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
#ifndef __PY_EDITOR_H_
#define __PY_EDITOR_H_

#include <glib.h>
#include <boost/shared_ptr.hpp>
#include "Signal.h"
#include "String.h"
#include "Text.h"
#include "LookupTable.h"
#include "PinyinProperties.h"
#include "Config.h"

namespace PY {

class Editor;
typedef boost::shared_ptr<Editor> EditorPtr;

class Editor {
public:
    Editor (PinyinProperties & prop, Config & config);
    virtual ~Editor (void);

    virtual gboolean processKeyEvent (guint keyval, guint keycode, guint modifiers);
    virtual void pageUp (void);
    virtual void pageDown (void);
    virtual void cursorUp (void);
    virtual void cursorDown (void);
    virtual void update (void);
    virtual void reset (void);
    virtual void candidateClicked (guint index, guint button, guint state);

    const String & text (void) const { return m_text; }
    void setText (const String & text, guint cursor) {
        m_text = text;
        m_cursor = cursor;
    }

    /* signals */
    signal <void (Text &)> & signalCommitText (void) { return m_signal_commit_text; }
    signal <void (Text &, guint, gboolean)> & signalUpdatePreeditText (void) { return m_signal_update_preedit_text; }
    signal <void ()> & signalShowPreeditText (void) { return m_signal_show_preedit_text; }
    signal <void ()> & signalHidePreeditText (void) { return m_signal_hide_preedit_text; }
    signal <void (Text &, gboolean)> & signalUpdateAuxiliaryText (void) { return m_signal_update_auxiliary_text; }
    signal <void ()> & signalShowAuxiliaryText (void) { return m_signal_show_auxiliary_text; }
    signal <void ()> & signalHideAuxiliaryText (void) { return m_signal_hide_auxiliary_text; }
    signal <void (LookupTable &, gboolean)> & signalUpdateLookupTable (void) { return m_signal_update_lookup_table; }
    signal <void (LookupTable &, gboolean)> & signalUpdateLookupTableFast (void) { return m_signal_update_lookup_table_fast; }
    signal <void ()> & signalShowLookupTable (void) { return m_signal_show_lookup_table; }
    signal <void ()> & signalHideLookupTable (void) { return m_signal_hide_lookup_table; }

protected:
    /* methods */
    void commitText (Text & text) {
        m_signal_commit_text (text);
    }

    void updatePreeditText (Text & text, guint cursor, gboolean visible) {
        m_signal_update_preedit_text (text, cursor, visible);
    }

    void showPreeditText (void) {
        m_signal_show_preedit_text ();
    }

    void hidePreeditText (void) {
        m_signal_hide_preedit_text ();
    }

    void updateAuxiliaryText (Text & text, gboolean visible) {
        m_signal_update_auxiliary_text (text, visible);
    }

    void showAuxiliaryText (void) {
        m_signal_show_auxiliary_text ();
    }

    void hideAuxiliaryText (void) {
        m_signal_hide_auxiliary_text ();
    }

    void updateLookupTable (LookupTable & table, gboolean visible) {
        m_signal_update_lookup_table (table, visible);
    }

    void updateLookupTableFast (LookupTable & table, gboolean visible) {
        m_signal_update_lookup_table_fast (table, visible);
    }

    void showLookupTable (void) {
        m_signal_show_lookup_table ();
    }

    void hideLookupTable (void) {
        m_signal_hide_lookup_table ();
    }

protected:
    /* signals */
    signal <void (Text &)> m_signal_commit_text;
    signal <void ( Text &, guint, gboolean)> m_signal_update_preedit_text;
    signal <void ()> m_signal_show_preedit_text;
    signal <void ()> m_signal_hide_preedit_text;
    signal <void (Text &, gboolean)> m_signal_update_auxiliary_text;
    signal <void ()> m_signal_show_auxiliary_text;
    signal <void ()> m_signal_hide_auxiliary_text;
    signal <void (LookupTable &, gboolean)> m_signal_update_lookup_table;
    signal <void (LookupTable &, gboolean)> m_signal_update_lookup_table_fast;
    signal <void ()> m_signal_show_lookup_table;
    signal <void ()> m_signal_hide_lookup_table;

protected:
    String m_text;
    guint  m_cursor;
    PinyinProperties & m_props;
    Config & m_config;
};

};

#endif