12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031 |
- Strict
- Import MaxGUI.MaxGUI
- Import Pub.MacOs
- Import brl.systemdefault
- Import "-framework WebKit"
- Import "cocoa.macos.m"
- Extern
-
- Function bbSystemEmitOSEvent( nsevent:Byte Ptr,nsview:Byte Ptr,source:Object )
-
- Function ScheduleEventDispatch()
-
- Function NSBegin()
- Function NSEnd()
-
- Function NSGetSysColor(colorindex,r:Int Ptr,g:Int Ptr, b:Int Ptr)
- Function NSColorRequester(r,g,b)
- Function NSSetPointer(shape)
-
- Function NSCharWidth(font:Byte Ptr,charcode)
- ' create
- Function NSInitGadget(gadget:TNSGadget)
- ' generic
- Function NSActiveGadget:Byte Ptr()
- Function NSFreeGadget(gadget:TNSGadget)
- Function NSClientWidth(gadget:TNSGadget)
- Function NSClientHeight(gadget:TNSGadget)
- Function NSRethink(gadget:TNSGadget)
- Function NSRedraw(gadget:TNSGadget)
- Function NSActivate(gadget:TNSGadget,code)
- Function NSState(gadget:TNSGadget)
- Function NSShow(gadget:TNSGadget,bool)
- Function NSEnable(gadget:TNSGadget,bool)
- Function NSCheck(gadget:TNSGadget,bool)
- Function NSSetNextView(gadget:TNSGadget,nextgadget:TNSGadget)
- Function NSSetHotKey(gadget:TNSGadget,hotkey,modifier)
- Function NSSetTooltip(gadget:TNSGadget,tip$)
- Function NSGetTooltip$(gadget:TNSGadget)
- Function NSSuperview:Byte Ptr(view:Byte Ptr)
- ' window
- Function NSSetStatus(gadget:TNSGadget,text$,pos)
- Function NSSetMinimumSize(gadget:TNSGadget,width,height)
- Function NSSetMaximumSize(gadget:TNSGadget,width,height)
- Function NSPopupMenu(gadget:TNSGadget,menu:TNSGadget)
- ' font
- Function NSRequestFont:Byte Ptr(font:Byte Ptr)
- Function NSLoadFont:Byte Ptr(name$,size:Double,flags)
- Function NSGetDefaultFont:Byte Ptr()
- Function NSSetFont(gadget:TNSGadget,font:Byte Ptr)
- Function NSFontName$(font:Byte Ptr)
- Function NSFontStyle(font:Byte Ptr)
- Function NSFontSize:Double(font:Byte Ptr)
- ' items
- Function NSClearItems(gadget:TNSGadget)
- Function NSAddItem(gadget:TNSGadget,index,text$,tip$,image:Byte Ptr,extra:Object)
- Function NSSetItem(gadget:TNSGadget,index,text$,tip$,image:Byte Ptr,extra:Object)
- Function NSRemoveItem(gadget:TNSGadget,index)
- Function NSSelectItem(gadget:TNSGadget,index,state)
- Function NSSelectedItem(gadget:TNSGadget,index)
- Function NSSelectedNode:Byte Ptr(gadget:TNSGadget)
- ' text
- Function NSSetText(gadget:TNSGadget,text$)
- Function NSGetText$(gadget:TNSGadget)
- Function NSReplaceText(gadget:TNSGadget,pos,length,text$,units)
- Function NSAddText(gadget:TNSGadget,text$)
- Function NSAreaText$(gadget:TNSGadget,pos,length,units)
- Function NSAreaLen(gadget:TNSGadget,units)
- Function NSLockText(gadget:TNSGadget)
- Function NSUnlockText(gadget:TNSGadget)
- Function NSSetTabs(gadget:TNSGadget,tabwidth)
- Function NSSetMargins(gadget:TNSGadget,leftmargin)
- Function NSSetColor(gadget:TNSGadget,r,g,b)
- Function NSRemoveColor(gadget:TNSGadget)
- Function NSSetAlpha(gadget:TNSGadget,alpha#)
- Function NSSetTextColor(gadget:TNSGadget,r,g,b)
- Function NSGetCursorPos(gadget:TNSGadget,units)
- Function NSGetSelectionlength(gadget:TNSGadget,units)
- Function NSSetStyle(gadget:TNSGadget,r,g,b,flags,pos,length,units)
- Function NSSetSelection(gadget:TNSGadget,pos,length,units)
- Function NSCharAt(gadget:TNSGadget,line)
- Function NSLineAt(gadget:TNSGadget,index)
- Function NSCharX(gadget:TGadget,char)
- Function NSCharY(gadget:TGadget,char)
- ' prop
- Function NSSetValue(gadget:TNSGadget,value#)
- ' slider
- Function NSSetSlider(gadget:TNSGadget,value:Double,small:Double,big:Double)
- Function NSGetSlider:Double(gadget:TNSGadget)
- ' images for panels and nodes
- Function NSPixmapImage:Byte Ptr(image:TPixmap)
- Function NSSetImage(gadget:TNSGadget,nsimage:Byte Ptr,flags)
- Function NSSetIcon(gadget:TNSGadget,nsimage:Byte Ptr)
- Function NSCountKids(gadget:TNSGadget)
- ' html
- Function NSRun$(gadget:TNSGadget,script$)
- ' misc
- Function NSRelease(nsobject:Byte Ptr)
- ' system
- Function NSGetUserName$()
- Function NSGetComputerName$()
-
- EndExtern
- Global GadgetMap:TMap=New TMap
- maxgui_driver=New TCocoaMaxGuiDriver
- Type TCocoaMaxGUIDriver Extends TMaxGUIDriver
-
- Global CocoaGuiFont:TCocoaGuiFont
-
- Method New()
- NSBegin
- atexit_ NSEnd
- If Not CocoaGuiFont Then CocoaGuiFont = TCocoaGuiFont(LibraryFont(GUIFONT_SYSTEM))
- End Method
-
- Method UserName$()
- Return NSGetUserName$()
- End Method
-
- Method ComputerName$()
- Return NSGetComputerName$()
- End Method
-
- Method CreateGadget:TGadget(internalclass,name$,x,y,w,h,group:TGadget,style)
- Local p,hotkey
- If internalclass=GADGET_MENUITEM
- name=name.Replace("&","")
- ElseIf internalclass=GADGET_BUTTON
- p=name.Find("&")
- If p>-1
- ' hotkey=Asc(name[p..p+1]) 'to do - convert and call SetHotKey before return
- name=name[..p]+name[p+1..]
- EndIf
- ElseIf internalclass=GADGET_TOOLBAR
- Global _toolbarcount
- _toolbarcount:+1
- name="Toolbar"+_toolbarcount
- EndIf
- Local gadget:TNSGadget = TNSGadget.Create(internalclass,name,x,y,w,h,TNSGadget(group),style)
- If internalclass<>GADGET_WINDOW And internalclass<>GADGET_MENUITEM And internalclass<>GADGET_DESKTOP
- gadget.SetLayout EDGE_CENTERED,EDGE_CENTERED,EDGE_CENTERED,EDGE_CENTERED
- EndIf
- If group Then gadget._SetParent group
- gadget.SetTextColor(0,0,0)
- gadget.LinkView
- Return gadget
- End Method
-
- Function CreateFont:TGuiFont(handle:Byte Ptr,flags=FONT_NORMAL)
- Local font:TGuiFont = New TCocoaGuiFont
- font.handle = handle
- font.name = NSFontName(handle)
- font.size = NSFontSize(handle)
- font.style = NSFontStyle(handle)|flags
- Return font
- EndFunction
- Method LoadFont:TGuiFont(name$,size,flags)
- Return CreateFont(NSLoadFont(name,Double(size),flags),flags)
- End Method
-
- Method LoadFontWithDouble:TGuiFont(name$,size:Double,flags)
- Return CreateFont(NSLoadFont(name,size,flags),flags)
- End Method
-
- Method LibraryFont:TGuiFont( pFontType% = GUIFONT_SYSTEM, pFontSize:Double = 0, pFontStyle% = FONT_NORMAL )
- If pFontType = GUIFONT_SYSTEM Then
- Local tmpHandle:Byte Ptr = NSGetDefaultFont()
- If pFontSize <= 0 Then pFontSize = NSFontSize(tmpHandle)
- Return LoadFontWithDouble( NSFontName(tmpHandle), pFontSize, NSFontStyle(tmpHandle)|pFontStyle )
- Else
- Return Super.LibraryFont( pFontType, pFontSize, pFontStyle )
- EndIf
- EndMethod
-
- Method LookupColor( colorindex:Int, red:Byte Var, green:Byte Var, blue:Byte Var )
-
- Local r, g, b
-
- If NSGetSysColor( colorindex, Varptr r, Varptr g, Varptr b )
- red = r & $FF
- green = g & $FF
- blue = b & $FF
- Return True
- EndIf
-
- Return Super.LookupColor( colorindex, red, green, blue )
-
- EndMethod
-
- Method RequestColor(r,g,b)
- Return NSColorRequester(r,g,b)
- End Method
-
- Method RequestFont:TGuiFont(font:TGuiFont)
- Local handle:Byte Ptr
- If font handle=font.handle
- handle=NSRequestFont(handle)
- If handle
- If font And handle=font.handle Return font
- Return CreateFont(handle)
- EndIf
- End Method
-
- Method SetPointer(shape)
- NSSetPointer shape
- End Method
-
- Method ActiveGadget:TGadget()
- PollSystem()
- Local handle:Byte Ptr = NSActiveGadget()
- If handle Return GadgetFromHandle(handle)
- End Method
-
- Method LoadIconStrip:TIconStrip(source:Object)
- Return TCocoaIconStrip.Create(source)
- End Method
- End Type
- Function GadgetFromHandle:TNSGadget( handle:Byte Ptr )
- Return TNSGadget( GadgetMap.ValueForKey( TPtrWrapper.Create(handle) ) )
- End Function
- Function EmitCocoaOSEvent( event:Byte Ptr,handle:Byte Ptr,gadget:Object = Null )
- Local owner:TGadget = TGadget(gadget)
- If Not owner Then owner = GadgetFromHandle( handle )
- If owner Then
- While owner.source
- owner = owner.source
- Wend
- EndIf
- bbSystemEmitOSEvent event,handle,owner
- End Function
- Function EmitCocoaMouseEvent( event:Byte Ptr, handle:Byte Ptr )
- Local gadget:TNSGadget
- ' While handle
- gadget = GadgetFromHandle( handle )
- If gadget Then
- If (gadget.sensitivity & SENSITIZE_MOUSE) Then
- EmitCocoaOSEvent( event, handle, gadget )
- Return 1
- EndIf
- Return 0
- EndIf
- ' handle = NSSuperview(handle)
- ' Wend
- End Function
- Function EmitCocoaKeyEvent( event:Byte Ptr, handle:Byte Ptr )
- Local gadget:TNSGadget
- While handle
- gadget = GadgetFromHandle( handle )
- If gadget Then
- If (gadget.sensitivity & SENSITIZE_KEYS) Then
- EmitCocoaOSEvent( event, handle, gadget )
- Return 1
- EndIf
- Return 0
- EndIf
- handle = NSSuperview(handle)
- Wend
- End Function
- ?Not x64
- Function PostCocoaGuiEvent( id,handle:Byte Ptr,data,mods,x,y,extra:Object )
- ?x64
- Function PostCocoaGuiEvent( id,handle:Byte Ptr,data:Long,mods,x,y,extra:Object )
- ?
- 'DebugLog "PostCocoaGuiEvent"
- Local gadget:TNSGadget
-
- DispatchGuiEvents()
-
- If handle Then
-
- gadget = GadgetFromHandle(handle)
-
- If gadget Then
-
- Select gadget.internalclass
- Case GADGET_TREEVIEW
- extra=GadgetFromHandle(data)
- data = 0
- EndSelect
-
- Select id
- Case EVENT_WINDOWSIZE
- If gadget.width <> x Or gadget.height <> y Then
- gadget.SetRect gadget.xpos,gadget.ypos,x,y
- gadget.LayoutKids
- Else
- Return
- EndIf
-
- Case EVENT_WINDOWMOVE
- If gadget.xpos <> x Or gadget.ypos <> y Then
- gadget.SetRect x,y,gadget.width,gadget.height
- Else
- Return
- EndIf
-
- Case EVENT_MENUACTION
- extra=TNSGadget.popupextra
- TNSGadget.popupextra=Null
-
- Case EVENT_GADGETACTION
-
- Select gadget.internalclass
- Case GADGET_SLIDER
- Local oldValue:Int = gadget.GetProp()
- If data Then
- Select (gadget.style&(SLIDER_SCROLLBAR|SLIDER_TRACKBAR|SLIDER_STEPPER))
- Case SLIDER_SCROLLBAR
- If data > 1 Then
- data = gadget.small
- ElseIf data < -1 Then
- data = -gadget.small
- EndIf
- EndSelect
- gadget.SetProp(oldValue+data)
- data=gadget.GetProp()
- If (data = oldValue) Then Return
- Else
- data=gadget.GetProp()
- EndIf
- Case GADGET_LISTBOX, GADGET_COMBOBOX, GADGET_TABBER
- If (data > -1 And data < gadget.items.length) extra=gadget.ItemExtra(data)
- Case GADGET_BUTTON
- Select (gadget.style&7)
- Case BUTTON_CHECKBOX
- If ButtonState(gadget) = CHECK_INDETERMINATE Then SetButtonState(gadget, CHECK_SELECTED )
- Case BUTTON_RADIO
- If (gadget.style&BUTTON_PUSH) Then SetButtonState(gadget,CHECK_SELECTED)
- gadget.ExcludeOthers()
- EndSelect
- data=ButtonState(gadget)
- Case GADGET_TOOLBAR
- If data>-1 Then
- extra=gadget.ItemExtra(data)
- If (gadget.ItemFlags(data)&GADGETITEM_TOGGLE) Then gadget.SelectItem(data,2)
- EndIf
- EndSelect
-
- Case EVENT_GADGETSELECT, EVENT_GADGETMENU
- Select gadget.internalclass
- Case GADGET_LISTBOX, GADGET_COMBOBOX, GADGET_TABBER
- If data>-1 Then extra=gadget.ItemExtra(data)
- EndSelect
-
- Case EVENT_GADGETLOSTFOCUS
-
- QueueGuiEvent id,gadget,data,mods,x,y,extra
- ScheduleEventDispatch()
- Return
-
- EndSelect
- EndIf
-
- EndIf
-
- PostGuiEvent id,gadget,data,mods,x,y,extra
-
- EndFunction
- Function FilterKeyDown( handle:Byte Ptr,key,mods )
- Local source:TNSGadget
- If handle
- source=GadgetFromHandle(handle)
- EndIf
- If source And source.eventfilter<>Null
- Local event:TEvent=CreateEvent(EVENT_KEYDOWN,source,key,mods)
- Return source.eventfilter(event,source.context)
- EndIf
- Return 1
- End Function
- Function FilterChar( handle:Byte Ptr,key,mods )
- Local source:TNSGadget
- Select key
- ' Return true if they are arrow key characters
- Case 63232, 63233, 63234, 63235
- Return 1
- EndSelect
- If handle
- source=GadgetFromHandle(handle)
- EndIf
- If source And source.eventfilter<>Null 'Return source.charfilter(char,mods,source.context)
- Local event:TEvent=CreateEvent(EVENT_KEYCHAR,source,key,mods)
- Return source.eventfilter(event,source.context)
- EndIf
- Return 1
- End Function
- Type TNSGadget Extends TGadget
-
- Field internalclass, origclass 'internalclass: Class the Cocoa driver uses to draw the gadget, origclass: Expected class to be returned by Class() method
- Field handle:Byte Ptr
- Field view:Byte Ptr, textcolor:Byte Ptr 'view: NSView handle, textcolor: NSColor handle for Objective-C code
- Field intFontStyle 'Copy of font.style used by cocoa.macos.m to handle underlining/strikethrough etc. that isn't included in NSFont
- Field pixmap:TPixmap
- Field icons:TCocoaIconStrip
- Field small, big
- Field canvas:TGraphics
- Field font:TCocoaGuiFont
- Field enabled:Int = True, forceDisable:Int = False
- ' main factory command
- Function Create:TNSGadget(internalclass,text$,x,y,w,h,group:TGadget,style)
-
- Local gadget:TNSGadget = New TNSGadget
- gadget.origclass = internalclass
- gadget.internalclass = internalclass
-
- If Not group And internalclass<>GADGET_DESKTOP Then group = Desktop()
- gadget.parent = group
-
- gadget.name = text
- gadget.SetRect x,y,w,h 'setarea
- gadget.style = style
- gadget.font = TCocoaMaxGUIDriver.CocoaGUIFont
-
- If TNSGadget(group) Then
- gadget.forceDisable = Not (TNSGadget(group).enabled And Not TNSGadget(group).forceDisable)
- EndIf
-
- NSInitGadget gadget
- If internalclass<>GADGET_TOOLBAR 'toolbars retain name to key insertgadgetitem
- gadget.name = Null
- EndIf
-
- GadgetMap.Insert TPtrWrapper.Create(gadget.handle),gadget
- If gadget.view And gadget.handle <> gadget.view Then
- GadgetMap.Insert TPtrWrapper.Create(gadget.view),gadget
- EndIf
-
- If internalclass=GADGET_SLIDER Then gadget.SetRange(1,10)
- gadget.LockLayout()
-
- If (internalclass=GADGET_WINDOW) And (style&WINDOW_STATUS) Then
- If (style&WINDOW_CLIENTCOORDS) Then
- gadget.SetMinimumSize(25,0)
- Else
- gadget.SetMinimumSize(25,70)
- EndIf
- EndIf
-
- If LocalizationMode() & LOCALIZATION_OVERRIDE Then LocalizeGadget(gadget,text,"")
-
- gadget.SetEnabled(gadget.enabled)
-
- Return gadget
-
- End Function
-
- Method Class()
- Return origclass
- EndMethod
-
- Function ToView:TNSGadget(value:Object)
- Local view:TNSGadget = TNSGadget(value)
- If Not view Return
- Select view.internalclass
- Case GADGET_DESKTOP,GADGET_WINDOW,GADGET_TOOLBAR,GADGET_LABEL,GADGET_PROGBAR,GADGET_MENUITEM,GADGET_NODE
- Return Null
- End Select
- Return view
- End Function
-
- Method LinkView()
- Local First:TNSGadget
- Local prev:TNSGadget
- Local i,n
- If Not parent Return
- If Not ToView(Self) Return
- n=parent.kids.count()-1
- If n<0 Return
- ' find first view in family
- For i=0 Until n
- First=ToView(parent.kids.ValueAtIndex(i))
- If First Exit
- Next
- If Not First Return
- ' find last view in family
- For i=n-1 To 0 Step -1
- prev=ToView(parent.kids.ValueAtIndex(i))
- If prev Exit
- Next
- If Not prev Return
- NSSetNextView(prev,Self)
- NSSetNextView(Self,First)
- End Method
-
- Method Delete()
- Free()
- End Method
-
- ' generic gadget commands
- Method Query:Byte Ptr(queryid)
- Select queryid
- Case QUERY_NSVIEW
- Return handle
- Case QUERY_NSVIEW_CLIENT
- Return view
- End Select
- End Method
- Method Free()
- If handle Then
-
- If canvas Then canvas.close
-
- GadgetMap.Remove TPtrWrapper.Create(handle)
- If view And handle <> view Then
- GadgetMap.Remove TPtrWrapper.Create(view)
- view = Null
- EndIf
-
- If parent Then
- parent.kids.Remove Self
- End If
-
- NSFreeGadget Self
- font = Null
-
- handle = Null
-
- EndIf
- End Method
- Method Rethink() 'resize - was recursive
- NSRethink( Self )
- End Method
-
- Method ClientWidth()
- Return Max(NSClientWidth(Self),0)
- End Method
-
- Method ClientHeight()
- Return Max(NSClientHeight(Self),0)
- End Method
-
- Method Activate(cmd)
- NSActivate( Self, cmd )
- End Method
-
- Method State()
- Local tmpState:Int = NSState(Self)&~STATE_DISABLED
- If Not enabled Then tmpState:|STATE_DISABLED
- Return tmpState
- End Method
-
- Method SetShow(bool)
- NSShow( Self, bool )
- End Method
- Method SetText(msg$)
- If internalclass=GADGET_HTMLVIEW
- Local anchor$,a
- a=msg.Find("#")
- If a<>-1 anchor=msg[a..];msg=msg[..a]
- If msg[0..7].ToLower()<>"http://" And msg[0..7].ToLower()<>"file://"
- If FileType(msg)
- msg="file://"+msg
- Else
- msg="http://"+msg
- EndIf
- EndIf
- msg:+anchor
- msg=msg.Replace(" ","%20")
- ElseIf internalclass=GADGET_MENUITEM
- msg=msg.Replace("&", "")
- EndIf
- NSSetText Self,msg
- End Method
-
- Method Run$(msg$)
- If internalclass=GADGET_HTMLVIEW Return NSRun(Self,msg)
- End Method
- Method GetText$()
- Return NSGetText(Self)
- End Method
- Method SetFont(pFont:TGuiFont)
- If Not TCocoaGuiFont(pFont) Then pFont = TCocoaMaxGUIDriver.CocoaGuiFont
- font = TCocoaGuiFont(pFont)
- intFontStyle = font.style
- NSSetFont( Self, font.handle )
- End Method
- Method SetColor(r,g,b)
- NSSetColor Self,r,g,b
- End Method
- Method RemoveColor()
- NSRemoveColor Self
- End Method
- Method SetAlpha(alpha#)
- NSSetAlpha Self,alpha
- End Method
-
- Method SetTextColor(r,g,b)
- NSSetTextColor Self,r,g,b
- End Method
-
- Method SetPixmap(pixmap:TPixmap,flags)
- Local nsimage:Byte Ptr, x
- If pixmap
- Select pixmap.format
- Case PF_I8,PF_BGR888
- pixmap=pixmap.Convert( PF_RGB888 )
- Case PF_A8,PF_BGRA8888
- pixmap=pixmap.Convert( PF_RGBA8888 )
- End Select
-
- If AlphaBitsPerPixel[ pixmap.format ]
- For Local y=0 Until pixmap.height
- For x=0 Until pixmap.width
- Local argb=pixmap.ReadPixel( x,y )
- pixmap.WritePixel x,y,premult(argb)
- Next
- Next
- EndIf
- nsimage=NSPixmapImage(pixmap)
- EndIf
- NSSetImage(Self,nsimage,flags)
- End Method
-
- Method SetTooltip(pTip$)
- Select internalclass
- Case GADGET_WINDOW, GADGET_DESKTOP, GADGET_LISTBOX, GADGET_MENUITEM, GADGET_TOOLBAR, GADGET_TABBER, GADGET_NODE
- Default;Return NSSetTooltip( Self, pTip )
- EndSelect
- EndMethod
-
- Method GetTooltip$()
- Select internalclass
- Case GADGET_WINDOW, GADGET_DESKTOP, GADGET_LISTBOX, GADGET_MENUITEM, GADGET_TOOLBAR, GADGET_TABBER, GADGET_NODE
- Default;Return NSGetTooltip( Self )
- EndSelect
- EndMethod
-
- Method ExcludeOthers()
- For Local g:TNSGadget = EachIn parent.kids
- If g<>Self And g.internalclass=GADGET_BUTTON And (g.style&7)=BUTTON_RADIO
- NSCheck g,False
- EndIf
- Next
- End Method
- Method SetSelected(bool)
- NSCheck Self,bool
- If internalclass=GADGET_BUTTON And (style&7)=BUTTON_RADIO And bool
- ExcludeOthers
- EndIf
- End Method
-
- Method SetEnabled(enable)
- Local old:Int = enabled And Not forceDisable
- enabled = enable
- If Class() = GADGET_WINDOW Then
- NSEnable Self, enable
- Else
- enable = enable And Not forceDisable
- NSEnable Self, enable
- If (enable <> old) Then
- For Local tmpGadget:TNSGadget = EachIn kids
- tmpGadget.forceDisable = Not enable
- If tmpGadget.Class() <> GADGET_WINDOW Then tmpGadget.SetEnabled(tmpGadget.enabled)
- Next
- EndIf
- EndIf
- End Method
-
- Method SetHotKey(hotkey,modifier)
- NSSetHotKey Self,hotkey,modifier
- End Method
-
- ' window commands
-
- Field _statustext$
-
- Method GetStatusText$()
- Return _statustext
- EndMethod
-
- Method SetStatusText(msg$)
- Local t,m0$,m1$,m2$
- _statustext = msg
- m0=msg
- t=m0.find("~t");If t<>-1 m1=m0[t+1..];m0=m0[..t];
- t=m1.find("~t");If t<>-1 m2=m1[t+1..];m1=m1[..t];
- NSSetStatus Self,m0,0
- NSSetStatus Self,m1,1
- NSSetStatus Self,m2,2
- End Method
-
- Method GetMenu:TGadget()
- Return Self
- End Method
- Global popupextra:Object
-
- Method PopupMenu(menu:TGadget,extra:Object)
- popupextra=extra
- NSPopupMenu Self,TNSGadget(menu)
- End Method
-
- Method UpdateMenu()
- End Method
-
- Method SetMinimumSize(w,h)
- NSSetMinimumSize Self,w,h
- End Method
-
- Method SetMaximumSize(w,h)
- NSSetMaximumSize Self,w,h
- End Method
- Method SetIconStrip(iconstrip:TIconStrip)
- icons=TCocoaIconStrip(iconstrip)
- End Method
- ' item handling commands
- Method ClearListItems()
- NSClearItems Self
- End Method
- Method InsertListItem(index,item$,tip$,icon,extra:Object)
- Local image:Byte Ptr
- If internalclass=GADGET_TOOLBAR
- item=name+":"+index
- EndIf
- If icons And icon>=0 image=icons.images[icon]
- NSAddItem Self,index,item,tip,image,extra
- End Method
-
- Method SetListItem(index,item$,tip$,icon,extra:Object)
- Local image:Byte Ptr
- If internalclass=GADGET_TOOLBAR
- item=name+":"+index
- EndIf
- If icons And icon>=0 image=icons.images[icon]
- NSSetItem Self,index,item,tip,image,extra
- End Method
-
- Method RemoveListItem(index)
- NSRemoveItem Self,index
- End Method
-
- Method SetListItemState(index,state)
- NSSelectItem Self,index,state
- End Method
-
- Method ListItemState(index)
- Return NSSelectedItem(Self,index)
- End Method
-
- ' treeview commands
- Method RootNode:TGadget()
- Return Self
- End Method
-
- Method SetIcon(icon)
- Local p:TNSGadget
- p=Self
- While p
- If p.icons Exit
- p=TNSGadget(p.parent)
- Wend
- If p
- If icon>-1
- NSSetIcon Self,p.icons.images[icon]
- Else
- NSSetIcon Self,Null
- EndIf
- EndIf
- End Method
-
- Method InsertNode:TGadget(index,text$,icon)
- Local node:TNSGadget = Create(GADGET_NODE,text,0,0,0,0,Self,index)
- node.SetIcon icon
- node._SetParent Self
- Return node
- End Method
-
- Method ModifyNode(text$,icon)
- NSSetText Self,text
- SetIcon icon
- End Method
- Method SelectedNode:TGadget()
- Local index:Byte Ptr = NSSelectedNode(Self)
- If (index) Return GadgetFromHandle(index)
- End Method
- Method CountKids()
- Return NSCountKids(Self)
- End Method
- ' textarea commands
- Method ReplaceText(pos,length,text$,units)
- ?debug
- If pos<0 Or pos+length>AreaLen(units) Throw "Illegal Range"
- ?
- NSReplaceText Self,pos,length,text$,units
- End Method
- Method AddText(text$)
- NSAddText Self,text
- End Method
- Method AreaText$(pos,length,units)
- ?debug
- If pos<0 Or pos+length>AreaLen(units) Throw "Illegal Range"
- ?
- Return NSAreaText(Self,pos,length,units)
- End Method
- Method AreaLen(units)
- Return NSAreaLen(Self,units)
- End Method
- Method LockText()
- NSLockText Self
- End Method
- Method UnlockText()
- NSUnlockText Self
- End Method
- Method SetTabs(tabwidth)
- NSSetTabs Self,tabwidth
- End Method
- Method SetMargins(leftmargin)
- NSSetMargins Self,leftmargin
- End Method
- Method GetCursorPos(units)
- Return NSGetCursorPos(Self,units)
- End Method
- Method GetSelectionLength(units)
- Return NSGetSelectionLength(Self,units)
- End Method
- Method SetStyle(r,g,b,flags,pos,length,units)
- ?debug
- If pos<0 Or pos+length>AreaLen(units) Throw "Illegal Range"
- ?
- If length NSSetStyle Self,r,g,b,flags,pos,length,units
- End Method
- Method SetSelection(pos,length,units)
- ?debug
- If pos<0 Or pos+length>AreaLen(units) Throw "Illegal Range"
- ?
- NSSetSelection Self,pos,length,units
- End Method
- Method CharAt(line)
- ?debug
- If line<0 Or line>AreaLen(TEXTAREA_LINES) Throw "Parameter Out Of Range"
- ?
- Return NSCharAt(Self,line)
- End Method
- Method LineAt(index)
- ?debug
- If index<0 Or index>AreaLen(TEXTAREA_CHARS) Throw "Parameter Out Of Range"
- ?
- Return NSLineAt(Self,index)
- End Method
-
- Method CharX(char)
- Return NSCharX(Self,char)
- EndMethod
-
- Method CharY(char)
- Return NSCharY(Self,char)
- EndMethod
-
- ' progbar
-
- Method SetValue(value#)
- NSSetValue Self,value
- End Method
- ' slider / scrollbar
- Method SetRange(_small,_big)
- small=_small
- big=_big
- NSSetSlider Self,GetProp(),small,big
- End Method
-
- Method SetProp(pos)
- NSSetSlider Self,pos,small,big
- End Method
- Method GetProp()
- Local value:Double = NSGetSlider(Self)
- If Not (style&(SLIDER_TRACKBAR|SLIDER_STEPPER))
- value:*(big-small)
- If value>big-small value=big-small
- EndIf
- Return Int(value+0.5:Double)
- End Method
-
- ' canvas
- Method AttachGraphics:TGraphics( flags )
- canvas=brl.Graphics.AttachGraphics( Query(QUERY_NSVIEW_CLIENT),flags )
- End Method
-
- Method CanvasGraphics:TGraphics()
- Return canvas
- End Method
- End Type
- Type TCocoaIconStrip Extends TIconStrip
-
- Field images:Byte Ptr[]
-
- Function IsNotBlank(pixmap:TPixmap)
- Local y, h = pixmap.height
- Local c = pixmap.ReadPixel(0,0)
- For Local x = 0 Until h
- For y = 0 Until h
- If pixmap.ReadPixel(x,y)<>c Return True
- Next
- Next
- End Function
-
- Function Create:TCocoaIconStrip(source:Object)
- Local icons:TCocoaIconStrip
- Local pixmap:TPixmap,pix:TPixmap
- Local n,x,w
- pixmap=TPixmap(source)
- If Not pixmap pixmap=LoadPixmap(source)
- If Not pixmap Return
- Select pixmap.format
- Case PF_I8,PF_BGR888
- pixmap=pixmap.Convert( PF_RGB888 )
- Case PF_A8,PF_BGRA8888
- pixmap=pixmap.Convert( PF_RGBA8888 )
- End Select
-
- If AlphaBitsPerPixel[ pixmap.format ]
- For Local y=0 Until pixmap.height
- For x=0 Until pixmap.width
- Local argb=pixmap.ReadPixel( x,y )
- pixmap.WritePixel x,y,premult(argb)
- Next
- Next
- EndIf
- n=pixmap.width/pixmap.height;
- If n=0 Return
- icons=New TCocoaIconStrip
- icons.pixmap=pixmap
- icons.count=n
- icons.images=New Byte Ptr[n]
- w=pixmap.width/n
- For x=0 Until n
- pix=pixmap.Window(x*w,0,w,pixmap.height)
- If IsNotBlank(pix) icons.images[x]=NSPixmapImage(pix)
- Next
- Return icons
- EndFunction
-
- EndType
- Type TCocoaGuiFont Extends TGuiFont
-
- Method Delete()
- If handle Then
- NSRelease(handle)
- handle = 0
- EndIf
- EndMethod
-
- Method CharWidth(char)
- If handle
- Return NSCharWidth(handle,char)
- EndIf
- Return 0
- EndMethod
-
- EndType
- Type TPtrWrapper Final
- Field value:Byte Ptr
- Function Create:TPtrWrapper(value:Byte Ptr)
- Local tmpWrapper:TPtrWrapper = New TPtrWrapper
- tmpWrapper.value = value
- Return tmpWrapper
- EndFunction
- Method Compare( o:Object )
- Local c:TPtrWrapper = TPtrWrapper(o)
- If c Then Return (value - c.value)
- Return Super.Compare(o)
- EndMethod
- Method ToString$()
- 'Return value
- EndMethod
- EndType
- Private
- Function premult(argb)
- Local a = ((argb Shr 24) & $FF)
- Return ((((argb&$ff00ff)*a)Shr 8)&$ff00ff)|((((argb&$ff00)*a)Shr 8)&$ff00)|(a Shl 24)
- End Function
|