# kdeui Library API Documentation

Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Source Files

# kmenubar.cpp

    00001 /*
    00002
    00003     Copyright (C) 1997, 1998, 1999, 2000  Sven Radej (radej@kde.org)
    00004     Copyright (C) 1997, 1998, 1999, 2000 Matthias Ettrich (ettrich@kde.org)
    00005     Copyright (C) 1999, 2000 Daniel "Mosfet" Duley (mosfet@kde.org)
    00006
    00007     This library is free software; you can redistribute it and/or
    00008     modify it under the terms of the GNU Library General Public
    00009     License as published by the Free Software Foundation; either
    00010     version 2 of the License, or (at your option) any later version.
    00011
    00012     This library is distributed in the hope that it will be useful,
    00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
    00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00015     Library General Public License for more details.
    00016
    00017     You should have received a copy of the GNU Library General Public License
    00018     along with this library; see the file COPYING.LIB.  If not, write to
    00019     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00020     Boston, MA 02111-1307, USA.
    00021     */
    00022
    00023
    00024 #ifndef INCLUDE_MENUITEM_DEF
    00025 #define INCLUDE_MENUITEM_DEF
    00026 #endif
    00027
    00028 #include <qevent.h>
    00029 #include <qobjectlist.h>
    00030 #include <qaccel.h>
    00031
    00032 #include <kconfig.h>
    00033 #include <kglobalsettings.h>
    00034 #include <kmenubar.h>
    00035 #include <kapplication.h>
    00036 #include <kwin.h>
    00037 #include <kwinmodule.h>
    00038 #include <kglobal.h>
    00039
    00040 #ifndef Q_WS_QWS
    00041 #include <X11/Xlib.h>
    00042 #include <X11/Xutil.h>
    00043 #include <X11/Xatom.h>
    00044 #endif
    00045
    00046
    00047 class KMenuBar::KMenuBarPrivate
    00048 {
    00049 public:
    00050     KMenuBarPrivate()
    00051     {
    00052       topLevel = false;
    00053       forcedTopLevel = false;
    00054       wasTopLevel = false;
    00055     }
    00056     bool forcedTopLevel;
    00057     bool topLevel;
    00058     int frameStyle;
    00059     bool wasTopLevel; // when TLW is fullscreen, remember state
    00060 };
    00061
    00062 KMenuBar::KMenuBar(QWidget *parent, const char *name)
    00063   : QMenuBar(parent, name)
    00064 {
    00065     d = new KMenuBarPrivate;
    00066     d->frameStyle = frameStyle();
    00067
    00068     if ( kapp )
    00069         // toolbarAppearanceChanged(int) is sent when changing macstyle
    00070         connect( kapp, SIGNAL(toolbarAppearanceChanged(int)),
    00071             this, SLOT(slotReadConfig()));
    00072
    00073     slotReadConfig();
    00074 }
    00075
    00076 KMenuBar::~KMenuBar()
    00077 {
    00078   delete d;
    00079 }
    00080
    00081 void KMenuBar::setTopLevelMenu(bool top_level)
    00082 {
    00083   d->forcedTopLevel = top_level;
    00084   setTopLevelMenuInternal( top_level );
    00085 }
    00086
    00087 #if QT_VERSION < 0x030100
    00088 namespace
    00089 {
    00090 class QWidgetHack
    00091     : public QWidget
    00092     {
    00093     public:
    00094         bool isFullScreen() { return isTopLevel() && topData()->fullscreen; }
    00095     };
    00096 }
    00097 #endif
    00098
    00099 void KMenuBar::setTopLevelMenuInternal(bool top_level)
    00100 {
    00101   if (d->forcedTopLevel)
    00102     top_level = true;
    00103
    00104   if( parentWidget()
    00105 #if QT_VERSION >= 0x030100
    00106       && parentWidget()->topLevelWidget()->isFullScreen()) {
    00107 #else
    00108       && static_cast<QWidgetHack*>(parentWidget()->topLevelWidget())->isFullScreen()) {
    00109 #endif
    00110     d->wasTopLevel = top_level;
    00111     top_level = false;
    00112   }
    00113
    00114   if ( isTopLevelMenu() == top_level )
    00115     return;
    00116   d->topLevel = top_level;
    00117   if ( isTopLevelMenu() ) {
    00118       bool wasVisible = !isHidden();
    00119       d->frameStyle = frameStyle();
    00120       removeEventFilter( topLevelWidget() );
    00121       reparent( parentWidget(), WType_TopLevel | WType_Dialog | WStyle_NoBorder, QPoint(0,0), false );
    00122 #ifndef Q_WS_QWS //FIXME
    00123       KWin::setType( winId(), NET::TopMenu );
    00124 #endif
    00125       setFrameStyle( MenuBarPanel );
    00126       installEventFilter( parentWidget()->topLevelWidget() );
    00127       if ( wasVisible )
    00128           show();
    00129   } else {
    00130       if ( parentWidget() ) {
    00131           reparent( parentWidget(), QPoint(0,0), !isHidden());
    00132           setBackgroundMode( PaletteButton );
    00133           installEventFilter( topLevelWidget() );
    00134           setFrameStyle( d->frameStyle );
    00135       }
    00136   }
    00137 }
    00138
    00139 bool KMenuBar::isTopLevelMenu() const
    00140 {
    00141   return d->topLevel;
    00142 }
    00143
    00144 void KMenuBar::show()
    00145 {
    00146     // work around a Qt bug
    00147     // why is this still needed? (Simon)
    00148     if ( d->topLevel && isVisible() )
    00149         return;
    00150
    00151     QMenuBar::show();
    00152 }
    00153
    00154 void KMenuBar::slotReadConfig()
    00155 {
    00156   KConfig *config = KGlobal::config();
    00157   KConfigGroupSaver saver( config, "KDE" );
    00158   setTopLevelMenuInternal( config->readBoolEntry( "macStyle", false ) );
    00159 }
    00160
    00161 bool KMenuBar::eventFilter(QObject *obj, QEvent *ev)
    00162 {
    00163
    00164     if ( d->topLevel ) {
    00165         if ( ev->type() == QEvent::Resize )
    00166             return FALSE; // hinder QMenubar to adjust its size
    00167         if ( parentWidget() && obj == parentWidget()->topLevelWidget()  ) {
    00168
    00169             if ( ev->type() == QEvent::Accel || ev->type() == QEvent::AccelAvailable ) {
    00170                 if ( QApplication::sendEvent( topLevelWidget(), ev ) )
    00171                     return TRUE;
    00172             }
    00173
    00174 //          if ( ev->type() == QEvent::Show && isHidden())
    00175 //              show();  doesn't seem to do anything besides breaking things
    00176 //          else
    00177             if ( ev->type() == QEvent::WindowActivate )
    00178                 raise();
    00179             else if(ev->type() == QEvent::ShowFullScreen )
    00180                 // will update the state properly
    00181                 setTopLevelMenuInternal( d->topLevel );
    00182         }
    00183     } else {
    00184         if( topLevelWidget() && obj == topLevelWidget()) {
    00185             if( ev->type() == QEvent::ShowNormal )
    00186                 setTopLevelMenuInternal( d->wasTopLevel );
    00187         }
    00188     }
    00189     return QMenuBar::eventFilter( obj, ev );
    00190 }
    00191
    00192 void KMenuBar::showEvent( QShowEvent *e )
    00193 {
    00194     updateKMenubarSize();
    00195     QMenuBar::showEvent(e);
    00196 }
    00197
    00198 void KMenuBar::resizeEvent( QResizeEvent *e )
    00199 {
    00200     updateKMenubarSize();
    00201     QMenuBar::resizeEvent(e);
    00202 }
    00203
    00204 void KMenuBar::updateKMenubarSize()
    00205 {
    00206     if ( d->topLevel ) {
    00207         KConfigGroup xineramaConfig(KGlobal::config(),"Xinerama");
    00208         int screen = xineramaConfig.readNumEntry("MenubarScreen",
    00209             QApplication::desktop()->screenNumber(QPoint(0,0)) );
    00210         QRect area = QApplication::desktop()->screenGeometry(screen);
    00211         QMenuBar::setGeometry(area.left(), area.top()-frameWidth()-2, area.width(), heightForWidth( area.width() ) );
    00212 #ifndef Q_WS_QWS //FIXME
    00213         int strut_height = height()-frameWidth()-2;
    00214         if( strut_height < 0 )
    00215             strut_height = 0;
    00216         KWin::setStrut( winId(), 0, 0, strut_height, 0 );
    00217 #endif
    00218     }
    00219 }
    00220
    00221 void KMenuBar::setGeometry( int x, int y, int w, int h )
    00222 {
    00223    // With the toolbar in toplevel-mode it sometimes has the tendency to cuddle up in
    00224    // the topleft corner due to a misguided attempt from the layout manager (?) to
    00225    // size us. The follow line filters out any resize attempt while in toplevel-mode.
    00226    if ( !d->topLevel )
    00227        QMenuBar::setGeometry(x,y,w,h);
    00228 }
    00229
    00230 void KMenuBar::virtual_hook( int, void* )
    00231 { /*BASE::virtual_hook( id, data );*/ }
    00232
    00233
    00234
    00235
    00236 #include "kmenubar.moc"

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 12:57:22 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001