Text Selection/Highlight Color for Editor or String Gadget

Mac OSX specific forum
coder14
Enthusiast
Enthusiast
Posts: 327
Joined: Tue Jun 21, 2011 10:39 am

Text Selection/Highlight Color for Editor or String Gadget

Post by coder14 »

I've found posts for changing the text selection/highlight color for EditorGadget and TextGadget on Windows. Is there any way to do this on MacOS?
WilliamL
Addict
Addict
Posts: 1214
Joined: Mon Aug 04, 2008 10:56 pm
Location: Seattle, USA

Re: Text Selection/Highlight Color for Editor or String Gadg

Post by WilliamL »

MacBook Pro-M1 (2021), Sonoma 14.3.1 (CLT 15.3), PB 6.10b7 M1
User avatar
Keya
Addict
Addict
Posts: 1891
Joined: Thu Jun 04, 2015 7:10 am

Re: Text Selection/Highlight Color for Editor or String Gadg

Post by Keya »

or if you mean just changing which part of the text is selected (using the default highlight/selection color) see the last code snippet here https://purebasic.developpez.com/faq/?p ... ing-Gadget
coder14
Enthusiast
Enthusiast
Posts: 327
Joined: Tue Jun 21, 2011 10:39 am

Re: Text Selection/Highlight Color for Editor or String Gadg

Post by coder14 »

I'm looking to change the HIGHLIGHT color when text in the editor or string gadget is SELECTED when we PRESS THE LEFT MOUSE BUTTON AND DRAG or when we PRESS THE SHIFT AND ARROW KEYS.

Image

The Windows version done by Sparkie is here:

http://forums.purebasic.com/english/vie ... 6a#p215974

Could this be done in MacOS?
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Text Selection/Highlight Color for Editor or String Gadg

Post by wilbert »

Something like this ?

Code: Select all

If OpenWindow(0, 0, 0, 322, 150, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  EditorGadget(0, 8, 8, 306, 133)
  
  Attributes = CocoaMessage(0, 0, "NSDictionary dictionaryWithObject:", 
                            CocoaMessage(0, 0, "NSColor orangeColor"),
                            "forKey:$", @"NSBackgroundColor")
  
  CocoaMessage(0, GadgetID(0), "setSelectedTextAttributes:", Attributes)
  
  For a = 0 To 5
    AddGadgetItem(0, a, "Line "+Str(a))
  Next
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
Windows (x64)
Raspberry Pi OS (Arm64)
coder14
Enthusiast
Enthusiast
Posts: 327
Joined: Tue Jun 21, 2011 10:39 am

Re: Text Selection/Highlight Color for Editor or String Gadg

Post by coder14 »

wilbert wrote:Something like this ?

Code: Select all

If OpenWindow(0, 0, 0, 322, 150, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  EditorGadget(0, 8, 8, 306, 133)
  
  Attributes = CocoaMessage(0, 0, "NSDictionary dictionaryWithObject:", 
                            CocoaMessage(0, 0, "NSColor orangeColor"),
                            "forKey:$", @"NSBackgroundColor")
  
  CocoaMessage(0, GadgetID(0), "setSelectedTextAttributes:", Attributes)
  
  For a = 0 To 5
    AddGadgetItem(0, a, "Line "+Str(a))
  Next
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
EXACTLY! That did it! :D :D :D

Thank you wilbert. You're my savior.
Post Reply