core/vgui/impl/mfc/vgui_mfc_mainfrm.cxx
Go to the documentation of this file.
00001 // This is core/vgui/impl/mfc/vgui_mfc_mainfrm.cxx
00002 #include "StdAfx.h"
00003 #include "vgui_mfc_mainfrm.h"
00004 //:
00005 //  \file
00006 //
00007 // See vgui_mfc_mainfrm.h for a description of this file.
00008 //
00009 
00010 #include "vgui_mfc.h"
00011 #include "vgui_mfc_utils.h"
00012 #include "vgui_mfc_adaptor.h"
00013 #include "vgui_mfc_statusbar.h"
00014 
00015 #ifdef _DEBUG
00016 #define new DEBUG_NEW
00017 #undef THIS_FILE
00018 static char THIS_FILE[] = __FILE__;
00019 #endif
00020 
00021 /////////////////////////////////////////////////////////////////////////////
00022 // vgui_mfc_mainfrm
00023 
00024 IMPLEMENT_DYNCREATE(vgui_mfc_mainfrm, CFrameWnd)
00025 
00026 BEGIN_MESSAGE_MAP(vgui_mfc_mainfrm, CFrameWnd)
00027   ON_WM_CREATE()
00028   ON_WM_HSCROLL() // - We are processing both horizontal scroll bar
00029   ON_WM_VSCROLL() // and vertical scroll bar events
00030   ON_WM_TIMER()   //
00031   ON_WM_CLOSE()   // added manually by awf
00032   ON_COMMAND_RANGE(ID_MENU_ITEMS,ID_MENU_ITEMS+MAX_ITEM_COUNT,process_menus)
00033   ON_UPDATE_COMMAND_UI(ID_SEPARATOR,OnUpdateStatusBar)
00034 END_MESSAGE_MAP()
00035 
00036 /////////////////////////////////////////////////////////////////////////////
00037 // vgui_mfc_mainfrm construction/destruction
00038 
00039 vgui_mfc_mainfrm::vgui_mfc_mainfrm()
00040 {
00041         // TODO: add member initialization code here
00042         // Set the scroll range
00043 }
00044 
00045 vgui_mfc_mainfrm::~vgui_mfc_mainfrm()
00046 {
00047 }
00048 
00049 //: Called by MFC before window creation.
00050 //  Store any desired info in cs.
00051 //  Returns non-zero value to indicate creation should continue.
00052 BOOL vgui_mfc_mainfrm::PreCreateWindow(CREATESTRUCT& cs)
00053 {
00054         if ( !CFrameWnd::PreCreateWindow(cs) )
00055                 return FALSE;
00056         // TODO: Modify the Window class or styles here by modifying
00057         //  the CREATESTRUCT cs
00058 
00059         return TRUE;
00060 }
00061 
00062 //: Called by MFC on window creation
00063 int vgui_mfc_mainfrm::OnCreate(LPCREATESTRUCT lpCreateStruct)
00064 {
00065   if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
00066     return -1;
00067   return 0;
00068 }
00069 
00070 void vgui_mfc_mainfrm::OnClose()
00071 {
00072   // hmmm.  don't know if it's bad not to do this,
00073   // but I don't like the segv. -awf 0201
00074   //CFrameWnd::OnClose();
00075 
00076   DestroyWindow();
00077   DestroyAcceleratorTable(vgui_mfc_utils::instance()->AccelTable);
00078   PostQuitMessage(0);
00079 }
00080 
00081 //: Called by MFC before a message is sent to the menus.
00082 //  We are overriding this function so we can use our own menu
00083 //  accelerators defined AccelTable.
00084 //  FIXME - kym, this doesn't seem to work!!!
00085 BOOL vgui_mfc_mainfrm::PreTranslateMessage(MSG* pmsg)
00086 {
00087   if (pmsg->message >= WM_KEYFIRST && pmsg->message <= WM_KEYLAST)
00088   {
00089     // m_hWnd is the handle of this Windows window attached to this CWnd:
00090     TranslateAccelerator(m_hWnd, vgui_mfc_utils::instance()->AccelTable, (LPMSG)pmsg);
00091   }
00092   return CFrameWnd::PreTranslateMessage(pmsg);
00093 }
00094 
00095 //: Called whenever a menu item has been selected
00096 void vgui_mfc_mainfrm::process_menus(UINT nID)
00097 {
00098   vgui_mfc_utils::instance()->menu_dispatcher(nID);
00099 }
00100 
00101 //: Called when ON_WM_HSCROLL message is received
00102 void vgui_mfc_mainfrm::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar )
00103 {
00104   // --- For the time being this routine only deals with this windows' scroll
00105   // bar and not to any controls within the window
00106   CWinApp *app = AfxGetApp();
00107   POSITION pos = app->GetFirstDocTemplatePosition();
00108   CDocTemplate *tmpl = app->GetNextDocTemplate(pos);
00109   pos = tmpl->GetFirstDocPosition();
00110   CDocument *pdoc = tmpl->GetNextDoc(pos);
00111   pos = pdoc->GetFirstViewPosition();
00112   vgui_mfc_adaptor *adaptor = (vgui_mfc_adaptor *)pdoc->GetNextView(pos);
00113   ASSERT(pScrollBar == NULL);
00114   vgui_event e(vgui_HSCROLL);
00115 
00116   switch (nSBCode)
00117   {
00118    case SB_THUMBTRACK:
00119    case SB_THUMBPOSITION:
00120     SetScrollPos(SB_HORZ,nPos);
00121     e.data = &nPos;
00122     adaptor->dispatch_to_tableau(e);
00123     adaptor->service_redraws();
00124     break;
00125    case SB_LINELEFT:
00126     SetScrollPos(SB_HORZ,GetScrollPos(SB_HORZ)-1);
00127     nPos = GetScrollPos(SB_HORZ);
00128     e.data = &nPos;
00129     adaptor->dispatch_to_tableau(e);
00130     adaptor->service_redraws();
00131     break;
00132    case SB_LINERIGHT:
00133     SetScrollPos(SB_HORZ,GetScrollPos(SB_HORZ)+1);
00134     nPos = GetScrollPos(SB_HORZ);
00135     e.data = &nPos;
00136     adaptor->dispatch_to_tableau(e);
00137     adaptor->service_redraws();
00138     break;
00139   }
00140 }
00141 
00142 //: Called when ON_WM_VSCROLL message is received
00143 void vgui_mfc_mainfrm::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar )
00144 {
00145   // For the time being this routine only deals with this windows' scroll
00146   // bar and not to any controls within the window
00147   CWinApp *app = AfxGetApp();
00148   POSITION pos = app->GetFirstDocTemplatePosition();
00149   CDocTemplate *tmpl = app->GetNextDocTemplate(pos);
00150   pos = tmpl->GetFirstDocPosition();
00151   CDocument *pdoc = tmpl->GetNextDoc(pos);
00152   pos = pdoc->GetFirstViewPosition();
00153   vgui_mfc_adaptor *adaptor = (vgui_mfc_adaptor *)pdoc->GetNextView(pos);
00154 
00155   ASSERT(pScrollBar == NULL);
00156   vgui_event e(vgui_VSCROLL);
00157   switch (nSBCode)
00158   {
00159    case SB_THUMBTRACK:
00160    case SB_THUMBPOSITION:
00161     SetScrollPos(SB_VERT,nPos);
00162     e.data = &nPos;
00163     adaptor->dispatch_to_tableau(e);
00164     adaptor->service_redraws();
00165     break;
00166    case SB_LINEUP:
00167     SetScrollPos(SB_VERT,GetScrollPos(SB_VERT)-1);
00168     nPos = GetScrollPos(SB_VERT);
00169     e.data = &nPos;
00170     adaptor->dispatch_to_tableau(e);
00171     adaptor->service_redraws();
00172     break;
00173    case SB_LINEDOWN:
00174     SetScrollPos(SB_VERT,GetScrollPos(SB_VERT)+1);
00175     nPos = GetScrollPos(SB_VERT);
00176     e.data = &nPos;
00177     adaptor->dispatch_to_tableau(e);
00178     adaptor->service_redraws();
00179     break;
00180   }
00181 }
00182 
00183 void vgui_mfc_mainfrm::OnUpdateStatusBar(CCmdUI *sbar)
00184 {
00185   sbar->Enable();
00186   sbar->SetText(statusbar->linebuffer.c_str());
00187 }
00188 
00189 void vgui_mfc_mainfrm::OnTimer(UINT_PTR id)
00190 {
00191   vgui_event e(vgui_TIMER);
00192   e.timer_id = id;
00193   vgui_adaptor::current->dispatch_to_tableau(e);
00194 }
00195 
00196 #ifdef _DEBUG
00197 void vgui_mfc_mainfrm::AssertValid() const
00198 {
00199         CFrameWnd::AssertValid();
00200 }
00201 
00202 void vgui_mfc_mainfrm::Dump(CDumpContext& dc) const
00203 {
00204         CFrameWnd::Dump(dc);
00205 }
00206 
00207 #endif //_DEBUG