OSDN Git Service

An attempt to reduce build time
[winmerge-jp/winmerge-jp.git] / Src / EditorFilepathBar.h
1 /////////////////////////////////////////////////////////////////////////////
2 //    WinMerge:  an interactive diff/merge utility
3 //    Copyright (C) 1997  Dean P. Grimm
4 //    SPDX-License-Identifier: GPL-2.0-or-later
5 /////////////////////////////////////////////////////////////////////////////
6 /** 
7  * @file  EditorFilePathBar.h
8  *
9  * @brief Interface of the CEditorFilePathBar class.
10  *
11  */
12 #pragma once
13
14 #include "FilepathEdit.h"
15 #include <functional>
16
17 /**
18  * Interface to update the header data.
19  */
20 class IHeaderBar
21 {
22 public:
23         virtual String GetText(int pane) const = 0;
24         virtual void SetText(int pane, const String& sString) = 0;
25         virtual void SetActive(int pane, bool bActive) = 0;
26         virtual void SetPaneCount(int nPanes) = 0;
27         virtual void Resize() = 0;
28         virtual void SetOnSetFocusCallback(const std::function<void(int)> callbackfunc) = 0;
29         virtual void SetOnCaptionChangedCallback(const std::function<void(int, const String& sText)> callbackfunc) = 0;
30         virtual void SetOnFileSelectedCallback(const std::function<void(int, const String& sFilepath)> callbackfunc) = 0;
31         virtual void SetOnFolderSelectedCallback(const std::function<void(int, const String& sFolderpath)> callbackfunc) = 0;
32 };
33
34
35 /**
36  * @brief A dialog bar with two controls for left/right path.
37  * This class is a dialog bar for the both files path in the editor. 
38  * The bar looks like a statusBar (font, height). The control
39  * displays a tip for each path (as a tooltip). 
40  */
41 class CEditorFilePathBar : public CDialogBar, public IHeaderBar
42 {
43 public : 
44         CEditorFilePathBar();
45         ~CEditorFilePathBar();
46
47         BOOL Create( CWnd* pParentWnd);
48         virtual CSize CalcFixedLayout(BOOL bStretch, BOOL bHorz);
49
50 // Dialog Data
51         enum { IDD = IDD_EDITOR_HEADERBAR };
52         
53         void Resize() override;
54         void Resize(int widths[]);
55         void SetOnSetFocusCallback(const std::function<void(int)> callbackfunc) override;
56         void SetOnCaptionChangedCallback(const std::function<void(int, const String& sText)> callbackfunc) override;
57         void SetOnFileSelectedCallback(const std::function<void(int, const String& sFilepath)> callbackfunc) override;
58         void SetOnFolderSelectedCallback(const std::function<void(int, const String& sFolderpath)> callbackfunc) override;
59
60         // Implement IFilepathHeaders
61         void SetText(int pane, const String& sString) override;
62         String GetText(int pane) const override;
63         void SetActive(int pane, bool bActive) override;
64         void SetPaneCount(int nPanes) override;
65
66 protected:
67         //{{AFX_MSG(CEditorFilePathBar)
68         afx_msg BOOL OnToolTipNotify( UINT id, NMHDR * pTTTStruct, LRESULT * pResult );
69         afx_msg void OnSetFocusEdit(UINT id);
70         afx_msg void OnChangeEdit(UINT id);
71         afx_msg void OnSelectEdit(UINT id);
72         //}}AFX_MSG
73         DECLARE_MESSAGE_MAP();
74
75 private:
76         // this dialog uses custom edit boxes
77         CFilepathEdit m_Edit[3]; /**< Edit controls. */
78         CFont m_font; /**< Font for editcontrols */
79         int m_nPanes;
80         std::function<void(int)> m_setFocusCallbackfunc;
81         std::function<void(int, const String& sText)> m_captionChangedCallbackfunc;
82         std::function<void(int, const String& sFilepath)> m_fileSelectedCallbackfunc;
83         std::function<void(int, const String& sFolderpath)> m_folderSelectedCallbackfunc;
84 };
85
86 inline void CEditorFilePathBar::SetPaneCount(int nPanes)
87 {
88         m_nPanes = nPanes;
89 }
90
91 /** 
92  * @brief Set callback function on EN_SETFOCUS notification
93  */
94 inline void CEditorFilePathBar::SetOnSetFocusCallback(const std::function<void(int)> callbackfunc)
95 {
96         m_setFocusCallbackfunc = callbackfunc;
97 }
98
99 inline void CEditorFilePathBar::SetOnCaptionChangedCallback(const std::function<void(int, const String& sText)> callbackfunc)
100 {
101         m_captionChangedCallbackfunc = callbackfunc;
102 }
103
104 inline void CEditorFilePathBar::SetOnFileSelectedCallback(const std::function<void(int, const String& sFilepath)> callbackfunc)
105 {
106         m_fileSelectedCallbackfunc = callbackfunc;
107         for (int pane = 0; pane < m_nPanes; ++pane)
108                 m_Edit[pane].EnableFileSelection(true);
109 }
110
111 inline void CEditorFilePathBar::SetOnFolderSelectedCallback(const std::function<void(int, const String& sFolderpath)> callbackfunc)
112 {
113         m_folderSelectedCallbackfunc = callbackfunc;
114         for (int pane = 0; pane < m_nPanes; ++pane)
115                 m_Edit[pane].EnableFolderSelection(true);
116 }
117