Page 1 of 1

AddGadgetItem()...What??

Posted: Wed Jan 17, 2007 9:41 pm
by i.candide
Good Afternoon,

I'm back with a crazy question.

If I open a window -
add an editor gadget -
add the read only attribute -
open a text file -
then try to display the text file in the editor gadget -
with the '-1' parameter, the file appears proper without scrollbars &
with the '0' parameter, the file appears backwards (last line first) with scrollbars

[code]

If OpenWindow(0, 132, 152, 650, 350, "Officer Phone List")

If CreateGadgetList(WindowID(0)) And LoadFont(0, "Arial", 11)

EditorGadget(0, 8, 8, 635, 335)
SetGadgetAttribute(0, #PB_Editor_ReadOnly, 1)

If ReadFile(0, "Text.txt")

While Eof(0) = 0
AddGadgetItem(0, -1, ReadString(0))
Wend

CloseFile(0)

Else
MessageRequester("Information","Couldn't open the file!")
EndIf

Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf

CloseWindow (0)
EndIf

End
[/code]


Why does the text file appear in the gadget backwards?

Help!!

Enjoy the day,
Earl

Posted: Wed Jan 17, 2007 9:51 pm
by srod
Hi, in the command

Code: Select all

AddGadgetItem(0, -1, ReadString(0)) 
the value of -1 instructs Purebasic to add the new line to the end of the editor gadget which means that the lines will appear in the correct order.

However, the command

Code: Select all

AddGadgetItem(0, 0, ReadString(0)) 
instructs PB to position each new line at row 0 which is the first line in the editor gadget. This causes the lines to be placed in reverse order.


By the way, does anyone else have the problem of the scrollbars disappearing when SetGadgetAttribute(0, #PB_Editor_ReadOnly, 1) is used? Actually a part of the scrollbar remains!

Posted: Thu Jan 18, 2007 10:24 am
by Derek
@srod, yeah, same here. Can see a 1 pixel line missing out of the border where the scroll bar should be.

Posted: Thu Jan 18, 2007 10:32 am
by srod
That's weird isn't it. :?

Posted: Thu Jan 18, 2007 11:16 am
by Derek
Another one for the BUGS list, starting to think PB4.02 isn't as stable as I would have hoped. :(

Posted: Thu Jan 18, 2007 11:22 am
by srod
I'll post a bug report.

Actually everything is okay if we move the SetGadgetAttribute() until after the data is added to the gadget!

Posted: Thu Jan 18, 2007 11:31 am
by Derek
Yeah, just tried it and it works on mine. Makes sense if you think about it, making it read only before adding data to it seems to be the wrong way round, even if it still works.

Posted: Thu Jan 18, 2007 11:41 am
by srod
I'd agree if Windows worked this way, but it doesn't.

Code: Select all

 If OpenWindow(0, 0, 0, 322, 150, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0)) 
    EditorGadget(0, 8, 8, 306, 133) 
    SendMessage_(GadgetID(0), #EM_SETREADONLY, 1, 0)
    For a = 0 To 50 
      AddGadgetItem(0, a, "Line "+Str(a)) 
    Next 
    Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow 
  EndIf 

Posted: Thu Jan 18, 2007 12:07 pm
by Derek
Good point. :(

You can always turn to the windows API. :) :)

Posted: Thu Jan 18, 2007 5:14 pm
by i.candide
Good Morning,

Thank you for the responses. I learned quite a lot, and now have a scroll bar.

Enjoy the day,
Earl

Posted: Thu Jan 18, 2007 5:56 pm
by Azul
hmm.. do I understand LoadFont incorrectly or do you miss this (or similar) from somewhere your code?

Code: Select all

SetGadgetFont(0,FontID(0))
update: corrected FontID() and typing errors :P

Posted: Thu Jan 18, 2007 7:37 pm
by srod
If you don't use SetGadgetFont() then Windows will simply use a default font. No problem. :)

Posted: Thu Jan 18, 2007 7:39 pm
by merihevonen
srod wrote:If you don't use SetGadgetFont() then Windows will simply use a default font. No problem. :)
He's just creative :)
After all, it's Pure :wink: