LadspaEffectDialog::LadspaEffectDialog(LadspaEffect *eff, wxWindow * parent, const LADSPA_Descriptor *data, float *inputControls, int sampleRate, double length) :wxDialog(parent, -1, LAT1CTOWX(data->Name), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER), effect(eff) { mLength = length; numParams = 0; this->mData = data; this->inputControls = inputControls; this->sampleRate = sampleRate; #ifdef __WXMSW__ // On Windows, for some reason, wxWidgets calls OnTextCtrl during creation // of the text control, and LadspaEffectDialog::OnTextCtrl calls HandleText, // which assumes all the fields have been initialized. // This can give us a bad pointer crash, so manipulate inSlider to // no-op HandleText during creation. inSlider = true; #else inSlider = false; #endif inText = false; toggles = new wxCheckBox*[mData->PortCount]; sliders = new wxSlider*[mData->PortCount]; fields = new wxTextCtrl*[mData->PortCount]; labels = new wxStaticText*[mData->PortCount]; ports = new unsigned long [mData->PortCount]; unsigned long p; for(p=0; p<mData->PortCount; p++) { LADSPA_PortDescriptor d = mData->PortDescriptors[p]; if (LADSPA_IS_PORT_CONTROL(d) && LADSPA_IS_PORT_INPUT(d)) { ports[numParams] = p; numParams++; } } wxControl *item; wxBoxSizer *vSizer = new wxBoxSizer(wxVERTICAL); if (mData->Maker && mData->Maker[0] && LAT1CTOWX(mData->Maker) != wxString(_("None"))) { item = new wxStaticText(this, 0, wxString(_("Author: "))+LAT1CTOWX(mData->Maker)); vSizer->Add(item, 0, wxALL, 5); } if (mData->Copyright && mData->Copyright[0] && LAT1CTOWX(mData->Copyright) != wxString(_("None"))) { item = new wxStaticText(this, 0, LAT1CTOWX(mData->Copyright)); vSizer->Add(item, 0, wxALL, 5); } wxScrolledWindow *w = new wxScrolledWindow(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxVSCROLL | wxTAB_TRAVERSAL); // Try to give the window a sensible default/minimum size w->SetMinSize(wxSize( wxMax(600, parent->GetSize().GetWidth() * 2/3), parent->GetSize().GetHeight() / 2)); w->SetScrollRate(0, 20); vSizer->Add(w, 1, wxEXPAND|wxALL, 5); // Preview, OK, & Cancel buttons vSizer->Add(CreateStdButtonSizer(this, ePreviewButton|eCancelButton|eOkButton), 0, wxEXPAND); SetSizer(vSizer); wxSizer *paramSizer = new wxStaticBoxSizer(wxVERTICAL, w, _("Effect Settings")); wxFlexGridSizer *gridSizer = new wxFlexGridSizer(5, 0, 0); gridSizer->AddGrowableCol(3); for (p = 0; p < numParams; p++) { wxString labelText = LAT1CTOWX(mData->PortNames[ports[p]]); item = new wxStaticText(w, 0, labelText + wxT(":")); gridSizer->Add(item, 0, wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT | wxALL, 5); wxString fieldText; LADSPA_PortRangeHint hint = mData->PortRangeHints[ports[p]]; if (LADSPA_IS_HINT_TOGGLED(hint.HintDescriptor)) { toggles[p] = new wxCheckBox(w, p, wxT("")); toggles[p]->SetName(labelText); toggles[p]->SetValue(inputControls[ports[p]] > 0); gridSizer->Add(toggles[p], 0, wxALL, 5); ConnectFocus(toggles[p]); gridSizer->Add(1, 1, 0); gridSizer->Add(1, 1, 0); gridSizer->Add(1, 1, 0); } else { if (LADSPA_IS_HINT_INTEGER(hint.HintDescriptor)) fieldText.Printf(wxT("%d"), (int)(inputControls[ports[p]] + 0.5)); else fieldText = Internat::ToDisplayString(inputControls[ports[p]]); fields[p] = new wxTextCtrl(w, p, fieldText); fields[p]->SetName(labelText); gridSizer->Add(fields[p], 0, wxALIGN_CENTER_VERTICAL | wxALL, 5); ConnectFocus(fields[p]); wxString bound; double lower = 0.0; double upper = 0.0; bool haslo = false; bool hashi = false; bool forceint = false; if (LADSPA_IS_HINT_BOUNDED_BELOW(hint.HintDescriptor)) { lower = hint.LowerBound; haslo = true; } if (LADSPA_IS_HINT_BOUNDED_ABOVE(hint.HintDescriptor)) { upper = hint.UpperBound; hashi = true; } if (LADSPA_IS_HINT_SAMPLE_RATE(hint.HintDescriptor)) { lower *= sampleRate * 1000; upper *= sampleRate; forceint = true; } wxString str; if (haslo) { if (LADSPA_IS_HINT_INTEGER(hint.HintDescriptor) || forceint) str.Printf(wxT("%d"), (int)(lower + 0.5)); else str = Internat::ToDisplayString(lower); item = new wxStaticText(w, 0, str); gridSizer->Add(item, 0, wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT | wxALL, 5); } else { gridSizer->Add(1, 1, 0); } sliders[p] = new wxSlider(w, p, 0, 0, 1000, wxDefaultPosition, wxSize(200, -1)); sliders[p]->SetName(labelText); gridSizer->Add(sliders[p], 0, wxALIGN_CENTER_VERTICAL | wxEXPAND | wxALL, 5); ConnectFocus(sliders[p]); if (hashi) { if (LADSPA_IS_HINT_INTEGER(hint.HintDescriptor) || forceint) str.Printf(wxT("%d"), (int)(upper + 0.5)); else str = Internat::ToDisplayString(upper); item = new wxStaticText(w, 0, str); gridSizer->Add(item, 0, wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT | wxALL, 5); } else { gridSizer->Add(1, 1, 0); } } } // Now add the length control if (effect->GetEffectFlags() & INSERT_EFFECT) { item = new wxStaticText(w, 0, _("Length (seconds)")); gridSizer->Add(item, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5); mSeconds = new wxTextCtrl(w, LADSPA_SECONDS_ID, Internat::ToDisplayString(length)); mSeconds->SetName(_("Length (seconds)")); gridSizer->Add(mSeconds, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5); gridSizer->Add(1, 1, 0); gridSizer->Add(1, 1, 0); gridSizer->Add(1, 1, 0); ConnectFocus(mSeconds); } // Set all of the sliders based on the value in the // text fields inSlider = false; // Now we're ready for HandleText to actually do something. HandleText(); paramSizer->Add(gridSizer, 1, wxEXPAND | wxALL, 5); w->SetSizer(paramSizer); Layout(); Fit(); SetSizeHints(GetSize()); }
void LV2EffectDialog::OnTextCtrl(wxCommandEvent & WXUNUSED(event)) { HandleText(); }
LadspaEffectDialog::LadspaEffectDialog(LadspaEffect *eff, wxWindow * parent, const LADSPA_Descriptor *data, float *inputControls, int sampleRate) :wxDialog(parent, -1, data->Name, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE), effect(eff) { numParams = 0; this->mData = data; this->inputControls = inputControls; this->sampleRate = sampleRate; #ifdef __WXMSW__ // On Windows, for some reason, wxWindows calls OnTextCtrl during creation // of the text control, and LadspaEffectDialog::OnTextCtrl calls HandleText, // which assumes all the fields have been initialized. // This can give us a bad pointer crash, so manipulate inSlider to // no-op HandleText during creation. inSlider = true; #else inSlider = false; #endif inText = false; targetSlider = NULL; sliders = new wxSlider*[mData->PortCount]; fields = new wxTextCtrl*[mData->PortCount]; labels = new wxStaticText*[mData->PortCount]; ports = new unsigned long [mData->PortCount]; unsigned long p; for(p=0; p<mData->PortCount; p++) { LADSPA_PortDescriptor d = mData->PortDescriptors[p]; if (LADSPA_IS_PORT_CONTROL(d) && LADSPA_IS_PORT_INPUT(d)) { ports[numParams] = p; numParams++; } } wxBoxSizer *mainSizer = new wxBoxSizer(wxVERTICAL); wxControl *item; if (mData->Maker && mData->Maker[0] && mData->Maker != wxString(_("None"))) { item = new wxStaticText(this, 0, wxString(_("Author: "))+mData->Maker); mainSizer->Add(item, 0, wxALL, 5); } if (mData->Copyright && mData->Copyright[0] && mData->Copyright != wxString(_("None"))) { item = new wxStaticText(this, 0, mData->Copyright); mainSizer->Add(item, 0, wxALL, 5); } wxSizer *paramSizer = new wxStaticBoxSizer(new wxStaticBox(this, -1, _("Effect Settings")), wxVERTICAL ); wxFlexGridSizer *gridSizer = new wxFlexGridSizer(3, 0, 0); for (p = 0; p < numParams; p++) { item = new wxStaticText(this, 0, mData->PortNames[ports[p]]); gridSizer->Add(item, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5); wxString fieldText; LADSPA_PortRangeHint hint = mData->PortRangeHints[ports[p]]; if (LADSPA_IS_HINT_INTEGER(hint.HintDescriptor)) fieldText.Printf("%d", (int)(inputControls[ports[p]] + 0.5)); else fieldText.Printf("%f", inputControls[ports[p]]); fields[p] = new wxTextCtrl(this, LADSPA_TEXTCTRL_ID, fieldText); gridSizer->Add(fields[p], 0, wxALL, 5); sliders[p] = new wxSlider(this, LADSPA_SLIDER_ID, 0, 0, 1000, wxDefaultPosition, wxSize(200, -1)); gridSizer->Add(sliders[p], 0, wxALL, 5); } // Set all of the sliders based on the value in the // text fields inSlider = false; // Now we're ready for HandleText to actually do something. HandleText(); paramSizer->Add(gridSizer, 1, wxALL, 5); mainSizer->Add(paramSizer, 1, wxALL, 5); wxBoxSizer *okSizer = new wxBoxSizer(wxHORIZONTAL); wxButton *button; button = new wxButton(this, LADSPA_PREVIEW_ID, effect->GetPreviewName()); okSizer->Add(button, 0, wxALIGN_CENTRE | wxALL, 5); button = new wxButton(this, wxID_CANCEL, _("Cancel")); okSizer->Add(button, 0, wxALIGN_CENTRE | wxALL, 5); button = new wxButton(this, wxID_OK, _("OK")); button->SetDefault(); button->SetFocus(); okSizer->Add(button, 0, wxALIGN_CENTRE | wxALL, 5); mainSizer->Add(okSizer, 0, wxALIGN_CENTRE | wxALL, 5); SetAutoLayout(TRUE); SetSizer(mainSizer); mainSizer->Fit(this); mainSizer->SetSizeHints(this); }
LV2EffectDialog::LV2EffectDialog(LV2Effect *eff, wxWindow * parent, SLV2Plugin data, int sampleRate, double length, double noteLength, unsigned char noteVelocity, unsigned char noteKey) :wxDialog(parent, -1, LAT1CTOWX(slv2_value_as_string(slv2_plugin_get_name(data))), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER), effect(eff), mControls(eff->GetControls()) { mLength = length; this->mData = data; this->sampleRate = sampleRate; #ifdef __WXMSW__ // On Windows, for some reason, wxWindows calls OnTextCtrl during creation // of the text control, and LV2EffectDialog::OnTextCtrl calls HandleText, // which assumes all the fields have been initialized. // This can give us a bad pointer crash, so manipulate inSlider to // no-op HandleText during creation. inSlider = true; #else inSlider = false; #endif inText = false; // Allocate memory for the user parameter controls toggles = new wxCheckBox*[mControls.size()]; sliders = new wxSlider*[mControls.size()]; fields = new wxTextCtrl*[mControls.size()]; labels = new wxStaticText*[mControls.size()]; wxControl *item; wxBoxSizer *vSizer = new wxBoxSizer(wxVERTICAL); // Add information about the plugin SLV2Value tmpValue = slv2_plugin_get_author_name(data); if (tmpValue) { const char* author = slv2_value_as_string(tmpValue); item = new wxStaticText(this, 0, wxString(_("Author: "))+LAT1CTOWX(author)); vSizer->Add(item, 0, wxALL, 5); slv2_value_free(tmpValue); } wxScrolledWindow *w = new wxScrolledWindow(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxVSCROLL | wxTAB_TRAVERSAL); // Try to give the window a sensible default/minimum size w->SetMinSize(wxSize( wxMax(600, parent->GetSize().GetWidth() * 2/3), parent->GetSize().GetHeight() / 2)); w->SetScrollRate(0, 20); vSizer->Add(w, 1, wxEXPAND|wxALL, 5); // Preview, OK, & Cancel buttons vSizer->Add(CreateStdButtonSizer(this, ePreviewButton|eCancelButton|eOkButton), 0, wxEXPAND); SetSizer(vSizer); wxSizer *paramSizer = new wxStaticBoxSizer(wxVERTICAL, w, _("Effect Settings")); wxFlexGridSizer *gridSizer = new wxFlexGridSizer(5, 0, 0); gridSizer->AddGrowableCol(3); const LV2PortGroup& rootGroup = eff->GetPortGroups(); const ScalePointMap& scalePoints = eff->GetScalePoints(); // Now add the length control if (effect->GetEffectFlags() & INSERT_EFFECT) { item = new wxStaticText(w, 0, _("Length (seconds)")); gridSizer->Add(item, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5); mSeconds = new wxTextCtrl(w, LADSPA_SECONDS_ID, Internat::ToDisplayString(length)); mSeconds->SetName(_("Length (seconds)")); gridSizer->Add(mSeconds, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5); gridSizer->Add(1, 1, 0); gridSizer->Add(1, 1, 0); gridSizer->Add(1, 1, 0); ConnectFocus(mSeconds); } // The note controls if the plugin is a synth if (effect->IsSynth()) { // Note length control item = new wxStaticText(w, 0, _("Note length (seconds)")); gridSizer->Add(item, 0, wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT | wxALL, 5); mNoteSeconds = new wxTextCtrl(w, LADSPA_SECONDS_ID, Internat::ToDisplayString(length / 2)); mNoteSeconds->SetName(_("Note length (seconds)")); gridSizer->Add(mNoteSeconds, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5); gridSizer->Add(1, 1, 0); gridSizer->Add(1, 1, 0); gridSizer->Add(1, 1, 0); ConnectFocus(mNoteSeconds); // Note velocity control item = new wxStaticText(w, 0, _("Note velocity")); gridSizer->Add(item, 0, wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT | wxALL, 5); mNoteVelocity = new wxTextCtrl(w, LADSPA_SECONDS_ID, Internat::ToDisplayString(64)); mNoteVelocity->SetName(_("Note velocity")); gridSizer->Add(mNoteVelocity, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5); gridSizer->Add(1, 1, 0); gridSizer->Add(1, 1, 0); gridSizer->Add(1, 1, 0); ConnectFocus(mNoteVelocity); // Note key control item = new wxStaticText(w, 0, _("Note key")); gridSizer->Add(item, 0, wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT | wxALL, 5); mNoteKey = new wxTextCtrl(w, LADSPA_SECONDS_ID, Internat::ToDisplayString(64)); mNoteKey->SetName(_("Note key")); gridSizer->Add(mNoteKey, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5); gridSizer->Add(1, 1, 0); gridSizer->Add(1, 1, 0); gridSizer->Add(1, 1, 0); ConnectFocus(mNoteKey); } paramSizer->Add(gridSizer, 1, wxEXPAND | wxALL, 5); // Create user parameter controls std::queue<const LV2PortGroup*> groups; groups.push(&rootGroup); while (!groups.empty()) { const LV2PortGroup* pg = groups.front(); groups.pop(); if (pg->GetName() != wxT("")) { wxSizer *groupSizer = new wxStaticBoxSizer(wxVERTICAL, w, pg->GetName()); paramSizer->Add(groupSizer, 0, wxEXPAND | wxALL, 5); gridSizer = new wxFlexGridSizer(5, 0, 0); gridSizer->AddGrowableCol(3); groupSizer->Add(gridSizer, 1, wxEXPAND | wxALL, 5); } std::vector<LV2PortGroup>::const_iterator iter; for (iter = pg->GetSubGroups().begin(); iter != pg->GetSubGroups().end(); ++iter) { groups.push(&*iter); } const std::vector<uint32_t>& params = pg->GetParameters(); for (uint32_t k = 0; k < params.size(); ++k) { uint32_t p = params[k]; wxString labelText = mControls[p].mName; item = new wxStaticText(w, 0, labelText + wxT(":")); gridSizer->Add(item, 0, wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT | wxALL, 5); wxString fieldText; if (mControls[p].mToggle) { toggles[p] = new wxCheckBox(w, p, wxT("")); toggles[p]->SetName(labelText); toggles[p]->SetValue(mControls[p].mControlBuffer > 0); gridSizer->Add(toggles[p], 0, wxALL, 5); ConnectFocus(toggles[p]); gridSizer->Add(1, 1, 0); gridSizer->Add(1, 1, 0); gridSizer->Add(1, 1, 0); } else { if (mControls[p].mInteger) fieldText.Printf(wxT("%d"), (int)(mControls[p].mControlBuffer + 0.5)); else fieldText = Internat::ToDisplayString(mControls[p].mControlBuffer); fields[p] = new wxTextCtrl(w, p, fieldText); fields[p]->SetName(labelText); gridSizer->Add(fields[p], 0, wxALIGN_CENTER_VERTICAL | wxALL, 5); ConnectFocus(fields[p]); wxString bound; double lower = 0.0; double upper = 0.0; bool haslo = false; bool hashi = false; bool forceint = false; wxString loLabel; wxString hiLabel; ScalePointMap::const_iterator iter = scalePoints.find(mControls[p].mIndex); if (!std::isnan(mControls[p].mMin)) { lower = mControls[p].mMin; haslo = true; if (iter != scalePoints.end()) { std::map<float, wxString>::const_iterator iter2 = iter->second.find(lower); if (iter2 != iter->second.end()) { loLabel = iter2->second; } } } if (!std::isnan(mControls[p].mMax)) { upper = mControls[p].mMax; hashi = true; if (iter != scalePoints.end()) { std::map<float, wxString>::const_iterator iter2 = iter->second.find(upper); if (iter2 != iter->second.end()) hiLabel = iter2->second; } } if (mControls[p].mSampleRate) { lower *= sampleRate * 1000; upper *= sampleRate; forceint = true; } wxString str; if (haslo) { str = loLabel; if (str.IsEmpty()) { if (mControls[p].mInteger || forceint) str.Printf(wxT("%d"), (int)(lower + 0.5)); else str = Internat::ToDisplayString(lower); } item = new wxStaticText(w, 0, str); gridSizer->Add(item, 0, wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT | wxALL, 5); } else { gridSizer->Add(1, 1, 0); } sliders[p] = new wxSlider(w, p, 0, 0, 1000, wxDefaultPosition, wxSize(200, -1)); sliders[p]->SetName(labelText); gridSizer->Add(sliders[p], 0, wxALIGN_CENTER_VERTICAL | wxEXPAND | wxALL, 5); ConnectFocus(sliders[p]); if (hashi) { str = hiLabel; if (str.IsEmpty()) { if (mControls[p].mInteger || forceint) str.Printf(wxT("%d"), (int)(upper + 0.5)); else str = Internat::ToDisplayString(upper); } item = new wxStaticText(w, 0, str); gridSizer->Add(item, 0, wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT | wxALL, 5); } else { gridSizer->Add(1, 1, 0); } } } } // Set all of the sliders based on the value in the // text fields inSlider = false; // Now we're ready for HandleText to actually do something. HandleText(); w->SetSizer(paramSizer); Layout(); Fit(); SetSizeHints(GetSize()); }
LadspaEffectDialog::LadspaEffectDialog(wxWindow * parent, const LADSPA_Descriptor *data, float *inputControls, int sampleRate) :wxDialog(parent, -1, data->Name, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE) { numParams = 0; this->mData = data; this->inputControls = inputControls; this->sampleRate = sampleRate; inSlider = false; inText = false; targetSlider = NULL; sliders = new wxSlider*[mData->PortCount]; fields = new wxTextCtrl*[mData->PortCount]; labels = new wxStaticText*[mData->PortCount]; ports = new unsigned long [mData->PortCount]; unsigned long p; for(p=0; p<mData->PortCount; p++) { LADSPA_PortDescriptor d = mData->PortDescriptors[p]; if (LADSPA_IS_PORT_CONTROL(d) && LADSPA_IS_PORT_INPUT(d)) { ports[numParams] = p; numParams++; } } wxBoxSizer *mainSizer = new wxBoxSizer(wxVERTICAL); wxControl *item; item = new wxStaticText(this, 0, wxString(_("Author: "))+mData->Maker); mainSizer->Add(item, 0, wxALL, 5); if (mData->Copyright && mData->Copyright[0] && mData->Copyright != wxString(_("None"))) { item = new wxStaticText(this, 0, mData->Copyright); mainSizer->Add(item, 0, wxALL, 5); } wxSizer *paramSizer = new wxStaticBoxSizer(new wxStaticBox(this, -1, _("Ladspa Effect Settings")), wxVERTICAL ); wxFlexGridSizer *gridSizer = new wxFlexGridSizer(3, 0, 0); for (p = 0; p < numParams; p++) { item = new wxStaticText(this, 0, mData->PortNames[ports[p]]); gridSizer->Add(item, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5); wxString fieldText; LADSPA_PortRangeHint hint = mData->PortRangeHints[ports[p]]; if (LADSPA_IS_HINT_INTEGER(hint.HintDescriptor)) fieldText.Printf("%d", (int)(inputControls[ports[p]] + 0.5)); else fieldText.Printf("%f", inputControls[ports[p]]); fields[p] = new wxTextCtrl(this, LADSPA_TEXTCTRL_ID, fieldText); gridSizer->Add(fields[p], 0, wxALL, 5); sliders[p] = new wxSlider(this, LADSPA_SLIDER_ID, 0, 0, 1000, wxDefaultPosition, wxSize(200, -1)); gridSizer->Add(sliders[p], 0, wxALL, 5); } // Set all of the sliders based on the value in the // text fields HandleText(); paramSizer->Add(gridSizer, 1, wxALL, 5); mainSizer->Add(paramSizer, 1, wxALL, 5); wxBoxSizer *okSizer = new wxBoxSizer(wxHORIZONTAL); wxButton *button; button = new wxButton(this, wxID_OK, _("OK")); button->SetDefault(); button->SetFocus(); okSizer->Add(button, 0, wxALIGN_CENTRE | wxALL, 5); button = new wxButton(this, wxID_CANCEL, _("Cancel")); okSizer->Add(button, 0, wxALIGN_CENTRE | wxALL, 5); mainSizer->Add(okSizer, 0, wxALIGN_CENTRE | wxALL, 5); SetAutoLayout(TRUE); SetSizer(mainSizer); mainSizer->Fit(this); mainSizer->SetSizeHints(this); }
NS_IMETHODIMP EditorEventListener::HandleEvent(nsIDOMEvent* aEvent) { NS_ENSURE_TRUE(mEditorBase, NS_ERROR_FAILURE); nsCOMPtr<nsIEditor> kungFuDeathGrip = mEditorBase; Unused << kungFuDeathGrip; // mEditorBase is not referred to in this function WidgetEvent* internalEvent = aEvent->WidgetEventPtr(); // Let's handle each event with the message of the internal event of the // coming event. If the DOM event was created with improper interface, // e.g., keydown event is created with |new MouseEvent("keydown", {});|, // its message is always 0. Therefore, we can ban such strange event easy. // However, we need to handle strange "focus" and "blur" event. See the // following code of this switch statement. // NOTE: Each event handler may require specific event interface. Before // calling it, this queries the specific interface. If it would fail, // each event handler would just ignore the event. So, in this method, // you don't need to check if the QI succeeded before each call. switch (internalEvent->mMessage) { // dragenter case eDragEnter: { nsCOMPtr<nsIDOMDragEvent> dragEvent = do_QueryInterface(aEvent); return DragEnter(dragEvent); } // dragover case eDragOver: { nsCOMPtr<nsIDOMDragEvent> dragEvent = do_QueryInterface(aEvent); return DragOver(dragEvent); } // dragexit case eDragExit: { nsCOMPtr<nsIDOMDragEvent> dragEvent = do_QueryInterface(aEvent); return DragExit(dragEvent); } // drop case eDrop: { nsCOMPtr<nsIDOMDragEvent> dragEvent = do_QueryInterface(aEvent); return Drop(dragEvent); } #ifdef HANDLE_NATIVE_TEXT_DIRECTION_SWITCH // keydown case eKeyDown: { nsCOMPtr<nsIDOMKeyEvent> keyEvent = do_QueryInterface(aEvent); return KeyDown(keyEvent); } // keyup case eKeyUp: { nsCOMPtr<nsIDOMKeyEvent> keyEvent = do_QueryInterface(aEvent); return KeyUp(keyEvent); } #endif // #ifdef HANDLE_NATIVE_TEXT_DIRECTION_SWITCH // keypress case eKeyPress: { nsCOMPtr<nsIDOMKeyEvent> keyEvent = do_QueryInterface(aEvent); return KeyPress(keyEvent); } // mousedown case eMouseDown: { nsCOMPtr<nsIDOMMouseEvent> mouseEvent = do_QueryInterface(aEvent); NS_ENSURE_TRUE(mouseEvent, NS_OK); // EditorEventListener may receive (1) all mousedown, mouseup and click // events, (2) only mousedown event or (3) only mouseup event. // mMouseDownOrUpConsumedByIME is used only for ignoring click event if // preceding mousedown and/or mouseup event is consumed by IME. // Therefore, even if case #2 or case #3 occurs, // mMouseDownOrUpConsumedByIME is true here. Therefore, we should always // overwrite it here. mMouseDownOrUpConsumedByIME = NotifyIMEOfMouseButtonEvent(mouseEvent); return mMouseDownOrUpConsumedByIME ? NS_OK : MouseDown(mouseEvent); } // mouseup case eMouseUp: { nsCOMPtr<nsIDOMMouseEvent> mouseEvent = do_QueryInterface(aEvent); NS_ENSURE_TRUE(mouseEvent, NS_OK); // See above comment in the eMouseDown case, first. // This code assumes that case #1 is occuring. However, if case #3 may // occurs after case #2 and the mousedown is consumed, // mMouseDownOrUpConsumedByIME is true even though EditorEventListener // has not received the preceding mousedown event of this mouseup event. // So, mMouseDownOrUpConsumedByIME may be invalid here. However, // this is not a matter because mMouseDownOrUpConsumedByIME is referred // only by eMouseClick case but click event is fired only in case #1. // So, before a click event is fired, mMouseDownOrUpConsumedByIME is // always initialized in the eMouseDown case if it's referred. if (NotifyIMEOfMouseButtonEvent(mouseEvent)) { mMouseDownOrUpConsumedByIME = true; } return mMouseDownOrUpConsumedByIME ? NS_OK : MouseUp(mouseEvent); } // click case eMouseClick: { nsCOMPtr<nsIDOMMouseEvent> mouseEvent = do_QueryInterface(aEvent); NS_ENSURE_TRUE(mouseEvent, NS_OK); // If the preceding mousedown event or mouseup event was consumed, // editor shouldn't handle this click event. if (mMouseDownOrUpConsumedByIME) { mMouseDownOrUpConsumedByIME = false; mouseEvent->AsEvent()->PreventDefault(); return NS_OK; } return MouseClick(mouseEvent); } // focus case eFocus: return Focus(aEvent); // blur case eBlur: return Blur(aEvent); // text case eCompositionChange: return HandleText(aEvent); // compositionstart case eCompositionStart: return HandleStartComposition(aEvent); // compositionend case eCompositionEnd: HandleEndComposition(aEvent); return NS_OK; default: break; } nsAutoString eventType; aEvent->GetType(eventType); // We should accept "focus" and "blur" event even if it's synthesized with // wrong interface for compatibility with older Gecko. if (eventType.EqualsLiteral("focus")) { return Focus(aEvent); } if (eventType.EqualsLiteral("blur")) { return Blur(aEvent); } #ifdef DEBUG nsPrintfCString assertMessage("Editor doesn't handle \"%s\" event " "because its internal event doesn't have proper message", NS_ConvertUTF16toUTF8(eventType).get()); NS_ASSERTION(false, assertMessage.get()); #endif return NS_OK; }
NS_IMETHODIMP nsAutoCompleteController::HandleDelete(PRBool *_retval) { *_retval = PR_FALSE; if (!mInput) return NS_OK; nsCOMPtr<nsIAutoCompleteInput> input(mInput); PRBool isOpen = PR_FALSE; input->GetPopupOpen(&isOpen); if (!isOpen || mRowCount <= 0) { // Nothing left to delete, proceed as normal HandleText(); return NS_OK; } nsCOMPtr<nsIAutoCompletePopup> popup; input->GetPopup(getter_AddRefs(popup)); PRInt32 index, searchIndex, rowIndex; popup->GetSelectedIndex(&index); RowIndexToSearch(index, &searchIndex, &rowIndex); NS_ENSURE_TRUE(searchIndex >= 0 && rowIndex >= 0, NS_ERROR_FAILURE); nsIAutoCompleteResult *result = mResults[searchIndex]; NS_ENSURE_TRUE(result, NS_ERROR_FAILURE); nsAutoString search; input->GetSearchParam(search); // Clear the row in our result and in the DB. result->RemoveValueAt(rowIndex, PR_TRUE); --mRowCount; // We removed it, so make sure we cancel the event that triggered this call. *_retval = PR_TRUE; // Unselect the current item. popup->SetSelectedIndex(-1); // Tell the tree that the row count changed. if (mTree) mTree->RowCountChanged(mRowCount, -1); // Adjust index, if needed. if (index >= (PRInt32)mRowCount) index = mRowCount - 1; if (mRowCount > 0) { // There are still rows in the popup, select the current index again. popup->SetSelectedIndex(index); // Complete to the new current value. PRBool shouldComplete = PR_FALSE; mInput->GetCompleteDefaultIndex(&shouldComplete); if (shouldComplete) { nsAutoString value; if (NS_SUCCEEDED(GetResultValueAt(index, PR_TRUE, value))) { CompleteValue(value); } } // Invalidate the popup. popup->Invalidate(); } else { // Nothing left in the popup, clear any pending search timers and // close the popup. ClearSearchTimer(); ClosePopup(); } return NS_OK; }
VampEffectDialog::VampEffectDialog(VampEffect *effect, wxWindow *parent, Vamp::Plugin *plugin) : wxDialog(parent, -1, effect->GetEffectName(), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER), mEffect(effect), mPlugin(plugin) { Vamp::Plugin::ProgramList programs = plugin->getPrograms(); mParameters = plugin->getParameterDescriptors(); #if defined(__WXMSW__) || (defined(__WXGTK__) && wxCHECK_VERSION(3, 0, 0)) // In some environments wxWidgets calls OnTextCtrl during creation // of the text control, and VampEffectDialog::OnTextCtrl calls HandleText, // which assumes all the fields have been initialized. // This can give us a bad pointer crash, so manipulate inSlider to // no-op HandleText during creation. inSlider = true; #else inSlider = false; #endif inText = false; int count = mParameters.size(); toggles = new wxCheckBox*[count]; sliders = new wxSlider*[count]; fields = new wxTextCtrl*[count]; labels = new wxStaticText*[count]; combos = new wxComboBox*[count]; wxControl *item; wxBoxSizer *vSizer = new wxBoxSizer(wxVERTICAL); item = new wxStaticText(this, 0, LAT1CTOWX(plugin->getName().c_str()) + wxString(_(" - Vamp audio analysis plugin"))); vSizer->Add(item, 0, wxALL, 5); item = new wxStaticText(this, 0, LAT1CTOWX(plugin->getDescription().c_str())); vSizer->Add(item, 0, wxALL, 5); item = new wxStaticText(this, 0, wxString(_("Author: ")) + LAT1CTOWX(plugin->getMaker().c_str())); vSizer->Add(item, 0, wxALL, 5); item = new wxStaticText(this, 0, LAT1CTOWX(plugin->getCopyright().c_str())); vSizer->Add(item, 0, wxALL, 5); wxScrolledWindow *w = new wxScrolledWindow(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxVSCROLL | wxTAB_TRAVERSAL); // Try to give the window a sensible default/minimum size w->SetMinSize(wxSize( wxMax(400, parent->GetSize().GetWidth() / 2), parent->GetSize().GetHeight() / 2)); w->SetScrollRate(0, 20); vSizer->Add(w, 1, wxEXPAND|wxALL, 5); vSizer->Add(CreateStdButtonSizer(this, eCancelButton|eOkButton), 0, wxEXPAND); SetSizer(vSizer); wxSizer *paramSizer = new wxStaticBoxSizer(wxVERTICAL, w, _("Plugin Settings")); wxFlexGridSizer *gridSizer = new wxFlexGridSizer(5, 0, 0); gridSizer->AddGrowableCol(3); programCombo = 0; if (!programs.empty()) { wxArrayString choices; wxString currentProgram = wxString(mPlugin->getCurrentProgram().c_str(), wxConvISO8859_1); for (size_t i = 0; i < programs.size(); ++i) { wxString choice = wxString(programs[i].c_str(), wxConvISO8859_1); choices.Add(choice); } gridSizer->Add(new wxStaticText(w, 0, _("Program")), 0, wxALIGN_CENTER_VERTICAL | wxALL, 5); programCombo = new wxComboBox(w, 9999, currentProgram, wxDefaultPosition, wxDefaultSize, choices, wxCB_READONLY); programCombo->SetName(_("Program")); gridSizer->Add(1, 1, 0); gridSizer->Add(1, 1, 0); gridSizer->Add(programCombo, 0, wxALIGN_CENTER_VERTICAL | wxEXPAND | wxALL, 5); ConnectFocus(programCombo); gridSizer->Add(1, 1, 0); } for (int p = 0; p < count; p++) { wxString labelText = LAT1CTOWX(mParameters[p].name.c_str()); item = new wxStaticText(w, 0, labelText + wxT(":")); item->SetName(labelText); gridSizer->Add(item, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5); wxString fieldText; float value = mPlugin->getParameter(mParameters[p].identifier); toggles[p] = 0; combos[p] = 0; sliders[p] = 0; fields[p] = 0; if (mParameters[p].isQuantized && mParameters[p].quantizeStep == 1.0 && mParameters[p].minValue == 0.0 && mParameters[p].maxValue == 1.0) { toggles[p] = new wxCheckBox(w, p, wxT("")); toggles[p]->SetName(labelText); toggles[p]->SetValue(value > 0.5); gridSizer->Add(toggles[p], 0, wxALL, 5); ConnectFocus(toggles[p]); gridSizer->Add(1, 1, 0); gridSizer->Add(1, 1, 0); gridSizer->Add(1, 1, 0); } else if (mParameters[p].isQuantized && mParameters[p].quantizeStep == 1.0 && !mParameters[p].valueNames.empty()) { wxArrayString choices; wxString selected; for (size_t i = 0; i < mParameters[p].valueNames.size(); ++i) { wxString choice = wxString (mParameters[p].valueNames[i].c_str(), wxConvISO8859_1); if (size_t(value - mParameters[p].minValue + 0.5) == i) { selected = choice; } choices.Add(choice); } combos[p] = new wxComboBox(w, p, selected, wxDefaultPosition, wxDefaultSize, choices, wxCB_READONLY); combos[p]->SetName(labelText); gridSizer->Add(1, 1, 0); gridSizer->Add(1, 1, 0); gridSizer->Add(combos[p], 0, wxALIGN_CENTER_VERTICAL | wxEXPAND | wxALL, 5); ConnectFocus(combos[p]); gridSizer->Add(1, 1, 0); } else { fieldText = Internat::ToDisplayString(value); fields[p] = new wxTextCtrl(w, p, fieldText); fields[p]->SetName(labelText); gridSizer->Add(fields[p], 0, wxALIGN_CENTER_VERTICAL | wxALL, 5); ConnectFocus(fields[p]); wxString str = Internat::ToDisplayString(mParameters[p].minValue); item = new wxStaticText(w, 0, str); gridSizer->Add(item, 0, wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT | wxALL, 5); sliders[p] = new wxSlider(w, p, 0, 0, 1000, wxDefaultPosition, wxSize(100, -1)); sliders[p]->SetName(labelText); gridSizer->Add(sliders[p], 0, wxALIGN_CENTER_VERTICAL | wxEXPAND | wxALL, 5); ConnectFocus(sliders[p]); str = Internat::ToDisplayString(mParameters[p].maxValue); item = new wxStaticText(w, 0, str); gridSizer->Add(item, 0, wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT | wxALL, 5); } } // Set all of the sliders based on the value in the // text fields inSlider = false; // Now we're ready for HandleText to actually do something. HandleText(); paramSizer->Add(gridSizer, 1, wxEXPAND | wxALL, 5); w->SetSizer(paramSizer); Layout(); Fit(); SetSizeHints(GetSize()); }
void HtmlFormatter::HandleText(HtmlToken* t) { CrashIf(!t->IsText()); HandleText(t->s, t->sLen); }