kdeui Library API Documentation

kdockwidget.cpp

00001 
00002 /* This file is part of the KDE libraries
00003    Copyright (C) 2000 Max Judin <novaprint@mtu-net.ru>
00004    Copyright (C) 2002,2003 Joseph Wenninger <jowenn@kde.org>
00005 
00006    This library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Library General Public
00008    License version 2 as published by the Free Software Foundation.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00018    Boston, MA 02111-1307, USA.
00019 */
00020 #include "kdockwidget.h"
00021 #include "kdockwidget_private.h"
00022 #include "kdockwidget_p.h"
00023 
00024 #include <qapplication.h>
00025 #include <qlayout.h>
00026 #include <qpainter.h>
00027 #include <qobjectlist.h>
00028 #include <qstrlist.h>
00029 #include <qcursor.h>
00030 #include <qwidgetlist.h>
00031 #include <qtabwidget.h>
00032 #include <qtooltip.h>
00033 #include <qstyle.h>
00034 
00035 #ifndef NO_KDE2
00036 #include <kconfig.h>
00037 #include <kglobal.h>
00038 #include <klocale.h>
00039 #include <ktoolbar.h>
00040 #include <kpopupmenu.h>
00041 #include <kwin.h>
00042 #include <kdebug.h>
00043 #include <kglobalsettings.h>
00044 
00045 #include "config.h"
00046 #ifdef Q_WS_X11
00047 #include <X11/X.h>
00048 #include <X11/Xlib.h>
00049 #endif
00050 
00051 #else
00052 #include <qtoolbar.h>
00053 #include <qpopupmenu.h>
00054 #endif
00055 
00056 #include <stdlib.h>
00057 
00058 #undef BORDERLESS_WINDOWS
00059 
00060 #define DOCK_CONFIG_VERSION "0.0.5"
00061 
00062 static const char* const dockback_xpm[]={
00063 "6 6 2 1",
00064 "# c black",
00065 ". c None",
00066 "......",
00067 ".#....",
00068 "..#..#",
00069 "...#.#",
00070 "....##",
00071 "..####"};
00072 
00073 static const char* const todesktop_xpm[]={
00074 "5 5 2 1",
00075 "# c black",
00076 ". c None",
00077 "####.",
00078 "##...",
00079 "#.#..",
00080 "#..#.",
00081 "....#"};
00082 
00083 static const char* const not_close_xpm[]={
00084 "5 5 2 1",
00085 "# c black",
00086 ". c None",
00087 "#####",
00088 "#...#",
00089 "#...#",
00090 "#...#",
00091 "#####"};
00092 
00102 KDockMainWindow::KDockMainWindow( QWidget* parent, const char *name, WFlags f)
00103 :KMainWindow( parent, name, f )
00104 {
00105   QString new_name = QString(name) + QString("_DockManager");
00106   dockManager = new KDockManager( this, new_name.latin1() );
00107   mainDockWidget = 0L;
00108 }
00109 
00110 KDockMainWindow::~KDockMainWindow()
00111 {
00112     delete dockManager;
00113 }
00114 
00115 void KDockMainWindow::setMainDockWidget( KDockWidget* mdw )
00116 {
00117   if ( mainDockWidget == mdw ) return;
00118   mainDockWidget = mdw;
00119   dockManager->setMainDockWidget2(mdw);
00120 }
00121 
00122 void KDockMainWindow::setView( QWidget *view )
00123 {
00124   if ( view->isA("KDockWidget") ){
00125     if ( view->parent() != this ) ((KDockWidget*)view)->applyToWidget( this );
00126   }
00127 
00128 #ifndef NO_KDE2
00129   KMainWindow::setCentralWidget(view);
00130 #else
00131   QMainWindow::setCentralWidget(view);
00132 #endif
00133 }
00134 
00135 KDockWidget* KDockMainWindow::createDockWidget( const QString& name, const QPixmap &pixmap, QWidget* parent, const QString& strCaption, const QString& strTabPageLabel)
00136 {
00137   return new KDockWidget( dockManager, name.latin1(), pixmap, parent, strCaption, strTabPageLabel );
00138 }
00139 
00140 void KDockMainWindow::makeDockVisible( KDockWidget* dock )
00141 {
00142   if ( dock )
00143     dock->makeDockVisible();
00144 }
00145 
00146 void KDockMainWindow::makeDockInvisible( KDockWidget* dock )
00147 {
00148   if ( dock )
00149     dock->undock();
00150 }
00151 
00152 void KDockMainWindow::makeWidgetDockVisible( QWidget* widget )
00153 {
00154   makeDockVisible( dockManager->findWidgetParentDock(widget) );
00155 }
00156 
00157 void KDockMainWindow::writeDockConfig(QDomElement &base)
00158 {
00159   dockManager->writeConfig(base);
00160 }
00161 
00162 void KDockMainWindow::readDockConfig(QDomElement &base)
00163 {
00164   dockManager->readConfig(base);
00165 }
00166 
00167 #ifndef NO_KDE2
00168 void KDockMainWindow::writeDockConfig( KConfig* c, QString group )
00169 {
00170   dockManager->writeConfig( c, group );
00171 }
00172 
00173 void KDockMainWindow::readDockConfig( KConfig* c, QString group )
00174 {
00175   dockManager->readConfig( c, group );
00176 }
00177 #endif
00178 
00179 void KDockMainWindow::slotDockWidgetUndocked()
00180 {
00181   QObject* pSender = (QObject*) sender();
00182   if (!pSender->inherits("KDockWidget")) return;
00183   KDockWidget* pDW = (KDockWidget*) pSender;
00184   emit dockWidgetHasUndocked( pDW);
00185 }
00186 
00187 /*************************************************************************/
00188 KDockWidgetAbstractHeaderDrag::KDockWidgetAbstractHeaderDrag( KDockWidgetAbstractHeader* parent, KDockWidget* dock, const char* name )
00189 :QFrame( parent, name )
00190 {
00191   dw = dock;
00192   installEventFilter( dock->dockManager() );
00193 }
00194 /*************************************************************************/
00195 KDockWidgetHeaderDrag::KDockWidgetHeaderDrag( KDockWidgetAbstractHeader* parent, KDockWidget* dock, const char* name )
00196 :KDockWidgetAbstractHeaderDrag( parent, dock, name )
00197 {
00198 }
00199 
00200 void KDockWidgetHeaderDrag::paintEvent( QPaintEvent* )
00201 {
00202   QPainter paint;
00203 
00204   paint.begin( this );
00205 
00206   style().drawPrimitive (QStyle::PE_DockWindowHandle, &paint, QRect(0,0,width(), height()), colorGroup());
00207 
00208   paint.end();
00209 }
00210 /*************************************************************************/
00211 KDockWidgetAbstractHeader::KDockWidgetAbstractHeader( KDockWidget* parent, const char* name )
00212 :QFrame( parent, name )
00213 {
00214 }
00215 /*************************************************************************/
00216 KDockWidgetHeader::KDockWidgetHeader( KDockWidget* parent, const char* name )
00217 :KDockWidgetAbstractHeader( parent, name )
00218 {
00219 #ifdef BORDERLESS_WINDOWS
00220   setCursor(QCursor(ArrowCursor));
00221 #endif
00222   d = new KDockWidgetHeaderPrivate( this );
00223 
00224   layout = new QHBoxLayout( this );
00225   layout->setResizeMode( QLayout::Minimum );
00226 
00227   drag = new KDockWidgetHeaderDrag( this, parent );
00228 
00229   closeButton = new KDockButton_Private( this, "DockCloseButton" );
00230   QToolTip::add( closeButton, i18n("Close") );
00231   closeButton->setPixmap( style().stylePixmap (QStyle::SP_TitleBarCloseButton , this));
00232   closeButton->setFixedSize(closeButton->pixmap()->width(),closeButton->pixmap()->height());
00233   connect( closeButton, SIGNAL(clicked()), parent, SIGNAL(headerCloseButtonClicked()));
00234   connect( closeButton, SIGNAL(clicked()), parent, SLOT(undock()));
00235 
00236   stayButton = new KDockButton_Private( this, "DockStayButton" );
00237   QToolTip::add( stayButton, i18n("Freeze the window geometry", "Freeze") );
00238   stayButton->setToggleButton( true );
00239   stayButton->setPixmap( const_cast< const char** >(not_close_xpm) );
00240   stayButton->setFixedSize(closeButton->pixmap()->width(),closeButton->pixmap()->height());
00241   connect( stayButton, SIGNAL(clicked()), this, SLOT(slotStayClicked()));
00242 
00243   dockbackButton = new KDockButton_Private( this, "DockbackButton" );
00244   QToolTip::add( dockbackButton, i18n("Dock this window", "Dock") );
00245   dockbackButton->setPixmap( const_cast< const char** >(dockback_xpm));
00246   dockbackButton->setFixedSize(closeButton->pixmap()->width(),closeButton->pixmap()->height());
00247   connect( dockbackButton, SIGNAL(clicked()), parent, SIGNAL(headerDockbackButtonClicked()));
00248   connect( dockbackButton, SIGNAL(clicked()), parent, SLOT(dockBack()));
00249 
00250   d->toDesktopButton = new KDockButton_Private( this, "ToDesktopButton" );
00251   QToolTip::add( d->toDesktopButton, i18n("Detach") );
00252   d->toDesktopButton->setPixmap( const_cast< const char** >(todesktop_xpm));
00253   d->toDesktopButton->setFixedSize(closeButton->pixmap()->width(),closeButton->pixmap()->height());
00254   connect( d->toDesktopButton, SIGNAL(clicked()), parent, SLOT(toDesktop()));
00255   stayButton->hide();
00256 
00257   d->dummy = new QWidget( this );
00258   d->dummy->setFixedSize( 1,closeButton->pixmap()->height() );
00259 
00260 
00261   layout->addWidget( drag );
00262   layout->addWidget( dockbackButton );
00263   layout->addWidget( d->toDesktopButton );
00264   layout->addWidget( d->dummy);
00265   layout->addWidget( stayButton );
00266   layout->addWidget( closeButton );
00267   layout->activate();
00268   d->dummy->hide();
00269   drag->setFixedHeight( layout->minimumSize().height() );
00270 }
00271 
00272 void KDockWidgetHeader::setTopLevel( bool isTopLevel )
00273 {
00274   d->topLevel = isTopLevel;
00275   if ( isTopLevel ){
00276     KDockWidget* par = (KDockWidget*)parent();
00277     if( par) {
00278       if( par->isDockBackPossible())
00279         dockbackButton->show();
00280       else
00281         dockbackButton->hide();
00282     }
00283     stayButton->hide();
00284     closeButton->hide();
00285     d->toDesktopButton->hide();
00286     drag->setEnabled( true );
00287   } else {
00288     dockbackButton->hide();
00289     stayButton->hide();
00290     if (!d->forceCloseButtonHidden) closeButton->show();
00291     if( d->showToDesktopButton )
00292       d->toDesktopButton->show();
00293   }
00294   layout->activate();
00295 
00296    bool dontShowDummy=drag->isVisibleTo(this) || dockbackButton->isVisibleTo(this) ||
00297         d->toDesktopButton->isVisibleTo(this) || stayButton->isVisibleTo(this) ||
00298         closeButton->isVisibleTo(this);
00299    for (QPtrListIterator<KDockButton_Private> it( d->btns );it.current();++it) {
00300         dontShowDummy=dontShowDummy || (it.current()->isVisibleTo(this));
00301    }
00302    if (dontShowDummy) d->dummy->hide(); else d->dummy->show();
00303 
00304   updateGeometry();
00305 }
00306 
00307 void KDockWidgetHeader::forceCloseButtonHidden(bool hidden) {
00308   d->forceCloseButtonHidden=hidden;
00309   if (hidden) closeButton->hide();
00310   else closeButton->show();
00311 }
00312 
00313 KDockWidgetHeaderDrag *KDockWidgetHeader::dragPanel() {
00314     return drag;
00315 }
00316 
00317 void KDockWidgetHeader::setDragPanel( KDockWidgetHeaderDrag* nd )
00318 {
00319   if ( !nd ) return;
00320 
00321   delete layout;
00322   layout = new QHBoxLayout( this );
00323   layout->setResizeMode( QLayout::Minimum );
00324 
00325   delete drag;
00326   drag = nd;
00327   if (drag->parentWidget()!=this) {
00328     drag->reparent(this,QPoint(0,0));
00329   }
00330 
00331 
00332   layout->addWidget( drag );
00333   layout->addWidget( dockbackButton );
00334   layout->addWidget( d->dummy );
00335   layout->addWidget( d->toDesktopButton );
00336   layout->addWidget( stayButton );
00337   bool dontShowDummy=drag->isVisibleTo(this) || dockbackButton->isVisibleTo(this) ||
00338     d->toDesktopButton->isVisibleTo(this) || stayButton->isVisibleTo(this) ||
00339     closeButton->isVisibleTo(this);
00340   for (QPtrListIterator<KDockButton_Private> it( d->btns );it.current();++it) {
00341       layout->addWidget(it.current());
00342     dontShowDummy=dontShowDummy || (it.current()->isVisibleTo(this));
00343   }
00344   if (dontShowDummy) d->dummy->hide(); else d->dummy->show();
00345   layout->addWidget( closeButton );
00346   layout->activate();
00347   kdDebug(282)<<"KdockWidgetHeader::setDragPanel:minimum height="<<layout->minimumSize().height()<<endl;
00348 #ifdef __GNUC__
00349 #warning FIXME
00350 #endif
00351   drag->setFixedHeight( closeButton->height()); // /*layout->minimumS*/sizeHint().height() );
00352 }
00353 
00354 void KDockWidgetHeader::addButton(KDockButton_Private* btn) {
00355     if (!btn) return;
00356 
00357     if (btn->parentWidget()!=this) {
00358         btn->reparent(this,QPoint(0,0));
00359     }
00360     btn->setFixedSize(closeButton->pixmap()->width(),closeButton->pixmap()->height());
00361     if (!d->btns.containsRef(btn)) d->btns.append(btn);
00362 
00363     btn->show();
00364 
00365     delete layout;
00366     layout = new QHBoxLayout( this );
00367     layout->setResizeMode( QLayout::Minimum );
00368 
00369     layout->addWidget( drag );
00370     layout->addWidget( dockbackButton );
00371     layout->addWidget( d->toDesktopButton );
00372     layout->addWidget( d->dummy);
00373     layout->addWidget( stayButton );
00374      bool dontShowDummy=drag->isVisibleTo(this) || dockbackButton->isVisibleTo(this) ||
00375             d->toDesktopButton->isVisibleTo(this) || stayButton->isVisibleTo(this) ||
00376             closeButton->isVisibleTo(this);
00377      for (QPtrListIterator<KDockButton_Private> it( d->btns );it.current();++it) {
00378             layout->addWidget(it.current());
00379         dontShowDummy=dontShowDummy || (it.current()->isVisibleTo(this));
00380     }
00381     if (dontShowDummy) d->dummy->hide(); else d->dummy->show();
00382     layout->addWidget( closeButton );
00383     layout->activate();
00384     drag->setFixedHeight( layout->minimumSize().height() );
00385 }
00386 
00387 void KDockWidgetHeader::removeButton(KDockButton_Private* btn) {
00388     if (btn->parentWidget()==this) {
00389         if (d->btns.containsRef(btn)) d->btns.removeRef(btn);
00390         delete btn;
00391     }
00392 }
00393 
00394 
00395 void KDockWidgetHeader::slotStayClicked()
00396 {
00397   setDragEnabled(!stayButton->isOn());
00398 }
00399 
00400 bool KDockWidgetHeader::dragEnabled() const
00401 {
00402   return drag->isEnabled();
00403 }
00404 
00405 void KDockWidgetHeader::showUndockButton(bool show)
00406 {
00407   kdDebug(282)<<"KDockWidgetHeader::showUndockButton("<<show<<")"<<endl;
00408   if( d->showToDesktopButton == show )
00409     return;
00410 
00411   d->showToDesktopButton = show;
00412   if( !show || d->topLevel )
00413     d->toDesktopButton->hide( );
00414   else
00415     d->toDesktopButton->show( );
00416 }
00417 
00418 void KDockWidgetHeader::setDragEnabled(bool b)
00419 {
00420   stayButton->setOn(!b);
00421   closeButton->setEnabled(b);
00422   drag->setEnabled(b);
00423 }
00424 
00425 #ifndef NO_KDE2
00426 void KDockWidgetHeader::saveConfig( KConfig* c )
00427 {
00428   c->writeEntry( QString("%1%2").arg(parent()->name()).arg(":stayButton"), stayButton->isOn() );
00429 }
00430 
00431 void KDockWidgetHeader::loadConfig( KConfig* c )
00432 {
00433   setDragEnabled( !c->readBoolEntry( QString("%1%2").arg(parent()->name()).arg(":stayButton"), false ) );
00434 }
00435 #endif
00436 
00437 /*************************************************************************/
00438 
00439 class KDockManager::KDockManagerPrivate
00440 {
00441 public:
00445   QRect dragRect;
00446 
00450   QRect oldDragRect;
00451 
00455   bool readyToDrag;
00456 
00460   QPoint dragOffset;
00461 
00465   bool splitterOpaqueResize;
00466   bool splitterKeepSize;
00467   bool splitterHighResolution;
00468 
00469   QGuardedPtr<KDockWidget> mainDockWidget;
00470 
00471   QObjectList containerDocks;
00472 
00473   QGuardedPtr<KDockWidget> leftContainer;
00474   QGuardedPtr<KDockWidget> topContainer;
00475   QGuardedPtr<KDockWidget> rightContainer;
00476   QGuardedPtr<KDockWidget> bottomContainer;
00477   int m_readDockConfigMode;
00478 };
00479 
00480 
00481 /*************************************************************************/
00482 KDockWidget::KDockWidget( KDockManager* dockManager, const char* name, const QPixmap &pixmap, QWidget* parent, const QString& strCaption, const QString& strTabPageLabel, WFlags f)
00483 #ifdef BORDERLESS_WINDOWS
00484 : QWidget( parent, name, f )//| WType_Dialog | WStyle_Customize | WStyle_NoBorder )
00485 #else
00486 : QWidget( parent, name, f )
00487 #endif
00488   ,formerBrotherDockWidget(0L)
00489   ,currentDockPos(DockNone)
00490   ,formerDockPos(DockNone)
00491   ,widget(0L)
00492   ,pix(new QPixmap(pixmap))
00493   ,prevSideDockPosBeforeDrag(DockNone)
00494   ,isGroup(false)
00495 {
00496   d = new KDockWidgetPrivate();  // create private data
00497 
00498   d->_parent = parent;
00499 
00500   layout = new QVBoxLayout( this );
00501   layout->setResizeMode( QLayout::Minimum );
00502 
00503   manager = dockManager;
00504   manager->childDock->append( this );
00505   installEventFilter( manager );
00506 
00507   eDocking = DockFullDocking;
00508   sDocking = DockFullSite;
00509 
00510   header = 0L;
00511   setHeader( new KDockWidgetHeader( this, "AutoCreatedDockHeader" ) );
00512 
00513   if( strCaption.isNull() )
00514     setCaption( name );
00515   else
00516     setCaption( strCaption);
00517 
00518   if( strTabPageLabel == " ")
00519     setTabPageLabel( caption());
00520   else
00521     setTabPageLabel( strTabPageLabel);
00522 
00523   isTabGroup = false;
00524   d->isContainer =false;
00525   setIcon( pixmap);
00526   widget = 0L;
00527 
00528   QObject::connect(this, SIGNAL(hasUndocked()), manager->main, SLOT(slotDockWidgetUndocked()) );
00529   applyToWidget( parent, QPoint(0,0) );
00530 }
00531 
00532 void KDockWidget::setPixmap(const QPixmap& pixmap) {
00533     delete pix;
00534     pix=new QPixmap(pixmap);
00535     setIcon(*pix);
00536     KDockTabGroup *dtg=parentDockTabGroup();
00537     if (dtg)
00538         dtg->changeTab(this,pixmap,dtg->tabLabel(this));
00539      QWidget *contWid=parentDockContainer();
00540          if (contWid) {
00541             KDockContainer *x = dynamic_cast<KDockContainer*>(contWid);
00542                 if (x) {
00543                         x->setPixmap(this,pixmap);
00544                 }
00545          }
00546 }
00547 
00548 const QPixmap& KDockWidget::pixmap() const {
00549     return *pix;
00550 }
00551 
00552 KDockWidget::~KDockWidget()
00553 {
00554   d->pendingDtor = true;
00555   if ( !manager->undockProcess ){
00556     d->blockHasUndockedSignal = true;
00557     undock();
00558     d->blockHasUndockedSignal = false;
00559   }
00560 
00561   if (latestKDockContainer()) {
00562     KDockContainer *x = dynamic_cast<KDockContainer*>(latestKDockContainer());
00563     if (x) {
00564       x->removeWidget(this);
00565     }
00566   }
00567   emit iMBeingClosed();
00568   if (manager->d) manager->d->containerDocks.remove(this);
00569   manager->childDock->remove( this );
00570   delete pix;
00571   delete d; // destroy private data
00572   d=0;
00573 }
00574 
00575 void KDockWidget::paintEvent(QPaintEvent* pe)
00576 {
00577     QWidget::paintEvent(pe);
00578         QPainter paint;
00579         paint.begin( this );
00580         style().drawPrimitive (QStyle::PE_Panel, &paint, QRect(0,0,width(), height()), colorGroup());
00581         paint.end();
00582 }
00583 
00584 void KDockWidget::leaveEvent(QEvent *e)
00585 {
00586     QWidget::leaveEvent(e);
00587 #ifdef BORDERLESS_WINDOWS
00588     if (parent()) return;
00589 //  setCursor(QCursor(ArrowCursor));
00590 #endif
00591 }
00592 
00593 void KDockWidget::mousePressEvent(QMouseEvent* mme)
00594 {
00595 #ifdef BORDERLESS_WINDOWS
00596     if (!parent())
00597     {
00598         kdDebug(282)<<"KDockWidget::mousePressEvent"<<endl;
00599 
00600         bool bbottom;
00601         bool bleft;
00602         bool bright;
00603         bool btop;
00604         int styleheight;
00605         QPoint mp;
00606         mp=mme->pos();
00607             styleheight=2*style().pixelMetric(QStyle::PM_DefaultFrameWidth,this);
00608         bbottom=mp.y()>=height()-styleheight;
00609         btop=mp.y()<=styleheight;
00610         bleft=mp.x()<=styleheight;
00611         bright=mp.x()>=width()-styleheight;
00612         kdDebug(282)<<"mousemovevent"<<endl;
00613         d->resizing=true;
00614         if (bright)
00615         {
00616             if (btop)
00617             {
00618                 d->resizeMode=KDockWidgetPrivate::ResizeTopRight;
00619                 d->resizePos=QPoint(width(),0)-mme->pos();
00620 
00621             }
00622             else
00623             {
00624                 d->resizePos=QPoint(width(),height())-mme->pos();
00625                 if (bbottom) d->resizeMode=KDockWidgetPrivate::ResizeBottomRight;
00626                 else d->resizeMode=KDockWidgetPrivate::ResizeRight;
00627             }
00628         }
00629         else if (bleft)
00630         {
00631             if (btop) setCursor(QCursor(SizeFDiagCursor));
00632             else
00633             if (bbottom) setCursor(QCursor(SizeBDiagCursor));
00634             else setCursor(QCursor(SizeHorCursor));
00635         }
00636         else
00637         if (bbottom)
00638         {
00639             d->resizeMode=KDockWidgetPrivate::ResizeBottom;
00640             d->resizePos=QPoint(0,height())-mme->pos();
00641         }
00642         else
00643         if  (btop) setCursor(QCursor(SizeVerCursor));
00644         else d->resizing=false;
00645 
00646         if (d->resizing) grabMouse(cursor());
00647 
00648     }
00649 #endif
00650     QWidget::mousePressEvent(mme);
00651 }
00652 
00653 void KDockWidget::mouseReleaseEvent(QMouseEvent* ev)
00654 {
00655 #ifdef BORDERLESS_WINDOWS
00656     d->resizing=false;
00657     releaseMouse();
00658 #endif
00659     QWidget::mouseReleaseEvent(ev);
00660 }
00661 
00662 void  KDockWidget::mouseMoveEvent(QMouseEvent* mme)
00663 {
00664     QWidget::mouseMoveEvent(mme);
00665 #ifdef BORDERLESS_WINDOWS
00666     if (parent()) return;
00667 
00668     if (d->resizing)
00669     {
00670         switch (d->resizeMode)
00671         {
00672             case KDockWidgetPrivate::ResizeRight:
00673                 resize(mme->pos().x()+d->resizePos.x(),height());
00674                 break;
00675             case KDockWidgetPrivate::ResizeBottomRight:
00676                 resize(mme->pos().x()+d->resizePos.x(),mme->pos().y()+d->resizePos.y());
00677                 break;
00678             case KDockWidgetPrivate::ResizeBottom:
00679                 resize(width(),mme->pos().y()+d->resizePos.y());
00680                 break;
00681             default:
00682                 break;
00683         }
00684         return;
00685     }
00686 
00687 
00688     bool bbottom;
00689     bool bleft;
00690     bool bright;
00691     bool btop;
00692     int styleheight;
00693     QPoint mp;
00694     mp=mme->pos();
00695         styleheight=2*style().pixelMetric(QStyle::PM_DefaultFrameWidth,this);
00696     bbottom=mp.y()>=height()-styleheight;
00697     btop=mp.y()<=styleheight;
00698     bleft=mp.x()<=styleheight;
00699     bright=mp.x()>=width()-styleheight;
00700     kdDebug(282)<<"mousemovevent"<<endl;
00701     if (bright)
00702     {
00703         if (btop) setCursor(QCursor(SizeBDiagCursor));
00704         else
00705         if (bbottom) setCursor(QCursor(SizeFDiagCursor));
00706         else setCursor(QCursor(SizeHorCursor));
00707     }
00708     else if (bleft)
00709     {
00710         if (btop) setCursor(QCursor(SizeFDiagCursor));
00711         else
00712         if (bbottom) setCursor(QCursor(SizeBDiagCursor));
00713         else setCursor(QCursor(SizeHorCursor));
00714     }
00715     else
00716     if (bbottom ||  btop) setCursor(QCursor(SizeVerCursor));
00717     else setCursor(QCursor(ArrowCursor));
00718 #endif
00719 }
00720 
00721 void KDockWidget::setLatestKDockContainer(QWidget* container)
00722 {
00723     if (container)
00724     {
00725         if (dynamic_cast<KDockContainer*>(container))
00726             d->container=container;
00727         else
00728             d->container=0;
00729     }
00730 }
00731 
00732 QWidget* KDockWidget::latestKDockContainer()
00733 {
00734     if (!(d->container)) return 0;
00735     if (dynamic_cast<KDockContainer*>(d->container.operator->())) return d->container;
00736     return 0;
00737 }
00738 
00739 
00740 
00741 KDockWidgetAbstractHeader *KDockWidget::getHeader() {
00742     return header;
00743 }
00744 
00745 void KDockWidget::setHeader( KDockWidgetAbstractHeader* h )
00746 {
00747   if ( !h ) return;
00748 
00749   if ( header ){
00750     delete header;
00751     delete layout;
00752     header = h;
00753     layout = new QVBoxLayout( this );
00754     layout->setResizeMode( QLayout::Minimum );
00755     layout->addWidget( header );
00756      setWidget( widget );
00757   } else {
00758     header = h;
00759     layout->addWidget( header );
00760   }
00761   kdDebug(282)<<caption()<<": KDockWidget::setHeader"<<endl;
00762   setEnableDocking(eDocking);
00763 }
00764 
00765 void KDockWidget::setEnableDocking( int pos )
00766 {
00767   eDocking = pos;
00768   if( header && header->inherits( "KDockWidgetHeader" ) )
00769      ( ( KDockWidgetHeader* ) header )->showUndockButton( pos & DockDesktop );
00770   updateHeader();
00771 }
00772 
00773 void KDockWidget::updateHeader()
00774 {
00775   if ( parent() ){
00776 #ifdef BORDERLESS_WINDOWS
00777       layout->setMargin(0);
00778       setMouseTracking(false);
00779       setCursor(QCursor(ArrowCursor));
00780 #endif
00781 
00782     if ( (parent() == manager->main) || isGroup || (eDocking == KDockWidget::DockNone) ){
00783       header->hide();
00784     } else {
00785       header->setTopLevel( false );
00786       if (widget && dynamic_cast<KDockContainer*>(widget))
00787         header->hide();
00788       else
00789         header->show();
00790     }
00791   } else {
00792     header->setTopLevel( true );
00793     header->show();
00794 #ifdef BORDERLESS_WINDOWS
00795       layout->setMargin(2*style().pixelMetric(QStyle::PM_DefaultFrameWidth,this));
00796       setMouseTracking(true);
00797 #endif
00798   }
00799 }
00800 
00801 void KDockWidget::applyToWidget( QWidget* s, const QPoint& p )
00802 {
00803   if ( parent() != s )
00804   {
00805     hide();
00806     reparent(s, 0, QPoint(0,0), false);
00807   }
00808 
00809   if ( s && s->inherits("KDockMainWindow") ){
00810     ((KDockMainWindow*)s)->setView( this );
00811   }
00812 
00813   if ( manager && s == manager->main ){
00814       setGeometry( QRect(QPoint(0,0), manager->main->geometry().size()) );
00815   }
00816 
00817   if ( !s )
00818   {
00819     move(p);
00820 
00821 #ifndef NO_KDE2
00822 #ifdef Q_WS_X11
00823     if (d->transient && d->_parent)
00824       XSetTransientForHint( qt_xdisplay(), winId(), d->_parent->winId() );
00825 
00826 #ifdef BORDERLESS_WINDOWS
00827     KWin::setType( winId(), NET::Override); //d->windowType );
00828 //      setWFlags(WStyle_Customize | WStyle_NoBorder | WStyle_Tool);
00829 #else
00830     KWin::setType( winId(), d->windowType );
00831 #endif // BORDERLESS_WINDOW
00832 #endif // Q_WS_X11
00833 #endif
00834 
00835   }
00836   updateHeader();
00837 
00838   setIcon(*pix);
00839 }
00840 
00841 void KDockWidget::show()
00842 {
00843   if ( parent() || manager->main->isVisible() )
00844     if ( !parent() ){
00845      emit manager->setDockDefaultPos( this );
00846      emit setDockDefaultPos();
00847      if ( parent() ){
00848         makeDockVisible();
00849       } else {
00850         QWidget::show();
00851       }
00852     } else {
00853      QWidget::show();
00854     }
00855 }
00856 
00857 #ifndef NO_KDE2
00858 
00859 void KDockWidget::setDockWindowType (NET::WindowType windowType)
00860 {
00861   d->windowType = windowType;
00862   applyToWidget( parentWidget(), QPoint(0,0) );
00863 }
00864 
00865 #endif
00866 
00867 void KDockWidget::setDockWindowTransient (QWidget *parent, bool transientEnabled)
00868 {
00869   d->_parent = parent;
00870   d->transient = transientEnabled;
00871   applyToWidget( parentWidget(), QPoint(0,0) );
00872 }
00873 
00874 QWidget *KDockWidget::transientTo() {
00875     if (d->transient && d->_parent) return d->_parent; else return 0;
00876 }
00877 
00878 bool KDockWidget::event( QEvent *event )
00879 {
00880   switch ( event->type() )
00881   {
00882     #undef FocusIn
00883     case QEvent::FocusIn:
00884       if (widget && !d->pendingFocusInEvent) {
00885          d->pendingFocusInEvent = true;
00886          widget->setFocus();
00887       }
00888       d->pendingFocusInEvent = false;
00889       break;
00890     case QEvent::ChildRemoved:
00891       if ( widget == ((QChildEvent*)event)->child() ) widget = 0L;
00892       break;
00893     case QEvent::Show:
00894       if ( widget ) widget->show();
00895       emit manager->change();
00896       break;
00897     case QEvent::Hide:
00898       if ( widget ) widget->hide();
00899       emit manager->change();
00900       break;
00901     case QEvent::CaptionChange:
00902       if ( parentWidget() ){
00903         if ( parent()->inherits("KDockSplitter") ){
00904           ((KDockSplitter*)(parent()))->updateName();
00905         }
00906         if ( parentDockTabGroup() ){
00907           setDockTabName( parentDockTabGroup() );
00908           parentDockTabGroup()->setTabLabel( this, tabPageLabel() );
00909         }
00910       }
00911       break;
00912     case QEvent::Close:
00913       emit iMBeingClosed();
00914       break;
00915     default:
00916       break;
00917   }
00918   return QWidget::event( event );
00919 }
00920 
00921 KDockWidget *KDockWidget::findNearestDockWidget(DockPosition pos)
00922 {
00923     if (!parent()) return 0;
00924     if (!parent()->inherits("KDockSplitter")) return 0;
00925     Orientation orientation=((pos==DockLeft) || (pos==DockRight)) ? Vertical:Horizontal;
00926         if (((KDockSplitter*)(parent()))->orientation()==orientation)
00927         {
00928             KDockWidget *neighbor=
00929                 ((pos==DockLeft)||(pos==DockTop))?
00930                 static_cast<KDockWidget*>(((KDockSplitter*)(parent()))->getFirst()):
00931                 static_cast<KDockWidget*>(((KDockSplitter*)(parent()))->getLast());
00932 
00933             if (neighbor==this)
00934             return (static_cast<KDockWidget*>(parent()->parent())->findNearestDockWidget(pos));
00935             else
00936             if (neighbor->getWidget() && (neighbor->getWidget()->qt_cast("KDockTabGroup")))
00937                 return (KDockWidget*)(((KDockTabGroup*)neighbor->getWidget())->page(0));
00938             else
00939             return neighbor;
00940         }
00941         else
00942         return (static_cast<KDockWidget*>(parent()->parent())->findNearestDockWidget(pos));
00943 
00944     return 0;
00945 }
00946 
00947 
00948 KDockWidget* KDockWidget::manualDock( KDockWidget* target, DockPosition dockPos, int spliPos, QPoint pos, bool check, int tabIndex )
00949 {
00950   if (this == target)
00951     return 0L;  // docking to itself not possible
00952 //  kdDebug(282)<<"manualDock called "<<endl;
00953   bool succes = true; // tested flag
00954 
00955   // check allowed this dock submit this operations
00956   if ( !(eDocking & (int)dockPos) ){
00957     succes = false;
00958 //  kdDebug(282)<<"KDockWidget::manualDock(): success = false (1)"<<endl;
00959   }
00960 
00961   KDockWidget *tmpTarget;
00962   switch (dockPos) {
00963     case DockLeft:tmpTarget=dockManager()->d->leftContainer;
00964         break;
00965     case DockRight:tmpTarget=dockManager()->d->rightContainer;
00966         break;
00967     case DockBottom:tmpTarget=dockManager()->d->bottomContainer;
00968         break;
00969     case DockTop:tmpTarget=dockManager()->d->topContainer;
00970         break;
00971     default: tmpTarget=0;
00972   }
00973 
00974   if (this!=tmpTarget) {
00975     if (target && (target==dockManager()->d->mainDockWidget) && tmpTarget) {
00976     return manualDock(tmpTarget,DockCenter,spliPos,pos,check,tabIndex);
00977     }
00978   }
00979 
00980   // check allowed target submit this operations
00981   if ( target && !(target->sDocking & (int)dockPos) ){
00982     succes = false;
00983 //  kdDebug(282)<<"KDockWidget::manualDock(): success = false (2)"<<endl;
00984   }
00985 
00986   if ( parent() && !parent()->inherits("KDockSplitter") && !parentDockTabGroup() &&
00987     !(dynamic_cast<KDockContainer*>(parent())) && !parentDockContainer()){
00988 //  kdDebug(282)<<"KDockWidget::manualDock(): success = false (3)"<<endl;
00989 //  kdDebug(282)<<parent()->name()<<endl;
00990     succes = false;
00991   }
00992 
00993 //  kdDebug(282)<<"KDockWidget::manualDock(): success == false "<<endl;
00994   if ( !succes ){
00995     // try to make another manualDock
00996     KDockWidget* dock_result = 0L;
00997     if ( target && !check ){
00998       KDockWidget::DockPosition another__dockPos = KDockWidget::DockNone;
00999       switch ( dockPos ){
01000         case KDockWidget::DockLeft  : another__dockPos = KDockWidget::DockRight ; break;
01001         case KDockWidget::DockRight : another__dockPos = KDockWidget::DockLeft  ; break;
01002         case KDockWidget::DockTop   : another__dockPos = KDockWidget::DockBottom; break;
01003         case KDockWidget::DockBottom: another__dockPos = KDockWidget::DockTop   ; break;
01004         default: break;
01005       }
01006       dock_result = target->manualDock( this, another__dockPos, spliPos, pos, true, tabIndex );
01007     }
01008     return dock_result;
01009   }
01010   // end check block
01011 
01012   d->blockHasUndockedSignal = true;
01013   undock();
01014   d->blockHasUndockedSignal = false;
01015 
01016   if ( !target ){
01017     move( pos );
01018     show();
01019     emit manager->change();
01020     return this;
01021   }
01022 
01023 //  kdDebug(282)<<"Looking for  KDockTabGroup"<<endl;
01024   KDockTabGroup* parentTab = target->parentDockTabGroup();
01025   if ( parentTab ){
01026     // add to existing TabGroup
01027     applyToWidget( parentTab );
01028     parentTab->insertTab( this, icon() ? *icon() : QPixmap(),
01029                           tabPageLabel(), tabIndex );
01030 
01031     QWidget *wantTransient=parentTab->transientTo();
01032     target->setDockWindowTransient(wantTransient,wantTransient);
01033 
01034     setDockTabName( parentTab );
01035     if( !toolTipStr.isEmpty())
01036       parentTab->setTabToolTip( this, toolTipStr);
01037 
01038     currentDockPos = KDockWidget::DockCenter;
01039     emit manager->change();
01040     return (KDockWidget*)parentTab->parent();
01041   }
01042   else
01043   {
01044 //      kdDebug(282)<<"Looking for  KDockContainer"<<endl;
01045     QWidget *contWid=target->parentDockContainer();
01046       if (!contWid) contWid=target->widget;
01047       if (contWid)
01048       {
01049         KDockContainer *cont=dynamic_cast<KDockContainer*>(contWid);
01050           if (cont)
01051           {
01052             if (latestKDockContainer() && (latestKDockContainer()!=contWid)) {
01053                 KDockContainer* dc = dynamic_cast<KDockContainer*>(latestKDockContainer());
01054                 if (dc) {
01055                     dc->removeWidget(this);
01056                 }
01057             }
01058 //          kdDebug(282)<<"KDockContainerFound"<<endl;
01059             applyToWidget( contWid );
01060             cont->insertWidget( this, icon() ? *icon() : QPixmap(),
01061                         tabPageLabel(), tabIndex );
01062             setLatestKDockContainer(contWid);
01063 //          setDockTabName( parentTab );
01064             if( !toolTipStr.isEmpty())
01065             cont->setToolTip( this, toolTipStr);
01066 
01067             currentDockPos = KDockWidget::DockCenter;
01068             emit manager->change();
01069             return (KDockWidget*)(cont->parentDockWidget());
01070 
01071           }
01072       }
01073   }
01074 
01075   // create a new dockwidget that will contain the target and this
01076   QWidget* parentDock = target->parentWidget();
01077   KDockWidget* newDock = new KDockWidget( manager, "tempName", QPixmap(""), parentDock );
01078   newDock->currentDockPos = target->currentDockPos;
01079 
01080   if ( dockPos == KDockWidget::DockCenter ){
01081     newDock->isTabGroup = true;
01082   } else {
01083     newDock->isGroup = true;
01084   }
01085   newDock->eDocking = (target->eDocking & eDocking) & (~(int)KDockWidget::DockCenter);
01086 
01087   newDock->applyToWidget( parentDock );
01088 
01089   if ( !parentDock ){
01090     // dock to a toplevel dockwidget means newDock is toplevel now
01091     newDock->move( target->frameGeometry().topLeft() );
01092     newDock->resize( target->geometry().size() );
01093     if ( target->isVisibleToTLW() ) newDock->show();
01094   }
01095 
01096   // redirect the dockback button to the new dockwidget
01097   if( target->formerBrotherDockWidget ) {
01098     newDock->setFormerBrotherDockWidget(target->formerBrotherDockWidget);
01099     if( formerBrotherDockWidget )
01100       target->loseFormerBrotherDockWidget();
01101     }
01102   newDock->formerDockPos = target->formerDockPos;
01103 
01104 
01105  // HERE SOMETING CREATING CONTAINERS SHOULD BE ADDED !!!!!
01106   if ( dockPos == KDockWidget::DockCenter )
01107   {
01108     KDockTabGroup* tab = new KDockTabGroup( newDock, "_dock_tab");
01109     QObject::connect(tab, SIGNAL(currentChanged(QWidget*)), d, SLOT(slotFocusEmbeddedWidget(QWidget*)));
01110     newDock->setWidget( tab );
01111 
01112     target->applyToWidget( tab );
01113     applyToWidget( tab );
01114 
01115 
01116     tab->insertTab( target, target->icon() ? *(target->icon()) : QPixmap(),
01117                     target->tabPageLabel() );
01118 
01119 
01120 
01121     if( !target->toolTipString().isEmpty())
01122      tab->setTabToolTip( target, target->toolTipString());
01123 
01124     tab->insertTab( this, icon() ? *icon() : QPixmap(),
01125                     tabPageLabel(), tabIndex );
01126 
01127     QRect geom=newDock->geometry();
01128     QWidget *wantTransient=tab->transientTo();
01129     newDock->setDockWindowTransient(wantTransient,wantTransient);
01130     newDock->setGeometry(geom);
01131 
01132     if( !toolTipString().isEmpty())
01133       tab->setTabToolTip( this, toolTipString());
01134 
01135     setDockTabName( tab );
01136     tab->show();
01137 
01138     currentDockPos = DockCenter;
01139     target->formerDockPos = target->currentDockPos;
01140     target->currentDockPos = DockCenter;
01141   }
01142   else {
01143     // if to dock not to the center of the target dockwidget,
01144     // dock to newDock
01145     KDockSplitter* panner = 0L;
01146     if ( dockPos == KDockWidget::DockTop  || dockPos == KDockWidget::DockBottom ) panner = new KDockSplitter( newDock, "_dock_split_", Horizontal, spliPos, manager->splitterHighResolution() );
01147     if ( dockPos == KDockWidget::DockLeft || dockPos == KDockWidget::DockRight  ) panner = new KDockSplitter( newDock, "_dock_split_", Vertical , spliPos, manager->splitterHighResolution() );
01148     newDock->setWidget( panner );
01149 
01150     panner->setOpaqueResize(manager->splitterOpaqueResize());
01151     panner->setKeepSize(manager->splitterKeepSize());
01152     panner->setFocusPolicy( NoFocus );
01153     target->applyToWidget( panner );
01154     applyToWidget( panner );
01155     target->formerDockPos = target->currentDockPos;
01156     if ( dockPos == KDockWidget::DockRight) {
01157       panner->activate( target, this );
01158       currentDockPos = KDockWidget::DockRight;
01159       target->currentDockPos = KDockWidget::DockLeft;
01160     }
01161     else if( dockPos == KDockWidget::DockBottom) {
01162       panner->activate( target, this );
01163       currentDockPos = KDockWidget::DockBottom;
01164       target->currentDockPos = KDockWidget::DockTop;
01165     }
01166     else if( dockPos == KDockWidget::DockTop) {
01167       panner->activate( this, target );
01168       currentDockPos = KDockWidget::DockTop;
01169       target->currentDockPos = KDockWidget::DockBottom;
01170     }
01171     else if( dockPos == KDockWidget::DockLeft) {
01172       panner->activate( this, target );
01173       currentDockPos = KDockWidget::DockLeft;
01174       target->currentDockPos = KDockWidget::DockRight;
01175     }
01176     target->show();
01177     show();
01178     panner->show();
01179   }
01180 
01181   if ( parentDock ){
01182     if ( parentDock->inherits("KDockSplitter") ){
01183       KDockSplitter* sp = (KDockSplitter*)parentDock;
01184       sp->deactivate();
01185       if ( sp->getFirst() == target )
01186         sp->activate( newDock, 0L );
01187       else
01188         sp->activate( 0L, newDock );
01189     }
01190   }
01191 
01192   newDock->show();
01193   emit target->docking( this, dockPos );
01194   emit manager->replaceDock( target, newDock );
01195   emit manager->change();
01196 
01197   return newDock;
01198 }
01199 
01200 KDockTabGroup* KDockWidget::parentDockTabGroup() const
01201 {
01202   if ( !parent() ) return 0L;
01203   QWidget* candidate = parentWidget()->parentWidget();
01204   if ( candidate && candidate->inherits("KDockTabGroup") ) return (KDockTabGroup*)candidate;
01205   return 0L;
01206 }
01207 
01208 QWidget *KDockWidget::parentDockContainer() const
01209 {
01210   if (!parent()) return 0L;
01211   QWidget* candidate = parentWidget()->parentWidget();
01212   if (candidate && dynamic_cast<KDockContainer*>(candidate)) return candidate;
01213   return 0L;
01214 }
01215 
01216 
01217 void KDockWidget::setForcedFixedWidth(int w)
01218 {
01219     d->forcedWidth=w;
01220     setFixedWidth(w);
01221     if (!parent()) return;
01222     if (parent()->inherits("KDockSplitter"))
01223         static_cast<KDockSplitter*>(parent()->qt_cast("KDockSplitter"))->setForcedFixedWidth(this,w);
01224 }
01225 
01226 void KDockWidget::setForcedFixedHeight(int h)
01227 {
01228     d->forcedHeight=h;
01229     setFixedHeight(h);
01230     if (!parent()) return;
01231     if (parent()->inherits("KDockSplitter"))
01232         static_cast<KDockSplitter*>(parent()->qt_cast("KDockSplitter"))->setForcedFixedHeight(this,h);
01233 }
01234 
01235 int KDockWidget::forcedFixedWidth()
01236 {
01237     return d->forcedWidth;
01238 }
01239 
01240 int KDockWidget::forcedFixedHeight()
01241 {
01242     return d->forcedHeight;
01243 }
01244 
01245 void KDockWidget::restoreFromForcedFixedSize()
01246 {
01247     d->forcedWidth=-1;
01248     setMinimumWidth(0);
01249     setMaximumWidth(32000);
01250     setMinimumHeight(0);
01251     setMaximumHeight(32000);
01252     if (!parent()) return;
01253     if (parent()->inherits("KDockSplitter"))
01254         static_cast<KDockSplitter*>(parent()->qt_cast("KDockSplitter"))->restoreFromForcedFixedSize(this);
01255 }
01256 
01257 void KDockWidget::toDesktop()
01258 {
01259    QPoint p = mapToGlobal( QPoint( -30, -30 ) );
01260    if( p.x( ) < 0 )
01261       p.setX( 0 );
01262    if( p.y( ) < 0 )
01263       p.setY( 0 );
01264    manualDock( 0, DockDesktop, 50, p );
01265 }
01266 
01267 KDockWidget::DockPosition KDockWidget::currentDockPosition() const
01268 {
01269     return currentDockPos;
01270 }
01271 
01272 void KDockWidget::undock()
01273 {
01274 //  kdDebug(282)<<"KDockWidget::undock()"<<endl;
01275 
01276   manager->d->dragRect = QRect ();
01277   manager->drawDragRectangle ();
01278 
01279   QWidget* parentW = parentWidget();
01280   if ( !parentW ){
01281     hide();
01282     if (!d->blockHasUndockedSignal)
01283       emit hasUndocked();
01284     return;
01285   }
01286 
01287   formerDockPos = currentDockPos;
01288   currentDockPos = KDockWidget::DockDesktop;
01289 
01290   manager->blockSignals(true);
01291   manager->undockProcess = true;
01292 
01293   bool isV = parentW->isVisibleToTLW();
01294 
01295   //UNDOCK HAS TO BE IMPLEMENTED CORRECTLY :)
01296   KDockTabGroup* parentTab = parentDockTabGroup();
01297   if ( parentTab ){
01298     d->index = parentTab->indexOf( this); // memorize the page position in the tab widget
01299     parentTab->removePage( this );
01300 /*
01301     QWidget *wantTransient=parentTab->transientTo();
01302     target->setDockWindowTransient(wantTransient,wantTransient);
01303  */
01304     setFormerBrotherDockWidget((KDockWidget*)parentTab->page(0));
01305     applyToWidget( 0L );
01306     if ( parentTab->count() == 1 ){
01307 
01308       // last subdock widget in the tab control
01309       KDockWidget* lastTab = (KDockWidget*)parentTab->page(0);
01310       parentTab->removePage( lastTab );
01311 /*      QWidget *wantTransient=parentTab->transientTo();
01312       target->setDockWindowTransient(wantTransient,wantTransient);*/
01313 
01314       lastTab->applyToWidget( 0L );
01315       lastTab->move( parentTab->mapToGlobal(parentTab->frameGeometry().topLeft()) );
01316 
01317       // KDockTabGroup always have a parent that is a KDockWidget
01318       KDockWidget* parentOfTab = (KDockWidget*)parentTab->parent();
01319       delete parentTab; // KDockTabGroup
01320 
01321       QWidget* parentOfDockWidget = parentOfTab->parentWidget();
01322       if ( !parentOfDockWidget ){
01323           if ( isV ) lastTab->show();
01324       } else {
01325         if ( parentOfDockWidget->inherits("KDockSplitter") ){
01326           KDockSplitter* split = (KDockSplitter*)parentOfDockWidget;
01327           lastTab->applyToWidget( split );
01328           split->deactivate();
01329           if ( split->getFirst() == parentOfTab ){
01330             split->activate( lastTab );
01331             if ( ((KDockWidget*)split->parent())->splitterOrientation == Vertical )
01332               emit ((KDockWidget*)split->getAnother(parentOfTab))->docking( parentOfTab, KDockWidget::DockLeft );
01333             else
01334               emit ((KDockWidget*)split->getAnother(parentOfTab))->docking( parentOfTab, KDockWidget::DockTop );
01335           } else {
01336             split->activate( 0L, lastTab );
01337             if ( ((KDockWidget*)split->parent())->splitterOrientation == Vertical )
01338               emit ((KDockWidget*)split->getAnother(parentOfTab))->docking( parentOfTab, KDockWidget::DockRight );
01339             else
01340               emit ((KDockWidget*)split->getAnother(parentOfTab))->docking( parentOfTab, KDockWidget::DockBottom );
01341           }
01342           split->show();
01343         } else {
01344           lastTab->applyToWidget( parentOfDockWidget );
01345         }
01346         lastTab->show();
01347       }
01348       manager->blockSignals(false);
01349       emit manager->replaceDock( parentOfTab, lastTab );
01350       lastTab->currentDockPos = parentOfTab->currentDockPos;
01351       emit parentOfTab->iMBeingClosed();
01352       manager->blockSignals(true);
01353       delete parentOfTab;
01354 
01355     } else {
01356       setDockTabName( parentTab );
01357     }
01358   } else {
01359  /*********************************************************************************************/
01360   //QWidget* containerWidget = (QWidget*)parent();
01361   bool undockedFromContainer=false;
01362   if (d->container)
01363   {
01364 //    kdDebug(282)<<"undocked from dockcontainer"<<endl;
01365       undockedFromContainer=true;
01366       KDockContainer* dc = dynamic_cast<KDockContainer*>(d->container.operator->());
01367       if (dc) {
01368           dc->undockWidget(this);
01369           setFormerBrotherDockWidget(dc->parentDockWidget());
01370       }
01371       applyToWidget( 0L );
01372   }
01373    if (!undockedFromContainer) {
01374 /*********************************************************************************************/
01375     if ( parentW->inherits("KDockSplitter") ){
01376       KDockSplitter* parentSplitterOfDockWidget = (KDockSplitter*)parentW;
01377       d->splitPosInPercent = parentSplitterOfDockWidget->separatorPos();
01378 
01379       KDockWidget* secondWidget = (KDockWidget*)parentSplitterOfDockWidget->getAnother( this );
01380       KDockWidget* group        = (KDockWidget*)parentSplitterOfDockWidget->parentWidget();
01381       setFormerBrotherDockWidget(secondWidget);
01382       applyToWidget( 0L );
01383       group->hide();
01384 
01385       if ( !group->parentWidget() ){
01386         secondWidget->applyToWidget( 0L, group->frameGeometry().topLeft() );
01387         secondWidget->resize( group->width(), group->height() );
01388       } else {
01389         QWidget* obj = group->parentWidget();
01390         secondWidget->applyToWidget( obj );
01391         if ( obj->inherits("KDockSplitter") ){
01392           KDockSplitter* parentOfGroup = (KDockSplitter*)obj;
01393           parentOfGroup->deactivate();
01394 
01395           if ( parentOfGroup->getFirst() == group )
01396             parentOfGroup->activate( secondWidget );
01397           else
01398             parentOfGroup->activate( 0L, secondWidget );
01399         }
01400       }
01401       secondWidget->currentDockPos = group->currentDockPos;
01402       secondWidget->formerDockPos  = group->formerDockPos;
01403       delete parentSplitterOfDockWidget;
01404       manager->blockSignals(false);
01405       emit manager->replaceDock( group, secondWidget );
01406       emit group->iMBeingClosed();
01407       manager->blockSignals(true);
01408       delete group;
01409 
01410       if ( isV ) secondWidget->show();
01411     } else {
01412       if (!d->pendingDtor) {
01413         // don't reparent in the dtor of this
01414         applyToWidget( 0L );
01415       }
01416     }
01417 /*********************************************************************************************/
01418   }
01419   }
01420   manager->blockSignals(false);
01421   if (!d->blockHasUndockedSignal)
01422     emit manager->change();
01423   manager->undockProcess = false;
01424 
01425   if (!d->blockHasUndockedSignal)
01426     emit hasUndocked();
01427 }
01428 
01429 void KDockWidget::setWidget( QWidget* mw )
01430 {
01431   if ( !mw ) return;
01432 
01433   if ( mw->parent() != this ){
01434     mw->reparent(this, 0, QPoint(0,0), false);
01435   }
01436 
01437 #ifdef BORDERLESS_WINDOWS
01438   if (!mw->ownCursor()) mw->setCursor(QCursor(ArrowCursor));
01439 #endif
01440   widget = mw;
01441   delete layout;
01442 
01443   layout = new QVBoxLayout( this );
01444   layout->setResizeMode( QLayout::Minimum );
01445 
01446   KDockContainer* dc = dynamic_cast<KDockContainer*>(widget);
01447   if (dc)
01448   {
01449     d->isContainer=true;
01450     manager->d->containerDocks.append(this);
01451   }
01452   else
01453   {
01454     d->isContainer=false;
01455   }
01456 
01457   {
01458      header->show();
01459      layout->addWidget( header );
01460      layout->addWidget( widget,1 );
01461   }
01462   updateHeader();
01463   emit widgetSet(mw);
01464 }
01465 
01466 void KDockWidget::setDockTabName( KDockTabGroup* tab )
01467 {
01468   QString listOfName;
01469   QString listOfCaption;
01470   for ( int i = 0; i < tab->count(); ++i ) {
01471     QWidget *w = tab->page( i );
01472     listOfCaption.append( w->caption() ).append(",");
01473     listOfName.append( w->name() ).append(",");
01474   }
01475   listOfCaption.remove( listOfCaption.length()-1, 1 );
01476   listOfName.remove( listOfName.length()-1, 1 );
01477 
01478   tab->parentWidget()->setName( listOfName.utf8() );
01479   tab->parentWidget()->setCaption( listOfCaption );
01480 
01481   tab->parentWidget()->repaint( false ); // KDockWidget->repaint
01482   if ( tab->parentWidget()->parent() )
01483     if ( tab->parentWidget()->parent()->inherits("KDockSplitter") )
01484       ((KDockSplitter*)(tab->parentWidget()->parent()))->updateName();
01485 }
01486 
01487 bool KDockWidget::mayBeHide() const
01488 {
01489   bool f = (parent() != manager->main);
01490   return ( !isGroup && !isTabGroup && f && isVisible() && ( eDocking != (int)KDockWidget::DockNone ) );
01491 }
01492 
01493 bool KDockWidget::mayBeShow() const
01494 {
01495   bool f = (parent() != manager->main);
01496   return ( !isGroup && !isTabGroup && f && !isVisible() );
01497 }
01498 
01499 void KDockWidget::changeHideShowState()
01500 {
01501   if ( mayBeHide() ){
01502     undock();
01503     return;
01504   }
01505 
01506   if ( mayBeShow() ){
01507     if ( manager->main->inherits("KDockMainWindow") ){
01508       ((KDockMainWindow*)manager->main)->makeDockVisible(this);
01509     } else {
01510       makeDockVisible();
01511     }
01512   }
01513 }
01514 
01515 void KDockWidget::makeDockVisible()
01516 {
01517   if ( parentDockTabGroup() ){
01518     parentDockTabGroup()->showPage( this );
01519   }
01520   if (parentDockContainer()) {
01521     QWidget *contWid=parentDockContainer();
01522     KDockContainer *x = dynamic_cast<KDockContainer*>(contWid);
01523     if (x) {
01524       x->showWidget(this);
01525     }
01526   }
01527   if ( isVisible() ) return;
01528 
01529   QWidget* p = parentWidget();
01530   while ( p ){
01531     if ( !p->isVisible() )
01532       p->show();
01533     p = p->parentWidget();
01534   }
01535   if( !parent() ) // is undocked
01536     dockBack();
01537   show();
01538 }
01539 
01540 void KDockWidget::setFormerBrotherDockWidget(KDockWidget *dockWidget)
01541 {
01542   formerBrotherDockWidget = dockWidget;
01543   if( formerBrotherDockWidget )
01544     QObject::connect( formerBrotherDockWidget, SIGNAL(iMBeingClosed()),
01545                       this, SLOT(loseFormerBrotherDockWidget()) );
01546 }
01547 
01548 void KDockWidget::loseFormerBrotherDockWidget()
01549 {
01550   if( formerBrotherDockWidget )
01551     QObject::disconnect( formerBrotherDockWidget, SIGNAL(iMBeingClosed()),
01552                          this, SLOT(loseFormerBrotherDockWidget()) );
01553   formerBrotherDockWidget = 0L;
01554   repaint();
01555 }
01556 
01557 void KDockWidget::dockBack()
01558 {
01559   if( formerBrotherDockWidget) {
01560     // search all children if it tries to dock back to a child
01561     bool found = false;
01562     QObjectList* cl = queryList("KDockWidget");
01563     QObjectListIt it( *cl );
01564     QObject * obj;
01565     while ( !found && (obj=it.current()) != 0 ) {
01566       ++it;
01567       QWidget* widg = (QWidget*)obj;
01568       if( widg == formerBrotherDockWidget)
01569         found = true;
01570     }
01571     delete cl;
01572 
01573     if( !found) {
01574       // can dock back to the former brother dockwidget
01575       manualDock( formerBrotherDockWidget, formerDockPos, d->splitPosInPercent, QPoint(0,0), false, d->index);
01576       formerBrotherDockWidget = 0L;
01577       makeDockVisible();
01578       return;
01579     }
01580   }
01581 
01582   // else dockback to the dockmainwindow (default behavior)
01583   manualDock( ((KDockMainWindow*)manager->main)->getMainDockWidget(), formerDockPos, d->splitPosInPercent, QPoint(0,0), false, d->index);
01584   formerBrotherDockWidget = 0L;
01585   if (parent())
01586     makeDockVisible();
01587 }
01588 
01589 bool KDockWidget::isDockBackPossible() const
01590 {
01591   if( !(formerBrotherDockWidget) || !(formerBrotherDockWidget->dockSite() & formerDockPos))
01592     return false;
01593   else
01594     return true;
01595 }
01596 
01597 /**************************************************************************************/
01598 
01599 
01600 KDockManager::KDockManager( QWidget* mainWindow , const char* name )
01601 :QObject( mainWindow, name )
01602   ,main(mainWindow)
01603   ,currentDragWidget(0L)
01604   ,currentMoveWidget(0L)
01605   ,childDockWidgetList(0L)
01606   ,autoCreateDock(0L)
01607   ,storeW(0)
01608   ,storeH(0)
01609   ,dragging(false)
01610   ,undockProcess(false)
01611   ,dropCancel(true)
01612 {
01613   d = new KDockManagerPrivate;
01614 
01615   d->readyToDrag = false;
01616   d->mainDockWidget=0;
01617 
01618 #ifndef NO_KDE2
01619   d->splitterOpaqueResize = KGlobalSettings::opaqueResize();
01620 #else
01621   d->splitterOpaqueResize = false;
01622 #endif
01623 
01624   d->splitterKeepSize = false;
01625   d->splitterHighResolution = false;
01626   d->m_readDockConfigMode = WrapExistingWidgetsOnly; // default as before
01627 
01628   main->installEventFilter( this );
01629 
01630   undockProcess = false;
01631 
01632   menuData = new QPtrList<MenuDockData>;
01633   menuData->setAutoDelete( true );
01634   menuData->setAutoDelete( true );
01635 
01636 #ifndef NO_KDE2
01637   menu = new KPopupMenu();
01638 #else
01639   menu = new QPopupMenu();
01640 #endif
01641 
01642   connect( menu, SIGNAL(aboutToShow()), SLOT(slotMenuPopup()) );
01643   connect( menu, SIGNAL(activated(int)), SLOT(slotMenuActivated(int)) );
01644 
01645   childDock = new QObjectList();
01646   childDock->setAutoDelete( false );
01647 }
01648 
01649 
01650 void KDockManager::setMainDockWidget2(KDockWidget *w)
01651 {
01652   d->mainDockWidget=w;
01653 }
01654 
01655 KDockManager::~KDockManager()
01656 {
01657   delete menuData;
01658   delete menu;
01659 
01660   QObjectListIt it( *childDock );
01661   KDockWidget * obj;
01662 
01663   while ( (obj=(KDockWidget*)it.current()) ) {
01664     delete obj;
01665   }
01666   delete childDock;
01667   delete d;
01668   d=0;
01669 }
01670 
01671 void KDockManager::activate()
01672 {
01673   QObjectListIt it( *childDock );
01674   KDockWidget * obj;
01675 
01676   while ( (obj=(KDockWidget*)it.current()) ) {
01677     ++it;
01678     if ( obj->widget ) obj->widget->show();
01679     if ( !obj->parentDockTabGroup() ){
01680         obj->show();
01681     }
01682   }
01683   if ( !main->inherits("QDialog") ) main->show();
01684 }
01685 
01686 bool KDockManager::eventFilter( QObject *obj, QEvent *event )
01687 {
01688 
01689   if ( obj->inherits("KDockWidgetAbstractHeaderDrag") ){
01690     KDockWidget* pDockWdgAtCursor = 0L;
01691     KDockWidget* curdw = ((KDockWidgetAbstractHeaderDrag*)obj)->dockWidget();
01692     switch ( event->type() ){
01693       case QEvent::MouseButtonDblClick:
01694         if (curdw->currentDockPos == KDockWidget::DockDesktop)  curdw->dockBack();
01695         else
01696     {
01697         curdw->toDesktop();
01698         // curdw->manualDock (0, KDockWidget::DockDesktop);
01699     }
01700         break;
01701 
01702       case QEvent::MouseButtonPress:
01703         if ( ((QMouseEvent*)event)->button() == LeftButton ){
01704           if ( curdw->eDocking != (int)KDockWidget::DockNone ){
01705             dropCancel = true;
01706             curdw->setFocus();
01707             qApp->processOneEvent();
01708 
01709             currentDragWidget = curdw;
01710             currentMoveWidget = 0L;
01711             childDockWidgetList = new QWidgetList();
01712             childDockWidgetList->append( curdw );
01713             findChildDockWidget( curdw, childDockWidgetList );
01714 
01715             //d->oldDragRect = QRect(); should fix rectangle not erased problem
01716             d->dragRect = QRect(curdw->geometry());
01717             QPoint p = curdw->mapToGlobal(QPoint(0,0));
01718             d->dragRect.moveTopLeft(p);
01719             drawDragRectangle();
01720             d->readyToDrag = true;
01721 
01722             d->dragOffset = QCursor::pos()-currentDragWidget->mapToGlobal(QPoint(0,0));
01723           }
01724 
01725         }
01726         break;
01727       case QEvent::MouseButtonRelease:
01728         if ( ((QMouseEvent*)event)->button() == LeftButton ){
01729           if ( dragging ){
01730             if ( !dropCancel )
01731               drop();
01732             else
01733               cancelDrop();
01734           }
01735           if (d->readyToDrag) {
01736               d->readyToDrag = false;
01737               //d->oldDragRect = QRect(); should fix rectangle not erased problem
01738               d->dragRect = QRect(curdw->geometry());
01739               QPoint p = curdw->mapToGlobal(QPoint(0,0));
01740               d->dragRect.moveTopLeft(p);
01741               drawDragRectangle();
01742               currentDragWidget = 0L;
01743               delete childDockWidgetList;
01744               childDockWidgetList = 0L;
01745           }
01746           dragging = false;
01747           dropCancel = true;
01748         }
01749         break;
01750       case QEvent::MouseMove:
01751         if ( dragging ) {
01752 
01753 #ifdef BORDERLESS_WINDOWS
01754 //BEGIN TEST
01755       KDockWidget *oldMoveWidget;
01756       if (!curdw->parent())
01757       {
01758         curdw->move(QCursor::pos()-d->dragOffset);
01759             pDockWdgAtCursor = findDockWidgetAt( QCursor::pos()-QPoint(0,d->dragOffset.y()+3) );
01760                 oldMoveWidget = currentMoveWidget;
01761       }
01762       else
01763       {
01764             pDockWdgAtCursor = findDockWidgetAt( QCursor::pos() );
01765                 oldMoveWidget = currentMoveWidget;
01766       }
01767 //END TEST
01768 #else
01769       pDockWdgAtCursor = findDockWidgetAt( QCursor::pos() );
01770           KDockWidget* oldMoveWidget = currentMoveWidget;
01771 #endif
01772 
01773       if ( currentMoveWidget  && pDockWdgAtCursor == currentMoveWidget ) { //move
01774             dragMove( currentMoveWidget, currentMoveWidget->mapFromGlobal( QCursor::pos() ) );
01775             break;
01776           } else {
01777             if (dropCancel && curdw) {
01778               d->dragRect = QRect(curdw->geometry());
01779               QPoint p = curdw->mapToGlobal(QPoint(0,0));
01780               d->dragRect.moveTopLeft(p);
01781             }else
01782               d->dragRect = QRect();
01783 
01784             drawDragRectangle();
01785           }
01786 
01787           if ( !pDockWdgAtCursor && !(curdw->eDocking & (int)KDockWidget::DockDesktop) ){
01788               // just moving at the desktop
01789               currentMoveWidget = pDockWdgAtCursor;
01790               curPos = KDockWidget::DockDesktop;
01791           } else {
01792             if ( oldMoveWidget && pDockWdgAtCursor != currentMoveWidget ) { //leave
01793               currentMoveWidget = pDockWdgAtCursor;
01794               curPos = KDockWidget::DockDesktop;
01795             }
01796           }
01797 
01798           if ( oldMoveWidget != pDockWdgAtCursor && pDockWdgAtCursor ) { //enter pDockWdgAtCursor
01799             currentMoveWidget = pDockWdgAtCursor;
01800             curPos = KDockWidget::DockDesktop;
01801           }
01802         } else {
01803           if (d->readyToDrag) {
01804             d->readyToDrag = false;
01805           }
01806           if ( (((QMouseEvent*)event)->state() == LeftButton) &&
01807                (curdw->eDocking != (int)KDockWidget::DockNone) ) {
01808             startDrag( curdw);
01809           }
01810         }
01811     break;
01812       default:
01813         break;
01814     }
01815   }
01816   return QObject::eventFilter( obj, event );
01817 }
01818 
01819 KDockWidget* KDockManager::findDockWidgetAt( const QPoint& pos )
01820 {
01821   dropCancel = true;
01822 
01823   if (!currentDragWidget)
01824     return 0L; // pointer access safety
01825 
01826   if (currentDragWidget->eDocking == (int)KDockWidget::DockNone ) return 0L;
01827 
01828   QWidget* p = QApplication::widgetAt( pos );
01829   if ( !p ) {
01830     dropCancel = false;
01831     return 0L;
01832   }
01833 #if defined(_OS_WIN32_) || defined(Q_OS_WIN32)
01834   p = p->topLevelWidget();
01835 #endif
01836   QWidget* w = 0L;
01837   findChildDockWidget( w, p, p->mapFromGlobal(pos) );
01838   if ( !w ){
01839     if ( !p->inherits("KDockWidget") ) {
01840       return 0L;
01841     }
01842     w = p;
01843   }
01844   if ( qt_find_obj_child( w, "KDockSplitter", "_dock_split_" ) ) return 0L;
01845   if ( qt_find_obj_child( w, "KDockTabGroup", "_dock_tab" ) ) return 0L;
01846   if (dynamic_cast<KDockContainer*>(w)) return 0L;
01847 
01848   if (!childDockWidgetList) return 0L;
01849   if ( childDockWidgetList->find(w) != -1 ) return 0L;
01850   if ( currentDragWidget->isGroup && ((KDockWidget*)w)->parentDockTabGroup() ) return 0L;
01851 
01852   KDockWidget* www = (KDockWidget*)w;
01853   if ( www->sDocking == (int)KDockWidget::DockNone ) return 0L;
01854   if( !www->widget )
01855     return 0L;
01856 
01857   KDockWidget::DockPosition curPos = KDockWidget::DockDesktop;
01858   QPoint cpos  = www->mapFromGlobal( pos );
01859 
01860   int ww = www->widget->width() / 3;
01861   int hh = www->widget->height() / 3;
01862 
01863   if ( cpos.y() <= hh ){
01864     curPos = KDockWidget::DockTop;
01865   } else
01866     if ( cpos.y() >= 2*hh ){
01867       curPos = KDockWidget::DockBottom;
01868     } else
01869       if ( cpos.x() <= ww ){
01870         curPos = KDockWidget::DockLeft;
01871       } else
01872         if ( cpos.x() >= 2*ww ){
01873           curPos = KDockWidget::DockRight;
01874         } else
01875             curPos = KDockWidget::DockCenter;
01876 
01877   if ( !(www->sDocking & (int)curPos) ) return 0L;
01878   if ( !(currentDragWidget->eDocking & (int)curPos) ) return 0L;
01879   if ( www->manager != this ) return 0L;
01880 
01881   dropCancel = false;
01882   return www;
01883 }
01884 
01885 void KDockManager::findChildDockWidget( QWidget*& ww, const QWidget* p, const QPoint& pos )
01886 {
01887   if ( p->children() ) {
01888     QWidget *w;
01889     QObjectListIt it( *p->children() );
01890     it.toLast();
01891     while ( it.current() ) {
01892       if ( it.current()->isWidgetType() ) {
01893         w = (QWidget*)it.current();
01894         if ( w->isVisible() && w->geometry().contains(pos) ) {
01895           if ( w->inherits("KDockWidget") ) ww = w;
01896           findChildDockWidget( ww, w, w->mapFromParent(pos) );
01897           return;
01898         }
01899       }
01900       --it;
01901     }
01902   }
01903   return;
01904 }
01905 
01906 void KDockManager::findChildDockWidget( const QWidget* p, QWidgetList*& list )
01907 {
01908   if ( p->children() ) {
01909     QWidget *w;
01910     QObjectListIt it( *p->children() );
01911     it.toLast();
01912     while ( it.current() ) {
01913       if ( it.current()->isWidgetType() ) {
01914         w = (QWidget*)it.current();
01915         if ( w->isVisible() ) {
01916           if ( w->inherits("KDockWidget") ) list->append( w );
01917           findChildDockWidget( w, list );
01918         }
01919       }
01920       --it;
01921     }
01922   }
01923   return;
01924 }
01925 
01926 void KDockManager::startDrag( KDockWidget* w )
01927 {
01928   if(( w->currentDockPos == KDockWidget::DockLeft) || ( w->currentDockPos == KDockWidget::DockRight)
01929    || ( w->currentDockPos == KDockWidget::DockTop) || ( w->currentDockPos == KDockWidget::DockBottom)) {
01930     w->prevSideDockPosBeforeDrag = w->currentDockPos;
01931 
01932     if ( w->parentWidget()->inherits("KDockSplitter") ){
01933       KDockSplitter* parentSplitterOfDockWidget = (KDockSplitter*)(w->parentWidget());
01934       w->d->splitPosInPercent = parentSplitterOfDockWidget->separatorPos();
01935     }
01936   }
01937 
01938   curPos = KDockWidget::DockDesktop;
01939   dragging = true;
01940 
01941   QApplication::setOverrideCursor(QCursor(sizeAllCursor));
01942 }
01943 
01944 void KDockManager::dragMove( KDockWidget* dw, QPoint pos )
01945 {
01946   QPoint p = dw->mapToGlobal( dw->widget->pos() );
01947   KDockWidget::DockPosition oldPos = curPos;
01948 
01949   QSize r = dw->widget->size();
01950   if ( dw->parentDockTabGroup() ){
01951     curPos = KDockWidget::DockCenter;
01952     if ( oldPos != curPos ) {
01953       d->dragRect.setRect( p.x()+2, p.y()+2, r.width()-4, r.height()-4 );
01954     }
01955     return;
01956   }
01957 
01958   int w = r.width() / 3;
01959   int h = r.height() / 3;
01960 
01961   if ( pos.y() <= h ){
01962     curPos = KDockWidget::DockTop;
01963     w = r.width();
01964   } else
01965     if ( pos.y() >= 2*h ){
01966       curPos = KDockWidget::DockBottom;
01967       p.setY( p.y() + 2*h );
01968       w = r.width();
01969     } else
01970       if ( pos.x() <= w ){
01971         curPos = KDockWidget::DockLeft;
01972         h = r.height();
01973       } else
01974         if ( pos.x() >= 2*w ){
01975           curPos = KDockWidget::DockRight;
01976           p.setX( p.x() + 2*w );
01977           h = r.height();
01978         } else
01979           {
01980             curPos = KDockWidget::DockCenter;
01981             p.setX( p.x() + w );
01982             p.setY( p.y() + h );
01983           }
01984 
01985   if ( oldPos != curPos ) {
01986     d->dragRect.setRect( p.x(), p.y(), w, h );
01987     drawDragRectangle();
01988   }
01989 }
01990 
01991 
01992 void KDockManager::cancelDrop()
01993 {
01994   QApplication::restoreOverrideCursor();
01995 
01996   delete childDockWidgetList;
01997   childDockWidgetList = 0L;
01998 
01999   d->dragRect = QRect();  // cancel drawing
02000   drawDragRectangle();    // only the old rect will be deleted
02001 }
02002 
02003 
02004 void KDockManager::drop()
02005 {
02006   d->dragRect = QRect();  // cancel drawing
02007   drawDragRectangle();    // only the old rect will be deleted
02008 
02009   QApplication::restoreOverrideCursor();
02010 
02011   delete childDockWidgetList;
02012   childDockWidgetList = 0L;
02013 
02014   if ( dropCancel ) return;
02015   if ( !currentMoveWidget && (!(currentDragWidget->eDocking & (int)KDockWidget::DockDesktop)) ) {
02016     d->dragRect = QRect();  // cancel drawing
02017     drawDragRectangle();    // only the old rect will be deleted
02018     return;
02019   }
02020   if ( !currentMoveWidget && !currentDragWidget->parent() ) {
02021     currentDragWidget->move( QCursor::pos() - d->dragOffset );
02022   }
02023   else {
02024     int splitPos = currentDragWidget->d->splitPosInPercent;
02025     // do we have to calculate 100%-splitPosInPercent?
02026     if( (curPos != currentDragWidget->prevSideDockPosBeforeDrag) && (curPos != KDockWidget::DockCenter) && (curPos != KDockWidget::DockDesktop)) {
02027       switch( currentDragWidget->prevSideDockPosBeforeDrag) {
02028       case KDockWidget::DockLeft:   if(curPos != KDockWidget::DockTop)    splitPos = 100-splitPos; break;
02029       case KDockWidget::DockRight:  if(curPos != KDockWidget::DockBottom) splitPos = 100-splitPos; break;
02030       case KDockWidget::DockTop:    if(curPos != KDockWidget::DockLeft)   splitPos = 100-splitPos; break;
02031       case KDockWidget::DockBottom: if(curPos != KDockWidget::DockRight)  splitPos = 100-splitPos; break;
02032       default: break;
02033       }
02034     }
02035     currentDragWidget->manualDock( currentMoveWidget, curPos , splitPos, QCursor::pos() - d->dragOffset );
02036     currentDragWidget->makeDockVisible();
02037   }
02038 }
02039 
02040 
02041 static QDomElement createStringEntry(QDomDocument &doc, const QString &tagName, const QString &str)
02042 {
02043     QDomElement el = doc.createElement(tagName);
02044 
02045     el.appendChild(doc.createTextNode(str));
02046     return el;
02047 }
02048 
02049 
02050 static QDomElement createBoolEntry(QDomDocument &doc, const QString &tagName, bool b)
02051 {
02052     return createStringEntry(doc, tagName, QString::fromLatin1(b? "true" : "false"));
02053 }
02054 
02055 
02056 static QDomElement createNumberEntry(QDomDocument &doc, const QString &tagName, int n)
02057 {
02058     return createStringEntry(doc, tagName, QString::number(n));
02059 }
02060 
02061 
02062 static QDomElement createRectEntry(QDomDocument &doc, const QString &tagName, const QRect &rect)
02063 {
02064     QDomElement el = doc.createElement(tagName);
02065 
02066     QDomElement xel = doc.createElement("x");
02067     xel.appendChild(doc.createTextNode(QString::number(rect.x())));
02068     el.appendChild(xel);
02069     QDomElement yel = doc.createElement("y");
02070     yel.appendChild(doc.createTextNode(QString::number(rect.y())));
02071     el.appendChild(yel);
02072     QDomElement wel = doc.createElement("width");
02073     wel.appendChild(doc.createTextNode(QString::number(rect.width())));
02074     el.appendChild(wel);
02075     QDomElement hel = doc.createElement("height");
02076     hel.appendChild(doc.createTextNode(QString::number(rect.height())));
02077     el.appendChild(hel);
02078 
02079     return el;
02080 }
02081 
02082 
02083 static QDomElement createListEntry(QDomDocument &doc, const QString &tagName,
02084                                    const QString &subTagName, const QStrList &list)
02085 {
02086     QDomElement el = doc.createElement(tagName);
02087 
02088     QStrListIterator it(list);
02089     for (; it.current(); ++it) {
02090         QDomElement subel = doc.createElement(subTagName);
02091         subel.appendChild(doc.createTextNode(QString::fromLatin1(it.current())));
02092         el.appendChild(subel);
02093     }
02094 
02095     return el;
02096 }
02097 
02098 
02099 static QString stringEntry(QDomElement &base, const QString &tagName)
02100 {
02101     return base.namedItem(tagName).firstChild().toText().data();
02102 }
02103 
02104 
02105 static bool boolEntry(QDomElement &base, const QString &tagName)
02106 {
02107     return base.namedItem(tagName).firstChild().toText().data() == "true";
02108 }
02109 
02110 
02111 static int numberEntry(QDomElement &base, const QString &tagName)
02112 {
02113     return stringEntry(base, tagName).toInt();
02114 }
02115 
02116 
02117 static QRect rectEntry(QDomElement &base, const QString &tagName)
02118 {
02119     QDomElement el = base.namedItem(tagName).toElement();
02120 
02121     int x = numberEntry(el, "x");
02122     int y = numberEntry(el, "y");
02123     int width = numberEntry(el, "width");
02124     int height = numberEntry(el,  "height");
02125 
02126     return QRect(x, y, width, height);
02127 }
02128 
02129 
02130 static QStrList listEntry(QDomElement &base, const QString &tagName, const QString &subTagName)
02131 {
02132     QStrList list;
02133 
02134     for( QDomNode n = base.namedItem(tagName).firstChild(); !n.isNull(); n = n.nextSibling() )
02135     {
02136         QDomElement subel = n.toElement();
02137         if (subel.tagName() == subTagName)
02138             list.append(subel.firstChild().toText().data().latin1());
02139     }
02140 
02141     return list;
02142 }
02143 
02144 
02145 void KDockManager::writeConfig(QDomElement &base)
02146 {
02147     // First of all, clear the tree under base
02148     while (!base.firstChild().isNull())
02149         base.removeChild(base.firstChild());
02150     QDomDocument doc = base.ownerDocument();
02151 
02152     QStrList nameList;
02153     QString mainWidgetStr;
02154 
02155     // collect widget names
02156     QStringList nList;
02157     QObjectListIt it(*childDock);
02158     KDockWidget *obj1;
02159     while ( (obj1=(KDockWidget*)it.current()) ) {
02160         if ( obj1->parent() == main )
02161             mainWidgetStr = QString::fromLatin1(obj1->name());
02162         nList.append(obj1->name());
02163         ++it;
02164     }
02165 
02166     for (QObjectListIt it(d->containerDocks);it.current();++it)
02167     {
02168         KDockContainer* dc = dynamic_cast<KDockContainer*>(((KDockWidget*)it.current())->widget);
02169         if (dc) {
02170                 dc->prepareSave(nList);
02171         }
02172     }
02173 
02174     QStringList::Iterator nListIt=nList.begin();
02175     while ( nListIt!=nList.end() ) {
02176         KDockWidget *obj = getDockWidgetFromName( *nListIt);
02177         if ((obj->isGroup && (!obj->d->isContainer)) && (nameList.find( obj->firstName.latin1() ) == -1
02178                              || nameList.find(obj->lastName.latin1()) == -1)) {
02179             // Skip until children are saved (why?)
02180             ++nListIt;
02181 //            nList.next();
02182 //falk?            if ( !nList.current() ) nList.first();
02183             continue;
02184         }
02185 
02186         QDomElement groupEl;
02187     if (obj->d->isContainer) {
02188             KDockContainer* x = dynamic_cast<KDockContainer*>(obj->widget);
02189             if (x) {
02190             groupEl=doc.createElement("dockContainer");
02191                 x->save(groupEl);
02192             }
02193         } else
02194         if (obj->isGroup) {
02196             groupEl = doc.createElement("splitGroup");
02197 
02198             groupEl.appendChild(createStringEntry(doc, "firstName", obj->firstName));
02199             groupEl.appendChild(createStringEntry(doc, "secondName", obj->lastName));
02200             groupEl.appendChild(createNumberEntry(doc, "orientation", (int)obj->splitterOrientation));
02201             groupEl.appendChild(createNumberEntry(doc, "separatorPos", ((KDockSplitter*)obj->widget)->separatorPos()));
02202         } else if (obj->isTabGroup) {
02204             groupEl = doc.createElement("tabGroup");
02205 
02206             QStrList list;
02207             for ( int i = 0; i < ((KDockTabGroup*)obj->widget)->count(); ++i )
02208                 list.append( ((KDockTabGroup*)obj->widget)->page( i )->name() );
02209             groupEl.appendChild(createListEntry(doc, "tabs", "tab", list));
02210             groupEl.appendChild(createNumberEntry(doc, "currentTab", ((KDockTabGroup*)obj->widget)->currentPageIndex()));
02211             if (!obj->parent()) {
02212                 groupEl.appendChild(createStringEntry(doc, "dockBackTo", obj->formerBrotherDockWidget ? obj->formerBrotherDockWidget->name() : ""));
02213                 groupEl.appendChild(createNumberEntry(doc, "dockBackToPos", obj->formerDockPos));
02214             }
02215         } else {
02217             groupEl = doc.createElement("dock");
02218             groupEl.appendChild(createStringEntry(doc, "tabCaption", obj->tabPageLabel()));
02219             groupEl.appendChild(createStringEntry(doc, "tabToolTip", obj->toolTipString()));
02220             if (!obj->parent()) {
02221                 groupEl.appendChild(createStringEntry(doc, "dockBackTo", obj->formerBrotherDockWidget ? obj->formerBrotherDockWidget->name() : ""));
02222                 groupEl.appendChild(createNumberEntry(doc, "dockBackToPos", obj->formerDockPos));
02223             }
02224         }
02225 
02226         groupEl.appendChild(createStringEntry(doc, "name", QString::fromLatin1(obj->name())));
02227         groupEl.appendChild(createBoolEntry(doc, "hasParent", obj->parent()));
02228         if ( !obj->parent() ) {
02229             groupEl.appendChild(createRectEntry(doc, "geometry", QRect(main->frameGeometry().topLeft(), main->size())));
02230             groupEl.appendChild(createBoolEntry(doc, "visible", obj->isVisible()));
02231         }
02232         if (obj->header && obj->header->inherits("KDockWidgetHeader")) {
02233             KDockWidgetHeader *h = static_cast<KDockWidgetHeader*>(obj->header);
02234             groupEl.appendChild(createBoolEntry(doc, "dragEnabled", h->dragEnabled()));
02235         }
02236 
02237         base.appendChild(groupEl);
02238         nameList.append(obj->name());
02239         nList.remove(nListIt);
02240         nListIt=nList.begin();
02241     }
02242 
02243     if (main->inherits("KDockMainWindow")) {
02244         KDockMainWindow *dmain = (KDockMainWindow*)main;
02245         QString centralWidgetStr = QString(dmain->centralWidget()? dmain->centralWidget()->name() : "");
02246         base.appendChild(createStringEntry(doc, "centralWidget", centralWidgetStr));
02247         QString mainDockWidgetStr = QString(dmain->getMainDockWidget()? dmain->getMainDockWidget()->name() : "");
02248         base.appendChild(createStringEntry(doc, "mainDockWidget", mainDockWidgetStr));
02249     } else {
02250         base.appendChild(createStringEntry(doc, "mainWidget", mainWidgetStr));
02251     }
02252 
02253     base.appendChild(createRectEntry(doc, "geometry", QRect(main->frameGeometry().topLeft(), main->size())));
02254 }
02255 
02256 
02257 void KDockManager::readConfig(QDomElement &base)
02258 {
02259     if (base.namedItem("group").isNull()
02260         && base.namedItem("tabgroup").isNull()
02261         && base.namedItem("dock").isNull()
02262     && base.namedItem("dockContainer").isNull()) {
02263         activate();
02264         return;
02265     }
02266 
02267     autoCreateDock = new QObjectList();
02268     autoCreateDock->setAutoDelete( true );
02269 
02270     bool isMainVisible = main->isVisible();
02271     main->hide();
02272 
02273     QObjectListIt it(*childDock);
02274     KDockWidget *obj1;
02275     while ( (obj1=(KDockWidget*)it.current()) ) {
02276         if ( !obj1->isGroup && !obj1->isTabGroup ) {
02277             if ( obj1->parent() )
02278                 obj1->undock();
02279             else
02280                 obj1->hide();
02281         }
02282         ++it;
02283     }
02284 
02285     // firstly, recreate all common dockwidgets
02286     for( QDomNode n = base.firstChild(); !n.isNull(); n = n.nextSibling() )
02287     {
02288         QDomElement childEl = n.toElement();
02289         if (childEl.tagName() != "dock") continue;
02290 
02291         // Read an ordinary dock widget
02292         KDockWidget *obj = getDockWidgetFromName(stringEntry(childEl, "name"));
02293         obj->setTabPageLabel(stringEntry(childEl, "tabCaption"));
02294         obj->setToolTipString(stringEntry(childEl, "tabToolTip"));
02295 
02296         if (!boolEntry(childEl, "hasParent")) {
02297             QRect r = rectEntry(childEl, "geometry");
02298             obj = getDockWidgetFromName(stringEntry(childEl, "name"));
02299             obj->applyToWidget(0);
02300             obj->setGeometry(r);
02301             if (boolEntry(childEl, "visible"))
02302                 obj->QWidget::show();
02303         }
02304 
02305         if (obj && obj->header && obj->header->inherits("KDockWidgetHeader")) {
02306             KDockWidgetHeader *h = static_cast<KDockWidgetHeader*>(obj->header);
02307             h->setDragEnabled(boolEntry(childEl, "dragEnabled"));
02308         }
02309     }
02310 
02311     // secondly, now iterate again and create the groups and tabwidgets, apply the dockwidgets to them
02312     for( QDomNode n = base.firstChild(); !n.isNull(); n = n.nextSibling() )
02313     {
02314         QDomElement childEl = n.toElement();
02315         if (childEl.isNull()) continue;
02316 
02317         KDockWidget *obj = 0;
02318 
02319     if (childEl.tagName() == "dockContainer") {
02320 
02321         KDockWidget *cont=getDockWidgetFromName(stringEntry(childEl, "name"));
02322         kdDebug(282)<<"dockContainer: "<<stringEntry(childEl,"name")<<endl;
02323         if (!(cont->d->isContainer)) {
02324             kdDebug(282)<<"restoration of dockContainer is only supported for already existing dock containers"<<endl;
02325         } else {
02326             KDockContainer *dc=dynamic_cast<KDockContainer*>(cont->getWidget());
02327             if (!dc) kdDebug(282)<<"Error while trying to handle dockcontainer configuration restoration"<<endl;
02328                 else {
02329                     dc->load(childEl);
02330                     removeFromAutoCreateList(cont);
02331                 }
02332 
02333         }
02334     }
02335     else
02336         if (childEl.tagName() == "splitGroup") {
02337             // Read a group
02338             QString name = stringEntry(childEl, "name");
02339             QString firstName = stringEntry(childEl, "firstName");
02340             QString secondName = stringEntry(childEl, "secondName");
02341             int orientation = numberEntry(childEl, "orientation");
02342             int separatorPos = numberEntry(childEl, "separatorPos");
02343 
02344             KDockWidget *first = getDockWidgetFromName(firstName);
02345             KDockWidget *second = getDockWidgetFromName(secondName);
02346             if (first && second) {
02347                 obj = first->manualDock(second,
02348                                         (orientation == (int)Vertical)? KDockWidget::DockLeft : KDockWidget::DockTop,
02349                                         separatorPos);
02350                 if (obj)
02351                     obj->setName(name.latin1());
02352             }
02353         } else if (childEl.tagName() == "tabGroup") {
02354             // Read a tab group
02355             QString name = stringEntry(childEl, "name");
02356             QStrList list = listEntry(childEl, "tabs", "tab");
02357 
02358             KDockWidget *d1 = getDockWidgetFromName( list.first() );
02359             list.next();
02360             KDockWidget *d2 = getDockWidgetFromName( list.current() );
02361 
02362             KDockWidget *obj = d2->manualDock( d1, KDockWidget::DockCenter );
02363             if (obj) {
02364                 KDockTabGroup *tab = (KDockTabGroup*)obj->widget;
02365                 list.next();
02366                 while (list.current() && obj) {
02367                     KDockWidget *tabDock = getDockWidgetFromName(list.current());
02368                     obj = tabDock->manualDock(d1, KDockWidget::DockCenter);
02369                     list.next();
02370                 }
02371                 if (obj) {
02372                     obj->setName(name.latin1());
02373                     tab->showPage(tab->page(numberEntry(childEl, "currentTab")));
02374                 }
02375             }
02376         } else {
02377             continue;
02378         }
02379 
02380         if (!boolEntry(childEl, "hasParent")) {
02381             QRect r = rectEntry(childEl, "geometry");
02382             obj = getDockWidgetFromName(stringEntry(childEl, "name"));
02383             obj->applyToWidget(0);
02384             obj->setGeometry(r);
02385             if (boolEntry(childEl, "visible"))
02386                 obj->QWidget::show();
02387         }
02388 
02389         if (obj && obj->header && obj->header->inherits("KDockWidgetHeader")) {
02390             KDockWidgetHeader *h = static_cast<KDockWidgetHeader*>(obj->header);
02391             h->setDragEnabled(boolEntry(childEl, "dragEnabled"));
02392         }
02393     }
02394 
02395     // thirdly, now that all ordinary dockwidgets are created,
02396     // iterate them again and link them with their corresponding dockwidget for the dockback action
02397     for( QDomNode n = base.firstChild(); !n.isNull(); n = n.nextSibling() )
02398     {
02399         QDomElement childEl = n.toElement();
02400 
02401         if (childEl.tagName() != "dock" && childEl.tagName() != "tabGroup")
02402             continue;
02403 
02404         KDockWidget *obj = 0;
02405 
02406         if (!boolEntry(childEl, "hasParent")) {
02407             // Read a common toplevel dock widget
02408             obj = getDockWidgetFromName(stringEntry(childEl, "name"));
02409             QString name = stringEntry(childEl, "dockBackTo");
02410             if (!name.isEmpty()) {
02411                 obj->setFormerBrotherDockWidget(getDockWidgetFromName(name));
02412             }
02413             obj->formerDockPos = KDockWidget::DockPosition(numberEntry(childEl, "dockBackToPos"));
02414             obj->updateHeader();
02415         }
02416     }
02417 
02418     if (main->inherits("KDockMainWindow")) {
02419         KDockMainWindow *dmain = (KDockMainWindow*)main;
02420 
02421         QString mv = stringEntry(base, "centralWidget");
02422         if (!mv.isEmpty() && getDockWidgetFromName(mv) ) {
02423             KDockWidget *mvd  = getDockWidgetFromName(mv);
02424             mvd->applyToWidget(dmain);
02425             mvd->show();
02426             dmain->setCentralWidget(mvd);
02427         }
02428         QString md = stringEntry(base, "mainDockWidget");
02429         if (!md.isEmpty() && getDockWidgetFromName(md)) {
02430             KDockWidget *mvd  = getDockWidgetFromName(md);
02431             dmain->setMainDockWidget(mvd);
02432         }
02433     } else {
02434         QString mv = stringEntry(base, "mainWidget");
02435         if (!mv.isEmpty() && getDockWidgetFromName(mv)) {
02436             KDockWidget *mvd  = getDockWidgetFromName(mv);
02437             mvd->applyToWidget(main);
02438             mvd->show();
02439         }
02440 
02441         // only resize + move non-mainwindows
02442         QRect mr = rectEntry(base, "geometry");
02443         main->move(mr.topLeft());
02444         main->resize(mr.size());
02445     }
02446 
02447     if (isMainVisible)
02448         main->show();
02449 
02450     if (d->m_readDockConfigMode == WrapExistingWidgetsOnly) {
02451         finishReadDockConfig(); // remove empty dockwidgets
02452     }
02453 }
02454 
02455 void KDockManager::removeFromAutoCreateList(KDockWidget* pDockWidget)
02456 {
02457     if (!autoCreateDock) return;
02458     autoCreateDock->setAutoDelete(false);
02459     autoCreateDock->removeRef(pDockWidget);
02460     autoCreateDock->setAutoDelete(true);
02461 }
02462 
02463 void KDockManager::finishReadDockConfig()
02464 {
02465     delete autoCreateDock;
02466     autoCreateDock = 0;
02467 }
02468 
02469 void KDockManager::setReadDockConfigMode(int mode)
02470 {
02471     d->m_readDockConfigMode = mode;
02472 }
02473 
02474 #ifndef NO_KDE2
02475 void KDockManager::writeConfig( KConfig* c, QString group )
02476 {
02477   //debug("BEGIN Write Config");
02478   if ( !c ) c = KGlobal::config();
02479   if ( group.isEmpty() ) group = "dock_setting_default";
02480 
02481   c->setGroup( group );
02482   c->writeEntry( "Version", DOCK_CONFIG_VERSION );
02483 
02484   QStringList nameList;
02485   QStringList findList;
02486   QObjectListIt it( *childDock );
02487   KDockWidget * obj;
02488 
02489   // collect KDockWidget's name
02490   QStringList nList;
02491   while ( (obj=(KDockWidget*)it.current()) ) {
02492     ++it;
02493     //debug("  +Add subdock %s", obj->name());
02494     nList.append( obj->name() );
02495     if ( obj->parent() == main )
02496       c->writeEntry( "Main:view", obj->name() );
02497   }
02498 
02499 //  kdDebug(282)<<QString("list size: %1").arg(nList.count())<<endl;
02500   for (QObjectListIt it(d->containerDocks);it.current();++it)
02501   {
02502     KDockContainer* dc = dynamic_cast<KDockContainer*>(((KDockWidget*)it.current())->widget);
02503     if (dc) {
02504         dc->prepareSave(nList);
02505     }
02506   }
02507 //  kdDebug(282)<<QString("new list size: %1").arg(nList.count())<<endl;
02508 
02509   QStringList::Iterator nListIt=nList.begin();
02510   while ( nListIt!=nList.end() ){
02511     //debug("  -Try to save %s", nList.current());
02512     obj = getDockWidgetFromName( *nListIt );
02513     QString cname = obj->name();
02514     if ( obj->header ){
02515       obj->header->saveConfig( c );
02516     }
02517     if (obj->d->isContainer) {
02518        KDockContainer* x = dynamic_cast<KDockContainer*>(obj->widget);
02519        if (x) {
02520           x->save(c,group);
02521        }
02522     }
02523 /*************************************************************************************************/
02524     if ( obj->isGroup ){
02525       if ( (findList.find( obj->firstName ) != findList.end()) && (findList.find( obj->lastName ) != findList.end() )){
02526 
02527         c->writeEntry( cname+":type", "GROUP");
02528         if ( !obj->parent() ){
02529           c->writeEntry( cname+":parent", "___null___");
02530           c->writeEntry( cname+":geometry", QRect(obj->frameGeometry().topLeft(), obj->size()) );
02531           c->writeEntry( cname+":visible", obj->isVisible());
02532         } else {
02533           c->writeEntry( cname+":parent", "yes");
02534         }
02535         c->writeEntry( cname+":first_name", obj->firstName );
02536         c->writeEntry( cname+":last_name", obj->lastName );
02537         c->writeEntry( cname+":orientation", (int)obj->splitterOrientation );
02538         c->writeEntry( cname+":sepPos", ((KDockSplitter*)obj->widget)->separatorPos() );
02539 
02540         nameList.append( obj->name() );
02541         findList.append( obj->name() );
02542         //debug("  Save %s", nList.current());
02543         nList.remove(nListIt);
02544         nListIt=nList.begin(); //nList.first();
02545       } else {
02546 /*************************************************************************************************/
02547         //debug("  Skip %s", nList.current());
02548         //if ( findList.find( obj->firstName ) == -1 )
02549         //  debug("  ? Not found %s", obj->firstName);
02550         //if ( findList.find( obj->lastName ) == -1 )
02551         //  debug("  ? Not found %s", obj->lastName);
02552         ++nListIt;
02553         // if ( !nList.current() ) nList.first();
02554     if (nListIt==nList.end()) nListIt=nList.begin();
02555       }
02556     } else {
02557 /*************************************************************************************************/
02558       if ( obj->isTabGroup){
02559         c->writeEntry( cname+":type", "TAB_GROUP");
02560         if ( !obj->parent() ){
02561           c->writeEntry( cname+":parent", "___null___");
02562           c->writeEntry( cname+":geometry", QRect(obj->frameGeometry().topLeft(), obj->size()) );
02563           c->writeEntry( cname+":visible", obj->isVisible());
02564           c->writeEntry( cname+":dockBackTo", obj->formerBrotherDockWidget ? obj->formerBrotherDockWidget->name() : "");
02565           c->writeEntry( cname+":dockBackToPos", obj->formerDockPos);
02566         } else {
02567           c->writeEntry( cname+":parent", "yes");
02568         }
02569         QStrList list;
02570         for ( int i = 0; i < ((KDockTabGroup*)obj->widget)->count(); ++i )
02571           list.append( ((KDockTabGroup*)obj->widget)->page( i )->name() );
02572         c->writeEntry( cname+":tabNames", list );
02573         c->writeEntry( cname+":curTab", ((KDockTabGroup*)obj->widget)->currentPageIndex() );
02574 
02575         nameList.append( obj->name() );
02576         findList.append( obj->name() ); // not really need !!!
02577         //debug("  Save %s", nList.current());
02578         nList.remove(nListIt);
02579         nListIt=nList.begin();
02580       } else {
02581 /*************************************************************************************************/
02582         c->writeEntry( cname+":tabCaption", obj->tabPageLabel());
02583         c->writeEntry( cname+":tabToolTip", obj->toolTipString());
02584         if ( !obj->parent() ){
02585           c->writeEntry( cname+":type", "NULL_DOCK");
02586           c->writeEntry( cname+":geometry", QRect(obj->frameGeometry().topLeft(), obj->size()) );
02587           c->writeEntry( cname+":visible", obj->isVisible());
02588           c->writeEntry( cname+":dockBackTo", obj->formerBrotherDockWidget ? obj->formerBrotherDockWidget->name() : "");
02589           c->writeEntry( cname+":dockBackToPos", obj->formerDockPos);
02590         } else {
02591           c->writeEntry( cname+":type", "DOCK");
02592         }
02593         nameList.append( cname.latin1() );
02594         //debug("  Save %s", nList.current());
02595         findList.append( obj->name() );
02596         nList.remove(nListIt);
02597         nListIt=nList.begin();
02598       }
02599     }
02600   }
02601   c->writeEntry( "NameList", nameList );
02602 
02603   c->writeEntry( "Main:Geometry", QRect(main->frameGeometry().topLeft(), main->size()) );
02604   c->writeEntry( "Main:visible", main->isVisible()); // curently nou use
02605 
02606   if ( main->inherits("KDockMainWindow") ){
02607     KDockMainWindow* dmain = (KDockMainWindow*)main;
02608     // for KDockMainWindow->setView() in readConfig()
02609     c->writeEntry( "Main:view", dmain->centralWidget() ? dmain->centralWidget()->name():"" );
02610     c->writeEntry( "Main:dock", dmain->getMainDockWidget()     ? dmain->getMainDockWidget()->name()    :"" );
02611   }
02612 
02613   c->sync();
02614   //debug("END Write Config");
02615 }
02616 #include <qmessagebox.h>
02617 void KDockManager::readConfig( KConfig* c, QString group )
02618 {
02619   if ( !c ) c = KGlobal::config();
02620   if ( group.isEmpty() ) group = "dock_setting_default";
02621 
02622   c->setGroup( group );
02623   QStrList nameList;
02624   c->readListEntry( "NameList", nameList );
02625   QString ver = c->readEntry( "Version", "0.0.1" );
02626   nameList.first();
02627   if ( !nameList.current() || ver != DOCK_CONFIG_VERSION ){
02628     activate();
02629     return;
02630   }
02631 
02632   autoCreateDock = new QObjectList();
02633   autoCreateDock->setAutoDelete( true );
02634 
02635   bool isMainVisible = main->isVisible();
02636  // if (isMainVisible)  // CCC
02637   //QMessageBox::information(0,"","hallo");
02638 //COMMENTED4TESTING  main->hide();
02639 
02640   QObjectListIt it( *childDock );
02641   KDockWidget * obj;
02642 
02643   while ( (obj=(KDockWidget*)it.current()) ){
02644     ++it;
02645     if ( !obj->isGroup && !obj->isTabGroup )
02646     {
02647       if ( obj->parent() ) obj->undock(); else obj->hide();
02648     }
02649   }
02650 
02651   // firstly, only the common dockwidgets,
02652   // they must be restored before e.g. tabgroups are restored
02653   nameList.first();
02654   while ( nameList.current() ){
02655     QString oname = nameList.current();
02656     c->setGroup( group );
02657     QString type = c->readEntry( oname + ":type" );
02658     obj = 0L;
02659 
02660     if ( type == "NULL_DOCK" || c->readEntry( oname + ":parent") == "___null___" ){
02661       QRect r = c->readRectEntry( oname + ":geometry" );
02662       obj = getDockWidgetFromName( oname );
02663       obj->applyToWidget( 0L );
02664       obj->setGeometry(r);
02665 
02666       c->setGroup( group );
02667       obj->setTabPageLabel(c->readEntry( oname + ":tabCaption" ));
02668       obj->setToolTipString(c->readEntry( oname + ":tabToolTip" ));
02669       if ( c->readBoolEntry( oname + ":visible" ) ){
02670         obj->QWidget::show();
02671       }
02672     }
02673 
02674     if ( type == "DOCK"  ){
02675       obj = getDockWidgetFromName( oname );
02676       obj->setTabPageLabel(c->readEntry( oname + ":tabCaption" ));
02677       obj->setToolTipString(c->readEntry( oname + ":tabToolTip" ));
02678     }
02679 
02680     if (obj && obj->d->isContainer) {
02681         dynamic_cast<KDockContainer*>(obj->widget)->load(c,group);
02682         removeFromAutoCreateList(obj);
02683     }
02684     if ( obj && obj->header){
02685       obj->header->loadConfig( c );
02686     }
02687     nameList.next();
02688   }
02689 
02690   // secondly, after the common dockwidgets, restore the groups and tabgroups
02691   nameList.first();
02692   while ( nameList.current() ){
02693     QString oname = nameList.current();
02694     c->setGroup( group );
02695     QString type = c->readEntry( oname + ":type" );
02696     obj = 0L;
02697 
02698     if ( type == "GROUP" ){
02699       KDockWidget* first = getDockWidgetFromName( c->readEntry( oname + ":first_name" ) );
02700       KDockWidget* last  = getDockWidgetFromName( c->readEntry( oname + ":last_name"  ) );
02701       int sepPos = c->readNumEntry( oname + ":sepPos" );
02702 
02703       Orientation p = (Orientation)c->readNumEntry( oname + ":orientation" );
02704       if ( first  && last ){
02705         obj = first->manualDock( last, ( p == Vertical ) ? KDockWidget::DockLeft : KDockWidget::DockTop, sepPos );
02706         if (obj){
02707           obj->setName( oname.latin1() );
02708         }
02709       }
02710     }
02711 
02712     if ( type == "TAB_GROUP" ){
02713       QStrList list;
02714       KDockWidget* tabDockGroup = 0L;
02715       c->readListEntry( oname+":tabNames", list );
02716       KDockWidget* d1 = getDockWidgetFromName( list.first() );
02717       list.next();
02718       KDockWidget* d2 = getDockWidgetFromName( list.current() );
02719       tabDockGroup = d2->manualDock( d1, KDockWidget::DockCenter );
02720       if ( tabDockGroup ){
02721         KDockTabGroup* tab = dynamic_cast<KDockTabGroup*>(tabDockGroup->widget);
02722         list.next();
02723         while ( list.current() && tabDockGroup ){
02724           KDockWidget* tabDock = getDockWidgetFromName( list.current() );
02725           tabDockGroup = tabDock->manualDock( d1, KDockWidget::DockCenter );
02726           list.next();
02727         }
02728         if ( tabDockGroup ){
02729           tabDockGroup->setName( oname.latin1() );
02730           c->setGroup( group );
02731           if (tab)
02732             tab->showPage( tab->page( c->readNumEntry( oname+":curTab" ) ) );
02733         }
02734       }
02735       obj = tabDockGroup;
02736     }
02737 
02738     if (obj && obj->d->isContainer)  dynamic_cast<KDockContainer*>(obj->widget)->load(c,group);
02739     if ( obj && obj->header){
02740       obj->header->loadConfig( c );
02741     }
02742     nameList.next();
02743   }
02744 
02745   // thirdly, now that all ordinary dockwidgets are created,
02746   // iterate them again and link the toplevel ones of them with their corresponding dockwidget for the dockback action
02747   nameList.first();
02748   while ( nameList.current() ){
02749     QString oname = nameList.current();
02750     c->setGroup( group );
02751     QString type = c->readEntry( oname + ":type" );
02752     obj = 0L;
02753 
02754     if ( type == "NULL_DOCK" || c->readEntry( oname + ":parent") == "___null___" ){
02755       obj = getDockWidgetFromName( oname );
02756       c->setGroup( group );
02757       QString name = c->readEntry( oname + ":dockBackTo" );
02758       if (!name.isEmpty()) {
02759           obj->setFormerBrotherDockWidget(getDockWidgetFromName( name ));
02760       }
02761       obj->formerDockPos = KDockWidget::DockPosition(c->readNumEntry( oname + ":dockBackToPos" ));
02762     }
02763 
02764     nameList.next();
02765   }
02766 
02767   if ( main->inherits("KDockMainWindow") ){
02768     KDockMainWindow* dmain = (KDockMainWindow*)main;
02769 
02770     c->setGroup( group );
02771     QString mv = c->readEntry( "Main:view" );
02772     if ( !mv.isEmpty() && getDockWidgetFromName( mv ) ){
02773       KDockWidget* mvd  = getDockWidgetFromName( mv );
02774       mvd->applyToWidget( dmain );
02775       mvd->show();
02776       dmain->setView( mvd );
02777     }
02778     c->setGroup( group );
02779     QString md = c->readEntry( "Main:dock" );
02780     if ( !md.isEmpty() && getDockWidgetFromName( md ) ){
02781       KDockWidget* mvd  = getDockWidgetFromName( md );
02782       dmain->setMainDockWidget( mvd );
02783     }
02784   } else {
02785     c->setGroup( group );
02786     QString mv = c->readEntry( "Main:view" );
02787     if ( !mv.isEmpty() && getDockWidgetFromName( mv ) ){
02788       KDockWidget* mvd  = getDockWidgetFromName( mv );
02789       mvd->applyToWidget( main );
02790       mvd->show();
02791     }
02792 
02793   }
02794 
02795   // delete all autocreate dock
02796   if (d->m_readDockConfigMode == WrapExistingWidgetsOnly) {
02797     finishReadDockConfig(); // remove empty dockwidgets
02798   }
02799 
02800   c->setGroup( group );
02801   QRect mr = c->readRectEntry("Main:Geometry");
02802   main->move(mr.topLeft());
02803   main->resize(mr.size());
02804   if ( isMainVisible ) main->show();
02805 }
02806 #endif
02807 
02808 
02809 void KDockManager::dumpDockWidgets() {
02810   QObjectListIt it( *childDock );
02811   KDockWidget * obj;
02812   while ( (obj=(KDockWidget*)it.current()) ) {
02813     ++it;
02814     kdDebug(282)<<"KDockManager::dumpDockWidgets:"<<obj->name()<<endl;
02815   }
02816 
02817 }
02818 
02819 KDockWidget* KDockManager::getDockWidgetFromName( const QString& dockName )
02820 {
02821   QObjectListIt it( *childDock );
02822   KDockWidget * obj;
02823   while ( (obj=(KDockWidget*)it.current()) ) {
02824     ++it;
02825     if ( QString(obj->name()) == dockName ) return obj;
02826   }
02827 
02828   KDockWidget* autoCreate = 0L;
02829   if ( autoCreateDock ){
02830     kdDebug(282)<<"Autocreating dock: "<<dockName<<endl;
02831     autoCreate = new KDockWidget( this, dockName.latin1(), QPixmap("") );
02832     autoCreateDock->append( autoCreate );
02833   }
02834   return autoCreate;
02835 }
02836 void KDockManager::setSplitterOpaqueResize(bool b)
02837 {
02838   d->splitterOpaqueResize = b;
02839 }
02840 
02841 bool KDockManager::splitterOpaqueResize() const
02842 {
02843   return d->splitterOpaqueResize;
02844 }
02845 
02846 void KDockManager::setSplitterKeepSize(bool b)
02847 {
02848   d->splitterKeepSize = b;
02849 }
02850 
02851 bool KDockManager::splitterKeepSize() const
02852 {
02853   return d->splitterKeepSize;
02854 }
02855 
02856 void KDockManager::setSplitterHighResolution(bool b)
02857 {
02858   d->splitterHighResolution = b;
02859 }
02860 
02861 bool KDockManager::splitterHighResolution() const
02862 {
02863   return d->splitterHighResolution;
02864 }
02865 
02866 void KDockManager::slotMenuPopup()
02867 {
02868   menu->clear();
02869   menuData->clear();
02870 
02871   QObjectListIt it( *childDock );
02872   KDockWidget * obj;
02873   int numerator = 0;
02874   while ( (obj=(KDockWidget*)it.current()) ) {
02875     ++it;
02876     if ( obj->mayBeHide() )
02877     {
02878       menu->insertItem( obj->icon() ? *(obj->icon()) : QPixmap(), i18n("Hide %1").arg(obj->caption()), numerator++ );
02879       menuData->append( new MenuDockData( obj, true ) );
02880     }
02881 
02882     if ( obj->mayBeShow() )
02883     {
02884       menu->insertItem( obj->icon() ? *(obj->icon()) : QPixmap(), i18n("Show %1").arg(obj->caption()), numerator++ );
02885       menuData->append( new MenuDockData( obj, false ) );
02886     }
02887   }
02888 }
02889 
02890 void KDockManager::slotMenuActivated( int id )
02891 {
02892   MenuDockData* data = menuData->at( id );
02893   data->dock->changeHideShowState();
02894 }
02895 
02896 KDockWidget* KDockManager::findWidgetParentDock( QWidget* w ) const
02897 {
02898   QObjectListIt it( *childDock );
02899   KDockWidget * dock;
02900   KDockWidget * found = 0L;
02901 
02902   while ( (dock=(KDockWidget*)it.current()) ) {
02903     ++it;
02904     if ( dock->widget == w ){ found  = dock; break; }
02905   }
02906   return found;
02907 }
02908 
02909 void KDockManager::drawDragRectangle()
02910 {
02911 #ifdef BORDERLESS_WINDOWS
02912     return
02913 #endif
02914   if (d->oldDragRect == d->dragRect)
02915     return;
02916 
02917   int i;
02918   QRect oldAndNewDragRect[2];
02919   oldAndNewDragRect[0] = d->oldDragRect;
02920   oldAndNewDragRect[1] = d->dragRect;
02921 
02922   // 2 calls, one for the old and one for the new drag rectangle
02923   for (i = 0; i <= 1; i++) {
02924     if (oldAndNewDragRect[i].isEmpty())
02925       continue;
02926 
02927     KDockWidget* pDockWdgAtRect = (KDockWidget*) QApplication::widgetAt( oldAndNewDragRect[i].topLeft(), true );
02928     if (!pDockWdgAtRect)
02929       continue;
02930 
02931     bool isOverMainWdg = false;
02932     bool unclipped;
02933     KDockMainWindow* pMain = 0L;
02934     KDockWidget* pTLDockWdg = 0L;
02935     QWidget* topWdg;
02936     if (pDockWdgAtRect->topLevelWidget() == main) {
02937       isOverMainWdg = true;
02938       topWdg = pMain = (KDockMainWindow*) main;
02939       unclipped = pMain->testWFlags( WPaintUnclipped );
02940       pMain->setWFlags( WPaintUnclipped );
02941     }
02942     else {
02943       topWdg = pTLDockWdg = (KDockWidget*) pDockWdgAtRect->topLevelWidget();
02944       unclipped = pTLDockWdg->testWFlags( WPaintUnclipped );
02945       pTLDockWdg->setWFlags( WPaintUnclipped );
02946     }
02947 
02948     // draw the rectangle unclipped over the main dock window
02949     QPainter p;
02950     p.begin( topWdg );
02951       if ( !unclipped ) {
02952         if (isOverMainWdg)
02953           pMain->clearWFlags(WPaintUnclipped);
02954         else
02955           pTLDockWdg->clearWFlags(WPaintUnclipped);
02956       }
02957       // draw the rectangle
02958       p.setRasterOp(Qt::NotXorROP);
02959       QRect r = oldAndNewDragRect[i];
02960       r.moveTopLeft( r.topLeft() - topWdg->mapToGlobal(QPoint(0,0)) );
02961       p.drawRect(r.x(), r.y(), r.width(), r.height());
02962     p.end();
02963   }
02964 
02965   // memorize the current rectangle for later removing
02966   d->oldDragRect = d->dragRect;
02967 }
02968 
02969 void KDockManager::setSpecialLeftDockContainer(KDockWidget* container) {
02970     d->leftContainer=container;
02971 }
02972 
02973 void KDockManager::setSpecialTopDockContainer(KDockWidget* container) {
02974     d->topContainer=container;
02975 }
02976 
02977 void KDockManager::setSpecialRightDockContainer(KDockWidget* container) {
02978     d->rightContainer=container;
02979 
02980 }
02981 
02982 void KDockManager::setSpecialBottomDockContainer(KDockWidget* container) {
02983     d->bottomContainer=container;
02984 }
02985 
02986 
02987 KDockArea::KDockArea( QWidget* parent, const char *name)
02988 :QWidget( parent, name)
02989 {
02990   QString new_name = QString(name) + QString("_DockManager");
02991   dockManager = new KDockManager( this, new_name.latin1() );
02992   mainDockWidget = 0L;
02993 }
02994 
02995 KDockArea::~KDockArea()
02996 {
02997     delete dockManager;
02998 }
02999 
03000 KDockWidget* KDockArea::createDockWidget( const QString& name, const QPixmap &pixmap, QWidget* parent, const QString& strCaption, const QString& strTabPageLabel)
03001 {
03002   return new KDockWidget( dockManager, name.latin1(), pixmap, parent, strCaption, strTabPageLabel );
03003 }
03004 
03005 void KDockArea::makeDockVisible( KDockWidget* dock )
03006 {
03007   if ( dock )
03008     dock->makeDockVisible();
03009 }
03010 
03011 void KDockArea::makeDockInvisible( KDockWidget* dock )
03012 {
03013   if ( dock )
03014     dock->undock();
03015 }
03016 
03017 void KDockArea::makeWidgetDockVisible( QWidget* widget )
03018 {
03019   makeDockVisible( dockManager->findWidgetParentDock(widget) );
03020 }
03021 
03022 void KDockArea::writeDockConfig(QDomElement &base)
03023 {
03024   dockManager->writeConfig(base);
03025 }
03026 
03027 void KDockArea::readDockConfig(QDomElement &base)
03028 {
03029   dockManager->readConfig(base);
03030 }
03031 
03032 void KDockArea::slotDockWidgetUndocked()
03033 {
03034   QObject* pSender = (QObject*) sender();
03035   if (!pSender->inherits("KDockWidget")) return;
03036   KDockWidget* pDW = (KDockWidget*) pSender;
03037   emit dockWidgetHasUndocked( pDW);
03038 }
03039 
03040 void KDockArea::resizeEvent(QResizeEvent *rsize)
03041 {
03042   QWidget::resizeEvent(rsize);
03043   if (children()){
03044 #ifndef NO_KDE2
03045 //    kdDebug(282)<<"KDockArea::resize"<<endl;
03046 #endif
03047     QObjectList *list=queryList("QWidget",0,false);
03048 
03049     QObjectListIt it( *list ); // iterate over the buttons
03050     QObject *obj;
03051 
03052     while ( (obj = it.current()) != 0 ) {
03053         // for each found object...
03054         ((QWidget*)obj)->setGeometry(QRect(QPoint(0,0),size()));
03055     break;
03056     }
03057     delete list;
03058 #if 0
03059     KDockSplitter *split;
03060 //    for (unsigned int i=0;i<children()->count();i++)
03061     {
03062 //      QPtrList<QObject> list(children());
03063 //       QObject *obj=((QPtrList<QObject*>)children())->at(i);
03064     QObject *obj=children()->getFirst();
03065        if (split = dynamic_cast<KDockSplitter*>(obj))
03066        {
03067           split->setGeometry( QRect(QPoint(0,0), size() ));
03068 //    break;
03069        }
03070     }
03071 #endif
03072    }
03073 }
03074 
03075 #ifndef NO_KDE2
03076 void KDockArea::writeDockConfig( KConfig* c, QString group )
03077 {
03078   dockManager->writeConfig( c, group );
03079 }
03080 
03081 void KDockArea::readDockConfig( KConfig* c, QString group )
03082 {
03083   dockManager->readConfig( c, group );
03084 }
03085 
03086 void KDockArea::setMainDockWidget( KDockWidget* mdw )
03087 {
03088   if ( mainDockWidget == mdw ) return;
03089   mainDockWidget = mdw;
03090   mdw->applyToWidget(this);
03091 }
03092 #endif
03093 
03094 
03095 
03096 // KDOCKCONTAINER - AN ABSTRACTION OF THE KDOCKTABWIDGET
03097 KDockContainer::KDockContainer(){m_overlapMode=false; m_childrenListBegin=0; m_childrenListEnd=0;}
03098 KDockContainer::~KDockContainer(){
03099 
03100     if (m_childrenListBegin)
03101     {
03102         struct ListItem *tmp=m_childrenListBegin;
03103         while (tmp)
03104         {
03105             struct ListItem *tmp2=tmp->next;
03106             free(tmp->data);
03107             delete tmp;
03108             tmp=tmp2;
03109         }
03110         m_childrenListBegin=0;
03111         m_childrenListEnd=0;
03112     }
03113 
03114 }
03115 
03116 void KDockContainer::activateOverlapMode(int nonOverlapSize) {
03117     m_nonOverlapSize=nonOverlapSize;
03118     m_overlapMode=true;
03119     if (parentDockWidget()) {
03120         if (parentDockWidget()->parent()) {
03121             kdDebug(282)<<"KDockContainer::activateOverlapMode: recalculating sizes"<<endl;
03122             KDockSplitter *sp= static_cast<KDockSplitter*>(parentDockWidget()->
03123                 parent()->qt_cast("KDockSplitter"));
03124             if (sp) sp->resizeEvent(0);
03125         }
03126     }
03127 }
03128 
03129 void KDockContainer::deactivateOverlapMode() {
03130     if (!m_overlapMode) return;
03131     m_overlapMode=false;
03132     if (parentDockWidget()) {
03133         if (parentDockWidget()->parent()) {
03134             kdDebug(282)<<"KDockContainer::deactivateOverlapMode: recalculating sizes"<<endl;
03135             KDockSplitter *sp= static_cast<KDockSplitter*>(parentDockWidget()->
03136                 parent()->qt_cast("KDockSplitter"));
03137             if (sp) sp->resizeEvent(0);
03138         }
03139     }
03140 
03141 }
03142 
03143 bool KDockContainer::isOverlapMode() {
03144     return m_overlapMode;
03145 }
03146 
03147 
03148 bool KDockContainer::dockDragEnter(KDockWidget*, QMouseEvent *) { return false;}
03149 bool KDockContainer::dockDragMove(KDockWidget*, QMouseEvent *) { return false;}
03150 bool KDockContainer::dockDragLeave(KDockWidget*, QMouseEvent *) { return false;}
03151 
03152 
03153 KDockWidget *KDockContainer::parentDockWidget(){return 0;}
03154 
03155 QStringList KDockContainer::containedWidgets() const {
03156     QStringList tmp;
03157     for (struct ListItem *it=m_childrenListBegin;it;it=it->next) {
03158         tmp<<QString(it->data);
03159     }
03160 
03161     return tmp;
03162 }
03163 
03164 void KDockContainer::showWidget(KDockWidget *) {
03165 }
03166 
03167 void KDockContainer::insertWidget (KDockWidget *dw, QPixmap, const QString &, int &)
03168     {
03169         struct ListItem *it=new struct ListItem;
03170         it->data=strdup(dw->name());
03171         it->next=0;
03172 
03173         if (m_childrenListEnd)
03174         {
03175             m_childrenListEnd->next=it;
03176             it->prev=m_childrenListEnd;
03177             m_childrenListEnd=it;
03178         }
03179         else
03180         {
03181             it->prev=0;
03182             m_childrenListEnd=it;
03183             m_childrenListBegin=it;
03184         }
03185     }
03186 void KDockContainer::removeWidget (KDockWidget *dw){
03187     for (struct ListItem *tmp=m_childrenListBegin;tmp;tmp=tmp->next)
03188     {
03189         if (!strcmp(tmp->data,dw->name()))
03190         {
03191             free(tmp->data);
03192             if (tmp->next) tmp->next->prev=tmp->prev;
03193             if (tmp->prev) tmp->prev->next=tmp->next;
03194             if (tmp==m_childrenListBegin) m_childrenListBegin=tmp->next;
03195             if (tmp==m_childrenListEnd) m_childrenListEnd=tmp->prev;
03196             delete tmp;
03197             break;
03198         }
03199     }
03200 }
03201 
03202 //m_children.remove(dw->name());}
03203 void KDockContainer::undockWidget (KDockWidget *){;}
03204 void KDockContainer::setToolTip(KDockWidget *, QString &){;}
03205 void KDockContainer::setPixmap(KDockWidget*,const QPixmap&){;}
03206 void KDockContainer::load (KConfig*, const QString&){;}
03207 void KDockContainer::save (KConfig*, const QString&){;}
03208 void KDockContainer::load (QDomElement&){;}
03209 void KDockContainer::save (QDomElement&){;}
03210 void KDockContainer::prepareSave(QStringList &names)
03211 {
03212 
03213     for (struct ListItem *tmp=m_childrenListBegin;tmp; tmp=tmp->next)
03214         names.remove(tmp->data);
03215 //  for (uint i=0;i<m_children.count();i++)
03216 //  {
03217 //      names.remove(m_children.at(i));
03218 //  }
03219 }
03220 
03221 
03222 QWidget *KDockTabGroup::transientTo() {
03223     QWidget *tT=0;
03224     for (int i=0;i<count();i++) {
03225         KDockWidget *dw=static_cast<KDockWidget*>(page(i)->qt_cast("KDockWidget"));
03226         QWidget *tmp;
03227         if ((tmp=dw->transientTo())) {
03228             if (!tT) tT=tmp;
03229             else {
03230                 if (tT!=tmp) {
03231                     kdDebug(282)<<"KDockTabGroup::transientTo: widget mismatch"<<endl;
03232                     return 0;
03233                 }
03234             }
03235         }
03236     }
03237 
03238     kdDebug(282)<<"KDockTabGroup::transientTo: "<<(tT?"YES":"NO")<<endl;
03239 
03240     return tT;
03241 }
03242 
03243 void KDockWidgetAbstractHeader::virtual_hook( int, void* )
03244 { /*BASE::virtual_hook( id, data );*/ }
03245 
03246 void KDockWidgetAbstractHeaderDrag::virtual_hook( int, void* )
03247 { /*BASE::virtual_hook( id, data );*/ }
03248 
03249 void KDockWidgetHeaderDrag::virtual_hook( int id, void* data )
03250 { KDockWidgetAbstractHeaderDrag::virtual_hook( id, data ); }
03251 
03252 void KDockWidgetHeader::virtual_hook( int id, void* data )
03253 { KDockWidgetAbstractHeader::virtual_hook( id, data ); }
03254 
03255 void KDockTabGroup::virtual_hook( int, void* )
03256 { /*BASE::virtual_hook( id, data );*/ }
03257 
03258 void KDockWidget::virtual_hook( int, void* )
03259 { /*BASE::virtual_hook( id, data );*/ }
03260 
03261 void KDockManager::virtual_hook( int, void* )
03262 { /*BASE::virtual_hook( id, data );*/ }
03263 
03264 void KDockMainWindow::virtual_hook( int id, void* data )
03265 { KMainWindow::virtual_hook( id, data ); }
03266 
03267 void KDockArea::virtual_hook( int, void* )
03268 { /*KMainWindow::virtual_hook( id, data );*/ }
03269 
03270 
03271 #ifndef NO_INCLUDE_MOCFILES // for Qt-only projects, because tmake doesn't take this name
03272 #include "kdockwidget.moc"
03273 #endif
KDE Logo
This file is part of the documentation for kdeui Library Version 3.4.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Jul 21 13:14:02 2006 by doxygen 1.4.0 written by Dimitri van Heesch, © 1997-2003