00001
00002
00003
00004 #include "stdafx.h"
00005 #include "aspectspectbl.h"
00006 #include "AspectSpecDlg.h"
00007 #include "logger.h"
00008 #include "ModelRep.h"
00009 #include "ReferenceRep.h"
00010
00011 #include "globals.h"
00012 extern Globals global_vars;
00013
00014
00015 #define DUMPER_NOT_SPECIFIED_STR "Not specified"
00016
00017
00018 #ifdef _DEBUG
00019 #define new DEBUG_NEW
00020 #undef THIS_FILE
00021 static char THIS_FILE[] = __FILE__;
00022 #endif
00023
00025
00026
00027 CAspectSpecDlg::CAspectSpecDlg(LPCTSTR pszCaption, CWnd* pParentWnd, UINT iSelectPage)
00028 : CPropertySheet(pszCaption, pParentWnd, iSelectPage)
00029 , lastID(0)
00030 , countPages(0)
00031 , m_bNeedInit(TRUE)
00032 , m_nMinCX(0)
00033 , m_nMinCY(0)
00034 {
00035 m_psh.dwFlags |= PSH_NOAPPLYNOW;
00036 m_rCrt.SetRectEmpty();
00037 }
00038
00039 CAspectSpecDlg::~CAspectSpecDlg()
00040 {
00041 POSITION pos = aspectPages.GetHeadPosition();
00042 while (pos)
00043 delete aspectPages.GetNext(pos);
00044
00045 aspectPages.RemoveAll();
00046 }
00047
00048
00049
00050 #define WM_TABPAGESELECTIONCHANGE WM_USER + 111
00051
00052 BEGIN_MESSAGE_MAP(CAspectSpecDlg, CPropertySheet)
00053 ON_WM_CREATE()
00054 ON_WM_SIZE()
00055 ON_WM_GETMINMAXINFO()
00056 ON_MESSAGE(WM_TABPAGESELECTIONCHANGE, OnTabPageSelectionChange)
00057
00058
00059
00060 END_MESSAGE_MAP()
00061
00063
00064
00065
00066
00067 int CAspectSpecDlg::AddEntry(CString aspectName, CString roleName, CString kindAspect, CString primaryAsp, const void * ptr)
00068 {
00069 CAspectPage *aspectPage = NULL;
00070
00071 POSITION pos = aspectPages.GetHeadPosition();
00072 while (pos) {
00073 CAspectPage *page = aspectPages.GetNext(pos);
00074 CString title = page->GetAspectName();;
00075
00076 if (title == aspectName)
00077 aspectPage = page;
00078 }
00079
00080 if (!aspectPage) {
00081 aspectPage = new CAspectPage();
00082 aspectPage->SetAspectName(aspectName);
00083 aspectNames.AddTail(aspectName);
00084 AddPage(aspectPage);
00085 aspectPages.AddTail(aspectPage);
00086 ++countPages;
00087 }
00088
00089 aspectPage->AddEntry(lastID, roleName, kindAspect, primaryAsp, ptr);
00090 return lastID++;
00091 }
00092
00093 void CAspectSpecDlg::GetEntry(int rowID, CString &roleName, CString &kindAspect, CString &isPrimary, const void * &ptr)
00094 {
00095 POSITION pos = aspectPages.GetHeadPosition();
00096 while (pos) {
00097 if (aspectPages.GetNext(pos)->GetEntry(rowID, roleName, kindAspect, isPrimary, ptr))
00098 break;
00099 }
00100
00101 }
00102
00103 void CAspectSpecDlg::GetAspects(CStringList &aspects)
00104 {
00105 aspects.RemoveAll();
00106 aspects.AddTail(&aspectNames);
00107 }
00108
00109 void CAspectSpecDlg::GetAspects( int rowID, CStringList &aspects)
00110 {
00111 aspects.RemoveAll();
00112 CString role_name = "N/A", kind_asp = "N/A", is_prim;
00113 const void * ptr;
00114 GetEntry( rowID, role_name, kind_asp, is_prim, ptr);
00115 if ( role_name == "N/A")
00116 global_vars.err << MSG_ERROR << "Internal error: GetEntry failed. Empty rolename\n";
00117 const FCO * fco_ptr = static_cast<const FCO*>( ptr);
00118 if ( fco_ptr)
00119 {
00120 if ( fco_ptr->getMyKind() == Any::MODEL)
00121 {
00122 const ModelRep * m_ptr = static_cast<const ModelRep *>(ptr);
00123 m_ptr->getAspectNames( aspects);
00124 }
00125 else if (fco_ptr->getMyKind() == Any::REF)
00126 {
00127 aspects.AddTail( DUMPER_NOT_SPECIFIED_STR);
00128 const ReferenceRep * r_ptr = static_cast< const ReferenceRep *>(ptr);
00129 std::vector< AspectRep *> asps = r_ptr->getAspectsIntersection();
00130 std::vector< AspectRep *>::iterator asp_it = asps.begin();
00131 for( ; asp_it != asps.end(); ++asp_it)
00132 {
00133 aspects.AddTail( (*asp_it)->getName().c_str());
00134 }
00135 }
00136 else global_vars.err << MSG_ERROR << "Internal error: why other type than Model and Ref has Kindaspect?\n";
00137 }
00138 else global_vars.err << MSG_ERROR << "Internal error: zero pointer\n";
00139 }
00140
00141 BOOL CAspectSpecDlg::OnInitDialog()
00142 {
00143
00144 BOOL bResult = CPropertySheet::OnInitDialog();
00145
00146
00147
00148
00149
00150 CMenu* pMenu = GetSystemMenu(FALSE);
00151 ASSERT(pMenu);
00152
00153 GetSystemMenu( TRUE );
00154
00155 ModifyStyle(WS_DLGFRAME, WS_OVERLAPPEDWINDOW, 0);
00156
00157
00158
00159
00160
00161 CTabCtrl* tab = GetTabControl();
00162 int count = tab->GetItemCount();
00163 POSITION pos = aspectNames.GetHeadPosition();
00164 for (int i = 0; i < count; i++) {
00165 TC_ITEM tcItem;
00166 tcItem.mask = TCIF_TEXT;
00167 tcItem.pszText = aspectNames.GetNext(pos).GetBuffer(255);
00168 tab->SetItem(i, &tcItem);
00169 }
00170
00171 SetActivePage(0);
00172
00173
00174 CAspectPage* firstpage;
00175 POSITION pos1 = aspectPages.GetHeadPosition();
00176 if (pos1) {
00177 firstpage = aspectPages.GetNext(pos1);
00178 firstpage->resizeTableToFitIn();
00179 }
00180
00181
00182 CRect r;
00183 GetWindowRect(&r);
00184 m_nMinCX = r.Width();
00185 m_nMinCY = r.Height();
00186
00187 m_bNeedInit = FALSE;
00188 GetClientRect(&m_rCrt);
00189
00190 return bResult;
00191 }
00192
00193 BOOL CAspectSpecDlg::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
00194 {
00195 NMHDR* pnmh = (LPNMHDR) lParam;
00196
00197 BOOL retVal = CPropertySheet::OnNotify(wParam, lParam, pResult);
00198
00199
00200 if (TCN_SELCHANGE == pnmh->code) {
00201
00202
00203 PostMessage(WM_TABPAGESELECTIONCHANGE);
00204 }
00205
00206 return retVal;
00207 }
00208
00209 int CAspectSpecDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
00210 {
00211
00212
00213
00214
00215
00216
00217 EnableStackedTabs(countPages <= 19);
00218
00219
00220 return CPropertySheet::OnCreate(lpCreateStruct);
00221 }
00222
00223
00224
00225 void CAspectSpecDlg::OnSize(UINT nType, int cx, int cy)
00226 {
00227 CPropertySheet::OnSize(nType, cx, cy);
00228
00229 CRect r1;
00230
00231 if (m_bNeedInit)
00232 return;
00233
00234 CTabCtrl *pTab = GetTabControl();
00235 ASSERT(NULL != pTab && IsWindow(pTab->m_hWnd));
00236
00237 int dx = cx - m_rCrt.Width();
00238 int dy = cy - m_rCrt.Height();
00239 GetClientRect(&m_rCrt);
00240
00241 HDWP hDWP = ::BeginDeferWindowPos(5);
00242
00243 pTab->GetClientRect(&r1);
00244 r1.right += dx;
00245 r1.bottom += dy;
00246 ::DeferWindowPos(hDWP, pTab->m_hWnd, NULL,
00247 0, 0, r1.Width(), r1.Height(),
00248 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER);
00249
00250
00251 for(CWnd *pChild = GetWindow(GW_CHILD);
00252 pChild != NULL;
00253 pChild = pChild->GetWindow(GW_HWNDNEXT))
00254 {
00255 if (pChild->SendMessage(WM_GETDLGCODE) & DLGC_BUTTON)
00256 {
00257 pChild->GetWindowRect(&r1); ScreenToClient(&r1);
00258 r1.top += dy;
00259 r1.bottom += dy;
00260 r1.left+= dx;
00261 r1.right += dx;
00262 ::DeferWindowPos(hDWP, pChild->m_hWnd, NULL,
00263 r1.left, r1.top, 0, 0,
00264 SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOZORDER);
00265 }
00266
00267 else
00268 {
00269 pChild->GetClientRect(&r1);
00270 r1.right += dx;
00271 r1.bottom += dy;
00272 ::DeferWindowPos(hDWP, pChild->m_hWnd, NULL, 0, 0, r1.Width(), r1.Height(),
00273 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER);
00274 }
00275
00276 }
00277
00278 ::EndDeferWindowPos(hDWP);
00279
00280
00281 CAspectPage* firstpage;
00282 POSITION pos1 = aspectPages.GetHeadPosition();
00283 if (pos1) {
00284 firstpage = aspectPages.GetNext(pos1);
00285 firstpage->resizeTableToFitIn();
00286 }
00287 }
00288
00289 void CAspectSpecDlg::OnGetMinMaxInfo(MINMAXINFO* lpMMI)
00290 {
00291 CPropertySheet::OnGetMinMaxInfo(lpMMI);
00292 lpMMI->ptMinTrackSize.x = m_nMinCX;
00293 lpMMI->ptMinTrackSize.y = m_nMinCY;
00294 }
00295
00296 LRESULT CAspectSpecDlg::OnTabPageSelectionChange(WPARAM wParam, LPARAM lParam)
00297 {
00298
00299
00300 CAspectPage* page = dynamic_cast<CAspectPage*> (GetActivePage());
00301 ASSERT(page);
00302 page->resizeTableToFitIn();
00303
00304 return 0;
00305 }