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
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* EEntry: An EText-based entry widget
*
* Authors:
* Miguel de Icaza <miguel@helixcode.com>
* Chris Lahey <clahey@helixcode.com>
* Jon Trowbridge <trow@ximian.com>
*
* Copyright (C) 1999, 2000, 2001 Ximian Inc.
*/
/*
* This program 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 program 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 program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
#include <config.h>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#ifdef HAVE_ALLOCA_H
#include <alloca.h>
#endif
#include <stdio.h>
#include <libgnomeui/gnome-canvas.h>
#include <gtk/gtksignal.h>
#include <gnome-xml/parser.h>
#include "gal/util/e-util.h"
#include "gal/widgets/e-canvas.h"
#include "gal/widgets/e-canvas-utils.h"
#include "e-completion-view.h"
#include "e-text.h"
#include "e-entry.h"
#define MIN_ENTRY_WIDTH 150
#define INNER_BORDER 2
#define PARENT_TYPE gtk_table_get_type ()
static GtkObjectClass *parent_class;
enum {
E_ENTRY_CHANGED,
E_ENTRY_ACTIVATE,
E_ENTRY_LAST_SIGNAL
};
static guint e_entry_signals[E_ENTRY_LAST_SIGNAL] = { 0 };
/* Object argument IDs */
enum {
ARG_0,
ARG_MODEL,
ARG_EVENT_PROCESSOR,
ARG_TEXT,
ARG_FONT,
ARG_FONTSET,
ARG_FONT_GDK,
ARG_ANCHOR,
ARG_JUSTIFICATION,
ARG_X_OFFSET,
ARG_Y_OFFSET,
ARG_FILL_COLOR,
ARG_FILL_COLOR_GDK,
ARG_FILL_COLOR_RGBA,
ARG_FILL_STIPPLE,
ARG_EDITABLE,
ARG_USE_ELLIPSIS,
ARG_ELLIPSIS,
ARG_LINE_WRAP,
ARG_BREAK_CHARACTERS,
ARG_MAX_LINES,
ARG_ALLOW_NEWLINES,
ARG_DRAW_BORDERS,
ARG_DRAW_BACKGROUND,
ARG_CURSOR_POS
};
typedef struct _EEntryPrivate EEntryPrivate;
struct _EEntryPrivate {
GnomeCanvas *canvas;
EText *item;
GtkJustification justification;
guint changed_proxy_tag;
guint activate_proxy_tag;
/* Data related to completions */
ECompletion *completion;
EEntryCompletionHandler handler;
GtkWidget *completion_view;
guint nonempty_signal_id;
guint added_signal_id;
guint full_signal_id;
guint browse_signal_id;
guint unbrowse_signal_id;
guint activate_signal_id;
GtkWidget *completion_view_popup;
gboolean popup_is_visible;
gchar *pre_browse_text;
gint completion_delay;
guint completion_delay_tag;
guint draw_borders : 1;
};
static gboolean e_entry_is_empty (EEntry *entry);
static void e_entry_show_popup (EEntry *entry, gboolean x);
static void e_entry_start_completion (EEntry *entry);
static void e_entry_start_delayed_completion (EEntry *entry, gint delay);
static void e_entry_cancel_delayed_completion (EEntry *entry);
static void
canvas_size_allocate (GtkWidget *widget, GtkAllocation *alloc,
EEntry *entry)
{
gint xthick;
gint ythick;
gnome_canvas_set_scroll_region (entry->priv->canvas,
0, 0, alloc->width, alloc->height);
gtk_object_set (GTK_OBJECT (entry->priv->item),
"clip_width", (double) (alloc->width),
"clip_height", (double) (alloc->height),
NULL);
if (entry->priv->draw_borders) {
xthick = 0;
ythick = 0;
} else {
xthick = widget->style->klass->xthickness;
ythick = widget->style->klass->ythickness;
}
switch (entry->priv->justification) {
case GTK_JUSTIFY_RIGHT:
e_canvas_item_move_absolute(GNOME_CANVAS_ITEM(entry->priv->item),
alloc->width - xthick, ythick);
break;
case GTK_JUSTIFY_CENTER:
e_canvas_item_move_absolute(GNOME_CANVAS_ITEM(entry->priv->item),
alloc->width / 2, ythick);
break;
default:
e_canvas_item_move_absolute(GNOME_CANVAS_ITEM(entry->priv->item),
xthick, ythick);
break;
}
}
static void
canvas_size_request (GtkWidget *widget, GtkRequisition *requisition,
EEntry *entry)
{
int border;
g_return_if_fail (widget != NULL);
g_return_if_fail (GNOME_IS_CANVAS (widget));
g_return_if_fail (requisition != NULL);
if (entry->priv->draw_borders)
border = INNER_BORDER;
else
border = 0;
requisition->width = MIN_ENTRY_WIDTH + (widget->style->klass->xthickness + border) * 2;
requisition->height = (widget->style->font->ascent +
widget->style->font->descent +
(widget->style->klass->ythickness + border) * 2);
}
static gint
canvas_focus_in_event (GtkWidget *widget, GdkEventFocus *focus, EEntry *entry)
{
if (entry->priv->canvas->focused_item != GNOME_CANVAS_ITEM(entry->priv->item))
gnome_canvas_item_grab_focus(GNOME_CANVAS_ITEM(entry->priv->item));
return 0;
}
static void
e_entry_proxy_changed (EText *text, EEntry *entry)
{
if (e_entry_is_empty (entry)) {
e_entry_cancel_delayed_completion (entry);
e_entry_show_popup (entry, FALSE);
} else if (entry->priv->popup_is_visible)
e_entry_start_completion (entry);
else if (entry->priv->completion && entry->priv->completion_delay >= 0)
e_entry_start_delayed_completion (entry, entry->priv->completion_delay);
gtk_signal_emit (GTK_OBJECT (entry), e_entry_signals [E_ENTRY_CHANGED]);
}
static void
e_entry_proxy_activate (EText *text, EEntry *entry)
{
gtk_signal_emit (GTK_OBJECT (entry), e_entry_signals [E_ENTRY_ACTIVATE]);
}
static void
e_entry_init (GtkObject *object)
{
EEntry *entry = E_ENTRY (object);
GtkTable *gtk_table = GTK_TABLE (object);
entry->priv = g_new0 (EEntryPrivate, 1);
entry->priv->canvas = GNOME_CANVAS (e_canvas_new ());
gtk_signal_connect (GTK_OBJECT (entry->priv->canvas),
"size_allocate",
GTK_SIGNAL_FUNC (canvas_size_allocate),
entry);
gtk_signal_connect (GTK_OBJECT (entry->priv->canvas),
"size_request",
GTK_SIGNAL_FUNC (canvas_size_request),
entry);
gtk_signal_connect(GTK_OBJECT (entry->priv->canvas),
"focus_in_event",
GTK_SIGNAL_FUNC(canvas_focus_in_event),
entry);
entry->priv->draw_borders = TRUE;
entry->priv->item = E_TEXT(gnome_canvas_item_new(gnome_canvas_root (entry->priv->canvas),
e_text_get_type(),
"clip", TRUE,
"fill_clip_rectangle", TRUE,
"anchor", GTK_ANCHOR_NW,
"draw_borders", TRUE,
"draw_background", TRUE,
"max_lines", 1,
"editable", TRUE,
NULL));
entry->priv->justification = GTK_JUSTIFY_LEFT;
gtk_table_attach (gtk_table, GTK_WIDGET (entry->priv->canvas),
0, 1, 0, 1,
GTK_EXPAND | GTK_FILL | GTK_SHRINK,
GTK_EXPAND | GTK_FILL | GTK_SHRINK,
0, 0);
gtk_widget_show (GTK_WIDGET (entry->priv->canvas));
/*
* Proxy functions: we proxy the changed and activate signals
* from the item to outselves
*/
entry->priv->changed_proxy_tag = gtk_signal_connect (GTK_OBJECT (entry->priv->item),
"changed",
GTK_SIGNAL_FUNC (e_entry_proxy_changed),
entry);
entry->priv->activate_proxy_tag = gtk_signal_connect (GTK_OBJECT (entry->priv->item),
"activate",
GTK_SIGNAL_FUNC (e_entry_proxy_activate),
entry);
entry->priv->completion_delay = -1;
}
/**
* e_entry_construct
*
* Constructs the given EEntry.
*
**/
void
e_entry_construct (EEntry *entry)
{
/* Do nothing */
}
/**
* e_entry_new
*
* Creates a new EEntry.
*
* Returns: The new EEntry
**/
GtkWidget *
e_entry_new (void)
{
EEntry *entry;
entry = gtk_type_new (e_entry_get_type ());
e_entry_construct (entry);
return GTK_WIDGET (entry);
}
const gchar *
e_entry_get_text (EEntry *entry)
{
g_return_val_if_fail (entry != NULL && E_IS_ENTRY (entry), NULL);
return e_text_model_get_text (entry->priv->item->model);
}
void
e_entry_set_text (EEntry *entry, const gchar *txt)
{
g_return_if_fail (entry != NULL && E_IS_ENTRY (entry));
e_text_model_set_text (entry->priv->item->model, txt);
}
static void
e_entry_set_text_quiet (EEntry *entry, const gchar *txt)
{
g_return_if_fail (entry != NULL && E_IS_ENTRY (entry));
gtk_signal_handler_block (GTK_OBJECT (entry->priv->item), entry->priv->changed_proxy_tag);
e_entry_set_text (entry, txt);
gtk_signal_handler_unblock (GTK_OBJECT (entry->priv->item), entry->priv->changed_proxy_tag);
}
void
e_entry_set_editable (EEntry *entry, gboolean am_i_editable)
{
g_return_if_fail (entry != NULL && E_IS_ENTRY (entry));
gtk_object_set (GTK_OBJECT (entry->priv->item), "editable", am_i_editable, NULL);
}
gint
e_entry_get_position (EEntry *entry)
{
g_return_val_if_fail (entry != NULL && E_IS_ENTRY (entry), -1);
return entry->priv->item->selection_start;
}
void
e_entry_set_position (EEntry *entry, gint pos)
{
g_return_if_fail (entry != NULL && E_IS_ENTRY (entry));
if (pos < 0)
pos = 0;
else if (pos > e_text_model_get_text_length (entry->priv->item->model))
pos = e_text_model_get_text_length (entry->priv->item->model);
entry->priv->item->selection_start = entry->priv->item->selection_end = pos;
}
void
e_entry_select_region (EEntry *entry, gint pos1, gint pos2)
{
gint len;
g_return_if_fail (entry != NULL && E_IS_ENTRY (entry));
len = e_text_model_get_text_length (entry->priv->item->model);
pos1 = CLAMP (pos1, 0, len);
pos2 = CLAMP (pos2, 0, len);
entry->priv->item->selection_start = MIN (pos1, pos2);
entry->priv->item->selection_end = MAX (pos1, pos2);
}
/** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **/
/*** Completion-related code ***/
static gboolean
e_entry_is_empty (EEntry *entry)
{
const gchar *txt = e_entry_get_text (entry);
if (txt == NULL)
return TRUE;
while (*txt) {
if (!isspace ((gint) *txt))
return FALSE;
++txt;
}
return TRUE;
}
static void
e_entry_show_popup (EEntry *entry, gboolean visible)
{
GtkWidget *pop = entry->priv->completion_view_popup;
if (pop == NULL)
return;
if (visible) {
GtkAllocation *dim = &(GTK_WIDGET (entry)->allocation);
gint x, y;
/* Figure out where to put our popup. */
gdk_window_get_origin (GTK_WIDGET (entry)->window, &x, &y);
x += dim->x;
y += dim->height + dim->y;
gtk_widget_set_uposition (pop, x, y);
e_completion_view_set_width (E_COMPLETION_VIEW (entry->priv->completion_view), dim->width);
gtk_widget_show (pop);
gdk_keyboard_grab (GTK_WIDGET (entry)->window, TRUE, GDK_CURRENT_TIME);
gdk_pointer_grab (GTK_WIDGET (entry->priv->completion_view)->window, TRUE,
(GdkEventMask) GDK_BUTTON_PRESS_MASK | GDK_BUTTON_MOTION_MASK | GDK_BUTTON_RELEASE_MASK,
NULL, NULL, GDK_CURRENT_TIME);
} else {
gtk_widget_hide (pop);
gdk_keyboard_ungrab (GDK_CURRENT_TIME);
gdk_pointer_ungrab (GDK_CURRENT_TIME);
}
e_completion_view_set_editable (E_COMPLETION_VIEW (entry->priv->completion_view), visible);
entry->priv->popup_is_visible = visible;
}
static void
e_entry_refresh_popup (EEntry *entry)
{
if (entry->priv->popup_is_visible)
e_entry_show_popup (entry, TRUE);
}
static void
e_entry_start_completion (EEntry *entry)
{
if (entry->priv->completion == NULL)
return;
e_entry_cancel_delayed_completion (entry);
if (e_entry_is_empty (entry))
return;
if (entry->priv->completion)
e_completion_begin_search (entry->priv->completion,
e_entry_get_text (entry),
e_entry_get_position (entry),
0); /* No limit. Probably a bad idea. */
}
static gboolean
start_delayed_cb (gpointer user_data)
{
EEntry *entry = E_ENTRY (user_data);
entry->priv->completion_delay_tag = 0;
e_entry_start_completion (entry);
return FALSE;
}
static void
e_entry_start_delayed_completion (EEntry *entry, gint delay)
{
if (delay < 0)
return;
e_entry_cancel_delayed_completion (entry);
if (delay == 0)
e_entry_start_completion (entry);
else
entry->priv->completion_delay_tag = gtk_timeout_add (delay, start_delayed_cb, entry);
}
static void
e_entry_cancel_delayed_completion (EEntry *entry)
{
if (entry->priv->completion == NULL)
return;
e_completion_cancel_search (entry->priv->completion); /* just to be sure... */
if (entry->priv->completion_delay_tag) {
gtk_timeout_remove (entry->priv->completion_delay_tag);
entry->priv->completion_delay_tag = 0;
}
}
static void
nonempty_cb (ECompletionView *view, gpointer user_data)
{
EEntry *entry = E_ENTRY (user_data);
e_entry_show_popup (entry, TRUE);
}
static void
added_cb (ECompletionView *view, gpointer user_data)
{
EEntry *entry = E_ENTRY (user_data);
e_entry_refresh_popup (entry);
}
static void
full_cb (ECompletionView *view, gpointer user_data)
{
EEntry *entry = E_ENTRY (user_data);
e_entry_show_popup (entry, view->choice_count > 0);
}
static void
browse_cb (ECompletionView *view, const gchar *txt, gpointer user_data)
{
EEntry *entry = E_ENTRY (user_data);
if (txt == NULL) {
/* Requesting a completion. */
e_entry_start_completion (entry);
return;
}
if (entry->priv->pre_browse_text == NULL)
entry->priv->pre_browse_text = g_strdup (e_entry_get_text (entry));
/* If there is no other handler in place, echo the selected completion in
the entry. */
if (entry->priv->handler == NULL)
e_entry_set_text_quiet (entry, txt);
}
static void
unbrowse_cb (ECompletionView *view, gpointer user_data)
{
EEntry *entry = E_ENTRY (user_data);
if (entry->priv->pre_browse_text) {
if (entry->priv->handler == NULL)
e_entry_set_text_quiet (entry, entry->priv->pre_browse_text);
g_free (entry->priv->pre_browse_text);
entry->priv->pre_browse_text = NULL;
}
e_entry_show_popup (entry, FALSE);
}
static void
activate_cb (ECompletionView *view, const gchar *txt, gpointer extra_data, gpointer user_data)
{
EEntry *entry = E_ENTRY (user_data);
e_entry_cancel_delayed_completion (entry);
g_free (entry->priv->pre_browse_text);
entry->priv->pre_browse_text = NULL;
e_entry_show_popup (entry, FALSE);
if (entry->priv->handler)
entry->priv->handler (entry, txt, extra_data);
else
e_entry_set_text (entry, txt);
e_entry_cancel_delayed_completion (entry);
}
void
e_entry_enable_completion (EEntry *entry, ECompletion *completion)
{
g_return_if_fail (entry != NULL && E_IS_ENTRY (entry));
g_return_if_fail (completion != NULL && E_IS_COMPLETION (completion));
e_entry_enable_completion_full (entry, completion, -1, NULL);
}
static void
button_press_cb (GtkWidget *w, GdkEvent *ev, gpointer user_data)
{
EEntry *entry = E_ENTRY (user_data);
GtkWidget *child;
/* Bail out if our click happened inside of our widget. */
child = gtk_get_event_widget (ev);
if (child != w) {
while (child) {
if (child == w)
return;
child = child->parent;
}
}
e_entry_show_popup (entry, FALSE);
}
void
e_entry_enable_completion_full (EEntry *entry, ECompletion *completion, gint delay, EEntryCompletionHandler handler)
{
g_return_if_fail (entry != NULL && E_IS_ENTRY (entry));
g_return_if_fail (completion != NULL && E_IS_COMPLETION (completion));
/* For now, completion can't be changed mid-stream. */
g_return_if_fail (entry->priv->completion == NULL);
entry->priv->completion = completion;
gtk_object_ref (GTK_OBJECT (completion));
gtk_object_sink (GTK_OBJECT (completion));
entry->priv->completion_delay = delay;
entry->priv->handler = handler;
entry->priv->completion_view = e_completion_view_new (completion);
/* Make the up and down keys enable and disable completions. */
e_completion_view_set_complete_key (E_COMPLETION_VIEW (entry->priv->completion_view), GDK_Down);
e_completion_view_set_uncomplete_key (E_COMPLETION_VIEW (entry->priv->completion_view), GDK_Up);
gtk_signal_connect_after (GTK_OBJECT (entry->priv->completion_view),
"button_press_event",
GTK_SIGNAL_FUNC (button_press_cb),
entry);
entry->priv->nonempty_signal_id = gtk_signal_connect (GTK_OBJECT (entry->priv->completion_view),
"nonempty",
GTK_SIGNAL_FUNC (nonempty_cb),
entry);
entry->priv->added_signal_id = gtk_signal_connect (GTK_OBJECT (entry->priv->completion_view),
"added",
GTK_SIGNAL_FUNC (added_cb),
entry);
entry->priv->full_signal_id = gtk_signal_connect (GTK_OBJECT (entry->priv->completion_view),
"full",
GTK_SIGNAL_FUNC (full_cb),
entry);
entry->priv->browse_signal_id = gtk_signal_connect (GTK_OBJECT (entry->priv->completion_view),
"browse",
GTK_SIGNAL_FUNC (browse_cb),
entry);
entry->priv->unbrowse_signal_id = gtk_signal_connect (GTK_OBJECT (entry->priv->completion_view),
"unbrowse",
GTK_SIGNAL_FUNC (unbrowse_cb),
entry);
entry->priv->activate_signal_id = gtk_signal_connect (GTK_OBJECT (entry->priv->completion_view),
"activate",
GTK_SIGNAL_FUNC (activate_cb),
entry);
entry->priv->completion_view_popup = gtk_window_new (GTK_WINDOW_POPUP);
gtk_object_ref (GTK_OBJECT (entry->priv->completion_view_popup));
gtk_object_sink (GTK_OBJECT (entry->priv->completion_view_popup));
gtk_window_set_policy (GTK_WINDOW (entry->priv->completion_view_popup), FALSE, TRUE, FALSE);
gtk_container_add (GTK_CONTAINER (entry->priv->completion_view_popup), entry->priv->completion_view);
gtk_widget_show (entry->priv->completion_view);
e_completion_view_connect_keys (E_COMPLETION_VIEW (entry->priv->completion_view), GTK_WIDGET (entry->priv->canvas));
}
/** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **/
static void
et_get_arg (GtkObject *o, GtkArg *arg, guint arg_id)
{
EEntry *entry = E_ENTRY (o);
GtkObject *item = GTK_OBJECT (entry->priv->item);
switch (arg_id){
case ARG_MODEL:
gtk_object_get(item,
"model", >K_VALUE_OBJECT (*arg),
NULL);
break;
case ARG_EVENT_PROCESSOR:
gtk_object_get(item,
"event_processor", >K_VALUE_OBJECT (*arg),
NULL);
break;
case ARG_TEXT:
gtk_object_get(item,
"text", >K_VALUE_STRING (*arg),
NULL);
break;
case ARG_FONT_GDK:
gtk_object_get(item,
"font_gdk", >K_VALUE_BOXED (*arg),
NULL);
break;
case ARG_JUSTIFICATION:
gtk_object_get(item,
"justification", >K_VALUE_ENUM (*arg),
NULL);
break;
case ARG_FILL_COLOR_GDK:
gtk_object_get(item,
"fill_color_gdk", >K_VALUE_BOXED (*arg),
NULL);
break;
case ARG_FILL_COLOR_RGBA:
gtk_object_get(item,
"fill_color_rgba", >K_VALUE_UINT (*arg),
NULL);
break;
case ARG_FILL_STIPPLE:
gtk_object_get(item,
"fill_stiple", >K_VALUE_BOXED (*arg),
NULL);
break;
case ARG_EDITABLE:
gtk_object_get(item,
"editable", >K_VALUE_BOOL (*arg),
NULL);
break;
case ARG_USE_ELLIPSIS:
gtk_object_get(item,
"use_ellipsis", >K_VALUE_BOOL (*arg),
NULL);
break;
case ARG_ELLIPSIS:
gtk_object_get(item,
"ellipsis", >K_VALUE_STRING (*arg),
NULL);
break;
case ARG_LINE_WRAP:
gtk_object_get(item,
"line_wrap", >K_VALUE_BOOL (*arg),
NULL);
break;
case ARG_BREAK_CHARACTERS:
gtk_object_get(item,
"break_characters", >K_VALUE_STRING (*arg),
NULL);
break;
case ARG_MAX_LINES:
gtk_object_get(item,
"max_lines", >K_VALUE_INT (*arg),
NULL);
break;
case ARG_ALLOW_NEWLINES:
gtk_object_get(item,
"allow_newlines", >K_VALUE_BOOL (*arg),
NULL);
break;
case ARG_DRAW_BORDERS:
GTK_VALUE_BOOL (*arg) = entry->priv->draw_borders;
break;
case ARG_DRAW_BACKGROUND:
gtk_object_get (item,
"draw_background", >K_VALUE_BOOL (*arg),
NULL);
break;
case ARG_CURSOR_POS:
gtk_object_get (item,
"cursor_pos", >K_VALUE_INT (*arg),
NULL);
default:
arg->type = GTK_TYPE_INVALID;
break;
}
}
static void
et_set_arg (GtkObject *o, GtkArg *arg, guint arg_id)
{
EEntry *entry = E_ENTRY (o);
GtkObject *item = GTK_OBJECT (entry->priv->item);
GtkAnchorType anchor;
double width, height;
gint xthick;
gint ythick;
GtkWidget *widget = GTK_WIDGET(entry->priv->canvas);
switch (arg_id){
case ARG_MODEL:
gtk_object_set(item,
"model", GTK_VALUE_OBJECT (*arg),
NULL);
break;
case ARG_EVENT_PROCESSOR:
gtk_object_set(item,
"event_processor", GTK_VALUE_OBJECT (*arg),
NULL);
break;
case ARG_TEXT:
gtk_object_set(item,
"text", GTK_VALUE_STRING (*arg),
NULL);
break;
case ARG_FONT:
gtk_object_set(item,
"font", GTK_VALUE_STRING (*arg),
NULL);
break;
case ARG_FONTSET:
gtk_object_set(item,
"fontset", GTK_VALUE_STRING (*arg),
NULL);
break;
case ARG_FONT_GDK:
gtk_object_set(item,
"font_gdk", GTK_VALUE_BOXED (*arg),
NULL);
break;
case ARG_JUSTIFICATION:
entry->priv->justification = GTK_VALUE_ENUM (*arg);
gtk_object_get(item,
"clip_width", &width,
"clip_height", &height,
NULL);
if (entry->priv->draw_borders) {
xthick = 0;
ythick = 0;
} else {
xthick = widget->style->klass->xthickness;
ythick = widget->style->klass->ythickness;
}
switch (entry->priv->justification) {
case GTK_JUSTIFY_CENTER:
anchor = GTK_ANCHOR_N;
e_canvas_item_move_absolute(GNOME_CANVAS_ITEM(entry->priv->item), width / 2, ythick);
break;
case GTK_JUSTIFY_RIGHT:
anchor = GTK_ANCHOR_NE;
e_canvas_item_move_absolute(GNOME_CANVAS_ITEM(entry->priv->item), width - xthick, ythick);
break;
default:
anchor = GTK_ANCHOR_NW;
e_canvas_item_move_absolute(GNOME_CANVAS_ITEM(entry->priv->item), xthick, ythick);
break;
}
gtk_object_set(item,
"justification", entry->priv->justification,
"anchor", anchor,
NULL);
break;
case ARG_FILL_COLOR:
gtk_object_set(item,
"fill_color", GTK_VALUE_STRING (*arg),
NULL);
break;
case ARG_FILL_COLOR_GDK:
gtk_object_set(item,
"fill_color_gdk", GTK_VALUE_BOXED (*arg),
NULL);
break;
case ARG_FILL_COLOR_RGBA:
gtk_object_set(item,
"fill_color_rgba", GTK_VALUE_UINT (*arg),
NULL);
break;
case ARG_FILL_STIPPLE:
gtk_object_set(item,
"fill_stiple", GTK_VALUE_BOXED (*arg),
NULL);
break;
case ARG_EDITABLE:
gtk_object_set(item,
"editable", GTK_VALUE_BOOL (*arg),
NULL);
break;
case ARG_USE_ELLIPSIS:
gtk_object_set(item,
"use_ellipsis", GTK_VALUE_BOOL (*arg),
NULL);
break;
case ARG_ELLIPSIS:
gtk_object_set(item,
"ellipsis", GTK_VALUE_STRING (*arg),
NULL);
break;
case ARG_LINE_WRAP:
gtk_object_set(item,
"line_wrap", GTK_VALUE_BOOL (*arg),
NULL);
break;
case ARG_BREAK_CHARACTERS:
gtk_object_set(item,
"break_characters", GTK_VALUE_STRING (*arg),
NULL);
break;
case ARG_MAX_LINES:
gtk_object_set(item,
"max_lines", GTK_VALUE_INT (*arg),
NULL);
break;
case ARG_ALLOW_NEWLINES:
gtk_object_set(item,
"allow_newlines", GTK_VALUE_BOOL (*arg),
NULL);
break;
case ARG_DRAW_BORDERS: {
gboolean need_queue;
need_queue = (entry->priv->draw_borders ^ GTK_VALUE_BOOL (*arg));
gtk_object_set (item, "draw_borders", GTK_VALUE_BOOL (*arg), NULL);
entry->priv->draw_borders = GTK_VALUE_BOOL (*arg);
if (need_queue)
gtk_widget_queue_resize (GTK_WIDGET (entry));
break;
}
case ARG_CURSOR_POS:
gtk_object_set (item,
"cursor_pos", GTK_VALUE_INT (*arg), NULL);
break;
case ARG_DRAW_BACKGROUND:
gtk_object_set (item, "draw_background",
GTK_VALUE_BOOL (*arg), NULL);
break;
}
}
static void
e_entry_destroy (GtkObject *object)
{
EEntry *entry = E_ENTRY (object);
if (entry->priv->completion_delay_tag)
gtk_timeout_remove (entry->priv->completion_delay_tag);
if (entry->priv->completion)
gtk_object_unref (GTK_OBJECT (entry->priv->completion));
if (entry->priv->completion_view_popup)
gtk_widget_destroy (entry->priv->completion_view_popup);
g_free (entry->priv->pre_browse_text);
g_free (entry->priv);
entry->priv = NULL;
}
static void
e_entry_class_init (GtkObjectClass *object_class)
{
EEntryClass *klass = E_ENTRY_CLASS(object_class);
parent_class = gtk_type_class (PARENT_TYPE);
object_class->set_arg = et_set_arg;
object_class->get_arg = et_get_arg;
object_class->destroy = e_entry_destroy;
klass->changed = NULL;
klass->activate = NULL;
e_entry_signals[E_ENTRY_CHANGED] = gtk_signal_new ("changed",
GTK_RUN_LAST,
object_class->type,
GTK_SIGNAL_OFFSET (EEntryClass, changed),
gtk_marshal_NONE__NONE,
GTK_TYPE_NONE, 0);
e_entry_signals[E_ENTRY_ACTIVATE] = gtk_signal_new ("activate",
GTK_RUN_LAST,
object_class->type,
GTK_SIGNAL_OFFSET (EEntryClass, activate),
gtk_marshal_NONE__NONE,
GTK_TYPE_NONE, 0);
gtk_object_class_add_signals (object_class, e_entry_signals, E_ENTRY_LAST_SIGNAL);
gtk_object_add_arg_type ("EEntry::model",
GTK_TYPE_OBJECT, GTK_ARG_READWRITE, ARG_MODEL);
gtk_object_add_arg_type ("EEntry::event_processor",
GTK_TYPE_OBJECT, GTK_ARG_READWRITE, ARG_EVENT_PROCESSOR);
gtk_object_add_arg_type ("EEntry::text",
GTK_TYPE_STRING, GTK_ARG_READWRITE, ARG_TEXT);
gtk_object_add_arg_type ("EEntry::font",
GTK_TYPE_STRING, GTK_ARG_WRITABLE, ARG_FONT);
gtk_object_add_arg_type ("EEntry::fontset",
GTK_TYPE_STRING, GTK_ARG_WRITABLE, ARG_FONTSET);
gtk_object_add_arg_type ("EEntry::font_gdk",
GTK_TYPE_GDK_FONT, GTK_ARG_READWRITE, ARG_FONT_GDK);
gtk_object_add_arg_type ("EEntry::justification",
GTK_TYPE_JUSTIFICATION, GTK_ARG_READWRITE, ARG_JUSTIFICATION);
gtk_object_add_arg_type ("EEntry::fill_color",
GTK_TYPE_STRING, GTK_ARG_WRITABLE, ARG_FILL_COLOR);
gtk_object_add_arg_type ("EEntry::fill_color_gdk",
GTK_TYPE_GDK_COLOR, GTK_ARG_READWRITE, ARG_FILL_COLOR_GDK);
gtk_object_add_arg_type ("EEntry::fill_color_rgba",
GTK_TYPE_UINT, GTK_ARG_READWRITE, ARG_FILL_COLOR_RGBA);
gtk_object_add_arg_type ("EEntry::fill_stipple",
GTK_TYPE_GDK_WINDOW, GTK_ARG_READWRITE, ARG_FILL_STIPPLE);
gtk_object_add_arg_type ("EEntry::editable",
GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_EDITABLE);
gtk_object_add_arg_type ("EEntry::use_ellipsis",
GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_USE_ELLIPSIS);
gtk_object_add_arg_type ("EEntry::ellipsis",
GTK_TYPE_STRING, GTK_ARG_READWRITE, ARG_ELLIPSIS);
gtk_object_add_arg_type ("EEntry::line_wrap",
GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_LINE_WRAP);
gtk_object_add_arg_type ("EEntry::break_characters",
GTK_TYPE_STRING, GTK_ARG_READWRITE, ARG_BREAK_CHARACTERS);
gtk_object_add_arg_type ("EEntry::max_lines",
GTK_TYPE_INT, GTK_ARG_READWRITE, ARG_MAX_LINES);
gtk_object_add_arg_type ("EEntry::allow_newlines",
GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_ALLOW_NEWLINES);
gtk_object_add_arg_type ("EEntry::draw_borders",
GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_DRAW_BORDERS);
gtk_object_add_arg_type ("EEntry::draw_background",
GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_DRAW_BACKGROUND);
gtk_object_add_arg_type ("EEntry::cursor_pos",
GTK_TYPE_INT, GTK_ARG_READWRITE, ARG_CURSOR_POS);
}
E_MAKE_TYPE(e_entry, "EEntry", EEntry, e_entry_class_init, e_entry_init, PARENT_TYPE);
|