Difference between revisions of "CPlusPlus for Gideros Studio Help"

From GiderosMobile
Line 114: Line 114:
 
#include <wchar.h> // new 20221026 XXX
 
#include <wchar.h> // new 20221026 XXX
 
...
 
...
         }else if (strcmp(what, "openFileDialog") == 0)
+
         }else if ((strcmp(what, "openDirectoryDialog") == 0)
 +
                || (strcmp(what, "openFileDialog") == 0)
 +
                || (strcmp(what, "saveFileDialog") == 0))
 
         {
 
         {
             DWORD dwFlags; // XXX
+
        /* TODO parse extension :-( */
 
+
             // for win32 args ("title|path|extensions//help") is only 1 arg
             if (args.size()>0)
+
            // unlike Qt which seems to cut the | into different args
            {
+
             if(args.size() == 1){ // do we need to deal with "help" as arg or leave it to Qt?
                 std::wstring s=ws(args[0].s.c_str()); // "Title|C:/tmp/|Text (*.txt);; Image (*.png)"
+
                // we cut the args
 +
                 std::wstring s=ws(args[0].s.c_str()); // "Title|c:\\tmp|Text (*.txt);; Image (*.png)"
 
                 size_t index = s.find(L"|");
 
                 size_t index = s.find(L"|");
 
                 size_t index2 = s.find(L"|", index+1);
 
                 size_t index2 = s.find(L"|", index+1);
Line 126: Line 129:
 
                 std::wstring place = s.substr(index+1, index2-index-1);
 
                 std::wstring place = s.substr(index+1, index2-index-1);
 
                 std::wstring extension = s.substr(index2+1);
 
                 std::wstring extension = s.substr(index2+1);
                printf("t p e:\n %ls\n %ls\n %ls\n", title.c_str(),place.c_str(),extension.c_str()); // TEST OK
+
//                printf("t p e:\n %ls\n %ls\n %ls\n", title.c_str(),place.c_str(),extension.c_str()); // TEST OK
  
 +
                DWORD dwFlags; // new 20221028 XXX
 
                 HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
 
                 HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
 
                 if (SUCCEEDED(hr))
 
                 if (SUCCEEDED(hr))
 
                 {
 
                 {
                     IFileOpenDialog *pFile;
+
                     if (strcmp(what, "openDirectoryDialog") == 0){
                    COMDLG_FILTERSPEC fileTypes[] =
+
                        /* TO DO */
                    {
+
                        /*--------------------------------------------------*/
                        { L"Text Documents", L"*.txt" },
+
                    }else if (strcmp(what, "openFileDialog") == 0){
                        { L"All Files", L"*.*" },
+
                        IFileOpenDialog *pFile;
                    }; // NEED TO PASS FROM ARGS wstring extension
+
                        COMDLG_FILTERSPEC fileTypes[] = /* TODO parse from wstring extension :-( */
 
+
                        {
                    // Create the FileOpenDialog object.
+
                            { L"Text Documents", L"*.txt" },
                    hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_ALL,
+
                            { L"All Files", L"*.*" },
                            IID_IFileOpenDialog, reinterpret_cast<void**>(&pFile));
+
                        };
  
                    if (SUCCEEDED(hr))
+
                         // Create the FileOpenDialog object.
                    {
+
                         hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_ALL,  
                        // get/set options
+
                                IID_IFileOpenDialog, reinterpret_cast<void**>(&pFile));
                        pFile->GetOptions(&dwFlags);
 
                        pFile->SetOptions(dwFlags | FOS_FORCEFILESYSTEM);
 
                        pFile->SetFileTypes(ARRAYSIZE(fileTypes), fileTypes);
 
                         pFile->SetFileTypeIndex(1); // index starts at 1 XXX
 
//                        pFile->SetDefaultExtension(L"obj;fbx"); // XXX
 
                        hr = pFile->SetTitle(title.c_str()); // need more check?
 
                        // set starting folder
 
                        IShellItem *pItem = NULL;
 
                         hr = SHCreateItemFromParsingName(place.c_str(), NULL, IID_IShellItem, (LPVOID *)&pItem);
 
 
                         if (SUCCEEDED(hr))
 
                         if (SUCCEEDED(hr))
 
                         {
 
                         {
                             pFile->SetFolder(pItem);
+
                            // get/set options
                             pItem->Release();
+
                             pFile->GetOptions(&dwFlags);
                             pItem = NULL;
+
                             pFile->SetOptions(dwFlags | FOS_FORCEFILESYSTEM);
                        }
+
                             pFile->SetFileTypes(ARRAYSIZE(fileTypes), fileTypes); // SEE ABOVE fileTypes
 +
                            pFile->SetFileTypeIndex(1); // index starts at 1
 +
//                            pFile->SetDefaultExtension(L"obj;fbx"); // XXX
 +
                            hr = pFile->SetTitle(title.c_str()); // need more check?
  
                        // Show the Open dialog box.
+
                            // set starting folder
                        hr = pFile->Show(NULL);
+
                            IShellItem *pItem = NULL;
 +
                            hr = SHCreateItemFromParsingName(place.c_str(), NULL, IID_IShellItem, (LPVOID *)&pItem);
 +
                            if (SUCCEEDED(hr))
 +
                            {
 +
                                pFile->SetFolder(pItem);
 +
                                pItem->Release();
 +
                                pItem = NULL;
 +
                            }
  
                        // Get the file name from the dialog box.
+
                            // Show the Open dialog box.
                        if (SUCCEEDED(hr))
+
                             hr = pFile->Show(NULL);
                        {
+
                            // Get the file name from the dialog box.
                            IShellItem *pItem;
 
                             hr = pFile->GetResult(&pItem);
 
 
                             if (SUCCEEDED(hr))
 
                             if (SUCCEEDED(hr))
 
                             {
 
                             {
                                 PWSTR pszFilePath;
+
                                 IShellItem *pItem;
                                 hr = pItem->GetDisplayName(SIGDN_FILESYSPATH, &pszFilePath);
+
                                 hr = pFile->GetResult(&pItem);
 
 
                                // Display the file name to the user.
 
 
                                 if (SUCCEEDED(hr))
 
                                 if (SUCCEEDED(hr))
 
                                 {
 
                                 {
//                                  MessageBoxW(NULL, pszFilePath, L"File Path", MB_OK);
+
                                    PWSTR pszFilePath;
                                     r.type=gapplication_Variant::STRING;
+
                                    hr = pItem->GetDisplayName(SIGDN_FILESYSPATH, &pszFilePath);
                                    r.s=us(pszFilePath);
+
                                     if (SUCCEEDED(hr))
                                    rets.push_back(r);
+
                                    {
 +
                                        r.type=gapplication_Variant::STRING;
 +
                                        r.s=us(pszFilePath);
 +
                                        rets.push_back(r);
  
                                    CoTaskMemFree(pszFilePath);
+
                                        CoTaskMemFree(pszFilePath);
 +
                                    }
 +
                                    pItem->Release();
 
                                 }
 
                                 }
                                pItem->Release();
 
 
                             }
 
                             }
 +
                            pFile->Release();
 
                         }
 
                         }
                         pFile->Release();
+
                         CoUninitialize();
 +
                        /*--------------------------------------------------*/
 +
                    }else if (strcmp(what, "saveFileDialog") == 0){
 +
                        /* TO DO */
 +
                        /*--------------------------------------------------*/
 
                     }
 
                     }
                    CoUninitialize();
 
 
                 }
 
                 }
 
             }
 
             }
 
             /*------------------------------------------------------------------*/
 
             /*------------------------------------------------------------------*/
         }else if (strcmp(what, "saveFileDialog") == 0)
+
         }else if (strcmp(what, "temporaryDirectory") == 0)
 
</source>
 
</source>
  

Revision as of 04:30, 28 October 2022

Here you will find various resources to help learn C++ for people who wish to help with Gideros Studio development.


KNOWNFOLDERID

platform-win32.cpp

refs:

C:\dev\gideros_hgy29\libgid\src\win32\platform-win32.cpp


Convert wstring <-> string

platform-win32.cpp

refs:

C:\dev\gideros_hgy29\libgid\src\win32\platform-win32.cpp

#include <locale> // new 20221014 XXX
#include <codecvt> // new 20221014 XXX

...

std::wstring s2ws(const std::string& str)
{
    using convert_typeX = std::codecvt_utf8<wchar_t>;
    std::wstring_convert<convert_typeX, wchar_t> converterX;

    return converterX.from_bytes(str);
}

std::string ws2s(const std::wstring& wstr)
{
    using convert_typeX = std::codecvt_utf8<wchar_t>;
    std::wstring_convert<convert_typeX, wchar_t> converterX;

    return converterX.to_bytes(wstr);
}


win32 minimum, maximum screen size

platform-win32.cpp

refs:

C:\dev\gideros_hgy29\libgid\src\win32\platform-win32.cpp


win32 LFS problem with separator

Recent changes to path handling (most likely [0]) caused AssetCatalogTest.create_catalog_after_loading_file to fail on WIN32.

The test relied on the resulting path to be joined with "/" as a path separator. The resulting path used both forward and back-slashes. While these do work for some API's on WIN32, mixing both in a file path isn't expected behavior in most cases, so update the tests to use native slash direction for file-paths.

 * \note If you want a trailing slash, add `SEP_STR` as the last path argument,
 * duplicate slashes will be cleaned up.
 */
size_t BLI_path_join(char *__restrict dst, size_t dst_len, const char *path, ...)
#  define SEP '\\'
#  define ALTSEP '/'
#  define SEP_STR "\\"
#  define ALTSEP_STR "/"
#else
#  define SEP '/'
#define SEP_CHR     '#'
#define SEP_STR     "#"

#define EPS 0.001

#define UN_SC_KM    1000.0f
#define UN_SC_HM    100.0f
      str_tmp, TEMP_STR_SIZE, "*%.9g" SEP_STR, unit->scalar / scale_pref);

  if (len_num > len_max) {
    len_num = len_max;
  }

  if (found_ofs + len_num + len_move > len_max) {


openFileDialog

platform-win32.cpp

refs:

#include <wchar.h> // new 20221026 XXX
...
        }else if ((strcmp(what, "openDirectoryDialog") == 0)
                || (strcmp(what, "openFileDialog") == 0)
                || (strcmp(what, "saveFileDialog") == 0))
        {
        	/* TODO parse extension :-( */
            // for win32 args ("title|path|extensions//help") is only 1 arg
            // unlike Qt which seems to cut the | into different args
            if(args.size() == 1){ // do we need to deal with "help" as arg or leave it to Qt?
                // we cut the args
                std::wstring s=ws(args[0].s.c_str()); // "Title|c:\\tmp|Text (*.txt);; Image (*.png)"
                size_t index = s.find(L"|");
                size_t index2 = s.find(L"|", index+1);
                std::wstring title = s.substr(0, index);
                std::wstring place = s.substr(index+1, index2-index-1);
                std::wstring extension = s.substr(index2+1);
//                printf("t p e:\n %ls\n %ls\n %ls\n", title.c_str(),place.c_str(),extension.c_str()); // TEST OK

                DWORD dwFlags; // new 20221028 XXX
                HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
                if (SUCCEEDED(hr))
                {
                    if (strcmp(what, "openDirectoryDialog") == 0){
                        /* TO DO */
                        /*--------------------------------------------------*/
                    }else if (strcmp(what, "openFileDialog") == 0){
                        IFileOpenDialog *pFile;
                        COMDLG_FILTERSPEC fileTypes[] = /* TODO parse from wstring extension :-( */
                        {
                            { L"Text Documents", L"*.txt" },
                            { L"All Files", L"*.*" },
                        };

                        // Create the FileOpenDialog object.
                        hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_ALL, 
                                IID_IFileOpenDialog, reinterpret_cast<void**>(&pFile));
                        if (SUCCEEDED(hr))
                        {
                            // get/set options
                            pFile->GetOptions(&dwFlags);
                            pFile->SetOptions(dwFlags | FOS_FORCEFILESYSTEM);
                            pFile->SetFileTypes(ARRAYSIZE(fileTypes), fileTypes); // SEE ABOVE fileTypes
                            pFile->SetFileTypeIndex(1); // index starts at 1
//                            pFile->SetDefaultExtension(L"obj;fbx"); // XXX
                            hr = pFile->SetTitle(title.c_str()); // need more check?

                            // set starting folder
                            IShellItem *pItem = NULL;
                            hr = SHCreateItemFromParsingName(place.c_str(), NULL, IID_IShellItem, (LPVOID *)&pItem);
                            if (SUCCEEDED(hr))
                            {
                                pFile->SetFolder(pItem);
                                pItem->Release();
                                pItem = NULL;
                            }

                            // Show the Open dialog box.
                            hr = pFile->Show(NULL);
                            // Get the file name from the dialog box.
                            if (SUCCEEDED(hr))
                            {
                                IShellItem *pItem;
                                hr = pFile->GetResult(&pItem);
                                if (SUCCEEDED(hr))
                                {
                                    PWSTR pszFilePath;
                                    hr = pItem->GetDisplayName(SIGDN_FILESYSPATH, &pszFilePath);
                                    if (SUCCEEDED(hr))
                                    {
                                        r.type=gapplication_Variant::STRING;
                                        r.s=us(pszFilePath);
                                        rets.push_back(r);

                                        CoTaskMemFree(pszFilePath);
                                    }
                                    pItem->Release();
                                }
                            }
                            pFile->Release();
                        }
                        CoUninitialize();
                        /*--------------------------------------------------*/
                    }else if (strcmp(what, "saveFileDialog") == 0){
                        /* TO DO */
                        /*--------------------------------------------------*/
                    }
                }
            }
            /*------------------------------------------------------------------*/
        }else if (strcmp(what, "temporaryDirectory") == 0)

Locate first occurrence of character in wide string

platform-win32.cpp

refs:

std::wstring gs=ws(args[0].s.c_str()); // "Title|C:/tmp/|Text (*.txt);; Image (*.png)"
size_t index = gs.find(L"|");
size_t index2 = gs.find(L"|", index+1);
printf("args0: %ls\n", gs.c_str()); // output: Title|C:/tmp/|Text (*.txt);; Image (*.png)
printf("indices: %d, %d\n", index,index2); // output 5, 13
std::wstring title = gs.substr(0, index);
std::wstring path = gs.substr(index+1, index2-index-1);
std::wstring exts = gs.substr(index2+1);
printf("t p e:\n %ls\n %ls\n %ls\n", title.c_str(),path.c_str(),exts.c_str()); // Title C:/tmp/ Text (*.txt);; Image (*.png)