1 /*
2  Copyright (C) 2010-2014 Kristian Duske
3 
4  This file is part of TrenchBroom.
5 
6  TrenchBroom is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  TrenchBroom is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with TrenchBroom. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef TrenchBroom_LayerListView
21 #define TrenchBroom_LayerListView
22 
23 #include "Model/ModelTypes.h"
24 #include "View/ViewTypes.h"
25 
26 #include <wx/panel.h>
27 
28 #include <vector>
29 
30 class wxScrolledWindow;
31 
32 namespace TrenchBroom {
33     namespace View {
34         class LayerCommand;
35     }
36 }
37 
38 typedef void (wxEvtHandler::*LayerCommandFunction)(TrenchBroom::View::LayerCommand &);
39 
40 wxDECLARE_EVENT(LAYER_SELECTED_EVENT, TrenchBroom::View::LayerCommand);
41 #define LayerSelectedHandler(func) wxEVENT_HANDLER_CAST(LayerCommandFunction, func)
42 
43 wxDECLARE_EVENT(LAYER_SET_CURRENT_EVENT, TrenchBroom::View::LayerCommand);
44 #define LayerSetCurrentHandler(func) wxEVENT_HANDLER_CAST(LayerCommandFunction, func)
45 
46 wxDECLARE_EVENT(LAYER_RIGHT_CLICK_EVENT, TrenchBroom::View::LayerCommand);
47 #define LayerRightClickHandler(func) wxEVENT_HANDLER_CAST(LayerCommandFunction, func)
48 
49 wxDECLARE_EVENT(LAYER_TOGGLE_VISIBLE_EVENT, TrenchBroom::View::LayerCommand);
50 #define LayerToggleVisibleHandler(func) wxEVENT_HANDLER_CAST(LayerCommandFunction, func)
51 
52 wxDECLARE_EVENT(LAYER_TOGGLE_LOCKED_EVENT, TrenchBroom::View::LayerCommand);
53 #define LayerToggleLockedHandler(func) wxEVENT_HANDLER_CAST(LayerCommandFunction, func)
54 
55 namespace TrenchBroom {
56     namespace View {
57         class LayerCommand : public wxCommandEvent {
58         protected:
59             Model::Layer* m_layer;
60         public:
61             LayerCommand(wxEventType commandType, int id = 0);
62 
63             Model::Layer* layer() const;
64             void setLayer(Model::Layer* layer);
65 
66             virtual wxEvent* Clone() const;
67         };
68 
69         class LayerListView : public wxPanel {
70         private:
71             class LayerEntry;
72 
73             typedef std::vector<LayerEntry*> LayerEntryList;
74 
75             MapDocumentWPtr m_document;
76 
77             wxScrolledWindow* m_scrollWindow;
78             LayerEntryList m_entries;
79 
80             int m_selection;
81         public:
82             LayerListView(wxWindow* parent, MapDocumentWPtr document);
83             ~LayerListView();
84 
85             Model::Layer* selectedLayer() const;
86             void setSelectedLayer(Model::Layer* layer);
87 
88             void OnMouseEntryDown(wxMouseEvent& event);
89             void OnMouseEntryDClick(wxMouseEvent& event);
90             void OnMouseEntryRightUp(wxMouseEvent& event);
91             void OnMouseVoidDown(wxMouseEvent& event);
92         private:
93             void bindObservers();
94             void unbindObservers();
95 
96             void documentDidChange(MapDocument* document);
97             void nodesDidChange(const Model::NodeList& nodes);
98             void currentLayerDidChange();
99 
100             void createGui();
101 
102             void reload();
103             void refresh();
104         };
105     }
106 }
107 
108 #endif /* defined(TrenchBroom_LayerListView) */
109