AddGadgetItem()...What??

Just starting out? Need help? Post your questions and find answers here.
i.candide
User
User
Posts: 13
Joined: Tue Jan 02, 2007 1:43 pm
Location: Orange County, California, USA

AddGadgetItem()...What??

Post 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
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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!
I may look like a mule, but I'm not a complete ass.
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post by Derek »

@srod, yeah, same here. Can see a 1 pixel line missing out of the border where the scroll bar should be.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

That's weird isn't it. :?
I may look like a mule, but I'm not a complete ass.
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post by Derek »

Another one for the BUGS list, starting to think PB4.02 isn't as stable as I would have hoped. :(
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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!
I may look like a mule, but I'm not a complete ass.
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post 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.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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 
I may look like a mule, but I'm not a complete ass.
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post by Derek »

Good point. :(

You can always turn to the windows API. :) :)
i.candide
User
User
Posts: 13
Joined: Tue Jan 02, 2007 1:43 pm
Location: Orange County, California, USA

Post 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
User avatar
Azul
Enthusiast
Enthusiast
Posts: 109
Joined: Fri Dec 29, 2006 9:50 pm
Location: Finland

Post 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
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

If you don't use SetGadgetFont() then Windows will simply use a default font. No problem. :)
I may look like a mule, but I'm not a complete ass.
merihevonen
Enthusiast
Enthusiast
Posts: 326
Joined: Mon Jan 01, 2007 7:20 pm

Post 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:
Post Reply