From 465af4c4d4f403909208a420c21dbf7cf9cc015d Mon Sep 17 00:00:00 2001 From: Ben Wiederhake Date: Sun, 31 Oct 2021 23:38:04 +0100 Subject: [PATCH] Applications: Fix visibility of Object-derivative constructors Derivatives of Core::Object should be constructed through ClassName::construct(), to avoid handling ref-counted objects with refcount zero. Fixing the visibility means that misuses like this are more difficult. --- Userland/Applets/Network/main.cpp | 3 +- Userland/Applets/ResourceGraph/main.cpp | 2 +- Userland/Applications/Assistant/main.cpp | 40 +++++++++---------- .../Applications/KeyboardMapper/KeyButton.h | 4 +- .../KeyboardMapper/KeyboardMapperWidget.h | 5 ++- .../Applications/PDFViewer/NumericInput.h | 2 +- Userland/Applications/Piano/AudioPlayerLoop.h | 6 +-- .../Applications/PixelPaint/PaletteWidget.cpp | 17 ++++---- Userland/Applications/SoundPlayer/Common.h | 3 +- .../SoundPlayer/PlaylistWidget.cpp | 2 + .../Applications/SoundPlayer/PlaylistWidget.h | 7 +++- .../SoundPlayerWidgetAdvancedView.h | 4 +- .../SoundPlayer/VisualizationWidget.h | 1 + 13 files changed, 53 insertions(+), 43 deletions(-) diff --git a/Userland/Applets/Network/main.cpp b/Userland/Applets/Network/main.cpp index dbb44cd856..fd06555704 100644 --- a/Userland/Applets/Network/main.cpp +++ b/Userland/Applets/Network/main.cpp @@ -20,7 +20,7 @@ class NetworkWidget final : public GUI::ImageWidget { C_OBJECT(NetworkWidget); -public: +private: NetworkWidget(bool notifications) { m_notifications = notifications; @@ -28,7 +28,6 @@ public: start_timer(5000); } -private: virtual void timer_event(Core::TimerEvent&) override { update_widget(); diff --git a/Userland/Applets/ResourceGraph/main.cpp b/Userland/Applets/ResourceGraph/main.cpp index 60287ad0a4..69300ccff4 100644 --- a/Userland/Applets/ResourceGraph/main.cpp +++ b/Userland/Applets/ResourceGraph/main.cpp @@ -30,6 +30,7 @@ class GraphWidget final : public GUI::Frame { public: static constexpr size_t history_size = 24; +private: GraphWidget(GraphType graph_type, Optional graph_color, Optional graph_error_color) : m_graph_type(graph_type) { @@ -39,7 +40,6 @@ public: start_timer(1000); } -private: virtual void timer_event(Core::TimerEvent&) override { switch (m_graph_type) { diff --git a/Userland/Applications/Assistant/main.cpp b/Userland/Applications/Assistant/main.cpp index 426d8913ac..522e65a444 100644 --- a/Userland/Applications/Assistant/main.cpp +++ b/Userland/Applications/Assistant/main.cpp @@ -35,26 +35,6 @@ struct AppState { class ResultRow final : public GUI::Widget { C_OBJECT(ResultRow) public: - ResultRow() - { - auto& layout = set_layout(); - layout.set_spacing(12); - layout.set_margins(4); - - m_image = add(); - - m_label_container = add(); - m_label_container->set_layout(); - m_label_container->set_fixed_height(30); - - m_title = m_label_container->add(); - m_title->set_text_alignment(Gfx::TextAlignment::CenterLeft); - - set_shrink_to_fit(true); - set_fill_with_background_color(true); - set_greedy_for_hits(true); - } - void set_image(RefPtr bitmap) { m_image->set_bitmap(bitmap); @@ -89,6 +69,26 @@ public: Function on_selected; private: + ResultRow() + { + auto& layout = set_layout(); + layout.set_spacing(12); + layout.set_margins(4); + + m_image = add(); + + m_label_container = add(); + m_label_container->set_layout(); + m_label_container->set_fixed_height(30); + + m_title = m_label_container->add(); + m_title->set_text_alignment(Gfx::TextAlignment::CenterLeft); + + set_shrink_to_fit(true); + set_fill_with_background_color(true); + set_greedy_for_hits(true); + } + void mousedown_event(GUI::MouseEvent&) override { set_background_role(ColorRole::MenuBase); diff --git a/Userland/Applications/KeyboardMapper/KeyButton.h b/Userland/Applications/KeyboardMapper/KeyButton.h index 6aed8d059a..38afde394a 100644 --- a/Userland/Applications/KeyboardMapper/KeyButton.h +++ b/Userland/Applications/KeyboardMapper/KeyButton.h @@ -8,7 +8,7 @@ #include -class KeyButton : public GUI::AbstractButton { +class KeyButton final : public GUI::AbstractButton { C_OBJECT(KeyButton) public: @@ -25,5 +25,7 @@ protected: virtual void paint_event(GUI::PaintEvent&) override; private: + KeyButton() = default; + bool m_pressed { false }; }; diff --git a/Userland/Applications/KeyboardMapper/KeyboardMapperWidget.h b/Userland/Applications/KeyboardMapper/KeyboardMapperWidget.h index 1c11dc17ca..84534be567 100644 --- a/Userland/Applications/KeyboardMapper/KeyboardMapperWidget.h +++ b/Userland/Applications/KeyboardMapper/KeyboardMapperWidget.h @@ -10,11 +10,10 @@ #include #include -class KeyboardMapperWidget : public GUI::Widget { +class KeyboardMapperWidget final : public GUI::Widget { C_OBJECT(KeyboardMapperWidget) public: - KeyboardMapperWidget(); virtual ~KeyboardMapperWidget() override; void create_frame(); @@ -31,6 +30,8 @@ protected: void update_window_title(); private: + KeyboardMapperWidget(); + Vector m_keys; RefPtr m_map_group; diff --git a/Userland/Applications/PDFViewer/NumericInput.h b/Userland/Applications/PDFViewer/NumericInput.h index 8f256bd62f..2e9a53540d 100644 --- a/Userland/Applications/PDFViewer/NumericInput.h +++ b/Userland/Applications/PDFViewer/NumericInput.h @@ -12,7 +12,6 @@ class NumericInput final : public GUI::TextBox { C_OBJECT(NumericInput) public: - NumericInput(); virtual ~NumericInput() override = default; Function on_number_changed; @@ -22,6 +21,7 @@ public: void set_current_number(i32 number, bool call_change_handler = true); private: + NumericInput(); void on_focus_lost(); bool m_needs_text_reset { false }; diff --git a/Userland/Applications/Piano/AudioPlayerLoop.h b/Userland/Applications/Piano/AudioPlayerLoop.h index 0125215298..186b833190 100644 --- a/Userland/Applications/Piano/AudioPlayerLoop.h +++ b/Userland/Applications/Piano/AudioPlayerLoop.h @@ -17,17 +17,17 @@ class TrackManager; // Wrapper class accepting custom events to advance the track playing and forward audio data to the system. // This does not run on a separate thread, preventing IPC multithreading madness. -class AudioPlayerLoop : public Core::Object { +class AudioPlayerLoop final : public Core::Object { C_OBJECT(AudioPlayerLoop) public: - AudioPlayerLoop(TrackManager& track_manager, bool& need_to_write_wav, Audio::WavWriter& wav_writer); - void enqueue_audio(); void toggle_paused(); bool is_playing() { return m_should_play_audio; } private: + AudioPlayerLoop(TrackManager& track_manager, bool& need_to_write_wav, Audio::WavWriter& wav_writer); + TrackManager& m_track_manager; Array m_buffer; Optional> m_resampler; diff --git a/Userland/Applications/PixelPaint/PaletteWidget.cpp b/Userland/Applications/PixelPaint/PaletteWidget.cpp index b6affd8ed8..bae64b426c 100644 --- a/Userland/Applications/PixelPaint/PaletteWidget.cpp +++ b/Userland/Applications/PixelPaint/PaletteWidget.cpp @@ -24,13 +24,6 @@ class ColorWidget : public GUI::Frame { C_OBJECT(ColorWidget); public: - explicit ColorWidget(Color color, PaletteWidget& palette_widget) - : m_palette_widget(palette_widget) - , m_color(color) - { - set_fixed_width(16); - } - virtual ~ColorWidget() override { } @@ -57,6 +50,13 @@ public: } private: + explicit ColorWidget(Color color, PaletteWidget& palette_widget) + : m_palette_widget(palette_widget) + , m_color(color) + { + set_fixed_width(16); + } + PaletteWidget& m_palette_widget; Color m_color; }; @@ -87,6 +87,9 @@ public: Function on_color_change; Color m_color = Color::White; + +private: + SelectedColorWidget() = default; }; PaletteWidget::PaletteWidget() diff --git a/Userland/Applications/SoundPlayer/Common.h b/Userland/Applications/SoundPlayer/Common.h index 901a7d17bb..75f8aed2e5 100644 --- a/Userland/Applications/SoundPlayer/Common.h +++ b/Userland/Applications/SoundPlayer/Common.h @@ -21,7 +21,7 @@ public: bool mouse_is_down() const { return m_mouse_is_down; } -protected: +private: AutoSlider(Orientation orientation) : GUI::Slider(orientation) { @@ -42,6 +42,5 @@ protected: GUI::Slider::mouseup_event(event); } -private: bool m_mouse_is_down { false }; }; diff --git a/Userland/Applications/SoundPlayer/PlaylistWidget.cpp b/Userland/Applications/SoundPlayer/PlaylistWidget.cpp index 189ab67d32..f954c93489 100644 --- a/Userland/Applications/SoundPlayer/PlaylistWidget.cpp +++ b/Userland/Applications/SoundPlayer/PlaylistWidget.cpp @@ -92,6 +92,8 @@ String PlaylistModel::column_name(int column) const VERIFY_NOT_REACHED(); } +PlaylistTableView::PlaylistTableView() = default; + void PlaylistTableView::doubleclick_event(GUI::MouseEvent& event) { AbstractView::doubleclick_event(event); diff --git a/Userland/Applications/SoundPlayer/PlaylistWidget.h b/Userland/Applications/SoundPlayer/PlaylistWidget.h index 5b19b6e79a..d4c10360ad 100644 --- a/Userland/Applications/SoundPlayer/PlaylistWidget.h +++ b/Userland/Applications/SoundPlayer/PlaylistWidget.h @@ -40,19 +40,22 @@ public: void doubleclick_event(GUI::MouseEvent& event) override; Function&)> on_doubleclick; + +private: + PlaylistTableView(); }; class PlaylistWidget : public GUI::Widget { C_OBJECT(PlaylistWidget) public: - PlaylistWidget(); void set_data_model(RefPtr model) { m_table_view->set_model(model); m_table_view->update(); } -protected: private: + PlaylistWidget(); + RefPtr m_table_view; }; diff --git a/Userland/Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.h b/Userland/Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.h index f63ad7658c..e8198f7eca 100644 --- a/Userland/Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.h +++ b/Userland/Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.h @@ -21,8 +21,6 @@ class SoundPlayerWidgetAdvancedView final : public GUI::Widget C_OBJECT(SoundPlayerWidgetAdvancedView) public: - explicit SoundPlayerWidgetAdvancedView(GUI::Window&, Audio::ClientConnection&); - void set_nonlinear_volume_slider(bool nonlinear); void set_playlist_visible(bool visible); @@ -51,6 +49,8 @@ protected: void keydown_event(GUI::KeyEvent&) override; private: + SoundPlayerWidgetAdvancedView(GUI::Window&, Audio::ClientConnection&); + void sync_previous_next_buttons(); void drop_event(GUI::DropEvent& event) override; diff --git a/Userland/Applications/SoundPlayer/VisualizationWidget.h b/Userland/Applications/SoundPlayer/VisualizationWidget.h index 99a64ae711..03db2e6e46 100644 --- a/Userland/Applications/SoundPlayer/VisualizationWidget.h +++ b/Userland/Applications/SoundPlayer/VisualizationWidget.h @@ -17,5 +17,6 @@ public: virtual void set_samplerate(int) { } protected: + VisualizationWidget() = default; virtual ~VisualizationWidget() = default; };