3 summary:: The basic visible element of GUI
7 The View class is the superclass of all view classes.
9 The view is the basic visible element of which the graphical user interface is composed. It occupies a rectangular space on screen within which it draws itself to display some data or to indicate a mode of interaction between the user and the program. Views receive keyboard and mouse events generated by the user and respond to them by controlling the behavior of the program. They also display information about the state of the program and the data on which it operates.
19 Creates a new instance of View and makes it a child of another View or Window, effectively placing it within the parent's visual space. If there is a link::#-decorator#decorator:: installed on the parent, it will manage the position of the new View.
25 The 'parent' argument may be omitted, in which case the view will be displayed as a window on its own, when link::Classes/QView#-front#shown::.
27 The 'bounds' argument may be omitted, in which case the view will be created with its preferred size at position (0,0).
29 If a parent is given and there is a layout installed on it, the layout will manage the position and size of this view and the 'bounds' argument will have no effect.
33 The instance of View or Window that the new View will become a child of.
36 A Rect or a Point describing size and position of the new View. If a Point is given, its coordinates will denote the view's size, while the view's position will be (0,0). Position is measured relative to the parent's top-left corner.
40 SuperCollider has different GUI kits implementing the same functionality on different platforms. The View's constructor will return an instance of the equivalent class of the currently active GUI kit. See link::Guides/GUI-Introduction:: for detailed explanation.
44 METHOD:: globalKeyDownAction
46 A settable class variable containing an object (e.g. an instance of Function or FunctionList) which is evaluated (i.e. link::Classes/Object#-value#value:: method is called on it) whenever a key is pressed, independently of keyboard focus. See also link::#-addAction::.
48 When the action object is evaluated, it is passed the following arguments: view, char, modifiers, unicode, keycode.
51 METHOD:: globalKeyUpAction
53 A settable class variable containing an object (e.g. an instance of Function or FunctionList) which is evaluated (i.e. link::Classes/Object#-value#value:: method is called on it) whenever a key is released, independently of keyboard focus. See also link::#-addAction::.
55 When the action object is evaluated, it is passed the following arguments: view, char, modifiers, unicode, keycode.
60 A class variable holding the content of the current drag. It is set by beginDrag.
63 METHOD:: currentDragString
65 A class variable holding the content of the current drag as link::Classes/Object#-asCompileString#"compile string"::. It is set by beginDrag.
72 SUBSECTION:: Hierarchy and existence
75 returns:: The view's parent view, or nil if the view is a top view.
78 returns:: An array of all the parents, grandparents, etc., of the view.
81 returns:: Same as link::-parents::.
84 returns:: An array of all immediate children of the view.
87 Removes the view from its parent view (if any) and destroys the view. After this method is called, the view is not usable anymore.
90 Removes all the children of the view and destroys them. After this method is called, the former child views are not usable anymore.
93 note:: only in Qt GUI ::
95 If link::#-deleteOnClose:: is true, this method has the same effect as link::#-remove::, otherwise makes the view invisible.
98 returns:: A Boolean stating whether the view has been destroyed.
101 returns:: A Boolean, the opposite of 'isClosed'.
104 Method that allows compatibility with Window and other classes that are not real subclasses of View, but implement a part of its interface.
108 SUBSECTION:: Visibility
111 Gets or sets wether the view is visible.
115 Making a child view invisible means it does not occupy any space from the standpoint of the layout that contains it, so the layout will distribute the space the view occupied when visible among other views. When the view becomes visible again it is given back the same space.
117 If the view has no parent, setting this to true has the same effect as link::#-front::, and setting it to false closes the window without destroying it.
120 A Boolean stating the visibility of the view.
123 note:: only in Qt GUI ::
124 If the view does not have a parent, displays it on the screen as a window (it has the same effect as setting link::#-visible:: to true), otherwise it has no effect.
127 note:: only in Qt GUI ::
128 If the view is a window, hides it (only keep it present in the dock/taskbar/etc.).
131 note:: only in Qt GUI ::
132 If the view is a window, restores the its previous state after being minimized.
135 note:: only in Qt GUI ::
136 If the view is a window, displays it full-screen.
138 METHOD:: endFullScreen
139 note:: only in Qt GUI ::
140 If the view is a window, restores its previous state after being displayed full-screen.
143 note:: only in Qt GUI ::
145 If the view is a window, gets or sets whether it should always stay on top of other windows.
148 A Boolean stating whether the view should always stay on top.
153 SUBSECTION:: Size and position
157 Gets or sets both the position and the size of the view. The position is relative to the parent view's top-left corner. Some containers, such as HLayoutView and VLayoutView, will use only the width and height of a child view's bounds.
159 The setter takes a Rect or a Point interpreted link::Classes/Point#-asRect#as Rect::. The getter always returns a Rect.
161 METHOD:: absoluteBounds
163 returns:: A Rect describing the absolute position and the size of the view on the screen.
166 note:: only in Qt GUI ::
167 returns:: A Size describing the preferred size of the view to comfortably display its contents and allow useful interaction.
170 note:: only in Qt GUI ::
172 returns:: A Size describing the minimum size of the view to be able to display its contents and allow any interaction.
175 note:: only in Qt GUI ::
176 Set maximum allowed size of the view. The view will not be able to grow larger than this size, neither by user interaction nor programmatically.
182 note:: only in Qt GUI ::
183 Set minimum allowed size of the view. The view will not be able to shrink smaller than this size, neither by user interaction nor programmatically.
190 note:: only in Qt GUI ::
191 Set both minimum and maximum allowed size of the view, thus making it non-resizable.
197 note:: only in Qt GUI ::
198 Set maximum allowed width of the view, the view will not be able to grow larger in width, neither by user interaction nor programmatically.
205 note:: only in Qt GUI ::
206 Set minimum allowed width of the view, the view will not be able to shrink smaller in width, neither by user interaction nor programmatically.
213 note:: only in Qt GUI ::
214 Set maximum allowed height of the view, the view will not be able to grow larger in height, neither by user interaction nor programmatically.
222 note:: only in Qt GUI ::
223 Set minimum allowed height of the view, the view will not be able to shrink smaller in height, neither by user interaction nor programmatically.
229 note:: only in Qt GUI ::
230 Move the view to new position, preserving its size.
233 An Int: the horizontal position of the new position.
236 An Int: the vertical position of the new position.
239 note:: only in Qt GUI ::
240 Resize the view, preserving its position.
243 An Int: the new horizontal size of the view.
246 An Int: the new vertical size of the view.
249 Determines what happens with the view's position and size when its parent is resized. See link::Guides/GUI-Introduction#view:: for further explanation.
252 An Int (1 to 9) defining the auto-resize behavior. See link::Reference/Resize:: for a list of valid resize modes.
255 note:: only in Qt GUI ::
257 Get or set the decorator object, that automatically manages the positioning of new children of the view when they are created. See link::Guides/GUI-Introduction#decorators:: for further explanation.
260 An instance of a decorator class (e.g. FlowLayout).
262 METHOD:: addFlowLayout
263 note:: only in Qt GUI ::
265 A convenience method which sets decorator to a new instance of FlowLayout. See link::Classes/FlowLayout:: for examples.
268 A Point describing the link::Classes/FlowLayout#-margin#margin:: of the FlowLayout.
271 A Point describing the link::Classes/FlowLayout#-gap#gap:: of the FlowLayout.
273 returns:: The new FlowLayout instance.
276 note:: only in Qt GUI ::
278 Creates a FlowView as a child of the view, and then evalutes the object given in the 'func' argument. It is most common to pass a Function for 'func' in which the FlowView is filled with other child views.
281 The object that will be evaluated after the creation of the FlowView, passing the new FlowView instance as an argument.
284 A Rect to set as the bounds of the FlowView, or nil, implying the size of this view and position (0,0).
286 After 'func' is evaluated, the FlowView will be resized to fit its contents and cast away any extra space it occupies.
288 returns:: The new FlowView instance.
291 note:: only in Qt GUI ::
293 Get or set the layout object, that automatically manages the position and the size of the children of the view dynamically, in relation to the view's size. See link::Guides/GUI-Introduction#layouts:: for further explanation.
296 An instance of a subclass of QLayout.
302 note:: only in Qt GUI ::
304 Map a point relative to this view's top-left to absolute position on screen.
307 A Point describing a position relative to the view.
310 A Point describing the same position, but relative to the screen.
313 SUBSECTION:: Appearance
316 note:: only in Qt GUI ::
318 If the view is a window, sets its title
321 A String containing text for the window title.
325 note:: only in Qt GUI ::
327 If the view is a window, this controls its transparency.
330 A Float between 0.0 (invisible) and 1.0 (opaque).
333 note:: Only in Qt every view has this method. In other GUI kits, only some views have it. ::
334 The font used by the view to display text (if any).
341 Get or set the color of whatever is considered the background of the view.
348 Get or set the color used to display keyboard focus on the view.
354 Redraws the view and all its children.
357 SUBSECTION:: Common behavior
360 METHOD:: userCanClose
361 note:: only in Qt GUI ::
363 If the view is a window, sets or gets whether the user can close it via mouse or key actions.
369 METHOD:: deleteOnClose
370 note:: only in Qt GUI ::
372 Sets or gets whether the view should be destroyed when closed.
378 Sets or gets whether the view allows the user to interact with it. Usually, when a view is disabled it will be displayed differently (typically it will be greyed out).
385 Sets or gets whether the view can receive keyboard focus.
391 If 'flag' is true, gives keyboard focus to the view (if possible), otherwise removes the keayboard focus from it.
398 returns:: A Boolean, stating whether the view currently has the keyboard focus.
403 SUBSECTION:: Actions in general
406 Gets or sets the default action of the view, i.e. the object to be evaluated when the user interacts with the view in an essential way (e.g. a Button is clicked, a ListView item is selected, etc.).
409 Any object to set as default action, usually a Function or a FunctionList. When evaluated, it will be passed the view as an argument.
413 Evaluates the default link::#-action#action::.
417 METHOD:: removeAction
419 Adds/removes 'func' to or from the list of objects in the variable determined by 'selector'. If 'selector' is not an Array or a List, it will become one, containing the previous object plus 'func'.
421 This is useful for adding functionality to existing frameworks that have action functions already.
424 Any object to add as an action, usually a Function.
427 A Symbol containing the name of the action variable to which 'func' will be added. In other words, 'add' method will be invoked on that variable; by default that is \action, but any other (sensible) instance or class variable of the view could work (e.g. \globalKeyDownAction or \mouseUpAction or \onClose, etc.). See the other action variables below.
432 SUBSECTION:: Mouse actions
434 Use the methods below to set or get the view's actions in response to mouse interaction with the view. A view must be enabled for the mouse actions to work.
436 When the action object is evaluated, it is passed one or more arguments from the following list (in that order):
439 ## strong::view:: - the view
440 ## strong::x:: - the x coordinate
441 ## strong::y:: - the y coordinate
442 ## strong::modifiers:: - A bitwise or of integers indicating the modifier keys in effect. For a list of these, see link::Reference/Modifiers::.
443 ## strong::buttonNumber:: - 0-left, 1-right, 2-middle, etc.
444 ## strong::clickCount:: - the number of clicks within the system click time limit. At least 1.
447 METHOD:: mouseDownAction
448 Sets or gets the object to be evaluated when a mouse button is pressed on the view.
450 It is passed the following arguments: view, x, y, modifiers, buttonNumber, clickCount.
452 METHOD:: mouseUpAction
453 Sets or gets the object to be evaluated when a mouse button is released after it was pressed on the view.
455 It is passed the following arguments: view, x, y, modifiers.
457 METHOD:: mouseMoveAction
458 Sets or gets the object to be evaluated whenever the mouse pointer moves after a mouse button was pressed on the view.
460 It is passed the following arguments: view, x, y, modifiers.
462 METHOD:: mouseOverAction
463 Sets or gets the object to be evaluated when the mouse pointer enters the view.
465 It is passed the following arguments: view, x, y.
467 METHOD:: mouseLeaveAction
468 note:: strong:: Only in Qt GUI :: ::
470 Sets or gets the object to be evaluated when the mouse pointer leaves the view.
472 It is passed the following arguments: view, x, y.
475 SUBSECTION:: Key actions
477 Use the methods below to set or get the view's actions in response to keyboard interaction when the view has the keyboard focus.
479 If evaluating the action object returns nil, or there is no action set, keyboard event will propagate up to the parent view which may then respond and trigger its actions. On the same condition, it will continue to propagate up unless some view responds or it hits the top of the view hierarchy. You may register an action on the Window's top view to respond to all unhandled keyboard events for the window.
482 In Qt GUI, event propagation works differently. After handling a key event within SuperCollider language, the event processing continues in the Qt implementation of the view, and if it is not handled there it propagates to the parent view. If you want to have control over key event propagation, you can return true or false from key actions (meaning that the event was handled and will not propagate, or converse), but note that this will also prevent the Qt view implementation to respond to the key event.
485 When the action object is evaluated, it is passed one or more arguments from the following list (in that order):
488 ## strong::view:: - The view.
490 ## strong::char:: - The character associated with the key, possibly unprintable. Character sequences (for example é) get passed as two characters, the first one blank ( ), the second one is the unmodified character (e). This will also vary depending on the nationality the keyboard is set to. note:: In Qt GUI only printable characters are passed. If a key is not associated with any printable character, nil will be passed instead.::
492 ## strong::modifiers:: - A bitwise or of integers indicating the modifier keys in effect. You can examine individual flag settings using the C bitwise AND operator. For a list of these, see link::Reference/Modifiers::.
494 ## strong::unicode:: - The Integer unicode number associated with the 'char' passed.
496 ## strong::keycode:: - The hardware dependent keycode indicating the physical key. This will vary from machine to machine, but is useful for building musical interfaces using the computer keyboard. warning::Function key modifier in combination with another key may change the latter's keycode.::
500 In Cocoa GUI, for various reasons the following key events don't make it through to SuperCollider:
502 ## most command modifiers
505 ## tab and shift tab are currently trapped by SC itself for cycling the focus through the views.
510 METHOD:: keyDownAction
511 Sets or gets the object to be evaluated when a key is pressed.
513 It is passed the following arguments: strong::view, char, modifiers, unicode, keycode::.
516 Sets or gets the object to be evaluated when a key is released.
518 It is passed the following arguments: strong::view, char, modifiers, unicode, keycode::.
520 METHOD:: keyModifiersChangedAction
521 Sets or gets the object to be evaluated when a modifier key is pressed or released.
523 It is passed the following arguments: strong::view, modifiers::.
526 SUBSECTION:: Drag and drop
528 Use the methods below to define or override how the view handles drag&drop operations.
530 METHOD:: beginDragAction
531 Sets or gets the object evaluated when a drag&drop operation is initiated.
533 At evaluation, the following arguments will be passed: strong:: view, x, y ::. The view expects an object to be returned which will become the data subject to the drag&drop operation. Returning nil will prevent the drag&drop operation to begin.
535 If this variable is nil (the default) the view's link::#-defaultGetDrag:: method is called instead.
537 METHOD:: canReceiveDragHandler
538 Sets or gets the object evaluated when the mouse pointer moves over the view while a drag&drop operation is taking place.
540 At evaluation, the following arguments will be passed: strong:: view, x, y ::. The view expects the link::#*currentDrag#drag&drop data:: to be examined, and a Boolean returned stating whether the view can make use of that data. If true is returned, the data may be dropped on the view, otherwise the drop event will not be handled by this view.
542 If this variable is nil (the default) the view's link::#-defaultCanReceiveDrag:: method is called instead.
544 METHOD:: receiveDragHandler
545 Sets or gets the object evaluated when a drag&drop operation finishes on this view.
547 At evaluation, the following arguments will be passed: strong:: view, x, y ::. The link::#*currentDrag#drag&drop data:: is expected to be applied to the view in some way.
549 If this variable is nil (the default) the view's link::#-defaultReceiveDrag:: method is called instead.
553 Sets or gets the text displayed by the mouse pointer during the drag&drop operation. It is expected to be set while handling the beginning of the operation, i.e. in link::#-beginDragAction:: or link::#-defaultGetDrag::.
556 A String containing the text to be displayed.
561 SUBSECTION:: Other actions and hooks
563 METHOD:: focusGainedAction
564 note:: only in Qt and SwingOSC GUI::
566 Sets or gets the object to be evaluated when the view gains the keyboard focus. It is passed the view as an argument.
568 METHOD:: focusLostAction
569 note:: only in Qt and SwingOSC GUI::
571 Sets or gets the object to be evaluated when the view looses the keyboard focus. It is passed the view as an argument.
573 METHOD:: toFrontAction
574 note:: only in Qt GUI ::
576 Sets or gets the object to be evaluated when the view becomes the active window. It is passed the view as an argument.
578 METHOD:: endFrontAction
579 note:: only in Qt GUI ::
581 Sets or gets the object to be evaluated when the view becomes the active window. It is passed the view as an argument.
585 Sets or gets the object to be evaluated when the view is destroyed (i.e. link::#-close#closed:: or link::#-remove#removed::). It is passed the view as an argument.
590 SUBSECTION:: Subclassing
592 The following methods are the default handlers of key press and release events. When subclassing, override them to implement custom functionality. Many view classes in the standard library do that.
594 METHOD:: defaultKeyDownAction
596 The method called when a key is pressed and link::#-keyDownAction:: is nil. Subclass it to define your own functionality on key-press.
598 See link::#key_actions#Key actions :: for explanation of arguments.
600 returns:: nil, if the key event is not handled by the view, which will propagated it to the parent.
602 METHOD:: defaultKeyUpAction
604 The method called when a key is released and link::#-keyUpAction:: is nil. Subclass it to define your own functionality on key-release.
606 See link::#key_actions#Key actions :: for explanation of arguments.
608 returns:: nil, if the key event is not handled by the view, which will propagated it to the parent.
612 Handles response to a key press event. First evaluates link::#*globalKeyDownAction::, then calls link::#-handleKeyDownBubbling::.
615 In Qt GUI, instead of calling link::#-handleKeyDownBubbling::, this method directly triggers the action and returns, forwarding the action's return value. See link::#key_actions#Key Actions :: for detailed explanation.
618 See link::#key_actions#Key actions :: for explanation of arguments.
620 returns:: strong:: Only in Qt GUI: :: A Boolean, stating whether the event was handled or not (and will not or will propagate to the parent view, respectively), or the view, in which case it lets the Qt view implementation handle the event.
624 Handles response to a key release event. Sets link::#-keyTyped:: to 'char', evaluates link::#*globalKeyUpAction::, and then calls link::#-handleKeyUpBubbling::.
627 In Qt GUI, instead of calling link::#-handleKeyUpBubbling::, this method directly triggers the action and returns, forwarding the action's return value. See link::#key_actions#Key Actions :: for detailed explanation.
630 See link::#key_actions#Key actions :: for explanation of arguments.
632 returns:: strong:: Only in Qt GUI: :: A Boolean, stating whether the event was handled or not (and will not or will propagate to the parent view, respectively), or the view, in which case it lets the Qt view implementation handle the event.
634 METHOD:: keyModifiersChanged
635 Handles response to a modifier key press or release event. Calls link::#-handleKeyModifiersChangedBubbling::.
638 In Qt GUI, instead of calling link::#-handleKeyModifiersChangedBubbling::, a modifier key press or release event also produces a normal key press or release event, and it is the handling of those events that will determine propagation to the parent.
641 See link::#key_actions#Key actions :: for explanation of arguments.
643 METHOD:: handleKeyDownBubbling
644 note:: Only in Cocoa and SwingOSC GUI ::
645 Triggers key-down action and propagates the key event to the parent view, if the action returns nil.
647 METHOD:: handleKeyUpBubbling
648 note:: Only in Cocoa and SwingOSC GUI ::
649 Triggers key-up action and propagates the key event to the parent view, if the action returns nil.
651 METHOD:: handleKeyModifiersChangedBubbling
652 note:: Only in Cocoa and SwingOSC GUI ::
653 Triggers key-modifiers-changed action and propagates the key event to the parent view, if the action returns nil.
657 An instance variable containing the key just typed (after it is released).
662 Handles response to a mouse button press event. Evaluates link::#-mouseDownAction::.
664 See link::#mouse_actions#Mouse actions :: for explanation of arguments.
667 Handles response to a mouse button release event. Evaluates link::#-mouseDownAction::.
669 See link::#mouse_actions#Mouse actions :: for explanation of arguments.
672 Handles response to mouse pointer moving over the view after a mouse button has been pressed. Evaluates link::#-mouseMoveAction::.
674 See link::#mouse_actions#Mouse actions :: for explanation of arguments.
677 Handles response to mouse pointer entering the view. Evaluates link::#-mouseOverAction::.
679 See link::#mouse_actions#Mouse actions :: for explanation of arguments.
682 note:: strong:: Only in Qt GUI :: ::
684 Handles response to mouse pointer leaving the view. Evaluates link::#-mouseLeaveAction::.
686 See link::#mouse_actions#Mouse actions :: for explanation of arguments.
690 METHOD:: defaultGetDrag
692 The view's default method to determine the content of the drag&drop operation just initiated.
694 returns:: The object to be set as link::#*currentDrag::. If nil is returned, the drag&drop operation will not begin.
696 METHOD:: defaultCanReceiveDrag
698 The view's default evaluation whether the content of the ongoing drag&drop operation can be accepted.
700 returns:: A Boolean stating whether link::#*currentDrag:: is useful. If false is returned, the drop will not be handled by this view.
702 METHOD:: defaultReceiveDrag
704 The view's default handling of the data dropped on it (stored in link::#*currentDrag::).
707 Handles initiation of a drag&drop operation. Evaluates link::#-beginDragAction:: or calls link::#-defaultGetDrag:: if the former is nil, then stores the object returned into link::#*currentDrag::, and the object interpreted as link::Classes/Object#-asCompileString#"compile string":: into link::#*currentDragString::. Returns whether link::#*currentDrag:: is not nil.
709 note:: The description of arguments and return value is valid strong:: only for Qt GUI: ::. In other GUI kits this method has no arguments and its return value is insignificant. ::
712 Current horizontal position of the mouse pointer.
715 Current vertical position of the mouse pointer.
717 returns:: A Boolean stating whether the drag&drop operation shall begin.
719 METHOD:: canReceiveDrag
720 Handles evaluation whether the view can accept the current drag&drop data. Evaluates link::#-canReceiveDragHandler:: or calls link::#-defaultCanReceiveDrag:: if the former is nil, then forwards the return value.
722 note:: The description of arguments is valid strong:: only for Qt GUI: ::. In other GUI kits this method has no arguments. ::
725 Current horizontal position of the mouse pointer.
728 Current vertical position of the mouse pointer.
730 returns:: A Boolean stating whether the current drag&drop content can be dropped on the view.
733 Handles the end of the drag&drop operation. Evaluates link::#-receiveDragHandler:: or calls link::#-defaultReceiveDrag:: if the former is nil, then sets link::#*currentDrag:: and link::#*currentDragString:: to nil.
736 Current horizontal position of the mouse pointer.
739 Current vertical position of the mouse pointer.