64c43175ede53302d5ce5a5be1ef63971572ca54
[platform/core/csapi/tizenfx.git] / src / ElmSharp / ElmSharp / PreloadedWindow.cs
1 /*
2  * Copyright (c) 2018 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 namespace ElmSharp
18 {
19     internal class PreloadedWindow : Window
20     {
21         static PreloadedWindow s_precreated;
22
23         public PreloadedWindow(bool useBaseLayout=true) : base("PreloadWindow")
24         {
25             s_precreated = this;
26             if (useBaseLayout)
27                 InitializeBaseLayout();
28             WarmupWidgets();
29             BackButtonPressed += DummyHandler;
30             BackButtonPressed -= DummyHandler;
31             void DummyHandler(object sender, System.EventArgs e) { }
32         }
33
34         public Layout BaseLayout
35         {
36             get;
37             protected set;
38         }
39
40         public void InitializeBaseLayout()
41         {
42             var conformant = new Conformant(this);
43             conformant.Show();
44
45             var layout = new Layout(conformant);
46             layout.SetTheme("layout", "application", "default");
47             layout.Show();
48
49             BaseLayout = layout;
50             conformant.SetContent(BaseLayout);
51         }
52
53         public void WarmupWidgets()
54         {
55             new Entry(this).Unrealize();
56             new Scroller(this).Unrealize();
57             new Box(this).Unrealize();
58             new Label(this).Unrealize();
59             new GenList(this).Unrealize();
60             new Button(this).Unrealize();
61             new Check(this).Unrealize();
62             new Naviframe(this).Unrealize();
63             new Slider(this).Unrealize();
64             new Spinner(this).Unrealize();
65             new ProgressBar(this).Unrealize();
66             new GestureLayer(this).Unrealize();
67             new Polygon(this).Unrealize();
68             new Image(this).Unrealize();
69             //TODO: Consider to call Image.LoadAsync()
70         }
71
72         public static PreloadedWindow GetInstance()
73         {
74             var instance = s_precreated;
75             s_precreated = null;
76             return instance;
77         }
78     }
79 }