Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Scintilla code folding
#1
Hi,
I found a piece of C++ code whose function is to achieve code folding
[Image: aa.png]
I converted it to QM code, but it didn't work
There may be some areas that need to be modified. 

Thanks in advance for any suggestions and help
diavd

Macro SCI_cpp2
Code:
Copy      Help
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 384 240 "Dialog" "4"
;3 Scintilla 0x54000000 0x20000 8 8 368 206 ""
;1 Button 0x54030001 0x4 268 220 48 14 "OK"
;2 Button 0x54030000 0x4 328 220 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040C02 "*" "" "" ""

str controls="3"
str cs3
cs3=
;#include <iostream>
;using namespace std;
;int main ()
;{
;,//Comments: output strings
;,cout << "hello world!" << endl;
;,for (int i=0; 1<10; 1++)
;,{
;,,cout << i << endl;
;,}
;,return 0;
;}

int sci

def STYLE_DEFAULT 32
def STYLE_LINENUMBER 33

def MARGIN_FOLD_INDEX 2 

def SC_MARKNUM_FOLDEREND 25
def SC_MARKNUM_FOLDEROPENMID 26
def SC_MARKNUM_FOLDERMIDTAIL 27
def SC_MARKNUM_FOLDERTAIL 28
def SC_MARKNUM_FOLDERSUB 29
def SC_MARKNUM_FOLDER 30
def SC_MARKNUM_FOLDEROPEN 31

def SCN_MARGINCLICK 2010
def SCINT_ID 1010
def SC_MARGIN_SYMBOL 0
def SC_MARGIN_NUMBER 1
def SC_MASK_FOLDERS 0xFE000000
def SC_MARK_CIRCLEPLUS 18
def SC_MARK_CIRCLEPLUSCONNECTED 19
def SC_MARK_CIRCLEMINUS 20
def SC_MARK_CIRCLEMINUSCONNECTED 21
def SC_MARK_TCORNERCURVE 17
def SC_MARK_VLINE 9
def SC_MARK_LCORNERCURVE 16

if(!ShowDialog(dd &sub.DlgProc &controls)) ret


#sub DlgProc v
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,sci=id(3 hDlg)
,sub.SetText cs3
,SendMessage(sci SCI.SCI_SETPROPERTY "fold" "1") ;;Turn on code folding
,
,SendMessage(sci SCI.SCI_SETMARGINTYPEN MARGIN_FOLD_INDEX SC_MARGIN_SYMBOL) ;;Margin Type  
,SendMessage(sci SCI.SCI_SETMARGINMASKN MARGIN_FOLD_INDEX SC_MASK_FOLDERS) ;;Page margin mask    
,SendMessage(sci SCI.SCI_SETMARGINWIDTHN MARGIN_FOLD_INDEX 11) ;;Margin Width  
,SendMessage(sci SCI.SCI_SETMARGINSENSITIVEN MARGIN_FOLD_INDEX 1) ;;Respond to mouse messages
,
,;Collapse Label Style
,SendMessage(sci SCI.SCI_MARKERDEFINE SC_MARKNUM_FOLDER SC_MARK_CIRCLEPLUS)
,SendMessage(sci SCI.SCI_MARKERDEFINE SC_MARKNUM_FOLDEROPEN SC_MARK_CIRCLEMINUS)
,SendMessage(sci SCI.SCI_MARKERDEFINE SC_MARKNUM_FOLDEREND SC_MARK_CIRCLEPLUSCONNECTED)
,SendMessage(sci SCI.SCI_MARKERDEFINE SC_MARKNUM_FOLDEROPENMID SC_MARK_CIRCLEMINUSCONNECTED)
,SendMessage(sci SCI.SCI_MARKERDEFINE SC_MARKNUM_FOLDERMIDTAIL SC_MARK_TCORNERCURVE)
,SendMessage(sci SCI.SCI_MARKERDEFINE SC_MARKNUM_FOLDERSUB SC_MARK_VLINE)
,SendMessage(sci SCI.SCI_MARKERDEFINE SC_MARKNUM_FOLDERTAIL SC_MARK_LCORNERCURVE)
,
,;Collapse Label Color
,SendMessage(sci SCI.SCI_MARKERSETBACK SC_MARKNUM_FOLDERSUB 0xa0a0a0)
,SendMessage(sci SCI.SCI_MARKERSETBACK SC_MARKNUM_FOLDERMIDTAIL 0xa0a0a0)
,SendMessage(sci SCI.SCI_MARKERSETBACK SC_MARKNUM_FOLDERTAIL 0xa0a0a0)
,
,SendMessage(sci SCI.SCI_SETFOLDFLAGS 16|4 0) ;;Display a horizontal line above and below the line after folding
,case WM_DESTROY
,case WM_COMMAND goto messages2
,case WM_NOTIFY goto messages3
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1
;messages3
SCI.SCNotification* k=+lParam
sel k.nmhdr.code
,case SCN_MARGINCLICK
,if k.nmhdr.idFrom=SCINT_ID
,,int line_number=SendMessage(sci SCI.SCI_LINEFROMPOSITION k.position 0)
,,out line_number
,,SendMessage(sci SCI.SCI_TOGGLEFOLD line_number 0)

#sub Sci v
function# message [param1] [param2]
ret SendMessage(sci message param1 param2)

#sub Sci2 v
function# message [param1] [$text]
ret SendMessage(sci message param1 text)

#sub SetText v
function $text
sub.Sci2(SCI.SCI_SETTEXT 0 text)

Cpp code:
Code:
Copy      Help
#define MARGIN_FOLD_INDEX 2  
void TForm1::setFold()  
{  
    SendEditor(SCI_SETPROPERTY,(sptr_t)"fold",(sptr_t)"1");   //Turn on code folding
    
    SendEditor(SCI_SETMARGINTYPEN, MARGIN_FOLD_INDEX, SC_MARGIN_SYMBOL);//Margin Type  
    SendEditor(SCI_SETMARGINMASKN, MARGIN_FOLD_INDEX, SC_MASK_FOLDERS); //Page margin mask  
    SendEditor(SCI_SETMARGINWIDTHN, MARGIN_FOLD_INDEX, 11); //Margin Width
    SendEditor(SCI_SETMARGINSENSITIVEN, MARGIN_FOLD_INDEX, TRUE); //Respond to mouse messages
    
    // Collapse Label Style
    SendEditor(SCI_MARKERDEFINE, SC_MARKNUM_FOLDER, SC_MARK_CIRCLEPLUS);  
    SendEditor(SCI_MARKERDEFINE, SC_MARKNUM_FOLDEROPEN, SC_MARK_CIRCLEMINUS);  
    SendEditor(SCI_MARKERDEFINE, SC_MARKNUM_FOLDEREND,  SC_MARK_CIRCLEPLUSCONNECTED);  
    SendEditor(SCI_MARKERDEFINE, SC_MARKNUM_FOLDEROPENMID, SC_MARK_CIRCLEMINUSCONNECTED);  
    SendEditor(SCI_MARKERDEFINE, SC_MARKNUM_FOLDERMIDTAIL, SC_MARK_TCORNERCURVE);  
    SendEditor(SCI_MARKERDEFINE, SC_MARKNUM_FOLDERSUB, SC_MARK_VLINE);  
    SendEditor(SCI_MARKERDEFINE, SC_MARKNUM_FOLDERTAIL, SC_MARK_LCORNERCURVE);  
    
    // Collapse Label Color
    SendEditor(SCI_MARKERSETBACK, SC_MARKNUM_FOLDERSUB, 0xa0a0a0);  
    SendEditor(SCI_MARKERSETBACK, SC_MARKNUM_FOLDERMIDTAIL, 0xa0a0a0);  
    SendEditor(SCI_MARKERSETBACK, SC_MARKNUM_FOLDERTAIL, 0xa0a0a0);  
    
    SendEditor(SCI_SETFOLDFLAGS, 16|4, 0); //Display a horizontal line above and below the line after folding
}  
__fastcall TForm1::TForm1(TComponent* Owner)  
    : TForm(Owner)  
{  
    ...  
    setFold();  
}  
void __fastcall TForm1::WndProc(Messages::TMessage &Message)  
{  
    TForm::WndProc(Message);  
    
    if(Message.Msg == WM_NOTIFY){  
        SCNotification* notify = (SCNotification*)Message.LParam;  
        if(notify->nmhdr.code == SCN_MARGINCLICK &&  
            notify->nmhdr.idFrom == SCINT_ID){  
            const int line_number = SendEditor(SCI_LINEFROMPOSITION,notify->position);  
            SendEditor(SCI_TOGGLEFOLD, line_number);  
        }  
    }  
}


Messages In This Thread
Scintilla code folding - by Davider - 04-01-2023, 02:01 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)