Changeset 63797 in vbox
- Timestamp:
- Sep 12, 2016 12:59:44 PM (8 years ago)
- svn:sync-xref-src-repo-rev:
- 110622
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/platform/darwin/UICocoaSpecialControls.mm
r63796 r63797 38 38 39 39 /* Qt includes */ 40 #include <QAccessibleWidget> 40 41 #include <QApplication> 41 42 #include <QIcon> 42 43 #include <QKeyEvent> 43 44 #include <QMacCocoaViewContainer> 45 46 /* Other VBox includes: */ 47 #include <iprt/assert.h> 44 48 45 49 #if 0 /* This is a built-in according to clang. Not sure how it relates to QT_VERSION... */ … … 50 54 #endif /* QT_VERSION >= 0x050000 */ 51 55 #endif 56 57 /* Forward declarations: */ 58 class UIAccessibilityInterfaceForUICocoaSegmentedButton; 59 52 60 53 61 /* … … 349 357 } 350 358 359 360 /** QAccessibleInterface extension used as an accessibility interface for segmented-button segment. */ 361 class UIAccessibilityInterfaceForUICocoaSegmentedButtonSegment : public QAccessibleInterface 362 { 363 public: 364 365 /** Constructs an accessibility interface. 366 * @param pParent Brings the parent interface we are linked to. 367 * @param iIndex Brings the index of segment we are referring to. */ 368 UIAccessibilityInterfaceForUICocoaSegmentedButtonSegment(UIAccessibilityInterfaceForUICocoaSegmentedButton *pParent, int iIndex) 369 : m_pParent(pParent) 370 , m_iIndex(iIndex) 371 {} 372 373 /** Returns whether the interface is valid. */ 374 virtual bool isValid() const /* override */ { return true; } 375 376 /** Returns the wrapped object. */ 377 virtual QObject *object() const /* override */ { return 0; } 378 /** Returns the parent. */ 379 virtual QAccessibleInterface *parent() const /* override */; 380 381 /** Returns the number of children. */ 382 virtual int childCount() const /* override */ { return 0; } 383 /** Returns the child with the passed @a iIndex. */ 384 virtual QAccessibleInterface *child(int /* iIndex */) const /* override */ { return 0; } 385 /** Returns the child at position QPoint(@a x, @a y). */ 386 virtual QAccessibleInterface *childAt(int /* x */, int /* y */) const /* override */ { return 0; } 387 /** Returns the index of the passed @a pChild. */ 388 virtual int indexOfChild(const QAccessibleInterface * /* pChild */) const /* override */ { return -1; } 389 390 /** Returns the rect. */ 391 virtual QRect rect() const /* override */; 392 393 /** Defines a @a strText for the passed @a enmTextRole. */ 394 virtual void setText(QAccessible::Text /* enmTextRole */, const QString & /* strText */) /* override */ {} 395 /** Returns a text for the passed @a enmTextRole. */ 396 virtual QString text(QAccessible::Text /* enmTextRole */) const /* override */; 397 398 /** Returns the role. */ 399 virtual QAccessible::Role role() const /* override */ { return QAccessible::RadioButton; } 400 /** Returns the state. */ 401 virtual QAccessible::State state() const /* override */; 402 403 private: 404 405 /** Holds the parent interface we are linked to. */ 406 UIAccessibilityInterfaceForUICocoaSegmentedButton *m_pParent; 407 /** Holds the index of segment we are referring to. */ 408 const int m_iIndex; 409 }; 410 411 412 /** QAccessibleWidget extension used as an accessibility interface for segmented-button. */ 413 class UIAccessibilityInterfaceForUICocoaSegmentedButton : public QAccessibleWidget 414 { 415 public: 416 417 /** Returns an accessibility interface for passed @a strClassname and @a pObject. */ 418 static QAccessibleInterface *pFactory(const QString &strClassname, QObject *pObject) 419 { 420 /* Creating segmented-button accessibility interface: */ 421 if (pObject && strClassname == QLatin1String("UICocoaSegmentedButton")) 422 return new UIAccessibilityInterfaceForUICocoaSegmentedButton(qobject_cast<QWidget*>(pObject)); 423 424 /* Null by default: */ 425 return 0; 426 } 427 428 /** Constructs an accessibility interface passing @a pWidget to the base-class. */ 429 UIAccessibilityInterfaceForUICocoaSegmentedButton(QWidget *pWidget) 430 : QAccessibleWidget(pWidget, QAccessible::ToolBar) 431 { 432 /* Prepare: */ 433 prepare(); 434 } 435 436 /** Destructs an accessibility interface. */ 437 ~UIAccessibilityInterfaceForUICocoaSegmentedButton() 438 { 439 /* Cleanup: */ 440 cleanup(); 441 } 442 443 /** Returns the number of children. */ 444 virtual int childCount() const /* override */ { return m_children.size(); } 445 /** Returns the child with the passed @a iIndex. */ 446 virtual QAccessibleInterface *child(int iIndex) const /* override */ { return m_children.at(iIndex); } 447 448 /** Returns corresponding segmented-button. */ 449 UICocoaSegmentedButton *button() const { return qobject_cast<UICocoaSegmentedButton*>(widget()); } 450 451 private: 452 453 /** Prepares all. */ 454 void prepare() 455 { 456 /* Prepare the list of children interfaces: */ 457 for (int i = 0; i < button()->count(); ++i) 458 m_children << new UIAccessibilityInterfaceForUICocoaSegmentedButtonSegment(this, i); 459 } 460 461 /** Cleanups all. */ 462 void cleanup() 463 { 464 /* Cleanup the list of children interfaces: */ 465 qDeleteAll(m_children); 466 m_children.clear(); 467 } 468 469 /** Holds the list of children interfaces. */ 470 QList<UIAccessibilityInterfaceForUICocoaSegmentedButtonSegment*> m_children; 471 }; 472 473 474 QAccessibleInterface *UIAccessibilityInterfaceForUICocoaSegmentedButtonSegment::parent() const 475 { 476 return m_pParent; 477 } 478 479 QRect UIAccessibilityInterfaceForUICocoaSegmentedButtonSegment::rect() const 480 { 481 // TODO: Return the -=real=- segment rectangle. 482 const QRect myRect = m_pParent->rect(); 483 return QRect(myRect.x() + myRect.width() / 2 * m_iIndex, 484 myRect.y(), myRect.width() / 2, myRect.height()); 485 } 486 487 QString UIAccessibilityInterfaceForUICocoaSegmentedButtonSegment::text(QAccessible::Text /* enmTextRole */) const 488 { 489 /* Return the segment description: */ 490 return m_pParent->button()->description(m_iIndex); 491 } 492 493 QAccessible::State UIAccessibilityInterfaceForUICocoaSegmentedButtonSegment::state() const 494 { 495 /* Compose the segment state: */ 496 QAccessible::State state; 497 state.checkable = true; 498 state.checked = m_pParent->button()->isSelected(m_iIndex); 499 500 /* Return the segment state: */ 501 return state; 502 } 503 504 351 505 UICocoaSegmentedButton::UICocoaSegmentedButton(QWidget *pParent, int count, CocoaSegmentType type /* = RoundRectSegment */) 352 506 : QMacCocoaViewContainer(0, pParent) 353 507 { 508 /* Install segmented-button accessibility interface factory: */ 509 QAccessible::installFactory(UIAccessibilityInterfaceForUICocoaSegmentedButton::pFactory); 510 354 511 /* Prepare auto-release pool: */ 355 512 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
Note:
See TracChangeset
for help on using the changeset viewer.