123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536 |
- #include <windows.h>
- #include <commctrl.h>
- #include "r_defs.h"
- #include "resource.h"
- #include "../Agave/Language/api_language.h"
- #if 0
- #include "compiler.h"
- #include "richedit.h"
- #endif
- char* GetTextResource(UINT id){
- void* data = 0;
- HRSRC rsrc = FindResource(WASABI_API_LNG_HINST,MAKEINTRESOURCE(id),"TEXT");
- if(rsrc){
- HGLOBAL resourceHandle = LoadResource(WASABI_API_LNG_HINST,rsrc);
- data = LockResource(resourceHandle);
- }
- return (char*)data;
- }
- void loadComboBox(HWND dlg, char *ext, char *selectedName)
- {
- char path[MAX_PATH];
- int a;
- HANDLE ff;
- WIN32_FIND_DATA fd;
- wsprintf(path,"%s\\%s",g_path,ext);
- ff=FindFirstFile(path, &fd);
- if (ff == INVALID_HANDLE_VALUE) return;
- do
- {
- SendMessage(dlg, CB_ADDSTRING, 0, (LPARAM)(fd.cFileName));
- } while (FindNextFile(ff, &fd));
- FindClose(ff);
- a = SendMessage(dlg, CB_FINDSTRINGEXACT, 0, (LPARAM)(selectedName));
- if (a != CB_ERR) SendMessage(dlg, CB_SETCURSEL, (WPARAM) a, 0);
- }
- void GR_SelectColor(HWND hwnd, int *a)
- {
- static COLORREF custcolors[16];
- CHOOSECOLOR cs;
- cs.lStructSize = sizeof(cs);
- cs.hwndOwner = hwnd;
- cs.hInstance = 0;
- cs.rgbResult=((*a>>16)&0xff)|(*a&0xff00)|((*a<<16)&0xff0000);
- cs.lpCustColors = custcolors;
- cs.Flags = CC_RGBINIT|CC_FULLOPEN;
- if (ChooseColor(&cs))
- {
- *a = ((cs.rgbResult>>16)&0xff)|(cs.rgbResult&0xff00)|((cs.rgbResult<<16)&0xff0000);
- }
- }
- void GR_DrawColoredButton(DRAWITEMSTRUCT *di, COLORREF color)
- {
- color = ((color>>16)&0xff)|(color&0xff00)|((color<<16)&0xff0000);
- char wt[123];
- HPEN hPen,hOldPen;
- HBRUSH hBrush,hOldBrush;
- hPen = (HPEN)GetStockObject(BLACK_PEN);
- LOGBRUSH lb={BS_SOLID,color,0};
- hBrush = CreateBrushIndirect(&lb);
- hOldPen=(HPEN)SelectObject(di->hDC,hPen);
- hOldBrush=(HBRUSH)SelectObject(di->hDC,hBrush);
- Rectangle(di->hDC,di->rcItem.left,di->rcItem.top,di->rcItem.right,di->rcItem.bottom);
- GetWindowText(di->hwndItem,wt,sizeof(wt));
- SetBkColor(di->hDC,color);
- SetTextColor(di->hDC,~color & 0xffffff);
- DrawText(di->hDC,wt,-1,&di->rcItem,DT_CENTER|DT_VCENTER|DT_SINGLELINE);
-
- DeleteObject(hBrush);
- SelectObject(di->hDC,hOldPen);
- SelectObject(di->hDC,hOldBrush);
- }
- static int m_help_lastpage=4;
- static char *m_localtext;
- static void _dosetsel(HWND hwndDlg)
- {
- HWND tabwnd=GetDlgItem(hwndDlg,IDC_TAB1);
- int sel=TabCtrl_GetCurSel(tabwnd);
- char *text="";
- m_help_lastpage=sel;
- if (sel == 0)
- text=GetTextResource(IDR_HELP_1);
- else if (sel == 1)
- text=GetTextResource(IDR_HELP_2);
- else if (sel == 2)
- text=GetTextResource(IDR_HELP_3);
- else if (sel == 3)
- text=GetTextResource(IDR_HELP_4);
- else if (sel == 4 && m_localtext)
- text=m_localtext;
- SetDlgItemText(hwndDlg,IDC_EDIT1,text);
- }
- static BOOL CALLBACK evalHelpDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam,LPARAM lParam)
- {
- switch (uMsg)
- {
- case WM_INITDIALOG:
- {
- TCITEM item;
- HWND tabwnd=GetDlgItem(hwndDlg,IDC_TAB1);
- item.mask=TCIF_TEXT;
- item.pszText=WASABI_API_LNGSTRING(IDS_GENERAL);
- TabCtrl_InsertItem(tabwnd,0,&item);
- item.pszText=WASABI_API_LNGSTRING(IDS_OPERATORS);
- TabCtrl_InsertItem(tabwnd,1,&item);
- item.pszText=WASABI_API_LNGSTRING(IDS_FUNCTIONS);
- TabCtrl_InsertItem(tabwnd,2,&item);
- item.pszText=WASABI_API_LNGSTRING(IDS_CONSTANTS);
- TabCtrl_InsertItem(tabwnd,3,&item);
-
- m_localtext=0;
- if (lParam)
- {
- item.pszText=(char *)lParam;
- m_localtext=item.pszText + strlen(item.pszText)+1;
- TabCtrl_InsertItem(tabwnd,4,&item);
- }
- else if (m_help_lastpage > 3) m_help_lastpage=0;
- TabCtrl_SetCurSel(tabwnd,m_help_lastpage);
- _dosetsel(hwndDlg);
- }
- return 0;
- case WM_COMMAND:
- if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
- EndDialog(hwndDlg,1);
- return 0;
- case WM_NOTIFY:
- {
- LPNMHDR p=(LPNMHDR) lParam;
- if (p->idFrom == IDC_TAB1 && p->code == TCN_SELCHANGE) _dosetsel(hwndDlg);
- }
- return 0;
- }
- return 0;
- }
- void compilerfunctionlist(HWND hwndDlg, char *localinfo)
- {
- WASABI_API_DIALOGBOXPARAM(IDD_EVAL_HELP,hwndDlg,evalHelpDlgProc, (LONG)localinfo);
- }
- #if 0
- #define M_WORD 1
- #define M_NUM 2
- #define M_COMM 3
- #define is_alpha(a) ((((a) >= 'A') && ((a) <= 'Z')) || (((a) >= 'a') && ((a) <= 'z')))
- #define is_num(a) (((a) >= '0') && ((a) <= '9'))
- #define is_op(a) (((a) == '=') || ((a) == '+') || ((a) == '-') || ((a) == '*') || ((a) == '/') || ((a) == '%'))
- static int bcol[] = { RGB(192, 0, 0), RGB(64, 128, 128), RGB(128, 0, 255), RGB(128, 128, 255) };
- #define COLOR_COMMENT RGB(0, 128, 0)
- #define COLOR_FUNC RGB(0, 0, 192)
- #define COLOR_VAR RGB(96, 96, 96)
- #define COLOR_OP RGB(0, 0, 0)
- #define COLOR_NUMBER RGB(0, 0, 128)
- void doAVSEvalHighLight(HWND hwndDlg, UINT sub, char *data) {
- int size=strlen(data);
- HWND hwnd=GetDlgItem(hwndDlg,sub);
- CHARRANGE cr, cro;
-
- CHARFORMAT cf;
- cf.cbSize = sizeof(CHARFORMAT);
- cf.dwMask = CFM_COLOR;
- cf.dwEffects = 0;
- SendMessage(hwnd, WM_SETREDRAW, false, 0);
- SendMessage(hwnd, EM_EXGETSEL, 0, (LPARAM)&cro);
- int mode = 0;
- int pos = 0;
- int brackets = 0;
- for (int i = 0; i < size; ++i) {
- if (mode == M_COMM) {
-
- if ((data[i] == ';') || ((data[i] == '*') && ((i+1) < size) && (data[++i] == '/'))) {
- mode = 0;
- cf.crTextColor = COLOR_COMMENT;
- cr.cpMin = pos;
- cr.cpMax = i+1;
- SendMessage(hwnd, EM_EXSETSEL, 0, (LPARAM)&cr);
- SendMessage(hwnd, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf);
- }
- } else if (is_alpha(data[i]) || ((mode == M_WORD) && is_num(data[i]))) {
-
- if (mode != M_WORD) {
-
- mode = M_WORD;
- pos = i;
- }
-
- bool valid = (i != (size-1));
- if (valid) {
- valid = is_num(data[i+1]) || is_alpha(data[i+1]);
- }
- if (!valid) {
-
- cr.cpMin = pos;
- cr.cpMax = i+1;
-
- bool func = false;
- for (int j = 0; j < (sizeof(fnTable) / sizeof(fnTable[0])); ++j) {
- if ((i - pos + 1) == (signed)strlen(fnTable[j].name)) {
- if (strnicmp(fnTable[j].name, &data[pos], strlen(fnTable[j].name)) == 0) {
- func = true;
- break;
- }
- }
- }
- cf.crTextColor = func ? COLOR_FUNC : COLOR_VAR;
- SendMessage(hwnd, EM_EXSETSEL, 0, (LPARAM)&cr);
- SendMessage(hwnd, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf);
- }
- } else if (is_op(data[i])) {
-
- mode = 0;
- cf.crTextColor = COLOR_OP;
- cr.cpMin = i;
- cr.cpMax = i+1;
- SendMessage(hwnd, EM_EXSETSEL, 0, (LPARAM)&cr);
- SendMessage(hwnd, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf);
- } else if ((data[i] & 0x80) || ((data[i] == '/') && ((i+1) < size) && (data[++i] == '*'))) {
-
- mode = M_COMM;
- pos = i;
- } else if ((data[i] == '(') || (data[i] == ')') || (data[i] == ',')) {
-
- mode = 0;
- if (data[i] == '(') ++brackets;
- cf.crTextColor = bcol[brackets % (sizeof(bcol) / sizeof(bcol[0]))];
- if (data[i] == ')') --brackets;
- cr.cpMin = i;
- cr.cpMax = i+1;
- SendMessage(hwnd, EM_EXSETSEL, 0, (LPARAM)&cr);
- SendMessage(hwnd, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf);
- } else if (is_num(data[i]) || (data[i] == '.')) {
-
- if (mode != M_NUM) {
- pos = i;
- mode = M_NUM;
- }
-
- bool valid = (i != (size-1));
- if (valid) {
- valid = is_num(data[i+1]) || (data[i+1] == '.');
- }
- if (!valid) {
- cf.crTextColor = COLOR_NUMBER;
- cr.cpMin = pos;
- cr.cpMax = i+1;
- SendMessage(hwnd, EM_EXSETSEL, 0, (LPARAM)&cr);
- SendMessage(hwnd, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf);
- }
- } else if (data[i] == ';') {
-
- mode = 0;
- brackets = 0;
- }
- }
- SendMessage(hwnd, EM_EXSETSEL, 0, (LPARAM)&cro);
- SendMessage(hwnd, WM_SETREDRAW, true, 0);
- InvalidateRect(hwnd, 0, true);
- }
- #endif
|