1. MleText window does not show text
- Posted by sergelli Nov 10, 2012
- 1532 views
- Last edited Nov 11, 2012
This program selects and displays sequences if containing a typed text.
For example: When I type the letter "S" should show all rows that have that character in anywhere.
If I type another letter, this letter joins with the first and the program is looking for new selection lines containing the two letters together.
Please, use "e" as the second letter. The MleText window is hidden if the two letters make a sequel nonexistent.
I use a window MleText, for displaying the selected sequences.
And hide this window when not in use.
But a problem is happening, the result is only shown after entering the second letter onwards.
The problem becomes more evident if uncomment the line with the instruction "sleep ()"
The code follows below,
Any response is welcome
Thanks in advance
-- 11/11/12 sintaxColor.exw -- separa e coloriza trecho digitado em lista de opções include WIN32lib.ew constant version="1.1" -- ,FONTWH={12,12} ,WIN1 =create(Window,"Pedido - "&version,0,00,00,900,720,0) -- col,lin ,NOMBOX=create(MleText ,"",WIN1,240,03,420,30, -- cx entrada nome cliente { WS_CLIPPINGCHILD, WS_VISIBLE,WS_TABSTOP, ES_SAVESEL ,WS_BORDER } ) ,FINDNOM=create(MleText ,"",WIN1,220,55,626,240, -- *8 Para font default { WS_CLIPPINGCHILD, WS_VISIBLE,WS_TABSTOP, ES_SAVESEL ,WS_BORDER } ) ,FONE =create(MleText ,"",WIN1,680,03,160,30, -- cx entrada nome cliente { WS_CLIPPINGCHILD, WS_VISIBLE,WS_TABSTOP, ES_SAVESEL ,WS_BORDER } ) ----------------------------------------------------------------------------------- setWindowBackColor( WIN1,{200,255,230}) setFont({FINDNOM,FONE,NOMBOX},"Courier New", 12, Bold ) -- setVisible(FINDNOM,0) setFocus(NOMBOX) ----------------------------------------------------------------------------------- atom Li1,Choice Li1=1 Choice=2 sequence LisCli,Linhas,PARMS LisCli={"0001|sem cadastro |11 97222-6461" ,"0002|Dudu e Isa |11 91234-1234" ,"0003|Jerry |12 91234-1234" ,"0004|Alcindo e Silvana |12 91234-1234" ,"0005|Sergio Gelli |11 97222-6461" ,"0006|Jose Inacio |11 91234-1234"} -- ------------------------------------------teste linha formatada ------------------------ cor text, cor fundo, zero inutil, mas nao da erro -- block={ { { "aaaaaaa" }, {BrightWhite},{Blue},{0} } -- linha 1 c/1 palavra -- , { { "aaaaaaa" }, {Blue},{BrightWhite} } -- linha 1 c/1 palavra ----------------------- text1 text2 fund 1 fund2 -- , { { "AAAAAAA","bbBB" }, {Blue,BrightWhite},{BrightWhite ,Red } } -- linha 2 c/2 palavras ----------------------- text1 text2 text3 fund 1 fund2 fund3 -- , { { "AAAAAAA","bbBB","ccCC" }, {Blue,BrightWhite,0},{BrightWhite,0,Red } } -- linha 2 c/3 palavras -- } -- ------------------------------------------fim teste ---------------------------------------------------------------------------------------------------------- procedure printText(integer id,sequence block,integer colunaX, integer linhaY ) integer colTempX, fontwidth, fontheight atom hdc, result, pstr sequence BBox, comboline, textline, text, colourline, backcolour, data -- early out? if length( block ) = 0 then -- block=bloco usando o texto formatado c/TextToAnalysedLine(junk) return end if -- data = getFontSize(id) -- -- if length(data)=0 then data={10,10} end if data={10,18} fontwidth = data[1] fontheight = data[2] hdc = getDC( id ) -- ORIGINAL get the device context -- hdc = getDC( WIN2 ) -- ORIGINAL get the device context result= assignFont( {id,hdc}) -- Gets the device context for id with the current font installed. -- result= assignFont( {WIN2,hdc}) -- Gets the device context for id with the current font installed. ------------------- ------------------- -- display the text ------------------- ------------------- for i = 1 to length(block) do comboline = block[i] -- extract data for the current line textline = comboline[1] -- extract text for the current line colourline = comboline[2] -- extract color text for the current line backcolour = comboline[3] -- extract backGround for the current line colTempX = colunaX for j = 1 to length(textline) do text = textline[j] -- set the Pen Position BBox = convPctToPixel(id, colTempX,linhaY, 0, 0) result = w32Func( xSetTextColor, {hdc, colourline[j] } ) result = w32Func( xSetBkColor, {hdc, backcolour[j] } ) result = w32Func( xSetBkMode, {hdc, OPAQUE } ) -- copy string to memory pstr = w32acquire_mem(0,text ) -- write out string to window/device w32Proc( xTextOut, { hdc, BBox[1], BBox[2], pstr, length( text ) } ) -- advance column pointer to next start pos colTempX += length(text) * fontwidth -- Free the string w32release_mem(pstr) end for -- advance row to next position linhaY += fontheight end for -- replace the font with the default again replaceObject( id, kFontObject, hdc,-1,ForProgram) -- -1 = DefaultFontID -- release the device context -- copyBlt(id, 250, 250, id) releaseDC( id ) end procedure ------------------------------------------------------------------------------------------------------- procedure fazLinha(sequence preDigi,sequence digi2,sequence posDigi,sequence data4) sequence spc spc={} while length(spc&preDigi&digi2&posDigi&data4)<60 do spc&=" " -- p/completar nome c/espaços end while --Linhas={ { { "aaaaaaa" }, {12345679},{987654321} } -- linha 1 c/1 palavra -- -- -- -- -- -- cores texto cores fundo -- , { { "AAAAAAA","bbBB","ccCC" }, { 65200,12582911,0},{0,65200,12582911 } } -- linha 2 c/3 palavras if Li1=Choice then Linhas=append (Linhas,{ {preDigi,digi2,posDigi,spc&data4},{Yellow,Red,Yellow,Yellow},{Red,Yellow,Red,Red} } ) else Linhas=append (Linhas,{ {preDigi,digi2,posDigi,spc&data4},{65200,Blue,65200,65200},{Blue,65200,Blue,Blue} } ) end if Li1+=1 end procedure -- setVisible(FINDNOM,1) -- abre janela FINDNOM -------------------------------------------------------------------------------------------------------------- procedure afterKeyUp(integer id, integer event, sequence parms) atom zzz sequence text1 zzz=0 if id!=NOMBOX then return end if if not match(sprintf("%s",{parms[1]}),"1234567890_- +/\\&@#%*()ABCDEFGHIJKLMNOPQRSTUVXYZ_abcdefghijklmnopqrstuvxyz") then if parms[1]=8 then -- do nothing else return -- printable key em NOMBOX end if end if text1=getText(NOMBOX) if length(text1)=0 then return end if Linhas={} Li1=1 for i=1 to length(LisCli) do event=match(upper(text1),upper(LisCli[i])) -- event>0 = encontrou nome com texto digitado if event>0 then -- encontrou texto digitado zzz=1 parms=w32trim( LisCli[i]) -- linha que contém o texto fazLinha(parms[1..event-1] -- antes do digitado ,text1 -- texto digitado ,parms[event+length(text1)..length(parms)] -- depois do digitado ,"" ) -- telefone end if end for if zzz=0 then setVisible(FINDNOM,0) else printText(FINDNOM,Linhas,03, 03) -- procedure em resources.ew copyBlt(FINDNOM, 1,1, FINDNOM) if getIndex(NOMBOX)=2 then end if end if end procedure ----------------------------------------------------------------------------------------------------------- procedure Nom() -- test setVisible(FINDNOM,1) -- abre janela FINDNOM end procedure ----------------------------------------------------------------------------------------------------------- procedure afterKEY(integer id, integer event, sequence parms) afterKeyUp( id, event,PARMS) -- sleep(1) -- to see the first time, first key end procedure ----------------------------------------------------------------------------------------------------------- procedure printableKeyNOM(integer id, integer event, sequence parms) -- setVisible(FINDNOM,1) -- abre janela FINDNOM -- Nom() -- test setVisible(FINDNOM,1) -- abre janela FINDNOM PARMS=parms end procedure ----------------------------------------------------------------------------------------------------------- setHandler({NOMBOX},w32HKeyPress ,routine_id("printableKeyNOM")) -- teclado numérico e Enter setHandler({NOMBOX},w32HChange ,routine_id("afterKEY")) -- teclado numérico e Enter WinMain(WIN1,Normal)
2. Re: MleText window does not show text
- Posted by petelomax Nov 11, 2012
- 1452 views
But a problem is happening, the result is only shown after entering the second letter onwards.
The problem becomes more evident if uncomment the line with the instruction "sleep ()"
The code follows below,
Any response is welcome
I would try adding an onpaint routine, and do all drawing from there.
3. Re: MleText window does not show text
- Posted by sergelli Nov 11, 2012
- 1451 views
I would try adding an onpaint routine, and do all drawing from there.
Thanks, Pete
I used w32HKeyUp and made some changes in procedure "afterKeyUp" and the program worked well.
But it seems that this code does not work, if I use w32HKeyPress and w32KeyDown, without making special code
Following, is the code that is now working. Perhaps it is useful for someone who wants to know about syntax coloring
-- 11/11/12 sintaxColor.exw -- separa e coloriza trecho digitado em lista de opções include WIN32lib.ew constant version="1.1" -- ,FONTWH={12,12} ,WIN1 =create(Window,"Pedido - "&version,0,00,00,900,720,0) -- col,lin ,NOMBOX=create(MleText ,"",WIN1,240,03,420,30, -- cx entrada nome cliente { WS_CLIPPINGCHILD, WS_VISIBLE,WS_TABSTOP, ES_SAVESEL ,WS_BORDER } ) ,FINDNOM=create(MleText ,"",WIN1,220,55,626,240, -- *8 Para font default { WS_CLIPPINGCHILD, WS_VISIBLE,WS_TABSTOP, ES_SAVESEL ,WS_BORDER } ) ,FONE =create(MleText ,"",WIN1,680,03,160,30, -- cx entrada nome cliente { WS_CLIPPINGCHILD, WS_VISIBLE,WS_TABSTOP, ES_SAVESEL ,WS_BORDER } ) ----------------------------------------------------------------------------------- setWindowBackColor( WIN1,{200,255,230}) setFont({FINDNOM,FONE,NOMBOX},"Courier New", 12, Bold ) -- setVisible(FINDNOM,0) setFocus(NOMBOX) ----------------------------------------------------------------------------------- atom Li1,Choice Li1=1 Choice=2 sequence LisCli,Linhas LisCli={"0001|sem cadastro |11 97222-6461" ,"0002|Dudu e Isa |11 91234-1234" ,"0003|Jerry |12 91234-1234" ,"0004|Alcindo e Silvana |12 91234-1234" ,"0005|Sergio Gelli |11 97222-6461" ,"0006|Jose Inacio |11 91234-1234"} -- ------------------------------------------teste linha formatada ------------------------ cor text, cor fundo, zero inutil, mas nao da erro -- block={ { { "aaaaaaa" }, {BrightWhite},{Blue},{0} } -- linha 1 c/1 palavra -- , { { "aaaaaaa" }, {Blue},{BrightWhite} } -- linha 1 c/1 palavra ----------------------- text1 text2 fund 1 fund2 -- , { { "AAAAAAA","bbBB" }, {Blue,BrightWhite},{BrightWhite ,Red } } -- linha 2 c/2 palavras ----------------------- text1 text2 text3 fund 1 fund2 fund3 -- , { { "AAAAAAA","bbBB","ccCC" }, {Blue,BrightWhite,0},{BrightWhite,0,Red } } -- linha 2 c/3 palavras -- } -- ------------------------------------------fim teste ---------------------------------------------------------------------------------------------------------- procedure printText(integer id,sequence block,integer colunaX, integer linhaY ) integer colTempX, fontwidth, fontheight atom hdc, result, pstr sequence BBox, comboline, textline, text, colourline, backcolour, data -- early out? if length( block ) = 0 then -- block=bloco usando o texto formatado c/TextToAnalysedLine(junk) return end if -- data = getFontSize(id) -- -- if length(data)=0 then data={10,10} end if data={10,18} fontwidth = data[1] fontheight = data[2] hdc = getDC( id ) -- ORIGINAL get the device context -- hdc = getDC( WIN2 ) -- ORIGINAL get the device context result= assignFont( {id,hdc}) -- Gets the device context for id with the current font installed. -- result= assignFont( {WIN2,hdc}) -- Gets the device context for id with the current font installed. ------------------- ------------------- -- display the text ------------------- ------------------- for i = 1 to length(block) do comboline = block[i] -- extract data for the current line textline = comboline[1] -- extract text for the current line colourline = comboline[2] -- extract color text for the current line backcolour = comboline[3] -- extract backGround for the current line colTempX = colunaX for j = 1 to length(textline) do text = textline[j] -- set the Pen Position BBox = convPctToPixel(id, colTempX,linhaY, 0, 0) result = w32Func( xSetTextColor, {hdc, colourline[j] } ) result = w32Func( xSetBkColor, {hdc, backcolour[j] } ) result = w32Func( xSetBkMode, {hdc, OPAQUE } ) -- copy string to memory pstr = w32acquire_mem(0,text ) -- write out string to window/device w32Proc( xTextOut, { hdc, BBox[1], BBox[2], pstr, length( text ) } ) -- advance column pointer to next start pos colTempX += length(text) * fontwidth -- Free the string w32release_mem(pstr) end for -- advance row to next position linhaY += fontheight end for -- replace the font with the default again replaceObject( id, kFontObject, hdc,-1,ForProgram) -- -1 = DefaultFontID -- release the device context -- copyBlt(id, 250, 250, id) releaseDC( id ) end procedure ------------------------------------------------------------------------------------------------------- procedure fazLinha(sequence preDigi,sequence digi2,sequence posDigi,sequence data4) sequence spc spc={} while length(spc&preDigi&digi2&posDigi&data4)<60 do spc&=" " -- p/completar nome c/espaços end while --Linhas={ { { "aaaaaaa" }, {12345679},{987654321} } -- linha 1 c/1 palavra -- -- -- -- -- -- cores texto cores fundo -- , { { "AAAAAAA","bbBB","ccCC" }, { 65200,12582911,0},{0,65200,12582911 } } -- linha 2 c/3 palavras if Li1=Choice then Linhas=append (Linhas,{ {preDigi,digi2,posDigi,spc&data4},{Yellow,Red,Yellow,Yellow},{Red,Yellow,Red,Red} } ) else Linhas=append (Linhas,{ {preDigi,digi2,posDigi,spc&data4},{65200,Blue,65200,65200},{Blue,65200,Blue,Blue} } ) end if Li1+=1 end procedure -------------------------------------------------------------------------------------------------------------- procedure afterKeyUp(integer id, integer event, sequence parms) atom zzz sequence text1 zzz=0 if id!=NOMBOX then return end if clearWindow (FINDNOM) if not match(sprintf("%s",{parms[1]}),"1234567890_- +/\\&@#%*()ABCDEFGHIJKLMNOPQRSTUVXYZ_abcdefghijklmnopqrstuvxyz") then if parms[1]=8 then -- do nothing else return -- printable key em NOMBOX end if end if text1=getText(NOMBOX) if length(text1)=0 then return end if setVisible(FINDNOM,1) repaintWindow( FINDNOM ) Linhas={} Li1=1 for i=1 to length(LisCli) do event=match(upper(text1),upper(LisCli[i])) -- event>0 = encontrou nome com texto digitado if event>0 then -- encontrou texto digitado zzz=1 parms=w32trim( LisCli[i]) -- linha que contém o texto fazLinha(parms[1..event-1] -- antes do digitado ,text1 -- texto digitado ,parms[event+length(text1)..length(parms)] -- depois do digitado ,"" ) -- telefone end if end for if zzz=0 then setVisible(FINDNOM,0) else printText(FINDNOM,Linhas,03, 03) -- procedure em resources.ew copyBlt(FINDNOM, 1,1, FINDNOM) end if end procedure ----------------------------------------------------------------------------------------------------------- setHandler( NOMBOX, w32HKeyUp,routine_id("afterKeyUp")) ----------------------------------------------------------------------------------------------------------- WinMain(WIN1,Normal)
4. Re: MleText window does not show text
- Posted by DerekParnell (admin) Nov 11, 2012
- 1428 views
I used w32HKeyUp and made some changes in procedure "afterKeyUp" and the program worked well.
But it seems that this code does not work, if I use w32HKeyPress and w32KeyDown, without making special code
Following, is the code that is now working. Perhaps it is useful for someone who wants to know about syntax coloring
I'll have a look at it later today but my first impression is that you've made it more complex than it needs to be.
5. Re: MleText window does not show text
- Posted by sergelli Nov 12, 2012
- 1440 views
I'll have a look at it later today but my first impression is that you've made it more complex than it needs to be.
Yes, you're right. This code is more complicated than necessary.
But what you do not know, is that this code is a summary of a larger program that performs many functions that are not present here.
I made this complicated example (but small), to maintain minimum characteristics that larger program.
For example, for every keystroke, I need to filter keys, key texts, navigation keys, etc. and then format the result to an appropriate output.
If you believe that there is something I do not know, please let me know
Thanks Derek
6. Re: MleText window does not show text
- Posted by DerekParnell (admin) Nov 24, 2012
- 1339 views
If you believe that there is something I do not know, please let me know
Here is a simpler technique that works quite well, I think.
-- 11/11/12 sintaxColor.exw -- separa e coloriza trecho digitado em lista de opções include WIN32lib.ew constant version="1.1" -- ,FONTWH={12,12} ,WIN1 =create(Window,"Pedido - "&version,0,00,00,900,720,0) -- col,lin ,NOMBOX=create(SleText ,"",WIN1,240,03,420,30, -- cx entrada nome cliente { WS_CLIPPINGCHILD, WS_VISIBLE,WS_TABSTOP, ES_SAVESEL ,WS_BORDER } ) ,FINDNOM=create(Window ,"",WIN1,220,55,626,240, -- *8 Para font default { WS_CLIPPINGCHILD, WS_VISIBLE,WS_TABSTOP, ES_SAVESEL ,WS_BORDER } ) ,FINDPMAP=create(Pixmap ,"",0,0,0,626,240, 0 ) -- Where text gets drawn to ,FONE =create(SleText ,"",WIN1,680,03,160,30, -- cx entrada nome cliente { WS_CLIPPINGCHILD, WS_VISIBLE,WS_TABSTOP, ES_SAVESEL ,WS_BORDER } ) ----------------------------------------------------------------------------------- setWindowBackColor( WIN1,{200,255,230}) setFont({FINDPMAP,FONE,NOMBOX},"Courier New", 12, Bold ) -- setVisible(FINDNOM,0) setFocus(NOMBOX) ----------------------------------------------------------------------------------- atom Li1,Choice Li1=1 Choice=2 sequence LisCli,Linhas,PARMS LisCli={"0001|sem cadastro |11 97222-6461" ,"0002|Dudu e Isa |11 91234-1234" ,"0003|Jerry |12 91234-1234" ,"0004|Alcindo e Silvana |12 91234-1234" ,"0005|Sergio Gelli |11 97222-6461" ,"0006|Jose Inacio |11 91234-1234"} ---------------------------------------------------------------------------------------------------------- procedure printText(integer id,sequence block,integer colunaX, integer linhaY ) -- Draw text to a pixmap, which is copied to the display window when needed. integer colTempX, fontwidth, fontheight sequence comboline, textline, text, colourline, backcolour, data -- early out? if length( block ) = 0 then -- block=bloco usando o texto formatado c/TextToAnalysedLine(junk) return end if data = getTextExtent(FINDPMAP, "W") fontwidth = data[1] fontheight = data[2] + 1 -- Add a one-pixel gap between lines. ------------------- ------------------- -- display the text ------------------- ------------------- setBackColor(FINDPMAP, Pink) -- Clears the text area setPenBkMode(FINDPMAP, OPAQUE) -- Ensure we see back ground text colors for i = 1 to length(block) do comboline = block[i] -- extract data for the current line textline = comboline[1] -- extract text for the current line colourline = comboline[2] -- extract color text for the current line backcolour = comboline[3] -- extract backGround for the current line colTempX = colunaX for j = 1 to length(textline) do text = textline[j] -- set the Pen Position setPenPos(FINDPMAP, colTempX,linhaY) setTextColor(FINDPMAP, colourline[j] ) setPenBkColor(FINDPMAP, backcolour[j] ) wPuts({FINDPMAP, colTempX, linhaY}, text) colTempX += length(text) * fontwidth end for -- advance row to next position linhaY += fontheight end for -- Force a repaint of the viewport repaintFG(id) end procedure ------------------------------------------------------------------------------------------------------- procedure fazLinha(sequence preDigi,sequence digi2,sequence posDigi,sequence data4) sequence text integer textlen sequence colors textlen = length(preDigi) + length(digi2) + length(posDigi) + length(data4) if textlen < 60 then textlen = 60 - textlen else textlen = 0 end if text = {preDigi, digi2, posDigi, repeat(' ', textlen) & data4} if Li1=Choice then colors = {{Yellow,Red,Yellow,Yellow},{Red,Yellow,Red,Red}} else colors = {{65200,Blue,65200,65200},{Blue,65200,Blue,Blue}} end if Linhas=append (Linhas,{ text, colors[1], colors[2] } ) Li1+=1 end procedure -------------------------------------------------------------------------------------------------------------- procedure afterKeyUp(integer id, integer event, sequence parms) atom zzz sequence text1 sequence CompText if id != NOMBOX then return end if zzz=0 text1 = getText(NOMBOX) if length(text1) = 0 then setVisible(FINDNOM,0) return end if clearWindow(FINDNOM) Linhas = {} Li1=1 for i=1 to length(LisCli) do CompText = w32trim(LisCli[i]) event = match(upper(text1),upper(CompText)) -- event>0 = encontrou nome com texto digitado if event > 0 then -- encontrou texto digitado zzz=1 fazLinha(CompText[1..event-1] -- antes do digitado ,CompText[event .. event+length(text1) - 1] -- texto digitado ,CompText[event+length(text1)..length(CompText)] -- depois do digitado ,"" ) -- telefone end if end for if zzz = 0 then setVisible(FINDNOM,0) else setVisible(FINDNOM,1) -- abre janela FINDNOM printText(FINDNOM,Linhas,03, 03) -- procedure em resources.ew end if end procedure ----------------------------------------------------------------------------------------------------------- procedure afterKEY(integer id, integer event, sequence parms) afterKeyUp( id, event, parms) --PARMS) end procedure ----------------------------------------------------------------------------------------------------------- setHandler({NOMBOX},w32HChange ,routine_id("afterKEY")) -- teclado numérico e Enter procedure onPaintView(integer id, integer event, sequence parms) copyBlt(id, 0, 0, FINDPMAP) end procedure ----------------------------------------------------------------------------------------------------------- setHandler(FINDNOM,w32HPaint ,routine_id("onPaintView")) -- teclado numérico e Enter WinMain(WIN1,Normal)