Debian Codegraph @

src/af/xap/gtk/xap_UnixDlg_WindowMore.cpp

raw
1 /* -*- mode: C++; tab-width: 4; c-basic-offset: 4; -*- */
2
3 /* AbiSource Application Framework
4 * Copyright (C) 1998-2000 AbiSource, Inc.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 * 02110-1301 USA.
20 */
21
22 #include "ut_string.h"
23 #include "ut_assert.h"
24 #include "ut_debugmsg.h"
25
26 #include "xap_UnixDialogHelper.h"
27
28 #include "xap_App.h"
29 #include "xap_UnixApp.h"
30 #include "xap_Frame.h"
31
32 #include "xap_Dialog_Id.h"
33 #include "xap_Dlg_WindowMore.h"
34 #include "xap_UnixDlg_WindowMore.h"
35
36 /*****************************************************************/
37
38 #define CUSTOM_RESPONSE_VIEW 1
39
40 /*****************************************************************/
41
42 XAP_Dialog * XAP_UnixDialog_WindowMore::static_constructor(XAP_DialogFactory * pFactory,
43 XAP_Dialog_Id id)
44 {
45 return new XAP_UnixDialog_WindowMore(pFactory,id);
46 }
47
48 XAP_UnixDialog_WindowMore::XAP_UnixDialog_WindowMore(XAP_DialogFactory * pDlgFactory,
49 XAP_Dialog_Id id)
50 : XAP_Dialog_WindowMore(pDlgFactory,id)
51 {
52 }
53
54 XAP_UnixDialog_WindowMore::~XAP_UnixDialog_WindowMore(void)
55 {
56 }
57
58 void XAP_UnixDialog_WindowMore::s_list_dblclicked(GtkTreeView * /*treeview*/,
59 GtkTreePath * /*arg1*/,
60 GtkTreeViewColumn * /*arg2*/,
61 XAP_UnixDialog_WindowMore * me)
62 {
63 gtk_dialog_response (GTK_DIALOG(me->m_windowMain), CUSTOM_RESPONSE_VIEW);
64 }
65
66 /*****************************************************************/
67
68 void XAP_UnixDialog_WindowMore::runModal(XAP_Frame * pFrame)
69 {
70 // Initialize member so we know where we are now
71 m_ndxSelFrame = m_pApp->findFrame(pFrame);
72 UT_ASSERT_HARMLESS(m_ndxSelFrame >= 0);
73
74 // Build the window's widgets and arrange them
75 GtkWidget * mainWindow = _constructWindow();
76 UT_return_if_fail(mainWindow);
77
78 // Populate the window's data items
79 _populateWindowData();
80
81 switch ( abiRunModalDialog ( GTK_DIALOG(mainWindow), pFrame, this, CUSTOM_RESPONSE_VIEW, false ) )
82 {
83 case CUSTOM_RESPONSE_VIEW:
84 event_View () ; break ;
85 default:
86 event_Cancel (); break ;
87 }
88
89 abiDestroyWidget ( mainWindow ) ;
90 }
91
92 void XAP_UnixDialog_WindowMore::event_View(void)
93 {
94 GtkTreeSelection * selection;
95 GtkTreeIter iter;
96 GtkTreeModel * model;
97
98 gint row = 0;
99
100 m_answer = XAP_Dialog_WindowMore::a_CANCEL;
101
102 selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_listWindows) );
103
104 // if there is no selection, or the selection's data (GtkListItem widget)
105 // is empty, return cancel. GTK can make this happen.
106 if ( !selection ||
107 !gtk_tree_selection_get_selected (selection, &model, &iter)
108 )
109 return;
110
111 // get the ID of the selected Type
112 gtk_tree_model_get (model, &iter, 1, &row, -1);
113
114 if (row >= 0) {
115 m_ndxSelFrame = static_cast<UT_uint32>(row);
116 m_answer = XAP_Dialog_WindowMore::a_OK;
117 }
118 }
119
120 void XAP_UnixDialog_WindowMore::event_Cancel(void)
121 {
122 m_answer = XAP_Dialog_WindowMore::a_CANCEL;
123 }
124
125 /*****************************************************************/
126
127 GtkWidget * XAP_UnixDialog_WindowMore::_constructWindow(void)
128 {
129 const XAP_StringSet * pSS = m_pApp->getStringSet();
130 GtkCellRenderer *renderer;
131 GtkTreeViewColumn *column;
132
133 // load the dialog from the UI file
134 #if GTK_CHECK_VERSION(3,0,0)
135 GtkBuilder* builder = newDialogBuilder("xap_UnixDlg_WindowMore.ui");
136 #else
137 GtkBuilder* builder = newDialogBuilder("xap_UnixDlg_WindowMore-2.ui");
138 #endif
139
140 // Update our member variables with the important widgets that
141 // might need to be queried or altered later
142 m_windowMain = GTK_WIDGET(gtk_builder_get_object(builder, "xap_UnixDlg_WindowMore"));
143 m_listWindows = GTK_WIDGET(gtk_builder_get_object(builder, "tvAvailableDocuments"));
144
145 std::string s;
146 pSS->getValueUTF8(XAP_STRING_ID_DLG_MW_MoreWindows,s);
147 gtk_window_set_title (GTK_WINDOW(m_windowMain), s.c_str());
148 localizeLabelMarkup(GTK_WIDGET(gtk_builder_get_object(builder, "lbAvailableDocuments")), pSS, XAP_STRING_ID_DLG_MW_AvailableDocuments);
149 localizeButtonUnderline(GTK_WIDGET(gtk_builder_get_object(builder, "btView")), pSS, XAP_STRING_ID_DLG_MW_ViewButton);
150
151 // add a column to our TreeViews
152
153 renderer = gtk_cell_renderer_text_new ();
154 column = gtk_tree_view_column_new_with_attributes ("Format",
155 renderer,
156 "text",
157 0,
158 NULL);
159 gtk_tree_view_append_column( GTK_TREE_VIEW(m_listWindows), column);
160
161 // connect a dbl-clicked signal to the column
162
163 g_signal_connect_after(G_OBJECT(m_listWindows),
164 "row-activated",
165 G_CALLBACK(s_list_dblclicked),
166 static_cast<gpointer>(this));
167
168 g_object_unref(G_OBJECT(builder));
169
170 return m_windowMain;
171 }
172
173 void XAP_UnixDialog_WindowMore::_populateWindowData(void)
174 {
175 GtkListStore *model;
176 GtkTreeIter iter;
177
178 model = gtk_list_store_new (2,
179 G_TYPE_STRING,
180 G_TYPE_INT);
181
182 for (UT_sint32 i = 0; i < m_pApp->getFrameCount(); i++)
183 {
184 XAP_Frame * f = m_pApp->getFrame(i);
185 UT_return_if_fail(f);
186
187 // Add a new row to the model
188 gtk_list_store_append (model, &iter);
189 gtk_list_store_set (model, &iter,
190 0, f->getTitle().utf8_str(),
191 1, i,
192 -1);
193 }
194
195 gtk_tree_view_set_model(GTK_TREE_VIEW(m_listWindows), reinterpret_cast<GtkTreeModel *>(model));
196
197 g_object_unref (model);
198
199 // now select first item in box
200 gtk_widget_grab_focus (m_listWindows);
201
202 GtkTreePath* path = gtk_tree_path_new ();
203 gtk_tree_path_append_index (path, m_ndxSelFrame);
204
205 gtk_tree_view_set_cursor(GTK_TREE_VIEW(m_listWindows),
206 path,
207 gtk_tree_view_get_column (GTK_TREE_VIEW(m_listWindows), 0),
208 FALSE);
209
210 gtk_tree_path_free (path);
211 }