'Alternative code editor for Oxygen Basic v0.36,compiled with A041
'by Aurel 25.2.2018 ,sci-1.6.7.0,awinh-035
$ Filename "AurelEdit.exe"
'Include "RTL32.inc"
use corewin
Include "awinh035.inc"
#LOOKAHEAD ' for procedures
 Type NMHDR
      hwndFrom as sys
      idFrom   as sys
      code     as sys
  End Type

sys win,hsci,wabout,optWin,fWindow,theme
INT winstyle,aboutWindow,optWinOn,findWinOn,stFW1,stFW2,stfw1ID=600,stfw2ID=601
INT fb1,fb2,fb3,fb1ID=501,fb2ID=502,fb3ID=503,fwed1,fwed1ID=504,fwed2,fwed2ID=505
INT button0,button1,button2,button3,button4,button5,button6,button7,button8,bGoto
INT edit1,edit2,edit3,edit4,edit5,editOpt
INT Lbox,static1,static2,static3,static4,ststic6,static7,static8,static9
INT ed1ID,ed2ID,ed3ID,edoID
INT b0ID,b1ID,b2ID,b3ID,b4ID,b5ID,b6ID,b7ID,b8ID=0,b9ID,b10ID
INT bo1,bo2,bo3,bo4,bo5,bo5,bo6,bo7
INT bo1ID=151,bo2ID=152,bo3ID=153,bo4ID=154,bo5ID=155,bo6ID=156
INT LboxID = 300,LBhdc,LBhdcMEM
INT st1ID,st2ID,st6ID,st7ID,st8ID
int x,y,w,h : string CRLF = chr(13)+chr(10)
INT reID
bGotoID = 120
b0ID=99                                                                                                         h
b1ID=100
b2ID=101
b3ID=102
b4ID=103
b5ID=104
b6ID=105
b7ID=106
b8ID=107
'print str(b8ID)
b9ID =108
b10ID=110
% SW_RESIZE = 2
'-----------------
ed1ID=200
ed2ID=201
ed3ID=202
ed4ID=203
ed5ID=204
edoID=205
'----------------
st1ID=350
st2ID=351
st3ID=352
st4ID=353
st6ID=356
st7ID=357
'##### SCINTILLA CONSTANTS ###################################
sciID=400  'scintilla ID
INT hlibsci,hsci 'scintilla handlers
INT bip

% SCE_O2_DEFAULT = 0
% SCE_O2_LINECOMMENT = 1
% SCE_O2_NUMBER = 2
% SCE_O2_KEYWORD0 = 3
% SCE_O2_STRING = 4
% SCE_O2_PREPROCESSOR = 5
% SCE_O2_OPERATOR = 6
% SCE_O2_IDENTIFIER = 7
% SCE_O2_DATE = 8
% SCE_O2_STRINGEOL = 9
% SCE_O2_KEYWORD1 = 10
% SCE_O2_KEYWORD2 = 11
% SCE_O2_KEYWORD3 = 12

% SCLEX_O2BASIC = 75 'fb lexer

% SCI_SETLEXER = 4001
% SCI_COLOURISE = 4003
% SCI_STYLESETFORE = 2051
% SCI_STYLESETBACK = 2052
% SCI_STYLECLEARALL = 2050
% SCI_SETKEYWORDS = 4005
% SCI_STYLESETFONT = 2056
% SCI_STYLESETSIZE = 2055
% SCI_STYLESETBOLD = 2053
% SCI_SETMARGINWIDTHN = 2242
% SCI_SETMARGINTYPEN = 2240
% SCI_SETMARGINSENSITIVEN = 2246
% SCI_SETSELBACK = 2068
% SCI_SetSelFore = 2067
% SCI_GOTOLINE = 2024
% SCI_LINELENGTH = 2350
% SCI_GETLINE = 2153
% SCI_GETLINECOUNT = 2154
% SCI_GETCURLINE= 2027
% SCI_SCROLLCARET=2169
% SCI_SETCURRENTPOS = 2141
% SCI_SETANCHOR=2026
% SCI_SEARCHANCHOR=2366
% SCI_GETSELECTIONSTART=2143
'--------------------------------
% SCFIND_REGEXP=0x00200000
% SCFIND_WHOLEWORD=2
% SCFIND_MATCHCASE=4
% SCI_SEARCHNEXT=2367
% SCI_SEARCHPREV=2368
% SCI_REPLACESEL = 2170
'--------------------------------
% SCI_GOTOPOS=2025
% SCI_GETTEXT = 2182
% SCI_SETTEXT = 2181
% SCI_GETTEXTLENGTH = 2183

% SCI_CLEAR=2180
% SCI_CLEARALL=2004
% SCI_BRACEBADLIGHT=2352
% SCI_BRACEHIGHLIGHT=2351
% SCI_BRACEMATCH=2353
% SCI_GETSELECTIONEND=2145
% SCI_SETSELECTIONEND=2144
% SCI_SETCARETLINEVISIBLE=2096
% SCI_SETCARETFORE = 2069
% SCI_SETCARETLINEBACK = 2098
% SCI_SCROLLCARET=2169
% SCI_UNDO = 2176
% SCI_CUT = 2177
% SCI_COPY = 2178
% SCI_PASTE = 2179
% SCI_SETSAVEPOINT = 2014
% SCI_EMPTYUNDOBUFFER = 2175

% SC_MARGIN_SYMBOL = 0
% SC_MARGIN_NUMBER = 1
% SCI_SETMARGINMASKN = 2244

% TCN_SELCHANGE = -551

'init color strings
bSTRING sciBlue,sciRed,sciBrown
Gosub oxyKeywords 'load oxygen basic keywords
'- tree view -------------
INT htv
'--------------------
STRING cOption="-c " ' default copt - gui No console "-c " for oxygen
STRING fName
char tx[500000]
string gxName="c:\oxygenbasic\gxo2.exe"   ' for oxygen change path to \gxo2.exe
char cdPath[256]
'string cdPath
GetCurrentDirectory 256,strptr cdPath
'GetTempPath ( 256, strptr cdPath)
cdPath = cdPath + gxName
'MsgBox cdPath , "Compiler Path...OK!"
'-------------------------------------
'global file name 
STRING fileName
INT tab
'--------------------------------------
'loadbmp
'##################################################
INT bmpB0,bmpB1,bmpB2,bmpB3,bmpB4,bmpB5,bmpB6,bmpB7,bmpB8
bmpB1 = LoadImage(0,"AELogo.bmp",0,400,300,16)
'......................................................

'##################################################
x=100:y=100:w=740:h=480
winstyle = WS_CLIPCHILDREN | WS_MINMAXSIZE 
'create window **************************************************
win = SetWindow("AurelEdit:",x,y,w,h,0,winstyle) 
'InitDrawing(win)
	'WindowColor( win, 220, 230, 250)
'****************************************************************
bGoto = SetButton(win,388,4,60,24,"GOTO-->",0x50000000,0x200,bGotoID)
edit2 = SetEditBox(win,450,5,48,22,"LINE",0x50004000,0x200,ed2ID)
':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
'create single-line edit control
edit1 = SetEditBox(win,160,30,560,23,"",0x50004000,0x200,ed1ID)
'tab item
edit3 = SetEditBox(win,30,30,18,20,"64",0x50004000,0x200,ed3ID)
'tab name
edit4 = SetEditBox(win,50,30,104,20,"TabName",0x50004000,0x200,ed4ID)
'create listbox ===================================================
INT lbx,lby,lbw,lbh
lbx=6:lby=54:lbw=168:lbh=366
Lbox = SetListBox(win,lbx,lby,lbw,lbh,"",0x50000140|CTLISTNOTIFY|WS_VSCROLL,0x200,LboxID)
ControlFont(LBox, 15, 7, 400, "Courier New") 
Dim LBitems[2000] as INT
Dim LBitem as INT
'=================================================================
'create static control
static1 = SetStatic(win,6,32,24,13,"TAB:",0,0,st1ID)
'button  set compiler gxo2.exe path
static6 = SetButton(win,502,4,38,23,"GXO2",0,0x200,st6ID) ' gxo2 path button
ControlFont(static6, 16, 7, 500, "Courier New") 
'option edit box
editOpt = SetEditBox(win,544,5,140,22,"add compiler Path",0x50004000,0x200,edoID)

'set sci dimensions
'INT rx,ry,rw,rh
'rx=160:ry=80:rw=466:rh=360

'TOOLBAR-------------------------------------------------------------
Dim tbb as TBBUTTON
Dim AddBmp as TBADDBITMAP
' setting common control mode 
Dim iccx as INITCOMMONCONTROLSEXtype 
  iccx.dwSize = sizeOf(iccx ) 
  iccx.dwICC  = 4 
' initialize common controls 32 
InitCommonControlsEx( iccx )
with Addbmp
  .hinst = -1
  .nID   =  0
end with
INT htbar
INT toolID=99
'add handlers
INT  hImageList,hImage,iNum,id
'create toolbar -----------------------------------------------------
htbar = SetToolbar (win, 0 ,0,toolID)
'create tooltip -----------------------------------------------------
NMHDR pHdr
'set toolbar size ---------------------------------------------------
MoveWindow(htbar, 0, 0, 380, 28,0)
' Set the imagelist used with default images
  hImageList = ImageList_Create(20, 20, ILC_MASK OR ILC_COLOR8, 1, 0)
  hImage = LoadImage(0, "rCodetb.bmp", 0, 280, 20, 24)
  ImageList_AddMasked hImageList, hImage, RGB(231,223,231)
  DeleteObject hImage
'set image list  
SendMessage htbar,TB_SETIMAGELIST,0, hImageList
'set button structure size
SendMessage htbar , 1054, sizeof(tbb), NULL

'TBUTTONS & TOOLTIPS -------------------------------------------------
INT tooltip
tooltip = SetToolTip(htbar)

AddTButton(htbar, 100, 0, "New File")
AddTButton(htbar, 101, 1, "Open File")
AddTButton(htbar, 102, 2, "Save As...")
AddTButton(htbar, 103, 3, "Save File")
AddTButton(htbar, 104, 4, "Close File")
AddTButton(htbar, 105, 5, "Copy -->")
AddTButton(htbar, 106, 6, "<Paste>")
AddTButton(htbar, 107, 7, "Compile::")
AddTButton(htbar, 108, 8, "Run")
AddTButton(htbar, 109, 9, "Web Site")
AddTButton(htbar, 110, 10, "Info")
AddTButton(htbar, 111, 11, "Find")
AddTButton(htbar, 112, 12, "Options")
AddTButton(htbar, 113, 13, "Help")

'TAB control --------------------------------------------------------- 
INT tc,tcID=500
tc = SetTabControl(win,180,55,466,26,0,0,tcID)
indexbase 0
INT tbArr[64],tabIndex,ai
STRING tabName[64],tabValue[64]
'reset tab info array >>>>>
For ai = 0 To 63
tabName[ai]  = ""
tabValue[ai] = ""
Next ai
'<<<<<<<<<<<<<<<<<<<<<<<<<<
tabIndex = -1 
'add first tab.. index 0
CreateNewTab()

'Status bar
INT status
status = SetStatusBar ( win, "Status-Bar...",0,0)
'--------------------------------------------------------------------
int hdc=getdc(win)
int iBrush = CreateSolidBrush (0xff0000)
SelectObject Hdc, iBrush
'Rectangle Hdc, 0, 0, w,h
SetBkColor hdc,ibrush
ReleaseDC win,hdc

'Create Scintilla control ->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
INT hlibsci,hsci,i
hlibsci = LoadLibrary "SciLexer.dll"
'print str(hlibsci)
INT rx,ry,rw,rh,ext,sci_style
rx=180: ry=80 : rw=540 : rh=340 : ext=0x200 
'rx=180: ry=80 : rw=540 : rh=340 
sci_style =  WS_CHILD|WS_VISIBLE|ES_SUNKEN
hsci = CreateWindowEx(ext,"Scintilla","",sci_style,rx,ry,rw,rh,win,sciID,0,0)
UpdateWindow hsci
'basic setings...
SENDMESSAGE(hsci, SCI_SETLEXER, SCLEX_O2BASIC, 1)
'set sci backColor
SENDMESSAGE(hsci, SCI_STYLESETBACK,32,rgb(255,255,255)) 'white
SENDMESSAGE(hsci, SCI_STYLECLEARALL, 0, 1)
'set font
For i = 0 to 12
	SENDMESSAGE (hsci, SCI_STYLESETFONT, i, "Courier New")
	SENDMESSAGE (hsci, SCI_STYLESETSIZE, i, 10)
Next i

'set keywords group colors
SENDMESSAGE(hsci, SCI_SETKEYWORDS, 0, sciBlue )  :  'blue
SENDMESSAGE(hsci, SCI_SETKEYWORDS, 1, sciRed )   :  'red 
SENDMESSAGE(hsci, SCI_SETKEYWORDS, 2, sciBrown ) :  'brown 

'////////////////////////////////////////////////////////
'set number margin (for numnbers)
SendMessage(hsci, SCI_SETMARGINTYPEN, 0, SC_MARGIN_NUMBER)
SendMessage(hsci, SCI_SETMARGINWIDTHN, 0, 46)
'set SELECTIONED LINES COLOR
SendMessage hsci,SCI_SetSelBack,1, RGB(49, 106, 197) 
SendMessage hsci,SCI_SetSelFore,1, RGB(255, 235, 225)
'caret line
SENDMESSAGE hsci,SCI_SETCARETLINEBACK,RGB(235,235,255),0
'SENDMESSAGE hsci,SCI_SETCARETFORE,RGB(115,115,255),0
SENDMESSAGE hsci,SCI_SETCARETLINEVISIBLE,1,0
SetFocus win

'--------------------------------------------------------------------
	SENDMESSAGE(hsci, SCI_STYLESETFORE, SCE_O2_DEFAULT,0)                 		'0 default
	SENDMESSAGE(hsci, SCI_STYLESETFORE, SCE_O2_LINECOMMENT,rgb(0,120,0))  		'1 line comment
	SENDMESSAGE(hsci, SCI_STYLESETFORE, SCE_O2_NUMBER, rgb(160,0,0)) 			'2 number
	SENDMESSAGE(hsci, SCI_STYLESETFORE, SCE_O2_KEYWORD0,RGB(0,0,200))			'3 keyword0 - blue
	SENDMESSAGE(hsci, SCI_STYLESETFORE, SCE_O2_STRING,RGB(150,0,150))			'4 string
	SENDMESSAGE(hsci, SCI_STYLESETFORE, SCE_O2_PREPROCESSOR,RGB(0,0,250)) :       '5 preproc
	SENDMESSAGE(hsci, SCI_STYLESETFORE, SCE_O2_OPERATOR,rgb(250,,0)):			'6 operator
	SENDMESSAGE(hsci, SCI_STYLESETFORE, SCE_O2_IDENTIFIER,RGB(0,0,0))             '7 identifier/var names
	SENDMESSAGE(hsci, SCI_STYLESETFORE, SCE_O2_DATE,RGB(0,0,0))              	'8 date
	SENDMESSAGE(hsci, SCI_STYLESETFORE, SCE_O2_STRINGEOL,rgb(0,0,0))			'9 string EOL
	SENDMESSAGE(hsci, SCI_STYLESETFORE, SCE_O2_KEYWORD1,RGB(250,0,0) )			'10 keyword1 -work red
	SENDMESSAGE(hsci, SCI_STYLESETFORE, SCE_O2_KEYWORD2,RGB(160,80,0))            '11 keyword2 - as brown
	SENDMESSAGE(hsci, SCI_STYLESETFORE, SCE_O2_KEYWORD3,RGB(220,0,220))			'12 keyword3 - magenta	

'->->->->->->->->->->->->->->->->->->
sys bRet
  '
  WHILE GetMessage (&wm,0,0,0)<>0
  TranslateMessage &wm
  DispatchMessage &wm
 WEND
'<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-

Function WndProc(byval hWnd as long,byval wMsg as long, byval wParam as long,byval lparam as sys) as sys callback


SELECT hWnd
'-----------
CASE win
'----------
Select wMsg

CASE WM_CREATE
/*
hlibsci = LoadLibrary "SciLexer.dll"  'load sciLexer.dll
if not hlibsci then
      print "Unable to load Scintilla: SciLexer.dll"
end if
sys rx,ry,rw,rh,ext,sci_style
rx=180: ry=80 : rw=540 : rh=340 : ext=0x200 
sci_style =  WS_CHILD|WS_VISIBLE|ES_SUNKEN
hsci = CreateWindowEx(ext,"Scintilla","",sci_style,rx,ry,rw,rh,win,sciID,0,0)
SendMessage hsci,
     '3  cpp
     '8  vb ***
     '40 lout
     '51 powerbasic
     '75 freebasic
      SendMessage hsci, SCI_SETLEXER, 8, 0
      'include "oxykeywords.inc"
      'string sciblue
      SendMessage hsci, SCI_SETKEYWORDS, 0, sciblue
      SendMessage hsci, SCI_COLOURISE, 0, -1
      '
     'sm SCI_STYLESETFORE, SCE_OB_DEFAULT,0
     'sm SCI_STYLESETBACK,32,0xFFFFFF  'white
     'sm SCI_STYLECLEARALL, 0, 1
      for i=0 to 7
        SendMessage hsci, SCI_STYLESETFONT, i, "Courier New" 'Courier / Lucida Console
        SendMessage hsci, SCI_STYLESETSIZE, i, 9 '10..14 point size range
      next i
      '
      SendMessage hsci, SCI_SETMARGINTYPEN,  0, SC_MARGIN_NUMBER
      SendMessage hsci, SCI_SETMARGINWIDTHN, 0, 46
      SendMessage hsci, SCI_SETCARETLINEBACK,RGB(245,245,200),0
      SendMessage hsci, SCI_SETCARETFORE,    0xff4444,0
      SendMessage hsci, SCI_SETCARETLINEVISIBLE,1,0
      '
      def sn SendMessage hsci, SCI_STYLESETFORE,
      '
      'setting RGB colors
      sn 0,  0x000000  '
      sn 1,  0x207800         'line comment
      sn 2,  rgb(164,42,42)  'numbers
      sn 3,  rgb(0,0,170)     'keywords
      sn 4,  rgb(150,0,150)   'string
      sn 5,  0xc00080         '#names
      sn 6,  rgb(200,0,0)     'symbols
      sn 7,  0x002000  '
      '
*/
CASE WM_DESTROY
PostQuitMessage 0
'------------------
case WM_SIZE
GetSize(win,x,y,w,h)
MoveWindow(hsci,180,80,(w-rw/2)+84,(h-76)-32 ,1)
MoveWindow(edit1,180,30,(w-rw/2)+84,23 ,1)
MoveWindow(Lbox,6,54,lbw,(h-76)-6 ,1)
MoveWindow(tc,180,55,(w-rw/2)+116,24,1)
'fix statusbar position on botom of window
MoveWindow ( status,0,(h-32),w,h,1)

'-------------------------------------------------------------
CASE WM_NOTIFY
  NMHDR notify at lparam
  Select notify.code
	case -552  'tcn_selchanging
    'leaving tab
    'int p = SendMessage(tc,TCM_GETCURSEL,0,0)
    'print "LEAVING-TAB->" + str(p)
	autoSave()

	case -551  'tcn_selchange
    'selected tab
	'int i = SendMessage(tc,TCM_GETCURSEL,0,0)
	'print "TAB:" + str(i)
     FindTab()

End Select

/*
CASE WM_CTLCOLORLISTBOX
LBhdc = getDC(LBox)
If theme = 3 ' default
	INT lbColor = CreateSolidBrush(RGB(255,255,255))
	'SetBkMode(LBhdc,1)
	SetBkColor( wparam, RGB(255,255,255))
	SetTextColor( wparam,RGB(20,45,125))
	'InvalidateRect(Lbox, 1, 0)
	return lbColor
End if
If theme = 1 ' light blue
	INT lbColor = CreateSolidBrush(RGB(240,240,255))
	'SetBkMode(LBhdc,1)
	SetBkColor( wparam, RGB(240,240,255))
	SetTextColor( wparam,RGB(0,5,0))
	'InvalidateRect(Lbox, 1, 0)
	return lbColor
End if
If theme = 2 ' soft yellow
	INT lbColor = CreateSolidBrush(RGB(243,242,214))
	'SetBkMode(LBhdc,1)
	SetBkColor( wparam, RGB(243,242,214))
	SetTextColor( wparam,RGB(0,5,0))
	'InvalidateRect(Lbox, 1, 0)
	return lbColor
End if
*/
'-------------------------------------------------------------
	CASE WM_COMMAND	
	controlID = LoWord(wParam) 'get control ID
	notifyCode = HiWord(wParam) 'get notification message

	Select controlID
     CASE LBoxID
     'doubleClick listbox item -> jump to line
		IF notifycode = LBN_DBLCLICK
		'pos=GETSELECTED(w1,3)
         pos = SendMessage Lbox,LB_GETCURSEL,0,0
         
		For n=0 TO pos	
			IF pos = n
			fnpos=LBitems[pos]
			SetFocus hsci
			SendMessage hsci,SCI_GOTOLINE,fnpos,0
			END IF
		Next n
		pos=0
		END IF

     'get file from clicked tab
    'CASE tcID
     
    

	   CASE b1ID
        'NEW 
		If notifycode=0 
			autoSave() 'save current content
			SendMessage hsci,SCI_SETTEXT,0,strptr ""   'clear scintila
              NewTab()  'create new tab      
		End If

	   CASE b2ID
        'OPEN
		If notifycode=0  
			doOpen()
			fnParser()
		End If

	   CASE b3ID
	     If notifycode=0 
		doSave()    
		End If

	  CASE b4ID
		If notifycode=0
		autoSave()
         'Beep 1200,60
		End If

	  CASE b5ID
		If notifycode=0
		doClose()
         'Beep 800,50: Beep 600,50: Beep 400,50
		End If

	  CASE b6ID
		If notifycode=0
		doCopy()
		End If

      CASE b7ID
		If notifycode=0
		doPaste()
		End If

      CASE 107
		If notifycode=0
		doCompile()
		End If

      CASE b9ID
		If notifycode=0
		doRun()
		End If

	  CASE b10ID
		If notifycode=0
		'show About window
         AboutBox()
		End If

      CASE 111 ' open FindWindow
         If notifycode = 0
           FindWindow()
         End If

      CASE 112 ' Option Window
        If notifycode=0
        OptWindow()
        End If

     CASE st6ID ' set compiler path [ gxo2.exe ]
      If notifycode = 0
      cdPath = GetText(editOpt)
      MsgBox cdPath , "Compiler Path:"
      End If

	CASE bGotoID
     JumpToLine()

End Select



END SELECT
'------------------------------


'-----------------------
CASE wabout
'----------------------
Select wMsg
CASE WM_CLOSE
  IF aboutWindow = 1
    CloseWindow(wabout)
     aboutWindow=0
  END IF

End Select
'---------------------
CASE optWin   'option window events
'..........................
Select wMsg
'::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
CASE WM_COMMAND
	controlID = LoWord(wParam) 'get control ID
	notifyCode = HiWord(wParam) 'get notification message

	Select controlID
	CASE bo1ID
        'theme Clear Sea
		If notifycode=0 
		print "You select theme -> CLEAR SEA"
         theme = 1 : SetTheme1(): ControlFont (LBox, 15,7, 0,"Courier New")
		End If
     CASE bo2ID
         'theme Soft Desert
		If notifycode=0 
		print "You select theme -> SOFT DESERT"
         theme = 2 : SetTheme2(): ControlFont (LBox, 16,8, 0,"Courier New")	
		End If

	CASE bo3ID
         'theme Default
		If notifycode=0 
		print "You select theme -> DEFAULT"
         theme = 3 : SetTheme3(): ControlFont (LBox, 16,8, 0,"Courier New")	
		End If

	CASE bo4ID
         'theme Dark Moon
		If notifycode=0 
		print "You select theme -> DARK MOON"
         theme = 4 : SetTheme4(): ControlFont (LBox, 16,8, 0,"Courier New")	
		End If

    End Select
	
':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
CASE WM_CLOSE
  IF optWinOn = 1
    CloseWindow(optWin)
     optWinOn=0
  END IF
End Select
'////////////// FIND WINDOW  ///////////////////////////////////
CASE fWindow
'///////////
Select wMsg ' for Find/Replace toolwindow
'////////////////////////////////////////////////////////////
CASE WM_COMMAND
	controlID = LoWord(wParam) 'get control ID
	notifyCode = HiWord(wParam) 'get notification message

	Select controlID

	CASE fb1ID
        'Find-next...
		If notifycode=0 
		FindNext()        
		End If
     CASE fb2ID
         'ReplaceOnce
		If notifycode=0 
		ReplaceOnce(0)           
		End If
	CASE fb3ID
		If notifycode=0
         ReplaceAll()
         End If


    End Select

'.............................
CASE WM_CLOSE
  IF findWinOn = 1
    CloseWindow(fWindow) ' cloase [Find/Replace] toolwindow
     findWinOn = 0
  END IF
End Select
'////////////////////////////////////////////////////////
'CASE Lbox
	'select  wMsg
		'case wm_paint
		'BitBlt(hDC, 0, 0, ww, hh, hdcMem, 0, 0, SRCCOPY)
		'InvalidateRect(Lbox, 1, 0)

    'end select

END SELECT


FUNCTION = DefWindowProc hwnd,wMsg,wParam,lParam


END FUNCTION


'************************************************************
'open file
Sub doOpen

INT hsize=0
fName=""
string dir=""
string sep=chr(0)
'filter = "All Files"+sep+"*.*"+sep"Text files"+sep+"*.txt"+ sep
filter = "All files "+sep+"*.*"+sep+"o2 files "+sep+"*.o2bas"
title="Open File... "
hwnd=0
fName = FileDialog(dir,filter,title,0,0,"o2bas")
fileName = fName
IF fName = "" Then Return
SendMessage edit1,WM_SETTEXT,0,strptr(fName)
SendMessage status,WM_SETTEXT,0,strptr(fName)
 tx =  GetFile fName
SendMessage hsci,SCI_SETTEXT,0,strptr(tx)
SendMessage hsci,SCI_SETSAVEPOINT, 0, 0
SendMessage hsci,SCI_EMPTYUNDOBUFFER,0,0

If fName <> ""
FindNewTab()
End If

End Sub

'************************************************************
'save file
SUB doSave
INT hsize=0,found,c
string dir="",filePath
'char tx[32768]
'bstring tx
string ext=".o2bas"

filter= "OB Files (*.o2bas)"
title="Save File... "    'for Oxygen change to *.o2bas
hwnd=0
fName = FileDialog(dir,filter,title,0,1,"o2bas")

'print fname
If fName="" then Return
  IF RightS(fname,6) <> ".o2bas"  'for Oxygen set number to 6 , .o2bas
    fname = fname + ext
  END IF
'print fname
hsize = SendMessage hsci, SCI_GETTEXTLENGTH, 0, 0
'exit if empty
IF hsize = 0
print "ERROR: -> Document is Empty!" 
Return    ' ->->->
END IF

'SendMessage hsci,SCI_GETTEXT,hsize+1,tx
'PutFile fName,tx
'SendMessage(hsci, SCI_SETSAVEPOINT, 0, 0)
'filePath = fName

found=0
INT tab = GetSelectedTab(tc)
string tName = GetTabText(tc,tab)
tName = Trim(tName)
'print "SAVE:tabname;" + tname 
'if file exists ...............................................................
For c = 0 To 63
    IF tName <> "*New"
		IF tabName[c] = tName
		   filePath = tabValue[c]
            'SetTabText(tc,tab,tName)  'update tab name
             'ReOpenFile()             'reOpen file from filePath
             fnParser()               'parse code
		    found=1                  'confirm found	
             Exit For       
	    END IF
   END IF
Next c
'if is tab *New ...............................................................
IF found = 0
print "is there tab NEW?"
For c = 0 To 63
		IF tabName[c] = "*New"
            filePath = Trim(fName)
		   tabValue[c] = filePath
              tName = GetFileName(filePath)   'extract file name from file Path
			SetTabText(tc,tab,tName)        'update tab name
              tabName[c] = tName              'update tab name element
             'ReOpenFile()                    'reOpen file from filePath
             fnParser()                       'parse code
		    found=1                          'confirm found	
             Exit For       
	    END IF
Next c
END IF
'if filename not exists and there is no tab *New -> create NEW tab
'IF found = 0
'END IF

IF found = 1
	SendMessage hsci,SCI_GETTEXT,hsize+1,tx
	PutFile filePath,tx
	Return
ELSE
    Print "ERROR: SAVE! - File Not Found!" + chr(10) + "Create [*New] Document!"
    Return
END IF


END SUB
'*************************************************************
'auto-save
SUB autoSave
INT hsize,tab,found,c
STRING tName,filePath
'print "AutoSave->FNAME:" + fName

hsize = SendMessage hsci, SCI_GETTEXTLENGTH, 0, 0
'exit if empty
IF hsize = 0 Then Return    ' ->->->
found=0
INT tab = GetSelectedTab(tc)
string tName = GetTabText(tc,tab)
tName = Trim(tName)
'search...
For c = 0 To 63
		IF tabName[c] = tName
		   filePath = tabValue[c]
            'SetTabText(tc,tab,tName)  'update tab name
             'ReOpenFile()             'reOpen file from filePath
             'fnParser()               'parse code
		    found=1                  'confirm found	
             Exit For       
	    END IF
Next c

IF found = 1
	SendMessage hsci,SCI_GETTEXT,hsize+1,tx
	PutFile filePath,tx
	Return
ELSE
    Print "ERROR: AUTOSAVE! - File Not Found!" 
    Return
END IF

END SUB
'*************************************************************
'do Close
SUB doClose
INT tab,tabCount,c
STRING tName
'clear sci control
SendMessage hsci,SCI_SETTEXT,0,strptr ""
tabCount=GetTabCount(tc)
'print "TAB COUNT:" tabCount
IF tabCount > 0
	tab = GetSelectedTab(tc)
	'print "SELECTED TAB:" + str(tab)
		If tab > -1
         tName = GetTabText(tc,tab)
         tName = Trim(tName)
		DeleteTab(tc,tab)   ' delete selected tab
            'delete tab info from tabArray[]
         	For c = 0 To 63
			IF  tabName[c] = tName     	
			    tabName[c] = ""      ' clear
                  tabValue[c] = ""     ' clear             
                  Exit For
              END IF 
         Next c
         'print "TAB.INDEX:" + str(tabIndex)
         tabIndex = tabIndex -1
         SendMessage tc,TCM_SETCURSEL,tabIndex,0
		Findtab()
		End if
END IF
IF tabCount = 0
CreateNewTab()
END IF

END SUB
'*************************************************************
'do Copy / paste
SUB doCopy
SendMessage hsci,SCI_COPY,0,0
END SUB
'-------------------------------------------------------------
SUB doPaste
SendMessage hsci,SCI_PASTE,0,0
END SUB
'----------------------------------------------------------
SUB doCompile
char ln[256]
string fn=""
SendMessage edit1,WM_GETTEXT,256,strptr ln
fn = Trim(ln)
'print "FN:" + fn
IF LEN(fn) < 1
MsgBox "File Not Open!","Error::File"
Return
End If
int sRet
autosave()
'(sys hwnd, string lpOperation, lpFile, lpParameters, lpDirectory, sys nShowCmd) as sys
sRet = ShellExecute(0,"open",gxName,"-c" + fName,"" , 5) ' if work sRet = 42
If sRet = 2 then MsgBox "Compiler gxo2 Not Found!"+ crlf + "Enter new compiler path!" , "GXO2 Path"
'sRet = ShellExecute 0,"open","gxo2.exe","-c "+ fn,"",5
'sRet = ShellExecute 0,"open",cdPath,cOption & chr(34) & fName & chr(34),"",5 'fb

END SUB
'---------------------------------------------------------

SUB doRun
STRING exepath=""
INT dotpos=0
dotpos=INSTR(fName,".")
exepath=Mid$(fName,1,dotpos-1)
exepath=exepath + ".exe"
'MESSAGEBOX 0,"path:"+exepath,"OK"
ShellExecute(0,"open", exepath, "","" , 5)
END SUB

'--------------------------------------------------------
SUB GetFileName (src as string) as String

String fname,sign1,name
INT dotpos,bslashpos,nameLen
'print "ShowFName::TABCOUNT->:"+str(tabcount)
'C:\OxygenBasic\examples\GUI\SciEditor\WinControls.o2bas
src=Trim(src)
bslashpos = FieldCount(src,chr(92))
name = Mid(src,bslashpos+1,LEN(src))
dotpos = INSTR(name,".")
'print "DOTP:" + str(dotpos)
'nameLen = LEN(src)-(LEN(src)-dotpos)

name = Mid(name,1,dotpos-1)
'
'print "ShowName->:" + name

Return name
END SUB
'-----------------------------------------------------------
SUB JumpToLine
INT tmpLine : char ln[100]
SendMessage edit2,WM_GETTEXT,100,ln
tmpLine = VAL (ln)-1
SetFocus hsci
SendMessage hsci,SCI_GOTOLINE,tmpLine,0
END SUB
'-----------------------------------------------------------
SUB FieldCount(source As String,delimiter As String) as Int
	Dim delpos,nexpos,count As Int
	'delimiter=chr$(92)
	count=1
	delpos=1
	nexpos=InStr(source,delimiter)
	While nexpos
		delpos=nexpos
		nexpos=InStr(delpos+1,source,delimiter)
		count++
	Wend
	RETURN delpos
END SUB  

'-----------------------------------------------------------------

SUB FindNewTab
INT found,tempTab,c,pos
STRING tName,tempName,tabNum
pos = GetSelectedTab(tc)
found=0
'search for tab -> *New
For c = 0 To 63
	IF  tabName[c] = "*New"     	
		tabValue[c] = filename
         tName = GetFileName(filename) ' extract file name from filePath/tab name/
         tabName[c] = tName             ' update tab name
         SetTabText(tc,pos,tName)       ' set updated as tab text
         fnParser()
         found=1 
         Exit For			
	END IF
Next c 
			
IF found=1
'print "tab *New found!->RETURN"
Return   'ret	
end if
 '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~       
'If tabname already exists !
'IF found=0	
'tName = GetTabText(tc,pos)
'tName = Trim(tName)
/*
For c = 0 To 63
		IF tabName[c] = tName
		   tabValue[c] = filename
            SetTabText(tc,pos,tName)  'update tab name
             ReOpenFile()             'reOpen file from filePath
             fnParser()               'parse code
		    found=1                  'confirm found	       
	    END IF
Next c
END IF
*/

IF found=1 
'print "tabname already exists!->RETURN" 
Return   'ret
end if
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'print" ELSE -> create new tab ...."
'print "ELSE->CREATE NEW TAB"

tabIndex=tabIndex+1  ' increase tab count 
AddTab( tc, tabIndex, "*New")
SendMessage tc,TCM_SETCURSEL,tabIndex,0  ' set newTab as SELECTED

IF found=0
INT epos = -1
'search for first empty tabName in tabName[]
		For c = 0 To 63
			IF  tabName[c] = ""     	
			    tabName[c] = "*New" ' set first empty place with *New
                  tabValue[c] = ""    ' reset
                  epos=c              
                  Exit For
              END IF 
         Next c
'-------------------------------------------
IF epos = -1
print "ERROR: File List Out Of Range! -> 63"
RETURN
END IF
'------------------------------------------
'if is OK update new tab !
pos = GetSelectedTab(tc)
'print "GET SELECTED TAB:" + str(pos)
'search for tab -> *New
For c = 0 To 63
	IF  tabName[c] = "*New"     	
		tabValue[c] = filename
         tName = GetFileName(filename) ' extract file name from filePath/tab name/
         tabName[c] = tName             ' update tab name
         SetTabText(tc,pos,tName)       ' set updated as tab text
         ReOpenFile()                   'reOpen file from filePath
         fnParser()    
         found=1 
         Exit For			
	END IF
Next c 

END IF
'~~~~~~~~~~~~~~~~~~~~~~
RETURN
END SUB
'----------------------------------------------------------
SUB FindTab
INT found,tempTab,c
STRING tName,tabItem

tempTab=GetSelectedTab(tc)
tabItem = str(tempTab)
SendMessage edit3,WM_SETTEXT,0,strptr(tabItem) ' show tab id /zero-based/
tName=GetTabText(tc,tempTab)
tName=Trim(tName)
'print "LEN:GETText:" + str(len(tname))
SendMessage edit4,WM_SETTEXT,0,strptr(tName)   'show tab name
'print "LEN_after_TRIM:" + str(len(tName))

IF tName="*New"
SendMessage hsci,SCI_CLEARALL,0,0
Return
END IF

found=0
'show filePath [EDIT 1]-> C:\folder\myfile.bas
SendMessage edit1,WM_SETTEXT,0,strptr(tabValue[tempTab])
'search tab name...
For c = 0 To 63
	IF  tabName[c] = tName 
         'print "FOUND:" + tabName[c]     	
		found=1:Exit For				
	END IF
Next c

IF found = 1
ReOpenFile()
fnParser()
Return				
END IF
'-------------------
IF found=0
'MESSAGEBOX 0,"New File!","Message..."
Return
END IF

END SUB

'----------------------------------------------------------
SUB ReOpenFile
SendMessage hsci,SCI_CLEARALL,0,0
INT tempTab,c
STRING name,filePath
tempTab=GetSelectedTab(tc)
name=GetTabText(tc,tempTab)
name=Trim(name)
'print "RE-OPEN:" + name

For c = 0 To 63
	IF  tabName[c] = name      	
		filePath = tabValue[c]
         Exit For			
	END IF
Next c
SendMessage edit1,WM_SETTEXT,0,strptr(filePath)
'print "REOPEN-GetName:" + name
 tx =  GetFile filePath
SendMessage hsci,SCI_SETTEXT,0,strptr(tx)
SendMessage hsci,SCI_SETSAVEPOINT, 0, 0
SendMessage hsci,SCI_EMPTYUNDOBUFFER,0,0


END SUB
'----------------------------------------------------------
SUB CreateNewTab
int tab,c=0 : string tabnum
tabIndex=tabIndex+1
'first stored info for tabArray AT pos->0
tabName[c]="*New"
tabValue[c] = ""
'create new tab
AddTab( tc, tabIndex,"*New")
SendMessage tc,TCM_SETCURSEL,tabIndex,0  'set selected new tab
Tab=GetSelectedTab(tc)                   'get selected tab
tabNum = str(tab)
SendMessage edit3,WM_SETTEXT,0,strptr(tabnum) 'show tab ID

Return
END SUB 

'-----------------------------------------------------------
SUB NewTab
tabIndex=tabIndex+1  ' increase tab count 
AddTab( tc, tabIndex, "*New")
SendMessage tc,TCM_SETCURSEL,tabIndex,0  ' set newTab as SELECTED
INT epos = -1
'search for first empty tabName in tabName[]
		For c = 0 To 63
			IF  tabName[c] = ""     	
			    tabName[c] = "*New" ' set first empty place with *New
                  tabValue[c] = ""    ' reset
                  epos=c              
                  Exit For
              END IF 
         Next c
'-------------------------------------------
IF epos = -1
print "ERROR: File List Out Of Range! -> 63"
RETURN
END IF

END SUB
'-----------------------------------------------------------

SUB fnParser
'reset listbox content ***************************************
STRING o2script[100000] 'string array
SendMessage LBox,LB_RESETCONTENT,0,o2script[100000]
STRING i$,txt,d$=" "
STRING GW1,GW2
INT smax,start,lineNum,iLen,bo,ipos
start=0
smax = Sendmessage hsci,SCI_GETLINECOUNT, 0, 0

'parse line by line >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
FOR lineNum = 1 TO smax
	
int Pos=0
int EPos=0
int SPos=0
int WC=0

'get-line ........................................................

iLen = SendMessage hsci,SCI_LINELENGTH,lineNum,0    'get line length
o2script[lineNum] = String(iLen," ")                'set buffer space
Sendmessage hsci,SCI_GETLINE, lineNum, strPtr(o2script[lineNum])
'test ///////////////////////////////
'print "LINE:" + o2script[lineNum]
'///////////////////////////////////
o2script[lineNum] = Ltrim(o2script[lineNum])
'--------------------------------------------
WC = 1
	Pos = InStr(1,o2script[lineNum], d$)
    While Pos > 0
        WC = WC + 1
		Pos = InStr(pos+1,o2script[lineNum], d$)
    Wend
'test wc------------------------------------------
'print WC
IF wc>0       
    SPos = 1      
    EPos = InStr(SPos,o2script[lineNum], d$) - 1
    If EPos <= 0 Then EPos = LEN(o2script[lineNum])
    GW1 = RTrim(LTrim(Mid(o2script[lineNum], SPos, EPos - SPos + 1)))
'print "GW1:"+GW1 
END IF
'--------------------------------------------------
IF wc>1      
    SPos=EPos+2      
    EPos = InStr(SPos,o2script[lineNum], d$) - 1
    If EPos <= 0 Then EPos = LEN(o2script[lineNum])
    GW2 = RTrim(LTrim(Mid(o2script[lineNum], SPos, EPos - SPos + 1)))
'print "GW2:"+GW2 
END IF

'test string & add to listbox
'/// SUB ///
IF Ucase(GW1) = "SUB"
'remove bracket ((((((((((((((((
bo = Instr (GW2,"(")
'print str(Len(GW2))
'print "BO:"+str(bo)
 IF bo<>0
   bo=bo-1
   GW2=Mid(GW2,1,bo)
   bo=0
 END IF
i$ = "SUB:" + GW2

SendMessage Lbox,LB_ADDSTRING,0,i$
LBitems[LBitem]=lineNum
LBitem=LBitem+1
END IF

'/// FUNCTION ///
IF (Ucase(GW1) = "FUNCTION") And (Left(GW2,1)<>"=") And (Mid(GW1,9)<>"=")
bo = Instr (GW2,"(")
 IF bo<>0
   bo=bo-1
   GW2=Mid(GW2,1,bo)
   bo=0
 END IF
i$ = "FN:" + GW2
SendMessage Lbox,LB_ADDSTRING,0,i$
LBitems[LBitem]=lineNum
LBitem=LBitem+1
END IF
GW1="":GW2=""

NEXT
LBitem=0
END SUB


'///////////////////////////////////////
SUB AddTButton(twnd as sys,id as sys,iNum as sys,tip as string)
TOOLINFO tti

 tti.cbSize = sizeof tti
 tti.uFlags = 0   'TTF_SUBCLASS | TTF_IDISHWND
 tti.hwnd   = twnd
 tti.uId    = id
 tti.hinst  = 0
 tti.lpszText = strPtr tip

SendMessage(SendMessage( htbar, 1059,0,0),1028, 0, &tti)

'add button
tbb.iBitmap = iNum
tbb.idCommand = id
tbb.fsState = 4
tbb.fsStyle = 0     
tbb.dwData = 0
SendMessage htbar , 1044, 1, &tbb

END SUB 


'//////////////////////////////////////
SUB oxyKeywords
'blue
sciblue="enum operator dim const local static global declare function sub method end if then else elseif endif "
sciblue=sciblue+"endsel do while enddo endwhile wend exit continue operation operations select case for to step next "
sciblue=sciblue+"goto gosub methods return block scope indexbase lib library extern that this "
sciblue=sciblue+"readstate writestate deff type val ltrim rtrim lcase ucase space left mid instr "
sciblue=sciblue+"asc len chr str hex print ellipse rgb sendmessage  "
sciblue=sciblue+"with "
sciblue=sciblue+"noinit "
sciblue=sciblue+"byval "
sciblue=sciblue+"byref "
sciblue=sciblue+"economy "
sciblue=sciblue+"fpu "
sciblue=sciblue+"cpu "
sciblue=sciblue+"noprec "
sciblue=sciblue+"include "
sciblue=sciblue+"define "
sciblue=sciblue+"typedef "
sciblue=sciblue+"includepath "
sciblue=sciblue+"lookahead "
sciblue=sciblue+"view "
sciblue=sciblue+"endv "
sciblue=sciblue+"version "
sciblue=sciblue+"getmemory "
sciblue=sciblue+"freememory "
sciblue=sciblue+"getprocaddress "
sciblue=sciblue+"copy0 "
sciblue=sciblue+"copy00 "
sciblue=sciblue+"copyn "
sciblue=sciblue+"copy "
sciblue=sciblue+"mbox "
sciblue=sciblue+"comparestr "
'----------------------------
sciblue=sciblue+"alias macro as "
sciblue=sciblue+"incl "
sciblue=sciblue+"semicolon "
sciblue=sciblue+"indexers "
sciblue=sciblue+"retn "
sciblue=sciblue+"offset "
sciblue=sciblue+"skip "
sciblue=sciblue+"with "
sciblue=sciblue+"dataspace "
sciblue=sciblue+"data "
sciblue=sciblue+"o2 "
sciblue=sciblue+"bind "
sciblue=sciblue+"defs "
sciblue=sciblue+"def "
sciblue=sciblue+"struct "
sciblue=sciblue+"class "
sciblue=sciblue+"var "
sciblue=sciblue+"asm "
sciblue=sciblue+"o2h "
sciblue=sciblue+"librarypath "
sciblue=sciblue+"file "
sciblue=sciblue+"quote "
sciblue=sciblue+"union "
sciblue=sciblue+"leaf "
sciblue=sciblue+"autodim "
sciblue=sciblue+"minormajor "
sciblue=sciblue+"alert "
sciblue=sciblue+"pragma "
sciblue=sciblue+"unique "
sciblue=sciblue+"console "
sciblue=sciblue+"elif "
sciblue=sciblue+"fi "
sciblue=sciblue+"ifdef "
sciblue=sciblue+"ifndef "
sciblue=sciblue+"undef "
sciblue=sciblue+"undefine "
sciblue=sciblue+"blockdepth "
sciblue=sciblue+"new "
sciblue=sciblue+"del "
sciblue=sciblue+"terminate "
sciblue=sciblue+"freestrings "
sciblue=sciblue+"freelibs "
sciblue=sciblue+"inherits "
sciblue=sciblue+"of "
sciblue=sciblue+"from "
sciblue=sciblue+"has "
sciblue=sciblue+"export "
sciblue=sciblue+"external "
sciblue=sciblue+"com "
sciblue=sciblue+"virtual "
sciblue=sciblue+"endselect "
sciblue=sciblue+"load "
sciblue=sciblue+"and "
sciblue=sciblue+"or "
sciblue=sciblue+"xor "
sciblue=sciblue+"stdcall "
sciblue=sciblue+"cdecl "
sciblue=sciblue+"ms64 "
sciblue=sciblue+"at "
sciblue=sciblue+"not "
sciblue=sciblue+"once "
sciblue=sciblue+"public "
sciblue=sciblue+"private "
sciblue=sciblue+"strptr "
sciblue=sciblue+"getfile putfile loadlibrary getdc releasedc sizeof "
sciblue=sciblue+"createwindowex filedialog trim replace #lookahead "

'AWIH keywords in sciBrown  //////////////////////////////////////////////////////////////
sciBrown=sciBrown+"wndproc addtab getselectedtab settabtext gettabtext gettabcount setselectedtab deletetab controlfont setricheditbackcolor "
sciBrown=sciBrown+"setwindow seteditbox setrichedit setbutton setlistbox setcombobox setstatic settoolbar settabcontrol settooltip "
sciBrown=sciBrown+"gettext settext setstatusbar settrackbar gettruckpos settreeview tvinsertitem setprogressbar pbsetpos setradiobutton "
sciBrown=sciBrown+"setcheckbox initdrawing windowcolor msgbox default notifycode "

'sciRed - red - var types
sciRed=sciRed+"void " 
sciRed=sciRed+"byte "
sciRed=sciRed+"astring "
sciRed=sciRed+"pstring "
sciRed=sciRed+"bstring "
sciRed=sciRed+"char "
sciRed=sciRed+"zstring " 
sciRed=sciRed+"wstring "
sciRed=sciRed+"bstring2 "
sciRed=sciRed+"zstring2 "
sciRed=sciRed+"asciiz "
sciRed=sciRed+"short "
sciRed=sciRed+"int "
sciRed=sciRed+"integer " 
sciRed=sciRed+"float "
sciRed=sciRed+"single "
sciRed=sciRed+"sys "
sciRed=sciRed+"double " 
sciRed=sciRed+"quad "
sciRed=sciRed+"word "
sciRed=sciRed+"dword "
sciRed=sciRed+"qword "
sciRed=sciRed+"uint "
sciRed=sciRed+"__int8 "
sciRed=sciRed+"__int16 "
sciRed=sciRed+"__int32 "
sciRed=sciRed+"__int64 " 
sciRed=sciRed+"int8_t " 
sciRed=sciRed+"int16_t " 
sciRed=sciRed+"int32_t " 
sciRed=sciRed+"int64_t "
sciRed=sciRed+"uint8_t " 
sciRed=sciRed+"uint16_t "
sciRed=sciRed+"uint32_t "
sciRed=sciRed+"uint64_t " 
sciRed=sciRed+"any "
sciRed=sciRed+"sys"
sciRed=sciRed+"bool "
sciRed=sciRed+"signed " 
sciRed=sciRed+"unsigned "
sciRed=sciRed+"string "
sciRed=sciRed+"long "

END SUB
'
'///// EDITOR  ABOUT WINDOW - AboutBox  ///////////////////////////////////////////
SUB AboutBox
String mbff=""
mbff="Scintilla based code editor written with pure WIN32 API"+chr(13)
'mbff=mbff + "Code Editor written..................."+chr(13)
mbff=mbff + "Created by Aurel v036-2018"+chr(13)
'create  about window **************************
wabout = SetWindow("About AurelEdit...",300,160,412,400,0,WS_SYSMENU)
'create static control
static3 = SetStatic(wabout,2,2,400,300,"",0x5000030E,0,st3ID)
SendMessage static3, 370, 0, bmpB1
static4 = SetStatic(wabout,4,310,398,50,mbff,0x50000101,0x200,st4ID)

aboutWindow = 1
END SUB
	
'/////// EDITOR OPTION WINDOW  ////////////////////////////////////////////////////
SUB OptWindow
INT static5,st5ID=355
STRING bff,bf1
'create option window **************************
optWin = SetWindow("Editor options...",300,160,412,400,0,WS_SYSMENU)
bff="SET Theme by choosing one of options..."
static5 = SetStatic(optWin,4,4,398,14,bff,0x50000101,0,st5ID)
'----------------------------------------------------------------------------------
INT st6ID=336,st7ID=338,st8ID=339,st9ID=340
INT static6b,st6bID=337,static7b,st7bID=337,st8bID=440,st9bID=441
'----------------------------------------------------------------------------------
static6 = SetStatic(optWin,8,30,126,14,"Theme : Clear Sea",0x50000100,0,st6ID)
static6b = SetStatic(optWin,330,24,26,26,"",0x5000030E,0,st6bID)
SendMessage static6b, 370, 0, bmpB2
bo1 = SetButton(optWin,160,25,100,24,"[ CLEAR SEA ] -",0x50000000,0x200,bo1ID)
'---------------------------------------------------------------------------------
static7 = SetStatic(optWin,8,60,126,14,"Theme : Soft Desert",0x50000100,0,st7ID)
bo2 = SetButton(optWin,160,55,100,24,"[ SOFT DESERT ] -",0x50000000,0x200,bo2ID)
static7b = SetStatic(optWin,330,55,26,26,"",0x5000030E,0,st7bID)
SendMessage static7b, 370, 0, bmpB3
'----------------------------------------------------------------------------------
static8 = SetStatic(optWin,8,90,126,14,"Theme : Default",0x50000100,0,st8ID)
bo3 = SetButton(optWin,160,85,100,24,"[ DEFAULT ] -",0x50000000,0x200,bo3ID)
static8b = SetStatic(optWin,330,55,26,26,"",0x5000030E,0,st8bID)
SendMessage static8b, 370, 0, bmpB4
'----------------------------------------------------------------------------------
static9 = SetStatic(optWin,8,120,126,14,"Theme : Dark Moon",0x50000100,0,st9ID)
bo4 = SetButton(optWin,160,115,100,24,"[ DARK MOON ] -",0x50000000,0x200,bo4ID)
static9b = SetStatic(optWin,330,55,26,26,"",0x5000030E,0,st9bID)
SendMessage static9b, 370, 0, bmpB5

'----------------------------------------------------------------------------------
optWinOn = 1
END SUB 
'=================================================================================
SUB FindWindow ' create Find/Replace window As TOOLWINDOW? 
'INT fb1,fb2,fb3,fb1ID=501,fb2ID=502,fb3ID=503,fwed1,fwed1ID=504,fwed2,fwed2ID=505
'create ToolWindow require exetended window style to be set
INT hinst = GetModuleHandle 0
fWindow=CreateWindowEx (WS_TOOLWINDOW|WS_EX_TOPMOST , wcx.lpszClassName,"Find/Replace...",WS_SYSMENU, 600, 160, 412, 300, 0, 0, hinst, 0)
ShowWindow fWindow,SW_SHOW : UpdateWindow fWindow
fb1=SetButton(fWindow,20,240,100,24,"[ Find ]",0x50000000,0x200,fb1ID)
fb2=SetButton(fWindow,150,240,100,24,"[ Replace ]",0x50000000,0x200,fb2ID)
fb3=SetButton(fWindow,280,240,100,24,"[ Replace All ]",0x50000000,0x200,fb3ID)
'create single-line edit control and static control
stFW1 = SetStatic(fWindow,20,30,100,26,"Search Word >>>",0x50000001,0,stfw1ID)
fwed1 = SetEditBox(fWindow,150,30,200,23,"",0x50004000,0x200,fwed1ID)
stFW2 = SetStatic(fWindow,20,80,100,26,"Replace With >>>",0x50000001,0,stfw2ID)
fwed2 = SetEditBox(fWindow,150,80,200,23,"",0x50004000,0x200,fwed2ID)
findWinOn = 1
END SUB
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Sub FindNext () as long
INT loc=1,temp 
if loc 
loc=SENDMESSAGE hsci,SCI_GETSELECTIONEND,0,0
'print "is selected-LOC: " + str(loc)
else
loc=SENDMESSAGE hsci,SCI_GETSELECTIONSTART,0,0
'print "selection start-LOC: " + str(loc) 
end if

SENDMESSAGE hsci,SCI_SETANCHOR,loc,0,
SENDMESSAGE hsci,SCI_SETCURRENTPOS,loc,0
SENDMESSAGE hsci,SCI_SEARCHANCHOR,0,0

temp = SCFIND_WHOLEWORD
'print "TEMP: " + str(temp)
loc=SENDMESSAGE hsci,SCI_SEARCHNEXT,temp,GetText(fwed1)
'print "SEARCH-NEXT: " + str(loc)
'---------------------------------------------
IF loc > -1
      SENDMESSAGE hsci,SCI_SCROLLCARET,0,0
ELSE
	Msgbox "No matches found","Search"
Return 0
END IF
'-------------------------------------------
Return loc
End Sub
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Function ReplaceOnce(RepeatS As Long) As Long
If FindNext() = 0	
	Return 0
End if
SENDMESSAGE hsci,SCI_REPLACESEL,0,GetText(fwed2)
Return 1
End Function
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Sub ReplaceAll
   dim iResult As Long
   'If FindNext() = 0 then 
   ' Exit Function
   'End If
   iResult = ReplaceOnce(1)
If iResult = 0 then Exit Sub
   While iResult =1
      FindNext() 
      iResult = ReplaceOnce(1)                   
   Wend
   MsgBox " All words Replaced!","Info"
End Sub
'/////////////////////////////////////////////////////////////////////
'//////////////////   theme  CLEAR SEA          //////////////////////
Sub SetTheme1
SENDMESSAGE(hsci, SCI_STYLESETBACK,32, RGB(240,240,255)) 'clear sea
SENDMESSAGE(hsci, SCI_STYLECLEARALL, 0, 1)
'set scintilla font
For i = 0 to 8
	SENDMESSAGE (hsci, SCI_STYLESETFONT, i, "Consolas")
	SENDMESSAGE (hsci, SCI_STYLESETSIZE, i, 11)
Next i
'set keyword colors
'SENDMESSAGE(hsci, SCI_SETKEYWORDS, 3,scibrown) :'darkred 
SENDMESSAGE(hsci, SCI_SETKEYWORDS, 0, sciblue ):'blue
 'Margins ////////////////////////////////////////////////////////
'set number margin (for numnbers)
SendMessage(hsci, SCI_SETMARGINTYPEN, 0, SC_MARGIN_NUMBER)
SendMessage(hsci, SCI_SETMARGINWIDTHN, 0, 46)
'caret line
SENDMESSAGE hsci,SCI_SETCARETLINEBACK,RGB(245,245,200),0
SENDMESSAGE hsci,SCI_SETCARETLINEVISIBLE,1,0
'SetFocus win
'--------------------------------------------------------------------
 def sn SendMessage hsci, SCI_STYLESETFORE,
      '
      'setting RGB colors
      sn 0,  0xff0000  '
      sn 1,  0x207800         'line comment
      sn 2,  rgb(160,42,42)  'numbers
      sn 3,  rgb(0,0,170)     'keywords
      sn 4,  rgb(150,0,150)   'string
      sn 5,  0xc00080         '#names
      sn 6,  rgb(200,0,0)     'symbols
      sn 7,  0x002000  '
      '
SetFocus Lbox
End Sub
'//////////////////////////////////////////////////////////////////////
'////// theme  SOFT DESERT  ///////////////////////////////////////////
Sub SetTheme2
SENDMESSAGE(hsci, SCI_STYLESETBACK,32, rgb(243,242,214)) 'soft desert
SENDMESSAGE(hsci, SCI_STYLECLEARALL, 0, 1)
'set scintilla font
For i = 0 to 8
	SENDMESSAGE (hsci, SCI_STYLESETFONT, i, "Courier New")
	SENDMESSAGE (hsci, SCI_STYLESETSIZE, i, 12)
     'SENDMESSAGE hsci, SCI_STYLESETBOLD, i, 12 'uncomment if you wish bold text
Next i
'set keyword colors
'SENDMESSAGE(hsci, SCI_SETKEYWORDS, 0, sciblue ):'blue
SENDMESSAGE(hsci, SCI_SETKEYWORDS, 0, sciblue )
 SendMessage hsci, SCI_COLOURISE, 0, -1
 'Margins ////////////////////////////////////////////////////////
'set number margin (for numnbers)
SendMessage(hsci, SCI_SETMARGINTYPEN, 0, SC_MARGIN_NUMBER)
SendMessage(hsci, SCI_SETMARGINWIDTHN, 0, 46)
'caret line
SENDMESSAGE hsci,SCI_SETCARETLINEBACK,RGB(220,220,245),0
SENDMESSAGE hsci,SCI_SETCARETLINEVISIBLE,1,0

'--------------------------------------------------------------------
def sn SendMessage hsci, SCI_STYLESETFORE,
      '
      'setting RGB colors
      sn 0,  rgb(180,0,0)  '
      sn 1,  0x207800         'line comment
      sn 2,  rgb(164,42,42)  'numbers
      sn 3,  rgb(0,0,170)     'keywords
      sn 4,  rgb(150,0,150)   'string
      sn 5,  0xc00080         '#names
      sn 6,  rgb(200,0,0)     'symbols
      sn 7,  0x002000  '
      '	
SetFocus Lbox

End Sub
'///////////////////////////////////////////////////////////////////////
'////// theme DEFAULT   /////////////////////////////////////////////////
Sub SetTheme3
SENDMESSAGE(hsci, SCI_STYLESETBACK,32, rgb(255,255,255)) 'default
SENDMESSAGE(hsci, SCI_STYLECLEARALL, 0, 1)
'set scintilla font
For i = 0 to 8
	SENDMESSAGE (hsci, SCI_STYLESETFONT, i, "Courier New")
	SENDMESSAGE (hsci, SCI_STYLESETSIZE, i, 10)
     'SENDMESSAGE hsci, SCI_STYLESETBOLD, i, 12 'uncomment if you wish bold text
Next i
'set keyword colors
'SENDMESSAGE(hsci, SCI_SETKEYWORDS, 0, sciblue ):'blue
SENDMESSAGE(hsci, SCI_SETKEYWORDS, 0, sciblue )
 SendMessage hsci, SCI_COLOURISE, 0, -1
 'Margins ////////////////////////////////////////////////////////
'set number margin (for numnbers)
SendMessage(hsci, SCI_SETMARGINTYPEN, 0, SC_MARGIN_NUMBER)
SendMessage(hsci, SCI_SETMARGINWIDTHN, 0, 46)
'caret line
SENDMESSAGE hsci,SCI_SETCARETLINEBACK,RGB(245,245,200),0
SENDMESSAGE hsci,SCI_SETCARETLINEVISIBLE,1,0

'--------------------------------------------------------------------
def sn SendMessage hsci, SCI_STYLESETFORE,
      '
      'setting RGB colors
      sn 0,  rgb(180,0,0)  '
      sn 1,  0x207800         'line comment
      sn 2,  rgb(164,42,42)  'numbers
      sn 3,  rgb(0,0,170)     'keywords
      sn 4,  rgb(150,0,150)   'string
      sn 5,  0xc00080         '#names
      sn 6,  rgb(200,0,0)     'symbols
      sn 7,  0x002000  '
      '	
SetFocus Lbox

End Sub
'//////////////////////////////////////////////////////////////////////////
'///// theme DARK MOON   //////////////////////////////////////////////////
Sub SetTheme4
SENDMESSAGE(hsci, SCI_STYLESETBACK,32, rgb(50,50,80)) 'dark moon
SENDMESSAGE(hsci, SCI_STYLECLEARALL, 0, 1)
'set scintilla font
For i = 0 to 8
	SENDMESSAGE (hsci, SCI_STYLESETFONT, i, "Courier New")
	SENDMESSAGE (hsci, SCI_STYLESETSIZE, i, 10)
     'SENDMESSAGE hsci, SCI_STYLESETBOLD, i, 12 'uncomment if you wish bold text
Next i
'set keyword colors
'SENDMESSAGE(hsci, SCI_SETKEYWORDS, 0, sciblue ):'blue
SENDMESSAGE(hsci, SCI_SETKEYWORDS, 0, sciblue )
 SendMessage hsci, SCI_COLOURISE, 0, -1
 'Margins ////////////////////////////////////////////////////////
'set number margin (for numnbers)
SendMessage(hsci, SCI_SETMARGINTYPEN, 0, SC_MARGIN_NUMBER)
SendMessage(hsci, SCI_SETMARGINWIDTHN, 0, 46)
'caret line
SENDMESSAGE hsci,SCI_SETCARETLINEBACK,RGB(45,145,60),0
SENDMESSAGE hsci,SCI_SETCARETLINEVISIBLE,1,0

'--------------------------------------------------------------------
def sn SendMessage hsci, SCI_STYLESETFORE,
      '
      'setting RGB colors
      sn 0,  rgb(0,0,220)  '
      sn 1,  rgb(80,100,100)        'line comment
      sn 2,  rgb(200,180,123)   'numbers
      sn 3,  rgb(140,140,250)     'keywords
      sn 4,  rgb(150,0,150)   'string
      sn 5,  0xc00080         '#names
      sn 6,  rgb(200,180,100)     'symbols
      sn 7,  rgb(180,200,220) 'other
      '	
SetFocus Lbox
End Sub




 