Improve speed of category tab title updates
[amule.git] / src / MuleTextCtrl.cpp
blobfc29a853e9e859a009b670aedc54862a99284753
1 //
2 // This file is part of the aMule Project.
3 //
4 // Copyright (c) 2004-2008 aMule Team ( admin@amule.org / http://www.amule.org )
5 //
6 // Any parts of this program derived from the xMule, lMule or eMule project,
7 // or contributed by third-party developers are copyrighted by their
8 // respective authors.
9 //
10 // This program is free software; you can redistribute it and/or modify
11 // it under the terms of the GNU General Public License as published by
12 // the Free Software Foundation; either version 2 of the License, or
13 // (at your option) any later version.
15 // This program is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with this program; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include "MuleTextCtrl.h"
26 #include <wx/menu.h>
27 #include <wx/intl.h>
28 #include <wx/dataobj.h>
29 #include <wx/clipbrd.h>
31 /**
32 * These are the IDs used to identify the different menu-items.
34 * Please note that I make use of predefined wxIDs for the first two, but not
35 * for Paste. This is because wxMenu poses some restrictions on what can be
36 * done with items using those IDs, and by default, Paste is enabled even if
37 * there's nothing to paste!
38 */
39 enum CMTC_Events
41 //! Cut text, uses provided ID
42 CMTCE_Cut = wxID_CUT,
43 //! Copy text, uses privided ID
44 CMTCE_Copy = wxID_COPY,
45 //! Paste text, uses custom ID
46 CMTCE_Paste = wxID_HIGHEST + 666, // Random satanic ID
47 //! Clear text, uses custom ID
48 CMTCE_Clear,
49 //! Select All text, uses custom ID
50 CMTCE_SelAll
54 BEGIN_EVENT_TABLE(CMuleTextCtrl, wxTextCtrl)
55 #ifndef __WXGTK__
56 EVT_RIGHT_DOWN (CMuleTextCtrl::OnRightDown)
58 EVT_MENU (CMTCE_Paste, CMuleTextCtrl::OnPaste)
59 EVT_MENU (CMTCE_Clear, CMuleTextCtrl::OnClear)
60 EVT_MENU (CMTCE_SelAll, CMuleTextCtrl::OnSelAll)
61 #endif
62 END_EVENT_TABLE()
65 CMuleTextCtrl::CMuleTextCtrl(wxWindow* parent, wxWindowID id, const wxString& value, const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator, const wxString& name)
66 : wxTextCtrl( parent, id, value, pos, size, style, validator, name)
71 void CMuleTextCtrl::OnRightDown( wxMouseEvent& evt )
73 // If this control doesn't have focus, then set it
74 if ( FindFocus() != this )
75 SetFocus();
77 wxMenu popup_menu;
79 popup_menu.Append( CMTCE_Cut, _("Cut") );
80 popup_menu.Append( CMTCE_Copy, _("Copy") );
81 popup_menu.Append( CMTCE_Paste, _("Paste") );
82 popup_menu.Append( CMTCE_Clear, _("Clear") );
84 popup_menu.AppendSeparator();
86 popup_menu.Append( CMTCE_SelAll, _("Select All") );
89 // wxMenu will automatically enable/disable the Cut and Copy items,
90 // however, were are a little more pricky about the Paste item than they
91 // are, so we enable/disable it on our own, depending on whenever or not
92 // there's actually something to paste
93 bool canpaste = false;
94 if ( CanPaste() ) {
95 if ( wxTheClipboard->Open() ) {
96 if ( wxTheClipboard->IsSupported( wxDF_TEXT ) ) {
97 wxTextDataObject data;
98 wxTheClipboard->GetData( data );
100 canpaste = (data.GetTextLength() > 0);
102 wxTheClipboard->Close();
107 popup_menu.Enable( CMTCE_Paste, canpaste );
108 popup_menu.Enable( CMTCE_Clear, IsEditable() && !GetValue().IsEmpty() );
110 PopupMenu( &popup_menu, evt.GetX(), evt.GetY() );
114 void CMuleTextCtrl::OnPaste( wxCommandEvent& WXUNUSED(evt) )
116 Paste();
120 void CMuleTextCtrl::OnSelAll( wxCommandEvent& WXUNUSED(evt) )
122 // Move the pointer to the front
123 SetInsertionPoint( 0 );
125 // Selects everything
126 SetSelection( -1, -1 );
130 void CMuleTextCtrl::OnClear( wxCommandEvent& WXUNUSED(evt) )
132 Clear();
136 #ifdef __WXMAC__
137 //#warning Remove this when wxMAC has been fixed.
138 // https://sourceforge.net/tracker/?func=detail&atid=109863&aid=1189859&group_id=9863
139 void CMuleTextCtrl::Clear()
141 if (IsMultiLine()) {
142 wxFont font = GetFont();
143 wxTextCtrl::Clear();
144 SetFont(font);
145 } else {
146 wxTextCtrl::Clear();
149 #endif
151 // File_checked_for_headers