Ampersand doesn't appear in option gadget text

Found an issue in the documentation ? Please report it here !

Moderator: Documentation Editors

Axeman
User
User
Posts: 89
Joined: Mon Nov 03, 2003 5:34 am

Ampersand doesn't appear in option gadget text

Post by Axeman »

The problem that I'm having is that ampersands don't appear in option gadget text.

Example Code

Code: Select all

If OpenWindow(0, 0, 0, 140, 80, "OptionGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
	OptionGadget(0, 10, 10, 120, 20, "Option 1 - &Test")
	OptionGadget(1, 10, 30, 120, 20, "Option 2 - &Test")
	OptionGadget(2, 10, 50, 120, 20, "Option 3 - &Test")
	SetGadgetState(1, 1)   ; set second option as active one
	Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf

This issue appears to be something to do with a Windows #SS_NOPREFIX flag near as i can tell from the forum posts below. This seems to be a behavior that was changed for some gadgets (TextGadgets) a few years ago, but doesn't seem to have been changed for OptionGadgets. I can't see the point of having this behavior for OptionGadgets as it doesn't achieve anything useful, so I assume this is some kind of bug or oversight.

A couple of threads that seem to be related.
http://www.purebasic.fr/english/viewtop ... 13&t=61540
http://www.purebasic.fr/english/viewtop ... 13&t=58677

I can't seem to disable this nonsense either. Surely there's some way of including an ampersand in OptionGadget text?

Code: Select all

If OpenWindow(0, 0, 0, 140, 80, "OptionGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
	OptionGadget(0, 10, 10, 120, 20, "Option 1 - &Test")
	OptionGadget(1, 10, 30, 120, 20, "Option 2 - &Test")
	OptionGadget(2, 10, 50, 120, 20, "Option 3 - &Test")
	SetGadgetState(1, 1)   ; set second option as active one
	SetWindowLongPtr_( GadgetID( 0 ), #GWL_STYLE, GetWindowLongPtr_( GadgetID( 0 ), #GWL_STYLE ) | #SS_NOPREFIX )
	SetGadgetText( 0, "Option X - &Test" )
	Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
User avatar
TI-994A
Addict
Addict
Posts: 2512
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Ampersand doesn't appear in option gadget text

Post by TI-994A »

Axeman wrote:...Surely there's some way of including an ampersand in OptionGadget text?
Just prefix another ampersand:

Code: Select all

If OpenWindow(0, 0, 0, 140, 80, "OptionGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
   OptionGadget(0, 10, 10, 120, 20, "Option 1 - &&Test")
   OptionGadget(1, 10, 30, 120, 20, "Option 2 - &&Test")
   OptionGadget(2, 10, 50, 120, 20, "Option 3 - &&Test")
   SetGadgetState(1, 1)   ; set second option as active one
   Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Re: Ampersand doesn't appear in option gadget text

Post by Mistrel »

The ampersand will underline up to a single following letter in the denoted string and is meant to provide a hint for accelerators such as alt-key shortcuts. You have to escape it with "&&".

I only know that this is the functionality by-design for Win32. It might behave differently on other platforms.
Axeman
User
User
Posts: 89
Joined: Mon Nov 03, 2003 5:34 am

Re: Ampersand doesn't appear in option gadget text

Post by Axeman »

Ok, thanks for the info. The double ampersand fix worked for me.

I think this really needs to be added somewhere in the Purebasic docs, though. Possibly in the main 'Gadgets' documentation page.
User avatar
Andre
PureBasic Team
PureBasic Team
Posts: 2056
Joined: Fri Apr 25, 2003 6:14 pm
Location: Germany (Saxony, Deutscheinsiedel)
Contact:

Re: Ampersand doesn't appear in option gadget text

Post by Andre »

I leave to this for Fred/freak to check + comment, especially to be aware of probably different behaviour on the different supported OS.
(furthermore I wouldn't be sure, where the best place is to add a note in the docs...)
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)
Post Reply