EASY Prefs

Just starting out? Need help? Post your questions and find answers here.
SMaag
Enthusiast
Enthusiast
Posts: 327
Joined: Sat Jan 14, 2023 6:55 pm
Location: Bavaria/Germany

Re: EASY Prefs

Post by SMaag »

and also ALL (or some) gadgets/rectcontrols' full State
Yes, that was what I understood at the beginning! All gadgets!
But If the user can't manipulate the Gadget-Positions, why you want to save ist! They are defined by your code and maybe the resize window, saving that positions don't make sense.


But if user can manually change Gadgets, then you have to save this data too. That's the case for a Splitter Gadget!

The way to do this:
- write individual code for your design to save that data
- a more flexible approach would be an automatic listing of all Windows and Gadgets and save the Datas for all. Does not matter if it is necessary for the Gadget or not.
To do the Window and Gadget-listing look at the System Modul from mk-soft, that's only possilble with the SDK functions what are not docmented in the PB-Help. To find such information you have to look in the C-header files shipped with PB and in the SourceCode of the IDE.

Just a simple dump with copymemory is not possible. The Datas ar not packed in a single structure. And the X,Y, Width, Height seems to be only at OS side and not double buffered by PB. So you have to call all the Gadgets GetDataFunctions to retrieve the Datas.
User avatar
Piero
Addict
Addict
Posts: 1040
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Re: EASY Prefs

Post by Piero »

SMaag wrote: Mon Feb 10, 2025 8:22 pmYes, that was what I understood at the beginning! All gadgets!
Thanks for your tips and forgive me…

…anyway this is just a challenge to the PB Gurus to see if something (at least partially) like that ancient thing is possible ;)

Edit/PS: did you see my test of the mk-soft thing above? Seems like the flags value is "reversed-endian", did I do something horrible getting it?
SMaag
Enthusiast
Enthusiast
Posts: 327
Joined: Sat Jan 14, 2023 6:55 pm
Location: Bavaria/Germany

Re: EASY Prefs

Post by SMaag »

Yes I saw! But better do not direct access this Data. It's undocumnted Data. There is no description what is stored in Flags. But the 2 entries Type and Flag exists only at MacOS. On Windows and Linux it do not exist in this way. As long as we do not know what is exactly stored in Flags we can't say anything about the values you see. That's just speculation.

But let's come back to the beginning:
1.
Until know I do not understand why you think you have to save states of Gadgetes.
What you exactly mean with state of Gadgets? The X,Y Width and Heigt? - if yes, who changed that values so they are different from design now!


2. As I explained before: it is not possible to copy out all the Data from the sdkGadget Structure.
you have to call all Methodes StepByStep to get back the Data.
GadgetX()
GadgetY()
GetGadgetSate()
etc.


here I found a Modul what can save WindowResize Data!
https://github.com/Hoeppner1867/PureBas ... Module.pbi
User avatar
Piero
Addict
Addict
Posts: 1040
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Re: EASY Prefs

Post by Piero »

SMaag wrote: Tue Feb 11, 2025 5:00 pm Yes I saw! But better do not direct access this Data. It's undocumnted Data. There is no description what is stored in Flags.
………
Until know I do not understand why you think you have to save states of Gadgetes.
What you exactly mean with state of Gadgets? The X,Y Width and Heigt? - if yes, who changed that values so they are different from design now
The mk-soft thing has some sense; you CAN extract the real value:

Code: Select all

#PB_CheckBox_Right       (1) ;$100000004
#PB_CheckBox_Center      (2) ;$200000004
#PB_CheckBox_ThreeState  (4) ;$400000004
The ancient module saved/restored all, ALL: text that was edited, selections of all kinds, checkboxes status…
ANYTHING that the user had changed!!! And obviously you could exclude some gadgets…
The gadgets position on a resizable (but unrestored) window was NOT a problem to restore the gadgets! :!:
User avatar
Piero
Addict
Addict
Posts: 1040
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Re: EASY Prefs

Post by Piero »

:lol: :lol: :lol: …but it works here!

I tried to change the "endian", but………

Code: Select all

CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
   ; PB Internal Structure Gadget MacOS
   Structure sdkGadget
      *gadget
      *container
      *vt
      UserData.i
      Window.i ; 10
      Flags.i 
      Type.i ; ?
   EndStructure
   
   If OpenWindow(10,0,0,270,270,"Gadgets' Flags Test",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
      CheckBoxGadget(0,10,10,250,20,"Standard   0")
      CheckBoxGadget(1,10,40,250,20,"Right      1",#PB_CheckBox_Right)
      CheckBoxGadget(2,10,70,250,20,"Center     2",#PB_CheckBox_Center)
      CheckBoxGadget(4,10,100,250,20,"3S        4",#PB_CheckBox_ThreeState):SetGadgetState(4,#PB_Checkbox_Inbetween)
      CheckBoxGadget(5,10,130,250,20,"3S+Right  4+1",#PB_CheckBox_ThreeState|#PB_CheckBox_Right)
      CheckBoxGadget(16,10,160,250,20,"Test     16",16) ; test (8,16,32…)
      StringGadget(128,10,190,250,20,"String    0")
      StringGadget(129,10,230,250,20,"Hidden    1",#PB_String_Password)
      Repeat
         ev=WaitWindowEvent()
         If ev=#PB_Event_Gadget And IsGadget(EventGadget())
            if EventType() = #PB_EventType_Change or GadgetType(EventGadget()) = #PB_GadgetType_CheckBox
               *Gadget.sdkGadget = IsGadget(EventGadget())
               g=*Gadget\Flags
               
               Debug val("$"+Left(Hex(g),Len(Hex(g))-8))
               
            EndIf
         EndIf
      Until ev=#PB_Event_CloseWindow
   EndIf
CompilerEndIf
User avatar
Piero
Addict
Addict
Posts: 1040
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

EASY Prefs Update

Post by Piero »

Code: Select all

; savegadgets prototype

; returns name now… maybe may be useful to save or restore/replace gadgets later…
Procedure.s getGType(g)
   Select g
     Case #PB_GadgetType_Unknown ;        0
         ProcedureReturn "Unknown"
      Case #PB_GadgetType_Button ;        1
         ProcedureReturn "Button"
      Case #PB_GadgetType_String ;        2
         ProcedureReturn "String"
      Case #PB_GadgetType_Text ;          3
         ProcedureReturn "Text"
      Case #PB_GadgetType_CheckBox ;      4
         ProcedureReturn "CheckBox"
      Case #PB_GadgetType_Option ;        5
         ProcedureReturn "Option"
      Case #PB_GadgetType_ListView ;      6
         ProcedureReturn "ListView"
      Case #PB_GadgetType_Frame ;         7
         ProcedureReturn "Frame"
      Case #PB_GadgetType_ComboBox ;      8
         ProcedureReturn "ComboBox"
      Case #PB_GadgetType_Image ;         9
         ProcedureReturn "Image"
      Case #PB_GadgetType_HyperLink ;     10
         ProcedureReturn "HyperLink"
      Case #PB_GadgetType_Container ;     11
         ProcedureReturn "Container"
      Case #PB_GadgetType_ListIcon ;      12
         ProcedureReturn "ListIcon"
      Case #PB_GadgetType_IPAddress ;     13
         ProcedureReturn "IPAddress"
      Case #PB_GadgetType_ProgressBar ;   14
         ProcedureReturn "ProgressBar"
      Case #PB_GadgetType_ScrollBar ;     15
         ProcedureReturn "ScrollBar"
      Case #PB_GadgetType_ScrollArea ;    16
         ProcedureReturn "ScrollArea"
      Case #PB_GadgetType_TrackBar ;      17
         ProcedureReturn "TrackBar"
      Case #PB_GadgetType_Web ;           18
         ProcedureReturn "Web"
      Case #PB_GadgetType_ButtonImage ;   19
         ProcedureReturn "ButtonImage"
      Case #PB_GadgetType_Calendar ;      20
         ProcedureReturn "Calendar"
      Case #PB_GadgetType_Date ;          21
         ProcedureReturn "Date"
      Case #PB_GadgetType_Editor ;        22
         ProcedureReturn "Editor"
      Case #PB_GadgetType_ExplorerList ;  23
         ProcedureReturn "ExplorerList"
      Case #PB_GadgetType_ExplorerTree ;  24
         ProcedureReturn "ExplorerTree"
      Case #PB_GadgetType_ExplorerCombo ; 25
         ProcedureReturn "ExplorerCombo"
      Case #PB_GadgetType_Spin ;          26
         ProcedureReturn "Spin"
      Case #PB_GadgetType_Tree ;          27
         ProcedureReturn "Tree"
      Case #PB_GadgetType_Panel ;         28
         ProcedureReturn "Panel"
      Case #PB_GadgetType_Splitter ;      29
         ProcedureReturn "Splitter"
      Case #PB_GadgetType_MDI ;           30
         ProcedureReturn "MDI"
      Case #PB_GadgetType_Scintilla ;     31
         ProcedureReturn "Scintilla"
      Case #PB_GadgetType_Shortcut ;      32
         ProcedureReturn "Shortcut"
      Case #PB_GadgetType_Canvas ;        33
         ProcedureReturn "Canvas"
      Case #PB_GadgetType_OpenGL ;        34
         ProcedureReturn "OpenGL"
      Case #PB_GadgetType_WebView ;       35
         ProcedureReturn "WebView"
   EndSelect
EndProcedure

CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
   ; PB Internal Structure Gadget MacOS from PureBasic.app/Contents/Resources/sdk/c/PureLibraries/Gadget/Gadget.h
   Structure sdkGadget
      *Gadget    ; thanks mk-soft!
      *Container
      *Functions ; ref-ed (released when the view is destroyed)
      UserData.i ; integer
      Window.i   ; integer
      Type.l     ; int
      Flags.l    ; int
   EndStructure
   
   If OpenWindow(10,0,0,270,270,"Gadgets' Flags Test",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
      CheckBoxGadget(0,10,10,250,20,"Standard   0")
      CheckBoxGadget(1,10,40,250,20,"Right      1",#PB_CheckBox_Right)
      CheckBoxGadget(2,10,70,250,20,"Center     2",#PB_CheckBox_Center)
      CheckBoxGadget(4,10,100,250,20,"3S        4",#PB_CheckBox_ThreeState):SetGadgetState(4,#PB_Checkbox_Inbetween)
      CheckBoxGadget(5,10,130,250,20,"3S+Right  4+1",#PB_CheckBox_ThreeState|#PB_CheckBox_Right)
      CheckBoxGadget(16,10,160,250,20,"Test     16",16) ; test (8,16,32…)
      StringGadget(128,10,190,250,20,"String    0")
      StringGadget(129,10,230,250,20,"Hidden    1",#PB_String_Password)
      Repeat
         ev=WaitWindowEvent()
         If ev=#PB_Event_Gadget And IsGadget(EventGadget())
            if EventType() = #PB_EventType_Change or GadgetType(EventGadget()) = #PB_GadgetType_CheckBox
               *Gadget.sdkGadget = IsGadget(EventGadget()) ; thanks mk-soft!
               
               Debug "Gadget Type:  "+ getGType(*Gadget\Type) +"Gadget"
               state= GetGadgetState(EventGadget())
               ;SetGadgetState(EventGadget(),state) ; bad for strings (but good for almost all gadgets)
               Debug "Gadget State: "+ state
               Debug "Gadget Flags: "+ *Gadget\Flags
               Debug ""
               
            EndIf
         EndIf
      Until ev=#PB_Event_CloseWindow
   EndIf
CompilerEndIf
SMaag
Enthusiast
Enthusiast
Posts: 327
Joined: Sat Jan 14, 2023 6:55 pm
Location: Bavaria/Germany

Re: EASY Prefs

Post by SMaag »

The mk-soft thing has some sense; you CAN extract the real value:
Yes, but this structure is different on Windwos, Linux, MacOS.

The reason I set a link to the mk-soft stuff is:
wit this module it is possible to enumerate all Windows and all Gadgets or all Gadgets of a Window.

But until know you did not asked my Question, why you want to restore Gadgets.
It's because this is not necessary because normally the user can't change gadget positions.
The only thing what you have to restore is the Window- position and size. The rest should be done by the resize procedure.
User avatar
Piero
Addict
Addict
Posts: 1040
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Re: EASY Prefs

Post by Piero »

SMaag wrote: Sat Feb 15, 2025 7:05 pmwhy you want to restore Gadgets
Just a stupid example (I don't think someone would want to restore a password field visibility)
https://www.purebasic.fr/english/viewto ... 00#p635000
…but perhaps it MAY be useful to restore other kinds of gadgets…

Meanwhile I wanted to learn about PB internals, and, who knows, it may be useful also for someone else for something else…
User avatar
Piero
Addict
Addict
Posts: 1040
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Save Selection (Mac)

Post by Piero »

Code: Select all

CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
   ; https://www.purebasic.fr/english/viewtopic.php?t=60177
   OpenWindow(0, 270, 100, 200, 130, "EditorGadget")
   EditorGadget(0, 10, 10, 180, 80, #PB_Editor_WordWrap)
   SetGadgetText(0, "The quick brown fox jumps over the lazy dog.")
   ButtonGadget(1, 100, 100, 95, 25, "Set Sel")
   ButtonGadget(2, 5, 100, 95, 25, "Save Sel")
   CocoaMessage(0, GadgetID(0), "selectAll:", 0)
   desel.nsrange
   Sel.NSRange
   Repeat
      Select WaitWindowEvent()
         Case #PB_Event_CloseWindow
            Break
         Case #PB_Event_Gadget
            Select EventGadget()
               Case 1
                  CocoaMessage(0, GadgetID(0), "setSelectedRange:@", @Sel) ; Set selection
               Case 2
                  CocoaMessage(@Sel.NSRange, GadgetID(0), "selectedRange") ; Get selection
                  Debug ~"Selection Text:\n"+ Mid(GetGadgetText(0), Sel\location + 1, Sel\length)
                  CocoaMessage(0, GadgetID(0), "setSelectedRange:@", @desel)
            EndSelect
      EndSelect
   ForEver
CompilerEndIf
User avatar
Piero
Addict
Addict
Posts: 1040
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Re: EASY Prefs

Post by Piero »

I wonder if the best way to save (and then replace/restore) "snapshots" of gadgets should be a PB/OS hybrid, somewhat like Shardik did here

For Mac, there's also the problem that Cocoa is becoming obsolete… I hope it will be easy to keep new versions of PB working on old Mac OSs!
Post Reply