2
2
* sciwrappers.c - this file is part of Geany, a fast and lightweight IDE
4
* Copyright 2006 Enrico Troeger <enrico.troeger@uvena.de>
4
* Copyright 2005-2008 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
5
* Copyright 2006-2008 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
6
6
* This program is free software; you can redistribute it and/or modify
7
7
* it under the terms of the GNU General Public License as published by
8
8
* the Free Software Foundation; either version 2 of the License, or
17
17
* along with this program; if not, write to the Free Software
18
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
* $Id: sciwrappers.c 829 2006-09-21 10:31:06Z ntrel $
20
* $Id: sciwrappers.c 2312 2008-03-07 15:42:46Z eht16 $
24
* Wrappers for the SCI_* Scintilla messages.
25
* Originally from the cssed project (http://cssed.sf.net).
23
28
#include <string.h>
30
35
#define SSM(s, m, w, l) scintilla_send_message(s, m, w, l)
33
// stolen from cssed (http://cssed.sf.net), thanks
38
/* stolen from cssed (http://cssed.sf.net), thanks */
36
41
/* line numbers visibility */
44
49
g_snprintf(tmp_str, 15, "_%d%d", len, extra_width);
45
50
width = SSM(sci, SCI_TEXTWIDTH, STYLE_LINENUMBER, (sptr_t) tmp_str);
46
51
SSM (sci, SCI_SETMARGINWIDTHN, 0, width);
47
SSM (sci, SCI_SETMARGINSENSITIVEN, 0, FALSE); // use default behaviour
52
SSM (sci, SCI_SETMARGINSENSITIVEN, 0, FALSE); /* use default behaviour */
76
SSM(sci, SCI_SETEDGECOLUMN, column - 1, 0);
81
SSM(sci, SCI_SETEDGECOLUMN, column, 0);
77
82
SSM(sci, SCI_SETEDGECOLOUR, utils_strtod(colour, NULL, TRUE), 0);
160
164
void sci_set_lines_wrapped(ScintillaObject* sci, gboolean set )
163
167
SSM(sci,SCI_SETWRAPMODE,SC_WRAP_WORD,0);
164
SSM(sci, SCI_SETWRAPVISUALFLAGS, SC_WRAPVISUALFLAG_END, 0);
166
169
SSM(sci,SCI_SETWRAPMODE,SC_WRAP_NONE,0);
170
172
gboolean sci_get_lines_wrapped(ScintillaObject* sci)
190
192
void sci_add_text(ScintillaObject* sci, const gchar* text)
192
if( text != NULL ){// if null text is passed to scintilla will segfault
194
if( text != NULL ){ /* if null text is passed to scintilla will segfault */
193
195
SSM( sci, SCI_ADDTEXT, strlen(text), (sptr_t) text);
197
199
void sci_set_text(ScintillaObject* sci, const gchar* text)
199
if( text != NULL ){// if null text is passed to scintilla will segfault
201
if( text != NULL ){ /* if null text is passed to scintilla will segfault */
200
202
SSM( sci, SCI_SETTEXT, 0, (sptr_t) text);
205
207
void sci_add_text_buffer(ScintillaObject* sci, const gchar* text, gint len)
207
if( text != NULL ){// if null text is passed to scintilla will segfault
209
if( text != NULL ){ /* if null text is passed to scintilla will segfault */
208
210
SSM(sci, SCI_CLEARALL, 0, 0);
209
211
SSM(sci, SCI_ADDTEXT, len, (sptr_t) text);
317
state = SSM( sci, SCI_MARKERGET, line, marker );
318
return(!(state & (1 << marker)));
327
state = SSM( sci, SCI_MARKERGET, line, 0 );
328
return (state & (1 << marker));
322
gboolean sci_marker_next(ScintillaObject* sci, gint line, gint marker_mask)
332
/* Returns the line number of the next marker that matches marker_mask, or -1.
333
* marker_mask is a bitor of 1 << marker_index. (See MarkerHandleSet::MarkValue()).
334
* Note: If there is a marker on the line, it returns the same line. */
335
gint sci_marker_next(ScintillaObject* sci, gint line, gint marker_mask, gboolean wrap)
324
337
gint marker_line;
326
339
marker_line = SSM(sci, SCI_MARKERNEXT, line, marker_mask);
328
if( marker_line != -1 ){
329
SSM(sci,SCI_GOTOLINE,marker_line,0);
340
if (wrap && marker_line == -1)
341
marker_line = SSM(sci, SCI_MARKERNEXT, 0, marker_mask);
337
gboolean sci_marker_prev(ScintillaObject* sci, gint line, gint marker_mask)
346
/* Returns the line number of the previous marker that matches marker_mask, or -1.
347
* marker_mask is a bitor of 1 << marker_index. (See MarkerHandleSet::MarkValue()).
348
* Note: If there is a marker on the line, it returns the same line. */
349
gint sci_marker_previous(ScintillaObject* sci, gint line, gint marker_mask, gboolean wrap)
339
351
gint marker_line;
341
353
marker_line = SSM(sci, SCI_MARKERPREVIOUS, line, marker_mask);
354
if (wrap && marker_line == -1)
356
gint len = sci_get_length(sci);
357
gint last_line = sci_get_line_from_position(sci, len - 1);
343
if( marker_line != -1 ){
344
SSM(sci,SCI_GOTOLINE,marker_line,0);
359
marker_line = SSM(sci, SCI_MARKERPREVIOUS, last_line, marker_mask);
376
void sci_set_current_position(ScintillaObject* sci, gint position )
389
void sci_set_current_position(ScintillaObject* sci, gint position, gboolean scroll_to_caret)
378
SSM(sci, SCI_GOTOPOS, position, 0);
392
SSM(sci, SCI_GOTOPOS, position, 0);
395
SSM(sci, SCI_SETCURRENTPOS, position, 0);
396
SSM(sci, SCI_SETANCHOR, position, 0); /* to avoid creation of a selection */
398
SSM(sci, SCI_CHOOSECARETX, 0, 0);
382
void sci_set_current_line(ScintillaObject* sci, gint line )
402
/* Set the cursor line without scrolling the view.
403
* Use sci_goto_line() to also scroll. */
404
void sci_set_current_line(ScintillaObject* sci, gint line)
384
SSM(sci, SCI_GOTOLINE, line, 0);
406
gint pos = sci_get_position_from_line(sci, line);
407
sci_set_current_position(sci, pos, FALSE);
406
gint sci_get_line_end_from_position(ScintillaObject* sci, gint position)
429
gint sci_get_line_end_position(ScintillaObject* sci, gint line)
408
return SSM(sci, SCI_GETLINEENDPOSITION, position, 0);
431
return SSM(sci, SCI_GETLINEENDPOSITION, line, 0);
472
void sci_get_line(ScintillaObject* sci, gint line, gchar* text)
495
/* Returns: a NULL-terminated copy of the line text */
496
gchar *sci_get_line(ScintillaObject* sci, gint line_num)
474
SSM(sci,SCI_GETLINE, line, (sptr_t) text);
498
gint len = sci_get_line_length(sci, line_num);
499
gchar *linebuf = g_malloc(len + 1);
501
SSM(sci, SCI_GETLINE, line_num, (sptr_t) linebuf);
477
// the last char will be null terminated
507
/* the last char will be null terminated */
478
508
void sci_get_text(ScintillaObject* sci, gint len, gchar* text)
480
510
SSM( sci, SCI_GETTEXT, len, (sptr_t) text );
514
/* Text must be allocated sci_get_selected_text_length() + 1, because
515
* the selection will be NULL-terminated. */
484
516
void sci_get_selected_text(ScintillaObject* sci, gchar* text)
486
518
SSM( sci, SCI_GETSELTEXT, 0, (sptr_t) text);
496
528
gint sci_get_position_from_xy(ScintillaObject* sci, gint x, gint y, gboolean nearby)
498
// for nearby return -1 if there is no character near to the x,y point.
530
/* for nearby return -1 if there is no character near to the x,y point. */
499
531
return SSM(sci, (nearby) ? SCI_POSITIONFROMPOINTCLOSE : SCI_POSITIONFROMPOINT, x, y);
561
/* Get the next line after start_line with fold level <= level */
562
gint sci_get_last_child(ScintillaObject* sci, gint start_line, gint level)
564
return SSM( sci, SCI_GETLASTCHILD, start_line, level);
568
/* Get the line number of the fold point before start_line, or -1 if there isn't one */
569
gint sci_get_fold_parent(ScintillaObject* sci, gint start_line)
571
return SSM( sci, SCI_GETFOLDPARENT, start_line, 0);
529
575
void sci_toggle_fold(ScintillaObject* sci, gint line)
531
577
SSM( sci, SCI_TOGGLEFOLD, line, 1);
565
gint sci_get_line_end_styled(ScintillaObject * sci, gint end_styled)
567
return SSM(sci,SCI_LINEFROMPOSITION, end_styled,0);
571
611
void sci_set_tab_width(ScintillaObject * sci, gint width)
573
613
SSM(sci, SCI_SETTABWIDTH, width, 0);
617
void sci_goto_pos(ScintillaObject *sci, gint pos, gboolean ensure_visibility)
657
void sci_goto_pos(ScintillaObject *sci, gint pos, gboolean unfold)
619
if (ensure_visibility) SSM(sci,SCI_ENSUREVISIBLE,SSM(sci, SCI_LINEFROMPOSITION, pos, 0),0);
659
if (unfold) SSM(sci,SCI_ENSUREVISIBLE,SSM(sci, SCI_LINEFROMPOSITION, pos, 0),0);
620
660
SSM(sci, SCI_GOTOPOS, pos, 0);
682
void sci_scroll_lines(ScintillaObject *sci, gint lines)
684
SSM(sci, SCI_LINESCROLL, 0, lines);
642
688
gint sci_search_next(ScintillaObject *sci, gint flags, const gchar *text)
644
690
return SSM(sci, SCI_SEARCHNEXT, flags, (sptr_t) text );
674
void sci_goto_line_scroll(ScintillaObject *sci, gint line, gdouble percent_of_view)
676
gint vis1, los, delta;
678
sci_goto_line(sci, line, TRUE);
679
// sci 'visible line' != file line number
680
vis1 = SSM(sci, SCI_GETFIRSTVISIBLELINE, 0, 0);
681
vis1 = SSM(sci, SCI_DOCLINEFROMVISIBLE, vis1, 0);
682
los = SSM(sci, SCI_LINESONSCREEN, 0, 0);
683
delta = (line - vis1) - los * percent_of_view;
684
sci_scroll_lines(sci, delta);
685
sci_scroll_caret(sci); //ensure visible, in case of excessive folding/wrapping
689
720
void sci_marker_delete_all(ScintillaObject *sci, gint marker)
691
722
SSM(sci, SCI_MARKERDELETEALL, marker, 0);
785
817
SSM(sci, SCI_SETKEYWORDS, k, (sptr_t) text);
788
void sci_scroll_lines(ScintillaObject *sci, gint lines)
790
SSM(sci, SCI_LINESCROLL, 0, lines);
793
820
void sci_set_readonly(ScintillaObject *sci, gboolean readonly)
795
822
SSM(sci, SCI_SETREADONLY, readonly, 0);
800
827
return SSM(sci, SCI_GETREADONLY, 0, 0);
803
// a simple convenience function to not have SSM() in the outside of this file
830
/* a simple convenience function to not have SSM() in the outside of this file */
804
831
void sci_cmd(ScintillaObject * sci, gint cmd)
806
833
SSM(sci, cmd, 0, 0);
809
gint sci_get_current_line(ScintillaObject *sci, gint pos)
837
gint sci_get_current_line(ScintillaObject *sci)
813
return SSM(sci, SCI_LINEFROMPOSITION, pos, 0);
817
return SSM(sci, SCI_LINEFROMPOSITION, SSM(sci, SCI_GETCURRENTPOS, 0, 0), 0);
839
return SSM(sci, SCI_LINEFROMPOSITION, SSM(sci, SCI_GETCURRENTPOS, 0, 0), 0);
821
842
/* Get number of lines partially or fully selected.
827
848
gint end = SSM(sci, SCI_GETSELECTIONEND, 0, 0);
829
850
if (start == end)
830
return 0; // no selection
851
return 0; /* no selection */
832
853
return SSM(sci, SCI_LINEFROMPOSITION, end, 0) - SSM(sci, SCI_LINEFROMPOSITION, start, 0) + 1;
856
gint sci_get_first_visible_line(ScintillaObject *sci)
858
return SSM(sci, SCI_GETFIRSTVISIBLELINE, 0, 0);
835
862
void sci_set_styling(ScintillaObject *sci, gint len, gint style)
837
864
if (len < 0 || style < 0) return;
859
886
SSM(sci, SCI_AUTOCSETMAXHEIGHT, val, 0);
889
gint sci_find_bracematch(ScintillaObject *sci, gint pos)
891
return SSM(sci, SCI_BRACEMATCH, pos, 0);
894
gint sci_get_overtype(ScintillaObject *sci)
896
return SSM(sci, SCI_GETOVERTYPE, 0, 0);
899
void sci_set_tab_indents(ScintillaObject *sci, gboolean set)
901
SSM(sci, SCI_SETTABINDENTS, set, 0);
904
void sci_set_use_tabs(ScintillaObject *sci, gboolean set)
906
SSM(sci, SCI_SETUSETABS, set, 0);
909
gint sci_get_pos_at_line_sel_start(ScintillaObject *sci, gint line)
911
return SSM(sci, SCI_GETLINESELSTARTPOSITION, line, 0);
914
gint sci_get_pos_at_line_sel_end(ScintillaObject *sci, gint line)
916
return SSM(sci, SCI_GETLINESELENDPOSITION, line, 0);
919
gint sci_get_selection_mode(ScintillaObject *sci)
921
return SSM(sci, SCI_GETSELECTIONMODE, 0, 0);
924
void sci_set_selection_mode(ScintillaObject *sci, gint mode)
926
SSM(sci, SCI_SETSELECTIONMODE, mode, 0);
929
void sci_set_scrollbar_mode(ScintillaObject *sci, gboolean visible)
931
SSM(sci, SCI_SETHSCROLLBAR, visible, 0);
932
SSM(sci, SCI_SETVSCROLLBAR, visible, 0);
935
void sci_set_line_indentation(ScintillaObject *sci, gint line, gint indent)
937
SSM(sci, SCI_SETLINEINDENTATION, line, indent);
940
int sci_get_line_indentation(ScintillaObject *sci, gint line)
942
return SSM(sci, SCI_GETLINEINDENTATION, line, 0);
945
void sci_set_caret_policy_x(ScintillaObject *sci, gint policy, gint slop)
947
SSM(sci, SCI_SETXCARETPOLICY, policy, slop);
950
void sci_set_caret_policy_y(ScintillaObject *sci, gint policy, gint slop)
952
SSM(sci, SCI_SETYCARETPOLICY, policy, slop);