/
sciwrappers.c
1266 lines (975 loc) · 29.6 KB
/
sciwrappers.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* sciwrappers.c - this file is part of Geany, a fast and lightweight IDE
*
* Copyright 2005-2012 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
* Copyright 2006-2012 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/** @file sciwrappers.h
* Wrapper functions for the Scintilla editor widget @c SCI_* messages.
* You should also check the http://scintilla.org documentation, as it is more detailed.
*
* To get Scintilla notifications, use the
* @link pluginsignals.c @c "editor-notify" signal @endlink.
*
* @note These functions were originally from the cssed project
* (http://cssed.sf.net, thanks).
* @see scintilla_send_message().
*/
#include <string.h>
#include "geany.h"
#include "sciwrappers.h"
#include "utils.h"
#define SSM(s, m, w, l) scintilla_send_message(s, m, w, l)
/* line numbers visibility */
void sci_set_line_numbers(ScintillaObject *sci, gboolean set, gint extra_width)
{
if (set)
{
gchar tmp_str[15];
gint len = (gint) SSM(sci, SCI_GETLINECOUNT, 0, 0);
gint width;
g_snprintf(tmp_str, 15, "_%d", len);
width = sci_text_width(sci, STYLE_LINENUMBER, tmp_str);
if (extra_width)
{
g_snprintf(tmp_str, 15, "%d", extra_width);
width += sci_text_width(sci, STYLE_LINENUMBER, tmp_str);
}
SSM(sci, SCI_SETMARGINWIDTHN, 0, width);
SSM(sci, SCI_SETMARGINSENSITIVEN, 0, FALSE); /* use default behaviour */
}
else
{
SSM(sci, SCI_SETMARGINWIDTHN, 0, 0);
}
}
void sci_set_mark_long_lines(ScintillaObject *sci, gint type, gint column, const gchar *colour)
{
glong colour_val = utils_strtod(colour, NULL, TRUE); /* Scintilla uses a "long" value */
if (column == 0)
type = 2;
switch (type)
{
case 0:
{
SSM(sci, SCI_SETEDGEMODE, EDGE_LINE, 0);
break;
}
case 1:
{
SSM(sci, SCI_SETEDGEMODE, EDGE_BACKGROUND, 0);
break;
}
case 2:
{
SSM(sci, SCI_SETEDGEMODE, EDGE_NONE, 0);
return;
}
}
SSM(sci, SCI_SETEDGECOLUMN, (uptr_t) column, 0);
SSM(sci, SCI_SETEDGECOLOUR, (uptr_t) colour_val, 0);
}
/* symbol margin visibility */
void sci_set_symbol_margin(ScintillaObject *sci, gboolean set)
{
if (set)
{
SSM(sci, SCI_SETMARGINWIDTHN, 1, 16);
SSM(sci, SCI_SETMARGINSENSITIVEN, 1, TRUE);
}
else
{
SSM(sci, SCI_SETMARGINWIDTHN, 1, 0);
SSM(sci, SCI_SETMARGINSENSITIVEN, 1, FALSE);
}
}
/* folding margin visibility */
void sci_set_folding_margin_visible(ScintillaObject *sci, gboolean set)
{
if (set)
{
SSM(sci, SCI_SETMARGINWIDTHN, 2, 12);
SSM(sci, SCI_SETMARGINSENSITIVEN, 2, TRUE);
}
else
{
SSM(sci, SCI_SETMARGINSENSITIVEN, 2, FALSE);
SSM(sci, SCI_SETMARGINWIDTHN, 2, 0);
}
}
/* end of lines */
void sci_set_visible_eols(ScintillaObject *sci, gboolean set)
{
SSM(sci, SCI_SETVIEWEOL, set != FALSE, 0);
}
void sci_set_visible_white_spaces(ScintillaObject *sci, gboolean set)
{
if (set)
SSM(sci, SCI_SETVIEWWS, SCWS_VISIBLEALWAYS, 0);
else
SSM(sci, SCI_SETVIEWWS, SCWS_INVISIBLE, 0);
}
void sci_set_lines_wrapped(ScintillaObject *sci, gboolean set)
{
if (set)
SSM(sci, SCI_SETWRAPMODE, SC_WRAP_WORD, 0);
else
SSM(sci, SCI_SETWRAPMODE, SC_WRAP_NONE, 0);
}
gint sci_get_eol_mode(ScintillaObject *sci)
{
return (gint) SSM(sci, SCI_GETEOLMODE, 0, 0);
}
void sci_set_eol_mode(ScintillaObject *sci, gint eolmode)
{
SSM(sci, SCI_SETEOLMODE, (uptr_t) eolmode, 0);
}
void sci_convert_eols(ScintillaObject *sci, gint eolmode)
{
SSM(sci, SCI_CONVERTEOLS, (uptr_t) eolmode, 0);
}
void sci_add_text(ScintillaObject *sci, const gchar *text)
{
if (text != NULL)
{ /* if null text is passed scintilla will segfault */
SSM(sci, SCI_ADDTEXT, strlen(text), (sptr_t) text);
}
}
/** Sets all text.
* @param sci Scintilla widget.
* @param text Text. */
void sci_set_text(ScintillaObject *sci, const gchar *text)
{
if( text != NULL ){ /* if null text is passed to scintilla will segfault */
SSM(sci, SCI_SETTEXT, 0, (sptr_t) text);
}
}
gboolean sci_can_undo(ScintillaObject *sci)
{
return SSM(sci, SCI_CANUNDO, 0, 0) != FALSE;
}
gboolean sci_can_redo(ScintillaObject *sci)
{
return SSM(sci, SCI_CANREDO, 0, 0) != FALSE;
}
void sci_undo(ScintillaObject *sci)
{
if (sci_can_undo(sci))
SSM(sci, SCI_UNDO, 0, 0);
}
void sci_redo(ScintillaObject *sci)
{
if (sci_can_redo(sci))
SSM(sci, SCI_REDO, 0, 0);
}
/** Begins grouping a set of edits together as one Undo action.
* You must call sci_end_undo_action() after making your edits.
* @param sci Scintilla @c GtkWidget. */
void sci_start_undo_action(ScintillaObject *sci)
{
SSM(sci, SCI_BEGINUNDOACTION, 0, 0);
}
/** Ends grouping a set of edits together as one Undo action.
* @param sci Scintilla @c GtkWidget.
* @see sci_start_undo_action(). */
void sci_end_undo_action(ScintillaObject *sci)
{
SSM(sci, SCI_ENDUNDOACTION, 0, 0);
}
void sci_set_undo_collection(ScintillaObject *sci, gboolean set)
{
SSM(sci, SCI_SETUNDOCOLLECTION, set != FALSE, 0);
}
void sci_empty_undo_buffer(ScintillaObject *sci)
{
SSM(sci, SCI_EMPTYUNDOBUFFER, 0, 0);
}
gboolean sci_is_modified(ScintillaObject *sci)
{
return (SSM(sci, SCI_GETMODIFY, 0, 0) != 0);
}
void sci_zoom_in(ScintillaObject *sci)
{
SSM(sci, SCI_ZOOMIN, 0, 0);
}
void sci_zoom_out(ScintillaObject *sci)
{
SSM(sci, SCI_ZOOMOUT, 0, 0);
}
void sci_zoom_off(ScintillaObject *sci)
{
SSM(sci, SCI_SETZOOM, 0, 0);
}
gint sci_get_zoom(ScintillaObject *sci)
{
return (gint) SSM(sci, SCI_GETZOOM, 0, 0);
}
/** Sets a line marker.
* @param sci Scintilla widget.
* @param line_number Line number.
* @param marker Marker number. */
void sci_set_marker_at_line(ScintillaObject *sci, gint line_number, gint marker)
{
SSM(sci, SCI_MARKERADD, (uptr_t) line_number, marker);
}
/** Deletes a line marker.
* @param sci Scintilla widget.
* @param line_number Line number.
* @param marker Marker number. */
void sci_delete_marker_at_line(ScintillaObject *sci, gint line_number, gint marker)
{
SSM(sci, SCI_MARKERDELETE, (uptr_t) line_number, marker);
}
/** Checks if a line has a marker set.
* @param sci Scintilla widget.
* @param line Line number.
* @param marker Marker number.
* @return Whether it's set. */
gboolean sci_is_marker_set_at_line(ScintillaObject *sci, gint line, gint marker)
{
gint state;
state = (gint) SSM(sci, SCI_MARKERGET, (uptr_t) line, 0);
return (state & (1 << marker));
}
void sci_toggle_marker_at_line(ScintillaObject *sci, gint line, gint marker)
{
gboolean set = sci_is_marker_set_at_line(sci, line, marker);
if (!set)
sci_set_marker_at_line(sci, line, marker);
else
sci_delete_marker_at_line(sci, line, marker);
}
/* Returns the line number of the next marker that matches marker_mask, or -1.
* marker_mask is a bitor of 1 << marker_index. (See MarkerHandleSet::MarkValue()).
* Note: If there is a marker on the line, it returns the same line. */
gint sci_marker_next(ScintillaObject *sci, gint line, gint marker_mask, gboolean wrap)
{
gint marker_line;
marker_line = (gint) SSM(sci, SCI_MARKERNEXT, (uptr_t) line, marker_mask);
if (wrap && marker_line == -1)
marker_line = (gint) SSM(sci, SCI_MARKERNEXT, 0, marker_mask);
return marker_line;
}
/* Returns the line number of the previous marker that matches marker_mask, or -1.
* marker_mask is a bitor of 1 << marker_index. (See MarkerHandleSet::MarkValue()).
* Note: If there is a marker on the line, it returns the same line. */
gint sci_marker_previous(ScintillaObject *sci, gint line, gint marker_mask, gboolean wrap)
{
gint marker_line;
marker_line = (gint) SSM(sci, SCI_MARKERPREVIOUS, (uptr_t) line, marker_mask);
if (wrap && marker_line == -1)
{
gint len = sci_get_length(sci);
gint last_line = sci_get_line_from_position(sci, len - 1);
marker_line = (gint) SSM(sci, SCI_MARKERPREVIOUS, (uptr_t) last_line, marker_mask);
}
return marker_line;
}
/** Gets the line number from @a position.
* @param sci Scintilla widget.
* @param position Position.
* @return The line. */
gint sci_get_line_from_position(ScintillaObject *sci, gint position)
{
return (gint) SSM(sci, SCI_LINEFROMPOSITION, (uptr_t) position, 0);
}
/** Gets the column number relative to the start of the line that @a position is on.
* @param sci Scintilla widget.
* @param position Position.
* @return The column. */
gint sci_get_col_from_position(ScintillaObject *sci, gint position)
{
return (gint) SSM(sci, SCI_GETCOLUMN, (uptr_t) position, 0);
}
/** Gets the position for the start of @a line.
* @param sci Scintilla widget.
* @param line Line.
* @return Position. */
gint sci_get_position_from_line(ScintillaObject *sci, gint line)
{
return (gint) SSM(sci, SCI_POSITIONFROMLINE, (uptr_t) line, 0);
}
/** Gets the cursor position.
* @param sci Scintilla widget.
* @return Position. */
gint sci_get_current_position(ScintillaObject *sci)
{
return (gint) SSM(sci, SCI_GETCURRENTPOS, 0, 0);
}
/** Sets the cursor position.
* @param sci Scintilla widget.
* @param position Position.
* @param scroll_to_caret Whether to scroll the cursor in view. */
void sci_set_current_position(ScintillaObject *sci, gint position, gboolean scroll_to_caret)
{
if (scroll_to_caret)
SSM(sci, SCI_GOTOPOS, (uptr_t) position, 0);
else
{
SSM(sci, SCI_SETCURRENTPOS, (uptr_t) position, 0);
SSM(sci, SCI_SETANCHOR, (uptr_t) position, 0); /* to avoid creation of a selection */
}
SSM(sci, SCI_CHOOSECARETX, 0, 0);
}
/* Set the cursor line without scrolling the view.
* Use sci_goto_line() to also scroll. */
void sci_set_current_line(ScintillaObject *sci, gint line)
{
gint pos = sci_get_position_from_line(sci, line);
sci_set_current_position(sci, pos, FALSE);
}
/** Gets the total number of lines.
* @param sci Scintilla widget.
* @return The line count. */
gint sci_get_line_count(ScintillaObject *sci)
{
return (gint) SSM(sci, SCI_GETLINECOUNT, 0, 0);
}
/** Sets the selection start position.
* @param sci Scintilla widget.
* @param position Position. */
void sci_set_selection_start(ScintillaObject *sci, gint position)
{
SSM(sci, SCI_SETSELECTIONSTART, (uptr_t) position, 0);
}
/** Sets the selection end position.
* @param sci Scintilla widget.
* @param position Position. */
void sci_set_selection_end(ScintillaObject *sci, gint position)
{
SSM(sci, SCI_SETSELECTIONEND, (uptr_t) position, 0);
}
void sci_set_selection(ScintillaObject *sci, gint anchorPos, gint currentPos)
{
SSM(sci, SCI_SETSEL, (uptr_t) anchorPos, currentPos);
}
/** Gets the position at the end of a line
* @param sci Scintilla widget.
* @param line Line.
* @return The position at the end of the line. */
gint sci_get_line_end_position(ScintillaObject *sci, gint line)
{
return (gint) SSM(sci, SCI_GETLINEENDPOSITION, (uptr_t) line, 0);
}
void sci_cut(ScintillaObject *sci)
{
SSM(sci, SCI_CUT, 0, 0);
}
void sci_copy(ScintillaObject *sci)
{
SSM(sci, SCI_COPY, 0, 0);
}
void sci_paste(ScintillaObject *sci)
{
SSM(sci, SCI_PASTE, 0, 0);
}
void sci_clear(ScintillaObject *sci)
{
SSM(sci, SCI_CLEAR, 0, 0);
}
/** Gets the selection start position.
* @param sci Scintilla widget.
* @return Position. */
gint sci_get_selection_start(ScintillaObject *sci)
{
return (gint) SSM(sci, SCI_GETSELECTIONSTART, 0, 0);
}
/** Gets the selection end position.
* @param sci Scintilla widget.
* @return Position. */
gint sci_get_selection_end(ScintillaObject *sci)
{
return (gint) SSM(sci, SCI_GETSELECTIONEND, 0, 0);
}
/** Replaces selection.
* @param sci Scintilla widget.
* @param text Text. */
void sci_replace_sel(ScintillaObject *sci, const gchar *text)
{
SSM(sci, SCI_REPLACESEL, 0, (sptr_t) text);
}
/** Gets the length of all text.
* @param sci Scintilla widget.
* @return Length. */
gint sci_get_length(ScintillaObject *sci)
{
return (gint) SSM(sci, SCI_GETLENGTH, 0, 0);
}
gint sci_get_lexer(ScintillaObject *sci)
{
return (gint) SSM(sci, SCI_GETLEXER, 0, 0);
}
void sci_set_lexer(ScintillaObject *sci, guint lexer_id)
{
gint old = sci_get_lexer(sci);
SSM(sci, SCI_SETLEXER, lexer_id, 0);
if (old != (gint)lexer_id)
SSM(sci, SCI_CLEARDOCUMENTSTYLE, 0, 0);
}
/** Gets line length.
* @param sci Scintilla widget.
* @param line Line number.
* @return Length. */
gint sci_get_line_length(ScintillaObject *sci, gint line)
{
return (gint) SSM(sci, SCI_LINELENGTH, (uptr_t) line, 0);
}
/* safe way to read Scintilla string into new memory.
* works with any string buffer messages that follow the Windows message convention. */
gchar *sci_get_string(ScintillaObject *sci, guint msg, gulong wParam)
{
gint size = (gint) SSM(sci, msg, wParam, 0);
gchar *str = g_malloc(size + 1);
SSM(sci, msg, wParam, (sptr_t) str);
str[size] = '\0'; /* ensure termination, needed for SCI_GETLINE */
return str;
}
/** Gets line contents.
* @param sci Scintilla widget.
* @param line_num Line number.
* @return A @c NULL-terminated copy of the line text. */
gchar *sci_get_line(ScintillaObject *sci, gint line_num)
{
return sci_get_string(sci, SCI_GETLINE, (gulong) line_num);
}
/** Gets all text.
* @deprecated sci_get_text is deprecated and should not be used in newly-written code.
* Use sci_get_contents() instead.
*
* @param sci Scintilla widget.
* @param len Length of @a text buffer, usually sci_get_length() + 1.
* @param text Text buffer; must be allocated @a len + 1 bytes for null-termination. */
void sci_get_text(ScintillaObject *sci, gint len, gchar *text)
{
SSM(sci, SCI_GETTEXT, (uptr_t) len, (sptr_t) text);
}
/** Gets all text inside a given text length.
* @param sci Scintilla widget.
* @param len Length of the text to retrieve from the start of the document,
* usually sci_get_length() + 1.
* @return A copy of the text. Should be freed when no longer needed.
*
* @since 0.17
*/
gchar *sci_get_contents(ScintillaObject *sci, gint len)
{
gchar *text = g_malloc(len);
SSM(sci, SCI_GETTEXT, (uptr_t) len, (sptr_t) text);
return text;
}
/** Gets selected text.
* @deprecated sci_get_selected_text is deprecated and should not be used in newly-written code.
* Use sci_get_selection_contents() instead.
*
* @param sci Scintilla widget.
* @param text Text buffer; must be allocated sci_get_selected_text_length() + 1 bytes
* for null-termination. */
void sci_get_selected_text(ScintillaObject *sci, gchar *text)
{
SSM(sci, SCI_GETSELTEXT, 0, (sptr_t) text);
}
/** Gets selected text.
* @param sci Scintilla widget.
*
* @return The selected text. Should be freed when no longer needed.
*
* @since 0.17
*/
gchar *sci_get_selection_contents(ScintillaObject *sci)
{
return sci_get_string(sci, SCI_GETSELTEXT, 0);
}
/** Gets selected text length.
* @param sci Scintilla widget.
* @return Length. */
gint sci_get_selected_text_length(ScintillaObject *sci)
{
return (gint) SSM(sci, SCI_GETSELTEXT, 0, 0);
}
gint sci_get_position_from_xy(ScintillaObject *sci, gint x, gint y, gboolean nearby)
{
/* for nearby return -1 if there is no character near to the x,y point. */
return (gint) SSM(sci, (nearby) ? SCI_POSITIONFROMPOINTCLOSE : SCI_POSITIONFROMPOINT, (uptr_t) x, y);
}
/** Checks if a line is visible (folding may have hidden it).
* @param sci Scintilla widget.
* @param line Line number.
* @return Whether @a line will be drawn on the screen. */
gboolean sci_get_line_is_visible(ScintillaObject *sci, gint line)
{
return SSM(sci, SCI_GETLINEVISIBLE, (uptr_t) line, 0) != FALSE;
}
/** Makes @a line visible (folding may have hidden it).
* @param sci Scintilla widget.
* @param line Line number. */
void sci_ensure_line_is_visible(ScintillaObject *sci, gint line)
{
SSM(sci, SCI_ENSUREVISIBLE, (uptr_t) line, 0);
}
gint sci_get_fold_level(ScintillaObject *sci, gint line)
{
return (gint) SSM(sci, SCI_GETFOLDLEVEL, (uptr_t) line, 0);
}
/* Get the line number of the fold point before start_line, or -1 if there isn't one */
gint sci_get_fold_parent(ScintillaObject *sci, gint start_line)
{
return (gint) SSM(sci, SCI_GETFOLDPARENT, (uptr_t) start_line, 0);
}
void sci_toggle_fold(ScintillaObject *sci, gint line)
{
SSM(sci, SCI_TOGGLEFOLD, (uptr_t) line, 1);
}
gboolean sci_get_fold_expanded(ScintillaObject *sci, gint line)
{
return SSM(sci, SCI_GETFOLDEXPANDED, (uptr_t) line, 0) != FALSE;
}
void sci_colourise(ScintillaObject *sci, gint start, gint end)
{
SSM(sci, SCI_COLOURISE, (uptr_t) start, end);
}
void sci_clear_all(ScintillaObject *sci)
{
SSM(sci, SCI_CLEARALL, 0, 0);
}
gint sci_get_end_styled(ScintillaObject *sci)
{
return (gint) SSM(sci, SCI_GETENDSTYLED, 0, 0);
}
void sci_set_tab_width(ScintillaObject *sci, gint width)
{
SSM(sci, SCI_SETTABWIDTH, (uptr_t) width, 0);
}
/** Gets display tab width (this is not indent width, see GeanyIndentPrefs).
* @param sci Scintilla widget.
* @return Width.
*
* @since 0.15
**/
gint sci_get_tab_width(ScintillaObject *sci)
{
return (gint) SSM(sci, SCI_GETTABWIDTH, 0, 0);
}
/** Gets a character.
* @param sci Scintilla widget.
* @param pos Position.
* @return Char. */
gchar sci_get_char_at(ScintillaObject *sci, gint pos)
{
return (gchar) SSM(sci, SCI_GETCHARAT, (uptr_t) pos, 0);
}
void sci_set_savepoint(ScintillaObject *sci)
{
SSM(sci, SCI_SETSAVEPOINT, 0, 0);
}
void sci_set_indentation_guides(ScintillaObject *sci, gint mode)
{
SSM(sci, SCI_SETINDENTATIONGUIDES, (uptr_t) mode, 0);
}
void sci_use_popup(ScintillaObject *sci, gboolean enable)
{
SSM(sci, SCI_USEPOPUP, enable != FALSE, 0);
}
/** Checks if there's a selection.
* @param sci Scintilla widget.
* @return Whether a selection is present.
*
* @since 0.15
**/
gboolean sci_has_selection(ScintillaObject *sci)
{
if (SSM(sci, SCI_GETSELECTIONEND, 0, 0) - SSM(sci, SCI_GETSELECTIONSTART, 0, 0))
return TRUE;
else
return FALSE;
}
void sci_goto_pos(ScintillaObject *sci, gint pos, gboolean unfold)
{
if (unfold) SSM(sci, SCI_ENSUREVISIBLE, (uptr_t) SSM(sci, SCI_LINEFROMPOSITION, (uptr_t) pos, 0), 0);
SSM(sci, SCI_GOTOPOS, (uptr_t) pos, 0);
}
void sci_set_search_anchor(ScintillaObject *sci)
{
SSM(sci, SCI_SEARCHANCHOR, 0, 0);
}
/* removes a selection if pos < 0 */
void sci_set_anchor(ScintillaObject *sci, gint pos)
{
if (pos < 0)
pos = sci_get_current_position(sci);
SSM(sci, SCI_SETANCHOR, (uptr_t) pos, 0);
}
/** Scrolls the cursor in view.
* @param sci Scintilla widget. */
void sci_scroll_caret(ScintillaObject *sci)
{
SSM(sci, SCI_SCROLLCARET, 0, 0);
}
void sci_scroll_lines(ScintillaObject *sci, gint lines)
{
SSM(sci, SCI_LINESCROLL, 0, lines);
}
void sci_scroll_columns(ScintillaObject *sci, gint columns)
{
SSM(sci, SCI_LINESCROLL, (uptr_t) columns, 0);
}
gint sci_search_next(ScintillaObject *sci, gint flags, const gchar *text)
{
/* FIXME: SCI_SEACHNEXT() actually returns long */
return (gint) SSM(sci, SCI_SEARCHNEXT, (uptr_t) flags, (sptr_t) text);
}
gint sci_search_prev(ScintillaObject *sci, gint flags, const gchar *text)
{
/* FIXME: SCI_SEACHPREV() actually returns long */
return (gint) SSM(sci, SCI_SEARCHPREV, (uptr_t) flags, (sptr_t) text);
}
/** Finds text in the document.
* The @a ttf argument should be a pointer to a Sci_TextToFind structure which contains
* the text to find and the range in which the text should be searched.
*
* Please refer to the Scintilla documentation for a more detailed description.
*
* @param sci Scintilla widget.
* @param flags Bitmask of Scintilla search flags (@c SCFIND_*, see Scintilla documentation).
* @param ttf Pointer to a TextToFind structure which contains the text to find and the range.
* @return The position of the start of the found text if it succeeds, otherwise @c -1.
* The @c chrgText.cpMin and @c chrgText.cpMax members of @c TextToFind are filled in
* with the start and end positions of the found text.
*/
gint sci_find_text(ScintillaObject *sci, gint flags, struct Sci_TextToFind *ttf)
{
return (gint) SSM(sci, SCI_FINDTEXT, (uptr_t) flags, (sptr_t) ttf);
}
/** Sets the font for a particular style.
* @param sci Scintilla widget.
* @param style The style.
* @param font The font name.
* @param size The font size. */
void sci_set_font(ScintillaObject *sci, gint style, const gchar *font, gint size)
{
SSM(sci, SCI_STYLESETFONT, (uptr_t) style, (sptr_t) font);
SSM(sci, SCI_STYLESETSIZE, (uptr_t) style, size);
}
/** Jumps to the specified line in the document.
* If @a unfold is set and @a line is hidden by a fold, it is unfolded
* first to ensure it is visible.
* @param sci Scintilla widget.
* @param line Line.
* @param unfold Whether to unfold first.
*/
void sci_goto_line(ScintillaObject *sci, gint line, gboolean unfold)
{
if (unfold) SSM(sci, SCI_ENSUREVISIBLE, (uptr_t) line, 0);
SSM(sci, SCI_GOTOLINE, (uptr_t) line, 0);
}
void sci_marker_delete_all(ScintillaObject *sci, gint marker)
{
SSM(sci, SCI_MARKERDELETEALL, (uptr_t) marker, 0);
}
/** Gets style ID at @a position.
* @param sci Scintilla widget.
* @param position Position.
* @return Style ID. */
gint sci_get_style_at(ScintillaObject *sci, gint position)
{
return (gint) SSM(sci, SCI_GETSTYLEAT, (uptr_t) position, 0);
}
void sci_set_codepage(ScintillaObject *sci, gint cp)
{
g_return_if_fail(cp == 0 || cp == SC_CP_UTF8);
SSM(sci, SCI_SETCODEPAGE, (uptr_t) cp, 0);
}
void sci_assign_cmdkey(ScintillaObject *sci, gint key, gint command)
{
SSM(sci, SCI_ASSIGNCMDKEY, (uptr_t) key, command);
}
void sci_clear_cmdkey(ScintillaObject *sci, gint key)
{
SSM(sci, SCI_CLEARCMDKEY, (uptr_t) key, 0);
}
/** Gets text between @a start and @a end.
* @deprecated sci_get_text_range is deprecated and should not be used in newly-written code.
* Use sci_get_contents_range() instead.
*
* @param sci Scintilla widget.
* @param start Start.
* @param end End.
* @param text Text will be zero terminated and must be allocated (end - start + 1) bytes. */
void sci_get_text_range(ScintillaObject *sci, gint start, gint end, gchar *text)
{
struct Sci_TextRange tr;
tr.chrg.cpMin = start;
tr.chrg.cpMax = end;
tr.lpstrText = text;
SSM(sci, SCI_GETTEXTRANGE, 0, (long) &tr);
}
/** Gets text between @a start and @a end.
*
* @param sci Scintilla widget.
* @param start Start.
* @param end End.
* @return The text inside the given range. Should be freed when no longer needed.
*
* @since 0.17
*/
gchar *sci_get_contents_range(ScintillaObject *sci, gint start, gint end)
{
gchar *text;
g_return_val_if_fail(start < end, NULL);
text = g_malloc((gsize) (end - start) + 1);
sci_get_text_range(sci, start, end, text);
return text;
}
void sci_line_duplicate(ScintillaObject *sci)
{
SSM(sci, SCI_LINEDUPLICATE, 0, 0);
}
void sci_selection_duplicate(ScintillaObject *sci)
{
SSM(sci, SCI_SELECTIONDUPLICATE, 0, 0);
}
/** Inserts text.
* @param sci Scintilla widget.
* @param pos Position, or -1 for current.
* @param text Text. */
void sci_insert_text(ScintillaObject *sci, gint pos, const gchar *text)
{
SSM(sci, SCI_INSERTTEXT, (uptr_t) pos, (sptr_t) text);
}
void sci_target_from_selection(ScintillaObject *sci)
{
SSM(sci, SCI_TARGETFROMSELECTION, 0, 0);
}
void sci_set_target_start(ScintillaObject *sci, gint start)
{
SSM(sci, SCI_SETTARGETSTART, (uptr_t) start, 0);
}
void sci_set_target_end(ScintillaObject *sci, gint end)
{
SSM(sci, SCI_SETTARGETEND, (uptr_t) end, 0);
}
gint sci_replace_target(ScintillaObject *sci, const gchar *text, gboolean regex)
{
return (gint) SSM(sci, (regex) ? SCI_REPLACETARGETRE : SCI_REPLACETARGET, (uptr_t) -1, (sptr_t) text);
}
void sci_set_keywords(ScintillaObject *sci, guint k, const gchar *text)
{
SSM(sci, SCI_SETKEYWORDS, k, (sptr_t) text);
}
void sci_set_readonly(ScintillaObject *sci, gboolean readonly)
{
SSM(sci, SCI_SETREADONLY, readonly != FALSE, 0);