[go: up one dir, main page]

File: text.c

package info (click to toggle)
linpopup 0.9.3.pre4-1
  • links: PTS
  • area: main
  • in suites: slink
  • size: 440 kB
  • ctags: 151
  • sloc: ansic: 2,102; sh: 197; makefile: 171
file content (139 lines) | stat: -rw-r--r-- 3,658 bytes parent folder | download
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
/* LinPopUp - A Linux enhanced port of Winpopup, running over Samba.
 * By Jean-Marc Jacquet <littleigloo@chez.com> 
 * Copyright (C) 1998 Little Igloo Org  http://www.chez.com/littleigloo
 *
 *
 * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include <gtk/gtk.h>
#include <gdk/gdk.h>
#include <gdk/gdkkeysyms.h>
#include <gtk/gtkstyle.h>
#include "protos.h"



void
clear_text (GtkWidget * text)
{
  gtk_text_freeze (GTK_TEXT (text));
  gtk_text_backward_delete (GTK_TEXT (text), gtk_text_get_length (GTK_TEXT (text)));
  gtk_text_thaw (GTK_TEXT (text));
}



void
realize_text (GtkWidget * text, gpointer data)
{
  gtk_text_freeze (GTK_TEXT (text));
  gtk_text_insert (GTK_TEXT (text), NULL, &text->style->black, NULL, data, -1);
  gtk_text_thaw (GTK_TEXT (text));
}





void
text_copy_to_clipboard (GtkWidget * widget, GtkWidget * this_window)
{
  GtkWidget *this_text;
  this_text = gtk_object_get_data (GTK_OBJECT (this_window), "text");
#ifdef GTK_1_1
  gtk_editable_copy_clipboard (GTK_EDITABLE (this_text));
#else
  gtk_editable_copy_clipboard (GTK_EDITABLE (this_text), 0);
#endif
}



void
text_cut_to_clipboard (GtkWidget * widget, GtkWidget * this_window)
{
  GtkWidget *this_text;
  this_text = gtk_object_get_data (GTK_OBJECT (this_window), "text");
#ifdef GTK_1_1
  gtk_editable_cut_clipboard (GTK_EDITABLE (this_text));
#else
  gtk_editable_cut_clipboard (GTK_EDITABLE (this_text), 0);
#endif
}



void
text_paste_from_clipboard (GtkWidget * widget, GtkWidget * this_window)
{
  GtkWidget *this_text;
  this_text = gtk_object_get_data (GTK_OBJECT (this_window), "text");
#ifdef GTK_1_1
  gtk_editable_paste_clipboard (GTK_EDITABLE (this_text));
#else
  gtk_editable_paste_clipboard (GTK_EDITABLE (this_text), 0);
#endif
}


void
text_select_all (GtkWidget * widget, GtkWidget * this_window)
{
  GtkWidget *this_text;
  this_text = gtk_object_get_data (GTK_OBJECT (this_window), "text");
  gtk_editable_select_region (GTK_EDITABLE (this_text), 0, gtk_text_get_length (GTK_TEXT (this_text)));
}





GtkWidget *
create_text (GtkWidget * vbox)
{
  GtkWidget *table;
  GtkWidget *text;
  GtkWidget *hscrollbar;
  GtkWidget *vscrollbar;
  static GdkColor text_bg =
  {0, 0xffec, 0xffec, 0xffec};


  table = gtk_table_new (2, 2, FALSE);
  text = gtk_text_new (NULL, NULL);

  gtk_table_attach (GTK_TABLE (table), text, 0, 1, 0, 1,
		    GTK_FILL | GTK_EXPAND,
		    GTK_FILL | GTK_EXPAND | GTK_SHRINK, 0, 0);
  gtk_widget_show (text);

  hscrollbar = gtk_hscrollbar_new (GTK_TEXT (text)->hadj);
  gtk_table_attach (GTK_TABLE (table), hscrollbar, 0, 1, 1, 2,
		    GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
  gtk_widget_show (hscrollbar);

  vscrollbar = gtk_vscrollbar_new (GTK_TEXT (text)->vadj);
  gtk_table_attach (GTK_TABLE (table), vscrollbar, 1, 2, 0, 1,
		    GTK_FILL, GTK_EXPAND | GTK_FILL | GTK_SHRINK, 0, 0);
  gtk_widget_show (vscrollbar);

  gtk_box_pack_start (GTK_BOX (vbox), table, TRUE, TRUE, 0);
  gtk_widget_show (table);

  text->style->base[0] = text_bg;

  return text;
}