5#include "Stroika/Foundation/StroikaPreComp.h"
12#include "LedLineItView.h"
15#include "LedLineItMainFrame.h"
19using namespace Stroika::Frameworks::Led;
21inline LedLineItView* GetActiveLedItView ()
23 CMDIFrameWnd* mainFrame =
dynamic_cast<CMDIFrameWnd*
> (::AfxGetMainWnd ());
24 if (mainFrame != NULL) {
25 CMDIChildWnd* childFrame = mainFrame->MDIGetActive ();
26 if (childFrame != NULL) {
27 return dynamic_cast<LedLineItView*
> (childFrame->GetActiveView ());
38using StatusBar = LedLineItMainFrame::StatusBar;
39using GotoEdit = StatusBar::GotoEdit;
40BEGIN_MESSAGE_MAP (GotoEdit, CEdit)
45UINT GotoEdit::OnGetDlgCode ()
47 return CEdit::OnGetDlgCode () | DLGC_WANTALLKEYS;
50void GotoEdit::OnKeyDown (UINT nChar, UINT nRepCnt, UINT nFlags)
52 if (nChar == VK_TAB or nChar == VK_RETURN) {
53 LedLineItView* v = GetActiveLedItView ();
59 CEdit::OnKeyDown (nChar, nRepCnt, nFlags);
68const int kMagicGotoWidgetID = 9991;
69using StatusBar = LedLineItMainFrame::StatusBar;
70BEGIN_MESSAGE_MAP (StatusBar, CStatusBar)
71ON_EN_CHANGE (kMagicGotoWidgetID, OnMagicEdited)
72ON_EN_KILLFOCUS (kMagicGotoWidgetID, OnMagicLoseFocus)
75void StatusBar::OnLButtonDown (UINT nFlags, CPoint oPoint)
79 if (r.PtInRect (oPoint)) {
80 TrackInGotoLineField ();
83 inherited::OnLButtonDown (nFlags, oPoint);
87void StatusBar::TrackInGotoLineField ()
92 r.right = max (r.right, r.left + 50);
93 if (fGotoEdit.m_hWnd == 0) {
94 Verify (fGotoEdit.Create (WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_CHILD | WS_VISIBLE | ES_NUMBER | ES_AUTOHSCROLL | ES_RIGHT, r,
95 this, kMagicGotoWidgetID));
97 fGotoEdit.SetFont (GetFont ());
98 fGotoEdit.SetWindowText (GetPaneText (1));
99 fGotoEdit.SetSel (0, -1);
100 fGotoEdit.SetFocus ();
103void StatusBar::OnMagicEdited ()
105 DISABLE_COMPILER_MSC_WARNING_START (4996)
107 fGotoEdit.GetWindowText (wt);
109 if (::_stscanf (wt, _T ("%d"), &lines) == 1) {
110 LedLineItView* v = GetActiveLedItView ();
112 v->SetCurUserLine (lines);
118 DISABLE_COMPILER_MSC_WARNING_END (4996)
121void StatusBar::OnMagicLoseFocus ()
123 Verify (fGotoEdit.DestroyWindow ());
131IMPLEMENT_DYNCREATE (LedLineItMainFrame, CMDIFrameWnd)
132BEGIN_MESSAGE_MAP (LedLineItMainFrame, LedLineItMainFrame::inherited)
134ON_WM_INITMENUPOPUP ()
135ON_COMMAND (ID_HELP_FINDER, OnHelpFinder)
136ON_COMMAND (ID_HELP, OnHelp)
137ON_COMMAND (ID_CONTEXT_HELP, OnContextHelp)
138ON_COMMAND (ID_DEFAULT_HELP, OnHelpFinder)
139ON_UPDATE_COMMAND_UI (ID_LINENUMBER, OnUpdateLineIndicator)
140ON_COMMAND (kCloseWindowCmdID, OnCloseWindowCommand)
141ON_COMMAND (kCloseAllWindowsCmdID, OnCloseAllWindowsCommand)
144bool LedLineItMainFrame::GetStatusBarShown ()
const
146 return !!fStatusBar.IsWindowVisible ();
149void LedLineItMainFrame::SetStatusBarShown (
bool shown)
151 fStatusBar.ShowWindow (shown ? SW_SHOWNORMAL : SW_HIDE);
154void LedLineItMainFrame::TrackInGotoLineField ()
156 Require (GetStatusBarShown ());
157 fStatusBar.TrackInGotoLineField ();
160int LedLineItMainFrame::OnCreate (LPCREATESTRUCT lpCreateStruct)
164 if (inherited::OnCreate (lpCreateStruct) == -1) {
168 Led_Size desiredSize =
169 Led_Size (Led_CvtScreenPixelsFromTWIPSV (TWIPS (1440 * 11)), Led_CvtScreenPixelsFromTWIPSH (TWIPS (
static_cast<long> (1440 * 8.5))));
170 Led_Rect newBounds = Led_Rect (lpCreateStruct->y, lpCreateStruct->x, desiredSize.v, desiredSize.h);
171 newBounds = EnsureRectOnScreen (newBounds);
172 MoveWindow (CRect (AsRECT (newBounds)));
174 CMenu* menuBar = GetMenu ();
176#if qSupportSyntaxColoring
177 FixupFontMenu (menuBar->GetSubMenu (2)->GetSubMenu (7));
179 FixupFontMenu (menuBar->GetSubMenu (2)->GetSubMenu (6));
182 if (!fToolBar.Create (
this) || !fToolBar.LoadToolBar (IDR_MAINFRAME)) {
183 TRACE0 (
"Failed to create toolbar\n");
187 static UINT indicators[] = {
191 if (!fStatusBar.Create (
this) || !fStatusBar.SetIndicators (indicators, sizeof (indicators) /
sizeof (UINT))) {
192 TRACE0 (
"Failed to create status bar\n");
197 fToolBar.SetBarStyle (fToolBar.GetBarStyle () | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
201 fToolBar.EnableDocking (CBRS_ALIGN_ANY);
202 EnableDocking (CBRS_ALIGN_ANY);
203 DockControlBar (&fToolBar);
208void LedLineItMainFrame::OnUpdateLineIndicator (CCmdUI* pCmdUI)
214 LedLineItView* v = GetActiveLedItView ();
217 Characters::CString::Copy (buf, Memory::NEltsOf (buf), _T (
"N/A"));
220 Characters::CString::Copy (buf, Memory::NEltsOf (buf),
221 Characters::Format (
"{}"_f,
static_cast<int> (v->GetCurUserLine ())).AsSDKString ().c_str ());
224 pCmdUI->SetText (buf);
228 HFONT hFont = (HFONT)fStatusBar.SendMessage (WM_GETFONT);
229 CClientDC dcScreen (NULL);
230 HGDIOBJ oldFont = NULL;
232 oldFont = dcScreen.SelectObject (hFont);
237 fStatusBar.GetPaneInfo (1, nID, nStyle, cxWidth);
238 cxWidth = max (dcScreen.GetTextExtent (buf).cx, 20l);
239 fStatusBar.SetPaneInfo (1, nID, nStyle, cxWidth);
240 if (oldFont != NULL) {
241 (void)dcScreen.SelectObject (oldFont);
245static bool IsPopupInOwningMenu (HMENU popup, HMENU potentialOwner)
248 if (potentialOwner != NULL) {
249 int nIndexMax = ::GetMenuItemCount (potentialOwner);
250 for (
int nIndex = 0; nIndex < nIndexMax; ++nIndex) {
251 HMENU itsSubMenu = ::GetSubMenu (potentialOwner, nIndex);
252 if (itsSubMenu == popup) {
255 else if (itsSubMenu != NULL) {
257 if (IsPopupInOwningMenu (popup, itsSubMenu)) {
265void LedLineItMainFrame::OnInitMenuPopup (CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu)
268 inherited::OnInitMenuPopup (pPopupMenu, nIndex, bSysMenu);
273 if (bSysMenu or IsPopupInOwningMenu (pPopupMenu->m_hMenu, ::GetMenu (m_hWnd))) {
280 state.m_pSubMenu = NULL;
281 state.m_pMenu = pPopupMenu;
282 Assert (state.m_pOther == NULL);
283 Assert (state.m_pParentMenu == NULL);
285 state.m_nIndexMax = pPopupMenu->GetMenuItemCount ();
289 bool prevItemSep =
true;
290 for (state.m_nIndex = 0; state.m_nIndex < state.m_nIndexMax;) {
291 state.m_nID = pPopupMenu->GetMenuItemID (state.m_nIndex);
292 if (state.m_nID == 0 and prevItemSep) {
293 pPopupMenu->RemoveMenu (state.m_nIndex, MF_BYPOSITION);
297 if (state.m_nID != 0) {
299 memset (&mInfo, 0,
sizeof (mInfo));
300 mInfo.cbSize =
sizeof (mInfo);
301 mInfo.fMask = MIIM_STATE;
302 Verify (::GetMenuItemInfo (pPopupMenu->GetSafeHmenu (), state.m_nIndex,
true, &mInfo));
303 if (mInfo.fState & MFS_DISABLED) {
304 pPopupMenu->RemoveMenu (state.m_nIndex, MF_BYPOSITION);
309 prevItemSep = bool (state.m_nID == 0);
314 pPopupMenu->RemoveMenu (state.m_nIndexMax - 1, MF_BYPOSITION);
319void LedLineItMainFrame::OnCloseWindowCommand ()
321 CMDIChildWnd* childFrame = MDIGetActive ();
322 if (childFrame != NULL) {
323 childFrame->SendMessage (WM_SYSCOMMAND, SC_CLOSE);
327void LedLineItMainFrame::OnCloseAllWindowsCommand ()
329 CMDIChildWnd* childFrame = NULL;
330 while ((childFrame = MDIGetActive ()) != NULL) {
331 CDocument* pDocument = childFrame->GetActiveDocument ();
332 if (pDocument != NULL) {
333 if (pDocument->SaveModified ()) {
334 pDocument->OnCloseDocument ();
341 childFrame->SendMessage (WM_SYSCOMMAND, SC_CLOSE);
#define RequireNotNull(p)
Create a format-string (see std::wformat_string or Stroika FormatString, or python 'f' strings.