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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
|
/*
* Copyright 2017 Samsung Electronics Co., Ltd
*
* Licensed under the Flora License, Version 1.1 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://floralicense.org/license/
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "gallery/view/PageContent.h"
#include "common.h"
namespace gallery { namespace { namespace impl {
constexpr LayoutTheme LAYOUT_MORE_OPTIONS
{"layout", "gallery", "more_options"};
constexpr LayoutTheme LAYOUT_SELECT_MODE
{"layout", "select_mode", "default"};
constexpr LayoutTheme LAYOUT_BOTTOM_BUTTON
{"layout", "bottom_button", "default"};
constexpr EdjePart PART_MORE_OPTIONS {"gallery.swallow.more_options"};
constexpr EdjePart PART_OVERLAY {"gallery.swallow.overlay"};
constexpr EdjeSignal SIGNAL_SHOW_SELECT_BUTTON {"select_mode,button,show"};
constexpr EdjeSignal SIGNAL_HIDE_SELECT_BUTTON {"select_mode,button,hide"};
constexpr EdjeSignal SIGNAL_SHOW_MORE_OPTIONS {"cue,show"};
constexpr EdjeSignal SIGNAL_HIDE_MORE_OPTIONS {"cue,hide"};
constexpr EdjeSignalSrc SIGNAL_SRC_EXT {"ext"};
template <class OBJ, class FUNC, class ...ARGS>
Result callSafe(OBJ *obj, FUNC &&func, ARGS &&...args)
{
if (!obj) {
FAIL_RETURN(RES_FAIL, "obj is NULL!");
}
func(*obj, std::forward<ARGS>(args)...);
return RES_OK;
}
}}}
namespace gallery {
using ucl::Layout;
using ucl::LayoutSRef;
using ucl::PART_BUTTON;
using ucl::PART_CONTENT;
using ucl::PART_ICON;
// PageContent::Builder //
PageContent::Builder::Builder() :
m_flags(0)
{
}
PageContent::Builder &PageContent::Builder::setFlags(const int flags)
{
m_flags = flags;
return *this;
}
PageContentSRef PageContent::Builder::build(ElmWidget &parent) const
{
auto layout = Layout::Builder().
setTheme(impl::LAYOUT_MORE_OPTIONS).
build(parent);
if (!layout) {
LOG_RETURN_VALUE(RES_FAIL, {}, "Layout::build() failed!");
}
auto result = makeShared<PageContent>(layout, m_flags);
result->bindToEo();
return result;
}
// PageContent //
PageContent::PageContent(IRefCountObj &rc,
const LayoutSRef &layout, const int flags) :
ElmWidget(&rc, *layout),
m_mainLayout(layout.get())
{
prepare(flags);
}
PageContent::~PageContent()
{
}
void PageContent::prepare(const int flags)
{
m_mainLayout->setIsOwner(false);
Layout *parent = m_mainLayout;
if (flags & FLAG_SELECT_BUTTON) {
m_selectMode = Layout::Builder().
setTheme(impl::LAYOUT_SELECT_MODE).
build(*parent);
if (m_selectMode) {
parent->setContent(*m_selectMode);
parent = m_selectMode.get();
}
}
if (flags & FLAG_BOTTOM_BUTTON) {
m_bottomButton = Layout::Builder().
setTheme(impl::LAYOUT_BOTTOM_BUTTON).
build(*parent);
if (m_bottomButton) {
parent->setContent(*m_bottomButton);
parent = m_bottomButton.get();
}
}
}
Result PageContent::set(Evas_Object *const eo, const Part part)
{
return doWithPart(part,
[eo](Layout &layout, const EdjePart part)
{
layout.setContent(eo, part);
});
}
Evas_Object *PageContent::unset(const Part part)
{
Evas_Object *result = {};
doWithPart(part,
[&result](Layout &layout, const EdjePart part)
{
result = layout.unsetContent(part);
});
return result;
}
Evas_Object *PageContent::get(const Part part) const
{
Evas_Object *result = {};
doWithPart(part,
[&result](Layout &layout, const EdjePart part)
{
result = layout.getContent(part);
});
return result;
}
Result PageContent::setSelectButtonVisible(const bool visible)
{
if (!m_selectMode) {
LOG_RETURN(RES_FAIL, "Select button is not supported!");
}
m_selectMode->emit(visible ? impl::SIGNAL_SHOW_SELECT_BUTTON :
impl::SIGNAL_HIDE_SELECT_BUTTON);
return RES_OK;
}
Result PageContent::setMoreOptionsVisible(const bool visible)
{
const auto content = m_mainLayout->getContent(impl::PART_MORE_OPTIONS);
if (!content) {
LOG_RETURN(RES_FAIL, "More option is not created!");
}
elm_layout_signal_emit(content, (visible ?
impl::SIGNAL_SHOW_MORE_OPTIONS :
impl::SIGNAL_HIDE_MORE_OPTIONS),
impl::SIGNAL_SRC_EXT);
return RES_OK;
}
template <class FUNC>
Result PageContent::doWithPart(const Part part, FUNC &&func) const
{
switch (part) {
case Part::DEFAULT:
return impl::callSafe(getTopLayout(), func, PART_CONTENT);
case Part::OVERLAY:
func(*m_mainLayout, impl::PART_OVERLAY);
return RES_OK;
case Part::MORE_OPTIONS:
func(*m_mainLayout, impl::PART_MORE_OPTIONS);
return RES_OK;
case Part::SELECT_BUTTON:
return impl::callSafe(m_selectMode.get(), func, PART_ICON);
case Part::BOTTOM_BUTTON:
return impl::callSafe(m_bottomButton.get(), func, PART_BUTTON);
}
LOG_RETURN(RES_FATAL, "Should not be here!");
}
Layout *PageContent::getTopLayout() const
{
if (m_bottomButton) {
return m_bottomButton.get();
}
if (m_selectMode) {
return m_selectMode.get();
}
return m_mainLayout;
}
}
|