update for HEAD-2003091401
[reactos.git] / subsys / system / explorer / Seashell / SeaShellExt / WindowPlacement.cpp
1 // MSJ 
2 // It it works contact Paul DiLascia
3 // if not you're own your own
4
5 #include "StdAfx.h"
6 #include "WindowPlacement.h"
7
8 CWindowPlacement::CWindowPlacement()
9 {
10    // Note: "length" is inherited from WINDOWPLACEMENT
11    length = sizeof(WINDOWPLACEMENT);
12    m_showCmd = -1;
13 }
14
15 CWindowPlacement::~CWindowPlacement()
16 {
17 }
18
19 //////////////////
20 // Restore window placement from profile key
21 BOOL CWindowPlacement::Restore(LPCTSTR lpKeyName, CWnd* pWnd)
22 {
23    if (!GetProfileWP(lpKeyName))
24            return FALSE;
25    // Only restore if window intersets the screen.
26    //
27    CRect rcTemp;
28    CRect rcScreen(0,0,GetSystemMetrics(SM_CXSCREEN),GetSystemMetrics(SM_CYSCREEN));
29    if (!::IntersectRect(&rcTemp, &rcNormalPosition, &rcScreen))
30       return FALSE;
31
32    pWnd->SetWindowPlacement(this);  
33    return TRUE;
34 }
35
36 //////////////////
37 // Get window placement from profile.
38 BOOL CWindowPlacement::GetProfileWP(LPCTSTR lpKeyName)
39 {
40    CWinApp *pApp = AfxGetApp();
41    ASSERT_VALID(pApp);
42
43    m_showCmd = pApp->GetProfileInt(lpKeyName, _T("wp.showCmd"), -1);
44    if (m_showCmd == -1)
45            return FALSE;
46    showCmd = m_showCmd;
47    flags   = pApp->GetProfileInt(lpKeyName, _T("wp.flags"), flags);
48
49         ptMinPosition.x = pApp->GetProfileInt(lpKeyName, _T("wp.ptMinPosition.x"),ptMinPosition.x);
50         ptMinPosition.y = pApp->GetProfileInt(lpKeyName, _T("wp.ptMinPosition.y"),ptMinPosition.y);
51         ptMaxPosition.x = pApp->GetProfileInt(lpKeyName, _T("wp.ptMaxPosition.x"),ptMaxPosition.x);
52         ptMaxPosition.y = pApp->GetProfileInt(lpKeyName, _T("wp.ptMaxPosition.y"),ptMaxPosition.y);
53
54    RECT& rc = rcNormalPosition;  // because I hate typing
55    rc.left  = pApp->GetProfileInt(lpKeyName, _T("wp.left"),   rc.left);
56    rc.right = pApp->GetProfileInt(lpKeyName, _T("wp.right"),  rc.right);
57    rc.top   = pApp->GetProfileInt(lpKeyName, _T("wp.top"),    rc.top);
58    rc.bottom= pApp->GetProfileInt(lpKeyName, _T("wp.bottom"), rc.bottom);
59    return TRUE;
60 }
61
62 ////////////////
63 // Save window placement in app profile
64 void CWindowPlacement::Save(LPCTSTR lpKeyName, CWnd* pWnd)
65 {
66    pWnd->GetWindowPlacement(this);
67    WriteProfileWP(lpKeyName);
68 }
69
70 //////////////////
71 // Write window placement to app profile
72 void CWindowPlacement::WriteProfileWP(LPCTSTR lpKeyName)
73 {
74    CWinApp *pApp = AfxGetApp();
75    ASSERT_VALID(pApp);
76    pApp->WriteProfileInt(lpKeyName, _T("wp.showCmd"),         showCmd);
77    pApp->WriteProfileInt(lpKeyName, _T("wp.flags"),                   flags);
78    pApp->WriteProfileInt(lpKeyName, _T("wp.ptMinPosition.x"), ptMinPosition.x);
79    pApp->WriteProfileInt(lpKeyName, _T("wp.ptMinPosition.y"), ptMinPosition.y);
80    pApp->WriteProfileInt(lpKeyName, _T("wp.ptMaxPosition.x"), ptMaxPosition.x);
81    pApp->WriteProfileInt(lpKeyName, _T("wp.ptMaxPosition.y"), ptMaxPosition.y);
82    pApp->WriteProfileInt(lpKeyName, _T("wp.left"),      rcNormalPosition.left);
83    pApp->WriteProfileInt(lpKeyName, _T("wp.right"), rcNormalPosition.right);
84    pApp->WriteProfileInt(lpKeyName, _T("wp.top"),   rcNormalPosition.top);
85    pApp->WriteProfileInt(lpKeyName, _T("wp.bottom"),rcNormalPosition.bottom);
86 }
87
88 // The ugly casts are required to help the VC++ 3.0 compiler decide which
89 // operator<< or operator>> to use. If you're using VC++ 4.0 or later, you 
90 // can delete this stuff.
91 //
92 #if (_MSC_VER < 1000)      // 1000 = VC++ 4.0
93 #define UINT_CAST (LONG)
94 #define UINT_CASTREF (LONG&)
95 #else
96 #define UINT_CAST
97 #define UINT_CASTREF
98 #endif
99
100 //////////////////
101 // Write window placement to archive
102 // WARNING: archiving functions are untested.
103 CArchive& operator<<(CArchive& ar, const CWindowPlacement& wp)
104 {
105    ar << UINT_CAST wp.length;
106    ar << UINT_CAST wp.flags;
107    ar << UINT_CAST wp.showCmd;
108    ar << wp.ptMinPosition;
109    ar << wp.ptMaxPosition;
110    ar << wp.rcNormalPosition;
111    return ar;
112 }
113
114 //////////////////
115 // Read window placement from archive
116 // WARNING: archiving functions are untested.
117 CArchive& operator>>(CArchive& ar, CWindowPlacement& wp)
118 {
119    ar >> UINT_CASTREF wp.length;
120    ar >> UINT_CASTREF wp.flags;
121    ar >> UINT_CASTREF wp.showCmd;
122    ar >> wp.ptMinPosition;
123    ar >> wp.ptMaxPosition;
124    ar >> wp.rcNormalPosition;
125    return ar;
126 }
127