$IFDEF FRANCAIS
CONST trfile="data\Notes.txt"
$ELSE
CONST trfile="data\Notes.txt"
$ENDIF
DECLARE SUB trinit
DECLARE SUB trnewclic
DECLARE SUB treeclic
DECLARE SUB trkeydown(key AS WORD, shift AS INTEGER)
DECLARE SUB trtextchange
DECLARE SUB treechange(i AS INTEGER)
CONST trmarginW=0.06
CONST trtreeW=0.22
CONST trseparW=0.03
CONST trtextW=0.69
CONST trVunit=20
CREATE TrPanel AS QPANEL
PARENT=Tab
left=4 : top=28
COLOR=colorfond
visible=false
borderstyle=0 : bevelouter=0 : bevelinner=0
CREATE tree AS QTREEVIEW
showhint=false
onchange=treechange
END CREATE
CREATE texttree AS QTREEVIEW
visible=false
END CREATE
CREATE trtext AS QRICHEDIT
wanttabs=true
onchange=trtextchange
END CREATE
CREATE trnew AS QBUTTON
CAPTION=s_New
onclick=trnewclic
END CREATE
END CREATE
CONST GWL_STYLE=-16
CONST TVS_NOTOOLTIPS=&H80
DECLARE FUNCTION SetWindowLong LIB "user32" ALIAS "SetWindowLongA" (hwnd AS LONG, nIndex AS LONG, dwNewLong AS LONG) AS LONG
DECLARE FUNCTION GetWindowLong LIB "user32" ALIAS "GetWindowLongA" (hwnd AS LONG, nIndex AS LONG) AS LONG
SetWindowLong(Tree.Handle, GWL_STYLE, GetWindowLong(Tree.Handle, GWL_STYLE) OR TVS_NOTOOLTIPS)
SUB trinit
trpanel.width=panelwidth: trpanel.height=panelheight
WITH tree
.left=panelwidth*trmarginW/2
.top=trVunit*2
.width=panelwidth*trtreeW
.height=panelheight-tree.top-trVunit
END WITH
WITH trtext
.left=panelwidth*(trmarginW/2+trtreeW+trseparW)
.top=tree.top
.width=panelwidth*trtextW
.height=tree.height
END WITH
WITH trnew
.left=tree.left
.top=trVunit/2
.width=tree.width * 0.3 : .height=trVunit
END WITH
fileprint.enabled=true
editnew.enabled=true
edituse.enabled=true
menuicon.enabled=false
editall.enabled=true
editfind.enabled=true
editfindnext.enabled=true
setfocus(tree.handle)
END SUB
SUB opentree
DIM s AS STRING, state AS STRING
DEFINT selecteditem=-1
CHDIR appdir
IF FILEEXISTS(trFile)=false THEN
tree.clear
ELSE
tree.loadfromfile(trFile)
END IF
FOR i=0 TO tree.itemcount-1
s=tree.item(i).text
state=LEFT$(s,1)
SELECT CASE state
CASE "["
tree.expand(i,0)
CASE "<"
tree.expand(i,0)
selecteditem=i
CASE ">"
selecteditem=i
END SELECT
s=FIELD$(s,CHR$(9),1)
s=RIGHT$(s,LEN(s)-1)
tree.item(i).text=s
NEXT
IF FILEEXISTS(trFile)=false THEN
texttree.clear
ELSE
texttree.loadfromfile(trFile)
END IF
FOR i=0 TO texttree.itemcount-1
s=texttree.item(i).text
placetab=INSTR(s,CHR$(9))
s=MID$(s,placetab+1,LEN(s)-placetab)
s=REPLACESUBSTR$(s,crSubst,crString)
texttree.item(i).text=s
NEXT
IF tree.itemcount>0 THEN tree.itemindex=selecteditem
END SUB
SUB treechange(i AS INTEGER)
posit=tree.itemindex
trtext.text=texttree.item(posit).text
END SUB
CONST TV_FIRST = &H1100
CONST TVM_EDITLABELA = TV_FIRST + 14
DECLARE FUNCTION SendMessageA LIB "user32" ALIAS "SendMessageA" (BYVAL hwnd AS LONG, BYVAL wMsg AS LONG, BYVAL wParam AS LONG, lParam AS LONG) AS LONG
SUB trnewclic
IF tree.itemcount=0 THEN
tree.additems("Notes")
texttree.additems("")
tree.itemindex=0
setfocus(tree.handle)
ELSE
posit=tree.itemindex
tree.addchilditems(posit,"Nouvelle note")
tree.expand(posit,false)
texttree.addchilditems(posit,"")
i=posit
positlevel=tree.item(posit).level
DO
i++
IF i=tree.itemcount-1 THEN EXIT DO
LOOP UNTIL (tree.item(i+1).level<=positlevel)
tree.itemindex=i
setfocus(tree.handle)
l=SendMessageA(tree.handle,TVM_EDITLABELA,0,tree.item(i).handle)
END IF
END SUB
SUB trtextchange
posit=tree.itemindex
texttree.item(posit).text=trtext.text
END SUB
SUB trsave
DIM s AS STRING, state AS STRING, title AS STRING
FOR i=0 TO tree.itemcount-1
title=tree.item(i).text
s=texttree.item(i).text
s=REPLACESUBSTR$(s,crString,crSubst)
IF i=tree.itemcount-1 THEN
state=IIF(i=tree.itemindex,">","]")
ELSE
isexpanded=tree.item(i).haschildren*tree.item(i+1).isvisible
state=IIF(isexpanded=0,IIF(i=tree.itemindex,">","]"),IIF(i=tree.itemindex,"<","["))
END IF
texttree.item(i).text=state+title+CHR$(9)+s
NEXT
CHDIR appdir
texttree.savetofile(trFile)
FOR i=0 TO tree.itemcount-1
s=texttree.item(i).text
placetab=INSTR(s,CHR$(9))
s=MID$(s,placetab+1,LEN(s)-placetab)
s=REPLACESUBSTR$(s,crSubst,crString)
texttree.item(i).text=s
NEXT
END SUB
SUB trdodelete(i AS INTEGER)
DIM s AS STRING
tree.delitems(i)
texttree.delitems(i)
posit=tree.itemindex
IF posit<0 THEN
s=""
ELSE
s=texttree.item(posit).text
END IF
trtext.text=s
END SUB
SUB TRdelete
DIM s AS STRING
posit=tree.itemindex
IF posit<0 THEN EXIT SUB
IF tree.item(posit).haschildren THEN
IF MESSAGEDLG(s_childdeleteconfirm, mtWarning, mbYes OR mbNo, 0) <> mrYes THEN EXIT SUB
END IF
tree.delitems(posit)
texttree.delitems(posit)
posit=tree.itemindex
IF posit<0 THEN
s=""
ELSE
s=texttree.item(posit).text
END IF
trtext.text=s
END SUB
CREATE clipboardtree AS QTREEVIEW
PARENT=form
visible=false
clear
END CREATE
CREATE clipboardtexttree AS QTREEVIEW
PARENT=form
visible=false
clear
END CREATE
SUB trCopyNode
DIM s AS STRING, texts AS STRING
clipboard.text=""
clipboardtree.clear
clipboardtexttree.clear
copynode=tree.itemindex
IF copynode<0 THEN EXIT SUB
copynodelevel=tree.item(copynode).level
s=tree.item(copynode).text
texts=texttree.item(copynode).text
clipboardtree.additems(s)
clipboardtexttree.additems(texts)
FOR i=copynode+1 TO tree.itemcount-1
s=tree.item(i).text
texts=texttree.item(i).text
ilevel=tree.item(i).level
IF ilevel<=copynodelevel THEN EXIT FOR
FOR j=i-1 TO copynode STEP -1
jlevel=tree.item(j).level
IF jlevel<ilevel THEN EXIT FOR
NEXT
clipboardtree.addchilditems(j-copynode,s)
clipboardtexttree.addchilditems(j-copynode,texts)
NEXT
FOR i=0 TO clipboardtree.itemcount-2
IF tree.item(copynode+i).haschildren*tree.item(copynode+i+1).isvisible THEN
clipboardtree.expand(i,0)
ELSE
clipboardtree.collapse(i,0)
END IF
NEXT
END SUB
SUB trcut
IF getfocus=tree.handle THEN
i=tree.itemindex
trCopyNode
trDoDelete(i)
ELSE
clipboard.text=trtext.seltext
trtext.seltext=""
END IF
END SUB
SUB trcopy
IF getfocus=tree.handle THEN
trCopyNode
ELSE
clipboard.text=trtext.seltext
END IF
END SUB
SUB trpaste
DIM s AS STRING, texts AS STRING
IF clipboardtree.itemcount=0 THEN GOTO notreeclipboard
IF getfocus <> tree.handle THEN EXIT SUB
pastenode=tree.itemindex
s=clipboardtree.item(0).text
texts=clipboardtexttree.item(0).text
IF tree.itemcount=0 THEN
tree.additems(s)
texttree.additems(texts)
firstpasted=0
ELSE
tree.addchilditems(pastenode,s)
texttree.addchilditems(pastenode,texts)
pastenodelevel=tree.item(pastenode).level
FOR i=pastenode+1 TO tree.itemcount-1
ilevel=tree.item(i).level
IF ilevel<=pastenodelevel THEN EXIT FOR
NEXT
firstpasted=i-1
END IF
FOR i=1 TO clipboardtree.itemcount-1
s=clipboardtree.item(i).text
texts=clipboardtexttree.item(i).text
ilevel=clipboardtree.item(i).level
FOR j=i-1 TO 0 STEP -1
jlevel=clipboardtree.item(j).level
IF jlevel<ilevel THEN EXIT FOR
NEXT
tree.addchilditems(firstpasted+j,s)
texttree.addchilditems(firstpasted+j,texts)
NEXT
FOR i=0 TO clipboardtree.itemcount-2
IF clipboardtree.item(i).haschildren*clipboardtree.item(i+1).isvisible THEN
tree.expand(firstpasted+i,0)
ELSE
tree.collapse(firstpasted+i,0)
END IF
NEXT
EXIT SUB
notreeclipboard:
trtext.seltext=clipboard.text
END SUB
SUB trselectall
setfocus(trtext.handle)
trtext.selstart=0
trtext.sellength=LEN(trtext.text)
END SUB
SUB truse
DIM s AS STRING
s=trtext.seltext
IF s="" THEN
s=trtext.line(trtext.wherey)
wherex=trtext.wherex
FOR i=wherex TO 1 STEP -1
IF MID$(s,i,1)=CHR$(9) THEN i++ : EXIT FOR
trtext.selstart=trtext.selstart-1
NEXT
trtext.sellength=0
FOR j=i TO LEN(s)
IF MID$(s,j,1)=CHR$(9) THEN EXIT FOR
trtext.sellength=trtext.sellength+1
NEXT
s=trtext.seltext
s=s-crString-CHR$(9)
END IF
use(s)
END SUB
SUB trpageup
i=tree.itemindex
IF i=0 THEN EXIT SUB
DO
i--
IF tree.item(i).isvisible THEN EXIT DO
LOOP UNTIL i=0
tree.itemindex=i
END SUB
SUB trpagedown
i=tree.itemindex
IF i=tree.itemcount-1 THEN EXIT SUB
DO
i++
IF tree.item(i).isvisible THEN GOTO nextvisiblenode
LOOP UNTIL i=tree.itemcount-1
EXIT SUB
nextvisiblenode:
tree.itemindex=i
END SUB
SUB togglecollapse
i=tree.itemindex
IF (i<0)OR(i>tree.itemcount-2) THEN EXIT SUB
state=tree.item(i+1).isvisible*tree.item(i).haschildren
IF state=0 THEN
tree.expand(i,0)
ELSE
tree.collapse(i,0)
END IF
END SUB
SUB trkeydown(key AS WORD, shift AS INTEGER)
SELECT CASE key
CASE 33 : trpageup
CASE 34 : trpagedown
CASE 13 : IF getfocus=tree.handle THEN togglecollapse
END SELECT
END SUB
SUB trprint
DIM s AS STRING, mydate AS STRING
CREATE trprintfont AS QFONT
name=appfontname
size=10
END CREATE
CREATE trprintfontbold AS QFONT
name=appfontname
size=10
addstyles(fsbold)
END CREATE
DEFINT printitem=tree.itemindex
DEFINT printitemlevel=tree.item(printitem).level
printer.orientation=0
s=tree.item(printitem).text
$IFDEF FRANCAIS
mydate=MID$(DATE$,4,2)+"."+LEFT$(DATE$,2)+"."+MID$(DATE$,7,4)
$ELSE
mydate=DATE$
$ENDIF
s=s+STRING$(20," ")+mydate
printer.font=trprintfontbold
LPRINT:LPRINT
LPRINT s
LPRINT STRING$(LEN(s),"_")
printer.font=trprintfont
LPRINT
LPRINT texttree.item(printitem).text
IF printitem=tree.itemcount-1 THEN GOTO endtrprint
FOR i=printitem+1 TO tree.itemcount-1
IF tree.item(i).level<=printitemlevel THEN GOTO endtrprint
LPRINT : LPRINT
s=tree.item(i).text
printer.font=trprintfontbold
LPRINT s
LPRINT STRING$(LEN(s),"_")
printer.font=trprintfont
LPRINT : LPRINT
LPRINT texttree.item(i).text
NEXT
endtrprint:
LFLUSH
END SUB
DIM findnote AS INTEGER, findpos AS INTEGER
SUB trdofind
DIM i AS INTEGER, s AS STRING, p AS INTEGER
s=findtext.text
IF s="" THEN EXIT SUB
findnote=tree.itemindex
p=INSTR(findpos,LCASE$(trtext.text),LCASE$(s))
IF p>0 THEN
trtext.selstart=p-1
findpos=p
trtext.sellength=LEN(s)
setfocus(trtext.handle)
EXIT SUB
END IF
FOR i=findnote+1 TO tree.itemcount-1
p=INSTR(LCASE$(texttree.item(i).text),LCASE$(s))
IF p>0 THEN
tree.itemindex=i
trtext.selstart=p-1
trtext.sellength=LEN(s)
findnote=i
findpos=p
setfocus(trtext.handle)
EXIT SUB
END IF
NEXT
FOR i=0 TO findnote
p=INSTR(LCASE$(texttree.item(i).text),LCASE$(s))
IF p>0 THEN
tree.itemindex=i
trtext.selstart=p-1
trtext.sellength=LEN(s)
findnote=i
findpos=p
setfocus(trtext.handle)
EXIT SUB
END IF
NEXT
END SUB
SUB trmenufind
findpos=trtext.selstart+1
trdofind
END SUB
SUB trfindnext
findpos=trtext.selstart+2
trdofind
END SUB
|
|