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().
38 #include "sciwrappers.h"
47 sptr_t
sci_send_message_internal (const gchar
*file
, guint line
, ScintillaObject
*sci
,
48 guint msg
, uptr_t wparam
, sptr_t lparam
)
53 scintilla_send_message(sci
, SCI_SETSTATUS
, 0, 0);
54 result
= scintilla_send_message(sci
, msg
, wparam
, lparam
);
55 status
= scintilla_send_message(sci
, SCI_GETSTATUS
, 0, 0);
59 const gchar
*sub_msg
= "unknown";
62 case SC_STATUS_FAILURE
:
63 sub_msg
= "generic failure";
65 case SC_STATUS_BADALLOC
:
66 sub_msg
= "memory is exhausted";
68 case SC_STATUS_WARN_REGEX
:
69 sub_msg
= "regular expression is invalid";
72 if (status
>= SC_STATUS_WARN_START
)
73 sub_msg
= "unknown warning";
75 sub_msg
= "unknown failure";
78 #define SCI_STATUS_FORMAT_STRING "%s:%u: scintilla has non-zero status " \
79 "code '%d' after sending message '%u' to instance '%p' with " \
80 "wParam='%lu' and lParam='%ld': %s"
81 if (status
>= SC_STATUS_WARN_START
)
83 g_warning(SCI_STATUS_FORMAT_STRING
, file
, line
, status
, msg
,
84 (gpointer
)sci
, wparam
, lparam
, sub_msg
);
88 g_critical(SCI_STATUS_FORMAT_STRING
, file
, line
, status
, msg
,
89 (gpointer
)sci
, wparam
, lparam
, sub_msg
);
98 /* line numbers visibility */
99 void sci_set_line_numbers(ScintillaObject
*sci
, gboolean set
)
104 gint len
= (gint
) SSM(sci
, SCI_GETLINECOUNT
, 0, 0);
107 g_snprintf(tmp_str
, 15, "_%d", len
);
108 width
= sci_text_width(sci
, STYLE_LINENUMBER
, tmp_str
);
109 SSM(sci
, SCI_SETMARGINWIDTHN
, 0, width
);
110 SSM(sci
, SCI_SETMARGINSENSITIVEN
, 0, FALSE
); /* use default behaviour */
114 SSM(sci
, SCI_SETMARGINWIDTHN
, 0, 0);
119 void sci_set_mark_long_lines(ScintillaObject
*sci
, gint type
, gint column
, const gchar
*colour
)
121 glong colour_val
= utils_parse_color_to_bgr(colour
); /* Scintilla uses a "long" value */
129 SSM(sci
, SCI_SETEDGEMODE
, EDGE_LINE
, 0);
134 SSM(sci
, SCI_SETEDGEMODE
, EDGE_BACKGROUND
, 0);
139 SSM(sci
, SCI_SETEDGEMODE
, EDGE_NONE
, 0);
143 SSM(sci
, SCI_SETEDGECOLUMN
, (uptr_t
) column
, 0);
144 SSM(sci
, SCI_SETEDGECOLOUR
, (uptr_t
) colour_val
, 0);
148 /* symbol margin visibility */
149 void sci_set_symbol_margin(ScintillaObject
*sci
, gboolean set
)
153 SSM(sci
, SCI_SETMARGINWIDTHN
, 1, 16);
154 SSM(sci
, SCI_SETMARGINSENSITIVEN
, 1, TRUE
);
158 SSM(sci
, SCI_SETMARGINWIDTHN
, 1, 0);
159 SSM(sci
, SCI_SETMARGINSENSITIVEN
, 1, FALSE
);
164 /* folding margin visibility */
165 void sci_set_folding_margin_visible(ScintillaObject
*sci
, gboolean set
)
169 SSM(sci
, SCI_SETMARGINWIDTHN
, 2, 12);
170 SSM(sci
, SCI_SETMARGINSENSITIVEN
, 2, TRUE
);
174 SSM(sci
, SCI_SETMARGINSENSITIVEN
, 2, FALSE
);
175 SSM(sci
, SCI_SETMARGINWIDTHN
, 2, 0);
181 void sci_set_visible_eols(ScintillaObject
*sci
, gboolean set
)
183 SSM(sci
, SCI_SETVIEWEOL
, set
!= FALSE
, 0);
187 void sci_set_visible_white_spaces(ScintillaObject
*sci
, gboolean set
)
190 SSM(sci
, SCI_SETVIEWWS
, SCWS_VISIBLEALWAYS
, 0);
192 SSM(sci
, SCI_SETVIEWWS
, SCWS_INVISIBLE
, 0);
196 void sci_set_lines_wrapped(ScintillaObject
*sci
, gboolean set
)
199 SSM(sci
, SCI_SETWRAPMODE
, SC_WRAP_WORD
, 0);
201 SSM(sci
, SCI_SETWRAPMODE
, SC_WRAP_NONE
, 0);
205 gint
sci_get_eol_mode(ScintillaObject
*sci
)
207 return (gint
) SSM(sci
, SCI_GETEOLMODE
, 0, 0);
211 void sci_set_eol_mode(ScintillaObject
*sci
, gint eolmode
)
213 SSM(sci
, SCI_SETEOLMODE
, (uptr_t
) eolmode
, 0);
217 void sci_convert_eols(ScintillaObject
*sci
, gint eolmode
)
219 SSM(sci
, SCI_CONVERTEOLS
, (uptr_t
) eolmode
, 0);
223 void sci_add_text(ScintillaObject
*sci
, const gchar
*text
)
226 { /* if null text is passed scintilla will segfault */
227 SSM(sci
, SCI_ADDTEXT
, strlen(text
), (sptr_t
) text
);
233 * @param sci Scintilla widget.
234 * @param text Text. */
236 void sci_set_text(ScintillaObject
*sci
, const gchar
*text
)
238 if( text
!= NULL
){ /* if null text is passed to scintilla will segfault */
239 SSM(sci
, SCI_SETTEXT
, 0, (sptr_t
) text
);
244 gboolean
sci_can_undo(ScintillaObject
*sci
)
246 return SSM(sci
, SCI_CANUNDO
, 0, 0) != FALSE
;
250 gboolean
sci_can_redo(ScintillaObject
*sci
)
252 return SSM(sci
, SCI_CANREDO
, 0, 0) != FALSE
;
256 void sci_undo(ScintillaObject
*sci
)
258 if (sci_can_undo(sci
))
259 SSM(sci
, SCI_UNDO
, 0, 0);
263 void sci_redo(ScintillaObject
*sci
)
265 if (sci_can_redo(sci
))
266 SSM(sci
, SCI_REDO
, 0, 0);
270 /** Begins grouping a set of edits together as one Undo action.
271 * You must call sci_end_undo_action() after making your edits.
272 * @param sci Scintilla @c GtkWidget. */
274 void sci_start_undo_action(ScintillaObject
*sci
)
276 SSM(sci
, SCI_BEGINUNDOACTION
, 0, 0);
280 /** Ends grouping a set of edits together as one Undo action.
281 * @param sci Scintilla @c GtkWidget.
282 * @see sci_start_undo_action(). */
284 void sci_end_undo_action(ScintillaObject
*sci
)
286 SSM(sci
, SCI_ENDUNDOACTION
, 0, 0);
290 void sci_set_undo_collection(ScintillaObject
*sci
, gboolean set
)
292 SSM(sci
, SCI_SETUNDOCOLLECTION
, set
!= FALSE
, 0);
296 void sci_empty_undo_buffer(ScintillaObject
*sci
)
298 SSM(sci
, SCI_EMPTYUNDOBUFFER
, 0, 0);
302 gboolean
sci_is_modified(ScintillaObject
*sci
)
304 return (SSM(sci
, SCI_GETMODIFY
, 0, 0) != 0);
308 void sci_zoom_in(ScintillaObject
*sci
)
310 SSM(sci
, SCI_ZOOMIN
, 0, 0);
314 void sci_zoom_out(ScintillaObject
*sci
)
316 SSM(sci
, SCI_ZOOMOUT
, 0, 0);
320 void sci_zoom_off(ScintillaObject
*sci
)
322 SSM(sci
, SCI_SETZOOM
, 0, 0);
326 /** Sets a line marker.
327 * @param sci Scintilla widget.
328 * @param line_number Line number.
329 * @param marker Marker number. */
331 void sci_set_marker_at_line(ScintillaObject
*sci
, gint line_number
, gint marker
)
333 SSM(sci
, SCI_MARKERADD
, (uptr_t
) line_number
, marker
);
337 /** Deletes a line marker.
338 * @param sci Scintilla widget.
339 * @param line_number Line number.
340 * @param marker Marker number. */
342 void sci_delete_marker_at_line(ScintillaObject
*sci
, gint line_number
, gint marker
)
344 SSM(sci
, SCI_MARKERDELETE
, (uptr_t
) line_number
, marker
);
348 /** Checks if a line has a marker set.
349 * @param sci Scintilla widget.
350 * @param line Line number.
351 * @param marker Marker number.
352 * @return Whether it's set. */
354 gboolean
sci_is_marker_set_at_line(ScintillaObject
*sci
, gint line
, gint marker
)
358 state
= (gint
) SSM(sci
, SCI_MARKERGET
, (uptr_t
) line
, 0);
359 return (state
& (1 << marker
));
363 void sci_toggle_marker_at_line(ScintillaObject
*sci
, gint line
, gint marker
)
365 gboolean set
= sci_is_marker_set_at_line(sci
, line
, marker
);
368 sci_set_marker_at_line(sci
, line
, marker
);
370 sci_delete_marker_at_line(sci
, line
, marker
);
374 /* Returns the line number of the next marker that matches marker_mask, or -1.
375 * marker_mask is a bitor of 1 << marker_index. (See MarkerHandleSet::MarkValue()).
376 * Note: If there is a marker on the line, it returns the same line. */
377 gint
sci_marker_next(ScintillaObject
*sci
, gint line
, gint marker_mask
, gboolean wrap
)
381 marker_line
= (gint
) SSM(sci
, SCI_MARKERNEXT
, (uptr_t
) line
, marker_mask
);
382 if (wrap
&& marker_line
== -1)
383 marker_line
= (gint
) SSM(sci
, SCI_MARKERNEXT
, 0, marker_mask
);
388 /* Returns the line number of the previous marker that matches marker_mask, or -1.
389 * marker_mask is a bitor of 1 << marker_index. (See MarkerHandleSet::MarkValue()).
390 * Note: If there is a marker on the line, it returns the same line. */
391 gint
sci_marker_previous(ScintillaObject
*sci
, gint line
, gint marker_mask
, gboolean wrap
)
395 marker_line
= (gint
) SSM(sci
, SCI_MARKERPREVIOUS
, (uptr_t
) line
, marker_mask
);
396 if (wrap
&& marker_line
== -1)
398 gint len
= sci_get_length(sci
);
399 gint last_line
= sci_get_line_from_position(sci
, len
- 1);
401 marker_line
= (gint
) SSM(sci
, SCI_MARKERPREVIOUS
, (uptr_t
) last_line
, marker_mask
);
407 /** Gets the line number from @a position.
408 * @param sci Scintilla widget.
409 * @param position Position.
410 * @return The line. */
412 gint
sci_get_line_from_position(ScintillaObject
*sci
, gint position
)
414 return (gint
) SSM(sci
, SCI_LINEFROMPOSITION
, (uptr_t
) position
, 0);
418 /** Gets the column number relative to the start of the line that @a position is on.
419 * @param sci Scintilla widget.
420 * @param position Position.
421 * @return The column. */
423 gint
sci_get_col_from_position(ScintillaObject
*sci
, gint position
)
425 return (gint
) SSM(sci
, SCI_GETCOLUMN
, (uptr_t
) position
, 0);
429 gint
sci_get_position_from_col(ScintillaObject
*sci
, gint line
, gint col
)
431 return (gint
) SSM(sci
, SCI_FINDCOLUMN
, line
, col
);
435 /** Gets the position for the start of @a line.
436 * @param sci Scintilla widget.
438 * @return Position. */
440 gint
sci_get_position_from_line(ScintillaObject
*sci
, gint line
)
442 return (gint
) SSM(sci
, SCI_POSITIONFROMLINE
, (uptr_t
) line
, 0);
446 /** Gets the cursor position.
447 * @param sci Scintilla widget.
448 * @return Position. */
450 gint
sci_get_current_position(ScintillaObject
*sci
)
452 return (gint
) SSM(sci
, SCI_GETCURRENTPOS
, 0, 0);
456 gint
sci_get_cursor_virtual_space(ScintillaObject
*sci
)
458 gint selection_mode
= sci_get_selection_mode(sci
);
460 return selection_mode
== SC_SEL_RECTANGLE
|| selection_mode
== SC_SEL_THIN
?
461 SSM(sci
, SCI_GETRECTANGULARSELECTIONCARETVIRTUALSPACE
, 0, 0) :
462 SSM(sci
, SCI_GETSELECTIONNCARETVIRTUALSPACE
,
463 SSM(sci
, SCI_GETMAINSELECTION
, 0, 0), 0);
467 /** Sets the cursor position.
468 * @param sci Scintilla widget.
469 * @param position Position.
470 * @param scroll_to_caret Whether to scroll the cursor in view. */
472 void sci_set_current_position(ScintillaObject
*sci
, gint position
, gboolean scroll_to_caret
)
475 SSM(sci
, SCI_GOTOPOS
, (uptr_t
) position
, 0);
478 SSM(sci
, SCI_SETCURRENTPOS
, (uptr_t
) position
, 0);
479 SSM(sci
, SCI_SETANCHOR
, (uptr_t
) position
, 0); /* to avoid creation of a selection */
481 SSM(sci
, SCI_CHOOSECARETX
, 0, 0);
485 /* Set the cursor line without scrolling the view.
486 * Use sci_goto_line() to also scroll. */
487 void sci_set_current_line(ScintillaObject
*sci
, gint line
)
489 gint pos
= sci_get_position_from_line(sci
, line
);
490 sci_set_current_position(sci
, pos
, FALSE
);
494 /** Gets the total number of lines.
495 * @param sci Scintilla widget.
496 * @return The line count. */
498 gint
sci_get_line_count(ScintillaObject
*sci
)
500 return (gint
) SSM(sci
, SCI_GETLINECOUNT
, 0, 0);
504 /** Sets the selection start position.
505 * @param sci Scintilla widget.
506 * @param position Position. */
508 void sci_set_selection_start(ScintillaObject
*sci
, gint position
)
510 SSM(sci
, SCI_SETSELECTIONSTART
, (uptr_t
) position
, 0);
514 /** Sets the selection end position.
515 * @param sci Scintilla widget.
516 * @param position Position. */
518 void sci_set_selection_end(ScintillaObject
*sci
, gint position
)
520 SSM(sci
, SCI_SETSELECTIONEND
, (uptr_t
) position
, 0);
524 void sci_set_selection(ScintillaObject
*sci
, gint anchorPos
, gint currentPos
)
526 SSM(sci
, SCI_SETSEL
, (uptr_t
) anchorPos
, currentPos
);
530 /** Gets the position at the end of a line
531 * @param sci Scintilla widget.
533 * @return The position at the end of the line. */
535 gint
sci_get_line_end_position(ScintillaObject
*sci
, gint line
)
537 return (gint
) SSM(sci
, SCI_GETLINEENDPOSITION
, (uptr_t
) line
, 0);
541 void sci_cut(ScintillaObject
*sci
)
543 SSM(sci
, SCI_CUT
, 0, 0);
547 void sci_copy(ScintillaObject
*sci
)
549 SSM(sci
, SCI_COPY
, 0, 0);
553 void sci_paste(ScintillaObject
*sci
)
555 SSM(sci
, SCI_PASTE
, 0, 0);
559 void sci_clear(ScintillaObject
*sci
)
561 SSM(sci
, SCI_CLEAR
, 0, 0);
565 /** Gets the selection start position.
566 * @param sci Scintilla widget.
567 * @return Position. */
569 gint
sci_get_selection_start(ScintillaObject
*sci
)
571 return (gint
) SSM(sci
, SCI_GETSELECTIONSTART
, 0, 0);
575 /** Gets the selection end position.
576 * @param sci Scintilla widget.
577 * @return Position. */
579 gint
sci_get_selection_end(ScintillaObject
*sci
)
581 return (gint
) SSM(sci
, SCI_GETSELECTIONEND
, 0, 0);
585 /** Replaces selection.
586 * @param sci Scintilla widget.
587 * @param text Text. */
589 void sci_replace_sel(ScintillaObject
*sci
, const gchar
*text
)
591 SSM(sci
, SCI_REPLACESEL
, 0, (sptr_t
) text
);
595 /** Gets the length of all text.
596 * @param sci Scintilla widget.
599 gint
sci_get_length(ScintillaObject
*sci
)
601 return (gint
) SSM(sci
, SCI_GETLENGTH
, 0, 0);
605 /** Gets the currently used lexer
606 * @param sci Scintilla widget.
607 * @returns The lexer ID
610 gint
sci_get_lexer(ScintillaObject
*sci
)
612 return (gint
) SSM(sci
, SCI_GETLEXER
, 0, 0);
616 void sci_set_lexer(ScintillaObject
*sci
, guint lexer_id
)
618 gint old
= sci_get_lexer(sci
);
620 SSM(sci
, SCI_SETLEXER
, lexer_id
, 0);
622 if (old
!= (gint
)lexer_id
)
623 SSM(sci
, SCI_CLEARDOCUMENTSTYLE
, 0, 0);
627 /** Gets line length.
628 * @param sci Scintilla widget.
629 * @param line Line number.
632 gint
sci_get_line_length(ScintillaObject
*sci
, gint line
)
634 return (gint
) SSM(sci
, SCI_LINELENGTH
, (uptr_t
) line
, 0);
638 /* safe way to read Scintilla string into new memory.
639 * works with any string buffer messages that follow the Windows message convention. */
640 gchar
*sci_get_string(ScintillaObject
*sci
, guint msg
, gulong wParam
)
642 gint size
= (gint
) SSM(sci
, msg
, wParam
, 0);
643 gchar
*str
= g_malloc(size
+ 1);
645 SSM(sci
, msg
, wParam
, (sptr_t
) str
);
646 str
[size
] = '\0'; /* ensure termination, needed for SCI_GETLINE */
651 /** Gets line contents.
652 * @param sci Scintilla widget.
653 * @param line_num Line number.
654 * @return A @c NULL-terminated copy of the line text. */
656 gchar
*sci_get_line(ScintillaObject
*sci
, gint line_num
)
658 return sci_get_string(sci
, SCI_GETLINE
, (gulong
) line_num
);
663 * @deprecated sci_get_text is deprecated and should not be used in newly-written code.
664 * Use sci_get_contents() instead.
666 * @param sci Scintilla widget.
667 * @param len Length of @a text buffer, usually sci_get_length() + 1.
668 * @param text Text buffer; must be allocated @a len + 1 bytes for null-termination. */
670 void sci_get_text(ScintillaObject
*sci
, gint len
, gchar
*text
)
672 SSM(sci
, SCI_GETTEXT
, (uptr_t
) len
, (sptr_t
) text
);
676 /** Allocates and fills a buffer with text from the start of the document.
677 * @param sci Scintilla widget.
678 * @param buffer_len Buffer length to allocate, including the terminating
679 * null char, e.g. sci_get_length() + 1. Alternatively use @c -1 to get all
680 * text (since Geany 1.23).
681 * @return A copy of the text. Should be freed when no longer needed.
686 gchar
*sci_get_contents(ScintillaObject
*sci
, gint buffer_len
)
691 buffer_len
= sci_get_length(sci
) + 1;
693 text
= g_malloc(buffer_len
);
694 SSM(sci
, SCI_GETTEXT
, (uptr_t
) buffer_len
, (sptr_t
) text
);
699 /** Gets selected text.
700 * @deprecated sci_get_selected_text is deprecated and should not be used in newly-written code.
701 * Use sci_get_selection_contents() instead.
703 * @param sci Scintilla widget.
704 * @param text Text buffer; must be allocated sci_get_selected_text_length() + 1 bytes
705 * for null-termination. */
707 void sci_get_selected_text(ScintillaObject
*sci
, gchar
*text
)
709 SSM(sci
, SCI_GETSELTEXT
, 0, (sptr_t
) text
);
713 /** Gets selected text.
714 * @param sci Scintilla widget.
716 * @return The selected text. Should be freed when no longer needed.
721 gchar
*sci_get_selection_contents(ScintillaObject
*sci
)
723 return sci_get_string(sci
, SCI_GETSELTEXT
, 0);
727 /** Gets selected text length.
728 * @param sci Scintilla widget.
731 gint
sci_get_selected_text_length(ScintillaObject
*sci
)
733 return (gint
) SSM(sci
, SCI_GETSELTEXT
, 0, 0);
737 gint
sci_get_position_from_xy(ScintillaObject
*sci
, gint x
, gint y
, gboolean nearby
)
739 /* for nearby return -1 if there is no character near to the x,y point. */
740 return (gint
) SSM(sci
, (nearby
) ? SCI_POSITIONFROMPOINTCLOSE
: SCI_POSITIONFROMPOINT
, (uptr_t
) x
, y
);
744 /** Checks if a line is visible (folding may have hidden it).
745 * @param sci Scintilla widget.
746 * @param line Line number.
747 * @return Whether @a line will be drawn on the screen. */
749 gboolean
sci_get_line_is_visible(ScintillaObject
*sci
, gint line
)
751 return SSM(sci
, SCI_GETLINEVISIBLE
, (uptr_t
) line
, 0) != FALSE
;
755 /** Makes @a line visible (folding may have hidden it).
756 * @param sci Scintilla widget.
757 * @param line Line number. */
759 void sci_ensure_line_is_visible(ScintillaObject
*sci
, gint line
)
761 SSM(sci
, SCI_ENSUREVISIBLE
, (uptr_t
) line
, 0);
765 gint
sci_get_fold_level(ScintillaObject
*sci
, gint line
)
767 return (gint
) SSM(sci
, SCI_GETFOLDLEVEL
, (uptr_t
) line
, 0);
771 /* Get the line number of the fold point before start_line, or -1 if there isn't one */
772 gint
sci_get_fold_parent(ScintillaObject
*sci
, gint start_line
)
774 return (gint
) SSM(sci
, SCI_GETFOLDPARENT
, (uptr_t
) start_line
, 0);
778 void sci_toggle_fold(ScintillaObject
*sci
, gint line
)
780 SSM(sci
, SCI_TOGGLEFOLD
, (uptr_t
) line
, 0);
784 gboolean
sci_get_fold_expanded(ScintillaObject
*sci
, gint line
)
786 return SSM(sci
, SCI_GETFOLDEXPANDED
, (uptr_t
) line
, 0) != FALSE
;
790 void sci_colourise(ScintillaObject
*sci
, gint start
, gint end
)
792 SSM(sci
, SCI_COLOURISE
, (uptr_t
) start
, end
);
796 void sci_clear_all(ScintillaObject
*sci
)
798 SSM(sci
, SCI_CLEARALL
, 0, 0);
802 gint
sci_get_end_styled(ScintillaObject
*sci
)
804 return (gint
) SSM(sci
, SCI_GETENDSTYLED
, 0, 0);
808 void sci_set_tab_width(ScintillaObject
*sci
, gint width
)
810 SSM(sci
, SCI_SETTABWIDTH
, (uptr_t
) width
, 0);
814 /** Gets display tab width (this is not indent width, see GeanyIndentPrefs).
815 * @param sci Scintilla widget.
821 gint
sci_get_tab_width(ScintillaObject
*sci
)
823 return (gint
) SSM(sci
, SCI_GETTABWIDTH
, 0, 0);
827 /** Gets a character.
828 * @param sci Scintilla widget.
829 * @param pos Position.
832 gchar
sci_get_char_at(ScintillaObject
*sci
, gint pos
)
834 return (gchar
) SSM(sci
, SCI_GETCHARAT
, (uptr_t
) pos
, 0);
838 void sci_set_savepoint(ScintillaObject
*sci
)
840 SSM(sci
, SCI_SETSAVEPOINT
, 0, 0);
844 void sci_set_indentation_guides(ScintillaObject
*sci
, gint mode
)
846 SSM(sci
, SCI_SETINDENTATIONGUIDES
, (uptr_t
) mode
, 0);
850 void sci_use_popup(ScintillaObject
*sci
, gboolean enable
)
852 SSM(sci
, SCI_USEPOPUP
, enable
!= FALSE
, 0);
856 /** Checks if there's a selection.
857 * @param sci Scintilla widget.
858 * @return Whether a selection is present.
863 gboolean
sci_has_selection(ScintillaObject
*sci
)
865 if (SSM(sci
, SCI_GETSELECTIONEND
, 0, 0) - SSM(sci
, SCI_GETSELECTIONSTART
, 0, 0))
872 void sci_goto_pos(ScintillaObject
*sci
, gint pos
, gboolean unfold
)
874 if (unfold
) SSM(sci
, SCI_ENSUREVISIBLE
, (uptr_t
) SSM(sci
, SCI_LINEFROMPOSITION
, (uptr_t
) pos
, 0), 0);
875 SSM(sci
, SCI_GOTOPOS
, (uptr_t
) pos
, 0);
879 void sci_set_search_anchor(ScintillaObject
*sci
)
881 SSM(sci
, SCI_SEARCHANCHOR
, 0, 0);
885 /* removes a selection if pos < 0 */
886 void sci_set_anchor(ScintillaObject
*sci
, gint pos
)
889 pos
= sci_get_current_position(sci
);
891 SSM(sci
, SCI_SETANCHOR
, (uptr_t
) pos
, 0);
895 /** Scrolls the cursor in view.
896 * @param sci Scintilla widget. */
898 void sci_scroll_caret(ScintillaObject
*sci
)
900 SSM(sci
, SCI_SCROLLCARET
, 0, 0);
904 void sci_scroll_columns(ScintillaObject
*sci
, gint columns
)
906 SSM(sci
, SCI_LINESCROLL
, (uptr_t
) columns
, 0);
910 gint
sci_search_next(ScintillaObject
*sci
, gint flags
, const gchar
*text
)
912 /* FIXME: SCI_SEACHNEXT() actually returns long */
913 return (gint
) SSM(sci
, SCI_SEARCHNEXT
, (uptr_t
) flags
, (sptr_t
) text
);
917 gint
sci_search_prev(ScintillaObject
*sci
, gint flags
, const gchar
*text
)
919 /* FIXME: SCI_SEACHPREV() actually returns long */
920 return (gint
) SSM(sci
, SCI_SEARCHPREV
, (uptr_t
) flags
, (sptr_t
) text
);
924 /** Finds text in the document.
925 * The @a ttf argument should be a pointer to a Sci_TextToFind structure which contains
926 * the text to find and the range in which the text should be searched.
928 * Please refer to the Scintilla documentation for a more detailed description.
930 * @param sci Scintilla widget.
931 * @param flags Bitmask of Scintilla search flags (@c SCFIND_*, see Scintilla documentation).
932 * @param ttf Pointer to a TextToFind structure which contains the text to find and the range.
933 * @return The position of the start of the found text if it succeeds, otherwise @c -1.
934 * The @c chrgText.cpMin and @c chrgText.cpMax members of @c TextToFind are filled in
935 * with the start and end positions of the found text.
938 gint
sci_find_text(ScintillaObject
*sci
, gint flags
, struct Sci_TextToFind
*ttf
)
940 return (gint
) SSM(sci
, SCI_FINDTEXT
, (uptr_t
) flags
, (sptr_t
) ttf
);
944 /** Sets the font for a particular style.
945 * @param sci Scintilla widget.
946 * @param style The style.
947 * @param font The font name.
948 * @param size The font size. */
950 void sci_set_font(ScintillaObject
*sci
, gint style
, const gchar
*font
, gint size
)
952 SSM(sci
, SCI_STYLESETFONT
, (uptr_t
) style
, (sptr_t
) font
);
953 SSM(sci
, SCI_STYLESETSIZE
, (uptr_t
) style
, size
);
957 /** Jumps to the specified line in the document.
958 * If @a unfold is set and @a line is hidden by a fold, it is unfolded
959 * first to ensure it is visible.
960 * @param sci Scintilla widget.
962 * @param unfold Whether to unfold first.
965 void sci_goto_line(ScintillaObject
*sci
, gint line
, gboolean unfold
)
967 if (unfold
) SSM(sci
, SCI_ENSUREVISIBLE
, (uptr_t
) line
, 0);
968 SSM(sci
, SCI_GOTOLINE
, (uptr_t
) line
, 0);
972 void sci_marker_delete_all(ScintillaObject
*sci
, gint marker
)
974 SSM(sci
, SCI_MARKERDELETEALL
, (uptr_t
) marker
, 0);
978 /** Gets style ID at @a position.
979 * @param sci Scintilla widget.
980 * @param position Position.
981 * @return Style ID. */
983 gint
sci_get_style_at(ScintillaObject
*sci
, gint position
)
985 return (gint
) SSM(sci
, SCI_GETSTYLEAT
, (uptr_t
) position
, 0);
989 void sci_set_codepage(ScintillaObject
*sci
, gint cp
)
991 g_return_if_fail(cp
== 0 || cp
== SC_CP_UTF8
);
992 SSM(sci
, SCI_SETCODEPAGE
, (uptr_t
) cp
, 0);
996 void sci_assign_cmdkey(ScintillaObject
*sci
, gint key
, gint command
)
998 SSM(sci
, SCI_ASSIGNCMDKEY
, (uptr_t
) key
, command
);
1002 void sci_clear_cmdkey(ScintillaObject
*sci
, gint key
)
1004 SSM(sci
, SCI_CLEARCMDKEY
, (uptr_t
) key
, 0);
1008 /** Gets text between @a start and @a end.
1009 * @deprecated sci_get_text_range is deprecated and should not be used in newly-written code.
1010 * Use sci_get_contents_range() instead.
1012 * @param sci Scintilla widget.
1013 * @param start Start.
1015 * @param text Text will be zero terminated and must be allocated (end - start + 1) bytes. */
1017 void sci_get_text_range(ScintillaObject
*sci
, gint start
, gint end
, gchar
*text
)
1019 struct Sci_TextRange tr
;
1020 tr
.chrg
.cpMin
= start
;
1021 tr
.chrg
.cpMax
= end
;
1022 tr
.lpstrText
= text
;
1023 SSM(sci
, SCI_GETTEXTRANGE
, 0, (sptr_t
) &tr
);
1027 /** Gets text between @a start and @a end.
1028 * @param sci Scintilla widget.
1029 * @param start Start position.
1030 * @param end End position.
1031 * @return The text inside the given range. Should be freed when no longer needed.
1036 gchar
*sci_get_contents_range(ScintillaObject
*sci
, gint start
, gint end
)
1040 g_return_val_if_fail(start
< end
, NULL
);
1042 text
= g_malloc((gsize
) (end
- start
) + 1);
1043 sci_get_text_range(sci
, start
, end
, text
);
1048 void sci_line_duplicate(ScintillaObject
*sci
)
1050 SSM(sci
, SCI_LINEDUPLICATE
, 0, 0);
1054 void sci_selection_duplicate(ScintillaObject
*sci
)
1056 SSM(sci
, SCI_SELECTIONDUPLICATE
, 0, 0);
1061 * @param sci Scintilla widget.
1062 * @param pos Position, or -1 for current.
1063 * @param text Text. */
1065 void sci_insert_text(ScintillaObject
*sci
, gint pos
, const gchar
*text
)
1067 SSM(sci
, SCI_INSERTTEXT
, (uptr_t
) pos
, (sptr_t
) text
);
1072 void sci_set_target_start(ScintillaObject
*sci
, gint start
)
1074 SSM(sci
, SCI_SETTARGETSTART
, (uptr_t
) start
, 0);
1079 void sci_set_target_end(ScintillaObject
*sci
, gint end
)
1081 SSM(sci
, SCI_SETTARGETEND
, (uptr_t
) end
, 0);
1086 gint
sci_replace_target(ScintillaObject
*sci
, const gchar
*text
, gboolean regex
)
1088 return (gint
) SSM(sci
, (regex
) ? SCI_REPLACETARGETRE
: SCI_REPLACETARGET
, (uptr_t
) -1, (sptr_t
) text
);
1092 void sci_set_keywords(ScintillaObject
*sci
, guint k
, const gchar
*text
)
1094 SSM(sci
, SCI_SETKEYWORDS
, k
, (sptr_t
) text
);
1098 void sci_set_readonly(ScintillaObject
*sci
, gboolean readonly
)
1100 SSM(sci
, SCI_SETREADONLY
, readonly
!= FALSE
, 0);
1104 /** Sends Scintilla commands without any parameters.
1105 * @param sci The Scintilla @c GtkWidget.
1106 * @param cmd @c SCI_COMMAND.
1107 * @see http://scintilla.org for the documentation.
1112 void sci_send_command(ScintillaObject
*sci
, gint cmd
)
1114 SSM(sci
, cmd
, 0, 0);
1118 /** Gets current line number.
1119 * @param sci Scintilla widget.
1120 * @return Line number. */
1122 gint
sci_get_current_line(ScintillaObject
*sci
)
1124 return (gint
) SSM(sci
, SCI_LINEFROMPOSITION
, (uptr_t
) SSM(sci
, SCI_GETCURRENTPOS
, 0, 0), 0);
1128 /* Get number of lines partially or fully selected.
1129 * Returns 1 if there is a partial selection on the same line.
1130 * Returns 2 if a whole line is selected including the line break char(s). */
1131 gint
sci_get_lines_selected(ScintillaObject
*sci
)
1133 gint start
= (gint
) SSM(sci
, SCI_GETSELECTIONSTART
, 0, 0);
1134 gint end
= (gint
) SSM(sci
, SCI_GETSELECTIONEND
, 0, 0);
1139 return 0; /* no selection */
1141 line_start
= (gint
) SSM(sci
, SCI_LINEFROMPOSITION
, (uptr_t
) start
, 0);
1142 line_end
= (gint
) SSM(sci
, SCI_LINEFROMPOSITION
, (uptr_t
) end
, 0);
1144 return line_end
- line_start
+ 1;
1148 gint
sci_get_first_visible_line(ScintillaObject
*sci
)
1150 return (gint
) SSM(sci
, SCI_GETFIRSTVISIBLELINE
, 0, 0);
1155 * Sets the current indicator. This is necessary to define an indicator for a range of text or
1156 * clearing indicators for a range of text.
1158 * @param sci Scintilla widget.
1159 * @param indic The indicator number to set.
1161 * @see sci_indicator_clear
1166 void sci_indicator_set(ScintillaObject
*sci
, gint indic
)
1168 SSM(sci
, SCI_SETINDICATORCURRENT
, (uptr_t
) indic
, 0);
1172 void sci_indicator_fill(ScintillaObject
*sci
, gint pos
, gint len
)
1174 SSM(sci
, SCI_INDICATORFILLRANGE
, (uptr_t
) pos
, len
);
1179 * Clears the currently set indicator from a range of text.
1180 * Starting at @a pos, @a len characters long.
1181 * In order to make this function properly, you need to set the current indicator before with
1182 * @ref sci_indicator_set().
1184 * @param sci Scintilla widget.
1185 * @param pos Starting position.
1186 * @param len Length.
1191 void sci_indicator_clear(ScintillaObject
*sci
, gint pos
, gint len
)
1193 SSM(sci
, SCI_INDICATORCLEARRANGE
, (uptr_t
) pos
, len
);
1197 void sci_select_all(ScintillaObject
*sci
)
1199 SSM(sci
, SCI_SELECTALL
, 0, 0);
1203 gint
sci_get_line_indent_position(ScintillaObject
*sci
, gint line
)
1205 return (gint
) SSM(sci
, SCI_GETLINEINDENTPOSITION
, (uptr_t
) line
, 0);
1209 void sci_set_autoc_max_height(ScintillaObject
*sci
, gint val
)
1211 SSM(sci
, SCI_AUTOCSETMAXHEIGHT
, (uptr_t
) val
, 0);
1215 /** Finds a matching brace at @a pos.
1216 * @param sci Scintilla widget.
1217 * @param pos Position.
1218 * @return Matching brace position.
1223 gint
sci_find_matching_brace(ScintillaObject
*sci
, gint pos
)
1225 return (gint
) SSM(sci
, SCI_BRACEMATCH
, (uptr_t
) pos
, 0);
1229 gint
sci_get_overtype(ScintillaObject
*sci
)
1231 return (gint
) SSM(sci
, SCI_GETOVERTYPE
, 0, 0);
1235 void sci_set_tab_indents(ScintillaObject
*sci
, gboolean set
)
1237 SSM(sci
, SCI_SETTABINDENTS
, set
!= FALSE
, 0);
1241 void sci_set_use_tabs(ScintillaObject
*sci
, gboolean set
)
1243 SSM(sci
, SCI_SETUSETABS
, set
!= FALSE
, 0);
1247 gint
sci_get_pos_at_line_sel_start(ScintillaObject
*sci
, gint line
)
1249 return (gint
) SSM(sci
, SCI_GETLINESELSTARTPOSITION
, (uptr_t
) line
, 0);
1253 gint
sci_get_pos_at_line_sel_end(ScintillaObject
*sci
, gint line
)
1255 return (gint
) SSM(sci
, SCI_GETLINESELENDPOSITION
, (uptr_t
) line
, 0);
1259 /** Gets selection mode.
1260 * @param sci Scintilla widget.
1261 * @return Selection mode. */
1263 gint
sci_get_selection_mode(ScintillaObject
*sci
)
1265 return (gint
) SSM(sci
, SCI_GETSELECTIONMODE
, 0, 0);
1269 /** Sets selection mode.
1270 * @param sci Scintilla widget.
1271 * @param mode Mode. */
1273 void sci_set_selection_mode(ScintillaObject
*sci
, gint mode
)
1275 SSM(sci
, SCI_SETSELECTIONMODE
, (uptr_t
) mode
, 0);
1279 void sci_set_scrollbar_mode(ScintillaObject
*sci
, gboolean visible
)
1281 SSM(sci
, SCI_SETHSCROLLBAR
, visible
!= FALSE
, 0);
1282 SSM(sci
, SCI_SETVSCROLLBAR
, visible
!= FALSE
, 0);
1286 /** Sets the indentation of a line.
1287 * @param sci Scintilla widget.
1288 * @param line Line to indent.
1289 * @param indent Indentation width.
1294 void sci_set_line_indentation(ScintillaObject
*sci
, gint line
, gint indent
)
1296 SSM(sci
, SCI_SETLINEINDENTATION
, (uptr_t
) line
, indent
);
1300 /** Gets the indentation width of a line.
1301 * @param sci Scintilla widget.
1302 * @param line Line to get the indentation from.
1303 * @return Indentation width.
1308 gint
sci_get_line_indentation(ScintillaObject
*sci
, gint line
)
1310 return (gint
) SSM(sci
, SCI_GETLINEINDENTATION
, (uptr_t
) line
, 0);
1314 void sci_set_caret_policy_x(ScintillaObject
*sci
, gint policy
, gint slop
)
1316 SSM(sci
, SCI_SETXCARETPOLICY
, (uptr_t
) policy
, slop
);
1320 void sci_set_caret_policy_y(ScintillaObject
*sci
, gint policy
, gint slop
)
1322 SSM(sci
, SCI_SETYCARETPOLICY
, (uptr_t
) policy
, slop
);
1326 void sci_set_scroll_stop_at_last_line(ScintillaObject
*sci
, gboolean set
)
1328 SSM(sci
, SCI_SETENDATLASTLINE
, set
!= FALSE
, 0);
1332 void sci_cancel(ScintillaObject
*sci
)
1334 SSM(sci
, SCI_CANCEL
, 0, 0);
1338 gint
sci_get_position_after(ScintillaObject
*sci
, gint start
)
1340 return (gint
) SSM(sci
, SCI_POSITIONAFTER
, (uptr_t
) start
, 0);
1344 void sci_lines_join(ScintillaObject
*sci
)
1346 SSM(sci
, SCI_LINESJOIN
, 0, 0);
1350 gint
sci_text_width(ScintillaObject
*sci
, gint styleNumber
, const gchar
*text
)
1352 return (gint
) SSM(sci
, SCI_TEXTWIDTH
, (uptr_t
) styleNumber
, (sptr_t
) text
);
1356 void sci_move_selected_lines_down(ScintillaObject
*sci
)
1358 SSM(sci
, SCI_MOVESELECTEDLINESDOWN
, 0, 0);
1362 void sci_move_selected_lines_up(ScintillaObject
*sci
)
1364 SSM(sci
, SCI_MOVESELECTEDLINESUP
, 0, 0);
1368 gint
sci_word_start_position(ScintillaObject
*sci
, gint position
, gboolean onlyWordCharacters
)
1370 return SSM(sci
, SCI_WORDSTARTPOSITION
, position
, onlyWordCharacters
);
1374 gint
sci_word_end_position(ScintillaObject
*sci
, gint position
, gboolean onlyWordCharacters
)
1376 return SSM(sci
, SCI_WORDENDPOSITION
, position
, onlyWordCharacters
);