summaryrefslogtreecommitdiff
path: root/LibGUI
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-04-03 16:50:08 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-04-03 16:52:25 +0200
commitc02c9880b61569455eeea1dacaa15d29c33021ea (patch)
tree35580c7110f28edd9ef5b41a043f38619c0f96f1 /LibGUI
parent528054d192448f93789fedc3782550b3a80bee27 (diff)
downloadserenity-c02c9880b61569455eeea1dacaa15d29c33021ea.zip
AK: Add Eternal<T> and use it in various places.
This is useful for static locals that never need to be destroyed: Thing& Thing::the() { static Eternal<Thing> the; return the; } The object will be allocated in data segment memory and will never have its destructor invoked.
Diffstat (limited to 'LibGUI')
-rw-r--r--LibGUI/GButton.cpp2
-rw-r--r--LibGUI/GClipboard.cpp14
-rw-r--r--LibGUI/GClipboard.h9
-rw-r--r--LibGUI/GDesktop.cpp7
-rw-r--r--LibGUI/GDesktop.h3
-rw-r--r--LibGUI/GFontDatabase.cpp8
-rw-r--r--LibGUI/GFontDatabase.h2
-rw-r--r--LibGUI/GScrollBar.cpp6
-rw-r--r--LibGUI/GStatusBar.cpp2
-rw-r--r--LibGUI/GTextEditor.cpp6
-rw-r--r--LibGUI/GToolBar.cpp2
11 files changed, 20 insertions, 41 deletions
diff --git a/LibGUI/GButton.cpp b/LibGUI/GButton.cpp
index 0c585ab54d..3ea605dbf9 100644
--- a/LibGUI/GButton.cpp
+++ b/LibGUI/GButton.cpp
@@ -26,7 +26,7 @@ void GButton::paint_event(GPaintEvent& event)
GPainter painter(*this);
painter.add_clip_rect(event.rect());
- StylePainter::the().paint_button(painter, rect(), m_button_style, m_being_pressed, m_hovered);
+ StylePainter::paint_button(painter, rect(), m_button_style, m_being_pressed, m_hovered);
if (!caption().is_empty() || m_icon) {
auto content_rect = rect();
diff --git a/LibGUI/GClipboard.cpp b/LibGUI/GClipboard.cpp
index 9a349a157d..39c167cdcb 100644
--- a/LibGUI/GClipboard.cpp
+++ b/LibGUI/GClipboard.cpp
@@ -3,19 +3,7 @@
#include <WindowServer/WSAPITypes.h>
#include <LibC/SharedBuffer.h>
-GClipboard& GClipboard::the()
-{
- static GClipboard* s_the;
- if (!s_the)
- s_the = new GClipboard;
- return *s_the;
-}
-
-GClipboard::GClipboard()
-{
-}
-
-String GClipboard::data() const
+String GClipboard::data()
{
WSAPI_ClientMessage request;
request.type = WSAPI_ClientMessage::Type::GetClipboardContents;
diff --git a/LibGUI/GClipboard.h b/LibGUI/GClipboard.h
index fc8cb5c95f..63b9621b71 100644
--- a/LibGUI/GClipboard.h
+++ b/LibGUI/GClipboard.h
@@ -4,11 +4,6 @@
class GClipboard {
public:
- static GClipboard& the();
-
- String data() const;
- void set_data(const String&);
-
-private:
- GClipboard();
+ static String data();
+ static void set_data(const String&);
};
diff --git a/LibGUI/GDesktop.cpp b/LibGUI/GDesktop.cpp
index e8046c4f35..faf8ed6af0 100644
--- a/LibGUI/GDesktop.cpp
+++ b/LibGUI/GDesktop.cpp
@@ -1,13 +1,12 @@
#include <LibGUI/GDesktop.h>
#include <LibGUI/GEventLoop.h>
+#include <AK/Eternal.h>
#include <string.h>
GDesktop& GDesktop::the()
{
- static GDesktop* s_the;
- if (!s_the)
- s_the = new GDesktop;
- return *s_the;
+ static Eternal<GDesktop> the;
+ return the;
}
GDesktop::GDesktop()
diff --git a/LibGUI/GDesktop.h b/LibGUI/GDesktop.h
index c8a118bed8..88341cfd7c 100644
--- a/LibGUI/GDesktop.h
+++ b/LibGUI/GDesktop.h
@@ -6,12 +6,11 @@
class GDesktop {
public:
static GDesktop& the();
+ GDesktop();
String wallpaper() const;
bool set_wallpaper(const String& path);
private:
- GDesktop();
-
Rect m_rect;
};
diff --git a/LibGUI/GFontDatabase.cpp b/LibGUI/GFontDatabase.cpp
index 63c8f7ec4d..74ace0a5fd 100644
--- a/LibGUI/GFontDatabase.cpp
+++ b/LibGUI/GFontDatabase.cpp
@@ -1,16 +1,14 @@
#include <LibGUI/GFontDatabase.h>
#include <SharedGraphics/Font.h>
+#include <AK/Eternal.h>
#include <dirent.h>
#include <stdio.h>
#include <stdlib.h>
-static GFontDatabase* s_the;
-
GFontDatabase& GFontDatabase::the()
{
- if (!s_the)
- s_the = new GFontDatabase;
- return *s_the;
+ static Eternal<GFontDatabase> the;
+ return the;
}
GFontDatabase::GFontDatabase()
diff --git a/LibGUI/GFontDatabase.h b/LibGUI/GFontDatabase.h
index 5cc37cc243..e0b8bff121 100644
--- a/LibGUI/GFontDatabase.h
+++ b/LibGUI/GFontDatabase.h
@@ -9,13 +9,13 @@ class Font;
class GFontDatabase {
public:
static GFontDatabase& the();
+ GFontDatabase();
RetainPtr<Font> get_by_name(const String&);
void for_each_font(Function<void(const String&)>);
void for_each_fixed_width_font(Function<void(const String&)>);
private:
- GFontDatabase();
~GFontDatabase();
struct Metadata {
diff --git a/LibGUI/GScrollBar.cpp b/LibGUI/GScrollBar.cpp
index 91f6e1f22c..d41dd99bdd 100644
--- a/LibGUI/GScrollBar.cpp
+++ b/LibGUI/GScrollBar.cpp
@@ -197,14 +197,14 @@ void GScrollBar::paint_event(GPaintEvent& event)
painter.fill_rect(rect(), Color::from_rgb(0xd6d2ce));
- StylePainter::the().paint_button(painter, up_button_rect(), ButtonStyle::Normal, false);
+ StylePainter::paint_button(painter, up_button_rect(), ButtonStyle::Normal, false);
painter.draw_bitmap(up_button_rect().location().translated(3, 3), orientation() == Orientation::Vertical ? *s_up_arrow_bitmap : *s_left_arrow_bitmap, has_scrubber() ? Color::Black : Color::MidGray);
- StylePainter::the().paint_button(painter, down_button_rect(), ButtonStyle::Normal, false);
+ StylePainter::paint_button(painter, down_button_rect(), ButtonStyle::Normal, false);
painter.draw_bitmap(down_button_rect().location().translated(3, 3), orientation() == Orientation::Vertical ? *s_down_arrow_bitmap : *s_right_arrow_bitmap, has_scrubber() ? Color::Black : Color::MidGray);
if (has_scrubber())
- StylePainter::the().paint_button(painter, scrubber_rect(), ButtonStyle::Normal, false);
+ StylePainter::paint_button(painter, scrubber_rect(), ButtonStyle::Normal, false);
}
void GScrollBar::mousedown_event(GMouseEvent& event)
diff --git a/LibGUI/GStatusBar.cpp b/LibGUI/GStatusBar.cpp
index 565c7e8f8b..ccf8ffc0bb 100644
--- a/LibGUI/GStatusBar.cpp
+++ b/LibGUI/GStatusBar.cpp
@@ -37,5 +37,5 @@ void GStatusBar::paint_event(GPaintEvent& event)
{
GPainter painter(*this);
painter.add_clip_rect(event.rect());
- StylePainter::the().paint_surface(painter, rect(), !spans_entire_window_horizontally());
+ StylePainter::paint_surface(painter, rect(), !spans_entire_window_horizontally());
}
diff --git a/LibGUI/GTextEditor.cpp b/LibGUI/GTextEditor.cpp
index f409f06a54..41ba03d4be 100644
--- a/LibGUI/GTextEditor.cpp
+++ b/LibGUI/GTextEditor.cpp
@@ -785,7 +785,7 @@ void GTextEditor::cut()
{
auto selected_text = this->selected_text();
printf("Cut: \"%s\"\n", selected_text.characters());
- GClipboard::the().set_data(selected_text);
+ GClipboard::set_data(selected_text);
delete_selection();
}
@@ -793,12 +793,12 @@ void GTextEditor::copy()
{
auto selected_text = this->selected_text();
printf("Copy: \"%s\"\n", selected_text.characters());
- GClipboard::the().set_data(selected_text);
+ GClipboard::set_data(selected_text);
}
void GTextEditor::paste()
{
- auto paste_text = GClipboard::the().data();
+ auto paste_text = GClipboard::data();
printf("Paste: \"%s\"\n", paste_text.characters());
insert_at_cursor_or_replace_selection(paste_text);
}
diff --git a/LibGUI/GToolBar.cpp b/LibGUI/GToolBar.cpp
index 9eb87574f8..14e58e9d51 100644
--- a/LibGUI/GToolBar.cpp
+++ b/LibGUI/GToolBar.cpp
@@ -79,5 +79,5 @@ void GToolBar::paint_event(GPaintEvent& event)
{
GPainter painter(*this);
painter.add_clip_rect(event.rect());
- StylePainter::the().paint_surface(painter, rect(), !spans_entire_window_horizontally());
+ StylePainter::paint_surface(painter, rect(), !spans_entire_window_horizontally());
}