How to set margin masks in Scintilla?

1.2k views Asked by At

I have a problem understanding how Scintilla markers are bound to a margin. Lets say I want 3 margins. 1st for linenumbers (no problem here), 2nd for arrow markers only and 3rd for circle makers only. I know from the documentation that I have to specify marginmasks to bind a marker to a margin, but I don't get how to specify the mask. I tried around a little but never got the wanted result. (Either arrows were displayed on both margings (2nd and 3rd) or no symbol was highlighted and instead the line was highlighed). Hope someone can enlighten me how to set the marginmasks.

/* 2nd marker margin -> only arrows */
Call(SCI_SETMARGINTYPEN, 1, SC_MARGIN_SYMBOL);
Call(SCI_SETMARGINWIDTHN, 1, 20);
Call(SCI_SETMARGINSENSITIVEN, 1, 1);
Call(SCI_SETMARGINMASKN, 1, SC_MARK_ARROW);    // <=== ???
 DefineMarker(1, SC_MARK_ARROW, 0xffffff, 0x0000ff);

/* 3rd marker margin -> only circles */
Call(SCI_SETMARGINTYPEN, 2, SC_MARGIN_SYMBOL);
Call(SCI_SETMARGINWIDTHN, 2, 50);
Call(SCI_SETMARGINSENSITIVEN, 2, 1);

DefineMarker(2, SC_MARK_CIRCLE, 0xffffff, 0x00ff00);
Call(SCI_SETMARGINMASKN, 2, SC_MARK_CIRCLE);    // <=== ???

Call(SCI_MARKERADD, 1, 1);
Call(SCI_MARKERADD, 1, 2);

That way I get an arrow marker on margin 1 but only a highlighted line and no circle marker for margin 2. I would be glad if someone can explain how the masks have to be set.

1

There are 1 answers

0
ekhumoro On BEST ANSWER

There are 32 markers available, and numbers 0 to 24 have no pre-defined use. The numbers 25 to 31 are used for folding, but if you don't need that, you could use those numbers as well.

The first step is to choose a number for each of the markers you want to set up: let's say 4 for arrows, and 5 for circles (probably some constants should be defined for these).

The margin mask is a 32-bit value. To set it, you need to flip the bit that corresponds with each of the marker numbers that should be enabled for that margin:

    Call(SCI_SETMARGINMASKN, 1, 1 << 4); // 2nd margin, arrow marker
    Call(SCI_SETMARGINMASKN, 2, 1 << 5); // 3rd margin, circle marker

Then you need to define the markers themselves:

    DefineMarker(4, SC_MARK_ARROW, 0xffffff, 0x0000ff);
    DefineMarker(5, SC_MARK_CIRCLE, 0xffffff, 0x00ff00);

So you can finally add them to a specific line:

    Call(SCI_MARKERADD, 1, 4);
    Call(SCI_MARKERADD, 1, 5);