GME  13
GMEPartBrowser.cpp
Go to the documentation of this file.
00001 // GMEPartBrowser.cpp: implementation of the CGMEPartBrowser class.
00002 //
00004 
00005 #include "stdafx.h"
00006 #include "GMEApp.h"
00007 #include "GMEstd.h"
00008 #include "mainfrm.h"
00009 #include "GMEDoc.h"
00010 #include "GMEView.h"
00011 #include "GMEPartBrowser.h"
00012 #include "GuiMeta.h"
00013 
00014 
00016 // CGMEPartBrowser
00017 
00018 CGMEPartBrowser* CGMEPartBrowser::theInstance = 0;
00020 // Construction/Destruction
00022 
00023 CGMEPartBrowser::CGMEPartBrowser():
00024         guiMetaModel (NULL)
00025 {
00026         //{{AFX_DATA_INIT(CGMEPartBrowser)
00027         //}}AFX_DATA_INIT
00028 
00029         VERIFY(theInstance == 0);
00030         theInstance = this;
00031 }
00032 
00033 
00034 BEGIN_MESSAGE_MAP(CGMEPartBrowser, CDockablePane)
00035         //{{AFX_MSG_MAP(CGMEPartBrowser)
00036         ON_WM_CREATE()
00037         ON_WM_SIZE()
00038         ON_WM_CLOSE()
00039         //}}AFX_MSG_MAP
00040 END_MESSAGE_MAP()
00041 
00042 
00043 BEGIN_EVENTSINK_MAP(CGMEPartBrowser, CDockablePane)
00044         //{{AFX_EVENTSINK_MAP(CGMEPartBrowser)
00045         ON_EVENT(CGMEPartBrowser, IDC_PARTBROWSERCTRL1, 1 /* AspectChanged */, OnAspectChangedGmePartBrowserCtrl, VTS_I4)
00046         //}}AFX_EVENTSINK_MAP
00047 END_EVENTSINK_MAP()
00048 
00050 // CGMEPartBrowser message handlers
00051 
00052 int CGMEPartBrowser::OnCreate(LPCREATESTRUCT lpCreateStruct)
00053 {
00054         if (CDockablePane::OnCreate(lpCreateStruct) == -1)
00055                 return -1;
00056 
00057         if (!m_PartBrowserWrapper.Create(_T("PartBrowser"), WS_CHILD | WS_VISIBLE, CRect(0, 0, 300, 150), this, IDC_PARTBROWSERCTRL1))
00058                 return -1;
00059 
00060         // older versions of Windows* (NT 3.51 for instance) fail with DEFAULT_GUI_FONT
00061         if (!m_font.CreateStockObject(DEFAULT_GUI_FONT))
00062                 if (!m_font.CreatePointFont(80, _T("MS Sans Serif")))
00063                         return -1;
00064         m_PartBrowserWrapper.SetFont(&m_font);
00065 
00066         return 0;
00067 }
00068 
00069 
00070 void CGMEPartBrowser::OnUpdateCmdUI(CFrameWnd* pTarget, BOOL bDisableIfNoHndler)
00071 {
00072         CDockablePane::OnUpdateCmdUI(pTarget, bDisableIfNoHndler);
00073 
00074         UpdateDialogControls(pTarget, bDisableIfNoHndler);
00075 }
00076 
00077 
00078 void CGMEPartBrowser::OnSize(UINT nType, int cx, int cy)
00079 {
00080         CDockablePane::OnSize(nType, cx, cy);
00081 
00082         CRect rc;
00083         GetClientRect(rc);
00084 
00085         m_PartBrowserWrapper.MoveWindow(rc);
00086 }
00087 
00088 
00089 void CGMEPartBrowser::DoDataExchange(CDataExchange* pDX)
00090 {
00091         //{{AFX_DATA_MAP(CGMEPartBrowser)
00092         DDX_Control(pDX, IDC_PARTBROWSERCTRL1, m_PartBrowserWrapper);
00093         //}}AFX_DATA_MAP
00094 }
00095 
00096 
00097 /* 
00098 ActiveX controls do not have their message pump, it is owned by their containers.
00099 The container in case of GME is a kind of control bar, which is treated as a dialog.
00100 Dialog box messages are filtered by ::IsDialogMessage, which does not allow the 
00101 default dialog kestroke messages (ESC - close dialog, ENTER - push default button
00102 TAB - next item in the tab order etc...) to be propagated to the controls placed on 
00103 the dialog.
00104 
00105 Here we avoid calling the default PreTranslateMessage which filtered by 
00106 ::IsDialogMessage, dispatch it directly to the controls.
00107 
00108 Tihamer
00109 
00110 */
00111 
00112 BOOL CGMEPartBrowser::PreTranslateMessage(MSG* pMsg)
00113 {
00114         if (pMsg->message == WM_KEYDOWN) {
00115                 switch (pMsg->wParam) {
00116                         case VK_RETURN:
00117                         case VK_ESCAPE:
00118                         case VK_DELETE:
00119                         // Modification by Volgyesi (undo problems)
00120                         case VK_CONTROL:
00121                         case 'z':
00122                         case 'Z':
00123                         // Modification End
00124                                 ::TranslateMessage(pMsg);
00125                                 ::DispatchMessage(pMsg);
00126                                 return TRUE;
00127                 }
00128         }
00129 
00130         return CDockablePane::PreTranslateMessage(pMsg);
00131 }
00132 
00133 
00134 void CGMEPartBrowser::SetProject(CComPtr<IMgaProject>& mgaProject)
00135 {
00136         m_PartBrowserWrapper.SetCurrentProject(mgaProject);
00137 }
00138 
00139 
00140 void CGMEPartBrowser::SetMetaModel(CGuiMetaModel* meta)
00141 {
00142         CComPtr<IUnknown> pMeta = NULL;
00143         guiMetaModel = meta;
00144         if (meta != NULL) {
00145                 CComQIPtr<IMgaMetaModel> iMeta;
00146                 iMeta = meta->mgaMeta;
00147                 if (iMeta)
00148                         pMeta = iMeta;
00149         }
00150         m_PartBrowserWrapper.SetMetaModel(pMeta);
00151 }
00152 
00153 
00154 void CGMEPartBrowser::SetBgColor(COLORREF bgColor)
00155 {
00156         m_PartBrowserWrapper.SetBgColor((OLE_COLOR)bgColor);
00157 }
00158 
00159 
00160 void CGMEPartBrowser::ChangeAspect(int ind)
00161 {
00162         m_PartBrowserWrapper.ChangeAspect(ind);
00163 }
00164 
00165 
00166 void CGMEPartBrowser::CycleAspect()
00167 {
00168         m_PartBrowserWrapper.CycleAspect();
00169 }
00170 
00171 
00172 void CGMEPartBrowser::RePaint(void)
00173 {
00174         m_PartBrowserWrapper.RePaint();
00175         CDockablePane::PostMessage(WM_PAINT); // @@@ Tihamer: SHOULD NOT BE INVALIDATE HERE?
00176 }
00177 
00178 
00179 void CGMEPartBrowser::OnAspectChangedGmePartBrowserCtrl(LONG index)
00180 {
00181         if (CGMEDoc::theInstance && guiMetaModel) {
00182                 CGuiMetaAspect* am = guiMetaModel->FindAspect(index);
00183                 VERIFY(am);
00184                 CString aspName = am->name;
00185                 CGMEDoc::theInstance->ChangeAspects(index, aspName);
00186         }
00187 }