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_RENDERER_UNIX_GTK_WINDOW_BASE_H_ 31 #define MOZC_RENDERER_UNIX_GTK_WINDOW_BASE_H_ 32 33 #include <gtk/gtk.h> 34 35 #include <memory> 36 37 #include "base/coordinates.h" 38 #include "base/port.h" 39 #include "renderer/unix/gtk_window_interface.h" 40 #include "renderer/unix/gtk_wrapper_interface.h" 41 42 #define MOZC_GTK_VIRTUAL_CALLBACK_0(CLASS, RETURN, METHOD) \ 43 static RETURN METHOD ## Thunk(GtkWidget *widget, gpointer userdata) { \ 44 return reinterpret_cast<CLASS*>(userdata)->METHOD(widget); \ 45 } \ 46 virtual RETURN METHOD(GtkWidget *widget); 47 48 #define MOZC_GTK_VIRTUAL_CALLBACK_1(CLASS, RETURN, METHOD, ARG1) \ 49 static RETURN METHOD ## Thunk(GtkWidget *widget, ARG1 one, \ 50 gpointer userdata) { \ 51 return reinterpret_cast<CLASS*>(userdata)->METHOD(widget, one); \ 52 } \ 53 virtual RETURN METHOD(GtkWidget *widget, ARG1 one); 54 55 namespace mozc { 56 namespace renderer { 57 namespace gtk { 58 59 class GtkWindowBaseTest; 60 class CandidateWindowTest; 61 62 class GtkWindowBase : public GtkWindowInterface { 63 public: 64 // GtkWindowBase takes ownership of GtkWrapperInterface. 65 explicit GtkWindowBase(GtkWrapperInterface *gtk); 66 virtual ~GtkWindowBase(); 67 68 virtual void ShowWindow(); 69 virtual void HideWindow(); 70 virtual GtkWidget *GetWindowWidget(); 71 virtual GtkWidget *GetCanvasWidget(); 72 73 virtual Rect GetWindowRect(); 74 virtual Size GetWindowSize(); 75 virtual Point GetWindowPos(); 76 77 virtual bool IsActive(); 78 virtual bool DestroyWindow(); 79 virtual void Move(const Point &pos); 80 virtual void Resize(const Size &size); 81 virtual void Redraw(); 82 83 virtual void Initialize(); 84 virtual Size Update(const commands::Candidates &candidates); 85 virtual Rect GetCandidateColumnInClientCord() const; 86 87 virtual void OnMouseLeftUp(const Point &pos); 88 virtual void OnMouseLeftDown(const Point &pos); 89 virtual void OnMouseRightUp(const Point &pos); 90 virtual void OnMouseRightDown(const Point &pos); 91 virtual void ReloadFontConfig(const string &font_description); 92 93 virtual bool SetSendCommandInterface( 94 client::SendCommandInterface *send_command_interface); 95 96 // Callbacks 97 MOZC_GTK_VIRTUAL_CALLBACK_0(GtkWindowBase, bool, OnDestroy) 98 MOZC_GTK_VIRTUAL_CALLBACK_1(GtkWindowBase, bool, OnPaint, GdkEventExpose *) 99 MOZC_GTK_VIRTUAL_CALLBACK_1(GtkWindowBase, gboolean, OnMouseDown, 100 GdkEventButton *) 101 MOZC_GTK_VIRTUAL_CALLBACK_1(GtkWindowBase, gboolean, OnMouseUp, 102 GdkEventButton *) 103 104 std::unique_ptr<GtkWrapperInterface> gtk_; 105 106 protected: 107 client::SendCommandInterface *send_command_interface_; 108 109 private: 110 GtkWidget *window_; 111 GtkWidget *canvas_; 112 113 friend class GtkWindowBaseTest; 114 friend class CandidateWindowTest; 115 116 DISALLOW_COPY_AND_ASSIGN(GtkWindowBase); 117 }; 118 119 } // namespace gtk 120 } // namespace renderer 121 } // namespace mozc 122 123 #undef MOZC_GTK_VIRTUAL_CALLBACK_0 124 #undef MOZC_GTK_VIRTUAL_CALLBACK_1 125 126 #endif // MOZC_RENDERER_UNIX_GTK_WINDOW_BASE_H_ 127