rewrite_reflow: Remove no longer used `sci_lines_split` function that wrapped SCI_LIN...
[geany-mirror.git] / src / sciwrappers.c
blob627b184d702888aaad49b1994d4506f0db9fd967
1 /*
2 * sciwrappers.c - this file is part of Geany, a fast and lightweight IDE
4 * Copyright 2005-2012 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
5 * Copyright 2006-2012 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 along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 /** @file sciwrappers.h
23 * Wrapper functions for the Scintilla editor widget @c SCI_* messages.
24 * You should also check the http://scintilla.org documentation, as it is more detailed.
26 * To get Scintilla notifications, use the
27 * @link pluginsignals.c @c "editor-notify" signal @endlink.
29 * @note These functions were originally from the cssed project
30 * (http://cssed.sf.net, thanks).
31 * @see scintilla_send_message().
34 #include <string.h>
36 #include "geany.h"
38 #include "sciwrappers.h"
39 #include "utils.h"
41 #define SSM(s, m, w, l) scintilla_send_message(s, m, w, l)
44 /* line numbers visibility */
45 void sci_set_line_numbers(ScintillaObject *sci, gboolean set, gint extra_width)
47 if (set)
49 gchar tmp_str[15];
50 gint len = (gint) SSM(sci, SCI_GETLINECOUNT, 0, 0);
51 gint width;
53 g_snprintf(tmp_str, 15, "_%d", len);
54 width = sci_text_width(sci, STYLE_LINENUMBER, tmp_str);
55 if (extra_width)
57 g_snprintf(tmp_str, 15, "%d", extra_width);
58 width += sci_text_width(sci, STYLE_LINENUMBER, tmp_str);
60 SSM(sci, SCI_SETMARGINWIDTHN, 0, width);
61 SSM(sci, SCI_SETMARGINSENSITIVEN, 0, FALSE); /* use default behaviour */
63 else
65 SSM(sci, SCI_SETMARGINWIDTHN, 0, 0);
70 void sci_set_mark_long_lines(ScintillaObject *sci, gint type, gint column, const gchar *colour)
72 glong colour_val = utils_strtod(colour, NULL, TRUE); /* Scintilla uses a "long" value */
74 if (column == 0)
75 type = 2;
76 switch (type)
78 case 0:
80 SSM(sci, SCI_SETEDGEMODE, EDGE_LINE, 0);
81 break;
83 case 1:
85 SSM(sci, SCI_SETEDGEMODE, EDGE_BACKGROUND, 0);
86 break;
88 case 2:
90 SSM(sci, SCI_SETEDGEMODE, EDGE_NONE, 0);
91 return;
94 SSM(sci, SCI_SETEDGECOLUMN, (uptr_t) column, 0);
95 SSM(sci, SCI_SETEDGECOLOUR, (uptr_t) colour_val, 0);
99 /* symbol margin visibility */
100 void sci_set_symbol_margin(ScintillaObject *sci, gboolean set)
102 if (set)
104 SSM(sci, SCI_SETMARGINWIDTHN, 1, 16);
105 SSM(sci, SCI_SETMARGINSENSITIVEN, 1, TRUE);
107 else
109 SSM(sci, SCI_SETMARGINWIDTHN, 1, 0);
110 SSM(sci, SCI_SETMARGINSENSITIVEN, 1, FALSE);
115 /* folding margin visibility */
116 void sci_set_folding_margin_visible(ScintillaObject *sci, gboolean set)
118 if (set)
120 SSM(sci, SCI_SETMARGINWIDTHN, 2, 12);
121 SSM(sci, SCI_SETMARGINSENSITIVEN, 2, TRUE);
123 else
125 SSM(sci, SCI_SETMARGINSENSITIVEN, 2, FALSE);
126 SSM(sci, SCI_SETMARGINWIDTHN, 2, 0);
131 /* end of lines */
132 void sci_set_visible_eols(ScintillaObject *sci, gboolean set)
134 SSM(sci, SCI_SETVIEWEOL, set != FALSE, 0);
138 void sci_set_visible_white_spaces(ScintillaObject *sci, gboolean set)
140 if (set)
141 SSM(sci, SCI_SETVIEWWS, SCWS_VISIBLEALWAYS, 0);
142 else
143 SSM(sci, SCI_SETVIEWWS, SCWS_INVISIBLE, 0);
147 void sci_set_lines_wrapped(ScintillaObject *sci, gboolean set)
149 if (set)
150 SSM(sci, SCI_SETWRAPMODE, SC_WRAP_WORD, 0);
151 else
152 SSM(sci, SCI_SETWRAPMODE, SC_WRAP_NONE, 0);
156 gint sci_get_eol_mode(ScintillaObject *sci)
158 return (gint) SSM(sci, SCI_GETEOLMODE, 0, 0);
162 void sci_set_eol_mode(ScintillaObject *sci, gint eolmode)
164 SSM(sci, SCI_SETEOLMODE, (uptr_t) eolmode, 0);
168 void sci_convert_eols(ScintillaObject *sci, gint eolmode)
170 SSM(sci, SCI_CONVERTEOLS, (uptr_t) eolmode, 0);
174 void sci_add_text(ScintillaObject *sci, const gchar *text)
176 if (text != NULL)
177 { /* if null text is passed scintilla will segfault */
178 SSM(sci, SCI_ADDTEXT, strlen(text), (sptr_t) text);
183 /** Sets all text.
184 * @param sci Scintilla widget.
185 * @param text Text. */
186 void sci_set_text(ScintillaObject *sci, const gchar *text)
188 if( text != NULL ){ /* if null text is passed to scintilla will segfault */
189 SSM(sci, SCI_SETTEXT, 0, (sptr_t) text);
194 gboolean sci_can_undo(ScintillaObject *sci)
196 return SSM(sci, SCI_CANUNDO, 0, 0) != FALSE;
200 gboolean sci_can_redo(ScintillaObject *sci)
202 return SSM(sci, SCI_CANREDO, 0, 0) != FALSE;
206 void sci_undo(ScintillaObject *sci)
208 if (sci_can_undo(sci))
209 SSM(sci, SCI_UNDO, 0, 0);
213 void sci_redo(ScintillaObject *sci)
215 if (sci_can_redo(sci))
216 SSM(sci, SCI_REDO, 0, 0);
220 /** Begins grouping a set of edits together as one Undo action.
221 * You must call sci_end_undo_action() after making your edits.
222 * @param sci Scintilla @c GtkWidget. */
223 void sci_start_undo_action(ScintillaObject *sci)
225 SSM(sci, SCI_BEGINUNDOACTION, 0, 0);
229 /** Ends grouping a set of edits together as one Undo action.
230 * @param sci Scintilla @c GtkWidget.
231 * @see sci_start_undo_action(). */
232 void sci_end_undo_action(ScintillaObject *sci)
234 SSM(sci, SCI_ENDUNDOACTION, 0, 0);
238 void sci_set_undo_collection(ScintillaObject *sci, gboolean set)
240 SSM(sci, SCI_SETUNDOCOLLECTION, set != FALSE, 0);
244 void sci_empty_undo_buffer(ScintillaObject *sci)
246 SSM(sci, SCI_EMPTYUNDOBUFFER, 0, 0);
250 gboolean sci_is_modified(ScintillaObject *sci)
252 return (SSM(sci, SCI_GETMODIFY, 0, 0) != 0);
256 void sci_zoom_in(ScintillaObject *sci)
258 SSM(sci, SCI_ZOOMIN, 0, 0);
262 void sci_zoom_out(ScintillaObject *sci)
264 SSM(sci, SCI_ZOOMOUT, 0, 0);
268 void sci_zoom_off(ScintillaObject *sci)
270 SSM(sci, SCI_SETZOOM, 0, 0);
274 gint sci_get_zoom(ScintillaObject *sci)
276 return (gint) SSM(sci, SCI_GETZOOM, 0, 0);
280 /** Sets a line marker.
281 * @param sci Scintilla widget.
282 * @param line_number Line number.
283 * @param marker Marker number. */
284 void sci_set_marker_at_line(ScintillaObject *sci, gint line_number, gint marker)
286 SSM(sci, SCI_MARKERADD, (uptr_t) line_number, marker);
290 /** Deletes a line marker.
291 * @param sci Scintilla widget.
292 * @param line_number Line number.
293 * @param marker Marker number. */
294 void sci_delete_marker_at_line(ScintillaObject *sci, gint line_number, gint marker)
296 SSM(sci, SCI_MARKERDELETE, (uptr_t) line_number, marker);
300 /** Checks if a line has a marker set.
301 * @param sci Scintilla widget.
302 * @param line Line number.
303 * @param marker Marker number.
304 * @return Whether it's set. */
305 gboolean sci_is_marker_set_at_line(ScintillaObject *sci, gint line, gint marker)
307 gint state;
309 state = (gint) SSM(sci, SCI_MARKERGET, (uptr_t) line, 0);
310 return (state & (1 << marker));
314 void sci_toggle_marker_at_line(ScintillaObject *sci, gint line, gint marker)
316 gboolean set = sci_is_marker_set_at_line(sci, line, marker);
318 if (!set)
319 sci_set_marker_at_line(sci, line, marker);
320 else
321 sci_delete_marker_at_line(sci, line, marker);
325 /* Returns the line number of the next marker that matches marker_mask, or -1.
326 * marker_mask is a bitor of 1 << marker_index. (See MarkerHandleSet::MarkValue()).
327 * Note: If there is a marker on the line, it returns the same line. */
328 gint sci_marker_next(ScintillaObject *sci, gint line, gint marker_mask, gboolean wrap)
330 gint marker_line;
332 marker_line = (gint) SSM(sci, SCI_MARKERNEXT, (uptr_t) line, marker_mask);
333 if (wrap && marker_line == -1)
334 marker_line = (gint) SSM(sci, SCI_MARKERNEXT, 0, marker_mask);
335 return marker_line;
339 /* Returns the line number of the previous marker that matches marker_mask, or -1.
340 * marker_mask is a bitor of 1 << marker_index. (See MarkerHandleSet::MarkValue()).
341 * Note: If there is a marker on the line, it returns the same line. */
342 gint sci_marker_previous(ScintillaObject *sci, gint line, gint marker_mask, gboolean wrap)
344 gint marker_line;
346 marker_line = (gint) SSM(sci, SCI_MARKERPREVIOUS, (uptr_t) line, marker_mask);
347 if (wrap && marker_line == -1)
349 gint len = sci_get_length(sci);
350 gint last_line = sci_get_line_from_position(sci, len - 1);
352 marker_line = (gint) SSM(sci, SCI_MARKERPREVIOUS, (uptr_t) last_line, marker_mask);
354 return marker_line;
358 /** Gets the line number from @a position.
359 * @param sci Scintilla widget.
360 * @param position Position.
361 * @return The line. */
362 gint sci_get_line_from_position(ScintillaObject *sci, gint position)
364 return (gint) SSM(sci, SCI_LINEFROMPOSITION, (uptr_t) position, 0);
368 /** Gets the column number relative to the start of the line that @a position is on.
369 * @param sci Scintilla widget.
370 * @param position Position.
371 * @return The column. */
372 gint sci_get_col_from_position(ScintillaObject *sci, gint position)
374 return (gint) SSM(sci, SCI_GETCOLUMN, (uptr_t) position, 0);
378 gint sci_get_position_from_col(ScintillaObject *sci, gint line, gint col)
380 return (gint) SSM(sci, SCI_FINDCOLUMN, line, col);
384 /** Gets the position for the start of @a line.
385 * @param sci Scintilla widget.
386 * @param line Line.
387 * @return Position. */
388 gint sci_get_position_from_line(ScintillaObject *sci, gint line)
390 return (gint) SSM(sci, SCI_POSITIONFROMLINE, (uptr_t) line, 0);
394 /** Gets the cursor position.
395 * @param sci Scintilla widget.
396 * @return Position. */
397 gint sci_get_current_position(ScintillaObject *sci)
399 return (gint) SSM(sci, SCI_GETCURRENTPOS, 0, 0);
403 /** Sets the cursor position.
404 * @param sci Scintilla widget.
405 * @param position Position.
406 * @param scroll_to_caret Whether to scroll the cursor in view. */
407 void sci_set_current_position(ScintillaObject *sci, gint position, gboolean scroll_to_caret)
409 if (scroll_to_caret)
410 SSM(sci, SCI_GOTOPOS, (uptr_t) position, 0);
411 else
413 SSM(sci, SCI_SETCURRENTPOS, (uptr_t) position, 0);
414 SSM(sci, SCI_SETANCHOR, (uptr_t) position, 0); /* to avoid creation of a selection */
416 SSM(sci, SCI_CHOOSECARETX, 0, 0);
420 /* Set the cursor line without scrolling the view.
421 * Use sci_goto_line() to also scroll. */
422 void sci_set_current_line(ScintillaObject *sci, gint line)
424 gint pos = sci_get_position_from_line(sci, line);
425 sci_set_current_position(sci, pos, FALSE);
429 /** Gets the total number of lines.
430 * @param sci Scintilla widget.
431 * @return The line count. */
432 gint sci_get_line_count(ScintillaObject *sci)
434 return (gint) SSM(sci, SCI_GETLINECOUNT, 0, 0);
438 /** Sets the selection start position.
439 * @param sci Scintilla widget.
440 * @param position Position. */
441 void sci_set_selection_start(ScintillaObject *sci, gint position)
443 SSM(sci, SCI_SETSELECTIONSTART, (uptr_t) position, 0);
447 /** Sets the selection end position.
448 * @param sci Scintilla widget.
449 * @param position Position. */
450 void sci_set_selection_end(ScintillaObject *sci, gint position)
452 SSM(sci, SCI_SETSELECTIONEND, (uptr_t) position, 0);
456 void sci_set_selection(ScintillaObject *sci, gint anchorPos, gint currentPos)
458 SSM(sci, SCI_SETSEL, (uptr_t) anchorPos, currentPos);
462 /** Gets the position at the end of a line
463 * @param sci Scintilla widget.
464 * @param line Line.
465 * @return The position at the end of the line. */
466 gint sci_get_line_end_position(ScintillaObject *sci, gint line)
468 return (gint) SSM(sci, SCI_GETLINEENDPOSITION, (uptr_t) line, 0);
472 void sci_cut(ScintillaObject *sci)
474 SSM(sci, SCI_CUT, 0, 0);
478 void sci_copy(ScintillaObject *sci)
480 SSM(sci, SCI_COPY, 0, 0);
484 void sci_paste(ScintillaObject *sci)
486 SSM(sci, SCI_PASTE, 0, 0);
490 void sci_clear(ScintillaObject *sci)
492 SSM(sci, SCI_CLEAR, 0, 0);
496 /** Gets the selection start position.
497 * @param sci Scintilla widget.
498 * @return Position. */
499 gint sci_get_selection_start(ScintillaObject *sci)
501 return (gint) SSM(sci, SCI_GETSELECTIONSTART, 0, 0);
505 /** Gets the selection end position.
506 * @param sci Scintilla widget.
507 * @return Position. */
508 gint sci_get_selection_end(ScintillaObject *sci)
510 return (gint) SSM(sci, SCI_GETSELECTIONEND, 0, 0);
514 /** Replaces selection.
515 * @param sci Scintilla widget.
516 * @param text Text. */
517 void sci_replace_sel(ScintillaObject *sci, const gchar *text)
519 SSM(sci, SCI_REPLACESEL, 0, (sptr_t) text);
523 /** Gets the length of all text.
524 * @param sci Scintilla widget.
525 * @return Length. */
526 gint sci_get_length(ScintillaObject *sci)
528 return (gint) SSM(sci, SCI_GETLENGTH, 0, 0);
532 /** Gets the currently used lexer
533 * @param sci Scintilla widget.
534 * @returns The lexer ID
536 gint sci_get_lexer(ScintillaObject *sci)
538 return (gint) SSM(sci, SCI_GETLEXER, 0, 0);
542 void sci_set_lexer(ScintillaObject *sci, guint lexer_id)
544 gint old = sci_get_lexer(sci);
546 SSM(sci, SCI_SETLEXER, lexer_id, 0);
548 if (old != (gint)lexer_id)
549 SSM(sci, SCI_CLEARDOCUMENTSTYLE, 0, 0);
553 /** Gets line length.
554 * @param sci Scintilla widget.
555 * @param line Line number.
556 * @return Length. */
557 gint sci_get_line_length(ScintillaObject *sci, gint line)
559 return (gint) SSM(sci, SCI_LINELENGTH, (uptr_t) line, 0);
563 /* safe way to read Scintilla string into new memory.
564 * works with any string buffer messages that follow the Windows message convention. */
565 gchar *sci_get_string(ScintillaObject *sci, guint msg, gulong wParam)
567 gint size = (gint) SSM(sci, msg, wParam, 0);
568 gchar *str = g_malloc(size + 1);
570 SSM(sci, msg, wParam, (sptr_t) str);
571 str[size] = '\0'; /* ensure termination, needed for SCI_GETLINE */
572 return str;
576 /** Gets line contents.
577 * @param sci Scintilla widget.
578 * @param line_num Line number.
579 * @return A @c NULL-terminated copy of the line text. */
580 gchar *sci_get_line(ScintillaObject *sci, gint line_num)
582 return sci_get_string(sci, SCI_GETLINE, (gulong) line_num);
586 /** Gets all text.
587 * @deprecated sci_get_text is deprecated and should not be used in newly-written code.
588 * Use sci_get_contents() instead.
590 * @param sci Scintilla widget.
591 * @param len Length of @a text buffer, usually sci_get_length() + 1.
592 * @param text Text buffer; must be allocated @a len + 1 bytes for null-termination. */
593 void sci_get_text(ScintillaObject *sci, gint len, gchar *text)
595 SSM(sci, SCI_GETTEXT, (uptr_t) len, (sptr_t) text);
599 /** Allocates and fills a buffer with text from the start of the document.
600 * @param sci Scintilla widget.
601 * @param buffer_len Buffer length to allocate, including the terminating
602 * null char, e.g. sci_get_length() + 1. Alternatively use @c -1 to get all
603 * text (since Geany 1.23).
604 * @return A copy of the text. Should be freed when no longer needed.
606 * @since 1.23 (0.17)
608 gchar *sci_get_contents(ScintillaObject *sci, gint buffer_len)
610 gchar *text;
612 if (buffer_len < 0)
613 buffer_len = sci_get_length(sci) + 1;
615 text = g_malloc(buffer_len);
616 SSM(sci, SCI_GETTEXT, (uptr_t) buffer_len, (sptr_t) text);
617 return text;
621 /** Gets selected text.
622 * @deprecated sci_get_selected_text is deprecated and should not be used in newly-written code.
623 * Use sci_get_selection_contents() instead.
625 * @param sci Scintilla widget.
626 * @param text Text buffer; must be allocated sci_get_selected_text_length() + 1 bytes
627 * for null-termination. */
628 void sci_get_selected_text(ScintillaObject *sci, gchar *text)
630 SSM(sci, SCI_GETSELTEXT, 0, (sptr_t) text);
634 /** Gets selected text.
635 * @param sci Scintilla widget.
637 * @return The selected text. Should be freed when no longer needed.
639 * @since 0.17
641 gchar *sci_get_selection_contents(ScintillaObject *sci)
643 return sci_get_string(sci, SCI_GETSELTEXT, 0);
647 /** Gets selected text length.
648 * @param sci Scintilla widget.
649 * @return Length. */
650 gint sci_get_selected_text_length(ScintillaObject *sci)
652 return (gint) SSM(sci, SCI_GETSELTEXT, 0, 0);
656 gint sci_get_position_from_xy(ScintillaObject *sci, gint x, gint y, gboolean nearby)
658 /* for nearby return -1 if there is no character near to the x,y point. */
659 return (gint) SSM(sci, (nearby) ? SCI_POSITIONFROMPOINTCLOSE : SCI_POSITIONFROMPOINT, (uptr_t) x, y);
663 /** Checks if a line is visible (folding may have hidden it).
664 * @param sci Scintilla widget.
665 * @param line Line number.
666 * @return Whether @a line will be drawn on the screen. */
667 gboolean sci_get_line_is_visible(ScintillaObject *sci, gint line)
669 return SSM(sci, SCI_GETLINEVISIBLE, (uptr_t) line, 0) != FALSE;
673 /** Makes @a line visible (folding may have hidden it).
674 * @param sci Scintilla widget.
675 * @param line Line number. */
676 void sci_ensure_line_is_visible(ScintillaObject *sci, gint line)
678 SSM(sci, SCI_ENSUREVISIBLE, (uptr_t) line, 0);
682 gint sci_get_fold_level(ScintillaObject *sci, gint line)
684 return (gint) SSM(sci, SCI_GETFOLDLEVEL, (uptr_t) line, 0);
688 /* Get the line number of the fold point before start_line, or -1 if there isn't one */
689 gint sci_get_fold_parent(ScintillaObject *sci, gint start_line)
691 return (gint) SSM(sci, SCI_GETFOLDPARENT, (uptr_t) start_line, 0);
695 void sci_toggle_fold(ScintillaObject *sci, gint line)
697 SSM(sci, SCI_TOGGLEFOLD, (uptr_t) line, 0);
701 gboolean sci_get_fold_expanded(ScintillaObject *sci, gint line)
703 return SSM(sci, SCI_GETFOLDEXPANDED, (uptr_t) line, 0) != FALSE;
707 void sci_colourise(ScintillaObject *sci, gint start, gint end)
709 SSM(sci, SCI_COLOURISE, (uptr_t) start, end);
713 void sci_clear_all(ScintillaObject *sci)
715 SSM(sci, SCI_CLEARALL, 0, 0);
719 gint sci_get_end_styled(ScintillaObject *sci)
721 return (gint) SSM(sci, SCI_GETENDSTYLED, 0, 0);
725 void sci_set_tab_width(ScintillaObject *sci, gint width)
727 SSM(sci, SCI_SETTABWIDTH, (uptr_t) width, 0);
731 /** Gets display tab width (this is not indent width, see GeanyIndentPrefs).
732 * @param sci Scintilla widget.
733 * @return Width.
735 * @since 0.15
737 gint sci_get_tab_width(ScintillaObject *sci)
739 return (gint) SSM(sci, SCI_GETTABWIDTH, 0, 0);
743 /** Gets a character.
744 * @param sci Scintilla widget.
745 * @param pos Position.
746 * @return Char. */
747 gchar sci_get_char_at(ScintillaObject *sci, gint pos)
749 return (gchar) SSM(sci, SCI_GETCHARAT, (uptr_t) pos, 0);
753 void sci_set_savepoint(ScintillaObject *sci)
755 SSM(sci, SCI_SETSAVEPOINT, 0, 0);
759 void sci_set_indentation_guides(ScintillaObject *sci, gint mode)
761 SSM(sci, SCI_SETINDENTATIONGUIDES, (uptr_t) mode, 0);
765 void sci_use_popup(ScintillaObject *sci, gboolean enable)
767 SSM(sci, SCI_USEPOPUP, enable != FALSE, 0);
771 /** Checks if there's a selection.
772 * @param sci Scintilla widget.
773 * @return Whether a selection is present.
775 * @since 0.15
777 gboolean sci_has_selection(ScintillaObject *sci)
779 if (SSM(sci, SCI_GETSELECTIONEND, 0, 0) - SSM(sci, SCI_GETSELECTIONSTART, 0, 0))
780 return TRUE;
781 else
782 return FALSE;
786 void sci_goto_pos(ScintillaObject *sci, gint pos, gboolean unfold)
788 if (unfold) SSM(sci, SCI_ENSUREVISIBLE, (uptr_t) SSM(sci, SCI_LINEFROMPOSITION, (uptr_t) pos, 0), 0);
789 SSM(sci, SCI_GOTOPOS, (uptr_t) pos, 0);
793 void sci_set_search_anchor(ScintillaObject *sci)
795 SSM(sci, SCI_SEARCHANCHOR, 0, 0);
799 /* removes a selection if pos < 0 */
800 void sci_set_anchor(ScintillaObject *sci, gint pos)
802 if (pos < 0)
803 pos = sci_get_current_position(sci);
805 SSM(sci, SCI_SETANCHOR, (uptr_t) pos, 0);
809 /** Scrolls the cursor in view.
810 * @param sci Scintilla widget. */
811 void sci_scroll_caret(ScintillaObject *sci)
813 SSM(sci, SCI_SCROLLCARET, 0, 0);
817 void sci_scroll_lines(ScintillaObject *sci, gint lines)
819 SSM(sci, SCI_LINESCROLL, 0, lines);
823 void sci_scroll_columns(ScintillaObject *sci, gint columns)
825 SSM(sci, SCI_LINESCROLL, (uptr_t) columns, 0);
829 gint sci_search_next(ScintillaObject *sci, gint flags, const gchar *text)
831 /* FIXME: SCI_SEACHNEXT() actually returns long */
832 return (gint) SSM(sci, SCI_SEARCHNEXT, (uptr_t) flags, (sptr_t) text);
836 gint sci_search_prev(ScintillaObject *sci, gint flags, const gchar *text)
838 /* FIXME: SCI_SEACHPREV() actually returns long */
839 return (gint) SSM(sci, SCI_SEARCHPREV, (uptr_t) flags, (sptr_t) text);
843 /** Finds text in the document.
844 * The @a ttf argument should be a pointer to a Sci_TextToFind structure which contains
845 * the text to find and the range in which the text should be searched.
847 * Please refer to the Scintilla documentation for a more detailed description.
849 * @param sci Scintilla widget.
850 * @param flags Bitmask of Scintilla search flags (@c SCFIND_*, see Scintilla documentation).
851 * @param ttf Pointer to a TextToFind structure which contains the text to find and the range.
852 * @return The position of the start of the found text if it succeeds, otherwise @c -1.
853 * The @c chrgText.cpMin and @c chrgText.cpMax members of @c TextToFind are filled in
854 * with the start and end positions of the found text.
856 gint sci_find_text(ScintillaObject *sci, gint flags, struct Sci_TextToFind *ttf)
858 return (gint) SSM(sci, SCI_FINDTEXT, (uptr_t) flags, (sptr_t) ttf);
862 /** Sets the font for a particular style.
863 * @param sci Scintilla widget.
864 * @param style The style.
865 * @param font The font name.
866 * @param size The font size. */
867 void sci_set_font(ScintillaObject *sci, gint style, const gchar *font, gint size)
869 SSM(sci, SCI_STYLESETFONT, (uptr_t) style, (sptr_t) font);
870 SSM(sci, SCI_STYLESETSIZE, (uptr_t) style, size);
874 /** Jumps to the specified line in the document.
875 * If @a unfold is set and @a line is hidden by a fold, it is unfolded
876 * first to ensure it is visible.
877 * @param sci Scintilla widget.
878 * @param line Line.
879 * @param unfold Whether to unfold first.
881 void sci_goto_line(ScintillaObject *sci, gint line, gboolean unfold)
883 if (unfold) SSM(sci, SCI_ENSUREVISIBLE, (uptr_t) line, 0);
884 SSM(sci, SCI_GOTOLINE, (uptr_t) line, 0);
888 void sci_marker_delete_all(ScintillaObject *sci, gint marker)
890 SSM(sci, SCI_MARKERDELETEALL, (uptr_t) marker, 0);
894 /** Gets style ID at @a position.
895 * @param sci Scintilla widget.
896 * @param position Position.
897 * @return Style ID. */
898 gint sci_get_style_at(ScintillaObject *sci, gint position)
900 return (gint) SSM(sci, SCI_GETSTYLEAT, (uptr_t) position, 0);
904 void sci_set_codepage(ScintillaObject *sci, gint cp)
906 g_return_if_fail(cp == 0 || cp == SC_CP_UTF8);
907 SSM(sci, SCI_SETCODEPAGE, (uptr_t) cp, 0);
911 void sci_assign_cmdkey(ScintillaObject *sci, gint key, gint command)
913 SSM(sci, SCI_ASSIGNCMDKEY, (uptr_t) key, command);
917 void sci_clear_cmdkey(ScintillaObject *sci, gint key)
919 SSM(sci, SCI_CLEARCMDKEY, (uptr_t) key, 0);
923 /** Gets text between @a start and @a end.
924 * @deprecated sci_get_text_range is deprecated and should not be used in newly-written code.
925 * Use sci_get_contents_range() instead.
927 * @param sci Scintilla widget.
928 * @param start Start.
929 * @param end End.
930 * @param text Text will be zero terminated and must be allocated (end - start + 1) bytes. */
931 void sci_get_text_range(ScintillaObject *sci, gint start, gint end, gchar *text)
933 struct Sci_TextRange tr;
934 tr.chrg.cpMin = start;
935 tr.chrg.cpMax = end;
936 tr.lpstrText = text;
937 SSM(sci, SCI_GETTEXTRANGE, 0, (long) &tr);
941 /** Gets text between @a start and @a end.
942 * @param sci Scintilla widget.
943 * @param start Start position.
944 * @param end End position.
945 * @return The text inside the given range. Should be freed when no longer needed.
947 * @since 0.17
949 gchar *sci_get_contents_range(ScintillaObject *sci, gint start, gint end)
951 gchar *text;
953 g_return_val_if_fail(start < end, NULL);
955 text = g_malloc((gsize) (end - start) + 1);
956 sci_get_text_range(sci, start, end, text);
957 return text;
961 void sci_line_duplicate(ScintillaObject *sci)
963 SSM(sci, SCI_LINEDUPLICATE, 0, 0);
967 void sci_selection_duplicate(ScintillaObject *sci)
969 SSM(sci, SCI_SELECTIONDUPLICATE, 0, 0);
973 /** Inserts text.
974 * @param sci Scintilla widget.
975 * @param pos Position, or -1 for current.
976 * @param text Text. */
977 void sci_insert_text(ScintillaObject *sci, gint pos, const gchar *text)
979 SSM(sci, SCI_INSERTTEXT, (uptr_t) pos, (sptr_t) text);
983 void sci_target_from_selection(ScintillaObject *sci)
985 SSM(sci, SCI_TARGETFROMSELECTION, 0, 0);
989 void sci_set_target_start(ScintillaObject *sci, gint start)
991 SSM(sci, SCI_SETTARGETSTART, (uptr_t) start, 0);
995 void sci_set_target_end(ScintillaObject *sci, gint end)
997 SSM(sci, SCI_SETTARGETEND, (uptr_t) end, 0);
1001 gint sci_replace_target(ScintillaObject *sci, const gchar *text, gboolean regex)
1003 return (gint) SSM(sci, (regex) ? SCI_REPLACETARGETRE : SCI_REPLACETARGET, (uptr_t) -1, (sptr_t) text);
1007 void sci_set_keywords(ScintillaObject *sci, guint k, const gchar *text)
1009 SSM(sci, SCI_SETKEYWORDS, k, (sptr_t) text);
1013 void sci_set_readonly(ScintillaObject *sci, gboolean readonly)
1015 SSM(sci, SCI_SETREADONLY, readonly != FALSE, 0);
1019 /** Sends Scintilla commands without any parameters.
1020 * @param sci The Scintilla @c GtkWidget.
1021 * @param cmd @c SCI_COMMAND.
1022 * @see http://scintilla.org for the documentation.
1024 * @since 0.16
1026 void sci_send_command(ScintillaObject *sci, gint cmd)
1028 SSM(sci, cmd, 0, 0);
1032 /** Gets current line number.
1033 * @param sci Scintilla widget.
1034 * @return Line number. */
1035 gint sci_get_current_line(ScintillaObject *sci)
1037 return (gint) SSM(sci, SCI_LINEFROMPOSITION, (uptr_t) SSM(sci, SCI_GETCURRENTPOS, 0, 0), 0);
1041 /* Get number of lines partially or fully selected.
1042 * Returns 1 if there is a partial selection on the same line.
1043 * Returns 2 if a whole line is selected including the line break char(s). */
1044 gint sci_get_lines_selected(ScintillaObject *sci)
1046 gint start = (gint) SSM(sci, SCI_GETSELECTIONSTART, 0, 0);
1047 gint end = (gint) SSM(sci, SCI_GETSELECTIONEND, 0, 0);
1048 gint line_start;
1049 gint line_end;
1051 if (start == end)
1052 return 0; /* no selection */
1054 line_start = (gint) SSM(sci, SCI_LINEFROMPOSITION, (uptr_t) start, 0);
1055 line_end = (gint) SSM(sci, SCI_LINEFROMPOSITION, (uptr_t) end, 0);
1057 return line_end - line_start + 1;
1061 gint sci_get_first_visible_line(ScintillaObject *sci)
1063 return (gint) SSM(sci, SCI_GETFIRSTVISIBLELINE, 0, 0);
1068 * Sets the current indicator. This is necessary to define an indicator for a range of text or
1069 * clearing indicators for a range of text.
1071 * @param sci Scintilla widget.
1072 * @param indic The indicator number to set.
1074 * @see sci_indicator_clear
1076 * @since 0.16
1078 void sci_indicator_set(ScintillaObject *sci, gint indic)
1080 SSM(sci, SCI_SETINDICATORCURRENT, (uptr_t) indic, 0);
1084 void sci_indicator_fill(ScintillaObject *sci, gint pos, gint len)
1086 SSM(sci, SCI_INDICATORFILLRANGE, (uptr_t) pos, len);
1091 * Clears the currently set indicator from a range of text.
1092 * Starting at @a pos, @a len characters long.
1093 * In order to make this function properly, you need to set the current indicator before with
1094 * @ref sci_indicator_set().
1096 * @param sci Scintilla widget.
1097 * @param pos Starting position.
1098 * @param len Length.
1100 * @since 0.16
1102 void sci_indicator_clear(ScintillaObject *sci, gint pos, gint len)
1104 SSM(sci, SCI_INDICATORCLEARRANGE, (uptr_t) pos, len);
1108 void sci_select_all(ScintillaObject *sci)
1110 SSM(sci, SCI_SELECTALL, 0, 0);
1114 gint sci_get_line_indent_position(ScintillaObject *sci, gint line)
1116 return (gint) SSM(sci, SCI_GETLINEINDENTPOSITION, (uptr_t) line, 0);
1120 void sci_set_autoc_max_height(ScintillaObject *sci, gint val)
1122 SSM(sci, SCI_AUTOCSETMAXHEIGHT, (uptr_t) val, 0);
1126 /** Finds a matching brace at @a pos.
1127 * @param sci Scintilla widget.
1128 * @param pos Position.
1129 * @return Matching brace position.
1131 * @since 0.15
1133 gint sci_find_matching_brace(ScintillaObject *sci, gint pos)
1135 return (gint) SSM(sci, SCI_BRACEMATCH, (uptr_t) pos, 0);
1139 gint sci_get_overtype(ScintillaObject *sci)
1141 return (gint) SSM(sci, SCI_GETOVERTYPE, 0, 0);
1145 void sci_set_tab_indents(ScintillaObject *sci, gboolean set)
1147 SSM(sci, SCI_SETTABINDENTS, set != FALSE, 0);
1151 void sci_set_use_tabs(ScintillaObject *sci, gboolean set)
1153 SSM(sci, SCI_SETUSETABS, set != FALSE, 0);
1157 gint sci_get_pos_at_line_sel_start(ScintillaObject *sci, gint line)
1159 return (gint) SSM(sci, SCI_GETLINESELSTARTPOSITION, (uptr_t) line, 0);
1163 gint sci_get_pos_at_line_sel_end(ScintillaObject *sci, gint line)
1165 return (gint) SSM(sci, SCI_GETLINESELENDPOSITION, (uptr_t) line, 0);
1169 /** Gets selection mode.
1170 * @param sci Scintilla widget.
1171 * @return Selection mode. */
1172 gint sci_get_selection_mode(ScintillaObject *sci)
1174 return (gint) SSM(sci, SCI_GETSELECTIONMODE, 0, 0);
1178 /** Sets selection mode.
1179 * @param sci Scintilla widget.
1180 * @param mode Mode. */
1181 void sci_set_selection_mode(ScintillaObject *sci, gint mode)
1183 SSM(sci, SCI_SETSELECTIONMODE, (uptr_t) mode, 0);
1187 void sci_set_scrollbar_mode(ScintillaObject *sci, gboolean visible)
1189 SSM(sci, SCI_SETHSCROLLBAR, visible != FALSE, 0);
1190 SSM(sci, SCI_SETVSCROLLBAR, visible != FALSE, 0);
1194 /** Sets the indentation of a line.
1195 * @param sci Scintilla widget.
1196 * @param line Line to indent.
1197 * @param indent Indentation width.
1199 * @since 0.19
1201 void sci_set_line_indentation(ScintillaObject *sci, gint line, gint indent)
1203 SSM(sci, SCI_SETLINEINDENTATION, (uptr_t) line, indent);
1207 /** Gets the indentation width of a line.
1208 * @param sci Scintilla widget.
1209 * @param line Line to get the indentation from.
1210 * @return Indentation width.
1212 * @since 0.19
1214 gint sci_get_line_indentation(ScintillaObject *sci, gint line)
1216 return (gint) SSM(sci, SCI_GETLINEINDENTATION, (uptr_t) line, 0);
1220 void sci_set_caret_policy_x(ScintillaObject *sci, gint policy, gint slop)
1222 SSM(sci, SCI_SETXCARETPOLICY, (uptr_t) policy, slop);
1226 void sci_set_caret_policy_y(ScintillaObject *sci, gint policy, gint slop)
1228 SSM(sci, SCI_SETYCARETPOLICY, (uptr_t) policy, slop);
1232 void sci_set_scroll_stop_at_last_line(ScintillaObject *sci, gboolean set)
1234 SSM(sci, SCI_SETENDATLASTLINE, set != FALSE, 0);
1238 void sci_cancel(ScintillaObject *sci)
1240 SSM(sci, SCI_CANCEL, 0, 0);
1244 gint sci_get_target_end(ScintillaObject *sci)
1246 return (gint) SSM(sci, SCI_GETTARGETEND, 0, 0);
1250 gint sci_get_position_after(ScintillaObject *sci, gint start)
1252 return (gint) SSM(sci, SCI_POSITIONAFTER, (uptr_t) start, 0);
1256 void sci_lines_join(ScintillaObject *sci)
1258 SSM(sci, SCI_LINESJOIN, 0, 0);
1262 gint sci_text_width(ScintillaObject *sci, gint styleNumber, const gchar *text)
1264 return (gint) SSM(sci, SCI_TEXTWIDTH, (uptr_t) styleNumber, (sptr_t) text);
1267 void sci_move_selected_lines_down(ScintillaObject *sci)
1269 SSM(sci, SCI_MOVESELECTEDLINESDOWN, 0, 0);
1272 void sci_move_selected_lines_up(ScintillaObject *sci)
1274 SSM(sci, SCI_MOVESELECTEDLINESUP, 0, 0);