void updateButtonUnderMouse (const MouseEvent& e) { TreeViewItem* newItem = 0; if (owner.openCloseButtonsVisible) { Rectangle<int> pos; TreeViewItem* item = findItemAt (e.y, pos); if (item != 0 && e.x < pos.getX() && e.x >= pos.getX() - owner.getIndentSize()) { newItem = item; if (! newItem->mightContainSubItems()) newItem = 0; } } if (buttonUnderMouse != newItem) { if (buttonUnderMouse != 0 && containsItem (buttonUnderMouse)) { const Rectangle<int> r (buttonUnderMouse->getItemPosition (false)); repaint (0, r.getY(), r.getX(), buttonUnderMouse->getItemHeight()); } buttonUnderMouse = newItem; if (buttonUnderMouse != 0) { const Rectangle<int> r (buttonUnderMouse->getItemPosition (false)); repaint (0, r.getY(), r.getX(), buttonUnderMouse->getItemHeight()); } } }
void MenuSystem::handleMouseMove(int x, int y) { if (!_editingDescription) { ItemID newItemID = findItemAt(x, y); if (_currItemID != newItemID) { leaveItem(_currItemID); _currItemID = newItemID; enterItem(newItemID); } } }
const String getTooltip() { Rectangle<int> pos; TreeViewItem* const item = findItemAt (getMouseXYRelative().getY(), pos); if (item != 0) return item->getTooltip(); return owner.getTooltip(); }
void mouseDoubleClick (const MouseEvent& e) { if (e.getNumberOfClicks() != 3) // ignore triple clicks { Rectangle<int> pos; TreeViewItem* const item = findItemAt (e.y, pos); if (item != 0 && (e.x >= pos.getX() || ! owner.openCloseButtonsVisible)) item->itemDoubleClicked (e.withNewPosition (e.getPosition() - pos.getPosition())); } }
void mouseUp (const MouseEvent& e) { updateButtonUnderMouse (e); if (needSelectionOnMouseUp && e.mouseWasClicked()) { Rectangle<int> pos; TreeViewItem* const item = findItemAt (e.y, pos); if (item != 0) selectBasedOnModifiers (item, e.mods); } }
void mouseDrag (const MouseEvent& e) { if (isEnabled() && ! (isDragging || e.mouseWasClicked() || e.getDistanceFromDragStart() < 5 || e.mods.isPopupMenu())) { isDragging = true; Rectangle<int> pos; TreeViewItem* const item = findItemAt (e.getMouseDownY(), pos); if (item != 0 && e.getMouseDownX() >= pos.getX()) { const String dragDescription (item->getDragSourceDescription()); if (dragDescription.isNotEmpty()) { DragAndDropContainer* const dragContainer = DragAndDropContainer::findParentDragContainerFor (this); if (dragContainer != 0) { pos.setSize (pos.getWidth(), item->itemHeight); Image dragImage (Component::createComponentSnapshot (pos, true)); dragImage.multiplyAllAlphas (0.6f); Point<int> imageOffset (pos.getPosition() - e.getPosition()); dragContainer->startDragging (dragDescription, &owner, dragImage, true, &imageOffset); } else { // to be able to do a drag-and-drop operation, the treeview needs to // be inside a component which is also a DragAndDropContainer. jassertfalse; } } } } }
void mouseDown (const MouseEvent& e) { updateButtonUnderMouse (e); isDragging = false; needSelectionOnMouseUp = false; Rectangle<int> pos; TreeViewItem* const item = findItemAt (e.y, pos); if (item == 0) return; // (if the open/close buttons are hidden, we'll treat clicks to the left of the item // as selection clicks) if (e.x < pos.getX() && owner.openCloseButtonsVisible) { if (e.x >= pos.getX() - owner.getIndentSize()) item->setOpen (! item->isOpen()); // (clicks to the left of an open/close button are ignored) } else { // mouse-down inside the body of the item.. if (! owner.isMultiSelectEnabled()) item->setSelected (true, true); else if (item->isSelected()) needSelectionOnMouseUp = ! e.mods.isPopupMenu(); else selectBasedOnModifiers (item, e.mods); if (e.x >= pos.getX()) item->itemClicked (e.withNewPosition (e.getPosition() - pos.getPosition())); } }
void MenuSystem::handleMouseClick(int x, int y) { if (!_editingDescription) { ItemID id = findItemAt(x, y); clickItem(id); } }
static int canvasFunc( ClientData data, Tcl_Interp *interp, int objc, Tcl_Obj * const objv[] ) { const char *cmds[] = { "delete", "configure", "cget", "isMapped", "getCurrentSize", "update", "raise", "lower", "create", "itemDelete", "itemShow", "itemConfigure", "itemCget", "itemCommand", "affine", "scale", "move", "rotate", "windowToCanvas", "canvasToWindow", "findItemAt", "getBounds", "findWithTag", NULL }; enum cmdIdx { DeleteIdx, ConfigureIdx, CgetIdx, IsMappedIdx, GetCurSizeIdx, UpdateIdx, RaiseIdx, LowerIdx, CreateIdx, ItemDeleteIdx, ItemShowIdx, ItemConfigureIdx, ItemCgetIdx, ItemCommandIdx, AffineIdx, ScaleIdx, MoveIdx, RotateIdx, WindowToCanvasIdx, CanvasToWindowIdx, FindItemAtIdx, GetBoundsIdx, GetIDsFromTagIdx }; CanvasParams *para = (CanvasParams *)data; GtkWidget *widget = GTK_WIDGET( para->canvas ); int idx; if( objc < 2 ) { Tcl_WrongNumArgs( interp, 1, objv, "command" ); return TCL_ERROR; } if( Tcl_GetIndexFromObj( interp, objv[1], cmds, "command", TCL_EXACT, &idx ) != TCL_OK ) return TCL_ERROR; switch( idx ) { case DeleteIdx: return gnoclDelete( interp, widget, objc, objv ); case ConfigureIdx: { int ret = TCL_ERROR; if( gnoclParseAndSetOptions( interp, objc - 1, objv + 1, canvasOptions, G_OBJECT( widget ) ) == TCL_OK ) { if( canvasOptions[antialiasedIdx].status == GNOCL_STATUS_CHANGED ) { Tcl_SetResult( interp, "antialiasing cannot be changed " "after creation", TCL_STATIC ); } else ret = configure( interp, para, canvasOptions ); } gnoclClearOptions( canvasOptions ); return ret; } break; case CgetIdx: { int idx; switch( gnoclCget( interp, objc, objv, G_OBJECT( widget ), canvasOptions, &idx ) ) { case GNOCL_CGET_ERROR: return TCL_ERROR; case GNOCL_CGET_HANDLED: return TCL_OK; case GNOCL_CGET_NOTHANDLED: return cget( interp, para->canvas, canvasOptions, idx ); } break; } case IsMappedIdx: return isMapped( interp, widget, objc, objv ); case GetCurSizeIdx: return getCurSize( interp, widget, objc, objv ); case UpdateIdx: if( objc != 2 ) { Tcl_WrongNumArgs( interp, 2, objv, NULL ); return TCL_ERROR; } gnome_canvas_update_now( para->canvas ); break; case CreateIdx: return canvasCreateItem( interp, objc, objv, para ); case RaiseIdx: case LowerIdx: case ItemDeleteIdx: case ItemShowIdx: case ItemConfigureIdx: case ItemCgetIdx: case ItemCommandIdx: case AffineIdx: case ScaleIdx: case MoveIdx: case RotateIdx: case GetBoundsIdx: case GetIDsFromTagIdx: { GPtrArray *items; int ret; if( objc < 3 ) { Tcl_WrongNumArgs( interp, 2, objv, "tag-or-id ?option val ...?" ); return TCL_ERROR; } if( gnoclCanvasItemsFromTagOrId( interp, para, Tcl_GetString( objv[2] ), &items ) != TCL_OK ) return TCL_ERROR; switch( idx ) { case RaiseIdx: case LowerIdx: ret = itemRaise( interp, objc, objv, para, items, idx == RaiseIdx ); break; case ItemDeleteIdx: ret = itemDelete( interp, objc, objv, para, items ); break; case ItemShowIdx: ret = itemShow( interp, objc, objv, para, items ); break; case ItemConfigureIdx: ret = itemConfigure( interp, objc, objv, para, items ); break; case ItemCgetIdx: ret = itemCget( interp, objc, objv, para, items ); break; case ItemCommandIdx: ret = itemCommand( interp, objc, objv, para, items ); break; case AffineIdx: ret = affine( interp, objc, objv, para, items, Affine ); break; case ScaleIdx: ret = affine( interp, objc, objv, para, items, Scale ); break; case MoveIdx: ret = affine( interp, objc, objv, para, items, Move ); break; case RotateIdx: ret = affine( interp, objc, objv, para, items, Rotate ); break; case GetBoundsIdx: ret = itemBounds( interp, objc, objv, para, items ); break; case GetIDsFromTagIdx: ret = getIDs( interp, objc, objv, para, items ); break; default: assert( 0 ); } if( items ) g_ptr_array_free( items, 0 ); return ret; } break; case WindowToCanvasIdx: return windowToCanvas( interp, objc, objv, para, 0 ); case CanvasToWindowIdx: return windowToCanvas( interp, objc, objv, para, 1 ); case FindItemAtIdx: return findItemAt( interp, objc, objv, para ); } return TCL_OK; }