1 // Copyright 2010-2018, Google Inc.
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
6 // met:
7 //
8 //     * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 //     * Redistributions in binary form must reproduce the above
11 // copyright notice, this list of conditions and the following disclaimer
12 // in the documentation and/or other materials provided with the
13 // distribution.
14 //     * Neither the name of Google Inc. nor the names of its
15 // contributors may be used to endorse or promote products derived from
16 // this software without specific prior written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 
30 #ifndef MOZC_UNIX_IBUS_PROPERTY_HANDLER_H_
31 #define MOZC_UNIX_IBUS_PROPERTY_HANDLER_H_
32 
33 #include <memory>
34 #include <vector>
35 
36 #include "base/port.h"
37 #include "unix/ibus/ibus_header.h"
38 #include "unix/ibus/property_handler_interface.h"
39 
40 namespace mozc {
41 
42 namespace client {
43 class ClientInterface;
44 }  // namespace client
45 namespace ibus {
46 
47 class MessageTranslatorInterface;
48 
49 class PropertyHandler : public PropertyHandlerInterface {
50  public:
51   // This class takes the ownership of translator, but not client.
52   PropertyHandler(MessageTranslatorInterface *translator,
53                   client::ClientInterface *client);
54   virtual ~PropertyHandler();
55 
56   virtual void Register(IBusEngine *engine);
57   virtual void ResetContentType(IBusEngine *engine);
58   virtual void UpdateContentType(IBusEngine *engine);
59   virtual void Update(IBusEngine *engine, const commands::Output &output);
60   virtual void ProcessPropertyActivate(IBusEngine *engine,
61                                        const gchar *property_name,
62                                        guint property_state);
63   virtual bool IsActivated() const;
64   virtual bool IsDisabled() const;
65   virtual commands::CompositionMode GetOriginalCompositionMode() const;
66 
67  private:
68   void UpdateContentTypeImpl(IBusEngine *engine, bool disabled);
69   // Appends composition properties into panel
70   void AppendCompositionPropertyToPanel();
71   // Appends tool properties into panel
72   void AppendToolPropertyToPanel();
73   // Appends switch properties into panel
74   void UpdateCompositionModeIcon(
75       IBusEngine* engine, const commands::CompositionMode new_composition_mode);
76   void SetCompositionMode(IBusEngine *engine,
77                           commands::CompositionMode composition_mode);
78 
79   IBusPropList *prop_root_;
80   IBusProperty *prop_composition_mode_;
81   IBusProperty *prop_mozc_tool_;
82   client::ClientInterface *client_;
83   std::unique_ptr<MessageTranslatorInterface> translator_;
84   commands::CompositionMode original_composition_mode_;
85   bool is_activated_;
86   bool is_disabled_;
87 };
88 
89 }  // namespace ibus
90 }  // namespace mozc
91 #endif  // MOZC_UNIX_IBUS_PROPERTY_HANDLER_H_
92