1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/srchctlg.cpp
3 // Purpose: implements wxSearchCtrl as a composite control
4 // Author: Vince Harron
8 // Copyright: Vince Harron
9 // License: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
28 #include "wx/button.h"
29 #include "wx/dcclient.h"
31 #include "wx/dcmemory.h"
36 #include "wx/srchctrl.h"
38 #if !USE_NATIVE_SEARCH_CONTROL
42 #define WXMIN(a,b) (a)<(b)?(a):(b)
43 #define WXMAX(a,b) (a)>(b)?(a):(b)
45 // ----------------------------------------------------------------------------
47 // ----------------------------------------------------------------------------
49 // the margin between the text control and the search/cancel buttons
50 static const wxCoord MARGIN
= 2;
52 // border around all controls to compensate for wxSIMPLE_BORDER
53 #if defined(__WXMSW__)
54 static const wxCoord BORDER
= 0;
55 static const wxCoord ICON_MARGIN
= 2;
56 static const wxCoord ICON_OFFSET
= 2;
58 static const wxCoord BORDER
= 2;
59 static const wxCoord ICON_MARGIN
= 0;
60 static const wxCoord ICON_OFFSET
= 0;
63 // ----------------------------------------------------------------------------
64 // wxSearchTextCtrl: text control used by search control
65 // ----------------------------------------------------------------------------
67 class wxSearchTextCtrl
: public wxTextCtrl
70 wxSearchTextCtrl(wxSearchCtrl
*search
, const wxString
& value
, int style
)
71 : wxTextCtrl(search
, wxID_ANY
, value
, wxDefaultPosition
, wxDefaultSize
,
76 // remove the default minsize, the searchctrl will have one instead
77 SetSizeHints(wxDefaultCoord
,wxDefaultCoord
);
81 void OnText(wxCommandEvent
& eventText
)
83 wxCommandEvent
event(eventText
);
84 event
.SetEventObject(m_search
);
85 event
.SetId(m_search
->GetId());
87 m_search
->GetEventHandler()->ProcessEvent(event
);
90 void OnTextUrl(wxTextUrlEvent
& eventText
)
92 // copy constructor is disabled for some reason?
93 //wxTextUrlEvent event(eventText);
96 eventText
.GetMouseEvent(),
97 eventText
.GetURLStart(),
100 event
.SetEventObject(m_search
);
102 m_search
->GetEventHandler()->ProcessEvent(event
);
106 wxSearchCtrl
* m_search
;
108 DECLARE_EVENT_TABLE()
111 BEGIN_EVENT_TABLE(wxSearchTextCtrl
, wxTextCtrl
)
112 EVT_TEXT(wxID_ANY
, wxSearchTextCtrl::OnText
)
113 EVT_TEXT_ENTER(wxID_ANY
, wxSearchTextCtrl::OnText
)
114 EVT_TEXT_URL(wxID_ANY
, wxSearchTextCtrl::OnTextUrl
)
115 EVT_TEXT_MAXLEN(wxID_ANY
, wxSearchTextCtrl::OnText
)
118 // ----------------------------------------------------------------------------
119 // wxSearchButton: search button used by search control
120 // ----------------------------------------------------------------------------
122 class wxSearchButton
: public wxControl
125 wxSearchButton(wxSearchCtrl
*search
, int eventType
, const wxBitmap
& bmp
)
126 : wxControl(search
, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
, wxNO_BORDER
),
128 m_eventType(eventType
),
132 void SetBitmapLabel(const wxBitmap
& label
) { m_bmp
= label
; }
136 wxSize
DoGetBestSize() const
138 return wxSize(m_bmp
.GetWidth(), m_bmp
.GetHeight());
141 void OnLeftUp(wxMouseEvent
&)
143 wxCommandEvent
event(m_eventType
, m_search
->GetId());
144 event
.SetEventObject(m_search
);
146 GetEventHandler()->ProcessEvent(event
);
148 m_search
->SetFocus();
150 if ( m_eventType
== wxEVT_COMMAND_SEARCHCTRL_SEARCH
)
152 // this happens automatically, just like on Mac OS X
153 m_search
->PopupSearchMenu();
157 void OnPaint(wxPaintEvent
&)
160 dc
.DrawBitmap(m_bmp
, 0,0, true);
165 wxSearchCtrl
*m_search
;
166 wxEventType m_eventType
;
169 DECLARE_EVENT_TABLE()
172 BEGIN_EVENT_TABLE(wxSearchButton
, wxControl
)
173 EVT_LEFT_UP(wxSearchButton::OnLeftUp
)
174 EVT_PAINT(wxSearchButton::OnPaint
)
177 BEGIN_EVENT_TABLE(wxSearchCtrl
, wxSearchCtrlBase
)
178 EVT_SEARCHCTRL_SEARCH(wxID_ANY
, wxSearchCtrl::OnSearchButton
)
179 EVT_SET_FOCUS(wxSearchCtrl::OnSetFocus
)
182 IMPLEMENT_DYNAMIC_CLASS(wxSearchCtrl
, wxSearchCtrlBase
)
184 // ============================================================================
186 // ============================================================================
188 // ----------------------------------------------------------------------------
189 // wxSearchCtrl creation
190 // ----------------------------------------------------------------------------
195 wxSearchCtrl::wxSearchCtrl()
200 wxSearchCtrl::wxSearchCtrl(wxWindow
*parent
, wxWindowID id
,
201 const wxString
& value
,
205 const wxValidator
& validator
,
206 const wxString
& name
)
210 Create(parent
, id
, value
, pos
, size
, style
, validator
, name
);
213 void wxSearchCtrl::Init()
220 m_searchButtonVisible
= true;
221 m_cancelButtonVisible
= false;
223 m_searchMenuBitmapUser
= false;
224 m_searchBitmapUser
= false;
225 m_cancelBitmapUser
= false;
228 bool wxSearchCtrl::Create(wxWindow
*parent
, wxWindowID id
,
229 const wxString
& value
,
233 const wxValidator
& validator
,
234 const wxString
& name
)
236 if ( !wxTextCtrlBase::Create(parent
, id
, pos
, size
, wxSIMPLE_BORDER
| style
, validator
, name
) )
241 m_text
= new wxSearchTextCtrl(this, value
, style
& ~wxBORDER_MASK
);
243 wxSize sizeText
= m_text
->GetBestSize();
245 m_searchButton
= new wxSearchButton(this,wxEVT_COMMAND_SEARCHCTRL_SEARCH
,m_searchBitmap
);
246 m_cancelButton
= new wxSearchButton(this,wxEVT_COMMAND_SEARCHCTRL_CANCEL
,m_cancelBitmap
);
248 SetForegroundColour( m_text
->GetForegroundColour() );
249 m_searchButton
->SetForegroundColour( m_text
->GetForegroundColour() );
250 m_cancelButton
->SetForegroundColour( m_text
->GetForegroundColour() );
252 SetBackgroundColour( m_text
->GetBackgroundColour() );
253 m_searchButton
->SetBackgroundColour( m_text
->GetBackgroundColour() );
254 m_cancelButton
->SetBackgroundColour( m_text
->GetBackgroundColour() );
258 SetInitialSize(size
);
263 wxSearchCtrl::~wxSearchCtrl()
266 delete m_searchButton
;
267 delete m_cancelButton
;
272 // search control specific interfaces
273 void wxSearchCtrl::SetMenu( wxMenu
* menu
)
275 if ( menu
== m_menu
)
281 bool hadMenu
= (m_menu
!=0);
284 if ( m_menu
&& !hadMenu
)
286 m_searchButton
->SetBitmapLabel(m_searchMenuBitmap
);
287 m_searchButton
->Refresh();
288 if ( !m_searchButtonVisible
)
290 // adding the menu will force the search button to be visible
291 wxRect rect
= GetRect();
292 LayoutControls(0, 0, rect
.GetWidth(), rect
.GetHeight());
295 else if ( !m_menu
&& hadMenu
)
297 m_searchButton
->SetBitmapLabel(m_searchBitmap
);
298 if ( m_searchButtonVisible
)
300 m_searchButton
->Refresh();
304 wxRect rect
= GetRect();
305 LayoutControls(0, 0, rect
.GetWidth(), rect
.GetHeight());
310 wxMenu
* wxSearchCtrl::GetMenu()
315 void wxSearchCtrl::ShowSearchButton( bool show
)
317 if ( m_searchButtonVisible
== show
)
322 m_searchButtonVisible
= show
;
323 if ( m_searchButtonVisible
)
328 wxRect rect
= GetRect();
329 LayoutControls(0, 0, rect
.GetWidth(), rect
.GetHeight());
332 bool wxSearchCtrl::IsSearchButtonVisible() const
334 return m_searchButtonVisible
;
338 void wxSearchCtrl::ShowCancelButton( bool show
)
340 if ( m_cancelButtonVisible
== show
)
345 m_cancelButtonVisible
= show
;
347 wxRect rect
= GetRect();
348 LayoutControls(0, 0, rect
.GetWidth(), rect
.GetHeight());
351 bool wxSearchCtrl::IsCancelButtonVisible() const
353 return m_cancelButtonVisible
;
357 // ----------------------------------------------------------------------------
359 // ----------------------------------------------------------------------------
361 wxSize
wxSearchCtrl::DoGetBestSize() const
363 wxSize sizeText
= m_text
->GetBestSize();
364 wxSize
sizeSearch(0,0);
365 wxSize
sizeCancel(0,0);
366 int searchMargin
= 0;
367 int cancelMargin
= 0;
368 if ( m_searchButtonVisible
|| m_menu
)
370 sizeSearch
= m_searchButton
->GetBestSize();
371 searchMargin
= MARGIN
;
373 if ( m_cancelButtonVisible
)
375 sizeCancel
= m_cancelButton
->GetBestSize();
376 cancelMargin
= MARGIN
;
379 int horizontalBorder
= 1 + ( sizeText
.y
- sizeText
.y
* 14 / 21 ) / 2;
381 // buttons are square and equal to the height of the text control
382 int height
= sizeText
.y
;
383 return wxSize(sizeSearch
.x
+ searchMargin
+ sizeText
.x
+ cancelMargin
+ sizeCancel
.x
+ 2*horizontalBorder
,
387 void wxSearchCtrl::DoMoveWindow(int x
, int y
, int width
, int height
)
389 wxSearchCtrlBase::DoMoveWindow(x
, y
, width
, height
);
391 LayoutControls(0, 0, width
, height
);
394 void wxSearchCtrl::LayoutControls(int x
, int y
, int width
, int height
)
396 wxSize sizeText
= m_text
->GetBestSize();
397 // make room for the search menu & clear button
398 int horizontalBorder
= 1 + ( sizeText
.y
- sizeText
.y
* 14 / 21 ) / 2;
399 x
+= horizontalBorder
;
401 width
-= horizontalBorder
*2;
404 wxSize
sizeSearch(0,0);
405 wxSize
sizeCancel(0,0);
406 int searchMargin
= 0;
407 int cancelMargin
= 0;
408 if ( m_searchButtonVisible
|| m_menu
)
410 sizeSearch
= m_searchButton
->GetBestSize();
411 searchMargin
= MARGIN
;
413 if ( m_cancelButtonVisible
)
415 sizeCancel
= m_cancelButton
->GetBestSize();
416 cancelMargin
= MARGIN
;
418 m_searchButton
->Show( m_searchButtonVisible
|| m_menu
);
419 m_cancelButton
->Show( m_cancelButtonVisible
);
421 if ( sizeSearch
.x
+ sizeCancel
.x
> width
)
423 sizeSearch
.x
= width
/2;
424 sizeCancel
.x
= width
/2;
428 wxCoord textWidth
= width
- sizeSearch
.x
- sizeCancel
.x
- searchMargin
- cancelMargin
;
430 // position the subcontrols inside the client area
432 m_searchButton
->SetSize(x
, y
+ ICON_OFFSET
, sizeSearch
.x
, height
);
433 m_text
->SetSize(x
+ sizeSearch
.x
+ searchMargin
, y
+ ICON_OFFSET
, textWidth
, height
);
434 m_cancelButton
->SetSize(x
+ sizeSearch
.x
+ searchMargin
+ textWidth
+ cancelMargin
,
435 y
+ ICON_OFFSET
, sizeCancel
.x
, height
);
442 wxString
wxSearchCtrl::GetValue() const
444 return m_text
->GetValue();
446 void wxSearchCtrl::SetValue(const wxString
& value
)
448 m_text
->SetValue(value
);
451 wxString
wxSearchCtrl::GetRange(long from
, long to
) const
453 return m_text
->GetRange(from
, to
);
456 int wxSearchCtrl::GetLineLength(long lineNo
) const
458 return m_text
->GetLineLength(lineNo
);
460 wxString
wxSearchCtrl::GetLineText(long lineNo
) const
462 return m_text
->GetLineText(lineNo
);
464 int wxSearchCtrl::GetNumberOfLines() const
466 return m_text
->GetNumberOfLines();
469 bool wxSearchCtrl::IsModified() const
471 return m_text
->IsModified();
473 bool wxSearchCtrl::IsEditable() const
475 return m_text
->IsEditable();
478 // more readable flag testing methods
479 bool wxSearchCtrl::IsSingleLine() const
481 return m_text
->IsSingleLine();
483 bool wxSearchCtrl::IsMultiLine() const
485 return m_text
->IsMultiLine();
488 // If the return values from and to are the same, there is no selection.
489 void wxSearchCtrl::GetSelection(long* from
, long* to
) const
491 m_text
->GetSelection(from
, to
);
494 wxString
wxSearchCtrl::GetStringSelection() const
496 return m_text
->GetStringSelection();
503 void wxSearchCtrl::Clear()
507 void wxSearchCtrl::Replace(long from
, long to
, const wxString
& value
)
509 m_text
->Replace(from
, to
, value
);
511 void wxSearchCtrl::Remove(long from
, long to
)
513 m_text
->Remove(from
, to
);
516 // load/save the controls contents from/to the file
517 bool wxSearchCtrl::LoadFile(const wxString
& file
)
519 return m_text
->LoadFile(file
);
521 bool wxSearchCtrl::SaveFile(const wxString
& file
)
523 return m_text
->SaveFile(file
);
526 // sets/clears the dirty flag
527 void wxSearchCtrl::MarkDirty()
531 void wxSearchCtrl::DiscardEdits()
533 m_text
->DiscardEdits();
536 // set the max number of characters which may be entered in a single line
538 void wxSearchCtrl::SetMaxLength(unsigned long len
)
540 m_text
->SetMaxLength(len
);
543 // writing text inserts it at the current position, appending always
544 // inserts it at the end
545 void wxSearchCtrl::WriteText(const wxString
& text
)
547 m_text
->WriteText(text
);
549 void wxSearchCtrl::AppendText(const wxString
& text
)
551 m_text
->AppendText(text
);
554 // insert the character which would have resulted from this key event,
555 // return true if anything has been inserted
556 bool wxSearchCtrl::EmulateKeyPress(const wxKeyEvent
& event
)
558 return m_text
->EmulateKeyPress(event
);
561 // text control under some platforms supports the text styles: these
562 // methods allow to apply the given text style to the given selection or to
563 // set/get the style which will be used for all appended text
564 bool wxSearchCtrl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
566 return m_text
->SetStyle(start
, end
, style
);
568 bool wxSearchCtrl::GetStyle(long position
, wxTextAttr
& style
)
570 return m_text
->GetStyle(position
, style
);
572 bool wxSearchCtrl::SetDefaultStyle(const wxTextAttr
& style
)
574 return m_text
->SetDefaultStyle(style
);
576 const wxTextAttr
& wxSearchCtrl::GetDefaultStyle() const
578 return m_text
->GetDefaultStyle();
581 // translate between the position (which is just an index in the text ctrl
582 // considering all its contents as a single strings) and (x, y) coordinates
583 // which represent column and line.
584 long wxSearchCtrl::XYToPosition(long x
, long y
) const
586 return m_text
->XYToPosition(x
, y
);
588 bool wxSearchCtrl::PositionToXY(long pos
, long *x
, long *y
) const
590 return m_text
->PositionToXY(pos
, x
, y
);
593 void wxSearchCtrl::ShowPosition(long pos
)
595 m_text
->ShowPosition(pos
);
598 // find the character at position given in pixels
600 // NB: pt is in device coords (not adjusted for the client area origin nor
602 wxTextCtrlHitTestResult
wxSearchCtrl::HitTest(const wxPoint
& pt
, long *pos
) const
604 return m_text
->HitTest(pt
, pos
);
606 wxTextCtrlHitTestResult
wxSearchCtrl::HitTest(const wxPoint
& pt
,
608 wxTextCoord
*row
) const
610 return m_text
->HitTest(pt
, col
, row
);
613 // Clipboard operations
614 void wxSearchCtrl::Copy()
618 void wxSearchCtrl::Cut()
622 void wxSearchCtrl::Paste()
627 bool wxSearchCtrl::CanCopy() const
629 return m_text
->CanCopy();
631 bool wxSearchCtrl::CanCut() const
633 return m_text
->CanCut();
635 bool wxSearchCtrl::CanPaste() const
637 return m_text
->CanPaste();
641 void wxSearchCtrl::Undo()
645 void wxSearchCtrl::Redo()
650 bool wxSearchCtrl::CanUndo() const
652 return m_text
->CanUndo();
654 bool wxSearchCtrl::CanRedo() const
656 return m_text
->CanRedo();
660 void wxSearchCtrl::SetInsertionPoint(long pos
)
662 m_text
->SetInsertionPoint(pos
);
664 void wxSearchCtrl::SetInsertionPointEnd()
666 m_text
->SetInsertionPointEnd();
668 long wxSearchCtrl::GetInsertionPoint() const
670 return m_text
->GetInsertionPoint();
672 wxTextPos
wxSearchCtrl::GetLastPosition() const
674 return m_text
->GetLastPosition();
677 void wxSearchCtrl::SetSelection(long from
, long to
)
679 m_text
->SetSelection(from
, to
);
681 void wxSearchCtrl::SelectAll()
686 void wxSearchCtrl::SetEditable(bool editable
)
688 m_text
->SetEditable(editable
);
691 bool wxSearchCtrl::SetFont(const wxFont
& font
)
693 bool result
= wxSearchCtrlBase::SetFont(font
);
694 if ( result
&& m_text
)
696 result
&= m_text
->SetFont(font
);
702 // search control generic only
703 void wxSearchCtrl::SetSearchBitmap( const wxBitmap
& bitmap
)
705 m_searchBitmap
= bitmap
;
706 m_searchBitmapUser
= bitmap
.Ok();
707 if ( m_searchBitmapUser
)
709 if ( m_searchButton
&& !m_menu
)
711 m_searchButton
->SetBitmapLabel( m_searchBitmap
);
716 // the user bitmap was just cleared, generate one
721 void wxSearchCtrl::SetSearchMenuBitmap( const wxBitmap
& bitmap
)
723 m_searchMenuBitmap
= bitmap
;
724 m_searchMenuBitmapUser
= bitmap
.Ok();
725 if ( m_searchMenuBitmapUser
)
727 if ( m_searchButton
&& m_menu
)
729 m_searchButton
->SetBitmapLabel( m_searchMenuBitmap
);
734 // the user bitmap was just cleared, generate one
739 void wxSearchCtrl::SetCancelBitmap( const wxBitmap
& bitmap
)
741 m_cancelBitmap
= bitmap
;
742 m_cancelBitmapUser
= bitmap
.Ok();
743 if ( m_cancelBitmapUser
)
745 if ( m_cancelButton
)
747 m_cancelButton
->SetBitmapLabel( m_cancelBitmap
);
752 // the user bitmap was just cleared, generate one
759 // override streambuf method
760 #if wxHAS_TEXT_WINDOW_STREAM
762 #endif // wxHAS_TEXT_WINDOW_STREAM
764 // stream-like insertion operators: these are always available, whether we
765 // were, or not, compiled with streambuf support
766 wxTextCtrl
& operator<<(const wxString
& s
);
767 wxTextCtrl
& operator<<(int i
);
768 wxTextCtrl
& operator<<(long i
);
769 wxTextCtrl
& operator<<(float f
);
770 wxTextCtrl
& operator<<(double d
);
771 wxTextCtrl
& operator<<(const wxChar c
);
774 void wxSearchCtrl::DoSetValue(const wxString
& value
, int flags
)
776 m_text
->ChangeValue( value
);
777 if ( flags
& SetValue_SendEvent
)
778 SendTextUpdatedEvent();
781 // do the window-specific processing after processing the update event
782 void wxSearchCtrl::DoUpdateWindowUI(wxUpdateUIEvent
& event
)
784 wxSearchCtrlBase::DoUpdateWindowUI(event
);
787 bool wxSearchCtrl::ShouldInheritColours() const
792 // icons are rendered at 3-8 times larger than necessary and downscaled for
794 static int GetMultiplier()
797 // speed up bitmap generation by using a small bitmap
800 int depth
= ::wxDisplayDepth();
810 wxBitmap
wxSearchCtrl::RenderSearchBitmap( int x
, int y
, bool renderDrop
)
812 wxColour bg
= GetBackgroundColour();
813 wxColour fg
= GetForegroundColour();
815 //===============================================================================
816 // begin drawing code
817 //===============================================================================
820 // force width:height ratio
832 // glass 11x11, top left corner
833 // handle (9,9)-(13,13)
834 // drop (13,16)-(19,6)-(16,9)
836 int multiplier
= GetMultiplier();
837 int penWidth
= multiplier
* 2;
839 penWidth
= penWidth
* x
/ 20;
841 wxBitmap
bitmap( multiplier
*x
, multiplier
*y
);
843 mem
.SelectObject(bitmap
);
846 mem
.SetBrush( wxBrush(bg
) );
847 mem
.SetPen( wxPen(bg
) );
848 mem
.DrawRectangle(0,0,bitmap
.GetWidth(),bitmap
.GetHeight());
851 mem
.SetBrush( wxBrush(fg
) );
852 mem
.SetPen( wxPen(fg
) );
853 int glassBase
= 5 * x
/ 20;
854 int glassFactor
= 2*glassBase
+ 1;
855 int radius
= multiplier
*glassFactor
/2;
856 mem
.DrawCircle(radius
,radius
,radius
);
857 mem
.SetBrush( wxBrush(bg
) );
858 mem
.SetPen( wxPen(bg
) );
859 mem
.DrawCircle(radius
,radius
,radius
-penWidth
);
862 int lineStart
= radius
+ (radius
-penWidth
/2) * 707 / 1000; // 707 / 1000 = 0.707 = 1/sqrt(2);
864 mem
.SetPen( wxPen(fg
) );
865 mem
.SetBrush( wxBrush(fg
) );
866 int handleCornerShift
= penWidth
* 707 / 1000 / 2; // 707 / 1000 = 0.707 = 1/sqrt(2);
867 handleCornerShift
= WXMAX( handleCornerShift
, 1 );
868 int handleBase
= 4 * x
/ 20;
869 int handleLength
= 2*handleBase
+1;
870 wxPoint handlePolygon
[] =
872 wxPoint(-handleCornerShift
,+handleCornerShift
),
873 wxPoint(+handleCornerShift
,-handleCornerShift
),
874 wxPoint(multiplier
*handleLength
/2+handleCornerShift
,multiplier
*handleLength
/2-handleCornerShift
),
875 wxPoint(multiplier
*handleLength
/2-handleCornerShift
,multiplier
*handleLength
/2+handleCornerShift
),
877 mem
.DrawPolygon(WXSIZEOF(handlePolygon
),handlePolygon
,lineStart
,lineStart
);
879 // draw drop triangle
880 int triangleX
= 13 * x
/ 20;
881 int triangleY
= 5 * x
/ 20;
882 int triangleBase
= 3 * x
/ 20;
883 int triangleFactor
= triangleBase
*2+1;
886 wxPoint dropPolygon
[] =
888 wxPoint(multiplier
*0,multiplier
*0), // triangle left
889 wxPoint(multiplier
*triangleFactor
-1,multiplier
*0), // triangle right
890 wxPoint(multiplier
*triangleFactor
/2,multiplier
*triangleFactor
/2), // triangle bottom
892 mem
.DrawPolygon(WXSIZEOF(dropPolygon
),dropPolygon
,multiplier
*triangleX
,multiplier
*triangleY
);
895 //===============================================================================
897 //===============================================================================
899 if ( multiplier
!= 1 )
901 wxImage image
= bitmap
.ConvertToImage();
903 bitmap
= wxBitmap( image
);
909 wxBitmap
wxSearchCtrl::RenderCancelBitmap( int x
, int y
)
911 wxColour bg
= GetBackgroundColour();
912 wxColour fg
= GetForegroundColour();
914 //===============================================================================
915 // begin drawing code
916 //===============================================================================
933 // cross line starts (4,4)-(10,10)
934 // drop (13,16)-(19,6)-(16,9)
936 int multiplier
= GetMultiplier();
938 int penWidth
= multiplier
* x
/ 14;
940 wxBitmap
bitmap( multiplier
*x
, multiplier
*y
);
942 mem
.SelectObject(bitmap
);
945 mem
.SetBrush( wxBrush(bg
) );
946 mem
.SetPen( wxPen(bg
) );
947 mem
.DrawRectangle(0,0,bitmap
.GetWidth(),bitmap
.GetHeight());
950 mem
.SetBrush( wxBrush(fg
) );
951 mem
.SetPen( wxPen(fg
) );
952 int radius
= multiplier
*x
/2;
953 mem
.DrawCircle(radius
,radius
,radius
);
956 int lineStartBase
= 4 * x
/ 14;
957 int lineLength
= x
- 2*lineStartBase
;
959 mem
.SetPen( wxPen(bg
) );
960 mem
.SetBrush( wxBrush(bg
) );
961 int handleCornerShift
= penWidth
/2;
962 handleCornerShift
= WXMAX( handleCornerShift
, 1 );
963 wxPoint handlePolygon
[] =
965 wxPoint(-handleCornerShift
,+handleCornerShift
),
966 wxPoint(+handleCornerShift
,-handleCornerShift
),
967 wxPoint(multiplier
*lineLength
+handleCornerShift
,multiplier
*lineLength
-handleCornerShift
),
968 wxPoint(multiplier
*lineLength
-handleCornerShift
,multiplier
*lineLength
+handleCornerShift
),
970 mem
.DrawPolygon(WXSIZEOF(handlePolygon
),handlePolygon
,multiplier
*lineStartBase
,multiplier
*lineStartBase
);
971 wxPoint handlePolygon2
[] =
973 wxPoint(+handleCornerShift
,+handleCornerShift
),
974 wxPoint(-handleCornerShift
,-handleCornerShift
),
975 wxPoint(multiplier
*lineLength
-handleCornerShift
,-multiplier
*lineLength
-handleCornerShift
),
976 wxPoint(multiplier
*lineLength
+handleCornerShift
,-multiplier
*lineLength
+handleCornerShift
),
978 mem
.DrawPolygon(WXSIZEOF(handlePolygon2
),handlePolygon2
,multiplier
*lineStartBase
,multiplier
*(x
-lineStartBase
));
980 //===============================================================================
982 //===============================================================================
984 if ( multiplier
!= 1 )
986 wxImage image
= bitmap
.ConvertToImage();
988 bitmap
= wxBitmap( image
);
994 void wxSearchCtrl::RecalcBitmaps()
1000 wxSize sizeText
= m_text
->GetBestSize();
1002 int bitmapHeight
= sizeText
.y
- 2 * ICON_MARGIN
;
1003 int bitmapWidth
= sizeText
.y
* 20 / 14;
1005 if ( !m_searchBitmapUser
)
1008 !m_searchBitmap
.Ok() ||
1009 m_searchBitmap
.GetHeight() != bitmapHeight
||
1010 m_searchBitmap
.GetWidth() != bitmapWidth
1013 m_searchBitmap
= RenderSearchBitmap(bitmapWidth
,bitmapHeight
,false);
1016 m_searchButton
->SetBitmapLabel(m_searchBitmap
);
1019 // else this bitmap was set by user, don't alter
1022 if ( !m_searchMenuBitmapUser
)
1025 !m_searchMenuBitmap
.Ok() ||
1026 m_searchMenuBitmap
.GetHeight() != bitmapHeight
||
1027 m_searchMenuBitmap
.GetWidth() != bitmapWidth
1030 m_searchMenuBitmap
= RenderSearchBitmap(bitmapWidth
,bitmapHeight
,true);
1033 m_searchButton
->SetBitmapLabel(m_searchMenuBitmap
);
1036 // else this bitmap was set by user, don't alter
1039 if ( !m_cancelBitmapUser
)
1042 !m_cancelBitmap
.Ok() ||
1043 m_cancelBitmap
.GetHeight() != bitmapHeight
||
1044 m_cancelBitmap
.GetWidth() != bitmapHeight
1047 m_cancelBitmap
= RenderCancelBitmap(bitmapHeight
-BORDER
,bitmapHeight
-BORDER
); // square
1048 m_cancelButton
->SetBitmapLabel(m_cancelBitmap
);
1050 // else this bitmap was set by user, don't alter
1054 void wxSearchCtrl::OnSearchButton( wxCommandEvent
& event
)
1059 void wxSearchCtrl::OnSetFocus( wxFocusEvent
& /*event*/ )
1067 void wxSearchCtrl::PopupSearchMenu()
1071 wxSize size
= GetSize();
1072 PopupMenu( m_menu
, 0, size
.y
);
1076 #endif // !USE_NATIVE_SEARCH_CONTROL
1078 #endif // wxUSE_SEARCHCTRL