Develop and Download Open Source Software

Browse CVS Repository

Contents of /shiki/shiki/buffer.c

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.6 - (show annotations) (download) (as text)
Sun Nov 26 18:41:43 2006 UTC (17 years, 4 months ago) by aloha
Branch: MAIN
Changes since 1.5: +9 -1 lines
File MIME type: text/x-csrc
add some API

1 /* vim: set encoding=utf8:
2 *
3 * buffer.c
4 *
5 * This file is part of Shiki.
6 *
7 * Copyright(C)2006 WAKATSUKI toshihiro
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * SOFTWARE.
26 *
27 * $Id: buffer.c,v 1.5 2006/11/26 15:34:16 aloha Exp $
28 */
29 #include"shiki.h"
30
31 gchar *Shiki_buffer_substring(gint start, gint end) {
32 if(start >= end)
33 return NULL;
34 else {
35 GtkTextIter s, e;
36 gtk_text_buffer_get_iter_at_offset(Shiki_CURRENT_TEXT_BUFFER, &s, start);
37 gtk_text_buffer_get_iter_at_offset(Shiki_CURRENT_TEXT_BUFFER, &e, end);
38
39 return gtk_text_buffer_get_text(Shiki_CURRENT_TEXT_BUFFER, &s, &e, FALSE);
40 }
41 }
42
43 void Shiki_delete_region(gint start, gint end) {
44 if(start >= end)
45 return;
46 else {
47 GtkTextIter s, e;
48 gtk_text_buffer_get_iter_at_offset(Shiki_CURRENT_TEXT_BUFFER, &s, start);
49 gtk_text_buffer_get_iter_at_offset(Shiki_CURRENT_TEXT_BUFFER, &e, end);
50
51 return gtk_text_buffer_delete(Shiki_CURRENT_TEXT_BUFFER, &s, &e);
52 }
53 }
54
55 gint Shiki_point() {
56 GtkTextIter p;
57 gtk_text_buffer_get_iter_at_mark(Shiki_CURRENT_TEXT_BUFFER,&p, gtk_text_buffer_get_insert(Shiki_CURRENT_TEXT_BUFFER));
58 return gtk_text_iter_get_offset(&p);
59 }
60
61 gint Shiki_point_max() {
62 GtkTextIter p;
63 gtk_text_buffer_get_end_iter(Shiki_CURRENT_TEXT_BUFFER, &p);
64 return gtk_text_iter_get_offset(&p);
65 }
66
67 gint Shiki_point_min() {
68 return 0;
69 }
70
71 void Shiki_goto_char(gint offset) {
72 GtkTextIter p;
73 gtk_text_buffer_get_iter_at_offset(Shiki_CURRENT_TEXT_BUFFER, &p, offset);
74 gtk_text_buffer_place_cursor(Shiki_CURRENT_TEXT_BUFFER, &p);
75 }
76
77 void Shiki_forward_char() {
78 GtkTextIter p;
79 gtk_text_buffer_get_iter_at_mark(Shiki_CURRENT_TEXT_BUFFER,&p, gtk_text_buffer_get_insert(Shiki_CURRENT_TEXT_BUFFER));
80 gtk_text_iter_forward_char(&p);
81 gtk_text_buffer_place_cursor(Shiki_CURRENT_TEXT_BUFFER, &p);
82 }
83
84 void Shiki_backward_char() {
85 GtkTextIter p;
86 gtk_text_buffer_get_iter_at_mark(Shiki_CURRENT_TEXT_BUFFER,&p, gtk_text_buffer_get_insert(Shiki_CURRENT_TEXT_BUFFER));
87 gtk_text_iter_backward_char(&p);
88 gtk_text_buffer_place_cursor(Shiki_CURRENT_TEXT_BUFFER, &p);
89 }
90
91 void Shiki_goto_line(gint line) {
92 GtkTextIter p;
93 gtk_text_buffer_get_iter_at_line(Shiki_CURRENT_TEXT_BUFFER, &p, line);
94 gtk_text_buffer_place_cursor(Shiki_CURRENT_TEXT_BUFFER, &p);
95 }
96
97 void Shiki_goto_bol() {
98 GtkTextIter p;
99 gtk_text_buffer_get_iter_at_mark(Shiki_CURRENT_TEXT_BUFFER,&p, gtk_text_buffer_get_insert(Shiki_CURRENT_TEXT_BUFFER));
100 gtk_text_buffer_get_iter_at_line_offset(Shiki_CURRENT_TEXT_BUFFER, &p, gtk_text_iter_get_line(&p), 0);
101 gtk_text_buffer_place_cursor(Shiki_CURRENT_TEXT_BUFFER, &p);
102 }
103
104 void Shiki_goto_eol() {
105 GtkTextIter p;
106 gtk_text_buffer_get_iter_at_mark(Shiki_CURRENT_TEXT_BUFFER,&p, gtk_text_buffer_get_insert(Shiki_CURRENT_TEXT_BUFFER));
107 gtk_text_iter_forward_to_line_end(&p);
108 gtk_text_iter_backward_char(&p);
109 gtk_text_buffer_place_cursor(Shiki_CURRENT_TEXT_BUFFER, &p);
110 }
111
112 static gint compBuffer(gconstpointer a, gconstpointer b) {
113 return ((ShikiBuffer *)a)->text_buffer == b ? 0 : b - a;
114 }
115
116 static GList *get_ShikiBufferListElement_By_GtkTextBuffer(GtkTextBuffer *b) {
117 return g_list_find_custom(Shiki_EDITOR_BUFFER_LIST, b, compBuffer);
118 }
119
120 const char *Shiki_buffer_name(GtkTextBuffer *buffer) {
121 GList *l = get_ShikiBufferListElement_By_GtkTextBuffer(buffer);
122 if(l)
123 return ((ShikiBuffer *)(l->data))->name;
124 else
125 return NULL;
126 }
127
128 gboolean Shiki_deleted_buffer_p(GtkTextBuffer *buffer) {
129 GList *l = get_ShikiBufferListElement_By_GtkTextBuffer(buffer);
130 if(l)
131 return FALSE;
132 else
133 return TRUE;
134 }
135
136 GtkTextBuffer *Shiki_get_next_buffer(GtkTextBuffer *buffer) {
137 GList *l = get_ShikiBufferListElement_By_GtkTextBuffer(buffer);
138 if(l && l->next)
139 return ((ShikiBuffer *)(l->next->data))->text_buffer;
140 else
141 return NULL;
142 }
143
144 GtkTextBuffer *Shiki_get_previous_buffer(GtkTextBuffer *buffer) {
145 GList *l = get_ShikiBufferListElement_By_GtkTextBuffer(buffer);
146 if(l && l->prev)
147 return ((ShikiBuffer *)(l->prev->data))->text_buffer;
148 else
149 return NULL;
150 }
151
152 ScmObj Shiki_buffer_list() {
153 GList *l;
154 GtkTextBuffer *b;
155 ScmObj bl = SCM_NIL;
156
157 for(l = Shiki_EDITOR_BUFFER_LIST; l != NULL; l = l->next) {
158 b= ((ShikiBuffer *)(l->data))->text_buffer;
159 bl = Scm_Cons(SHIKI_BUFFER_BOX(g_object_ref(b)), bl);
160 }
161 return bl;
162 }

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26