mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 13:07:46 +00:00
Merge remote-tracking branch 'origin/master' into serenity-keys
This commit is contained in:
commit
b635c3db54
527 changed files with 9637 additions and 5614 deletions
|
@ -6,7 +6,7 @@ GAbstractButton::GAbstractButton(GWidget* parent)
|
|||
{
|
||||
}
|
||||
|
||||
GAbstractButton::GAbstractButton(const String& text, GWidget* parent)
|
||||
GAbstractButton::GAbstractButton(const StringView& text, GWidget* parent)
|
||||
: GWidget(parent)
|
||||
, m_text(text)
|
||||
{
|
||||
|
@ -16,7 +16,7 @@ GAbstractButton::~GAbstractButton()
|
|||
{
|
||||
}
|
||||
|
||||
void GAbstractButton::set_text(const String& text)
|
||||
void GAbstractButton::set_text(const StringView& text)
|
||||
{
|
||||
if (m_text == text)
|
||||
return;
|
||||
|
@ -29,6 +29,20 @@ void GAbstractButton::set_checked(bool checked)
|
|||
if (m_checked == checked)
|
||||
return;
|
||||
m_checked = checked;
|
||||
|
||||
if (is_exclusive() && checked) {
|
||||
parent_widget()->for_each_child_of_type<GAbstractButton>([&] (auto& sibling) {
|
||||
if (!sibling.is_exclusive() || !sibling.is_checkable() || !sibling.is_checked())
|
||||
return IterationDecision::Continue;
|
||||
sibling.m_checked = false;
|
||||
sibling.update();
|
||||
if (sibling.on_checked)
|
||||
sibling.on_checked(false);
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
m_checked = true;
|
||||
}
|
||||
|
||||
update();
|
||||
if (on_checked)
|
||||
on_checked(checked);
|
||||
|
|
|
@ -11,9 +11,12 @@ public:
|
|||
|
||||
Function<void(bool)> on_checked;
|
||||
|
||||
void set_text(const String&);
|
||||
void set_text(const StringView&);
|
||||
const String& text() const { return m_text; }
|
||||
|
||||
bool is_exclusive() const { return m_exclusive; }
|
||||
void set_exclusive(bool b) { m_exclusive = b; }
|
||||
|
||||
bool is_checked() const { return m_checked; }
|
||||
void set_checked(bool);
|
||||
|
||||
|
@ -30,7 +33,7 @@ public:
|
|||
|
||||
protected:
|
||||
explicit GAbstractButton(GWidget* parent);
|
||||
GAbstractButton(const String&, GWidget* parent);
|
||||
GAbstractButton(const StringView&, GWidget* parent);
|
||||
|
||||
virtual void mousedown_event(GMouseEvent&) override;
|
||||
virtual void mousemove_event(GMouseEvent&) override;
|
||||
|
@ -43,9 +46,20 @@ protected:
|
|||
void paint_text(GPainter&, const Rect&, const Font&, TextAlignment);
|
||||
|
||||
private:
|
||||
virtual bool is_abstract_button() const final { return true; }
|
||||
|
||||
String m_text;
|
||||
bool m_checked { false };
|
||||
bool m_checkable { false };
|
||||
bool m_hovered { false };
|
||||
bool m_being_pressed { false };
|
||||
bool m_exclusive { false };
|
||||
};
|
||||
|
||||
template<>
|
||||
inline bool is<GAbstractButton>(const CObject& object)
|
||||
{
|
||||
if (!is<GWidget>(object))
|
||||
return false;
|
||||
return to<GWidget>(object).is_abstract_button();
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
#include <Kernel/KeyCode.h>
|
||||
#include <LibGUI/GAbstractView.h>
|
||||
#include <LibGUI/GModel.h>
|
||||
#include <LibGUI/GScrollBar.h>
|
||||
#include <LibGUI/GPainter.h>
|
||||
#include <LibGUI/GScrollBar.h>
|
||||
#include <LibGUI/GTextBox.h>
|
||||
#include <Kernel/KeyCode.h>
|
||||
|
||||
GAbstractView::GAbstractView(GWidget* parent)
|
||||
: GScrollableWidget(parent)
|
||||
|
@ -84,7 +84,7 @@ void GAbstractView::begin_editing(const GModelIndex& index)
|
|||
|
||||
void GAbstractView::stop_editing()
|
||||
{
|
||||
m_edit_index = { };
|
||||
m_edit_index = {};
|
||||
delete m_edit_widget;
|
||||
m_edit_widget = nullptr;
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#include <LibGUI/GButton.h>
|
||||
#include <LibGUI/GMenuItem.h>
|
||||
|
||||
GAction::GAction(const String& text, const String& custom_data, Function<void(GAction&)> on_activation_callback, GWidget* widget)
|
||||
GAction::GAction(const StringView& text, const StringView& custom_data, Function<void(GAction&)> on_activation_callback, GWidget* widget)
|
||||
: on_activation(move(on_activation_callback))
|
||||
, m_text(text)
|
||||
, m_custom_data(custom_data)
|
||||
|
@ -11,12 +11,12 @@ GAction::GAction(const String& text, const String& custom_data, Function<void(GA
|
|||
{
|
||||
}
|
||||
|
||||
GAction::GAction(const String& text, Function<void(GAction&)> on_activation_callback, GWidget* widget)
|
||||
GAction::GAction(const StringView& text, Function<void(GAction&)> on_activation_callback, GWidget* widget)
|
||||
: GAction(text, String(), move(on_activation_callback), widget)
|
||||
{
|
||||
}
|
||||
|
||||
GAction::GAction(const String& text, RetainPtr<GraphicsBitmap>&& icon, Function<void(GAction&)> on_activation_callback, GWidget* widget)
|
||||
GAction::GAction(const StringView& text, RetainPtr<GraphicsBitmap>&& icon, Function<void(GAction&)> on_activation_callback, GWidget* widget)
|
||||
: on_activation(move(on_activation_callback))
|
||||
, m_text(text)
|
||||
, m_icon(move(icon))
|
||||
|
@ -24,13 +24,12 @@ GAction::GAction(const String& text, RetainPtr<GraphicsBitmap>&& icon, Function<
|
|||
{
|
||||
}
|
||||
|
||||
GAction::GAction(const String& text, const GShortcut& shortcut, Function<void(GAction&)> on_activation_callback, GWidget* widget)
|
||||
GAction::GAction(const StringView& text, const GShortcut& shortcut, Function<void(GAction&)> on_activation_callback, GWidget* widget)
|
||||
: GAction(text, shortcut, nullptr, move(on_activation_callback), widget)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
GAction::GAction(const String& text, const GShortcut& shortcut, RetainPtr<GraphicsBitmap>&& icon, Function<void(GAction&)> on_activation_callback, GWidget* widget)
|
||||
GAction::GAction(const StringView& text, const GShortcut& shortcut, RetainPtr<GraphicsBitmap>&& icon, Function<void(GAction&)> on_activation_callback, GWidget* widget)
|
||||
: on_activation(move(on_activation_callback))
|
||||
, m_text(text)
|
||||
, m_icon(move(icon))
|
||||
|
@ -99,10 +98,10 @@ void GAction::set_enabled(bool enabled)
|
|||
if (m_enabled == enabled)
|
||||
return;
|
||||
m_enabled = enabled;
|
||||
for_each_toolbar_button([enabled] (GButton& button) {
|
||||
for_each_toolbar_button([enabled](GButton& button) {
|
||||
button.set_enabled(enabled);
|
||||
});
|
||||
for_each_menu_item([enabled] (GMenuItem& item) {
|
||||
for_each_menu_item([enabled](GMenuItem& item) {
|
||||
item.set_enabled(enabled);
|
||||
});
|
||||
}
|
||||
|
@ -112,10 +111,10 @@ void GAction::set_checked(bool checked)
|
|||
if (m_checked == checked)
|
||||
return;
|
||||
m_checked = checked;
|
||||
for_each_toolbar_button([checked] (GButton& button) {
|
||||
for_each_toolbar_button([checked](GButton& button) {
|
||||
button.set_checked(checked);
|
||||
});
|
||||
for_each_menu_item([checked] (GMenuItem& item) {
|
||||
for_each_menu_item([checked](GMenuItem& item) {
|
||||
item.set_checked(checked);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -18,29 +18,28 @@ class GWidget;
|
|||
class GAction : public Retainable<GAction>
|
||||
, public Weakable<GAction> {
|
||||
public:
|
||||
enum class ShortcutScope
|
||||
{
|
||||
enum class ShortcutScope {
|
||||
None,
|
||||
ApplicationGlobal,
|
||||
WidgetLocal,
|
||||
};
|
||||
static Retained<GAction> create(const String& text, Function<void(GAction&)> callback, GWidget* widget = nullptr)
|
||||
static Retained<GAction> create(const StringView& text, Function<void(GAction&)> callback, GWidget* widget = nullptr)
|
||||
{
|
||||
return adopt(*new GAction(text, move(callback), widget));
|
||||
}
|
||||
static Retained<GAction> create(const String& text, const String& custom_data, Function<void(GAction&)> callback, GWidget* widget = nullptr)
|
||||
static Retained<GAction> create(const StringView& text, const StringView& custom_data, Function<void(GAction&)> callback, GWidget* widget = nullptr)
|
||||
{
|
||||
return adopt(*new GAction(text, custom_data, move(callback), widget));
|
||||
}
|
||||
static Retained<GAction> create(const String& text, RetainPtr<GraphicsBitmap>&& icon, Function<void(GAction&)> callback, GWidget* widget = nullptr)
|
||||
static Retained<GAction> create(const StringView& text, RetainPtr<GraphicsBitmap>&& icon, Function<void(GAction&)> callback, GWidget* widget = nullptr)
|
||||
{
|
||||
return adopt(*new GAction(text, move(icon), move(callback), widget));
|
||||
}
|
||||
static Retained<GAction> create(const String& text, const GShortcut& shortcut, Function<void(GAction&)> callback, GWidget* widget = nullptr)
|
||||
static Retained<GAction> create(const StringView& text, const GShortcut& shortcut, Function<void(GAction&)> callback, GWidget* widget = nullptr)
|
||||
{
|
||||
return adopt(*new GAction(text, shortcut, move(callback), widget));
|
||||
}
|
||||
static Retained<GAction> create(const String& text, const GShortcut& shortcut, RetainPtr<GraphicsBitmap>&& icon, Function<void(GAction&)> callback, GWidget* widget = nullptr)
|
||||
static Retained<GAction> create(const StringView& text, const GShortcut& shortcut, RetainPtr<GraphicsBitmap>&& icon, Function<void(GAction&)> callback, GWidget* widget = nullptr)
|
||||
{
|
||||
return adopt(*new GAction(text, shortcut, move(icon), move(callback), widget));
|
||||
}
|
||||
|
@ -77,11 +76,11 @@ public:
|
|||
void unregister_menu_item(Badge<GMenuItem>, GMenuItem&);
|
||||
|
||||
private:
|
||||
GAction(const String& text, Function<void(GAction&)> = nullptr, GWidget* = nullptr);
|
||||
GAction(const String& text, const GShortcut&, Function<void(GAction&)> = nullptr, GWidget* = nullptr);
|
||||
GAction(const String& text, const GShortcut&, RetainPtr<GraphicsBitmap>&& icon, Function<void(GAction&)> = nullptr, GWidget* = nullptr);
|
||||
GAction(const String& text, RetainPtr<GraphicsBitmap>&& icon, Function<void(GAction&)> = nullptr, GWidget* = nullptr);
|
||||
GAction(const String& text, const String& custom_data = String(), Function<void(GAction&)> = nullptr, GWidget* = nullptr);
|
||||
GAction(const StringView& text, Function<void(GAction&)> = nullptr, GWidget* = nullptr);
|
||||
GAction(const StringView& text, const GShortcut&, Function<void(GAction&)> = nullptr, GWidget* = nullptr);
|
||||
GAction(const StringView& text, const GShortcut&, RetainPtr<GraphicsBitmap>&& icon, Function<void(GAction&)> = nullptr, GWidget* = nullptr);
|
||||
GAction(const StringView& text, RetainPtr<GraphicsBitmap>&& icon, Function<void(GAction&)> = nullptr, GWidget* = nullptr);
|
||||
GAction(const StringView& text, const StringView& custom_data = StringView(), Function<void(GAction&)> = nullptr, GWidget* = nullptr);
|
||||
|
||||
template<typename Callback>
|
||||
void for_each_toolbar_button(Callback);
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
#include <LibGUI/GAction.h>
|
||||
#include <LibGUI/GApplication.h>
|
||||
#include <LibGUI/GEventLoop.h>
|
||||
#include <LibGUI/GMenuBar.h>
|
||||
#include <LibGUI/GAction.h>
|
||||
#include <LibGUI/GWindow.h>
|
||||
#include <LibGUI/GLabel.h>
|
||||
#include <LibGUI/GMenuBar.h>
|
||||
#include <LibGUI/GPainter.h>
|
||||
#include <LibGUI/GWindow.h>
|
||||
#include <WindowServer/WSAPITypes.h>
|
||||
|
||||
static GApplication* s_the;
|
||||
|
@ -84,7 +84,7 @@ public:
|
|||
set_main_widget(m_label);
|
||||
}
|
||||
|
||||
void set_tooltip(const String& tooltip)
|
||||
void set_tooltip(const StringView& tooltip)
|
||||
{
|
||||
// FIXME: Add some kind of GLabel auto-sizing feature.
|
||||
int text_width = m_label->font().width(tooltip);
|
||||
|
@ -95,7 +95,7 @@ public:
|
|||
GLabel* m_label { nullptr };
|
||||
};
|
||||
|
||||
void GApplication::show_tooltip(const String& tooltip, const Point& screen_location)
|
||||
void GApplication::show_tooltip(const StringView& tooltip, const Point& screen_location)
|
||||
{
|
||||
if (!m_tooltip_window) {
|
||||
m_tooltip_window = new TooltipWindow;
|
||||
|
|
|
@ -26,7 +26,7 @@ public:
|
|||
void register_global_shortcut_action(Badge<GAction>, GAction&);
|
||||
void unregister_global_shortcut_action(Badge<GAction>, GAction&);
|
||||
|
||||
void show_tooltip(const String&, const Point& screen_location);
|
||||
void show_tooltip(const StringView&, const Point& screen_location);
|
||||
void hide_tooltip();
|
||||
|
||||
private:
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
#include "GButton.h"
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <Kernel/KeyCode.h>
|
||||
#include <LibGUI/GAction.h>
|
||||
#include <LibGUI/GPainter.h>
|
||||
#include <SharedGraphics/StylePainter.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <LibGUI/GAction.h>
|
||||
#include <Kernel/KeyCode.h>
|
||||
|
||||
GButton::GButton(GWidget* parent)
|
||||
: GAbstractButton(parent)
|
||||
{
|
||||
}
|
||||
|
||||
GButton::GButton(const String& text, GWidget* parent)
|
||||
GButton::GButton(const StringView& text, GWidget* parent)
|
||||
: GAbstractButton(text, parent)
|
||||
{
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ GButton::GButton(const String& text, GWidget* parent)
|
|||
GButton::~GButton()
|
||||
{
|
||||
if (m_action)
|
||||
m_action->unregister_button({ }, *this);
|
||||
m_action->unregister_button({}, *this);
|
||||
}
|
||||
|
||||
void GButton::paint_event(GPaintEvent& event)
|
||||
|
@ -60,6 +60,8 @@ void GButton::click()
|
|||
{
|
||||
if (!is_enabled())
|
||||
return;
|
||||
if (is_checkable())
|
||||
set_checked(!is_checked());
|
||||
if (on_click)
|
||||
on_click(*this);
|
||||
}
|
||||
|
@ -71,7 +73,7 @@ bool GButton::accepts_keyboard_select() const {
|
|||
void GButton::set_action(GAction& action)
|
||||
{
|
||||
m_action = action.make_weak_ptr();
|
||||
action.register_button({ }, *this);
|
||||
action.register_button({}, *this);
|
||||
set_enabled(action.is_enabled());
|
||||
set_checkable(action.is_checkable());
|
||||
if (action.is_checkable())
|
||||
|
|
|
@ -11,7 +11,7 @@ class GAction;
|
|||
|
||||
class GButton : public GAbstractButton {
|
||||
public:
|
||||
GButton(const String& text, GWidget* parent);
|
||||
GButton(const StringView& text, GWidget* parent);
|
||||
explicit GButton(GWidget* parent);
|
||||
virtual ~GButton() override;
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#include <Kernel/KeyCode.h>
|
||||
#include <LibGUI/GCheckBox.h>
|
||||
#include <LibGUI/GPainter.h>
|
||||
#include <SharedGraphics/CharacterBitmap.h>
|
||||
#include <SharedGraphics/StylePainter.h>
|
||||
#include <Kernel/KeyCode.h>
|
||||
|
||||
static const char* s_checked_bitmap_data = {
|
||||
" "
|
||||
|
@ -27,7 +27,7 @@ GCheckBox::GCheckBox(GWidget* parent)
|
|||
{
|
||||
}
|
||||
|
||||
GCheckBox::GCheckBox(const String& text, GWidget* parent)
|
||||
GCheckBox::GCheckBox(const StringView& text, GWidget* parent)
|
||||
: GAbstractButton(text, parent)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
class GCheckBox : public GAbstractButton {
|
||||
public:
|
||||
GCheckBox(const String&, GWidget* parent);
|
||||
GCheckBox(const StringView&, GWidget* parent);
|
||||
explicit GCheckBox(GWidget* parent);
|
||||
virtual ~GCheckBox() override;
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include <LibC/SharedBuffer.h>
|
||||
#include <LibGUI/GClipboard.h>
|
||||
#include <LibGUI/GEventLoop.h>
|
||||
#include <WindowServer/WSAPITypes.h>
|
||||
#include <LibC/SharedBuffer.h>
|
||||
|
||||
GClipboard& GClipboard::the()
|
||||
{
|
||||
|
@ -21,20 +21,20 @@ String GClipboard::data() const
|
|||
request.type = WSAPI_ClientMessage::Type::GetClipboardContents;
|
||||
auto response = GEventLoop::current().sync_request(request, WSAPI_ServerMessage::Type::DidGetClipboardContents);
|
||||
if (response.clipboard.shared_buffer_id < 0)
|
||||
return { };
|
||||
return {};
|
||||
auto shared_buffer = SharedBuffer::create_from_shared_buffer_id(response.clipboard.shared_buffer_id);
|
||||
if (!shared_buffer) {
|
||||
dbgprintf("GClipboard::data() failed to attach to the shared buffer\n");
|
||||
return { };
|
||||
return {};
|
||||
}
|
||||
if (response.clipboard.contents_size > shared_buffer->size()) {
|
||||
dbgprintf("GClipboard::data() clipping contents size is greater than shared buffer size\n");
|
||||
return { };
|
||||
return {};
|
||||
}
|
||||
return String((const char*)shared_buffer->data(), response.clipboard.contents_size);
|
||||
}
|
||||
|
||||
void GClipboard::set_data(const String& data)
|
||||
void GClipboard::set_data(const StringView& data)
|
||||
{
|
||||
WSAPI_ClientMessage request;
|
||||
request.type = WSAPI_ClientMessage::Type::SetClipboardContents;
|
||||
|
|
|
@ -7,7 +7,7 @@ public:
|
|||
static GClipboard& the();
|
||||
|
||||
String data() const;
|
||||
void set_data(const String&);
|
||||
void set_data(const StringView&);
|
||||
|
||||
private:
|
||||
GClipboard();
|
||||
|
|
|
@ -24,7 +24,7 @@ void GDesktop::did_receive_screen_rect(Badge<GEventLoop>, const Rect& rect)
|
|||
on_rect_change(rect);
|
||||
}
|
||||
|
||||
bool GDesktop::set_wallpaper(const String& path)
|
||||
bool GDesktop::set_wallpaper(const StringView& path)
|
||||
{
|
||||
WSAPI_ClientMessage message;
|
||||
message.type = WSAPI_ClientMessage::Type::SetWallpaper;
|
||||
|
|
|
@ -13,7 +13,7 @@ public:
|
|||
GDesktop();
|
||||
|
||||
String wallpaper() const;
|
||||
bool set_wallpaper(const String& path);
|
||||
bool set_wallpaper(const StringView& path);
|
||||
|
||||
Rect rect() const { return m_rect; }
|
||||
void did_receive_screen_rect(Badge<GEventLoop>, const Rect&);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include <LibGUI/GDesktop.h>
|
||||
#include <LibGUI/GDialog.h>
|
||||
#include <LibGUI/GEventLoop.h>
|
||||
#include <LibGUI/GDesktop.h>
|
||||
|
||||
GDialog::GDialog(CObject* parent)
|
||||
: GWindow(parent)
|
||||
|
|
|
@ -5,8 +5,7 @@
|
|||
|
||||
class GDialog : public GWindow {
|
||||
public:
|
||||
enum ExecResult
|
||||
{
|
||||
enum ExecResult {
|
||||
ExecOK = 0,
|
||||
ExecCancel = 1,
|
||||
ExecAborted = 2
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
#include "GDirectoryModel.h"
|
||||
#include <dirent.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <grp.h>
|
||||
#include <pwd.h>
|
||||
#include <AK/FileSystemPath.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <SharedGraphics/GraphicsBitmap.h>
|
||||
#include <LibGUI/GPainter.h>
|
||||
#include <LibCore/CLock.h>
|
||||
#include <LibCore/CDirIterator.h>
|
||||
#include <LibCore/CLock.h>
|
||||
#include <LibGUI/GPainter.h>
|
||||
#include <SharedGraphics/GraphicsBitmap.h>
|
||||
#include <dirent.h>
|
||||
#include <grp.h>
|
||||
#include <pwd.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static CLockable<HashMap<String, RetainPtr<GraphicsBitmap>>>& thumbnail_cache()
|
||||
{
|
||||
|
@ -94,13 +94,20 @@ int GDirectoryModel::column_count(const GModelIndex&) const
|
|||
String GDirectoryModel::column_name(int column) const
|
||||
{
|
||||
switch (column) {
|
||||
case Column::Icon: return "";
|
||||
case Column::Name: return "Name";
|
||||
case Column::Size: return "Size";
|
||||
case Column::Owner: return "Owner";
|
||||
case Column::Group: return "Group";
|
||||
case Column::Permissions: return "Mode";
|
||||
case Column::Inode: return "Inode";
|
||||
case Column::Icon:
|
||||
return "";
|
||||
case Column::Name:
|
||||
return "Name";
|
||||
case Column::Size:
|
||||
return "Size";
|
||||
case Column::Owner:
|
||||
return "Owner";
|
||||
case Column::Group:
|
||||
return "Group";
|
||||
case Column::Permissions:
|
||||
return "Mode";
|
||||
case Column::Inode:
|
||||
return "Inode";
|
||||
}
|
||||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
|
@ -108,13 +115,20 @@ String GDirectoryModel::column_name(int column) const
|
|||
GModel::ColumnMetadata GDirectoryModel::column_metadata(int column) const
|
||||
{
|
||||
switch (column) {
|
||||
case Column::Icon: return { 16, TextAlignment::Center };
|
||||
case Column::Name: return { 120, TextAlignment::CenterLeft };
|
||||
case Column::Size: return { 80, TextAlignment::CenterRight };
|
||||
case Column::Owner: return { 50, TextAlignment::CenterLeft };
|
||||
case Column::Group: return { 50, TextAlignment::CenterLeft };
|
||||
case Column::Permissions: return { 80, TextAlignment::CenterLeft };
|
||||
case Column::Inode: return { 80, TextAlignment::CenterRight };
|
||||
case Column::Icon:
|
||||
return { 16, TextAlignment::Center };
|
||||
case Column::Name:
|
||||
return { 120, TextAlignment::CenterLeft };
|
||||
case Column::Size:
|
||||
return { 80, TextAlignment::CenterRight };
|
||||
case Column::Owner:
|
||||
return { 50, TextAlignment::CenterLeft };
|
||||
case Column::Group:
|
||||
return { 50, TextAlignment::CenterLeft };
|
||||
case Column::Permissions:
|
||||
return { 80, TextAlignment::CenterLeft };
|
||||
case Column::Inode:
|
||||
return { 80, TextAlignment::CenterRight };
|
||||
}
|
||||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
|
@ -175,8 +189,7 @@ static String permission_string(mode_t mode)
|
|||
mode & S_IWGRP ? 'w' : '-',
|
||||
mode & S_ISGID ? 's' : (mode & S_IXGRP ? 'x' : '-'),
|
||||
mode & S_IROTH ? 'r' : '-',
|
||||
mode & S_IWOTH ? 'w' : '-'
|
||||
);
|
||||
mode & S_IWOTH ? 'w' : '-');
|
||||
|
||||
if (mode & S_ISVTX)
|
||||
builder.append("t");
|
||||
|
@ -207,31 +220,45 @@ GVariant GDirectoryModel::data(const GModelIndex& index, Role role) const
|
|||
auto& entry = this->entry(index.row());
|
||||
if (role == Role::Sort) {
|
||||
switch (index.column()) {
|
||||
case Column::Icon: return entry.is_directory() ? 0 : 1;
|
||||
case Column::Name: return entry.name;
|
||||
case Column::Size: return (int)entry.size;
|
||||
case Column::Owner: return name_for_uid(entry.uid);
|
||||
case Column::Group: return name_for_gid(entry.gid);
|
||||
case Column::Permissions: return permission_string(entry.mode);
|
||||
case Column::Inode: return (int)entry.inode;
|
||||
case Column::Icon:
|
||||
return entry.is_directory() ? 0 : 1;
|
||||
case Column::Name:
|
||||
return entry.name;
|
||||
case Column::Size:
|
||||
return (int)entry.size;
|
||||
case Column::Owner:
|
||||
return name_for_uid(entry.uid);
|
||||
case Column::Group:
|
||||
return name_for_gid(entry.gid);
|
||||
case Column::Permissions:
|
||||
return permission_string(entry.mode);
|
||||
case Column::Inode:
|
||||
return (int)entry.inode;
|
||||
}
|
||||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
if (role == Role::Display) {
|
||||
switch (index.column()) {
|
||||
case Column::Icon: return icon_for(entry);
|
||||
case Column::Name: return entry.name;
|
||||
case Column::Size: return (int)entry.size;
|
||||
case Column::Owner: return name_for_uid(entry.uid);
|
||||
case Column::Group: return name_for_gid(entry.gid);
|
||||
case Column::Permissions: return permission_string(entry.mode);
|
||||
case Column::Inode: return (int)entry.inode;
|
||||
case Column::Icon:
|
||||
return icon_for(entry);
|
||||
case Column::Name:
|
||||
return entry.name;
|
||||
case Column::Size:
|
||||
return (int)entry.size;
|
||||
case Column::Owner:
|
||||
return name_for_uid(entry.uid);
|
||||
case Column::Group:
|
||||
return name_for_gid(entry.gid);
|
||||
case Column::Permissions:
|
||||
return permission_string(entry.mode);
|
||||
case Column::Inode:
|
||||
return (int)entry.inode;
|
||||
}
|
||||
}
|
||||
if (role == Role::Icon) {
|
||||
return icon_for(entry);
|
||||
}
|
||||
return { };
|
||||
return {};
|
||||
}
|
||||
|
||||
void GDirectoryModel::update()
|
||||
|
@ -272,7 +299,7 @@ void GDirectoryModel::update()
|
|||
did_update();
|
||||
}
|
||||
|
||||
void GDirectoryModel::open(const String& a_path)
|
||||
void GDirectoryModel::open(const StringView& a_path)
|
||||
{
|
||||
FileSystemPath canonical_path(a_path);
|
||||
auto path = canonical_path.string();
|
||||
|
|
|
@ -11,8 +11,7 @@ public:
|
|||
static Retained<GDirectoryModel> create() { return adopt(*new GDirectoryModel); }
|
||||
virtual ~GDirectoryModel() override;
|
||||
|
||||
enum Column
|
||||
{
|
||||
enum Column {
|
||||
Icon = 0,
|
||||
Name,
|
||||
Size,
|
||||
|
@ -31,7 +30,7 @@ public:
|
|||
virtual void update() override;
|
||||
|
||||
String path() const { return m_path; }
|
||||
void open(const String& path);
|
||||
void open(const StringView& path);
|
||||
size_t bytes_in_files() const { return m_bytes_in_files; }
|
||||
|
||||
Function<void(int done, int total)> on_thumbnail_progress;
|
||||
|
|
|
@ -10,8 +10,7 @@ class CObject;
|
|||
|
||||
class GEvent : public CEvent {
|
||||
public:
|
||||
enum Type
|
||||
{
|
||||
enum Type {
|
||||
Show = 1000,
|
||||
Hide,
|
||||
Paint,
|
||||
|
@ -82,7 +81,7 @@ public:
|
|||
|
||||
class GWMWindowStateChangedEvent : public GWMEvent {
|
||||
public:
|
||||
GWMWindowStateChangedEvent(int client_id, int window_id, const String& title, const Rect& rect, bool is_active, GWindowType window_type, bool is_minimized)
|
||||
GWMWindowStateChangedEvent(int client_id, int window_id, const StringView& title, const Rect& rect, bool is_active, GWindowType window_type, bool is_minimized)
|
||||
: GWMEvent(GEvent::Type::WM_WindowStateChanged, client_id, window_id)
|
||||
, m_title(title)
|
||||
, m_rect(rect)
|
||||
|
@ -122,7 +121,7 @@ private:
|
|||
|
||||
class GWMWindowIconChangedEvent : public GWMEvent {
|
||||
public:
|
||||
GWMWindowIconChangedEvent(int client_id, int window_id, const String& icon_path)
|
||||
GWMWindowIconChangedEvent(int client_id, int window_id, const StringView& icon_path)
|
||||
: GWMEvent(GEvent::Type::WM_WindowIconChanged, client_id, window_id)
|
||||
, m_icon_path(icon_path)
|
||||
{
|
||||
|
@ -218,8 +217,7 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
enum GMouseButton : byte
|
||||
{
|
||||
enum GMouseButton : byte {
|
||||
None = 0,
|
||||
Left = 1,
|
||||
Right = 2,
|
||||
|
|
|
@ -1,24 +1,23 @@
|
|||
#include <LibCore/CObject.h>
|
||||
#include "GEventLoop.h"
|
||||
#include "GEvent.h"
|
||||
#include "GWindow.h"
|
||||
#include <LibGUI/GApplication.h>
|
||||
#include <LibGUI/GAction.h>
|
||||
#include <LibCore/CNotifier.h>
|
||||
#include <LibGUI/GMenu.h>
|
||||
#include <LibGUI/GDesktop.h>
|
||||
#include <LibGUI/GWidget.h>
|
||||
#include <LibC/unistd.h>
|
||||
#include <LibC/stdio.h>
|
||||
#include <LibC/errno.h>
|
||||
#include <LibC/fcntl.h>
|
||||
#include <LibC/stdio.h>
|
||||
#include <LibC/stdlib.h>
|
||||
#include <LibC/string.h>
|
||||
#include <LibC/time.h>
|
||||
#include <LibC/sys/select.h>
|
||||
#include <LibC/sys/socket.h>
|
||||
#include <LibC/sys/time.h>
|
||||
#include <LibC/errno.h>
|
||||
#include <LibC/string.h>
|
||||
#include <LibC/stdlib.h>
|
||||
#include <LibC/time.h>
|
||||
#include <LibC/unistd.h>
|
||||
#include <LibCore/CNotifier.h>
|
||||
#include <LibCore/CObject.h>
|
||||
#include <LibGUI/GAction.h>
|
||||
#include <LibGUI/GApplication.h>
|
||||
#include <LibGUI/GDesktop.h>
|
||||
#include <LibGUI/GMenu.h>
|
||||
#include <LibGUI/GWidget.h>
|
||||
#include <sys/uio.h>
|
||||
|
||||
//#define GEVENTLOOP_DEBUG
|
||||
|
@ -156,20 +155,42 @@ void GEventLoop::handle_mouse_event(const WSAPI_ServerMessage& event, GWindow& w
|
|||
#endif
|
||||
GMouseEvent::Type type;
|
||||
switch (event.type) {
|
||||
case WSAPI_ServerMessage::Type::MouseMove: type = GEvent::MouseMove; break;
|
||||
case WSAPI_ServerMessage::Type::MouseUp: type = GEvent::MouseUp; break;
|
||||
case WSAPI_ServerMessage::Type::MouseDown: type = GEvent::MouseDown; break;
|
||||
case WSAPI_ServerMessage::Type::MouseDoubleClick: type = GEvent::MouseDoubleClick; break;
|
||||
case WSAPI_ServerMessage::Type::MouseWheel: type = GEvent::MouseWheel; break;
|
||||
default: ASSERT_NOT_REACHED(); break;
|
||||
case WSAPI_ServerMessage::Type::MouseMove:
|
||||
type = GEvent::MouseMove;
|
||||
break;
|
||||
case WSAPI_ServerMessage::Type::MouseUp:
|
||||
type = GEvent::MouseUp;
|
||||
break;
|
||||
case WSAPI_ServerMessage::Type::MouseDown:
|
||||
type = GEvent::MouseDown;
|
||||
break;
|
||||
case WSAPI_ServerMessage::Type::MouseDoubleClick:
|
||||
type = GEvent::MouseDoubleClick;
|
||||
break;
|
||||
case WSAPI_ServerMessage::Type::MouseWheel:
|
||||
type = GEvent::MouseWheel;
|
||||
break;
|
||||
default:
|
||||
ASSERT_NOT_REACHED();
|
||||
break;
|
||||
}
|
||||
GMouseButton button { GMouseButton::None };
|
||||
switch (event.mouse.button) {
|
||||
case WSAPI_MouseButton::NoButton: button = GMouseButton::None; break;
|
||||
case WSAPI_MouseButton::Left: button = GMouseButton::Left; break;
|
||||
case WSAPI_MouseButton::Right: button = GMouseButton::Right; break;
|
||||
case WSAPI_MouseButton::Middle: button = GMouseButton::Middle; break;
|
||||
default: ASSERT_NOT_REACHED(); break;
|
||||
case WSAPI_MouseButton::NoButton:
|
||||
button = GMouseButton::None;
|
||||
break;
|
||||
case WSAPI_MouseButton::Left:
|
||||
button = GMouseButton::Left;
|
||||
break;
|
||||
case WSAPI_MouseButton::Right:
|
||||
button = GMouseButton::Right;
|
||||
break;
|
||||
case WSAPI_MouseButton::Middle:
|
||||
button = GMouseButton::Middle;
|
||||
break;
|
||||
default:
|
||||
ASSERT_NOT_REACHED();
|
||||
break;
|
||||
}
|
||||
post_event(window, make<GMouseEvent>(type, event.mouse.position, event.mouse.buttons, button, event.mouse.modifiers, event.mouse.wheel_delta));
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
#include <LibGUI/GToolBar.h>
|
||||
#include <SharedGraphics/PNGLoader.h>
|
||||
|
||||
GFilePicker::GFilePicker(const String& path, CObject* parent)
|
||||
GFilePicker::GFilePicker(const StringView& path, CObject* parent)
|
||||
: GDialog(parent)
|
||||
, m_model(GDirectoryModel::create())
|
||||
{
|
||||
|
@ -57,19 +57,19 @@ GFilePicker::GFilePicker(const String& path, CObject* parent)
|
|||
clear_preview();
|
||||
};
|
||||
|
||||
auto open_parent_directory_action = GAction::create("Open parent directory", { Mod_Alt, Key_Up }, GraphicsBitmap::load_from_file("/res/icons/16x16/open-parent-directory.png"), [this] (const GAction&) {
|
||||
auto open_parent_directory_action = GAction::create("Open parent directory", { Mod_Alt, Key_Up }, GraphicsBitmap::load_from_file("/res/icons/16x16/open-parent-directory.png"), [this](const GAction&) {
|
||||
m_model->open(String::format("%s/..", m_model->path().characters()));
|
||||
clear_preview();
|
||||
});
|
||||
toolbar->add_action(*open_parent_directory_action);
|
||||
|
||||
auto mkdir_action = GAction::create("New directory...", GraphicsBitmap::load_from_file("/res/icons/16x16/mkdir.png"), [this] (const GAction&) {
|
||||
auto mkdir_action = GAction::create("New directory...", GraphicsBitmap::load_from_file("/res/icons/16x16/mkdir.png"), [this](const GAction&) {
|
||||
GInputBox input_box("Enter name:", "New directory", this);
|
||||
if (input_box.exec() == GInputBox::ExecOK && !input_box.text_value().is_empty()) {
|
||||
auto new_dir_path = FileSystemPath(String::format("%s/%s",
|
||||
m_model->path().characters(),
|
||||
input_box.text_value().characters()
|
||||
)).string();
|
||||
m_model->path().characters(),
|
||||
input_box.text_value().characters()))
|
||||
.string();
|
||||
int rc = mkdir(new_dir_path.characters(), 0777);
|
||||
if (rc < 0) {
|
||||
GMessageBox::show(String::format("mkdir(\"%s\") failed: %s", new_dir_path.characters(), strerror(errno)), "Error", GMessageBox::Type::Error, this);
|
||||
|
@ -96,7 +96,7 @@ GFilePicker::GFilePicker(const String& path, CObject* parent)
|
|||
filename_label->set_preferred_size({ 60, 0 });
|
||||
auto* filename_textbox = new GTextBox(filename_container);
|
||||
|
||||
m_view->on_activation = [this, filename_textbox] (auto& index) {
|
||||
m_view->on_activation = [this, filename_textbox](auto& index) {
|
||||
auto& filter_model = (GSortingProxyModel&)*m_view->model();
|
||||
auto local_index = filter_model.map_to_target(index);
|
||||
const GDirectoryModel::Entry& entry = m_model->entry(local_index.row());
|
||||
|
@ -125,7 +125,7 @@ GFilePicker::GFilePicker(const String& path, CObject* parent)
|
|||
cancel_button->set_size_policy(SizePolicy::Fixed, SizePolicy::Fill);
|
||||
cancel_button->set_preferred_size({ 80, 0 });
|
||||
cancel_button->set_text("Cancel");
|
||||
cancel_button->on_click = [this] (auto&) {
|
||||
cancel_button->on_click = [this](auto&) {
|
||||
done(ExecCancel);
|
||||
};
|
||||
|
||||
|
@ -133,7 +133,7 @@ GFilePicker::GFilePicker(const String& path, CObject* parent)
|
|||
ok_button->set_size_policy(SizePolicy::Fixed, SizePolicy::Fill);
|
||||
ok_button->set_preferred_size({ 80, 0 });
|
||||
ok_button->set_text("OK");
|
||||
ok_button->on_click = [this, filename_textbox] (auto&) {
|
||||
ok_button->on_click = [this, filename_textbox](auto&) {
|
||||
FileSystemPath path(String::format("%s/%s", m_model->path().characters(), filename_textbox->text().characters()));
|
||||
m_selected_file = path;
|
||||
done(ExecOK);
|
||||
|
|
|
@ -7,7 +7,7 @@ class GLabel;
|
|||
|
||||
class GFilePicker final : public GDialog {
|
||||
public:
|
||||
GFilePicker(const String& path = "/", CObject* parent = nullptr);
|
||||
GFilePicker(const StringView& path = "/", CObject* parent = nullptr);
|
||||
virtual ~GFilePicker() override;
|
||||
|
||||
FileSystemPath selected_file() const { return m_selected_file; }
|
||||
|
|
|
@ -1,17 +1,21 @@
|
|||
#include <LibGUI/GFileSystemModel.h>
|
||||
#include <LibCore/CDirIterator.h>
|
||||
#include <AK/FileSystemPath.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <sys/stat.h>
|
||||
#include <LibCore/CDirIterator.h>
|
||||
#include <LibGUI/GFileSystemModel.h>
|
||||
#include <dirent.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
struct GFileSystemModel::Node {
|
||||
String name;
|
||||
Node* parent { nullptr };
|
||||
Vector<Node*> children;
|
||||
enum Type { Unknown, Directory, File };
|
||||
enum Type {
|
||||
Unknown,
|
||||
Directory,
|
||||
File
|
||||
};
|
||||
Type type { Unknown };
|
||||
|
||||
bool has_traversed { false };
|
||||
|
@ -92,7 +96,7 @@ struct GFileSystemModel::Node {
|
|||
}
|
||||
};
|
||||
|
||||
GModelIndex GFileSystemModel::index(const String& path) const
|
||||
GModelIndex GFileSystemModel::index(const StringView& path) const
|
||||
{
|
||||
FileSystemPath canonical_path(path);
|
||||
const Node* node = m_root;
|
||||
|
@ -111,21 +115,21 @@ GModelIndex GFileSystemModel::index(const String& path) const
|
|||
}
|
||||
}
|
||||
if (!found)
|
||||
return { };
|
||||
return {};
|
||||
}
|
||||
return { };
|
||||
return {};
|
||||
}
|
||||
|
||||
String GFileSystemModel::path(const GModelIndex& index) const
|
||||
{
|
||||
if (!index.is_valid())
|
||||
return { };
|
||||
return {};
|
||||
auto& node = *(Node*)index.internal_data();
|
||||
node.reify_if_needed(*this);
|
||||
return node.full_path(*this);
|
||||
}
|
||||
|
||||
GFileSystemModel::GFileSystemModel(const String& root_path, Mode mode)
|
||||
GFileSystemModel::GFileSystemModel(const StringView& root_path, Mode mode)
|
||||
: m_root_path(FileSystemPath(root_path).string())
|
||||
, m_mode(mode)
|
||||
{
|
||||
|
@ -172,11 +176,11 @@ GModelIndex GFileSystemModel::index(int row, int column, const GModelIndex& pare
|
|||
GModelIndex GFileSystemModel::parent_index(const GModelIndex& index) const
|
||||
{
|
||||
if (!index.is_valid())
|
||||
return { };
|
||||
return {};
|
||||
auto& node = *(const Node*)index.internal_data();
|
||||
if (!node.parent) {
|
||||
ASSERT(&node == m_root);
|
||||
return { };
|
||||
return {};
|
||||
}
|
||||
return node.parent->index(*this);
|
||||
}
|
||||
|
@ -184,7 +188,7 @@ GModelIndex GFileSystemModel::parent_index(const GModelIndex& index) const
|
|||
GVariant GFileSystemModel::data(const GModelIndex& index, Role role) const
|
||||
{
|
||||
if (!index.is_valid())
|
||||
return { };
|
||||
return {};
|
||||
auto& node = *(const Node*)index.internal_data();
|
||||
if (role == GModel::Role::Display)
|
||||
return node.name;
|
||||
|
@ -196,7 +200,7 @@ GVariant GFileSystemModel::data(const GModelIndex& index, Role role) const
|
|||
}
|
||||
return m_file_icon;
|
||||
}
|
||||
return { };
|
||||
return {};
|
||||
}
|
||||
|
||||
int GFileSystemModel::column_count(const GModelIndex&) const
|
||||
|
|
|
@ -6,14 +6,13 @@ class GFileSystemModel : public GModel {
|
|||
friend class Node;
|
||||
|
||||
public:
|
||||
enum Mode
|
||||
{
|
||||
enum Mode {
|
||||
Invalid,
|
||||
DirectoriesOnly,
|
||||
FilesAndDirectories
|
||||
};
|
||||
|
||||
static Retained<GFileSystemModel> create(const String& root_path = "/", Mode mode = Mode::FilesAndDirectories)
|
||||
static Retained<GFileSystemModel> create(const StringView& root_path = "/", Mode mode = Mode::FilesAndDirectories)
|
||||
{
|
||||
return adopt(*new GFileSystemModel(root_path, mode));
|
||||
}
|
||||
|
@ -21,7 +20,7 @@ public:
|
|||
|
||||
String root_path() const { return m_root_path; }
|
||||
String path(const GModelIndex&) const;
|
||||
GModelIndex index(const String& path) const;
|
||||
GModelIndex index(const StringView& path) const;
|
||||
|
||||
virtual int row_count(const GModelIndex& = GModelIndex()) const override;
|
||||
virtual int column_count(const GModelIndex& = GModelIndex()) const override;
|
||||
|
@ -31,7 +30,7 @@ public:
|
|||
virtual GModelIndex index(int row, int column = 0, const GModelIndex& parent = GModelIndex()) const override;
|
||||
|
||||
private:
|
||||
GFileSystemModel(const String& root_path, Mode);
|
||||
GFileSystemModel(const StringView& root_path, Mode);
|
||||
|
||||
String m_root_path;
|
||||
Mode m_mode { Invalid };
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#include <LibGUI/GFontDatabase.h>
|
||||
#include <LibCore/CDirIterator.h>
|
||||
#include <LibGUI/GFontDatabase.h>
|
||||
#include <SharedGraphics/Font.h>
|
||||
#include <dirent.h>
|
||||
#include <stdio.h>
|
||||
|
@ -38,14 +38,14 @@ GFontDatabase::~GFontDatabase()
|
|||
{
|
||||
}
|
||||
|
||||
void GFontDatabase::for_each_font(Function<void(const String&)> callback)
|
||||
void GFontDatabase::for_each_font(Function<void(const StringView&)> callback)
|
||||
{
|
||||
for (auto& it : m_name_to_metadata) {
|
||||
callback(it.key);
|
||||
}
|
||||
}
|
||||
|
||||
void GFontDatabase::for_each_fixed_width_font(Function<void(const String&)> callback)
|
||||
void GFontDatabase::for_each_fixed_width_font(Function<void(const StringView&)> callback)
|
||||
{
|
||||
for (auto& it : m_name_to_metadata) {
|
||||
if (it.value.is_fixed_width)
|
||||
|
@ -53,7 +53,7 @@ void GFontDatabase::for_each_fixed_width_font(Function<void(const String&)> call
|
|||
}
|
||||
}
|
||||
|
||||
RetainPtr<Font> GFontDatabase::get_by_name(const String& name)
|
||||
RetainPtr<Font> GFontDatabase::get_by_name(const StringView& name)
|
||||
{
|
||||
auto it = m_name_to_metadata.find(name);
|
||||
if (it == m_name_to_metadata.end())
|
||||
|
|
|
@ -16,11 +16,11 @@ class GFontDatabase {
|
|||
public:
|
||||
static GFontDatabase& the();
|
||||
|
||||
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&)>);
|
||||
RetainPtr<Font> get_by_name(const StringView&);
|
||||
void for_each_font(Function<void(const StringView&)>);
|
||||
void for_each_fixed_width_font(Function<void(const StringView&)>);
|
||||
|
||||
Metadata get_metadata_by_name(const String& name) const
|
||||
Metadata get_metadata_by_name(const StringView& name) const
|
||||
{
|
||||
return m_name_to_metadata.get(name);
|
||||
};
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include <LibGUI/GFrame.h>
|
||||
#include <SharedGraphics/StylePainter.h>
|
||||
#include <LibGUI/GPainter.h>
|
||||
#include <SharedGraphics/StylePainter.h>
|
||||
|
||||
GFrame::GFrame(GWidget* parent)
|
||||
: GWidget(parent)
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#include <LibGUI/GPainter.h>
|
||||
#include <SharedGraphics/StylePainter.h>
|
||||
|
||||
GGroupBox::GGroupBox(const String& title, GWidget* parent)
|
||||
GGroupBox::GGroupBox(const StringView& title, GWidget* parent)
|
||||
: GWidget(parent)
|
||||
, m_title(title)
|
||||
{
|
||||
|
@ -30,7 +30,7 @@ void GGroupBox::paint_event(GPaintEvent& event)
|
|||
painter.draw_text(text_rect, m_title, TextAlignment::Center, foreground_color());
|
||||
}
|
||||
|
||||
void GGroupBox::set_title(const String& title)
|
||||
void GGroupBox::set_title(const StringView& title)
|
||||
{
|
||||
if (m_title == title)
|
||||
return;
|
||||
|
|
|
@ -4,11 +4,11 @@
|
|||
|
||||
class GGroupBox : public GWidget {
|
||||
public:
|
||||
GGroupBox(const String& title, GWidget* parent);
|
||||
GGroupBox(const StringView& title, GWidget* parent);
|
||||
virtual ~GGroupBox() override;
|
||||
|
||||
String title() const { return m_title; }
|
||||
void set_title(const String&);
|
||||
void set_title(const StringView&);
|
||||
|
||||
virtual const char* class_name() const override { return "GGroupBox"; }
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@ void GIconImpl::set_bitmap_for_size(int size, RetainPtr<GraphicsBitmap>&& bitmap
|
|||
m_bitmaps.set(size, move(bitmap));
|
||||
}
|
||||
|
||||
GIcon GIcon::default_icon(const String& name)
|
||||
GIcon GIcon::default_icon(const StringView& name)
|
||||
{
|
||||
auto bitmap16 = GraphicsBitmap::load_from_file(String::format("/res/icons/16x16/%s.png", name.characters()));
|
||||
auto bitmap32 = GraphicsBitmap::load_from_file(String::format("/res/icons/32x32/%s.png", name.characters()));
|
||||
|
|
|
@ -25,7 +25,7 @@ public:
|
|||
GIcon(const GIcon&);
|
||||
~GIcon() {}
|
||||
|
||||
static GIcon default_icon(const String&);
|
||||
static GIcon default_icon(const StringView&);
|
||||
|
||||
GIcon& operator=(const GIcon& other)
|
||||
{
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
#include <LibGUI/GInputBox.h>
|
||||
#include <LibGUI/GBoxLayout.h>
|
||||
#include <LibGUI/GLabel.h>
|
||||
#include <LibGUI/GButton.h>
|
||||
#include <LibGUI/GInputBox.h>
|
||||
#include <LibGUI/GLabel.h>
|
||||
#include <LibGUI/GTextEditor.h>
|
||||
#include <stdio.h>
|
||||
|
||||
GInputBox::GInputBox(const String& prompt, const String& title, CObject* parent)
|
||||
GInputBox::GInputBox(const StringView& prompt, const StringView& title, CObject* parent)
|
||||
: GDialog(parent)
|
||||
, m_prompt(prompt)
|
||||
{
|
||||
|
@ -55,7 +55,7 @@ void GInputBox::build()
|
|||
m_cancel_button->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
|
||||
m_cancel_button->set_preferred_size({ 0, 20 });
|
||||
m_cancel_button->set_text("Cancel");
|
||||
m_cancel_button->on_click = [this] (auto&) {
|
||||
m_cancel_button->on_click = [this](auto&) {
|
||||
dbgprintf("GInputBox: Cancel button clicked\n");
|
||||
done(ExecCancel);
|
||||
};
|
||||
|
@ -64,7 +64,7 @@ void GInputBox::build()
|
|||
m_ok_button->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
|
||||
m_ok_button->set_preferred_size({ 0, 20 });
|
||||
m_ok_button->set_text("OK");
|
||||
m_ok_button->on_click = [this] (auto&) {
|
||||
m_ok_button->on_click = [this](auto&) {
|
||||
dbgprintf("GInputBox: OK button clicked\n");
|
||||
m_text_value = m_text_editor->text();
|
||||
done(ExecOK);
|
||||
|
|
|
@ -7,7 +7,7 @@ class GTextEditor;
|
|||
|
||||
class GInputBox : public GDialog {
|
||||
public:
|
||||
explicit GInputBox(const String& prompt, const String& title, CObject* parent = nullptr);
|
||||
explicit GInputBox(const StringView& prompt, const StringView& title, CObject* parent = nullptr);
|
||||
virtual ~GInputBox() override;
|
||||
|
||||
String text_value() const { return m_text_value; }
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#include <Kernel/KeyCode.h>
|
||||
#include <LibGUI/GItemView.h>
|
||||
#include <LibGUI/GModel.h>
|
||||
#include <LibGUI/GScrollBar.h>
|
||||
#include <LibGUI/GPainter.h>
|
||||
#include <Kernel/KeyCode.h>
|
||||
#include <LibGUI/GScrollBar.h>
|
||||
|
||||
GItemView::GItemView(GWidget* parent)
|
||||
: GAbstractView(parent)
|
||||
|
@ -38,7 +38,7 @@ void GItemView::did_update_model()
|
|||
void GItemView::update_content_size()
|
||||
{
|
||||
if (!model())
|
||||
return set_content_size({ });
|
||||
return set_content_size({});
|
||||
|
||||
m_visual_column_count = available_size().width() / effective_item_size().width();
|
||||
if (m_visual_column_count)
|
||||
|
@ -55,7 +55,7 @@ void GItemView::update_content_size()
|
|||
Rect GItemView::item_rect(int item_index) const
|
||||
{
|
||||
if (!m_visual_row_count || !m_visual_column_count)
|
||||
return { };
|
||||
return {};
|
||||
int visual_row_index = item_index / m_visual_column_count;
|
||||
int visual_column_index = item_index % m_visual_column_count;
|
||||
return {
|
||||
|
@ -79,7 +79,7 @@ void GItemView::mousedown_event(GMouseEvent& event)
|
|||
return;
|
||||
}
|
||||
}
|
||||
model()->set_selected_index({ });
|
||||
model()->set_selected_index({});
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
@ -100,7 +100,7 @@ void GItemView::paint_event(GPaintEvent& event)
|
|||
|
||||
GPainter painter(*this);
|
||||
painter.add_clip_rect(widget_inner_rect());
|
||||
painter.add_clip_rect(event.rect());
|
||||
painter.add_clip_rect(event.rect());
|
||||
painter.fill_rect(event.rect(), Color::White);
|
||||
painter.translate(-horizontal_scrollbar().value(), -vertical_scrollbar().value());
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ GLabel::GLabel(GWidget* parent)
|
|||
{
|
||||
}
|
||||
|
||||
GLabel::GLabel(const String& text, GWidget* parent)
|
||||
GLabel::GLabel(const StringView& text, GWidget* parent)
|
||||
: GFrame(parent)
|
||||
, m_text(text)
|
||||
{
|
||||
|
@ -22,7 +22,7 @@ void GLabel::set_icon(RetainPtr<GraphicsBitmap>&& icon)
|
|||
m_icon = move(icon);
|
||||
}
|
||||
|
||||
void GLabel::set_text(const String& text)
|
||||
void GLabel::set_text(const StringView& text)
|
||||
{
|
||||
if (text == m_text)
|
||||
return;
|
||||
|
|
|
@ -8,11 +8,11 @@ class GraphicsBitmap;
|
|||
class GLabel : public GFrame {
|
||||
public:
|
||||
explicit GLabel(GWidget* parent = nullptr);
|
||||
GLabel(const String& text, GWidget* parent = nullptr);
|
||||
GLabel(const StringView& text, GWidget* parent = nullptr);
|
||||
virtual ~GLabel() override;
|
||||
|
||||
String text() const { return m_text; }
|
||||
void set_text(const String&);
|
||||
void set_text(const StringView&);
|
||||
|
||||
void set_icon(RetainPtr<GraphicsBitmap>&&);
|
||||
const GraphicsBitmap* icon() const { return m_icon.ptr(); }
|
||||
|
|
|
@ -54,7 +54,7 @@ void GLayout::add_widget(GWidget& widget)
|
|||
|
||||
void GLayout::remove_widget(GWidget& widget)
|
||||
{
|
||||
m_entries.remove_first_matching([&] (auto& entry) {
|
||||
m_entries.remove_first_matching([&](auto& entry) {
|
||||
return entry.widget == &widget;
|
||||
});
|
||||
if (m_owner)
|
||||
|
|
|
@ -32,8 +32,7 @@ public:
|
|||
|
||||
protected:
|
||||
struct Entry {
|
||||
enum class Type
|
||||
{
|
||||
enum class Type {
|
||||
Invalid = 0,
|
||||
Widget,
|
||||
Layout,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include <LibGUI/GListView.h>
|
||||
#include <LibGUI/GScrollBar.h>
|
||||
#include <LibGUI/GPainter.h>
|
||||
#include <Kernel/KeyCode.h>
|
||||
#include <LibGUI/GListView.h>
|
||||
#include <LibGUI/GPainter.h>
|
||||
#include <LibGUI/GScrollBar.h>
|
||||
|
||||
GListView::GListView(GWidget* parent)
|
||||
: GAbstractView(parent)
|
||||
|
@ -18,7 +18,7 @@ GListView::~GListView()
|
|||
void GListView::update_content_size()
|
||||
{
|
||||
if (!model())
|
||||
return set_content_size({ });
|
||||
return set_content_size({});
|
||||
|
||||
int content_width = 0;
|
||||
for (int row = 0, row_count = model()->row_count(); row < row_count; ++row) {
|
||||
|
@ -76,7 +76,7 @@ void GListView::mousedown_event(GMouseEvent& event)
|
|||
update();
|
||||
return;
|
||||
}
|
||||
model()->set_selected_index({ });
|
||||
model()->set_selected_index({});
|
||||
update();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include <LibGUI/GAction.h>
|
||||
#include <LibGUI/GMenu.h>
|
||||
#include <LibGUI/GEventLoop.h>
|
||||
#include <AK/HashMap.h>
|
||||
#include <LibGUI/GAction.h>
|
||||
#include <LibGUI/GEventLoop.h>
|
||||
#include <LibGUI/GMenu.h>
|
||||
|
||||
//#define GMENU_DEBUG
|
||||
|
||||
|
@ -21,7 +21,7 @@ GMenu* GMenu::from_menu_id(int menu_id)
|
|||
return (*it).value;
|
||||
}
|
||||
|
||||
GMenu::GMenu(const String& name)
|
||||
GMenu::GMenu(const StringView& name)
|
||||
: m_name(name)
|
||||
{
|
||||
}
|
||||
|
@ -81,8 +81,8 @@ int GMenu::realize_menu()
|
|||
ASSERT(m_menu_id > 0);
|
||||
for (int i = 0; i < m_items.size(); ++i) {
|
||||
auto& item = *m_items[i];
|
||||
item.set_menu_id({ }, m_menu_id);
|
||||
item.set_identifier({ }, i);
|
||||
item.set_menu_id({}, m_menu_id);
|
||||
item.set_identifier({}, i);
|
||||
if (item.type() == GMenuItem::Separator) {
|
||||
WSAPI_ClientMessage request;
|
||||
request.type = WSAPI_ClientMessage::Type::AddMenuSeparator;
|
||||
|
|
|
@ -11,7 +11,7 @@ class Point;
|
|||
|
||||
class GMenu {
|
||||
public:
|
||||
explicit GMenu(const String& name);
|
||||
explicit GMenu(const StringView& name);
|
||||
~GMenu();
|
||||
|
||||
static GMenu* from_menu_id(int);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#include <LibGUI/GMenuBar.h>
|
||||
#include <LibGUI/GEventLoop.h>
|
||||
#include <LibGUI/GMenuBar.h>
|
||||
|
||||
GMenuBar::GMenuBar()
|
||||
{
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include <LibGUI/GMenuItem.h>
|
||||
#include <LibGUI/GAction.h>
|
||||
#include <LibGUI/GEventLoop.h>
|
||||
#include <LibGUI/GMenuItem.h>
|
||||
#include <WindowServer/WSAPITypes.h>
|
||||
|
||||
GMenuItem::GMenuItem(unsigned menu_id, Type type)
|
||||
|
@ -14,7 +14,7 @@ GMenuItem::GMenuItem(unsigned menu_id, Retained<GAction>&& action)
|
|||
, m_menu_id(menu_id)
|
||||
, m_action(move(action))
|
||||
{
|
||||
m_action->register_menu_item({ }, *this);
|
||||
m_action->register_menu_item({}, *this);
|
||||
m_enabled = m_action->is_enabled();
|
||||
m_checkable = m_action->is_checkable();
|
||||
if (m_checkable)
|
||||
|
@ -24,7 +24,7 @@ GMenuItem::GMenuItem(unsigned menu_id, Retained<GAction>&& action)
|
|||
GMenuItem::~GMenuItem()
|
||||
{
|
||||
if (m_action)
|
||||
m_action->unregister_menu_item({ }, *this);
|
||||
m_action->unregister_menu_item({}, *this);
|
||||
}
|
||||
|
||||
void GMenuItem::set_enabled(bool enabled)
|
||||
|
|
|
@ -8,8 +8,7 @@ class GMenu;
|
|||
|
||||
class GMenuItem {
|
||||
public:
|
||||
enum Type
|
||||
{
|
||||
enum Type {
|
||||
Invalid,
|
||||
Action,
|
||||
Separator
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
#include <LibGUI/GMessageBox.h>
|
||||
#include <LibGUI/GBoxLayout.h>
|
||||
#include <LibGUI/GLabel.h>
|
||||
#include <LibGUI/GButton.h>
|
||||
#include <LibGUI/GLabel.h>
|
||||
#include <LibGUI/GMessageBox.h>
|
||||
#include <stdio.h>
|
||||
|
||||
void GMessageBox::show(const String& text, const String& title, Type type, CObject* parent)
|
||||
void GMessageBox::show(const StringView& text, const StringView& title, Type type, CObject* parent)
|
||||
{
|
||||
GMessageBox box(text, title, type, parent);
|
||||
box.exec();
|
||||
}
|
||||
|
||||
GMessageBox::GMessageBox(const String& text, const String& title, Type type, CObject* parent)
|
||||
GMessageBox::GMessageBox(const StringView& text, const StringView& title, Type type, CObject* parent)
|
||||
: GDialog(parent)
|
||||
, m_text(text)
|
||||
, m_type(type)
|
||||
|
@ -73,7 +73,7 @@ void GMessageBox::build()
|
|||
button->set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed);
|
||||
button->set_preferred_size({ 100, 20 });
|
||||
button->set_text("OK");
|
||||
button->on_click = [this] (auto&) {
|
||||
button->on_click = [this](auto&) {
|
||||
dbgprintf("GMessageBox: OK button clicked\n");
|
||||
done(0);
|
||||
};
|
||||
|
|
|
@ -4,18 +4,17 @@
|
|||
|
||||
class GMessageBox : public GDialog {
|
||||
public:
|
||||
enum class Type
|
||||
{
|
||||
enum class Type {
|
||||
None,
|
||||
Information,
|
||||
Warning,
|
||||
Error,
|
||||
};
|
||||
|
||||
explicit GMessageBox(const String& text, const String& title, Type type = Type::None, CObject* parent = nullptr);
|
||||
explicit GMessageBox(const StringView& text, const StringView& title, Type type = Type::None, CObject* parent = nullptr);
|
||||
virtual ~GMessageBox() override;
|
||||
|
||||
static void show(const String& text, const String& title, Type type = Type::None, CObject* parent = nullptr);
|
||||
static void show(const StringView& text, const StringView& title, Type type = Type::None, CObject* parent = nullptr);
|
||||
|
||||
virtual const char* class_name() const override { return "GMessageBox"; }
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#include <LibGUI/GModel.h>
|
||||
#include <LibGUI/GAbstractView.h>
|
||||
#include <LibGUI/GModel.h>
|
||||
|
||||
GModel::GModel()
|
||||
{
|
||||
|
@ -29,7 +29,7 @@ void GModel::did_update()
|
|||
{
|
||||
if (on_model_update)
|
||||
on_model_update(*this);
|
||||
for_each_view([] (auto& view) {
|
||||
for_each_view([](auto& view) {
|
||||
view.did_update_model();
|
||||
});
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ void GModel::set_selected_index(const GModelIndex& index)
|
|||
m_selected_index = index;
|
||||
if (on_selection_changed)
|
||||
on_selection_changed(index);
|
||||
for_each_view([] (auto& view) {
|
||||
for_each_view([](auto& view) {
|
||||
view.did_update_selection();
|
||||
});
|
||||
}
|
||||
|
@ -54,9 +54,9 @@ GModelIndex GModel::create_index(int row, int column, void* data) const
|
|||
GModelIndex GModel::sibling(int row, int column, const GModelIndex& parent) const
|
||||
{
|
||||
if (!parent.is_valid())
|
||||
return { };
|
||||
return {};
|
||||
int row_count = this->row_count(parent);
|
||||
if (row < 0 || row > row_count)
|
||||
return { };
|
||||
return {};
|
||||
return index(row, column, parent);
|
||||
}
|
||||
|
|
|
@ -12,8 +12,7 @@
|
|||
class Font;
|
||||
class GAbstractView;
|
||||
|
||||
enum class GSortOrder
|
||||
{
|
||||
enum class GSortOrder {
|
||||
None,
|
||||
Ascending,
|
||||
Descending
|
||||
|
@ -21,8 +20,7 @@ enum class GSortOrder
|
|||
|
||||
class GModelNotification {
|
||||
public:
|
||||
enum Type
|
||||
{
|
||||
enum Type {
|
||||
Invalid = 0,
|
||||
ModelUpdated,
|
||||
};
|
||||
|
@ -49,8 +47,7 @@ public:
|
|||
const Font* font { nullptr };
|
||||
};
|
||||
|
||||
enum class Role
|
||||
{
|
||||
enum class Role {
|
||||
Display,
|
||||
Sort,
|
||||
Custom,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include <LibGUI/GProgressBar.h>
|
||||
#include <LibGUI/GPainter.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <LibGUI/GPainter.h>
|
||||
#include <LibGUI/GProgressBar.h>
|
||||
|
||||
GProgressBar::GProgressBar(GWidget* parent)
|
||||
: GFrame(parent)
|
||||
|
|
|
@ -17,10 +17,9 @@ public:
|
|||
int max() const { return m_max; }
|
||||
|
||||
String caption() const { return m_caption; }
|
||||
void set_caption(const String& caption) { m_caption = caption; }
|
||||
void set_caption(const StringView& caption) { m_caption = caption; }
|
||||
|
||||
enum Format
|
||||
{
|
||||
enum Format {
|
||||
NoText,
|
||||
Percentage,
|
||||
ValueSlashMax
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#include <LibGUI/GRadioButton.h>
|
||||
#include <LibGUI/GPainter.h>
|
||||
#include <LibGUI/GRadioButton.h>
|
||||
#include <SharedGraphics/GraphicsBitmap.h>
|
||||
|
||||
static RetainPtr<GraphicsBitmap> s_unfilled_circle_bitmap;
|
||||
|
@ -7,7 +7,7 @@ static RetainPtr<GraphicsBitmap> s_filled_circle_bitmap;
|
|||
static RetainPtr<GraphicsBitmap> s_changing_filled_circle_bitmap;
|
||||
static RetainPtr<GraphicsBitmap> s_changing_unfilled_circle_bitmap;
|
||||
|
||||
GRadioButton::GRadioButton(const String& text, GWidget* parent)
|
||||
GRadioButton::GRadioButton(const StringView& text, GWidget* parent)
|
||||
: GAbstractButton(text, parent)
|
||||
{
|
||||
if (!s_unfilled_circle_bitmap) {
|
||||
|
@ -55,7 +55,7 @@ void GRadioButton::for_each_in_group(Callback callback)
|
|||
{
|
||||
if (!parent())
|
||||
return;
|
||||
parent()->for_each_child_of_type<GRadioButton>([&] (auto& child) {
|
||||
parent()->for_each_child_of_type<GRadioButton>([&](auto& child) {
|
||||
return callback(static_cast<GRadioButton&>(child));
|
||||
});
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ void GRadioButton::click()
|
|||
{
|
||||
if (!is_enabled())
|
||||
return;
|
||||
for_each_in_group([this] (auto& button) {
|
||||
for_each_in_group([this](auto& button) {
|
||||
if (&button != this)
|
||||
button.set_checked(false);
|
||||
return IterationDecision::Continue;
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
class GRadioButton : public GAbstractButton {
|
||||
public:
|
||||
GRadioButton(const String& text, GWidget* parent);
|
||||
GRadioButton(const StringView& text, GWidget* parent);
|
||||
virtual ~GRadioButton() override;
|
||||
|
||||
virtual const char* class_name() const override { return "GRadioButton"; }
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#include <LibGUI/GResizeCorner.h>
|
||||
#include <LibGUI/GPainter.h>
|
||||
#include <LibGUI/GResizeCorner.h>
|
||||
#include <LibGUI/GWindow.h>
|
||||
#include <SharedGraphics/GraphicsBitmap.h>
|
||||
#include <WindowServer/WSAPITypes.h>
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
#include <LibGUI/GPainter.h>
|
||||
#include <LibGUI/GScrollBar.h>
|
||||
#include <SharedGraphics/StylePainter.h>
|
||||
#include <SharedGraphics/CharacterBitmap.h>
|
||||
#include <SharedGraphics/GraphicsBitmap.h>
|
||||
#include <LibGUI/GPainter.h>
|
||||
|
||||
//#define GUTTER_DOES_PAGEUP_PAGEDOWN
|
||||
#include <SharedGraphics/StylePainter.h>
|
||||
|
||||
static const char* s_up_arrow_bitmap_data = {
|
||||
" "
|
||||
|
@ -30,7 +28,6 @@ static const char* s_down_arrow_bitmap_data = {
|
|||
" "
|
||||
};
|
||||
|
||||
|
||||
static const char* s_left_arrow_bitmap_data = {
|
||||
" "
|
||||
" # "
|
||||
|
@ -78,6 +75,11 @@ GScrollBar::GScrollBar(Orientation orientation, GWidget* parent)
|
|||
} else {
|
||||
set_preferred_size({ 0, 15 });
|
||||
}
|
||||
|
||||
m_automatic_scrolling_timer.set_interval(100);
|
||||
m_automatic_scrolling_timer.on_timeout = [this] {
|
||||
on_automatic_scrolling_timer_fired();
|
||||
};
|
||||
}
|
||||
|
||||
GScrollBar::~GScrollBar()
|
||||
|
@ -118,12 +120,12 @@ void GScrollBar::set_value(int value)
|
|||
update();
|
||||
}
|
||||
|
||||
Rect GScrollBar::up_button_rect() const
|
||||
Rect GScrollBar::decrement_button_rect() const
|
||||
{
|
||||
return { 0, 0, button_width(), button_height() };
|
||||
}
|
||||
|
||||
Rect GScrollBar::down_button_rect() const
|
||||
Rect GScrollBar::increment_button_rect() const
|
||||
{
|
||||
if (orientation() == Orientation::Vertical)
|
||||
return { 0, height() - button_height(), button_width(), button_height() };
|
||||
|
@ -131,7 +133,7 @@ Rect GScrollBar::down_button_rect() const
|
|||
return { width() - button_width(), 0, button_width(), button_height() };
|
||||
}
|
||||
|
||||
Rect GScrollBar::upper_gutter_rect() const
|
||||
Rect GScrollBar::decrement_gutter_rect() const
|
||||
{
|
||||
if (orientation() == Orientation::Vertical)
|
||||
return { 0, button_height(), button_width(), scrubber_rect().top() - button_height() };
|
||||
|
@ -139,11 +141,11 @@ Rect GScrollBar::upper_gutter_rect() const
|
|||
return { button_width(), 0, scrubber_rect().x() - button_width(), button_height() };
|
||||
}
|
||||
|
||||
Rect GScrollBar::lower_gutter_rect() const
|
||||
Rect GScrollBar::increment_gutter_rect() const
|
||||
{
|
||||
auto scrubber_rect = this->scrubber_rect();
|
||||
if (orientation() == Orientation::Vertical)
|
||||
return { 0, scrubber_rect.bottom() + 1, button_width(), height() - button_height() - scrubber_rect.bottom() - 1};
|
||||
return { 0, scrubber_rect.bottom() + 1, button_width(), height() - button_height() - scrubber_rect.bottom() - 1 };
|
||||
else
|
||||
return { scrubber_rect.right() + 1, 0, width() - button_width() - scrubber_rect.right() - 1, button_width() };
|
||||
}
|
||||
|
@ -171,7 +173,7 @@ int GScrollBar::scrubber_size() const
|
|||
Rect GScrollBar::scrubber_rect() const
|
||||
{
|
||||
if (!has_scrubber())
|
||||
return { };
|
||||
return {};
|
||||
float x_or_y;
|
||||
if (m_value == m_min)
|
||||
x_or_y = button_size();
|
||||
|
@ -197,38 +199,42 @@ void GScrollBar::paint_event(GPaintEvent& event)
|
|||
|
||||
painter.fill_rect(rect(), Color::from_rgb(0xd6d2ce));
|
||||
|
||||
StylePainter::paint_button(painter, up_button_rect(), ButtonStyle::Normal, false, m_hovered_component == Component::DecrementButton);
|
||||
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::paint_button(painter, decrement_button_rect(), ButtonStyle::Normal, false, m_hovered_component == Component::DecrementButton);
|
||||
painter.draw_bitmap(decrement_button_rect().location().translated(3, 3), orientation() == Orientation::Vertical ? *s_up_arrow_bitmap : *s_left_arrow_bitmap, has_scrubber() ? Color::Black : Color::MidGray);
|
||||
|
||||
StylePainter::paint_button(painter, down_button_rect(), ButtonStyle::Normal, false, m_hovered_component == Component::IncrementButton);
|
||||
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);
|
||||
StylePainter::paint_button(painter, increment_button_rect(), ButtonStyle::Normal, false, m_hovered_component == Component::IncrementButton);
|
||||
painter.draw_bitmap(increment_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::paint_button(painter, scrubber_rect(), ButtonStyle::Normal, false, m_hovered_component == Component::Scrubber);
|
||||
}
|
||||
|
||||
void GScrollBar::on_automatic_scrolling_timer_fired()
|
||||
{
|
||||
if (m_automatic_scrolling_direction == AutomaticScrollingDirection::Decrement) {
|
||||
set_value(value() - m_step);
|
||||
return;
|
||||
}
|
||||
if (m_automatic_scrolling_direction == AutomaticScrollingDirection::Increment) {
|
||||
set_value(value() + m_step);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void GScrollBar::mousedown_event(GMouseEvent& event)
|
||||
{
|
||||
if (event.button() != GMouseButton::Left)
|
||||
return;
|
||||
if (up_button_rect().contains(event.position())) {
|
||||
set_value(value() - m_step);
|
||||
if (decrement_button_rect().contains(event.position())) {
|
||||
m_automatic_scrolling_direction = AutomaticScrollingDirection::Decrement;
|
||||
set_automatic_scrolling_active(true);
|
||||
return;
|
||||
}
|
||||
if (down_button_rect().contains(event.position())) {
|
||||
set_value(value() + m_step);
|
||||
if (increment_button_rect().contains(event.position())) {
|
||||
m_automatic_scrolling_direction = AutomaticScrollingDirection::Increment;
|
||||
set_automatic_scrolling_active(true);
|
||||
return;
|
||||
}
|
||||
#ifdef GUTTER_DOES_PAGEUP_PAGEDOWN
|
||||
if (has_scrubber() && upper_gutter_rect().contains(event.position())) {
|
||||
set_value(value() - m_big_step);
|
||||
return;
|
||||
}
|
||||
if (has_scrubber() && lower_gutter_rect().contains(event.position())) {
|
||||
set_value(value() + m_big_step);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
if (has_scrubber() && scrubber_rect().contains(event.position())) {
|
||||
m_scrubbing = true;
|
||||
m_scrub_start_value = value();
|
||||
|
@ -236,7 +242,7 @@ void GScrollBar::mousedown_event(GMouseEvent& event)
|
|||
update();
|
||||
return;
|
||||
}
|
||||
#ifndef GUTTER_DOES_PAGEUP_PAGEDOWN
|
||||
|
||||
if (has_scrubber()) {
|
||||
float range_size = m_max - m_min;
|
||||
float available = scrubbable_range_in_pixels();
|
||||
|
@ -256,34 +262,51 @@ void GScrollBar::mousedown_event(GMouseEvent& event)
|
|||
m_scrub_start_value = value();
|
||||
m_scrub_origin = event.position();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void GScrollBar::mouseup_event(GMouseEvent& event)
|
||||
{
|
||||
if (event.button() != GMouseButton::Left)
|
||||
return;
|
||||
m_automatic_scrolling_direction = AutomaticScrollingDirection::None;
|
||||
set_automatic_scrolling_active(false);
|
||||
if (!m_scrubbing)
|
||||
return;
|
||||
m_scrubbing = false;
|
||||
update();
|
||||
}
|
||||
|
||||
void GScrollBar::set_automatic_scrolling_active(bool active)
|
||||
{
|
||||
if (active) {
|
||||
on_automatic_scrolling_timer_fired();
|
||||
m_automatic_scrolling_timer.start();
|
||||
} else {
|
||||
m_automatic_scrolling_timer.stop();
|
||||
}
|
||||
}
|
||||
|
||||
void GScrollBar::mousemove_event(GMouseEvent& event)
|
||||
{
|
||||
auto old_hovered_component = m_hovered_component;
|
||||
if (scrubber_rect().contains(event.position()))
|
||||
m_hovered_component = Component::Scrubber;
|
||||
else if (up_button_rect().contains(event.position()))
|
||||
else if (decrement_button_rect().contains(event.position()))
|
||||
m_hovered_component = Component::DecrementButton;
|
||||
else if (down_button_rect().contains(event.position()))
|
||||
else if (increment_button_rect().contains(event.position()))
|
||||
m_hovered_component = Component::IncrementButton;
|
||||
else if (rect().contains(event.position()))
|
||||
m_hovered_component = Component::Gutter;
|
||||
else
|
||||
m_hovered_component = Component::Invalid;
|
||||
if (old_hovered_component != m_hovered_component)
|
||||
if (old_hovered_component != m_hovered_component) {
|
||||
update();
|
||||
|
||||
if (m_automatic_scrolling_direction == AutomaticScrollingDirection::Decrement)
|
||||
set_automatic_scrolling_active(m_hovered_component == Component::DecrementButton);
|
||||
else if (m_automatic_scrolling_direction == AutomaticScrollingDirection::Increment)
|
||||
set_automatic_scrolling_active(m_hovered_component == Component::IncrementButton);
|
||||
}
|
||||
if (!m_scrubbing)
|
||||
return;
|
||||
float delta = orientation() == Orientation::Vertical ? (event.y() - m_scrub_origin.y()) : (event.x() - m_scrub_origin.x());
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/Function.h>
|
||||
#include <LibCore/CTimer.h>
|
||||
#include <LibGUI/GWidget.h>
|
||||
|
||||
class GScrollBar final : public GWidget {
|
||||
|
@ -28,8 +29,7 @@ public:
|
|||
|
||||
virtual const char* class_name() const override { return "GScrollBar"; }
|
||||
|
||||
enum Component
|
||||
{
|
||||
enum Component {
|
||||
Invalid,
|
||||
DecrementButton,
|
||||
IncrementButton,
|
||||
|
@ -48,13 +48,15 @@ private:
|
|||
int button_size() const { return 16; }
|
||||
int button_width() const { return orientation() == Orientation::Vertical ? width() : button_size(); }
|
||||
int button_height() const { return orientation() == Orientation::Horizontal ? height() : button_size(); }
|
||||
Rect up_button_rect() const;
|
||||
Rect down_button_rect() const;
|
||||
Rect upper_gutter_rect() const;
|
||||
Rect lower_gutter_rect() const;
|
||||
Rect decrement_button_rect() const;
|
||||
Rect increment_button_rect() const;
|
||||
Rect decrement_gutter_rect() const;
|
||||
Rect increment_gutter_rect() const;
|
||||
Rect scrubber_rect() const;
|
||||
int scrubber_size() const;
|
||||
int scrubbable_range_in_pixels() const;
|
||||
void on_automatic_scrolling_timer_fired();
|
||||
void set_automatic_scrolling_active(bool);
|
||||
|
||||
int m_min { 0 };
|
||||
int m_max { 0 };
|
||||
|
@ -68,4 +70,13 @@ private:
|
|||
|
||||
Orientation m_orientation { Orientation::Vertical };
|
||||
Component m_hovered_component { Component::Invalid };
|
||||
|
||||
enum class AutomaticScrollingDirection {
|
||||
None = 0,
|
||||
Decrement,
|
||||
Increment,
|
||||
};
|
||||
|
||||
AutomaticScrollingDirection m_automatic_scrolling_direction { AutomaticScrollingDirection::None };
|
||||
CTimer m_automatic_scrolling_timer;
|
||||
};
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
#include <LibGUI/GScrollableWidget.h>
|
||||
#include <LibGUI/GScrollBar.h>
|
||||
#include <LibGUI/GScrollableWidget.h>
|
||||
|
||||
GScrollableWidget::GScrollableWidget(GWidget* parent)
|
||||
: GFrame(parent)
|
||||
{
|
||||
m_vertical_scrollbar = new GScrollBar(Orientation::Vertical, this);
|
||||
m_vertical_scrollbar->set_step(4);
|
||||
m_vertical_scrollbar->on_change = [this] (int) {
|
||||
m_vertical_scrollbar->on_change = [this](int) {
|
||||
did_scroll();
|
||||
update();
|
||||
};
|
||||
|
@ -14,7 +14,7 @@ GScrollableWidget::GScrollableWidget(GWidget* parent)
|
|||
m_horizontal_scrollbar = new GScrollBar(Orientation::Horizontal, this);
|
||||
m_horizontal_scrollbar->set_step(4);
|
||||
m_horizontal_scrollbar->set_big_step(30);
|
||||
m_horizontal_scrollbar->on_change = [this] (int) {
|
||||
m_horizontal_scrollbar->on_change = [this](int) {
|
||||
did_scroll();
|
||||
update();
|
||||
};
|
||||
|
|
|
@ -1,114 +1,218 @@
|
|||
#include <LibGUI/GShortcut.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <LibGUI/GShortcut.h>
|
||||
|
||||
static String to_string(KeyCode key)
|
||||
{
|
||||
switch (key) {
|
||||
case Key_Escape: return "Escape";
|
||||
case Key_Tab: return "Tab";
|
||||
case Key_Backspace: return "Backspace";
|
||||
case Key_Return: return "Return";
|
||||
case Key_Insert: return "Insert";
|
||||
case Key_Delete: return "Delete";
|
||||
case Key_PrintScreen: return "PrintScreen";
|
||||
case Key_SysRq: return "SysRq";
|
||||
case Key_Home: return "Home";
|
||||
case Key_End: return "End";
|
||||
case Key_Left: return "Left";
|
||||
case Key_Up: return "Up";
|
||||
case Key_Right: return "Right";
|
||||
case Key_Down: return "Down";
|
||||
case Key_PageUp: return "PageUp";
|
||||
case Key_PageDown: return "PageDown";
|
||||
case Key_Shift: return "Shift";
|
||||
case Key_Control: return "Control";
|
||||
case Key_Alt: return "Alt";
|
||||
case Key_CapsLock: return "CapsLock";
|
||||
case Key_NumLock: return "NumLock";
|
||||
case Key_ScrollLock: return "ScrollLock";
|
||||
case Key_F1: return "F1";
|
||||
case Key_F2: return "F2";
|
||||
case Key_F3: return "F3";
|
||||
case Key_F4: return "F4";
|
||||
case Key_F5: return "F5";
|
||||
case Key_F6: return "F6";
|
||||
case Key_F7: return "F7";
|
||||
case Key_F8: return "F8";
|
||||
case Key_F9: return "F9";
|
||||
case Key_F10: return "F10";
|
||||
case Key_F11: return "F11";
|
||||
case Key_F12: return "F12";
|
||||
case Key_Space: return "Space";
|
||||
case Key_ExclamationPoint: return "!";
|
||||
case Key_DoubleQuote: return "\"";
|
||||
case Key_Hashtag: return "#";
|
||||
case Key_Dollar: return "$";
|
||||
case Key_Percent: return "%";
|
||||
case Key_Ampersand: return "&";
|
||||
case Key_Apostrophe: return "'";
|
||||
case Key_LeftParen: return "(";
|
||||
case Key_RightParen: return ")";
|
||||
case Key_Asterisk: return "*";
|
||||
case Key_Plus: return "+";
|
||||
case Key_Comma: return ",";
|
||||
case Key_Minus: return "-";
|
||||
case Key_Period: return ",";
|
||||
case Key_Slash: return "/";
|
||||
case Key_0: return "0";
|
||||
case Key_1: return "1";
|
||||
case Key_2: return "2";
|
||||
case Key_3: return "3";
|
||||
case Key_4: return "4";
|
||||
case Key_5: return "5";
|
||||
case Key_6: return "6";
|
||||
case Key_7: return "7";
|
||||
case Key_8: return "8";
|
||||
case Key_9: return "9";
|
||||
case Key_Colon: return ":";
|
||||
case Key_Semicolon: return ";";
|
||||
case Key_LessThan: return "<";
|
||||
case Key_Equal: return "=";
|
||||
case Key_GreaterThan: return ">";
|
||||
case Key_QuestionMark: return "?";
|
||||
case Key_AtSign: return "@";
|
||||
case Key_A: return "A";
|
||||
case Key_B: return "B";
|
||||
case Key_C: return "C";
|
||||
case Key_D: return "D";
|
||||
case Key_E: return "E";
|
||||
case Key_F: return "F";
|
||||
case Key_G: return "G";
|
||||
case Key_H: return "H";
|
||||
case Key_I: return "I";
|
||||
case Key_J: return "J";
|
||||
case Key_K: return "K";
|
||||
case Key_L: return "L";
|
||||
case Key_M: return "M";
|
||||
case Key_N: return "N";
|
||||
case Key_O: return "O";
|
||||
case Key_P: return "P";
|
||||
case Key_Q: return "Q";
|
||||
case Key_R: return "R";
|
||||
case Key_S: return "S";
|
||||
case Key_T: return "T";
|
||||
case Key_U: return "U";
|
||||
case Key_V: return "V";
|
||||
case Key_W: return "W";
|
||||
case Key_X: return "X";
|
||||
case Key_Y: return "Y";
|
||||
case Key_Z: return "Z";
|
||||
case Key_LeftBracket: return "[";
|
||||
case Key_RightBracket: return "]";
|
||||
case Key_Backslash: return "\\";
|
||||
case Key_Circumflex: return "^";
|
||||
case Key_Underscore: return "_";
|
||||
case Key_LeftBrace: return "{";
|
||||
case Key_RightBrace: return "}";
|
||||
case Key_Pipe: return "|";
|
||||
case Key_Tilde: return "~";
|
||||
case Key_Backtick: return "`";
|
||||
case Key_Escape:
|
||||
return "Escape";
|
||||
case Key_Tab:
|
||||
return "Tab";
|
||||
case Key_Backspace:
|
||||
return "Backspace";
|
||||
case Key_Return:
|
||||
return "Return";
|
||||
case Key_Insert:
|
||||
return "Insert";
|
||||
case Key_Delete:
|
||||
return "Delete";
|
||||
case Key_PrintScreen:
|
||||
return "PrintScreen";
|
||||
case Key_SysRq:
|
||||
return "SysRq";
|
||||
case Key_Home:
|
||||
return "Home";
|
||||
case Key_End:
|
||||
return "End";
|
||||
case Key_Left:
|
||||
return "Left";
|
||||
case Key_Up:
|
||||
return "Up";
|
||||
case Key_Right:
|
||||
return "Right";
|
||||
case Key_Down:
|
||||
return "Down";
|
||||
case Key_PageUp:
|
||||
return "PageUp";
|
||||
case Key_PageDown:
|
||||
return "PageDown";
|
||||
case Key_Shift:
|
||||
return "Shift";
|
||||
case Key_Control:
|
||||
return "Control";
|
||||
case Key_Alt:
|
||||
return "Alt";
|
||||
case Key_CapsLock:
|
||||
return "CapsLock";
|
||||
case Key_NumLock:
|
||||
return "NumLock";
|
||||
case Key_ScrollLock:
|
||||
return "ScrollLock";
|
||||
case Key_F1:
|
||||
return "F1";
|
||||
case Key_F2:
|
||||
return "F2";
|
||||
case Key_F3:
|
||||
return "F3";
|
||||
case Key_F4:
|
||||
return "F4";
|
||||
case Key_F5:
|
||||
return "F5";
|
||||
case Key_F6:
|
||||
return "F6";
|
||||
case Key_F7:
|
||||
return "F7";
|
||||
case Key_F8:
|
||||
return "F8";
|
||||
case Key_F9:
|
||||
return "F9";
|
||||
case Key_F10:
|
||||
return "F10";
|
||||
case Key_F11:
|
||||
return "F11";
|
||||
case Key_F12:
|
||||
return "F12";
|
||||
case Key_Space:
|
||||
return "Space";
|
||||
case Key_ExclamationPoint:
|
||||
return "!";
|
||||
case Key_DoubleQuote:
|
||||
return "\"";
|
||||
case Key_Hashtag:
|
||||
return "#";
|
||||
case Key_Dollar:
|
||||
return "$";
|
||||
case Key_Percent:
|
||||
return "%";
|
||||
case Key_Ampersand:
|
||||
return "&";
|
||||
case Key_Apostrophe:
|
||||
return "'";
|
||||
case Key_LeftParen:
|
||||
return "(";
|
||||
case Key_RightParen:
|
||||
return ")";
|
||||
case Key_Asterisk:
|
||||
return "*";
|
||||
case Key_Plus:
|
||||
return "+";
|
||||
case Key_Comma:
|
||||
return ",";
|
||||
case Key_Minus:
|
||||
return "-";
|
||||
case Key_Period:
|
||||
return ",";
|
||||
case Key_Slash:
|
||||
return "/";
|
||||
case Key_0:
|
||||
return "0";
|
||||
case Key_1:
|
||||
return "1";
|
||||
case Key_2:
|
||||
return "2";
|
||||
case Key_3:
|
||||
return "3";
|
||||
case Key_4:
|
||||
return "4";
|
||||
case Key_5:
|
||||
return "5";
|
||||
case Key_6:
|
||||
return "6";
|
||||
case Key_7:
|
||||
return "7";
|
||||
case Key_8:
|
||||
return "8";
|
||||
case Key_9:
|
||||
return "9";
|
||||
case Key_Colon:
|
||||
return ":";
|
||||
case Key_Semicolon:
|
||||
return ";";
|
||||
case Key_LessThan:
|
||||
return "<";
|
||||
case Key_Equal:
|
||||
return "=";
|
||||
case Key_GreaterThan:
|
||||
return ">";
|
||||
case Key_QuestionMark:
|
||||
return "?";
|
||||
case Key_AtSign:
|
||||
return "@";
|
||||
case Key_A:
|
||||
return "A";
|
||||
case Key_B:
|
||||
return "B";
|
||||
case Key_C:
|
||||
return "C";
|
||||
case Key_D:
|
||||
return "D";
|
||||
case Key_E:
|
||||
return "E";
|
||||
case Key_F:
|
||||
return "F";
|
||||
case Key_G:
|
||||
return "G";
|
||||
case Key_H:
|
||||
return "H";
|
||||
case Key_I:
|
||||
return "I";
|
||||
case Key_J:
|
||||
return "J";
|
||||
case Key_K:
|
||||
return "K";
|
||||
case Key_L:
|
||||
return "L";
|
||||
case Key_M:
|
||||
return "M";
|
||||
case Key_N:
|
||||
return "N";
|
||||
case Key_O:
|
||||
return "O";
|
||||
case Key_P:
|
||||
return "P";
|
||||
case Key_Q:
|
||||
return "Q";
|
||||
case Key_R:
|
||||
return "R";
|
||||
case Key_S:
|
||||
return "S";
|
||||
case Key_T:
|
||||
return "T";
|
||||
case Key_U:
|
||||
return "U";
|
||||
case Key_V:
|
||||
return "V";
|
||||
case Key_W:
|
||||
return "W";
|
||||
case Key_X:
|
||||
return "X";
|
||||
case Key_Y:
|
||||
return "Y";
|
||||
case Key_Z:
|
||||
return "Z";
|
||||
case Key_LeftBracket:
|
||||
return "[";
|
||||
case Key_RightBracket:
|
||||
return "]";
|
||||
case Key_Backslash:
|
||||
return "\\";
|
||||
case Key_Circumflex:
|
||||
return "^";
|
||||
case Key_Underscore:
|
||||
return "_";
|
||||
case Key_LeftBrace:
|
||||
return "{";
|
||||
case Key_RightBrace:
|
||||
return "}";
|
||||
case Key_Pipe:
|
||||
return "|";
|
||||
case Key_Tilde:
|
||||
return "~";
|
||||
case Key_Backtick:
|
||||
return "`";
|
||||
|
||||
case Key_Invalid: return "Invalid";
|
||||
case Key_Invalid:
|
||||
return "Invalid";
|
||||
default:
|
||||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#include <LibGUI/GSlider.h>
|
||||
#include <LibGUI/GPainter.h>
|
||||
#include <LibGUI/GSlider.h>
|
||||
#include <SharedGraphics/StylePainter.h>
|
||||
|
||||
GSlider::GSlider(GWidget* parent)
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
#include <LibGUI/GSortingProxyModel.h>
|
||||
#include <AK/QuickSort.h>
|
||||
#include <stdlib.h>
|
||||
#include <LibGUI/GSortingProxyModel.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
GSortingProxyModel::GSortingProxyModel(Retained<GModel>&& target)
|
||||
: m_target(move(target))
|
||||
, m_key_column(-1)
|
||||
{
|
||||
m_target->on_model_update = [this] (GModel&) {
|
||||
m_target->on_model_update = [this](GModel&) {
|
||||
resort();
|
||||
};
|
||||
}
|
||||
|
@ -29,9 +29,9 @@ int GSortingProxyModel::column_count(const GModelIndex& index) const
|
|||
GModelIndex GSortingProxyModel::map_to_target(const GModelIndex& index) const
|
||||
{
|
||||
if (!index.is_valid())
|
||||
return { };
|
||||
return {};
|
||||
if (index.row() >= m_row_mappings.size() || index.column() >= column_count())
|
||||
return { };
|
||||
return {};
|
||||
return target().index(m_row_mappings[index.row()], index.column());
|
||||
}
|
||||
|
||||
|
@ -82,7 +82,7 @@ void GSortingProxyModel::resort()
|
|||
did_update();
|
||||
return;
|
||||
}
|
||||
quick_sort(m_row_mappings.begin(), m_row_mappings.end(), [&] (auto row1, auto row2) -> bool {
|
||||
quick_sort(m_row_mappings.begin(), m_row_mappings.end(), [&](auto row1, auto row2) -> bool {
|
||||
auto data1 = target().data(target().index(row1, m_key_column), GModel::Role::Sort);
|
||||
auto data2 = target().data(target().index(row2, m_key_column), GModel::Role::Sort);
|
||||
if (data1 == data2)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#include <LibGUI/GSpinBox.h>
|
||||
#include <LibGUI/GButton.h>
|
||||
#include <LibGUI/GSpinBox.h>
|
||||
#include <LibGUI/GTextEditor.h>
|
||||
|
||||
GSpinBox::GSpinBox(GWidget* parent)
|
||||
|
@ -16,10 +16,10 @@ GSpinBox::GSpinBox(GWidget* parent)
|
|||
};
|
||||
m_increment_button = new GButton(this);
|
||||
m_increment_button->set_text("\xf6");
|
||||
m_increment_button->on_click = [this] (GButton&) { set_value(m_value + 1); };
|
||||
m_increment_button->on_click = [this](GButton&) { set_value(m_value + 1); };
|
||||
m_decrement_button = new GButton(this);
|
||||
m_decrement_button->set_text("\xf7");
|
||||
m_decrement_button->on_click = [this] (GButton&) { set_value(m_value - 1); };
|
||||
m_decrement_button->on_click = [this](GButton&) { set_value(m_value - 1); };
|
||||
}
|
||||
|
||||
GSpinBox::~GSpinBox()
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#include <LibGUI/GSplitter.h>
|
||||
#include <LibGUI/GBoxLayout.h>
|
||||
#include <LibGUI/GSplitter.h>
|
||||
#include <LibGUI/GWindow.h>
|
||||
|
||||
GSplitter::GSplitter(Orientation orientation, GWidget* parent)
|
||||
|
@ -40,7 +40,7 @@ void GSplitter::mousedown_event(GMouseEvent& event)
|
|||
GWidget* first_resizee { nullptr };
|
||||
GWidget* second_resizee { nullptr };
|
||||
int fudge = layout()->spacing();
|
||||
for_each_child_widget([&] (auto& child) {
|
||||
for_each_child_widget([&](auto& child) {
|
||||
int child_start = m_orientation == Orientation::Horizontal ? child.relative_rect().left() : child.relative_rect().top();
|
||||
int child_end = m_orientation == Orientation::Horizontal ? child.relative_rect().right() : child.relative_rect().bottom();
|
||||
if (x_or_y > child_end && (x_or_y - fudge) <= child_end)
|
||||
|
@ -65,7 +65,8 @@ void GSplitter::mousemove_event(GMouseEvent& event)
|
|||
if (!m_first_resizee || !m_second_resizee) {
|
||||
// One or both of the resizees were deleted during an ongoing resize, screw this.
|
||||
m_resizing = false;
|
||||
return;;
|
||||
return;
|
||||
;
|
||||
}
|
||||
int minimum_size = 0;
|
||||
auto new_first_resizee_size = m_first_resizee_start_size;
|
||||
|
@ -112,5 +113,4 @@ void GSplitter::mouseup_event(GMouseEvent& event)
|
|||
m_resizing = false;
|
||||
if (!rect().contains(event.position()))
|
||||
window()->set_override_cursor(GStandardCursor::None);
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#include <LibGUI/GStackWidget.h>
|
||||
#include <LibGUI/GBoxLayout.h>
|
||||
#include <LibGUI/GStackWidget.h>
|
||||
|
||||
GStackWidget::GStackWidget(GWidget* parent)
|
||||
: GWidget(parent)
|
||||
|
@ -28,7 +28,7 @@ void GStackWidget::resize_event(GResizeEvent& event)
|
|||
{
|
||||
if (!m_active_widget)
|
||||
return;
|
||||
m_active_widget->set_relative_rect({ { }, event.size() });
|
||||
m_active_widget->set_relative_rect({ {}, event.size() });
|
||||
}
|
||||
|
||||
void GStackWidget::child_event(CChildEvent& event)
|
||||
|
@ -44,9 +44,9 @@ void GStackWidget::child_event(CChildEvent& event)
|
|||
} else if (event.type() == GEvent::ChildRemoved) {
|
||||
if (m_active_widget == &child) {
|
||||
GWidget* new_active_widget = nullptr;
|
||||
for_each_child_widget([&] (auto& new_child) {
|
||||
for_each_child_widget([&](auto& new_child) {
|
||||
new_active_widget = &new_child;
|
||||
return IterationDecision::Abort;
|
||||
return IterationDecision::Break;
|
||||
});
|
||||
set_active_widget(new_active_widget);
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
#include <LibGUI/GStatusBar.h>
|
||||
#include <LibGUI/GLabel.h>
|
||||
#include <LibGUI/GBoxLayout.h>
|
||||
#include <SharedGraphics/StylePainter.h>
|
||||
#include <LibGUI/GLabel.h>
|
||||
#include <LibGUI/GPainter.h>
|
||||
#include <LibGUI/GResizeCorner.h>
|
||||
#include <LibGUI/GStatusBar.h>
|
||||
#include <SharedGraphics/StylePainter.h>
|
||||
|
||||
GStatusBar::GStatusBar(GWidget* parent)
|
||||
: GWidget(parent)
|
||||
|
@ -26,7 +26,7 @@ GStatusBar::~GStatusBar()
|
|||
{
|
||||
}
|
||||
|
||||
void GStatusBar::set_text(const String& text)
|
||||
void GStatusBar::set_text(const StringView& text)
|
||||
{
|
||||
m_label->set_text(text);
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ public:
|
|||
virtual ~GStatusBar() override;
|
||||
|
||||
String text() const;
|
||||
void set_text(const String&);
|
||||
void set_text(const StringView&);
|
||||
|
||||
virtual const char* class_name() const override { return "GStatusBar"; }
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include <LibGUI/GTabWidget.h>
|
||||
#include <LibGUI/GBoxLayout.h>
|
||||
#include <LibGUI/GPainter.h>
|
||||
#include <LibGUI/GTabWidget.h>
|
||||
#include <SharedGraphics/StylePainter.h>
|
||||
|
||||
GTabWidget::GTabWidget(GWidget* parent)
|
||||
|
@ -14,7 +14,7 @@ GTabWidget::~GTabWidget()
|
|||
{
|
||||
}
|
||||
|
||||
void GTabWidget::add_widget(const String& title, GWidget* widget)
|
||||
void GTabWidget::add_widget(const StringView& title, GWidget* widget)
|
||||
{
|
||||
m_tabs.append({ title, widget });
|
||||
add_child(*widget);
|
||||
|
@ -61,9 +61,9 @@ void GTabWidget::child_event(CChildEvent& event)
|
|||
} else if (event.type() == GEvent::ChildRemoved) {
|
||||
if (m_active_widget == &child) {
|
||||
GWidget* new_active_widget = nullptr;
|
||||
for_each_child_widget([&] (auto& new_child) {
|
||||
for_each_child_widget([&](auto& new_child) {
|
||||
new_active_widget = &new_child;
|
||||
return IterationDecision::Abort;
|
||||
return IterationDecision::Break;
|
||||
});
|
||||
set_active_widget(new_active_widget);
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ public:
|
|||
int bar_height() const { return 21; }
|
||||
int container_padding() const { return 2; }
|
||||
|
||||
void add_widget(const String&, GWidget*);
|
||||
void add_widget(const StringView&, GWidget*);
|
||||
|
||||
virtual const char* class_name() const override { return "GTabWidget"; }
|
||||
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
#include <LibGUI/GTableView.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <Kernel/KeyCode.h>
|
||||
#include <LibGUI/GAction.h>
|
||||
#include <LibGUI/GMenu.h>
|
||||
#include <LibGUI/GModel.h>
|
||||
#include <LibGUI/GScrollBar.h>
|
||||
#include <LibGUI/GPainter.h>
|
||||
#include <LibGUI/GScrollBar.h>
|
||||
#include <LibGUI/GTableView.h>
|
||||
#include <LibGUI/GTextBox.h>
|
||||
#include <LibGUI/GWindow.h>
|
||||
#include <LibGUI/GMenu.h>
|
||||
#include <LibGUI/GAction.h>
|
||||
#include <Kernel/KeyCode.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
|
||||
GTableView::GTableView(GWidget* parent)
|
||||
: GAbstractView(parent)
|
||||
|
@ -24,7 +24,7 @@ GTableView::~GTableView()
|
|||
void GTableView::update_content_size()
|
||||
{
|
||||
if (!model())
|
||||
return set_content_size({ });
|
||||
return set_content_size({});
|
||||
|
||||
int content_width = 0;
|
||||
int column_count = model()->column_count();
|
||||
|
@ -80,9 +80,9 @@ int GTableView::column_width(int column_index) const
|
|||
Rect GTableView::header_rect(int column_index) const
|
||||
{
|
||||
if (!model())
|
||||
return { };
|
||||
return {};
|
||||
if (is_column_hidden(column_index))
|
||||
return { };
|
||||
return {};
|
||||
int x_offset = 0;
|
||||
for (int i = 0; i < column_index; ++i) {
|
||||
if (is_column_hidden(i))
|
||||
|
@ -100,7 +100,7 @@ Point GTableView::adjusted_position(const Point& position)
|
|||
Rect GTableView::column_resize_grabbable_rect(int column) const
|
||||
{
|
||||
if (!model())
|
||||
return { };
|
||||
return {};
|
||||
auto header_rect = this->header_rect(column);
|
||||
return { header_rect.right() - 1, header_rect.top(), 4, header_rect.height() };
|
||||
}
|
||||
|
@ -148,7 +148,7 @@ void GTableView::mousedown_event(GMouseEvent& event)
|
|||
return;
|
||||
}
|
||||
}
|
||||
model()->set_selected_index({ });
|
||||
model()->set_selected_index({});
|
||||
update();
|
||||
}
|
||||
|
||||
|
@ -427,7 +427,7 @@ GMenu& GTableView::ensure_header_context_menu()
|
|||
for (int column = 0; column < model()->column_count(); ++column) {
|
||||
auto& column_data = this->column_data(column);
|
||||
auto name = model()->column_name(column);
|
||||
column_data.visibility_action = GAction::create(name, [this, column] (GAction& action) {
|
||||
column_data.visibility_action = GAction::create(name, [this, column](GAction& action) {
|
||||
action.set_checked(!action.is_checked());
|
||||
set_column_hidden(column, !action.is_checked());
|
||||
});
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
#include <LibGUI/GTextEditor.h>
|
||||
#include <LibGUI/GScrollBar.h>
|
||||
#include <LibGUI/GFontDatabase.h>
|
||||
#include <LibGUI/GClipboard.h>
|
||||
#include <LibGUI/GPainter.h>
|
||||
#include <LibGUI/GWindow.h>
|
||||
#include <LibGUI/GMenu.h>
|
||||
#include <LibGUI/GAction.h>
|
||||
#include <Kernel/KeyCode.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <unistd.h>
|
||||
#include <Kernel/KeyCode.h>
|
||||
#include <LibGUI/GAction.h>
|
||||
#include <LibGUI/GClipboard.h>
|
||||
#include <LibGUI/GFontDatabase.h>
|
||||
#include <LibGUI/GMenu.h>
|
||||
#include <LibGUI/GPainter.h>
|
||||
#include <LibGUI/GScrollBar.h>
|
||||
#include <LibGUI/GTextEditor.h>
|
||||
#include <LibGUI/GWindow.h>
|
||||
#include <ctype.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <unistd.h>
|
||||
|
||||
GTextEditor::GTextEditor(Type type, GWidget* parent)
|
||||
: GScrollableWidget(parent)
|
||||
|
@ -22,6 +22,8 @@ GTextEditor::GTextEditor(Type type, GWidget* parent)
|
|||
set_frame_thickness(2);
|
||||
set_scrollbars_enabled(is_multi_line());
|
||||
set_font(GFontDatabase::the().get_by_name("Csilla Thin"));
|
||||
// FIXME: Recompute vertical scrollbar step size on font change.
|
||||
vertical_scrollbar().set_step(line_height());
|
||||
m_lines.append(make<Line>());
|
||||
m_cursor = { 0, 0 };
|
||||
create_actions();
|
||||
|
@ -33,32 +35,38 @@ GTextEditor::~GTextEditor()
|
|||
|
||||
void GTextEditor::create_actions()
|
||||
{
|
||||
m_undo_action = GAction::create("Undo", { Mod_Ctrl, Key_Z }, GraphicsBitmap::load_from_file("/res/icons/16x16/undo.png"), [&] (const GAction&) {
|
||||
m_undo_action = GAction::create("Undo", { Mod_Ctrl, Key_Z }, GraphicsBitmap::load_from_file("/res/icons/16x16/undo.png"), [&](const GAction&) {
|
||||
// FIXME: Undo
|
||||
}, this);
|
||||
},
|
||||
this);
|
||||
|
||||
m_redo_action = GAction::create("Redo", { Mod_Ctrl, Key_Y }, GraphicsBitmap::load_from_file("/res/icons/16x16/redo.png"), [&] (const GAction&) {
|
||||
m_redo_action = GAction::create("Redo", { Mod_Ctrl, Key_Y }, GraphicsBitmap::load_from_file("/res/icons/16x16/redo.png"), [&](const GAction&) {
|
||||
// FIXME: Redo
|
||||
}, this);
|
||||
},
|
||||
this);
|
||||
|
||||
m_cut_action = GAction::create("Cut", { Mod_Ctrl, Key_X }, GraphicsBitmap::load_from_file("/res/icons/cut16.png"), [&] (const GAction&) {
|
||||
m_cut_action = GAction::create("Cut", { Mod_Ctrl, Key_X }, GraphicsBitmap::load_from_file("/res/icons/cut16.png"), [&](const GAction&) {
|
||||
cut();
|
||||
}, this);
|
||||
},
|
||||
this);
|
||||
|
||||
m_copy_action = GAction::create("Copy", { Mod_Ctrl, Key_C }, GraphicsBitmap::load_from_file("/res/icons/16x16/edit-copy.png"), [&] (const GAction&) {
|
||||
m_copy_action = GAction::create("Copy", { Mod_Ctrl, Key_C }, GraphicsBitmap::load_from_file("/res/icons/16x16/edit-copy.png"), [&](const GAction&) {
|
||||
copy();
|
||||
}, this);
|
||||
},
|
||||
this);
|
||||
|
||||
m_paste_action = GAction::create("Paste", { Mod_Ctrl, Key_V }, GraphicsBitmap::load_from_file("/res/icons/paste16.png"), [&] (const GAction&) {
|
||||
m_paste_action = GAction::create("Paste", { Mod_Ctrl, Key_V }, GraphicsBitmap::load_from_file("/res/icons/paste16.png"), [&](const GAction&) {
|
||||
paste();
|
||||
}, this);
|
||||
},
|
||||
this);
|
||||
|
||||
m_delete_action = GAction::create("Delete", { 0, Key_Delete }, GraphicsBitmap::load_from_file("/res/icons/16x16/delete.png"), [&] (const GAction&) {
|
||||
m_delete_action = GAction::create("Delete", { 0, Key_Delete }, GraphicsBitmap::load_from_file("/res/icons/16x16/delete.png"), [&](const GAction&) {
|
||||
do_delete();
|
||||
}, this);
|
||||
},
|
||||
this);
|
||||
}
|
||||
|
||||
void GTextEditor::set_text(const String& text)
|
||||
void GTextEditor::set_text(const StringView& text)
|
||||
{
|
||||
if (is_single_line() && text.length() == m_lines[0]->length() && !memcmp(text.characters(), m_lines[0]->characters(), text.length()))
|
||||
return;
|
||||
|
@ -67,11 +75,11 @@ void GTextEditor::set_text(const String& text)
|
|||
m_lines.clear();
|
||||
int start_of_current_line = 0;
|
||||
|
||||
auto add_line = [&] (int current_position) {
|
||||
auto add_line = [&](int current_position) {
|
||||
int line_length = current_position - start_of_current_line;
|
||||
auto line = make<Line>();
|
||||
if (line_length)
|
||||
line->set_text(text.substring(start_of_current_line, current_position - start_of_current_line));
|
||||
line->set_text(text.substring_view(start_of_current_line, current_position - start_of_current_line));
|
||||
m_lines.append(move(line));
|
||||
start_of_current_line = current_position + 1;
|
||||
};
|
||||
|
@ -187,7 +195,7 @@ void GTextEditor::mousedown_event(GMouseEvent& event)
|
|||
|
||||
if (event.modifiers() & Mod_Shift) {
|
||||
if (!has_selection())
|
||||
m_selection.set(m_cursor, { });
|
||||
m_selection.set(m_cursor, {});
|
||||
} else {
|
||||
m_selection.clear();
|
||||
}
|
||||
|
@ -198,7 +206,7 @@ void GTextEditor::mousedown_event(GMouseEvent& event)
|
|||
|
||||
if (!(event.modifiers() & Mod_Shift)) {
|
||||
if (!has_selection())
|
||||
m_selection.set(m_cursor, { });
|
||||
m_selection.set(m_cursor, {});
|
||||
}
|
||||
|
||||
if (m_selection.start().is_valid() && m_selection.start() != m_cursor)
|
||||
|
@ -241,7 +249,7 @@ int GTextEditor::ruler_width() const
|
|||
Rect GTextEditor::ruler_content_rect(int line_index) const
|
||||
{
|
||||
if (!m_ruler_visible)
|
||||
return { };
|
||||
return {};
|
||||
return {
|
||||
0 - ruler_width() + horizontal_scrollbar().value(),
|
||||
line_index * line_height(),
|
||||
|
@ -261,7 +269,7 @@ void GTextEditor::paint_event(GPaintEvent& event)
|
|||
|
||||
painter.translate(frame_thickness(), frame_thickness());
|
||||
|
||||
Rect ruler_rect { 0, 0, ruler_width(), height() - height_occupied_by_horizontal_scrollbar()};
|
||||
Rect ruler_rect { 0, 0, ruler_width(), height() - height_occupied_by_horizontal_scrollbar() };
|
||||
|
||||
if (m_ruler_visible) {
|
||||
painter.fill_rect(ruler_rect, Color::LightGray);
|
||||
|
@ -287,8 +295,7 @@ void GTextEditor::paint_event(GPaintEvent& event)
|
|||
String::format("%u", i),
|
||||
is_current_line ? Font::default_bold_font() : font(),
|
||||
TextAlignment::CenterRight,
|
||||
is_current_line ? Color::DarkGray : Color::MidGray
|
||||
);
|
||||
is_current_line ? Color::DarkGray : Color::MidGray);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -301,18 +308,19 @@ void GTextEditor::paint_event(GPaintEvent& event)
|
|||
//line_rect.set_width(exposed_width);
|
||||
if (is_multi_line() && i == m_cursor.line())
|
||||
painter.fill_rect(line_rect, Color(230, 230, 230));
|
||||
painter.draw_text(line_rect, line.characters(), line.length(), m_text_alignment, Color::Black);
|
||||
painter.draw_text(line_rect, StringView(line.characters(), line.length()), m_text_alignment, Color::Black);
|
||||
bool line_has_selection = has_selection && i >= selection.start().line() && i <= selection.end().line();
|
||||
if (line_has_selection) {
|
||||
int selection_start_column_on_line = selection.start().line() == i ? selection.start().column() : 0;
|
||||
int selection_end_column_on_line = selection.end().line() == i ? selection.end().column() : line.length();
|
||||
|
||||
int selection_left = content_x_for_position({ i, selection_start_column_on_line });
|
||||
int selection_right = content_x_for_position({ i, selection_end_column_on_line });;
|
||||
int selection_right = content_x_for_position({ i, selection_end_column_on_line });
|
||||
;
|
||||
|
||||
Rect selection_rect { selection_left, line_rect.y(), selection_right - selection_left, line_rect.height() };
|
||||
painter.fill_rect(selection_rect, Color::from_rgb(0x955233));
|
||||
painter.draw_text(selection_rect, line.characters() + selection_start_column_on_line, line.length() - selection_start_column_on_line - (line.length() - selection_end_column_on_line), TextAlignment::CenterLeft, Color::White);
|
||||
painter.draw_text(selection_rect, StringView(line.characters() + selection_start_column_on_line, line.length() - selection_start_column_on_line - (line.length() - selection_end_column_on_line)), TextAlignment::CenterLeft, Color::White);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -323,7 +331,7 @@ void GTextEditor::paint_event(GPaintEvent& event)
|
|||
void GTextEditor::toggle_selection_if_needed_for_event(const GKeyEvent& event)
|
||||
{
|
||||
if (event.shift() && !m_selection.is_valid()) {
|
||||
m_selection.set(m_cursor, { });
|
||||
m_selection.set(m_cursor, {});
|
||||
did_update_selection();
|
||||
update();
|
||||
return;
|
||||
|
@ -574,7 +582,7 @@ void GTextEditor::do_delete()
|
|||
}
|
||||
}
|
||||
|
||||
void GTextEditor::insert_at_cursor(const String& text)
|
||||
void GTextEditor::insert_at_cursor(const StringView& text)
|
||||
{
|
||||
// FIXME: This should obviously not be implemented this way.
|
||||
for (int i = 0; i < text.length(); ++i) {
|
||||
|
@ -652,7 +660,7 @@ int GTextEditor::content_x_for_position(const GTextPosition& position) const
|
|||
Rect GTextEditor::cursor_content_rect() const
|
||||
{
|
||||
if (!m_cursor.is_valid())
|
||||
return { };
|
||||
return {};
|
||||
ASSERT(!m_lines.is_empty());
|
||||
ASSERT(m_cursor.column() <= (current_line().length() + 1));
|
||||
|
||||
|
@ -660,7 +668,7 @@ Rect GTextEditor::cursor_content_rect() const
|
|||
|
||||
if (is_single_line()) {
|
||||
Rect cursor_rect { cursor_x, 0, 1, font().glyph_height() + 2 };
|
||||
cursor_rect.center_vertically_within({ { }, frame_inner_rect().size() });
|
||||
cursor_rect.center_vertically_within({ {}, frame_inner_rect().size() });
|
||||
return cursor_rect;
|
||||
}
|
||||
return { cursor_x, m_cursor.line() * line_height(), 1, line_height() };
|
||||
|
@ -692,7 +700,7 @@ Rect GTextEditor::line_content_rect(int line_index) const
|
|||
auto& line = *m_lines[line_index];
|
||||
if (is_single_line()) {
|
||||
Rect line_rect = { content_x_for_position({ line_index, 0 }), 0, line.length() * glyph_width(), font().glyph_height() + 2 };
|
||||
line_rect.center_vertically_within({ { }, frame_inner_rect().size() });
|
||||
line_rect.center_vertically_within({ {}, frame_inner_rect().size() });
|
||||
return line_rect;
|
||||
}
|
||||
return {
|
||||
|
@ -756,7 +764,7 @@ GTextEditor::Line::Line()
|
|||
clear();
|
||||
}
|
||||
|
||||
GTextEditor::Line::Line(const String& text)
|
||||
GTextEditor::Line::Line(const StringView& text)
|
||||
{
|
||||
set_text(text);
|
||||
}
|
||||
|
@ -767,7 +775,7 @@ void GTextEditor::Line::clear()
|
|||
m_text.append(0);
|
||||
}
|
||||
|
||||
void GTextEditor::Line::set_text(const String& text)
|
||||
void GTextEditor::Line::set_text(const StringView& text)
|
||||
{
|
||||
if (text.length() == length() && !memcmp(text.characters(), characters(), length()))
|
||||
return;
|
||||
|
@ -828,7 +836,7 @@ void GTextEditor::Line::truncate(int length)
|
|||
m_text.last() = 0;
|
||||
}
|
||||
|
||||
bool GTextEditor::write_to_file(const String& path)
|
||||
bool GTextEditor::write_to_file(const StringView& path)
|
||||
{
|
||||
int fd = open(path.characters(), O_WRONLY | O_CREAT | O_TRUNC, 0666);
|
||||
if (fd < 0) {
|
||||
|
@ -885,7 +893,7 @@ void GTextEditor::clear()
|
|||
String GTextEditor::selected_text() const
|
||||
{
|
||||
if (!has_selection())
|
||||
return { };
|
||||
return {};
|
||||
|
||||
auto selection = normalized_selection();
|
||||
StringBuilder builder;
|
||||
|
@ -952,7 +960,7 @@ void GTextEditor::delete_selection()
|
|||
update();
|
||||
}
|
||||
|
||||
void GTextEditor::insert_at_cursor_or_replace_selection(const String& text)
|
||||
void GTextEditor::insert_at_cursor_or_replace_selection(const StringView& text)
|
||||
{
|
||||
ASSERT(!is_readonly());
|
||||
if (has_selection())
|
||||
|
@ -1003,7 +1011,7 @@ void GTextEditor::did_change()
|
|||
update_content_size();
|
||||
if (!m_have_pending_change_notification) {
|
||||
m_have_pending_change_notification = true;
|
||||
deferred_invoke([this] (auto&) {
|
||||
deferred_invoke([this](auto&) {
|
||||
if (on_change)
|
||||
on_change();
|
||||
m_have_pending_change_notification = false;
|
||||
|
|
|
@ -78,8 +78,7 @@ private:
|
|||
|
||||
class GTextEditor : public GScrollableWidget {
|
||||
public:
|
||||
enum Type
|
||||
{
|
||||
enum Type {
|
||||
MultiLine,
|
||||
SingleLine
|
||||
};
|
||||
|
@ -105,7 +104,7 @@ public:
|
|||
Function<void()> on_cursor_change;
|
||||
Function<void()> on_selection_change;
|
||||
|
||||
void set_text(const String&);
|
||||
void set_text(const StringView&);
|
||||
void scroll_cursor_into_view();
|
||||
int line_count() const { return m_lines.size(); }
|
||||
int line_spacing() const { return m_line_spacing; }
|
||||
|
@ -115,7 +114,7 @@ public:
|
|||
// FIXME: This should take glyph spacing into account, no?
|
||||
int glyph_width() const { return font().glyph_width('x'); }
|
||||
|
||||
bool write_to_file(const String& path);
|
||||
bool write_to_file(const StringView& path);
|
||||
|
||||
bool has_selection() const { return m_selection.is_valid(); }
|
||||
String selected_text() const;
|
||||
|
@ -168,12 +167,12 @@ private:
|
|||
|
||||
public:
|
||||
Line();
|
||||
explicit Line(const String&);
|
||||
explicit Line(const StringView&);
|
||||
|
||||
const char* characters() const { return m_text.data(); }
|
||||
int length() const { return m_text.size() - 1; }
|
||||
int width(const Font&) const;
|
||||
void set_text(const String&);
|
||||
void set_text(const StringView&);
|
||||
void append(char);
|
||||
void prepend(char);
|
||||
void insert(int index, char);
|
||||
|
@ -197,11 +196,11 @@ private:
|
|||
const Line& current_line() const { return *m_lines[m_cursor.line()]; }
|
||||
GTextPosition text_position_at(const Point&) const;
|
||||
void insert_at_cursor(char);
|
||||
void insert_at_cursor(const String&);
|
||||
void insert_at_cursor(const StringView&);
|
||||
int ruler_width() const;
|
||||
Rect ruler_content_rect(int line) const;
|
||||
void toggle_selection_if_needed_for_event(const GKeyEvent&);
|
||||
void insert_at_cursor_or_replace_selection(const String&);
|
||||
void insert_at_cursor_or_replace_selection(const StringView&);
|
||||
void delete_selection();
|
||||
void did_update_selection();
|
||||
int content_x_for_position(const GTextPosition&) const;
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#include <LibGUI/GToolBar.h>
|
||||
#include <LibGUI/GAction.h>
|
||||
#include <LibGUI/GBoxLayout.h>
|
||||
#include <LibGUI/GButton.h>
|
||||
#include <LibGUI/GAction.h>
|
||||
#include <LibGUI/GPainter.h>
|
||||
#include <LibGUI/GToolBar.h>
|
||||
|
||||
GToolBar::GToolBar(GWidget* parent)
|
||||
: GWidget(parent)
|
||||
|
@ -32,7 +32,7 @@ void GToolBar::add_action(Retained<GAction>&& action)
|
|||
button->set_icon(item->action->icon());
|
||||
else
|
||||
button->set_text(item->action->text());
|
||||
button->on_click = [raw_action_ptr] (const GButton&) {
|
||||
button->on_click = [raw_action_ptr](const GButton&) {
|
||||
raw_action_ptr->activate();
|
||||
};
|
||||
|
||||
|
@ -54,7 +54,7 @@ public:
|
|||
set_background_color(Color::White);
|
||||
set_preferred_size({ 8, 22 });
|
||||
}
|
||||
virtual ~SeparatorWidget() override { }
|
||||
virtual ~SeparatorWidget() override {}
|
||||
|
||||
virtual void paint_event(GPaintEvent& event) override
|
||||
{
|
||||
|
|
|
@ -21,8 +21,7 @@ private:
|
|||
virtual void paint_event(GPaintEvent&) override;
|
||||
|
||||
struct Item {
|
||||
enum Type
|
||||
{
|
||||
enum Type {
|
||||
Invalid,
|
||||
Separator,
|
||||
Action
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include <LibGUI/GTreeView.h>
|
||||
#include <LibGUI/GPainter.h>
|
||||
#include <LibGUI/GScrollBar.h>
|
||||
#include <LibGUI/GTreeView.h>
|
||||
|
||||
//#define DEBUG_ITEM_RECTS
|
||||
|
||||
|
@ -39,17 +39,17 @@ GModelIndex GTreeView::index_at_content_position(const Point& position, bool& is
|
|||
{
|
||||
is_toggle = false;
|
||||
if (!model())
|
||||
return { };
|
||||
return {};
|
||||
GModelIndex result;
|
||||
traverse_in_paint_order([&] (const GModelIndex& index, const Rect& rect, const Rect& toggle_rect, int) {
|
||||
traverse_in_paint_order([&](const GModelIndex& index, const Rect& rect, const Rect& toggle_rect, int) {
|
||||
if (rect.contains(position)) {
|
||||
result = index;
|
||||
return IterationDecision::Abort;
|
||||
return IterationDecision::Break;
|
||||
}
|
||||
if (toggle_rect.contains(position)) {
|
||||
result = index;
|
||||
is_toggle = true;
|
||||
return IterationDecision::Abort;
|
||||
return IterationDecision::Break;
|
||||
}
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
|
@ -88,7 +88,7 @@ void GTreeView::traverse_in_paint_order(Callback callback) const
|
|||
int indent_level = 0;
|
||||
int y_offset = 0;
|
||||
|
||||
Function<IterationDecision(const GModelIndex&)> traverse_index = [&] (const GModelIndex& index) {
|
||||
Function<IterationDecision(const GModelIndex&)> traverse_index = [&](const GModelIndex& index) {
|
||||
int row_count_at_index = model.row_count(index);
|
||||
if (index.is_valid()) {
|
||||
auto& metadata = ensure_metadata_for_index(index);
|
||||
|
@ -104,8 +104,8 @@ void GTreeView::traverse_in_paint_order(Callback callback) const
|
|||
toggle_rect = { toggle_x, rect.y(), toggle_size(), toggle_size() };
|
||||
toggle_rect.center_vertically_within(rect);
|
||||
}
|
||||
if (callback(index, rect, toggle_rect, indent_level) == IterationDecision::Abort)
|
||||
return IterationDecision::Abort;
|
||||
if (callback(index, rect, toggle_rect, indent_level) == IterationDecision::Break)
|
||||
return IterationDecision::Break;
|
||||
y_offset += item_height();
|
||||
// NOTE: Skip traversing children if this index is closed!
|
||||
if (!metadata.open)
|
||||
|
@ -115,8 +115,8 @@ void GTreeView::traverse_in_paint_order(Callback callback) const
|
|||
++indent_level;
|
||||
int row_count = model.row_count(index);
|
||||
for (int i = 0; i < row_count; ++i) {
|
||||
if (traverse_index(model.index(i, 0, index)) == IterationDecision::Abort)
|
||||
return IterationDecision::Abort;
|
||||
if (traverse_index(model.index(i, 0, index)) == IterationDecision::Break)
|
||||
return IterationDecision::Break;
|
||||
}
|
||||
--indent_level;
|
||||
return IterationDecision::Continue;
|
||||
|
@ -139,7 +139,7 @@ void GTreeView::paint_event(GPaintEvent& event)
|
|||
auto& model = *this->model();
|
||||
auto visible_content_rect = this->visible_content_rect();
|
||||
|
||||
traverse_in_paint_order([&] (const GModelIndex& index, const Rect& rect, const Rect& toggle_rect, int indent_level) {
|
||||
traverse_in_paint_order([&](const GModelIndex& index, const Rect& rect, const Rect& toggle_rect, int indent_level) {
|
||||
if (!rect.intersects(visible_content_rect))
|
||||
return IterationDecision::Continue;
|
||||
#ifdef DEBUG_ITEM_RECTS
|
||||
|
@ -202,10 +202,10 @@ void GTreeView::scroll_into_view(const GModelIndex& a_index, Orientation orienta
|
|||
if (!a_index.is_valid())
|
||||
return;
|
||||
Rect found_rect;
|
||||
traverse_in_paint_order([&] (const GModelIndex& index, const Rect& rect, const Rect&, int) {
|
||||
traverse_in_paint_order([&](const GModelIndex& index, const Rect& rect, const Rect&, int) {
|
||||
if (index == a_index) {
|
||||
found_rect = rect;
|
||||
return IterationDecision::Abort;
|
||||
return IterationDecision::Break;
|
||||
}
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
|
@ -251,7 +251,7 @@ void GTreeView::update_content_size()
|
|||
{
|
||||
int height = 0;
|
||||
int width = 0;
|
||||
traverse_in_paint_order([&] (const GModelIndex&, const Rect& rect, const Rect&, int) {
|
||||
traverse_in_paint_order([&](const GModelIndex&, const Rect& rect, const Rect&, int) {
|
||||
width = max(width, rect.right());
|
||||
height += rect.height();
|
||||
return IterationDecision::Continue;
|
||||
|
@ -267,10 +267,10 @@ void GTreeView::keydown_event(GKeyEvent& event)
|
|||
if (event.key() == KeyCode::Key_Up) {
|
||||
GModelIndex previous_index;
|
||||
GModelIndex found_index;
|
||||
traverse_in_paint_order([&] (const GModelIndex& index, const Rect&, const Rect&, int) {
|
||||
traverse_in_paint_order([&](const GModelIndex& index, const Rect&, const Rect&, int) {
|
||||
if (index == cursor_index) {
|
||||
found_index = previous_index;
|
||||
return IterationDecision::Abort;
|
||||
return IterationDecision::Break;
|
||||
}
|
||||
previous_index = index;
|
||||
return IterationDecision::Continue;
|
||||
|
@ -284,10 +284,10 @@ void GTreeView::keydown_event(GKeyEvent& event)
|
|||
if (event.key() == KeyCode::Key_Down) {
|
||||
GModelIndex previous_index;
|
||||
GModelIndex found_index;
|
||||
traverse_in_paint_order([&] (const GModelIndex& index, const Rect&, const Rect&, int) {
|
||||
traverse_in_paint_order([&](const GModelIndex& index, const Rect&, const Rect&, int) {
|
||||
if (previous_index == cursor_index) {
|
||||
found_index = index;
|
||||
return IterationDecision::Abort;
|
||||
return IterationDecision::Break;
|
||||
}
|
||||
previous_index = index;
|
||||
return IterationDecision::Continue;
|
||||
|
|
|
@ -252,4 +252,3 @@ String GVariant::to_string() const
|
|||
}
|
||||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
|
||||
|
|
|
@ -27,8 +27,7 @@ public:
|
|||
void clear();
|
||||
~GVariant();
|
||||
|
||||
enum class Type
|
||||
{
|
||||
enum class Type {
|
||||
Invalid,
|
||||
Bool,
|
||||
Int,
|
||||
|
|
|
@ -2,13 +2,13 @@
|
|||
#include "GEvent.h"
|
||||
#include "GEventLoop.h"
|
||||
#include "GWindow.h"
|
||||
#include <LibGUI/GLayout.h>
|
||||
#include <AK/Assertions.h>
|
||||
#include <SharedGraphics/GraphicsBitmap.h>
|
||||
#include <LibGUI/GAction.h>
|
||||
#include <LibGUI/GPainter.h>
|
||||
#include <LibGUI/GApplication.h>
|
||||
#include <LibGUI/GLayout.h>
|
||||
#include <LibGUI/GMenu.h>
|
||||
#include <LibGUI/GPainter.h>
|
||||
#include <SharedGraphics/GraphicsBitmap.h>
|
||||
#include <unistd.h>
|
||||
|
||||
GWidget::GWidget(GWidget* parent)
|
||||
|
@ -116,7 +116,7 @@ void GWidget::handle_paint_event(GPaintEvent& event)
|
|||
#endif
|
||||
}
|
||||
paint_event(event);
|
||||
for_each_child_widget([&] (auto& child) {
|
||||
for_each_child_widget([&](auto& child) {
|
||||
if (!child.is_visible())
|
||||
return IterationDecision::Continue;
|
||||
if (child.relative_rect().intersects(event.rect())) {
|
||||
|
@ -418,7 +418,7 @@ void GWidget::invalidate_layout()
|
|||
if (m_layout_dirty)
|
||||
return;
|
||||
m_layout_dirty = true;
|
||||
deferred_invoke([this] (auto&) {
|
||||
deferred_invoke([this](auto&) {
|
||||
m_layout_dirty = false;
|
||||
auto* w = window();
|
||||
if (!w)
|
||||
|
@ -472,7 +472,7 @@ void GWidget::move_to_front()
|
|||
return;
|
||||
if (parent->children().size() == 1)
|
||||
return;
|
||||
parent->children().remove_first_matching([this] (auto& entry) {
|
||||
parent->children().remove_first_matching([this](auto& entry) {
|
||||
return entry == this;
|
||||
});
|
||||
parent->children().append(this);
|
||||
|
@ -486,7 +486,7 @@ void GWidget::move_to_back()
|
|||
return;
|
||||
if (parent->children().size() == 1)
|
||||
return;
|
||||
parent->children().remove_first_matching([this] (auto& entry) {
|
||||
parent->children().remove_first_matching([this](auto& entry) {
|
||||
return entry == this;
|
||||
});
|
||||
parent->children().prepend(this);
|
||||
|
|
|
@ -17,23 +17,19 @@ class GLayout;
|
|||
class GMenu;
|
||||
class GWindow;
|
||||
|
||||
enum class SizePolicy
|
||||
{
|
||||
enum class SizePolicy {
|
||||
Fixed,
|
||||
Fill
|
||||
};
|
||||
enum class Orientation
|
||||
{
|
||||
enum class Orientation {
|
||||
Horizontal,
|
||||
Vertical
|
||||
};
|
||||
enum class HorizontalDirection
|
||||
{
|
||||
enum class HorizontalDirection {
|
||||
Left,
|
||||
Right
|
||||
};
|
||||
enum class VerticalDirection
|
||||
{
|
||||
enum class VerticalDirection {
|
||||
Up,
|
||||
Down
|
||||
};
|
||||
|
@ -56,7 +52,7 @@ public:
|
|||
|
||||
bool has_tooltip() const { return !m_tooltip.is_empty(); }
|
||||
String tooltip() const { return m_tooltip; }
|
||||
void set_tooltip(const String& tooltip) { m_tooltip = tooltip; }
|
||||
void set_tooltip(const StringView& tooltip) { m_tooltip = tooltip; }
|
||||
|
||||
bool is_enabled() const { return m_enabled; }
|
||||
void set_enabled(bool);
|
||||
|
@ -203,6 +199,7 @@ public:
|
|||
}
|
||||
|
||||
virtual bool is_radio_button() const { return false; }
|
||||
virtual bool is_abstract_button() const { return false; }
|
||||
|
||||
private:
|
||||
virtual bool is_widget() const final { return true; }
|
||||
|
|
|
@ -2,12 +2,12 @@
|
|||
#include "GEvent.h"
|
||||
#include "GEventLoop.h"
|
||||
#include "GWidget.h"
|
||||
#include <SharedGraphics/GraphicsBitmap.h>
|
||||
#include <LibGUI/GPainter.h>
|
||||
#include <AK/HashMap.h>
|
||||
#include <LibC/stdio.h>
|
||||
#include <LibC/stdlib.h>
|
||||
#include <LibC/unistd.h>
|
||||
#include <AK/HashMap.h>
|
||||
#include <LibGUI/GPainter.h>
|
||||
#include <SharedGraphics/GraphicsBitmap.h>
|
||||
|
||||
//#define UPDATE_COALESCING_DEBUG
|
||||
|
||||
|
@ -49,6 +49,17 @@ void GWindow::close()
|
|||
delete_later();
|
||||
}
|
||||
|
||||
void GWindow::move_to_front()
|
||||
{
|
||||
if (!m_window_id)
|
||||
return;
|
||||
|
||||
WSAPI_ClientMessage request;
|
||||
request.type = WSAPI_ClientMessage::Type::MoveWindowToFront;
|
||||
request.window_id = m_window_id;
|
||||
GEventLoop::post_message_to_server(request);
|
||||
}
|
||||
|
||||
void GWindow::show()
|
||||
{
|
||||
if (m_window_id)
|
||||
|
@ -93,7 +104,7 @@ void GWindow::hide()
|
|||
m_front_bitmap = nullptr;
|
||||
}
|
||||
|
||||
void GWindow::set_title(const String& title)
|
||||
void GWindow::set_title(const StringView& title)
|
||||
{
|
||||
m_title_when_windowless = title;
|
||||
if (!m_window_id)
|
||||
|
@ -224,7 +235,7 @@ void GWindow::event(CEvent& event)
|
|||
auto rect = rects.first();
|
||||
if (rect.is_empty() || created_new_backing_store) {
|
||||
rects.clear();
|
||||
rects.append({ { }, paint_event.window_size() });
|
||||
rects.append({ {}, paint_event.window_size() });
|
||||
}
|
||||
|
||||
for (auto& rect : rects)
|
||||
|
@ -325,10 +336,10 @@ void GWindow::event(CEvent& event)
|
|||
m_back_bitmap = nullptr;
|
||||
if (!m_pending_paint_event_rects.is_empty()) {
|
||||
m_pending_paint_event_rects.clear_with_capacity();
|
||||
m_pending_paint_event_rects.append({ { }, new_size });
|
||||
m_pending_paint_event_rects.append({ {}, new_size });
|
||||
}
|
||||
m_rect_when_windowless = { { }, new_size };
|
||||
m_main_widget->set_relative_rect({ { }, new_size });
|
||||
m_rect_when_windowless = { {}, new_size };
|
||||
m_main_widget->set_relative_rect({ {}, new_size });
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -421,7 +432,7 @@ void GWindow::update(const Rect& a_rect)
|
|||
}
|
||||
|
||||
if (m_pending_paint_event_rects.is_empty()) {
|
||||
deferred_invoke([this] (auto&) {
|
||||
deferred_invoke([this](auto&) {
|
||||
auto rects = move(m_pending_paint_event_rects);
|
||||
if (rects.is_empty())
|
||||
return;
|
||||
|
@ -452,7 +463,7 @@ void GWindow::set_main_widget(GWidget* widget)
|
|||
if (m_main_widget->vertical_size_policy() == SizePolicy::Fixed)
|
||||
new_window_rect.set_height(m_main_widget->preferred_size().height());
|
||||
set_rect(new_window_rect);
|
||||
m_main_widget->set_relative_rect({ { }, new_window_rect.size() });
|
||||
m_main_widget->set_relative_rect({ {}, new_window_rect.size() });
|
||||
m_main_widget->set_window(this);
|
||||
if (m_main_widget->accepts_focus())
|
||||
m_main_widget->set_focus(true);
|
||||
|
@ -597,7 +608,7 @@ void GWindow::wm_event(GWMEvent&)
|
|||
{
|
||||
}
|
||||
|
||||
void GWindow::set_icon_path(const String& path)
|
||||
void GWindow::set_icon_path(const StringView& path)
|
||||
{
|
||||
if (m_icon_path == path)
|
||||
return;
|
||||
|
@ -625,14 +636,14 @@ void GWindow::start_wm_resize()
|
|||
Vector<GWidget*> GWindow::focusable_widgets() const
|
||||
{
|
||||
if (!m_main_widget)
|
||||
return { };
|
||||
return {};
|
||||
|
||||
Vector<GWidget*> collected_widgets;
|
||||
|
||||
Function<void(GWidget&)> collect_focusable_widgets = [&] (GWidget& widget) {
|
||||
Function<void(GWidget&)> collect_focusable_widgets = [&](GWidget& widget) {
|
||||
if (widget.accepts_focus())
|
||||
collected_widgets.append(&widget);
|
||||
widget.for_each_child_widget([&] (auto& child) {
|
||||
widget.for_each_child_widget([&](auto& child) {
|
||||
if (!child.is_visible())
|
||||
return IterationDecision::Continue;
|
||||
if (!child.is_enabled())
|
||||
|
|
|
@ -13,8 +13,7 @@ class GPainter;
|
|||
class GWidget;
|
||||
class GWMEvent;
|
||||
|
||||
enum class GStandardCursor
|
||||
{
|
||||
enum class GStandardCursor {
|
||||
None = 0,
|
||||
Arrow,
|
||||
IBeam,
|
||||
|
@ -48,7 +47,7 @@ public:
|
|||
int window_id() const { return m_window_id; }
|
||||
|
||||
String title() const;
|
||||
void set_title(const String&);
|
||||
void set_title(const StringView&);
|
||||
|
||||
bool show_titlebar() const { return m_show_titlebar; };
|
||||
void set_show_titlebar(bool show) { m_show_titlebar = show; };
|
||||
|
@ -82,6 +81,7 @@ public:
|
|||
void show();
|
||||
void hide();
|
||||
void close();
|
||||
void move_to_front();
|
||||
|
||||
void start_wm_resize();
|
||||
|
||||
|
@ -121,7 +121,7 @@ public:
|
|||
void set_override_cursor(GStandardCursor);
|
||||
|
||||
String icon_path() const { return m_icon_path; }
|
||||
void set_icon_path(const String&);
|
||||
void set_icon_path(const StringView&);
|
||||
|
||||
Vector<GWidget*> focusable_widgets() const;
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
enum class GWindowType
|
||||
{
|
||||
enum class GWindowType {
|
||||
Invalid = 0,
|
||||
Normal,
|
||||
Menu,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue