Refactor appcore-widget
[platform/core/appfw/appcore-widget.git] / include / widget_base.hh
1 /*
2  * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef WIDGET_BASE_HH_
18 #define WIDGET_BASE_HH_
19
20 #include <app_common.h>
21
22 #include <memory>
23 #include <string>
24
25 #include <app_core_multi_window_base.hh>
26
27 #ifndef EXPORT_API
28 #define EXPORT_API __attribute__((visibility("default")))
29 #endif
30
31 namespace tizen_cpp {
32
33 class EXPORT_API WidgetBase : public AppCoreMultiWindowBase {
34  public:
35   WidgetBase();
36   virtual ~WidgetBase();
37
38   std::string GetViewerEndpoint();
39   void Run(int argc, char** argv) override;
40   void Exit() override;
41   int OnControl(tizen_base::Bundle b) override;
42   int OnCreate() override;
43   int OnTerminate() override;
44   int OnReceive(aul_type type, tizen_base::Bundle b) override;
45   void ExitContext(std::shared_ptr<Context> context) override;
46
47  protected:
48   void Dispose() override;
49
50  private:
51   friend class WidgetContext;
52   class Impl;
53   std::unique_ptr<Impl> impl_;
54 };
55
56 class EXPORT_API WidgetContext : public AppCoreMultiWindowBase::Context {
57  public:
58   enum class DestroyType {
59     PERMANENT,
60     TEMPORARY
61   };
62
63   WidgetContext(std::string context_id, std::string inst_id,
64       AppCoreMultiWindowBase* app);
65   virtual ~WidgetContext();
66   virtual bool OnCreate(const tizen_base::Bundle& contents, int w, int h) = 0;
67   virtual void OnDestroy(DestroyType reason,
68       const tizen_base::Bundle& contents) = 0;
69   virtual void OnPause();
70   virtual void OnResume();
71   virtual void OnResize(int w, int h);
72   virtual void OnUpdate(const tizen_base::Bundle& contents, bool force);
73   void ExitAsync();
74   int SetContents(const tizen_base::Bundle& contents);
75   int WindowBind(std::string id, Ecore_Wl2_Window* wl_win);
76
77  private:
78   using AppCoreMultiWindowBase::Context::WindowBind;
79   void OnCreate() override;
80   void OnTerminate() override;
81
82  private:
83   friend class WidgetBase;
84   class Impl;
85   std::unique_ptr<Impl> impl_;
86 };
87
88 }  // namespace tizen_cpp
89
90 #endif  // WIDGET_BASE_HH_