This commit is contained in:
dgis 2019-01-10 22:53:11 +00:00
parent 33686c480a
commit ced7132b0a
3 changed files with 73 additions and 47 deletions

View file

@ -12,7 +12,10 @@ NOT WORKING
- Debugger
TODO
- Add recent files
- If KML not found in OpenDocument, allow to choose a new one
- Improve loading errors
- Allows to see the errors in a log
- Improve button support with HDC operations
- Bug: Port1 is not enable from the state.e48 file!
- Option to allow rotation
- Option to auto hide the menu
@ -40,3 +43,5 @@ DONE
- Sound
- Bug: No refresh with the clock (Fix timers)
- Support 8bits images
- Add recent files
- Bug: Port2 not saved

View file

@ -34,10 +34,16 @@ struct timerEvent {
#define MAX_TIMER 10
struct timerEvent timerEvents[MAX_TIMER];
#define MAX_FILE_MAPPING_HANDLE 10
static HANDLE fileMappingHandles[MAX_FILE_MAPPING_HANDLE];
void win32Init() {
for (int i = 0; i < MAX_TIMER; ++i) {
timerEvents[i].valid = FALSE;
}
for (int i = 0; i < MAX_FILE_MAPPING_HANDLE; ++i) {
fileMappingHandles[i] = NULL;
}
}
VOID OutputDebugString(LPCSTR lpOutputString) {
@ -165,7 +171,7 @@ BOOL WriteFile(HANDLE hFile, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite,LPDWO
}
DWORD SetFilePointer(HANDLE hFile, LONG lDistanceToMove, PLONG lpDistanceToMoveHigh, DWORD dwMoveMethod) {
int moveMode;
int moveMode = FILE_BEGIN;
if(dwMoveMethod == FILE_BEGIN)
moveMode = SEEK_SET;
else if(dwMoveMethod == FILE_CURRENT)
@ -223,6 +229,7 @@ HANDLE CreateFileMapping(HANDLE hFile, LPSECURITY_ATTRIBUTES lpFileMappingAttrib
//https://msdn.microsoft.com/en-us/library/Aa366761(v=VS.85).aspx
LPVOID MapViewOfFile(HANDLE hFileMappingObject, DWORD dwDesiredAccess, DWORD dwFileOffsetHigh, DWORD dwFileOffsetLow, SIZE_T dwNumberOfBytesToMap) {
off_t offset = (dwFileOffsetHigh << 32) & dwFileOffsetLow;
LPVOID result = NULL;
if(hFileMappingObject->handleType == HANDLE_TYPE_FILE_MAPPING) {
int prot = PROT_NONE;
if (dwDesiredAccess & FILE_MAP_READ)
@ -232,19 +239,45 @@ LPVOID MapViewOfFile(HANDLE hFileMappingObject, DWORD dwDesiredAccess, DWORD dwF
hFileMappingObject->fileMappingAddress = mmap(NULL, hFileMappingObject->fileMappingSize,
prot, MAP_PRIVATE,
hFileMappingObject->fileDescriptor, offset);
return hFileMappingObject->fileMappingAddress;
} else if(hFileMappingObject->handleType == HANDLE_TYPE_FILE_MAPPING_ASSET) {
if (dwDesiredAccess & FILE_MAP_WRITE)
return NULL;
return (LPVOID) (AAsset_getBuffer(hFileMappingObject->fileAsset) + offset);
hFileMappingObject->fileMappingAddress = (LPVOID) (AAsset_getBuffer(hFileMappingObject->fileAsset) + offset);
}
return NULL;
if(hFileMappingObject->fileMappingAddress) {
for (int i = 0; i < MAX_FILE_MAPPING_HANDLE; ++i) {
if(!fileMappingHandles[i]) {
fileMappingHandles[i] = hFileMappingObject;
break;
}
}
}
result = hFileMappingObject->fileMappingAddress;
return result;
}
// https://msdn.microsoft.com/en-us/library/aa366882(v=vs.85).aspx
BOOL UnmapViewOfFile(LPCVOID lpBaseAddress) {
//TODO for HANDLE_TYPE_FILE_MAPPING/HANDLE_TYPE_FILE_MAPPING_ASSET
int result = munmap(lpBaseAddress, -1);
int result = -1;
for (int i = 0; i < MAX_FILE_MAPPING_HANDLE; ++i) {
HANDLE fileMappingHandle = fileMappingHandles[i];
if(fileMappingHandle && lpBaseAddress == fileMappingHandle->fileMappingAddress) {
if(fileMappingHandle->handleType == HANDLE_TYPE_FILE_MAPPING) {
// munmap does not seem to work, so:
off_t currentPosition = lseek(fileMappingHandle->fileDescriptor, 0, SEEK_CUR);
lseek(fileMappingHandle->fileDescriptor, 0, SEEK_SET);
write(fileMappingHandle->fileDescriptor, fileMappingHandle->fileMappingAddress, fileMappingHandle->fileMappingSize);
lseek(fileMappingHandle->fileDescriptor, currentPosition, SEEK_SET);
result = munmap(lpBaseAddress, fileMappingHandle->fileMappingSize);
} else if(fileMappingHandle->handleType == HANDLE_TYPE_FILE_MAPPING_ASSET) {
// No need to unmap
result = 0;
}
fileMappingHandles[i] = NULL;
break;
}
}
return result == 0;
}
@ -497,16 +530,12 @@ BOOL WINAPI CloseHandle(HANDLE hObject) {
return TRUE;
}
case HANDLE_TYPE_FILE_MAPPING: {
int closeResult = UnmapViewOfFile(hObject->fileMappingAddress);
if(closeResult == TRUE) {
hObject->handleType = HANDLE_TYPE_INVALID;
hObject->fileDescriptor = 0;
hObject->fileMappingSize = 0;
hObject->fileMappingAddress = NULL;
free(hObject);
return TRUE;
}
break;
hObject->handleType = HANDLE_TYPE_INVALID;
hObject->fileDescriptor = 0;
hObject->fileMappingSize = 0;
hObject->fileMappingAddress = NULL;
free(hObject);
return TRUE;
}
case HANDLE_TYPE_FILE_MAPPING_ASSET: {
hObject->handleType = HANDLE_TYPE_INVALID;

View file

@ -77,27 +77,12 @@ public class MainActivity extends AppCompatActivity
public static MainActivity mainActivity;
private static final String TAG = "MainActivity";
private MainScreenView mainScreenView;
private SharedPreferences sharedPreferences;
private SharedPreferences.OnSharedPreferenceChangeListener sharedPreferenceChangeListener;
private NavigationView navigationView;
private DrawerLayout drawer;
private final static int PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE = 2;
enum FileType {
PDF,
SVG,
JPG,
PNG
}
enum ExportType {
Share,
View,
Print
}
private int MRU_ID_START = 10000;
private int MAX_MRU = 5;
private LinkedHashMap<String, String> mruLinkedHashMap = new LinkedHashMap<String, String>(5, 1.0f, true) {
@ -123,7 +108,7 @@ public class MainActivity extends AppCompatActivity
}
});
drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer = findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
@ -141,8 +126,8 @@ public class MainActivity extends AppCompatActivity
mainActivity = this;
ViewGroup mainScreenContainer = (ViewGroup)findViewById(R.id.main_screen_container);
mainScreenView = new MainScreenView(this); //, currentProject);
ViewGroup mainScreenContainer = findViewById(R.id.main_screen_container);
MainScreenView mainScreenView = new MainScreenView(this);
// mainScreenView.setOnTouchListener(new View.OnTouchListener() {
// @Override
// public boolean onTouch(View view, MotionEvent motionEvent) {
@ -174,7 +159,7 @@ public class MainActivity extends AppCompatActivity
updateMRU();
updateFromPreferences(null, false);
sharedPreferenceChangeListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
SharedPreferences.OnSharedPreferenceChangeListener sharedPreferenceChangeListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
updateFromPreferences(key, true);
@ -195,7 +180,8 @@ public class MainActivity extends AppCompatActivity
if (action.equals(Intent.ACTION_VIEW)) {
documentToOpenUri = intent.getData();
if (documentToOpenUri != null) {
if(documentToOpenUri.getScheme().compareTo("file") == 0) {
String scheme = documentToOpenUri.getScheme();
if(scheme != null && scheme.compareTo("file") == 0) {
documentToOpenUrl = documentToOpenUri.getPath();
isFileAndNeedPermission = true;
} else
@ -211,7 +197,7 @@ public class MainActivity extends AppCompatActivity
}
//https://developer.android.com/guide/topics/providers/document-provider#permissions
if(documentToOpenUrl.length() > 0)
if(documentToOpenUrl != null && documentToOpenUrl.length() > 0)
try {
if(isFileAndNeedPermission
&& ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
@ -304,6 +290,7 @@ public class MainActivity extends AppCompatActivity
try {
makeUriPersistable(getIntent(), Uri.parse(lastDocumentUrl));
} catch (Exception e) {
// Do nothing
}
}
// return;
@ -1022,18 +1009,23 @@ public class MainActivity extends AppCompatActivity
void clipboardCopyText(String text) {
// Gets a handle to the clipboard service.
ClipboardManager clipboard = (ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("simple text", text);
// Set the clipboard's primary clip.
clipboard.setPrimaryClip(clip);
if(clipboard != null) {
ClipData clip = ClipData.newPlainText("simple text", text);
// Set the clipboard's primary clip.
clipboard.setPrimaryClip(clip);
}
}
String clipboardPasteText() {
ClipboardManager clipboard = (ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE);
if (clipboard.hasPrimaryClip()) {
ClipData.Item item = clipboard.getPrimaryClip().getItemAt(0);
// Gets the clipboard as text.
CharSequence pasteData = item.getText();
if(pasteData != null)
return pasteData.toString();
if (clipboard != null && clipboard.hasPrimaryClip()) {
ClipData clipData = clipboard.getPrimaryClip();
if(clipData != null) {
ClipData.Item item = clipData.getItemAt(0);
// Gets the clipboard as text.
CharSequence pasteData = item.getText();
if (pasteData != null)
return pasteData.toString();
}
}
return "";
}