r5118 | eht16 | 2010-08-05 22:54:18 +0100 (Thu, 05 Aug 2010) | 1 line
[geany-mirror.git] / src / sciwrappers.c
blob3b00b55b12a0253122d9a2a122cb44919561a579
1 /*
2 * sciwrappers.c - this file is part of Geany, a fast and lightweight IDE
4 * Copyright 2005-2010 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
5 * Copyright 2006-2010 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 * $Id$
24 /** @file sciwrappers.h
25 * Wrapper functions for the Scintilla editor widget @c SCI_* messages.
26 * You should also check the http://scintilla.org documentation, as it is more detailed.
28 * To get Scintilla notifications, use the @c editor-notify @link signals Geany Signal @endlink.
30 * @note These functions were originally from the cssed project
31 * (http://cssed.sf.net, thanks).
32 * @see scintilla_send_message().
35 #include <string.h>
37 #include "geany.h"
39 #include "sciwrappers.h"
40 #include "utils.h"
42 #define SSM(s, m, w, l) scintilla_send_message(s, m, w, l)
45 /* line numbers visibility */
46 void sci_set_line_numbers(ScintillaObject *sci, gboolean set, gint extra_width)
48 if (set)
50 gchar tmp_str[15];
51 gint len = SSM(sci, SCI_GETLINECOUNT, 0, 0);
52 gint width;
54 g_snprintf(tmp_str, 15, "_%d", len);
55 width = sci_text_width(sci, STYLE_LINENUMBER, tmp_str);
56 if (extra_width)
58 g_snprintf(tmp_str, 15, "%d", extra_width);
59 width += sci_text_width(sci, STYLE_LINENUMBER, tmp_str);
61 SSM(sci, SCI_SETMARGINWIDTHN, 0, width);
62 SSM(sci, SCI_SETMARGINSENSITIVEN, 0, FALSE); /* use default behaviour */
64 else
66 SSM(sci, SCI_SETMARGINWIDTHN, 0, 0);
71 void sci_set_mark_long_lines(ScintillaObject *sci, gint type, gint column, const gchar *colour)
73 if (column == 0)
74 type = 2;
75 switch (type)
77 case 0:
79 SSM(sci, SCI_SETEDGEMODE, EDGE_LINE, 0);
80 break;
82 case 1:
84 SSM(sci, SCI_SETEDGEMODE, EDGE_BACKGROUND, 0);
85 break;
87 case 2:
89 SSM(sci, SCI_SETEDGEMODE, EDGE_NONE, 0);
90 return;
93 SSM(sci, SCI_SETEDGECOLUMN, column, 0);
94 SSM(sci, SCI_SETEDGECOLOUR, utils_strtod(colour, NULL, TRUE), 0);
98 /* symbol margin visibility */
99 void sci_set_symbol_margin(ScintillaObject *sci, gboolean set)
101 if (set)
103 SSM(sci, SCI_SETMARGINWIDTHN, 1, 16);
104 SSM(sci, SCI_SETMARGINSENSITIVEN, 1, TRUE);
106 else
108 SSM(sci, SCI_SETMARGINWIDTHN, 1, 0);
109 SSM(sci, SCI_SETMARGINSENSITIVEN, 1, FALSE);
114 /* folding margin visibility */
115 void sci_set_folding_margin_visible(ScintillaObject *sci, gboolean set)
117 if (set)
119 SSM(sci, SCI_SETMARGINWIDTHN, 2, 12);
120 SSM(sci, SCI_SETMARGINSENSITIVEN, 2, TRUE);
122 else
124 SSM(sci, SCI_SETMARGINSENSITIVEN, 2, FALSE);
125 SSM(sci, SCI_SETMARGINWIDTHN, 2, 0);
130 /* end of lines */
131 void sci_set_visible_eols(ScintillaObject *sci, gboolean set)
133 SSM(sci, SCI_SETVIEWEOL, set, 0);
137 void sci_set_visible_white_spaces(ScintillaObject *sci, gboolean set)
139 if (set)
140 SSM(sci, SCI_SETVIEWWS, SCWS_VISIBLEALWAYS, 0);
141 else
142 SSM(sci, SCI_SETVIEWWS, SCWS_INVISIBLE, 0);
146 void sci_set_lines_wrapped(ScintillaObject *sci, gboolean set)
148 if (set)
149 SSM(sci, SCI_SETWRAPMODE, SC_WRAP_WORD, 0);
150 else
151 SSM(sci, SCI_SETWRAPMODE, SC_WRAP_NONE, 0);
155 gint sci_get_eol_mode(ScintillaObject *sci)
157 return SSM(sci, SCI_GETEOLMODE, 0, 0);
161 void sci_set_eol_mode(ScintillaObject *sci, gint eolmode)
163 SSM(sci, SCI_SETEOLMODE, eolmode, 0);
167 void sci_convert_eols(ScintillaObject *sci, gint eolmode)
169 SSM(sci, SCI_CONVERTEOLS, eolmode, 0);
173 void sci_add_text(ScintillaObject *sci, const gchar *text)
175 if (text != NULL)
176 { /* if null text is passed scintilla will segfault */
177 SSM(sci, SCI_ADDTEXT, strlen(text), (sptr_t) text);
182 /** Sets all text.
183 * @param sci Scintilla widget.
184 * @param text Text. */
185 void sci_set_text(ScintillaObject *sci, const gchar *text)
187 if( text != NULL ){ /* if null text is passed to scintilla will segfault */
188 SSM(sci, SCI_SETTEXT, 0, (sptr_t) text);
193 gboolean sci_can_undo(ScintillaObject *sci)
195 return SSM(sci, SCI_CANUNDO, 0, 0);
199 gboolean sci_can_redo(ScintillaObject *sci)
201 return SSM(sci, SCI_CANREDO, 0, 0);
205 void sci_undo(ScintillaObject *sci)
207 if (sci_can_undo(sci))
208 SSM(sci, SCI_UNDO, 0, 0);
212 void sci_redo(ScintillaObject *sci)
214 if (sci_can_redo(sci))
215 SSM(sci, SCI_REDO, 0, 0);
219 /** Begins grouping a set of edits together as one Undo action.
220 * You must call sci_end_undo_action() after making your edits.
221 * @param sci Scintilla @c GtkWidget. */
222 void sci_start_undo_action(ScintillaObject *sci)
224 SSM(sci, SCI_BEGINUNDOACTION, 0, 0);
228 /** Ends grouping a set of edits together as one Undo action.
229 * @param sci Scintilla @c GtkWidget.
230 * @see sci_start_undo_action(). */
231 void sci_end_undo_action(ScintillaObject *sci)
233 SSM(sci, SCI_ENDUNDOACTION, 0, 0);
237 void sci_set_undo_collection(ScintillaObject *sci, gboolean set)
239 SSM(sci, SCI_SETUNDOCOLLECTION, set, 0);
243 void sci_empty_undo_buffer(ScintillaObject *sci)
245 SSM(sci, SCI_EMPTYUNDOBUFFER, 0, 0);
249 gboolean sci_is_modified(ScintillaObject *sci)
251 return (SSM(sci, SCI_GETMODIFY, 0, 0) != 0);
255 void sci_zoom_in(ScintillaObject *sci)
257 SSM(sci, SCI_ZOOMIN, 0, 0);
261 void sci_zoom_out(ScintillaObject *sci)
263 SSM(sci, SCI_ZOOMOUT, 0, 0);
267 void sci_zoom_off(ScintillaObject *sci)
269 SSM(sci, SCI_SETZOOM, 0, 0);
273 gint sci_get_zoom(ScintillaObject *sci)
275 return SSM(sci, SCI_GETZOOM, 0, 0);
279 /** Sets a line marker.
280 * @param sci Scintilla widget.
281 * @param line_number Line number.
282 * @param marker Marker number. */
283 void sci_set_marker_at_line(ScintillaObject *sci, gint line_number, gint marker)
285 SSM(sci, SCI_MARKERADD, line_number, marker);
289 /** Deletes a line marker.
290 * @param sci Scintilla widget.
291 * @param line_number Line number.
292 * @param marker Marker number. */
293 void sci_delete_marker_at_line(ScintillaObject *sci, gint line_number, gint marker)
295 SSM(sci, SCI_MARKERDELETE, line_number, marker);
299 /** Checks if a line has a marker set.
300 * @param sci Scintilla widget.
301 * @param line Line number.
302 * @param marker Marker number.
303 * @return Whether it's set. */
304 gboolean sci_is_marker_set_at_line(ScintillaObject *sci, gint line, gint marker)
306 gint state;
308 state = SSM(sci, SCI_MARKERGET, line, 0);
309 return (state & (1 << marker));
313 void sci_toggle_marker_at_line(ScintillaObject *sci, gint line, gint marker)
315 gboolean set = sci_is_marker_set_at_line(sci, line, marker);
317 if (!set)
318 sci_set_marker_at_line(sci, line, marker);
319 else
320 sci_delete_marker_at_line(sci, line, marker);
324 /* Returns the line number of the next marker that matches marker_mask, or -1.
325 * marker_mask is a bitor of 1 << marker_index. (See MarkerHandleSet::MarkValue()).
326 * Note: If there is a marker on the line, it returns the same line. */
327 gint sci_marker_next(ScintillaObject *sci, gint line, gint marker_mask, gboolean wrap)
329 gint marker_line;
331 marker_line = SSM(sci, SCI_MARKERNEXT, line, marker_mask);
332 if (wrap && marker_line == -1)
333 marker_line = SSM(sci, SCI_MARKERNEXT, 0, marker_mask);
334 return marker_line;
338 /* Returns the line number of the previous marker that matches marker_mask, or -1.
339 * marker_mask is a bitor of 1 << marker_index. (See MarkerHandleSet::MarkValue()).
340 * Note: If there is a marker on the line, it returns the same line. */
341 gint sci_marker_previous(ScintillaObject *sci, gint line, gint marker_mask, gboolean wrap)
343 gint marker_line;
345 marker_line = SSM(sci, SCI_MARKERPREVIOUS, line, marker_mask);
346 if (wrap && marker_line == -1)
348 gint len = sci_get_length(sci);
349 gint last_line = sci_get_line_from_position(sci, len - 1);
351 marker_line = SSM(sci, SCI_MARKERPREVIOUS, last_line, marker_mask);
353 return marker_line;
357 /** Gets the line number from @a position.
358 * @param sci Scintilla widget.
359 * @param position Position. */
360 gint sci_get_line_from_position(ScintillaObject *sci, gint position)
362 return SSM(sci, SCI_LINEFROMPOSITION, position, 0);
366 /** Gets the column number relative to the start of the line that @a position is on.
367 * @param sci Scintilla widget.
368 * @param position Position. */
369 gint sci_get_col_from_position(ScintillaObject *sci, gint position)
371 return SSM(sci, SCI_GETCOLUMN, position, 0);
375 /** Gets the position for the start of @a line.
376 * @param sci Scintilla widget.
377 * @param line Line.
378 * @return Position. */
379 gint sci_get_position_from_line(ScintillaObject *sci, gint line)
381 return SSM(sci, SCI_POSITIONFROMLINE, line, 0);
385 /** Gets the cursor position.
386 * @param sci Scintilla widget.
387 * @return Position. */
388 gint sci_get_current_position(ScintillaObject *sci)
390 return SSM(sci, SCI_GETCURRENTPOS, 0, 0);
394 /** Sets the cursor position.
395 * @param sci Scintilla widget.
396 * @param position Position.
397 * @param scroll_to_caret Whether to scroll the cursor in view. */
398 void sci_set_current_position(ScintillaObject *sci, gint position, gboolean scroll_to_caret)
400 if (scroll_to_caret)
401 SSM(sci, SCI_GOTOPOS, position, 0);
402 else
404 SSM(sci, SCI_SETCURRENTPOS, position, 0);
405 SSM(sci, SCI_SETANCHOR, position, 0); /* to avoid creation of a selection */
407 SSM(sci, SCI_CHOOSECARETX, 0, 0);
411 /* Set the cursor line without scrolling the view.
412 * Use sci_goto_line() to also scroll. */
413 void sci_set_current_line(ScintillaObject *sci, gint line)
415 gint pos = sci_get_position_from_line(sci, line);
416 sci_set_current_position(sci, pos, FALSE);
420 /** Gets the total number of lines.
421 * @param sci Scintilla widget. */
422 gint sci_get_line_count(ScintillaObject *sci)
424 return SSM(sci, SCI_GETLINECOUNT, 0, 0);
428 /** Sets the selection start position.
429 * @param sci Scintilla widget.
430 * @param position Position. */
431 void sci_set_selection_start(ScintillaObject *sci, gint position)
433 SSM(sci, SCI_SETSELECTIONSTART, position, 0);
437 /** Sets the selection end position.
438 * @param sci Scintilla widget.
439 * @param position Position. */
440 void sci_set_selection_end(ScintillaObject *sci, gint position)
442 SSM(sci, SCI_SETSELECTIONEND, position, 0);
446 void sci_set_selection(ScintillaObject *sci, gint anchorPos, gint currentPos)
448 SSM(sci, SCI_SETSEL, anchorPos, currentPos);
452 gint sci_get_line_end_position(ScintillaObject *sci, gint line)
454 return SSM(sci, SCI_GETLINEENDPOSITION, line, 0);
458 void sci_cut(ScintillaObject *sci)
460 SSM(sci, SCI_CUT, 0, 0);
464 void sci_copy(ScintillaObject *sci)
466 SSM(sci, SCI_COPY, 0, 0);
470 void sci_paste(ScintillaObject *sci)
472 SSM(sci, SCI_PASTE, 0, 0);
476 void sci_clear(ScintillaObject *sci)
478 SSM(sci, SCI_CLEAR, 0, 0);
482 /** Gets the selection start position.
483 * @param sci Scintilla widget.
484 * @return Position. */
485 gint sci_get_selection_start(ScintillaObject *sci)
487 return SSM(sci, SCI_GETSELECTIONSTART, 0, 0);
491 /** Gets the selection end position.
492 * @param sci Scintilla widget.
493 * @return Position. */
494 gint sci_get_selection_end(ScintillaObject *sci)
496 return SSM(sci, SCI_GETSELECTIONEND, 0, 0);
500 /** Replaces selection.
501 * @param sci Scintilla widget.
502 * @param text Text. */
503 void sci_replace_sel(ScintillaObject *sci, const gchar *text)
505 SSM(sci, SCI_REPLACESEL, 0, (sptr_t) text);
509 /** Gets the length of all text.
510 * @param sci Scintilla widget.
511 * @return Length. */
512 gint sci_get_length(ScintillaObject *sci)
514 return SSM(sci, SCI_GETLENGTH, 0, 0);
518 gint sci_get_lexer(ScintillaObject *sci)
520 return SSM(sci, SCI_GETLEXER, 0, 0);
524 /** Gets line length.
525 * @param sci Scintilla widget.
526 * @param line Line number.
527 * @return Length. */
528 gint sci_get_line_length(ScintillaObject *sci, gint line)
530 return SSM(sci, SCI_LINELENGTH, line, 0);
534 /* safe way to read Scintilla string into new memory.
535 * works with any string buffer messages that follow the Windows message convention. */
536 gchar *sci_get_string(ScintillaObject *sci, gint msg, gulong wParam)
538 gint size = SSM(sci, msg, wParam, 0) + 1;
539 gchar *str = g_malloc(size);
541 SSM(sci, msg, wParam, (sptr_t)str);
542 str[size - 1] = '\0'; /* ensure termination, needed for SCI_GETLINE */
543 return str;
547 /** Gets line contents.
548 * @param sci Scintilla widget.
549 * @param line_num Line number.
550 * @return A @c NULL-terminated copy of the line text. */
551 gchar *sci_get_line(ScintillaObject *sci, gint line_num)
553 return sci_get_string(sci, SCI_GETLINE, line_num);
557 /** Gets all text.
558 * @deprecated sci_get_text is deprecated and should not be used in newly-written code.
559 * Use sci_get_contents() instead.
561 * @param sci Scintilla widget.
562 * @param len Length of @a text buffer, usually sci_get_length() + 1.
563 * @param text Text buffer; must be allocated @a len + 1 bytes for null-termination. */
564 void sci_get_text(ScintillaObject *sci, gint len, gchar *text)
566 SSM(sci, SCI_GETTEXT, len, (sptr_t) text);
570 /** Gets all text inside a given text length.
571 * @param sci Scintilla widget.
572 * @param len Length of the text to retrieve from the start of the document,
573 * usually sci_get_length() + 1.
574 * @return A copy of the text. Should be freed when no longer needed.
576 * @since 0.17
578 gchar *sci_get_contents(ScintillaObject *sci, gint len)
580 gchar *text = g_malloc(len);
581 SSM(sci, SCI_GETTEXT, len, (sptr_t) text);
582 return text;
586 /** Gets selected text.
587 * @deprecated sci_get_selected_text is deprecated and should not be used in newly-written code.
588 * Use sci_get_selection_contents() instead.
590 * @param sci Scintilla widget.
591 * @param text Text buffer; must be allocated sci_get_selected_text_length() + 1 bytes
592 * for null-termination. */
593 void sci_get_selected_text(ScintillaObject *sci, gchar *text)
595 SSM(sci, SCI_GETSELTEXT, 0, (sptr_t) text);
599 /** Gets selected text.
600 * @param sci Scintilla widget.
602 * @return The selected text. Should be freed when no longer needed.
604 * @since 0.17
606 gchar *sci_get_selection_contents(ScintillaObject *sci)
608 return sci_get_string(sci, SCI_GETSELTEXT, 0);
612 /** Gets selected text length.
613 * @param sci Scintilla widget.
614 * @return Length. */
615 gint sci_get_selected_text_length(ScintillaObject *sci)
617 return SSM(sci, SCI_GETSELTEXT, 0, 0);
621 gint sci_get_position_from_xy(ScintillaObject *sci, gint x, gint y, gboolean nearby)
623 /* for nearby return -1 if there is no character near to the x,y point. */
624 return SSM(sci, (nearby) ? SCI_POSITIONFROMPOINTCLOSE : SCI_POSITIONFROMPOINT, x, y);
628 /** Checks if a line is visible (folding may have hidden it).
629 * @param sci Scintilla widget.
630 * @param line Line number.
631 * @return Whether @a line will be drawn on the screen. */
632 gboolean sci_get_line_is_visible(ScintillaObject *sci, gint line)
634 return SSM(sci, SCI_GETLINEVISIBLE, line, 0);
638 /** Makes @a line visible (folding may have hidden it).
639 * @param sci Scintilla widget.
640 * @param line Line number. */
641 void sci_ensure_line_is_visible(ScintillaObject *sci, gint line)
643 SSM(sci, SCI_ENSUREVISIBLE, line, 0);
647 gint sci_get_fold_level(ScintillaObject *sci, gint line)
649 return SSM(sci, SCI_GETFOLDLEVEL, line, 0);
653 /* Get the line number of the fold point before start_line, or -1 if there isn't one */
654 gint sci_get_fold_parent(ScintillaObject *sci, gint start_line)
656 return SSM(sci, SCI_GETFOLDPARENT, start_line, 0);
660 void sci_toggle_fold(ScintillaObject *sci, gint line)
662 SSM(sci, SCI_TOGGLEFOLD, line, 1);
666 gboolean sci_get_fold_expanded(ScintillaObject *sci, gint line)
668 return SSM(sci, SCI_GETFOLDEXPANDED, line, 0);
672 void sci_colourise(ScintillaObject *sci, gint start, gint end)
674 SSM(sci, SCI_COLOURISE, start, end);
678 void sci_clear_all(ScintillaObject *sci)
680 SSM(sci, SCI_CLEARALL, 0, 0);
684 gint sci_get_end_styled(ScintillaObject *sci)
686 return SSM(sci, SCI_GETENDSTYLED, 0, 0);
690 void sci_set_tab_width(ScintillaObject *sci, gint width)
692 SSM(sci, SCI_SETTABWIDTH, width, 0);
696 /** Gets display tab width (this is not indent width, see GeanyIndentPrefs).
697 * @param sci Scintilla widget.
698 * @return Width.
700 * @since 0.15
702 gint sci_get_tab_width(ScintillaObject *sci)
704 return SSM(sci, SCI_GETTABWIDTH, 0, 0);
708 /** Gets a character.
709 * @param sci Scintilla widget.
710 * @param pos Position.
711 * @return Char. */
712 gchar sci_get_char_at(ScintillaObject *sci, gint pos)
714 return (gchar) SSM(sci, SCI_GETCHARAT, pos, 0);
718 void sci_set_savepoint(ScintillaObject *sci)
720 SSM(sci, SCI_SETSAVEPOINT, 0, 0);
724 void sci_set_indentation_guides(ScintillaObject *sci, gint mode)
726 SSM(sci, SCI_SETINDENTATIONGUIDES, mode, 0);
730 void sci_use_popup(ScintillaObject *sci, gboolean enable)
732 SSM(sci, SCI_USEPOPUP, enable, 0);
736 /** Checks if there's a selection.
737 * @param sci Scintilla widget.
738 * @return Whether a selection is present.
740 * @since 0.15
742 gboolean sci_has_selection(ScintillaObject *sci)
744 if (SSM(sci, SCI_GETSELECTIONEND, 0, 0) - SSM(sci, SCI_GETSELECTIONSTART, 0, 0))
745 return TRUE;
746 else
747 return FALSE;
751 void sci_goto_pos(ScintillaObject *sci, gint pos, gboolean unfold)
753 if (unfold) SSM(sci, SCI_ENSUREVISIBLE, SSM(sci, SCI_LINEFROMPOSITION, pos, 0), 0);
754 SSM(sci, SCI_GOTOPOS, pos, 0);
758 void sci_set_search_anchor(ScintillaObject *sci)
760 SSM(sci, SCI_SEARCHANCHOR, 0, 0);
764 /* removes a selection if pos < 0 */
765 void sci_set_anchor(ScintillaObject *sci, gint pos)
767 if (pos < 0)
768 pos = sci_get_current_position(sci);
770 SSM(sci, SCI_SETANCHOR, pos, 0);
774 /** Scrolls the cursor in view.
775 * @param sci Scintilla widget. */
776 void sci_scroll_caret(ScintillaObject *sci)
778 SSM(sci, SCI_SCROLLCARET, 0, 0);
782 void sci_scroll_lines(ScintillaObject *sci, gint lines)
784 SSM(sci, SCI_LINESCROLL, 0, lines);
788 void sci_scroll_columns(ScintillaObject *sci, gint columns)
790 SSM(sci, SCI_LINESCROLL, columns, 0);
794 gint sci_search_next(ScintillaObject *sci, gint flags, const gchar *text)
796 return SSM(sci, SCI_SEARCHNEXT, flags, (sptr_t) text);
800 gint sci_search_prev(ScintillaObject *sci, gint flags, const gchar *text)
802 return SSM(sci, SCI_SEARCHPREV, flags, (sptr_t) text);
806 /** Finds text in the document.
807 * The @a ttf argument should be a pointer to a Sci_TextToFind structure which contains
808 * the text to find and the range in which the text should be searched.
810 * Please refer to the Scintilla documentation for a more detailed description.
812 * @param sci Scintilla widget.
813 * @param flags Bitmask of Scintilla search flags (@c SCFIND_*, see Scintilla documentation).
814 * @param ttf Pointer to a TextToFind structure which contains the text to find and the range.
815 * @return The position of the start of the found text if it succeeds, otherwise @c -1.
816 * The @c chrgText.cpMin and @c chrgText.cpMax members of @c TextToFind are filled in
817 * with the start and end positions of the found text.
819 gint sci_find_text(ScintillaObject *sci, gint flags, struct Sci_TextToFind *ttf)
821 return SSM(sci, SCI_FINDTEXT, flags, (long) ttf);
825 void sci_set_font(ScintillaObject *sci, gint style, const gchar *font, gint size)
827 SSM(sci, SCI_STYLESETFONT, style, (sptr_t) font);
828 SSM(sci, SCI_STYLESETSIZE, style, size);
832 /** Jumps to the specified line in the document.
833 * If @a unfold is set and @a line is hidden by a fold, it is unfolded
834 * first to ensure it is visible.
835 * @param sci Scintilla widget.
836 * @param line Line.
837 * @param unfold Whether to unfold first.
839 void sci_goto_line(ScintillaObject *sci, gint line, gboolean unfold)
841 if (unfold) SSM(sci, SCI_ENSUREVISIBLE, line, 0);
842 SSM(sci, SCI_GOTOLINE, line, 0);
846 void sci_marker_delete_all(ScintillaObject *sci, gint marker)
848 SSM(sci, SCI_MARKERDELETEALL, marker, 0);
852 /** Gets style ID at @a position.
853 * @param sci Scintilla widget.
854 * @param position Position.
855 * @return Style ID. */
856 gint sci_get_style_at(ScintillaObject *sci, gint position)
858 return SSM(sci, SCI_GETSTYLEAT, position, 0);
862 void sci_set_codepage(ScintillaObject *sci, gint cp)
864 g_return_if_fail(cp == 0 || cp == SC_CP_UTF8);
865 SSM(sci, SCI_SETCODEPAGE, cp, 0);
869 void sci_assign_cmdkey(ScintillaObject *sci, gint key, gint command)
871 SSM(sci, SCI_ASSIGNCMDKEY, key, command);
875 void sci_clear_cmdkey(ScintillaObject *sci, gint key)
877 SSM(sci, SCI_CLEARCMDKEY, key, 0);
881 /** Gets text between @a start and @a end.
882 * @deprecated sci_get_text_range is deprecated and should not be used in newly-written code.
883 * Use sci_get_contents_range() instead.
885 * @param sci Scintilla widget.
886 * @param start Start.
887 * @param end End.
888 * @param text Text will be zero terminated and must be allocated (end - start + 1) bytes. */
889 void sci_get_text_range(ScintillaObject *sci, gint start, gint end, gchar *text)
891 struct Sci_TextRange tr;
892 tr.chrg.cpMin = start;
893 tr.chrg.cpMax = end;
894 tr.lpstrText = text;
895 SSM(sci, SCI_GETTEXTRANGE, 0, (long) &tr);
899 /** Gets text between @a start and @a end.
901 * @param sci Scintilla widget.
902 * @param start Start.
903 * @param end End.
904 * @return The text inside the given range. Should be freed when no longer needed.
906 * @since 0.17
908 gchar *sci_get_contents_range(ScintillaObject *sci, gint start, gint end)
910 gchar *text = g_malloc((end - start) + 1);
911 sci_get_text_range(sci, start, end, text);
912 return text;
916 void sci_line_duplicate(ScintillaObject *sci)
918 SSM(sci, SCI_LINEDUPLICATE, 0, 0);
922 void sci_selection_duplicate(ScintillaObject *sci)
924 SSM(sci, SCI_SELECTIONDUPLICATE, 0, 0);
928 /** Inserts text.
929 * @param sci Scintilla widget.
930 * @param pos Position, or -1 for current.
931 * @param text Text. */
932 void sci_insert_text(ScintillaObject *sci, gint pos, const gchar *text)
934 SSM(sci, SCI_INSERTTEXT, pos, (sptr_t) text);
938 void sci_target_from_selection(ScintillaObject *sci)
940 SSM(sci, SCI_TARGETFROMSELECTION, 0, 0);
944 void sci_set_target_start(ScintillaObject *sci, gint start)
946 SSM(sci, SCI_SETTARGETSTART, start, 0);
950 void sci_set_target_end(ScintillaObject *sci, gint end)
952 SSM(sci, SCI_SETTARGETEND, end, 0);
956 gint sci_replace_target(ScintillaObject *sci, const gchar *text, gboolean regex)
958 return SSM(sci, (regex) ? SCI_REPLACETARGETRE : SCI_REPLACETARGET, (uptr_t) -1, (sptr_t) text);
962 void sci_set_keywords(ScintillaObject *sci, gint k, const gchar *text)
964 SSM(sci, SCI_SETKEYWORDS, k, (sptr_t) text);
968 void sci_set_readonly(ScintillaObject *sci, gboolean readonly)
970 SSM(sci, SCI_SETREADONLY, readonly, 0);
974 /** Sends Scintilla commands without any parameters.
975 * @param sci The Scintilla @c GtkWidget.
976 * @param cmd @c SCI_COMMAND.
977 * @see http://scintilla.org for the documentation.
979 * @since 0.16
981 void sci_send_command(ScintillaObject *sci, gint cmd)
983 SSM(sci, cmd, 0, 0);
987 /** Gets current line number.
988 * @param sci Scintilla widget.
989 * @return Line number. */
990 gint sci_get_current_line(ScintillaObject *sci)
992 return SSM(sci, SCI_LINEFROMPOSITION, SSM(sci, SCI_GETCURRENTPOS, 0, 0), 0);
996 /* Get number of lines partially or fully selected.
997 * Returns 1 if there is a partial selection on the same line.
998 * Returns 2 if a whole line is selected including the line break char(s). */
999 gint sci_get_lines_selected(ScintillaObject *sci)
1001 gint start = SSM(sci, SCI_GETSELECTIONSTART, 0, 0);
1002 gint end = SSM(sci, SCI_GETSELECTIONEND, 0, 0);
1004 if (start == end)
1005 return 0; /* no selection */
1007 return SSM(sci, SCI_LINEFROMPOSITION, end, 0) - SSM(sci, SCI_LINEFROMPOSITION, start, 0) + 1;
1011 gint sci_get_first_visible_line(ScintillaObject *sci)
1013 return SSM(sci, SCI_GETFIRSTVISIBLELINE, 0, 0);
1018 * Sets the current indicator. This is necessary to define an indicator for a range of text or
1019 * clearing indicators for a range of text.
1021 * @param sci Scintilla widget.
1022 * @param indic The indicator number to set.
1024 * @see sci_indicator_clear
1026 * @since 0.16
1028 void sci_indicator_set(ScintillaObject *sci, gint indic)
1030 SSM(sci, SCI_SETINDICATORCURRENT, indic, 0);
1034 void sci_indicator_fill(ScintillaObject *sci, gint pos, gint len)
1036 SSM(sci, SCI_INDICATORFILLRANGE, pos, len);
1041 * Clears the currently set indicator from a range of text.
1042 * Starting at @a pos, @a len characters long.
1043 * In order to make this function properly, you need to set the current indicator before with
1044 * @ref sci_indicator_set().
1046 * @param sci Scintilla widget.
1047 * @param pos Starting position.
1048 * @param len Length.
1050 * @since 0.16
1052 void sci_indicator_clear(ScintillaObject *sci, gint pos, gint len)
1054 SSM(sci, SCI_INDICATORCLEARRANGE, pos, len);
1058 void sci_select_all(ScintillaObject *sci)
1060 SSM(sci, SCI_SELECTALL, 0, 0);
1064 gint sci_get_line_indent_position(ScintillaObject *sci, gint line)
1066 return SSM(sci, SCI_GETLINEINDENTPOSITION, line, 0);
1070 void sci_set_autoc_max_height(ScintillaObject *sci, gint val)
1072 SSM(sci, SCI_AUTOCSETMAXHEIGHT, val, 0);
1076 /** Finds a matching brace at @a pos.
1077 * @param sci Scintilla widget.
1078 * @param pos Position.
1079 * @return Matching brace position.
1081 * @since 0.15
1083 gint sci_find_matching_brace(ScintillaObject *sci, gint pos)
1085 return SSM(sci, SCI_BRACEMATCH, pos, 0);
1089 gint sci_get_overtype(ScintillaObject *sci)
1091 return SSM(sci, SCI_GETOVERTYPE, 0, 0);
1095 void sci_set_tab_indents(ScintillaObject *sci, gboolean set)
1097 SSM(sci, SCI_SETTABINDENTS, set, 0);
1101 void sci_set_use_tabs(ScintillaObject *sci, gboolean set)
1103 SSM(sci, SCI_SETUSETABS, set, 0);
1107 gint sci_get_pos_at_line_sel_start(ScintillaObject *sci, gint line)
1109 return SSM(sci, SCI_GETLINESELSTARTPOSITION, line, 0);
1113 gint sci_get_pos_at_line_sel_end(ScintillaObject *sci, gint line)
1115 return SSM(sci, SCI_GETLINESELENDPOSITION, line, 0);
1119 /** Gets selection mode.
1120 * @param sci Scintilla widget.
1121 * @return Selection mode. */
1122 gint sci_get_selection_mode(ScintillaObject *sci)
1124 return SSM(sci, SCI_GETSELECTIONMODE, 0, 0);
1128 /** Sets selection mode.
1129 * @param sci Scintilla widget.
1130 * @param mode Mode. */
1131 void sci_set_selection_mode(ScintillaObject *sci, gint mode)
1133 SSM(sci, SCI_SETSELECTIONMODE, mode, 0);
1137 void sci_set_scrollbar_mode(ScintillaObject *sci, gboolean visible)
1139 SSM(sci, SCI_SETHSCROLLBAR, visible, 0);
1140 SSM(sci, SCI_SETVSCROLLBAR, visible, 0);
1144 /** Sets the indentation of a line.
1145 * @param sci Scintilla widget.
1146 * @param line Line to indent.
1147 * @param indent Indentation width.
1149 * @since 0.19
1151 void sci_set_line_indentation(ScintillaObject *sci, gint line, gint indent)
1153 SSM(sci, SCI_SETLINEINDENTATION, line, indent);
1157 /** Gets the indentation width of a line.
1158 * @param sci Scintilla widget.
1159 * @param line Line to get the indentation from.
1160 * @return Indentation width.
1162 * @since 0.19
1164 gint sci_get_line_indentation(ScintillaObject *sci, gint line)
1166 return SSM(sci, SCI_GETLINEINDENTATION, line, 0);
1170 void sci_set_caret_policy_x(ScintillaObject *sci, gint policy, gint slop)
1172 SSM(sci, SCI_SETXCARETPOLICY, policy, slop);
1176 void sci_set_caret_policy_y(ScintillaObject *sci, gint policy, gint slop)
1178 SSM(sci, SCI_SETYCARETPOLICY, policy, slop);
1182 void sci_set_scroll_stop_at_last_line(ScintillaObject *sci, gboolean set)
1184 SSM(sci, SCI_SETENDATLASTLINE, set, 0);
1188 void sci_cancel(ScintillaObject *sci)
1190 SSM(sci, SCI_CANCEL, 0, 0);
1194 gint sci_get_target_end(ScintillaObject *sci)
1196 return SSM(sci, SCI_GETTARGETEND, 0, 0);
1200 gint sci_get_position_after(ScintillaObject *sci, gint start)
1202 return SSM(sci, SCI_POSITIONAFTER, start, 0);
1206 void sci_lines_split(ScintillaObject *sci, gint pixelWidth)
1208 SSM(sci, SCI_LINESSPLIT, pixelWidth, 0);
1212 void sci_lines_join(ScintillaObject *sci)
1214 SSM(sci, SCI_LINESJOIN, 0, 0);
1218 gint sci_text_width(ScintillaObject *sci, gint styleNumber, const gchar *text)
1220 return SSM(sci, SCI_TEXTWIDTH, styleNumber, (sptr_t) text);