--- source/MainFrm.cpp	Sat Mar 19 16:30:56 2005
+++ source.patch/MainFrm.cpp	Sun Mar 20 13:53:02 2005
@@ -478,30 +478,38 @@
 	{
 		m_wndLocalSplitter.GetRowInfo(1,s2,temp);
 		m_wndLocalSplitter.GetRowInfo(0,s1,temp);
-		if (s1>s2)
+		if (s1>s2) {
 			m_wndLocalSplitter.SetRowInfo(0,(s1+s2)/2,1);
+			m_wndLocalSplitter.RecalcLayout();
+		}
 	}
 	else
 	{
 		m_wndLocalSplitter.GetColumnInfo(1,s2,temp);
 		m_wndLocalSplitter.GetColumnInfo(0,s1,temp);
-		if (s1 > s2)
+		if (s1 > s2) {
 			m_wndLocalSplitter.SetColumnInfo(0,(s1+s2)/2,1);
+			m_wndLocalSplitter.RecalcLayout();
+		}
 	}
 	
 	if (!m_nRemoteTreeViewLocation)
 	{
 		m_wndRemoteSplitter.GetRowInfo(1, s2, temp);
 		m_wndRemoteSplitter.GetRowInfo(0, s1, temp);
-		if (s1>s2)
+		if (s1>s2) {
 			m_wndRemoteSplitter.SetRowInfo(0,(s1+s2)/2,1);
+			m_wndRemoteSplitter.RecalcLayout();
+		}
 	}
 	else
 	{
 		m_wndRemoteSplitter.GetColumnInfo(1, s2, temp);
 		m_wndRemoteSplitter.GetColumnInfo(0, s1, temp);
-		if (s1>s2)
+		if (s1>s2) {
 			m_wndRemoteSplitter.SetColumnInfo(0,(s1+s2)/2,1);
+			m_wndRemoteSplitter.RecalcLayout();
+		}
 	}
 
 
@@ -514,11 +522,9 @@
 	m_wndMainSplitter.GetColumnInfo(0,cx,temp);
 	m_wndMainSplitter.GetColumnInfo(1,cx2,temp);
 	m_wndMainSplitter.SetColumnInfo(0,(cx+cx2)/2,0);
+	m_wndMainSplitter.RecalcLayout();
 	((CQueueCtrl*)GetQueuePane()->GetListCtrl())->UpdateStatusbar();
 
-	//Restore window size and position
-	RestoreSize();
-
 	//Hide panes disabled in options
 	if (COptions::GetOptionVal(OPTION_SHOWNOTOOLBAR))
 		OnViewToolbar();
@@ -549,12 +555,6 @@
 	}
 	SetLocalFolder(folder);
 	
-	if (COptions::GetOptionVal(OPTION_SHOWSITEMANAGERONSTARTUP))
-	{
-		ShowWindow(SW_SHOW);
-		OnSitemanager();
-	}
-
 	if (COptions::GetOptionVal(OPTION_ENABLEDEBUGMENU))
 	{
 		CMenu *pMenu=GetMenu();
@@ -593,6 +593,12 @@
 		m_pMinTrayBtn->MinTrayBtnShow();
 	}
 
+	//Restore window size and position
+	RestoreSize();
+
+	if (COptions::GetOptionVal(OPTION_SHOWSITEMANAGERONSTARTUP))
+		OnSitemanager();
+
 	return 0;
 }

@@ -1544,6 +1544,60 @@
 		CString folder=GetLocalPane2()->GetLocalFolder();
 		COptions::SetOption(OPTION_DEFAULTFOLDER,folder);
 	}
+	if (COptions::GetOptionVal(OPTION_REMEMBERVIEWS))
+	{
+		COptions::SetOption(OPTION_SHOWNOTOOLBAR,!m_pWndToolBar->IsVisible());
+		COptions::SetOption(OPTION_SHOWNOQUICKCONNECTBAR,!m_pWndDlgBar->IsVisible());
+		COptions::SetOption(OPTION_SHOWNOSTATUSBAR,!m_wndStatusBar.IsVisible());
+		COptions::SetOption(OPTION_SHOWNOMESSAGELOG,!m_bShowMessageLog);
+		COptions::SetOption(OPTION_SHOWNOTREEVIEW,!m_bShowTree);
+		COptions::SetOption(OPTION_SHOWREMOTETREEVIEW, m_bShowRemoteTree);
+		COptions::SetOption(OPTION_SHOWNOQUEUE,!m_bShowQueue);
+	}
+	if (COptions::GetOptionVal(OPTION_REMEMBERLOCALVIEW))
+	{
+		COptions::SetOption(OPTION_LOCALLISTVIEWSTYLE, m_nLocalListViewStyle);
+		COptions::SetOption(OPTION_HIDELOCALCOLUMNS, m_nHideLocalColumns);
+		COptions::SetOption(OPTION_SHOWLOCALSTATUSBAR, GetLocalPane2()->IsStatusbarEnabled()?1:0);
+	}
+	if (COptions::GetOptionVal(OPTION_REMEMBERREMOTEVIEW))
+	{
+		COptions::SetOption(OPTION_REMOTELISTVIEWSTYLE,m_nRemoteListViewStyle);
+		COptions::SetOption(OPTION_HIDEREMOTECOLUMNS, m_nHideRemoteColumns);
+		COptions::SetOption(OPTION_SHOWREMOTESTATUSBAR, GetFtpPane()->IsStatusbarEnabled()?1:0);
+	}
+	if (COptions::GetOptionVal(OPTION_REMEMBERLASTWINDOWPOS))
+	{
+		WINDOWPLACEMENT placement;
+		BOOL res=GetWindowPlacement(&placement);
+		CString str;
+		int state=0;
+		if (placement.showCmd==SW_MAXIMIZE || placement.showCmd==SW_SHOWMAXIMIZED)
+			state=1;
+		if (!m_PosData.state)
+			str.Format(_T("%d %d %d %d %d"), state,placement.rcNormalPosition.left, placement.rcNormalPosition.top, placement.rcNormalPosition.right, placement.rcNormalPosition.bottom);
+		else
+			str.Format(_T("%d %d %d %d %d"), state,m_PosData.NormalRect.left, m_PosData.NormalRect.top, m_PosData.NormalRect.right, m_PosData.NormalRect.bottom);
+		COptions::SetOption(OPTION_LASTWINDOWPOS,str);
+		if (m_wndVertSplitter.IsRowHidden(0))
+			m_wndVertSplitter.ShowRow(0);
+		if (m_wndVertSplitter.IsRowHidden(2))
+			m_wndVertSplitter.ShowRow(2);
+		int cy1,cy2,cy3, cy4, cx,tmp;
+		m_wndVertSplitter.GetRowInfoEx(0,cy1,tmp);
+		m_wndVertSplitter.GetRowInfoEx(1,cy2,tmp);
+		if (m_nLocalTreeViewLocation)
+			m_wndLocalSplitter.GetColumnInfoEx(0,cy3,tmp);
+		else
+			m_wndLocalSplitter.GetRowInfoEx(0,cy3,tmp);
+		if (m_nRemoteTreeViewLocation)
+			m_wndRemoteSplitter.GetColumnInfoEx(0,cy4,tmp);
+		else
+			m_wndRemoteSplitter.GetRowInfoEx(0,cy4,tmp);
+		m_wndMainSplitter.GetColumnInfo(m_bSwitchPaneLayout?1:0, cx, tmp);		
+		str.Format(_T("%d %d %d %d %d"), cy1, cy2, cy3, cy4, cx);
+		COptions::SetOption(OPTION_LASTSPLITTERSIZE, str);
+	}
 
 	CMenu *menu2 = GetMenu();
 	if (menu2 && menu2->m_hMenu!=m_hMenuDefault)
@@ -2606,61 +2660,6 @@
 
 void CMainFrame::OnDestroy() 
 {
-	if (COptions::GetOptionVal(OPTION_REMEMBERVIEWS))
-	{
-		COptions::SetOption(OPTION_SHOWNOTOOLBAR,!m_pWndToolBar->IsVisible());
-		COptions::SetOption(OPTION_SHOWNOQUICKCONNECTBAR,!m_pWndDlgBar->IsVisible());
-		COptions::SetOption(OPTION_SHOWNOSTATUSBAR,!m_wndStatusBar.IsVisible());
-		COptions::SetOption(OPTION_SHOWNOMESSAGELOG,!m_bShowMessageLog);
-		COptions::SetOption(OPTION_SHOWNOTREEVIEW,!m_bShowTree);
-		COptions::SetOption(OPTION_SHOWREMOTETREEVIEW, m_bShowRemoteTree);
-		COptions::SetOption(OPTION_SHOWNOQUEUE,!m_bShowQueue);
-	}
-	if (COptions::GetOptionVal(OPTION_REMEMBERLOCALVIEW))
-	{
-		COptions::SetOption(OPTION_LOCALLISTVIEWSTYLE, m_nLocalListViewStyle);
-		COptions::SetOption(OPTION_HIDELOCALCOLUMNS, m_nHideLocalColumns);
-		COptions::SetOption(OPTION_SHOWLOCALSTATUSBAR, GetLocalPane2()->IsStatusbarEnabled()?1:0);
-	}
-	if (COptions::GetOptionVal(OPTION_REMEMBERREMOTEVIEW))
-	{
-		COptions::SetOption(OPTION_REMOTELISTVIEWSTYLE,m_nRemoteListViewStyle);
-		COptions::SetOption(OPTION_HIDEREMOTECOLUMNS, m_nHideRemoteColumns);
-		COptions::SetOption(OPTION_SHOWREMOTESTATUSBAR, GetFtpPane()->IsStatusbarEnabled()?1:0);
-	}
-	if (COptions::GetOptionVal(OPTION_REMEMBERLASTWINDOWPOS))
-	{
-		WINDOWPLACEMENT placement;
-		BOOL res=GetWindowPlacement(&placement);
-		CString str;
-		int state=0;
-		if (placement.showCmd==SW_MAXIMIZE || placement.showCmd==SW_SHOWMAXIMIZED)
-			state=1;
-		if (!m_PosData.state)
-			str.Format(_T("%d %d %d %d %d"), state,placement.rcNormalPosition.left, placement.rcNormalPosition.top, placement.rcNormalPosition.right, placement.rcNormalPosition.bottom);
-		else
-			str.Format(_T("%d %d %d %d %d"), state,m_PosData.NormalRect.left, m_PosData.NormalRect.top, m_PosData.NormalRect.right, m_PosData.NormalRect.bottom);
-		COptions::SetOption(OPTION_LASTWINDOWPOS,str);
-		if (m_wndVertSplitter.IsRowHidden(0))
-			m_wndVertSplitter.ShowRow(0);
-		if (m_wndVertSplitter.IsRowHidden(2))
-			m_wndVertSplitter.ShowRow(2);
-		int cy1,cy2,cy3, cy4, cx,tmp;
-		m_wndVertSplitter.GetRowInfoEx(0,cy1,tmp);
-		m_wndVertSplitter.GetRowInfoEx(1,cy2,tmp);
-		if (m_nLocalTreeViewLocation)
-			m_wndLocalSplitter.GetColumnInfoEx(0,cy3,tmp);
-		else
-			m_wndLocalSplitter.GetRowInfoEx(0,cy3,tmp);
-		if (m_nRemoteTreeViewLocation)
-			m_wndRemoteSplitter.GetColumnInfoEx(0,cy4,tmp);
-		else
-			m_wndRemoteSplitter.GetRowInfoEx(0,cy4,tmp);
-		m_wndMainSplitter.GetColumnInfo(m_bSwitchPaneLayout?1:0, cx, tmp);		
-		str.Format(_T("%d %d %d %d %d"), cy1, cy2, cy3, cy4, cx);
-		COptions::SetOption(OPTION_LASTSPLITTERSIZE, str);
-	}
-
 	if (m_pSecureIconCtrl->GetSafeHwnd() && m_pSecureIconCtrl->GetIcon())
 		DestroyIcon(m_pSecureIconCtrl->GetIcon());
 	delete m_pSecureIconCtrl;
@@ -3251,7 +3250,8 @@
 	if (m_PosData.state==1)
- 	{
 		ShowWindow(SW_MAXIMIZE);
-		m_PosData.cy2-=27;
- 	}
 	else
 		ShowWindow(SW_RESTORE);
@@ -3259,10 +3265,12 @@
 		m_wndLocalSplitter.SetColumnInfo(0,m_PosData.cy3,0);
 	else
 		m_wndLocalSplitter.SetRowInfo(0,m_PosData.cy3,0);
+	m_wndLocalSplitter.RecalcLayout();
 	if (m_nRemoteTreeViewLocation)
 		m_wndRemoteSplitter.SetColumnInfo(0,m_PosData.cy4,0);
 	else
 		m_wndRemoteSplitter.SetRowInfo(0,m_PosData.cy4,0);
+	m_wndRemoteSplitter.RecalcLayout();
 	if (m_bSwitchPaneLayout)
 	{
 		int cx1, cx2, tmp;
@@ -3272,6 +3280,7 @@
 	}
 	else
 		m_wndMainSplitter.SetColumnInfo(0, m_PosData.cx, 0);
+	m_wndMainSplitter.RecalcLayout();
 	m_wndVertSplitter.RecalcLayout();
 	
 	return TRUE;
@@ -3598,6 +3607,12 @@
 	{
 		if (COptions::GetOptionVal(OPTION_MINIMIZETOTRAY) == 1)
 		{
+			WINDOWPLACEMENT placement;
+			BOOL res=GetWindowPlacement(&placement);
+			if (placement.showCmd==SW_MAXIMIZE || placement.showCmd==SW_SHOWMAXIMIZED)
+				m_bMaxBeforeTray = true;
+			else
+				m_bMaxBeforeTray = false;
 			ShowWindow(SW_HIDE);
 			m_TrayIcon.AddIcon();
 			m_TrayIcon.ShowIcon();
@@ -3605,6 +3620,12 @@
 	}
 	else if (nID == SC_MINIMIZETRAY)
 	{
+		WINDOWPLACEMENT placement;
+		BOOL res=GetWindowPlacement(&placement);
+		if (placement.showCmd==SW_MAXIMIZE || placement.showCmd==SW_SHOWMAXIMIZED)
+			m_bMaxBeforeTray = true;
+		else
+			m_bMaxBeforeTray = false;
 		ShowWindow(SW_HIDE);
 		m_TrayIcon.AddIcon();
 		m_TrayIcon.ShowIcon();
@@ -3794,7 +3815,10 @@
 void CMainFrame::OnTrayRestore() 
 {
 	ShowWindow(SW_RESTORE);
-	ShowWindow(SW_SHOW);
+	if (m_bMaxBeforeTray)
+		ShowWindow(SW_SHOWMAXIMIZED);
+	else
+		ShowWindow(SW_SHOW);
 	m_TrayIcon.HideIcon();
 }
 
diff -Nur source/MainFrm.h source.patch/MainFrm.h
--- source/MainFrm.h	Thu Mar 24 12:43:46 2005
+++ source.patch/MainFrm.h	Thu Mar 24 12:43:52 2005
@@ -161,6 +161,7 @@
 	} m_PosData;
 
 	// Minimize to tray button
+	BOOL m_bMaxBeforeTray;
 	CMinTrayBtn *m_pMinTrayBtn;
 
 	int m_nLocalTreeViewLocation;

