0023776: Redesign of MFC samples after V2d viewer removing
[occt.git] / samples / mfc / standard / Common / OCC_MainFrame.cpp
1 // OCC_MainFrame.cpp: implementation of the OCC_MainFrame class.
2 //
3 //////////////////////////////////////////////////////////////////////
4
5 #include "stdafx.h"
6
7 #include "OCC_MainFrame.h"
8
9 #include <res\OCC_Resource.h>
10
11 /////////////////////////////////////////////////////////////////////////////
12 // OCC_MainFrame
13
14 IMPLEMENT_DYNAMIC(OCC_MainFrame, CMDIFrameWnd)
15
16 BEGIN_MESSAGE_MAP(OCC_MainFrame, CMDIFrameWnd)
17         //{{AFX_MSG_MAP(OCC_MainFrame)
18                 // NOTE - the ClassWizard will add and remove mapping macros here.
19                 //    DO NOT EDIT what you see in these blocks of generated code !
20         ON_WM_CREATE()
21         //}}AFX_MSG_MAP
22         ON_COMMAND(ID_HELP_FINDER, CMDIFrameWnd::OnHelpFinder)
23 END_MESSAGE_MAP()
24
25 static UINT indicators[] =
26 {
27         ID_SEPARATOR,           // status line indicator
28         ID_INDICATOR_CAPS,
29         ID_INDICATOR_NUM,
30         ID_INDICATOR_SCRL,
31 };
32
33 /////////////////////////////////////////////////////////////////////////////
34 // OCC_MainFrame construction/destruction
35
36 OCC_MainFrame::OCC_MainFrame(BOOL withAISToolBar /*=false*/)
37 {
38   m_withAISToolBar=withAISToolBar;
39   if(withAISToolBar){
40     m_AISToolBar = new CToolBar;
41   }
42   else
43     m_AISToolBar = NULL;
44 }
45
46 OCC_MainFrame::~OCC_MainFrame()
47 {
48   if (m_AISToolBar) delete m_AISToolBar;
49 }
50
51 int OCC_MainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
52 {
53   if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
54     return -1;
55
56   if (!m_wndToolBar.Create(this) ||
57     !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
58   {
59     TRACE0("Failed to create toolbar\n");
60     return -1;      // fail to create
61   }
62
63   if (m_withAISToolBar){
64     if (!m_AISToolBar->Create(this) ||
65       !m_AISToolBar->LoadToolBar(IDR_TB_AIS))
66     {
67       TRACE0("Failed to create toolbar\n");
68       return -1;      // fail to create
69     }
70   }
71
72   if (!m_wndStatusBar.Create(this) ||
73     !m_wndStatusBar.SetIndicators(indicators,
74     sizeof(indicators)/sizeof(UINT)))
75   {
76     TRACE0("Failed to create status bar\n");
77     return -1;      // fail to create
78   }
79
80   // TODO: Remove this if you don't want tool tips or a resizeable toolbar
81   m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() |
82     CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
83
84   // TODO: Delete these three lines if you don't want the toolbar to
85   //  be dockable
86   m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
87   EnableDocking(CBRS_ALIGN_ANY);
88   DockControlBar(&m_wndToolBar,AFX_IDW_DOCKBAR_TOP);
89   if (m_withAISToolBar){
90     m_AISToolBar->SetBarStyle(m_AISToolBar->GetBarStyle() |
91       CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
92     m_AISToolBar->EnableDocking(CBRS_ALIGN_ANY);
93     DockControlBarLeftOf(m_AISToolBar,&m_wndToolBar);
94   }
95   return 0;
96 }
97
98 /////////////////////////////////////////////////////////////////////////////
99 // OCC_MainFrame diagnostics
100
101 #ifdef _DEBUG
102 void OCC_MainFrame::AssertValid() const
103 {
104   CMDIFrameWnd::AssertValid();
105 }
106
107 void OCC_MainFrame::Dump(CDumpContext& dc) const
108 {
109   CMDIFrameWnd::Dump(dc);
110 }
111
112 #endif //_DEBUG
113
114 void OCC_MainFrame::SetStatusMessage(const CString & message)
115 {
116   m_wndStatusBar.SetWindowText(message);
117 }
118
119
120 BOOL OCC_MainFrame::PreCreateWindow(CREATESTRUCT& cs)
121 {
122   // TODO: Modify the Window class or styles here by modifying
123   //  the CREATESTRUCT cs
124   return CMDIFrameWnd::PreCreateWindow(cs);
125 }
126
127 void OCC_MainFrame::DockControlBarLeftOf(CToolBar* Bar,CToolBar* LeftOf)
128 {
129   CRect rect;
130   DWORD dw;
131   UINT n;
132
133   // get MFC to adjust the dimensions of all docked ToolBars
134   // so that GetWindowRect will be accurate
135   RecalcLayout();
136   LeftOf->GetWindowRect(&rect);
137   rect.OffsetRect(1,0);
138   dw=LeftOf->GetBarStyle();
139   n = 0;
140   n = (dw&CBRS_ALIGN_TOP) ? AFX_IDW_DOCKBAR_TOP : n;
141   n = (dw&CBRS_ALIGN_BOTTOM && n==0) ? AFX_IDW_DOCKBAR_BOTTOM : n;
142   n = (dw&CBRS_ALIGN_LEFT && n==0) ? AFX_IDW_DOCKBAR_LEFT : n;
143   n = (dw&CBRS_ALIGN_RIGHT && n==0) ? AFX_IDW_DOCKBAR_RIGHT : n;
144
145   // When we take the default parameters on rect, DockControlBar will dock
146   // each Toolbar on a seperate line.  By calculating a rectangle, we in effect
147   // are simulating a Toolbar being dragged to that location and docked.
148   DockControlBar(Bar,n,&rect);
149 }