Saturday, April 21, 2012

Problems when highlighting text

I've been writing a mod to pull data out of wow onto notepad. To achieve this the mod puts all the data into an edit box from which you can cut and paste to wherever you want.

What I have at the moment is:

GetDataText:SetText(DataList);

GetDataText:SetFocus();

GetDataText:HighlightText();

GetDataDlg:Show();



The highlight seems to cause all the text to become selected because I can then Ctrl-C and then paste somewhere else and that all works fine. But the text is not shown as highlighted.

Even more weirdly if I run the app again the second time I show the EditBox the highlighting is shown. I've been put a ton of debug messages in and it seems to me that what I need to do is on my first pass through, after calling HighlightText() is get an OnCursorChanged event to be triggered for my edit box.

I've tried calling the function within the XML :

<OnCursorChanged>

ScrollingEdit_OnCursorChanged(arg1, arg2, arg3, arg4);

</OnCursorChanged>

and that does nothing. So my guess is that it's some default functionality which is part of all edit boxes.

Can I just send an event to my edit box? I cannot find any function that will do that for me.

Or does anyone know of another way round my problem.

I'll be grateful for any help people can offer|||Quote:








I've been writing a mod to pull data out of wow onto notepad. To achieve this the mod puts all the data into an edit box from which you can cut and paste to wherever you want.

What I have at the moment is:

GetDataText:SetText(DataList);

GetDataText:SetFocus();

GetDataText:HighlightText();

GetDataDlg:Show();



The highlight seems to cause all the text to become selected because I can then Ctrl-C and then paste somewhere else and that all works fine. But the text is not shown as highlighted.

Even more weirdly if I run the app again the second time I show the EditBox the highlighting is shown. I've been put a ton of debug messages in and it seems to me that what I need to do is on my first pass through, after calling HighlightText() is get an OnCursorChanged event to be triggered for my edit box.

I've tried calling the function within the XML :

<OnCursorChanged>

ScrollingEdit_OnCursorChanged(arg1, arg2, arg3, arg4);

</OnCursorChanged>

and that does nothing. So my guess is that it's some default functionality which is part of all edit boxes.

Can I just send an event to my edit box? I cannot find any function that will do that for me.

Or does anyone know of another way round my problem.

I'll be grateful for any help people can offer






Some random thoughts.... ;)

In other words, I'm not sure why your problem happens, but these are some things I'd be considering...

1.)

Have you tried the SetText and Highlight AFTER the :Show() ?

OR

You could try the SetText after the :Show(), and put the Highlight() in the EditBox's OnUpdate function.... ?

( This relates to the suggestion about the ScrollingEdit_OnUpdate function below... )

2.)

If your EditBox is part of a ScrollChild then I think you do need the XML you mentioned above, but you also need to call a default <OnTextChanged> function and OnUpdate function too ...although if you are only ever filling the edit box via code and the user isn't ever manually editing it then maybe its not important.


Code:


<OnTextChanged>
ScrollingEdit_OnTextChanged();
</OnTextChanged>
<OnCursorChanged>
ScrollingEdit_OnCursorChanged(arg1, arg2, arg3, arg4);
</OnCursorChanged>
<OnUpdate>
ScrollingEdit_OnUpdate();
</OnUpdate>

3.)

Have you set your EditBox to autofocus="true" ?

It might be worth a try....

4.)

Finally, its just a thought, but have you tried Hiding, and then Showing your EditBox again

to refresh it....based on your comment about the text being highlighted the next time you run it....although this is just me thinking about that autofocus feature again really...|||Thanks for all of those Telic. I've tried them all. No luck I'm afraid, but thanks for the suggestions.

I tried using ResetCursor() today that does send an OnCursorChanged event, but still no joy with the display so back to the drawing board. You may be right in that the ScrollChild could be responsible for updating the selected shading. So I'll try putting all my debug messages there, rather than the edit box, next time I get a chance to play :o)|||Prat displays URLs in a pop up box and the text is highlighted, you could check how it's done there.|||Can I see your entire frames xml?|||Quote:








Can I see your entire frames xml?




It still needs alot of work on the focusing and the like, but I'm hoping that isn't my problem. Anyway here it is:


Code:
<Ui xmlns="http://www.blizzard.com/wow/ui/" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.blizzard.com/wow/ui/..\FrameXML\UI.xsd">
<!-- Lua Scripts -->
<Script file="GetData.lua"/>

<!-- Frames -->
<Frame name="GetData_MainFrame">
<Scripts>
<OnLoad>
DEFAULT_CHAT_FRAME:AddMessage("Adding Slash XML",1,1,1);
GetData_OnLoad();
</OnLoad>
</Scripts>
</Frame>


<Frame name="GetDataDlg" toplevel="true" parent="UIparent" movable="false" resizable="false" enableMouse="true" hidden="true" enableKeyboard="true" frameStrata="DIALOG">
<Size>
<AbsDimension x="450" y="350"/>
</Size>
<Anchors>
<Anchor point="CENTER"/>
</Anchors>
<Backdrop bgFile="Interface\DialogFrame\UI-DialogBox-Background" edgeFile="Interface\DialogFrame\UI-DialogBox-Border" tile="true">
<BackgroundInsets>
<AbsInset left="11" right="12" top="12" bottom="11"/>
</BackgroundInsets>
<TileSize>
<AbsValue val="32"/>
</TileSize>
<EdgeSize>
<AbsValue val="32"/>
</EdgeSize>
</Backdrop>
<Frames>
<Button name="GetDataButtonClose" inherits="UIPanelButtonTemplate" text="Close">
<Size>
<AbsDimension x="75" y="20"/>
</Size>
<Anchors>
<Anchor point="BOTTOMRIGHT">
<Offset>
<AbsDimension x="-20" y="20"/>
</Offset>
</Anchor>
</Anchors>
<Scripts>
<OnClick>
GetDataDlg:Hide();
</OnClick>
</Scripts>
</Button>

<ScrollFrame name="GetDataScrollFrame" inherits="UIPanelScrollFrameTemplate">
<Size>
<AbsDimension x="390" y="255"/>
</Size>
<Anchors>
<Anchor point="TOPLEFT">
<Offset>
<AbsDimension x="18" y="-18"/>
</Offset>
</Anchor>
</Anchors>
<Layers>
<Layer level="ARTWORK">
<Texture name="GetDataScrollBarTop" file="Interface\PaperDollInfoFrame\UI-Character-ScrollBar">
<Size>
<AbsDimension x="31" y="156"/>
</Size>
<Anchors>
<Anchor point="TOPLEFT" relativePoint="TOPRIGHT">
<Offset>
<AbsDimension x="0" y="5"/>
</Offset>
</Anchor>
</Anchors>
<TexCoords left="0" right="0.484375" top="0" bottom="1.0"/>
</Texture>
<Texture name="GetDataScrollBarBottom" file="Interface\PaperDollInfoFrame\UI-Character-ScrollBar">
<Size>
<AbsDimension x="31" y="106"/>
</Size>
<Anchors>
<Anchor point="BOTTOMLEFT" relativePoint="BOTTOMRIGHT">
<Offset>
<AbsDimension x="0" y="-2"/>
</Offset>
</Anchor>
</Anchors>
<TexCoords left="0.515625" right="1.0" top="0" bottom="0.4140625"/>
</Texture>
<Texture name="GetDataScrollBarMiddle" file="Interface\PaperDollInfoFrame\UI-Character-ScrollBar">
<Size>
<AbsDimension x="31" y="60"/>
</Size>
<Anchors>
<Anchor point="TOP" relativeTo="GetDataScrollBarTop" relativePoint="BOTTOM">
<Offset>
<AbsDimension x="0" y="0"/>
</Offset>
</Anchor>
<Anchor point="BOTTOM" relativeTo="GetDataScrollBarBottom" relativePoint="TOP">
<Offset>
<AbsDimension x="0" y="0"/>
</Offset>
</Anchor>
</Anchors>
<TexCoords left="0" right="0.484375" top=".75" bottom="1.0"/>
</Texture>
</Layer>
</Layers>
<Scripts>
<OnTextChanged>
ScrollingEdit_OnTextChanged(GetDataScrollFrame);
</OnTextChanged>
<OnCursorChanged>
ScrollingEdit_OnCursorChanged(arg1, arg2, arg3, arg4);
</OnCursorChanged>
<OnUpdate>
ScrollingEdit_OnUpdate(GetDataScrollFrame);
</OnUpdate>
</Scripts>
<ScrollChild>
<EditBox name="GetDataText" autofocus="true" multiLine="true" letters="12000">
<Size>
<AbsDimension x="541" y="234"/>
</Size>
<Scripts>
<OnTextChanged>
ScrollingEdit_OnTextChanged(GetDataScrollFrame);
</OnTextChanged>
<OnCursorChanged>
ScrollingEdit_OnCursorChanged(arg1, arg2, arg3, arg4);
</OnCursorChanged>
<OnUpdate>
ScrollingEdit_OnUpdate(GetDataScrollFrame);
</OnUpdate>
</Scripts>
<FontString inherits="ChatFontNormal"/>
</EditBox>
<Scripts>
<OnTextChanged>
ScrollingEdit_OnTextChanged(GetDataScrollFrame);
</OnTextChanged>
<OnCursorChanged>
ScrollingEdit_OnCursorChanged(arg1, arg2, arg3, arg4);
</OnCursorChanged>
<OnUpdate>
ScrollingEdit_OnUpdate(GetDataScrollFrame);
</OnUpdate>
</Scripts>
</ScrollChild>
</ScrollFrame>

</Frames>
</Frame>


</Ui>
|||Quote:








Prat displays URLs in a pop up box and the text is highlighted, you could check how it's done there.




hehe on first scan I thought you were insulting me ;o)

I downloaded Prat and gave it a try. Am I right in that the URL pops up in an separate box with just a single line of text. If so I'm not sure it helps. I stole some similar code from Deadly Boss Mods to base mine on. My problem seems to be the volume of text I'm trying to highlight. If I just populate a couple of lines in the edit box they get highlighted fine. But what I'm trying to do involves hundreds of lines of text, the start of which is beyond the top of the scroll box and has scrolled off. I'm wondering if I'm actually trying to get the UI to do something for which it was has never really been tested :o/

K|||Yeah it's just the URL on a single line as you say, ah well figured it was worth mentioning, hope you get it working :) .|||This 'probably' won't help with your problem but just to clarify my earlier point...

The "ScrollingEdit_On..." Scripts only need to be set for the EditBox. (i.e. within the EditBox tags)

Not for the ScrollFrame or the ScrollChild

I'm not sure what the consequences would be of trying to add those scripts to all 3 - it probably just generates FrameXML errors, and skips 'em when not needed...

Anyway, sorry the suggestions didn't help - don't forget to post the solution if you do find one ;)|||Quote:








This 'probably' won't help with your problem but just to clarify my earlier point...

The "ScrollingEdit_On..." Scripts only need to be set for the EditBox. (i.e. within the EditBox tags)

Anyway, sorry the suggestions didn't help - don't forget to post the solution if you do find one ;)




No worries. This wasn't my inention for the final XML, I just went mad (mainly with desparation) and dumped the handler stuff all over the place. Thanks for pointing out that it was still there, I'll take it out again

Thanks for all the help and don't worry if I ever solve the problem I'll let you know

No comments:

Post a Comment