Xojo Conferences
XDCMay2019MiamiUSA

Platforms to show: All Mac Windows Linux Cross-Platform

/MacFrameworks/Cocoa Controls/NSComboBox Example
Function:
Required plugins for this example: MBS MacBase Plugin, MBS MacCocoa Plugin, MBS MacControls Plugin, MBS MacFrameworks Plugin, MBS Main Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacFrameworks/Cocoa Controls/NSComboBox Example
This example is the version from Sat, 20th Jul 2012.
Project "NSComboBox Example.rbp"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
EventHandler Sub Open() ' Set the application to AutoQuit, ' so if all windows are closed then the application will quit. autoQuit = True #if not TargetMacOS then MsgBox "For MacOS X only" Quit #endif End EventHandler
End Class
Class Window1 Inherits Window
Control CocoaControlMBS1 Inherits CocoaControlMBS
ControlInstance CocoaControlMBS1 Inherits CocoaControlMBS
EventHandler Function GetView() As NSViewMBS dim t as new myComboBoxMBS(20, 20, 100, 20) cbOne = t cbOne.list = listbox1 'cbOne.isButtonBordered=true cbOne.addItemWithObjectValue("Jan") cbOne.addItemWithObjectValue("Feb") cbOne.addItemWithObjectValue("Mar") cbOne.addItemWithObjectValue("Apr") cbOne.addItemWithObjectValue("May") cbOne.addItemWithObjectValue("Jun") cbOne.addItemWithObjectValue("Jul") cbOne.addItemWithObjectValue("Aug") cbOne.addItemWithObjectValue("Sep") cbOne.addItemWithObjectValue("Oct") cbOne.addItemWithObjectValue("Nov") cbOne.addItemWithObjectValue("Dec") Return cbOne End EventHandler
End Control
Control la1 Inherits Label
ControlInstance la1(0) Inherits Label
ControlInstance la1(1) Inherits Label
ControlInstance la1(2) Inherits Label
ControlInstance la1(3) Inherits Label
ControlInstance la1(4) Inherits Label
ControlInstance la1(5) Inherits Label
End Control
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action() 'Function: Creates a new button with size 100/100 and position 0/0 'NSComboBoxMBS.Constructor '''''''''' see GetView 'Function: Adds an object to the end of the receiver’s internal item list. 'NSComboBoxMBS.addItemWithObjectValue(value as variant) '''''''''' see GetView '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' get the index of the selected item 'NSComboBoxMBS.indexOfSelectedItem as integer la1(0).text = "Selected Item " + cstr(cbOne.indexOfSelectedItem) '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' get the index of the match item 'NSComboBoxMBS.indexOfItemWithObjectValue(value as variant) as integer la1(1).text = "Index of Match 'Jun' :" + cstr(cbOne.indexOfItemWithObjectValue("Jun") ) '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 'Returns the total number of items in the pop-up list. 'NSComboBoxMBS.numberOfItems as integer la1(2).text = "Number of item: " + cstr(cbOne.numberOfItems ) '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 'Returns the maximum number of items visible in the pop-up list 'NSComboBoxMBS.numberOfVisibleItems as integer la1(3).text = "Number of item visible: " + cstr( cbOne.numberOfVisibleItems ) 'return the selected item value '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' la1(4).text = "Value of item Selected: " + cbOne.StringValue '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' la1(5).text = "" '//////////// rest of function are not demostrated <<<<<<<<<<<<<<<<< 'Function: Returns a Boolean value indicating whether the receiver tries to complete what the user types in the text field. 'NSComboBoxMBS.completes as boolean 'Function: Deselects the pop-up list item at the specified index if it’s selected. 'index: The index of the item to deselect. 'NSComboBoxMBS.deselectItemAtIndex(index as integer) 'Function: Returns a Boolean value indicating whether the receiver will display a vertical scroller. 'NSComboBoxMBS.hasVerticalScroller as boolean 'Returns the space between cells in the pop-up list. The default spacing is (3.0, 2.0). 'NSComboBoxMBS.intercellSpacing as NSSizeMBS 'True if the button has a border; otherwise false. 'NSComboBoxMBS.isButtonBordered as boolean 'Returns the height of each item in the receiver’s pop-up list. The default item height is 16.0. 'NSComboBoxMBS.itemHeight as double 'Informs the receiver that the number of items in its data source has changed. 'NSComboBoxMBS.noteNumberOfItemsChanged 'Function: Marks the receiver as needing redisplay, so that it will reload the data for visible pop-up items and draw the new values. 'NSComboBoxMBS.reloadData 'Function: Removes all items from the receiver’s internal item list. 'NSComboBoxMBS.removeAllItems 'Function: Removes the object at the specified location from the receiver’s internal item list. 'NSComboBoxMBS.removeItemAtIndex(index as integer) 'Function: Removes all occurrences of the given object from the receiver’s internal item list. 'NSComboBoxMBS.removeItemWithObjectValue(value as variant) 'Function: Scrolls the receiver’s pop-up list vertically so that the item at the specified index is as close to the top as possible. 'NSComboBoxMBS.scrollItemAtIndexToTop(index as integer) 'Function: Scrolls the receiver’s pop-up list vertically so that the item at the specified index is visible. 'NSComboBoxMBS.scrollItemAtIndexToVisible(index as integer) 'Function: Selects the pop-up list row at the given index. 'NSComboBoxMBS.selectItemAtIndex(index as integer) 'Function: Selects the first pop-up list item that corresponds to the given object. 'NSComboBoxMBS.selectItemWithObjectValue(value as variant) 'Function: A Boolean value indicating whether the receiver uses an external data source to populate its pop-up list. 'NSComboBoxMBS.usesDataSource as boolean End EventHandler
End Control
Control Listbox1 Inherits Listbox
ControlInstance Listbox1 Inherits Listbox
End Control
Control CheckBox1 Inherits CheckBox
ControlInstance CheckBox1 Inherits CheckBox
EventHandler Sub Action() cbOne.completes = me.Value End EventHandler
End Control
Property cbOne As myComboBoxMBS
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "Select &All"
End MenuBar
Class myComboBoxMBS Inherits NSComboBoxMBS
EventHandler Sub Action() if list<>Nil then list.InsertRow 0, "Action event: "+me.StringValue end if End EventHandler
EventHandler Function textShouldBeginEditing(fieldEditor as NSTextMBS) As boolean if list<>Nil then list.InsertRow 0, "textShouldBeginEditing event: "+me.StringValue end if Return true End EventHandler
EventHandler Function textShouldEndEditing(fieldEditor as NSTextMBS) As boolean if list<>Nil then list.InsertRow 0, "textShouldEndEditing event: "+me.StringValue end if Return true End EventHandler
Property Changed As Boolean
Property list As listbox
End Class
End Project

See also:

Feedback, Comments & Corrections

The items on this page are in the following plugins: MBS MacFrameworks Plugin.




Links
MBS Xojo PDF Plugins