26 #include "tdemainwindow.h"
27 #include "tdemainwindowiface.h"
28 #include "tdetoolbarhandler.h"
29 #include "kwhatsthismanager_p.h"
30 #include <tqsessionmanager.h>
31 #include <tqobjectlist.h>
34 #include <tqwidgetlist.h>
38 #include <tdeaction.h>
39 #include <tdeapplication.h>
40 #include <tdeconfig.h>
42 #include <khelpmenu.h>
43 #include <tdemenubar.h>
44 #include <kstatusbar.h>
46 #include <kedittoolbar.h>
47 #include <tdemainwindow.h>
50 #include <kstandarddirs.h>
51 #include <kstaticdeleter.h>
60 class TDEMainWindowPrivate {
64 bool autoSaveSettings:1;
66 bool autoSaveWindowSize:1;
67 bool care_about_geometry:1;
69 bool newStyleRefCounting:1;
70 TQString autoSaveGroup;
74 TQTimer* settingsTimer;
76 TQRect defaultWindowSize;
77 TQPtrList<TQDockWindow> hiddenDockWindows;
81 static bool no_query_exit =
false;
82 static KMWSessionManaged* ksm = 0;
105 for (it.toFirst(); it.current(); ++it){
107 it.current()->savePropertiesInternal(config, n);
109 config->
setGroup(TQString::fromLatin1(
"Number"));
110 config->
writeEntry(TQString::fromLatin1(
"NumberOfWindows"), n );
117 if ( sm.allowsInteraction() ) {
118 bool canceled =
false;
120 ::no_query_exit =
true;
121 for (it.toFirst(); it.current() && !canceled;){
124 if ( !window->testWState( TQt::WState_ForceHide ) ) {
126 TQApplication::sendEvent( window, &e );
127 canceled = !e.isAccepted();
144 ::no_query_exit =
false;
149 for (it.toFirst(); it.current() && !canceled; ++it){
151 if ( !window->testWState( TQt::WState_ForceHide ) ) {
166 static bool being_first =
true;
169 : TQMainWindow( parent, name, f ),
KXMLGUIBuilder( this ), helpMenu2( 0 ), factory_( 0 )
171 initTDEMainWindow(name, 0);
175 : TQMainWindow( parent, name, f ),
KXMLGUIBuilder( this ), helpMenu2( 0 ), factory_( 0 )
177 initTDEMainWindow(name, cflags);
180 void TDEMainWindow::initTDEMainWindow(
const char *name,
int cflags)
182 KWhatsThisManager::init ();
183 setDockMenuEnabled(
false );
185 kapp->setTopWidget(
this );
187 connect(kapp, TQT_SIGNAL(shutDown()),
this, TQT_SLOT(shuttingDown()));
192 ksm = ksmd.
setObject(ksm,
new KMWSessionManaged());
199 objname = kapp->instanceName() +
"-mainwindow#";
203 else if( name[0] !=
'\0' && name[ strlen( name ) - 1 ] ==
'#' )
216 TQWidgetList* list = kapp->topLevelWidgets();
217 TQWidgetListIt it( *list );
219 for( TQWidget* w = it.current();
221 ++it, w = it.current())
222 if( w !=
this && w->name() == s )
230 s.setNum( ++unusedNumber );
237 d =
new TDEMainWindowPrivate;
238 d->showHelpMenu =
true;
239 d->settingsDirty =
false;
240 d->autoSaveSettings =
false;
241 d->autoSaveWindowSize =
true;
243 d->toolBarHandler = 0;
244 d->settingsTimer = 0;
245 d->showStatusBarAction = NULL;
246 d->shuttingDown =
false;
247 if ((d->care_about_geometry = being_first)) {
249 if ( kapp->geometryArgument().isNull() )
250 d->care_about_geometry =
false;
256 if ( cflags & NoDCOPObject)
261 if ( cflags & NewRefCountMode ) {
262 d->newStyleRefCounting =
true;
266 d->newStyleRefCounting =
false;
269 if (!kapp->authorize(
"movable_toolbars"))
270 setDockWindowsMovable(
false);
275 if ( !d->toolBarHandler )
278 return d->toolBarHandler->toolBarMenuAction();
284 if ( d->toolBarHandler )
285 d->toolBarHandler->setupActions();
290 assert ( !kapp->geometryArgument().isNull() );
291 assert ( d->care_about_geometry );
296 int m = XParseGeometry( kapp->geometryArgument().latin1(), &x, &y, (
unsigned int*)&w, (
unsigned int*)&h);
298 TQSize minSize = minimumSize();
299 TQSize maxSize = maximumSize();
300 if ( !(m & WidthValue) )
302 if ( !(m & HeightValue) )
304 w = TQMIN(w,maxSize.width());
305 h = TQMIN(h,maxSize.height());
306 w = TQMAX(w,minSize.width());
307 h = TQMAX(h,minSize.height());
310 if ( parsewidth && !(m & XValue) )
312 if ( parsewidth && !(m & YValue) )
314 if ( (m & XNegative) )
315 x = TDEApplication::desktop()->width() + x - w;
316 if ( (m & YNegative) )
317 y = TDEApplication::desktop()->height() + y - h;
325 delete d->settingsTimer;
326 TQMenuBar* mb = internalMenuBar();
328 delete d->m_interface;
336 if ( aboutAppText.isEmpty() )
339 mHelpMenu =
new KHelpMenu(
this, aboutAppText, showWhatsThis );
347 return mHelpMenu->
menu();
353 mHelpMenu =
new KHelpMenu(
this, TQString::null, showWhatsThis );
358 return mHelpMenu->
menu();
363 if ( !kapp->isRestored() )
365 TDEConfig *config = kapp->sessionConfig();
368 config->
setGroup( TQString::fromLatin1(
"Number") );
369 int n = config->
readNumEntry( TQString::fromLatin1(
"NumberOfWindows") , 1 );
370 return number >= 1 && number <= n;
375 if ( !kapp->isRestored() )
376 return TQString::null;
377 TDEConfig *config = kapp->sessionConfig();
379 return TQString::null;
382 s.prepend( TQString::fromLatin1(
"WindowProperties") );
384 if ( !config->
hasKey( TQString::fromLatin1(
"ClassName") ) )
385 return TQString::null;
387 return config->
readEntry( TQString::fromLatin1(
"ClassName") );
394 for ( TQPtrListIterator<TQDockWindow> it( d->hiddenDockWindows ); it.current(); ++it )
395 it.current()->show();
397 d->hiddenDockWindows.clear();
404 d->hiddenDockWindows.clear();
406 TQObjectList *list = queryList( TQDOCKWINDOW_OBJECT_NAME_STRING );
407 for( TQObjectListIt it( *list ); it.current(); ++it ) {
408 TQDockWindow *dw = (TQDockWindow*)it.current();
409 if ( dw->isTopLevel() && dw->isVisible() ) {
410 d->hiddenDockWindows.append( dw );
424 TDEConfig *config = kapp->sessionConfig();
425 if ( readPropertiesInternal( config, number ) ){
436 factory_ =
new KXMLGUIFactory(
this, TQT_TQOBJECT(
this),
"guifactory" );
455 setupGUI(TQSize(), options, xmlfile);
459 if( options &
Keys ){
464 if( (options &
StatusBar) && internalStatusBar() ){
478 if( options &
Save ){
487 else if(defaultSize.isValid())
503 setUpdatesEnabled(
false );
509 TQMenuBar* mb = internalMenuBar();
514 toolbarList.setAutoDelete(
true );
516 toolbarList.setAutoDelete(
false );
519 if (d->showHelpMenu) {
531 if ( !xmlfile.isNull() ) {
534 TQString auto_file(
instance()->instanceName() +
"ui.rc");
545 if ( _conserveMemory )
562 for( TQDomNode n = doc.documentElement().firstChild();
563 !n.isNull(); n = n.nextSibling())
565 TQDomElement e = n.toElement();
567 if ( e.tagName().lower() ==
"toolbar" )
569 else if ( e.tagName().lower() ==
"menubar" )
576 setUpdatesEnabled(
true );
582 d->showHelpMenu = showHelpMenu;
587 return d->showHelpMenu;
604 NETWinInfo info( tqt_xdisplay(), winId(), tqt_xrootwin(), 0 );
605 info.setName( caption.utf8().data() );
628 KXMLGUIClient::ReverseStateChange reverse)
646 if (d->settingsDirty && d->autoSaveSettings)
652 int not_withdrawn = 0;
654 for (it.toFirst(); it.current(); ++it){
655 if ( !it.current()->isHidden() && it.current()->isTopLevel() && it.current() != this )
659 if ( !no_query_exit && not_withdrawn <= 0 ) {
660 if (
queryExit() && !kapp->sessionSaving() && !d->shuttingDown ) {
662 disconnect(kapp, TQT_SIGNAL(shutDown()),
this, TQT_SLOT(shuttingDown()));
663 d->shuttingDown =
true;
691 #if defined(KDE_COMPAT)
692 void TDEMainWindow::updateRects()
701 void TDEMainWindow::savePropertiesInternal(
TDEConfig *config,
int number )
703 bool oldASWS = d->autoSaveWindowSize;
704 d->autoSaveWindowSize =
true;
708 s.prepend(TQString::fromLatin1(
"WindowProperties"));
713 config->
writeEntry(TQString::fromLatin1(
"ObjectName"), name());
714 config->
writeEntry(TQString::fromLatin1(
"ClassName"), className());
722 d->autoSaveWindowSize = oldASWS;
727 kdDebug(200) <<
"TDEMainWindow::saveMainWindowSettings " << configGroup <<
endl;
730 if (!configGroup.isEmpty())
732 oldGroup = config->
group();
737 if ( d->autoSaveWindowSize )
740 TQStatusBar* sb = internalStatusBar();
742 if(!config->
hasDefault(
"StatusBar") && !sb->isHidden() )
745 config->
writeEntry(
"StatusBar", sb->isHidden() ?
"Disabled" :
"Enabled");
748 TQMenuBar* mb = internalMenuBar();
750 TQString MenuBar = TQString::fromLatin1(
"MenuBar");
751 if(!config->
hasDefault(
"MenuBar") && !mb->isHidden() )
754 config->
writeEntry(
"MenuBar", mb->isHidden() ?
"Disabled" :
"Enabled");
760 while ( ( toolbar = it.current() ) ) {
763 if (!configGroup.isEmpty())
767 group = (!::qstrcmp(toolbar->name(),
"unnamed") ? TQString::number(n) : TQString(
" ")+toolbar->name());
768 group.prepend(
" Toolbar");
769 group.prepend(configGroup);
774 if (!configGroup.isEmpty())
781 if ( d->toolBarHandler )
789 if ( !d->toolBarHandler )
795 delete d->toolBarHandler;
796 d->toolBarHandler = 0;
802 return ( d->toolBarHandler );
806 if(!d->showStatusBarAction){
809 connect(d->showStatusBarAction, TQT_SIGNAL(toggled(
bool)), sb, TQT_SLOT(setShown(
bool)));
810 d->showStatusBarAction->setChecked(sb->isHidden());
814 bool TDEMainWindow::readPropertiesInternal(
TDEConfig *config,
int number )
822 s.prepend(TQString::fromLatin1(
"WindowProperties"));
827 if ( config->
hasKey(TQString::fromLatin1(
"ObjectName" )) )
828 setName( config->
readEntry(TQString::fromLatin1(
"ObjectName")).latin1());
845 kdDebug(200) <<
"TDEMainWindow::applyMainWindowSettings" <<
endl;
851 TQStatusBar* sb = internalStatusBar();
853 TQString entry = config->
readEntry(
"StatusBar",
"Enabled");
854 if ( entry ==
"Disabled" )
858 if(d->showStatusBarAction)
859 d->showStatusBarAction->setChecked(!sb->isHidden());
862 TQMenuBar* mb = internalMenuBar();
864 TQString entry = config->
readEntry (
"MenuBar",
"Enabled");
865 if ( entry ==
"Disabled" )
875 for ( ; it.current(); ++it) {
876 toolbar= it.current();
878 if (!configGroup.isEmpty())
882 group = (!::qstrcmp(toolbar->name(),
"unnamed") ? TQString::number(n) : TQString(
" ")+toolbar->name());
883 group.prepend(
" Toolbar");
884 group.prepend(configGroup);
904 for ( ; it.current() ; ++it ) {
905 it.current()->positionYourself( force );
908 d->settingsDirty =
false;
913 int scnum = TQApplication::desktop()->screenNumber(parentWidget());
914 TQRect desk = TQApplication::desktop()->screenGeometry(scnum);
919 w = info.
state() & NET::MaxHoriz ? desk.width() + 1 : width();
920 h = info.
state() & NET::MaxVert ? desk.height() + 1 : height();
923 w = desk.width() + 1;
924 h = desk.height() + 1;
928 TQRect size( desk.width(), w, desk.height(), h );
929 bool defaultSize = (size == d->defaultWindowSize);
930 TQString widthString = TQString::fromLatin1(
"Width %1").arg(desk.width());
931 TQString heightString = TQString::fromLatin1(
"Height %1").arg(desk.height());
932 if (!config->
hasDefault(widthString) && defaultSize)
937 if (!config->
hasDefault(heightString) && defaultSize)
945 if (d->care_about_geometry) {
949 int scnum = TQApplication::desktop()->screenNumber(parentWidget());
950 TQRect desk = TQApplication::desktop()->screenGeometry(scnum);
951 if ( d->defaultWindowSize.isNull() )
952 d->defaultWindowSize = TQRect(desk.width(), width(), desk.height(), height());
953 TQSize size( config->
readNumEntry( TQString::fromLatin1(
"Width %1").arg(desk.width()), 0 ),
954 config->
readNumEntry( TQString::fromLatin1(
"Height %1").arg(desk.height()), 0 ) );
955 if (size.isEmpty()) {
957 size = TQSize( config->
readNumEntry( TQString::fromLatin1(
"Width"), 0 ),
958 config->
readNumEntry( TQString::fromLatin1(
"Height"), 0 ) );
959 if (!size.isEmpty()) {
961 config->
writeEntry( TQString::fromLatin1(
"Width"), 0 );
962 config->
writeEntry( TQString::fromLatin1(
"Height"), 0 );
965 if ( !size.isEmpty() ) {
968 if (size.width() > desk.width()) {
969 state = state | NET::MaxHoriz;
971 if (size.height() > desk.height()) {
972 state = state | NET::MaxVert;
975 if (( state & NET::Max ) == NET::Max ) {
976 resize( desk.width(), desk.height());
978 else if(( state & NET::MaxHoriz ) == NET::MaxHoriz ) {
979 resize( width(), size.height());
981 else if(( state & NET::MaxVert ) == NET::MaxVert ) {
982 resize( size.width(), height());
990 if (size.width() > desk.width() || size.height() > desk.height())
991 setWindowState( WindowMaximized );
1001 return d->care_about_geometry;
1006 d->care_about_geometry =
false;
1012 d->settingsDirty =
true;
1013 if ( d->autoSaveSettings )
1017 if ( !d->settingsTimer )
1019 d->settingsTimer =
new TQTimer(
this );
1022 d->settingsTimer->start( 500,
true );
1028 return d->settingsDirty;
1033 return d->autoSaveGroup;
1038 d->autoSaveSettings =
true;
1039 d->autoSaveGroup = groupName;
1042 disconnect(
this, TQT_SIGNAL( dockWindowPositionChanged( TQDockWindow * ) ),
1044 connect(
this, TQT_SIGNAL( dockWindowPositionChanged( TQDockWindow * ) ),
1053 d->autoSaveSettings =
false;
1054 if ( d->settingsTimer )
1055 d->settingsTimer->stop();
1060 return d->autoSaveSettings;
1065 return d->autoSaveGroup;
1070 Q_ASSERT( d->autoSaveSettings );
1074 d->settingsDirty =
false;
1075 if ( d->settingsTimer )
1076 d->settingsTimer->stop();
1079 void TDEMainWindow::resizeEvent( TQResizeEvent * )
1081 if ( d->autoSaveWindowSize )
1087 return (internalMenuBar());
1114 void TDEMainWindow::shuttingDown()
1118 static bool reentrancy_protection =
false;
1119 if (!reentrancy_protection)
1121 reentrancy_protection =
true;
1124 reentrancy_protection =
false;
1129 KMenuBar *TDEMainWindow::internalMenuBar()
1131 TQObjectList *l = queryList(
"KMenuBar", 0,
false,
false );
1132 if ( !l || !l->first() ) {
1142 KStatusBar *TDEMainWindow::internalStatusBar()
1144 TQObjectList *l = queryList(
"KStatusBar", 0,
false,
false );
1145 if ( !l || !l->first() ) {
1155 void TDEMainWindow::childEvent( TQChildEvent* e)
1157 TQMainWindow::childEvent( e );
1163 name =
"mainToolBar";
1167 bool honor_mode = (!strcmp(name,
"mainToolBar"));
1169 if ( builderClient() )
1170 return new TDEToolBar(
this, name, honor_mode);
1172 return new TDEToolBar(
this, DockTop,
false, name, honor_mode );
1177 toolbarList.clear();
1178 TQPtrList<TQToolBar> lst;
1179 for (
int i = (
int)TQMainWindow::DockUnmanaged; i <= (int)DockMinimized; ++i ) {
1180 lst = toolBars( (ToolBarDock)i );
1181 for ( TQToolBar *tb = lst.first(); tb; tb = lst.next() ) {
1182 if ( !tb->inherits(
"TDEToolBar" ) )
1187 return TQPtrListIterator<TDEToolBar>( toolbarList );
1193 d->tdeaccel =
new TDEAccel(
this,
"kmw-tdeaccel" );
1197 void TDEMainWindow::paintEvent( TQPaintEvent * pe )
1199 TQMainWindow::paintEvent(pe);
1205 if (tb && !tb->isHidden()) {
1208 case TDEToolBar::Top:
1209 case TDEToolBar::Bottom:
1210 size += TQSize(0, tb->sizeHint().height());
1213 case TDEToolBar::Left:
1214 case TDEToolBar::Right:
1215 size += TQSize(
toolBar()->sizeHint().width(), 0);
1218 case TDEToolBar::Flat:
1219 size += TQSize(0, 3+kapp->style().pixelMetric( TQStyle::PM_DockWindowHandleExtent ));
1227 if (mb && !mb->isHidden()) {
1228 size += TQSize(0,mb->heightForWidth(size.width()));
1229 if (style().styleHint(TQStyle::SH_MainWindow_SpaceBelowMenuBar,
this))
1230 size += TQSize( 0, dockWindowsMovable() ? 1 : 2);
1232 TQStatusBar *sb = internalStatusBar();
1233 if( sb && !sb->isHidden() )
1234 size += TQSize(0, sb->sizeHint().height());
1239 #if KDE_IS_VERSION( 3, 9, 0 )
1241 #warning Remove, should be in Qt
1261 void TDEMainWindow::virtual_hook(
int id,
void* data )
1262 { KXMLGUIBuilder::virtual_hook(
id, data );
1263 KXMLGUIClient::virtual_hook(
id, data ); }
1267 #include "tdemainwindow.moc"