Phix / PGUI simple_notepad demo problems

new topic     » topic index » view thread      » older message » newer message

Hi Pete

While rummaging about through Phix/PGUI I noted that the "simple_notepad.exw" demo has a small problem. Specifically, the 'Find' feature doesn't work (there IS a note in the source saying "not yet very well tested" smile

The cause of the 3 problems I noted are...

1. The original C version of this had a 'str_find' function that did things a strange (IMO) way. What it returned on a find is the offset from the position it started the search, so it was necessary to add the start offset to the returned position to actually find the searched string. This isn't necessary using 'match' because it (sensibly) returns the position from the start of the string.

2. C starts everything from 0 whereas Phix/Eu starts from 1.

3. The C function used 'casesensitive' == 0 to mean NOT sensitive whereas 'match' uses 'caseinsensitive' == 0 to mean sensitive.

My modified version of the callback function below shows code commented out and followed by my replacement. Not really very important stuff bit I hope it helps.

les

function find_next_action_cb(Ihandle /*ih*/) 
/* this callback can be called from the main dialog also */ 
    if find_dlg!=NULL then 
        string str; 
        integer pos; 
        integer find_pos = IupGetInt(multitext, "FIND_POS"); 
 
        string str_to_find = IupGetAttribute(find_txt, "VALUE"); 
 
-- LES 
--        integer casesensitive = IupGetInt(find_case, "VALUE"); 
        integer casesensitive = IupGetInt(find_case, "VALUE") xor 1; 
 
        /* test again, because it can be called from the hot key */ 
        if length(str_to_find)=0 then 
            return IUP_DEFAULT; 
        end if 
 
        if find_pos<=0 then 
            find_pos = 1 
        end if 
        str = IupGetAttribute(multitext, "VALUE"); 
 
        pos = match(str_to_find, str, find_pos, casesensitive) 
-- LES 
--        if pos>=0 then 
--            pos += find_pos; 
--        elsif find_pos>0 then 
--            pos = match(str_to_find, str, 1, casesensitive) /* try again from the start */ 
--        end if 
        if pos<=0 and find_pos>0 then 
            pos = match(str_to_find, str, 1, casesensitive) /* try again from the start */ 
        end if 
 
        if pos>0 then 
            integer line, col, 
            end_pos = pos+length(str_to_find); 
 
            IupSetInt(multitext, "FIND_POS", end_pos); 
 
            IupSetFocus(multitext); 
-- LES 
--            IupSetAttributes(multitext, "SELECTIONPOS=%d:%d", {pos, end_pos}); 
--            IupSetAttributes(multitext, "FIND_SELECTION=%d:%d", {pos, end_pos}); 
            IupSetAttributes(multitext, "SELECTIONPOS=%d:%d", {pos-1, end_pos-1}); 
            IupSetAttributes(multitext, "FIND_SELECTION=%d:%d", {pos-1, end_pos-1}); 
 
            {line,col} = IupTextConvertPosToLinCol(multitext, pos); 
            pos = IupTextConvertLinColToPos(multitext, line, 0);  /* position at col=0, just scroll lines */ 
            IupSetInt(multitext, "SCROLLTOPOS", pos); 
        else 
            IupSetInt(multitext, "FIND_POS", -1); 
            IupMessage("Warning", "Text not found."); 
        end if 
    end if 
 
    return IUP_DEFAULT; 
end function 
new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu