23 #ifndef INCLUDE_MENUITEM_DEF
24 #define INCLUDE_MENUITEM_DEF
29 #include <tqobjectlist.h>
31 #include <tqpainter.h>
35 #include <tdeconfig.h>
36 #include <tdeglobalsettings.h>
37 #include <tdemenubar.h>
38 #include <tdeapplication.h>
39 #include <tdeglobal.h>
41 #include <kmanagerselection.h>
45 #include <twinmodule.h>
49 #include <X11/Xutil.h>
50 #include <X11/Xatom.h>
70 class KMenuBar::KMenuBarPrivate
74 : forcedTopLevel( false ),
97 TDESelectionWatcher* selection;
99 TQTimer selection_timer;
101 static Atom makeSelectionAtom();
105 static Atom selection_atom = None;
106 static Atom msg_type_atom = None;
112 sprintf( nm,
"_KDE_TOPMENU_OWNER_S%d", DefaultScreen( tqt_xdisplay()));
113 char nm2[] =
"_KDE_TOPMENU_MINSIZE";
114 char* names[ 2 ] = { nm, nm2 };
116 XInternAtoms( tqt_xdisplay(), names, 2, False, atoms );
117 selection_atom = atoms[ 0 ];
118 msg_type_atom = atoms[ 1 ];
122 Atom KMenuBar::KMenuBarPrivate::makeSelectionAtom()
125 if( selection_atom == None )
127 return selection_atom;
133 KMenuBar::KMenuBar(TQWidget *parent,
const char *name)
134 : TQMenuBar(parent,
name)
137 QXEmbed::initialize();
139 d =
new KMenuBarPrivate;
140 connect( &d->selection_timer, TQ_SIGNAL( timeout()),
141 this, TQ_SLOT( selectionTimeout()));
143 connect( tqApp->desktop(), TQ_SIGNAL( resized(
int )), TQ_SLOT( updateFallbackSize()));
147 connect( kapp, TQ_SIGNAL(toolbarAppearanceChanged(
int)),
148 this, TQ_SLOT(slotReadConfig()));
153 KMenuBar::~KMenuBar()
160 d->forcedTopLevel = top_level;
161 setTopLevelMenuInternal( top_level );
164 void KMenuBar::setTopLevelMenuInternal(
bool top_level)
166 if (d->forcedTopLevel)
169 d->wasTopLevel = top_level;
171 && parentWidget()->topLevelWidget()->isFullScreen())
176 d->topLevel = top_level;
180 d->selection =
new TDESelectionWatcher( KMenuBarPrivate::makeSelectionAtom(),
181 DefaultScreen( tqt_xdisplay()));
182 connect( d->selection, TQ_SIGNAL( newOwner( Window )),
183 this, TQ_SLOT( updateFallbackSize()));
184 connect( d->selection, TQ_SIGNAL( lostOwner()),
185 this, TQ_SLOT( updateFallbackSize()));
187 d->frameStyle = frameStyle();
188 d->lineWidth = lineWidth();
189 d->margin = margin();
190 d->fallback_mode =
false;
191 bool wasShown = !isHidden();
192 reparent( parentWidget(), (WFlags)(WType_TopLevel | WStyle_Tool | WStyle_Customize | WStyle_NoBorder), TQPoint(0,0),
false );
196 XSetTransientForHint( tqt_xdisplay(), winId(), parentWidget()->topLevelWidget()->winId());
198 TQMenuBar::setFrameStyle( NoFrame );
199 TQMenuBar::setLineWidth( 0 );
200 TQMenuBar::setMargin( 0 );
201 updateFallbackSize();
202 d->min_size = TQSize( 0, 0 );
203 if( parentWidget() && !parentWidget()->isTopLevel())
204 setShown( parentWidget()->isVisible());
213 setBackgroundMode( PaletteButton );
214 setFrameStyle( d->frameStyle );
215 setLineWidth( d->lineWidth );
216 setMargin( d->margin );
217 setMinimumSize( 0, 0 );
218 setMaximumSize( TQWIDGETSIZE_MAX, TQWIDGETSIZE_MAX );
220 if ( parentWidget() )
221 reparent( parentWidget(), TQPoint(0,0), !isHidden());
231 void KMenuBar::show()
236 void KMenuBar::slotReadConfig()
240 setTopLevelMenuInternal( config->
readBoolEntry(
"macStyle",
false ) );
243 bool KMenuBar::eventFilter(TQObject *obj, TQEvent *ev)
247 if ( parentWidget() && obj == parentWidget()->topLevelWidget() )
249 if( ev->type() == TQEvent::Resize )
251 if ( ev->type() == TQEvent::Accel || ev->type() == TQEvent::AccelAvailable )
253 if ( TQApplication::sendEvent( topLevelWidget(), ev ) )
256 if(ev->type() == TQEvent::ShowFullScreen )
258 setTopLevelMenuInternal( d->topLevel );
260 if( parentWidget() && obj == parentWidget() && ev->type() == TQEvent::Reparent )
263 XSetTransientForHint( tqt_xdisplay(), winId(), parentWidget()->topLevelWidget()->winId());
267 setShown( parentWidget()->isTopLevel() || parentWidget()->isVisible());
269 if( parentWidget() && !parentWidget()->isTopLevel() && obj == parentWidget())
271 if( ev->type() == TQEvent::Show )
274 XSetTransientForHint( tqt_xdisplay(), winId(), parentWidget()->topLevelWidget()->winId());
280 if( ev->type() == TQEvent::Hide )
286 if( parentWidget() && obj == parentWidget()->topLevelWidget())
288 if( ev->type() == TQEvent::WindowStateChange
289 && !parentWidget()->topLevelWidget()->isFullScreen() )
290 setTopLevelMenuInternal( d->wasTopLevel );
293 return TQMenuBar::eventFilter( obj, ev );
297 void KMenuBar::showEvent( TQShowEvent *e )
299 TQMenuBar::showEvent(e);
302 void KMenuBar::updateFallbackSize()
307 if( d->selection->owner() != None )
311 d->selection_timer.stop();
312 if( d->fallback_mode )
314 d->fallback_mode =
false;
316 setMinimumSize( 0, 0 );
317 setMaximumSize( TQWIDGETSIZE_MAX, TQWIDGETSIZE_MAX );
322 if( d->selection_timer.isActive())
324 d->selection_timer.start( 100,
true );
327 void KMenuBar::selectionTimeout()
331 d->fallback_mode =
true;
333 int screen = xineramaConfig.readNumEntry(
"MenubarScreen",
334 TQApplication::desktop()->screenNumber(TQPoint(0,0)) );
336 if (kapp->desktop()->numScreens() < 2)
337 area = kapp->desktop()->geometry();
339 area = kapp->desktop()->screenGeometry(screen);
341 move(area.left() - margin, area.top() - margin);
342 setFixedSize(area.width() + 2* margin , heightForWidth( area.width() + 2 * margin ) );
344 int strut_height = height() - margin;
345 if( strut_height < 0 )
352 int KMenuBar::block_resize = 0;
354 void KMenuBar::resizeEvent( TQResizeEvent *e )
356 if( e->spontaneous() && d->topLevel && !d->fallback_mode )
359 TQMenuBar::resizeEvent(e);
363 TQMenuBar::resizeEvent(e);
366 void KMenuBar::setGeometry(
const TQRect& r )
368 setGeometry( r.x(), r.y(), r.width(), r.height() );
371 void KMenuBar::setGeometry(
int x,
int y,
int w,
int h )
373 if( block_resize > 0 )
379 if( geometry() != TQRect( x, y, w, h ))
380 TQMenuBar::setGeometry( x, y, w, h );
383 void KMenuBar::resize(
int w,
int h )
385 if( block_resize > 0 )
388 if( size() != TQSize( w, h ))
389 TQMenuBar::resize( w, h );
393 void KMenuBar::checkSize(
int& w,
int& h )
395 if( !d->topLevel || d->fallback_mode )
397 TQSize s = sizeHint();
403 w =
KMAX( w, d->min_size.width());
404 h =
KMAX( h, d->min_size.height());
408 TQSize KMenuBar::sizeHint()
const
410 if( !d->topLevel || block_resize > 0 )
411 return TQMenuBar::sizeHint();
416 int h = heightForWidth( 1000000 );
417 int w = TQMenuBar::sizeHint().width();
419 while( heightForWidth( w + 12 ) > h )
421 while( heightForWidth( w + 4 ) > h )
423 while( heightForWidth( w ) > h )
426 return TQSize( w, h );
430 bool KMenuBar::x11Event( XEvent* ev )
432 if( ev->type == ClientMessage && ev->xclient.message_type == msg_type_atom
433 && ev->xclient.window == winId())
439 d->min_size = TQSize( ev->xclient.data.l[ 1 ], ev->xclient.data.l[ 2 ] );
444 return TQMenuBar::x11Event( ev );
448 void KMenuBar::updateMenuBarSize()
450 menuContentsChanged();
454 void KMenuBar::setFrameStyle(
int style )
457 d->frameStyle = style;
459 TQMenuBar::setFrameStyle( style );
462 void KMenuBar::setLineWidth(
int width )
465 d->lineWidth = width;
467 TQMenuBar::setLineWidth( width );
470 void KMenuBar::setMargin(
int margin )
475 TQMenuBar::setMargin( margin );
478 void KMenuBar::closeEvent( TQCloseEvent* e )
483 TQMenuBar::closeEvent( e );
486 void KMenuBar::drawContents( TQPainter* p )
501 TQMenuBar::drawContents(p);
505 bool up_enabled = isUpdatesEnabled();
506 BackgroundMode bg_mode = backgroundMode();
507 BackgroundOrigin bg_origin = backgroundOrigin();
509 setUpdatesEnabled(
false);
510 setBackgroundMode(X11ParentRelative);
511 setBackgroundOrigin(WindowOrigin);
513 p->eraseRect( rect() );
516 TQColorGroup g = colorGroup();
519 for (
int i=0; i<(int)count(); i++ )
521 TQMenuItem *mi = findItem( idAt( i ) );
523 if ( !mi->text().isNull() || mi->pixmap() )
525 TQRect r = itemRect(i);
526 if(r.isEmpty() || !mi->isVisible())
529 e = mi->isEnabledAndVisible();
531 g = isEnabled() ? ( isActiveWindow() ? palette().active() :
532 palette().inactive() ) : palette().disabled();
534 g = palette().disabled();
536 bool item_active = ( actItem == i );
542 TQStyle::SFlags flags = TQStyle::Style_Default;
543 if (isEnabled() && e)
544 flags |= TQStyle::Style_Enabled;
546 flags |= TQStyle::Style_Active;
547 if ( item_active && actItemDown )
548 flags |= TQStyle::Style_Down;
549 flags |= TQStyle::Style_HasFocus;
551 style().drawControl(TQStyle::CE_MenuBarItem, p,
this,
552 r, g, flags, TQStyleOption(mi));
556 style().drawItem(p, r, AlignCenter | AlignVCenter | ShowPrefix,
557 g, e, mi->pixmap(), mi->text());
562 setBackgroundOrigin(bg_origin);
563 setBackgroundMode(bg_mode);
564 setUpdatesEnabled(up_enabled);
568 void KMenuBar::virtual_hook(
int,
void* )
571 #include "tdemenubar.moc"
static void setType(WId win, NET::WindowType windowType)
static void setStrut(WId win, int left, int right, int top, int bottom)
bool readBoolEntry(const TQString &pKey, bool bDefault=false) const
static TDEConfig * config()
TQString name(StdAccel id)