Add new function document_show_message()
[geany-mirror.git] / src / sciwrappers.c
blob859e9ada25a5d05dff2f41fc6ab308ac29b11fcc
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 #ifdef HAVE_CONFIG_H
35 # include "config.h"
36 #endif
38 #include "sciwrappers.h"
40 #include "utils.h"
42 #include <string.h>
45 #define SSM(s, m, w, l) scintilla_send_message(s, m, w, l)
47 /* line numbers visibility */
48 void sci_set_line_numbers(ScintillaObject *sci, gboolean set, gint extra_width)
50 if (set)
52 gchar tmp_str[15];
53 gint len = (gint) SSM(sci, SCI_GETLINECOUNT, 0, 0);
54 gint width;
56 g_snprintf(tmp_str, 15, "_%d", len);
57 width = sci_text_width(sci, STYLE_LINENUMBER, tmp_str);
58 if (extra_width)
60 g_snprintf(tmp_str, 15, "%d", extra_width);
61 width += sci_text_width(sci, STYLE_LINENUMBER, tmp_str);
63 SSM(sci, SCI_SETMARGINWIDTHN, 0, width);
64 SSM(sci, SCI_SETMARGINSENSITIVEN, 0, FALSE); /* use default behaviour */
66 else
68 SSM(sci, SCI_SETMARGINWIDTHN, 0, 0);
73 void sci_set_mark_long_lines(ScintillaObject *sci, gint type, gint column, const gchar *colour)
75 glong colour_val = utils_parse_color_to_bgr(colour); /* Scintilla uses a "long" value */
77 if (column == 0)
78 type = 2;
79 switch (type)
81 case 0:
83 SSM(sci, SCI_SETEDGEMODE, EDGE_LINE, 0);
84 break;
86 case 1:
88 SSM(sci, SCI_SETEDGEMODE, EDGE_BACKGROUND, 0);
89 break;
91 case 2:
93 SSM(sci, SCI_SETEDGEMODE, EDGE_NONE, 0);
94 return;
97 SSM(sci, SCI_SETEDGECOLUMN, (uptr_t) column, 0);
98 SSM(sci, SCI_SETEDGECOLOUR, (uptr_t) colour_val, 0);
102 /* symbol margin visibility */
103 void sci_set_symbol_margin(ScintillaObject *sci, gboolean set)
105 if (set)
107 SSM(sci, SCI_SETMARGINWIDTHN, 1, 16);
108 SSM(sci, SCI_SETMARGINSENSITIVEN, 1, TRUE);
110 else
112 SSM(sci, SCI_SETMARGINWIDTHN, 1, 0);
113 SSM(sci, SCI_SETMARGINSENSITIVEN, 1, FALSE);
118 /* folding margin visibility */
119 void sci_set_folding_margin_visible(ScintillaObject *sci, gboolean set)
121 if (set)
123 SSM(sci, SCI_SETMARGINWIDTHN, 2, 12);
124 SSM(sci, SCI_SETMARGINSENSITIVEN, 2, TRUE);
126 else
128 SSM(sci, SCI_SETMARGINSENSITIVEN, 2, FALSE);
129 SSM(sci, SCI_SETMARGINWIDTHN, 2, 0);
134 /* end of lines */
135 void sci_set_visible_eols(ScintillaObject *sci, gboolean set)
137 SSM(sci, SCI_SETVIEWEOL, set != FALSE, 0);
141 void sci_set_visible_white_spaces(ScintillaObject *sci, gboolean set)
143 if (set)
144 SSM(sci, SCI_SETVIEWWS, SCWS_VISIBLEALWAYS, 0);
145 else
146 SSM(sci, SCI_SETVIEWWS, SCWS_INVISIBLE, 0);
150 void sci_set_lines_wrapped(ScintillaObject *sci, gboolean set)
152 if (set)
153 SSM(sci, SCI_SETWRAPMODE, SC_WRAP_WORD, 0);
154 else
155 SSM(sci, SCI_SETWRAPMODE, SC_WRAP_NONE, 0);
159 gint sci_get_eol_mode(ScintillaObject *sci)
161 return (gint) SSM(sci, SCI_GETEOLMODE, 0, 0);
165 void sci_set_eol_mode(ScintillaObject *sci, gint eolmode)
167 SSM(sci, SCI_SETEOLMODE, (uptr_t) eolmode, 0);
171 void sci_convert_eols(ScintillaObject *sci, gint eolmode)
173 SSM(sci, SCI_CONVERTEOLS, (uptr_t) eolmode, 0);
177 void sci_add_text(ScintillaObject *sci, const gchar *text)
179 if (text != NULL)
180 { /* if null text is passed scintilla will segfault */
181 SSM(sci, SCI_ADDTEXT, strlen(text), (sptr_t) text);
186 /** Sets all text.
187 * @param sci Scintilla widget.
188 * @param text Text. */
189 void sci_set_text(ScintillaObject *sci, const gchar *text)
191 if( text != NULL ){ /* if null text is passed to scintilla will segfault */
192 SSM(sci, SCI_SETTEXT, 0, (sptr_t) text);
197 gboolean sci_can_undo(ScintillaObject *sci)
199 return SSM(sci, SCI_CANUNDO, 0, 0) != FALSE;
203 gboolean sci_can_redo(ScintillaObject *sci)
205 return SSM(sci, SCI_CANREDO, 0, 0) != FALSE;
209 void sci_undo(ScintillaObject *sci)
211 if (sci_can_undo(sci))
212 SSM(sci, SCI_UNDO, 0, 0);
216 void sci_redo(ScintillaObject *sci)
218 if (sci_can_redo(sci))
219 SSM(sci, SCI_REDO, 0, 0);
223 /** Begins grouping a set of edits together as one Undo action.
224 * You must call sci_end_undo_action() after making your edits.
225 * @param sci Scintilla @c GtkWidget. */
226 void sci_start_undo_action(ScintillaObject *sci)
228 SSM(sci, SCI_BEGINUNDOACTION, 0, 0);
232 /** Ends grouping a set of edits together as one Undo action.
233 * @param sci Scintilla @c GtkWidget.
234 * @see sci_start_undo_action(). */
235 void sci_end_undo_action(ScintillaObject *sci)
237 SSM(sci, SCI_ENDUNDOACTION, 0, 0);
241 void sci_set_undo_collection(ScintillaObject *sci, gboolean set)
243 SSM(sci, SCI_SETUNDOCOLLECTION, set != FALSE, 0);
247 void sci_empty_undo_buffer(ScintillaObject *sci)
249 SSM(sci, SCI_EMPTYUNDOBUFFER, 0, 0);
253 gboolean sci_is_modified(ScintillaObject *sci)
255 return (SSM(sci, SCI_GETMODIFY, 0, 0) != 0);
259 void sci_zoom_in(ScintillaObject *sci)
261 SSM(sci, SCI_ZOOMIN, 0, 0);
265 void sci_zoom_out(ScintillaObject *sci)
267 SSM(sci, SCI_ZOOMOUT, 0, 0);
271 void sci_zoom_off(ScintillaObject *sci)
273 SSM(sci, SCI_SETZOOM, 0, 0);
277 gint sci_get_zoom(ScintillaObject *sci)
279 return (gint) SSM(sci, SCI_GETZOOM, 0, 0);
283 /** Sets a line marker.
284 * @param sci Scintilla widget.
285 * @param line_number Line number.
286 * @param marker Marker number. */
287 void sci_set_marker_at_line(ScintillaObject *sci, gint line_number, gint marker)
289 SSM(sci, SCI_MARKERADD, (uptr_t) line_number, marker);
293 /** Deletes a line marker.
294 * @param sci Scintilla widget.
295 * @param line_number Line number.
296 * @param marker Marker number. */
297 void sci_delete_marker_at_line(ScintillaObject *sci, gint line_number, gint marker)
299 SSM(sci, SCI_MARKERDELETE, (uptr_t) line_number, marker);
303 /** Checks if a line has a marker set.
304 * @param sci Scintilla widget.
305 * @param line Line number.
306 * @param marker Marker number.
307 * @return Whether it's set. */
308 gboolean sci_is_marker_set_at_line(ScintillaObject *sci, gint line, gint marker)
310 gint state;
312 state = (gint) SSM(sci, SCI_MARKERGET, (uptr_t) line, 0);
313 return (state & (1 << marker));
317 void sci_toggle_marker_at_line(ScintillaObject *sci, gint line, gint marker)
319 gboolean set = sci_is_marker_set_at_line(sci, line, marker);
321 if (!set)
322 sci_set_marker_at_line(sci, line, marker);
323 else
324 sci_delete_marker_at_line(sci, line, marker);
328 /* Returns the line number of the next marker that matches marker_mask, or -1.
329 * marker_mask is a bitor of 1 << marker_index. (See MarkerHandleSet::MarkValue()).
330 * Note: If there is a marker on the line, it returns the same line. */
331 gint sci_marker_next(ScintillaObject *sci, gint line, gint marker_mask, gboolean wrap)
333 gint marker_line;
335 marker_line = (gint) SSM(sci, SCI_MARKERNEXT, (uptr_t) line, marker_mask);
336 if (wrap && marker_line == -1)
337 marker_line = (gint) SSM(sci, SCI_MARKERNEXT, 0, marker_mask);
338 return marker_line;
342 /* Returns the line number of the previous marker that matches marker_mask, or -1.
343 * marker_mask is a bitor of 1 << marker_index. (See MarkerHandleSet::MarkValue()).
344 * Note: If there is a marker on the line, it returns the same line. */
345 gint sci_marker_previous(ScintillaObject *sci, gint line, gint marker_mask, gboolean wrap)
347 gint marker_line;
349 marker_line = (gint) SSM(sci, SCI_MARKERPREVIOUS, (uptr_t) line, marker_mask);
350 if (wrap && marker_line == -1)
352 gint len = sci_get_length(sci);
353 gint last_line = sci_get_line_from_position(sci, len - 1);
355 marker_line = (gint) SSM(sci, SCI_MARKERPREVIOUS, (uptr_t) last_line, marker_mask);
357 return marker_line;
361 /** Gets the line number from @a position.
362 * @param sci Scintilla widget.
363 * @param position Position.
364 * @return The line. */
365 gint sci_get_line_from_position(ScintillaObject *sci, gint position)
367 return (gint) SSM(sci, SCI_LINEFROMPOSITION, (uptr_t) position, 0);
371 /** Gets the column number relative to the start of the line that @a position is on.
372 * @param sci Scintilla widget.
373 * @param position Position.
374 * @return The column. */
375 gint sci_get_col_from_position(ScintillaObject *sci, gint position)
377 return (gint) SSM(sci, SCI_GETCOLUMN, (uptr_t) position, 0);
381 gint sci_get_position_from_col(ScintillaObject *sci, gint line, gint col)
383 return (gint) SSM(sci, SCI_FINDCOLUMN, line, col);
387 /** Gets the position for the start of @a line.
388 * @param sci Scintilla widget.
389 * @param line Line.
390 * @return Position. */
391 gint sci_get_position_from_line(ScintillaObject *sci, gint line)
393 return (gint) SSM(sci, SCI_POSITIONFROMLINE, (uptr_t) line, 0);
397 /** Gets the cursor position.
398 * @param sci Scintilla widget.
399 * @return Position. */
400 gint sci_get_current_position(ScintillaObject *sci)
402 return (gint) SSM(sci, SCI_GETCURRENTPOS, 0, 0);
406 /** Sets the cursor position.
407 * @param sci Scintilla widget.
408 * @param position Position.
409 * @param scroll_to_caret Whether to scroll the cursor in view. */
410 void sci_set_current_position(ScintillaObject *sci, gint position, gboolean scroll_to_caret)
412 if (scroll_to_caret)
413 SSM(sci, SCI_GOTOPOS, (uptr_t) position, 0);
414 else
416 SSM(sci, SCI_SETCURRENTPOS, (uptr_t) position, 0);
417 SSM(sci, SCI_SETANCHOR, (uptr_t) position, 0); /* to avoid creation of a selection */
419 SSM(sci, SCI_CHOOSECARETX, 0, 0);
423 /* Set the cursor line without scrolling the view.
424 * Use sci_goto_line() to also scroll. */
425 void sci_set_current_line(ScintillaObject *sci, gint line)
427 gint pos = sci_get_position_from_line(sci, line);
428 sci_set_current_position(sci, pos, FALSE);
432 /** Gets the total number of lines.
433 * @param sci Scintilla widget.
434 * @return The line count. */
435 gint sci_get_line_count(ScintillaObject *sci)
437 return (gint) SSM(sci, SCI_GETLINECOUNT, 0, 0);
441 /** Sets the selection start position.
442 * @param sci Scintilla widget.
443 * @param position Position. */
444 void sci_set_selection_start(ScintillaObject *sci, gint position)
446 SSM(sci, SCI_SETSELECTIONSTART, (uptr_t) position, 0);
450 /** Sets the selection end position.
451 * @param sci Scintilla widget.
452 * @param position Position. */
453 void sci_set_selection_end(ScintillaObject *sci, gint position)
455 SSM(sci, SCI_SETSELECTIONEND, (uptr_t) position, 0);
459 void sci_set_selection(ScintillaObject *sci, gint anchorPos, gint currentPos)
461 SSM(sci, SCI_SETSEL, (uptr_t) anchorPos, currentPos);
465 /** Gets the position at the end of a line
466 * @param sci Scintilla widget.
467 * @param line Line.
468 * @return The position at the end of the line. */
469 gint sci_get_line_end_position(ScintillaObject *sci, gint line)
471 return (gint) SSM(sci, SCI_GETLINEENDPOSITION, (uptr_t) line, 0);
475 void sci_cut(ScintillaObject *sci)
477 SSM(sci, SCI_CUT, 0, 0);
481 void sci_copy(ScintillaObject *sci)
483 SSM(sci, SCI_COPY, 0, 0);
487 void sci_paste(ScintillaObject *sci)
489 SSM(sci, SCI_PASTE, 0, 0);
493 void sci_clear(ScintillaObject *sci)
495 SSM(sci, SCI_CLEAR, 0, 0);
499 /** Gets the selection start position.
500 * @param sci Scintilla widget.
501 * @return Position. */
502 gint sci_get_selection_start(ScintillaObject *sci)
504 return (gint) SSM(sci, SCI_GETSELECTIONSTART, 0, 0);
508 /** Gets the selection end position.
509 * @param sci Scintilla widget.
510 * @return Position. */
511 gint sci_get_selection_end(ScintillaObject *sci)
513 return (gint) SSM(sci, SCI_GETSELECTIONEND, 0, 0);
517 /** Replaces selection.
518 * @param sci Scintilla widget.
519 * @param text Text. */
520 void sci_replace_sel(ScintillaObject *sci, const gchar *text)
522 SSM(sci, SCI_REPLACESEL, 0, (sptr_t) text);
526 /** Gets the length of all text.
527 * @param sci Scintilla widget.
528 * @return Length. */
529 gint sci_get_length(ScintillaObject *sci)
531 return (gint) SSM(sci, SCI_GETLENGTH, 0, 0);
535 /** Gets the currently used lexer
536 * @param sci Scintilla widget.
537 * @returns The lexer ID
539 gint sci_get_lexer(ScintillaObject *sci)
541 return (gint) SSM(sci, SCI_GETLEXER, 0, 0);
545 void sci_set_lexer(ScintillaObject *sci, guint lexer_id)
547 gint old = sci_get_lexer(sci);
549 SSM(sci, SCI_SETLEXER, lexer_id, 0);
551 if (old != (gint)lexer_id)
552 SSM(sci, SCI_CLEARDOCUMENTSTYLE, 0, 0);
556 /** Gets line length.
557 * @param sci Scintilla widget.
558 * @param line Line number.
559 * @return Length. */
560 gint sci_get_line_length(ScintillaObject *sci, gint line)
562 return (gint) SSM(sci, SCI_LINELENGTH, (uptr_t) line, 0);
566 /* safe way to read Scintilla string into new memory.
567 * works with any string buffer messages that follow the Windows message convention. */
568 gchar *sci_get_string(ScintillaObject *sci, guint msg, gulong wParam)
570 gint size = (gint) SSM(sci, msg, wParam, 0);
571 gchar *str = g_malloc(size + 1);
573 SSM(sci, msg, wParam, (sptr_t) str);
574 str[size] = '\0'; /* ensure termination, needed for SCI_GETLINE */
575 return str;
579 /** Gets line contents.
580 * @param sci Scintilla widget.
581 * @param line_num Line number.
582 * @return A @c NULL-terminated copy of the line text. */
583 gchar *sci_get_line(ScintillaObject *sci, gint line_num)
585 return sci_get_string(sci, SCI_GETLINE, (gulong) line_num);
589 /** Gets all text.
590 * @deprecated sci_get_text is deprecated and should not be used in newly-written code.
591 * Use sci_get_contents() instead.
593 * @param sci Scintilla widget.
594 * @param len Length of @a text buffer, usually sci_get_length() + 1.
595 * @param text Text buffer; must be allocated @a len + 1 bytes for null-termination. */
596 void sci_get_text(ScintillaObject *sci, gint len, gchar *text)
598 SSM(sci, SCI_GETTEXT, (uptr_t) len, (sptr_t) text);
602 /** Allocates and fills a buffer with text from the start of the document.
603 * @param sci Scintilla widget.
604 * @param buffer_len Buffer length to allocate, including the terminating
605 * null char, e.g. sci_get_length() + 1. Alternatively use @c -1 to get all
606 * text (since Geany 1.23).
607 * @return A copy of the text. Should be freed when no longer needed.
609 * @since 1.23 (0.17)
611 gchar *sci_get_contents(ScintillaObject *sci, gint buffer_len)
613 gchar *text;
615 if (buffer_len < 0)
616 buffer_len = sci_get_length(sci) + 1;
618 text = g_malloc(buffer_len);
619 SSM(sci, SCI_GETTEXT, (uptr_t) buffer_len, (sptr_t) text);
620 return text;
624 /** Gets selected text.
625 * @deprecated sci_get_selected_text is deprecated and should not be used in newly-written code.
626 * Use sci_get_selection_contents() instead.
628 * @param sci Scintilla widget.
629 * @param text Text buffer; must be allocated sci_get_selected_text_length() + 1 bytes
630 * for null-termination. */
631 void sci_get_selected_text(ScintillaObject *sci, gchar *text)
633 SSM(sci, SCI_GETSELTEXT, 0, (sptr_t) text);
637 /** Gets selected text.
638 * @param sci Scintilla widget.
640 * @return The selected text. Should be freed when no longer needed.
642 * @since 0.17
644 gchar *sci_get_selection_contents(ScintillaObject *sci)
646 return sci_get_string(sci, SCI_GETSELTEXT, 0);
650 /** Gets selected text length.
651 * @param sci Scintilla widget.
652 * @return Length. */
653 gint sci_get_selected_text_length(ScintillaObject *sci)
655 return (gint) SSM(sci, SCI_GETSELTEXT, 0, 0);
659 gint sci_get_position_from_xy(ScintillaObject *sci, gint x, gint y, gboolean nearby)
661 /* for nearby return -1 if there is no character near to the x,y point. */
662 return (gint) SSM(sci, (nearby) ? SCI_POSITIONFROMPOINTCLOSE : SCI_POSITIONFROMPOINT, (uptr_t) x, y);
666 /** Checks if a line is visible (folding may have hidden it).
667 * @param sci Scintilla widget.
668 * @param line Line number.
669 * @return Whether @a line will be drawn on the screen. */
670 gboolean sci_get_line_is_visible(ScintillaObject *sci, gint line)
672 return SSM(sci, SCI_GETLINEVISIBLE, (uptr_t) line, 0) != FALSE;
676 /** Makes @a line visible (folding may have hidden it).
677 * @param sci Scintilla widget.
678 * @param line Line number. */
679 void sci_ensure_line_is_visible(ScintillaObject *sci, gint line)
681 SSM(sci, SCI_ENSUREVISIBLE, (uptr_t) line, 0);
685 gint sci_get_fold_level(ScintillaObject *sci, gint line)
687 return (gint) SSM(sci, SCI_GETFOLDLEVEL, (uptr_t) line, 0);
691 /* Get the line number of the fold point before start_line, or -1 if there isn't one */
692 gint sci_get_fold_parent(ScintillaObject *sci, gint start_line)
694 return (gint) SSM(sci, SCI_GETFOLDPARENT, (uptr_t) start_line, 0);
698 void sci_toggle_fold(ScintillaObject *sci, gint line)
700 SSM(sci, SCI_TOGGLEFOLD, (uptr_t) line, 0);
704 gboolean sci_get_fold_expanded(ScintillaObject *sci, gint line)
706 return SSM(sci, SCI_GETFOLDEXPANDED, (uptr_t) line, 0) != FALSE;
710 void sci_colourise(ScintillaObject *sci, gint start, gint end)
712 SSM(sci, SCI_COLOURISE, (uptr_t) start, end);
716 void sci_clear_all(ScintillaObject *sci)
718 SSM(sci, SCI_CLEARALL, 0, 0);
722 gint sci_get_end_styled(ScintillaObject *sci)
724 return (gint) SSM(sci, SCI_GETENDSTYLED, 0, 0);
728 void sci_set_tab_width(ScintillaObject *sci, gint width)
730 SSM(sci, SCI_SETTABWIDTH, (uptr_t) width, 0);
734 /** Gets display tab width (this is not indent width, see GeanyIndentPrefs).
735 * @param sci Scintilla widget.
736 * @return Width.
738 * @since 0.15
740 gint sci_get_tab_width(ScintillaObject *sci)
742 return (gint) SSM(sci, SCI_GETTABWIDTH, 0, 0);
746 /** Gets a character.
747 * @param sci Scintilla widget.
748 * @param pos Position.
749 * @return Char. */
750 gchar sci_get_char_at(ScintillaObject *sci, gint pos)
752 return (gchar) SSM(sci, SCI_GETCHARAT, (uptr_t) pos, 0);
756 void sci_set_savepoint(ScintillaObject *sci)
758 SSM(sci, SCI_SETSAVEPOINT, 0, 0);
762 void sci_set_indentation_guides(ScintillaObject *sci, gint mode)
764 SSM(sci, SCI_SETINDENTATIONGUIDES, (uptr_t) mode, 0);
768 void sci_use_popup(ScintillaObject *sci, gboolean enable)
770 SSM(sci, SCI_USEPOPUP, enable != FALSE, 0);
774 /** Checks if there's a selection.
775 * @param sci Scintilla widget.
776 * @return Whether a selection is present.
778 * @since 0.15
780 gboolean sci_has_selection(ScintillaObject *sci)
782 if (SSM(sci, SCI_GETSELECTIONEND, 0, 0) - SSM(sci, SCI_GETSELECTIONSTART, 0, 0))
783 return TRUE;
784 else
785 return FALSE;
789 void sci_goto_pos(ScintillaObject *sci, gint pos, gboolean unfold)
791 if (unfold) SSM(sci, SCI_ENSUREVISIBLE, (uptr_t) SSM(sci, SCI_LINEFROMPOSITION, (uptr_t) pos, 0), 0);
792 SSM(sci, SCI_GOTOPOS, (uptr_t) pos, 0);
796 void sci_set_search_anchor(ScintillaObject *sci)
798 SSM(sci, SCI_SEARCHANCHOR, 0, 0);
802 /* removes a selection if pos < 0 */
803 void sci_set_anchor(ScintillaObject *sci, gint pos)
805 if (pos < 0)
806 pos = sci_get_current_position(sci);
808 SSM(sci, SCI_SETANCHOR, (uptr_t) pos, 0);
812 /** Scrolls the cursor in view.
813 * @param sci Scintilla widget. */
814 void sci_scroll_caret(ScintillaObject *sci)
816 SSM(sci, SCI_SCROLLCARET, 0, 0);
820 void sci_scroll_lines(ScintillaObject *sci, gint lines)
822 SSM(sci, SCI_LINESCROLL, 0, lines);
826 void sci_scroll_columns(ScintillaObject *sci, gint columns)
828 SSM(sci, SCI_LINESCROLL, (uptr_t) columns, 0);
832 gint sci_search_next(ScintillaObject *sci, gint flags, const gchar *text)
834 /* FIXME: SCI_SEACHNEXT() actually returns long */
835 return (gint) SSM(sci, SCI_SEARCHNEXT, (uptr_t) flags, (sptr_t) text);
839 gint sci_search_prev(ScintillaObject *sci, gint flags, const gchar *text)
841 /* FIXME: SCI_SEACHPREV() actually returns long */
842 return (gint) SSM(sci, SCI_SEARCHPREV, (uptr_t) flags, (sptr_t) text);
846 /** Finds text in the document.
847 * The @a ttf argument should be a pointer to a Sci_TextToFind structure which contains
848 * the text to find and the range in which the text should be searched.
850 * Please refer to the Scintilla documentation for a more detailed description.
852 * @param sci Scintilla widget.
853 * @param flags Bitmask of Scintilla search flags (@c SCFIND_*, see Scintilla documentation).
854 * @param ttf Pointer to a TextToFind structure which contains the text to find and the range.
855 * @return The position of the start of the found text if it succeeds, otherwise @c -1.
856 * The @c chrgText.cpMin and @c chrgText.cpMax members of @c TextToFind are filled in
857 * with the start and end positions of the found text.
859 gint sci_find_text(ScintillaObject *sci, gint flags, struct Sci_TextToFind *ttf)
861 return (gint) SSM(sci, SCI_FINDTEXT, (uptr_t) flags, (sptr_t) ttf);
865 /** Sets the font for a particular style.
866 * @param sci Scintilla widget.
867 * @param style The style.
868 * @param font The font name.
869 * @param size The font size. */
870 void sci_set_font(ScintillaObject *sci, gint style, const gchar *font, gint size)
872 SSM(sci, SCI_STYLESETFONT, (uptr_t) style, (sptr_t) font);
873 SSM(sci, SCI_STYLESETSIZE, (uptr_t) style, size);
877 /** Jumps to the specified line in the document.
878 * If @a unfold is set and @a line is hidden by a fold, it is unfolded
879 * first to ensure it is visible.
880 * @param sci Scintilla widget.
881 * @param line Line.
882 * @param unfold Whether to unfold first.
884 void sci_goto_line(ScintillaObject *sci, gint line, gboolean unfold)
886 if (unfold) SSM(sci, SCI_ENSUREVISIBLE, (uptr_t) line, 0);
887 SSM(sci, SCI_GOTOLINE, (uptr_t) line, 0);
891 void sci_marker_delete_all(ScintillaObject *sci, gint marker)
893 SSM(sci, SCI_MARKERDELETEALL, (uptr_t) marker, 0);
897 /** Gets style ID at @a position.
898 * @param sci Scintilla widget.
899 * @param position Position.
900 * @return Style ID. */
901 gint sci_get_style_at(ScintillaObject *sci, gint position)
903 return (gint) SSM(sci, SCI_GETSTYLEAT, (uptr_t) position, 0);
907 void sci_set_codepage(ScintillaObject *sci, gint cp)
909 g_return_if_fail(cp == 0 || cp == SC_CP_UTF8);
910 SSM(sci, SCI_SETCODEPAGE, (uptr_t) cp, 0);
914 void sci_assign_cmdkey(ScintillaObject *sci, gint key, gint command)
916 SSM(sci, SCI_ASSIGNCMDKEY, (uptr_t) key, command);
920 void sci_clear_cmdkey(ScintillaObject *sci, gint key)
922 SSM(sci, SCI_CLEARCMDKEY, (uptr_t) key, 0);
926 /** Gets text between @a start and @a end.
927 * @deprecated sci_get_text_range is deprecated and should not be used in newly-written code.
928 * Use sci_get_contents_range() instead.
930 * @param sci Scintilla widget.
931 * @param start Start.
932 * @param end End.
933 * @param text Text will be zero terminated and must be allocated (end - start + 1) bytes. */
934 void sci_get_text_range(ScintillaObject *sci, gint start, gint end, gchar *text)
936 struct Sci_TextRange tr;
937 tr.chrg.cpMin = start;
938 tr.chrg.cpMax = end;
939 tr.lpstrText = text;
940 SSM(sci, SCI_GETTEXTRANGE, 0, (long) &tr);
944 /** Gets text between @a start and @a end.
945 * @param sci Scintilla widget.
946 * @param start Start position.
947 * @param end End position.
948 * @return The text inside the given range. Should be freed when no longer needed.
950 * @since 0.17
952 gchar *sci_get_contents_range(ScintillaObject *sci, gint start, gint end)
954 gchar *text;
956 g_return_val_if_fail(start < end, NULL);
958 text = g_malloc((gsize) (end - start) + 1);
959 sci_get_text_range(sci, start, end, text);
960 return text;
964 void sci_line_duplicate(ScintillaObject *sci)
966 SSM(sci, SCI_LINEDUPLICATE, 0, 0);
970 void sci_selection_duplicate(ScintillaObject *sci)
972 SSM(sci, SCI_SELECTIONDUPLICATE, 0, 0);
976 /** Inserts text.
977 * @param sci Scintilla widget.
978 * @param pos Position, or -1 for current.
979 * @param text Text. */
980 void sci_insert_text(ScintillaObject *sci, gint pos, const gchar *text)
982 SSM(sci, SCI_INSERTTEXT, (uptr_t) pos, (sptr_t) text);
986 void sci_target_from_selection(ScintillaObject *sci)
988 SSM(sci, SCI_TARGETFROMSELECTION, 0, 0);
992 void sci_set_target_start(ScintillaObject *sci, gint start)
994 SSM(sci, SCI_SETTARGETSTART, (uptr_t) start, 0);
998 void sci_set_target_end(ScintillaObject *sci, gint end)
1000 SSM(sci, SCI_SETTARGETEND, (uptr_t) end, 0);
1004 gint sci_replace_target(ScintillaObject *sci, const gchar *text, gboolean regex)
1006 return (gint) SSM(sci, (regex) ? SCI_REPLACETARGETRE : SCI_REPLACETARGET, (uptr_t) -1, (sptr_t) text);
1010 void sci_set_keywords(ScintillaObject *sci, guint k, const gchar *text)
1012 SSM(sci, SCI_SETKEYWORDS, k, (sptr_t) text);
1016 void sci_set_readonly(ScintillaObject *sci, gboolean readonly)
1018 SSM(sci, SCI_SETREADONLY, readonly != FALSE, 0);
1022 /** Sends Scintilla commands without any parameters.
1023 * @param sci The Scintilla @c GtkWidget.
1024 * @param cmd @c SCI_COMMAND.
1025 * @see http://scintilla.org for the documentation.
1027 * @since 0.16
1029 void sci_send_command(ScintillaObject *sci, gint cmd)
1031 SSM(sci, cmd, 0, 0);
1035 /** Gets current line number.
1036 * @param sci Scintilla widget.
1037 * @return Line number. */
1038 gint sci_get_current_line(ScintillaObject *sci)
1040 return (gint) SSM(sci, SCI_LINEFROMPOSITION, (uptr_t) SSM(sci, SCI_GETCURRENTPOS, 0, 0), 0);
1044 /* Get number of lines partially or fully selected.
1045 * Returns 1 if there is a partial selection on the same line.
1046 * Returns 2 if a whole line is selected including the line break char(s). */
1047 gint sci_get_lines_selected(ScintillaObject *sci)
1049 gint start = (gint) SSM(sci, SCI_GETSELECTIONSTART, 0, 0);
1050 gint end = (gint) SSM(sci, SCI_GETSELECTIONEND, 0, 0);
1051 gint line_start;
1052 gint line_end;
1054 if (start == end)
1055 return 0; /* no selection */
1057 line_start = (gint) SSM(sci, SCI_LINEFROMPOSITION, (uptr_t) start, 0);
1058 line_end = (gint) SSM(sci, SCI_LINEFROMPOSITION, (uptr_t) end, 0);
1060 return line_end - line_start + 1;
1064 gint sci_get_first_visible_line(ScintillaObject *sci)
1066 return (gint) SSM(sci, SCI_GETFIRSTVISIBLELINE, 0, 0);
1071 * Sets the current indicator. This is necessary to define an indicator for a range of text or
1072 * clearing indicators for a range of text.
1074 * @param sci Scintilla widget.
1075 * @param indic The indicator number to set.
1077 * @see sci_indicator_clear
1079 * @since 0.16
1081 void sci_indicator_set(ScintillaObject *sci, gint indic)
1083 SSM(sci, SCI_SETINDICATORCURRENT, (uptr_t) indic, 0);
1087 void sci_indicator_fill(ScintillaObject *sci, gint pos, gint len)
1089 SSM(sci, SCI_INDICATORFILLRANGE, (uptr_t) pos, len);
1094 * Clears the currently set indicator from a range of text.
1095 * Starting at @a pos, @a len characters long.
1096 * In order to make this function properly, you need to set the current indicator before with
1097 * @ref sci_indicator_set().
1099 * @param sci Scintilla widget.
1100 * @param pos Starting position.
1101 * @param len Length.
1103 * @since 0.16
1105 void sci_indicator_clear(ScintillaObject *sci, gint pos, gint len)
1107 SSM(sci, SCI_INDICATORCLEARRANGE, (uptr_t) pos, len);
1111 void sci_select_all(ScintillaObject *sci)
1113 SSM(sci, SCI_SELECTALL, 0, 0);
1117 gint sci_get_line_indent_position(ScintillaObject *sci, gint line)
1119 return (gint) SSM(sci, SCI_GETLINEINDENTPOSITION, (uptr_t) line, 0);
1123 void sci_set_autoc_max_height(ScintillaObject *sci, gint val)
1125 SSM(sci, SCI_AUTOCSETMAXHEIGHT, (uptr_t) val, 0);
1129 /** Finds a matching brace at @a pos.
1130 * @param sci Scintilla widget.
1131 * @param pos Position.
1132 * @return Matching brace position.
1134 * @since 0.15
1136 gint sci_find_matching_brace(ScintillaObject *sci, gint pos)
1138 return (gint) SSM(sci, SCI_BRACEMATCH, (uptr_t) pos, 0);
1142 gint sci_get_overtype(ScintillaObject *sci)
1144 return (gint) SSM(sci, SCI_GETOVERTYPE, 0, 0);
1148 void sci_set_tab_indents(ScintillaObject *sci, gboolean set)
1150 SSM(sci, SCI_SETTABINDENTS, set != FALSE, 0);
1154 void sci_set_use_tabs(ScintillaObject *sci, gboolean set)
1156 SSM(sci, SCI_SETUSETABS, set != FALSE, 0);
1160 gint sci_get_pos_at_line_sel_start(ScintillaObject *sci, gint line)
1162 return (gint) SSM(sci, SCI_GETLINESELSTARTPOSITION, (uptr_t) line, 0);
1166 gint sci_get_pos_at_line_sel_end(ScintillaObject *sci, gint line)
1168 return (gint) SSM(sci, SCI_GETLINESELENDPOSITION, (uptr_t) line, 0);
1172 /** Gets selection mode.
1173 * @param sci Scintilla widget.
1174 * @return Selection mode. */
1175 gint sci_get_selection_mode(ScintillaObject *sci)
1177 return (gint) SSM(sci, SCI_GETSELECTIONMODE, 0, 0);
1181 /** Sets selection mode.
1182 * @param sci Scintilla widget.
1183 * @param mode Mode. */
1184 void sci_set_selection_mode(ScintillaObject *sci, gint mode)
1186 SSM(sci, SCI_SETSELECTIONMODE, (uptr_t) mode, 0);
1190 void sci_set_scrollbar_mode(ScintillaObject *sci, gboolean visible)
1192 SSM(sci, SCI_SETHSCROLLBAR, visible != FALSE, 0);
1193 SSM(sci, SCI_SETVSCROLLBAR, visible != FALSE, 0);
1197 /** Sets the indentation of a line.
1198 * @param sci Scintilla widget.
1199 * @param line Line to indent.
1200 * @param indent Indentation width.
1202 * @since 0.19
1204 void sci_set_line_indentation(ScintillaObject *sci, gint line, gint indent)
1206 SSM(sci, SCI_SETLINEINDENTATION, (uptr_t) line, indent);
1210 /** Gets the indentation width of a line.
1211 * @param sci Scintilla widget.
1212 * @param line Line to get the indentation from.
1213 * @return Indentation width.
1215 * @since 0.19
1217 gint sci_get_line_indentation(ScintillaObject *sci, gint line)
1219 return (gint) SSM(sci, SCI_GETLINEINDENTATION, (uptr_t) line, 0);
1223 void sci_set_caret_policy_x(ScintillaObject *sci, gint policy, gint slop)
1225 SSM(sci, SCI_SETXCARETPOLICY, (uptr_t) policy, slop);
1229 void sci_set_caret_policy_y(ScintillaObject *sci, gint policy, gint slop)
1231 SSM(sci, SCI_SETYCARETPOLICY, (uptr_t) policy, slop);
1235 void sci_set_scroll_stop_at_last_line(ScintillaObject *sci, gboolean set)
1237 SSM(sci, SCI_SETENDATLASTLINE, set != FALSE, 0);
1241 void sci_cancel(ScintillaObject *sci)
1243 SSM(sci, SCI_CANCEL, 0, 0);
1247 gint sci_get_target_end(ScintillaObject *sci)
1249 return (gint) SSM(sci, SCI_GETTARGETEND, 0, 0);
1253 gint sci_get_position_after(ScintillaObject *sci, gint start)
1255 return (gint) SSM(sci, SCI_POSITIONAFTER, (uptr_t) start, 0);
1259 void sci_lines_join(ScintillaObject *sci)
1261 SSM(sci, SCI_LINESJOIN, 0, 0);
1265 gint sci_text_width(ScintillaObject *sci, gint styleNumber, const gchar *text)
1267 return (gint) SSM(sci, SCI_TEXTWIDTH, (uptr_t) styleNumber, (sptr_t) text);
1271 void sci_move_selected_lines_down(ScintillaObject *sci)
1273 SSM(sci, SCI_MOVESELECTEDLINESDOWN, 0, 0);
1277 void sci_move_selected_lines_up(ScintillaObject *sci)
1279 SSM(sci, SCI_MOVESELECTEDLINESUP, 0, 0);
1283 gint sci_word_start_position(ScintillaObject *sci, gint position, gboolean onlyWordCharacters)
1285 return SSM(sci, SCI_WORDSTARTPOSITION, position, onlyWordCharacters);
1289 gint sci_word_end_position(ScintillaObject *sci, gint position, gboolean onlyWordCharacters)
1291 return SSM(sci, SCI_WORDENDPOSITION, position, onlyWordCharacters);