File: fcitx_mozc.h

package info (click to toggle)
mozc 2.23.2815.102+dfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 138,784 kB
  • sloc: cpp: 223,701; java: 46,355; xml: 32,265; python: 8,557; lisp: 2,184; ansic: 763; sh: 121; yacc: 93; makefile: 83
file content (176 lines) | stat: -rw-r--r-- 5,852 bytes parent folder | download | duplicates (4)
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
// Copyright 2012~2013, Weng Xuetian <wengxt@gmail.com>
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
//     * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
//     * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#ifndef MOZC_UNIX_FCITX_FCITX_MOZC_H_
#define MOZC_UNIX_FCITX_FCITX_MOZC_H_

#include <memory>

#include <fcitx/instance.h>
#include <fcitx/candidate.h>
#include <fcitx-config/hotkey.h>
#include <libintl.h>

#include "base/port.h"
#include "base/run_level.h"
#include "protocol/commands.pb.h"
#include "client/client_interface.h"
#include "mozc_connection.h"

#define _(x) dgettext("fcitx-mozc", (x))

INPUT_RETURN_VALUE FcitxMozcGetCandidateWord(void* arg, FcitxCandidateWord* candWord);;

namespace mozc
{

namespace fcitx
{
const int32 kBadCandidateId = -12345;
class IMEngineFactory;
class MozcConnectionInterface;
class MozcResponseParser;
class KeyTranslator;

struct PreeditItem {
        std::string str;
        FcitxMessageType type;
};

// Preedit string and its attributes.
struct PreeditInfo
{
    uint32 cursor_pos;
    
    std::vector<PreeditItem> preedit;
};

class FcitxMozc
{
public:
    // This constructor is used by unittests.
    FcitxMozc ( FcitxInstance* instance,
                MozcConnectionInterface *connection,
                MozcResponseParser *parser );
    virtual ~FcitxMozc();

    bool process_key_event (FcitxKeySym sym, uint32 keycode, uint32 state, bool layout_is_jp, bool is_key_up);
    void select_candidate ( FcitxCandidateWord* candWord );
    void resetim();
    void reset();
    void init();
    void focus_out();
    bool paging(bool prev);

    // Functions called by the MozcResponseParser class to update UI.

    // Displays a 'result' (aka 'commit string') on FCITX UI.
    void SetResultString ( const std::string &result_string );
    // Displays a 'preedit' string on FCITX UI. This function takes ownership
    // of preedit_info. If the parameter is NULL, hides the string currently
    // displayed.
    void SetPreeditInfo ( const PreeditInfo *preedit_info );
    // Displays an auxiliary message (e.g., an error message, a title of
    // candidate window). If the string is empty (""), hides the message
    // currently being displayed.
    void SetAuxString ( const std::string &str );
    // Sets a current composition mode (e.g., Hankaku Katakana).
    void SetCompositionMode ( mozc::commands::CompositionMode mode );
    
    void SendCompositionMode ( mozc::commands::CompositionMode mode );

    // Sets the url to be opened by the default browser.
    void SetUrl ( const string &url );

    const std::string& GetIconFile(const std::string key);
    
    const std::string& GetCurrentCompositionModeIcon();
    
    mozc::commands::CompositionMode GetCompositionMode() { return composition_mode_; }
    
    FcitxInstance* GetInstance() { return instance; }
    
    FcitxInputState* GetInputState();

    mozc::client::ClientInterface* GetClient() { return connection_->GetClient(); }

    bool SendCommand(const mozc::commands::SessionCommand& session_command, mozc::commands::Output* new_output);

    void SetUsage(const std::string& title, const std::string& description);

    std::pair<std::string, std::string> GetUsage();

    void DrawAll();

private:
    friend class FcitxMozcTest;

    // Adds Mozc-specific icons to FCITX toolbar.
    void InitializeBar();
    
    void InitializeMenu();

    // Parses the response from mozc_server. Returns whether the server consumes
    // the input or not (true means 'consumed').
    bool ParseResponse ( const mozc::commands::Output &request );

    void ClearAll();
    void DrawPreeditInfo();
    void DrawAux();

    // Open url_ with a default browser.
    void OpenUrl();

    FcitxInstance* instance;
    FcitxInputState* input;
    const std::unique_ptr<MozcConnectionInterface> connection_;
    const std::unique_ptr<MozcResponseParser> parser_;

    // Strings and a window currently displayed on FCITX UI.
    std::unique_ptr<const PreeditInfo> preedit_info_;
    std::string aux_;  // error tooltip, or candidate window title.
    string url_;  // URL to be opened by a browser.
    mozc::commands::CompositionMode composition_mode_;
    
    std::map<std::string, std::string> iconMap;
    
    FcitxUIMenu compositionMenu;
    FcitxUIMenu toolMenu;
    string description;
    string title;

    DISALLOW_COPY_AND_ASSIGN ( FcitxMozc );
};

}  // namespace fcitx

}  // namespace mozc

#endif  // MOZC_UNIX_FCITX_FCITX_MOZC_H_