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#include <Carbon/Carbon.h> 31#include <objc/message.h> 32 33#import "CandidateView.h" 34 35#include "base/logging.h" 36#include "base/coordinates.h" 37#include "protocol/commands.pb.h" 38#include "renderer/mac/CandidateWindow.h" 39 40using mozc::commands::Candidates; 41 42namespace mozc { 43namespace renderer { 44namespace mac { 45 46CandidateWindow::CandidateWindow() 47 : command_sender_(nullptr) { 48} 49 50CandidateWindow::~CandidateWindow() { 51} 52 53void CandidateWindow::SetSendCommandInterface( 54 client::SendCommandInterface *send_command_interface) { 55 DLOG(INFO) << "CandidateWindow::SetSendCommandInterface()"; 56 command_sender_ = send_command_interface; 57 58 const CandidateView* candidate_view = (CandidateView*) view_.get(); 59 [candidate_view setSendCommandInterface:send_command_interface]; 60} 61 62void CandidateWindow::InitWindow() { 63 RendererBaseWindow::InitWindow(); 64 const CandidateView* candidate_view = (CandidateView*) view_.get(); 65 [candidate_view setSendCommandInterface:command_sender_]; 66} 67const mozc::renderer::TableLayout *CandidateWindow::GetTableLayout() const { 68 const CandidateView* candidate_view = (CandidateView*) view_.get(); 69 return [candidate_view tableLayout]; 70} 71 72void CandidateWindow::SetCandidates(const Candidates &candidates) { 73 DLOG(INFO) << "CandidateWindow::SetCandidates"; 74 if (candidates.candidate_size() == 0) { 75 return; 76 } 77 78 if (!window_) { 79 InitWindow(); 80 } 81 CandidateView* candidate_view = (CandidateView*) view_.get(); 82 [candidate_view setCandidates:&candidates]; 83 [candidate_view setNeedsDisplay:YES]; 84 NSSize size = [candidate_view updateLayout]; 85 ResizeWindow(size.width, size.height); 86} 87 88void CandidateWindow::ResetView(){ 89 DLOG(INFO) << "CandidateWindow::ResetView()"; 90 view_.reset([[CandidateView alloc] initWithFrame:NSMakeRect(0, 0, 1, 1)]); 91} 92 93} // namespace mozc::renderer::mac 94} // namespace mozc::renderer 95} // namespace mozc 96