| 1 |
/* AbiWord |
| 2 |
* Copyright (C) 2000 AbiSource, Inc. |
| 3 |
* Copyright (C) 2004 Hubert Figuiere |
| 4 |
* |
| 5 |
* This program is free software; you can redistribute it and/or |
| 6 |
* modify it under the terms of the GNU General Public License |
| 7 |
* as published by the Free Software Foundation; either version 2 |
| 8 |
* of the License, or (at your option) any later version. |
| 9 |
* |
| 10 |
* This program is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
* GNU General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU General Public License |
| 16 |
* along with this program; if not, write to the Free Software |
| 17 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
| 18 |
* 02110-1301 USA. |
| 19 |
*/ |
| 20 |
|
| 21 |
#include <stdlib.h> |
| 22 |
#include <time.h> |
| 23 |
|
| 24 |
#include "ut_string.h" |
| 25 |
#include "ut_assert.h" |
| 26 |
#include "ut_debugmsg.h" |
| 27 |
|
| 28 |
// This header defines some functions for Unix dialogs, |
| 29 |
// like centering them, measuring them, etc. |
| 30 |
#include "xap_UnixDialogHelper.h" |
| 31 |
|
| 32 |
#include "xap_App.h" |
| 33 |
#include "xap_UnixApp.h" |
| 34 |
#include "xap_Frame.h" |
| 35 |
|
| 36 |
#include "xap_Strings.h" |
| 37 |
#include "xap_Dialog_Id.h" |
| 38 |
#include "xap_Dlg_ListDocuments.h" |
| 39 |
#include "xap_UnixDlg_ListDocuments.h" |
| 40 |
|
| 41 |
#define CUSTOM_RESPONSE_VIEW 1 |
| 42 |
|
| 43 |
/*****************************************************************/ |
| 44 |
|
| 45 |
XAP_Dialog * XAP_UnixDialog_ListDocuments::static_constructor(XAP_DialogFactory * pFactory, |
| 46 |
XAP_Dialog_Id id) |
| 47 |
{ |
| 48 |
XAP_UnixDialog_ListDocuments * p = new XAP_UnixDialog_ListDocuments(pFactory,id); |
| 49 |
return p; |
| 50 |
} |
| 51 |
|
| 52 |
XAP_UnixDialog_ListDocuments::XAP_UnixDialog_ListDocuments(XAP_DialogFactory * pDlgFactory, |
| 53 |
XAP_Dialog_Id id) |
| 54 |
: XAP_Dialog_ListDocuments(pDlgFactory,id), |
| 55 |
m_listWindows(NULL), |
| 56 |
m_windowMain(NULL) |
| 57 |
{ |
| 58 |
} |
| 59 |
|
| 60 |
XAP_UnixDialog_ListDocuments::~XAP_UnixDialog_ListDocuments(void) |
| 61 |
{ |
| 62 |
} |
| 63 |
|
| 64 |
void XAP_UnixDialog_ListDocuments::s_list_dblclicked(GtkTreeView * /*treeview*/, |
| 65 |
GtkTreePath * /*arg1*/, |
| 66 |
GtkTreeViewColumn * /*arg2*/, |
| 67 |
XAP_UnixDialog_ListDocuments * me) |
| 68 |
{ |
| 69 |
gtk_dialog_response (GTK_DIALOG(me->m_windowMain), CUSTOM_RESPONSE_VIEW); |
| 70 |
} |
| 71 |
|
| 72 |
void XAP_UnixDialog_ListDocuments::runModal(XAP_Frame * pFrame) |
| 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_ListDocuments::event_View(void) |
| 93 |
{ |
| 94 |
GtkTreeSelection * selection; |
| 95 |
GtkTreeIter iter; |
| 96 |
GtkTreeModel * model; |
| 97 |
|
| 98 |
gint row = 0; |
| 99 |
|
| 100 |
selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_listWindows) ); |
| 101 |
|
| 102 |
// if there is no selection, or the selection's data (GtkListItem widget) |
| 103 |
// is empty, return cancel. GTK can make this happen. |
| 104 |
if ( !selection || |
| 105 |
!gtk_tree_selection_get_selected (selection, &model, &iter) |
| 106 |
) |
| 107 |
return; |
| 108 |
|
| 109 |
// get the ID of the selected Type |
| 110 |
gtk_tree_model_get (model, &iter, 1, &row, -1); |
| 111 |
|
| 112 |
if (row >= 0) { |
| 113 |
_setSelDocumentIndx(static_cast<UT_uint32>(row)); |
| 114 |
} |
| 115 |
} |
| 116 |
|
| 117 |
void XAP_UnixDialog_ListDocuments::event_Cancel(void) |
| 118 |
{ |
| 119 |
} |
| 120 |
|
| 121 |
/*****************************************************************/ |
| 122 |
|
| 123 |
GtkWidget * XAP_UnixDialog_ListDocuments::_constructWindow(void) |
| 124 |
{ |
| 125 |
GtkCellRenderer *renderer; |
| 126 |
GtkTreeViewColumn *column; |
| 127 |
GtkWidget *w; |
| 128 |
|
| 129 |
// load the dialog from the UI file |
| 130 |
#if GTK_CHECK_VERSION(3,0,0) |
| 131 |
GtkBuilder* builder = newDialogBuilder("xap_UnixDlg_ListDocuments.ui"); |
| 132 |
#else |
| 133 |
GtkBuilder* builder = newDialogBuilder("xap_UnixDlg_ListDocuments-2.ui"); |
| 134 |
#endif |
| 135 |
|
| 136 |
// Update our member variables with the important widgets that |
| 137 |
// might need to be queried or altered later |
| 138 |
m_windowMain = GTK_WIDGET(gtk_builder_get_object(builder, "xap_UnixDlg_ListDocuments")); |
| 139 |
m_listWindows = GTK_WIDGET(gtk_builder_get_object(builder, "tvAvailableDocuments")); |
| 140 |
|
| 141 |
gtk_window_set_title (GTK_WINDOW(m_windowMain), _getTitle()); |
| 142 |
w = GTK_WIDGET(gtk_builder_get_object(builder, "lbAvailableDocuments")); |
| 143 |
setLabelMarkup(w, _getHeading()); |
| 144 |
w = GTK_WIDGET(gtk_builder_get_object(builder, "btView")); |
| 145 |
gtk_button_set_label(GTK_BUTTON(w), _getOKButtonText()); |
| 146 |
|
| 147 |
// add a column to our TreeViews |
| 148 |
|
| 149 |
renderer = gtk_cell_renderer_text_new (); |
| 150 |
column = gtk_tree_view_column_new_with_attributes ("Format", |
| 151 |
renderer, |
| 152 |
"text", |
| 153 |
0, |
| 154 |
NULL); |
| 155 |
gtk_tree_view_append_column( GTK_TREE_VIEW(m_listWindows), column); |
| 156 |
|
| 157 |
// connect a dbl-clicked signal to the column |
| 158 |
|
| 159 |
g_signal_connect_after(G_OBJECT(m_listWindows), |
| 160 |
"row-activated", |
| 161 |
G_CALLBACK(s_list_dblclicked), |
| 162 |
static_cast<gpointer>(this)); |
| 163 |
|
| 164 |
g_object_unref(G_OBJECT(builder)); |
| 165 |
|
| 166 |
return m_windowMain; |
| 167 |
} |
| 168 |
|
| 169 |
void XAP_UnixDialog_ListDocuments::_populateWindowData(void) |
| 170 |
{ |
| 171 |
GtkListStore *model; |
| 172 |
GtkTreeIter iter; |
| 173 |
|
| 174 |
model = gtk_list_store_new (2, |
| 175 |
G_TYPE_STRING, |
| 176 |
G_TYPE_INT); |
| 177 |
|
| 178 |
for (UT_sint32 i = 0; i < _getDocumentCount(); i++) |
| 179 |
{ |
| 180 |
const char *s = _getNthDocumentName(i); |
| 181 |
UT_return_if_fail(s); |
| 182 |
// Add a new row to the model |
| 183 |
gtk_list_store_append (model, &iter); |
| 184 |
|
| 185 |
gtk_list_store_set (model, &iter, |
| 186 |
0, s, |
| 187 |
1, i, |
| 188 |
-1); |
| 189 |
} |
| 190 |
|
| 191 |
gtk_tree_view_set_model(GTK_TREE_VIEW(m_listWindows), reinterpret_cast<GtkTreeModel *>(model)); |
| 192 |
|
| 193 |
g_object_unref (model); |
| 194 |
|
| 195 |
// now select first item in box |
| 196 |
gtk_widget_grab_focus (m_listWindows); |
| 197 |
} |
| 198 |
|