TDE core libraries
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

dockmainwindow.cpp 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /* This file is part of the KDE project
  2. Copyright (C) 2000 Falk Brettschneider <gigafalk@yahoo.com>
  3. (C) 1999 Simon Hausmann <hausmann@kde.org>
  4. (C) 1999 David Faure <faure@kde.org>
  5. This library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Library General Public
  7. License as published by the Free Software Foundation; either
  8. version 2 of the License, or (at your option) any later version.
  9. This library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Library General Public License for more details.
  13. You should have received a copy of the GNU Library General Public License
  14. along with this library; see the file COPYING.LIB. If not, write to
  15. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  16. Boston, MA 02110-1301, USA.
  17. */
  18. #include <tdeparts/dockmainwindow.h>
  19. #include <tdeparts/event.h>
  20. #include <tdeparts/part.h>
  21. #include <tdeaccel.h>
  22. #include <tdeparts/plugin.h>
  23. #include <kstatusbar.h>
  24. #include <kinstance.h>
  25. #include <khelpmenu.h>
  26. #include <kstandarddirs.h>
  27. #include <tqapplication.h>
  28. #include <kdebug.h>
  29. #include <kxmlguifactory.h>
  30. #include <assert.h>
  31. using namespace KParts;
  32. namespace KParts
  33. {
  34. class DockMainWindowPrivate
  35. {
  36. public:
  37. DockMainWindowPrivate()
  38. {
  39. m_activePart = 0;
  40. m_bShellGUIActivated = false;
  41. m_helpMenu = 0;
  42. }
  43. ~DockMainWindowPrivate()
  44. {
  45. }
  46. TQGuardedPtr<Part> m_activePart;
  47. bool m_bShellGUIActivated;
  48. KHelpMenu *m_helpMenu;
  49. };
  50. }
  51. DockMainWindow::DockMainWindow( TQWidget* parent, const char *name, WFlags f )
  52. : KDockMainWindow( parent, name, f )
  53. {
  54. d = new DockMainWindowPrivate();
  55. PartBase::setPartObject( TQT_TQOBJECT(this) );
  56. }
  57. DockMainWindow::~DockMainWindow()
  58. {
  59. delete d;
  60. }
  61. void DockMainWindow::createGUI( Part * part )
  62. {
  63. kdDebug(1000) << TQString(TQString("DockMainWindow::createGUI for %1").arg(part?part->name():"0L")) << endl;
  64. KXMLGUIFactory *factory = guiFactory();
  65. setUpdatesEnabled( false );
  66. TQPtrList<Plugin> plugins;
  67. if ( d->m_activePart )
  68. {
  69. kdDebug(1000) << TQString(TQString("deactivating GUI for %1").arg(d->m_activePart->name())) << endl;
  70. GUIActivateEvent ev( false );
  71. TQApplication::sendEvent( d->m_activePart, &ev );
  72. factory->removeClient( d->m_activePart );
  73. disconnect( d->m_activePart, TQT_SIGNAL( setWindowCaption( const TQString & ) ),
  74. this, TQT_SLOT( setCaption( const TQString & ) ) );
  75. disconnect( d->m_activePart, TQT_SIGNAL( setStatusBarText( const TQString & ) ),
  76. this, TQT_SLOT( slotSetStatusBarText( const TQString & ) ) );
  77. }
  78. if ( !d->m_bShellGUIActivated )
  79. {
  80. loadPlugins( TQT_TQOBJECT(this), this, TDEGlobal::instance() );
  81. createShellGUI();
  82. d->m_bShellGUIActivated = true;
  83. }
  84. if ( part )
  85. {
  86. // do this before sending the activate event
  87. connect( part, TQT_SIGNAL( setWindowCaption( const TQString & ) ),
  88. this, TQT_SLOT( setCaption( const TQString & ) ) );
  89. connect( part, TQT_SIGNAL( setStatusBarText( const TQString & ) ),
  90. this, TQT_SLOT( slotSetStatusBarText( const TQString & ) ) );
  91. factory->addClient( part );
  92. GUIActivateEvent ev( true );
  93. TQApplication::sendEvent( part, &ev );
  94. }
  95. setUpdatesEnabled( true );
  96. d->m_activePart = part;
  97. }
  98. void DockMainWindow::slotSetStatusBarText( const TQString & text )
  99. {
  100. statusBar()->message( text );
  101. }
  102. void DockMainWindow::createShellGUI( bool create )
  103. {
  104. bool bAccelAutoUpdate = accel()->setAutoUpdate( false );
  105. assert( d->m_bShellGUIActivated != create );
  106. d->m_bShellGUIActivated = create;
  107. if ( create )
  108. {
  109. if ( isHelpMenuEnabled() )
  110. d->m_helpMenu = new KHelpMenu( this, instance()->aboutData(), true, actionCollection() );
  111. TQString f = xmlFile();
  112. setXMLFile( locate( "config", "ui/ui_standards.rc", instance() ) );
  113. if ( !f.isEmpty() )
  114. setXMLFile( f, true );
  115. else
  116. {
  117. TQString auto_file( instance()->instanceName() + "ui.rc" );
  118. setXMLFile( auto_file, true );
  119. }
  120. GUIActivateEvent ev( true );
  121. TQApplication::sendEvent( this, &ev );
  122. guiFactory()->addClient( this );
  123. }
  124. else
  125. {
  126. GUIActivateEvent ev( false );
  127. TQApplication::sendEvent( this, &ev );
  128. guiFactory()->removeClient( this );
  129. }
  130. accel()->setAutoUpdate( bAccelAutoUpdate );
  131. }
  132. #include "dockmainwindow.moc"