| 1 |
aloha |
1.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 |
aloha |
1.4 |
* $Id: buffer.c,v 1.3 2006/11/25 09:10:43 aloha Exp $ |
| 28 |
aloha |
1.1 |
*/ |
| 29 |
|
|
#include"shiki.h" |
| 30 |
aloha |
1.2 |
|
| 31 |
aloha |
1.3 |
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 |
aloha |
1.4 |
|
| 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 |
|
|
} |