~ubuntu-branches/ubuntu/raring/geany/raring-proposed

« back to all changes in this revision

Viewing changes to src/sciwrappers.c

  • Committer: Bazaar Package Importer
  • Author(s): Damián Viano
  • Date: 2008-05-02 11:37:45 UTC
  • mfrom: (1.2.1 upstream) (9 hardy)
  • mto: (3.2.1 squeeze)
  • mto: This revision was merged to the branch mainline in revision 12.
  • Revision ID: james.westby@ubuntu.com-20080502113745-xzp4g6dmovrpoj17
Tags: 0.14-1
New upstream release (Closes: #478126)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 *      sciwrappers.c - this file is part of Geany, a fast and lightweight IDE
3
3
 *
4
 
 *      Copyright 2006 Enrico Troeger <enrico.troeger@uvena.de>
5
 
 *
 
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.
19
19
 *
20
 
 * $Id: sciwrappers.c 829 2006-09-21 10:31:06Z ntrel $
 
20
 * $Id: sciwrappers.c 2312 2008-03-07 15:42:46Z eht16 $
 
21
 */
 
22
 
 
23
/*
 
24
 * Wrappers for the SCI_* Scintilla messages.
 
25
 * Originally from the cssed project (http://cssed.sf.net).
21
26
 */
22
27
 
23
28
#include <string.h>
30
35
#define SSM(s, m, w, l) scintilla_send_message(s, m, w, l)
31
36
 
32
37
 
33
 
// stolen from cssed (http://cssed.sf.net), thanks
 
38
/* stolen from cssed (http://cssed.sf.net), thanks */
34
39
 
35
40
 
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 */
48
53
        }
49
54
        else
50
55
        {
73
78
                        return;
74
79
                }
75
80
        }
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);
78
83
}
79
84
 
145
150
 
146
151
void sci_set_visible_white_spaces(ScintillaObject* sci, gboolean set )
147
152
{
148
 
        if(set){
 
153
        if (set)
149
154
                SSM(sci,SCI_SETVIEWWS,SCWS_VISIBLEALWAYS,0);
150
 
        }else{
 
155
        else
151
156
                SSM(sci,SCI_SETVIEWWS,SCWS_INVISIBLE,0);
152
 
        }
153
157
}
154
158
 
155
159
gboolean sci_get_visible_white_spaces(ScintillaObject* sci)
159
163
 
160
164
void sci_set_lines_wrapped(ScintillaObject* sci, gboolean set )
161
165
{
162
 
        if( set ){
 
166
        if (set)
163
167
                SSM(sci,SCI_SETWRAPMODE,SC_WRAP_WORD,0);
164
 
                SSM(sci, SCI_SETWRAPVISUALFLAGS, SC_WRAPVISUALFLAG_END, 0);
165
 
        }else{
 
168
        else
166
169
                SSM(sci,SCI_SETWRAPMODE,SC_WRAP_NONE,0);
167
 
        }
168
170
}
169
171
 
170
172
gboolean sci_get_lines_wrapped(ScintillaObject* sci)
189
191
 
190
192
void sci_add_text(ScintillaObject* sci, const gchar* text)
191
193
{
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);
194
196
        }
195
197
}
196
198
 
197
199
void sci_set_text(ScintillaObject* sci, const gchar* text)
198
200
{
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);
201
203
        }
202
204
}
204
206
 
205
207
void sci_add_text_buffer(ScintillaObject* sci, const gchar* text, gint len)
206
208
{
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);
210
212
        }
225
227
 
226
228
void sci_undo( ScintillaObject* sci )
227
229
{
228
 
        if( sci_can_undo(sci) ){
 
230
        if( sci_can_undo(sci) )
229
231
                SSM( sci, SCI_UNDO, 0, 0);
230
 
        }else{ // change it to a document function
 
232
        else
 
233
        { /* change it to a document function */
231
234
 
232
235
        }
233
236
}
235
238
 
236
239
void sci_redo( ScintillaObject* sci )
237
240
{
238
 
        if( sci_can_redo( sci ) ){
 
241
        if( sci_can_redo( sci ) )
239
242
                SSM( sci, SCI_REDO,0,0);
240
 
        }else{// change it to a document function
 
243
        else
 
244
        { /* change it to a document function */
241
245
 
242
246
        }
243
247
}
273
277
}
274
278
 
275
279
 
 
280
gboolean sci_is_modified(ScintillaObject *sci)
 
281
{
 
282
        return (SSM(sci, SCI_GETMODIFY, 0, 0) != 0);
 
283
}
 
284
 
 
285
 
276
286
void sci_zoom_in( ScintillaObject* sci )
277
287
{
278
288
        SSM( sci, SCI_ZOOMIN,0,0);
314
324
{
315
325
        gint state;
316
326
 
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));
319
329
}
320
330
 
321
331
 
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)
323
336
{
324
337
        gint marker_line;
325
338
 
326
339
        marker_line = SSM(sci, SCI_MARKERNEXT, line, marker_mask);
327
 
 
328
 
        if( marker_line != -1 ){
329
 
                SSM(sci,SCI_GOTOLINE,marker_line,0);
330
 
                return TRUE;
331
 
        }else{
332
 
                return FALSE;
333
 
        }
 
340
        if (wrap && marker_line == -1)
 
341
                marker_line = SSM(sci, SCI_MARKERNEXT, 0, marker_mask);
 
342
        return marker_line;
334
343
}
335
344
 
336
345
 
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)
338
350
{
339
351
        gint marker_line;
340
352
 
341
353
        marker_line = SSM(sci, SCI_MARKERPREVIOUS, line, marker_mask);
 
354
        if (wrap && marker_line == -1)
 
355
        {
 
356
                gint len = sci_get_length(sci);
 
357
                gint last_line = sci_get_line_from_position(sci, len - 1);
342
358
 
343
 
        if( marker_line != -1 ){
344
 
                SSM(sci,SCI_GOTOLINE,marker_line,0);
345
 
                return TRUE;
346
 
        }else{
347
 
                return FALSE;
 
359
                marker_line = SSM(sci, SCI_MARKERPREVIOUS, last_line, marker_mask);
348
360
        }
 
361
        return marker_line;
349
362
}
350
363
 
351
364
 
373
386
}
374
387
 
375
388
 
376
 
void sci_set_current_position(ScintillaObject* sci, gint position )
 
389
void sci_set_current_position(ScintillaObject* sci, gint position, gboolean scroll_to_caret)
377
390
{
378
 
        SSM(sci, SCI_GOTOPOS, position, 0);
 
391
        if (scroll_to_caret)
 
392
                SSM(sci, SCI_GOTOPOS, position, 0);
 
393
        else
 
394
        {
 
395
                SSM(sci, SCI_SETCURRENTPOS, position, 0);
 
396
                SSM(sci, SCI_SETANCHOR, position, 0); /* to avoid creation of a selection */
 
397
        }
 
398
        SSM(sci, SCI_CHOOSECARETX, 0, 0);
379
399
}
380
400
 
381
401
 
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)
383
405
{
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);
385
408
}
386
409
 
387
410
 
403
426
}
404
427
 
405
428
 
406
 
gint sci_get_line_end_from_position(ScintillaObject* sci, gint position)
 
429
gint sci_get_line_end_position(ScintillaObject* sci, gint line)
407
430
{
408
 
        return SSM(sci, SCI_GETLINEENDPOSITION, position, 0);
 
431
        return SSM(sci, SCI_GETLINEENDPOSITION, line, 0);
409
432
}
410
433
 
411
434
 
445
468
}
446
469
 
447
470
 
448
 
void sci_replace_sel(ScintillaObject* sci, gchar* text)
 
471
void sci_replace_sel(ScintillaObject* sci, const gchar* text)
449
472
{
450
473
        SSM(sci, SCI_REPLACESEL,0, (sptr_t) text);
451
474
}
469
492
}
470
493
 
471
494
 
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)
473
497
{
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);
 
500
 
 
501
        SSM(sci, SCI_GETLINE, line_num, (sptr_t) linebuf);
 
502
        linebuf[len] = '\0';
 
503
        return linebuf;
475
504
}
476
505
 
477
 
// the last char will be null terminated
 
506
 
 
507
/* the last char will be null terminated */
478
508
void sci_get_text(ScintillaObject* sci, gint len, gchar* text)
479
509
{
480
510
        SSM( sci, SCI_GETTEXT, len, (sptr_t) text );
481
511
}
482
512
 
483
513
 
 
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)
485
517
{
486
518
        SSM( sci, SCI_GETSELTEXT, 0, (sptr_t) text);
495
527
 
496
528
gint sci_get_position_from_xy(ScintillaObject* sci, gint x, gint y, gboolean nearby)
497
529
{
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);
500
532
}
501
533
 
526
558
}
527
559
 
528
560
 
 
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)
 
563
{
 
564
        return SSM( sci, SCI_GETLASTCHILD, start_line, level);
 
565
}
 
566
 
 
567
 
 
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)
 
570
{
 
571
        return SSM( sci, SCI_GETFOLDPARENT, start_line, 0);
 
572
}
 
573
 
 
574
 
529
575
void sci_toggle_fold(ScintillaObject* sci, gint line)
530
576
{
531
577
        SSM( sci, SCI_TOGGLEFOLD, line, 1);
562
608
}
563
609
 
564
610
 
565
 
gint sci_get_line_end_styled(ScintillaObject * sci, gint end_styled)
566
 
{
567
 
        return SSM(sci,SCI_LINEFROMPOSITION, end_styled,0);
568
 
}
569
 
 
570
 
 
571
611
void sci_set_tab_width(ScintillaObject * sci, gint width)
572
612
{
573
613
        SSM(sci, SCI_SETTABWIDTH, width, 0);
592
632
}
593
633
 
594
634
 
595
 
void sci_set_indentionguides(ScintillaObject *sci, gboolean enable)
 
635
void sci_set_indentation_guides(ScintillaObject *sci, gboolean enable)
596
636
{
597
637
        SSM(sci, SCI_SETINDENTATIONGUIDES, enable, 0);
598
638
}
604
644
}
605
645
 
606
646
 
607
 
// you can also call this has_selection
 
647
/* you can also call this has_selection */
608
648
gboolean sci_can_copy(ScintillaObject *sci)
609
649
{
610
650
        if (SSM(sci, SCI_GETSELECTIONEND,0,0) - SSM(sci, SCI_GETSELECTIONSTART,0,0))
614
654
}
615
655
 
616
656
 
617
 
void sci_goto_pos(ScintillaObject *sci, gint pos, gboolean ensure_visibility)
 
657
void sci_goto_pos(ScintillaObject *sci, gint pos, gboolean unfold)
618
658
{
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);
621
661
}
622
662
 
639
679
}
640
680
 
641
681
 
 
682
void sci_scroll_lines(ScintillaObject *sci, gint lines)
 
683
{
 
684
        SSM(sci, SCI_LINESCROLL, 0, lines);
 
685
}
 
686
 
 
687
 
642
688
gint sci_search_next(ScintillaObject *sci, gint flags, const gchar *text)
643
689
{
644
690
        return SSM(sci, SCI_SEARCHNEXT, flags, (sptr_t) text );
671
717
}
672
718
 
673
719
 
674
 
void sci_goto_line_scroll(ScintillaObject *sci, gint line, gdouble percent_of_view)
675
 
{
676
 
        gint vis1, los, delta;
677
 
 
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
686
 
}
687
 
 
688
 
 
689
720
void sci_marker_delete_all(ScintillaObject *sci, gint marker)
690
721
{
691
722
        SSM(sci, SCI_MARKERDELETEALL, marker, 0);
716
747
}
717
748
 
718
749
 
 
750
/* text will be zero terminated and must be allocated (end - start + 1) bytes */
719
751
void sci_get_text_range(ScintillaObject *sci, gint start, gint end, gchar *text)
720
752
{
721
753
        struct TextRange tr;
776
808
 
777
809
gint sci_target_replace(ScintillaObject *sci, const gchar *text, gboolean regex)
778
810
{
779
 
        return SSM(sci, (regex) ? SCI_REPLACETARGETRE : SCI_REPLACETARGET, -1, (sptr_t) text);
 
811
        return SSM(sci, (regex) ? SCI_REPLACETARGETRE : SCI_REPLACETARGET, (uptr_t) -1, (sptr_t) text);
780
812
}
781
813
 
782
814
 
785
817
        SSM(sci, SCI_SETKEYWORDS, k, (sptr_t) text);
786
818
}
787
819
 
788
 
void sci_scroll_lines(ScintillaObject *sci, gint lines)
789
 
{
790
 
        SSM(sci, SCI_LINESCROLL, 0, lines);
791
 
}
792
 
 
793
820
void sci_set_readonly(ScintillaObject *sci, gboolean readonly)
794
821
{
795
822
        SSM(sci, SCI_SETREADONLY, readonly, 0);
800
827
        return SSM(sci, SCI_GETREADONLY, 0, 0);
801
828
}
802
829
 
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)
805
832
{
806
833
        SSM(sci, cmd, 0, 0);
807
834
}
808
835
 
809
 
gint sci_get_current_line(ScintillaObject *sci, gint pos)
 
836
 
 
837
gint sci_get_current_line(ScintillaObject *sci)
810
838
{
811
 
        if (pos >= 0)
812
 
        {
813
 
                return SSM(sci, SCI_LINEFROMPOSITION, pos, 0);
814
 
        }
815
 
        else
816
 
        {
817
 
                return SSM(sci, SCI_LINEFROMPOSITION, SSM(sci, SCI_GETCURRENTPOS, 0, 0), 0);
818
 
        }
 
839
        return SSM(sci, SCI_LINEFROMPOSITION, SSM(sci, SCI_GETCURRENTPOS, 0, 0), 0);
819
840
}
820
841
 
821
842
/* Get number of lines partially or fully selected.
827
848
        gint end = SSM(sci, SCI_GETSELECTIONEND, 0, 0);
828
849
 
829
850
        if (start == end)
830
 
                return 0; // no selection
 
851
                return 0; /* no selection */
831
852
 
832
853
        return SSM(sci, SCI_LINEFROMPOSITION, end, 0) - SSM(sci, SCI_LINEFROMPOSITION, start, 0) + 1;
833
854
}
834
855
 
 
856
gint sci_get_first_visible_line(ScintillaObject *sci)
 
857
{
 
858
        return SSM(sci, SCI_GETFIRSTVISIBLELINE, 0, 0);
 
859
}
 
860
 
 
861
 
835
862
void sci_set_styling(ScintillaObject *sci, gint len, gint style)
836
863
{
837
864
        if (len < 0 || style < 0) return;
858
885
{
859
886
        SSM(sci, SCI_AUTOCSETMAXHEIGHT, val, 0);
860
887
}
 
888
 
 
889
gint sci_find_bracematch(ScintillaObject *sci, gint pos)
 
890
{
 
891
        return SSM(sci, SCI_BRACEMATCH, pos, 0);
 
892
}
 
893
 
 
894
gint sci_get_overtype(ScintillaObject *sci)
 
895
{
 
896
        return SSM(sci, SCI_GETOVERTYPE, 0, 0);
 
897
}
 
898
 
 
899
void sci_set_tab_indents(ScintillaObject *sci, gboolean set)
 
900
{
 
901
        SSM(sci, SCI_SETTABINDENTS, set, 0);
 
902
}
 
903
 
 
904
void sci_set_use_tabs(ScintillaObject *sci, gboolean set)
 
905
{
 
906
        SSM(sci, SCI_SETUSETABS, set, 0);
 
907
}
 
908
 
 
909
gint sci_get_pos_at_line_sel_start(ScintillaObject *sci, gint line)
 
910
{
 
911
        return SSM(sci, SCI_GETLINESELSTARTPOSITION, line, 0);
 
912
}
 
913
 
 
914
gint sci_get_pos_at_line_sel_end(ScintillaObject *sci, gint line)
 
915
{
 
916
        return SSM(sci, SCI_GETLINESELENDPOSITION, line, 0);
 
917
}
 
918
 
 
919
gint sci_get_selection_mode(ScintillaObject *sci)
 
920
{
 
921
        return SSM(sci, SCI_GETSELECTIONMODE, 0, 0);
 
922
}
 
923
 
 
924
void sci_set_selection_mode(ScintillaObject *sci, gint mode)
 
925
{
 
926
        SSM(sci, SCI_SETSELECTIONMODE, mode, 0);
 
927
}
 
928
 
 
929
void sci_set_scrollbar_mode(ScintillaObject *sci, gboolean visible)
 
930
{
 
931
        SSM(sci, SCI_SETHSCROLLBAR, visible, 0);
 
932
        SSM(sci, SCI_SETVSCROLLBAR, visible, 0);
 
933
}
 
934
 
 
935
void sci_set_line_indentation(ScintillaObject *sci, gint line, gint indent)
 
936
{
 
937
        SSM(sci, SCI_SETLINEINDENTATION, line, indent);
 
938
}
 
939
 
 
940
int sci_get_line_indentation(ScintillaObject *sci, gint line)
 
941
{
 
942
        return SSM(sci, SCI_GETLINEINDENTATION, line, 0);
 
943
}
 
944
 
 
945
void sci_set_caret_policy_x(ScintillaObject *sci, gint policy, gint slop)
 
946
{
 
947
        SSM(sci, SCI_SETXCARETPOLICY, policy, slop);
 
948
}
 
949
 
 
950
void sci_set_caret_policy_y(ScintillaObject *sci, gint policy, gint slop)
 
951
{
 
952
        SSM(sci, SCI_SETYCARETPOLICY, policy, slop);
 
953
}
 
954