// WinMain: // Extract command line parameters. // Run the configuration dialog box if necessary. // Report errors and quit, or // Run the main dialog that deals with hosting. int __stdcall WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) { appInstance_ = hInstance; int port = 0; // udp=1 for using unreliable transport char const * udp = strstr( lpCmdLine, "udp=" ); if( udp ) { dialogUdp = atoi( udp+4 ) != 0; } // port=1234 to serve on a specific port char const * param = strstr( lpCmdLine, "port=" ); if( param ) { port = atoi( param+5 ); } else { // If the port wasn't specified, run the options dialog. port = (int)RunDialog( IDD_HOSTDIALOG, HostDialogProc ); if( port == 0 ) { return 1; } } if( port < 1 || port > 65535 ) { error( "Port value must be between 1 and 65535 (inclusive)." ); } // chatHost_ deals with all the networking and user management. chatHost_ = NewChatHost( (short)port, !dialogUdp ); if( !chatHost_ ) { error( "Could not host chat server on the selected port." ); } // The modal dialog actually runs most of the program. RunDialog( IDD_USERLIST, UserListProc ); // Clean up and go home. (Too much clean-up is harmful, as the // kernel will do a good job of releasing all resources anyway) chatHost_->dispose(); return 0; }
void ClientHandler::EndTracing() { if (!CefCurrentlyOn(TID_UI)) { // Execute on the UI thread. CefPostTask(TID_UI, base::Bind(&ClientHandler::EndTracing, this)); return; } class Client : public CefEndTracingCallback, public CefRunFileDialogCallback { public: explicit Client(CefRefPtr<ClientHandler> handler) : handler_(handler) { RunDialog(); } void RunDialog() { static const char kDefaultFileName[] = "trace.txt"; std::string path = handler_->GetDownloadPath(kDefaultFileName); if (path.empty()) path = kDefaultFileName; // Results in a call to OnFileDialogDismissed. handler_->GetBrowser()->GetHost()->RunFileDialog( FILE_DIALOG_SAVE, CefString(), path, std::vector<CefString>(), this); } virtual void OnFileDialogDismissed( CefRefPtr<CefBrowserHost> browser_host, const std::vector<CefString>& file_paths) OVERRIDE { CEF_REQUIRE_UI_THREAD(); if (!file_paths.empty()) { // File selected. Results in a call to OnEndTracingComplete. CefEndTracing(file_paths.front(), this); } else { // No file selected. Discard the trace data. CefEndTracing(CefString(), NULL); } } virtual void OnEndTracingComplete( const CefString& tracing_file) OVERRIDE { CEF_REQUIRE_UI_THREAD(); handler_->SetLastDownloadFile(tracing_file.ToString()); handler_->SendNotification(NOTIFY_DOWNLOAD_COMPLETE); } private:
PRBool confirm_overwrite_file (GtkWidget *parent, nsILocalFile* file) { nsCOMPtr<nsIStringBundleService> sbs = do_GetService(NS_STRINGBUNDLE_CONTRACTID); nsCOMPtr<nsIStringBundle> bundle; nsresult rv = sbs->CreateBundle("chrome://global/locale/filepicker.properties", getter_AddRefs(bundle)); if (NS_FAILED(rv)) { return PR_FALSE; } nsAutoString leafName; file->GetLeafName(leafName); const PRUnichar *formatStrings[] = { leafName.get() }; nsXPIDLString title, message; bundle->GetStringFromName(NS_LITERAL_STRING("confirmTitle").get(), getter_Copies(title)); bundle->FormatStringFromName(NS_LITERAL_STRING("confirmFileReplacing").get(), formatStrings, NS_ARRAY_LENGTH(formatStrings), getter_Copies(message)); GtkWindow *parent_window = GTK_WINDOW(parent); GtkWidget *dialog; dialog = gtk_message_dialog_new(parent_window, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO, NS_ConvertUTF16toUTF8(message).get()); gtk_window_set_title(GTK_WINDOW(dialog), NS_ConvertUTF16toUTF8(title).get()); if (parent_window && parent_window->group) { gtk_window_group_add_window(parent_window->group, GTK_WINDOW(dialog)); } PRBool result = (RunDialog(GTK_DIALOG (dialog)) == GTK_RESPONSE_YES); gtk_widget_destroy (dialog); return result; }
// the 'cmdsrun' parameter counts how many commands are run. // if a 'Inv Item Was Used' check does not pass, it doesn't count // so cmdsrun remains 0 if no inventory items matched int run_interaction_commandlist (InteractionCommandList *nicl, int *timesrun, int*cmdsrun) { size_t i; if (nicl == NULL) return -1; for (i = 0; i < nicl->Cmds.size(); i++) { cmdsrun[0] ++; int room_was = play.room_changes; switch (nicl->Cmds[i].Type) { case 0: // Do nothing break; case 1: // Run script { TempEip tempip(4001); RuntimeScriptValue rval_null; update_mp3(); if ((strstr(evblockbasename,"character")!=0) || (strstr(evblockbasename,"inventory")!=0)) { // Character or Inventory (global script) const char *torun = make_ts_func_name(evblockbasename,evblocknum,nicl->Cmds[i].Data[0].Value); // we are already inside the mouseclick event of the script, can't nest calls QueueScriptFunction(kScInstGame, torun); } else { // Other (room script) const char *torun = make_ts_func_name(evblockbasename,evblocknum,nicl->Cmds[i].Data[0].Value); QueueScriptFunction(kScInstRoom, torun); } update_mp3(); break; } case 2: // Add score (first time) if (timesrun[0] > 0) break; timesrun[0] ++; case 3: // Add score GiveScore (IPARAM1); break; case 4: // Display Message /* if (comprdata<0) display_message_aschar=evb->data[ss];*/ DisplayMessage(IPARAM1); break; case 5: // Play Music PlayMusicResetQueue(IPARAM1); break; case 6: // Stop Music stopmusic (); break; case 7: // Play Sound play_sound (IPARAM1); break; case 8: // Play Flic play_flc_file(IPARAM1, IPARAM2); break; case 9: // Run Dialog { int room_was = play.room_changes; RunDialog(IPARAM1); // if they changed room within the dialog script, // the interaction command list is no longer valid if (room_was != play.room_changes) return -1; } break; case 10: // Enable Dialog Option SetDialogOption (IPARAM1, IPARAM2, 1); break; case 11: // Disable Dialog Option SetDialogOption (IPARAM1, IPARAM2, 0); break; case 12: // Go To Screen Character_ChangeRoomAutoPosition(playerchar, IPARAM1, IPARAM2); return -1; case 13: // Add Inventory add_inventory (IPARAM1); break; case 14: // Move Object MoveObject (IPARAM1, IPARAM2, IPARAM3, IPARAM4); // if they want to wait until finished, do so if (IPARAM5) GameLoopUntilEvent(UNTIL_MOVEEND,(long)&objs[IPARAM1].moving); break; case 15: // Object Off ObjectOff (IPARAM1); break; case 16: // Object On ObjectOn (IPARAM1); break; case 17: // Set Object View SetObjectView (IPARAM1, IPARAM2); break; case 18: // Animate Object AnimateObject (IPARAM1, IPARAM2, IPARAM3, IPARAM4); break; case 19: // Move Character if (IPARAM4) MoveCharacterBlocking (IPARAM1, IPARAM2, IPARAM3, 0); else MoveCharacter (IPARAM1, IPARAM2, IPARAM3); break; case 20: // If Inventory Item was used if (play.usedinv == IPARAM1) { if (game.options[OPT_NOLOSEINV] == 0) lose_inventory (play.usedinv); if (run_interaction_commandlist (nicl->Cmds[i].Children.get(), timesrun, cmdsrun)) return -1; } else cmdsrun[0] --; break; case 21: // if player has inventory item if (playerchar->inv[IPARAM1] > 0) if (run_interaction_commandlist (nicl->Cmds[i].Children.get(), timesrun, cmdsrun)) return -1; break; case 22: // if a character is moving if (game.chars[IPARAM1].walking) if (run_interaction_commandlist (nicl->Cmds[i].Children.get(), timesrun, cmdsrun)) return -1; break; case 23: // if two variables are equal if (IPARAM1 == IPARAM2) if (run_interaction_commandlist (nicl->Cmds[i].Children.get(), timesrun, cmdsrun)) return -1; break; case 24: // Stop character walking StopMoving (IPARAM1); break; case 25: // Go to screen at specific co-ordinates NewRoomEx (IPARAM1, IPARAM2, IPARAM3); return -1; case 26: // Move NPC to different room if (!is_valid_character(IPARAM1)) quit("!Move NPC to different room: invalid character specified"); game.chars[IPARAM1].room = IPARAM2; break; case 27: // Set character view SetCharacterView (IPARAM1, IPARAM2); break; case 28: // Release character view ReleaseCharacterView (IPARAM1); break; case 29: // Follow character FollowCharacter (IPARAM1, IPARAM2); break; case 30: // Stop following FollowCharacter (IPARAM1, -1); break; case 31: // Disable hotspot DisableHotspot (IPARAM1); break; case 32: // Enable hotspot EnableHotspot (IPARAM1); break; case 33: // Set variable value get_interaction_variable(nicl->Cmds[i].Data[0].Value)->Value = IPARAM2; break; case 34: // Run animation scAnimateCharacter(IPARAM1, IPARAM2, IPARAM3, 0); GameLoopUntilEvent(UNTIL_SHORTIS0,(long)&game.chars[IPARAM1].animating); break; case 35: // Quick animation SetCharacterView (IPARAM1, IPARAM2); scAnimateCharacter(IPARAM1, IPARAM3, IPARAM4, 0); GameLoopUntilEvent(UNTIL_SHORTIS0,(long)&game.chars[IPARAM1].animating); ReleaseCharacterView (IPARAM1); break; case 36: // Set idle animation SetCharacterIdle (IPARAM1, IPARAM2, IPARAM3); break; case 37: // Disable idle animation SetCharacterIdle (IPARAM1, -1, -1); break; case 38: // Lose inventory item lose_inventory (IPARAM1); break; case 39: // Show GUI InterfaceOn (IPARAM1); break; case 40: // Hide GUI InterfaceOff (IPARAM1); break; case 41: // Stop running more commands return -1; case 42: // Face location FaceLocation (IPARAM1, IPARAM2, IPARAM3); break; case 43: // Pause command processor scrWait (IPARAM1); break; case 44: // Change character view ChangeCharacterView (IPARAM1, IPARAM2); break; case 45: // If player character is if (GetPlayerCharacter() == IPARAM1) if (run_interaction_commandlist (nicl->Cmds[i].Children.get(), timesrun, cmdsrun)) return -1; break; case 46: // if cursor mode is if (GetCursorMode() == IPARAM1) if (run_interaction_commandlist (nicl->Cmds[i].Children.get(), timesrun, cmdsrun)) return -1; break; case 47: // if player has been to room if (HasBeenToRoom(IPARAM1)) if (run_interaction_commandlist (nicl->Cmds[i].Children.get(), timesrun, cmdsrun)) return -1; break; default: quit("unknown new interaction command"); break; } // if the room changed within the action, nicl is no longer valid if (room_was != play.room_changes) return -1; } return 0; }
void ChordFileChooserWindow::OpenFile(string fileName) { RunDialog(new ChordFileWindow(fileName, Midi, SD_Card)); }
NS_IMETHODIMP nsFilePicker::Show(PRInt16 *aReturn) { NS_ENSURE_ARG_POINTER(aReturn); nsXPIDLCString title; title.Adopt(ToNewUTF8String(mTitle)); GtkWindow *parent_widget = get_gtk_window_for_nsiwidget(mParentWidget); GtkFileChooserAction action = GetGtkFileChooserAction(mMode); const gchar *accept_button = (mMode == GTK_FILE_CHOOSER_ACTION_SAVE) ? GTK_STOCK_SAVE : GTK_STOCK_OPEN; GtkWidget *file_chooser = _gtk_file_chooser_dialog_new(title, parent_widget, action, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, accept_button, GTK_RESPONSE_ACCEPT, NULL); if (mAllowURLs) { _gtk_file_chooser_set_local_only(GTK_FILE_CHOOSER(file_chooser), FALSE); } if (mMode == GTK_FILE_CHOOSER_ACTION_OPEN || mMode == GTK_FILE_CHOOSER_ACTION_SAVE) { GtkWidget *img_preview = _gtk_image_new(); _gtk_file_chooser_set_preview_widget(GTK_FILE_CHOOSER(file_chooser), img_preview); g_signal_connect(file_chooser, "update-preview", G_CALLBACK(UpdateFilePreviewWidget), img_preview); } if (parent_widget && parent_widget->group) { gtk_window_group_add_window(parent_widget->group, GTK_WINDOW(file_chooser)); } if (mMode == nsIFilePicker::modeOpenMultiple) { _gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER(file_chooser), TRUE); } else if (mMode == nsIFilePicker::modeSave) { char *default_filename = ToNewUTF8String(mDefault); _gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(file_chooser), static_cast<const gchar*>(default_filename)); nsMemory::Free(default_filename); } gtk_dialog_set_default_response(GTK_DIALOG(file_chooser), GTK_RESPONSE_ACCEPT); nsCAutoString directory; if (mDisplayDirectory) { mDisplayDirectory->GetNativePath(directory); } else if (mPrevDisplayDirectory) { mPrevDisplayDirectory->GetNativePath(directory); } if (!directory.IsEmpty()) { _gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(file_chooser), directory.get()); } PRInt32 count = mFilters.Count(); for (PRInt32 i = 0; i < count; ++i) { // This is fun... the GTK file picker does not accept a list of filters // so we need to split out each string, and add it manually. char **patterns = g_strsplit(mFilters[i]->get(), ";", -1); if (!patterns) { return NS_ERROR_OUT_OF_MEMORY; } GtkFileFilter *filter = _gtk_file_filter_new (); for (int j = 0; patterns[j] != NULL; ++j) { _gtk_file_filter_add_pattern (filter, g_strstrip (patterns[j])); } g_strfreev(patterns); if (!mFilterNames[i]->IsEmpty()) { // If we have a name for our filter, let's use that. const char *filter_name = mFilterNames[i]->get(); _gtk_file_filter_set_name (filter, filter_name); } else { // If we don't have a name, let's just use the filter pattern. const char *filter_pattern = mFilters[i]->get(); _gtk_file_filter_set_name (filter, filter_pattern); } _gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (file_chooser), filter); // Set the initially selected filter if (mSelectedType == i) { _gtk_file_chooser_set_filter (GTK_FILE_CHOOSER(file_chooser), filter); } } PRBool checkForOverwrite = PR_TRUE; if (_gtk_file_chooser_set_do_overwrite_confirmation) { checkForOverwrite = PR_FALSE; // Only available in GTK 2.8 _gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(file_chooser), PR_TRUE); } gint response = RunDialog(GTK_DIALOG (file_chooser)); switch (response) { case GTK_RESPONSE_ACCEPT: ReadValuesFromFileChooser(file_chooser); *aReturn = nsIFilePicker::returnOK; if (mMode == nsIFilePicker::modeSave) { nsCOMPtr<nsILocalFile> file; GetFile(getter_AddRefs(file)); if (file) { PRBool exists = PR_FALSE; file->Exists(&exists); if (exists) { PRBool overwrite = !checkForOverwrite || confirm_overwrite_file (file_chooser, file); if (overwrite) { *aReturn = nsIFilePicker::returnReplace; } else { *aReturn = nsIFilePicker::returnCancel; } } } } break; case GTK_RESPONSE_CANCEL: case GTK_RESPONSE_CLOSE: case GTK_RESPONSE_DELETE_EVENT: *aReturn = nsIFilePicker::returnCancel; break; default: NS_WARNING("Unexpected response"); *aReturn = nsIFilePicker::returnCancel; break; } gtk_widget_destroy(file_chooser); return NS_OK; }
int main(int argc, char *argv[]) { openfluid::base::Init(); openfluid::machine::SimulationBlob SBlob; openfluid::base::RuntimeEnvironment* RunEnv; openfluid::guicommon::RunDialogMachineListener* MachineListen = new openfluid::guicommon::RunDialogMachineListener(); openfluid::io::IOListener* IOListen = new openfluid::io::IOListener(); openfluid::machine::Engine* SimEngine; openfluid::machine::ModelInstance Model(SBlob,MachineListen); openfluid::io::FluidXReader FXReader(IOListen); try { std::string InputDir = ""; std::string OutputDir = ""; std::string PlugsDir = ""; if (argc == 4) { InputDir = std::string(argv[1]); OutputDir = std::string(argv[2]); PlugsDir = std::string(argv[3]); } else throw openfluid::base::OFException("openfluid-minimal","Incorrect number of arguments, should be <inputdir> <outputdir> <pluginsdir>"); RunEnv = openfluid::base::RuntimeEnvironment::getInstance(); RunEnv->setInputDir(InputDir); RunEnv->setOutputDir(OutputDir); RunEnv->addExtraPluginsPaths(PlugsDir); FXReader.loadFromDirectory(InputDir); openfluid::machine::Factory::buildSimulationBlobFromDescriptors(FXReader.getDomainDescriptor(), FXReader.getRunDescriptor(), FXReader.getOutputDescriptor(), FXReader.getDatstoreDescriptor(), SBlob); openfluid::machine::Factory::buildModelInstanceFromDescriptor(FXReader.getModelDescriptor(), Model); SimEngine = new openfluid::machine::Engine(SBlob, Model, MachineListen, IOListen); } catch (openfluid::base::OFException& E) { std::cerr << "ERROR: " + std::string(E.what()) << std::endl; } catch (std::bad_alloc& E) { std::cerr << "MEMORY ALLOCATION ERROR: " + std::string(E.what()) + ". Possibly not enough memory available" << std::endl; } catch (std::exception& E) { std::cerr << "SYSTEM ERROR: " + std::string(E.what()) << std::endl; } catch (...) { std::cerr << "UNKNOWN ERROR" << std::endl; } Gtk::Main kit(argc, argv); openfluid::guicommon::SimulationRunDialog RunDialog(SimEngine); Gtk::Main::run(RunDialog); delete SimEngine; return 0; }
NS_IMETHODIMP nsFilePicker::Show(PRInt16 *aReturn) { NS_ENSURE_ARG_POINTER(aReturn); nsXPIDLCString title; title.Adopt(ToNewUTF8String(mTitle)); GtkWindow *parent_widget = get_gtk_window_for_nsiwidget(mParentWidget); GtkFileChooserAction action = GetGtkFileChooserAction(mMode); const gchar *accept_button = (action == GTK_FILE_CHOOSER_ACTION_SAVE) ? GTK_STOCK_SAVE : GTK_STOCK_OPEN; #if (MOZ_PLATFORM_MAEMO == 5) GtkWidget *file_chooser = hildon_file_chooser_dialog_new_with_properties(parent_widget, "action", action, "open-button-text", accept_button, NULL); gtk_window_set_title(GTK_WINDOW(file_chooser), title); #else GtkWidget *file_chooser = gtk_file_chooser_dialog_new(title, parent_widget, action, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, accept_button, GTK_RESPONSE_ACCEPT, NULL); gtk_dialog_set_alternative_button_order(GTK_DIALOG(file_chooser), GTK_RESPONSE_ACCEPT, GTK_RESPONSE_CANCEL, -1); if (mAllowURLs) { gtk_file_chooser_set_local_only(GTK_FILE_CHOOSER(file_chooser), FALSE); } #endif if (action == GTK_FILE_CHOOSER_ACTION_OPEN || action == GTK_FILE_CHOOSER_ACTION_SAVE) { GtkWidget *img_preview = gtk_image_new(); gtk_file_chooser_set_preview_widget(GTK_FILE_CHOOSER(file_chooser), img_preview); g_signal_connect(file_chooser, "update-preview", G_CALLBACK(UpdateFilePreviewWidget), img_preview); } if (parent_widget && parent_widget->group) { gtk_window_group_add_window(parent_widget->group, GTK_WINDOW(file_chooser)); } NS_ConvertUTF16toUTF8 defaultName(mDefault); switch (mMode) { case nsIFilePicker::modeOpenMultiple: gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(file_chooser), TRUE); break; case nsIFilePicker::modeSave: gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(file_chooser), defaultName.get()); break; } nsCOMPtr<nsIFile> defaultPath; if (mDisplayDirectory) { mDisplayDirectory->Clone(getter_AddRefs(defaultPath)); } else if (mPrevDisplayDirectory) { mPrevDisplayDirectory->Clone(getter_AddRefs(defaultPath)); } if (defaultPath) { if (!defaultName.IsEmpty() && mMode != nsIFilePicker::modeSave) { // Try to select the intended file. Even if it doesn't exist, GTK still switches // directories. defaultPath->AppendNative(defaultName); nsCAutoString path; defaultPath->GetNativePath(path); gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(file_chooser), path.get()); } else { nsCAutoString directory; defaultPath->GetNativePath(directory); gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(file_chooser), directory.get()); } } gtk_dialog_set_default_response(GTK_DIALOG(file_chooser), GTK_RESPONSE_ACCEPT); PRInt32 count = mFilters.Length(); for (PRInt32 i = 0; i < count; ++i) { // This is fun... the GTK file picker does not accept a list of filters // so we need to split out each string, and add it manually. char **patterns = g_strsplit(mFilters[i].get(), ";", -1); if (!patterns) { return NS_ERROR_OUT_OF_MEMORY; } GtkFileFilter *filter = gtk_file_filter_new(); for (int j = 0; patterns[j] != NULL; ++j) { nsCAutoString caseInsensitiveFilter = MakeCaseInsensitiveShellGlob(g_strstrip(patterns[j])); gtk_file_filter_add_pattern(filter, caseInsensitiveFilter.get()); } g_strfreev(patterns); if (!mFilterNames[i].IsEmpty()) { // If we have a name for our filter, let's use that. const char *filter_name = mFilterNames[i].get(); gtk_file_filter_set_name(filter, filter_name); } else { // If we don't have a name, let's just use the filter pattern. const char *filter_pattern = mFilters[i].get(); gtk_file_filter_set_name(filter, filter_pattern); } gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(file_chooser), filter); // Set the initially selected filter if (mSelectedType == i) { gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(file_chooser), filter); } } gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(file_chooser), PR_TRUE); gint response = RunDialog(GTK_DIALOG(file_chooser)); switch (response) { case GTK_RESPONSE_OK: case GTK_RESPONSE_ACCEPT: ReadValuesFromFileChooser(file_chooser); *aReturn = nsIFilePicker::returnOK; if (mMode == nsIFilePicker::modeSave) { nsCOMPtr<nsILocalFile> file; GetFile(getter_AddRefs(file)); if (file) { PRBool exists = PR_FALSE; file->Exists(&exists); if (exists) *aReturn = nsIFilePicker::returnReplace; } } break; case GTK_RESPONSE_CANCEL: case GTK_RESPONSE_CLOSE: case GTK_RESPONSE_DELETE_EVENT: *aReturn = nsIFilePicker::returnCancel; break; default: NS_WARNING("Unexpected response"); *aReturn = nsIFilePicker::returnCancel; break; } gtk_widget_destroy(file_chooser); return NS_OK; }