upload tizen 2.0 beta code
[profile/ivi/isf.git] / ism / extras / gtk_panel / isf_help_win.cpp
1 /*
2  * ISF(Input Service Framework)
3  *
4  * ISF is based on SCIM 1.4.7 and extended for supporting more mobile fitable.
5  * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
6  *
7  * Contact: Shuo Liu <shuo0805.liu@samsung.com>, Hengliang Luo <hl.luo@samsung.com>
8  *
9  * This library is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU Lesser General Public License as published by the
11  * Free Software Foundation; either version 2.1 of the License, or (at your option)
12  * any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but WITHOUT ANY
15  * WARRANTY; without even the implied warranty of MERCHANTABILITY or
16  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17  * License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with this library; if not, write to the Free Software Foundation, Inc., 51
21  * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  *
23  */
24
25 #include <gtk/gtk.h>
26 #include "isf_help_win.h"
27
28 static GtkWidget *_main_window  = 0;
29 static GtkWidget *_content_box  = 0;
30 static GtkWidget *_help_label   = 0;
31 static GtkWidget *_form         = 0;
32
33
34 extern int        _screen_width;
35 extern float      _width_rate;
36 extern float      _height_rate;
37
38 ISFHelpWin::ISFHelpWin ()
39 {
40 #if HAVE_GCONF
41     if (!_main_window) {
42         _main_window = gtk_main_window_new (GTK_WIN_STYLE_DEFAULT);
43         gtk_main_window_set_title_style (GTK_MAIN_WINDOW (_main_window), GTK_WIN_TITLE_STYLE_TEXT_ICON);
44
45         _form = gtk_form_new (TRUE);
46         gtk_form_set_title (GTK_FORM (_form), "Help");
47         GtkWidget *scroll = gtk_scrolled_window_new (NULL, NULL);
48         gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll),
49                                         GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
50         gtk_container_add (GTK_CONTAINER (_form), scroll);
51
52         _content_box = gtk_vbox_new (false, 0);
53         gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scroll), _content_box);
54
55 #ifdef USING_ISF_SWITCH_BUTTON
56         GtkWidget *softkey = GTK_WIDGET (gtk_form_get_softkey_bar (GTK_FORM (_form)));
57         gtk_softkey_bar_use_ise_switch (GTK_SOFTKEY_BAR (softkey), false);
58         gtk_softkey_bar_set_softkey (GTK_SOFTKEY_BAR (softkey), SOFTKEY4,
59                                      "Exit", NULL,
60                                      (SoftkeyActionType) SOFTKEY_CALLBACK,
61                                      (gpointer) (on_isf_help_back_callback),
62                                      (gpointer) this);
63 #else
64         gtk_form_add_softkey(GTK_FORM(_form), "Exit", NULL, SOFTKEY_CALLBACK, (void *)on_isf_help_back_callback, NULL);
65
66 #endif
67
68         gtk_main_window_add_form (GTK_MAIN_WINDOW (_main_window), GTK_FORM (_form));
69         gtk_main_window_set_current_form (GTK_MAIN_WINDOW (_main_window), GTK_FORM (_form));
70         gtk_widget_show_all (_form);
71     }
72 #endif
73 }
74
75
76 ISFHelpWin::~ISFHelpWin ()
77 {
78     if (_main_window) {
79         gtk_widget_destroy (_main_window);
80         _main_window = 0;
81     }
82     if (_content_box) {
83         gtk_widget_destroy (_content_box);
84         _content_box = 0;
85     }
86     if (_help_label) {
87         gtk_widget_destroy (_help_label);
88         _help_label = 0;
89     }
90     if (_form) {
91         gtk_widget_destroy (_form);
92         _form = 0;
93     }
94 }
95
96 void ISFHelpWin::show_help (const char *title, const char *help_info)
97 {
98     if (!_help_label) {
99         _help_label = gtk_label_new (help_info);
100         gtk_box_pack_start (GTK_BOX (_content_box), _help_label, true, true, 0);
101 #if HAVE_GCONF
102         gtk_form_set_title (GTK_FORM (_form), (gchar *)title);
103 #endif
104         gtk_widget_show_all (_form);
105         gtk_widget_show_all (_main_window);
106         gtk_window_present (GTK_WINDOW (_main_window));
107         gtk_main ();
108     } else {
109         gtk_window_present (GTK_WINDOW (_main_window));
110     }
111 }
112
113 void ISFHelpWin::on_isf_help_back_callback (GtkWidget *softkey,
114                                             gpointer   user_data)
115 {
116     gtk_widget_hide (_main_window);
117     if (_help_label) {
118         gtk_widget_destroy (_help_label);
119         _help_label = 0;
120     }
121     gtk_main_quit ();
122 }
123
124
125 /*
126 vi:ts=4:nowrap:ai:expandtab
127 */