Ember
Loading...
Searching...
No Matches
Panel.h
Go to the documentation of this file.
1#pragma once
2
14
15#include "Components/IPanel.h"
16#include <memory>
17#include <wx/panel.h>
18#include <wx/sizer.h>
19
28class Panel : public wxPanel, public IPanel {
29 public:
36 explicit Panel(wxWindow *parent, const wxString &name = "Panel", long style = wxTAB_TRAVERSAL);
37
41 virtual ~Panel();
42
43 // IPanel interface implementation
44 wxPanel *GetPanel() override { return this; }
45 wxString GetTitle() const override { return title_; }
46 wxString GetPanelType() const override { return panel_type_; }
47
48 void Initialize() override;
49 void Refresh() override;
50 void OnActivated() override;
51 void OnDeactivated() override;
52 void Cleanup() override;
53
54 bool IsValid() const override { return is_initialized_; }
55
56 wxString SerializeState() const override;
57 void DeserializeState(const wxString &state) override;
58
59 bool HasUnsavedChanges() const override { return has_unsaved_changes_; }
60 bool Save() override;
61
62 bool SupportsOperation(const wxString &operation) const override;
63 bool ExecuteOperation(const wxString &operation, const wxString &parameter = "") override;
64
65 // Additional Panel-specific methods
66 wxString GetName() const override { return name_; }
67 void SetName(const wxString &name) override;
68
69 void SetTitle(const wxString &title) { title_ = title; }
70 void SetPanelType(const wxString &type) { panel_type_ = type; }
71
72 protected:
77 virtual void CreateLayout();
78
83 virtual void ApplyTheme();
84
89 virtual void UpdateContent();
90
95 virtual void HandleActivation();
96
101 virtual void HandleDeactivation();
102
107 virtual bool ValidateState() const;
108
113
117 void MarkSaved() { has_unsaved_changes_ = false; }
118
122 wxSizer *GetMainSizer() const { return main_sizer_; }
123
127 void SetMainSizer(wxSizer *sizer);
128
129 // Event handlers
130 virtual void OnPanelSize(wxSizeEvent &event);
131 virtual void OnPanelPaint(wxPaintEvent &event);
132 virtual void OnPanelRightClick(wxContextMenuEvent &event);
133
134 private:
135 // Core components
136 wxSizer *main_sizer_;
137
138 // Panel properties
139 wxString name_;
140 wxString title_;
141 wxString panel_type_;
145
146 // Theme and appearance
150
151 // Helper methods (non-virtual, safe for use in ctor/dtor)
152 void InitializePanel();
153 void SetupEventHandlers();
154 void UpdateAppearance();
155 void DoCleanup();
156 void DoApplyTheme();
157
158 // Prevent copy
159 Panel(const Panel &) = delete;
160 Panel &operator=(const Panel &) = delete;
161
162 DECLARE_EVENT_TABLE()
163};
Abstract interface for all panels in the Ember application.
Definition IPanel.h:13
void OnActivated() override
Called when the panel becomes visible/active.
Definition Panel.cpp:54
wxSizer * main_sizer_
Definition Panel.h:136
bool SupportsOperation(const wxString &operation) const override
Check if this panel supports the given operation.
Definition Panel.cpp:115
virtual void HandleActivation()
Handle panel activation Called when panel becomes active.
Definition Panel.cpp:158
virtual void HandleDeactivation()
Handle panel deactivation Called when panel becomes inactive.
Definition Panel.cpp:162
void Initialize() override
Initialize the panel after construction Called once after the panel is created and configured.
Definition Panel.cpp:33
void SetPanelType(const wxString &type)
Definition Panel.h:70
virtual void OnPanelSize(wxSizeEvent &event)
Definition Panel.cpp:173
void Refresh() override
Called when the panel should refresh its display This should update the panel's content to reflect cu...
Definition Panel.cpp:45
wxString title_
Definition Panel.h:140
bool Save() override
Save the panel's data (if applicable)
Definition Panel.cpp:106
bool HasUnsavedChanges() const override
Check if this panel has unsaved changes.
Definition Panel.h:59
wxPanel * GetPanel() override
Get the main panel widget.
Definition Panel.h:44
virtual void ApplyTheme()
Apply current theme to the panel Called when theme changes.
Definition Panel.cpp:143
void DoApplyTheme()
Definition Panel.cpp:147
bool is_active_
Definition Panel.h:143
void SetupEventHandlers()
Definition Panel.cpp:196
wxColour background_color_
Definition Panel.h:147
wxColour foreground_color_
Definition Panel.h:148
virtual void OnPanelRightClick(wxContextMenuEvent &event)
Definition Panel.cpp:186
void DeserializeState(const wxString &state) override
Restore the panel's state from serialized data.
Definition Panel.cpp:100
wxString GetTitle() const override
Get the display title for this panel.
Definition Panel.h:45
virtual ~Panel()
Destructor.
Definition Panel.cpp:23
wxString panel_type_
Definition Panel.h:141
virtual bool ValidateState() const
Validate panel state Override to provide custom validation logic.
Definition Panel.cpp:166
void SetTitle(const wxString &title)
Definition Panel.h:69
wxFont panel_font_
Definition Panel.h:149
void Cleanup() override
Called when the panel is about to be destroyed Use this for cleanup operations.
Definition Panel.cpp:72
virtual void UpdateContent()
Update panel content Called during refresh.
Definition Panel.cpp:154
wxString SerializeState() const override
Serialize the panel's current state to a string.
Definition Panel.cpp:91
void SetMainSizer(wxSizer *sizer)
Set the main sizer (takes ownership)
Definition Panel.cpp:168
Panel(wxWindow *parent, const wxString &name="Panel", long style=wxTAB_TRAVERSAL)
Constructor.
void UpdateAppearance()
Definition Panel.cpp:200
void OnDeactivated() override
Called when the panel becomes hidden/inactive.
Definition Panel.cpp:63
bool has_unsaved_changes_
Definition Panel.h:144
void InitializePanel()
Definition Panel.cpp:191
bool is_initialized_
Definition Panel.h:142
wxString GetName() const override
Definition Panel.h:66
void SetName(const wxString &name) override
Definition Panel.cpp:28
wxString name_
Definition Panel.h:139
virtual void OnPanelPaint(wxPaintEvent &event)
Definition Panel.cpp:180
void MarkChanged()
Mark panel as having unsaved changes.
Definition Panel.h:112
wxString GetPanelType() const override
Get a unique identifier for this panel type.
Definition Panel.h:46
bool ExecuteOperation(const wxString &operation, const wxString &parameter="") override
Execute a named operation on this panel.
Definition Panel.cpp:120
virtual void CreateLayout()
Create the panel's UI layout Called during initialization.
Definition Panel.cpp:135
bool IsValid() const override
Check if the panel is in a valid state.
Definition Panel.h:54
void MarkSaved()
Mark panel as saved (no unsaved changes)
Definition Panel.h:117
Panel(const Panel &)=delete
void DoCleanup()
Definition Panel.cpp:76
Panel & operator=(const Panel &)=delete
wxSizer * GetMainSizer() const
Get the main sizer for layout management.
Definition Panel.h:122