TAB Order

Just starting out? Need help? Post your questions and find answers here.
RichardL
Enthusiast
Enthusiast
Posts: 532
Joined: Sat Sep 11, 2004 11:54 am
Location: UK

TAB Order

Post by RichardL »

Can any kindly assist and tell me how to set the TAB order for gadgets on a Windoze application?

Thanks...
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

Here's something you can try.

Code: Select all

Enumeration
  #ButtonGadget
  #StringGadget
  #CheckboxGadget
  #OptionGadget
EndEnumeration

; --> How many gadgets to tab
gadgetsToTab = 4

; --> Array of gadget tab stops
Dim tabStop(gadgetsToTab-1)

; --> Set tab stop order
tabStop(0) = #StringGadget
tabStop(1) = #OptionGadget
tabStop(2) = #ButtonGadget
tabStop(3) = #CheckboxGadget

; --> Procedure to change z-order (tab stops)
Procedure GadgetTabOrder()
  ; Get zero based array size
  tabCount = PeekL(@tabStop(0)-8)
  For gad = 0 To tabCount - 1
    If gad = 0
      ; First gadget is first tab stop
      pos = #HWND_TOP
    Else
      ; Remaining gadgets follow previous gadget
      pos = GadgetID(previousGad) 
    EndIf
    previousGad = tabStop(gad)
    ; --> Make the z-order change
    SetWindowPos_(GadgetID(tabStop(gad)), pos, -1, -1, -1, -1, #SWP_NOMOVE | #SWP_NOSIZE | #SWP_SHOWWINDOW)
  Next gad
EndProcedure

If OpenWindow(0, 0, 0, 220, 130, #PB_Window_SystemMenu | #PB_Window_ScreenCentered, "Gadget Tab Order") And CreateGadgetList(WindowID(0))
  ButtonGadget(#ButtonGadget, 10, 10, 200, 20, "Third Tab")
  StringGadget(#StringGadget, 10, 40, 200, 20, "First Tab")
  CheckBoxGadget(#CheckboxGadget, 10, 70, 200, 20, "Fouth Tab")
  OptionGadget(#OptionGadget, 10, 100, 200, 20, "Second Tab")
  GadgetTabOrder()
  Repeat
    event = WaitWindowEvent()
  Until event = #PB_Event_CloseWindow
EndIf
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
Fred
Administrator
Administrator
Posts: 18237
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

In PureBasic, the tab orders are the order of the created gadgets on your window.
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

My bad.

I was assuming RichardL wanted to change his z-order. ;)
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
RichardL
Enthusiast
Enthusiast
Posts: 532
Joined: Sat Sep 11, 2004 11:54 am
Location: UK

Post by RichardL »

Thanks Sparkie...

That is exactly what I needed. I am writing a fairly large application and create and destroy gadgets when various features are active or dormant; it is difficult to create the gadgets in the order I want to TAB them in, so now I can really sort things out.

An extra bonus from your example is that is seems that the size of an array can be found by a PeekL from the address of the zeroth element -8. It would be good to know what is at location @xxx(0)-4 and if there is anything else that can usefully be found... if the array type is available I could use this to make reasonable Insert and Delete functions that do not need to have the array type and size passed to them. I would like to do what the old GFA Basic did. (RIP old friend!). String arrays would be a challange...!
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

> the tab orders are the order of the created gadgets on your window

I just had my first problem with this: I have a StringGadget, then a PanelGadget,
which in turn has two other gadgets on it. I want to give the focus to the second
gadget on the PanelGadget, whenever I press the TAB key on the StringGadget.
However, due to the order of created gadgets, I can't do it. I'll probably use
Sparkie's code for now, but perhaps there could be a flag added in a future
release of PureBasic to set the tab index, like in Visual Basic?
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
zikitrake
Addict
Addict
Posts: 875
Joined: Thu Mar 25, 2004 2:15 pm
Location: Spain

Post by zikitrake »

:? Yes, It's a very old question, but.... are there any other mode to make this more easily?

Actually, I use PureVision and I create/destroy too many gadgets.

Thanks in advance
PB 6.21 beta, PureVision User
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

zikitrake wrote::? Yes, It's a very old question, but.... are there any other mode to make this more easily?
Actually, I use PureVision and I create/destroy too many gadgets.
Thanks in advance
Why don't you the change tab order in PureVision just before generating the code ?
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
zikitrake
Addict
Addict
Posts: 875
Joined: Thu Mar 25, 2004 2:15 pm
Location: Spain

Post by zikitrake »

gnozal wrote:Why don't you the change tab order in PureVision just before generating the code ?
Yes, I can do it, but, when I am creating and destroying gadgets every time, it's very laborious to sort them. I was looking for a possible solution that does to myself more easily this work.

(Sorry for 'google translation' :lol: )
Last edited by zikitrake on Fri Feb 16, 2007 3:17 pm, edited 1 time in total.
PB 6.21 beta, PureVision User
zikitrake
Addict
Addict
Posts: 875
Joined: Thu Mar 25, 2004 2:15 pm
Location: Spain

Post by zikitrake »

PB 6.21 beta, PureVision User
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

iirc the TAB-order is an attribute of the object ...
it's not the same as the display-Z-order, wich isn't an object's attribute.

I understand that Z-order changes are not supportet, since the OS does not.
but why isn't changing the TAB-order supported?
is it a LINUX/MAC compatibility problem?
oh... and have a nice day.
zikitrake
Addict
Addict
Posts: 875
Joined: Thu Mar 25, 2004 2:15 pm
Location: Spain

Post by zikitrake »

Hi, SortGadgetTabs lib makes an ArrayList of all gadget and sort it by X-Y position (GetGadgetX(), GetGadgetY()) and later make a:

Code: Select all

SetWindowPos_(GadgetN, GadgetNPrevious, -1, -1, -1, -1, #SWP_NOMOVE | #SWP_NOSIZE | #SWP_SHOWWINDOW)
of all elements
PB 6.21 beta, PureVision User
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

zikitrake wrote:Hi, SortGadgetTabs lib makes an ArrayList of all gadget and sort it by X-Y position (GetGadgetX(), GetGadgetY()) and later make a:

Code: Select all

SetWindowPos_(GadgetN, GadgetNPrevious, -1, -1, -1, -1, #SWP_NOMOVE | #SWP_NOSIZE | #SWP_SHOWWINDOW)
of all elements
Isn't that the same exact method I used in my code ^above ^ Why the need for a lib :?:
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
zikitrake
Addict
Addict
Posts: 875
Joined: Thu Mar 25, 2004 2:15 pm
Location: Spain

Post by zikitrake »

:oops: Yes, it's based in your code, but I modified to add Auto-count number of gadgets in any window.

:? The last thing that I would like is to bother someone. :?

My code is very chaotic for now, and I don't made any userlib until now, so I'm practicing with this code.

When I 'clean' the code it will be available with the lib.
PB 6.21 beta, PureVision User
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

zikitrake wrote:The last thing that I would like is to bother someone.
Not to worry zikitrake, I'm not bothered by your lib. :)

I thought since you created a lib for all this that you may have been using a method that was different and simpler than what I was using. My curiosity had me wondering. :wink:
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
Post Reply