Commit graph

407 commits

Author SHA1 Message Date
Marcus Nilsson
2f7dc29ab7 LibGUI/WindowServer: Add set_maximized IPC call
Add an IPC call to enable the client to manually maximize it's own
window.
2021-06-09 22:58:10 +02:00
Ali Mohammad Pur
50349de38c Meta: Disable -Wmaybe-uninitialized
It's prone to finding "technically uninitialized but can never happen"
cases, particularly in Optional<T> and Variant<Ts...>.
The general case seems to be that it cannot infer the dependency
between Variant's index (or Optional's boolean state) and a particular
alternative (or Optional's buffer) being untouched.
So it can flag cases like this:
```c++
if (index == StaticIndexForF)
    new (new_buffer) F(move(*bit_cast<F*>(old_buffer)));
```
The code in that branch can _technically_ make a partially initialized
`F`, but that path can never be taken since the buffer holding an
object of type `F` and the condition being true are correlated, and so
will never be taken _unless_ the buffer holds an object of type `F`.

This commit also removed the various 'diagnostic ignored' pragmas used
to work around this warning, as they no longer do anything.
2021-06-09 23:05:32 +04:30
Sam Atkins
6f92d1e639 LibGUI: Set TextEditor to unmodified after saving size=0 files
This fixes #7946

Previously, TextEditor::write_to_file() would not mark its document
as unmodified if the file size was 0. This caused a desync in the
Text Editor app between the window's is_modified state and the
TextEditor's. It's already noted in the comments of the app's
save action code that propagating the modified state automatically
would be good, and it would solve issues like this, but I'm not yet
familiar enough with the code to try a change like that.
2021-06-09 18:53:13 +02:00
Ali Mohammad Pur
7ac196974d Everywhere: Replace Vector<T*> with nonnull entries with Vector<T&> 2021-06-08 19:14:24 +02:00
Nick Miller
c3a60a5dcd LibGUI+SoundPlayer: Add Slider option to jump to cursor
When the cursor is clicked outside of the slider knob,
the current behavior is that it will step up or down by the
Slider page step amount.

This commit adds an option to jump the slider knob
directly to the where the mouse cursor is on mouse down events.

This behavior is disabled by default. It must be enabled with
`Slider::set_jump_to_cursor()`.

Jump to cursor is enabled in SoundPlayer since most music players
have this behavior.
2021-06-08 00:10:54 +04:30
Ali Mohammad Pur
71b4433b0d LibWeb+LibSyntax: Implement nested syntax highlighters
And use them to highlight javascript in HTML source.
This commit also changes how TextDocumentSpan::data is interpreted,
as it used to be an opaque pointer, but everyone stuffed an enum value
inside it, which made the values not unique to each highlighter;
that field is now a u64 serial id.
The syntax highlighters don't need to change their ways of stuffing
token types into that field, but a highlighter that calls another
nested highlighter needs to register the nested types for use with
token pairs.
2021-06-07 14:45:49 +04:30
dylanbobb
e24f1dfbe1 LibGUI: Don't delete within a line if the line is empty 2021-06-06 11:25:59 +02:00
Ali Mohammad Pur
51c2c69357 AK+Everywhere: Disallow constructing Functions from incompatible types
Previously, AK::Function would accept _any_ callable type, and try to
call it when called, first with the given set of arguments, then with
zero arguments, and if all of those failed, it would simply not call the
function and **return a value-constructed Out type**.
This lead to many, many, many hard to debug situations when someone
forgot a `const` in their lambda argument types, and many cases of
people taking zero arguments in their lambdas to ignore them.
This commit reworks the Function interface to not include any such
surprising behaviour, if your function instance is not callable with
the declared argument set of the Function, it can simply not be
assigned to that Function instance, end of story.
2021-06-06 00:27:30 +04:30
Marcus Nilsson
94551149d1 TreeView: Don't try to move cursor with invalid index
When clicking on the TreeView in profiler without selecting a node and
then pressing up or pgup, cursor_index was in an invalid state. Instead
select the first node in the index.
2021-06-05 11:27:05 +02:00
Max Wipfli
cb5a50d3f7 LibGUI: Fix off-by-one error in Lexer tokens
This changes the INI and GML lexers to conform to the now-fixed
rendering of syntax highlighting spans in GUI::TextEditor.

The other user of GMLToken::m_end, GMLAutocompleteProvider, has been
modified to take into account that end position columns have been
incremented by one.
2021-06-05 00:32:28 +04:30
Max Wipfli
e7b5dbe1ac LibGUI: Use CharacterTypes.h and constexpr functions in {INI,GML}Lexer 2021-06-05 00:32:28 +04:30
Max Wipfli
e10278402f LibGUI: Use east const style in {INI,GML}Lexer.{cpp,h} 2021-06-05 00:32:28 +04:30
Max Wipfli
a819f98956 LibGUI: Fix off-by-one error in rendering of highlighted text
This fixes an off-by-one error in TextEditor's rendering of the syntax
highlighting as generated by Syntax::Highlighter and its subclasses.

Before, a single character span was e.g. (0-3) to (0-3), but this was
considered invalid by GUI::TextRange. Now, a single character span would
be e.g. (0-3) to (0-4).

This fix requires all Syntax::Highlighter subclasses to be adjusted, as
they all relied on the previous implementation. This will then also fix
a bug where single-character HTML tags wouldn't be highlighted.
2021-06-05 00:32:28 +04:30
Marcus Nilsson
5a8cc85328 LibGUI/FileIconProvider: Return s_file_icon when stat() fails
Previously when using icon_for_path(), without specifying t_mode, on an
anonymous file it would return an empty Icon causing problems down the
line. Instead return the s_file_icon when stat fails.
2021-06-03 17:43:20 +01:00
Max Wipfli
bc8d16ad28 Everywhere: Replace ctype.h to avoid narrowing conversions
This replaces ctype.h with CharacterType.h everywhere I could find
issues with narrowing conversions. While using it will probably make
sense almost everywhere in the future, the most critical places should
have been addressed.
2021-06-03 13:31:46 +02:00
Brian Gianforcaro
06df26da67 LibGUI: Hide TextEditor dbgln spew under TEXTEDITOR_DEBUG 2021-06-03 11:21:38 +01:00
Matthew B. Jones
e7cfa9bf8e
LibGUI: Properly wrap multiple lines in IconView search highlighting 2021-06-03 08:32:31 +01:00
Matthew Jones
ef92493aba LibGUI: ComboBox now goes upwards when running out of room to render 2021-06-03 08:24:18 +02:00
Matthew Jones
36a1162eb8 LibGUI: ComboBox now correctly sizes height in relation to taskbar 2021-06-03 08:23:45 +02:00
Matthew Jones
6c520fab87 LibGUI: Desktop.h should get actual value from TaskbarWindow.h 2021-06-03 08:23:45 +02:00
Matthew Jones
af72b5ec82 LibGUI: Show pressed state for Space and Return key events
Also allows the user to press Esc while the button is being pressed
to cancel the button action.
2021-06-03 00:33:26 +01:00
Matthew Jones
ea4116f5bd LibGUI+LibGfx+WindowServer: Sanity check window size dimensions
Previous to this commit, if a `Window` wanted to set its width or height
greater than `INT16_MAX` (32768), both the application owning the Window
and the WindowServer would crash.

The root of this issue is that `size_would_overflow` check in `Bitmap`
has checks for `INT16_MAX`, and `Window.cpp:786` that is called by
`Gfx::Bitmap::create_with_anonymous_buffer` would get null back, then
causing a chain of events resulting in crashes.

Crashes can still occur but with `VERIFY` and `did_misbehave` the
causes of the crash can be more readily identified.
2021-06-02 23:59:57 +01:00
Matthew Jones
f0e9fd09b4 LibGUI: Tooltip no longer exceeds screen width, now truncates 2021-06-02 22:50:51 +01:00
Matthew Jones
123848f0c1 LibGUI: Fixes Widget->set_visible(false) still maintains focus bug
When setting a Widget->set_visible(false), if that Widget->has_focus()
it will continue to have focus, even though it's not visible to the user
anymore.

Now calling Widget->set_visible(false) will remove focus from the Widget
if it had focus, and the Window will give focus back to the Widget
that had it previously, if there was one.
2021-06-02 18:22:05 +02:00
Marcus Nilsson
11fa3e4f92 Terminal/LibGUI::TextEditor: Add shift+return to search forwards
This adds support for shift+return key combo in single line TextEditor
fields. Used in this case for searching backwards/forwards in the
Terminal find window.
2021-06-02 18:08:56 +02:00
Andreas Kling
12a42edd13 Everywhere: codepoint => code point 2021-06-01 10:01:11 +02:00
Max Wipfli
628c7f094f LibGUI+Shell+bt+ls: Use proper APIs for creating file URLs
This patch replaces ad-hoc generation of file URL strings with using
URL::create_with_file_scheme().
2021-06-01 09:28:05 +02:00
Itamar
8f6b496fed LibGUI: Add a FIXME about race in AutocompleteBox::apply_suggestion() 2021-06-01 08:28:27 +02:00
Itamar
7c2941d4ea LibGUI: Check that AutocompleteBox's selection row is valid
Previously we didn't check that the selection's row index is in a valid
range before attempting to access its data via the model.

This could cause an out-of-bounds access to the model's Vector of
suggestions.

I think this should fix #7404, but I can't verify it does because
I wasn't able to reproduce it on my machine.
2021-06-01 08:28:27 +02:00
Jelle Raaijmakers
7a4445a1fe LibGUI/TreeView: Select parent on collapse
When collapsing a tree that contains the current selection, the parent
node becomes selected instead.
2021-06-01 08:22:51 +02:00
Linus Groh
a4bd29828c LibGUI: Replace fprintf(stderr)/printf() with warnln()/dbgln() 2021-05-31 17:43:54 +01:00
Andreas Kling
460c0f9847 LibGUI: Don't scroll TreeView horizontally to bring index into view
This behavior was really irritating and basically never what you wanted
so let's stop doing it.
2021-05-30 09:28:19 +02:00
Andreas Kling
42b27d9f87 LibGUI: Avoid a bunch of virtual calls during TreeView painting
The index of the tree column will not change while painting.
Neither will the number of columsn. So avoid a whole bunch of virtual
function calls by caching these two values at the start of painting.
2021-05-30 09:05:37 +02:00
Jelle Raaijmakers
80a84f726e LibGUI/TreeView: Implement Home/End/PageUp/PageDn navigation
This adds an implementation for the Home, End, Page Up and Page Down
cursor movements for TreeView.

Also, the Up and Down movement implementations are replaced by a more
efficient traversal mechanism: whereas the old code would walk over all
visible nodes every time, the new code only evaluates relevant sibling
and parent indices.
2021-05-29 21:58:51 +04:30
Mart G
07e3934f01 LibGUI: Distribute remaining pixels in BoxLayout to fill the entire area
Previously, the layout algorithm preferred to give every item an equally
sized slice of the remaining space. This meant that not the entire area
was used when the remaining size did not divide evenly by the number of
items. This caused, for example, the ResizeCorner in HexEditor to be a
couple of pixels left of the actual corner for some sizes of the window.

Now, the remaining pixels are distributed on a first come, first served
basis. However, only one pixel is distributed at a time. This means
items towards the left might me a pixel larger than their siblings
towards the right.
2021-05-29 15:50:04 +02:00
Ali Mohammad Pur
3f5eb6446b LibGUI: Make HeaderView act only on the visible sections
i.e. Drawing them, or handling mouse events on them.
Fixes #7505.
2021-05-29 13:31:41 +04:30
Jesse Buhagiar
786275feb8 LibGUI: Add u64 type to LibGUI::Variant
`uint` has also been more appropriately renamed to
u32.
2021-05-28 16:37:25 +01:00
ry-sev
8146543a43 LibGUI+TextEditor: Add the calculation of selected words
This moves the calculation of selected words that was originally
in the TextEditor application to TextEditor in LibGUI.
This allows all applications with text editors to get
this number without having to calculating it themselves.
2021-05-27 09:05:39 +01:00
Andreas Kling
7a24a60e72 LibGUI: Paint some knurling in the middle of GUI::Splitter
This makes splitters stand out visually so you can actually spot them.
Before this, you had to guess/know where they were, which was weird.

The look of the knurling is the same as GUI::ResizeCorner, to build on
the established visual language.
2021-05-26 22:17:47 +02:00
Andreas Kling
89272e810a LibGUI: Have GUI::Splitter track all grabbable areas
Instead of computing the grabbable areas on the fly in mouse event
handlers, we now figure out which parts of the splitter are grabbable
when something moves around, and then remember it.

This makes the code a lot easier to follow.
2021-05-26 22:17:47 +02:00
Jelle Raaijmakers
2c772d1848 LibGUI/AbstractView: Remove on_selection
Since the introduction of multi-select, we have had both `on_selection`
and `on_selection_change`, the latter of which was only invoked when a
change in selection came in through the model.

This removes `AbstractView::on_selection` and replaces it usage with
the more explicit `on_selection_change` everywhere.
2021-05-26 17:39:13 +04:30
Jelle Raaijmakers
dbbc583860 LibGUI/AbstractView: Expose activates_on_selection 2021-05-24 23:31:42 +04:30
Jean-Baptiste Boric
e4394b1605 LibGfx: Use anonymous buffer instead of raw anon_fd for Gfx::Bitmap
Instead of using a low-level, proprietary API inside LibGfx, let's use
Core::AnonymousBuffer which already abstracts anon_fd and offers a
higher-level API too.
2021-05-24 13:31:01 +02:00
Andreas Kling
a1e133cc6b LibCore: Make ProcessStatisticsReader return results in a Vector
The HashMap API was overkill and made using this less ergonomic than
it should be.
2021-05-23 11:10:15 +02:00
Andreas Kling
a345a1f4a1 Userland: Mark subclasses of IPC::{Client,Server}Connection final 2021-05-23 09:53:55 +02:00
Andreas Kling
c1c252ddb2 LibIPC: Remove unnecessary IPC::ServerConnection::handshake()
This is no longer used by any of our IPC pairs.
2021-05-23 09:53:55 +02:00
Andreas Kling
2eceabdcfd LibGUI: Handle fast_greet stuff in WindowServerConnection constructor
Move the from handshake() to the constructor (and move the constructor
out-of-line while we're at it.)

This prepares getting rid of the handshake() mechanism since this is
the only remaining user.
2021-05-23 09:53:55 +02:00
Andreas Kling
78b57fcea3 NotificationServer: Remove unnecessary greet() message 2021-05-23 09:53:55 +02:00
Carlos César Neves Enumo
76a07b31e4 TextEditor: Prevent pasting with empty clipboard
Prevent erasing selected text when pasting with empty clipboard
2021-05-22 23:23:30 +02:00
Andreas Kling
3dfc3e362b LibGUI: Make GUI::Variant stringify floats with 2 decimals
The extremely high default precision was obnoxious in user interfaces.
2021-05-22 23:08:23 +02:00