OSDN Git Service

crystaledit/Sample: Fix clicking the "View Margins" or "Wrap Lines" menu items does...
authorTakashi Sawanaka <sdottaka@users.sourceforge.net>
Sun, 17 May 2020 09:13:46 +0000 (18:13 +0900)
committerTakashi Sawanaka <sdottaka@users.sourceforge.net>
Sun, 17 May 2020 09:13:46 +0000 (18:13 +0900)
Externals/crystaledit/Sample/SampleDoc.h
Externals/crystaledit/Sample/SampleView.cpp
Externals/crystaledit/Sample/SampleView.h

index b41be4f..2b2a1f4 100755 (executable)
@@ -49,6 +49,12 @@ public:
        virtual void AssertValid() const;
        virtual void Dump(CDumpContext& dc) const;
 #endif
+       template <class Func>
+       void ForEachView(Func func)
+       {
+               for (POSITION pos = GetFirstViewPosition(); pos != nullptr; )
+                       func(static_cast<CSampleView*>(GetNextView(pos)));
+       }
 
 protected:
 
index 2a0c4f4..cb9dd89 100755 (executable)
@@ -6,6 +6,7 @@
 
 #include "SampleDoc.h"
 #include "SampleView.h"
+#include "editcmd.h"
 
 #ifdef _DEBUG
 #define new DEBUG_NEW
@@ -26,6 +27,8 @@ BEGIN_MESSAGE_MAP(CSampleView, CCrystalEditView)
        ON_COMMAND(ID_FILE_PRINT, CCrystalEditView::OnFilePrint)
        ON_COMMAND(ID_FILE_PRINT_DIRECT, CCrystalEditView::OnFilePrint)
        ON_COMMAND(ID_FILE_PRINT_PREVIEW, CCrystalEditView::OnFilePrintPreview)
+       ON_COMMAND(ID_VIEW_SELMARGIN, OnSelMargin)
+       ON_COMMAND(ID_VIEW_WORDWRAP, OnWordWrap)
 END_MESSAGE_MAP()
 
 /////////////////////////////////////////////////////////////////////////////
@@ -86,10 +89,23 @@ void CSampleView::OnInitialUpdate()
        SetFont(GetDocument()->m_lf);
        SetColorContext(GetDocument()->m_pSyntaxColors);
        SetMarkersContext(GetDocument()->m_pMarkers);
-       SetWordWrapping(true);
 }
 
 void CSampleView::OnContextMenu(CWnd* pWnd, CPoint point) 
 {
        AfxMessageBox(_T("Build your own context menu!"));
 }
+
+void CSampleView::OnSelMargin()
+{
+       GetDocument()->ForEachView([](CSampleView* pView) {
+               pView->SetSelectionMargin(!pView->GetSelectionMargin());
+       });
+}
+
+void CSampleView::OnWordWrap()
+{
+       GetDocument()->ForEachView([](CSampleView* pView) {
+               pView->SetWordWrapping(!pView->GetWordWrapping());
+       });
+}
index 0caee80..bed9356 100755 (executable)
@@ -54,6 +54,8 @@ protected:
 protected:
        //{{AFX_MSG(CSampleView)
        afx_msg void OnContextMenu(CWnd* pWnd, CPoint point);
+       afx_msg void OnSelMargin();
+       afx_msg void OnWordWrap();
        //}}AFX_MSG
        DECLARE_MESSAGE_MAP()
 };