From 8236a88ae2cbbfade17a8dc325546402ed28e2ab Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 9 Jun 1999 11:36:45 +0000 Subject: [PATCH] menu changed, many uninitialized variables are now initialized - thanks Purify git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2725 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- samples/richedit/wxllist.cpp | 26 ++++++-------- samples/richedit/wxllist.h | 22 +++++++++++- samples/richedit/wxlwindow.cpp | 64 +++++++++++++++++++++++----------- samples/richedit/wxlwindow.h | 12 +++---- 4 files changed, 80 insertions(+), 44 deletions(-) diff --git a/samples/richedit/wxllist.cpp b/samples/richedit/wxllist.cpp index 83ff44ef42..cbec218f8e 100644 --- a/samples/richedit/wxllist.cpp +++ b/samples/richedit/wxllist.cpp @@ -463,23 +463,16 @@ wxLayoutStyleInfo::wxLayoutStyleInfo(int ifamily, wxColour *fg, wxColour *bg) { - family = ifamily; size = isize; - style = istyle; weight = iweight; + family = ifamily; + size = isize; + style = istyle; + weight = iweight; underline = iul != 0; - if(fg) - { - m_fg = *fg; - m_fg_valid = TRUE; - } - else - m_fg = *wxBLACK; - if(bg) - { - m_bg = *bg; - m_bg_valid = TRUE; - } - else - m_bg = *wxWHITE; + + m_fg_valid = fg != 0; + m_bg_valid = bg != 0; + m_fg = m_fg_valid ? *fg : *wxBLACK; + m_bg = m_fg_valid ? *bg : *wxWHITE; } #define COPY_SI_(what) if(right.what != -1) what = right.what; @@ -632,6 +625,7 @@ wxLayoutLine::wxLayoutLine(wxLayoutLine *prev, wxLayoutList *llist) m_LineNumber = 0; m_Width = m_Height = 0; m_Length = 0; + m_updateLeft = -1; MarkDirty(0); m_Previous = prev; m_Next = NULL; diff --git a/samples/richedit/wxllist.h b/samples/richedit/wxllist.h index d0d7c94ae6..552c2551b0 100644 --- a/samples/richedit/wxllist.h +++ b/samples/richedit/wxllist.h @@ -904,7 +904,6 @@ public: inline void SetFontColour(wxColour *fg, wxColour *bg = NULL) { SetFont(-1,-1,-1,-1,-1,fg,bg); } - /** Returns a pointer to the default settings. This is only valid temporarily and should not be stored @@ -913,6 +912,27 @@ public: */ wxLayoutStyleInfo &GetDefaultStyleInfo(void) { return m_DefaultStyleInfo ; } wxLayoutStyleInfo &GetStyleInfo(void) { return m_CurrentStyleInfo ; } + const wxLayoutStyleInfo &GetStyleInfo(void) const { return m_CurrentStyleInfo ; } + + /// is the current font underlined? + bool IsFontUnderlined() const { return GetStyleInfo().underline != 0; } + /// is the current font bold? + bool IsFontBold() const { return GetStyleInfo().weight == wxBOLD; } + /// is the current font italic? + bool IsFontItalic() const { return GetStyleInfo().style == wxITALIC; } + + /// set underline if it was off, turn it off if it was on + void ToggleFontUnderline() + { SetFontUnderline(!IsFontUnderlined()); } + + /// make font bold if it was normal or make it normal if it was bold + void ToggleFontWeight() + { SetFontWeight(IsFontBold() ? wxNORMAL : wxBOLD); } + + /// make font italic if it was normal or make it normal if it was italic + void ToggleFontItalics() + { SetFontStyle(IsFontItalic() ? wxNORMAL : wxITALIC); } + //@} /**@name Drawing */ diff --git a/samples/richedit/wxlwindow.cpp b/samples/richedit/wxlwindow.cpp index e893d1adac..44a575d665 100644 --- a/samples/richedit/wxlwindow.cpp +++ b/samples/richedit/wxlwindow.cpp @@ -85,13 +85,20 @@ static const int Y_SCROLL_PAGE = 20; BEGIN_EVENT_TABLE(wxLayoutWindow,wxScrolledWindow) EVT_PAINT (wxLayoutWindow::OnPaint) + EVT_CHAR (wxLayoutWindow::OnChar) EVT_KEY_UP (wxLayoutWindow::OnKeyUp) + EVT_LEFT_DOWN(wxLayoutWindow::OnLeftMouseClick) EVT_RIGHT_DOWN(wxLayoutWindow::OnRightMouseClick) EVT_LEFT_DCLICK(wxLayoutWindow::OnMouseDblClick) EVT_MOTION (wxLayoutWindow::OnMouseMove) + + EVT_UPDATE_UI(WXLOWIN_MENU_UNDERLINE, wxLayoutWindow::OnUpdateMenuUnderline) + EVT_UPDATE_UI(WXLOWIN_MENU_BOLD, wxLayoutWindow::OnUpdateMenuBold) + EVT_UPDATE_UI(WXLOWIN_MENU_ITALICS, wxLayoutWindow::OnUpdateMenuItalic) EVT_MENU_RANGE(WXLOWIN_MENU_FIRST, WXLOWIN_MENU_LAST, wxLayoutWindow::OnMenu) + EVT_SET_FOCUS(wxLayoutWindow::OnSetFocus) EVT_KILL_FOCUS(wxLayoutWindow::OnKillFocus) END_EVENT_TABLE() @@ -154,7 +161,8 @@ wxLayoutWindow::wxLayoutWindow(wxWindow *parent) caret->Show(); #endif // WXLAYOUT_USE_CARET - SetCursorVisibility(-1); + m_HandCursor = FALSE; + m_CursorVisibility = -1; SetCursor(wxCURSOR_IBEAM); SetDirty(); } @@ -951,39 +959,53 @@ wxLayoutWindow::MakeFormatMenu() m->Append(WXLOWIN_MENU_LARGER ,_("&Larger"),_("Switch to larger font."), false); m->Append(WXLOWIN_MENU_SMALLER ,_("&Smaller"),_("Switch to smaller font."), false); m->AppendSeparator(); - m->Append(WXLOWIN_MENU_UNDERLINE_ON, _("&Underline on"),_("Activate underline mode."), false); - m->Append(WXLOWIN_MENU_UNDERLINE_OFF,_("&Underline off"),_("Deactivate underline mode."), false); - m->Append(WXLOWIN_MENU_BOLD_ON ,_("&Bold on"),_("Activate bold mode."), false); - m->Append(WXLOWIN_MENU_BOLD_OFF ,_("&Bold off"),_("Deactivate bold mode."), false); - m->Append(WXLOWIN_MENU_ITALICS_ON ,_("&Italics on"),_("Activate italics mode."), false); - m->Append(WXLOWIN_MENU_ITALICS_OFF ,_("&Italics off"),_("Deactivate italics mode."), false); + m->Append(WXLOWIN_MENU_UNDERLINE, _("&Underline"),_("Underline mode."), true); + m->Append(WXLOWIN_MENU_BOLD, _("&Bold"),_("Bold mode."), true); + m->Append(WXLOWIN_MENU_ITALICS, _("&Italics"),_("Italics mode."), true); m->AppendSeparator(); m->Append(WXLOWIN_MENU_ROMAN ,_("&Roman"),_("Switch to roman font."), false); m->Append(WXLOWIN_MENU_TYPEWRITER,_("&Typewriter"),_("Switch to typewriter font."), false); m->Append(WXLOWIN_MENU_SANSSERIF ,_("&Sans Serif"),_("Switch to sans serif font."), false); + return m; } +void wxLayoutWindow::OnUpdateMenuUnderline(wxUpdateUIEvent& event) +{ + event.Check(m_llist->IsFontUnderlined()); +} + +void wxLayoutWindow::OnUpdateMenuBold(wxUpdateUIEvent& event) +{ + event.Check(m_llist->IsFontBold()); +} + +void wxLayoutWindow::OnUpdateMenuItalic(wxUpdateUIEvent& event) +{ + event.Check(m_llist->IsFontItalic()); +} + void wxLayoutWindow::OnMenu(wxCommandEvent& event) { switch (event.GetId()) { case WXLOWIN_MENU_LARGER: - m_llist->SetFontLarger(); break; + m_llist->SetFontLarger(); + break; case WXLOWIN_MENU_SMALLER: - m_llist->SetFontSmaller(); break; - case WXLOWIN_MENU_UNDERLINE_ON: - m_llist->SetFontUnderline(true); break; - case WXLOWIN_MENU_UNDERLINE_OFF: - m_llist->SetFontUnderline(false); break; - case WXLOWIN_MENU_BOLD_ON: - m_llist->SetFontWeight(wxBOLD); break; - case WXLOWIN_MENU_BOLD_OFF: - m_llist->SetFontWeight(wxNORMAL); break; - case WXLOWIN_MENU_ITALICS_ON: - m_llist->SetFontStyle(wxITALIC); break; - case WXLOWIN_MENU_ITALICS_OFF: - m_llist->SetFontStyle(wxNORMAL); break; + m_llist->SetFontSmaller(); + break; + + case WXLOWIN_MENU_UNDERLINE: + m_llist->ToggleFontUnderline(); + break; + case WXLOWIN_MENU_BOLD: + m_llist->ToggleFontWeight(); + break; + case WXLOWIN_MENU_ITALICS: + m_llist->ToggleFontItalics(); + break; + case WXLOWIN_MENU_ROMAN: m_llist->SetFontFamily(wxROMAN); break; case WXLOWIN_MENU_TYPEWRITER: diff --git a/samples/richedit/wxlwindow.h b/samples/richedit/wxlwindow.h index 7e4d0ce70f..6344296e96 100644 --- a/samples/richedit/wxlwindow.h +++ b/samples/richedit/wxlwindow.h @@ -29,12 +29,9 @@ enum { WXLOWIN_MENU_LARGER = WXLOWIN_MENU_FIRST, WXLOWIN_MENU_SMALLER, - WXLOWIN_MENU_UNDERLINE_ON, - WXLOWIN_MENU_UNDERLINE_OFF, - WXLOWIN_MENU_BOLD_ON, - WXLOWIN_MENU_BOLD_OFF, - WXLOWIN_MENU_ITALICS_ON, - WXLOWIN_MENU_ITALICS_OFF, + WXLOWIN_MENU_UNDERLINE, + WXLOWIN_MENU_BOLD, + WXLOWIN_MENU_ITALICS, WXLOWIN_MENU_ROMAN, WXLOWIN_MENU_TYPEWRITER, WXLOWIN_MENU_SANSSERIF, @@ -132,6 +129,9 @@ public: void OnPaint(wxPaintEvent &event); void OnChar(wxKeyEvent& event); void OnKeyUp(wxKeyEvent& event); + void OnUpdateMenuUnderline(wxUpdateUIEvent& event); + void OnUpdateMenuBold(wxUpdateUIEvent& event); + void OnUpdateMenuItalic(wxUpdateUIEvent& event); void OnMenu(wxCommandEvent& event); void OnLeftMouseClick(wxMouseEvent& event) { OnMouse(WXLOWIN_MENU_LCLICK, event); } void OnRightMouseClick(wxMouseEvent& event) { OnMouse(WXLOWIN_MENU_RCLICK, event); } -- 2.47.2