From e727e462d87aedef67720b1ed15330e7c2e3afd7 Mon Sep 17 00:00:00 2001 From: elasota Date: Tue, 3 Nov 2020 18:37:08 -0500 Subject: [PATCH] Move save dialog to top of screen when using OSK. --- ApplicationResourcePatches/DITL/2007.json | 53 +++++++++++++++++++++++ ApplicationResourcePatches/manifest.json | 1 + PortabilityLayer/FileBrowserUI.cpp | 28 +++++++++++- 3 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 ApplicationResourcePatches/DITL/2007.json diff --git a/ApplicationResourcePatches/DITL/2007.json b/ApplicationResourcePatches/DITL/2007.json new file mode 100644 index 0000000..533ab3f --- /dev/null +++ b/ApplicationResourcePatches/DITL/2007.json @@ -0,0 +1,53 @@ +{ + "items" : + [ + { + "name" : "Okay", + "itemType" : "Button", + "pos" : [ 376, 208 ], + "size" : [ 58, 20 ], + "id" : 1, + "enabled" : true + }, + { + "name" : "Cancel", + "itemType" : "Button", + "pos" : [ 302, 208 ], + "size" : [ 58, 20 ], + "id" : 2, + "enabled" : true + }, + { + "name" : "", + "itemType" : "CustomControl", + "pos" : [ 17, 33 ], + "size" : [ 401, 154 ], + "id" : 2, + "enabled" : true + }, + { + "name" : "", + "itemType" : "CustomControl", + "pos" : [ 418, 32 ], + "size" : [ 16, 156 ], + "id" : 3, + "enabled" : true + }, + { + "name" : "", + "itemType" : "EditBox", + "pos" : [ 16, 208 ], + "size" : [ 270, 16 ], + "id" : 4, + "enabled" : true + }, + { + "name" : "^0", + "itemType" : "Label", + "pos" : [ 16, 16 ], + "size" : [ 418, 16 ], + "id" : 10, + "enabled" : true + } + ] +} \ No newline at end of file diff --git a/ApplicationResourcePatches/manifest.json b/ApplicationResourcePatches/manifest.json index f8f0a04..2ae2da2 100644 --- a/ApplicationResourcePatches/manifest.json +++ b/ApplicationResourcePatches/manifest.json @@ -9,6 +9,7 @@ "DITL/2004.json" : "ApplicationResourcePatches/DITL/2004.json", "DITL/2005.json" : "ApplicationResourcePatches/DITL/2005.json", "DITL/2006.json" : "ApplicationResourcePatches/DITL/2006.json", + "DITL/2007.json" : "ApplicationResourcePatches/DITL/2007.json", "PICT/1300.bmp" : "ApplicationResourcePatches/PICT/1300.bmp", "PICT/1301.bmp" : "ApplicationResourcePatches/PICT/1301.bmp", "PICT/1302.bmp" : "ApplicationResourcePatches/PICT/1302.bmp", diff --git a/PortabilityLayer/FileBrowserUI.cpp b/PortabilityLayer/FileBrowserUI.cpp index a994608..d9c8232 100644 --- a/PortabilityLayer/FileBrowserUI.cpp +++ b/PortabilityLayer/FileBrowserUI.cpp @@ -41,6 +41,8 @@ static const int kFileBrowserUIOpenDialogTemplateID = 2001; static const int kFileBrowserUISaveDialogTemplateID = 2002; static const int kFileBrowserUIOverwriteDialogTemplateID = 2003; static const int kFileBrowserUIBadNameDialogTemplateID = 2004; +static const int kFileBrowserUISaveDialogUnobstructiveTemplateID = 2007; + static const int kOverwriteNoButton = 1; static const int kOverwriteYesButton = 2; @@ -472,6 +474,12 @@ namespace PortabilityLayer int16_t FileBrowserUIImpl::PopUpAlert(const Rect &rect, int dialogResID, const DialogTextSubstitutions *substitutions) { + PortabilityLayer::HostSystemServices *sysServices = PortabilityLayer::HostSystemServices::GetInstance(); + + // Disable text input temporarily and restore it after + const bool wasTextInput = sysServices->IsTextInputEnabled(); + sysServices->SetTextInputEnabled(false); + PortabilityLayer::DialogManager *dialogManager = PortabilityLayer::DialogManager::GetInstance(); Dialog *dialog = dialogManager->LoadDialogFromTemplate(dialogResID, rect, true, false, 0, 0, PL_GetPutInFrontWindowPtr(), PSTR(""), substitutions); @@ -488,16 +496,29 @@ namespace PortabilityLayer dialog->Destroy(); + sysServices->SetTextInputEnabled(wasTextInput); + return hit; } bool FileBrowserUI::Prompt(Mode mode, VirtualDirectory_t dirID, char *path, size_t &outPathLength, size_t pathCapacity, const PLPasStr &initialFileName, const PLPasStr &promptText) { int dialogID = 0; + bool isObstructive = false; + int windowHeight = 272; if (mode == Mode_Open) dialogID = kFileBrowserUIOpenDialogTemplateID; else if (mode == Mode_Save) - dialogID = kFileBrowserUISaveDialogTemplateID; + { + if (PortabilityLayer::HostSystemServices::GetInstance()->IsTextInputObstructive()) + { + dialogID = kFileBrowserUISaveDialogUnobstructiveTemplateID; + windowHeight = 240; + isObstructive = true; + } + else + dialogID = kFileBrowserUISaveDialogTemplateID; + } else { assert(false); @@ -538,7 +559,7 @@ namespace PortabilityLayer dirCursor->Destroy(); const int scrollBarWidth = 16; - const Rect windowRect = Rect::Create(0, 0, 272, 450); + const Rect windowRect = Rect::Create(0, 0, windowHeight, 450); PortabilityLayer::WindowDef wdef = PortabilityLayer::WindowDef::Create(windowRect, PortabilityLayer::WindowStyleFlags::kAlert, true, 0, 0, PSTR("")); @@ -557,6 +578,9 @@ namespace PortabilityLayer Window *window = dialog->GetWindow(); + if (isObstructive) + window->SetPosition(PortabilityLayer::Vec2i(window->GetPosition().m_x, 6)); + DrawSurface *surface = window->GetDrawSurface(); const PortabilityLayer::DialogItem &firstItem = *dialog->GetItems().begin();