summaryrefslogtreecommitdiffstats
path: root/sfx2/source/control/emojicontrol.cxx
blob: b2961c35df255ae124cfb54350e2bf3340888dc1 (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
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
177
178
179
180
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#include <emojicontrol.hxx>
#include <sfx2/emojipopup.hxx>
#include <emojiview.hxx>
#include <thumbnailviewitem.hxx>
#include <rtl/ustrbuf.hxx>
#include <vcl/tabpage.hxx>
#include <comphelper/propertysequence.hxx>
#include <comphelper/dispatchcommand.hxx>
#include <officecfg/Office/Common.hxx>

const char FILTER_PEOPLE[]    = "people";
const char FILTER_NATURE[]    = "nature";
const char FILTER_FOOD[]      = "food";
const char FILTER_ACTIVITY[]  = "activity";
const char FILTER_TRAVEL[]    = "travel";
const char FILTER_OBJECTS[]   = "objects";
const char FILTER_SYMBOLS[]   = "symbols";
const char FILTER_FLAGS[]     = "flags";
const char FILTER_UNICODE9[]  = "unicode9";

using namespace com::sun::star;

SfxEmojiControl::SfxEmojiControl(EmojiPopup* pControl, vcl::Window* pParent)
    : ToolbarPopup(pControl->getFrameInterface(), pParent, "emojictrl", "sfx/ui/emojicontrol.ui")
{
    get(mpTabControl, "tabcontrol");
    get(mpEmojiView, "emoji_view");

    sal_uInt16 nCurPageId = mpTabControl->GetPageId(FILTER_PEOPLE);
    TabPage *pTabPage = mpTabControl->GetTabPage(nCurPageId);
    ConvertLabelToUnicode(nCurPageId);
    pTabPage->Show();

    nCurPageId = mpTabControl->GetPageId(FILTER_NATURE);
    mpTabControl->SetTabPage(nCurPageId, pTabPage);
    ConvertLabelToUnicode(nCurPageId);
    pTabPage->Show();

    nCurPageId = mpTabControl->GetPageId(FILTER_FOOD);
    mpTabControl->SetTabPage(nCurPageId, pTabPage);
    ConvertLabelToUnicode(nCurPageId);
    pTabPage->Show();

    nCurPageId = mpTabControl->GetPageId(FILTER_ACTIVITY);
    mpTabControl->SetTabPage(nCurPageId, pTabPage);
    ConvertLabelToUnicode(nCurPageId);
    pTabPage->Show();

    nCurPageId = mpTabControl->GetPageId(FILTER_TRAVEL);
    mpTabControl->SetTabPage(nCurPageId, pTabPage);
    ConvertLabelToUnicode(nCurPageId);
    pTabPage->Show();

    nCurPageId = mpTabControl->GetPageId(FILTER_OBJECTS);
    mpTabControl->SetTabPage(nCurPageId, pTabPage);
    ConvertLabelToUnicode(nCurPageId);
    pTabPage->Show();

    nCurPageId = mpTabControl->GetPageId(FILTER_SYMBOLS);
    mpTabControl->SetTabPage(nCurPageId, pTabPage);
    ConvertLabelToUnicode(nCurPageId);
    pTabPage->Show();

    nCurPageId = mpTabControl->GetPageId(FILTER_FLAGS);
    mpTabControl->SetTabPage(nCurPageId, pTabPage);
    ConvertLabelToUnicode(nCurPageId);
    pTabPage->Show();

    nCurPageId = mpTabControl->GetPageId(FILTER_UNICODE9);
    mpTabControl->SetTabPage(nCurPageId, pTabPage);
    ConvertLabelToUnicode(nCurPageId);

    vcl::Font rFont = mpTabControl->GetControlFont();
    rFont.SetFontHeight(TAB_FONT_SIZE);
    mpTabControl->SetControlFont(rFont);
    pTabPage->Show();

    mpEmojiView->SetStyle(mpEmojiView->GetStyle() | WB_VSCROLL);
    mpEmojiView->setItemMaxTextLength(ITEM_MAX_TEXT_LENGTH);
    mpEmojiView->setItemDimensions(ITEM_MAX_WIDTH, 0, ITEM_MAX_HEIGHT, ITEM_PADDING);

    mpEmojiView->Populate();
    mpEmojiView->filterItems(ViewFilter_Category(FILTER_CATEGORY::PEOPLE));

    mpEmojiView->setInsertEmojiHdl(LINK(this, SfxEmojiControl, InsertHdl));
    mpEmojiView->Show();
    mpEmojiView->ShowTooltips(true);

    mpTabControl->SetActivatePageHdl(LINK(this, SfxEmojiControl, ActivatePageHdl));
}

SfxEmojiControl::~SfxEmojiControl()
{
    disposeOnce();
}

void SfxEmojiControl::dispose()
{
    mpTabControl.clear();
    mpEmojiView.clear();

    ToolbarPopup::dispose();
}

void SfxEmojiControl::ConvertLabelToUnicode(sal_uInt16 nPageId)
{
    OUStringBuffer sHexText = "";
    OUString sLabel = mpTabControl->GetPageText(nPageId);
    sHexText.appendUtf32(sLabel.toUInt32(16));
    mpTabControl->SetPageText(nPageId, sHexText.toString());
}

FILTER_CATEGORY SfxEmojiControl::getCurrentFilter() const
{
    const sal_uInt16 nCurPageId = mpTabControl->GetCurPageId();

    if (nCurPageId == mpTabControl->GetPageId(FILTER_PEOPLE))
        return FILTER_CATEGORY::PEOPLE;
    else if (nCurPageId == mpTabControl->GetPageId(FILTER_NATURE))
        return FILTER_CATEGORY::NATURE;
    else if (nCurPageId == mpTabControl->GetPageId(FILTER_FOOD))
        return FILTER_CATEGORY::FOOD;
    else if (nCurPageId == mpTabControl->GetPageId(FILTER_ACTIVITY))
        return FILTER_CATEGORY::ACTIVITY;
    else if (nCurPageId == mpTabControl->GetPageId(FILTER_TRAVEL))
        return FILTER_CATEGORY::TRAVEL;
    else if (nCurPageId == mpTabControl->GetPageId(FILTER_OBJECTS))
        return FILTER_CATEGORY::OBJECTS;
    else if (nCurPageId == mpTabControl->GetPageId(FILTER_SYMBOLS))
        return FILTER_CATEGORY::SYMBOLS;
    else if (nCurPageId == mpTabControl->GetPageId(FILTER_FLAGS))
        return FILTER_CATEGORY::FLAGS;
    else if (nCurPageId == mpTabControl->GetPageId(FILTER_UNICODE9))
        return FILTER_CATEGORY::UNICODE9;

    return FILTER_CATEGORY::PEOPLE;
}

IMPL_LINK_NOARG(SfxEmojiControl, ActivatePageHdl, TabControl*, void)
{
    mpEmojiView->filterItems(ViewFilter_Category(getCurrentFilter()));
}

IMPL_STATIC_LINK(SfxEmojiControl, InsertHdl, ThumbnailViewItem*, pItem, void)
{
    const OUString& sHexText = pItem->getTitle();
    sal_uInt32 cEmojiChar = sHexText.toUInt32(16);

    uno::Reference< uno::XComponentContext > xContext( comphelper::getProcessComponentContext() );
    OUString sFontName(officecfg::Office::Common::Misc::EmojiFont::get(xContext));

    uno::Sequence<beans::PropertyValue> aArgs( comphelper::InitPropertySequence({
            { "Symbols", uno::Any(OUString(&cEmojiChar, 1)) },
            // add font settings here
            { "FontName", uno::Any(sFontName) }
        }));

    comphelper::dispatchCommand(".uno:InsertSymbol", aArgs);
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */