mirror of
				https://github.com/SoftFever/OrcaSlicer.git
				synced 2025-10-30 20:21:12 -06:00 
			
		
		
		
	FIX: button handle key event
Change-Id: If3ecd2356e516105c2054c9b85a122f3ccc72d91
This commit is contained in:
		
							parent
							
								
									6c4b1f79da
								
							
						
					
					
						commit
						a74fb14613
					
				
					 6 changed files with 59 additions and 9 deletions
				
			
		|  | @ -340,7 +340,7 @@ void SavePresetDialog::build(std::vector<Preset::Type> types, std::string suffix | |||
|     m_confirm->SetTextColor(wxColour(255, 255, 255)); | ||||
|     m_confirm->SetMinSize(SAVE_PRESET_DIALOG_BUTTON_SIZE); | ||||
|     m_confirm->SetCornerRadius(12); | ||||
|     m_confirm->Bind(wxEVT_LEFT_DOWN, &SavePresetDialog::accept, this); | ||||
|     m_confirm->Bind(wxEVT_BUTTON, &SavePresetDialog::accept, this); | ||||
|     btns->Add(m_confirm, 0, wxEXPAND, 0); | ||||
| 
 | ||||
|     auto block_middle = new wxWindow(this, -1); | ||||
|  | @ -351,7 +351,7 @@ void SavePresetDialog::build(std::vector<Preset::Type> types, std::string suffix | |||
|     m_cancel->SetMinSize(SAVE_PRESET_DIALOG_BUTTON_SIZE); | ||||
|     m_cancel->SetTextColor(wxColour(107, 107, 107)); | ||||
|     m_cancel->SetCornerRadius(12); | ||||
|     m_cancel->Bind(wxEVT_LEFT_DOWN, &SavePresetDialog::on_select_cancel, this); | ||||
|     m_cancel->Bind(wxEVT_BUTTON, &SavePresetDialog::on_select_cancel, this); | ||||
|     btns->Add(m_cancel, 0, wxEXPAND, 0); | ||||
| 
 | ||||
|     auto block_right = new wxWindow(this, -1); | ||||
|  | @ -372,7 +372,7 @@ void SavePresetDialog::build(std::vector<Preset::Type> types, std::string suffix | |||
|     this->Centre(wxBOTH); | ||||
| } | ||||
| 
 | ||||
| void SavePresetDialog::on_select_cancel(wxMouseEvent &event) | ||||
| void SavePresetDialog::on_select_cancel(wxCommandEvent &event) | ||||
| { | ||||
|     EndModal(wxID_CANCEL); | ||||
| } | ||||
|  | @ -511,7 +511,7 @@ void SavePresetDialog::update_physical_printers(const std::string &preset_name) | |||
|     } | ||||
| } | ||||
| 
 | ||||
| void SavePresetDialog::accept(wxMouseEvent &event) | ||||
| void SavePresetDialog::accept(wxCommandEvent &event) | ||||
| { | ||||
|     for (Item *item : m_items) { | ||||
|         item->accept(); | ||||
|  |  | |||
|  | @ -111,9 +111,9 @@ protected: | |||
| 
 | ||||
| private: | ||||
|     void build(std::vector<Preset::Type> types, std::string suffix = ""); | ||||
|     void on_select_cancel(wxMouseEvent &event); | ||||
|     void on_select_cancel(wxCommandEvent &event); | ||||
|     void update_physical_printers(const std::string &preset_name); | ||||
|     void accept(wxMouseEvent &event); | ||||
|     void accept(wxCommandEvent &event); | ||||
| }; | ||||
| 
 | ||||
| } // namespace GUI
 | ||||
|  |  | |||
|  | @ -955,7 +955,7 @@ void UnsavedChangesDialog::build(Preset::Type type, PresetCollection *dependent_ | |||
|         (*btn)->SetMinSize(UNSAVE_CHANGE_DIALOG_BUTTON_SIZE); | ||||
|         (*btn)->SetCornerRadius(12); | ||||
| 
 | ||||
|         (*btn)->Bind(wxEVT_LEFT_DOWN, [this, close_act, dependent_presets](wxEvent &) { | ||||
|         (*btn)->Bind(wxEVT_BUTTON, [this, close_act, dependent_presets](wxEvent &) { | ||||
|             bool save_names_and_types = close_act == Action::Save || (close_act == Action::Transfer && ActionButtons::KEEP & m_buttons); | ||||
|             if (save_names_and_types && !save(dependent_presets, close_act == Action::Save)) return; | ||||
|             close(close_act); | ||||
|  |  | |||
|  | @ -7,6 +7,8 @@ BEGIN_EVENT_TABLE(Button, StaticBox) | |||
| 
 | ||||
| EVT_LEFT_DOWN(Button::mouseDown) | ||||
| EVT_LEFT_UP(Button::mouseReleased) | ||||
| EVT_KEY_DOWN(Button::keyDownUp) | ||||
| EVT_KEY_UP(Button::keyDownUp) | ||||
| 
 | ||||
| // catch paint events
 | ||||
| EVT_PAINT(Button::paintEvent) | ||||
|  | @ -241,9 +243,46 @@ void Button::mouseReleased(wxMouseEvent& event) | |||
|     } | ||||
| } | ||||
| 
 | ||||
| void Button::keyDownUp(wxKeyEvent &event) | ||||
| { | ||||
|     if (event.GetKeyCode() == WXK_SPACE || event.GetKeyCode() == WXK_RETURN) { | ||||
|         wxMouseEvent evt(event.GetEventType() == wxEVT_KEY_UP ? wxEVT_LEFT_UP : wxEVT_LEFT_DOWN); | ||||
|         event.SetEventObject(this); | ||||
|         GetEventHandler()->ProcessEvent(evt); | ||||
|         return; | ||||
|     } | ||||
|     event.Skip(); | ||||
| } | ||||
| 
 | ||||
| void Button::sendButtonEvent() | ||||
| { | ||||
|     wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, GetId()); | ||||
|     event.SetEventObject(this); | ||||
|     GetEventHandler()->ProcessEvent(event); | ||||
| } | ||||
| 
 | ||||
| #ifdef __WIN32__ | ||||
| 
 | ||||
| WXLRESULT Button::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) | ||||
| { | ||||
|     if (nMsg == WM_GETDLGCODE) { return DLGC_WANTMESSAGE; } | ||||
|     if (nMsg == WM_KEYDOWN) { | ||||
|         wxKeyEvent event(CreateKeyEvent(wxEVT_KEY_DOWN, wParam, lParam)); | ||||
|         switch (wParam) { | ||||
|         case WXK_RETURN: { | ||||
|             GetEventHandler()->ProcessEvent(event); | ||||
|             return 0; | ||||
|         } | ||||
|         case WXK_TAB: | ||||
|         case WXK_LEFT: | ||||
|         case WXK_RIGHT: | ||||
|         case WXK_UP: | ||||
|         case WXK_DOWN: | ||||
|             if (HandleAsNavigationKey(event)) | ||||
|                 return 0; | ||||
|         } | ||||
|     } | ||||
|     return wxWindow::MSWWindowProc(nMsg, wParam, lParam); | ||||
| } | ||||
| 
 | ||||
| #endif | ||||
|  |  | |||
|  | @ -47,6 +47,11 @@ public: | |||
| 
 | ||||
|     void Rescale(); | ||||
| 
 | ||||
| protected: | ||||
| #ifdef __WIN32__ | ||||
|     WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) override; | ||||
| #endif | ||||
| 
 | ||||
| private: | ||||
|     void paintEvent(wxPaintEvent& evt); | ||||
| 
 | ||||
|  | @ -57,6 +62,7 @@ private: | |||
|     // some useful events
 | ||||
|     void mouseDown(wxMouseEvent& event); | ||||
|     void mouseReleased(wxMouseEvent& event); | ||||
|     void keyDownUp(wxKeyEvent &event); | ||||
| 
 | ||||
|     void sendButtonEvent(); | ||||
| 
 | ||||
|  |  | |||
|  | @ -248,9 +248,11 @@ void ComboBox::keyDown(wxKeyEvent& event) { | |||
|             break; | ||||
|         case WXK_UP: | ||||
|         case WXK_DOWN: | ||||
|             if (event.GetKeyCode() == WXK_UP && GetSelection() > 0) { | ||||
|         case WXK_LEFT: | ||||
|         case WXK_RIGHT: | ||||
|             if ((event.GetKeyCode() == WXK_UP || event.GetKeyCode() == WXK_LEFT) && GetSelection() > 0) { | ||||
|                 SetSelection(GetSelection() - 1); | ||||
|             } else if (event.GetKeyCode() == WXK_DOWN && GetSelection() + 1 < texts.size()) { | ||||
|             } else if ((event.GetKeyCode() == WXK_DOWN || event.GetKeyCode() == WXK_RIGHT) && GetSelection() + 1 < texts.size()) { | ||||
|                 SetSelection(GetSelection() + 1); | ||||
|             } else { | ||||
|                 break; | ||||
|  | @ -263,6 +265,9 @@ void ComboBox::keyDown(wxKeyEvent& event) { | |||
|                 GetEventHandler()->ProcessEvent(e); | ||||
|             } | ||||
|             break; | ||||
|         case WXK_TAB: | ||||
|             HandleAsNavigationKey(event); | ||||
|             break; | ||||
|         default: | ||||
|             event.Skip(); | ||||
|             break; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 chunmao.guo
						chunmao.guo