SetGadgetState for EditorGadget [Resolved]

Just starting out? Need help? Post your questions and find answers here.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

SetGadgetState for EditorGadget [Resolved]

Post by Kwai chang caine »

Hello,

Is it possible to highlight a line in an EditorGadget, like the function

Code: Select all

SetGadgetState(#Listview, 1)
for a ListView

Thanks
Last edited by Kwai chang caine on Tue Nov 13, 2012 5:08 pm, edited 1 time in total.
ImageThe happiness is a road...
Not a destination
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: SetGadgetState for EditorGadget

Post by Kwai chang caine »

Thanks to a code of SPARKIE (for the hightlight), i have create this :oops:
I'm forced to use an Array of len :(

Code: Select all

Global Dim ArrayOfSize(100)

Procedure SetEditorState(IdEditor, NumItem)
 
 Start = 0
 
 For i = 1 To NumItem
  Start + ArrayOfSize(i)
 Next 
  
 editSel.CHARRANGE\cpMin = Start + NumItem
 editSel.CHARRANGE\cpMax = Start + ArrayOfSize(NumItem) + NumItem + 1
 SendMessage_(GadgetID(IdEditor), #EM_EXSETSEL, 0, @editSel)
  
EndProcedure

OpenWindow(0, 0, 0, 300, 150, "EditorGadget SetGadgetState", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
EditorGadget(0, 0, 5, 300, 145) 

For i = 1 To 100
 AddGadgetItem(0, - 1, "Line number " + Trim(Str(i)))
 ArrayOfSize(i) = Len("Line number " + Trim(Str(i)))
Next

For i = 1 To 50
 SetEditorState(0, i)
 Delay(300)
Next
ImageThe happiness is a road...
Not a destination
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: SetGadgetState for EditorGadget

Post by Kwai chang caine »

@Kcc try the next

Code: Select all

Procedure SetEditorState(IdEditor, NumItem)
 
 Start = 0
 
 For a = 0 To CountGadgetItems(IdEditor)
  
  If a = NumItem
   Break
  EndIf
        
  Start + Len(GetGadgetItemText(IdEditor, a))
  
 Next

 editSel.CHARRANGE\cpMin = Start + NumItem
 editSel.CHARRANGE\cpMax = Start + Len(GetGadgetItemText(IdEditor, a)) + NumItem + 1
 SendMessage_(GadgetID(IdEditor), #EM_EXSETSEL, 0, @editSel)
  
EndProcedure

OpenWindow(0, 0, 0, 300, 150, "EditorGadget SetGadgetState", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
EditorGadget(0, 0, 5, 300, 145) 

For i = 1 To 100
 AddGadgetItem(0, - 1, "Line number " + Trim(Str(i)))
Next

For i = 1 To 50
 SetEditorState(0, i)
 Delay(300)
Next
Last edited by Kwai chang caine on Tue Nov 13, 2012 5:13 pm, edited 1 time in total.
ImageThe happiness is a road...
Not a destination
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: SetGadgetState for EditorGadget

Post by Kwai chang caine »

Ooooohhh!!! Thanks KCC !!!!
Exactely, what i want, without the array 8)

I hope a futur function for the next PB (GOD... if you read me) :D

Thanks a lot :mrgreen:

Have a goooooood daaaaaaay
CHAMPAGNE, For a time i found alone
ImageThe happiness is a road...
Not a destination
User avatar
luis
Addict
Addict
Posts: 3893
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: SetGadgetState for EditorGadget [Resolved]

Post by luis »

I know KCC already helped you, but anyway...

Code: Select all

Procedure SetEditorState(IdEditor, NumItem)
 
;  Start = 0
;  
;  For a = 0 To CountGadgetItems(IdEditor)
;  
;   If a = NumItem
;    Break
;   EndIf
;        
;   Start + Len(GetGadgetItemText(IdEditor, a))
;  
;  Next
;  
 
 ; http://msdn.microsoft.com/en-us/library/windows/desktop/bb761611%28v=vs.85%29.aspx
 Start = SendMessage_(GadgetID(IdEditor), #EM_LINEINDEX, NumItem, 0) ; jump there, no loop
 
 editSel.CHARRANGE\cpMin = Start
 editSel.CHARRANGE\cpMax = Start + Len(GetGadgetItemText(IdEditor, NumItem)) + 1
 
 SendMessage_(GadgetID(IdEditor), #EM_EXSETSEL, 0, @editSel)
 
EndProcedure

OpenWindow(0, 0, 0, 300, 150, "EditorGadget SetGadgetState", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
EditorGadget(0, 0, 5, 300, 145)

For i = 1 To 100
 AddGadgetItem(0, - 1, "Line number " + Trim(Str(i)))
Next

For i = 0 To 50
 SetEditorState(0, i)
 Delay(300)
Next
"Have you tried turning it off and on again ?"
A little PureBasic review
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: SetGadgetState for EditorGadget [Resolved]

Post by Kwai chang caine »

Whaoouuh !!!
More better and shorter, than both KCC and KCC code :shock:
You are too strong, this time, it's really what i wanted 8)

One thousand of thanks LUIS 8)
I wish you a very good night
ImageThe happiness is a road...
Not a destination
Ulix
User
User
Posts: 48
Joined: Wed Jan 23, 2008 12:45 pm
Location: France, Montpellier

Re: SetGadgetState for EditorGadget [Resolved]

Post by Ulix »

Translated with google.

hello all :!:

I did not test this piece of code (because I'm on linux, but perfect person! :wink: ), but to see the reaction that KCC should do.

Y does the same code for linux?


En français
bonjour a tous :!:
je n'ai pas tester ce bout de code(car je suis sous linux, personne mais parfait ! :wink:(Non là c'est de l'humour francais, partie non traduite!), mais a voir la réaction de KCC ça doit faire.

Y a t-il un même code pour linux ?

Ulix
MachineCode
Addict
Addict
Posts: 1482
Joined: Tue Feb 22, 2011 1:16 pm

Re: SetGadgetState for EditorGadget

Post by MachineCode »

Kwaï chang caïne wrote:@Kcc try the next
and
Kwaï chang caïne wrote:Ooooohhh!!! Thanks KCC !!!!
Why are you having a conversation with yourself? :shock:
Microsoft Visual Basic only lasted 7 short years: 1991 to 1998.
PureBasic: Born in 1998 and still going strong to this very day!
User avatar
Kurzer
Enthusiast
Enthusiast
Posts: 670
Joined: Sun Jun 11, 2006 12:07 am
Location: Near Hamburg

Re: SetGadgetState for EditorGadget [Resolved]

Post by Kurzer »

Haha, Kwaï, you're such a crazy guy! :lol:
I like you. :D
PB 6.02 x64, OS: Win 7 Pro x64 & Win 11 x64, Desktopscaling: 125%, CPU: I7 6500, RAM: 16 GB, GPU: Intel Graphics HD 520, User age in 2024: 56y
"Happiness is a pet." | "Never run a changing system!"
User avatar
Shardik
Addict
Addict
Posts: 2058
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: SetGadgetState for EditorGadget [Resolved]

Post by Shardik »

Ulix wrote:Y does the same code for linux?
I have taken luis' code, modified it slightly and added the necessary API functions for Linux and MacOS (both Carbon and Cocoa framework). Now this code example can be run in Windows, Linux and MacOS X . MacOS users with PB 5 using the default subsystem (Cocoa) should notice that wilbert's CocoaMessage userlib must have been installed before they can execute this code!

Code: Select all

EnableExplicit

CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
  CompilerIf #PB_Compiler_Version < 500 Or (#PB_Compiler_Version >= 500 And Subsystem("Carbon"))
    ImportC ""
      GetControlProperty(ControlRef.L, PropertyCreator.L, PropertyTag.L, BufferSize.L, *ActualSize, *PropertyBuffer)
      TXNSetSelection(TXNObject.L, StartOffset.L, EndOffset.L)
      TXNShowSelection(TXNObject.L, ShowEnd.L)
    EndImport
  CompilerEndIf
CompilerEndIf

Procedure SelectEditorLine(EditorID.I, LineNumber.I)
  CompilerSelect #PB_Compiler_OS
    CompilerCase #PB_OS_Linux
      Protected EndOfLine.GtkTextIter
      Protected StartOfLine.GtkTextIter
      Protected *TextBuffer.GtkTextBuffer
      
      *TextBuffer = gtk_text_view_get_buffer_(GadgetID(EditorID))
      gtk_text_buffer_get_iter_at_line_(*TextBuffer, @StartOfLine, LineNumber)
      gtk_text_view_scroll_to_iter_(GadgetID(EditorID), StartOfLine, 0.0, #False, 0.0, 0.0)
      EndOfLine = StartOfLine
      gtk_text_iter_forward_to_line_end_(EndOfLine)
      gtk_text_buffer_select_range_(*TextBuffer, StartOfLine, EndOfLine)
    CompilerCase #PB_OS_MacOS
      CompilerIf #PB_Compiler_Version < 470 Or (#PB_Compiler_Version >= 500 And Subsystem("Carbon"))
        Protected EndOfLine.L
        Protected StartOfLine.L
        Protected TXNObject.L
        
        If GetControlProperty(GadgetID(EditorID), $50555245, $54584F42, 4, 0, @TXNObject) = 0
          StartOfLine = FindString(GetGadgetText(EditorID), GetGadgetItemText(EditorID, LineNumber)) - 1
          EndOfLine = StartOfLine + Len(GetGadgetItemText(EditorID, LineNumber))
          TXNSetSelection(TXNObject, StartOfLine, EndOfLine)
          TXNShowSelection(TXNObject, #True)
        EndIf
      CompilerElse
        Protected Range.NSRange
        
        Range\location = FindString(GetGadgetText(EditorID), GetGadgetItemText(EditorID, LineNumber)) - 1
        Range\length = Len(GetGadgetItemText(EditorID, LineNumber))
        CocoaMessage(0, GadgetID(EditorID), "setSelectedRange:@", @Range)
        CocoaMessage(0, GadgetID(EditorID), "scrollRangeToVisible:@", @Range)
      CompilerEndIf
    CompilerCase #PB_OS_Windows
      Protected Selection.CHARRANGE
      Protected StartOfLine.I
      
      StartOfLine = SendMessage_(GadgetID(EditorID), #EM_LINEINDEX, LineNumber, 0)
      Selection.CHARRANGE\cpMin = StartOfLine
      Selection.CHARRANGE\cpMax = StartOfLine + Len(GetGadgetItemText(EditorID, LineNumber)) + 1
      SendMessage_(GadgetID(EditorID), #EM_EXSETSEL, 0, @Selection)
  CompilerEndSelect
EndProcedure

Define i.I

OpenWindow(0, 270, 100, 200, 154, "Select line by line", #PB_Window_SystemMenu)
EditorGadget(0, 5, 5, 190, 144)

For i = 1 To 15
  AddGadgetItem(0, - 1, "Line number " + Trim(Str(i)))
Next

For i = 0 To CountGadgetItems(0) - 1
  SelectEditorLine(0, i)
  Delay(400)

  Repeat
    Select WindowEvent()
      Case 0
        Break
      Case #PB_Event_CloseWindow
        End
    EndSelect
  ForEver 
Next i

Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
Update 1: Support for Mac OS X running with PB 5 and default subsystem Cocoa has been added.
Update 2: In the Linux part the code line

Code: Select all

gtk_text_view_scroll_to_iter_(GadgetID(EditorID), StartOfLine, 0.0, #False, 0.0, 0.0)
has been added to scroll a selected line which is currently hidden into the visible area. Furthermore for the sake of clarity I renamed the procedure from SetEditorState() to SelectEditorLine().
Update 3: The Mac part has been extended to also run with PB 4 or PB 5 with subsystem Carbon.
Last edited by Shardik on Sun Nov 18, 2012 7:45 pm, edited 4 times in total.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: SetGadgetState for EditorGadget [Resolved]

Post by Kwai chang caine »

@Shardik
Even if i don't have linux, thanks for your code 8)

@Ulix
Yes top cool the LUIS code 8)
My dream ... that one day, reading the bible bill as it :shock: 8)

@MachineCode
Simply because at this moment i'm alone ... :(
Image
So, after the miracle, i'm so surprising to find myself the solution.... :shock: bad solution....but solution when even ..
The slightest thing was to thank me :mrgreen:
But reassure you, every day, I insult me more often, than i congratulate myself :lol:
Haha, Kwaï, you're such a crazy guy!
I like you.
Thanks a lot :D
And me....and I love the people who like me 8) :mrgreen:
I sign you into my dance card ... I still have empty seats for the next dance :lol: :lol:
Image
ImageThe happiness is a road...
Not a destination
Ulix
User
User
Posts: 48
Joined: Wed Jan 23, 2008 12:45 pm
Location: France, Montpellier

Re: SetGadgetState for EditorGadget [Resolved]

Post by Ulix »

Translated with Google:

@ Shardik
Thank you! :lol:
Travaillel perfectly!

For all the world!

I want to share this reflection! (If you feel that this reflection is relevant, I authorize you to copy this post and create a new topic with. :oops:)

This is my reflection:

(The previous code) is the kind of feature that is lacking in native PureBasic!
Since it is possible with the API (Windows, Linux, MacOS), why Fred does not incorporate in PB?
(A meet him ... if he wants, no obligation!. It is a matter of rétorique!)


And waiting why not have a resource file ("xxxx.res") which would have added these commands for all OS?

Imagine commands like:

GetGadgetTextSelect (GadgetID, Start, End)
SetGadgetTextSelect (GadgetID, Start, End)
....

(A you list the commands you want, provided they can be made using API and all OS)

This resource file could be maintained by the community PureBasic, and would make available, functions that we lack (until Fred develops and integrates to PB).

And we would not have to reinvent the wheel.
We would not lose many hours of research.
We would not have to redo or test codes without end.
We would have these commands to work better!

If some do not know what code, the idea is there, and the whole community would benefit!

What do you think? :wink:

;===================================
En Français :

@ Shardik
Merci ! :lol:
Travaillel parfaitement !

Pour tout les monde !

Je désire partager cette réflexion ! (Si vous jugez que cette réflexion est pertinente, je vous autorise à copier ce post et à en créer un nouveau topic avec. :oops: )

Voilà ma reflexion :

(Le code prècedent) est le genre de fonction qui manque dans PureBasic en natif !
Puisque c'est possible avec les API (windows, linux, MacOS), pourquoi Fred ne les intègre pas dans PB ?
(A lui de répondre... si il le veut, pas obligé !. C'est une question de rétorique !) :mrgreen:


Et attendant pourquoi ne pas avoir un fichier ressource ("xxxx.res") supplémentaire qui disposerait de ces commandes pour tous les OS ?

Imaginons des commandes comme :

GetGadgetTextSelect(GadgetID, Start, End)
SetGadgetTextSelect(GadgetID, Start, End)
....

(A vous de lister les commandes que vous désirez, pourvu qu'elles puissent être réalisées avec des API et sur tous les OS)

Ce fichier ressource pourrait être maintenu par la communauté PureBasic, et mettrait à disposition, des fonctions qui nous manquent (en attendant que Fred les développe et les intégre à PB).

Nous n'aurions ainsi pas a ré-inventer la roue.
Nous n'aurions pas à perdre de longues heures en recherche.
Nous n'aurions pas à faire ou refaire des codes de test à n'en plus finir.
Nous aurions ces commandes pour mieux travailler !

Si certains ne savent pas quoi coder, l'idée est là , et toute la communauté en profiterait!

Qu'en pensez-vous ? :wink:


A+
Ulix

Ps : @KCC
Yes top cool the LUIS code 8)
My dream ... that one day, reading the bible bill as it :shock: 8)
Le mien avoir toutes ces fonctions qui nous manque !
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: SetGadgetState for EditorGadget [Resolved]

Post by Kwai chang caine »

Ulix wrote:My dream is to have all the functions that we lack!
Le mien avoir toutes ces fonctions qui nous manque !
So good luck....you not again beginning to sleep :lol:
http://www.purebasic.fr/french/viewtopi ... =5&t=10072

And do like everybody....queuing at the supermarket as :mrgreen: :lol: :lol:

Me since 6 years i wait, not the return of the JEDI......

Image


But just the return of the line and the GIF lib :(
Image


En franche wrote:Et ben bonne chance .....t'es pas pres de t'endormir :lol:
http://www.purebasic.fr/french/viewtopi ... =5&t=10072
Et puis fait comme tout le monde....la queue comme à carrouf :mrgreen: :lol: :lol:

Moi, ça fait 6 ans que j'attend non pas le retour du JEDI
Image
Mais seulement le retour à la ligne et la lib GIF :(
Image
ImageThe happiness is a road...
Not a destination
Ulix
User
User
Posts: 48
Joined: Wed Jan 23, 2008 12:45 pm
Location: France, Montpellier

Re: SetGadgetState for EditorGadget [Resolved]

Post by Ulix »

hello


Shardik wrote
Code:
gtk_text_view_scroll_to_iter_(GadgetID(EditorID), StartOfLine, 0.0, #False, 0.0, 0.0)
has been added to scroll a selected line which is currently hidden into the visible area. Furthermore for the sake of clarity I renamed the procedure from SetEditorState() to SelectEditorLine().


seen!

Yet an API that could be part of the additional controls (see my previous post)

thank you :lol:
Post Reply