voidCScriptView::InitEditor( void ){s( SCI_CLEARDOCUMENTSTYLE );s( SCI_SETCODEPAGE, SC_CP_UTF8 );// 支援unicodeSetAStyle( STYLE_DEFAULT, black, white, 12, "Fixedsys" );s( SCI_STYLECLEARALL );// Copies global style to all others// set the number of styling bits to 7 - the asp/html views need a lot of styling - default is 5// If you leave the default you will see twiggle lines instead of ASP codes( SCI_SETSTYLEBITS, 7 );// tab寬度s( SCI_SETTABWIDTH, 4 );s( SCI_SETFOCUS, true );// Snooper 文法解析//SendEditor( SCI_SETLEXER, SCLEX_SNOOPER_APDU_NOCASE );s( SCI_SETLEXERLANGUAGE, 0, reinterpret_cast<LPARAM>( "snooper_apdu_nocase" ) );s( SCI_SETKEYWORDS, 0, reinterpret_cast<LPARAM>( g____apdu_keywords ) );//設定關鍵字s( SCI_SETKEYWORDS, 1, reinterpret_cast<LPARAM>( g____apdu_pre_keywords ) );//設定關鍵字s( SCI_SETKEYWORDS, 2, reinterpret_cast<LPARAM>( g____apdu_function_list ) );//設定關鍵字SetAStyle( SCE_SS_DEFAULT,RGB( 0x00, 0x00, 0x00 ) );// 預設SetAStyle( SCE_SS_COMMENT,RGB( 0x00, 0x80, 0x80 ) );// 注釋SetAStyle( SCE_SS_LABEL,RGB( 0X00, 0X80, 0X40 ), (~RGB( 0X00, 0X80, 0X40 ) & 0xffffff) );// 標號SetAStyle( SCE_SS_HEX_WRONG,RGB( 50, 100, 45 ) );// 不是偶數個的hex串// 當前行高亮s( SCI_SETCARETLINEVISIBLE, TRUE );//SendEditor( SCI_SETCARETLINEBACK, 0xb0ffff ); s( SCI_SETCARETLINEBACK, RGB( 226, 217, 232 ) ); // 括弧匹配顏色s( SCI_STYLESETBACK, STYLE_BRACELIGHT, RGB( 0x00, 0xFF, 0x00 ) );//s( SCI_STYLESETBACK, STYLE_BRACEBAD, RGB( 0xFF, 0x00, 0x00 ) );// 選擇背景s( SCI_SETSELBACK, true, RGB(0x9f,0xbb,0xe8) );// 設定margin 0s( SCI_SETMARGINTYPEN, 0, SC_MARGIN_NUMBER );// 設定margin 1s( SCI_SETMARGINTYPEN, 1, SC_MARGIN_SYMBOL );// 掩碼s( SCI_SETMARGINMASKN, 1, 3 );// bit 0 and bit 1s( SCI_MARKERSETFORE, 0, RGB( 0xff, 0x00, 0x00 ) );//1-reds( SCI_MARKERSETFORE, 1, RGB( 0x00, 0xff, 0x00 ) );//1-綠色s( SCI_SETMARGINWIDTHN, 1, 9 );// 接受滑鼠點擊//s( SCI_SETMARGINSENSITIVEN, true );//s( SCI_TEXTWIDTH(STYLE_LINENUMBER, "_99999") );// 設定mouse hover時間s( SCI_SETMOUSEDWELLTIME, 500 );}
文法高亮之後,就是代碼自動提示與自動完成
先用scintilla派生一個類,俺這個類叫editor,再建個view,嵌入這個editor,這樣就可以在view中處理editor的大部分事件了。
代碼提示,vc用'.'或'->'或'::'來呼叫,俺自己做這個就用.來呼叫函數列表了,在輸入'(', ',', ')'是檢查函數是否完成,進行參數提示,按F1或滑鼠晃過去顯示。
俺在UpdateUI中完成的參數提示,只要當前游標左邊是一個'.',就顯示函數列表
case SCN_UPDATEUI:// 更新介面UpdateUI();break;
voidCScriptView::UpdateUI( void ){long lStart = s(SCI_GETCURRENTPOS, 0, 0);int ch = s( SCI_GETCHARAT, lStart - 1 );if( '.' == ch ){s( SCI_AUTOCSHOW, 0, (sptr_t)g____apdu_function_list );}
唯一不足的就是前面多了一個'.',俺在自動完成的時候給刪掉了。
參數提示
參數提示是在訊息charadded時進行計算的,基本過程就是取得當前行的內容,再取得當前caret的位置,再再取得行首caret的位置,來計算當前caret對應行內的位移量
snooper的運算式與其他不同,函數可嵌套,並且'(', '<', '{' 都有不同的意義,所以計算流程沒有通用性。
BOOLCScriptView::GetFunction( int pos_x, char *funpara, int *start, int *end ){int line_num = s( SCI_LINEFROMPOSITION, pos_x );// 當前行int line_length = s( SCI_LINELENGTH, line_num );// 當前行長度
// 下面幾句相當重要噢,取得行內位移量
int pos0 = s( SCI_FINDCOLUMN, line_num, 0 );// 取得當前行的最左邊位置的開始posint pos;pos = pos_x - pos0;// 在行內的位移量,從1開始