How to set TAB positions in a TextGadget

Just starting out? Need help? Post your questions and find answers here.
Capella
User
User
Posts: 16
Joined: Wed Mar 19, 2008 5:32 pm

How to set TAB positions in a TextGadget

Post by Capella »

Is there any way to set the TAB positions in a TextGadget, so when CHR(9) for Tabulated positioning is sent, the printed text appear at the right, pre-defined tabulated positions?
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

Not sure if that's possible with a TextGadget but I have this, for Windows only...

Code: Select all

Procedure.l SetSparkedGadgetText(gad.l, text$, tabSpace.l = 8) 
  ; ------------------------------------------------ 
  ;  Set tab stops 
  ;  Each unit is 1/4 of a char 
  ;  so we multiply by 4 
  ; ------------------------------------------------ 
  tabSpace * 4 
  SendMessage_(GadgetID(gad), #EM_SETTABSTOPS, 1, @tabSpace) 
  SetGadgetText(gad, text$) 
EndProcedure 
Procedure.l SparkedTextGadget_(gad.l, x.l, y.l, w.l, h.l, text$, tabSpace.l = 8) 
  ;... ContainerGadget will hold our SparkedTextGadget 
  cGad.l = ContainerGadget(#PB_Any, x, y, w, h) 
  ;... Use multiline, readonly StringGadget 
  hwnd.l = StringGadget(gad, 0, 0, w, h, "", #ES_MULTILINE | #PB_String_ReadOnly) 
  CloseGadgetList() 
  ;... Remove border 
  SetWindowLong_(GadgetID(gad), #GWL_EXSTYLE, GetWindowLong_(GadgetID(gad), #GWL_EXSTYLE) &~#WS_EX_CLIENTEDGE) 
  SetWindowPos_(GadgetID(gad), 0, 0, 0, 0, 0, #SWP_NOMOVE | #SWP_NOSIZE | #SWP_NOZORDER | #SWP_FRAMECHANGED) 
  ;... Set background color to match default window color 
  SetGadgetColor(0, #PB_Gadget_BackColor, GetSysColor_(#COLOR_BTNFACE)) 
  ;... Disable ContainerGadget to prevent StringGadget cursor from appearing 
  DisableGadget(cGad, 1) 
  ; ------------------------------------------------ 
  ;  Set tab stops 
  ;  Each unit is 1/4 of a char 
  ;  so we multiply by 4 
  ; ------------------------------------------------ 
  tabSpace * 4 
  SendMessage_(GadgetID(gad), #EM_SETTABSTOPS, 1, @tabSpace) 
  SetGadgetText(gad, text$) 
  ProcedureReturn hwnd 
EndProcedure 

If OpenWindow(0, 0, 0, 400, 200, "Test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0)) 
  SparkedTextGadget_(0, 10, 10, 380, 50, "Hello" + #TAB$ + "World" + #CRLF$  + "PureBasic" + #TAB$ + "Rocks", 10) 
  ButtonGadget(1, 10, 80, 100, 30, "Change Text") 
  Repeat 
    event = WaitWindowEvent() 
    If event = #PB_Event_Gadget And EventGadget() = 1 
      SetSparkedGadgetText(0, "Changed" + #TAB$ + "Text" + #CRLF$ + "and" + #TAB$ + "tab" + #TAB$ + "space", 20) 
      DisableGadget(1, 1) 
    EndIf 
  Until event = #PB_Event_CloseWindow 
EndIf 
End 
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
Post Reply