Re: Where do I call setHint for statusbar?

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

Andrew Katz wrote:
> The message is showing ok, but not the tooltip.

I have a solution but its not a trival fix. The diff-text is below. I've not
tested it in all situations but it seems to be holding up.

** in createEx()
> replace ...
            if sequence(sbPanels) then
                call_proc(r_setSubFields,{id, sbPanels})
            end if
> with ...
            if sequence(sbPanels) then
                call_proc(r_setSubFields,{id, sbPanels})
                call_proc(r_setHintEx, { {id, 0}, pCaption, 0})
            end if

** in setText()
> replace ...
    if atom(pID) then
        id = pID
        lPart = 1
    else
> with ...
    if atom(pID) then
        id = pID
        lPart = 0
    else

> replace ...
    if ctrl_Type[ id ] = StatusBar then

        -- send the text to the statusbar
        VOID = sendMessage( id, SB_SETTEXT,    lPart-1, s)
        VOID = sendMessage( id, SB_SETTIPTEXT, lPart-1, s)
> with ...
    if ctrl_Type[ id ] = StatusBar then

        -- send the text to the statusbar
        VOID = sendMessage( id, SB_SETTEXT,    lPart-1, s)
        call_proc(r_setHintEx, { {id, lPart-1}, s, 0})

** replace all of fDoTTN_GETDISPINFO()
> with ...
-- start tone skoda: support for longer than 80-char long tooltips
atom TTTextPtr
TTTextPtr = 0
-- end tone skoda

----------------------------------------------------
function fDoTTN_GETDISPINFO(integer id, atom hWnd, atom wParam, atom lParam)
----------------------------------------------------
    sequence lText
    atom hFrom
    atom hFromId
    atom lTextLen
    atom lUflags

    -- start tone skoda: autowidth of tooltip
    sequence lineText
    integer largestWid, lineWid
    sequence screenSize
    -- end tone skoda

    id = getId( wParam )
    if id = 0 then
        hFrom = w32fetch(lParam, NMHDR_hwndFrom )
        hFromId = w32fetch(lParam, NMHDR_idFrom )
        lUflags = w32fetch(lParam, NMTTDISPINFO_uFlags )

        id = getId(hFrom)
        if id = 0 then
            if ctrl_Statusbar[ mainWindow ] != 0 then
                id = ctrl_Statusbar[ mainWindow ]
            end if
        end if
    end if

    if id > 0 and id <= length(ctrl_Hint_Text) then
        if atom(ctrl_Hint_Text[id]) then
            if integer(ctrl_Hint_Text[id]) and ctrl_Hint_Text[id] >= 0 then
                -- The user routine returns either a string or a sequence in
                -- the form of { string, width }, eg. {"Sample text", 120}
                lText = call_func(ctrl_Hint_Text[id], {id,
                                ctrl_Hint_Width[id]})
                if length(lText) = 2 and sequence(lText[1]) and
                              integer(lText[2]) then
                    ctrl_Hint_Width[id] = lText[2]
                    lTextLen = lText[2]
                    lText = lText[1]
                elsif length(lText) = 0 then
                    lTextLen = 0
                else
                    lTextLen = ctrl_Hint_Width[id]
                end if
            else
                lText = sprintf("Invalid routine_id %g", ctrl_Hint_Text[id])
                lTextLen = ctrl_Hint_Width[id]
            end if
        else
            if id = ctrl_Statusbar[ mainWindow ] then
                if length(ctrl_Hint_Text[id]) > 0 and
                   sequence(ctrl_Hint_Text[id][1]) then
                    if length(ctrl_Hint_Text[id][1]) > hFromId then
                        lText = ctrl_Hint_Text[id][1][hFromId+1]
                    else
                        lText = ""
                    end if
                else
                    lText = ctrl_Hint_Text[id]
                end if
            else
                lText = ctrl_Hint_Text[id]
            end if
            lTextLen = ctrl_Hint_Width[id]
       end if

        w32store( lParam, NMTTDISPINFO_szText, lText )

        -- start tone skoda: support for longer than 80-char long tooltips
        if length (lText) > 80 then
            if TTTextPtr != 0 then
                w32release_mem (TTTextPtr)
            end if
            TTTextPtr = w32acquire_mem (0, lText)
            w32store( lParam, NMTTDISPINFO_lpszText, TTTextPtr )
        end if
        -- end tone skoda

        -- start tone skoda: autowidth of tooltip

        -- 1.get largestWid
        lineText = ""
        largestWid = 0
        for i = 1 to length (lText) do
            if lText [i] = '\n' or i = length (lText) then
                if i = length (lText) then
                    lineText &= lText [i]
                end if
                if not tooltipControl then
                    tooltipControl = createEx( ToolTip, "", 
                                        0, 0, 0, 0, 0, 0, 0)
                end if
                lineWid = getTextWidth (tooltipControl, lineText)
                if lineWid > largestWid then
                    largestWid = lineWid
                end if
                lineText = ""
            else
                lineText &= lText [i]
            end if
        end for

        -- 2. get lTextLen, if larger than screen then adjust to screen
        lTextLen = largestWid
        screenSize = getCtlSize( Screen )
        if lTextLen > screenSize [1] then
            lTextLen = screenSize [1]
        end if
        -- end tone skoda

        VOID = w32Func(xSendMessage,{w32fetch(lParam, NMHDR_hwndFrom ),
                          TTM_SETMAXTIPWIDTH, 0,
                          lTextLen})

    end if

   return {kMainMsg}
end function

** in setHintEx() 
> replace ...
            VOID = sendMessage(id, SB_SETTIPTEXT, lPart, text)
> with ...
            VOID = sendMessage(id, SB_SETTIPTEXT, lPart, text)
            if not tooltipControl then
                tooltipControl = createEx( ToolTip, "", 0, 0, 0, 0, 0, 0, 0)
            end if
            if lPart >= 0 then
                lPart += 1
                if length(ctrl_Hint_Text[id]) = 0 then
                    ctrl_Hint_Text[id] = {{}}
                end if
                if length(ctrl_Hint_Text[id][1]) < lPart then
                    ctrl_Hint_Text[id][1] = append(ctrl_Hint_Text[id][1],
                         repeat("", 1 + lPart - length(ctrl_Hint_Text[id])))
                end if
                ctrl_Hint_Text[id][1][lPart] = text
            else                  
                ctrl_Hint_Text[id] = text
            end if
----------------

Okay so try this out and let me know if it works for you. Then I can add it to
the 'official' code base.
-- 
Derek Parnell
Melbourne, Australia
Skype name: derek.j.parnell

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

Search



Quick Links

User menu

Not signed in.

Misc Menu