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"
45 #define SSM(s, m, w, l) scintilla_send_message(s, m, w, l)
48 /* line numbers visibility */
49 void sci_set_line_numbers(ScintillaObject
*sci
, gboolean set
)
54 gint len
= (gint
) SSM(sci
, SCI_GETLINECOUNT
, 0, 0);
57 g_snprintf(tmp_str
, 15, "_%d", len
);
58 width
= sci_text_width(sci
, STYLE_LINENUMBER
, tmp_str
);
59 SSM(sci
, SCI_SETMARGINWIDTHN
, 0, width
);
60 SSM(sci
, SCI_SETMARGINSENSITIVEN
, 0, FALSE
); /* use default behaviour */
64 SSM(sci
, SCI_SETMARGINWIDTHN
, 0, 0);
69 void sci_set_mark_long_lines(ScintillaObject
*sci
, gint type
, gint column
, const gchar
*colour
)
71 glong colour_val
= utils_parse_color_to_bgr(colour
); /* Scintilla uses a "long" value */
79 SSM(sci
, SCI_SETEDGEMODE
, EDGE_LINE
, 0);
84 SSM(sci
, SCI_SETEDGEMODE
, EDGE_BACKGROUND
, 0);
89 SSM(sci
, SCI_SETEDGEMODE
, EDGE_NONE
, 0);
93 SSM(sci
, SCI_SETEDGECOLUMN
, (uptr_t
) column
, 0);
94 SSM(sci
, SCI_SETEDGECOLOUR
, (uptr_t
) colour_val
, 0);
98 /* symbol margin visibility */
99 void sci_set_symbol_margin(ScintillaObject
*sci
, gboolean set
)
103 SSM(sci
, SCI_SETMARGINWIDTHN
, 1, 16);
104 SSM(sci
, SCI_SETMARGINSENSITIVEN
, 1, TRUE
);
108 SSM(sci
, SCI_SETMARGINWIDTHN
, 1, 0);
109 SSM(sci
, SCI_SETMARGINSENSITIVEN
, 1, FALSE
);
114 /* folding margin visibility */
115 void sci_set_folding_margin_visible(ScintillaObject
*sci
, gboolean set
)
119 SSM(sci
, SCI_SETMARGINWIDTHN
, 2, 12);
120 SSM(sci
, SCI_SETMARGINSENSITIVEN
, 2, TRUE
);
124 SSM(sci
, SCI_SETMARGINSENSITIVEN
, 2, FALSE
);
125 SSM(sci
, SCI_SETMARGINWIDTHN
, 2, 0);
131 void sci_set_visible_eols(ScintillaObject
*sci
, gboolean set
)
133 SSM(sci
, SCI_SETVIEWEOL
, set
!= FALSE
, 0);
137 void sci_set_visible_white_spaces(ScintillaObject
*sci
, gboolean set
)
140 SSM(sci
, SCI_SETVIEWWS
, SCWS_VISIBLEALWAYS
, 0);
142 SSM(sci
, SCI_SETVIEWWS
, SCWS_INVISIBLE
, 0);
146 void sci_set_lines_wrapped(ScintillaObject
*sci
, gboolean set
)
149 SSM(sci
, SCI_SETWRAPMODE
, SC_WRAP_WORD
, 0);
151 SSM(sci
, SCI_SETWRAPMODE
, SC_WRAP_NONE
, 0);
155 gint
sci_get_eol_mode(ScintillaObject
*sci
)
157 return (gint
) SSM(sci
, SCI_GETEOLMODE
, 0, 0);
161 void sci_set_eol_mode(ScintillaObject
*sci
, gint eolmode
)
163 SSM(sci
, SCI_SETEOLMODE
, (uptr_t
) eolmode
, 0);
167 void sci_convert_eols(ScintillaObject
*sci
, gint eolmode
)
169 SSM(sci
, SCI_CONVERTEOLS
, (uptr_t
) eolmode
, 0);
173 void sci_add_text(ScintillaObject
*sci
, const gchar
*text
)
176 { /* if null text is passed scintilla will segfault */
177 SSM(sci
, SCI_ADDTEXT
, strlen(text
), (sptr_t
) text
);
183 * @param sci Scintilla widget.
184 * @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. */
224 void sci_start_undo_action(ScintillaObject
*sci
)
226 SSM(sci
, SCI_BEGINUNDOACTION
, 0, 0);
230 /** Ends grouping a set of edits together as one Undo action.
231 * @param sci Scintilla @c GtkWidget.
232 * @see sci_start_undo_action(). */
234 void sci_end_undo_action(ScintillaObject
*sci
)
236 SSM(sci
, SCI_ENDUNDOACTION
, 0, 0);
240 void sci_set_undo_collection(ScintillaObject
*sci
, gboolean set
)
242 SSM(sci
, SCI_SETUNDOCOLLECTION
, set
!= FALSE
, 0);
246 void sci_empty_undo_buffer(ScintillaObject
*sci
)
248 SSM(sci
, SCI_EMPTYUNDOBUFFER
, 0, 0);
252 gboolean
sci_is_modified(ScintillaObject
*sci
)
254 return (SSM(sci
, SCI_GETMODIFY
, 0, 0) != 0);
258 void sci_zoom_in(ScintillaObject
*sci
)
260 SSM(sci
, SCI_ZOOMIN
, 0, 0);
264 void sci_zoom_out(ScintillaObject
*sci
)
266 SSM(sci
, SCI_ZOOMOUT
, 0, 0);
270 void sci_zoom_off(ScintillaObject
*sci
)
272 SSM(sci
, SCI_SETZOOM
, 0, 0);
276 gint
sci_get_zoom(ScintillaObject
*sci
)
278 return (gint
) SSM(sci
, SCI_GETZOOM
, 0, 0);
282 /** Sets a line marker.
283 * @param sci Scintilla widget.
284 * @param line_number Line number.
285 * @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. */
298 void sci_delete_marker_at_line(ScintillaObject
*sci
, gint line_number
, gint marker
)
300 SSM(sci
, SCI_MARKERDELETE
, (uptr_t
) line_number
, marker
);
304 /** Checks if a line has a marker set.
305 * @param sci Scintilla widget.
306 * @param line Line number.
307 * @param marker Marker number.
308 * @return Whether it's set. */
310 gboolean
sci_is_marker_set_at_line(ScintillaObject
*sci
, gint line
, gint marker
)
314 state
= (gint
) SSM(sci
, SCI_MARKERGET
, (uptr_t
) line
, 0);
315 return (state
& (1 << marker
));
319 void sci_toggle_marker_at_line(ScintillaObject
*sci
, gint line
, gint marker
)
321 gboolean set
= sci_is_marker_set_at_line(sci
, line
, marker
);
324 sci_set_marker_at_line(sci
, line
, marker
);
326 sci_delete_marker_at_line(sci
, line
, marker
);
330 /* Returns the line number of the next marker that matches marker_mask, or -1.
331 * marker_mask is a bitor of 1 << marker_index. (See MarkerHandleSet::MarkValue()).
332 * Note: If there is a marker on the line, it returns the same line. */
333 gint
sci_marker_next(ScintillaObject
*sci
, gint line
, gint marker_mask
, gboolean wrap
)
337 marker_line
= (gint
) SSM(sci
, SCI_MARKERNEXT
, (uptr_t
) line
, marker_mask
);
338 if (wrap
&& marker_line
== -1)
339 marker_line
= (gint
) SSM(sci
, SCI_MARKERNEXT
, 0, marker_mask
);
344 /* Returns the line number of the previous marker that matches marker_mask, or -1.
345 * marker_mask is a bitor of 1 << marker_index. (See MarkerHandleSet::MarkValue()).
346 * Note: If there is a marker on the line, it returns the same line. */
347 gint
sci_marker_previous(ScintillaObject
*sci
, gint line
, gint marker_mask
, gboolean wrap
)
351 marker_line
= (gint
) SSM(sci
, SCI_MARKERPREVIOUS
, (uptr_t
) line
, marker_mask
);
352 if (wrap
&& marker_line
== -1)
354 gint len
= sci_get_length(sci
);
355 gint last_line
= sci_get_line_from_position(sci
, len
- 1);
357 marker_line
= (gint
) SSM(sci
, SCI_MARKERPREVIOUS
, (uptr_t
) last_line
, marker_mask
);
363 /** Gets the line number from @a position.
364 * @param sci Scintilla widget.
365 * @param position Position.
366 * @return The line. */
368 gint
sci_get_line_from_position(ScintillaObject
*sci
, gint position
)
370 return (gint
) SSM(sci
, SCI_LINEFROMPOSITION
, (uptr_t
) position
, 0);
374 /** Gets the column number relative to the start of the line that @a position is on.
375 * @param sci Scintilla widget.
376 * @param position Position.
377 * @return The column. */
379 gint
sci_get_col_from_position(ScintillaObject
*sci
, gint position
)
381 return (gint
) SSM(sci
, SCI_GETCOLUMN
, (uptr_t
) position
, 0);
385 gint
sci_get_position_from_col(ScintillaObject
*sci
, gint line
, gint col
)
387 return (gint
) SSM(sci
, SCI_FINDCOLUMN
, line
, col
);
391 /** Gets the position for the start of @a line.
392 * @param sci Scintilla widget.
394 * @return Position. */
396 gint
sci_get_position_from_line(ScintillaObject
*sci
, gint line
)
398 return (gint
) SSM(sci
, SCI_POSITIONFROMLINE
, (uptr_t
) line
, 0);
402 /** Gets the cursor position.
403 * @param sci Scintilla widget.
404 * @return Position. */
406 gint
sci_get_current_position(ScintillaObject
*sci
)
408 return (gint
) SSM(sci
, SCI_GETCURRENTPOS
, 0, 0);
412 gint
sci_get_cursor_virtual_space(ScintillaObject
*sci
)
414 gint selection_mode
= sci_get_selection_mode(sci
);
416 return selection_mode
== SC_SEL_RECTANGLE
|| selection_mode
== SC_SEL_THIN
?
417 SSM(sci
, SCI_GETRECTANGULARSELECTIONCARETVIRTUALSPACE
, 0, 0) :
418 SSM(sci
, SCI_GETSELECTIONNCARETVIRTUALSPACE
,
419 SSM(sci
, SCI_GETMAINSELECTION
, 0, 0), 0);
423 /** Sets the cursor position.
424 * @param sci Scintilla widget.
425 * @param position Position.
426 * @param scroll_to_caret Whether to scroll the cursor in view. */
428 void sci_set_current_position(ScintillaObject
*sci
, gint position
, gboolean scroll_to_caret
)
431 SSM(sci
, SCI_GOTOPOS
, (uptr_t
) position
, 0);
434 SSM(sci
, SCI_SETCURRENTPOS
, (uptr_t
) position
, 0);
435 SSM(sci
, SCI_SETANCHOR
, (uptr_t
) position
, 0); /* to avoid creation of a selection */
437 SSM(sci
, SCI_CHOOSECARETX
, 0, 0);
441 /* Set the cursor line without scrolling the view.
442 * Use sci_goto_line() to also scroll. */
443 void sci_set_current_line(ScintillaObject
*sci
, gint line
)
445 gint pos
= sci_get_position_from_line(sci
, line
);
446 sci_set_current_position(sci
, pos
, FALSE
);
450 /** Gets the total number of lines.
451 * @param sci Scintilla widget.
452 * @return The line count. */
454 gint
sci_get_line_count(ScintillaObject
*sci
)
456 return (gint
) SSM(sci
, SCI_GETLINECOUNT
, 0, 0);
460 /** Sets the selection start position.
461 * @param sci Scintilla widget.
462 * @param position Position. */
464 void sci_set_selection_start(ScintillaObject
*sci
, gint position
)
466 SSM(sci
, SCI_SETSELECTIONSTART
, (uptr_t
) position
, 0);
470 /** Sets the selection end position.
471 * @param sci Scintilla widget.
472 * @param position Position. */
474 void sci_set_selection_end(ScintillaObject
*sci
, gint position
)
476 SSM(sci
, SCI_SETSELECTIONEND
, (uptr_t
) position
, 0);
480 void sci_set_selection(ScintillaObject
*sci
, gint anchorPos
, gint currentPos
)
482 SSM(sci
, SCI_SETSEL
, (uptr_t
) anchorPos
, currentPos
);
486 /** Gets the position at the end of a line
487 * @param sci Scintilla widget.
489 * @return The position at the end of the line. */
491 gint
sci_get_line_end_position(ScintillaObject
*sci
, gint line
)
493 return (gint
) SSM(sci
, SCI_GETLINEENDPOSITION
, (uptr_t
) line
, 0);
497 void sci_cut(ScintillaObject
*sci
)
499 SSM(sci
, SCI_CUT
, 0, 0);
503 void sci_copy(ScintillaObject
*sci
)
505 SSM(sci
, SCI_COPY
, 0, 0);
509 void sci_paste(ScintillaObject
*sci
)
511 SSM(sci
, SCI_PASTE
, 0, 0);
515 void sci_clear(ScintillaObject
*sci
)
517 SSM(sci
, SCI_CLEAR
, 0, 0);
521 /** Gets the selection start position.
522 * @param sci Scintilla widget.
523 * @return Position. */
525 gint
sci_get_selection_start(ScintillaObject
*sci
)
527 return (gint
) SSM(sci
, SCI_GETSELECTIONSTART
, 0, 0);
531 /** Gets the selection end position.
532 * @param sci Scintilla widget.
533 * @return Position. */
535 gint
sci_get_selection_end(ScintillaObject
*sci
)
537 return (gint
) SSM(sci
, SCI_GETSELECTIONEND
, 0, 0);
541 /** Replaces selection.
542 * @param sci Scintilla widget.
543 * @param text Text. */
545 void sci_replace_sel(ScintillaObject
*sci
, const gchar
*text
)
547 SSM(sci
, SCI_REPLACESEL
, 0, (sptr_t
) text
);
551 /** Gets the length of all text.
552 * @param sci Scintilla widget.
555 gint
sci_get_length(ScintillaObject
*sci
)
557 return (gint
) SSM(sci
, SCI_GETLENGTH
, 0, 0);
561 /** Gets the currently used lexer
562 * @param sci Scintilla widget.
563 * @returns The lexer ID
566 gint
sci_get_lexer(ScintillaObject
*sci
)
568 return (gint
) SSM(sci
, SCI_GETLEXER
, 0, 0);
572 void sci_set_lexer(ScintillaObject
*sci
, guint lexer_id
)
574 gint old
= sci_get_lexer(sci
);
576 SSM(sci
, SCI_SETLEXER
, lexer_id
, 0);
578 if (old
!= (gint
)lexer_id
)
579 SSM(sci
, SCI_CLEARDOCUMENTSTYLE
, 0, 0);
583 /** Gets line length.
584 * @param sci Scintilla widget.
585 * @param line Line number.
588 gint
sci_get_line_length(ScintillaObject
*sci
, gint line
)
590 return (gint
) SSM(sci
, SCI_LINELENGTH
, (uptr_t
) line
, 0);
594 /* safe way to read Scintilla string into new memory.
595 * works with any string buffer messages that follow the Windows message convention. */
596 gchar
*sci_get_string(ScintillaObject
*sci
, guint msg
, gulong wParam
)
598 gint size
= (gint
) SSM(sci
, msg
, wParam
, 0);
599 gchar
*str
= g_malloc(size
+ 1);
601 SSM(sci
, msg
, wParam
, (sptr_t
) str
);
602 str
[size
] = '\0'; /* ensure termination, needed for SCI_GETLINE */
607 /** Gets line contents.
608 * @param sci Scintilla widget.
609 * @param line_num Line number.
610 * @return A @c NULL-terminated copy of the line text. */
612 gchar
*sci_get_line(ScintillaObject
*sci
, gint line_num
)
614 return sci_get_string(sci
, SCI_GETLINE
, (gulong
) line_num
);
619 * @deprecated sci_get_text is deprecated and should not be used in newly-written code.
620 * Use sci_get_contents() instead.
622 * @param sci Scintilla widget.
623 * @param len Length of @a text buffer, usually sci_get_length() + 1.
624 * @param text Text buffer; must be allocated @a len + 1 bytes for null-termination. */
626 void sci_get_text(ScintillaObject
*sci
, gint len
, gchar
*text
)
628 SSM(sci
, SCI_GETTEXT
, (uptr_t
) len
, (sptr_t
) text
);
632 /** Allocates and fills a buffer with text from the start of the document.
633 * @param sci Scintilla widget.
634 * @param buffer_len Buffer length to allocate, including the terminating
635 * null char, e.g. sci_get_length() + 1. Alternatively use @c -1 to get all
636 * text (since Geany 1.23).
637 * @return A copy of the text. Should be freed when no longer needed.
642 gchar
*sci_get_contents(ScintillaObject
*sci
, gint buffer_len
)
647 buffer_len
= sci_get_length(sci
) + 1;
649 text
= g_malloc(buffer_len
);
650 SSM(sci
, SCI_GETTEXT
, (uptr_t
) buffer_len
, (sptr_t
) text
);
655 /** Gets selected text.
656 * @deprecated sci_get_selected_text is deprecated and should not be used in newly-written code.
657 * Use sci_get_selection_contents() instead.
659 * @param sci Scintilla widget.
660 * @param text Text buffer; must be allocated sci_get_selected_text_length() + 1 bytes
661 * for null-termination. */
663 void sci_get_selected_text(ScintillaObject
*sci
, gchar
*text
)
665 SSM(sci
, SCI_GETSELTEXT
, 0, (sptr_t
) text
);
669 /** Gets selected text.
670 * @param sci Scintilla widget.
672 * @return The selected text. Should be freed when no longer needed.
677 gchar
*sci_get_selection_contents(ScintillaObject
*sci
)
679 return sci_get_string(sci
, SCI_GETSELTEXT
, 0);
683 /** Gets selected text length.
684 * @param sci Scintilla widget.
687 gint
sci_get_selected_text_length(ScintillaObject
*sci
)
689 return (gint
) SSM(sci
, SCI_GETSELTEXT
, 0, 0);
693 gint
sci_get_position_from_xy(ScintillaObject
*sci
, gint x
, gint y
, gboolean nearby
)
695 /* for nearby return -1 if there is no character near to the x,y point. */
696 return (gint
) SSM(sci
, (nearby
) ? SCI_POSITIONFROMPOINTCLOSE
: SCI_POSITIONFROMPOINT
, (uptr_t
) x
, y
);
700 /** Checks if a line is visible (folding may have hidden it).
701 * @param sci Scintilla widget.
702 * @param line Line number.
703 * @return Whether @a line will be drawn on the screen. */
705 gboolean
sci_get_line_is_visible(ScintillaObject
*sci
, gint line
)
707 return SSM(sci
, SCI_GETLINEVISIBLE
, (uptr_t
) line
, 0) != FALSE
;
711 /** Makes @a line visible (folding may have hidden it).
712 * @param sci Scintilla widget.
713 * @param line Line number. */
715 void sci_ensure_line_is_visible(ScintillaObject
*sci
, gint line
)
717 SSM(sci
, SCI_ENSUREVISIBLE
, (uptr_t
) line
, 0);
721 gint
sci_get_fold_level(ScintillaObject
*sci
, gint line
)
723 return (gint
) SSM(sci
, SCI_GETFOLDLEVEL
, (uptr_t
) line
, 0);
727 /* Get the line number of the fold point before start_line, or -1 if there isn't one */
728 gint
sci_get_fold_parent(ScintillaObject
*sci
, gint start_line
)
730 return (gint
) SSM(sci
, SCI_GETFOLDPARENT
, (uptr_t
) start_line
, 0);
734 void sci_toggle_fold(ScintillaObject
*sci
, gint line
)
736 SSM(sci
, SCI_TOGGLEFOLD
, (uptr_t
) line
, 0);
740 gboolean
sci_get_fold_expanded(ScintillaObject
*sci
, gint line
)
742 return SSM(sci
, SCI_GETFOLDEXPANDED
, (uptr_t
) line
, 0) != FALSE
;
746 void sci_colourise(ScintillaObject
*sci
, gint start
, gint end
)
748 SSM(sci
, SCI_COLOURISE
, (uptr_t
) start
, end
);
752 void sci_clear_all(ScintillaObject
*sci
)
754 SSM(sci
, SCI_CLEARALL
, 0, 0);
758 gint
sci_get_end_styled(ScintillaObject
*sci
)
760 return (gint
) SSM(sci
, SCI_GETENDSTYLED
, 0, 0);
764 void sci_set_tab_width(ScintillaObject
*sci
, gint width
)
766 SSM(sci
, SCI_SETTABWIDTH
, (uptr_t
) width
, 0);
770 /** Gets display tab width (this is not indent width, see GeanyIndentPrefs).
771 * @param sci Scintilla widget.
777 gint
sci_get_tab_width(ScintillaObject
*sci
)
779 return (gint
) SSM(sci
, SCI_GETTABWIDTH
, 0, 0);
783 /** Gets a character.
784 * @param sci Scintilla widget.
785 * @param pos Position.
788 gchar
sci_get_char_at(ScintillaObject
*sci
, gint pos
)
790 return (gchar
) SSM(sci
, SCI_GETCHARAT
, (uptr_t
) pos
, 0);
794 void sci_set_savepoint(ScintillaObject
*sci
)
796 SSM(sci
, SCI_SETSAVEPOINT
, 0, 0);
800 void sci_set_indentation_guides(ScintillaObject
*sci
, gint mode
)
802 SSM(sci
, SCI_SETINDENTATIONGUIDES
, (uptr_t
) mode
, 0);
806 void sci_use_popup(ScintillaObject
*sci
, gboolean enable
)
808 SSM(sci
, SCI_USEPOPUP
, enable
!= FALSE
, 0);
812 /** Checks if there's a selection.
813 * @param sci Scintilla widget.
814 * @return Whether a selection is present.
819 gboolean
sci_has_selection(ScintillaObject
*sci
)
821 if (SSM(sci
, SCI_GETSELECTIONEND
, 0, 0) - SSM(sci
, SCI_GETSELECTIONSTART
, 0, 0))
828 void sci_goto_pos(ScintillaObject
*sci
, gint pos
, gboolean unfold
)
830 if (unfold
) SSM(sci
, SCI_ENSUREVISIBLE
, (uptr_t
) SSM(sci
, SCI_LINEFROMPOSITION
, (uptr_t
) pos
, 0), 0);
831 SSM(sci
, SCI_GOTOPOS
, (uptr_t
) pos
, 0);
835 void sci_set_search_anchor(ScintillaObject
*sci
)
837 SSM(sci
, SCI_SEARCHANCHOR
, 0, 0);
841 /* removes a selection if pos < 0 */
842 void sci_set_anchor(ScintillaObject
*sci
, gint pos
)
845 pos
= sci_get_current_position(sci
);
847 SSM(sci
, SCI_SETANCHOR
, (uptr_t
) pos
, 0);
851 /** Scrolls the cursor in view.
852 * @param sci Scintilla widget. */
854 void sci_scroll_caret(ScintillaObject
*sci
)
856 SSM(sci
, SCI_SCROLLCARET
, 0, 0);
860 void sci_scroll_lines(ScintillaObject
*sci
, gint lines
)
862 SSM(sci
, SCI_LINESCROLL
, 0, lines
);
866 void sci_scroll_columns(ScintillaObject
*sci
, gint columns
)
868 SSM(sci
, SCI_LINESCROLL
, (uptr_t
) columns
, 0);
872 gint
sci_search_next(ScintillaObject
*sci
, gint flags
, const gchar
*text
)
874 /* FIXME: SCI_SEACHNEXT() actually returns long */
875 return (gint
) SSM(sci
, SCI_SEARCHNEXT
, (uptr_t
) flags
, (sptr_t
) text
);
879 gint
sci_search_prev(ScintillaObject
*sci
, gint flags
, const gchar
*text
)
881 /* FIXME: SCI_SEACHPREV() actually returns long */
882 return (gint
) SSM(sci
, SCI_SEARCHPREV
, (uptr_t
) flags
, (sptr_t
) text
);
886 /** Finds text in the document.
887 * The @a ttf argument should be a pointer to a Sci_TextToFind structure which contains
888 * the text to find and the range in which the text should be searched.
890 * Please refer to the Scintilla documentation for a more detailed description.
892 * @param sci Scintilla widget.
893 * @param flags Bitmask of Scintilla search flags (@c SCFIND_*, see Scintilla documentation).
894 * @param ttf Pointer to a TextToFind structure which contains the text to find and the range.
895 * @return The position of the start of the found text if it succeeds, otherwise @c -1.
896 * The @c chrgText.cpMin and @c chrgText.cpMax members of @c TextToFind are filled in
897 * with the start and end positions of the found text.
900 gint
sci_find_text(ScintillaObject
*sci
, gint flags
, struct Sci_TextToFind
*ttf
)
902 return (gint
) SSM(sci
, SCI_FINDTEXT
, (uptr_t
) flags
, (sptr_t
) ttf
);
906 /** Sets the font for a particular style.
907 * @param sci Scintilla widget.
908 * @param style The style.
909 * @param font The font name.
910 * @param size The font size. */
912 void sci_set_font(ScintillaObject
*sci
, gint style
, const gchar
*font
, gint size
)
914 SSM(sci
, SCI_STYLESETFONT
, (uptr_t
) style
, (sptr_t
) font
);
915 SSM(sci
, SCI_STYLESETSIZE
, (uptr_t
) style
, size
);
919 /** Jumps to the specified line in the document.
920 * If @a unfold is set and @a line is hidden by a fold, it is unfolded
921 * first to ensure it is visible.
922 * @param sci Scintilla widget.
924 * @param unfold Whether to unfold first.
927 void sci_goto_line(ScintillaObject
*sci
, gint line
, gboolean unfold
)
929 if (unfold
) SSM(sci
, SCI_ENSUREVISIBLE
, (uptr_t
) line
, 0);
930 SSM(sci
, SCI_GOTOLINE
, (uptr_t
) line
, 0);
934 void sci_marker_delete_all(ScintillaObject
*sci
, gint marker
)
936 SSM(sci
, SCI_MARKERDELETEALL
, (uptr_t
) marker
, 0);
940 /** Gets style ID at @a position.
941 * @param sci Scintilla widget.
942 * @param position Position.
943 * @return Style ID. */
945 gint
sci_get_style_at(ScintillaObject
*sci
, gint position
)
947 return (gint
) SSM(sci
, SCI_GETSTYLEAT
, (uptr_t
) position
, 0);
951 void sci_set_codepage(ScintillaObject
*sci
, gint cp
)
953 g_return_if_fail(cp
== 0 || cp
== SC_CP_UTF8
);
954 SSM(sci
, SCI_SETCODEPAGE
, (uptr_t
) cp
, 0);
958 void sci_assign_cmdkey(ScintillaObject
*sci
, gint key
, gint command
)
960 SSM(sci
, SCI_ASSIGNCMDKEY
, (uptr_t
) key
, command
);
964 void sci_clear_cmdkey(ScintillaObject
*sci
, gint key
)
966 SSM(sci
, SCI_CLEARCMDKEY
, (uptr_t
) key
, 0);
970 /** Gets text between @a start and @a end.
971 * @deprecated sci_get_text_range is deprecated and should not be used in newly-written code.
972 * Use sci_get_contents_range() instead.
974 * @param sci Scintilla widget.
975 * @param start Start.
977 * @param text Text will be zero terminated and must be allocated (end - start + 1) bytes. */
979 void sci_get_text_range(ScintillaObject
*sci
, gint start
, gint end
, gchar
*text
)
981 struct Sci_TextRange tr
;
982 tr
.chrg
.cpMin
= start
;
985 SSM(sci
, SCI_GETTEXTRANGE
, 0, (long) &tr
);
989 /** Gets text between @a start and @a end.
990 * @param sci Scintilla widget.
991 * @param start Start position.
992 * @param end End position.
993 * @return The text inside the given range. Should be freed when no longer needed.
998 gchar
*sci_get_contents_range(ScintillaObject
*sci
, gint start
, gint end
)
1002 g_return_val_if_fail(start
< end
, NULL
);
1004 text
= g_malloc((gsize
) (end
- start
) + 1);
1005 sci_get_text_range(sci
, start
, end
, text
);
1010 void sci_line_duplicate(ScintillaObject
*sci
)
1012 SSM(sci
, SCI_LINEDUPLICATE
, 0, 0);
1016 void sci_selection_duplicate(ScintillaObject
*sci
)
1018 SSM(sci
, SCI_SELECTIONDUPLICATE
, 0, 0);
1023 * @param sci Scintilla widget.
1024 * @param pos Position, or -1 for current.
1025 * @param text Text. */
1027 void sci_insert_text(ScintillaObject
*sci
, gint pos
, const gchar
*text
)
1029 SSM(sci
, SCI_INSERTTEXT
, (uptr_t
) pos
, (sptr_t
) text
);
1033 void sci_target_from_selection(ScintillaObject
*sci
)
1035 SSM(sci
, SCI_TARGETFROMSELECTION
, 0, 0);
1040 void sci_set_target_start(ScintillaObject
*sci
, gint start
)
1042 SSM(sci
, SCI_SETTARGETSTART
, (uptr_t
) start
, 0);
1047 void sci_set_target_end(ScintillaObject
*sci
, gint end
)
1049 SSM(sci
, SCI_SETTARGETEND
, (uptr_t
) end
, 0);
1054 gint
sci_replace_target(ScintillaObject
*sci
, const gchar
*text
, gboolean regex
)
1056 return (gint
) SSM(sci
, (regex
) ? SCI_REPLACETARGETRE
: SCI_REPLACETARGET
, (uptr_t
) -1, (sptr_t
) text
);
1060 void sci_set_keywords(ScintillaObject
*sci
, guint k
, const gchar
*text
)
1062 SSM(sci
, SCI_SETKEYWORDS
, k
, (sptr_t
) text
);
1066 void sci_set_readonly(ScintillaObject
*sci
, gboolean readonly
)
1068 SSM(sci
, SCI_SETREADONLY
, readonly
!= FALSE
, 0);
1072 /** Sends Scintilla commands without any parameters.
1073 * @param sci The Scintilla @c GtkWidget.
1074 * @param cmd @c SCI_COMMAND.
1075 * @see http://scintilla.org for the documentation.
1080 void sci_send_command(ScintillaObject
*sci
, gint cmd
)
1082 SSM(sci
, cmd
, 0, 0);
1086 /** Gets current line number.
1087 * @param sci Scintilla widget.
1088 * @return Line number. */
1090 gint
sci_get_current_line(ScintillaObject
*sci
)
1092 return (gint
) SSM(sci
, SCI_LINEFROMPOSITION
, (uptr_t
) SSM(sci
, SCI_GETCURRENTPOS
, 0, 0), 0);
1096 /* Get number of lines partially or fully selected.
1097 * Returns 1 if there is a partial selection on the same line.
1098 * Returns 2 if a whole line is selected including the line break char(s). */
1099 gint
sci_get_lines_selected(ScintillaObject
*sci
)
1101 gint start
= (gint
) SSM(sci
, SCI_GETSELECTIONSTART
, 0, 0);
1102 gint end
= (gint
) SSM(sci
, SCI_GETSELECTIONEND
, 0, 0);
1107 return 0; /* no selection */
1109 line_start
= (gint
) SSM(sci
, SCI_LINEFROMPOSITION
, (uptr_t
) start
, 0);
1110 line_end
= (gint
) SSM(sci
, SCI_LINEFROMPOSITION
, (uptr_t
) end
, 0);
1112 return line_end
- line_start
+ 1;
1116 gint
sci_get_first_visible_line(ScintillaObject
*sci
)
1118 return (gint
) SSM(sci
, SCI_GETFIRSTVISIBLELINE
, 0, 0);
1123 * Sets the current indicator. This is necessary to define an indicator for a range of text or
1124 * clearing indicators for a range of text.
1126 * @param sci Scintilla widget.
1127 * @param indic The indicator number to set.
1129 * @see sci_indicator_clear
1134 void sci_indicator_set(ScintillaObject
*sci
, gint indic
)
1136 SSM(sci
, SCI_SETINDICATORCURRENT
, (uptr_t
) indic
, 0);
1140 void sci_indicator_fill(ScintillaObject
*sci
, gint pos
, gint len
)
1142 SSM(sci
, SCI_INDICATORFILLRANGE
, (uptr_t
) pos
, len
);
1147 * Clears the currently set indicator from a range of text.
1148 * Starting at @a pos, @a len characters long.
1149 * In order to make this function properly, you need to set the current indicator before with
1150 * @ref sci_indicator_set().
1152 * @param sci Scintilla widget.
1153 * @param pos Starting position.
1154 * @param len Length.
1159 void sci_indicator_clear(ScintillaObject
*sci
, gint pos
, gint len
)
1161 SSM(sci
, SCI_INDICATORCLEARRANGE
, (uptr_t
) pos
, len
);
1165 void sci_select_all(ScintillaObject
*sci
)
1167 SSM(sci
, SCI_SELECTALL
, 0, 0);
1171 gint
sci_get_line_indent_position(ScintillaObject
*sci
, gint line
)
1173 return (gint
) SSM(sci
, SCI_GETLINEINDENTPOSITION
, (uptr_t
) line
, 0);
1177 void sci_set_autoc_max_height(ScintillaObject
*sci
, gint val
)
1179 SSM(sci
, SCI_AUTOCSETMAXHEIGHT
, (uptr_t
) val
, 0);
1183 /** Finds a matching brace at @a pos.
1184 * @param sci Scintilla widget.
1185 * @param pos Position.
1186 * @return Matching brace position.
1191 gint
sci_find_matching_brace(ScintillaObject
*sci
, gint pos
)
1193 return (gint
) SSM(sci
, SCI_BRACEMATCH
, (uptr_t
) pos
, 0);
1197 gint
sci_get_overtype(ScintillaObject
*sci
)
1199 return (gint
) SSM(sci
, SCI_GETOVERTYPE
, 0, 0);
1203 void sci_set_tab_indents(ScintillaObject
*sci
, gboolean set
)
1205 SSM(sci
, SCI_SETTABINDENTS
, set
!= FALSE
, 0);
1209 void sci_set_use_tabs(ScintillaObject
*sci
, gboolean set
)
1211 SSM(sci
, SCI_SETUSETABS
, set
!= FALSE
, 0);
1215 gint
sci_get_pos_at_line_sel_start(ScintillaObject
*sci
, gint line
)
1217 return (gint
) SSM(sci
, SCI_GETLINESELSTARTPOSITION
, (uptr_t
) line
, 0);
1221 gint
sci_get_pos_at_line_sel_end(ScintillaObject
*sci
, gint line
)
1223 return (gint
) SSM(sci
, SCI_GETLINESELENDPOSITION
, (uptr_t
) line
, 0);
1227 /** Gets selection mode.
1228 * @param sci Scintilla widget.
1229 * @return Selection mode. */
1231 gint
sci_get_selection_mode(ScintillaObject
*sci
)
1233 return (gint
) SSM(sci
, SCI_GETSELECTIONMODE
, 0, 0);
1237 /** Sets selection mode.
1238 * @param sci Scintilla widget.
1239 * @param mode Mode. */
1241 void sci_set_selection_mode(ScintillaObject
*sci
, gint mode
)
1243 SSM(sci
, SCI_SETSELECTIONMODE
, (uptr_t
) mode
, 0);
1247 void sci_set_scrollbar_mode(ScintillaObject
*sci
, gboolean visible
)
1249 SSM(sci
, SCI_SETHSCROLLBAR
, visible
!= FALSE
, 0);
1250 SSM(sci
, SCI_SETVSCROLLBAR
, visible
!= FALSE
, 0);
1254 /** Sets the indentation of a line.
1255 * @param sci Scintilla widget.
1256 * @param line Line to indent.
1257 * @param indent Indentation width.
1262 void sci_set_line_indentation(ScintillaObject
*sci
, gint line
, gint indent
)
1264 SSM(sci
, SCI_SETLINEINDENTATION
, (uptr_t
) line
, indent
);
1268 /** Gets the indentation width of a line.
1269 * @param sci Scintilla widget.
1270 * @param line Line to get the indentation from.
1271 * @return Indentation width.
1276 gint
sci_get_line_indentation(ScintillaObject
*sci
, gint line
)
1278 return (gint
) SSM(sci
, SCI_GETLINEINDENTATION
, (uptr_t
) line
, 0);
1282 void sci_set_caret_policy_x(ScintillaObject
*sci
, gint policy
, gint slop
)
1284 SSM(sci
, SCI_SETXCARETPOLICY
, (uptr_t
) policy
, slop
);
1288 void sci_set_caret_policy_y(ScintillaObject
*sci
, gint policy
, gint slop
)
1290 SSM(sci
, SCI_SETYCARETPOLICY
, (uptr_t
) policy
, slop
);
1294 void sci_set_scroll_stop_at_last_line(ScintillaObject
*sci
, gboolean set
)
1296 SSM(sci
, SCI_SETENDATLASTLINE
, set
!= FALSE
, 0);
1300 void sci_cancel(ScintillaObject
*sci
)
1302 SSM(sci
, SCI_CANCEL
, 0, 0);
1306 gint
sci_get_target_end(ScintillaObject
*sci
)
1308 return (gint
) SSM(sci
, SCI_GETTARGETEND
, 0, 0);
1312 gint
sci_get_position_after(ScintillaObject
*sci
, gint start
)
1314 return (gint
) SSM(sci
, SCI_POSITIONAFTER
, (uptr_t
) start
, 0);
1318 void sci_lines_join(ScintillaObject
*sci
)
1320 SSM(sci
, SCI_LINESJOIN
, 0, 0);
1324 gint
sci_text_width(ScintillaObject
*sci
, gint styleNumber
, const gchar
*text
)
1326 return (gint
) SSM(sci
, SCI_TEXTWIDTH
, (uptr_t
) styleNumber
, (sptr_t
) text
);
1330 void sci_move_selected_lines_down(ScintillaObject
*sci
)
1332 SSM(sci
, SCI_MOVESELECTEDLINESDOWN
, 0, 0);
1336 void sci_move_selected_lines_up(ScintillaObject
*sci
)
1338 SSM(sci
, SCI_MOVESELECTEDLINESUP
, 0, 0);
1342 gint
sci_word_start_position(ScintillaObject
*sci
, gint position
, gboolean onlyWordCharacters
)
1344 return SSM(sci
, SCI_WORDSTARTPOSITION
, position
, onlyWordCharacters
);
1348 gint
sci_word_end_position(ScintillaObject
*sci
, gint position
, gboolean onlyWordCharacters
)
1350 return SSM(sci
, SCI_WORDENDPOSITION
, position
, onlyWordCharacters
);