void IGraphicsWin::Resize(int w, int h) { int dw = w - Width(), dh = h - Height(); IGraphics::Resize(w, h); if (mDrawBitmap) { mDrawBitmap->resize(w, h); } if (WindowIsOpen()) { HWND pParent = 0, pGrandparent = 0; int w = 0, h = 0, parentW = 0, parentH = 0, grandparentW = 0, grandparentH = 0; GetWindowSize(mPlugWnd, &w, &h); if (IsChildWindow(mPlugWnd)) { pParent = GetParent(mPlugWnd); GetWindowSize(pParent, &parentW, &parentH); if (IsChildWindow(pParent)) { pGrandparent = GetParent(pParent); GetWindowSize(pGrandparent, &grandparentW, &grandparentH); } } SetWindowPos(mPlugWnd, 0, 0, 0, w + dw, h + dh, SETPOS_FLAGS); if (pParent) { SetWindowPos(pParent, 0, 0, 0, parentW + dw, parentH + dh, SETPOS_FLAGS); } if (pGrandparent) { SetWindowPos(pGrandparent, 0, 0, 0, grandparentW + dw, grandparentH + dh, SETPOS_FLAGS); } RECT r = { 0, 0, w, h }; InvalidateRect(mPlugWnd, &r, FALSE); } }
void IGraphicsWin::PromptForFile(WDL_String* pFilename, int action, char* dir, char* extensions) { pFilename->Set(""); if (!WindowIsOpen()) { return; } WDL_String pathStr; char fnCStr[MAX_PATH_LEN], dirCStr[MAX_PATH_LEN]; fnCStr[0] = '\0'; dirCStr[0] = '\0'; if (CSTR_NOT_EMPTY(dir)) { pathStr.Set(dir); strcpy(dirCStr, dir); } else { HostPath(&pathStr); } OPENFILENAME ofn; memset(&ofn, 0, sizeof(OPENFILENAME)); ofn.lStructSize = sizeof(OPENFILENAME); ofn.hwndOwner = mPlugWnd; ofn.lpstrFile = fnCStr; ofn.nMaxFile = MAX_PATH_LEN - 1; ofn.lpstrInitialDir = dirCStr; ofn.Flags = OFN_PATHMUSTEXIST; //if (!extensions.empty()) { //static char extStr[256]; //static char defExtStr[16]; //int i, j, p; //for (j = 0, p = 0; j < extensions.size(); ++j) { // extStr[p++] = extensions[j++]; //} //extStr[p++] = '\0'; //StrVector exts = SplitStr(extensions); //for (i = 0, p = 0; i < exts.size(); ++i) { // const std::string& ext = exts[i]; // if (i) { // extStr[p++] = ';'; // } // extStr[p++] = '*'; // extStr[p++] = '.'; // for (j = 0; j < ext.size(); ++j) { // extStr[p++] = ext[j]; // } //} //extStr[p++] = '\0'; //extStr[p++] = '\0'; //ofn.lpstrFilter = extStr; // //strcpy(defExtStr, exts.front().c_str()); //ofn.lpstrDefExt = defExtStr; //} bool rc = false; switch (action) { case kFileSave: ofn.Flags |= OFN_OVERWRITEPROMPT; rc = GetSaveFileName(&ofn); break; case kFileOpen: default: ofn.Flags |= OFN_FILEMUSTEXIST; rc = GetOpenFileName(&ofn); break; } if (rc) { pFilename->Set(ofn.lpstrFile); } }
void IGraphicsWin::PromptForFile(WDL_String* pFilename, EFileAction action, WDL_String* pDir, char* extensions) { if (!WindowIsOpen()) { pFilename->Set(""); return; } char fnCStr[MAX_PATH_LEN]; char dirCStr[MAX_PATH_LEN]; if (pFilename->GetLength()) strcpy(fnCStr, pFilename->Get()); else fnCStr[0] = '\0'; dirCStr[0] = '\0'; if (!pDir->GetLength()) { DesktopPath(pDir); } strcpy(dirCStr, pDir->Get()); OPENFILENAME ofn; memset(&ofn, 0, sizeof(OPENFILENAME)); ofn.lStructSize = sizeof(OPENFILENAME); ofn.hwndOwner = mPlugWnd; ofn.lpstrFile = fnCStr; ofn.nMaxFile = MAX_PATH_LEN - 1; ofn.lpstrInitialDir = dirCStr; ofn.Flags = OFN_PATHMUSTEXIST; if (CSTR_NOT_EMPTY(extensions)) { char extStr[256]; char defExtStr[16]; int i, p, n = strlen(extensions); bool seperator = true; for (i = 0, p = 0; i < n; ++i) { if (seperator) { if (p) { extStr[p++] = ';'; } seperator = false; extStr[p++] = '*'; extStr[p++] = '.'; } if (extensions[i] == ' ') { seperator = true; } else { extStr[p++] = extensions[i]; } } extStr[p++] = '\0'; strcpy(&extStr[p], extStr); extStr[p + p] = '\0'; ofn.lpstrFilter = extStr; for (i = 0, p = 0; i < n && extensions[i] != ' '; ++i) { defExtStr[p++] = extensions[i]; } defExtStr[p++] = '\0'; ofn.lpstrDefExt = defExtStr; } bool rc = false; switch (action) { case kFileSave: ofn.Flags |= OFN_OVERWRITEPROMPT; rc = GetSaveFileName(&ofn); break; case kFileOpen: default: ofn.Flags |= OFN_FILEMUSTEXIST; rc = GetOpenFileName(&ofn); break; } if (rc) { char drive[_MAX_DRIVE]; if(_splitpath_s(ofn.lpstrFile, drive, sizeof(drive), dirCStr, sizeof(dirCStr), NULL, 0, NULL, 0) == 0) { pDir->SetFormatted(MAX_PATH_LEN, "%s%s", drive, dirCStr); } pFilename->Set(ofn.lpstrFile); } }