tdemainwindow.h
00001 /* 00002 This file is part of the KDE libraries 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License version 2 as published by the Free Software Foundation. 00007 00008 This library is distributed in the hope that it will be useful, 00009 but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00011 Library General Public License for more details. 00012 00013 You should have received a copy of the GNU Library General Public License 00014 along with this library; see the file COPYING.LIB. If not, write to 00015 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00016 Boston, MA 02110-1301, USA. 00017 00018 00019 */ 00020 00021 #ifndef TDEMAINWINDOW_H 00022 #define TDEMAINWINDOW_H 00023 00024 #include "kxmlguifactory.h" 00025 #include "kxmlguiclient.h" 00026 #include "kxmlguibuilder.h" 00027 #include <tqmainwindow.h> 00028 #include <tqmetaobject.h> 00029 #include <tdetoolbar.h> 00030 00031 class TDEPopupMenu; 00032 class KXMLGUIFactory; 00033 class TDEConfig; 00034 class KHelpMenu; 00035 class KStatusBar; 00036 class TQStatusBar; 00037 class KMenuBar; 00038 class KMWSessionManaged; 00039 class TDEMainWindowPrivate; 00040 class TDEAccel; 00041 class TDEToolBarMenuAction; 00042 class DCOPObject; 00043 00044 #define KDE_DEFAULT_WINDOWFLAGS WType_TopLevel | WDestructiveClose 00045 00046 00098 class TDEUI_EXPORT TDEMainWindow : public TQMainWindow, public KXMLGUIBuilder, virtual public KXMLGUIClient 00099 { 00100 friend class KMWSessionManaged; 00101 Q_OBJECT 00102 00103 public: 00136 #ifdef qdoc 00137 TDEMainWindow( TQWidget* parent = 0, const char *name = 0, WFlags f = WType_TopLevel | WDestructiveClose ); 00138 #else 00139 TDEMainWindow( TQWidget* parent = 0, const char *name = 0, WFlags f = (WFlags)(WType_TopLevel | WDestructiveClose) ); 00140 #endif 00141 00152 enum CreationFlags 00153 { 00154 NoDCOPObject = 1, 00155 NewRefCountMode = 2 00156 }; 00157 00163 #ifdef qdoc 00164 TDEMainWindow( int cflags, TQWidget* parent = 0, const char *name = 0, WFlags f = WType_TopLevel | WDestructiveClose ); 00165 #else 00166 TDEMainWindow( int cflags, TQWidget* parent = 0, const char *name = 0, WFlags f = (WFlags)(WType_TopLevel | WDestructiveClose) ); 00167 #endif 00168 00175 virtual ~TDEMainWindow(); 00176 00201 TDEPopupMenu* helpMenu( const TQString &aboutAppText = TQString::null, 00202 bool showWhatsThis = true ); 00203 00226 TDEPopupMenu* customHelpMenu( bool showWhatsThis = true ); 00227 00294 static bool canBeRestored( int number ); 00295 00303 // KDE 4 return TQCString - TQObject::className() returns const char* 00304 static const TQString classNameOfToplevel( int number ); 00305 00309 // KDE4 remove this method if this has been fixed in Qt 00310 virtual void show(); 00311 00315 // KDE4 remove this method if this has been fixed in Qt 00316 virtual void hide(); 00317 00326 bool restore( int number, bool show = true ); 00327 00328 virtual KXMLGUIFactory *guiFactory(); 00329 00349 void createGUI( const TQString &xmlfile = TQString::null, bool _conserveMemory = true ); 00350 00357 void setHelpMenuEnabled(bool showHelpMenu = true); 00358 00362 bool isHelpMenuEnabled(); 00363 00364 00369 bool hasMenuBar(); 00370 00376 KMenuBar *menuBar(); 00377 00389 KStatusBar *statusBar(); 00390 00394 static TQPtrList<TDEMainWindow>* memberList; 00395 00396 //KDE4: replace with memberList() and make memberList member private 00401 static TQPtrList<TDEMainWindow>* getMemberList(); 00402 00413 TDEToolBar *toolBar( const char *name=0 ); 00414 00418 TQPtrListIterator<TDEToolBar> toolBarIterator(); 00419 00424 TDEAccel *accel(); 00425 00426 void setFrameBorderWidth( int ) {} 00427 00459 void setAutoSaveSettings( const TQString & groupName = TQString::fromLatin1("MainWindow"), 00460 bool saveWindowSize = true ); 00461 00466 void resetAutoSaveSettings(); 00467 00473 bool autoSaveSettings() const; 00474 00482 TQString autoSaveGroup() const; 00483 00493 void applyMainWindowSettings(TDEConfig *config, const TQString &groupName, bool force); 00494 // KDE4 merge with force=false 00495 void applyMainWindowSettings(TDEConfig *config, const TQString &groupName = TQString::null); 00496 00505 void saveMainWindowSettings(TDEConfig *config, const TQString &groupName = TQString::null); 00506 00525 void setStandardToolBarMenuEnabled( bool enable ); 00527 bool isStandardToolBarMenuEnabled() const; 00528 00529 00550 void createStandardStatusBarAction(); 00551 00555 enum StandardWindowOptions 00556 { 00562 ToolBar = 1, 00563 00567 Keys = 2, 00568 00573 StatusBar = 4, 00574 00585 Save = 8, 00586 00591 Create = 16 00592 }; 00593 00605 void setupGUI( int options = ToolBar | Keys | StatusBar | Save | Create, const TQString& xmlfile = TQString::null ); 00606 00620 void setupGUI( TQSize defaultSize, int options = ToolBar | Keys | StatusBar | Save | Create, const TQString& xmlfile = TQString::null ); 00621 00626 TDEAction *toolBarMenuAction(); 00627 00632 void setupToolbarMenuActions(); 00633 00634 // why do we support old gcc versions? using KXMLGUIBuilder::finalizeGUI; 00636 virtual void finalizeGUI( KXMLGUIClient *client ); 00637 00641 void finalizeGUI( bool force ); 00642 00647 bool initialGeometrySet() const; 00648 00653 void ignoreInitialGeometry(); 00654 00670 // KDE4 to be removed 00671 TQSize sizeForCentralWidgetSize(TQSize size) KDE_DEPRECATED; 00672 00676 // KDE4 remove 00677 virtual void setIcon( const TQPixmap & ); 00678 00679 public slots: 00692 int configureToolbars(); // TODO KDE4: make virtual and reimplement in KParts::MainWindow 00693 00701 virtual void setCaption( const TQString &caption ); 00711 virtual void setCaption( const TQString &caption, bool modified ); 00712 00719 virtual void setPlainCaption( const TQString &caption ); 00720 00742 void appHelpActivated( void ); 00743 00750 virtual void slotStateChanged(const TQString &newstate); 00751 00760 void slotStateChanged(const TQString &newstate, 00761 KXMLGUIClient::ReverseStateChange); // KDE 4.0: remove this 00762 00763 00771 // void slotStateChanged(const TQString &newstate, 00772 // bool reverse); // KDE 4.0: enable this 00773 00781 void setSettingsDirty(); 00782 00783 protected: 00784 void paintEvent( TQPaintEvent* e ); 00785 void childEvent( TQChildEvent* e); 00786 void resizeEvent( TQResizeEvent* e); 00794 virtual void closeEvent ( TQCloseEvent *); 00795 00796 // KDE4 This seems to be flawed to me. Either the app has only one 00797 // mainwindow, so queryClose() is enough, or if it can have more of them, 00798 // then the windows should take care of themselves, and queryExit() 00799 // would be useful only for the annoying 'really quit' dialog, which 00800 // also doesn't make sense in apps with multiple mainwindows. 00801 // And saving configuration in something called queryExit()? IMHO 00802 // one can e.g. use TDEApplication::shutDown(), which if nothing else 00803 // has at least better fitting name. 00804 // See also TDEApplication::sessionSaving(). 00805 // This stuff should get changed somehow, so that it at least doesn't 00806 // mess with session management. 00834 virtual bool queryExit(); 00835 00870 virtual bool queryClose(); 00871 00885 virtual void saveProperties( TDEConfig* ) {} 00886 00890 virtual void readProperties( TDEConfig* ) {} 00891 00908 virtual void saveGlobalProperties( TDEConfig* sessionConfig ); 00909 00915 virtual void readGlobalProperties( TDEConfig* sessionConfig ); 00916 void savePropertiesInternal( TDEConfig*, int ); 00917 bool readPropertiesInternal( TDEConfig*, int ); 00918 00922 bool settingsDirty() const; 00926 TQString settingsGroup() const; 00931 void saveWindowSize( TDEConfig * config ) const; 00937 void restoreWindowSize( TDEConfig * config ); 00938 00940 void parseGeometry(bool parsewidth); 00941 00942 protected slots: 00947 void saveNewToolbarConfig(); // TODO KDE4: make virtual and reimplement in KParts::MainWindow 00948 00973 virtual void showAboutApplication(); 00974 00998 void saveAutoSaveSettings(); 00999 01000 private slots: 01004 void shuttingDown(); 01005 01006 private: 01007 KMenuBar *internalMenuBar(); 01008 KStatusBar *internalStatusBar(); 01009 KHelpMenu *mHelpMenu, *helpMenu2; 01010 KXMLGUIFactory *factory_; 01011 TQPtrList<TDEToolBar> toolbarList; 01012 protected: 01013 virtual void virtual_hook( int id, void* data ); 01014 private: 01015 TDEMainWindowPrivate *d; 01016 void initTDEMainWindow(const char *name, int cflags); 01017 }; 01018 01019 #define RESTORE(type) { int n = 1;\ 01020 while (TDEMainWindow::canBeRestored(n)){\ 01021 (new type)->restore(n);\ 01022 n++;}} 01023 01024 #define KDE_RESTORE_MAIN_WINDOWS_NUM_TEMPLATE_ARGS 3 01025 01036 template <typename T> 01037 inline void kRestoreMainWindows() { 01038 for ( int n = 1 ; TDEMainWindow::canBeRestored( n ) ; ++n ) { 01039 const TQString className = TDEMainWindow::classNameOfToplevel( n ); 01040 if ( className == TQString::fromLatin1( T::staticMetaObject()->className() ) ) 01041 (new T)->restore( n ); 01042 } 01043 } 01044 01045 template <typename T0, typename T1> 01046 inline void kRestoreMainWindows() { 01047 const char * classNames[2]; 01048 classNames[0] = T0::staticMetaObject()->className(); 01049 classNames[1] = T1::staticMetaObject()->className(); 01050 for ( int n = 1 ; TDEMainWindow::canBeRestored( n ) ; ++n ) { 01051 const TQString className = TDEMainWindow::classNameOfToplevel( n ); 01052 if ( className == TQString::fromLatin1( classNames[0] ) ) 01053 (new T0)->restore( n ); 01054 else if ( className == TQString::fromLatin1( classNames[1] ) ) 01055 (new T1)->restore( n ); 01056 } 01057 } 01058 01059 template <typename T0, typename T1, typename T2> 01060 inline void kRestoreMainWindows() { 01061 const char * classNames[3]; 01062 classNames[0] = T0::staticMetaObject()->className(); 01063 classNames[1] = T1::staticMetaObject()->className(); 01064 classNames[2] = T2::staticMetaObject()->className(); 01065 for ( int n = 1 ; TDEMainWindow::canBeRestored( n ) ; ++n ) { 01066 const TQString className = TDEMainWindow::classNameOfToplevel( n ); 01067 if ( className == TQString::fromLatin1( classNames[0] ) ) 01068 (new T0)->restore( n ); 01069 else if ( className == TQString::fromLatin1( classNames[1] ) ) 01070 (new T1)->restore( n ); 01071 else if ( className == TQString::fromLatin1( classNames[2] ) ) 01072 (new T2)->restore( n ); 01073 } 01074 } 01075 01076 #endif 01077