Merge branch 'master' into jgrpp

# Conflicts:
#	cmake/SourceList.cmake
#	src/build_vehicle_gui.cpp
#	src/company_gui.cpp
#	src/console_cmds.cpp
#	src/depot_base.h
#	src/elrail.cpp
#	src/network/core/udp.cpp
#	src/network/network_admin.cpp
#	src/network/network_chat_gui.cpp
#	src/network/network_gui.cpp
#	src/network/network_server.cpp
#	src/newgrf.cpp
#	src/newgrf_engine.cpp
#	src/newgrf_railtype.cpp
#	src/newgrf_railtype.h
#	src/newgrf_storage.h
#	src/os/unix/crashlog_unix.cpp
#	src/rail.h
#	src/rail_cmd.cpp
#	src/rail_gui.cpp
#	src/road_cmd.cpp
#	src/road_map.h
#	src/saveload/labelmaps_sl.cpp
#	src/settings_gui.cpp
#	src/settings_type.h
#	src/sl/oldloader_sl.cpp
#	src/station_cmd.cpp
#	src/station_gui.cpp
#	src/table/settings/world_settings.ini
#	src/tests/test_script_admin.cpp
#	src/textfile_gui.cpp
#	src/toolbar_gui.cpp
#	src/train_cmd.cpp
#	src/tunnelbridge_cmd.cpp
#	src/vehicle_gui.cpp
#	src/widget.cpp
#	src/window.cpp
#	src/window_gui.h
#	src/window_type.h
This commit is contained in:
Jonathan G Rennison
2023-11-19 12:19:17 +00:00
230 changed files with 2458 additions and 1106 deletions

View File

@@ -32,6 +32,7 @@
#include "../../window_func.h"
#include "../../window_gui.h"
#include "../../spritecache.h"
#include "../../textbuf_type.h"
#include "../../toolbar_gui.h"
#include <array>
@@ -935,7 +936,7 @@ void CocoaDialog(const char *title, const char *message, const char *buttonLabel
const char *replace_range = NULL;
if (replacementRange.location != NSNotFound) {
/* Calculate the part to be replaced. */
insert_point = Utf8AdvanceByUtf16Units(_focused_window->GetFocusedText(), replacementRange.location);
insert_point = Utf8AdvanceByUtf16Units(_focused_window->GetFocusedTextbuf()->GetText(), replacementRange.location);
replace_range = Utf8AdvanceByUtf16Units(insert_point, replacementRange.length);
}
@@ -963,7 +964,7 @@ void CocoaDialog(const char *title, const char *message, const char *buttonLabel
if (replacementRange.location != NSNotFound) {
/* Calculate the part to be replaced. */
NSRange marked = [ self markedRange ];
insert_point = Utf8AdvanceByUtf16Units(_focused_window->GetFocusedText(), replacementRange.location + (marked.location != NSNotFound ? marked.location : 0u));
insert_point = Utf8AdvanceByUtf16Units(_focused_window->GetFocusedTextbuf()->GetText(), replacementRange.location + (marked.location != NSNotFound ? marked.location : 0u));
replace_range = Utf8AdvanceByUtf16Units(insert_point, replacementRange.length);
}
@@ -991,7 +992,9 @@ void CocoaDialog(const char *title, const char *message, const char *buttonLabel
{
if (!EditBoxInGlobalFocus()) return NSMakeRange(NSNotFound, 0);
NSUInteger start = CountUtf16Units(_focused_window->GetFocusedText(), _focused_window->GetCaret());
const Textbuf *text_buf = _focused_window->GetFocusedTextbuf();
const char *text = text_buf->GetText();
NSUInteger start = CountUtf16Units(text, text + text_buf->caretpos);
return NSMakeRange(start, 0);
}
@@ -1000,11 +1003,12 @@ void CocoaDialog(const char *title, const char *message, const char *buttonLabel
{
if (!EditBoxInGlobalFocus()) return NSMakeRange(NSNotFound, 0);
size_t mark_len;
const char *mark = _focused_window->GetMarkedText(&mark_len);
if (mark != nullptr) {
NSUInteger start = CountUtf16Units(_focused_window->GetFocusedText(), mark);
NSUInteger len = CountUtf16Units(mark, mark + mark_len);
const Textbuf *text_buf = _focused_window->GetFocusedTextbuf();
if (text_buf->markend != 0) {
const char *text = text_buf->GetText();
const char *mark = text + text_buf->markpos;
NSUInteger start = CountUtf16Units(text, mark);
NSUInteger len = CountUtf16Units(mark, text + text_buf->markend);
return NSMakeRange(start, len);
}
@@ -1017,8 +1021,7 @@ void CocoaDialog(const char *title, const char *message, const char *buttonLabel
{
if (!EditBoxInGlobalFocus()) return NO;
size_t len;
return _focused_window->GetMarkedText(&len) != nullptr;
return _focused_window->GetFocusedTextbuf()->markend != 0;
}
/** Get a string corresponding to the given range. */
@@ -1026,7 +1029,7 @@ void CocoaDialog(const char *title, const char *message, const char *buttonLabel
{
if (!EditBoxInGlobalFocus()) return nil;
NSString *s = [ NSString stringWithUTF8String:_focused_window->GetFocusedText() ];
NSString *s = [ NSString stringWithUTF8String:_focused_window->GetFocusedTextbuf()->GetText() ];
NSRange valid_range = NSIntersectionRange(NSMakeRange(0, [ s length ]), theRange);
if (actualRange != nullptr) *actualRange = valid_range;
@@ -1046,7 +1049,7 @@ void CocoaDialog(const char *title, const char *message, const char *buttonLabel
{
if (!EditBoxInGlobalFocus()) return [ [ [ NSAttributedString alloc ] initWithString:@"" ] autorelease ];
return [ [ [ NSAttributedString alloc ] initWithString:[ NSString stringWithUTF8String:_focused_window->GetFocusedText() ] ] autorelease ];
return [ [ [ NSAttributedString alloc ] initWithString:[ NSString stringWithUTF8String:_focused_window->GetFocusedTextbuf()->GetText() ] ] autorelease ];
}
/** Get the character that is rendered at the given point. */
@@ -1061,7 +1064,7 @@ void CocoaDialog(const char *title, const char *message, const char *buttonLabel
auto index = _focused_window->GetTextCharacterAtPosition(pt);
if (index == -1) return NSNotFound;
auto text = _focused_window->GetFocusedText();
auto text = _focused_window->GetFocusedTextbuf()->GetText();
return CountUtf16Units(text, text + index);
}
@@ -1070,9 +1073,10 @@ void CocoaDialog(const char *title, const char *message, const char *buttonLabel
{
if (!EditBoxInGlobalFocus()) return NSMakeRect(0, 0, 0, 0);
const char *focused_text = _focused_window->GetFocusedTextbuf()->GetText();
/* Convert range to UTF-8 string pointers. */
const char *start = Utf8AdvanceByUtf16Units(_focused_window->GetFocusedText(), aRange.location);
const char *end = aRange.length != 0 ? Utf8AdvanceByUtf16Units(_focused_window->GetFocusedText(), aRange.location + aRange.length) : start;
const char *start = Utf8AdvanceByUtf16Units(focused_text, aRange.location);
const char *end = aRange.length != 0 ? Utf8AdvanceByUtf16Units(focused_text, aRange.location + aRange.length) : start;
/* Get the bounding rect for the text range.*/
Rect r = _focused_window->GetTextBoundingRect(start, end);