Update of /cvsroot/audacity/audacity-src/src
In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv15145

Modified Files:
        AudacityApp.cpp Project.cpp 
Log Message:
Fix problem with hidden project window on Windows (thanks to Ed Musgrove)

Index: Project.cpp
===================================================================
RCS file: /cvsroot/audacity/audacity-src/src/Project.cpp,v
retrieving revision 1.455
retrieving revision 1.456
diff -u -d -r1.455 -r1.456
--- Project.cpp 20 Sep 2009 19:06:06 -0000      1.455
+++ Project.cpp 30 Sep 2009 19:31:44 -0000      1.456
@@ -470,7 +470,6 @@
 {
    bool bMaximized;
    wxRect wndRect;
-
    GetNextWindowPlacement(&wndRect, &bMaximized);
 
    //Create and show a new project
@@ -544,15 +543,13 @@
 // BG: Does not store X and Y in prefs. This is intentional.
 void GetNextWindowPlacement(wxRect *nextRect, bool *bMaximized)
 {
-   wxRect defWndRect;
    int inc = 25;
-
-   GetDefaultWindowRect(&defWndRect);
-
    *bMaximized = false;
+   wxRect defWndRect;
 
    if (gAudacityProjects.IsEmpty()) {
       //Read the values from the registry, or use the defaults
+      GetDefaultWindowRect(&defWndRect);
       nextRect->SetX(gPrefs->Read(wxT("/Window/X"), defWndRect.GetX()));
       nextRect->SetY(gPrefs->Read(wxT("/Window/Y"), defWndRect.GetY()));
       nextRect->SetWidth(gPrefs->Read(wxT("/Window/Width"), 
defWndRect.GetWidth()));
@@ -561,11 +558,33 @@
       gPrefs->Read(wxT("/Window/Maximized"), bMaximized);
    }
    else {
-      //Base the values on the previous Window
-      *nextRect = gAudacityProjects[gAudacityProjects.GetCount()-1]->GetRect();
-
-      *bMaximized = 
gAudacityProjects[gAudacityProjects.GetCount()-1]->IsMaximized();
-
+   //This code was heavily modified to deal with iconized project windows
+   //efm5 28 September 2009
+      bool validWindowSize = FALSE;
+      AudacityProject * validProject = NULL;
+      size_t numProjects = gAudacityProjects.Count();
+      for (size_t i = 0; i < numProjects; i++)
+      {
+         if (!gAudacityProjects[i]->IsIconized()) {
+            validWindowSize = TRUE;
+            validProject = gAudacityProjects[i];
+            i = numProjects;
+         }
+      }
+      if (validWindowSize)
+      {
+         *nextRect = validProject->GetRect();
+         *bMaximized = validProject->IsMaximized();
+      }
+      else 
+      {
+         GetDefaultWindowRect(&defWndRect);
+         nextRect->SetX(gPrefs->Read(wxT("/Window/X"), defWndRect.GetX()));
+         nextRect->SetY(gPrefs->Read(wxT("/Window/Y"), defWndRect.GetY()));
+         nextRect->SetWidth(gPrefs->Read(wxT("/Window/Width"), 
defWndRect.GetWidth()));
+         nextRect->SetHeight(gPrefs->Read(wxT("/Window/Height"), 
defWndRect.GetHeight()));
+         gPrefs->Read(wxT("/Window/Maximized"), bMaximized);
+      }
       //Placement depends on the increments
       nextRect->x += inc;
       nextRect->y += inc;
@@ -1448,6 +1467,7 @@
 
 void AudacityProject::OnIconize(wxIconizeEvent &event)
 {
+
    int VisibleProjectCount = 0;
 
    //JKC: On Iconizing we get called twice.  Don't know
@@ -1803,9 +1823,11 @@
    //
    // LL: Save before doing anything else to the window that might make
    //     its size change.
-   if (gAudacityProjects.GetCount() == 1) {
-      SaveWindowSize();
-   }
+   //This is to repair the potential situation in which Audacity opens with
+   //   the initial opening window invisible.
+      //This SaveWindowSize call was modified to deal with iconized project 
windows
+      //efm5 28 September 2009
+         SaveWindowSize();
 
    mLastFocusedWindow = NULL;
    mIsDeleting = true;

Index: AudacityApp.cpp
===================================================================
RCS file: /cvsroot/audacity/audacity-src/src/AudacityApp.cpp,v
retrieving revision 1.248
retrieving revision 1.249
diff -u -d -r1.248 -r1.249
--- AudacityApp.cpp     20 Sep 2009 19:06:04 -0000      1.248
+++ AudacityApp.cpp     30 Sep 2009 19:31:43 -0000      1.249
@@ -221,25 +221,8 @@
 bool gInited = false;
 bool gIsQuitting = false;
 
-void SaveWindowSize()
-{
-   if(!gAudacityProjects.IsEmpty())
-   {
-      // BG: Save size of Window 0.
-      if (!gAudacityProjects[0]->IsIconized()) {
-         wxRect r = gAudacityProjects[0]->GetRect();
-         bool wndMaximized = gAudacityProjects[0]->IsMaximized();
-         gPrefs->Write(wxT("/Window/X"), r.GetX());
-         gPrefs->Write(wxT("/Window/Y"), r.GetY());
-         gPrefs->Write(wxT("/Window/Width"), r.GetWidth());
-         gPrefs->Write(wxT("/Window/Height"), r.GetHeight());
-         gPrefs->Write(wxT("/Window/Maximized"), wndMaximized);   
-      }
-   }
-}
-
 void QuitAudacity(bool bForce)
-{
+{                                          
    if (gIsQuitting)
       return;
 
@@ -250,7 +233,7 @@
    // BG: unless force is true
 
    // BG: Are there any projects open?
-       //-   if (!gAudacityProjects.IsEmpty())
+   //-   if (!gAudacityProjects.IsEmpty())
 /*start+*/
    if (gAudacityProjects.IsEmpty())
    {
@@ -258,10 +241,12 @@
       AudacityProject::DeleteClipboard();
 #endif
    }
-       else
+   else
 /*end+*/
-
    {
+      //This SaveWindowSize call was heavily modified to deal with iconized 
project windows
+      //efm5 28 September 2009
+      SaveWindowSize();
       while (gAudacityProjects.Count())
       {
          if (bForce)
@@ -314,10 +299,58 @@
 }
 
 void QuitAudacity()
-{
+{   
    QuitAudacity(false);
 }
 
+
+//Use this new static Boolean to determine if the project window
+//   location and size have already been written to preferences.
+//efm5 28 September 2009
+static bool windowRectAlreadySaved = FALSE;
+
+void SaveWindowSize()
+   //This code was heavily modified to deal with iconized project windows.
+   //efm5 28 September 2009
+{
+   if (windowRectAlreadySaved)
+   {
+      return;
+   }
+   bool validWindowForSaveWindowSize = FALSE;
+   AudacityProject * validProject = NULL;
+   size_t numProjects = gAudacityProjects.Count();
+   for (size_t i = 0; i < numProjects; i++)
+   {
+      if (!gAudacityProjects[i]->IsIconized()) {
+         validWindowForSaveWindowSize = TRUE;
+         validProject = gAudacityProjects[i];
+         i = numProjects;
+      }
+   }
+   if (validWindowForSaveWindowSize)
+   {
+      wxRect windowRect = validProject->GetRect();
+      bool wndMaximized = validProject->IsMaximized();
+      gPrefs->Write(wxT("/Window/X"), windowRect.GetX());
+      gPrefs->Write(wxT("/Window/Y"), windowRect.GetY());
+      gPrefs->Write(wxT("/Window/Width"), windowRect.GetWidth());
+      gPrefs->Write(wxT("/Window/Height"), windowRect.GetHeight());
+      gPrefs->Write(wxT("/Window/Maximized"), wndMaximized);
+   }
+   else
+   {
+      wxRect defWndRect;
+      GetDefaultWindowRect(&defWndRect);
+      gPrefs->Write(wxT("/Window/X"), defWndRect.GetX());
+      gPrefs->Write(wxT("/Window/Y"), defWndRect.GetY());
+      gPrefs->Write(wxT("/Window/Width"), defWndRect.GetWidth());
+      gPrefs->Write(wxT("/Window/Height"), defWndRect.GetHeight());
+      gPrefs->Write(wxT("/Window/Maximized"), FALSE);
+   }
+   windowRectAlreadySaved = TRUE;
+}
+
 #if defined(__WXGTK__) && defined(HAVE_GTK)
 
 ///////////////////////////////////////////////////////////////////////////////
@@ -837,9 +870,9 @@
 
    InitPreferences();
 
-       #if defined(__WXMSW__) && !defined(__WXUNIVERSAL__) && 
!defined(__CYGWIN__)
-               this->AssociateFileTypes(); 
-       #endif
+   #if defined(__WXMSW__) && !defined(__WXUNIVERSAL__) && !defined(__CYGWIN__)
+      this->AssociateFileTypes(); 
+   #endif
 
    // TODO - read the number of files to store in history from preferences
    mRecentFiles = new FileHistory(/* number of files */);
@@ -1124,12 +1157,12 @@
    }                            // if (argc>1)
 
 #else //__CYGWIN__
-       
+   
    // Cygwin command line parser (by Dave Fancella)
    if (argc > 1 && !didRecoverAnything) {
       int optionstart = 1;
       bool startAtOffset = false;
-               
+      
       // Scan command line arguments looking for trouble
       for (int option = 1; option < argc; option++) {
          if (!argv[option])
@@ -1141,14 +1174,14 @@
             optionstart = option + 1;
          }
       }
-               
+      
       for (int option = optionstart; option < argc; option++) {
          if (!argv[option])
             continue;
          bool handled = false;
          bool openThisFile = false;
          wxString fileToOpen;
-                       
+         
          if (!wxString(wxT("-help")).CmpNoCase(argv[option])) {
             PrintCommandLineHelp(); // print the help message out
             exit(0);
@@ -1178,10 +1211,10 @@
             wxPrintf(_("Unknown command line option: %s\n"), argv[option]);
             exit(0);
          }
-                       
+         
          if(handled)
             fileToOpen.Clear();
-                       
+         
          if (!handled)
             fileToOpen = fileToOpen + wxT(" ") + argv[option];
          if(wxString(argv[option]).Lower().Contains(wxT(".aup")))
@@ -1735,11 +1768,11 @@
 
 //BG: On Windows, associate the aup file type with Audacity
 /* We do this in the Windows installer now, 
-       to avoid issues where user doesn't have admin privileges, but 
-       in case that didn't work, allow the user to decide at startup.
+   to avoid issues where user doesn't have admin privileges, but 
+   in case that didn't work, allow the user to decide at startup.
 
-       //v Should encapsulate this & allow access from Prefs, too, 
-       //              if people want to manually change associations.
+   //v Should encapsulate this & allow access from Prefs, too, 
+   //      if people want to manually change associations.
 */
 #if defined(__WXMSW__) && !defined(__WXUNIVERSAL__) && !defined(__CYGWIN__)
 void AudacityApp::AssociateFileTypes()
@@ -1752,7 +1785,7 @@
       associateFileTypes.SetName(wxT("HKCU\\Software\\Classes\\.AUP"));
       bKeyExists = associateFileTypes.Exists();
    }
-   if (!bKeyExists) {  
+   if (!bKeyExists) {   
       // File types are not currently associated. 
       // Check pref in case user has already decided against it.
       bool bWantAssociateFiles = true;


------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf
_______________________________________________
Audacity-cvs mailing list
Audacity-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/audacity-cvs

Reply via email to