Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/lintest/myrulib.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKandrashin Denis <mail@lintest.ru>2012-06-29 20:29:16 +0400
committerKandrashin Denis <mail@lintest.ru>2012-06-29 20:29:16 +0400
commit488bf39cd3fd9359ae8bb0b403310adaeb1ce44a (patch)
tree0a64c2982574682bdf35df95b27f08f38b9dc8a5 /sources
parent4bfade2a2a104dc9ffb6f7ecdfa413c064ace604 (diff)
Optimize class FbSearchCtrl
Diffstat (limited to 'sources')
-rw-r--r--sources/MyRuLib/FbMainFrame.cpp46
-rw-r--r--sources/MyRuLib/FbMainFrame.h2
-rw-r--r--sources/MyRuLib/controls/FbSearchCtrl.cpp145
-rw-r--r--sources/MyRuLib/controls/FbSearchCtrl.h70
4 files changed, 31 insertions, 232 deletions
diff --git a/sources/MyRuLib/FbMainFrame.cpp b/sources/MyRuLib/FbMainFrame.cpp
index e5661910..6aea732f 100644
--- a/sources/MyRuLib/FbMainFrame.cpp
+++ b/sources/MyRuLib/FbMainFrame.cpp
@@ -53,6 +53,9 @@ BEGIN_EVENT_TABLE(FbMainFrame, wxFrame)
EVT_MENU(wxID_ABOUT, FbMainFrame::OnAbout)
EVT_MENU_RANGE(wxID_FILE1, wxID_FILE5, FbMainFrame::OnMenuRecent)
+ EVT_SEARCHCTRL_SEARCH_BTN(ID_AUTHOR_TXT, FbMainFrame::OnFindAuthor)
+ EVT_SEARCHCTRL_SEARCH_BTN(ID_TITLE_TXT, FbMainFrame::OnFindTitle)
+
EVT_UPDATE_UI(wxID_FILE, FbMainFrame::OnRecentUpdate)
EVT_MENU(wxID_SAVE, FbMainFrame::OnSubmenu)
@@ -183,26 +186,16 @@ bool FbMainFrame::ProcessEvent(wxEvent& event)
wxWindow * focused = wxDynamicCast(FindFocus(), wxWindow);
+ if (focused && focused->GetEventHandler() == this) {
+ return wxFrame::ProcessEvent(event);
+ }
+
if (event.GetId() == wxID_SELECTALL && event.GetEventType() == wxEVT_COMMAND_MENU_SELECTED) {
if (wxTextCtrl * text = wxDynamicCast(focused, wxTextCtrl)) { text->SelectAll(); return true; }
if (FbSearchCtrl * text = wxDynamicCast(focused, FbSearchCtrl)) { text->SelectAll(); return true; }
if (wxComboCtrl * combo = wxDynamicCast(focused, wxComboCtrl)) { combo->GetTextCtrl()->SelectAll(); return true; }
}
- if (event.GetEventType() == wxEVT_COMMAND_SEARCHCTRL_SEARCH_BTN) {
- switch (event.GetId()) {
- case ID_AUTHOR_TXT: { DoFindAuthor(); return true; }
- case ID_TITLE_TXT: { DoFindTitle(); return true; }
- }
- }
-
- if (event.GetEventType() == wxEVT_COMMAND_SEARCHCTRL_CANCEL_BTN) {
- switch (event.GetId()) {
- case ID_AUTHOR_TXT: { m_FindAuthor->Clear(); return true; }
- case ID_TITLE_TXT: { m_FindTitle->Clear(); return true; }
- }
- }
-
if (focused && focused->GetEventHandler()->ProcessEvent(event)) return true;
wxWindow * window = GetActiveChild();
@@ -438,6 +431,9 @@ void FbMainFrame::OnAbout(wxCommandEvent & event)
wxToolBar * FbMainFrame::CreateToolBar()
{
+ wxString textAuth = _(" Author: ");
+ wxString textBook = _(" Book: ");
+
FbToolBar * toolbar = new FbToolBar;
toolbar->Create(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTB_FLAT);
wxFont font = FbParams(FB_FONT_TOOL);
@@ -447,9 +443,12 @@ wxToolBar * FbMainFrame::CreateToolBar()
#ifdef __WXMSW__
toolbar->AddSeparator();
+#else
+ textAuth.Prepend(wxT(" "));
+ textBook.Prepend(wxT(" "));
#endif // __WXMSW__
- wxStaticText * text1 = new wxStaticText( toolbar, wxID_ANY, _(" Author: "), wxDefaultPosition, wxDefaultSize, 0 );
+ wxStaticText * text1 = new wxStaticText( toolbar, wxID_ANY, textAuth, wxDefaultPosition, wxDefaultSize, 0 );
text1->Wrap( -1 );
text1->SetFont(font);
toolbar->AddControl( text1 );
@@ -463,7 +462,7 @@ wxToolBar * FbMainFrame::CreateToolBar()
toolbar->AddSeparator();
#endif // __WXMSW__
- wxStaticText * text2 = new wxStaticText(toolbar, wxID_ANY, _(" Book: "), wxDefaultPosition, wxDefaultSize, 0 );
+ wxStaticText * text2 = new wxStaticText(toolbar, wxID_ANY, textBook, wxDefaultPosition, wxDefaultSize, 0 );
text2->Wrap( -1 );
text2->SetFont(font);
toolbar->AddControl( text2 );
@@ -482,9 +481,6 @@ wxToolBar * FbMainFrame::CreateToolBar()
#ifdef __WXMSW__
toolbar->AddSeparator();
-#else
- m_FindAuthor->SetEventHandler(this);
- m_FindTitle->SetEventHandler(this);
#endif // __WXMSW__
toolbar->AddTool(wxID_SAVE, _("Export"), wxART_FILE_SAVE, _("Export to external device"));
@@ -574,16 +570,11 @@ void FbMainFrame::OnHideLog(wxCommandEvent& event)
void FbMainFrame::OnFindAuthor(wxCommandEvent& event)
{
- DoFindAuthor();
+ FindAuthor(m_FindAuthor->GetValue());
}
void FbMainFrame::OnFindTitle(wxCommandEvent& event)
{
- DoFindTitle();
-}
-
-void FbMainFrame::DoFindTitle()
-{
FindTitle(m_FindTitle->GetValue(), m_FindAuthor->GetValue());
}
@@ -596,11 +587,6 @@ void FbMainFrame::FindTitle(const wxString &title, const wxString &author)
}
}
-void FbMainFrame::DoFindAuthor()
-{
- FindAuthor(m_FindAuthor->GetValue());
-}
-
void FbMainFrame::FindAuthor(const wxString &text)
{
FbFrameAuth * authors = wxDynamicCast(FindFrameById(ID_FRAME_AUTH, true), FbFrameAuth);
diff --git a/sources/MyRuLib/FbMainFrame.h b/sources/MyRuLib/FbMainFrame.h
index 37fb060b..a2490c03 100644
--- a/sources/MyRuLib/FbMainFrame.h
+++ b/sources/MyRuLib/FbMainFrame.h
@@ -34,8 +34,6 @@ class FbMainFrame : public wxFrame
wxToolBar * CreateToolBar();
wxAuiPaneInfo * FindLog();
void ShowLog(bool forced = false);
- void DoFindAuthor();
- void DoFindTitle();
void FindAuthor(const wxString &text);
void FindTitle(const wxString &title, const wxString &author);
wxWindow * FindFrameById(const int id, bool bActivate = false);
diff --git a/sources/MyRuLib/controls/FbSearchCtrl.cpp b/sources/MyRuLib/controls/FbSearchCtrl.cpp
index 3666ae88..6253fbd7 100644
--- a/sources/MyRuLib/controls/FbSearchCtrl.cpp
+++ b/sources/MyRuLib/controls/FbSearchCtrl.cpp
@@ -101,7 +101,7 @@ static int GetMultiplier()
#endif
}
-#ifdef __WXMSW__
+#ifdef FB_SEARCH_COMBO_CTRL
IMPLEMENT_CLASS(FbSearchCtrl, wxOwnerDrawnComboBox)
@@ -339,14 +339,6 @@ protected:
GetEventHandler()->ProcessEvent(event);
m_search->SetFocus();
-
-#if wxUSE_MENUS
- if ( m_eventType == wxEVT_COMMAND_SEARCHCTRL_SEARCH_BTN )
- {
- // this happens automatically, just like on Mac OS X
- m_search->PopupSearchMenu();
- }
-#endif // wxUSE_MENUS
}
void OnPaint(wxPaintEvent&)
@@ -412,18 +404,12 @@ void FbSearchCtrl::Init()
m_text = NULL;
m_searchButton = NULL;
m_cancelButton = NULL;
-#if wxUSE_MENUS
- m_menu = NULL;
-#endif // wxUSE_MENUS
m_searchButtonVisible = true;
m_cancelButtonVisible = false;
m_searchBitmapUser = false;
m_cancelBitmapUser = false;
-#if wxUSE_MENUS
- m_searchMenuBitmapUser = false;
-#endif // wxUSE_MENUS
}
bool FbSearchCtrl::Create(wxWindow *parent, wxWindowID id,
@@ -475,50 +461,8 @@ FbSearchCtrl::~FbSearchCtrl()
delete m_text;
delete m_searchButton;
delete m_cancelButton;
-#if wxUSE_MENUS
- delete m_menu;
-#endif // wxUSE_MENUS
}
-
-// search control specific interfaces
-#if wxUSE_MENUS
-
-void FbSearchCtrl::SetMenu( wxMenu* menu )
-{
- if ( menu == m_menu )
- {
- // no change
- return;
- }
- bool hadMenu = (m_menu != NULL);
- delete m_menu;
- m_menu = menu;
-
- if ( m_menu && !hadMenu )
- {
- m_searchButton->SetBitmapLabel(m_searchMenuBitmap);
- m_searchButton->Refresh();
- }
- else if ( !m_menu && hadMenu )
- {
- m_searchButton->SetBitmapLabel(m_searchBitmap);
- if ( m_searchButtonVisible )
- {
- m_searchButton->Refresh();
- }
- }
- wxRect rect = GetRect();
- LayoutControls(0, 0, rect.GetWidth(), rect.GetHeight());
-}
-
-wxMenu* FbSearchCtrl::GetMenu()
-{
- return m_menu;
-}
-
-#endif // wxUSE_MENUS
-
void FbSearchCtrl::ShowSearchButton( bool show )
{
if ( m_searchButtonVisible == show )
@@ -581,7 +525,7 @@ wxSize FbSearchCtrl::DoGetBestSize() const
wxSize sizeCancel(0,0);
int searchMargin = 0;
int cancelMargin = 0;
- if ( m_searchButtonVisible || HasMenu() )
+ if ( m_searchButtonVisible )
{
sizeSearch = m_searchButton->GetBestSize();
searchMargin = MARGIN;
@@ -624,7 +568,7 @@ void FbSearchCtrl::LayoutControls(int x, int y, int width, int height)
wxSize sizeCancel(0,0);
int searchMargin = 0;
int cancelMargin = 0;
- if ( m_searchButtonVisible || HasMenu() )
+ if ( m_searchButtonVisible )
{
sizeSearch = m_searchButton->GetBestSize();
searchMargin = MARGIN;
@@ -634,7 +578,7 @@ void FbSearchCtrl::LayoutControls(int x, int y, int width, int height)
sizeCancel = m_cancelButton->GetBestSize();
cancelMargin = MARGIN;
}
- m_searchButton->Show( m_searchButtonVisible || HasMenu() );
+ m_searchButton->Show( m_searchButtonVisible );
m_cancelButton->Show( m_cancelButtonVisible );
if ( sizeSearch.x + sizeCancel.x > width )
@@ -935,7 +879,7 @@ void FbSearchCtrl::SetSearchBitmap( const wxBitmap& bitmap )
m_searchBitmapUser = bitmap.Ok();
if ( m_searchBitmapUser )
{
- if ( m_searchButton && !HasMenu() )
+ if ( m_searchButton )
{
m_searchButton->SetBitmapLabel( m_searchBitmap );
}
@@ -947,28 +891,6 @@ void FbSearchCtrl::SetSearchBitmap( const wxBitmap& bitmap )
}
}
-#if wxUSE_MENUS
-
-void FbSearchCtrl::SetSearchMenuBitmap( const wxBitmap& bitmap )
-{
- m_searchMenuBitmap = bitmap;
- m_searchMenuBitmapUser = bitmap.Ok();
- if ( m_searchMenuBitmapUser )
- {
- if ( m_searchButton && m_menu )
- {
- m_searchButton->SetBitmapLabel( m_searchMenuBitmap );
- }
- }
- else
- {
- // the user bitmap was just cleared, generate one
- RecalcBitmaps();
- }
-}
-
-#endif // wxUSE_MENUS
-
void FbSearchCtrl::SetCancelBitmap( const wxBitmap& bitmap )
{
m_cancelBitmap = bitmap;
@@ -987,23 +909,6 @@ void FbSearchCtrl::SetCancelBitmap( const wxBitmap& bitmap )
}
}
-#if 0
-
-// override streambuf method
-#if wxHAS_TEXT_WINDOW_STREAM
-int overflow(int i);
-#endif // wxHAS_TEXT_WINDOW_STREAM
-
-// stream-like insertion operators: these are always available, whether we
-// were, or not, compiled with streambuf support
-wxTextCtrl& operator<<(const wxString& s);
-wxTextCtrl& operator<<(int i);
-wxTextCtrl& operator<<(long i);
-wxTextCtrl& operator<<(float f);
-wxTextCtrl& operator<<(double d);
-wxTextCtrl& operator<<(const wxChar c);
-#endif
-
void FbSearchCtrl::DoSetValue(const wxString& value, int flags)
{
m_text->ChangeValue( value );
@@ -1232,32 +1137,10 @@ void FbSearchCtrl::RecalcBitmaps()
)
{
m_searchBitmap = RenderSearchBitmap(bitmapWidth,bitmapHeight,false);
- if ( !HasMenu() )
- {
- m_searchButton->SetBitmapLabel(m_searchBitmap);
- }
- }
- // else this bitmap was set by user, don't alter
- }
-
-#if wxUSE_MENUS
- if ( !m_searchMenuBitmapUser )
- {
- if (
- !m_searchMenuBitmap.Ok() ||
- m_searchMenuBitmap.GetHeight() != bitmapHeight ||
- m_searchMenuBitmap.GetWidth() != bitmapWidth
- )
- {
- m_searchMenuBitmap = RenderSearchBitmap(bitmapWidth,bitmapHeight,true);
- if ( m_menu )
- {
- m_searchButton->SetBitmapLabel(m_searchMenuBitmap);
- }
+ m_searchButton->SetBitmapLabel(m_searchBitmap);
}
// else this bitmap was set by user, don't alter
}
-#endif // wxUSE_MENUS
if ( !m_cancelBitmapUser )
{
@@ -1301,18 +1184,4 @@ void FbSearchCtrl::OnSize( wxSizeEvent& WXUNUSED(event) )
LayoutControls(0, 0, width, height);
}
-#if wxUSE_MENUS
-
-void FbSearchCtrl::PopupSearchMenu()
-{
- if ( m_menu )
- {
- wxSize size = GetSize();
- PopupMenu( m_menu, 0, size.y );
- }
-}
-
-#endif // __WXMSW__
-
-#endif // wxUSE_MENUS
-
+#endif // FB_SEARCH_COMBO_CTRL
diff --git a/sources/MyRuLib/controls/FbSearchCtrl.h b/sources/MyRuLib/controls/FbSearchCtrl.h
index 52d4ca4a..59f2b919 100644
--- a/sources/MyRuLib/controls/FbSearchCtrl.h
+++ b/sources/MyRuLib/controls/FbSearchCtrl.h
@@ -13,10 +13,13 @@
#include <wx/wx.h>
#include <wx/odcombo.h>
+#include <wx/srchctrl.h>
#ifdef __WXMSW__
+ #define FB_SEARCH_COMBO_CTRL
+#endif // __WXMSW__
-#include <wx/srchctrl.h>
+#ifdef FB_SEARCH_COMBO_CTRL
class FbSearchCtrl : public wxOwnerDrawnComboBox
{
@@ -50,7 +53,7 @@ public:
}
virtual void SelectAll() {
- GetTextCtrl()->SelectAll();
+ GetTextCtrl()->SelectAll();
}
protected:
@@ -60,7 +63,7 @@ private:
DECLARE_CLASS(FbTextCtrl)
};
-#else // __WXMSW__
+#else // FB_SEARCH_COMBO_CTRL
// ----------------------------------------------------------------------------
// a search ctrl is a text control with a search button and a cancel button
@@ -76,12 +79,6 @@ public:
FbSearchCtrlBase() { }
virtual ~FbSearchCtrlBase() { }
- // search control
-#if wxUSE_MENUS
- virtual void SetMenu(wxMenu *menu) = 0;
- virtual wxMenu *GetMenu() = 0;
-#endif // wxUSE_MENUS
-
// get/set options
virtual void ShowSearchButton( bool show ) = 0;
virtual bool IsSearchButtonVisible() const = 0;
@@ -119,13 +116,6 @@ public:
const wxValidator& validator = wxDefaultValidator,
const wxString& name = wxSearchCtrlNameStr);
-#if wxUSE_MENUS
- // get/set search button menu
- // --------------------------
- virtual void SetMenu( wxMenu* menu );
- virtual wxMenu* GetMenu();
-#endif // wxUSE_MENUS
-
// get/set search options
// ----------------------
virtual void ShowSearchButton( bool show );
@@ -214,9 +204,7 @@ public:
// NB: pt is in device coords (not adjusted for the client area origin nor
// scrolling)
virtual wxTextCtrlHitTestResult HitTest(const wxPoint& pt, long *pos) const;
- virtual wxTextCtrlHitTestResult HitTest(const wxPoint& pt,
- wxTextCoord *col,
- wxTextCoord *row) const;
+ virtual wxTextCtrlHitTestResult HitTest(const wxPoint& pt, wxTextCoord *col, wxTextCoord *row) const;
// Clipboard operations
virtual void Copy();
@@ -244,23 +232,6 @@ public:
virtual void SelectAll();
virtual void SetEditable(bool editable);
-#if 0
-
- // override streambuf method
-#if wxHAS_TEXT_WINDOW_STREAM
- int overflow(int i);
-#endif // wxHAS_TEXT_WINDOW_STREAM
-
- // stream-like insertion operators: these are always available, whether we
- // were, or not, compiled with streambuf support
- wxTextCtrl& operator<<(const wxString& s);
- wxTextCtrl& operator<<(int i);
- wxTextCtrl& operator<<(long i);
- wxTextCtrl& operator<<(float f);
- wxTextCtrl& operator<<(double d);
- wxTextCtrl& operator<<(const wxChar c);
-#endif
-
// do the window-specific processing after processing the update event
virtual void DoUpdateWindowUI(wxUpdateUIEvent& event);
@@ -272,9 +243,6 @@ public:
// search control generic only
void SetSearchBitmap( const wxBitmap& bitmap );
void SetCancelBitmap( const wxBitmap& bitmap );
-#if wxUSE_MENUS
- void SetSearchMenuBitmap( const wxBitmap& bitmap );
-#endif // wxUSE_MENUS
protected:
virtual void DoSetValue(const wxString& value, int flags = 0);
@@ -297,44 +265,22 @@ protected:
void OnSetFocus( wxFocusEvent& event );
void OnSize( wxSizeEvent& event );
- bool HasMenu() const
- {
-#if wxUSE_MENUS
- return m_menu != NULL;
-#else // !wxUSE_MENUS
- return false;
-#endif // wxUSE_MENUS/!wxUSE_MENUS
- }
-
private:
friend class FbSearchButton;
-#if wxUSE_MENUS
- void PopupSearchMenu();
-#endif // wxUSE_MENUS
-
// the subcontrols
FbSearchTextCtrl *m_text;
FbSearchButton *m_searchButton;
FbSearchButton *m_cancelButton;
-#if wxUSE_MENUS
- wxMenu *m_menu;
-#endif // wxUSE_MENUS
bool m_searchButtonVisible;
bool m_cancelButtonVisible;
bool m_searchBitmapUser;
bool m_cancelBitmapUser;
-#if wxUSE_MENUS
- bool m_searchMenuBitmapUser;
-#endif // wxUSE_MENUS
wxBitmap m_searchBitmap;
wxBitmap m_cancelBitmap;
-#if wxUSE_MENUS
- wxBitmap m_searchMenuBitmap;
-#endif // wxUSE_MENUS
private:
DECLARE_DYNAMIC_CLASS(FbSearchCtrl)
@@ -342,6 +288,6 @@ private:
DECLARE_EVENT_TABLE()
};
-#endif // __WXMSW__
+#endif // FB_SEARCH_COMBO_CTRL
#endif // __SEARCHCTRL_H__