00001 #ifndef NSFLEXPROPERTYSHEET_IMPLEMENTATION_FILE
00002 #define NSFLEXPROPERTYSHEET_IMPLEMENTATION_FILE
00003
00004
00005
00006
00007 #include "stdafx.h"
00008 #include "NSFlexPropertySheet.h"
00009 #include "NSFlexConstraints.h"
00010 #include "NSFlexConstraintList.h"
00011 #include "NSFlexMDIChildWnd.h"
00012 #include "NSViewsMessages.h"
00013
00014 #include <basis/convert_utf.h>
00015
00016 IMPLEMENT_DYNAMIC(CNSFlexPropertySheet, CPropertySheet)
00017
00018 BEGIN_MESSAGE_MAP(CNSFlexPropertySheet, CPropertySheet)
00019
00020 ON_WM_CREATE()
00021 ON_WM_SIZE()
00022 ON_WM_GETMINMAXINFO()
00023 ON_WM_ERASEBKGND()
00024
00025 ON_MESSAGE(WM_PAGESETACTIVE, OnPageSetActive)
00026 ON_COMMAND(ID_APPLY_NOW, OnApply)
00027 ON_COMMAND(IDOK, OnOK)
00028 ON_COMMAND(IDCANCEL, OnCancel)
00029 END_MESSAGE_MAP()
00030
00031 CNSFlexPropertySheet::CNSFlexPropertySheet()
00032 : CPropertySheet(),
00033 m_nMinTrackingWidth(0), m_nMinTrackingHeight(0), m_pSubject(NULL), m_bLastCommandWasEscape(false)
00034 {
00035 m_pFlexConstraintList = new CNSFlexConstraintList(this);
00036 }
00037
00038 CNSFlexPropertySheet::CNSFlexPropertySheet(UINT nIDCaption, CWnd* pParentWnd,
00039 UINT nSelectPage, void* pSubject) :
00040 CPropertySheet(nIDCaption,pParentWnd,nSelectPage),
00041 m_nMinTrackingWidth(0), m_nMinTrackingHeight(0), m_pSubject(pSubject), m_bLastCommandWasEscape(false)
00042 {
00043 m_pFlexConstraintList = new CNSFlexConstraintList(this);
00044 }
00045
00046 CNSFlexPropertySheet::CNSFlexPropertySheet(LPCTSTR pszCaption,
00047 CWnd* pParentWnd, UINT nSelectPage, void* pSubject) :
00048 CPropertySheet(pszCaption,pParentWnd,nSelectPage),
00049 m_nMinTrackingWidth(0), m_nMinTrackingHeight(0), m_pSubject(pSubject), m_bLastCommandWasEscape(false)
00050 {
00051 m_pFlexConstraintList = new CNSFlexConstraintList(this);
00052 }
00053
00054 CNSFlexPropertySheet::~CNSFlexPropertySheet()
00055 {
00056 delete m_pFlexConstraintList;
00057 }
00058
00059 void* CNSFlexPropertySheet::GetSubject() const
00060 {
00061 return m_pSubject;
00062 }
00063
00064 void CNSFlexPropertySheet::OnApply()
00065 {
00066 if (!GetActivePage()->UpdateData(TRUE))
00067 return;
00068
00069 if (!OnApplyChanges(m_pSubject))
00070 return;
00071
00072 for (int nPage = 0; nPage < GetPageCount(); nPage++)
00073 {
00074 CPropertyPage* pPropertyPage = GetPage(nPage);
00075 ASSERT(pPropertyPage);
00076 pPropertyPage->SetModified(FALSE);
00077 }
00078 }
00079
00080 BOOL CNSFlexPropertySheet::OnApplyChanges(void* pSubject)
00081 {
00082 return TRUE;
00083 }
00084
00085 void CNSFlexPropertySheet::OnCancel()
00086 {
00087 if (!m_bLastCommandWasEscape || GetActivePage()->OnQueryCancel())
00088 EndDialog(IDCANCEL);
00089 }
00090
00091 int CNSFlexPropertySheet::OnCreate(LPCREATESTRUCT lpCreateStruct)
00092 {
00093 if (CPropertySheet::OnCreate(lpCreateStruct) == -1)
00094 return -1;
00095
00096 LONG lSTYLE = GetWindowLong(m_hWnd,GWL_STYLE);
00097 LONG lEXSTYLE = GetWindowLong(m_hWnd,GWL_EXSTYLE);
00098
00099 if ( ((lSTYLE & DS_MODALFRAME) == DS_MODALFRAME) ||
00100 ((lSTYLE & WS_THICKFRAME) != WS_THICKFRAME) )
00101 {
00102 lSTYLE &= ~(LONG)DS_MODALFRAME;
00103 lSTYLE |= WS_THICKFRAME;
00104 SetWindowLong(m_hWnd,GWL_STYLE,lSTYLE);
00105 }
00106
00107 if ((lEXSTYLE & WS_EX_DLGMODALFRAME) == WS_EX_DLGMODALFRAME)
00108 {
00109
00110
00111
00112
00113 }
00114 else
00115 {
00116 lEXSTYLE |= (DWORD)WS_EX_CLIENTEDGE;
00117 SetWindowLong(m_hWnd,GWL_EXSTYLE,lEXSTYLE);
00118 }
00119
00120 return 0;
00121 }
00122
00123 BOOL CNSFlexPropertySheet::OnEraseBkgnd(CDC* pDC)
00124 {
00125 ASSERT_VALID(pDC);
00126 CBrush backBrush(GetSysColor(COLOR_BTNFACE));
00127 CBrush* pOldBrush = pDC->SelectObject(&backBrush);
00128 CRect rect;
00129 pDC->GetClipBox(&rect);
00130 pDC->PatBlt(rect.left,rect.top,rect.Width(),rect.Height(),PATCOPY);
00131 pDC->SelectObject(pOldBrush);
00132 return TRUE;
00133 }
00134
00135 void CNSFlexPropertySheet::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
00136 {
00137 CPropertySheet::OnGetMinMaxInfo(lpMMI);
00138
00139 lpMMI->ptMinTrackSize.x = m_nMinTrackingWidth;
00140 lpMMI->ptMinTrackSize.y = m_nMinTrackingHeight;
00141 }
00142
00143 BOOL CNSFlexPropertySheet::OnInitDialog()
00144 {
00145 CPropertySheet::OnInitDialog();
00146
00147 if (m_bModeless)
00148 {
00149 #ifdef _DEBUG
00150 if (!GetParentFrame()->IsKindOf(RUNTIME_CLASS(CNSFlexMDIChildWnd)))
00151 TRACE_PRINT("Warning! Modeless CNSFlexPropertySheet "
00152 "used without a CNSFlexMDIChildWnd frame.\n");
00153 #endif
00154 SetWindowPos(NULL,0,0,0,0,SWP_NOSIZE|SWP_NOZORDER|SWP_NOACTIVATE);
00155 }
00156
00157 CRect rect;
00158
00159 GetWindowRect(rect);
00160 m_nMinTrackingWidth = rect.Width();
00161 m_nMinTrackingHeight = rect.Height();
00162
00163 GetClientRect(rect);
00164 m_pFlexConstraintList->
00165 SetClientBaseSize(rect.Width(),rect.Height());
00166
00167 m_pFlexConstraintList->AddConstraint(
00168 IDOK, NSFlexShiftRight, NSFlexShiftDown);
00169 m_pFlexConstraintList->AddConstraint(
00170 IDCANCEL, NSFlexShiftRight, NSFlexShiftDown);
00171 if ((m_psh.dwFlags & PSH_NOAPPLYNOW) != PSH_NOAPPLYNOW)
00172 m_pFlexConstraintList->AddConstraint(
00173 ID_APPLY_NOW, NSFlexShiftRight, NSFlexShiftDown);
00174 if ((m_psh.dwFlags & PSH_HASHELP) == PSH_HASHELP)
00175 m_pFlexConstraintList->AddConstraint(
00176 IDHELP, NSFlexShiftRight, NSFlexShiftDown);
00177 m_pFlexConstraintList->AddConstraint(
00178 AFX_IDC_TAB_CONTROL, NSFlexExpandRight, NSFlexExpandDown);
00179
00180 return TRUE;
00181 }
00182
00183 void CNSFlexPropertySheet::OnOK()
00184 {
00185 if (!GetActivePage()->UpdateData(TRUE))
00186 return;
00187
00188 if (!OnApplyChanges(m_pSubject))
00189 return;
00190
00191 EndDialog(IDOK);
00192 }
00193
00194 LRESULT CNSFlexPropertySheet::OnPageSetActive(WPARAM wParam, LPARAM lParam)
00195 {
00196 if (m_nMinTrackingWidth == 0)
00197 return 1;
00198
00199 CRect rectTabControl;
00200 GetTabControl()->GetWindowRect(&rectTabControl);
00201 ScreenToClient(&rectTabControl);
00202
00203 CRect rectTab;
00204 int nCurSel = GetTabControl()->GetCurSel();
00205 GetTabControl()->GetItemRect(nCurSel,&rectTab);
00206
00207 CPropertyPage* pPropertyPage = GetPage(nCurSel);
00208 rectTabControl.TopLeft().y += rectTab.BottomRight().y;
00209
00210 pPropertyPage->SetWindowPos(NULL,rectTabControl.TopLeft().x+4,
00211 rectTabControl.TopLeft().y+2,rectTabControl.Width()-8,
00212 rectTabControl.Height()-5,SWP_NOZORDER|SWP_NOACTIVATE);
00213
00214 return 1;
00215 }
00216
00217 void CNSFlexPropertySheet::OnSize(UINT nType, int cx, int cy)
00218 {
00219 CPropertySheet::OnSize(nType, cx, cy);
00220
00221 if (nType != SIZE_MINIMIZED)
00222 {
00223 m_pFlexConstraintList->PositionControls(cx,cy);
00224 OnPageSetActive(0,0);
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234 if (m_nMinTrackingWidth != 0)
00235 {
00236 CTabCtrl* pTabCtrl = GetTabControl();
00237 ASSERT(pTabCtrl);
00238 pTabCtrl->Invalidate();
00239 }
00240
00241 Invalidate();
00242
00243
00244
00245
00246 }
00247 }
00248
00249 BOOL CNSFlexPropertySheet::PreTranslateMessage(MSG* pMsg)
00250 {
00251 if ((WM_KEYFIRST <= pMsg->message) && (pMsg->message <= WM_KEYLAST) && (pMsg->wParam == VK_ESCAPE))
00252 m_bLastCommandWasEscape = true;
00253 else
00254 m_bLastCommandWasEscape = false;
00255
00256 CView* pParent = (CView*)GetParent();
00257 if (pParent && pParent->IsKindOf(RUNTIME_CLASS(CView)))
00258 if(pParent->PreTranslateMessage(pMsg))
00259 return TRUE;
00260
00261 return CPropertySheet::PreTranslateMessage(pMsg);
00262 }
00263
00264 void CNSFlexPropertySheet::SetSubject(void* pSubject)
00265 {
00266 m_pSubject = pSubject;
00267 }
00268
00269 #endif //NSFLEXPROPERTYSHEET_IMPLEMENTATION_FILE
00270