SetGadgetState for EditorGadget [Resolved]

Just starting out? Need help? Post your questions and find answers here.
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