Fenster updaten
-
Also hier ist der Code von meinem Programm(Ich lebe in Italien,also sind die ganzen Strings und so in Italienisch und der Code ist auch noch nicht komplett):
#include <wx/wx.h> #include <wx/slider.h> #include <wx/textctrl.h> #include <wx/tglbtn.h> #include <wx/gauge.h> #include <wx/statusbr.h> #include <wx/stattext.h> #include <wx/statbmp.h> #include <wx/statline.h> #include <wx/statbox.h> #include <wx/toolbar.h> #include <wx/image.h> #include <wx/filedlg.h> #include <wx/fontdlg.h> #include <wx/font.h> //defines #define ID_TEXT 1 #define ID_SHOW 2 #define ID_AUTACAP 3 #define ID_SAVE 4 #define ID_OPEN 5 #define ID_SAVEAS 6 #define ID_NEW 7 #define ID_UNDO 8 #define ID_REDO 9 #define ID_CUT 10 #define ID_COPY 11 #define ID_PASTE 12 #define ID_REMOVE 13 #define ID_SELALL 14 #define ID_FONT 15 class MyApp : public wxApp { public: virtual bool OnInit(); }; class MyFrame : public wxFrame { public: MyFrame(const wxString& title); void OnQuit(wxCommandEvent& event); void OnAbout(wxCommandEvent& event); void OnACap(wxCommandEvent& event); void OnSave(wxCommandEvent& event); void OnSaveAs(wxCommandEvent& event); void OnOpen(wxCommandEvent& event); void OnNew(wxCommandEvent& event); void OnUndo(wxCommandEvent& event); void OnRedo(wxCommandEvent& event); void OnCut(wxCommandEvent& event); void OnCopy(wxCommandEvent& event); void OnPaste(wxCommandEvent& event); void OnRemove(wxCommandEvent& event); void OnSelectAll(wxCommandEvent& event); void OnFont(wxCommandEvent& event); private: wxTextCtrl *textCtrl; wxStatusBar *status; wxMenu *fileMenu; wxMenu *helpMenu; wxMenu *showMenu; wxMenu *formatMenu; wxMenu *editMenu; wxString filePath; wxString caption; wxString wildcard; wxString defaultDir; wxString defaultFilename; bool alreadySaved; bool autACap; DECLARE_EVENT_TABLE() }; DECLARE_APP(MyApp) IMPLEMENT_APP(MyApp) bool MyApp::OnInit(){ MyFrame *frame= new MyFrame(wxT("SpiNote")); frame->Show(true); return true; } BEGIN_EVENT_TABLE(MyFrame,wxFrame) EVT_MENU(wxID_EXIT,MyFrame::OnQuit) EVT_MENU(wxID_ABOUT,MyFrame::OnAbout) EVT_MENU(ID_AUTACAP,MyFrame::OnACap) EVT_MENU(ID_SAVE,MyFrame::OnSave) EVT_MENU(ID_SAVEAS,MyFrame::OnSaveAs) EVT_MENU(ID_OPEN,MyFrame::OnOpen) EVT_MENU(ID_NEW,MyFrame::OnNew) EVT_MENU(ID_UNDO,MyFrame::OnUndo) EVT_MENU(ID_REDO,MyFrame::OnRedo) EVT_MENU(ID_CUT,MyFrame::OnCut) EVT_MENU(ID_COPY,MyFrame::OnCopy) EVT_MENU(ID_PASTE,MyFrame::OnPaste) EVT_MENU(ID_REMOVE,MyFrame::OnRemove) EVT_MENU(ID_SELALL,MyFrame::OnSelectAll) EVT_MENU(ID_FONT,MyFrame::OnFont) END_EVENT_TABLE() void MyFrame::OnAbout(wxCommandEvent& event){ wxString msg; msg.Printf(wxT("Questo programma è stato creato da:\nSpina")); wxMessageBox(msg,wxT("Dettagli"),wxOK | wxICON_INFORMATION,this); } void MyFrame::OnQuit(wxCommandEvent& event){ Close(); } void MyFrame::OnACap(wxCommandEvent& event){ if(!autACap){ textCtrl->SetWindowStyleFlag(wxTE_MULTILINE | wxTE_CHARWRAP); autACap=true; } else{ textCtrl->SetWindowStyleFlag(wxTE_MULTILINE | wxTE_DONTWRAP | wxHSCROLL); autACap=false; } textCtrl->Refresh(true); textCtrl->Update(); } void MyFrame::OnSave(wxCommandEvent& event){ if(!alreadySaved){ this->OnSaveAs(event); } else { if(filePath!=wxEmptyString){ textCtrl->SaveFile(filePath); } } } void MyFrame::OnSaveAs(wxCommandEvent& event){ wxFileDialog dialog(this, caption, defaultDir, defaultFilename,wildcard, wxSAVE); if (dialog.ShowModal() == wxID_OK){ filePath = dialog.GetPath(); int filterIndex = dialog.GetFilterIndex(); } textCtrl->SaveFile(filePath); alreadySaved=true; } void MyFrame::OnNew(wxCommandEvent& event){ textCtrl->Clear(); alreadySaved=false; filePath=wxEmptyString; } void MyFrame::OnOpen(wxCommandEvent& event){ wxFileDialog dialog(this, caption, defaultDir, defaultFilename,wildcard, wxOPEN); if (dialog.ShowModal() == wxID_OK){ filePath = dialog.GetPath(); int filterIndex = dialog.GetFilterIndex(); } textCtrl->LoadFile(filePath); alreadySaved=true; } void MyFrame::OnUndo(wxCommandEvent& event){ textCtrl->Undo(); } void MyFrame::OnRedo(wxCommandEvent& event){ textCtrl->Redo(); } void MyFrame::OnCut(wxCommandEvent& event){ textCtrl->Cut(); } void MyFrame::OnCopy(wxCommandEvent& event){ textCtrl->Copy(); } void MyFrame::OnPaste(wxCommandEvent& event){ textCtrl->Paste(); } void MyFrame::OnRemove(wxCommandEvent& event){ long int a,b; textCtrl->GetSelection(&a,&b); textCtrl->Remove(a,b); } void MyFrame::OnSelectAll(wxCommandEvent& event){ textCtrl->SetSelection(0,textCtrl->GetLastPosition()); } void MyFrame::OnFont(wxCommandEvent& event){ wxColor m_textColor(0,0,0); wxColor m_backColor(255,255,255); wxFont m_font; m_font.New(8,wxFONTFAMILY_DEFAULT,wxFONTSTYLE_NORMAL); wxFontData data; data.SetInitialFont(m_font); data.SetColour(m_textColor); wxFontDialog dialog(this,data); if (dialog.ShowModal() == wxID_OK){ wxFontData retData = dialog.GetFontData(); m_font = retData.GetChosenFont(); m_textColor = retData.GetColour(); wxTextAttr attr; attr.SetFont(m_font); attr.SetBackgroundColour(m_backColor); attr.SetTextColour(m_textColor); textCtrl->SetDefaultStyle(attr); } textCtrl->Refresh(); textCtrl->Update(); } MyFrame::MyFrame(const wxString& title) : wxFrame(NULL,wxID_ANY,title) { fileMenu=new wxMenu; helpMenu=new wxMenu; showMenu=new wxMenu; formatMenu=new wxMenu; editMenu=new wxMenu; helpMenu->Append(wxID_ABOUT,wxT("Informazioni su SpiNote\tF1"),wxT("Informazioni sul programma")); fileMenu->Append(ID_NEW,wxT("Nuovo\tCTRL+N"),wxT("Crea un nuovo documento")); fileMenu->AppendSeparator(); fileMenu->Append(ID_OPEN,wxT("Apri...\tCTRL+F12"),wxT("Apri un file in modalità testo")); fileMenu->Append(ID_SAVE,wxT("Salva\tMAIUSC+F12"),wxT("Salva il testo in un file")); fileMenu->Append(ID_SAVEAS,wxT("Salva con nome...")); fileMenu->AppendSeparator(); fileMenu->Append(wxID_EXIT,wxT("Esci\tALT+X"),wxT("Esci dal programma")); showMenu->Append(ID_SHOW,wxT("Barra di stato"),wxT("Visualizza la barra di stato"),wxITEM_CHECK); formatMenu->Append(ID_AUTACAP,wxT("A capo automatico"),wxT("Abilita/Disabilita A capo automatico"),wxITEM_CHECK); formatMenu->Append(ID_FONT,wxT("Carattere..."),wxT("Cambia il carattere del testo")); editMenu->Append(ID_UNDO,wxT("Annulla\tCTRL+Z"),wxT("Annulla l'ultima azione compiuta")); editMenu->Append(ID_REDO,wxT("Ripeti\tMAIUSC+CTRL+Z"),wxT("Ripeti l'ultima azione annullata")); editMenu->AppendSeparator(); editMenu->Append(ID_CUT,wxT("Taglia\tCTRL+X"),wxT("Taglia la parte di testo selezionata")); editMenu->Append(ID_COPY,wxT("Copia\tCTRL+C"),wxT("Copia la parte di testo selezionata")); editMenu->Append(ID_PASTE,wxT("Incolla\tCTRL+V"),wxT("Incolla nel punto selezionato")); editMenu->Append(ID_REMOVE,wxT("Elimina"),wxT("Elimina la parte di testo seleziata")); editMenu->AppendSeparator(); editMenu->Append(ID_SELALL,wxT("Seleziona tutto\tCTRL+5"),wxT("Seleziona tutto il testo")); wxMenuBar *menuBar=new wxMenuBar(); menuBar->Append(fileMenu,wxT("File")); menuBar->Append(editMenu,wxT("Modifica")); menuBar->Append(formatMenu,wxT("Formato")); menuBar->Append(showMenu,wxT("Visualizza")); menuBar->Append(helpMenu,wxT("?")); SetMenuBar(menuBar); status=CreateStatusBar(2); SetStatusBar(status); SetStatusText(wxT("SpiNote")); textCtrl=new wxTextCtrl(this,ID_TEXT,wxEmptyString,wxDefaultPosition,wxSize(),wxTE_MULTILINE | wxTE_CHARWRAP); formatMenu->Check(ID_AUTACAP,true); caption=wxT("Salva"); wildcard =wxT("TXT files (*.txt)|*.txt|SPINA files (*.spina)|*.spina"); defaultDir = wxT("c:\\"); defaultFilename = wxEmptyString; alreadySaved=false; autACap=true; }
Es gibt noch ein kleines Problem:Ich wollte auch den Font-Typ ändern aber es funktioniert auch nicht...
PS:Falls jemand Tipps hat wie man das verbessern kann,bitte posten!
PS2:Danke für das Interesse und die Hilfe!!!
-
Und jetzt poste bitte noch den Teil wo der Fehler auftritt
-
Es gibt keinen Fehler beim kompilieren sondern wenn man das Programm startet und dann auf das Menu clickt um das Fenster upzudaten...da tut sich dann nichts...
Wenn Du auf das Menu "Formato->A capo automatico" clickst müsste das eigentlich alleine die Zeilen trennen aber tut es nicht...
Und der Font-Typ wird auch nicht geändert("Formato->Carattere...")....
-
http://wxwidgets.org/manuals/stable/wx_wxtextctrl.html#wxtextctrlsetdefaultstyle
Evtl. mal testen ob SetDefaultStyle true zurückgibt.
Und evtl. direkt danach ein Refresh() aufrufen.
-
Also SetDefaultStyle() gibt true zurück...hab Ich mit einer messageBox geprüft.
Und Ich hab auch direkt danach ein textCtrl->Refresh(); eingebaut und auch versucht ein textCtrl->Update(); nach dem Refresh() hinzuschreiben.
Hab es auch mit dem refreshen des Frames versucht,aber da tut sich leider nichts...
-
Hm, evtl. hilft ein Aufruf von Layout() beim Frame/Parentpanel.
Ansonsten versuch mal eine kleines Beispiel zu posten, was nur dieses Verhalten zeigt.
-
Leider bin Ich im Moment nicht bei zuhause sondern bei einem Freund,aber morgen poste Ich sofort!
Aber was für ein Verhalten meinst Du?
SetDefaultStyle() oder Refresh()??
-
Na, das was dich stört. Irgendwas soll sich ja ändern, und ändert sich nicht...
-
Ja,der Font-Typ soll halt vom Benutzer geändert werden...aber es funktionier irgendwie nich...
Ich hab versucht alles was nicht dringend nötig ist,wegzulassen.Ich hab also nur das wxFrame und den wxTextCtrl gelassen.Und noch ein Menu um den FontDialog aufzumachen.Aber der Font-Typ wird nicht geändert...keine ahnung...
-
Changes the default style to use for the new text which is going to be added to the control using WriteText or AppendText.
Mach mal danach ein AppendText, und schau ob sich was ändert.
Es ist evtl. nicht die Methode zum Ändern des Styles für das Ctrl.
-
Ich hab es versucht,es tut sich aber nicht:es wird Text hinzugefügt aber nicht mit dem Font-Typ den Ich ausgesucht habe...
-
Ich glaube du suchst SetStyle.
Schau dir mal die Doku zu wxTextCtrl an.
-
Hatte Ich auch schon dran gedacht,aber es funktioniert auch nicht...
Also meiner Meinung nach ist es ein problem mit dem updaten vom Frame oder vom textCtrl...
-
Dir fehlt ein Style beim TextCtrl: wxTE_RICH bzw. wxTE_RICH2.
Dann klappts.
-
Toll!!!Danke!!!!
Sobald Ich das Programm fertiggeschrieben habe,poste Ich es sofort!!