1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* Nautilus
*
* Copyright (C) 1999, 2000 Red Hat, Inc.
* Copyright (C) 1999, 2000 Eazel, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* Authors: Elliot Lee <sopwith@redhat.com>
* John Sullivan <sullivan@eazel.com>
*
*/
/* ntl-window.c: Implementation of the main window object */
#include <config.h>
#include "ntl-window-private.h"
#include <gnome.h>
#include <math.h>
#include "nautilus.h"
#include "nautilus-bookmarks-window.h"
#include "nautilus-signaller.h"
#include "nautilus-location-bar.h"
#include "ntl-index-panel.h"
#include "ntl-miniicon.h"
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <libnautilus/nautilus-gtk-extensions.h>
#include <libnautilus/nautilus-icon-factory.h>
#include <libnautilus/nautilus-string.h>
#include "nautilus-zoom-control.h"
#include <ctype.h>
#include <libgnomevfs/gnome-vfs-uri.h>
enum
{
LAST_SIGNAL
};
static void nautilus_window_realize (GtkWidget *widget);
static void nautilus_window_real_set_content_view (NautilusWindow *window, NautilusView *new_view);
/* Object framework static variables */
static GnomeAppClass *parent_class = NULL;
static guint window_signals[LAST_SIGNAL];
/* Other static variables */
static GSList *history_list = NULL;
/* Stuff for handling the CORBA interface */
typedef struct {
POA_Nautilus_ViewWindow servant;
gpointer bonobo_object;
NautilusWindow *window;
} impl_POA_Nautilus_ViewWindow;
static const CORBA_char *impl_Nautilus_ViewWindow__get_current_uri (impl_POA_Nautilus_ViewWindow *servant,
CORBA_Environment *ev);
static Nautilus_Application impl_Nautilus_ViewWindow__get_application (impl_POA_Nautilus_ViewWindow *servant,
CORBA_Environment *ev);
static void impl_Nautilus_ViewWindow_open_uri (impl_POA_Nautilus_ViewWindow *servant,
CORBA_char *uri,
CORBA_Environment *ev);
static void impl_Nautilus_ViewWindow_close (impl_POA_Nautilus_ViewWindow *servant,
CORBA_Environment *ev);
static POA_Nautilus_ViewWindow__epv impl_Nautilus_ViewWindow_epv =
{
NULL,
(gpointer) &impl_Nautilus_ViewWindow__get_current_uri,
(gpointer) &impl_Nautilus_ViewWindow__get_application,
(gpointer) &impl_Nautilus_ViewWindow_open_uri,
(gpointer) &impl_Nautilus_ViewWindow_close
};
static PortableServer_ServantBase__epv base_epv = { NULL, NULL, NULL };
static POA_Nautilus_ViewWindow__vepv impl_Nautilus_ViewWindow_vepv =
{
&base_epv,
NULL,
&impl_Nautilus_ViewWindow_epv
};
static const CORBA_char *
impl_Nautilus_ViewWindow__get_current_uri (impl_POA_Nautilus_ViewWindow *servant,
CORBA_Environment *ev)
{
return nautilus_window_get_requested_uri (servant->window);
}
static Nautilus_Application
impl_Nautilus_ViewWindow__get_application (impl_POA_Nautilus_ViewWindow *servant,
CORBA_Environment *ev)
{
return CORBA_Object_duplicate(bonobo_object_corba_objref(servant->window->app), ev);
}
static void
impl_Nautilus_ViewWindow_open_uri (impl_POA_Nautilus_ViewWindow *servant,
CORBA_char *uri,
CORBA_Environment *ev)
{
nautilus_window_goto_uri (servant->window, uri);
}
static void
impl_Nautilus_ViewWindow_close (impl_POA_Nautilus_ViewWindow *servant,
CORBA_Environment *ev)
{
nautilus_window_close (servant->window);
}
static void
impl_Nautilus_ViewWindow__destroy(BonoboObject *obj, impl_POA_Nautilus_ViewWindow *servant)
{
PortableServer_ObjectId *objid;
CORBA_Environment ev;
CORBA_exception_init(&ev);
objid = PortableServer_POA_servant_to_id(bonobo_poa(), servant, &ev);
PortableServer_POA_deactivate_object(bonobo_poa(), objid, &ev);
CORBA_free(objid);
obj->servant = NULL;
POA_Nautilus_ViewWindow__fini((PortableServer_Servant) servant, &ev);
g_free(servant);
CORBA_exception_free(&ev);
}
static BonoboObject *
impl_Nautilus_ViewWindow__create(NautilusWindow *window)
{
BonoboObject *retval;
impl_POA_Nautilus_ViewWindow *newservant;
CORBA_Environment ev;
CORBA_exception_init(&ev);
newservant = g_new0(impl_POA_Nautilus_ViewWindow, 1);
newservant->servant.vepv = &impl_Nautilus_ViewWindow_vepv;
newservant->window = window;
POA_Nautilus_ViewWindow__init((PortableServer_Servant) newservant, &ev);
retval = bonobo_object_new_from_servant(newservant);
gtk_signal_connect(GTK_OBJECT(retval), "destroy", GTK_SIGNAL_FUNC(impl_Nautilus_ViewWindow__destroy), newservant);
CORBA_exception_free(&ev);
return retval;
}
static void nautilus_window_class_init (NautilusWindowClass *klass);
static void nautilus_window_init (NautilusWindow *window);
static void nautilus_window_destroy (NautilusWindow *window);
static void nautilus_window_set_arg (GtkObject *object,
GtkArg *arg,
guint arg_id);
static void nautilus_window_get_arg (GtkObject *object,
GtkArg *arg,
guint arg_id);
static void nautilus_window_goto_uri_cb (GtkWidget *widget,
const char *uri,
GtkWidget *window);
static void zoom_in_cb (NautilusZoomControl *zoom_control,
NautilusWindow *window);
static void zoom_out_cb (NautilusZoomControl *zoom_control,
NautilusWindow *window);
/* #define CONTENTS_AS_HBOX 1 */
/* milliseconds */
#define STATUSBAR_CLEAR_TIMEOUT 5000
GtkType
nautilus_window_get_type(void)
{
static guint window_type = 0;
if (!window_type)
{
GtkTypeInfo window_info =
{
"NautilusWindow",
sizeof(NautilusWindow),
sizeof(NautilusWindowClass),
(GtkClassInitFunc) nautilus_window_class_init,
(GtkObjectInitFunc) nautilus_window_init,
NULL,
NULL,
NULL
};
window_type = gtk_type_unique (gnome_app_get_type(), &window_info);
}
return window_type;
}
#if 0
typedef void (*GtkSignal_NONE__BOXED_OBJECT) (GtkObject * object,
gpointer arg1,
GtkObject *arg2,
gpointer user_data);
static void
gtk_marshal_NONE__BOXED_OBJECT (GtkObject * object,
GtkSignalFunc func,
gpointer func_data,
GtkArg * args)
{
GtkSignal_NONE__BOXED_OBJECT rfunc;
rfunc = (GtkSignal_NONE__BOXED_OBJECT) func;
(*rfunc) (object,
GTK_VALUE_BOXED (args[0]),
GTK_VALUE_OBJECT (args[1]),
func_data);
}
#endif
enum {
ARG_0,
ARG_APP_ID,
ARG_APP,
ARG_CONTENT_VIEW
};
static void
nautilus_window_class_init (NautilusWindowClass *klass)
{
GtkObjectClass *object_class;
GtkWidgetClass *widget_class;
parent_class = gtk_type_class(gnome_app_get_type());
object_class = (GtkObjectClass*) klass;
object_class->destroy = (void (*)(GtkObject *))nautilus_window_destroy;
object_class->get_arg = nautilus_window_get_arg;
object_class->set_arg = nautilus_window_set_arg;
widget_class = (GtkWidgetClass*) klass;
klass->parent_class = gtk_type_class (gtk_type_parent (object_class->type));
gtk_object_class_add_signals (object_class, window_signals, LAST_SIGNAL);
gtk_object_add_arg_type ("NautilusWindow::app_id",
GTK_TYPE_STRING,
GTK_ARG_READWRITE|GTK_ARG_CONSTRUCT,
ARG_APP_ID);
gtk_object_add_arg_type ("NautilusWindow::app",
GTK_TYPE_OBJECT,
GTK_ARG_READWRITE|GTK_ARG_CONSTRUCT,
ARG_APP);
gtk_object_add_arg_type ("NautilusWindow::content_view",
GTK_TYPE_OBJECT,
GTK_ARG_READWRITE,
ARG_CONTENT_VIEW);
impl_Nautilus_ViewWindow_vepv.Bonobo_Unknown_epv = bonobo_object_get_epv();
widget_class->realize = nautilus_window_realize;
}
static void
nautilus_window_init (NautilusWindow *window)
{
gtk_quit_add_destroy (1, GTK_OBJECT (window));
}
static gboolean
nautilus_window_clear_status(NautilusWindow *window)
{
gtk_statusbar_pop(GTK_STATUSBAR(GNOME_APP(window)->statusbar), window->statusbar_ctx);
window->statusbar_clear_id = 0;
return FALSE;
}
void
nautilus_window_set_status(NautilusWindow *window, const char *txt)
{
if(window->statusbar_clear_id)
g_source_remove(window->statusbar_clear_id);
gtk_statusbar_pop(GTK_STATUSBAR(GNOME_APP(window)->statusbar), window->statusbar_ctx);
if(txt && *txt)
{
window->statusbar_clear_id = g_timeout_add(STATUSBAR_CLEAR_TIMEOUT, (GSourceFunc)nautilus_window_clear_status, window);
gtk_statusbar_push(GTK_STATUSBAR(GNOME_APP(window)->statusbar), window->statusbar_ctx, txt);
}
else
window->statusbar_clear_id = 0;
}
void
nautilus_window_goto_uri (NautilusWindow *window, const char *uri)
{
Nautilus_NavigationRequestInfo navinfo;
memset(&navinfo, 0, sizeof(navinfo));
navinfo.requested_uri = (char *)uri;
navinfo.new_window_requested = FALSE;
nautilus_window_request_location_change (window, &navinfo, NULL);
}
static void
nautilus_window_goto_uri_cb (GtkWidget *widget,
const char *uri,
GtkWidget *window)
{
nautilus_window_goto_uri(NAUTILUS_WINDOW(window), uri);
}
static void
zoom_in_cb (NautilusZoomControl *zoom_control,
NautilusWindow *window)
{
if (window->content_view != NULL) {
nautilus_view_zoom_in (window->content_view);
}
}
static void
zoom_out_cb (NautilusZoomControl *zoom_control,
NautilusWindow *window)
{
if (window->content_view != NULL) {
nautilus_view_zoom_out (window->content_view);
}
}
static void
nautilus_window_constructed(NautilusWindow *window)
{
GnomeApp *app;
GtkWidget *location_bar_box, *statusbar;
GtkWidget *temp_frame;
app = GNOME_APP(window);
/* set up location bar */
location_bar_box = gtk_hbox_new(FALSE, GNOME_PAD);
gtk_container_set_border_width(GTK_CONTAINER(location_bar_box), GNOME_PAD_SMALL);
window->ent_uri = nautilus_location_bar_new();
gtk_signal_connect(GTK_OBJECT(window->ent_uri), "location_changed",
nautilus_window_goto_uri_cb, window);
gtk_box_pack_start(GTK_BOX(location_bar_box), window->ent_uri, TRUE, TRUE, GNOME_PAD_SMALL);
gnome_app_add_docked(app, location_bar_box, "uri-entry",
GNOME_DOCK_ITEM_BEH_EXCLUSIVE|GNOME_DOCK_ITEM_BEH_NEVER_VERTICAL,
GNOME_DOCK_TOP, 2, 0, 0);
/* Option menu for content view types; it's empty here, filled in when a uri is set. */
window->option_cvtype = gtk_option_menu_new();
gtk_box_pack_end(GTK_BOX(location_bar_box), window->option_cvtype, FALSE, FALSE, GNOME_PAD_SMALL);
gtk_widget_show(window->option_cvtype);
/* allocate the zoom control and place on the right next to the menu */
window->zoom_control = nautilus_zoom_control_new ();
gtk_widget_show (window->zoom_control);
gtk_signal_connect (GTK_OBJECT (window->zoom_control), "zoom_in", zoom_in_cb, window);
gtk_signal_connect (GTK_OBJECT (window->zoom_control), "zoom_out", zoom_out_cb, window);
gtk_box_pack_end (GTK_BOX (location_bar_box), window->zoom_control, FALSE, FALSE, 0);
gtk_widget_show_all(location_bar_box);
/* set up status bar */
gnome_app_set_statusbar(app, (statusbar = gtk_statusbar_new()));
/* insert a little padding so text isn't jammed against frame */
gtk_misc_set_padding(GTK_MISC ((GTK_STATUSBAR (statusbar))->label), GNOME_PAD, 0);
window->statusbar_ctx = gtk_statusbar_get_context_id(GTK_STATUSBAR(statusbar), "IhateGtkStatusbar");
/* set up window contents and policy */
gtk_window_set_policy(GTK_WINDOW(window), FALSE, TRUE, FALSE);
gtk_window_set_default_size(GTK_WINDOW(window), 650, 400);
#ifdef CONTENTS_AS_HBOX
window->content_hbox = gtk_hbox_new(FALSE, 0);
#else
window->content_hbox = gtk_hpaned_new();
{
/* special case the width of the index panel for sopwith */
char *user_name = getenv("USER");
gint pos = 136;
if (!strcmp(user_name, "sopwith"))
pos = 275;
gtk_paned_set_position(GTK_PANED(window->content_hbox), pos);
}
#endif
gnome_app_set_contents(app, window->content_hbox);
/* set up the index panel in a frame */
temp_frame = gtk_frame_new(NULL);
gtk_frame_set_shadow_type(GTK_FRAME(temp_frame), GTK_SHADOW_OUT);
gtk_widget_show(temp_frame);
window->index_panel = nautilus_index_panel_new();
gtk_widget_show (GTK_WIDGET (window->index_panel));
gtk_container_add(GTK_CONTAINER(temp_frame), GTK_WIDGET (window->index_panel));
#ifdef CONTENTS_AS_HBOX
gtk_box_pack_start(GTK_BOX(window->content_hbox), temp_frame, FALSE, FALSE, 0);
#else
gtk_paned_pack1(GTK_PANED(window->content_hbox), temp_frame, TRUE, TRUE);
#endif
gtk_widget_show_all(window->content_hbox);
/* enable mouse tracking for the index panel */
gtk_widget_add_events(GTK_WIDGET (window->index_panel), GDK_POINTER_MOTION_MASK);
/* CORBA and Bonobo setup */
window->ntl_viewwindow = impl_Nautilus_ViewWindow__create(window);
window->uih = bonobo_ui_handler_new();
bonobo_ui_handler_set_app(window->uih, app);
bonobo_ui_handler_set_statusbar(window->uih, statusbar);
/* Create menus and toolbars */
nautilus_window_initialize_menus (window);
nautilus_window_initialize_toolbars (window);
/* Set initial sensitivity of some buttons & menu items
* now that they're all created.
*/
nautilus_window_allow_back(window, FALSE);
nautilus_window_allow_forward(window, FALSE);
nautilus_window_allow_stop(window, FALSE);
}
static void
nautilus_window_set_arg (GtkObject *object,
GtkArg *arg,
guint arg_id)
{
GnomeApp *app = (GnomeApp *) object;
char *old_app_name;
NautilusWindow *window = (NautilusWindow *) object;
switch(arg_id) {
case ARG_APP_ID:
if(!GTK_VALUE_STRING(*arg))
return;
old_app_name = app->name;
g_free(app->name);
app->name = g_strdup(GTK_VALUE_STRING(*arg));
g_assert(app->name);
g_free(app->prefix);
app->prefix = g_strconcat("/", app->name, "/", NULL);
if(!old_app_name)
nautilus_window_constructed(NAUTILUS_WINDOW(object));
break;
case ARG_APP:
window->app = BONOBO_OBJECT(GTK_VALUE_OBJECT(*arg));
break;
case ARG_CONTENT_VIEW:
nautilus_window_real_set_content_view (window, (NautilusView *)GTK_VALUE_OBJECT(*arg));
break;
}
}
static void
nautilus_window_get_arg (GtkObject *object,
GtkArg *arg,
guint arg_id)
{
GnomeApp *app = (GnomeApp *) object;
switch(arg_id) {
case ARG_APP_ID:
GTK_VALUE_STRING(*arg) = app->name;
break;
case ARG_APP:
GTK_VALUE_OBJECT(*arg) = GTK_OBJECT(NAUTILUS_WINDOW(object)->app);
break;
case ARG_CONTENT_VIEW:
GTK_VALUE_OBJECT(*arg) = GTK_OBJECT(((NautilusWindow *)object)->content_view);
break;
}
}
static void
nautilus_window_destroy (NautilusWindow *window)
{
NautilusWindowClass *klass = NAUTILUS_WINDOW_CLASS(GTK_OBJECT(window)->klass);
g_slist_free(window->meta_views);
CORBA_free(window->ni);
CORBA_free(window->si);
g_slist_foreach(window->back_list, (GFunc)gtk_object_unref, NULL);
g_slist_foreach(window->forward_list, (GFunc)gtk_object_unref, NULL);
g_slist_free(window->back_list);
g_slist_free(window->forward_list);
if(window->statusbar_clear_id)
g_source_remove(window->statusbar_clear_id);
if(GTK_OBJECT_CLASS(klass->parent_class)->destroy)
GTK_OBJECT_CLASS(klass->parent_class)->destroy(GTK_OBJECT(window));
}
void
nautilus_window_close (NautilusWindow *window)
{
g_return_if_fail (NAUTILUS_IS_WINDOW (window));
gtk_widget_destroy (GTK_WIDGET (window));
}
/* The reason for this function is that
`gdk_pixbuf_render_pixmap_and_mask', as currently implemented, will
fail on a pixbuf with no alpha channel. This function will instead
return with NULL in *mask_retval in such a case. If that ever gets
fixed, this function should be removed.
*/
static void
would_be_in_gdk_pixbuf_if_federico_wasnt_stubborn_pixbuf_render(GdkPixbuf *pixbuf,
GdkPixmap **pixmap,
GdkBitmap **mask_retval,
gint alpha_threshold)
{
GdkBitmap *mask = NULL;
g_return_if_fail(pixbuf != NULL);
/* generate mask */
if (gdk_pixbuf_get_has_alpha(pixbuf)) {
mask = gdk_pixmap_new(NULL,
gdk_pixbuf_get_width(pixbuf),
gdk_pixbuf_get_height(pixbuf),
1);
gdk_pixbuf_render_threshold_alpha(pixbuf, mask,
0, 0, 0, 0,
gdk_pixbuf_get_width(pixbuf),
gdk_pixbuf_get_height(pixbuf),
alpha_threshold);
}
/* Draw to pixmap */
if (pixmap != NULL) {
GdkGC* gc;
*pixmap = gdk_pixmap_new(NULL,
gdk_pixbuf_get_width(pixbuf),
gdk_pixbuf_get_height(pixbuf),
gdk_rgb_get_visual()->depth);
gc = gdk_gc_new(*pixmap);
gdk_gc_set_clip_mask(gc, mask);
gdk_pixbuf_render_to_drawable(pixbuf, *pixmap,
gc,
0, 0, 0, 0,
gdk_pixbuf_get_width(pixbuf),
gdk_pixbuf_get_height(pixbuf),
GDK_RGB_DITHER_NORMAL,
0, 0);
gdk_gc_unref(gc);
}
if (mask_retval)
*mask_retval = mask;
else
gdk_bitmap_unref(mask);
}
static void
nautilus_window_realize (GtkWidget *widget)
{
GdkPixmap *pixmap = NULL;
GdkBitmap *mask = NULL;
gchar *filename;
/* Create our GdkWindow */
if (GTK_WIDGET_CLASS(parent_class)->realize)
(* GTK_WIDGET_CLASS(parent_class)->realize) (widget);
/* Set the mini icon */
/* FIXME draw a real icon */
/* FIXME The icon should be 16x16, we get garbage on the edges
since it's 12x12 */
filename = gnome_pixmap_file("panel-arrow-down.png");
if (filename != NULL) {
GdkPixbuf *pixbuf;
pixbuf = gdk_pixbuf_new_from_file(filename);
if (pixbuf != NULL) {
would_be_in_gdk_pixbuf_if_federico_wasnt_stubborn_pixbuf_render(pixbuf,
&pixmap,
&mask,
128);
}
}
if (pixmap != NULL)
nautilus_set_mini_icon(widget->window,
pixmap,
mask);
/* FIXME I think we are leaking the pixmap/mask here */
}
/*
* Main API
*/
#if 0
static gboolean
nautilus_window_send_show_properties(GtkWidget *dockitem, GdkEventButton *event, NautilusView *meta_view)
{
if(event->button != 3)
return FALSE;
gtk_signal_emit_stop_by_name(GTK_OBJECT(dockitem), "button_press_event");
nautilus_view_show_properties(meta_view);
return TRUE;
}
#endif
void
nautilus_window_set_content_view(NautilusWindow *window, NautilusView *content_view)
{
nautilus_window_real_set_content_view (window, content_view);
}
void
nautilus_window_add_meta_view(NautilusWindow *window, NautilusView *meta_view)
{
g_return_if_fail (!g_slist_find (window->meta_views, meta_view));
g_return_if_fail (NAUTILUS_IS_META_VIEW (meta_view));
nautilus_index_panel_add_meta_view (window->index_panel, meta_view);
window->meta_views = g_slist_prepend (window->meta_views, meta_view);
}
void
nautilus_window_remove_meta_view_real(NautilusWindow *window, NautilusView *meta_view)
{
nautilus_index_panel_remove_meta_view(window->index_panel, meta_view);
}
void
nautilus_window_remove_meta_view(NautilusWindow *window, NautilusView *meta_view)
{
if(!g_slist_find(window->meta_views, meta_view))
return;
window->meta_views = g_slist_remove(window->meta_views, meta_view);
nautilus_window_remove_meta_view_real(window, meta_view);
}
void
nautilus_window_back_or_forward (NautilusWindow *window, gboolean back, guint distance)
{
Nautilus_NavigationRequestInfo nri;
GSList *list;
list = back ? window->back_list : window->forward_list;
g_assert (g_slist_length (list) > distance);
memset(&nri, 0, sizeof(nri));
/* FIXME: Have to cast away the const for nri.requested_uri. This field should be
* declared const. */
nri.requested_uri = (char *)nautilus_bookmark_get_uri (g_slist_nth_data (list, distance));
nri.new_window_requested = FALSE;
nautilus_window_begin_location_change (window, &nri, NULL, back ? NAUTILUS_LOCATION_CHANGE_BACK : NAUTILUS_LOCATION_CHANGE_FORWARD, distance);
}
void
nautilus_window_back_cb (GtkWidget *widget, NautilusWindow *window)
{
nautilus_window_back_or_forward (window, TRUE, 0);
}
void
nautilus_window_forward_cb (GtkWidget *widget, NautilusWindow *window)
{
nautilus_window_back_or_forward (window, FALSE, 0);
}
const char *
nautilus_window_get_requested_uri (NautilusWindow *window)
{
return window->ni == NULL ? NULL : window->ni->requested_uri;
}
BonoboUIHandler *
nautilus_window_get_uih(NautilusWindow *window)
{
return window->uih;
}
void
nautilus_window_up_cb (GtkWidget *widget, NautilusWindow *window)
{
const char *requested_uri;
GnomeVFSURI *current_uri;
GnomeVFSURI *parent_uri;
char *parent_uri_string;
requested_uri = nautilus_window_get_requested_uri(window);
if (requested_uri == NULL)
return;
current_uri = gnome_vfs_uri_new (requested_uri);
parent_uri = gnome_vfs_uri_get_parent (current_uri);
gnome_vfs_uri_unref (current_uri);
parent_uri_string = gnome_vfs_uri_to_string (parent_uri, GNOME_VFS_URI_HIDE_NONE);
gnome_vfs_uri_unref (parent_uri);
nautilus_window_goto_uri (window, parent_uri_string);
g_free (parent_uri_string);
}
void
nautilus_window_home_cb (GtkWidget *widget, NautilusWindow *window)
{
nautilus_window_set_initial_state(window, NULL);
}
void
nautilus_window_allow_back (NautilusWindow *window, gboolean allow)
{
gtk_widget_set_sensitive(window->back_button, allow);
bonobo_ui_handler_menu_set_sensitivity(window->uih, "/Go/Back", allow);
}
void
nautilus_window_allow_forward (NautilusWindow *window, gboolean allow)
{
gtk_widget_set_sensitive(window->forward_button, allow);
bonobo_ui_handler_menu_set_sensitivity(window->uih, "/Go/Forward", allow);
}
void
nautilus_window_allow_up (NautilusWindow *window, gboolean allow)
{
gtk_widget_set_sensitive(window->up_button, allow);
bonobo_ui_handler_menu_set_sensitivity(window->uih, "/Go/Up", allow);
}
void
nautilus_window_allow_reload (NautilusWindow *window, gboolean allow)
{
gtk_widget_set_sensitive(window->reload_button, allow);
}
void
nautilus_window_allow_stop (NautilusWindow *window, gboolean allow)
{
gtk_widget_set_sensitive(window->stop_button, allow);
}
void
nautilus_send_history_list_changed ()
{
gtk_signal_emit_by_name (GTK_OBJECT (nautilus_signaller_get_current ()),
"history_list_changed");
}
void
nautilus_add_to_history_list (NautilusBookmark *bookmark)
{
/* Note that the history is shared amongst all windows so
* this is not a NautilusWindow function. Perhaps it belongs
* in its own file.
*/
GSList *found_link;
g_return_if_fail (NAUTILUS_IS_BOOKMARK (bookmark));
found_link = g_slist_find_custom (history_list,
bookmark,
nautilus_bookmark_compare_with);
/* Remove any older entry for this same item. There can be at most 1. */
if (found_link != NULL)
{
gtk_object_unref (found_link->data);
history_list = g_slist_remove_link (history_list, found_link);
}
/* New item goes first. */
gtk_object_ref (GTK_OBJECT (bookmark));
history_list = g_slist_prepend(history_list, bookmark);
/* Tell world that history list has changed. At least all the
* NautilusWindows (not just this one) are listening.
*/
nautilus_send_history_list_changed ();
}
GSList *
nautilus_get_history_list ()
{
return history_list;
}
static void
nautilus_window_request_location_change_cb (NautilusView *view,
Nautilus_NavigationRequestInfo *info,
NautilusWindow *window)
{
nautilus_window_request_location_change(window, info, view);
}
static void
nautilus_window_request_selection_change_cb (NautilusView *view,
Nautilus_SelectionRequestInfo *info,
NautilusWindow *window)
{
nautilus_window_request_selection_change(window, info, view);
}
static void
nautilus_window_request_status_change_cb (NautilusView *view,
Nautilus_StatusRequestInfo *info,
NautilusWindow *window)
{
nautilus_window_request_status_change(window, info, view);
}
static void
nautilus_window_request_progress_change_cb (NautilusView *view,
Nautilus_ProgressRequestInfo *info,
NautilusWindow *window)
{
nautilus_window_request_progress_change(window, info, view);
}
static void
nautilus_window_request_title_change_callback (NautilusContentView *view,
const char *new_title,
NautilusWindow *window)
{
nautilus_window_request_title_change(window, new_title, view);
}
void
nautilus_window_connect_view(NautilusWindow *window, NautilusView *view)
{
GtkObject *view_object;
view_object = GTK_OBJECT(view);
gtk_signal_connect(view_object,
"request_location_change",
nautilus_window_request_location_change_cb,
window);
gtk_signal_connect(view_object,
"request_selection_change",
nautilus_window_request_selection_change_cb,
window);
gtk_signal_connect(view_object,
"request_status_change",
nautilus_window_request_status_change_cb,
window);
gtk_signal_connect(view_object,
"request_progress_change",
nautilus_window_request_progress_change_cb,
window);
gtk_signal_connect(view_object,
"destroy",
nautilus_window_view_destroyed,
window);
}
void
nautilus_window_connect_content_view(NautilusWindow *window, NautilusContentView *view)
{
GtkObject *view_object;
/* First connect with NautilusView signals. */
nautilus_window_connect_view (window, NAUTILUS_VIEW (view));
/* Now connect with NautilusContentView signals. */
view_object = GTK_OBJECT(view);
gtk_signal_connect(view_object,
"request_title_change",
nautilus_window_request_title_change_callback,
window);
}
void
nautilus_window_display_error(NautilusWindow *window, const char *error_msg)
{
GtkWidget *dialog;
dialog = gnome_message_box_new(error_msg, GNOME_MESSAGE_BOX_ERROR, _("Close"), NULL);
gnome_dialog_set_close(GNOME_DIALOG(dialog), TRUE);
gnome_dialog_set_default(GNOME_DIALOG(dialog), 0);
gtk_widget_show(dialog);
}
static void
nautilus_window_real_set_content_view (NautilusWindow *window, NautilusView *new_view)
{
g_return_if_fail (NAUTILUS_IS_WINDOW (window));
g_return_if_fail (new_view == NULL || NAUTILUS_IS_VIEW (new_view));
if (new_view == window->content_view)
{
return;
}
if (window->content_view != NULL)
{
gtk_container_remove (GTK_CONTAINER (window->content_hbox), GTK_WIDGET (window->content_view));
}
if (new_view != NULL)
{
nautilus_zoom_control_reset_zoom_level (NAUTILUS_ZOOM_CONTROL (window->zoom_control));
gtk_widget_show (GTK_WIDGET (new_view));
nautilus_content_view_set_active (NAUTILUS_CONTENT_VIEW (new_view));
#ifdef CONTENTS_AS_HBOX
gtk_box_pack_end(GTK_BOX(window->content_hbox), GTK_WIDGET (new_view), TRUE, TRUE, 0);
#else
gtk_paned_pack2(GTK_PANED(window->content_hbox), GTK_WIDGET (new_view), TRUE, FALSE);
#endif
}
gtk_widget_queue_resize(window->content_hbox);
window->content_view = new_view;
}
|