*/}}
Browse Source

Android fixes

YimingWu 2 months ago
parent
commit
bd509c322a
9 changed files with 103 additions and 52 deletions
  1. 12 2
      la_data.c
  2. 3 12
      la_interface.h
  3. 17 28
      la_kernel.c
  4. 30 0
      la_util.c
  5. 3 0
      la_util.h
  6. 19 2
      resources/la_operators.c
  7. 3 1
      resources/la_properties.c
  8. 13 4
      resources/la_templates.c
  9. 3 3
      resources/la_widgets.c

+ 12 - 2
la_data.c

@@ -3492,6 +3492,11 @@ int laPackUDF(laUDF *udf, int UseInstanceList, int DoBackup){
         }
     }
 
+#ifdef LAGUI_ANDROID
+    if(!laAndroidEnsureValidFilePath(SSTR(udf->FileName),W_OK)){ logPrintNew("Can't open \"%s\" on android\n",SSTR(udf->FileName)); return 0; }
+    strSafeSet(&udf->FileName, MAIN.AndroidLastPath);
+    logPrintNew(MAIN.AndroidLastPath);
+#endif
     sprintf(OldPath,"%s",SSTR(udf->FileName));
     sprintf(FilePath,"%s.incomplete",SSTR(udf->FileName));
     udf->DiskFile = fopen(FilePath, "wb");
@@ -3837,11 +3842,16 @@ laUDF *laOpenUDF(char *FileName, int ReadToMemory, laUDFRegistry* ReadRegistryRe
 
     udf=memAcquire(sizeof(laUDF));
 
-    strSafeSet(&udf->FileName, FileName);
 
-    udf->DiskFile = fopen(SSTR(udf->FileName), "rb");
+    udf->DiskFile = fopen(FileName, "rb");
     if (!udf->DiskFile) return 0;
 
+#ifdef LAGUI_ANDROID
+    strSafeSet(&udf->FileName, MAIN.AndroidLastPath);
+#else
+    strSafeSet(&udf->FileName, FileName);
+#endif
+
     if(ReadToMemory){ la_ReadUDFToMemory(udf); fclose(udf->DiskFile); udf->DiskFile = 0; }
 
     la_ReadBuffer(udf, sizeof(LA_UDF_IDENTIFIER) - 1, Identifier);

+ 3 - 12
la_interface.h

@@ -452,6 +452,7 @@ STRUCTURE(LA){
     AAssetManager *AssetManager;
     char *InternalDataPath;
     char *ExternalDataPath;
+    char *AndroidLastPath;
 #endif
     int InkOrWinTab;
     int WacomDeviceStylus; real StylusPressure, StylusOrientation, StylusDeviation, StylusMaxPressure;
@@ -1380,12 +1381,6 @@ STRUCTURE(laPanel){
     int Mode;
     int NoConfirm;
 
-    int LiveEditing;
-    laUiItem *EditingUi;
-    laUiItem *FocusingUi;
-
-    void *SFPNode;
-
     int SL, SR, ST, SB; //Snap To Edge
 
     laSafeString *Title;
@@ -1394,6 +1389,8 @@ STRUCTURE(laPanel){
     laPropPack PP;
     laPropStep FakePS;
 
+    //laSafeString *_ToolboxName;
+    //int _ToolboxLayout;
     laPropContainer* PropLinkContainer;
     laSubProp* PropLinkFakeProp;
     laPropPack PropLinkPP;
@@ -1419,12 +1416,6 @@ STRUCTURE(laPanel){
     laOperator *ParentOperator;
 
     u64bit Tag;
-
-    //64 Main Types are useable,with 31 subtypes avainable each.
-    //Main Type 0~63(some are occupied by LA internal)
-    //Sub Type 0~31
-    //Main (Low)  0|            1|            2|            3|...
-    //[---32bits---][---32bits---][---32bits---][---32bits---]...
 };
 
 STRUCTURE(laPanelMessage){

+ 17 - 28
la_kernel.c

@@ -3963,16 +3963,15 @@ void laDestroySinglePanel(laPanel *p, int immediate){
 }
 
 int laEnclosePanelContent(laPanel *p, laUiList *uil){
-    laBoxedTheme *bt = _LA_THEME_FLOATING_PANEL;
     int MinW,MinWt=0;
     int TitleReserve=p->Mode==LA_PANEL_FLOATING_TOP?LA_RH:0;
+    if(!MAIN.CurrentWindow){ MAIN.CurrentWindow=MAIN.Windows.pFirst; if(!MAIN.CurrentWindow) return 0; }
     int CW = MAIN.CurrentWindow->CW;
     if(p->SL && p->SR){return 0;}
     la_SetPropMathcerContext(p);
-    int em=bt->BoxStyle==-1?LA_M:0;
 
-    la_UpdateUiListRecursive(&p->TitleBar, LA_M+em, LA_M+em, p->TW - LA_M*2, p->TH, 0, p);
-    la_UpdateUiListRecursive(uil, LA_M+p->TitleBar.B, em, 1000, 0, 0, p);
+    la_UpdateUiListRecursive(&p->TitleBar, LA_M, LA_M, p->TW - LA_M*2, p->TH, 0, p);
+    la_UpdateUiListRecursive(uil, LA_M+p->TitleBar.B, 0, 1000, 0, 0, p);
     MinWt = la_TestUiListMinumWidth(&p->TitleBar);
     MinW = la_TestUiListMinumWidth(uil);
     if (MinW<MinWt){MinW=MinWt;}
@@ -3983,8 +3982,8 @@ int laEnclosePanelContent(laPanel *p, laUiList *uil){
     la_PanelValidateWidth(p,uil);
     laEnsurePanelInBound(p,uil);
     if(p->TW>CW){ p->TW=CW; }
-    la_UpdateUiListRecursive(&p->TitleBar, LA_M+em, LA_M+em, p->TW-LA_M*2, p->TH, 0, p);
-    la_UpdateUiListRecursive(uil, LA_M+p->TitleBar.B, LA_M+em, p->TW-LA_M-ScrollerW, 0, 0, p);
+    la_UpdateUiListRecursive(&p->TitleBar, LA_M, LA_M, p->TW-LA_M*2, p->TH, 0, p);
+    la_UpdateUiListRecursive(uil, LA_M+p->TitleBar.B, LA_M, p->TW-LA_M-ScrollerW, 0, 0, p);
     laRedrawPanel(p);
     return 1;
 }
@@ -6513,7 +6512,7 @@ void la_DrawUiListScrollerH(laUiList *uil, int DisplayOffset, int TotalW, int Di
 }
 void la_DrawInstanceBkg(laUiList *uil, real* color, int LP, int RP){
     tnsUseNoTexture(); tnsColor4dv(color);
-    la_DrawBox(uil->L-LP+1,uil->R+RP-1,uil->U+1,uil->B-1);
+    la_DrawBox(uil->L-LP,uil->R+RP,uil->U,uil->B);
 }
 void la_InitSocketRecord(laUiListDraw* uild, laUiList* container){
     laSocketRecord* sr;
@@ -8956,40 +8955,30 @@ static int android_close(void *cookie){
 // Ref: https://developer.android.com/ndk/reference/group/asset
 FILE *android_fopen(const char *fileName, const char *mode)
 {
-    char buf[1024];
-    if (mode[0] == 'w')
-    {
+    MAIN.AndroidLastPath=0;
+    if (mode[0] == 'w'){
         // fopen() is mapped to android_fopen() that only grants read access to
         // assets directory through AAssetManager but we want to also be able to
         // write data when required using the standard stdio FILE access functions
         // Ref: https://stackoverflow.com/questions/11294487/android-writing-saving-files-from-native-code-only
         #undef fopen
-        FILE* result=fopen(fileName, mode); if(result){ return result; }
-        sprintf(buf,"%s/%s", MAIN.InternalDataPath, fileName);
-        result=fopen(buf, mode); if(result) return result;
-        sprintf(buf,"%s/%s", MAIN.ExternalDataPath, fileName);
-        return fopen(buf, mode);
+        char* valid_path=laAndroidEnsureValidFilePath(fileName,W_OK); if(!valid_path){ return 0; }
+        FILE* result=fopen(valid_path, mode); if(result){ MAIN.AndroidLastPath=valid_path; return result; }
+        return 0;
         #define fopen(name, mode) android_fopen(name, mode)
-    }
-    else
-    {
+    }else{
         // NOTE: AAsset provides access to read-only asset
         AAsset *asset = AAssetManager_open(MAIN.AssetManager, fileName, AASSET_MODE_UNKNOWN);
 
-        if (asset != NULL)
-        {
+        if (asset != NULL){
             // Get pointer to file in the assets
             return funopen(asset, android_read, android_write, android_seek, android_close);
-        }
-        else
-        {
+        }else{
             #undef fopen
-            FILE* result=fopen(fileName, mode); if(result){ return result; }
             // Just do a regular open if file is not found in the assets
-            sprintf(buf,"%s/%s", MAIN.InternalDataPath, fileName);
-            result=fopen(buf, mode); if(result){ return result; }
-            sprintf(buf,"%s/%s", MAIN.ExternalDataPath, fileName);
-            return fopen(buf, mode);
+            char* valid_path=laAndroidEnsureValidFilePath(fileName,R_OK); if(!valid_path){ return 0; }
+            FILE* result=fopen(valid_path, mode); if(result){ MAIN.AndroidLastPath=valid_path; return result; }
+            return 0;
             #define fopen(name, mode) android_fopen(name, mode)
         }
     }

+ 30 - 0
la_util.c

@@ -2372,6 +2372,36 @@ int laEnsureDir(const char *dir) {
 #endif
 }
 
+#ifdef LAGUI_ANDROID
+static char* la_FileDoableOrDir(char* file_path,int mode){
+    if(!access(file_path,F_OK)){
+        if(!access(file_path,mode)){ return file_path; }
+    }else{
+        char buf[PATH_MAX];
+        strcpy(buf,file_path);
+        strDiscardLastSegmentSeperateBy(buf,'/');
+        struct stat statbuf;
+        if(stat(buf, &statbuf) != 0){ return 0; }
+        if(S_ISDIR(statbuf.st_mode)){
+            if(mode&W_OK){ if(statbuf.st_mode & S_IWUSR) return file_path; }
+            if(mode&R_OK){ if(statbuf.st_mode & S_IRUSR) return file_path; }
+        }
+    }
+    return 0;
+}
+char* laAndroidEnsureValidFilePath(char* file_path, int mode){
+    static char buf[PATH_MAX];
+    MAIN.AndroidLastPath=0;
+    char* result=0;
+    if(result=la_FileDoableOrDir(file_path, mode)){ MAIN.AndroidLastPath=result; return result; }
+    sprintf(buf,"%s/%s", MAIN.InternalDataPath, file_path);
+    if(result=la_FileDoableOrDir(buf, mode)){ MAIN.AndroidLastPath=result; return result; }
+    sprintf(buf,"%s/%s", MAIN.ExternalDataPath, file_path);
+    if(result=la_FileDoableOrDir(buf, mode)){ MAIN.AndroidLastPath=result; return result; }
+    return 0;
+}
+#endif
+
 //======================================================[ translation ]
 
 void transNewLanguage(const char *LanguageID){

+ 3 - 0
la_util.h

@@ -761,6 +761,9 @@ void strMoveView(laStringEdit *se, int DownLines, int RightCharacters);
 
 int laCopyFile(char *to, char *from);
 int laEnsureDir(const char *dir);
+#ifdef LAGUI_ANDROID
+char* laAndroidEnsureValidFilePath(char* file_path, int mode);
+#endif
 
 void transNewLanguage(const char * LanguageID);
 void transSetLanguage(const char * LanguageID);

+ 19 - 2
resources/la_operators.c

@@ -424,7 +424,7 @@ laFileBrowser *la_FileBrowserInit(laOperator *a){
 #ifdef LAGUI_ANDROID
     strcpy(fb->Path, MAIN.ExternalDataPath);
     laBookmarkedFolder* bf=memAcquireSimple(sizeof(laBookmarkedFolder));
-    strcpy(bf->Path,fb->Path); strcpy(bf->Name,strGetLastSegment(fb->Path,"External")); lstAppendItem(&fb->Bookmarks,bf);
+    strcpy(bf->Path,fb->Path); strcpy(bf->Name,strGetLastSegment(fb->Path,"/")); lstAppendItem(&fb->Bookmarks,bf);
     bf=memAcquireSimple(sizeof(laBookmarkedFolder));
     strcpy(bf->Path,MAIN.InternalDataPath); strcpy(bf->Name,"Internal"); lstAppendItem(&fb->Bookmarks,bf);
 
@@ -872,7 +872,7 @@ int OPINV_ManagedSave(laOperator *a, laEvent *e){
             if(!empty){
                 if(!laSaveManagedUDF(modified_only)){
                     laEnableMessagePanel(0,0,"Caution",
-                        "Not all files have been successfully written.\nSee messages in terminal for details.",e->x,e->y,400,e);
+                        "Not all files have been successfully written.\nSee messages in terminal for details.\n",e->x,e->y,400,e);
                 }
                 return LA_FINISHED;
             }
@@ -2558,6 +2558,18 @@ int OPINV_PanPanel(laOperator *a, laEvent *e){
     return LA_FINISHED;
 }
 
+#ifdef _WIN32
+#define _WIN32_WINNT 0x0500
+#include <wincon.h> 
+
+int OPINV_ToggleSystemConsole(laOperator *a, laEvent *e){
+    HWND wnd=GetConsoleWindow();
+    int showhide=IsWindowVisible(wnd)?SW_HIDE:SW_SHOW;
+    ShowWindow(wnd,showhide);
+    return LA_FINISHED;
+}
+#endif
+
 int OPCHK_IsHyper(laPropPack *This, laStringSplitor *ss){
     if (This && This->LastPs->p->Container->Hyper) return 1;
     return 0;
@@ -2682,6 +2694,11 @@ void la_RegisterBuiltinOperators(){
     laCreateOperatorType("LA_dock_panel", "Dock Panel", "Dock a panel",
                           OPCHK_IsPanel, 0, 0, OPINV_DockPanel, 0, 0, LA_ACTUATOR_SYSTEM);
     
+#ifdef _WIN32
+    laCreateOperatorType("LA_toggle_system_console", "Toggle System Console", "Toggle Win32 console window",
+                          0, 0, 0, OPINV_ToggleSystemConsole, 0, 0, LA_ACTUATOR_SYSTEM|LA_ACTUATOR_HIDDEN);
+#endif
+
     laCreateOperatorType("LA_prop_restore_default", "Restore default value", "Restore property back to its default value", OPCHK_PropSetValue, 0, 0, OPINV_PropSetDefault, 0, U'⭯', LA_ACTUATOR_SYSTEM);
     laCreateOperatorType("LA_prop_set_min", "Set Min Value", "Set property to its minimum value", OPCHK_PropSetValue, 0, 0, OPINV_PropSetMin, 0, 0, LA_ACTUATOR_SYSTEM);
     laCreateOperatorType("LA_prop_set_max", "Set Max Value", "Set property to its maximum value", OPCHK_PropSetValue, 0, 0, OPINV_PropSetMax, 0, 0, LA_ACTUATOR_SYSTEM);

+ 3 - 1
resources/la_properties.c

@@ -2048,7 +2048,7 @@ void la_RegisterInternalProps(){
             laAddOperatorProperty(p, "hide", "Hide", "Hide this panel", "LA_hide_panel", U'🗕', 0);
             laAddOperatorProperty(p, "dock", "Dock", "Dock this panel", "LA_dock_panel", U'🗖', 0);
             laAddOperatorProperty(p, "close", "Close", "Close this panel", "LA_block_close_panel", U'🞫', 0);
-            //laAddSubGroup(p, "Detached Props", "Detached Props", "detached_prop",0,0,0,0,0,0,0,0,0,0,0,0,offsetof(laPanel, PropLinkContainer->Props), 0);
+            //laAddSubGroup(p, "Detached Props", "Detached Props", "detached_props",0,0,0,0,0,0,0,0,0,0,0,offsetof(laPanel, PropLinkContainer->Props), 0);
             laAddSubGroup(p, "uil","Ui List", "Panel Main Ui List", "ui_list",0,0,0,offsetof(laPanel, UI), 0,0,0,0,0,0,0,LA_UDF_IGNORE);
             laAddSubGroup(p, "title_uil","Title Ui List", "Panel Title Ui List", "ui_list",0,0,0, offsetof(laPanel, TitleBar), 0,0,0,0,0,0,0,LA_UDF_IGNORE);
             laAddSubGroup(p, "pp","Prop Pack", "Panel Base With Own Instance", "property_package",0,0,0,offsetof(laPanel, PP), 0,0,0,0,0,0,0,LA_UDF_REFER|LA_UDF_IGNORE);
@@ -2056,6 +2056,8 @@ void la_RegisterInternalProps(){
             laAddSubGroup(p, "parent_block","Parent Block", "The Block That Directly Links This Panel In", "ui_block",0,0,0,offsetof(laPanel, Block), 0,0,0,0,0,0,0,LA_UDF_REFER|LA_UDF_IGNORE);
             laAddSubGroup(p, "template","Template", "Panel template", "panel_template",0,0,0,offsetof(laPanel, PanelTemplate), 0,0,0,0,0,0,0,LA_UDF_REFER);
             laAddSubGroup(p, "block", "Block", "Block reference of this panel", "ui_block",0,0,0,offsetof(laPanel, Block), 0,0,0,0,0,0,0,LA_UDF_REFER);
+            //laAddStringProperty(p, "_toolbox_name", "Toolbox Name", "Toolbox name",0,0,0,0,1,offsetof(laPanel,_ToolboxName),0,laget_PanelToolboxName,0,0,LA_READ_ONLY);
+            //laAddIntProperty(p, "_toolbox_layout", "Toolbox Layout", "Toolbox layout", 0,0,0,0,0,0,0,0,offsetof(laPanel,_ToolboxLayout),0,0,0,0,laget_PanelToolboxLayout, 0,0,0,0,0,LA_READ_ONLY);
         }
 
         // UI ITEM ==========================================================================================

+ 13 - 4
resources/la_templates.c

@@ -533,6 +533,16 @@ void laui_DefaultMenuButtonsOptionEntries(laUiList *uil, laPropPack *pp, laPropP
     laShowItemFull(uil, c, 0, "LA_panel_activator", 0, "panel_id=LAUI_user_preferences;", 0, 0);
     laShowLabel(uil, c, "Information", 0, 0)->Flags|=LA_TEXT_MONO|LA_UI_FLAGS_DISABLED;
     laShowItemFull(uil, c, 0, "LA_panel_activator", 0, "panel_id=LAUI_about;text=About;", 0, 0);
+#ifdef _WIN32
+    laShowSeparator(uil,c);
+    laShowItem(uil,c,0,"LA_toggle_system_console");
+#endif
+    if(MAIN.InitArgs.HasTerminal){
+#ifndef _WIN32
+        laShowSeparator(uil,c);
+#endif
+        laShowItemFull(uil, c, 0, "LA_panel_activator", 0, "panel_id=LAUI_terminal;", 0, 0);
+    }
 }
 void laui_DefaultMenuButtons(laUiList *uil, laPropPack *pp, laPropPack *actinst, laColumn *extracol, int context){
     laUiList *muil; laColumn *mc,*c = laFirstColumn(uil);
@@ -700,11 +710,10 @@ void laui_Theme(laUiList *uil, laPropPack *Base, laPropPack *UNUSED_This, laColu
     
     laShowLabel(uil,col,"Theme Details",0,0)->Flags|=LA_TEXT_ALIGN_CENTER;
 
-    laShowItem(uil,cl,Base, "name");
 
-    ui=laBeginRow(uil,cr, 0,0);
-    laShowSeparator(uil,cr)->Expand=1;
-    laShowItem(uil,cr,Base, "delete")->Flags|=LA_UI_FLAGS_ICON;
+    ui=laBeginRow(uil,col, 0,0);
+    laShowItem(uil,col,Base, "name")->Expand=1;
+    laShowItem(uil,col,Base, "delete");
     laEndRow(uil, ui);
 
     ui=laBeginRow(uil,col, 0,0);

+ 3 - 3
resources/la_widgets.c

@@ -805,7 +805,7 @@ void la_IntDraw(laUiItem *ui, int h){
                     tnsPackAs(GL_TRIANGLE_FAN);
                 }
 
-                la_DrawBoxAutoBorderArray(_L,_R,_U,_B,bt,ui->State,IsVertical,i==Len-1);
+                la_DrawBoxAutoBorderArray(_L,_R,_U,_B,bt,ui->State,IsVertical,i==0);
             }
             if (ui->Extra->On == i + 1 && ui->Extra->Edit){
                 uint32_t *buf = strGetCursorLine(ui->Extra->Edit, 0)->Buf;
@@ -1675,7 +1675,7 @@ void la_ValueMeterType1Draw(laUiItem *ui, int h){
             la_DrawBox(_L-sw,R1-sw,U1-sw,_B-sw);
             tnsPackAs(GL_TRIANGLE_FAN);
 
-            la_DrawBoxAutoBorderArray(_L,_R,_U,_B,bt,ui->State,IsVertical,i==Len-1);
+            la_DrawBoxAutoBorderArray(_L,_R,_U,_B,bt,ui->State,IsVertical,i==0);
         }
 
         if(!NoLabel){
@@ -1856,7 +1856,7 @@ void la_ValueMeterType2Draw(laUiItem *ui, int h){
         tnsPackAs(GL_LINES);
 
         if(!NoDecal){
-            la_DrawBoxAutoBorderArray(_L,_R,_U,_B,bt,ui->State,IsVertical,i==Len-1);
+            la_DrawBoxAutoBorderArray(_L,_R,_U,_B,bt,ui->State,IsVertical,i==0);
         }
 
         //if(IsVertical){