2 * sciwrappers.c - this file is part of Geany, a fast and lightweight IDE
4 * Copyright 2005-2011 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
5 * Copyright 2006-2011 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
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"
41 #define SSM(s, m, w, l) scintilla_send_message(s, m, w, l)
44 /* line numbers visibility */
45 void sci_set_line_numbers(ScintillaObject
*sci
, gboolean set
, gint extra_width
)
50 gint len
= (gint
) SSM(sci
, SCI_GETLINECOUNT
, 0, 0);
53 g_snprintf(tmp_str
, 15, "_%d", len
);
54 width
= sci_text_width(sci
, STYLE_LINENUMBER
, tmp_str
);
57 g_snprintf(tmp_str
, 15, "%d", extra_width
);
58 width
+= sci_text_width(sci
, STYLE_LINENUMBER
, tmp_str
);
60 SSM(sci
, SCI_SETMARGINWIDTHN
, 0, width
);
61 SSM(sci
, SCI_SETMARGINSENSITIVEN
, 0, FALSE
); /* use default behaviour */
65 SSM(sci
, SCI_SETMARGINWIDTHN
, 0, 0);
70 void sci_set_mark_long_lines(ScintillaObject
*sci
, gint type
, gint column
, const gchar
*colour
)
72 glong colour_val
= utils_strtod(colour
, NULL
, TRUE
); /* Scintilla uses a "long" value */
80 SSM(sci
, SCI_SETEDGEMODE
, EDGE_LINE
, 0);
85 SSM(sci
, SCI_SETEDGEMODE
, EDGE_BACKGROUND
, 0);
90 SSM(sci
, SCI_SETEDGEMODE
, EDGE_NONE
, 0);
94 SSM(sci
, SCI_SETEDGECOLUMN
, (uptr_t
) column
, 0);
95 SSM(sci
, SCI_SETEDGECOLOUR
, (uptr_t
) colour_val
, 0);
99 /* symbol margin visibility */
100 void sci_set_symbol_margin(ScintillaObject
*sci
, gboolean set
)
104 SSM(sci
, SCI_SETMARGINWIDTHN
, 1, 16);
105 SSM(sci
, SCI_SETMARGINSENSITIVEN
, 1, TRUE
);
109 SSM(sci
, SCI_SETMARGINWIDTHN
, 1, 0);
110 SSM(sci
, SCI_SETMARGINSENSITIVEN
, 1, FALSE
);
115 /* folding margin visibility */
116 void sci_set_folding_margin_visible(ScintillaObject
*sci
, gboolean set
)
120 SSM(sci
, SCI_SETMARGINWIDTHN
, 2, 12);
121 SSM(sci
, SCI_SETMARGINSENSITIVEN
, 2, TRUE
);
125 SSM(sci
, SCI_SETMARGINSENSITIVEN
, 2, FALSE
);
126 SSM(sci
, SCI_SETMARGINWIDTHN
, 2, 0);
132 void sci_set_visible_eols(ScintillaObject
*sci
, gboolean set
)
134 SSM(sci
, SCI_SETVIEWEOL
, set
!= FALSE
, 0);
138 void sci_set_visible_white_spaces(ScintillaObject
*sci
, gboolean set
)
141 SSM(sci
, SCI_SETVIEWWS
, SCWS_VISIBLEALWAYS
, 0);
143 SSM(sci
, SCI_SETVIEWWS
, SCWS_INVISIBLE
, 0);
147 void sci_set_lines_wrapped(ScintillaObject
*sci
, gboolean set
)
150 SSM(sci
, SCI_SETWRAPMODE
, SC_WRAP_WORD
, 0);
152 SSM(sci
, SCI_SETWRAPMODE
, SC_WRAP_NONE
, 0);
156 gint
sci_get_eol_mode(ScintillaObject
*sci
)
158 return (gint
) SSM(sci
, SCI_GETEOLMODE
, 0, 0);
162 void sci_set_eol_mode(ScintillaObject
*sci
, gint eolmode
)
164 SSM(sci
, SCI_SETEOLMODE
, (uptr_t
) eolmode
, 0);
168 void sci_convert_eols(ScintillaObject
*sci
, gint eolmode
)
170 SSM(sci
, SCI_CONVERTEOLS
, (uptr_t
) eolmode
, 0);
174 void sci_add_text(ScintillaObject
*sci
, const gchar
*text
)
177 { /* if null text is passed scintilla will segfault */
178 SSM(sci
, SCI_ADDTEXT
, strlen(text
), (sptr_t
) text
);
184 * @param sci Scintilla widget.
185 * @param text Text. */
186 void sci_set_text(ScintillaObject
*sci
, const gchar
*text
)
188 if( text
!= NULL
){ /* if null text is passed to scintilla will segfault */
189 SSM(sci
, SCI_SETTEXT
, 0, (sptr_t
) text
);
194 gboolean
sci_can_undo(ScintillaObject
*sci
)
196 return SSM(sci
, SCI_CANUNDO
, 0, 0) != FALSE
;
200 gboolean
sci_can_redo(ScintillaObject
*sci
)
202 return SSM(sci
, SCI_CANREDO
, 0, 0) != FALSE
;
206 void sci_undo(ScintillaObject
*sci
)
208 if (sci_can_undo(sci
))
209 SSM(sci
, SCI_UNDO
, 0, 0);
213 void sci_redo(ScintillaObject
*sci
)
215 if (sci_can_redo(sci
))
216 SSM(sci
, SCI_REDO
, 0, 0);
220 /** Begins grouping a set of edits together as one Undo action.
221 * You must call sci_end_undo_action() after making your edits.
222 * @param sci Scintilla @c GtkWidget. */
223 void sci_start_undo_action(ScintillaObject
*sci
)
225 SSM(sci
, SCI_BEGINUNDOACTION
, 0, 0);
229 /** Ends grouping a set of edits together as one Undo action.
230 * @param sci Scintilla @c GtkWidget.
231 * @see sci_start_undo_action(). */
232 void sci_end_undo_action(ScintillaObject
*sci
)
234 SSM(sci
, SCI_ENDUNDOACTION
, 0, 0);
238 void sci_set_undo_collection(ScintillaObject
*sci
, gboolean set
)
240 SSM(sci
, SCI_SETUNDOCOLLECTION
, set
!= FALSE
, 0);
244 void sci_empty_undo_buffer(ScintillaObject
*sci
)
246 SSM(sci
, SCI_EMPTYUNDOBUFFER
, 0, 0);
250 gboolean
sci_is_modified(ScintillaObject
*sci
)
252 return (SSM(sci
, SCI_GETMODIFY
, 0, 0) != 0);
256 void sci_zoom_in(ScintillaObject
*sci
)
258 SSM(sci
, SCI_ZOOMIN
, 0, 0);
262 void sci_zoom_out(ScintillaObject
*sci
)
264 SSM(sci
, SCI_ZOOMOUT
, 0, 0);
268 void sci_zoom_off(ScintillaObject
*sci
)
270 SSM(sci
, SCI_SETZOOM
, 0, 0);
274 gint
sci_get_zoom(ScintillaObject
*sci
)
276 return (gint
) SSM(sci
, SCI_GETZOOM
, 0, 0);
280 /** Sets a line marker.
281 * @param sci Scintilla widget.
282 * @param line_number Line number.
283 * @param marker Marker number. */
284 void sci_set_marker_at_line(ScintillaObject
*sci
, gint line_number
, gint marker
)
286 SSM(sci
, SCI_MARKERADD
, (uptr_t
) line_number
, marker
);
290 /** Deletes a line marker.
291 * @param sci Scintilla widget.
292 * @param line_number Line number.
293 * @param marker Marker number. */
294 void sci_delete_marker_at_line(ScintillaObject
*sci
, gint line_number
, gint marker
)
296 SSM(sci
, SCI_MARKERDELETE
, (uptr_t
) line_number
, marker
);
300 /** Checks if a line has a marker set.
301 * @param sci Scintilla widget.
302 * @param line Line number.
303 * @param marker Marker number.
304 * @return Whether it's set. */
305 gboolean
sci_is_marker_set_at_line(ScintillaObject
*sci
, gint line
, gint marker
)
309 state
= (gint
) SSM(sci
, SCI_MARKERGET
, (uptr_t
) line
, 0);
310 return (state
& (1 << marker
));
314 void sci_toggle_marker_at_line(ScintillaObject
*sci
, gint line
, gint marker
)
316 gboolean set
= sci_is_marker_set_at_line(sci
, line
, marker
);
319 sci_set_marker_at_line(sci
, line
, marker
);
321 sci_delete_marker_at_line(sci
, line
, marker
);
325 /* Returns the line number of the next marker that matches marker_mask, or -1.
326 * marker_mask is a bitor of 1 << marker_index. (See MarkerHandleSet::MarkValue()).
327 * Note: If there is a marker on the line, it returns the same line. */
328 gint
sci_marker_next(ScintillaObject
*sci
, gint line
, gint marker_mask
, gboolean wrap
)
332 marker_line
= (gint
) SSM(sci
, SCI_MARKERNEXT
, (uptr_t
) line
, marker_mask
);
333 if (wrap
&& marker_line
== -1)
334 marker_line
= (gint
) SSM(sci
, SCI_MARKERNEXT
, 0, marker_mask
);
339 /* Returns the line number of the previous marker that matches marker_mask, or -1.
340 * marker_mask is a bitor of 1 << marker_index. (See MarkerHandleSet::MarkValue()).
341 * Note: If there is a marker on the line, it returns the same line. */
342 gint
sci_marker_previous(ScintillaObject
*sci
, gint line
, gint marker_mask
, gboolean wrap
)
346 marker_line
= (gint
) SSM(sci
, SCI_MARKERPREVIOUS
, (uptr_t
) line
, marker_mask
);
347 if (wrap
&& marker_line
== -1)
349 gint len
= sci_get_length(sci
);
350 gint last_line
= sci_get_line_from_position(sci
, len
- 1);
352 marker_line
= (gint
) SSM(sci
, SCI_MARKERPREVIOUS
, (uptr_t
) last_line
, marker_mask
);
358 /** Gets the line number from @a position.
359 * @param sci Scintilla widget.
360 * @param position Position.
361 * @return The line. */
362 gint
sci_get_line_from_position(ScintillaObject
*sci
, gint position
)
364 return (gint
) SSM(sci
, SCI_LINEFROMPOSITION
, (uptr_t
) position
, 0);
368 /** Gets the column number relative to the start of the line that @a position is on.
369 * @param sci Scintilla widget.
370 * @param position Position.
371 * @return The column. */
372 gint
sci_get_col_from_position(ScintillaObject
*sci
, gint position
)
374 return (gint
) SSM(sci
, SCI_GETCOLUMN
, (uptr_t
) position
, 0);
378 /** Gets the position for the start of @a line.
379 * @param sci Scintilla widget.
381 * @return Position. */
382 gint
sci_get_position_from_line(ScintillaObject
*sci
, gint line
)
384 return (gint
) SSM(sci
, SCI_POSITIONFROMLINE
, (uptr_t
) line
, 0);
388 /** Gets the cursor position.
389 * @param sci Scintilla widget.
390 * @return Position. */
391 gint
sci_get_current_position(ScintillaObject
*sci
)
393 return (gint
) SSM(sci
, SCI_GETCURRENTPOS
, 0, 0);
397 /** Sets the cursor position.
398 * @param sci Scintilla widget.
399 * @param position Position.
400 * @param scroll_to_caret Whether to scroll the cursor in view. */
401 void sci_set_current_position(ScintillaObject
*sci
, gint position
, gboolean scroll_to_caret
)
404 SSM(sci
, SCI_GOTOPOS
, (uptr_t
) position
, 0);
407 SSM(sci
, SCI_SETCURRENTPOS
, (uptr_t
) position
, 0);
408 SSM(sci
, SCI_SETANCHOR
, (uptr_t
) position
, 0); /* to avoid creation of a selection */
410 SSM(sci
, SCI_CHOOSECARETX
, 0, 0);
414 /* Set the cursor line without scrolling the view.
415 * Use sci_goto_line() to also scroll. */
416 void sci_set_current_line(ScintillaObject
*sci
, gint line
)
418 gint pos
= sci_get_position_from_line(sci
, line
);
419 sci_set_current_position(sci
, pos
, FALSE
);
423 /** Gets the total number of lines.
424 * @param sci Scintilla widget.
425 * @return The line count. */
426 gint
sci_get_line_count(ScintillaObject
*sci
)
428 return (gint
) SSM(sci
, SCI_GETLINECOUNT
, 0, 0);
432 /** Sets the selection start position.
433 * @param sci Scintilla widget.
434 * @param position Position. */
435 void sci_set_selection_start(ScintillaObject
*sci
, gint position
)
437 SSM(sci
, SCI_SETSELECTIONSTART
, (uptr_t
) position
, 0);
441 /** Sets the selection end position.
442 * @param sci Scintilla widget.
443 * @param position Position. */
444 void sci_set_selection_end(ScintillaObject
*sci
, gint position
)
446 SSM(sci
, SCI_SETSELECTIONEND
, (uptr_t
) position
, 0);
450 void sci_set_selection(ScintillaObject
*sci
, gint anchorPos
, gint currentPos
)
452 SSM(sci
, SCI_SETSEL
, (uptr_t
) anchorPos
, currentPos
);
456 /** Gets the position at the end of a line
457 * @param sci Scintilla widget.
459 * @return The position at the end of the line. */
460 gint
sci_get_line_end_position(ScintillaObject
*sci
, gint line
)
462 return (gint
) SSM(sci
, SCI_GETLINEENDPOSITION
, (uptr_t
) line
, 0);
466 void sci_cut(ScintillaObject
*sci
)
468 SSM(sci
, SCI_CUT
, 0, 0);
472 void sci_copy(ScintillaObject
*sci
)
474 SSM(sci
, SCI_COPY
, 0, 0);
478 void sci_paste(ScintillaObject
*sci
)
480 SSM(sci
, SCI_PASTE
, 0, 0);
484 void sci_clear(ScintillaObject
*sci
)
486 SSM(sci
, SCI_CLEAR
, 0, 0);
490 /** Gets the selection start position.
491 * @param sci Scintilla widget.
492 * @return Position. */
493 gint
sci_get_selection_start(ScintillaObject
*sci
)
495 return (gint
) SSM(sci
, SCI_GETSELECTIONSTART
, 0, 0);
499 /** Gets the selection end position.
500 * @param sci Scintilla widget.
501 * @return Position. */
502 gint
sci_get_selection_end(ScintillaObject
*sci
)
504 return (gint
) SSM(sci
, SCI_GETSELECTIONEND
, 0, 0);
508 /** Replaces selection.
509 * @param sci Scintilla widget.
510 * @param text Text. */
511 void sci_replace_sel(ScintillaObject
*sci
, const gchar
*text
)
513 SSM(sci
, SCI_REPLACESEL
, 0, (sptr_t
) text
);
517 /** Gets the length of all text.
518 * @param sci Scintilla widget.
520 gint
sci_get_length(ScintillaObject
*sci
)
522 return (gint
) SSM(sci
, SCI_GETLENGTH
, 0, 0);
526 gint
sci_get_lexer(ScintillaObject
*sci
)
528 return (gint
) SSM(sci
, SCI_GETLEXER
, 0, 0);
532 void sci_set_lexer(ScintillaObject
*sci
, guint lexer_id
)
534 gint old
= sci_get_lexer(sci
);
536 SSM(sci
, SCI_SETLEXER
, lexer_id
, 0);
538 if (old
!= (gint
)lexer_id
)
539 SSM(sci
, SCI_CLEARDOCUMENTSTYLE
, 0, 0);
543 /** Gets line length.
544 * @param sci Scintilla widget.
545 * @param line Line number.
547 gint
sci_get_line_length(ScintillaObject
*sci
, gint line
)
549 return (gint
) SSM(sci
, SCI_LINELENGTH
, (uptr_t
) line
, 0);
553 /* safe way to read Scintilla string into new memory.
554 * works with any string buffer messages that follow the Windows message convention. */
555 gchar
*sci_get_string(ScintillaObject
*sci
, guint msg
, gulong wParam
)
557 gint size
= (gint
) SSM(sci
, msg
, wParam
, 0);
558 gchar
*str
= g_malloc(size
+ 1);
560 SSM(sci
, msg
, wParam
, (sptr_t
) str
);
561 str
[size
] = '\0'; /* ensure termination, needed for SCI_GETLINE */
566 /** Gets line contents.
567 * @param sci Scintilla widget.
568 * @param line_num Line number.
569 * @return A @c NULL-terminated copy of the line text. */
570 gchar
*sci_get_line(ScintillaObject
*sci
, gint line_num
)
572 return sci_get_string(sci
, SCI_GETLINE
, (gulong
) line_num
);
577 * @deprecated sci_get_text is deprecated and should not be used in newly-written code.
578 * Use sci_get_contents() instead.
580 * @param sci Scintilla widget.
581 * @param len Length of @a text buffer, usually sci_get_length() + 1.
582 * @param text Text buffer; must be allocated @a len + 1 bytes for null-termination. */
583 void sci_get_text(ScintillaObject
*sci
, gint len
, gchar
*text
)
585 SSM(sci
, SCI_GETTEXT
, (uptr_t
) len
, (sptr_t
) text
);
589 /** Gets all text inside a given text length.
590 * @param sci Scintilla widget.
591 * @param len Length of the text to retrieve from the start of the document,
592 * usually sci_get_length() + 1.
593 * @return A copy of the text. Should be freed when no longer needed.
597 gchar
*sci_get_contents(ScintillaObject
*sci
, gint len
)
599 gchar
*text
= g_malloc(len
);
600 SSM(sci
, SCI_GETTEXT
, (uptr_t
) len
, (sptr_t
) text
);
605 /** Gets selected text.
606 * @deprecated sci_get_selected_text is deprecated and should not be used in newly-written code.
607 * Use sci_get_selection_contents() instead.
609 * @param sci Scintilla widget.
610 * @param text Text buffer; must be allocated sci_get_selected_text_length() + 1 bytes
611 * for null-termination. */
612 void sci_get_selected_text(ScintillaObject
*sci
, gchar
*text
)
614 SSM(sci
, SCI_GETSELTEXT
, 0, (sptr_t
) text
);
618 /** Gets selected text.
619 * @param sci Scintilla widget.
621 * @return The selected text. Should be freed when no longer needed.
625 gchar
*sci_get_selection_contents(ScintillaObject
*sci
)
627 return sci_get_string(sci
, SCI_GETSELTEXT
, 0);
631 /** Gets selected text length.
632 * @param sci Scintilla widget.
634 gint
sci_get_selected_text_length(ScintillaObject
*sci
)
636 return (gint
) SSM(sci
, SCI_GETSELTEXT
, 0, 0);
640 gint
sci_get_position_from_xy(ScintillaObject
*sci
, gint x
, gint y
, gboolean nearby
)
642 /* for nearby return -1 if there is no character near to the x,y point. */
643 return (gint
) SSM(sci
, (nearby
) ? SCI_POSITIONFROMPOINTCLOSE
: SCI_POSITIONFROMPOINT
, (uptr_t
) x
, y
);
647 /** Checks if a line is visible (folding may have hidden it).
648 * @param sci Scintilla widget.
649 * @param line Line number.
650 * @return Whether @a line will be drawn on the screen. */
651 gboolean
sci_get_line_is_visible(ScintillaObject
*sci
, gint line
)
653 return SSM(sci
, SCI_GETLINEVISIBLE
, (uptr_t
) line
, 0) != FALSE
;
657 /** Makes @a line visible (folding may have hidden it).
658 * @param sci Scintilla widget.
659 * @param line Line number. */
660 void sci_ensure_line_is_visible(ScintillaObject
*sci
, gint line
)
662 SSM(sci
, SCI_ENSUREVISIBLE
, (uptr_t
) line
, 0);
666 gint
sci_get_fold_level(ScintillaObject
*sci
, gint line
)
668 return (gint
) SSM(sci
, SCI_GETFOLDLEVEL
, (uptr_t
) line
, 0);
672 /* Get the line number of the fold point before start_line, or -1 if there isn't one */
673 gint
sci_get_fold_parent(ScintillaObject
*sci
, gint start_line
)
675 return (gint
) SSM(sci
, SCI_GETFOLDPARENT
, (uptr_t
) start_line
, 0);
679 void sci_toggle_fold(ScintillaObject
*sci
, gint line
)
681 SSM(sci
, SCI_TOGGLEFOLD
, (uptr_t
) line
, 1);
685 gboolean
sci_get_fold_expanded(ScintillaObject
*sci
, gint line
)
687 return SSM(sci
, SCI_GETFOLDEXPANDED
, (uptr_t
) line
, 0) != FALSE
;
691 void sci_colourise(ScintillaObject
*sci
, gint start
, gint end
)
693 SSM(sci
, SCI_COLOURISE
, (uptr_t
) start
, end
);
697 void sci_clear_all(ScintillaObject
*sci
)
699 SSM(sci
, SCI_CLEARALL
, 0, 0);
703 gint
sci_get_end_styled(ScintillaObject
*sci
)
705 return (gint
) SSM(sci
, SCI_GETENDSTYLED
, 0, 0);
709 void sci_set_tab_width(ScintillaObject
*sci
, gint width
)
711 SSM(sci
, SCI_SETTABWIDTH
, (uptr_t
) width
, 0);
715 /** Gets display tab width (this is not indent width, see GeanyIndentPrefs).
716 * @param sci Scintilla widget.
721 gint
sci_get_tab_width(ScintillaObject
*sci
)
723 return (gint
) SSM(sci
, SCI_GETTABWIDTH
, 0, 0);
727 /** Gets a character.
728 * @param sci Scintilla widget.
729 * @param pos Position.
731 gchar
sci_get_char_at(ScintillaObject
*sci
, gint pos
)
733 return (gchar
) SSM(sci
, SCI_GETCHARAT
, (uptr_t
) pos
, 0);
737 void sci_set_savepoint(ScintillaObject
*sci
)
739 SSM(sci
, SCI_SETSAVEPOINT
, 0, 0);
743 void sci_set_indentation_guides(ScintillaObject
*sci
, gint mode
)
745 SSM(sci
, SCI_SETINDENTATIONGUIDES
, (uptr_t
) mode
, 0);
749 void sci_use_popup(ScintillaObject
*sci
, gboolean enable
)
751 SSM(sci
, SCI_USEPOPUP
, enable
!= FALSE
, 0);
755 /** Checks if there's a selection.
756 * @param sci Scintilla widget.
757 * @return Whether a selection is present.
761 gboolean
sci_has_selection(ScintillaObject
*sci
)
763 if (SSM(sci
, SCI_GETSELECTIONEND
, 0, 0) - SSM(sci
, SCI_GETSELECTIONSTART
, 0, 0))
770 void sci_goto_pos(ScintillaObject
*sci
, gint pos
, gboolean unfold
)
772 if (unfold
) SSM(sci
, SCI_ENSUREVISIBLE
, (uptr_t
) SSM(sci
, SCI_LINEFROMPOSITION
, (uptr_t
) pos
, 0), 0);
773 SSM(sci
, SCI_GOTOPOS
, (uptr_t
) pos
, 0);
777 void sci_set_search_anchor(ScintillaObject
*sci
)
779 SSM(sci
, SCI_SEARCHANCHOR
, 0, 0);
783 /* removes a selection if pos < 0 */
784 void sci_set_anchor(ScintillaObject
*sci
, gint pos
)
787 pos
= sci_get_current_position(sci
);
789 SSM(sci
, SCI_SETANCHOR
, (uptr_t
) pos
, 0);
793 /** Scrolls the cursor in view.
794 * @param sci Scintilla widget. */
795 void sci_scroll_caret(ScintillaObject
*sci
)
797 SSM(sci
, SCI_SCROLLCARET
, 0, 0);
801 void sci_scroll_lines(ScintillaObject
*sci
, gint lines
)
803 SSM(sci
, SCI_LINESCROLL
, 0, lines
);
807 void sci_scroll_columns(ScintillaObject
*sci
, gint columns
)
809 SSM(sci
, SCI_LINESCROLL
, (uptr_t
) columns
, 0);
813 gint
sci_search_next(ScintillaObject
*sci
, gint flags
, const gchar
*text
)
815 /* FIXME: SCI_SEACHNEXT() actually returns long */
816 return (gint
) SSM(sci
, SCI_SEARCHNEXT
, (uptr_t
) flags
, (sptr_t
) text
);
820 gint
sci_search_prev(ScintillaObject
*sci
, gint flags
, const gchar
*text
)
822 /* FIXME: SCI_SEACHPREV() actually returns long */
823 return (gint
) SSM(sci
, SCI_SEARCHPREV
, (uptr_t
) flags
, (sptr_t
) text
);
827 /** Finds text in the document.
828 * The @a ttf argument should be a pointer to a Sci_TextToFind structure which contains
829 * the text to find and the range in which the text should be searched.
831 * Please refer to the Scintilla documentation for a more detailed description.
833 * @param sci Scintilla widget.
834 * @param flags Bitmask of Scintilla search flags (@c SCFIND_*, see Scintilla documentation).
835 * @param ttf Pointer to a TextToFind structure which contains the text to find and the range.
836 * @return The position of the start of the found text if it succeeds, otherwise @c -1.
837 * The @c chrgText.cpMin and @c chrgText.cpMax members of @c TextToFind are filled in
838 * with the start and end positions of the found text.
840 gint
sci_find_text(ScintillaObject
*sci
, gint flags
, struct Sci_TextToFind
*ttf
)
842 return (gint
) SSM(sci
, SCI_FINDTEXT
, (uptr_t
) flags
, (sptr_t
) ttf
);
846 /** Sets the font for a particular style.
847 * @param sci Scintilla widget.
848 * @param style The style.
849 * @param font The font name.
850 * @param size The font size. */
851 void sci_set_font(ScintillaObject
*sci
, gint style
, const gchar
*font
, gint size
)
853 SSM(sci
, SCI_STYLESETFONT
, (uptr_t
) style
, (sptr_t
) font
);
854 SSM(sci
, SCI_STYLESETSIZE
, (uptr_t
) style
, size
);
858 /** Jumps to the specified line in the document.
859 * If @a unfold is set and @a line is hidden by a fold, it is unfolded
860 * first to ensure it is visible.
861 * @param sci Scintilla widget.
863 * @param unfold Whether to unfold first.
865 void sci_goto_line(ScintillaObject
*sci
, gint line
, gboolean unfold
)
867 if (unfold
) SSM(sci
, SCI_ENSUREVISIBLE
, (uptr_t
) line
, 0);
868 SSM(sci
, SCI_GOTOLINE
, (uptr_t
) line
, 0);
872 void sci_marker_delete_all(ScintillaObject
*sci
, gint marker
)
874 SSM(sci
, SCI_MARKERDELETEALL
, (uptr_t
) marker
, 0);
878 /** Gets style ID at @a position.
879 * @param sci Scintilla widget.
880 * @param position Position.
881 * @return Style ID. */
882 gint
sci_get_style_at(ScintillaObject
*sci
, gint position
)
884 return (gint
) SSM(sci
, SCI_GETSTYLEAT
, (uptr_t
) position
, 0);
888 void sci_set_codepage(ScintillaObject
*sci
, gint cp
)
890 g_return_if_fail(cp
== 0 || cp
== SC_CP_UTF8
);
891 SSM(sci
, SCI_SETCODEPAGE
, (uptr_t
) cp
, 0);
895 void sci_assign_cmdkey(ScintillaObject
*sci
, gint key
, gint command
)
897 SSM(sci
, SCI_ASSIGNCMDKEY
, (uptr_t
) key
, command
);
901 void sci_clear_cmdkey(ScintillaObject
*sci
, gint key
)
903 SSM(sci
, SCI_CLEARCMDKEY
, (uptr_t
) key
, 0);
907 /** Gets text between @a start and @a end.
908 * @deprecated sci_get_text_range is deprecated and should not be used in newly-written code.
909 * Use sci_get_contents_range() instead.
911 * @param sci Scintilla widget.
912 * @param start Start.
914 * @param text Text will be zero terminated and must be allocated (end - start + 1) bytes. */
915 void sci_get_text_range(ScintillaObject
*sci
, gint start
, gint end
, gchar
*text
)
917 struct Sci_TextRange tr
;
918 tr
.chrg
.cpMin
= start
;
921 SSM(sci
, SCI_GETTEXTRANGE
, 0, (long) &tr
);
925 /** Gets text between @a start and @a end.
927 * @param sci Scintilla widget.
928 * @param start Start.
930 * @return The text inside the given range. Should be freed when no longer needed.
934 gchar
*sci_get_contents_range(ScintillaObject
*sci
, gint start
, gint end
)
938 g_return_val_if_fail(start
< end
, NULL
);
940 text
= g_malloc((gsize
) (end
- start
) + 1);
941 sci_get_text_range(sci
, start
, end
, text
);
946 void sci_line_duplicate(ScintillaObject
*sci
)
948 SSM(sci
, SCI_LINEDUPLICATE
, 0, 0);
952 void sci_selection_duplicate(ScintillaObject
*sci
)
954 SSM(sci
, SCI_SELECTIONDUPLICATE
, 0, 0);
959 * @param sci Scintilla widget.
960 * @param pos Position, or -1 for current.
961 * @param text Text. */
962 void sci_insert_text(ScintillaObject
*sci
, gint pos
, const gchar
*text
)
964 SSM(sci
, SCI_INSERTTEXT
, (uptr_t
) pos
, (sptr_t
) text
);
968 void sci_target_from_selection(ScintillaObject
*sci
)
970 SSM(sci
, SCI_TARGETFROMSELECTION
, 0, 0);
974 void sci_set_target_start(ScintillaObject
*sci
, gint start
)
976 SSM(sci
, SCI_SETTARGETSTART
, (uptr_t
) start
, 0);
980 void sci_set_target_end(ScintillaObject
*sci
, gint end
)
982 SSM(sci
, SCI_SETTARGETEND
, (uptr_t
) end
, 0);
986 gint
sci_replace_target(ScintillaObject
*sci
, const gchar
*text
, gboolean regex
)
988 return (gint
) SSM(sci
, (regex
) ? SCI_REPLACETARGETRE
: SCI_REPLACETARGET
, (uptr_t
) -1, (sptr_t
) text
);
992 void sci_set_keywords(ScintillaObject
*sci
, guint k
, const gchar
*text
)
994 SSM(sci
, SCI_SETKEYWORDS
, k
, (sptr_t
) text
);
998 void sci_set_readonly(ScintillaObject
*sci
, gboolean readonly
)
1000 SSM(sci
, SCI_SETREADONLY
, readonly
!= FALSE
, 0);
1004 /** Sends Scintilla commands without any parameters.
1005 * @param sci The Scintilla @c GtkWidget.
1006 * @param cmd @c SCI_COMMAND.
1007 * @see http://scintilla.org for the documentation.
1011 void sci_send_command(ScintillaObject
*sci
, gint cmd
)
1013 SSM(sci
, cmd
, 0, 0);
1017 /** Gets current line number.
1018 * @param sci Scintilla widget.
1019 * @return Line number. */
1020 gint
sci_get_current_line(ScintillaObject
*sci
)
1022 return (gint
) SSM(sci
, SCI_LINEFROMPOSITION
, (uptr_t
) SSM(sci
, SCI_GETCURRENTPOS
, 0, 0), 0);
1026 /* Get number of lines partially or fully selected.
1027 * Returns 1 if there is a partial selection on the same line.
1028 * Returns 2 if a whole line is selected including the line break char(s). */
1029 gint
sci_get_lines_selected(ScintillaObject
*sci
)
1031 gint start
= (gint
) SSM(sci
, SCI_GETSELECTIONSTART
, 0, 0);
1032 gint end
= (gint
) SSM(sci
, SCI_GETSELECTIONEND
, 0, 0);
1037 return 0; /* no selection */
1039 line_start
= (gint
) SSM(sci
, SCI_LINEFROMPOSITION
, (uptr_t
) start
, 0);
1040 line_end
= (gint
) SSM(sci
, SCI_LINEFROMPOSITION
, (uptr_t
) end
, 0);
1042 return line_end
- line_start
+ 1;
1046 gint
sci_get_first_visible_line(ScintillaObject
*sci
)
1048 return (gint
) SSM(sci
, SCI_GETFIRSTVISIBLELINE
, 0, 0);
1053 * Sets the current indicator. This is necessary to define an indicator for a range of text or
1054 * clearing indicators for a range of text.
1056 * @param sci Scintilla widget.
1057 * @param indic The indicator number to set.
1059 * @see sci_indicator_clear
1063 void sci_indicator_set(ScintillaObject
*sci
, gint indic
)
1065 SSM(sci
, SCI_SETINDICATORCURRENT
, (uptr_t
) indic
, 0);
1069 void sci_indicator_fill(ScintillaObject
*sci
, gint pos
, gint len
)
1071 SSM(sci
, SCI_INDICATORFILLRANGE
, (uptr_t
) pos
, len
);
1076 * Clears the currently set indicator from a range of text.
1077 * Starting at @a pos, @a len characters long.
1078 * In order to make this function properly, you need to set the current indicator before with
1079 * @ref sci_indicator_set().
1081 * @param sci Scintilla widget.
1082 * @param pos Starting position.
1083 * @param len Length.
1087 void sci_indicator_clear(ScintillaObject
*sci
, gint pos
, gint len
)
1089 SSM(sci
, SCI_INDICATORCLEARRANGE
, (uptr_t
) pos
, len
);
1093 void sci_select_all(ScintillaObject
*sci
)
1095 SSM(sci
, SCI_SELECTALL
, 0, 0);
1099 gint
sci_get_line_indent_position(ScintillaObject
*sci
, gint line
)
1101 return (gint
) SSM(sci
, SCI_GETLINEINDENTPOSITION
, (uptr_t
) line
, 0);
1105 void sci_set_autoc_max_height(ScintillaObject
*sci
, gint val
)
1107 SSM(sci
, SCI_AUTOCSETMAXHEIGHT
, (uptr_t
) val
, 0);
1111 /** Finds a matching brace at @a pos.
1112 * @param sci Scintilla widget.
1113 * @param pos Position.
1114 * @return Matching brace position.
1118 gint
sci_find_matching_brace(ScintillaObject
*sci
, gint pos
)
1120 return (gint
) SSM(sci
, SCI_BRACEMATCH
, (uptr_t
) pos
, 0);
1124 gint
sci_get_overtype(ScintillaObject
*sci
)
1126 return (gint
) SSM(sci
, SCI_GETOVERTYPE
, 0, 0);
1130 void sci_set_tab_indents(ScintillaObject
*sci
, gboolean set
)
1132 SSM(sci
, SCI_SETTABINDENTS
, set
!= FALSE
, 0);
1136 void sci_set_use_tabs(ScintillaObject
*sci
, gboolean set
)
1138 SSM(sci
, SCI_SETUSETABS
, set
!= FALSE
, 0);
1142 gint
sci_get_pos_at_line_sel_start(ScintillaObject
*sci
, gint line
)
1144 return (gint
) SSM(sci
, SCI_GETLINESELSTARTPOSITION
, (uptr_t
) line
, 0);
1148 gint
sci_get_pos_at_line_sel_end(ScintillaObject
*sci
, gint line
)
1150 return (gint
) SSM(sci
, SCI_GETLINESELENDPOSITION
, (uptr_t
) line
, 0);
1154 /** Gets selection mode.
1155 * @param sci Scintilla widget.
1156 * @return Selection mode. */
1157 gint
sci_get_selection_mode(ScintillaObject
*sci
)
1159 return (gint
) SSM(sci
, SCI_GETSELECTIONMODE
, 0, 0);
1163 /** Sets selection mode.
1164 * @param sci Scintilla widget.
1165 * @param mode Mode. */
1166 void sci_set_selection_mode(ScintillaObject
*sci
, gint mode
)
1168 SSM(sci
, SCI_SETSELECTIONMODE
, (uptr_t
) mode
, 0);
1172 void sci_set_scrollbar_mode(ScintillaObject
*sci
, gboolean visible
)
1174 SSM(sci
, SCI_SETHSCROLLBAR
, visible
!= FALSE
, 0);
1175 SSM(sci
, SCI_SETVSCROLLBAR
, visible
!= FALSE
, 0);
1179 /** Sets the indentation of a line.
1180 * @param sci Scintilla widget.
1181 * @param line Line to indent.
1182 * @param indent Indentation width.
1186 void sci_set_line_indentation(ScintillaObject
*sci
, gint line
, gint indent
)
1188 SSM(sci
, SCI_SETLINEINDENTATION
, (uptr_t
) line
, indent
);
1192 /** Gets the indentation width of a line.
1193 * @param sci Scintilla widget.
1194 * @param line Line to get the indentation from.
1195 * @return Indentation width.
1199 gint
sci_get_line_indentation(ScintillaObject
*sci
, gint line
)
1201 return (gint
) SSM(sci
, SCI_GETLINEINDENTATION
, (uptr_t
) line
, 0);
1205 void sci_set_caret_policy_x(ScintillaObject
*sci
, gint policy
, gint slop
)
1207 SSM(sci
, SCI_SETXCARETPOLICY
, (uptr_t
) policy
, slop
);
1211 void sci_set_caret_policy_y(ScintillaObject
*sci
, gint policy
, gint slop
)
1213 SSM(sci
, SCI_SETYCARETPOLICY
, (uptr_t
) policy
, slop
);
1217 void sci_set_scroll_stop_at_last_line(ScintillaObject
*sci
, gboolean set
)
1219 SSM(sci
, SCI_SETENDATLASTLINE
, set
!= FALSE
, 0);
1223 void sci_cancel(ScintillaObject
*sci
)
1225 SSM(sci
, SCI_CANCEL
, 0, 0);
1229 gint
sci_get_target_end(ScintillaObject
*sci
)
1231 return (gint
) SSM(sci
, SCI_GETTARGETEND
, 0, 0);
1235 gint
sci_get_position_after(ScintillaObject
*sci
, gint start
)
1237 return (gint
) SSM(sci
, SCI_POSITIONAFTER
, (uptr_t
) start
, 0);
1241 void sci_lines_split(ScintillaObject
*sci
, gint pixelWidth
)
1243 SSM(sci
, SCI_LINESSPLIT
, (uptr_t
) pixelWidth
, 0);
1247 void sci_lines_join(ScintillaObject
*sci
)
1249 SSM(sci
, SCI_LINESJOIN
, 0, 0);
1253 gint
sci_text_width(ScintillaObject
*sci
, gint styleNumber
, const gchar
*text
)
1255 return (gint
) SSM(sci
, SCI_TEXTWIDTH
, (uptr_t
) styleNumber
, (sptr_t
) text
);
1258 void sci_move_selected_lines_down(ScintillaObject
*sci
)
1260 SSM(sci
, SCI_MOVESELECTEDLINESDOWN
, 0, 0);
1263 void sci_move_selected_lines_up(ScintillaObject
*sci
)
1265 SSM(sci
, SCI_MOVESELECTEDLINESUP
, 0, 0);