I have improved my code somehow and post the result. The reference manual tells, that Super doesn't work in the current implementation - you'll see it working quite the way expected:
UKWindow.NSWindow
- Code: Select all
IBOutlet myButton As UKButton
Dim theTimeOut As Double
' we can make the compiler believe, that instances of UKButton
' receives messages that aren't defined in its implementation
' but are part of its parent's vocab
'
Declare Sub "UKButton" - (void)highlight:(BOOL)flag
Declare Function "UKButton" - (NSString *)title
Event Init()
Alert("UKWindow init")
theTimeOut = 8
End Event
' myButton isn't instanciated during the Init() event
' so I chose to use this event, that will surely be
' raised as soon as the window is brought to the
' foreground
Event WindowDidBecomeKey()
myButton.setTimer(theTimeOut)
' message is received by myButton and passed up the chain
' cause myButton doesn't know how to handle it
myButton.highlight(1)
End Event
IBAction ukButtonPressed(sender As id)
' Alert(sender)
' Alert("Button Pressed!")
' Alert(myButton.title())
' myButton.setTimer(theTimeOut)
' using an overrideen message can be fun ;-)
myButton.setTitle("Huhn")
myButton.performClick(myButton)
End IBAction
UKButton.NSButton
- Code: Select all
Private Dim myDuration As Double
Private Dim myTimer As NSTimer
' in order to use Super invocations correctly, we need to introduce
' the needed messages by Declaring them
'
Declare Sub "NSButton" - (void)setEnabled:(BOOL)state
Declare Sub "NSButton" - (void)setTitle:(NSString *)title
Declare Sub "NSButton" - (void)performClick:(id)sender
' standard setter
Public Sub setTimer(theDuration As Double)
myDuration = theDuration
Log("setTimer")
Log(myDuration)
End Sub
' standard getter
Public Function getTimer() As Double
Log("GetTimer")
Log(myDuration)
Return myDuration
End Function
' overriden message, the sent title will never be set
' it is alway overriden to "Title!" - you could do other
' things
Public Sub setTitle(theTitle As String)
Log("The title")
Log(theTitle)
Super.setTitle("Title!")
End Sub
' Overriding action from parent NSButton
' just use the convention presented by Class Reference
'
' the idea is to disable the button until the set duration
' has elapsed
'
Sub performClick(sender As id)
Log("performClick")
Super.setEnabled(0)
myTimer = NSTimer(myDuration)
Super.performClick(sender)
End Sub
' the duration has elapsed, so we can reenable the button
'
Action myTimer()
myTimer.Stop()
Log("time is out!")
Super.setEnabled(1)
End Action
You'll find the complete project attached.
Kind regards
Udo
BTW: It's very hard to upload a project within the board's filesize limit of 256KByte