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(wxID_ANY
, wxSearchCtrl::OnSearchButton
)
169 EVT_SET_FOCUS(wxSearchCtrl::OnSetFocus
)
172 IMPLEMENT_DYNAMIC_CLASS(wxSearchCtrl
, wxSearchCtrlBase
)
174 // ============================================================================
176 // ============================================================================
178 // ----------------------------------------------------------------------------
179 // wxSearchCtrl creation
180 // ----------------------------------------------------------------------------
185 wxSearchCtrl::wxSearchCtrl()
190 wxSearchCtrl::wxSearchCtrl(wxWindow
*parent
, wxWindowID id
,
191 const wxString
& value
,
195 const wxValidator
& validator
,
196 const wxString
& name
)
200 Create(parent
, id
, value
, pos
, size
, style
, validator
, name
);
203 void wxSearchCtrl::Init()
210 m_searchButtonVisible
= true;
211 m_cancelButtonVisible
= false;
213 m_searchMenuBitmapUser
= false;
214 m_searchBitmapUser
= false;
215 m_cancelBitmapUser
= false;
218 bool wxSearchCtrl::Create(wxWindow
*parent
, wxWindowID id
,
219 const wxString
& value
,
223 const wxValidator
& validator
,
224 const wxString
& name
)
226 if ( !wxTextCtrlBase::Create(parent
, id
, pos
, size
, wxSIMPLE_BORDER
| style
, validator
, name
) )
231 m_text
= new wxSearchTextCtrl(this, value
, style
& ~wxBORDER_MASK
);
233 wxSize sizeText
= m_text
->GetBestSize();
235 m_searchButton
= new wxSearchButton(this,wxEVT_COMMAND_SEARCHCTRL_SEARCH_BTN
,m_searchBitmap
);
236 m_cancelButton
= new wxSearchButton(this,wxEVT_COMMAND_SEARCHCTRL_CANCEL_BTN
,m_cancelBitmap
);
238 SetForegroundColour( m_text
->GetForegroundColour() );
239 m_searchButton
->SetForegroundColour( m_text
->GetForegroundColour() );
240 m_cancelButton
->SetForegroundColour( m_text
->GetForegroundColour() );
242 SetBackgroundColour( m_text
->GetBackgroundColour() );
243 m_searchButton
->SetBackgroundColour( m_text
->GetBackgroundColour() );
244 m_cancelButton
->SetBackgroundColour( m_text
->GetBackgroundColour() );
248 SetInitialSize(size
);
253 wxSearchCtrl::~wxSearchCtrl()
256 delete m_searchButton
;
257 delete m_cancelButton
;
262 // search control specific interfaces
263 void wxSearchCtrl::SetMenu( wxMenu
* menu
)
265 if ( menu
== m_menu
)
270 bool hadMenu
= (m_menu
!= NULL
);
274 if ( m_menu
&& !hadMenu
)
276 m_searchButton
->SetBitmapLabel(m_searchMenuBitmap
);
277 m_searchButton
->Refresh();
278 if ( !m_searchButtonVisible
)
280 // adding the menu will force the search button to be visible
281 wxRect rect
= GetRect();
282 LayoutControls(0, 0, rect
.GetWidth(), rect
.GetHeight());
285 else if ( !m_menu
&& hadMenu
)
287 m_searchButton
->SetBitmapLabel(m_searchBitmap
);
288 if ( m_searchButtonVisible
)
290 m_searchButton
->Refresh();
294 wxRect rect
= GetRect();
295 LayoutControls(0, 0, rect
.GetWidth(), rect
.GetHeight());
300 wxMenu
* wxSearchCtrl::GetMenu()
305 void wxSearchCtrl::ShowSearchButton( bool show
)
307 if ( m_searchButtonVisible
== show
)
312 m_searchButtonVisible
= show
;
313 if ( m_searchButtonVisible
)
318 wxRect rect
= GetRect();
319 LayoutControls(0, 0, rect
.GetWidth(), rect
.GetHeight());
322 bool wxSearchCtrl::IsSearchButtonVisible() const
324 return m_searchButtonVisible
;
328 void wxSearchCtrl::ShowCancelButton( bool show
)
330 if ( m_cancelButtonVisible
== show
)
335 m_cancelButtonVisible
= show
;
337 wxRect rect
= GetRect();
338 LayoutControls(0, 0, rect
.GetWidth(), rect
.GetHeight());
341 bool wxSearchCtrl::IsCancelButtonVisible() const
343 return m_cancelButtonVisible
;
347 // ----------------------------------------------------------------------------
349 // ----------------------------------------------------------------------------
351 wxSize
wxSearchCtrl::DoGetBestSize() const
353 wxSize sizeText
= m_text
->GetBestSize();
354 wxSize
sizeSearch(0,0);
355 wxSize
sizeCancel(0,0);
356 int searchMargin
= 0;
357 int cancelMargin
= 0;
358 if ( m_searchButtonVisible
|| m_menu
)
360 sizeSearch
= m_searchButton
->GetBestSize();
361 searchMargin
= MARGIN
;
363 if ( m_cancelButtonVisible
)
365 sizeCancel
= m_cancelButton
->GetBestSize();
366 cancelMargin
= MARGIN
;
369 int horizontalBorder
= 1 + ( sizeText
.y
- sizeText
.y
* 14 / 21 ) / 2;
371 // buttons are square and equal to the height of the text control
372 int height
= sizeText
.y
;
373 return wxSize(sizeSearch
.x
+ searchMargin
+ sizeText
.x
+ cancelMargin
+ sizeCancel
.x
+ 2*horizontalBorder
,
377 void wxSearchCtrl::DoMoveWindow(int x
, int y
, int width
, int height
)
379 wxSearchCtrlBase::DoMoveWindow(x
, y
, width
, height
);
381 LayoutControls(0, 0, width
, height
);
384 void wxSearchCtrl::LayoutControls(int x
, int y
, int width
, int height
)
386 wxSize sizeText
= m_text
->GetBestSize();
387 // make room for the search menu & clear button
388 int horizontalBorder
= 1 + ( sizeText
.y
- sizeText
.y
* 14 / 21 ) / 2;
389 x
+= horizontalBorder
;
391 width
-= horizontalBorder
*2;
394 wxSize
sizeSearch(0,0);
395 wxSize
sizeCancel(0,0);
396 int searchMargin
= 0;
397 int cancelMargin
= 0;
398 if ( m_searchButtonVisible
|| m_menu
)
400 sizeSearch
= m_searchButton
->GetBestSize();
401 searchMargin
= MARGIN
;
403 if ( m_cancelButtonVisible
)
405 sizeCancel
= m_cancelButton
->GetBestSize();
406 cancelMargin
= MARGIN
;
408 m_searchButton
->Show( m_searchButtonVisible
|| m_menu
);
409 m_cancelButton
->Show( m_cancelButtonVisible
);
411 if ( sizeSearch
.x
+ sizeCancel
.x
> width
)
413 sizeSearch
.x
= width
/2;
414 sizeCancel
.x
= width
/2;
418 wxCoord textWidth
= width
- sizeSearch
.x
- sizeCancel
.x
- searchMargin
- cancelMargin
;
420 // position the subcontrols inside the client area
422 m_searchButton
->SetSize(x
, y
+ ICON_OFFSET
, sizeSearch
.x
, height
);
423 m_text
->SetSize(x
+ sizeSearch
.x
+ searchMargin
, y
+ ICON_OFFSET
, textWidth
, height
);
424 m_cancelButton
->SetSize(x
+ sizeSearch
.x
+ searchMargin
+ textWidth
+ cancelMargin
,
425 y
+ ICON_OFFSET
, sizeCancel
.x
, height
);
432 wxString
wxSearchCtrl::GetValue() const
434 return m_text
->GetValue();
436 void wxSearchCtrl::SetValue(const wxString
& value
)
438 m_text
->SetValue(value
);
441 wxString
wxSearchCtrl::GetRange(long from
, long to
) const
443 return m_text
->GetRange(from
, to
);
446 int wxSearchCtrl::GetLineLength(long lineNo
) const
448 return m_text
->GetLineLength(lineNo
);
450 wxString
wxSearchCtrl::GetLineText(long lineNo
) const
452 return m_text
->GetLineText(lineNo
);
454 int wxSearchCtrl::GetNumberOfLines() const
456 return m_text
->GetNumberOfLines();
459 bool wxSearchCtrl::IsModified() const
461 return m_text
->IsModified();
463 bool wxSearchCtrl::IsEditable() const
465 return m_text
->IsEditable();
468 // more readable flag testing methods
469 bool wxSearchCtrl::IsSingleLine() const
471 return m_text
->IsSingleLine();
473 bool wxSearchCtrl::IsMultiLine() const
475 return m_text
->IsMultiLine();
478 // If the return values from and to are the same, there is no selection.
479 void wxSearchCtrl::GetSelection(long* from
, long* to
) const
481 m_text
->GetSelection(from
, to
);
484 wxString
wxSearchCtrl::GetStringSelection() const
486 return m_text
->GetStringSelection();
493 void wxSearchCtrl::Clear()
497 void wxSearchCtrl::Replace(long from
, long to
, const wxString
& value
)
499 m_text
->Replace(from
, to
, value
);
501 void wxSearchCtrl::Remove(long from
, long to
)
503 m_text
->Remove(from
, to
);
506 // load/save the controls contents from/to the file
507 bool wxSearchCtrl::LoadFile(const wxString
& file
)
509 return m_text
->LoadFile(file
);
511 bool wxSearchCtrl::SaveFile(const wxString
& file
)
513 return m_text
->SaveFile(file
);
516 // sets/clears the dirty flag
517 void wxSearchCtrl::MarkDirty()
521 void wxSearchCtrl::DiscardEdits()
523 m_text
->DiscardEdits();
526 // set the max number of characters which may be entered in a single line
528 void wxSearchCtrl::SetMaxLength(unsigned long len
)
530 m_text
->SetMaxLength(len
);
533 // writing text inserts it at the current position, appending always
534 // inserts it at the end
535 void wxSearchCtrl::WriteText(const wxString
& text
)
537 m_text
->WriteText(text
);
539 void wxSearchCtrl::AppendText(const wxString
& text
)
541 m_text
->AppendText(text
);
544 // insert the character which would have resulted from this key event,
545 // return true if anything has been inserted
546 bool wxSearchCtrl::EmulateKeyPress(const wxKeyEvent
& event
)
548 return m_text
->EmulateKeyPress(event
);
551 // text control under some platforms supports the text styles: these
552 // methods allow to apply the given text style to the given selection or to
553 // set/get the style which will be used for all appended text
554 bool wxSearchCtrl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
556 return m_text
->SetStyle(start
, end
, style
);
558 bool wxSearchCtrl::GetStyle(long position
, wxTextAttr
& style
)
560 return m_text
->GetStyle(position
, style
);
562 bool wxSearchCtrl::SetDefaultStyle(const wxTextAttr
& style
)
564 return m_text
->SetDefaultStyle(style
);
566 const wxTextAttr
& wxSearchCtrl::GetDefaultStyle() const
568 return m_text
->GetDefaultStyle();
571 // translate between the position (which is just an index in the text ctrl
572 // considering all its contents as a single strings) and (x, y) coordinates
573 // which represent column and line.
574 long wxSearchCtrl::XYToPosition(long x
, long y
) const
576 return m_text
->XYToPosition(x
, y
);
578 bool wxSearchCtrl::PositionToXY(long pos
, long *x
, long *y
) const
580 return m_text
->PositionToXY(pos
, x
, y
);
583 void wxSearchCtrl::ShowPosition(long pos
)
585 m_text
->ShowPosition(pos
);
588 // find the character at position given in pixels
590 // NB: pt is in device coords (not adjusted for the client area origin nor
592 wxTextCtrlHitTestResult
wxSearchCtrl::HitTest(const wxPoint
& pt
, long *pos
) const
594 return m_text
->HitTest(pt
, pos
);
596 wxTextCtrlHitTestResult
wxSearchCtrl::HitTest(const wxPoint
& pt
,
598 wxTextCoord
*row
) const
600 return m_text
->HitTest(pt
, col
, row
);
603 // Clipboard operations
604 void wxSearchCtrl::Copy()
608 void wxSearchCtrl::Cut()
612 void wxSearchCtrl::Paste()
617 bool wxSearchCtrl::CanCopy() const
619 return m_text
->CanCopy();
621 bool wxSearchCtrl::CanCut() const
623 return m_text
->CanCut();
625 bool wxSearchCtrl::CanPaste() const
627 return m_text
->CanPaste();
631 void wxSearchCtrl::Undo()
635 void wxSearchCtrl::Redo()
640 bool wxSearchCtrl::CanUndo() const
642 return m_text
->CanUndo();
644 bool wxSearchCtrl::CanRedo() const
646 return m_text
->CanRedo();
650 void wxSearchCtrl::SetInsertionPoint(long pos
)
652 m_text
->SetInsertionPoint(pos
);
654 void wxSearchCtrl::SetInsertionPointEnd()
656 m_text
->SetInsertionPointEnd();
658 long wxSearchCtrl::GetInsertionPoint() const
660 return m_text
->GetInsertionPoint();
662 wxTextPos
wxSearchCtrl::GetLastPosition() const
664 return m_text
->GetLastPosition();
667 void wxSearchCtrl::SetSelection(long from
, long to
)
669 m_text
->SetSelection(from
, to
);
671 void wxSearchCtrl::SelectAll()
676 void wxSearchCtrl::SetEditable(bool editable
)
678 m_text
->SetEditable(editable
);
681 bool wxSearchCtrl::SetFont(const wxFont
& font
)
683 bool result
= wxSearchCtrlBase::SetFont(font
);
684 if ( result
&& m_text
)
686 result
= m_text
->SetFont(font
);
692 // search control generic only
693 void wxSearchCtrl::SetSearchBitmap( const wxBitmap
& bitmap
)
695 m_searchBitmap
= bitmap
;
696 m_searchBitmapUser
= bitmap
.Ok();
697 if ( m_searchBitmapUser
)
699 if ( m_searchButton
&& !m_menu
)
701 m_searchButton
->SetBitmapLabel( m_searchBitmap
);
706 // the user bitmap was just cleared, generate one
711 void wxSearchCtrl::SetSearchMenuBitmap( const wxBitmap
& bitmap
)
713 m_searchMenuBitmap
= bitmap
;
714 m_searchMenuBitmapUser
= bitmap
.Ok();
715 if ( m_searchMenuBitmapUser
)
717 if ( m_searchButton
&& m_menu
)
719 m_searchButton
->SetBitmapLabel( m_searchMenuBitmap
);
724 // the user bitmap was just cleared, generate one
729 void wxSearchCtrl::SetCancelBitmap( const wxBitmap
& bitmap
)
731 m_cancelBitmap
= bitmap
;
732 m_cancelBitmapUser
= bitmap
.Ok();
733 if ( m_cancelBitmapUser
)
735 if ( m_cancelButton
)
737 m_cancelButton
->SetBitmapLabel( m_cancelBitmap
);
742 // the user bitmap was just cleared, generate one
749 // override streambuf method
750 #if wxHAS_TEXT_WINDOW_STREAM
752 #endif // wxHAS_TEXT_WINDOW_STREAM
754 // stream-like insertion operators: these are always available, whether we
755 // were, or not, compiled with streambuf support
756 wxTextCtrl
& operator<<(const wxString
& s
);
757 wxTextCtrl
& operator<<(int i
);
758 wxTextCtrl
& operator<<(long i
);
759 wxTextCtrl
& operator<<(float f
);
760 wxTextCtrl
& operator<<(double d
);
761 wxTextCtrl
& operator<<(const wxChar c
);
764 void wxSearchCtrl::DoSetValue(const wxString
& value
, int flags
)
766 m_text
->ChangeValue( value
);
767 if ( flags
& SetValue_SendEvent
)
768 SendTextUpdatedEvent();
771 // do the window-specific processing after processing the update event
772 void wxSearchCtrl::DoUpdateWindowUI(wxUpdateUIEvent
& event
)
774 wxSearchCtrlBase::DoUpdateWindowUI(event
);
777 bool wxSearchCtrl::ShouldInheritColours() const
782 // icons are rendered at 3-8 times larger than necessary and downscaled for
784 static int GetMultiplier()
787 // speed up bitmap generation by using a small bitmap
790 int depth
= ::wxDisplayDepth();
800 wxBitmap
wxSearchCtrl::RenderSearchBitmap( int x
, int y
, bool renderDrop
)
802 wxColour bg
= GetBackgroundColour();
803 wxColour fg
= GetForegroundColour();
805 //===============================================================================
806 // begin drawing code
807 //===============================================================================
810 // force width:height ratio
822 // glass 11x11, top left corner
823 // handle (9,9)-(13,13)
824 // drop (13,16)-(19,6)-(16,9)
826 int multiplier
= GetMultiplier();
827 int penWidth
= multiplier
* 2;
829 penWidth
= penWidth
* x
/ 20;
831 wxBitmap
bitmap( multiplier
*x
, multiplier
*y
);
833 mem
.SelectObject(bitmap
);
836 mem
.SetBrush( wxBrush(bg
) );
837 mem
.SetPen( wxPen(bg
) );
838 mem
.DrawRectangle(0,0,bitmap
.GetWidth(),bitmap
.GetHeight());
841 mem
.SetBrush( wxBrush(fg
) );
842 mem
.SetPen( wxPen(fg
) );
843 int glassBase
= 5 * x
/ 20;
844 int glassFactor
= 2*glassBase
+ 1;
845 int radius
= multiplier
*glassFactor
/2;
846 mem
.DrawCircle(radius
,radius
,radius
);
847 mem
.SetBrush( wxBrush(bg
) );
848 mem
.SetPen( wxPen(bg
) );
849 mem
.DrawCircle(radius
,radius
,radius
-penWidth
);
852 int lineStart
= radius
+ (radius
-penWidth
/2) * 707 / 1000; // 707 / 1000 = 0.707 = 1/sqrt(2);
854 mem
.SetPen( wxPen(fg
) );
855 mem
.SetBrush( wxBrush(fg
) );
856 int handleCornerShift
= penWidth
* 707 / 1000 / 2; // 707 / 1000 = 0.707 = 1/sqrt(2);
857 handleCornerShift
= WXMAX( handleCornerShift
, 1 );
858 int handleBase
= 4 * x
/ 20;
859 int handleLength
= 2*handleBase
+1;
860 wxPoint handlePolygon
[] =
862 wxPoint(-handleCornerShift
,+handleCornerShift
),
863 wxPoint(+handleCornerShift
,-handleCornerShift
),
864 wxPoint(multiplier
*handleLength
/2+handleCornerShift
,multiplier
*handleLength
/2-handleCornerShift
),
865 wxPoint(multiplier
*handleLength
/2-handleCornerShift
,multiplier
*handleLength
/2+handleCornerShift
),
867 mem
.DrawPolygon(WXSIZEOF(handlePolygon
),handlePolygon
,lineStart
,lineStart
);
869 // draw drop triangle
870 int triangleX
= 13 * x
/ 20;
871 int triangleY
= 5 * x
/ 20;
872 int triangleBase
= 3 * x
/ 20;
873 int triangleFactor
= triangleBase
*2+1;
876 wxPoint dropPolygon
[] =
878 wxPoint(multiplier
*0,multiplier
*0), // triangle left
879 wxPoint(multiplier
*triangleFactor
-1,multiplier
*0), // triangle right
880 wxPoint(multiplier
*triangleFactor
/2,multiplier
*triangleFactor
/2), // triangle bottom
882 mem
.DrawPolygon(WXSIZEOF(dropPolygon
),dropPolygon
,multiplier
*triangleX
,multiplier
*triangleY
);
885 //===============================================================================
887 //===============================================================================
889 if ( multiplier
!= 1 )
891 wxImage image
= bitmap
.ConvertToImage();
893 bitmap
= wxBitmap( image
);
899 wxBitmap
wxSearchCtrl::RenderCancelBitmap( int x
, int y
)
901 wxColour bg
= GetBackgroundColour();
902 wxColour fg
= GetForegroundColour();
904 //===============================================================================
905 // begin drawing code
906 //===============================================================================
923 // cross line starts (4,4)-(10,10)
924 // drop (13,16)-(19,6)-(16,9)
926 int multiplier
= GetMultiplier();
928 int penWidth
= multiplier
* x
/ 14;
930 wxBitmap
bitmap( multiplier
*x
, multiplier
*y
);
932 mem
.SelectObject(bitmap
);
935 mem
.SetBrush( wxBrush(bg
) );
936 mem
.SetPen( wxPen(bg
) );
937 mem
.DrawRectangle(0,0,bitmap
.GetWidth(),bitmap
.GetHeight());
940 mem
.SetBrush( wxBrush(fg
) );
941 mem
.SetPen( wxPen(fg
) );
942 int radius
= multiplier
*x
/2;
943 mem
.DrawCircle(radius
,radius
,radius
);
946 int lineStartBase
= 4 * x
/ 14;
947 int lineLength
= x
- 2*lineStartBase
;
949 mem
.SetPen( wxPen(bg
) );
950 mem
.SetBrush( wxBrush(bg
) );
951 int handleCornerShift
= penWidth
/2;
952 handleCornerShift
= WXMAX( handleCornerShift
, 1 );
953 wxPoint handlePolygon
[] =
955 wxPoint(-handleCornerShift
,+handleCornerShift
),
956 wxPoint(+handleCornerShift
,-handleCornerShift
),
957 wxPoint(multiplier
*lineLength
+handleCornerShift
,multiplier
*lineLength
-handleCornerShift
),
958 wxPoint(multiplier
*lineLength
-handleCornerShift
,multiplier
*lineLength
+handleCornerShift
),
960 mem
.DrawPolygon(WXSIZEOF(handlePolygon
),handlePolygon
,multiplier
*lineStartBase
,multiplier
*lineStartBase
);
961 wxPoint handlePolygon2
[] =
963 wxPoint(+handleCornerShift
,+handleCornerShift
),
964 wxPoint(-handleCornerShift
,-handleCornerShift
),
965 wxPoint(multiplier
*lineLength
-handleCornerShift
,-multiplier
*lineLength
-handleCornerShift
),
966 wxPoint(multiplier
*lineLength
+handleCornerShift
,-multiplier
*lineLength
+handleCornerShift
),
968 mem
.DrawPolygon(WXSIZEOF(handlePolygon2
),handlePolygon2
,multiplier
*lineStartBase
,multiplier
*(x
-lineStartBase
));
970 //===============================================================================
972 //===============================================================================
974 if ( multiplier
!= 1 )
976 wxImage image
= bitmap
.ConvertToImage();
978 bitmap
= wxBitmap( image
);
984 void wxSearchCtrl::RecalcBitmaps()
990 wxSize sizeText
= m_text
->GetBestSize();
992 int bitmapHeight
= sizeText
.y
- 2 * ICON_MARGIN
;
993 int bitmapWidth
= sizeText
.y
* 20 / 14;
995 if ( !m_searchBitmapUser
)
998 !m_searchBitmap
.Ok() ||
999 m_searchBitmap
.GetHeight() != bitmapHeight
||
1000 m_searchBitmap
.GetWidth() != bitmapWidth
1003 m_searchBitmap
= RenderSearchBitmap(bitmapWidth
,bitmapHeight
,false);
1006 m_searchButton
->SetBitmapLabel(m_searchBitmap
);
1009 // else this bitmap was set by user, don't alter
1012 if ( !m_searchMenuBitmapUser
)
1015 !m_searchMenuBitmap
.Ok() ||
1016 m_searchMenuBitmap
.GetHeight() != bitmapHeight
||
1017 m_searchMenuBitmap
.GetWidth() != bitmapWidth
1020 m_searchMenuBitmap
= RenderSearchBitmap(bitmapWidth
,bitmapHeight
,true);
1023 m_searchButton
->SetBitmapLabel(m_searchMenuBitmap
);
1026 // else this bitmap was set by user, don't alter
1029 if ( !m_cancelBitmapUser
)
1032 !m_cancelBitmap
.Ok() ||
1033 m_cancelBitmap
.GetHeight() != bitmapHeight
||
1034 m_cancelBitmap
.GetWidth() != bitmapHeight
1037 m_cancelBitmap
= RenderCancelBitmap(bitmapHeight
-BORDER
,bitmapHeight
-BORDER
); // square
1038 m_cancelButton
->SetBitmapLabel(m_cancelBitmap
);
1040 // else this bitmap was set by user, don't alter
1044 void wxSearchCtrl::OnSearchButton( wxCommandEvent
& event
)
1049 void wxSearchCtrl::OnSetFocus( wxFocusEvent
& /*event*/ )
1057 void wxSearchCtrl::PopupSearchMenu()
1061 wxSize size
= GetSize();
1062 PopupMenu( m_menu
, 0, size
.y
);
1066 #endif // !wxUSE_NATIVE_SEARCH_CONTROL
1068 #endif // wxUSE_SEARCHCTRL