| 1 | -- Hyperlink Behavior for custom hyperlink colors in #text members |
|---|
| 2 | -- ©03 alex da franca -- alex@farbflash.de |
|---|
| 3 | |
|---|
| 4 | property pSprite |
|---|
| 5 | property pLastHL, pLastPress |
|---|
| 6 | property pHLColorNormal, pHLColorVisited, pHLColorOver, pHLStyle, pHLCursor, pHLColorActive |
|---|
| 7 | |
|---|
| 8 | property pXtras |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | -- PUBLIC |
|---|
| 12 | -- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
|---|
| 13 | -- Example: |
|---|
| 14 | |
|---|
| 15 | -- paramlist = [:] |
|---|
| 16 | -- paramlist.setaprop(#link, rgb(0,0,150)) |
|---|
| 17 | -- paramlist.setaprop(#hover, rgb(0,0,200)) |
|---|
| 18 | -- paramlist.setaprop(#active, rgb(200,0,0)) |
|---|
| 19 | -- paramlist.setaprop(#visited, rgb(200,0,100)) |
|---|
| 20 | -- paramlist.setaprop(#fontstsyle, [#underline]) |
|---|
| 21 | -- paramlist.setaprop(#cursor, 280) |
|---|
| 22 | |
|---|
| 23 | -- sendSprite(x, #mSetHyperLinkStyles, paramlist) |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | on mSetHyperLinkStyles me, paramList |
|---|
| 27 | |
|---|
| 28 | if ilk(paramList) <> #proplist then exit |
|---|
| 29 | |
|---|
| 30 | val = paramList.getaprop(#link) |
|---|
| 31 | if ilk(val) = #color then pHLColorNormal = val |
|---|
| 32 | |
|---|
| 33 | val = paramList.getaprop(#hover) |
|---|
| 34 | if ilk(val) = #color then pHLColorOver = val |
|---|
| 35 | |
|---|
| 36 | val = paramList.getaprop(#active) |
|---|
| 37 | if ilk(val) = #color then pHLColorActive = val |
|---|
| 38 | |
|---|
| 39 | val = paramList.getaprop(#visited) |
|---|
| 40 | if ilk(val) = #color then pHLColorVisited = val |
|---|
| 41 | |
|---|
| 42 | val = paramList.getaprop(#fontstsyle) |
|---|
| 43 | if ilk(val) = #list then pHLStyle = val |
|---|
| 44 | |
|---|
| 45 | val = paramList.getaprop(#cursor) |
|---|
| 46 | if ilk(val) = #integer then pHLCursor = val |
|---|
| 47 | |
|---|
| 48 | mInitLinkStyles me, pHLColorNormal, pHLColorVisited, pHLStyle |
|---|
| 49 | |
|---|
| 50 | end |
|---|
| 51 | |
|---|
| 52 | |
|---|
| 53 | -- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
|---|
| 54 | |
|---|
| 55 | -- Example: |
|---|
| 56 | |
|---|
| 57 | -- sendSprite(x, #mClearHyperlinkState) |
|---|
| 58 | |
|---|
| 59 | on mClearHyperlinkState me |
|---|
| 60 | |
|---|
| 61 | textmember = pSprite.member |
|---|
| 62 | if textmember.type <> #text then exit |
|---|
| 63 | |
|---|
| 64 | hl = textmember.hyperlinks |
|---|
| 65 | repeat with thisHL in hl |
|---|
| 66 | chunkRef = textmember.char[thisHL[1] .. thisHL[2]].ref |
|---|
| 67 | chunkRef.hyperlinkstate = #normal |
|---|
| 68 | chunkRef.color = pHLColorNormal |
|---|
| 69 | end repeat |
|---|
| 70 | |
|---|
| 71 | end |
|---|
| 72 | |
|---|
| 73 | |
|---|
| 74 | -- CALLBACK |
|---|
| 75 | -- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
|---|
| 76 | |
|---|
| 77 | on mHyperLinkClicked me, data, range, linktext |
|---|
| 78 | -- put data |
|---|
| 79 | -- put linktext |
|---|
| 80 | |
|---|
| 81 | if mCheckForXtra(me, "BudAPI") then |
|---|
| 82 | -- give BudAPI precedence before gotonetpage |
|---|
| 83 | theMail = baOpenURL(data, "normal") |
|---|
| 84 | else |
|---|
| 85 | gotonetpage(data, "_blank") |
|---|
| 86 | end if |
|---|
| 87 | |
|---|
| 88 | end |
|---|
| 89 | |
|---|
| 90 | |
|---|
| 91 | -- STANDARD |
|---|
| 92 | -- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
|---|
| 93 | |
|---|
| 94 | on beginsprite me |
|---|
| 95 | pSprite = sprite(me.spritenum) |
|---|
| 96 | mInitLinkStyles me, pHLColorNormal, pHLColorVisited, pHLStyle |
|---|
| 97 | end |
|---|
| 98 | |
|---|
| 99 | |
|---|
| 100 | -- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
|---|
| 101 | |
|---|
| 102 | on getPropertyDescriptionList |
|---|
| 103 | retliste = [:] |
|---|
| 104 | retliste[#pHLColorNormal] = [#format:#color, #default:rgb(0,0,150), comment:"Hyperlink color:"] |
|---|
| 105 | retliste[#pHLColorVisited] = [#format:#color, #default:rgb(100,0,100), comment:"Visited Hyperlink color:"] |
|---|
| 106 | retliste[#pHLColorOver] = [#format:#color, #default:rgb(0,0,255), comment:"Hyperlink rollover color:"] |
|---|
| 107 | retliste[#pHLColorActive] = [#format:#color, #default:rgb(200,0,0), comment:"Hyperlink active color:"] |
|---|
| 108 | retliste[#pHLStyle] = [#format:#list, #default:[#underline], comment:"Hyperlink fontstyle:"] |
|---|
| 109 | retliste[#pHLCursor] = [#format:#integer, #default:280, comment:"Hyperlink cursor:"] |
|---|
| 110 | return retliste |
|---|
| 111 | end |
|---|
| 112 | |
|---|
| 113 | -- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
|---|
| 114 | |
|---|
| 115 | on mousewithin me |
|---|
| 116 | if pSprite.pointinhyperlink(the mouseloc) then |
|---|
| 117 | hlrange = pSprite.pointToChar(the mouseloc) |
|---|
| 118 | if hlrange > 0 then hlrange = pSprite.member.char[hlrange].hyperlinkrange |
|---|
| 119 | if hlrange <> pLastHL then |
|---|
| 120 | if listP(pLastHL) then |
|---|
| 121 | chunkRef = pSprite.member.char[pLastHL[1] .. pLastHL[2]].ref |
|---|
| 122 | if chunkRef.hyperlinkstate = #visited then chunkRef.color = pHLColorVisited |
|---|
| 123 | else chunkRef.color = pHLColorNormal |
|---|
| 124 | end if |
|---|
| 125 | pLastHL = hlrange |
|---|
| 126 | if listP(hlrange) then |
|---|
| 127 | pSprite.member.char[hlrange[1] .. hlrange[2]].color = pHLColorOver |
|---|
| 128 | cursor pHLCursor |
|---|
| 129 | end if |
|---|
| 130 | end if |
|---|
| 131 | |
|---|
| 132 | else |
|---|
| 133 | if listP(pLastHL) then |
|---|
| 134 | chunkRef = pSprite.member.char[pLastHL[1] .. pLastHL[2]].ref |
|---|
| 135 | if chunkRef.hyperlinkstate = #visited then chunkRef.color = pHLColorVisited |
|---|
| 136 | else chunkRef.color = pHLColorNormal |
|---|
| 137 | pLastHL = 0 |
|---|
| 138 | cursor 0 |
|---|
| 139 | end if |
|---|
| 140 | end if |
|---|
| 141 | end |
|---|
| 142 | |
|---|
| 143 | -- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
|---|
| 144 | |
|---|
| 145 | on mouseLeave me |
|---|
| 146 | if listP(pLastHL) then |
|---|
| 147 | chunkRef = pSprite.member.char[pLastHL[1] .. pLastHL[2]].ref |
|---|
| 148 | if chunkRef.hyperlinkstate = #visited then chunkRef.color = pHLColorVisited |
|---|
| 149 | else chunkRef.color = pHLColorNormal |
|---|
| 150 | pLastHL = 0 |
|---|
| 151 | cursor 0 |
|---|
| 152 | end if |
|---|
| 153 | end |
|---|
| 154 | |
|---|
| 155 | -- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
|---|
| 156 | |
|---|
| 157 | on mouseDown me |
|---|
| 158 | if pSprite.pointinhyperlink(the clickloc) then |
|---|
| 159 | hlrange = pSprite.pointToChar(the clickloc) |
|---|
| 160 | hlrange = pSprite.member.char[hlrange].hyperlinkrange |
|---|
| 161 | pLastPress = hlrange |
|---|
| 162 | pSprite.member.char[hlrange[1] .. hlrange[2]].color = pHLColorActive |
|---|
| 163 | end if |
|---|
| 164 | end |
|---|
| 165 | |
|---|
| 166 | -- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
|---|
| 167 | |
|---|
| 168 | on mouseUp me |
|---|
| 169 | if listP(pLastPress) then |
|---|
| 170 | hlrange = pSprite.pointToChar(the mouseloc) |
|---|
| 171 | hlrange = pSprite.member.char[hlrange].hyperlinkrange |
|---|
| 172 | |
|---|
| 173 | chunkRef = pSprite.member.char[pLastPress[1] .. pLastPress[2]].ref |
|---|
| 174 | if hlrange = pLastPress then |
|---|
| 175 | chunkRef.color = pHLColorVisited |
|---|
| 176 | chunkRef.hyperlinkstate = #visited |
|---|
| 177 | mHyperLinkClicked me, chunkRef.hyperlink, pLastPress, chunkRef.text |
|---|
| 178 | else |
|---|
| 179 | if chunkRef.hyperlinkstate = #visited then chunkRef.color = pHLColorVisited |
|---|
| 180 | else chunkRef.color = pHLColorNormal |
|---|
| 181 | end if |
|---|
| 182 | pLastPress = 0 |
|---|
| 183 | end if |
|---|
| 184 | end |
|---|
| 185 | |
|---|
| 186 | -- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
|---|
| 187 | |
|---|
| 188 | on mouseUpOutside me |
|---|
| 189 | if listP(pLastPress) then |
|---|
| 190 | chunkRef = pSprite.member.char[pLastPress[1] .. pLastPress[2]].ref |
|---|
| 191 | if chunkRef.hyperlinkstate = #visited then chunkRef.color = pHLColorVisited |
|---|
| 192 | else chunkRef.color = pHLColorNormal |
|---|
| 193 | pLastPress = 0 |
|---|
| 194 | cursor 0 |
|---|
| 195 | end if |
|---|
| 196 | end |
|---|
| 197 | |
|---|
| 198 | |
|---|
| 199 | -- PRIVATE: |
|---|
| 200 | -- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
|---|
| 201 | |
|---|
| 202 | on mInitLinkStyles me, colorNormal, colorVisited, theFontstyle |
|---|
| 203 | |
|---|
| 204 | textmember = pSprite.member |
|---|
| 205 | if textmember.type <> #text then exit |
|---|
| 206 | |
|---|
| 207 | -- funny bug. we must set it twice: |
|---|
| 208 | textmember.usehypertextstyles = 1 |
|---|
| 209 | textmember.usehypertextstyles = 0 |
|---|
| 210 | |
|---|
| 211 | hl = textmember.hyperlinks |
|---|
| 212 | repeat with thisHL in hl |
|---|
| 213 | chunkRef = textmember.char[thisHL[1] .. thisHL[2]].ref |
|---|
| 214 | if chunkRef.hyperlinkstate = #visited then chunkRef.color = colorVisited |
|---|
| 215 | else chunkRef.color = colorNormal |
|---|
| 216 | chunkRef.fontstyle = theFontstyle |
|---|
| 217 | end repeat |
|---|
| 218 | |
|---|
| 219 | end |
|---|
| 220 | |
|---|
| 221 | -- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
|---|
| 222 | |
|---|
| 223 | on mCheckForXtra me, whichXtra |
|---|
| 224 | if ilk(pXtras) <> #proplist then pXtras = [:] |
|---|
| 225 | xtraPresent = pXtras.getaprop(whichXtra) |
|---|
| 226 | if voidP(xtraPresent) then |
|---|
| 227 | xtraPresent = 0 |
|---|
| 228 | numX = the number of xtras |
|---|
| 229 | repeat with n = 1 to numX |
|---|
| 230 | if (the name of xtra n = whichXtra) then |
|---|
| 231 | xtraPresent = 1 |
|---|
| 232 | exit repeat |
|---|
| 233 | end if |
|---|
| 234 | end repeat |
|---|
| 235 | pXtras.setaprop(whichXtra, xtraPresent) |
|---|
| 236 | end if |
|---|
| 237 | return xtraPresent |
|---|
| 238 | end |
|---|