1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/srchctlg.cpp
3 // Purpose: implements wxSearchCtrl as a composite control
4 // Author: Vince Harron
7 // Copyright: Vince Harron
8 // License: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
20 #include "wx/srchctrl.h"
23 #include "wx/button.h"
24 #include "wx/dcclient.h"
26 #include "wx/dcmemory.h"
29 #if !wxUSE_NATIVE_SEARCH_CONTROL
33 #define WXMAX(a,b) ((a)>(b)?(a):(b))
35 // ----------------------------------------------------------------------------
37 // ----------------------------------------------------------------------------
39 // the margin between the text control and the search/cancel buttons
40 static const wxCoord MARGIN
= 2;
42 // border around all controls to compensate for wxSIMPLE_BORDER
43 #if defined(__WXMSW__)
44 static const wxCoord BORDER
= 0;
45 static const wxCoord ICON_MARGIN
= 2;
46 static const wxCoord ICON_OFFSET
= 2;
48 static const wxCoord BORDER
= 2;
49 static const wxCoord ICON_MARGIN
= 0;
50 static const wxCoord ICON_OFFSET
= 0;
53 // ----------------------------------------------------------------------------
54 // wxSearchTextCtrl: text control used by search control
55 // ----------------------------------------------------------------------------
57 class wxSearchTextCtrl
: public wxTextCtrl
60 wxSearchTextCtrl(wxSearchCtrl
*search
, const wxString
& value
, int style
)
61 : wxTextCtrl(search
, wxID_ANY
, value
, wxDefaultPosition
, wxDefaultSize
,
66 // remove the default minsize, the searchctrl will have one instead
67 SetSizeHints(wxDefaultCoord
,wxDefaultCoord
);
71 void OnText(wxCommandEvent
& eventText
)
73 wxCommandEvent
event(eventText
);
74 event
.SetEventObject(m_search
);
75 event
.SetId(m_search
->GetId());
77 m_search
->GetEventHandler()->ProcessEvent(event
);
80 void OnTextUrl(wxTextUrlEvent
& eventText
)
82 // copy constructor is disabled for some reason?
83 //wxTextUrlEvent event(eventText);
86 eventText
.GetMouseEvent(),
87 eventText
.GetURLStart(),
90 event
.SetEventObject(m_search
);
92 m_search
->GetEventHandler()->ProcessEvent(event
);
96 wxSearchCtrl
* m_search
;
101 BEGIN_EVENT_TABLE(wxSearchTextCtrl
, wxTextCtrl
)
102 EVT_TEXT(wxID_ANY
, wxSearchTextCtrl::OnText
)
103 EVT_TEXT_ENTER(wxID_ANY
, wxSearchTextCtrl::OnText
)
104 EVT_TEXT_URL(wxID_ANY
, wxSearchTextCtrl::OnTextUrl
)
105 EVT_TEXT_MAXLEN(wxID_ANY
, wxSearchTextCtrl::OnText
)
108 // ----------------------------------------------------------------------------
109 // wxSearchButton: search button used by search control
110 // ----------------------------------------------------------------------------
112 class wxSearchButton
: public wxControl
115 wxSearchButton(wxSearchCtrl
*search
, int eventType
, const wxBitmap
& bmp
)
116 : wxControl(search
, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
, wxNO_BORDER
),
118 m_eventType(eventType
),
122 void SetBitmapLabel(const wxBitmap
& label
) { m_bmp
= label
; }
126 wxSize
DoGetBestSize() const
128 return wxSize(m_bmp
.GetWidth(), m_bmp
.GetHeight());
131 void OnLeftUp(wxMouseEvent
&)
133 wxCommandEvent
event(m_eventType
, m_search
->GetId());
134 event
.SetEventObject(m_search
);
136 GetEventHandler()->ProcessEvent(event
);
138 m_search
->SetFocus();
140 if ( m_eventType
== wxEVT_COMMAND_SEARCHCTRL_SEARCH_BTN
)
142 // this happens automatically, just like on Mac OS X
143 m_search
->PopupSearchMenu();
147 void OnPaint(wxPaintEvent
&)
150 dc
.DrawBitmap(m_bmp
, 0,0, true);
155 wxSearchCtrl
*m_search
;
156 wxEventType m_eventType
;
159 DECLARE_EVENT_TABLE()
162 BEGIN_EVENT_TABLE(wxSearchButton
, wxControl
)
163 EVT_LEFT_UP(wxSearchButton::OnLeftUp
)
164 EVT_PAINT(wxSearchButton::OnPaint
)
167 BEGIN_EVENT_TABLE(wxSearchCtrl
, wxSearchCtrlBase
)
168 EVT_SEARCHCTRL_SEARCH_BTN(wxID_ANY
, wxSearchCtrl::OnSearchButton
)
169 EVT_SET_FOCUS(wxSearchCtrl::OnSetFocus
)
170 EVT_SIZE(wxSearchCtrl::OnSize
)
173 IMPLEMENT_DYNAMIC_CLASS(wxSearchCtrl
, wxSearchCtrlBase
)
175 // ============================================================================
177 // ============================================================================
179 // ----------------------------------------------------------------------------
180 // wxSearchCtrl creation
181 // ----------------------------------------------------------------------------
186 wxSearchCtrl::wxSearchCtrl()
191 wxSearchCtrl::wxSearchCtrl(wxWindow
*parent
, wxWindowID id
,
192 const wxString
& value
,
196 const wxValidator
& validator
,
197 const wxString
& name
)
201 Create(parent
, id
, value
, pos
, size
, style
, validator
, name
);
204 void wxSearchCtrl::Init()
211 m_searchButtonVisible
= true;
212 m_cancelButtonVisible
= false;
214 m_searchMenuBitmapUser
= false;
215 m_searchBitmapUser
= false;
216 m_cancelBitmapUser
= false;
219 bool wxSearchCtrl::Create(wxWindow
*parent
, wxWindowID id
,
220 const wxString
& value
,
224 const wxValidator
& validator
,
225 const wxString
& name
)
228 if ( !wxTextCtrlBase::Create(parent
, id
, pos
, size
, wxSUNKEN_BORDER
| style
, validator
, name
) )
230 if ( !wxTextCtrlBase::Create(parent
, id
, pos
, size
, wxSIMPLE_BORDER
| style
, validator
, name
) )
236 m_text
= new wxSearchTextCtrl(this, value
, style
& ~wxBORDER_MASK
);
238 wxSize sizeText
= m_text
->GetBestSize();
240 m_searchButton
= new wxSearchButton(this,wxEVT_COMMAND_SEARCHCTRL_SEARCH_BTN
,m_searchBitmap
);
241 m_cancelButton
= new wxSearchButton(this,wxEVT_COMMAND_SEARCHCTRL_CANCEL_BTN
,m_cancelBitmap
);
243 SetForegroundColour( m_text
->GetForegroundColour() );
244 m_searchButton
->SetForegroundColour( m_text
->GetForegroundColour() );
245 m_cancelButton
->SetForegroundColour( m_text
->GetForegroundColour() );
247 SetBackgroundColour( m_text
->GetBackgroundColour() );
248 m_searchButton
->SetBackgroundColour( m_text
->GetBackgroundColour() );
249 m_cancelButton
->SetBackgroundColour( m_text
->GetBackgroundColour() );
253 SetInitialSize(size
);
258 wxSearchCtrl::~wxSearchCtrl()
261 delete m_searchButton
;
262 delete m_cancelButton
;
267 // search control specific interfaces
268 void wxSearchCtrl::SetMenu( wxMenu
* menu
)
270 if ( menu
== m_menu
)
275 bool hadMenu
= (m_menu
!= NULL
);
279 if ( m_menu
&& !hadMenu
)
281 m_searchButton
->SetBitmapLabel(m_searchMenuBitmap
);
282 m_searchButton
->Refresh();
283 if ( !m_searchButtonVisible
)
285 // adding the menu will force the search button to be visible
286 wxRect rect
= GetRect();
287 LayoutControls(0, 0, rect
.GetWidth(), rect
.GetHeight());
290 else if ( !m_menu
&& hadMenu
)
292 m_searchButton
->SetBitmapLabel(m_searchBitmap
);
293 if ( m_searchButtonVisible
)
295 m_searchButton
->Refresh();
299 wxRect rect
= GetRect();
300 LayoutControls(0, 0, rect
.GetWidth(), rect
.GetHeight());
305 wxMenu
* wxSearchCtrl::GetMenu()
310 void wxSearchCtrl::ShowSearchButton( bool show
)
312 if ( m_searchButtonVisible
== show
)
317 m_searchButtonVisible
= show
;
318 if ( m_searchButtonVisible
)
323 wxRect rect
= GetRect();
324 LayoutControls(0, 0, rect
.GetWidth(), rect
.GetHeight());
327 bool wxSearchCtrl::IsSearchButtonVisible() const
329 return m_searchButtonVisible
;
333 void wxSearchCtrl::ShowCancelButton( bool show
)
335 if ( m_cancelButtonVisible
== show
)
340 m_cancelButtonVisible
= show
;
342 wxRect rect
= GetRect();
343 LayoutControls(0, 0, rect
.GetWidth(), rect
.GetHeight());
346 bool wxSearchCtrl::IsCancelButtonVisible() const
348 return m_cancelButtonVisible
;
352 // ----------------------------------------------------------------------------
354 // ----------------------------------------------------------------------------
356 wxSize
wxSearchCtrl::DoGetBestSize() const
358 wxSize sizeText
= m_text
->GetBestSize();
359 wxSize
sizeSearch(0,0);
360 wxSize
sizeCancel(0,0);
361 int searchMargin
= 0;
362 int cancelMargin
= 0;
363 if ( m_searchButtonVisible
|| m_menu
)
365 sizeSearch
= m_searchButton
->GetBestSize();
366 searchMargin
= MARGIN
;
368 if ( m_cancelButtonVisible
)
370 sizeCancel
= m_cancelButton
->GetBestSize();
371 cancelMargin
= MARGIN
;
374 int horizontalBorder
= 1 + ( sizeText
.y
- sizeText
.y
* 14 / 21 ) / 2;
376 // buttons are square and equal to the height of the text control
377 int height
= sizeText
.y
;
378 return wxSize(sizeSearch
.x
+ searchMargin
+ sizeText
.x
+ cancelMargin
+ sizeCancel
.x
+ 2*horizontalBorder
,
382 void wxSearchCtrl::DoMoveWindow(int x
, int y
, int width
, int height
)
384 wxSearchCtrlBase::DoMoveWindow(x
, y
, width
, height
);
386 LayoutControls(0, 0, width
, height
);
389 void wxSearchCtrl::LayoutControls(int x
, int y
, int width
, int height
)
394 wxSize sizeText
= m_text
->GetBestSize();
395 // make room for the search menu & clear button
396 int horizontalBorder
= 1 + ( sizeText
.y
- sizeText
.y
* 14 / 21 ) / 2;
397 x
+= horizontalBorder
;
399 width
-= horizontalBorder
*2;
402 wxSize
sizeSearch(0,0);
403 wxSize
sizeCancel(0,0);
404 int searchMargin
= 0;
405 int cancelMargin
= 0;
406 if ( m_searchButtonVisible
|| m_menu
)
408 sizeSearch
= m_searchButton
->GetBestSize();
409 searchMargin
= MARGIN
;
411 if ( m_cancelButtonVisible
)
413 sizeCancel
= m_cancelButton
->GetBestSize();
414 cancelMargin
= MARGIN
;
416 m_searchButton
->Show( m_searchButtonVisible
|| m_menu
);
417 m_cancelButton
->Show( m_cancelButtonVisible
);
419 if ( sizeSearch
.x
+ sizeCancel
.x
> width
)
421 sizeSearch
.x
= width
/2;
422 sizeCancel
.x
= width
/2;
426 wxCoord textWidth
= width
- sizeSearch
.x
- sizeCancel
.x
- searchMargin
- cancelMargin
;
428 // position the subcontrols inside the client area
430 m_searchButton
->SetSize(x
, y
+ ICON_OFFSET
, sizeSearch
.x
, height
);
431 m_text
->SetSize( x
+ sizeSearch
.x
+ searchMargin
,
432 y
+ ICON_OFFSET
- BORDER
,
435 m_cancelButton
->SetSize(x
+ sizeSearch
.x
+ searchMargin
+ textWidth
+ cancelMargin
,
436 y
+ ICON_OFFSET
, sizeCancel
.x
, height
);
443 wxString
wxSearchCtrl::GetValue() const
445 return m_text
->GetValue();
447 void wxSearchCtrl::SetValue(const wxString
& value
)
449 m_text
->SetValue(value
);
452 wxString
wxSearchCtrl::GetRange(long from
, long to
) const
454 return m_text
->GetRange(from
, to
);
457 int wxSearchCtrl::GetLineLength(long lineNo
) const
459 return m_text
->GetLineLength(lineNo
);
461 wxString
wxSearchCtrl::GetLineText(long lineNo
) const
463 return m_text
->GetLineText(lineNo
);
465 int wxSearchCtrl::GetNumberOfLines() const
467 return m_text
->GetNumberOfLines();
470 bool wxSearchCtrl::IsModified() const
472 return m_text
->IsModified();
474 bool wxSearchCtrl::IsEditable() const
476 return m_text
->IsEditable();
479 // more readable flag testing methods
480 bool wxSearchCtrl::IsSingleLine() const
482 return m_text
->IsSingleLine();
484 bool wxSearchCtrl::IsMultiLine() const
486 return m_text
->IsMultiLine();
489 // If the return values from and to are the same, there is no selection.
490 void wxSearchCtrl::GetSelection(long* from
, long* to
) const
492 m_text
->GetSelection(from
, to
);
495 wxString
wxSearchCtrl::GetStringSelection() const
497 return m_text
->GetStringSelection();
504 void wxSearchCtrl::Clear()
508 void wxSearchCtrl::Replace(long from
, long to
, const wxString
& value
)
510 m_text
->Replace(from
, to
, value
);
512 void wxSearchCtrl::Remove(long from
, long to
)
514 m_text
->Remove(from
, to
);
517 // load/save the controls contents from/to the file
518 bool wxSearchCtrl::LoadFile(const wxString
& file
)
520 return m_text
->LoadFile(file
);
522 bool wxSearchCtrl::SaveFile(const wxString
& file
)
524 return m_text
->SaveFile(file
);
527 // sets/clears the dirty flag
528 void wxSearchCtrl::MarkDirty()
532 void wxSearchCtrl::DiscardEdits()
534 m_text
->DiscardEdits();
537 // set the max number of characters which may be entered in a single line
539 void wxSearchCtrl::SetMaxLength(unsigned long len
)
541 m_text
->SetMaxLength(len
);
544 // writing text inserts it at the current position, appending always
545 // inserts it at the end
546 void wxSearchCtrl::WriteText(const wxString
& text
)
548 m_text
->WriteText(text
);
550 void wxSearchCtrl::AppendText(const wxString
& text
)
552 m_text
->AppendText(text
);
555 // insert the character which would have resulted from this key event,
556 // return true if anything has been inserted
557 bool wxSearchCtrl::EmulateKeyPress(const wxKeyEvent
& event
)
559 return m_text
->EmulateKeyPress(event
);
562 // text control under some platforms supports the text styles: these
563 // methods allow to apply the given text style to the given selection or to
564 // set/get the style which will be used for all appended text
565 bool wxSearchCtrl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
567 return m_text
->SetStyle(start
, end
, style
);
569 bool wxSearchCtrl::GetStyle(long position
, wxTextAttr
& style
)
571 return m_text
->GetStyle(position
, style
);
573 bool wxSearchCtrl::SetDefaultStyle(const wxTextAttr
& style
)
575 return m_text
->SetDefaultStyle(style
);
577 const wxTextAttr
& wxSearchCtrl::GetDefaultStyle() const
579 return m_text
->GetDefaultStyle();
582 // translate between the position (which is just an index in the text ctrl
583 // considering all its contents as a single strings) and (x, y) coordinates
584 // which represent column and line.
585 long wxSearchCtrl::XYToPosition(long x
, long y
) const
587 return m_text
->XYToPosition(x
, y
);
589 bool wxSearchCtrl::PositionToXY(long pos
, long *x
, long *y
) const
591 return m_text
->PositionToXY(pos
, x
, y
);
594 void wxSearchCtrl::ShowPosition(long pos
)
596 m_text
->ShowPosition(pos
);
599 // find the character at position given in pixels
601 // NB: pt is in device coords (not adjusted for the client area origin nor
603 wxTextCtrlHitTestResult
wxSearchCtrl::HitTest(const wxPoint
& pt
, long *pos
) const
605 return m_text
->HitTest(pt
, pos
);
607 wxTextCtrlHitTestResult
wxSearchCtrl::HitTest(const wxPoint
& pt
,
609 wxTextCoord
*row
) const
611 return m_text
->HitTest(pt
, col
, row
);
614 // Clipboard operations
615 void wxSearchCtrl::Copy()
619 void wxSearchCtrl::Cut()
623 void wxSearchCtrl::Paste()
628 bool wxSearchCtrl::CanCopy() const
630 return m_text
->CanCopy();
632 bool wxSearchCtrl::CanCut() const
634 return m_text
->CanCut();
636 bool wxSearchCtrl::CanPaste() const
638 return m_text
->CanPaste();
642 void wxSearchCtrl::Undo()
646 void wxSearchCtrl::Redo()
651 bool wxSearchCtrl::CanUndo() const
653 return m_text
->CanUndo();
655 bool wxSearchCtrl::CanRedo() const
657 return m_text
->CanRedo();
661 void wxSearchCtrl::SetInsertionPoint(long pos
)
663 m_text
->SetInsertionPoint(pos
);
665 void wxSearchCtrl::SetInsertionPointEnd()
667 m_text
->SetInsertionPointEnd();
669 long wxSearchCtrl::GetInsertionPoint() const
671 return m_text
->GetInsertionPoint();
673 wxTextPos
wxSearchCtrl::GetLastPosition() const
675 return m_text
->GetLastPosition();
678 void wxSearchCtrl::SetSelection(long from
, long to
)
680 m_text
->SetSelection(from
, to
);
682 void wxSearchCtrl::SelectAll()
687 void wxSearchCtrl::SetEditable(bool editable
)
689 m_text
->SetEditable(editable
);
692 bool wxSearchCtrl::SetFont(const wxFont
& font
)
694 bool result
= wxSearchCtrlBase::SetFont(font
);
695 if ( result
&& m_text
)
697 result
= m_text
->SetFont(font
);
703 // search control generic only
704 void wxSearchCtrl::SetSearchBitmap( const wxBitmap
& bitmap
)
706 m_searchBitmap
= bitmap
;
707 m_searchBitmapUser
= bitmap
.Ok();
708 if ( m_searchBitmapUser
)
710 if ( m_searchButton
&& !m_menu
)
712 m_searchButton
->SetBitmapLabel( m_searchBitmap
);
717 // the user bitmap was just cleared, generate one
722 void wxSearchCtrl::SetSearchMenuBitmap( const wxBitmap
& bitmap
)
724 m_searchMenuBitmap
= bitmap
;
725 m_searchMenuBitmapUser
= bitmap
.Ok();
726 if ( m_searchMenuBitmapUser
)
728 if ( m_searchButton
&& m_menu
)
730 m_searchButton
->SetBitmapLabel( m_searchMenuBitmap
);
735 // the user bitmap was just cleared, generate one
740 void wxSearchCtrl::SetCancelBitmap( const wxBitmap
& bitmap
)
742 m_cancelBitmap
= bitmap
;
743 m_cancelBitmapUser
= bitmap
.Ok();
744 if ( m_cancelBitmapUser
)
746 if ( m_cancelButton
)
748 m_cancelButton
->SetBitmapLabel( m_cancelBitmap
);
753 // the user bitmap was just cleared, generate one
760 // override streambuf method
761 #if wxHAS_TEXT_WINDOW_STREAM
763 #endif // wxHAS_TEXT_WINDOW_STREAM
765 // stream-like insertion operators: these are always available, whether we
766 // were, or not, compiled with streambuf support
767 wxTextCtrl
& operator<<(const wxString
& s
);
768 wxTextCtrl
& operator<<(int i
);
769 wxTextCtrl
& operator<<(long i
);
770 wxTextCtrl
& operator<<(float f
);
771 wxTextCtrl
& operator<<(double d
);
772 wxTextCtrl
& operator<<(const wxChar c
);
775 void wxSearchCtrl::DoSetValue(const wxString
& value
, int flags
)
777 m_text
->ChangeValue( value
);
778 if ( flags
& SetValue_SendEvent
)
779 SendTextUpdatedEvent();
782 // do the window-specific processing after processing the update event
783 void wxSearchCtrl::DoUpdateWindowUI(wxUpdateUIEvent
& event
)
785 wxSearchCtrlBase::DoUpdateWindowUI(event
);
788 bool wxSearchCtrl::ShouldInheritColours() const
793 // icons are rendered at 3-8 times larger than necessary and downscaled for
795 static int GetMultiplier()
798 // speed up bitmap generation by using a small bitmap
801 int depth
= ::wxDisplayDepth();
811 wxBitmap
wxSearchCtrl::RenderSearchBitmap( int x
, int y
, bool renderDrop
)
813 wxColour bg
= GetBackgroundColour();
814 wxColour fg
= GetForegroundColour();
816 //===============================================================================
817 // begin drawing code
818 //===============================================================================
821 // force width:height ratio
833 // glass 11x11, top left corner
834 // handle (9,9)-(13,13)
835 // drop (13,16)-(19,6)-(16,9)
837 int multiplier
= GetMultiplier();
838 int penWidth
= multiplier
* 2;
840 penWidth
= penWidth
* x
/ 20;
842 wxBitmap
bitmap( multiplier
*x
, multiplier
*y
);
844 mem
.SelectObject(bitmap
);
847 mem
.SetBrush( wxBrush(bg
) );
848 mem
.SetPen( wxPen(bg
) );
849 mem
.DrawRectangle(0,0,bitmap
.GetWidth(),bitmap
.GetHeight());
852 mem
.SetBrush( wxBrush(fg
) );
853 mem
.SetPen( wxPen(fg
) );
854 int glassBase
= 5 * x
/ 20;
855 int glassFactor
= 2*glassBase
+ 1;
856 int radius
= multiplier
*glassFactor
/2;
857 mem
.DrawCircle(radius
,radius
,radius
);
858 mem
.SetBrush( wxBrush(bg
) );
859 mem
.SetPen( wxPen(bg
) );
860 mem
.DrawCircle(radius
,radius
,radius
-penWidth
);
863 int lineStart
= radius
+ (radius
-penWidth
/2) * 707 / 1000; // 707 / 1000 = 0.707 = 1/sqrt(2);
865 mem
.SetPen( wxPen(fg
) );
866 mem
.SetBrush( wxBrush(fg
) );
867 int handleCornerShift
= penWidth
* 707 / 1000 / 2; // 707 / 1000 = 0.707 = 1/sqrt(2);
868 handleCornerShift
= WXMAX( handleCornerShift
, 1 );
869 int handleBase
= 4 * x
/ 20;
870 int handleLength
= 2*handleBase
+1;
871 wxPoint handlePolygon
[] =
873 wxPoint(-handleCornerShift
,+handleCornerShift
),
874 wxPoint(+handleCornerShift
,-handleCornerShift
),
875 wxPoint(multiplier
*handleLength
/2+handleCornerShift
,multiplier
*handleLength
/2-handleCornerShift
),
876 wxPoint(multiplier
*handleLength
/2-handleCornerShift
,multiplier
*handleLength
/2+handleCornerShift
),
878 mem
.DrawPolygon(WXSIZEOF(handlePolygon
),handlePolygon
,lineStart
,lineStart
);
880 // draw drop triangle
881 int triangleX
= 13 * x
/ 20;
882 int triangleY
= 5 * x
/ 20;
883 int triangleBase
= 3 * x
/ 20;
884 int triangleFactor
= triangleBase
*2+1;
887 wxPoint dropPolygon
[] =
889 wxPoint(multiplier
*0,multiplier
*0), // triangle left
890 wxPoint(multiplier
*triangleFactor
-1,multiplier
*0), // triangle right
891 wxPoint(multiplier
*triangleFactor
/2,multiplier
*triangleFactor
/2), // triangle bottom
893 mem
.DrawPolygon(WXSIZEOF(dropPolygon
),dropPolygon
,multiplier
*triangleX
,multiplier
*triangleY
);
896 //===============================================================================
898 //===============================================================================
900 if ( multiplier
!= 1 )
902 wxImage image
= bitmap
.ConvertToImage();
904 bitmap
= wxBitmap( image
);
910 wxBitmap
wxSearchCtrl::RenderCancelBitmap( int x
, int y
)
912 wxColour bg
= GetBackgroundColour();
913 wxColour fg
= GetForegroundColour();
915 //===============================================================================
916 // begin drawing code
917 //===============================================================================
934 // cross line starts (4,4)-(10,10)
935 // drop (13,16)-(19,6)-(16,9)
937 int multiplier
= GetMultiplier();
939 int penWidth
= multiplier
* x
/ 14;
941 wxBitmap
bitmap( multiplier
*x
, multiplier
*y
);
943 mem
.SelectObject(bitmap
);
946 mem
.SetBrush( wxBrush(bg
) );
947 mem
.SetPen( wxPen(bg
) );
948 mem
.DrawRectangle(0,0,bitmap
.GetWidth(),bitmap
.GetHeight());
951 mem
.SetBrush( wxBrush(fg
) );
952 mem
.SetPen( wxPen(fg
) );
953 int radius
= multiplier
*x
/2;
954 mem
.DrawCircle(radius
,radius
,radius
);
957 int lineStartBase
= 4 * x
/ 14;
958 int lineLength
= x
- 2*lineStartBase
;
960 mem
.SetPen( wxPen(bg
) );
961 mem
.SetBrush( wxBrush(bg
) );
962 int handleCornerShift
= penWidth
/2;
963 handleCornerShift
= WXMAX( handleCornerShift
, 1 );
964 wxPoint handlePolygon
[] =
966 wxPoint(-handleCornerShift
,+handleCornerShift
),
967 wxPoint(+handleCornerShift
,-handleCornerShift
),
968 wxPoint(multiplier
*lineLength
+handleCornerShift
,multiplier
*lineLength
-handleCornerShift
),
969 wxPoint(multiplier
*lineLength
-handleCornerShift
,multiplier
*lineLength
+handleCornerShift
),
971 mem
.DrawPolygon(WXSIZEOF(handlePolygon
),handlePolygon
,multiplier
*lineStartBase
,multiplier
*lineStartBase
);
972 wxPoint handlePolygon2
[] =
974 wxPoint(+handleCornerShift
,+handleCornerShift
),
975 wxPoint(-handleCornerShift
,-handleCornerShift
),
976 wxPoint(multiplier
*lineLength
-handleCornerShift
,-multiplier
*lineLength
-handleCornerShift
),
977 wxPoint(multiplier
*lineLength
+handleCornerShift
,-multiplier
*lineLength
+handleCornerShift
),
979 mem
.DrawPolygon(WXSIZEOF(handlePolygon2
),handlePolygon2
,multiplier
*lineStartBase
,multiplier
*(x
-lineStartBase
));
981 //===============================================================================
983 //===============================================================================
985 if ( multiplier
!= 1 )
987 wxImage image
= bitmap
.ConvertToImage();
989 bitmap
= wxBitmap( image
);
995 void wxSearchCtrl::RecalcBitmaps()
1001 wxSize sizeText
= m_text
->GetBestSize();
1003 int bitmapHeight
= sizeText
.y
- 2 * ICON_MARGIN
;
1004 int bitmapWidth
= sizeText
.y
* 20 / 14;
1006 if ( !m_searchBitmapUser
)
1009 !m_searchBitmap
.Ok() ||
1010 m_searchBitmap
.GetHeight() != bitmapHeight
||
1011 m_searchBitmap
.GetWidth() != bitmapWidth
1014 m_searchBitmap
= RenderSearchBitmap(bitmapWidth
,bitmapHeight
,false);
1017 m_searchButton
->SetBitmapLabel(m_searchBitmap
);
1020 // else this bitmap was set by user, don't alter
1023 if ( !m_searchMenuBitmapUser
)
1026 !m_searchMenuBitmap
.Ok() ||
1027 m_searchMenuBitmap
.GetHeight() != bitmapHeight
||
1028 m_searchMenuBitmap
.GetWidth() != bitmapWidth
1031 m_searchMenuBitmap
= RenderSearchBitmap(bitmapWidth
,bitmapHeight
,true);
1034 m_searchButton
->SetBitmapLabel(m_searchMenuBitmap
);
1037 // else this bitmap was set by user, don't alter
1040 if ( !m_cancelBitmapUser
)
1043 !m_cancelBitmap
.Ok() ||
1044 m_cancelBitmap
.GetHeight() != bitmapHeight
||
1045 m_cancelBitmap
.GetWidth() != bitmapHeight
1048 m_cancelBitmap
= RenderCancelBitmap(bitmapHeight
-BORDER
,bitmapHeight
-BORDER
); // square
1049 m_cancelButton
->SetBitmapLabel(m_cancelBitmap
);
1051 // else this bitmap was set by user, don't alter
1055 void wxSearchCtrl::OnSearchButton( wxCommandEvent
& event
)
1060 void wxSearchCtrl::OnSetFocus( wxFocusEvent
& /*event*/ )
1068 void wxSearchCtrl::OnSize( wxSizeEvent
& WXUNUSED(event
) )
1071 GetSize(&width
, &height
);
1072 LayoutControls(0, 0, width
, height
);
1075 void wxSearchCtrl::PopupSearchMenu()
1079 wxSize size
= GetSize();
1080 PopupMenu( m_menu
, 0, size
.y
);
1084 #endif // !wxUSE_NATIVE_SEARCH_CONTROL
1086 #endif // wxUSE_SEARCHCTRL