5#include "Stroika/Foundation/StroikaPreComp.h"
10#include "LedItResources.h"
14#if qStroika_Foundation_Common_Platform_Windows
15#include "LedItApplication.h"
18#include "LedItMainFrame.h"
21using namespace Stroika::Frameworks::Led;
22using namespace Stroika::Frameworks::Led::Platform;
23using namespace Stroika::Frameworks::Led::StyledTextIO;
25inline LedItView* GetActiveLedItView ()
29 CMDIFrameWnd* mainFrame =
dynamic_cast<CMDIFrameWnd*
> (::AfxGetMainWnd ());
30 if (mainFrame != NULL) {
31 CMDIChildWnd* childFrame = mainFrame->MDIGetActive ();
32 if (childFrame != NULL) {
33 return dynamic_cast<LedItView*
> (childFrame->GetActiveView ());
38 CFrameWnd* mainFrame =
dynamic_cast<CFrameWnd*
> (::AfxGetMainWnd ());
39 if (mainFrame != NULL) {
40 return dynamic_cast<LedItView*
> (mainFrame->GetActiveView ());
51IMPLEMENT_DYNCREATE (LedItMainFrame, CFrameWnd)
53BEGIN_MESSAGE_MAP (LedItMainFrame, CFrameWnd)
57ON_COMMAND (ID_HELP_FINDER, OnHelpFinder)
58ON_COMMAND (ID_HELP, OnHelp)
59ON_COMMAND (ID_CONTEXT_HELP, OnContextHelp)
60ON_COMMAND (ID_DEFAULT_HELP, OnHelpFinder)
61ON_COMMAND (ID_CHAR_COLOR, OnCharColor)
62ON_COMMAND_EX (ID_VIEW_FORMATBAR, OnBarCheck)
63ON_UPDATE_COMMAND_UI (ID_VIEW_FORMATBAR, OnUpdateControlBarMenu)
64ON_COMMAND_EX (ID_VIEW_RULER, OnBarCheck)
65ON_UPDATE_COMMAND_UI (ID_VIEW_RULER, OnUpdateControlBarMenu)
68LedItMainFrame::LedItMainFrame ()
74 fFormatBar =
new FormatToolbar (*
this);
77LedItMainFrame::~LedItMainFrame ()
82int LedItMainFrame::OnCreate (LPCREATESTRUCT lpCreateStruct)
84 if (inherited::OnCreate (lpCreateStruct) == -1) {
88 Led_Size desiredSize = Led_Size (Led_CvtScreenPixelsFromTWIPSV (TWIPS (1440 * 11)),
90 Led_CvtScreenPixelsFromTWIPSH (TWIPS (
static_cast<long> (1440 * 7.5))));
91 Led_Rect newBounds = Led_Rect (lpCreateStruct->y, lpCreateStruct->x, desiredSize.v, desiredSize.h);
92 newBounds = EnsureRectOnScreen (newBounds);
93 MoveWindow (CRect (AsRECT (newBounds)));
95 CMenu* menuBar = GetMenu ();
96 LedItApplication::Get ().FixupFontMenu (menuBar->GetSubMenu (4)->GetSubMenu (0));
98 if (!fToolBar.Create (
this) || !fToolBar.LoadToolBar (IDR_MAINFRAME)) {
99 TRACE0 (
"Failed to create toolbar\n");
104 if (!fFormatBar->Create (
this, WS_CHILD | WS_VISIBLE | CBRS_TOP, ID_VIEW_FORMATBAR)) {
105 TRACE0 (
"Failed to create FormatBar\n");
109 const UINT indicators[] = {
115 if (!fStatusBar.Create (
this) || !fStatusBar.SetIndicators (indicators, sizeof (indicators) /
sizeof (UINT))) {
116 TRACE0 (
"Failed to create status bar\n");
121 fToolBar.SetBarStyle (fToolBar.GetBarStyle () | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
123 EnableDocking (CBRS_ALIGN_ANY);
125 if (!fRulerBar.Create (
this, WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_HIDE_INPLACE, ID_VIEW_RULER)) {
126 TRACE0 (
"Failed to create ruler\n");
132 fToolBar.EnableDocking (CBRS_ALIGN_ANY);
134 fFormatBar->EnableDocking (CBRS_ALIGN_TOP | CBRS_ALIGN_BOTTOM);
135 DockControlBar (&fToolBar);
136 DockControlBar (fFormatBar);
137 SetDockState (Options{}.GetDocBarState ());
144void LedItMainFrame::OnClose ()
146 CDockState dockState;
147 GetDockState (dockState);
148 Options{}.SetDocBarState (dockState);
149 inherited::OnClose ();
152BOOL LedItMainFrame::PreCreateWindow (CREATESTRUCT& cs)
154 return inherited::PreCreateWindow (cs);
157IncrementalFontSpecification LedItMainFrame::GetCurFont ()
const
159 IncrementalFontSpecification ifsp;
160 LedItView* liv = GetActiveLedItView ();
162 ifsp = liv->GetCurSelFontSpec ();
167void LedItMainFrame::SetCurFont (
const IncrementalFontSpecification& fsp)
169 LedItView* liv = GetActiveLedItView ();
171 liv->InteractiveSetFont (fsp);
175void LedItMainFrame::OnCharColor ()
180 int index = fFormatBar->CommandToIndex (ID_CHAR_COLOR);
181 fFormatBar->GetItemRect (index, &rc);
182 fFormatBar->ClientToScreen (rc);
183 colorMenu.TrackPopupMenu (TPM_LEFTALIGN | TPM_LEFTBUTTON, rc.left, rc.bottom,
this);
186static bool IsPopupInOwningMenu (HMENU popup, HMENU potentialOwner)
189 if (potentialOwner != NULL) {
190 int nIndexMax = ::GetMenuItemCount (potentialOwner);
191 for (
int nIndex = 0; nIndex < nIndexMax; ++nIndex) {
192 HMENU itsSubMenu = ::GetSubMenu (potentialOwner, nIndex);
193 if (itsSubMenu == popup) {
196 else if (itsSubMenu != NULL) {
198 if (IsPopupInOwningMenu (popup, itsSubMenu)) {
206void LedItMainFrame::OnInitMenuPopup (CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu)
209 inherited::OnInitMenuPopup (pPopupMenu, nIndex, bSysMenu);
214 if (bSysMenu or IsPopupInOwningMenu (pPopupMenu->m_hMenu, ::GetMenu (m_hWnd))) {
221 state.m_pSubMenu = NULL;
222 state.m_pMenu = pPopupMenu;
223 Assert (state.m_pOther == NULL);
224 Assert (state.m_pParentMenu == NULL);
226 state.m_nIndexMax = pPopupMenu->GetMenuItemCount ();
230 bool prevItemSep =
true;
231 for (state.m_nIndex = 0; state.m_nIndex < state.m_nIndexMax;) {
232 state.m_nID = pPopupMenu->GetMenuItemID (state.m_nIndex);
233 if (state.m_nID == 0 and prevItemSep) {
234 pPopupMenu->RemoveMenu (state.m_nIndex, MF_BYPOSITION);
238 if (state.m_nID != 0) {
240 memset (&mInfo, 0,
sizeof (mInfo));
241 mInfo.cbSize =
sizeof (mInfo);
242 mInfo.fMask = MIIM_STATE;
243 Verify (::GetMenuItemInfo (pPopupMenu->GetSafeHmenu (), state.m_nIndex,
true, &mInfo));
244 if (mInfo.fState & MFS_DISABLED) {
245 pPopupMenu->RemoveMenu (state.m_nIndex, MF_BYPOSITION);
250 prevItemSep = bool (state.m_nID == 0);
255 pPopupMenu->RemoveMenu (state.m_nIndexMax - 1, MF_BYPOSITION);
261void LedItMainFrame::AssertValid ()
const
263 inherited::AssertValid ();
266void LedItMainFrame::Dump (CDumpContext& dc)
const
268 inherited::Dump (dc);
#define RequireNotNull(p)