Boolean CProfileManager::DoNewProfileDialog(char *outName, UInt32 bufSize) { Boolean confirmed; StDialogHandler theHandler(dlog_NewProfile, LCommander::GetTopCommander()); LWindow *theDialog = theHandler.GetDialog(); ThrowIfNil_(theDialog); LEditText *responseText = dynamic_cast<LEditText*>(theDialog->FindPaneByID('Name')); ThrowIfNil_(responseText); theDialog->SetLatentSub(responseText); theDialog->Show(); theDialog->Select(); while (true) // This is our modal dialog event loop { MessageT hitMessage = theHandler.DoDialog(); if (hitMessage == msg_OK) { Str255 pStr; UInt32 outLen; responseText->GetDescriptor(pStr); outLen = pStr[0] >= bufSize ? bufSize - 1 : pStr[0]; memcpy(outName, &pStr[1], outLen); outName[outLen] = '\0'; confirmed = PR_TRUE; break; } else if (hitMessage == msg_Cancel) { confirmed = PR_FALSE; break; } } return confirmed; }
/*================================= DoSizeDialog ==================================*/ Boolean PTFontSizeDialog::DoSizeDialog( SInt16 inSize, SInt16 *outSize ) { try { /*************************** ensure that the window is created properly (Window Mgr bug) ****************************/ StSaveGWorld aSaver; ::SetGDevice( ::GetMainDevice() ); /*************************** create the dialog ****************************/ StApplicationContext appContext; // must load from application file StDialogHandler theHandler( PPob_TextSizeDialog, LCommander::GetTopCommander() ); LWindow * theWindow = theHandler.GetDialog(); LEditText * sizeField = dynamic_cast<LEditText*> (theWindow->FindPaneByID( PaneID_Size )); ThrowIf_( !sizeField ); /******************************************** initialize the values & show the window ********************************************/ sizeField->SetValue( inSize ); theWindow->Show(); /******************************************** go into an event loop ********************************************/ Boolean done = false; MessageT theMessage; SInt16 newSize; while( !done ) { theMessage = theHandler.DoDialog(); if ( theMessage == msg_Cancel ) done = true; else if ( theMessage == msg_OK ) { newSize = sizeField->GetValue(); if ( (newSize < 4) || (newSize > 512) ) { theWindow->SwitchTarget( sizeField ); sizeField->SelectAll(); SUErrors::DisplayError( err_BadFontSize ); } else done = true; } }; /******************************************** return values to the caller ********************************************/ if ( theMessage == msg_OK ) { *outSize = newSize; return( true ); } else return( false ); } catch( ... ) { SUErrors::DisplayError( err_Generic ); return( false ); } }
void CProfileManager::DoManageProfilesDialog() { nsresult rv; StDialogHandler theHandler(dlog_ManageProfiles, LCommander::GetTopCommander()); LWindow *theDialog = theHandler.GetDialog(); nsCOMPtr<nsIProfile> profileService = do_GetService(NS_PROFILE_CONTRACTID, &rv); ThrowIfNil_(profileService); // Set up the dialog by filling the list of current profiles LTextTableView *table = (LTextTableView*) theDialog->FindPaneByID('List'); ThrowIfNil_(table); LPushButton *deleteButton = (LPushButton *) theDialog->FindPaneByID('Dele'); ThrowIfNil_(deleteButton); //Str255 pascalStr; nsAutoString unicodeStr; nsCAutoString cStr; char dataBuf[256]; UInt32 dataSize; // PowerPlant stuff to set up the list view STableCell selectedCell(1, 1); SDimension16 tableSize; TableIndexT rows, cols; table->GetFrameSize(tableSize); table->SetTableGeometry(new LTableMonoGeometry(table, tableSize.width, 16)); table->SetTableStorage(new LTableArrayStorage(table, 0UL)); table->SetTableSelector(new LTableSingleSelector(table)); table->InsertCols(1, 0); // Get the name of the current profile so we can select it nsXPIDLString currProfileName; profileService->GetCurrentProfile(getter_Copies(currProfileName)); // Get the list of profile names and add them to the list PRUint32 listLen; PRUnichar **profileList; rv = profileService->GetProfileList(&listLen, &profileList); ThrowIfError_(rv); for (PRUint32 index = 0; index < listLen; index++) { CPlatformUCSConversion::GetInstance()->UCSToPlatform(nsDependentString(profileList[index]), cStr); table->InsertRows(1, LONG_MAX, cStr.get(), cStr.Length(), true); if (nsCRT::strcmp(profileList[index], currProfileName.get()) == 0) selectedCell.row = index + 1; } PRInt32 numProfiles; rv = profileService->GetProfileCount(&numProfiles); ThrowIfError_(rv); (numProfiles > 1) ? deleteButton->Enable() : deleteButton->Disable(); table->SelectCell(selectedCell); // Handle the "Ask At StartUp" checkbox LCheckBox *showAtStartCheck = (LCheckBox*) theDialog->FindPaneByID('Show'); ThrowIfNil_(showAtStartCheck); PRBool showIt; rv = GetShowDialogOnStart(&showIt); if (NS_FAILED(rv)) showIt = PR_TRUE; showAtStartCheck->SetValue(showIt); theDialog->Show(); theDialog->Select(); while (true) // This is our modal dialog event loop { MessageT hitMessage = theHandler.DoDialog(); if (hitMessage == msg_OK) { theDialog->Hide(); SetShowDialogOnStart(showAtStartCheck->GetValue()); selectedCell = table->GetFirstSelectedCell(); if (selectedCell.row > 0) { dataSize = sizeof(dataBuf) - 1; table->GetCellData(selectedCell, dataBuf, dataSize); dataBuf[dataSize] = '\0'; CPlatformUCSConversion::GetInstance()->PlatformToUCS(nsDependentCString(dataBuf), unicodeStr); rv = profileService->SetCurrentProfile(unicodeStr.get()); } break; } else if (hitMessage == msg_Cancel) { break; } else if (hitMessage == msg_OnNewProfile) { if (DoNewProfileDialog(dataBuf, sizeof(dataBuf))) { CPlatformUCSConversion::GetInstance()->PlatformToUCS(nsDependentCString(dataBuf), unicodeStr); rv = profileService->CreateNewProfile(unicodeStr.get(), nsnull, nsnull, PR_FALSE); if (NS_FAILED(rv)) break; table->InsertRows(1, LONG_MAX, dataBuf, strlen(dataBuf), true); table->GetTableSize(rows, cols); table->SelectCell(STableCell(rows, cols)); rv = profileService->GetProfileCount(&numProfiles); (NS_SUCCEEDED(rv) && numProfiles > 1) ? deleteButton->Enable() : deleteButton->Disable(); } } else if (hitMessage == msg_OnDeleteProfile) { selectedCell = table->GetFirstSelectedCell(); if (selectedCell.row > 0) { dataSize = sizeof(dataBuf) - 1; table->GetCellData(selectedCell, dataBuf, dataSize); dataBuf[dataSize] = '\0'; CPlatformUCSConversion::GetInstance()->PlatformToUCS(nsDependentCString(dataBuf), unicodeStr); rv = profileService->DeleteProfile(unicodeStr.get(), PR_TRUE); if (NS_FAILED(rv)) break; table->RemoveRows(1, selectedCell.row, true); table->GetTableSize(rows, cols); if (selectedCell.row >= rows) selectedCell.row = rows - 1; table->SelectCell(selectedCell); rv = profileService->GetProfileCount(&numProfiles); (NS_SUCCEEDED(rv) && numProfiles > 1) ? deleteButton->Enable() : deleteButton->Disable(); } } else if (hitMessage == msg_OnRenameProfile) { nsAutoString oldName; selectedCell = table->GetFirstSelectedCell(); dataSize = sizeof(dataBuf) - 1; table->GetCellData(selectedCell, dataBuf, dataSize); dataBuf[dataSize] = '\0'; CPlatformUCSConversion::GetInstance()->PlatformToUCS(nsDependentCString(dataBuf), oldName); if (DoNewProfileDialog(dataBuf, sizeof(dataBuf))) { CPlatformUCSConversion::GetInstance()->PlatformToUCS(nsDependentCString(dataBuf), unicodeStr); profileService->RenameProfile(oldName.get(), unicodeStr.get()); table->SetCellData(selectedCell, dataBuf, strlen(dataBuf)); } } } }