~ubuntu-branches/ubuntu/jaunty/mlview/jaunty

« back to all changes in this revision

Viewing changes to src/mlview-styled-view.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2004-05-11 23:55:05 UTC
  • Revision ID: james.westby@ubuntu.com-20040511235505-ktq97vaz6sl5amy7
Tags: upstream-0.6.3
ImportĀ upstreamĀ versionĀ 0.6.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C; indent-tabs-mode:nil; c-basic-offset: 8-*- */
 
2
/*
 
3
 *This file is part of MlView.
 
4
 *
 
5
 *MlView is free software; you can redistribute 
 
6
 *it and/or modify it under the terms of 
 
7
 *the GNU General Public License as published by the 
 
8
 *Free Software Foundation; either version 2, 
 
9
 *or (at your option) any later version.
 
10
 *
 
11
 *GNU MlView is distributed in the hope that it will 
 
12
 *be useful, but WITHOUT ANY WARRANTY; 
 
13
 *without even the implied warranty of 
 
14
 *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
15
 *See the GNU General Public License for more details.
 
16
 *
 
17
 *You should have received a copy of the 
 
18
 *GNU General Public License along with MlView; 
 
19
 *see the file COPYING.
 
20
 *If not, write to the Free Software Foundation,
 
21
 *Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
22
 *
 
23
 *See COPYRIGHTS file for copyright information.
 
24
 */
 
25
 
 
26
#include <string.h>
 
27
#include <gnome.h>
 
28
#include <glade/glade.h>
 
29
#include "mlview-styled-view.h"
 
30
#include "mlview-tree-editor2.h"
 
31
 
 
32
/**
 
33
 *Implementation of the #MlViewStyledView class.
 
34
 */
 
35
#ifdef MLVIEW_WITH_STYLE
 
36
 
 
37
#define PRIVATE(obj) ((obj)->priv)
 
38
 
 
39
struct _MlViewStyledViewPriv {  
 
40
        GtkPaned *main_paned ;
 
41
        MlViewTreeEditor2 *tree_editor ;
 
42
        SXBoxView * styled_editor ;
 
43
        gboolean dispose_has_run ;
 
44
        gboolean connected_to_doc ;
 
45
        MlViewXMLDocument *xml_doc ;
 
46
        MlViewAppContext *app_context ;
 
47
        GtkDialog * css_picker_dialog ;
 
48
        GtkEntry *css_picker_author_css_path ;
 
49
        GtkEntry *css_picker_user_css_path ;
 
50
        GtkEntry *css_picker_ua_css_path ;
 
51
        GtkWidget *sewfox_contextual_menu ;
 
52
        GtkWidget *tree_editor_contextual_menu ;
 
53
} ;
 
54
 
 
55
enum {
 
56
        FIRST_SIGNAL,
 
57
        /*this must be the last member of this enum*/   
 
58
        NUMBER_OF_SIGNALS
 
59
} ;
 
60
 
 
61
static MlViewViewAdapterClass *gv_parent_class = NULL ;
 
62
static guint gv_signals[NUMBER_OF_SIGNALS] = {0} ;
 
63
 
 
64
static GtkWidget * get_sewfox_contextual_menu (MlViewStyledView *a_this) ;
 
65
 
 
66
static GtkWidget * get_tree_editor_contextual_menu (MlViewStyledView *a_this) ;
 
67
 
 
68
/*****************
 
69
 *private methods
 
70
 *****************/
 
71
 
 
72
 
 
73
static void
 
74
mlview_styled_view_dispose (GObject *a_this)
 
75
{
 
76
        MlViewStyledView *thiz = NULL ;
 
77
 
 
78
        g_return_if_fail (a_this 
 
79
                          && MLVIEW_IS_STYLED_VIEW (a_this)) ;
 
80
 
 
81
        thiz = MLVIEW_STYLED_VIEW (a_this) ;
 
82
        if (PRIVATE (thiz)->dispose_has_run)
 
83
                return ;
 
84
        
 
85
        if (PRIVATE (thiz) 
 
86
            && PRIVATE (thiz)->connected_to_doc == TRUE
 
87
            && PRIVATE (thiz)->xml_doc) {
 
88
                mlview_styled_view_disconnect_from_doc
 
89
                        (MLVIEW_IVIEW (thiz),
 
90
                         PRIVATE (thiz)->xml_doc) ;
 
91
        }
 
92
        if (PRIVATE (thiz)
 
93
            && PRIVATE (thiz)->xml_doc) {
 
94
                mlview_xml_document_unref (PRIVATE (thiz)->xml_doc) ;
 
95
                PRIVATE (thiz)->xml_doc = NULL ;                
 
96
        }
 
97
        PRIVATE (thiz)->dispose_has_run = TRUE ;
 
98
}
 
99
 
 
100
static void
 
101
mlview_styled_view_finalize (GObject *a_this)
 
102
{
 
103
        MlViewStyledView *thiz = NULL ;
 
104
 
 
105
        g_return_if_fail (a_this && MLVIEW_IS_STYLED_VIEW (a_this)) ;
 
106
 
 
107
        thiz = MLVIEW_STYLED_VIEW (a_this) ;
 
108
        if (PRIVATE (thiz)) {
 
109
                g_free (PRIVATE (thiz));
 
110
                PRIVATE (thiz) = NULL ;
 
111
        }
 
112
}
 
113
 
 
114
static void
 
115
mlview_styled_view_class_init (MlViewStyledViewClass *a_class)
 
116
{
 
117
        GObjectClass *gobject_class = NULL ;
 
118
 
 
119
        g_return_if_fail (a_class != NULL);
 
120
 
 
121
        gv_parent_class = g_type_class_peek_parent (a_class);
 
122
        g_return_if_fail (gv_parent_class) ;
 
123
        gobject_class = G_OBJECT_CLASS (a_class);
 
124
        g_return_if_fail (gobject_class) ;
 
125
 
 
126
        gobject_class->dispose = mlview_styled_view_dispose ;
 
127
        gobject_class->finalize = mlview_styled_view_finalize ;
 
128
}
 
129
 
 
130
static void
 
131
mlview_styled_view_init (MlViewStyledView *a_this)
 
132
{
 
133
        MlViewIView *view_iface = NULL ;
 
134
        g_return_if_fail (a_this 
 
135
                          && MLVIEW_IS_STYLED_VIEW (a_this)
 
136
                          && MLVIEW_IS_IVIEW (a_this)) ;
 
137
 
 
138
        if (PRIVATE (a_this) == NULL) {
 
139
                PRIVATE (a_this) = g_try_malloc 
 
140
                        (sizeof (MlViewStyledViewPriv)) ;
 
141
                if (!PRIVATE (a_this)) {
 
142
                        mlview_utils_trace_info ("g_try_malloc failed") ;
 
143
                        return ;
 
144
                }
 
145
                memset (PRIVATE (a_this), 0, 
 
146
                        sizeof (MlViewStyledViewPriv)) ;
 
147
        }
 
148
        view_iface = MLVIEW_IVIEW_GET_IFACE (a_this) ;
 
149
        g_return_if_fail (view_iface) ;
 
150
        view_iface->execute_action = mlview_styled_view_execute_action ;
 
151
        view_iface->connect_to_doc = mlview_styled_view_connect_to_doc ;
 
152
        view_iface->disconnect_from_doc = mlview_styled_view_disconnect_from_doc ;
 
153
}
 
154
 
 
155
static void
 
156
browse_author_css_button_clicked_cb (GtkWidget *a_button,
 
157
                                     gpointer a_user_data)
 
158
{
 
159
        MlViewFileSelection *file_sel = NULL ;
 
160
        MlViewStyledView *view = NULL;
 
161
        gchar *path = NULL ;
 
162
        gint button = 0 ;
 
163
 
 
164
        g_return_if_fail (a_user_data && MLVIEW_IS_STYLED_VIEW (a_user_data)) ;
 
165
 
 
166
        view = a_user_data ;
 
167
        g_return_if_fail (PRIVATE (view) && PRIVATE (view)->app_context) ;
 
168
 
 
169
        file_sel = mlview_app_context_get_file_selector
 
170
                (PRIVATE (view)->app_context, "_(Choose a CSS stylesheet)") ;
 
171
        g_return_if_fail (file_sel) ;
 
172
        button = mlview_file_selection_run (file_sel, TRUE) ;
 
173
 
 
174
        switch (button) {
 
175
        case OK_BUTTON:
 
176
                path = g_strdup (gtk_file_selection_get_filename
 
177
                                 (GTK_FILE_SELECTION (file_sel))) ;
 
178
                gtk_entry_set_text (PRIVATE (view)->css_picker_author_css_path,
 
179
                                    path) ;
 
180
                if (path) {
 
181
                        g_free (path) ;
 
182
                        path = NULL ;
 
183
                }
 
184
                break ;
 
185
        case CANCEL_BUTTON:
 
186
        case WINDOW_CLOSED:                
 
187
        default:
 
188
                break ;
 
189
        }
 
190
}
 
191
 
 
192
static void
 
193
browse_user_css_button_clicked_cb (GtkWidget *a_button,
 
194
                                   gpointer a_user_data)
 
195
{
 
196
        MlViewFileSelection *file_sel = NULL ;
 
197
        MlViewStyledView *view = NULL;
 
198
        gchar *path = NULL ;
 
199
        gint button = 0 ;
 
200
 
 
201
        g_return_if_fail (a_user_data && MLVIEW_IS_STYLED_VIEW (a_user_data)) ;
 
202
 
 
203
        view = a_user_data ;
 
204
        g_return_if_fail (PRIVATE (view) && PRIVATE (view)->app_context) ;
 
205
 
 
206
        file_sel = mlview_app_context_get_file_selector 
 
207
                (PRIVATE (view)->app_context, "_(Choose a CSS stylesheet)") ;
 
208
        g_return_if_fail (file_sel) ;
 
209
        button = mlview_file_selection_run (file_sel, TRUE) ;
 
210
 
 
211
        switch (button) {
 
212
        case OK_BUTTON:
 
213
                path = g_strdup (gtk_file_selection_get_filename
 
214
                                 (GTK_FILE_SELECTION (file_sel))) ;
 
215
                gtk_entry_set_text (PRIVATE (view)->css_picker_user_css_path,
 
216
                                    path) ;
 
217
                if (path) {
 
218
                        g_free (path) ;
 
219
                        path = NULL ;
 
220
                }
 
221
                break ;
 
222
        case CANCEL_BUTTON:
 
223
        case WINDOW_CLOSED:                
 
224
        default:
 
225
                break ;
 
226
        }
 
227
}
 
228
 
 
229
static void
 
230
browse_ua_css_button_clicked_cb (GtkWidget *a_button,
 
231
                                 gpointer a_user_data)
 
232
{
 
233
        MlViewFileSelection *file_sel = NULL ;
 
234
        MlViewStyledView *view = NULL;
 
235
        gchar *path = NULL ;
 
236
        gint button = 0 ;
 
237
 
 
238
        g_return_if_fail (a_user_data && MLVIEW_IS_STYLED_VIEW (a_user_data)) ;
 
239
 
 
240
        view = a_user_data ;
 
241
        g_return_if_fail (PRIVATE (view) && PRIVATE (view)->app_context) ;
 
242
 
 
243
        file_sel = mlview_app_context_get_file_selector 
 
244
                (PRIVATE (view)->app_context, "_(Choose a CSS stylesheet)") ;
 
245
        g_return_if_fail (file_sel) ;
 
246
        button = mlview_file_selection_run (file_sel, TRUE) ;
 
247
 
 
248
        switch (button) {
 
249
        case OK_BUTTON:
 
250
                path = g_strdup (gtk_file_selection_get_filename
 
251
                                 (GTK_FILE_SELECTION (file_sel))) ;
 
252
                gtk_entry_set_text (PRIVATE (view)->css_picker_ua_css_path,
 
253
                                    path) ;
 
254
                if (path) {
 
255
                        g_free (path) ;
 
256
                        path = NULL ;
 
257
                }
 
258
                break ;
 
259
        case CANCEL_BUTTON:
 
260
        case WINDOW_CLOSED:                
 
261
        default:
 
262
                break ;
 
263
        }
 
264
}
 
265
 
 
266
static gboolean
 
267
button_press_event_cb (GtkWidget *a_box_view, 
 
268
                       GdkEvent *a_event,
 
269
                       gpointer a_user_data)
 
270
{
 
271
        MlViewAppContext *ctxt = NULL ;
 
272
        MlViewStyledView *view = NULL ;
 
273
        enum MlViewStatus status = MLVIEW_OK ;
 
274
 
 
275
        g_return_val_if_fail (a_event && a_box_view && SX_IS_BOX_VIEW (a_box_view)
 
276
                              && a_user_data && a_event                          
 
277
                              && MLVIEW_IS_STYLED_VIEW (a_user_data),
 
278
                              FALSE) ;
 
279
 
 
280
        view = MLVIEW_STYLED_VIEW (a_user_data) ;
 
281
        ctxt = mlview_styled_view_get_app_context (view) ;
 
282
        
 
283
        switch (a_event->type) {
 
284
        case GDK_BUTTON_PRESS:
 
285
                if (a_event->button.button == 3) {
 
286
                        /*
 
287
                         *user pressed the right mouse button.
 
288
                         *Notify the application (at least the
 
289
                         *editing view that contains use) that
 
290
                         *a request for a contextual menu request
 
291
                         *has been made
 
292
                         */
 
293
                        status = mlview_app_context_notify_contextual_menu_request
 
294
                                (ctxt, a_box_view, a_event) ;
 
295
                        g_return_val_if_fail (status == MLVIEW_OK, FALSE) ;
 
296
                        return TRUE ;
 
297
                }
 
298
                break ;
 
299
        default:
 
300
                break ;
 
301
        }
 
302
        return FALSE ;
 
303
}
 
304
 
 
305
static void
 
306
contextual_menu_request_cb (MlViewAppContext *a_this,
 
307
                            GtkWidget *a_request_source,
 
308
                            GdkEvent *a_event,
 
309
                            gpointer a_user_data)
 
310
{
 
311
        MlViewStyledView *view = NULL ;
 
312
        GtkWidget * contextual_menu = NULL ;
 
313
        GdkEventButton *button_event = NULL ;
 
314
 
 
315
        g_return_if_fail (a_this && MLVIEW_IS_APP_CONTEXT (a_this)
 
316
                          && a_request_source 
 
317
                          && GTK_IS_WIDGET (a_request_source)
 
318
                          && a_event
 
319
                          && a_user_data
 
320
                          && MLVIEW_IS_STYLED_VIEW (a_user_data)) ;
 
321
 
 
322
        view = MLVIEW_STYLED_VIEW (a_user_data) ;
 
323
        g_return_if_fail (view && PRIVATE (view)) ;
 
324
        if (a_event->type == GDK_BUTTON_PRESS) {
 
325
                button_event = (GdkEventButton*) a_event;
 
326
                if (GTK_WIDGET (PRIVATE (view)->styled_editor) 
 
327
                    == a_request_source) {
 
328
                        contextual_menu = get_sewfox_contextual_menu (view) ;
 
329
                } else if (GTK_WIDGET (PRIVATE (view)->tree_editor)
 
330
                        == a_request_source) {
 
331
                        contextual_menu = get_tree_editor_contextual_menu 
 
332
                                (view) ;                        
 
333
                }
 
334
 
 
335
                if (contextual_menu && GTK_IS_MENU (contextual_menu)) {
 
336
                        gtk_menu_popup (GTK_MENU (contextual_menu),
 
337
                                        NULL, NULL, NULL,
 
338
                                        a_this, button_event->button,
 
339
                                        button_event->time) ;
 
340
                } else {
 
341
                        mlview_utils_trace_info ("Null menu returned") ;
 
342
                }
 
343
        }
 
344
}
 
345
 
 
346
static void
 
347
load_a_cascade_menuitem_clicked_cb (GtkMenuItem *a_item,
 
348
                                    gpointer a_user_data)
 
349
{
 
350
        MlViewStyledView *view = NULL ;
 
351
 
 
352
        g_return_if_fail (a_item && GTK_IS_MENU_ITEM (a_item)) ;
 
353
        g_return_if_fail (a_user_data && MLVIEW_IS_STYLED_VIEW (a_user_data)) ;
 
354
 
 
355
        view = MLVIEW_STYLED_VIEW (a_user_data) ;
 
356
        mlview_styled_view_update_from_css_paths_interactive (view) ;        
 
357
}
 
358
 
 
359
static void
 
360
dump_box_model_menuitem_clicked_cb (GtkMenuItem *a_item,
 
361
                                    gpointer a_user_data)
 
362
{
 
363
        enum CRStatus status = CR_OK ;
 
364
        SXBoxModel *box_model = NULL ;
 
365
        MlViewStyledView *view = NULL ;
 
366
 
 
367
        g_return_if_fail (a_item && GTK_IS_MENU_ITEM (a_item)) ;
 
368
        g_return_if_fail (a_user_data && MLVIEW_IS_STYLED_VIEW (a_user_data)) ;
 
369
 
 
370
        view = MLVIEW_STYLED_VIEW (a_user_data) ;
 
371
        status = sx_box_view_get_box_model (PRIVATE (view)->styled_editor,
 
372
                                            &box_model) ;
 
373
        if (status == CR_OK && box_model) {
 
374
                sx_box_dump_to_file ((SXBox*)box_model, 2, stdout) ;
 
375
        } else {
 
376
                mlview_utils_trace_info ("Could not get box model") ;
 
377
        }
 
378
        
 
379
}
 
380
 
 
381
 
 
382
static void
 
383
add_child_node_menuitem_activated_cb (GtkMenuItem *a_menu_item,
 
384
                                      gpointer a_user_data)
 
385
{
 
386
        MlViewAction action = {0} ;
 
387
        MlViewStyledView *tree_view = a_user_data ;
 
388
 
 
389
        g_return_if_fail (tree_view 
 
390
                          && MLVIEW_STYLED_VIEW (tree_view)) ;
 
391
 
 
392
        action.name = (guchar*)"add-child-node-interactive" ;
 
393
        mlview_styled_view_execute_action (MLVIEW_IVIEW(tree_view),
 
394
                                         &action) ;
 
395
 
 
396
}
 
397
 
 
398
 
 
399
static void
 
400
insert_previous_node_menuitem_activated_cb (GtkMenuItem *a_menu_item,
 
401
                                            gpointer a_user_data)
 
402
{
 
403
        MlViewAction action = {0} ;
 
404
        MlViewStyledView *tree_view = a_user_data ;
 
405
 
 
406
        g_return_if_fail (tree_view 
 
407
                          && MLVIEW_STYLED_VIEW (tree_view)) ;
 
408
 
 
409
        action.name = (guchar*)"insert-prev-sibling-node-interactive" ;
 
410
        mlview_styled_view_execute_action (MLVIEW_IVIEW(tree_view),
 
411
                                         &action) ;
 
412
}
 
413
 
 
414
static void
 
415
insert_next_node_menuitem_activated_cb (GtkMenuItem *a_menu_item,
 
416
                                        gpointer a_user_data)
 
417
{
 
418
        MlViewAction action = {0} ;
 
419
        MlViewStyledView *tree_view = a_user_data ;
 
420
 
 
421
        g_return_if_fail (tree_view 
 
422
                          && MLVIEW_STYLED_VIEW (tree_view)) ;
 
423
 
 
424
        action.name = (guchar*) "insert-next-sibling-node-interactive" ;
 
425
        mlview_styled_view_execute_action (MLVIEW_IVIEW(tree_view),
 
426
                                         &action) ;
 
427
}
 
428
 
 
429
static void
 
430
copy_node_menuitem_activated_cb (GtkMenuItem *a_menu_item,
 
431
                                 gpointer a_user_data)
 
432
{
 
433
        MlViewAction action = {0} ;
 
434
        MlViewStyledView *tree_view = a_user_data ;
 
435
 
 
436
        g_return_if_fail (tree_view 
 
437
                          && MLVIEW_STYLED_VIEW (tree_view)) ;
 
438
 
 
439
        action.name = (guchar*) "copy-node" ;
 
440
        mlview_styled_view_execute_action (MLVIEW_IVIEW(tree_view),
 
441
                                         &action) ;
 
442
}
 
443
 
 
444
 
 
445
static void
 
446
cut_node_menuitem_activated_cb (GtkMenuItem *a_menu_item,
 
447
                                gpointer a_user_data)
 
448
{
 
449
        MlViewAction action = {0} ;
 
450
        MlViewStyledView *tree_view = a_user_data ;
 
451
 
 
452
        g_return_if_fail (tree_view 
 
453
                          && MLVIEW_STYLED_VIEW (tree_view)) ;
 
454
 
 
455
        action.name = (guchar*) "cut-node" ;
 
456
        mlview_styled_view_execute_action (MLVIEW_IVIEW(tree_view),
 
457
                                         &action) ;
 
458
}
 
459
 
 
460
static void
 
461
paste_node_as_child_menuitem_activated_cb (GtkMenuItem *a_menu_item,
 
462
                                           gpointer a_user_data)
 
463
{
 
464
        MlViewAction action = {0} ;
 
465
        MlViewStyledView *tree_view = a_user_data ;
 
466
 
 
467
        g_return_if_fail (tree_view 
 
468
                          && MLVIEW_STYLED_VIEW (tree_view)) ;
 
469
 
 
470
        action.name = (guchar*) "paste-node-as-child" ;
 
471
        mlview_styled_view_execute_action (MLVIEW_IVIEW(tree_view),
 
472
                                         &action) ;
 
473
}
 
474
 
 
475
static void
 
476
paste_node_as_prev_menuitem_activated_cb (GtkMenuItem *a_menu_item,
 
477
                                          gpointer a_user_data)
 
478
{
 
479
        MlViewAction action = {0} ;
 
480
        MlViewStyledView *tree_view = a_user_data ;
 
481
 
 
482
        g_return_if_fail (tree_view 
 
483
                          && MLVIEW_STYLED_VIEW (tree_view)) ;
 
484
 
 
485
        action.name = (guchar*) "paste-node-as-prev-sibling" ;
 
486
        mlview_styled_view_execute_action (MLVIEW_IVIEW(tree_view),
 
487
                                         &action) ;
 
488
}
 
489
 
 
490
static void
 
491
paste_node_as_next_menuitem_activated_cb (GtkMenuItem *a_menu_item,
 
492
                                          gpointer a_user_data)
 
493
{
 
494
        MlViewAction action = {0} ;
 
495
        MlViewStyledView *tree_view = a_user_data ;
 
496
 
 
497
        g_return_if_fail (tree_view 
 
498
                          && MLVIEW_STYLED_VIEW (tree_view)) ;
 
499
 
 
500
        action.name = (guchar*) "paste-node-as-next-sibling" ;
 
501
        mlview_styled_view_execute_action (MLVIEW_IVIEW(tree_view),
 
502
                                         &action) ;        
 
503
}
 
504
 
 
505
static void
 
506
search_an_xml_node_menuitem_activated_cb (GtkMenuItem *a_menu_item,
 
507
                                          gpointer a_user_data)
 
508
{
 
509
        MlViewAction action = {0} ;
 
510
        MlViewStyledView *tree_view = a_user_data ;
 
511
 
 
512
        g_return_if_fail (tree_view 
 
513
                          && MLVIEW_STYLED_VIEW (tree_view)) ;
 
514
 
 
515
        action.name = (guchar*) "find-node-that-contains-str-interactive" ;
 
516
        mlview_styled_view_execute_action (MLVIEW_IVIEW(tree_view),
 
517
                                         &action) ;
 
518
}
 
519
 
 
520
static void
 
521
expand_current_node_menuitem_activated_cb (GtkMenuItem *a_item,
 
522
                                           gpointer a_user_data)
 
523
{
 
524
        MlViewAction action = {0} ;
 
525
        MlViewStyledView *tree_view = a_user_data ;
 
526
 
 
527
        g_return_if_fail (tree_view 
 
528
                          && MLVIEW_STYLED_VIEW (tree_view)) ;
 
529
 
 
530
        action.name = (guchar*) "expand-tree-to-depth-interactive" ;
 
531
        mlview_styled_view_execute_action (MLVIEW_IVIEW (tree_view),
 
532
                                         &action) ;
 
533
}
 
534
 
 
535
static GtkWidget *
 
536
get_css_paths_picker_dialog (MlViewStyledView *a_this)
 
537
{
 
538
        guchar *path = NULL ;
 
539
        GladeXML *glade_xml = NULL ;
 
540
 
 
541
        g_return_val_if_fail (a_this && MLVIEW_IS_STYLED_VIEW (a_this)
 
542
                              && PRIVATE (a_this),
 
543
                              NULL) ;
 
544
 
 
545
        if (!PRIVATE (a_this)->css_picker_dialog)
 
546
        {
 
547
                path = gnome_program_locate_file (NULL, GNOME_FILE_DOMAIN_APP_DATADIR,
 
548
                                                  "mlview/mlview-css-picker.glade",
 
549
                                                  TRUE, NULL) ;
 
550
                if (!path) {
 
551
                        mlview_utils_trace_info
 
552
                                ("could not find mlview-css-picker.glade file") ;
 
553
                        return NULL ;
 
554
                }
 
555
                glade_xml = glade_xml_new (path, "CSSPicker", NULL) ;
 
556
                if (!glade_xml) {
 
557
                        mlview_utils_trace_info ("could not find mlview-css-picker.glade file") ;
 
558
                        goto cleanup ;
 
559
                }
 
560
                PRIVATE (a_this)->css_picker_dialog = GTK_DIALOG 
 
561
                        (glade_xml_get_widget (glade_xml, "CSSPicker")) ;
 
562
                if (!PRIVATE (a_this)->css_picker_dialog 
 
563
                    || !GTK_IS_DIALOG (PRIVATE (a_this)->css_picker_dialog)) {
 
564
                        mlview_utils_trace_info ("glade_xml_get_widget() made an unexpected result") ;
 
565
                }
 
566
                PRIVATE (a_this)->css_picker_author_css_path =
 
567
                        GTK_ENTRY (glade_xml_get_widget (glade_xml, 
 
568
                                              "AuthorCSSPathEntry")) ;
 
569
                g_return_val_if_fail (PRIVATE (a_this)->css_picker_author_css_path,
 
570
                                      NULL) ;
 
571
                PRIVATE (a_this)->css_picker_user_css_path =
 
572
                        GTK_ENTRY (glade_xml_get_widget (glade_xml,
 
573
                                                         "UserCSSPathEntry")) ;
 
574
                g_return_val_if_fail (PRIVATE (a_this)->css_picker_author_css_path, 
 
575
                                      NULL) ;
 
576
                PRIVATE (a_this)->css_picker_ua_css_path =
 
577
                        GTK_ENTRY (glade_xml_get_widget (glade_xml,
 
578
                                                         "UACSSPathEntry")) ;
 
579
                g_return_val_if_fail (PRIVATE (a_this)->css_picker_author_css_path, 
 
580
                                      NULL) ;
 
581
                glade_xml_signal_connect_data (glade_xml, "browse_author_css_button_clicked",
 
582
                                               G_CALLBACK (browse_author_css_button_clicked_cb),
 
583
                                               a_this) ;
 
584
                glade_xml_signal_connect_data (glade_xml, "browse_user_css_button_clicked",
 
585
                                               G_CALLBACK (browse_user_css_button_clicked_cb),
 
586
                                               a_this) ;
 
587
                glade_xml_signal_connect_data (glade_xml, "browse_ua_css_button_clicked",
 
588
                                               G_CALLBACK (browse_ua_css_button_clicked_cb),
 
589
                                               a_this) ;                
 
590
                g_object_unref (glade_xml) ;
 
591
                glade_xml = NULL; 
 
592
        }
 
593
        return GTK_WIDGET (PRIVATE (a_this)->css_picker_dialog) ;
 
594
 
 
595
 cleanup:
 
596
        if (path) {
 
597
                g_free (path) ;
 
598
                path = NULL ;
 
599
        }
 
600
        if (glade_xml) {
 
601
                g_object_unref (glade_xml) ;
 
602
                glade_xml = NULL ;
 
603
        }
 
604
        return NULL ;
 
605
}
 
606
 
 
607
static GtkWidget *
 
608
get_tree_editor_contextual_menu (MlViewStyledView *a_this)
 
609
{
 
610
        GtkWidget *menuitem = NULL, *menu = NULL ;
 
611
 
 
612
        g_return_val_if_fail (a_this
 
613
                              && MLVIEW_IS_STYLED_VIEW (a_this),
 
614
                              NULL) ;
 
615
 
 
616
        if (!PRIVATE (a_this)->tree_editor_contextual_menu) {
 
617
                menu = gtk_menu_new () ;
 
618
                menuitem = gtk_menu_item_new_with_label
 
619
                        (_("Add child node")) ;
 
620
                gtk_menu_shell_append (GTK_MENU_SHELL (menu),
 
621
                                       menuitem) ;
 
622
                gtk_widget_show (menuitem) ;
 
623
                g_signal_connect (G_OBJECT (menuitem),
 
624
                                  "activate",
 
625
                                  G_CALLBACK 
 
626
                                  (add_child_node_menuitem_activated_cb),
 
627
                                  a_this) ;
 
628
                menuitem = gtk_menu_item_new_with_label 
 
629
                        (_("Insert next node")) ;
 
630
                gtk_menu_shell_append (GTK_MENU_SHELL (menu),
 
631
                                       menuitem) ;
 
632
                gtk_widget_show (menuitem) ;
 
633
                g_signal_connect (G_OBJECT (menuitem),
 
634
                                  "activate",
 
635
                                  G_CALLBACK 
 
636
                                  (insert_next_node_menuitem_activated_cb),
 
637
                                  a_this) ;
 
638
 
 
639
                menuitem = gtk_menu_item_new_with_label 
 
640
                        (_("Insert previous node")) ;
 
641
                gtk_menu_shell_append (GTK_MENU_SHELL (menu),
 
642
                                       menuitem) ;
 
643
                gtk_widget_show (menuitem) ;
 
644
                g_signal_connect (G_OBJECT (menuitem),
 
645
                                  "activate",
 
646
                                  G_CALLBACK 
 
647
                                  (insert_previous_node_menuitem_activated_cb),
 
648
                                  a_this) ;
 
649
 
 
650
                menuitem = gtk_separator_menu_item_new () ;
 
651
                gtk_menu_shell_append (GTK_MENU_SHELL (menu),
 
652
                                       menuitem) ;
 
653
                gtk_widget_show (GTK_WIDGET (menuitem)) ;
 
654
 
 
655
                menuitem = gtk_menu_item_new_with_label 
 
656
                        (_("Copy node")) ;
 
657
                gtk_menu_shell_append (GTK_MENU_SHELL (menu),
 
658
                                       menuitem) ;
 
659
                gtk_widget_show (GTK_WIDGET (menuitem)) ;
 
660
                g_signal_connect (G_OBJECT (menuitem),
 
661
                                  "activate",
 
662
                                  G_CALLBACK 
 
663
                                  (copy_node_menuitem_activated_cb),
 
664
                                  a_this) ;
 
665
 
 
666
                menuitem = gtk_menu_item_new_with_label 
 
667
                        (_("Cut node")) ;
 
668
                gtk_menu_shell_append (GTK_MENU_SHELL (menu),
 
669
                                       menuitem) ;
 
670
                gtk_widget_show (menuitem) ;
 
671
                g_signal_connect (G_OBJECT (menuitem),
 
672
                                  "activate",
 
673
                                  G_CALLBACK (cut_node_menuitem_activated_cb),
 
674
                                  a_this) ;
 
675
 
 
676
                menuitem = gtk_separator_menu_item_new () ;
 
677
                gtk_menu_shell_append (GTK_MENU_SHELL (menu),
 
678
                                       menuitem) ;
 
679
                gtk_widget_show (menuitem) ;
 
680
 
 
681
                menuitem = gtk_menu_item_new_with_label
 
682
                        (_("Paste node as child")) ;
 
683
                gtk_menu_shell_append (GTK_MENU_SHELL (menu),
 
684
                                       menuitem) ;
 
685
                g_signal_connect (G_OBJECT (menuitem),
 
686
                                  "activate",
 
687
                                  G_CALLBACK 
 
688
                                  (paste_node_as_child_menuitem_activated_cb),
 
689
                                  a_this) ;
 
690
                gtk_widget_show (menuitem) ;
 
691
 
 
692
                menuitem = gtk_menu_item_new_with_label
 
693
                        (_("Paste node as prev")) ;
 
694
                gtk_menu_shell_append (GTK_MENU_SHELL (menu),
 
695
                                       menuitem) ;
 
696
                g_signal_connect (G_OBJECT (menuitem),
 
697
                                  "activate",
 
698
                                  G_CALLBACK 
 
699
                                  (paste_node_as_prev_menuitem_activated_cb),
 
700
                                  a_this) ;
 
701
                gtk_widget_show (menuitem) ;
 
702
 
 
703
                menuitem = gtk_menu_item_new_with_label 
 
704
                        (_("Paste node as next")) ;
 
705
                gtk_menu_shell_append (GTK_MENU_SHELL (menu),
 
706
                                       menuitem) ;
 
707
                g_signal_connect (G_OBJECT (menuitem),
 
708
                                  "activate",
 
709
                                  G_CALLBACK 
 
710
                                  (paste_node_as_next_menuitem_activated_cb),
 
711
                                  a_this) ;
 
712
                gtk_widget_show (menuitem) ;
 
713
 
 
714
                menuitem = gtk_separator_menu_item_new () ;
 
715
                gtk_menu_shell_append (GTK_MENU_SHELL (menu),
 
716
                                       menuitem) ;
 
717
                gtk_widget_show (menuitem) ;
 
718
 
 
719
                menuitem = gtk_menu_item_new_with_label 
 
720
                        (_("Expand current node")) ;
 
721
                gtk_menu_shell_append (GTK_MENU_SHELL (menu),
 
722
                                       menuitem) ;
 
723
                g_signal_connect (G_OBJECT (menuitem),
 
724
                                  "activate",
 
725
                                  G_CALLBACK 
 
726
                                  (expand_current_node_menuitem_activated_cb),
 
727
                                  a_this) ;
 
728
                gtk_widget_show (menuitem) ;
 
729
 
 
730
                menuitem = gtk_menu_item_new_with_label 
 
731
                        (_("Find an xml node")) ;
 
732
                gtk_menu_shell_append (GTK_MENU_SHELL (menu),
 
733
                                       menuitem) ;
 
734
                g_signal_connect (G_OBJECT (menuitem),
 
735
                                  "activate",
 
736
                                  G_CALLBACK 
 
737
                                  (search_an_xml_node_menuitem_activated_cb),
 
738
                                  a_this) ;
 
739
                gtk_widget_show (menuitem) ;
 
740
                PRIVATE (a_this)->tree_editor_contextual_menu = menu ;
 
741
        }
 
742
        return  PRIVATE (a_this)->tree_editor_contextual_menu ;
 
743
}
 
744
 
 
745
/**
 
746
 *Builds the contextual menu that should be popup'ed
 
747
 *when the user right clicks on the sewfox widget embedded
 
748
 *in the styled editing view
 
749
 *@param a_this the current instance of #MlViewStyledView
 
750
 *@return the contextual menu or NULL if a problem arises
 
751
 */
 
752
static GtkWidget *
 
753
get_sewfox_contextual_menu (MlViewStyledView *a_this)
 
754
{
 
755
        GtkWidget *menuitem = NULL ;
 
756
 
 
757
        g_return_val_if_fail (a_this
 
758
                              && MLVIEW_IS_STYLED_VIEW (a_this),
 
759
                              NULL) ;
 
760
 
 
761
        if (!PRIVATE (a_this)->sewfox_contextual_menu) {
 
762
                PRIVATE (a_this)->sewfox_contextual_menu = gtk_menu_new () ;
 
763
                menuitem = gtk_menu_item_new_with_label (_("Load a Cascade")) ;
 
764
                gtk_widget_show (menuitem) ;
 
765
                gtk_menu_shell_append (GTK_MENU_SHELL (PRIVATE (a_this)->sewfox_contextual_menu),
 
766
                                       menuitem) ;
 
767
                g_signal_connect (G_OBJECT (menuitem),
 
768
                                  "activate",
 
769
                                  G_CALLBACK (load_a_cascade_menuitem_clicked_cb),
 
770
                                  a_this) ;
 
771
#ifdef MLVIEW_VERBOSE
 
772
                menuitem = gtk_menu_item_new () ;
 
773
                gtk_widget_show (menuitem) ;
 
774
                gtk_menu_shell_append (GTK_MENU_SHELL (PRIVATE (a_this)->sewfox_contextual_menu),
 
775
                                       menuitem) ;
 
776
                menuitem = gtk_menu_item_new_with_label (_("Dump box model")) ;                
 
777
                gtk_menu_shell_append (GTK_MENU_SHELL (PRIVATE (a_this)->sewfox_contextual_menu),
 
778
                                       menuitem) ;
 
779
                gtk_widget_show (menuitem) ;
 
780
                g_signal_connect (G_OBJECT (menuitem),
 
781
                                  "activate",
 
782
                                  G_CALLBACK (dump_box_model_menuitem_clicked_cb),
 
783
                                  a_this) ;
 
784
#endif
 
785
        }
 
786
        return PRIVATE (a_this)->sewfox_contextual_menu ;
 
787
}
 
788
 
 
789
/****************
 
790
 *public methods
 
791
 ****************/
 
792
 
 
793
/*
 
794
 *TODO: 
 
795
 *1/code the methods to edit the document using the left hand
 
796
 *widget, wire them in mlview_styled_view_execute_action().
 
797
 *2/go code some facilities to dump the style structures for easier debuging.
 
798
 */
 
799
 
 
800
/**
 
801
 *Standard gobject based type getter of the
 
802
 *#MlViewStyledView class.
 
803
 *@return the type identifier of the #MlViewStyledView class.
 
804
 */
 
805
GType 
 
806
mlview_styled_view_get_type (void)
 
807
{
 
808
        static guint type = 0;
 
809
 
 
810
        if (!type) {
 
811
                static const GTypeInfo type_info = {
 
812
                        sizeof (MlViewStyledViewClass),
 
813
                        NULL, /*base_init*/
 
814
                        NULL, /*base_finalize*/
 
815
                        (GClassInitFunc)
 
816
                        mlview_styled_view_class_init,
 
817
                        NULL, /*class_finalize*/
 
818
                        NULL, /*class data*/
 
819
                        sizeof (MlViewStyledView),
 
820
                        0, /*n_prealloc*/
 
821
                        (GInstanceInitFunc)
 
822
                        mlview_styled_view_init
 
823
                } ;
 
824
                type = g_type_register_static
 
825
                        (MLVIEW_TYPE_VIEW_ADAPTER,
 
826
                         "MlViewStyledView", &type_info, 0);
 
827
        }
 
828
        return type;
 
829
}
 
830
 
 
831
/**
 
832
 *Constructor of the #MlViewStyledView class
 
833
 *@param a_doc the xml document to "edit"
 
834
 *@param a_name an arbitrary name for the document (or view)
 
835
 *@param a_app_context the application context. (should not be NULL)
 
836
 *@return the newly created instance of #MlViewStyledView or NULL in case
 
837
 *of error.
 
838
 */
 
839
GtkWidget*
 
840
mlview_styled_view_new (MlViewXMLDocument *a_doc,
 
841
                        gchar *a_name,
 
842
                        MlViewAppContext *a_app_context)
 
843
{
 
844
        MlViewStyledView *view = NULL ;
 
845
 
 
846
        g_return_val_if_fail (a_doc 
 
847
                              && MLVIEW_IS_XML_DOCUMENT (a_doc)
 
848
                              && PRIVATE (a_doc),
 
849
                              NULL) ;
 
850
        view = g_object_new (MLVIEW_TYPE_STYLED_VIEW, NULL) ;
 
851
        mlview_styled_view_construct (view, a_doc, a_name, a_app_context) ;
 
852
        mlview_iview_connect_to_doc (MLVIEW_IVIEW (view),
 
853
                                     a_doc) ;
 
854
        return GTK_WIDGET (view) ;
 
855
}
 
856
 
 
857
/**
 
858
 *Instance initializer of #MlViewStyleView; This should be called by
 
859
 *the constructor of #MlViewStyledView
 
860
 *@param a_doc the xml document we want to edit
 
861
 *@param a_view_name an arbitrary name of the view
 
862
 *@param a_app_context the application context to be associated to
 
863
 *the editing view
 
864
 *@return MLVIEW_OK upon successful completion, an erroro code otherwise.
 
865
 */
 
866
enum MlViewStatus
 
867
mlview_styled_view_construct (MlViewStyledView *a_this,
 
868
                              MlViewXMLDocument *a_doc,
 
869
                              guchar *a_view_name,
 
870
                              MlViewAppContext *a_app_context)
 
871
{
 
872
        enum CRStatus cr_status = CR_OK ;
 
873
        enum MlViewStatus status = MLVIEW_OK ;
 
874
        CRStyleSheet *sheet = NULL ;
 
875
        CRCascade * cascade = NULL ;
 
876
        xmlDoc *xml_doc = NULL ;
 
877
 
 
878
        if (PRIVATE (a_this)->main_paned 
 
879
            || PRIVATE (a_this)->tree_editor
 
880
            || PRIVATE (a_this)->styled_editor) {
 
881
                return MLVIEW_OK ;
 
882
        }
 
883
        status = mlview_view_adapter_construct
 
884
                (MLVIEW_VIEW_ADAPTER (a_this),
 
885
                 a_doc);
 
886
        g_return_val_if_fail (status == MLVIEW_VIEW_ADAPTER_OK,
 
887
                              status) ;
 
888
 
 
889
        cr_status = sx_box_view_get_default_stylesheet (&sheet) ;
 
890
        if (cr_status != CR_OK || ! sheet)
 
891
                return MLVIEW_ERROR ;
 
892
        cascade = cr_cascade_new (NULL, NULL, sheet) ;
 
893
        if (!cascade) {
 
894
                mlview_utils_trace_info ("cr_cascade_new() failed") ;
 
895
                status = MLVIEW_ERROR ;
 
896
                goto cleanup ;
 
897
        }
 
898
        xml_doc = mlview_xml_document_get_xml_document (a_doc) ;
 
899
        if (!xml_doc) {
 
900
                mlview_utils_trace_info 
 
901
                        ("mlview_xml_document_get_xml_document () failed") ;
 
902
                status = MLVIEW_OK ;
 
903
                goto cleanup ;
 
904
        }
 
905
        PRIVATE (a_this)->styled_editor = sx_box_view_new (cascade, xml_doc) ;
 
906
        if (!PRIVATE (a_this)->styled_editor) {
 
907
                mlview_utils_trace_info ("sx_box_new() failed") ;
 
908
                status = MLVIEW_OK ;
 
909
                goto cleanup ;
 
910
        }
 
911
        PRIVATE (a_this)->tree_editor = MLVIEW_TREE_EDITOR2
 
912
                (mlview_tree_editor2_new (a_app_context)) ;
 
913
        mlview_tree_editor2_edit_xml_doc (PRIVATE (a_this)->tree_editor,
 
914
                                          a_doc, (guchar*)"Experimental") ;
 
915
        PRIVATE (a_this)->main_paned = GTK_PANED (gtk_hpaned_new ()) ;
 
916
        gtk_box_pack_start (GTK_BOX (a_this), 
 
917
                            GTK_WIDGET (PRIVATE (a_this)->main_paned),
 
918
                            TRUE, TRUE, 0) ;
 
919
        gtk_paned_add1 (GTK_PANED (PRIVATE (a_this)->main_paned),
 
920
                         GTK_WIDGET (PRIVATE (a_this)->tree_editor)) ;
 
921
        gtk_paned_add2 (GTK_PANED (PRIVATE (a_this)->main_paned),
 
922
                        GTK_WIDGET (PRIVATE (a_this)->styled_editor)) ;
 
923
        PRIVATE (a_this)->xml_doc = a_doc ;
 
924
        mlview_xml_document_ref (a_doc) ;
 
925
        gtk_widget_show_all (GTK_WIDGET (PRIVATE (a_this)->main_paned)) ;
 
926
        PRIVATE (a_this)->app_context = a_app_context ;
 
927
 
 
928
        g_signal_connect (G_OBJECT (PRIVATE (a_this)->styled_editor),
 
929
                          "button-press-event",
 
930
                          G_CALLBACK (button_press_event_cb),
 
931
                          a_this) ;
 
932
        g_signal_connect (G_OBJECT (a_app_context),
 
933
                          "contextual-menu-requested",
 
934
                          G_CALLBACK (contextual_menu_request_cb),
 
935
                          a_this) ;
 
936
 
 
937
        sheet = NULL ;
 
938
        cascade = NULL ;
 
939
        xml_doc = NULL ;
 
940
 
 
941
 cleanup:
 
942
        if (sheet) {
 
943
                cr_stylesheet_unref (sheet) ;
 
944
                sheet = NULL ;
 
945
        }
 
946
        if (cascade) {
 
947
                cr_cascade_unref (cascade) ;
 
948
                cascade = NULL ;
 
949
        }
 
950
        if (xml_doc) {
 
951
                xmlFreeDoc (xml_doc) ;
 
952
                xml_doc = NULL ;
 
953
        }
 
954
        return status ;
 
955
}
 
956
 
 
957
/**
 
958
 *Creates an internal subset node 
 
959
 *(<DOCTYPE elname PUBLIC "blah" "blabla">)
 
960
 *@param a_this the current instance of #MlViewStyledView
 
961
 *@return MLVIEW_OK upon successful completion,
 
962
 *an error code otherwise.
 
963
 */
 
964
enum MlViewStatus
 
965
mlview_styled_view_create_internal_subset_node_interactive (MlViewStyledView *a_this)
 
966
{
 
967
        xmlDoc *native_doc = NULL ;
 
968
        gchar *name = NULL ;
 
969
 
 
970
        g_return_val_if_fail (a_this && MLVIEW_IS_STYLED_VIEW (a_this)
 
971
                              && PRIVATE (a_this)
 
972
                              && PRIVATE (a_this)->app_context,
 
973
                              MLVIEW_BAD_PARAM_ERROR) ;
 
974
 
 
975
        if (!PRIVATE (a_this)->xml_doc)
 
976
                return MLVIEW_NO_DOC_IN_VIEW_ERROR ;
 
977
        native_doc = mlview_xml_document_get_xml_document 
 
978
                (PRIVATE (a_this)->xml_doc) ;
 
979
        g_return_val_if_fail (native_doc, MLVIEW_ERROR) ;
 
980
        if (native_doc->intSubset) {
 
981
                mlview_app_context_error 
 
982
                        (PRIVATE (a_this)->app_context, 
 
983
                         _("The document already has an internal subset defined !")) ;
 
984
                return MLVIEW_INT_SUBSET_ALREADY_PRESENT_ERROR ;
 
985
        }
 
986
        mlview_app_context_ask_internal_subset_node_name (&name) ;
 
987
        if (name) {
 
988
                return mlview_xml_document_create_internal_subset 
 
989
                        (PRIVATE (a_this)->xml_doc, name, 
 
990
                         (xmlChar*)"default-public-id", 
 
991
                         (xmlChar*)"default-system-id",
 
992
                         TRUE) ;
 
993
        }
 
994
        return MLVIEW_OK ;
 
995
}
 
996
 
 
997
/**
 
998
 *Interactively add a child node to the currently selected xml node.
 
999
 *@param a_this the current instance of #MlViewStyledView
 
1000
 *@return MLVIEW_OK upon succesful completion, an error code otherwise.
 
1001
 */
 
1002
enum MlViewStatus
 
1003
mlview_styled_view_add_child_node_interactive (MlViewStyledView *a_this)
 
1004
{
 
1005
        MlViewTreeEditor2 *tree_editor = NULL ;
 
1006
        
 
1007
        g_return_val_if_fail (a_this && MLVIEW_IS_STYLED_VIEW (a_this)
 
1008
                              && PRIVATE (a_this)
 
1009
                              && PRIVATE (a_this)->app_context,
 
1010
                              MLVIEW_BAD_PARAM_ERROR) ;
 
1011
 
 
1012
        tree_editor = mlview_styled_view_get_tree_editor (a_this) ;
 
1013
        g_return_val_if_fail (tree_editor, MLVIEW_ERROR) ;
 
1014
        mlview_tree_editor2_add_child_node_interactive (tree_editor) ;
 
1015
        return MLVIEW_OK ;
 
1016
}
 
1017
 
 
1018
/**
 
1019
 *Interactively adds a previous sibling node to the currently selected
 
1020
 *xml node.
 
1021
 *@param a_this the current instance of #MlViewStyledView
 
1022
 *@return MLVIEW_OK upon successful completion, an error code otherwise
 
1023
 */
 
1024
enum MlViewStatus
 
1025
mlview_styled_view_insert_prev_sibling_node_interactive (MlViewStyledView *a_this)
 
1026
{
 
1027
        MlViewTreeEditor2 *tree_editor = NULL ;
 
1028
 
 
1029
        g_return_val_if_fail (a_this && MLVIEW_IS_STYLED_VIEW (a_this),
 
1030
                              MLVIEW_BAD_PARAM_ERROR) ;
 
1031
 
 
1032
        tree_editor = mlview_styled_view_get_tree_editor (a_this) ;
 
1033
        g_return_val_if_fail (tree_editor, MLVIEW_ERROR) ;
 
1034
        mlview_tree_editor2_insert_prev_sibling_node_interactive (tree_editor) ;
 
1035
        return MLVIEW_OK ;
 
1036
}
 
1037
 
 
1038
/**
 
1039
 *Interactively insert a next sibling node to the currently selected
 
1040
 *xml node.
 
1041
 *@param a_this the current instance of #MlViewStyledView
 
1042
 *@return MLVIEW_OK upon succesful completion, an error code otherwise.
 
1043
 */
 
1044
enum MlViewStatus
 
1045
mlview_styled_view_insert_next_sibling_node_interactive (MlViewStyledView * a_this) 
 
1046
{
 
1047
        MlViewTreeEditor2 *tree_editor = NULL;
 
1048
 
 
1049
        g_return_val_if_fail (a_this && MLVIEW_IS_STYLED_VIEW (a_this),
 
1050
                              MLVIEW_BAD_PARAM_ERROR) ;
 
1051
        tree_editor =
 
1052
                mlview_styled_view_get_tree_editor
 
1053
                (a_this);
 
1054
 
 
1055
        if (tree_editor) {
 
1056
                mlview_tree_editor2_insert_next_sibling_node_interactive
 
1057
                        (tree_editor);
 
1058
        }
 
1059
        return MLVIEW_OK ;
 
1060
}
 
1061
 
 
1062
/**
 
1063
 *Cuts the currently selected xml node.
 
1064
 *That is, unlink it from the tree and put it in
 
1065
 *the xml node clipboard.
 
1066
 *@param a_this the current instance of #MlViewStyledView
 
1067
 */
 
1068
enum MlViewStatus
 
1069
mlview_styled_view_cut_node (MlViewStyledView *a_this)
 
1070
{
 
1071
        MlViewTreeEditor2 *tree_editor = NULL;
 
1072
        GtkTreeIter cur_sel_start = {0};
 
1073
        enum MlViewStatus status = MLVIEW_OK ;
 
1074
 
 
1075
        tree_editor =
 
1076
                mlview_styled_view_get_tree_editor (a_this);
 
1077
 
 
1078
        if (tree_editor == NULL)
 
1079
                return MLVIEW_OK;
 
1080
        status = mlview_tree_editor2_get_cur_sel_start_iter 
 
1081
                (tree_editor, &cur_sel_start);
 
1082
        g_return_val_if_fail (status == MLVIEW_OK, status) ;
 
1083
        mlview_tree_editor2_cut_node (tree_editor,
 
1084
                                      &cur_sel_start);
 
1085
        return MLVIEW_OK ;
 
1086
}
 
1087
 
 
1088
 
 
1089
/**
 
1090
 *Copy the currently selected xml node into the local clipboard.
 
1091
 *@param a_this the current instance of #MlViewStyledView
 
1092
 *@return MLVIEW_OK upon succesful completion, an error code otherwise.
 
1093
 */
 
1094
enum MlViewStatus
 
1095
mlview_styled_view_copy_node (MlViewStyledView *a_this)
 
1096
{
 
1097
        MlViewTreeEditor2 *tree_editor = NULL;
 
1098
        GtkTreeIter cur_sel_start = {0} ;
 
1099
        enum MlViewStatus status = MLVIEW_OK ;
 
1100
 
 
1101
        g_return_val_if_fail (a_this && MLVIEW_IS_STYLED_VIEW (a_this), 
 
1102
                              MLVIEW_BAD_PARAM_ERROR);
 
1103
 
 
1104
        tree_editor =
 
1105
                mlview_styled_view_get_tree_editor
 
1106
                (a_this);
 
1107
        if (tree_editor == NULL)
 
1108
                return MLVIEW_OK;
 
1109
        status = mlview_tree_editor2_get_cur_sel_start_iter
 
1110
                (tree_editor, &cur_sel_start) ;
 
1111
        g_return_val_if_fail (status == MLVIEW_OK, status) ;
 
1112
        mlview_tree_editor2_copy_node (tree_editor,
 
1113
                                       &cur_sel_start) ;
 
1114
        return MLVIEW_OK ;
 
1115
}
 
1116
 
 
1117
 
 
1118
/**
 
1119
 *Paste the last node found in the clipboard into the xml document
 
1120
 *model.
 
1121
 *The pasted node is pasted as a child node of the currently selected
 
1122
 *xml node.
 
1123
 *@param a_this the current instance of #MlViewStyledView
 
1124
 *@return MLVIEW_OK upon succesful completion, an error code otherwise
 
1125
 */
 
1126
enum MlViewStatus
 
1127
mlview_styled_view_paste_node_as_child (MlViewStyledView * a_this) 
 
1128
{
 
1129
        GtkTreeIter cur_sel_start={0} ;
 
1130
        enum MlViewStatus status = MLVIEW_OK;
 
1131
 
 
1132
        g_return_val_if_fail (a_this
 
1133
                              && MLVIEW_IS_STYLED_VIEW (a_this)
 
1134
                              && PRIVATE (a_this)
 
1135
                              && PRIVATE (a_this)->tree_editor,
 
1136
                              MLVIEW_BAD_PARAM_ERROR);
 
1137
 
 
1138
        status = mlview_tree_editor2_get_cur_sel_start_iter 
 
1139
                (PRIVATE (a_this)->tree_editor,
 
1140
                 &cur_sel_start) ;
 
1141
        g_return_val_if_fail (status == MLVIEW_OK,
 
1142
                              status) ;
 
1143
        mlview_tree_editor2_paste_node_as_child
 
1144
                (PRIVATE (a_this)->tree_editor,
 
1145
                 &cur_sel_start);
 
1146
        return MLVIEW_OK ;
 
1147
}
 
1148
 
 
1149
 
 
1150
/**
 
1151
 *Paste the last node found in the clipboard into the xml document
 
1152
 *model.
 
1153
 *The pasted node is pasted as a previous sibling node of the 
 
1154
 *currently selected xml node.
 
1155
 *@param a_this the current instance of #MlViewStyledView
 
1156
 */
 
1157
enum MlViewStatus
 
1158
mlview_styled_view_paste_node_as_prev_sibling (MlViewStyledView * a_this) 
 
1159
{
 
1160
        GtkTreeIter cur_sel_start={0} ;
 
1161
        enum MlViewStatus status=MLVIEW_OK ;
 
1162
 
 
1163
        g_return_val_if_fail (a_this != NULL
 
1164
                              && MLVIEW_IS_STYLED_VIEW (a_this)
 
1165
                              && PRIVATE (a_this),
 
1166
                              MLVIEW_BAD_PARAM_ERROR) ;
 
1167
 
 
1168
        status = mlview_tree_editor2_get_cur_sel_start_iter
 
1169
                (PRIVATE (a_this)->tree_editor, 
 
1170
                 &cur_sel_start) ;
 
1171
        g_return_val_if_fail (status == MLVIEW_OK, status) ;
 
1172
        status = mlview_tree_editor2_paste_node_as_sibling
 
1173
                (PRIVATE (a_this)->tree_editor, 
 
1174
                 &cur_sel_start, TRUE) ;
 
1175
        return status ;
 
1176
}
 
1177
 
 
1178
/**
 
1179
 *Pastes the last node found in the clipboard at
 
1180
 *the place of the the currently selected xml node.
 
1181
 *@param a_this a pointer to the current instance
 
1182
 *of MlViewStyledView.
 
1183
 */
 
1184
enum MlViewStatus
 
1185
mlview_styled_view_paste_node_as_next_sibling (MlViewStyledView * a_this)
 
1186
{
 
1187
        GtkTreeIter cur_sel_start={0} ;
 
1188
        enum MlViewStatus status = MLVIEW_OK ;
 
1189
 
 
1190
        g_return_val_if_fail (a_this != NULL, MLVIEW_BAD_PARAM_ERROR);
 
1191
        g_return_val_if_fail (PRIVATE (a_this) != NULL, MLVIEW_BAD_PARAM_ERROR);
 
1192
 
 
1193
        status = mlview_tree_editor2_get_cur_sel_start_iter
 
1194
                (PRIVATE (a_this)->tree_editor,
 
1195
                 &cur_sel_start) ;
 
1196
        g_return_val_if_fail (status == MLVIEW_OK, status) ;
 
1197
        mlview_tree_editor2_paste_node_as_sibling
 
1198
                (PRIVATE (a_this)->tree_editor,
 
1199
                 &cur_sel_start, FALSE) ;
 
1200
        return MLVIEW_OK ;
 
1201
}
 
1202
 
 
1203
enum MlViewStatus
 
1204
mlview_styled_view_execute_action (MlViewIView *a_this,
 
1205
                                   MlViewAction *a_action)
 
1206
{
 
1207
        MlViewStyledView *view = NULL ;
 
1208
 
 
1209
        g_return_val_if_fail (a_this && MLVIEW_IS_IVIEW (a_this),
 
1210
                              MLVIEW_BAD_PARAM_ERROR) ;
 
1211
 
 
1212
        view = MLVIEW_STYLED_VIEW (a_this) ;
 
1213
        g_return_val_if_fail (PRIVATE (view), MLVIEW_BAD_PARAM_ERROR) ;
 
1214
        
 
1215
        if (!strcmp (a_action->name, "add-child-node-interactive")) {
 
1216
                mlview_styled_view_add_child_node_interactive (view) ;
 
1217
        } else if (!strcmp (a_action->name, "insert-prev-sibling-node-interactive")){
 
1218
                mlview_styled_view_insert_prev_sibling_node_interactive (view) ;
 
1219
        } else if (!strcmp (a_action->name, "insert-next-sibling-node-interactive")) {
 
1220
                mlview_styled_view_insert_next_sibling_node_interactive (view) ;
 
1221
        } else if (!strcmp (a_action->name, "cut-node")) {
 
1222
                mlview_styled_view_cut_node (view) ;
 
1223
        } else if (!strcmp (a_action->name, "copy-node")) {
 
1224
                mlview_styled_view_copy_node (view) ;
 
1225
        } else if (!strcmp (a_action->name, "paste-node-as-child")) {
 
1226
                mlview_styled_view_paste_node_as_child (view) ;
 
1227
        } else if (!strcmp (a_action->name, "paste-node-as-prev-sibling")) {
 
1228
                mlview_styled_view_paste_node_as_prev_sibling (view) ;
 
1229
        } else if (!strcmp (a_action->name, "paste-node-as-next-sibling")) {
 
1230
                mlview_styled_view_paste_node_as_next_sibling (view) ;
 
1231
        } 
 
1232
        return MLVIEW_OK ;
 
1233
}
 
1234
 
 
1235
/**
 
1236
 *Connects the view to the signals of the document object model.
 
1237
 *This implements the MlViewIView::connect_to_doc() method.
 
1238
 *@param a_this the current instance of #MlViewStyledView
 
1239
 *@param a_doc the document object model to connect to.
 
1240
 *@return MLVIEW_OK upon successful completion, an error code otherwise.
 
1241
 */
 
1242
enum MlViewStatus
 
1243
mlview_styled_view_connect_to_doc (MlViewIView *a_this,
 
1244
                                   MlViewXMLDocument *a_doc)
 
1245
{
 
1246
        MlViewStyledView *view = NULL ;
 
1247
 
 
1248
        g_return_val_if_fail (a_this                               
 
1249
                              && MLVIEW_IS_IVIEW (a_this)
 
1250
                              && MLVIEW_IS_STYLED_VIEW (a_this)
 
1251
                              && a_doc
 
1252
                              && MLVIEW_IS_XML_DOCUMENT (a_doc),
 
1253
                              MLVIEW_BAD_PARAM_ERROR) ;
 
1254
 
 
1255
        view = MLVIEW_STYLED_VIEW (a_this) ;
 
1256
        g_return_val_if_fail (view 
 
1257
                              && PRIVATE (view)
 
1258
                              && PRIVATE (view)->tree_editor
 
1259
                              && PRIVATE (view)->styled_editor,
 
1260
                              MLVIEW_BAD_PARAM_ERROR) ;
 
1261
 
 
1262
        if (PRIVATE (view)->connected_to_doc == TRUE)
 
1263
                return MLVIEW_OK ;
 
1264
 
 
1265
        mlview_tree_editor2_connect_to_doc (PRIVATE (view)->tree_editor,
 
1266
                                            a_doc) ;
 
1267
        /*
 
1268
         *TODO: connect the styled editor to the document signals
 
1269
         */
 
1270
        PRIVATE (view)->connected_to_doc = TRUE ;
 
1271
        return MLVIEW_OK ;
 
1272
}
 
1273
 
 
1274
/**
 
1275
 *Disonnects the view from the signals of the document object model.
 
1276
 *This implements the MlViewIView::disconnect_from_view() method.
 
1277
 *@param a_this the current instance of #MlViewStyledView
 
1278
 *@param a_doc the document object model to connect to.
 
1279
 *@return MLVIEW_OK upon successful completion, an error code otherwise.
 
1280
 */
 
1281
enum MlViewStatus
 
1282
mlview_styled_view_disconnect_from_doc (MlViewIView *a_this,
 
1283
                                        MlViewXMLDocument *a_doc)
 
1284
{
 
1285
 
 
1286
        MlViewStyledView *view = NULL ;
 
1287
 
 
1288
        g_return_val_if_fail (a_this                               
 
1289
                              && MLVIEW_IS_IVIEW (a_this)
 
1290
                              && MLVIEW_IS_STYLED_VIEW (a_this)
 
1291
                              && a_doc
 
1292
                              && MLVIEW_IS_XML_DOCUMENT (a_doc),
 
1293
                              MLVIEW_BAD_PARAM_ERROR) ;
 
1294
 
 
1295
 
 
1296
        view = MLVIEW_STYLED_VIEW (a_this) ;
 
1297
        g_return_val_if_fail (view 
 
1298
                              && PRIVATE (view)
 
1299
                              && PRIVATE (view)->tree_editor
 
1300
                              && PRIVATE (view)->styled_editor,
 
1301
                              MLVIEW_BAD_PARAM_ERROR) ;
 
1302
 
 
1303
        if (PRIVATE (view)->connected_to_doc == FALSE)
 
1304
                return MLVIEW_OK ;
 
1305
 
 
1306
        mlview_tree_editor2_disconnect_from_doc (PRIVATE (view)->tree_editor, 
 
1307
                                                 a_doc) ;
 
1308
        /*
 
1309
         *TODO: disconnect the styled editor to the document signals
 
1310
         */
 
1311
        return MLVIEW_OK ;
 
1312
}
 
1313
 
 
1314
 
 
1315
enum MlViewStatus
 
1316
mlview_styled_view_update_from_css_paths_interactive (MlViewStyledView *a_this)
 
1317
{
 
1318
        GtkDialog *dialog = NULL ;
 
1319
        gint response = 0 ;
 
1320
        enum CRStatus status = CR_OK ;
 
1321
        guchar *author_css=NULL, *user_css=NULL, *ua_css=NULL ;
 
1322
 
 
1323
        g_return_val_if_fail (a_this && MLVIEW_IS_STYLED_VIEW (a_this),
 
1324
                              MLVIEW_BAD_PARAM_ERROR) ;
 
1325
 
 
1326
        dialog = GTK_DIALOG (get_css_paths_picker_dialog (a_this)) ;    
 
1327
        g_return_val_if_fail (dialog, MLVIEW_ERROR) ;
 
1328
        response = gtk_dialog_run (dialog) ;
 
1329
        switch (response) {
 
1330
        case GTK_RESPONSE_OK:
 
1331
                author_css = g_strdup
 
1332
                        (gtk_entry_get_text
 
1333
                         (PRIVATE (a_this)->css_picker_author_css_path)) ;
 
1334
                user_css = g_strdup
 
1335
                        (gtk_entry_get_text
 
1336
                         (PRIVATE (a_this)->css_picker_user_css_path)) ;
 
1337
                ua_css = g_strdup
 
1338
                        (gtk_entry_get_text
 
1339
                         (PRIVATE (a_this)->css_picker_ua_css_path)) ;
 
1340
                status = sx_box_view_update_box_model_attrs_from_css 
 
1341
                        (PRIVATE (a_this)->styled_editor, author_css,
 
1342
                         user_css, ua_css, CR_ASCII) ;
 
1343
                if (author_css) {
 
1344
                        g_free (author_css) ;
 
1345
                        author_css = NULL ;
 
1346
                }
 
1347
                if (user_css) {
 
1348
                        g_free (user_css) ;
 
1349
                        user_css = NULL ;
 
1350
                }
 
1351
                if (ua_css) {
 
1352
                        g_free (ua_css) ;
 
1353
                        ua_css = NULL ;
 
1354
                }
 
1355
                break ;
 
1356
        case GTK_RESPONSE_CANCEL:
 
1357
        default:
 
1358
                break ;
 
1359
        }
 
1360
        gtk_widget_hide (GTK_WIDGET (dialog)) ;
 
1361
        return MLVIEW_OK ;
 
1362
}
 
1363
 
 
1364
enum MlViewStatus
 
1365
mlview_styled_view_update_from_css_paths (MlViewStyledView *a_this,
 
1366
                                          guchar *a_author_css_path,
 
1367
                                          guchar *a_user_css_path,
 
1368
                                          guchar *a_ua_css_path,
 
1369
                                          enum CREncoding a_enc)
 
1370
{
 
1371
        enum CRStatus status = CR_OK ;
 
1372
 
 
1373
        g_return_val_if_fail (a_this && MLVIEW_IS_STYLED_VIEW (a_this)
 
1374
                              && PRIVATE (a_this)->styled_editor,
 
1375
                              MLVIEW_BAD_PARAM_ERROR) ;
 
1376
 
 
1377
        status = sx_box_view_update_box_model_attrs_from_css
 
1378
                (PRIVATE (a_this)->styled_editor,
 
1379
                 a_author_css_path, a_user_css_path,
 
1380
                 a_ua_css_path, CR_ASCII) ;
 
1381
 
 
1382
        g_return_val_if_fail (status == CR_OK, MLVIEW_ERROR) ;
 
1383
 
 
1384
        return MLVIEW_OK ;
 
1385
 
 
1386
}
 
1387
 
 
1388
/**
 
1389
 *Getter of the application context associated to the
 
1390
 *current instance of #MlViewStyledView
 
1391
 *@param a_this the current instance of #MlViewStyledView
 
1392
 *@return the application context associated to the current
 
1393
 *instance of #MlViewStyledView
 
1394
 */
 
1395
MlViewAppContext *
 
1396
mlview_styled_view_get_app_context (MlViewStyledView *a_this)
 
1397
{
 
1398
        g_return_val_if_fail (a_this 
 
1399
                              && MLVIEW_IS_STYLED_VIEW (a_this)
 
1400
                              && PRIVATE (a_this),
 
1401
                              NULL) ;
 
1402
 
 
1403
        return PRIVATE (a_this)->app_context ;
 
1404
}
 
1405
 
 
1406
/**
 
1407
 *@param a_this the current instance of #MlViewStyledView
 
1408
 *@param a_app_context the instance of #MlViewAppContext associated
 
1409
 *to the current instance of #MlViewStyledView
 
1410
 *@return MLVIEW_OK upon successful completion, an error code
 
1411
 *otherwise.
 
1412
 */
 
1413
enum MlViewStatus
 
1414
mlview_styled_view_set_app_context (MlViewStyledView *a_this,
 
1415
                                    MlViewAppContext *a_app_context)
 
1416
{
 
1417
        g_return_val_if_fail (a_this && MLVIEW_IS_STYLED_VIEW (a_this)
 
1418
                              && PRIVATE (a_this),
 
1419
                              MLVIEW_BAD_PARAM_ERROR) ;
 
1420
 
 
1421
        PRIVATE (a_this)->app_context = a_app_context ;
 
1422
        return MLVIEW_OK ;
 
1423
}
 
1424
 
 
1425
 
 
1426
MlViewTreeEditor2 *
 
1427
mlview_styled_view_get_tree_editor (MlViewStyledView *a_this)
 
1428
{
 
1429
        g_return_val_if_fail (a_this && MLVIEW_IS_STYLED_VIEW (a_this),
 
1430
                              NULL) ;
 
1431
 
 
1432
        return PRIVATE (a_this)->tree_editor ;
 
1433
}
 
1434
 
 
1435
#endif /*MLVIEW_WITH_STYLE*/