Page 1 of 2

Re: StringGadget right alignment

Posted: Mon Jun 24, 2013 9:58 am
by Shardik
Fred wrote:Using other gadget flags is not supported, use SetWindowLong_() on Windows if you want to change the style
Unfortunately it's a little bit more complicated. In Windows XP the alignment is only possible on creation of the StringGadget. Beginning with Windows Vista it's possible to change the alignment of a StringGadget's content dynamically:
http://forum.purebasic.com/english/view ... 13&t=36853

Try the following cross-platform code which I tested on Windows XP x86 SP3, Windows 7 x86 SP1, Kubuntu 13.04 x86 and Linux Mint 15 x86 Cinnamon. It redefines the StringGadget on Windows XP with the attribute #ES_RIGHT and changes the alignment dynamically on Windows Vista, Windows 7, Linux and MacOS X:

Code: Select all

CompilerIf #PB_Compiler_OS = #PB_OS_Linux
  ImportC ""
    gtk_entry_set_alignment(Entry.I, XAlign.F)
  EndImport
CompilerEndIf

OpenWindow(0, 100, 100, 280, 70, "Right-aligned StringGadget", #PB_Window_SystemMenu)
StringGadget(0, 60, 20, 150, 21, "123")

CompilerSelect #PB_Compiler_OS
  CompilerCase #PB_OS_Linux
    gtk_entry_set_alignment(GadgetID(0), 1)
  CompilerCase #PB_OS_MacOS
    CocoaMessage(0, GadgetID(0), "setAlignment:", 1)
  CompilerCase #PB_OS_Windows
    If OSVersion() > #PB_OS_Windows_XP
      SetWindowLongPtr_(GadgetID(0), #GWL_STYLE, GetWindowLongPtr_(GadgetID(0), #GWL_STYLE) & $FFFFFFFC | #ES_RIGHT) 
    Else
      StringGadget(0, 60, 20, 150, 21, "123", #ES_RIGHT)
    EndIf
CompilerEndSelect

Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow

Re: StringGadget right alignment

Posted: Mon Jun 24, 2013 5:24 pm
by BorisTheOld
@Fred
Fred wrote:Using other gadget flags is not supported, use SetWindowLong_() on Windows if you want to change the style
We use code similar to Shardik to make our GUI classes cross-platform. It's not a big problem for us, but it can be for less experienced programmers who are trying to write cross-platform applications.

Given the ease with which string gadgets can be aligned with user code, can #PB_STRING_LEFT and #PB_STRING_RIGHT be allowed when creating a string gadget?

Thanks

Re: StringGadget right alignment

Posted: Tue Jun 25, 2013 3:59 am
by ken_anthony
Well done. It worked. This is the code I needed.

Code: Select all

ImportC ""
    gtk_entry_set_alignment(Entry.I, XAlign.F)
EndImport
gtk_entry_set_alignment(GadgetID(0), 1)