summaryrefslogtreecommitdiffstats
path: root/tqtinterface/qt4/src/widgets/tqpopupmenu.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tqtinterface/qt4/src/widgets/tqpopupmenu.cpp')
-rw-r--r--tqtinterface/qt4/src/widgets/tqpopupmenu.cpp112
1 files changed, 91 insertions, 21 deletions
diff --git a/tqtinterface/qt4/src/widgets/tqpopupmenu.cpp b/tqtinterface/qt4/src/widgets/tqpopupmenu.cpp
index bbfdb60..993c065 100644
--- a/tqtinterface/qt4/src/widgets/tqpopupmenu.cpp
+++ b/tqtinterface/qt4/src/widgets/tqpopupmenu.cpp
@@ -224,6 +224,8 @@ static TQMenuItem* whatsThisItem = 0;
Pop-Up\endlink
*/
+static const int gtkArrowHMargin = 0; // arrow horizontal margin
+static const int gtkArrowVMargin = 0; // arrow vertical margin
/*!
\fn void TQPopupMenu::aboutToShow()
@@ -272,6 +274,8 @@ public:
} scroll;
TQSize calcSize;
TQRegion mouseMoveBuffer;
+ uint hasmouse : 1;
+ TQPoint ignoremousepos;
};
static TQPopupMenu* active_popup_menu = 0;
@@ -291,6 +295,7 @@ TQPopupMenu::TQPopupMenu( TQWidget *tqparent, const char *name )
d->scroll.scrollableSize = d->scroll.topScrollableIndex = 0;
d->scroll.scrollable = TQPopupMenuPrivate::Scroll::ScrollNone;
d->scroll.scrolltimer = 0;
+ d->hasmouse = 0;
isPopupMenu = TRUE;
#ifndef TQT_NO_ACCEL
autoaccel = 0;
@@ -314,6 +319,9 @@ TQPopupMenu::TQPopupMenu( TQWidget *tqparent, const char *name )
connectModalRecursionSafety = 0;
setFocusPolicy( Qt::StrongFocus );
+#ifdef TQ_WS_X11
+ x11SetWindowType( X11WindowTypePopup );
+#endif
}
/*!
@@ -473,6 +481,15 @@ void TQPopupMenu::frameChanged()
menuContentsChanged();
}
+TQRect TQPopupMenu::screenRect( const TQPoint& pos )
+{
+ int screen_num = TQApplication::desktop()->screenNumber( pos );
+#ifdef TQ_WS_MAC
+ return TQApplication::desktop()->availableGeometry( screen_num );
+#else
+ return TQApplication::desktop()->screenGeometry( screen_num );
+#endif
+}
/*!
Displays the popup menu so that the item number \a indexAtPoint
will be at the specified \e global position \a pos. To translate a
@@ -517,6 +534,15 @@ void TQPopupMenu::popup( const TQPoint &pos, int indexAtPoint )
// point.
#endif
+ TQRect screen = screenRect( tqgeometry().center());
+ TQRect screen2 = screenRect( TQApplication::reverseLayout()
+ ? pos+TQPoint(width(),0) : pos );
+ // if the widget is not in the screen given by the position, move it
+ // there, so that updateSize() uses the right size of the screen
+ if( screen != screen2 ) {
+ screen = screen2;
+ move( screen.x(), screen.y());
+ }
if(d->scroll.scrollable) {
d->scroll.scrollable = TQPopupMenuPrivate::Scroll::ScrollNone;
d->scroll.topScrollableIndex = d->scroll.scrollableSize = 0;
@@ -536,18 +562,6 @@ void TQPopupMenu::popup( const TQPoint &pos, int indexAtPoint )
updateSize(TRUE);
}
- int screen_num;
- if (TQApplication::desktop()->isVirtualDesktop())
- screen_num =
- TQApplication::desktop()->screenNumber( TQApplication::reverseLayout() ?
- pos+TQPoint(width(),0) : pos );
- else
- screen_num = TQApplication::desktop()->screenNumber( this );
-#ifdef TQ_WS_MAC
- TQRect screen = TQApplication::desktop()->availableGeometry( screen_num );
-#else
- TQRect screen = TQApplication::desktop()->screenGeometry( screen_num );
-#endif
int sw = screen.width(); // screen width
int sh = screen.height(); // screen height
int sx = screen.x(); // screen pos
@@ -571,6 +585,29 @@ void TQPopupMenu::popup( const TQPoint &pos, int indexAtPoint )
if ( y < sy )
y = sy;
}
+#ifdef TQ_WS_X11
+#ifndef TQT_NO_MENUBAR
+ TQMenuData *top = this; // find top level
+ while ( top->parentMenu )
+ top = top->parentMenu;
+ if( top->isMenuBar )
+ x11SetWindowType( X11WindowTypeDropdown );
+ if( parentMenu && parentMenu->isMenuBar )
+ x11SetWindowTransient( static_cast< TQMenuBar* >( parentMenu )->tqtopLevelWidget());
+#endif
+ if( parentMenu && !parentMenu->isMenuBar )
+ x11SetWindowTransient( static_cast< TQPopupMenu* >( parentMenu ));
+ if( !parentMenu ) {
+ // hackish ... try to find the main window related to this popup
+ TQWidget* tqparent = parentWidget() ? parentWidget()->tqtopLevelWidget() : NULL;
+ if( tqparent == NULL )
+ tqparent = TQApplication::widgetAt( pos );
+ if( tqparent == NULL )
+ tqparent = tqApp->activeWindow();
+ if( tqparent != NULL )
+ x11SetWindowTransient( tqparent );
+ }
+#endif
if ( x+w > sx+sw ) // the complete widget must
x = sx+sw - w; // be visible
@@ -1075,7 +1112,7 @@ TQSize TQPopupMenu::updateSize(bool force_update, bool do_resize)
mi->iconSet()->pixmap( TQIconSet::Small, TQIconSet::Normal ).width() + 4 );
}
- int dh = TQApplication::desktop()->height();
+ int dh = screenRect( tqgeometry().center()).height();
ncols = 1;
for ( TQMenuItemListIt it2( *mitems ); it2.current(); ++it2 ) {
@@ -1389,6 +1426,7 @@ void TQPopupMenu::show()
popupActive = -1;
if(tqstyle().tqstyleHint(TQStyle::SH_PopupMenu_SubMenuPopupDelay, this))
d->mouseMoveBuffer = TQRegion();
+ d->ignoremousepos = TQCursor::pos();
}
/*!
@@ -1415,6 +1453,13 @@ void TQPopupMenu::hide()
#if defined(TQT_ACCESSIBILITY_SUPPORT)
TQAccessible::updateAccessibility( this, 0, TQAccessible::PopupMenuEnd );
#endif
+#ifndef TQT_NO_MENUBAR
+ TQMenuData *top = this; // find top level
+ while ( top->parentMenu )
+ top = top->parentMenu;
+ if( top->isMenuBar )
+ x11SetWindowType( X11WindowTypePopup ); // reset
+#endif
parentMenu = 0;
hidePopups();
TQWidget::hide();
@@ -1738,6 +1783,11 @@ void TQPopupMenu::mouseReleaseEvent( TQMouseEvent *e )
void TQPopupMenu::mouseMoveEvent( TQMouseEvent *e )
{
+ if( e->globalPos() == d->ignoremousepos ) {
+ return;
+ }
+ d->ignoremousepos = TQPoint();
+
motion++;
if ( parentMenu && parentMenu->isPopupMenu ) {
@@ -1778,6 +1828,11 @@ void TQPopupMenu::mouseMoveEvent( TQMouseEvent *e )
int item = itemAtPos( e->pos() );
if ( item == -1 ) { // no valid item
+ if( !d->hasmouse ) {
+ tryMenuBar( e );
+ return;
+ }
+ d->hasmouse = 0;
int lastActItem = actItem;
actItem = -1;
if ( lastActItem >= 0 )
@@ -1789,6 +1844,7 @@ void TQPopupMenu::mouseMoveEvent( TQMouseEvent *e )
}
} else { // mouse on valid item
// but did not register mouse press
+ d->hasmouse = 1;
if ( (e->state() & Qt::MouseButtonMask) && !mouseBtDn )
mouseBtDn = TRUE; // so mouseReleaseEvent will pop down
@@ -2200,6 +2256,7 @@ void TQPopupMenu::timerEvent( TQTimerEvent *e )
*/
void TQPopupMenu::leaveEvent( TQEvent * )
{
+ d->hasmouse = 0;
if ( testWFlags( TQt::WStyle_Tool ) && tqstyle().tqstyleHint(TQStyle::SH_PopupMenu_MouseTracking, this) ) {
int lastActItem = actItem;
actItem = -1;
@@ -2329,27 +2386,37 @@ void TQPopupMenu::subMenuTimer() {
TQRect r( itemGeometry( actItem ) );
TQPoint p;
TQSize ps = popup->tqsizeHint();
+ // GUI Style
+ int gs = style().tqstyleHint(TQStyle::SH_GUIStyle);
+ int arrowHMargin, arrowVMargin;
+ if (gs == GtkStyle) {
+ arrowHMargin = gtkArrowHMargin;
+ arrowVMargin = gtkArrowVMargin;
+ } else {
+ arrowHMargin = motifArrowHMargin;
+ arrowVMargin = motifArrowVMargin;
+ }
if( TQApplication::reverseLayout() ) {
- p = TQPoint( r.left() + motifArrowHMargin - ps.width(), r.top() + motifArrowVMargin );
+ p = TQPoint( r.left() + arrowHMargin - ps.width(), r.top() + arrowVMargin );
p = mapToGlobal( p );
bool right = FALSE;
if ( ( parentMenu && parentMenu->isPopupMenu &&
((TQPopupMenu*)parentMenu)->tqgeometry().x() < tqgeometry().x() ) ||
- p.x() < 0 )
+ p.x() < screenRect( p ).left())
right = TRUE;
- if ( right && (ps.width() > TQApplication::desktop()->width() - mapToGlobal( r.topRight() ).x() ) )
+ if ( right && (ps.width() > screenRect( p ).right() - mapToGlobal( r.topRight() ).x() ) )
right = FALSE;
if ( right )
p.setX( mapToGlobal( r.topRight() ).x() );
} else {
- p = TQPoint( r.right() - motifArrowHMargin, r.top() + motifArrowVMargin );
+ p = TQPoint( r.right() - arrowHMargin, r.top() + arrowVMargin );
p = mapToGlobal( p );
bool left = FALSE;
if ( ( parentMenu && parentMenu->isPopupMenu &&
((TQPopupMenu*)parentMenu)->tqgeometry().x() > tqgeometry().x() ) ||
- p.x() + ps.width() > TQApplication::desktop()->width() )
+ p.x() + ps.width() > screenRect( p ).right() )
left = TRUE;
if ( left && (ps.width() > mapToGlobal( r.topLeft() ).x() ) )
left = FALSE;
@@ -2357,8 +2424,8 @@ void TQPopupMenu::subMenuTimer() {
p.setX( mapToGlobal( r.topLeft() ).x() - ps.width() );
}
TQRect pr = popup->itemGeometry(popup->count() - 1);
- if (p.y() + ps.height() > TQApplication::desktop()->height() &&
- p.y() - ps.height() + (TQCOORD) pr.height() >= 0)
+ if (p.y() + ps.height() > screenRect( p ).bottom() &&
+ p.y() - ps.height() + (TQCOORD) pr.height() >= screenRect( p ).top())
p.setY( p.y() - ps.height() + (TQCOORD) pr.height());
if ( tqstyle().tqstyleHint(TQStyle::SH_PopupMenu_SloppySubMenus, this )) {
@@ -2569,7 +2636,7 @@ TQSize TQPopupMenu::tqsizeHint() const
constPolish();
TQPopupMenu* that = (TQPopupMenu*) this;
//We do not need a resize here, just the tqsizeHint..
- return that->updateSize(FALSE, FALSE).expandedTo( TQApplication::globalStrut() );
+ return that->updateSize(FALSE).expandedTo( TQApplication::globalStrut() );
}
@@ -2730,6 +2797,9 @@ void TQPopupMenu::toggleTearOff()
tqgeometry().topLeft(), FALSE );
p->mitems->setAutoDelete( FALSE );
p->tornOff = TRUE;
+#ifdef TQ_WS_X11
+ p->x11SetWindowType( X11WindowTypeMenu );
+#endif
for ( TQMenuItemListIt it( *mitems ); it.current(); ++it ) {
if ( it.current()->id() != TQMenuData::d->aInt && !it.current()->widget() )
p->mitems->append( it.current() );