Transparent TextArea

Hi,

In a TextArea, I have the following declares in the .Open event to make it transparent.

Declare Sub setDrawBack Lib "Cocoa" selector "setDrawsBackground:"(id As Integer, b As Boolean)
Declare Function docView Lib "Cocoa" selector "documentView"(id As Integer) As Integer
setDrawBack(Me.Handle, False)
setDrawBack(docView(Me.Handle), False)

…that works and looks good.
However, a while ago, I found out that when on an iMac without a trackpad, the Scrollbar isn’t transparent.

In the below .gif you’ll see what I mean. It changes a few seconds after I switch off my trackpad.

Does anyone know a way how I can adjust my declares so this doesn’t happen?

I think this is an OS X thing. It is only transparent when a trackpad or a mouse is attached to the computer. Without a pointing device the user has no way to get the information from the scroller (in that case, how long the text is).

On my MacBook I can go to System Preferences –> Accessibility and turn the trackpad off and the same thing happens.

Well, I forgot to mention that the mouse is still there.
I use both a regular logitech mouse and a trackpad. When I switch off my trackpad, the mouse is still active but it flips.

An iMac doesn’t come with a trackpad nowadays does it? I can’t remember.
So basically everyone with an iMac but without a trackpad sees the non-transparent Scrollbar?

There is a declare to prevent this from happening I believe.

    soft declare sub setScrollerStyle   lib "AppKit" selector "setScrollerStyle:" (obj as ptr,val as integer)

enum {
   NSScrollerStyleLegacy       = 0,
   NSScrollerStyleOverlay      = 1
};

With the Magic Mouse the scrollbar is transparent. But yet, it is sort of a trackpad within a mouse.

However, with an ordinary mouse, the white scrollbar shows up right away.

Does not seem to work here.

You could cover the scrollbar by placing the TextArea on a ContainerControl and set the scrollbar area off-container.

But then there will be no scrollbar at all. Not a problem with mice that have a wheel, though.

BTW, thank you for the declare. Neat :slight_smile:

@Richard Thank you but unfortunately, it doesn’t make any difference. :confused:

@Michel. Great suggestion on the container. And good to know about the magic mouse. I wasn’t aware of that. Thanks

My bad. You have to override isCompatibleWithOverlayScrollers to return true.

I’m sorry for being such a Declare novice but how can I do this override?

The complete code would be better.

I’m a declare novice myself and sorry for being cryptic, but the source code I have for this is not for me to share.

Although if you check the NSScrollview / Other suggestions thread/project, the declare follows the same concept as the isFlipped one.

You can disable the “Scroller Slot” drawing app-wide by modifying the Cocoa NSScroller Class.
If you want to disable it for specific controls, you would create a subclass of NSScroller (that overrides drawKnobSlotInRect:highlight:) and set an instance of the subclass as verticalScroller and horizontalScroller on each control. Somewhat more involved, but I can post a snippet here also if you like.

For this code, “drawknobslotinrect()” is a global method that does nothing, just to prevent drawing the background “slot”.

declare function NSClassFromString lib "Foundation" (classname as CFStringRef) as ptr declare function NSSelectorFromString lib "Foundation" (aSelectorName as CFStringRef) as Ptr declare function class_replaceMethod lib "/usr/lib/libobjc.dylib" (cls as ptr, name as Ptr, imp as Ptr, types as CString) as ptr call class_replaceMethod(NSClassFromString("NSScroller"),NSSelectorFromString("drawKnobSlotInRect:highlight:"),addressof drawknobslotinrect,"")

SOP - mess with it and you’ll may upset users. My wife prefers to see the scrollbars all the time. That’s how she rolls on her Mac.

Don’t forget that Apple has a system wide preference for this and you should respect it, even if it’s just to conform with the other applications that do.

Anyhoe, just my 2¢

[quote=238235:@Sam Rowlands]SOP - mess with it and you’ll may upset users. My wife prefers to see the scrollbars all the time. That’s how she rolls on her Mac.

Don’t forget that Apple has a system wide preference for this and you should respect it, even if it’s just to conform with the other applications that do.

Anyhoe, just my 2¢[/quote]

Agreed. I also keep scrollbars visible all the time and would find an app that unconditionally hides them to be frustrating.

Not sure it is feasible, but showing them only when the cursor gets to the right of the control or when the wheel is moved would be very nice.

[quote=238257:@Joe Ranieri]Agreed. I also keep scrollbars visible all the time and would find an app that unconditionally hides them to be frustrating.

[/quote]
I would too, but we’re not hiding the scrollers here…

[quote=238273:@Michel Bujardet]Not sure it is feasible, but showing them only when the cursor gets to the right of the control or when the wheel is moved would be very nice.

[/quote]

That might be more confusing to the user…

Here is code that will draw the tracks in a translucent manner that flows with the look OP was going for, but still follows Apple’s HIG.
Seems like a better idea than simply obliterating the drawing all together.

(to be placed in a module, NOT as a method in a window)

[code]Sub drawKnobSlotInRect(obj as ptr, sel as ptr, rect as cgrect, highlight as Boolean)

Declare function NSClassFromString lib “Foundation” (classname as CFStringRef) as ptr
Declare Function colorWithWhitealpha Lib “AppKit” selector “colorWithWhite:alpha:” _
(classref As ptr,white as CGFloat,alpha as CGFloat) As ptr
Declare sub fillRect Lib “AppKit” selector “fillRect:” (classref As ptr,rect as cgrect)
Declare sub set Lib “AppKit” selector “set” (obj As ptr)

set(colorWithWhitealpha( NSClassFromString(“NSColor”) , 1.0 , 0.3))
fillRect(NSClassFromString(“NSBezierPath”) , rect)

End Sub
[/code]
This is companion code to be used with what I posted previously.

Xojo complains there is no cgrect type…

Also, what is sel ? How do you set rect ?

You’ll need to add cgrect as a structure. It contains a cgpoint structure (origin) and a cgsize structure (size)

CGPoint{ x as cgfloat y as cgfloat }

CGRect{ o as CGPoint s as CGSize }

CGSize{ width as cgfloat Height as cgfloat }

[quote=238291:@jim mckay]Here is code that will draw the tracks in a translucent manner that flows with the look OP was going for, but still follows Apple’s HIG.
Seems like a better idea than simply obliterating the drawing all together.[/quote]
Wouldn’t it better to use either the correct color or to draw the actual slider track. White may work for Aqua appearance, but it will not work in dark Aqua, or any other Aqua that Apple might invent in the next few months.

I’m not sure what you mean. Marco was trying to eliminate the odd appearance of the opaque slider track. The code above just draws the slider track translucent so it works better with his dark background textarea. Not sure what you mean by “Dark Aqua”…