diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 7ebd024..c8df19f 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -57,10 +57,24 @@
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
ReleaseStringUTFChars(env, kmlFilename, filenameUTF8);
+ TCHAR * urlContentSchemeFound = _tcsstr(szChosenCurrentKml, _T("content://"));
+ if(urlContentSchemeFound) {
+ _tcscpy(szEmuDirectory, szChosenCurrentKml);
+ TCHAR * filename = _tcsrchr(szChosenCurrentKml, _T('/'));
+ if(filename) {
+ *filename = _T('\0');
+ }
+ _tcscpy(szRomDirectory, szEmuDirectory);
+ } else {
+ _tcscpy(szEmuDirectory, "assets/calculators/");
+ _tcscpy(szRomDirectory, "assets/calculators/");
+ }
+
BOOL result = NewDocument();
chooseCurrentKmlMode = ChooseKmlMode_UNKNOWN;
diff --git a/app/src/main/cpp/win32-layer.c b/app/src/main/cpp/win32-layer.c
index a2c63e6..da2d706 100644
--- a/app/src/main/cpp/win32-layer.c
+++ b/app/src/main/cpp/win32-layer.c
@@ -1049,7 +1049,15 @@ BOOL InsertMenu(HMENU hMenu, UINT uPosition, UINT uFlags, UINT_PTR uIDNewItem, L
BOOL SetWindowPos(HWND hWnd, HWND hWndInsertAfter, int X, int Y, int cx, int cy, UINT uFlags) { return 0; }
BOOL IsRectEmpty(CONST RECT *lprc) { return 0; }
-BOOL WINAPI SetWindowOrgEx(HDC hdc, int x, int y, LPPOINT lppt) { return 0; }
+BOOL WINAPI SetWindowOrgEx(HDC hdc, int x, int y, LPPOINT lppt) {
+ if(lppt) {
+ lppt->x = hdc->windowOrigineX;
+ lppt->y = hdc->windowOrigineY;
+ }
+ hdc->windowOrigineX = x;
+ hdc->windowOrigineY = y;
+ return TRUE;
+}
// GDI
HGDIOBJ SelectObject(HDC hdc, HGDIOBJ h) {
@@ -1345,6 +1353,8 @@ BOOL StretchBlt(HDC hdcDest, int xDest, int yDest, int wDest, int hDest, HDC hdc
destinationStride = (float)(destinationBytes * ((destinationWidth * hBitmapDestination->bitmapInfoHeader->biBitCount + 31) / 32));
}
+ xDest -= hdcDest->windowOrigineX;
+ yDest -= hdcDest->windowOrigineY;
//https://softwareengineering.stackexchange.com/questions/148123/what-is-the-algorithm-to-copy-a-region-of-one-bitmap-into-a-region-in-another
float src_dx = (float)wSrc / (float)wDest;
diff --git a/app/src/main/cpp/win32-layer.h b/app/src/main/cpp/win32-layer.h
index b9f3ac7..776f558 100644
--- a/app/src/main/cpp/win32-layer.h
+++ b/app/src/main/cpp/win32-layer.h
@@ -634,6 +634,8 @@ struct _HDC{
HBITMAP selectedBitmap;
HPALETTE selectedPalette;
HPALETTE realizedPalette;
+ int windowOrigineX;
+ int windowOrigineY;
};
//typedef HANDLE HDC;
@@ -1070,6 +1072,8 @@ extern int lstrcmpi(LPCWSTR lpString1, LPCWSTR lpString2);
#define _tcsncpy wcsncpy
#define _tcscat wcscat
#define _tcsstr wcsstr
+#define _tcsrchr wcsrchr
+
#else
@@ -1093,6 +1097,7 @@ extern int lstrcmpi(LPCSTR lpString1, LPCSTR lpString2);
#define _tcsncpy strncpy
#define _tcscat strcat
#define _tcsstr strstr
+#define _tcsrchr strrchr
#endif // !UNICODE
diff --git a/app/src/main/java/org/emulator/forty/eight/MainActivity.java b/app/src/main/java/org/emulator/forty/eight/MainActivity.java
index 6c17047..7b3614a 100644
--- a/app/src/main/java/org/emulator/forty/eight/MainActivity.java
+++ b/app/src/main/java/org/emulator/forty/eight/MainActivity.java
@@ -557,7 +557,8 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
public void onClick(DialogInterface dialog, int which) {
if(which == lastIndex) {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
- intent.setType("file/*");
+ //intent.setType("file/*");
+ intent.setType("*/*");
startActivityForResult(intent, INTENT_PICK_KML_FILE);
} else {
String kmlScriptFilename = kmlScripts.get(which).filename;
@@ -819,7 +820,8 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
break;
case INTENT_PICK_KML_FILE:
Log.d(TAG, "onActivityResult INTENT_OBJECT_SAVE " + url);
- newFileFromKML(url);
+ String filePath = Utils.getFilePath(this, url);
+ newFileFromKML(filePath);
break;
default:
break;
@@ -864,7 +866,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
private String getFilenameFromURL(String url) {
String displayName = "";
try {
- displayName = SettingsActivity.getFileName(this, url);
+ displayName = Utils.getFileName(this, url);
} catch(Exception e) {
// Do nothing
}
diff --git a/app/src/main/java/org/emulator/forty/eight/SettingsActivity.java b/app/src/main/java/org/emulator/forty/eight/SettingsActivity.java
index adb1bfb..e1f8512 100644
--- a/app/src/main/java/org/emulator/forty/eight/SettingsActivity.java
+++ b/app/src/main/java/org/emulator/forty/eight/SettingsActivity.java
@@ -334,7 +334,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
String stringValue = value.toString();
String displayName = stringValue;
try {
- displayName = getFileName(getActivity(), stringValue);
+ displayName = Utils.getFileName(getActivity(), stringValue);
} catch(Exception e) {
}
preference.setSummary(displayName);
@@ -389,27 +389,4 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
final int takeFlags = data.getFlags() & (Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
getContentResolver().takePersistableUriPermission(uri, takeFlags);
}
-
- public static String getFileName(Context context, String url) {
- Uri uri = Uri.parse(url);
- String result = null;
- if (uri.getScheme().equals("content")) {
- Cursor cursor = context.getContentResolver().query(uri, null, null, null, null);
- try {
- if (cursor != null && cursor.moveToFirst()) {
- result = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME));
- }
- } finally {
- cursor.close();
- }
- }
- if (result == null) {
- result = uri.getPath();
- int cut = result.lastIndexOf('/');
- if (cut != -1) {
- result = result.substring(cut + 1);
- }
- }
- return result;
- }
}