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
)
227 if ( !wxTextCtrlBase::Create(parent
, id
, pos
, size
, wxSIMPLE_BORDER
| style
, validator
, name
) )
232 m_text
= new wxSearchTextCtrl(this, value
, style
& ~wxBORDER_MASK
);
234 wxSize sizeText
= m_text
->GetBestSize();
236 m_searchButton
= new wxSearchButton(this,wxEVT_COMMAND_SEARCHCTRL_SEARCH_BTN
,m_searchBitmap
);
237 m_cancelButton
= new wxSearchButton(this,wxEVT_COMMAND_SEARCHCTRL_CANCEL_BTN
,m_cancelBitmap
);
239 SetForegroundColour( m_text
->GetForegroundColour() );
240 m_searchButton
->SetForegroundColour( m_text
->GetForegroundColour() );
241 m_cancelButton
->SetForegroundColour( m_text
->GetForegroundColour() );
243 SetBackgroundColour( m_text
->GetBackgroundColour() );
244 m_searchButton
->SetBackgroundColour( m_text
->GetBackgroundColour() );
245 m_cancelButton
->SetBackgroundColour( m_text
->GetBackgroundColour() );
249 SetInitialSize(size
);
254 wxSearchCtrl::~wxSearchCtrl()
257 delete m_searchButton
;
258 delete m_cancelButton
;
263 // search control specific interfaces
264 void wxSearchCtrl::SetMenu( wxMenu
* menu
)
266 if ( menu
== m_menu
)
271 bool hadMenu
= (m_menu
!= NULL
);
275 if ( m_menu
&& !hadMenu
)
277 m_searchButton
->SetBitmapLabel(m_searchMenuBitmap
);
278 m_searchButton
->Refresh();
279 if ( !m_searchButtonVisible
)
281 // adding the menu will force the search button to be visible
282 wxRect rect
= GetRect();
283 LayoutControls(0, 0, rect
.GetWidth(), rect
.GetHeight());
286 else if ( !m_menu
&& hadMenu
)
288 m_searchButton
->SetBitmapLabel(m_searchBitmap
);
289 if ( m_searchButtonVisible
)
291 m_searchButton
->Refresh();
295 wxRect rect
= GetRect();
296 LayoutControls(0, 0, rect
.GetWidth(), rect
.GetHeight());
301 wxMenu
* wxSearchCtrl::GetMenu()
306 void wxSearchCtrl::ShowSearchButton( bool show
)
308 if ( m_searchButtonVisible
== show
)
313 m_searchButtonVisible
= show
;
314 if ( m_searchButtonVisible
)
319 wxRect rect
= GetRect();
320 LayoutControls(0, 0, rect
.GetWidth(), rect
.GetHeight());
323 bool wxSearchCtrl::IsSearchButtonVisible() const
325 return m_searchButtonVisible
;
329 void wxSearchCtrl::ShowCancelButton( bool show
)
331 if ( m_cancelButtonVisible
== show
)
336 m_cancelButtonVisible
= show
;
338 wxRect rect
= GetRect();
339 LayoutControls(0, 0, rect
.GetWidth(), rect
.GetHeight());
342 bool wxSearchCtrl::IsCancelButtonVisible() const
344 return m_cancelButtonVisible
;
348 // ----------------------------------------------------------------------------
350 // ----------------------------------------------------------------------------
352 wxSize
wxSearchCtrl::DoGetBestSize() const
354 wxSize sizeText
= m_text
->GetBestSize();
355 wxSize
sizeSearch(0,0);
356 wxSize
sizeCancel(0,0);
357 int searchMargin
= 0;
358 int cancelMargin
= 0;
359 if ( m_searchButtonVisible
|| m_menu
)
361 sizeSearch
= m_searchButton
->GetBestSize();
362 searchMargin
= MARGIN
;
364 if ( m_cancelButtonVisible
)
366 sizeCancel
= m_cancelButton
->GetBestSize();
367 cancelMargin
= MARGIN
;
370 int horizontalBorder
= 1 + ( sizeText
.y
- sizeText
.y
* 14 / 21 ) / 2;
372 // buttons are square and equal to the height of the text control
373 int height
= sizeText
.y
;
374 return wxSize(sizeSearch
.x
+ searchMargin
+ sizeText
.x
+ cancelMargin
+ sizeCancel
.x
+ 2*horizontalBorder
,
378 void wxSearchCtrl::DoMoveWindow(int x
, int y
, int width
, int height
)
380 wxSearchCtrlBase::DoMoveWindow(x
, y
, width
, height
);
382 LayoutControls(0, 0, width
, height
);
385 void wxSearchCtrl::LayoutControls(int x
, int y
, int width
, int height
)
390 wxSize sizeText
= m_text
->GetBestSize();
391 // make room for the search menu & clear button
392 int horizontalBorder
= 1 + ( sizeText
.y
- sizeText
.y
* 14 / 21 ) / 2;
393 x
+= horizontalBorder
;
395 width
-= horizontalBorder
*2;
398 wxSize
sizeSearch(0,0);
399 wxSize
sizeCancel(0,0);
400 int searchMargin
= 0;
401 int cancelMargin
= 0;
402 if ( m_searchButtonVisible
|| m_menu
)
404 sizeSearch
= m_searchButton
->GetBestSize();
405 searchMargin
= MARGIN
;
407 if ( m_cancelButtonVisible
)
409 sizeCancel
= m_cancelButton
->GetBestSize();
410 cancelMargin
= MARGIN
;
412 m_searchButton
->Show( m_searchButtonVisible
|| m_menu
);
413 m_cancelButton
->Show( m_cancelButtonVisible
);
415 if ( sizeSearch
.x
+ sizeCancel
.x
> width
)
417 sizeSearch
.x
= width
/2;
418 sizeCancel
.x
= width
/2;
422 wxCoord textWidth
= width
- sizeSearch
.x
- sizeCancel
.x
- searchMargin
- cancelMargin
;
424 // position the subcontrols inside the client area
426 m_searchButton
->SetSize(x
, y
+ ICON_OFFSET
, sizeSearch
.x
, height
);
427 m_text
->SetSize(x
+ sizeSearch
.x
+ searchMargin
, y
+ ICON_OFFSET
, textWidth
, height
);
428 m_cancelButton
->SetSize(x
+ sizeSearch
.x
+ searchMargin
+ textWidth
+ cancelMargin
,
429 y
+ ICON_OFFSET
, sizeCancel
.x
, height
);
436 wxString
wxSearchCtrl::GetValue() const
438 return m_text
->GetValue();
440 void wxSearchCtrl::SetValue(const wxString
& value
)
442 m_text
->SetValue(value
);
445 wxString
wxSearchCtrl::GetRange(long from
, long to
) const
447 return m_text
->GetRange(from
, to
);
450 int wxSearchCtrl::GetLineLength(long lineNo
) const
452 return m_text
->GetLineLength(lineNo
);
454 wxString
wxSearchCtrl::GetLineText(long lineNo
) const
456 return m_text
->GetLineText(lineNo
);
458 int wxSearchCtrl::GetNumberOfLines() const
460 return m_text
->GetNumberOfLines();
463 bool wxSearchCtrl::IsModified() const
465 return m_text
->IsModified();
467 bool wxSearchCtrl::IsEditable() const
469 return m_text
->IsEditable();
472 // more readable flag testing methods
473 bool wxSearchCtrl::IsSingleLine() const
475 return m_text
->IsSingleLine();
477 bool wxSearchCtrl::IsMultiLine() const
479 return m_text
->IsMultiLine();
482 // If the return values from and to are the same, there is no selection.
483 void wxSearchCtrl::GetSelection(long* from
, long* to
) const
485 m_text
->GetSelection(from
, to
);
488 wxString
wxSearchCtrl::GetStringSelection() const
490 return m_text
->GetStringSelection();
497 void wxSearchCtrl::Clear()
501 void wxSearchCtrl::Replace(long from
, long to
, const wxString
& value
)
503 m_text
->Replace(from
, to
, value
);
505 void wxSearchCtrl::Remove(long from
, long to
)
507 m_text
->Remove(from
, to
);
510 // load/save the controls contents from/to the file
511 bool wxSearchCtrl::LoadFile(const wxString
& file
)
513 return m_text
->LoadFile(file
);
515 bool wxSearchCtrl::SaveFile(const wxString
& file
)
517 return m_text
->SaveFile(file
);
520 // sets/clears the dirty flag
521 void wxSearchCtrl::MarkDirty()
525 void wxSearchCtrl::DiscardEdits()
527 m_text
->DiscardEdits();
530 // set the max number of characters which may be entered in a single line
532 void wxSearchCtrl::SetMaxLength(unsigned long len
)
534 m_text
->SetMaxLength(len
);
537 // writing text inserts it at the current position, appending always
538 // inserts it at the end
539 void wxSearchCtrl::WriteText(const wxString
& text
)
541 m_text
->WriteText(text
);
543 void wxSearchCtrl::AppendText(const wxString
& text
)
545 m_text
->AppendText(text
);
548 // insert the character which would have resulted from this key event,
549 // return true if anything has been inserted
550 bool wxSearchCtrl::EmulateKeyPress(const wxKeyEvent
& event
)
552 return m_text
->EmulateKeyPress(event
);
555 // text control under some platforms supports the text styles: these
556 // methods allow to apply the given text style to the given selection or to
557 // set/get the style which will be used for all appended text
558 bool wxSearchCtrl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
560 return m_text
->SetStyle(start
, end
, style
);
562 bool wxSearchCtrl::GetStyle(long position
, wxTextAttr
& style
)
564 return m_text
->GetStyle(position
, style
);
566 bool wxSearchCtrl::SetDefaultStyle(const wxTextAttr
& style
)
568 return m_text
->SetDefaultStyle(style
);
570 const wxTextAttr
& wxSearchCtrl::GetDefaultStyle() const
572 return m_text
->GetDefaultStyle();
575 // translate between the position (which is just an index in the text ctrl
576 // considering all its contents as a single strings) and (x, y) coordinates
577 // which represent column and line.
578 long wxSearchCtrl::XYToPosition(long x
, long y
) const
580 return m_text
->XYToPosition(x
, y
);
582 bool wxSearchCtrl::PositionToXY(long pos
, long *x
, long *y
) const
584 return m_text
->PositionToXY(pos
, x
, y
);
587 void wxSearchCtrl::ShowPosition(long pos
)
589 m_text
->ShowPosition(pos
);
592 // find the character at position given in pixels
594 // NB: pt is in device coords (not adjusted for the client area origin nor
596 wxTextCtrlHitTestResult
wxSearchCtrl::HitTest(const wxPoint
& pt
, long *pos
) const
598 return m_text
->HitTest(pt
, pos
);
600 wxTextCtrlHitTestResult
wxSearchCtrl::HitTest(const wxPoint
& pt
,
602 wxTextCoord
*row
) const
604 return m_text
->HitTest(pt
, col
, row
);
607 // Clipboard operations
608 void wxSearchCtrl::Copy()
612 void wxSearchCtrl::Cut()
616 void wxSearchCtrl::Paste()
621 bool wxSearchCtrl::CanCopy() const
623 return m_text
->CanCopy();
625 bool wxSearchCtrl::CanCut() const
627 return m_text
->CanCut();
629 bool wxSearchCtrl::CanPaste() const
631 return m_text
->CanPaste();
635 void wxSearchCtrl::Undo()
639 void wxSearchCtrl::Redo()
644 bool wxSearchCtrl::CanUndo() const
646 return m_text
->CanUndo();
648 bool wxSearchCtrl::CanRedo() const
650 return m_text
->CanRedo();
654 void wxSearchCtrl::SetInsertionPoint(long pos
)
656 m_text
->SetInsertionPoint(pos
);
658 void wxSearchCtrl::SetInsertionPointEnd()
660 m_text
->SetInsertionPointEnd();
662 long wxSearchCtrl::GetInsertionPoint() const
664 return m_text
->GetInsertionPoint();
666 wxTextPos
wxSearchCtrl::GetLastPosition() const
668 return m_text
->GetLastPosition();
671 void wxSearchCtrl::SetSelection(long from
, long to
)
673 m_text
->SetSelection(from
, to
);
675 void wxSearchCtrl::SelectAll()
680 void wxSearchCtrl::SetEditable(bool editable
)
682 m_text
->SetEditable(editable
);
685 bool wxSearchCtrl::SetFont(const wxFont
& font
)
687 bool result
= wxSearchCtrlBase::SetFont(font
);
688 if ( result
&& m_text
)
690 result
= m_text
->SetFont(font
);
696 // search control generic only
697 void wxSearchCtrl::SetSearchBitmap( const wxBitmap
& bitmap
)
699 m_searchBitmap
= bitmap
;
700 m_searchBitmapUser
= bitmap
.Ok();
701 if ( m_searchBitmapUser
)
703 if ( m_searchButton
&& !m_menu
)
705 m_searchButton
->SetBitmapLabel( m_searchBitmap
);
710 // the user bitmap was just cleared, generate one
715 void wxSearchCtrl::SetSearchMenuBitmap( const wxBitmap
& bitmap
)
717 m_searchMenuBitmap
= bitmap
;
718 m_searchMenuBitmapUser
= bitmap
.Ok();
719 if ( m_searchMenuBitmapUser
)
721 if ( m_searchButton
&& m_menu
)
723 m_searchButton
->SetBitmapLabel( m_searchMenuBitmap
);
728 // the user bitmap was just cleared, generate one
733 void wxSearchCtrl::SetCancelBitmap( const wxBitmap
& bitmap
)
735 m_cancelBitmap
= bitmap
;
736 m_cancelBitmapUser
= bitmap
.Ok();
737 if ( m_cancelBitmapUser
)
739 if ( m_cancelButton
)
741 m_cancelButton
->SetBitmapLabel( m_cancelBitmap
);
746 // the user bitmap was just cleared, generate one
753 // override streambuf method
754 #if wxHAS_TEXT_WINDOW_STREAM
756 #endif // wxHAS_TEXT_WINDOW_STREAM
758 // stream-like insertion operators: these are always available, whether we
759 // were, or not, compiled with streambuf support
760 wxTextCtrl
& operator<<(const wxString
& s
);
761 wxTextCtrl
& operator<<(int i
);
762 wxTextCtrl
& operator<<(long i
);
763 wxTextCtrl
& operator<<(float f
);
764 wxTextCtrl
& operator<<(double d
);
765 wxTextCtrl
& operator<<(const wxChar c
);
768 void wxSearchCtrl::DoSetValue(const wxString
& value
, int flags
)
770 m_text
->ChangeValue( value
);
771 if ( flags
& SetValue_SendEvent
)
772 SendTextUpdatedEvent();
775 // do the window-specific processing after processing the update event
776 void wxSearchCtrl::DoUpdateWindowUI(wxUpdateUIEvent
& event
)
778 wxSearchCtrlBase::DoUpdateWindowUI(event
);
781 bool wxSearchCtrl::ShouldInheritColours() const
786 // icons are rendered at 3-8 times larger than necessary and downscaled for
788 static int GetMultiplier()
791 // speed up bitmap generation by using a small bitmap
794 int depth
= ::wxDisplayDepth();
804 wxBitmap
wxSearchCtrl::RenderSearchBitmap( int x
, int y
, bool renderDrop
)
806 wxColour bg
= GetBackgroundColour();
807 wxColour fg
= GetForegroundColour();
809 //===============================================================================
810 // begin drawing code
811 //===============================================================================
814 // force width:height ratio
826 // glass 11x11, top left corner
827 // handle (9,9)-(13,13)
828 // drop (13,16)-(19,6)-(16,9)
830 int multiplier
= GetMultiplier();
831 int penWidth
= multiplier
* 2;
833 penWidth
= penWidth
* x
/ 20;
835 wxBitmap
bitmap( multiplier
*x
, multiplier
*y
);
837 mem
.SelectObject(bitmap
);
840 mem
.SetBrush( wxBrush(bg
) );
841 mem
.SetPen( wxPen(bg
) );
842 mem
.DrawRectangle(0,0,bitmap
.GetWidth(),bitmap
.GetHeight());
845 mem
.SetBrush( wxBrush(fg
) );
846 mem
.SetPen( wxPen(fg
) );
847 int glassBase
= 5 * x
/ 20;
848 int glassFactor
= 2*glassBase
+ 1;
849 int radius
= multiplier
*glassFactor
/2;
850 mem
.DrawCircle(radius
,radius
,radius
);
851 mem
.SetBrush( wxBrush(bg
) );
852 mem
.SetPen( wxPen(bg
) );
853 mem
.DrawCircle(radius
,radius
,radius
-penWidth
);
856 int lineStart
= radius
+ (radius
-penWidth
/2) * 707 / 1000; // 707 / 1000 = 0.707 = 1/sqrt(2);
858 mem
.SetPen( wxPen(fg
) );
859 mem
.SetBrush( wxBrush(fg
) );
860 int handleCornerShift
= penWidth
* 707 / 1000 / 2; // 707 / 1000 = 0.707 = 1/sqrt(2);
861 handleCornerShift
= WXMAX( handleCornerShift
, 1 );
862 int handleBase
= 4 * x
/ 20;
863 int handleLength
= 2*handleBase
+1;
864 wxPoint handlePolygon
[] =
866 wxPoint(-handleCornerShift
,+handleCornerShift
),
867 wxPoint(+handleCornerShift
,-handleCornerShift
),
868 wxPoint(multiplier
*handleLength
/2+handleCornerShift
,multiplier
*handleLength
/2-handleCornerShift
),
869 wxPoint(multiplier
*handleLength
/2-handleCornerShift
,multiplier
*handleLength
/2+handleCornerShift
),
871 mem
.DrawPolygon(WXSIZEOF(handlePolygon
),handlePolygon
,lineStart
,lineStart
);
873 // draw drop triangle
874 int triangleX
= 13 * x
/ 20;
875 int triangleY
= 5 * x
/ 20;
876 int triangleBase
= 3 * x
/ 20;
877 int triangleFactor
= triangleBase
*2+1;
880 wxPoint dropPolygon
[] =
882 wxPoint(multiplier
*0,multiplier
*0), // triangle left
883 wxPoint(multiplier
*triangleFactor
-1,multiplier
*0), // triangle right
884 wxPoint(multiplier
*triangleFactor
/2,multiplier
*triangleFactor
/2), // triangle bottom
886 mem
.DrawPolygon(WXSIZEOF(dropPolygon
),dropPolygon
,multiplier
*triangleX
,multiplier
*triangleY
);
889 //===============================================================================
891 //===============================================================================
893 if ( multiplier
!= 1 )
895 wxImage image
= bitmap
.ConvertToImage();
897 bitmap
= wxBitmap( image
);
903 wxBitmap
wxSearchCtrl::RenderCancelBitmap( int x
, int y
)
905 wxColour bg
= GetBackgroundColour();
906 wxColour fg
= GetForegroundColour();
908 //===============================================================================
909 // begin drawing code
910 //===============================================================================
927 // cross line starts (4,4)-(10,10)
928 // drop (13,16)-(19,6)-(16,9)
930 int multiplier
= GetMultiplier();
932 int penWidth
= multiplier
* x
/ 14;
934 wxBitmap
bitmap( multiplier
*x
, multiplier
*y
);
936 mem
.SelectObject(bitmap
);
939 mem
.SetBrush( wxBrush(bg
) );
940 mem
.SetPen( wxPen(bg
) );
941 mem
.DrawRectangle(0,0,bitmap
.GetWidth(),bitmap
.GetHeight());
944 mem
.SetBrush( wxBrush(fg
) );
945 mem
.SetPen( wxPen(fg
) );
946 int radius
= multiplier
*x
/2;
947 mem
.DrawCircle(radius
,radius
,radius
);
950 int lineStartBase
= 4 * x
/ 14;
951 int lineLength
= x
- 2*lineStartBase
;
953 mem
.SetPen( wxPen(bg
) );
954 mem
.SetBrush( wxBrush(bg
) );
955 int handleCornerShift
= penWidth
/2;
956 handleCornerShift
= WXMAX( handleCornerShift
, 1 );
957 wxPoint handlePolygon
[] =
959 wxPoint(-handleCornerShift
,+handleCornerShift
),
960 wxPoint(+handleCornerShift
,-handleCornerShift
),
961 wxPoint(multiplier
*lineLength
+handleCornerShift
,multiplier
*lineLength
-handleCornerShift
),
962 wxPoint(multiplier
*lineLength
-handleCornerShift
,multiplier
*lineLength
+handleCornerShift
),
964 mem
.DrawPolygon(WXSIZEOF(handlePolygon
),handlePolygon
,multiplier
*lineStartBase
,multiplier
*lineStartBase
);
965 wxPoint handlePolygon2
[] =
967 wxPoint(+handleCornerShift
,+handleCornerShift
),
968 wxPoint(-handleCornerShift
,-handleCornerShift
),
969 wxPoint(multiplier
*lineLength
-handleCornerShift
,-multiplier
*lineLength
-handleCornerShift
),
970 wxPoint(multiplier
*lineLength
+handleCornerShift
,-multiplier
*lineLength
+handleCornerShift
),
972 mem
.DrawPolygon(WXSIZEOF(handlePolygon2
),handlePolygon2
,multiplier
*lineStartBase
,multiplier
*(x
-lineStartBase
));
974 //===============================================================================
976 //===============================================================================
978 if ( multiplier
!= 1 )
980 wxImage image
= bitmap
.ConvertToImage();
982 bitmap
= wxBitmap( image
);
988 void wxSearchCtrl::RecalcBitmaps()
994 wxSize sizeText
= m_text
->GetBestSize();
996 int bitmapHeight
= sizeText
.y
- 2 * ICON_MARGIN
;
997 int bitmapWidth
= sizeText
.y
* 20 / 14;
999 if ( !m_searchBitmapUser
)
1002 !m_searchBitmap
.Ok() ||
1003 m_searchBitmap
.GetHeight() != bitmapHeight
||
1004 m_searchBitmap
.GetWidth() != bitmapWidth
1007 m_searchBitmap
= RenderSearchBitmap(bitmapWidth
,bitmapHeight
,false);
1010 m_searchButton
->SetBitmapLabel(m_searchBitmap
);
1013 // else this bitmap was set by user, don't alter
1016 if ( !m_searchMenuBitmapUser
)
1019 !m_searchMenuBitmap
.Ok() ||
1020 m_searchMenuBitmap
.GetHeight() != bitmapHeight
||
1021 m_searchMenuBitmap
.GetWidth() != bitmapWidth
1024 m_searchMenuBitmap
= RenderSearchBitmap(bitmapWidth
,bitmapHeight
,true);
1027 m_searchButton
->SetBitmapLabel(m_searchMenuBitmap
);
1030 // else this bitmap was set by user, don't alter
1033 if ( !m_cancelBitmapUser
)
1036 !m_cancelBitmap
.Ok() ||
1037 m_cancelBitmap
.GetHeight() != bitmapHeight
||
1038 m_cancelBitmap
.GetWidth() != bitmapHeight
1041 m_cancelBitmap
= RenderCancelBitmap(bitmapHeight
-BORDER
,bitmapHeight
-BORDER
); // square
1042 m_cancelButton
->SetBitmapLabel(m_cancelBitmap
);
1044 // else this bitmap was set by user, don't alter
1048 void wxSearchCtrl::OnSearchButton( wxCommandEvent
& event
)
1053 void wxSearchCtrl::OnSetFocus( wxFocusEvent
& /*event*/ )
1061 void wxSearchCtrl::OnSize( wxSizeEvent
& event
)
1064 GetSize(&width
, &height
);
1065 LayoutControls(0, 0, width
, height
);
1068 void wxSearchCtrl::PopupSearchMenu()
1072 wxSize size
= GetSize();
1073 PopupMenu( m_menu
, 0, size
.y
);
1077 #endif // !wxUSE_NATIVE_SEARCH_CONTROL
1079 #endif // wxUSE_SEARCHCTRL