Skip to content

Commit

Permalink
MORPHOS: Add native file browser via Asl (scummvm#2574)
Browse files Browse the repository at this point in the history
MORPHOS: Add native file browser via Asl
  • Loading branch information
BeWorld2018 authored Oct 31, 2020
1 parent 6e5a81b commit a434791
Show file tree
Hide file tree
Showing 5 changed files with 170 additions and 2 deletions.
112 changes: 112 additions & 0 deletions backends/dialogs/morphos/morphos-dialogs.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/

#define FORBIDDEN_SYMBOL_EXCEPTION_FILE
#define FORBIDDEN_SYMBOL_EXCEPTION_unistd_h
#define FORBIDDEN_SYMBOL_EXCEPTION_time_h
#define FORBIDDEN_SYMBOL_EXCEPTION_strdup
#include "common/scummsys.h"

#if defined(__MORPHOS__) && defined(USE_SYSDIALOGS)

#include "backends/dialogs/morphos/morphos-dialogs.h"

#include "common/config-manager.h"
#include "common/encoding.h"
#include "common/translation.h"

#include <proto/exec.h>
#include <proto/dos.h>
#define __NOLIBBASE__
#include <proto/asl.h>
#include <proto/charsets.h>

char *MorphosDialogManager::utf8ToLocal(char *in) {

if (!in) {
return strdup("");
}

struct Library *CharsetsBase = OpenLibrary("charsets.library", 0);
if (CharsetsBase) {

LONG dstmib = GetSystemCharset(NULL, 0);
if (dstmib != MIBENUM_INVALID) {
LONG dstlen = GetByteSize((APTR)in, -1, MIBENUM_UTF_8, dstmib);
char *out = (char *)malloc(dstlen + 1);
if (out) {
if (ConvertTagList((APTR)in, -1, (APTR)out, -1, MIBENUM_UTF_8, dstmib, NULL) != -1) {
return out;
}
free(out);
}
}
CloseLibrary(CharsetsBase);
}

return strdup(in);
}

Common::DialogManager::DialogResult MorphosDialogManager::showFileBrowser(const Common::U32String &title, Common::FSNode &choice, bool isDirBrowser) {

DialogResult result = kDialogCancel;
char pathBuffer[PATH_MAX];
Common::String utf8Title = title.encode();
struct Library *AslBase = OpenLibrary(AslName, 39);

if (AslBase) {

struct FileRequester *fr = NULL;

if (ConfMan.hasKey("browser_lastpath")) {
strncpy(pathBuffer, ConfMan.get("browser_lastpath").c_str(), sizeof(pathBuffer) - 1);
}

fr = (struct FileRequester *)AllocAslRequestTags(ASL_FileRequest, TAG_DONE);

if (!fr)
return result;

char *newTitle = utf8ToLocal((char *)utf8Title.c_str());

if (AslRequestTags(fr, ASLFR_TitleText, (IPTR)newTitle, ASLFR_RejectIcons, TRUE, ASLFR_InitialDrawer, (IPTR)pathBuffer, ASLFR_DrawersOnly, (isDirBrowser ? TRUE : FALSE), TAG_DONE)) {

if (strlen(fr->fr_Drawer) < sizeof(pathBuffer)) {
strncpy(pathBuffer, fr->fr_Drawer, sizeof(pathBuffer));
if (!isDirBrowser) {
AddPart(pathBuffer, fr->fr_File, sizeof(pathBuffer));
}
choice = Common::FSNode(pathBuffer);
ConfMan.set("browser_lastpath", pathBuffer);
result = kDialogOk;
}
}

free(newTitle);
FreeAslRequest((APTR)fr);
CloseLibrary(AslBase);
}

return result;
}

#endif
41 changes: 41 additions & 0 deletions backends/dialogs/morphos/morphos-dialogs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/

#ifndef BACKEND_MORPHOS_DIALOGS_H
#define BACKEND_MORPHOS_DIALOGS_H

#if defined(__MORPHOS__) && defined(USE_SYSDIALOGS)

#include "common/fs.h"
#include "common/dialogs.h"

class MorphosDialogManager : public Common::DialogManager {
public:
virtual DialogResult showFileBrowser(const Common::U32String &title, Common::FSNode &choice, bool isDirBrowser);

private:
char *utf8ToLocal(char *in);
};

#endif

#endif // BACKEND_MORPHOS_DIALOGS_H
3 changes: 2 additions & 1 deletion backends/module.mk
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,8 @@ endif
ifdef MORPHOS
MODULE_OBJS += \
fs/morphos/morphos-fs.o \
fs/morphos/morphos-fs-factory.o
fs/morphos/morphos-fs-factory.o \
dialogs/morphos/morphos-dialogs.o
endif

ifdef RISCOS
Expand Down
12 changes: 11 additions & 1 deletion backends/platform/sdl/morphos/morphos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#include "backends/platform/sdl/morphos/morphos.h"
#include "backends/fs/morphos/morphos-fs-factory.h"
#include "backends/dialogs/morphos/morphos-dialogs.h"
#include <proto/openurl.h>

void OSystem_MorphOS::init() {
Expand All @@ -34,12 +35,21 @@ void OSystem_MorphOS::init() {

// Invoke parent implementation of this method
OSystem_SDL::init();

#if defined(USE_SYSDIALOGS)
_dialogManager = new MorphosDialogManager();
#endif
}

bool OSystem_MorphOS::hasFeature(Feature f) {
if (f == kFeatureOpenUrl)
return true;


#if defined(USE_SYSDIALOGS)
if (f == kFeatureSystemBrowserDialog)
return true;
#endif

return OSystem_SDL::hasFeature(f);
}

Expand Down
4 changes: 4 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -5821,6 +5821,10 @@ if test "$_dialogs" = "no"; then
echo "no"
else
case $_host_os in
morphos*)
echo "morphos"
_dialogs=yes
;;
mingw*)
append_var LIBS "-lole32 -luuid"
echo "win32"
Expand Down

0 comments on commit a434791

Please sign in to comment.