[Solved] NSScrollView from ScintillaGadget

Mac OSX specific forum
User avatar
kenmo
Addict
Addict
Posts: 1967
Joined: Tue Dec 23, 2003 3:54 am

[Solved] NSScrollView from ScintillaGadget

Post by kenmo »

Does anyone know how to get the NSScrollView handle internal to a ScintillaGadget?

I'm not sure what GadgetID() points to, for a ScintillaGadget.
Last edited by kenmo on Fri Nov 20, 2015 11:22 pm, edited 1 time in total.
User avatar
kenmo
Addict
Addict
Posts: 1967
Joined: Tue Dec 23, 2003 3:54 am

Re: NSScrollView from ScintillaGadget

Post by kenmo »

To clarify, my end goal is to change the white background color of OS X ScintillaGadget (beyond the SCI_SCROLLWIDTH).

Example and experimenting code...

Code: Select all

EnableExplicit

Procedure.i NSColor(RGB.i)
  Protected.CGFloat r, g, b, a
  r = Red(RGB)   / 255.0
  g = Green(RGB) / 255.0
  b = Blue(RGB)  / 255.0
  a = 1.0
  ProcedureReturn (CocoaMessage(0, 0, "NSColor colorWithDeviceRed:@", @r, "green:@", @g, "blue:@", @b, "alpha:@", @a))
EndProcedure

Procedure.i Cocoa_SetBackgroundColor(Object.i, RGB.i)
  ProcedureReturn (CocoaMessage(0, Object, "setBackgroundColor:", NSColor(RGB)))
EndProcedure

Procedure.s Cocoa_ClassName(Object.i)
  Protected Result.s
  CocoaMessage(@Object, Object, "className")
  CocoaMessage(@Object, Object, "UTF8String")
  Result = PeekS(Object, -1, #PB_UTF8)
  ProcedureReturn (Result)
EndProcedure

Procedure.i Cocoa_Superclass(Object.i)
  ProcedureReturn (CocoaMessage(0, Object, "superclass"))
EndProcedure

Procedure.i Cocoa_Superview(Object.i)
  ProcedureReturn (CocoaMessage(0, Object, "superview"))
EndProcedure

Procedure Cocoa_DebugClasses(Object.i)
  Debug "Superclasses:"
  While (Object)
    Debug Cocoa_ClassName(Object)
    Object = Cocoa_Superclass(Object)
  Wend
EndProcedure

Procedure Cocoa_DebugViews(Object.i)
  Debug "Superviews:"
  While (Object)
    Debug Cocoa_ClassName(Object)
    Object = Cocoa_Superview(Object)
  Wend
EndProcedure

DisableExplicit

OpenWindow(0, 0, 0, 200, 200, "Test", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)

InitScintilla()
ScintillaGadget(0, 0, 0, 200, 100, #Null)
ScintillaSendMessage(0, #SCI_SETSCROLLWIDTH, 100, 0)
ScintillaSendMessage(0, #SCI_STYLESETBACK, #STYLE_DEFAULT, RGB(192, 255, 255))
ScrollAreaGadget(1, 0, 100, 200, 100, 100, 50)
CloseGadgetList()

Cocoa_SetBackgroundColor(GadgetID(1), RGB(192, 255, 255))

ID = GadgetID(0) ; PBScintillaView
ID = Cocoa_Superview(ID)
ID = Cocoa_Superview(ID)
Cocoa_SetBackgroundColor(ID, RGB(255, 255, 192))
CocoaMessage(0, ID, "setDrawsBackground:", #YES)

Cocoa_DebugClasses(ID)
Debug ""
Cocoa_DebugViews(ID)
Debug ""

Repeat
  Event = WaitWindowEvent()
Until (Event = #PB_Event_CloseWindow) Or (Event = #PB_Event_Menu)
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: NSScrollView from ScintillaGadget

Post by wilbert »

Something like this ?

Code: Select all

ID = GadgetID(0) ; PBScintillaView
ScrollView = CocoaMessage(0, ID, "scrollView")
Cocoa_SetBackgroundColor(ScrollView, RGB(255, 255, 192))
Windows (x64)
Raspberry Pi OS (Arm64)
User avatar
kenmo
Addict
Addict
Posts: 1967
Joined: Tue Dec 23, 2003 3:54 am

Re: NSScrollView from ScintillaGadget

Post by kenmo »

Wow. THANK YOU! So simple, when you know the right Cocoa method to use.

I was experimenting based off this bit of the Scintilla source:

Code: Select all

/**
 * Helper function to get the scrolling view.
 */
NSScrollView* ScintillaCocoa::ScrollContainer() {
  NSView* container = static_cast<NSView*>(wMain.GetID());
  return static_cast<NSScrollView*>([[container superview] superview]);
}
This solves my "big white Scintilla area" problem on Mac (which the PB IDE used to have)
so I no longer have to set a super wide Scintilla scrollWidth (which the IDE currently does)
which essentially solves this beyond-ScintillaGadget cursor bug (which the IDE currently has).


:)
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: NSScrollView from ScintillaGadget

Post by wilbert »

kenmo wrote:Wow. THANK YOU! So simple, when you know the right Cocoa method to use.
I also looked at the Scintilla source to come up with this but maybe I looked in a different location.
Anyway, I'm glad it works for you :)
Windows (x64)
Raspberry Pi OS (Arm64)
Post Reply