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
)
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 m_searchButton
= new wxSearchButton(this,wxEVT_COMMAND_SEARCHCTRL_SEARCH
,m_searchBitmap
);
234 m_cancelButton
= new wxSearchButton(this,wxEVT_COMMAND_SEARCHCTRL_CANCEL
,m_cancelBitmap
);
236 SetForegroundColour( m_text
->GetForegroundColour() );
237 m_searchButton
->SetForegroundColour( m_text
->GetForegroundColour() );
238 m_cancelButton
->SetForegroundColour( m_text
->GetForegroundColour() );
240 SetBackgroundColour( m_text
->GetBackgroundColour() );
241 m_searchButton
->SetBackgroundColour( m_text
->GetBackgroundColour() );
242 m_cancelButton
->SetBackgroundColour( m_text
->GetBackgroundColour() );
246 SetInitialSize(size
);
251 wxSearchCtrl::~wxSearchCtrl()
254 delete m_searchButton
;
255 delete m_cancelButton
;
260 // search control specific interfaces
261 void wxSearchCtrl::SetMenu( wxMenu
* menu
)
263 if ( menu
== m_menu
)
268 bool hadMenu
= (m_menu
!= NULL
);
272 if ( m_menu
&& !hadMenu
)
274 m_searchButton
->SetBitmapLabel(m_searchMenuBitmap
);
275 m_searchButton
->Refresh();
276 if ( !m_searchButtonVisible
)
278 // adding the menu will force the search button to be visible
279 wxRect rect
= GetRect();
280 LayoutControls(0, 0, rect
.GetWidth(), rect
.GetHeight());
283 else if ( !m_menu
&& hadMenu
)
285 m_searchButton
->SetBitmapLabel(m_searchBitmap
);
286 if ( m_searchButtonVisible
)
288 m_searchButton
->Refresh();
292 wxRect rect
= GetRect();
293 LayoutControls(0, 0, rect
.GetWidth(), rect
.GetHeight());
298 wxMenu
* wxSearchCtrl::GetMenu()
303 void wxSearchCtrl::ShowSearchButton( bool show
)
305 if ( m_searchButtonVisible
== show
)
310 m_searchButtonVisible
= show
;
311 if ( m_searchButtonVisible
)
316 wxRect rect
= GetRect();
317 LayoutControls(0, 0, rect
.GetWidth(), rect
.GetHeight());
320 bool wxSearchCtrl::IsSearchButtonVisible() const
322 return m_searchButtonVisible
;
326 void wxSearchCtrl::ShowCancelButton( bool show
)
328 if ( m_cancelButtonVisible
== show
)
333 m_cancelButtonVisible
= show
;
335 wxRect rect
= GetRect();
336 LayoutControls(0, 0, rect
.GetWidth(), rect
.GetHeight());
339 bool wxSearchCtrl::IsCancelButtonVisible() const
341 return m_cancelButtonVisible
;
345 // ----------------------------------------------------------------------------
347 // ----------------------------------------------------------------------------
349 wxSize
wxSearchCtrl::DoGetBestSize() const
351 wxSize sizeText
= m_text
->GetBestSize();
352 wxSize
sizeSearch(0,0);
353 wxSize
sizeCancel(0,0);
354 int searchMargin
= 0;
355 int cancelMargin
= 0;
356 if ( m_searchButtonVisible
|| m_menu
)
358 sizeSearch
= m_searchButton
->GetBestSize();
359 searchMargin
= MARGIN
;
361 if ( m_cancelButtonVisible
)
363 sizeCancel
= m_cancelButton
->GetBestSize();
364 cancelMargin
= MARGIN
;
367 int horizontalBorder
= 1 + ( sizeText
.y
- sizeText
.y
* 14 / 21 ) / 2;
369 // buttons are square and equal to the height of the text control
370 int height
= sizeText
.y
;
371 return wxSize(sizeSearch
.x
+ searchMargin
+ sizeText
.x
+ cancelMargin
+ sizeCancel
.x
+ 2*horizontalBorder
,
375 void wxSearchCtrl::DoMoveWindow(int x
, int y
, int width
, int height
)
377 wxSearchCtrlBase::DoMoveWindow(x
, y
, width
, height
);
379 LayoutControls(0, 0, width
, height
);
382 void wxSearchCtrl::LayoutControls(int x
, int y
, int width
, int height
)
384 wxSize sizeText
= m_text
->GetBestSize();
385 // make room for the search menu & clear button
386 int horizontalBorder
= 1 + ( sizeText
.y
- sizeText
.y
* 14 / 21 ) / 2;
387 x
+= horizontalBorder
;
389 width
-= horizontalBorder
*2;
392 wxSize
sizeSearch(0,0);
393 wxSize
sizeCancel(0,0);
394 int searchMargin
= 0;
395 int cancelMargin
= 0;
396 if ( m_searchButtonVisible
|| m_menu
)
398 sizeSearch
= m_searchButton
->GetBestSize();
399 searchMargin
= MARGIN
;
401 if ( m_cancelButtonVisible
)
403 sizeCancel
= m_cancelButton
->GetBestSize();
404 cancelMargin
= MARGIN
;
406 m_searchButton
->Show( m_searchButtonVisible
|| m_menu
);
407 m_cancelButton
->Show( m_cancelButtonVisible
);
409 if ( sizeSearch
.x
+ sizeCancel
.x
> width
)
411 sizeSearch
.x
= width
/2;
412 sizeCancel
.x
= width
/2;
416 wxCoord textWidth
= width
- sizeSearch
.x
- sizeCancel
.x
- searchMargin
- cancelMargin
;
418 // position the subcontrols inside the client area
420 m_searchButton
->SetSize(x
, y
+ ICON_OFFSET
, sizeSearch
.x
, height
);
421 m_text
->SetSize(x
+ sizeSearch
.x
+ searchMargin
, y
+ ICON_OFFSET
, textWidth
, height
);
422 m_cancelButton
->SetSize(x
+ sizeSearch
.x
+ searchMargin
+ textWidth
+ cancelMargin
,
423 y
+ ICON_OFFSET
, sizeCancel
.x
, height
);
430 wxString
wxSearchCtrl::GetValue() const
432 return m_text
->GetValue();
434 void wxSearchCtrl::SetValue(const wxString
& value
)
436 m_text
->SetValue(value
);
439 wxString
wxSearchCtrl::GetRange(long from
, long to
) const
441 return m_text
->GetRange(from
, to
);
444 int wxSearchCtrl::GetLineLength(long lineNo
) const
446 return m_text
->GetLineLength(lineNo
);
448 wxString
wxSearchCtrl::GetLineText(long lineNo
) const
450 return m_text
->GetLineText(lineNo
);
452 int wxSearchCtrl::GetNumberOfLines() const
454 return m_text
->GetNumberOfLines();
457 bool wxSearchCtrl::IsModified() const
459 return m_text
->IsModified();
461 bool wxSearchCtrl::IsEditable() const
463 return m_text
->IsEditable();
466 // more readable flag testing methods
467 bool wxSearchCtrl::IsSingleLine() const
469 return m_text
->IsSingleLine();
471 bool wxSearchCtrl::IsMultiLine() const
473 return m_text
->IsMultiLine();
476 // If the return values from and to are the same, there is no selection.
477 void wxSearchCtrl::GetSelection(long* from
, long* to
) const
479 m_text
->GetSelection(from
, to
);
482 wxString
wxSearchCtrl::GetStringSelection() const
484 return m_text
->GetStringSelection();
491 void wxSearchCtrl::Clear()
495 void wxSearchCtrl::Replace(long from
, long to
, const wxString
& value
)
497 m_text
->Replace(from
, to
, value
);
499 void wxSearchCtrl::Remove(long from
, long to
)
501 m_text
->Remove(from
, to
);
504 // load/save the controls contents from/to the file
505 bool wxSearchCtrl::LoadFile(const wxString
& file
)
507 return m_text
->LoadFile(file
);
509 bool wxSearchCtrl::SaveFile(const wxString
& file
)
511 return m_text
->SaveFile(file
);
514 // sets/clears the dirty flag
515 void wxSearchCtrl::MarkDirty()
519 void wxSearchCtrl::DiscardEdits()
521 m_text
->DiscardEdits();
524 // set the max number of characters which may be entered in a single line
526 void wxSearchCtrl::SetMaxLength(unsigned long len
)
528 m_text
->SetMaxLength(len
);
531 // writing text inserts it at the current position, appending always
532 // inserts it at the end
533 void wxSearchCtrl::WriteText(const wxString
& text
)
535 m_text
->WriteText(text
);
537 void wxSearchCtrl::AppendText(const wxString
& text
)
539 m_text
->AppendText(text
);
542 // insert the character which would have resulted from this key event,
543 // return true if anything has been inserted
544 bool wxSearchCtrl::EmulateKeyPress(const wxKeyEvent
& event
)
546 return m_text
->EmulateKeyPress(event
);
549 // text control under some platforms supports the text styles: these
550 // methods allow to apply the given text style to the given selection or to
551 // set/get the style which will be used for all appended text
552 bool wxSearchCtrl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
554 return m_text
->SetStyle(start
, end
, style
);
556 bool wxSearchCtrl::GetStyle(long position
, wxTextAttr
& style
)
558 return m_text
->GetStyle(position
, style
);
560 bool wxSearchCtrl::SetDefaultStyle(const wxTextAttr
& style
)
562 return m_text
->SetDefaultStyle(style
);
564 const wxTextAttr
& wxSearchCtrl::GetDefaultStyle() const
566 return m_text
->GetDefaultStyle();
569 // translate between the position (which is just an index in the text ctrl
570 // considering all its contents as a single strings) and (x, y) coordinates
571 // which represent column and line.
572 long wxSearchCtrl::XYToPosition(long x
, long y
) const
574 return m_text
->XYToPosition(x
, y
);
576 bool wxSearchCtrl::PositionToXY(long pos
, long *x
, long *y
) const
578 return m_text
->PositionToXY(pos
, x
, y
);
581 void wxSearchCtrl::ShowPosition(long pos
)
583 m_text
->ShowPosition(pos
);
586 // find the character at position given in pixels
588 // NB: pt is in device coords (not adjusted for the client area origin nor
590 wxTextCtrlHitTestResult
wxSearchCtrl::HitTest(const wxPoint
& pt
, long *pos
) const
592 return m_text
->HitTest(pt
, pos
);
594 wxTextCtrlHitTestResult
wxSearchCtrl::HitTest(const wxPoint
& pt
,
596 wxTextCoord
*row
) const
598 return m_text
->HitTest(pt
, col
, row
);
601 // Clipboard operations
602 void wxSearchCtrl::Copy()
606 void wxSearchCtrl::Cut()
610 void wxSearchCtrl::Paste()
615 bool wxSearchCtrl::CanCopy() const
617 return m_text
->CanCopy();
619 bool wxSearchCtrl::CanCut() const
621 return m_text
->CanCut();
623 bool wxSearchCtrl::CanPaste() const
625 return m_text
->CanPaste();
629 void wxSearchCtrl::Undo()
633 void wxSearchCtrl::Redo()
638 bool wxSearchCtrl::CanUndo() const
640 return m_text
->CanUndo();
642 bool wxSearchCtrl::CanRedo() const
644 return m_text
->CanRedo();
648 void wxSearchCtrl::SetInsertionPoint(long pos
)
650 m_text
->SetInsertionPoint(pos
);
652 void wxSearchCtrl::SetInsertionPointEnd()
654 m_text
->SetInsertionPointEnd();
656 long wxSearchCtrl::GetInsertionPoint() const
658 return m_text
->GetInsertionPoint();
660 wxTextPos
wxSearchCtrl::GetLastPosition() const
662 return m_text
->GetLastPosition();
665 void wxSearchCtrl::SetSelection(long from
, long to
)
667 m_text
->SetSelection(from
, to
);
669 void wxSearchCtrl::SelectAll()
674 void wxSearchCtrl::SetEditable(bool editable
)
676 m_text
->SetEditable(editable
);
679 bool wxSearchCtrl::SetFont(const wxFont
& font
)
681 bool result
= wxSearchCtrlBase::SetFont(font
);
682 if ( result
&& m_text
)
684 result
= m_text
->SetFont(font
);
690 // search control generic only
691 void wxSearchCtrl::SetSearchBitmap( const wxBitmap
& bitmap
)
693 m_searchBitmap
= bitmap
;
694 m_searchBitmapUser
= bitmap
.Ok();
695 if ( m_searchBitmapUser
)
697 if ( m_searchButton
&& !m_menu
)
699 m_searchButton
->SetBitmapLabel( m_searchBitmap
);
704 // the user bitmap was just cleared, generate one
709 void wxSearchCtrl::SetSearchMenuBitmap( const wxBitmap
& bitmap
)
711 m_searchMenuBitmap
= bitmap
;
712 m_searchMenuBitmapUser
= bitmap
.Ok();
713 if ( m_searchMenuBitmapUser
)
715 if ( m_searchButton
&& m_menu
)
717 m_searchButton
->SetBitmapLabel( m_searchMenuBitmap
);
722 // the user bitmap was just cleared, generate one
727 void wxSearchCtrl::SetCancelBitmap( const wxBitmap
& bitmap
)
729 m_cancelBitmap
= bitmap
;
730 m_cancelBitmapUser
= bitmap
.Ok();
731 if ( m_cancelBitmapUser
)
733 if ( m_cancelButton
)
735 m_cancelButton
->SetBitmapLabel( m_cancelBitmap
);
740 // the user bitmap was just cleared, generate one
747 // override streambuf method
748 #if wxHAS_TEXT_WINDOW_STREAM
750 #endif // wxHAS_TEXT_WINDOW_STREAM
752 // stream-like insertion operators: these are always available, whether we
753 // were, or not, compiled with streambuf support
754 wxTextCtrl
& operator<<(const wxString
& s
);
755 wxTextCtrl
& operator<<(int i
);
756 wxTextCtrl
& operator<<(long i
);
757 wxTextCtrl
& operator<<(float f
);
758 wxTextCtrl
& operator<<(double d
);
759 wxTextCtrl
& operator<<(const wxChar c
);
762 void wxSearchCtrl::DoSetValue(const wxString
& value
, int flags
)
764 m_text
->ChangeValue( value
);
765 if ( flags
& SetValue_SendEvent
)
766 SendTextUpdatedEvent();
769 // do the window-specific processing after processing the update event
770 void wxSearchCtrl::DoUpdateWindowUI(wxUpdateUIEvent
& event
)
772 wxSearchCtrlBase::DoUpdateWindowUI(event
);
775 bool wxSearchCtrl::ShouldInheritColours() const
780 // icons are rendered at 3-8 times larger than necessary and downscaled for
782 static int GetMultiplier()
785 // speed up bitmap generation by using a small bitmap
788 int depth
= ::wxDisplayDepth();
798 wxBitmap
wxSearchCtrl::RenderSearchBitmap( int x
, int y
, bool renderDrop
)
800 wxColour bg
= GetBackgroundColour();
801 wxColour fg
= GetForegroundColour();
803 //===============================================================================
804 // begin drawing code
805 //===============================================================================
808 // force width:height ratio
820 // glass 11x11, top left corner
821 // handle (9,9)-(13,13)
822 // drop (13,16)-(19,6)-(16,9)
824 int multiplier
= GetMultiplier();
825 int penWidth
= multiplier
* 2;
827 penWidth
= penWidth
* x
/ 20;
829 wxBitmap
bitmap( multiplier
*x
, multiplier
*y
);
831 mem
.SelectObject(bitmap
);
834 mem
.SetBrush( wxBrush(bg
) );
835 mem
.SetPen( wxPen(bg
) );
836 mem
.DrawRectangle(0,0,bitmap
.GetWidth(),bitmap
.GetHeight());
839 mem
.SetBrush( wxBrush(fg
) );
840 mem
.SetPen( wxPen(fg
) );
841 int glassBase
= 5 * x
/ 20;
842 int glassFactor
= 2*glassBase
+ 1;
843 int radius
= multiplier
*glassFactor
/2;
844 mem
.DrawCircle(radius
,radius
,radius
);
845 mem
.SetBrush( wxBrush(bg
) );
846 mem
.SetPen( wxPen(bg
) );
847 mem
.DrawCircle(radius
,radius
,radius
-penWidth
);
850 int lineStart
= radius
+ (radius
-penWidth
/2) * 707 / 1000; // 707 / 1000 = 0.707 = 1/sqrt(2);
852 mem
.SetPen( wxPen(fg
) );
853 mem
.SetBrush( wxBrush(fg
) );
854 int handleCornerShift
= penWidth
* 707 / 1000 / 2; // 707 / 1000 = 0.707 = 1/sqrt(2);
855 handleCornerShift
= WXMAX( handleCornerShift
, 1 );
856 int handleBase
= 4 * x
/ 20;
857 int handleLength
= 2*handleBase
+1;
858 wxPoint handlePolygon
[] =
860 wxPoint(-handleCornerShift
,+handleCornerShift
),
861 wxPoint(+handleCornerShift
,-handleCornerShift
),
862 wxPoint(multiplier
*handleLength
/2+handleCornerShift
,multiplier
*handleLength
/2-handleCornerShift
),
863 wxPoint(multiplier
*handleLength
/2-handleCornerShift
,multiplier
*handleLength
/2+handleCornerShift
),
865 mem
.DrawPolygon(WXSIZEOF(handlePolygon
),handlePolygon
,lineStart
,lineStart
);
867 // draw drop triangle
868 int triangleX
= 13 * x
/ 20;
869 int triangleY
= 5 * x
/ 20;
870 int triangleBase
= 3 * x
/ 20;
871 int triangleFactor
= triangleBase
*2+1;
874 wxPoint dropPolygon
[] =
876 wxPoint(multiplier
*0,multiplier
*0), // triangle left
877 wxPoint(multiplier
*triangleFactor
-1,multiplier
*0), // triangle right
878 wxPoint(multiplier
*triangleFactor
/2,multiplier
*triangleFactor
/2), // triangle bottom
880 mem
.DrawPolygon(WXSIZEOF(dropPolygon
),dropPolygon
,multiplier
*triangleX
,multiplier
*triangleY
);
883 //===============================================================================
885 //===============================================================================
887 if ( multiplier
!= 1 )
889 wxImage image
= bitmap
.ConvertToImage();
891 bitmap
= wxBitmap( image
);
897 wxBitmap
wxSearchCtrl::RenderCancelBitmap( int x
, int y
)
899 wxColour bg
= GetBackgroundColour();
900 wxColour fg
= GetForegroundColour();
902 //===============================================================================
903 // begin drawing code
904 //===============================================================================
921 // cross line starts (4,4)-(10,10)
922 // drop (13,16)-(19,6)-(16,9)
924 int multiplier
= GetMultiplier();
926 int penWidth
= multiplier
* x
/ 14;
928 wxBitmap
bitmap( multiplier
*x
, multiplier
*y
);
930 mem
.SelectObject(bitmap
);
933 mem
.SetBrush( wxBrush(bg
) );
934 mem
.SetPen( wxPen(bg
) );
935 mem
.DrawRectangle(0,0,bitmap
.GetWidth(),bitmap
.GetHeight());
938 mem
.SetBrush( wxBrush(fg
) );
939 mem
.SetPen( wxPen(fg
) );
940 int radius
= multiplier
*x
/2;
941 mem
.DrawCircle(radius
,radius
,radius
);
944 int lineStartBase
= 4 * x
/ 14;
945 int lineLength
= x
- 2*lineStartBase
;
947 mem
.SetPen( wxPen(bg
) );
948 mem
.SetBrush( wxBrush(bg
) );
949 int handleCornerShift
= penWidth
/2;
950 handleCornerShift
= WXMAX( handleCornerShift
, 1 );
951 wxPoint handlePolygon
[] =
953 wxPoint(-handleCornerShift
,+handleCornerShift
),
954 wxPoint(+handleCornerShift
,-handleCornerShift
),
955 wxPoint(multiplier
*lineLength
+handleCornerShift
,multiplier
*lineLength
-handleCornerShift
),
956 wxPoint(multiplier
*lineLength
-handleCornerShift
,multiplier
*lineLength
+handleCornerShift
),
958 mem
.DrawPolygon(WXSIZEOF(handlePolygon
),handlePolygon
,multiplier
*lineStartBase
,multiplier
*lineStartBase
);
959 wxPoint handlePolygon2
[] =
961 wxPoint(+handleCornerShift
,+handleCornerShift
),
962 wxPoint(-handleCornerShift
,-handleCornerShift
),
963 wxPoint(multiplier
*lineLength
-handleCornerShift
,-multiplier
*lineLength
-handleCornerShift
),
964 wxPoint(multiplier
*lineLength
+handleCornerShift
,-multiplier
*lineLength
+handleCornerShift
),
966 mem
.DrawPolygon(WXSIZEOF(handlePolygon2
),handlePolygon2
,multiplier
*lineStartBase
,multiplier
*(x
-lineStartBase
));
968 //===============================================================================
970 //===============================================================================
972 if ( multiplier
!= 1 )
974 wxImage image
= bitmap
.ConvertToImage();
976 bitmap
= wxBitmap( image
);
982 void wxSearchCtrl::RecalcBitmaps()
988 wxSize sizeText
= m_text
->GetBestSize();
990 int bitmapHeight
= sizeText
.y
- 2 * ICON_MARGIN
;
991 int bitmapWidth
= sizeText
.y
* 20 / 14;
993 if ( !m_searchBitmapUser
)
996 !m_searchBitmap
.Ok() ||
997 m_searchBitmap
.GetHeight() != bitmapHeight
||
998 m_searchBitmap
.GetWidth() != bitmapWidth
1001 m_searchBitmap
= RenderSearchBitmap(bitmapWidth
,bitmapHeight
,false);
1004 m_searchButton
->SetBitmapLabel(m_searchBitmap
);
1007 // else this bitmap was set by user, don't alter
1010 if ( !m_searchMenuBitmapUser
)
1013 !m_searchMenuBitmap
.Ok() ||
1014 m_searchMenuBitmap
.GetHeight() != bitmapHeight
||
1015 m_searchMenuBitmap
.GetWidth() != bitmapWidth
1018 m_searchMenuBitmap
= RenderSearchBitmap(bitmapWidth
,bitmapHeight
,true);
1021 m_searchButton
->SetBitmapLabel(m_searchMenuBitmap
);
1024 // else this bitmap was set by user, don't alter
1027 if ( !m_cancelBitmapUser
)
1030 !m_cancelBitmap
.Ok() ||
1031 m_cancelBitmap
.GetHeight() != bitmapHeight
||
1032 m_cancelBitmap
.GetWidth() != bitmapHeight
1035 m_cancelBitmap
= RenderCancelBitmap(bitmapHeight
-BORDER
,bitmapHeight
-BORDER
); // square
1036 m_cancelButton
->SetBitmapLabel(m_cancelBitmap
);
1038 // else this bitmap was set by user, don't alter
1042 void wxSearchCtrl::OnSearchButton( wxCommandEvent
& event
)
1047 void wxSearchCtrl::OnSetFocus( wxFocusEvent
& /*event*/ )
1055 void wxSearchCtrl::PopupSearchMenu()
1059 wxSize size
= GetSize();
1060 PopupMenu( m_menu
, 0, size
.y
);
1064 #endif // !wxUSE_NATIVE_SEARCH_CONTROL
1066 #endif // wxUSE_SEARCHCTRL