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 // TODO: These functions or something like them should probably be made
55 // public. There are similar functions in src/aui/dockart.cpp...
57 static double wxBlendColour(double fg
, double bg
, double alpha
)
59 double result
= bg
+ (alpha
* (fg
- bg
));
67 static wxColor
wxStepColour(const wxColor
& c
, int ialpha
)
72 double r
= c
.Red(), g
= c
.Green(), b
= c
.Blue();
75 // ialpha is 0..200 where 0 is completely black
76 // and 200 is completely white and 100 is the same
77 // convert that to normal alpha 0.0 - 1.0
78 ialpha
= wxMin(ialpha
, 200);
79 ialpha
= wxMax(ialpha
, 0);
80 double alpha
= ((double)(ialpha
- 100.0))/100.0;
86 alpha
= 1.0 - alpha
; // 0 = transparent fg; 1 = opaque fg
92 alpha
= 1.0 + alpha
; // 0 = transparent fg; 1 = opaque fg
95 r
= wxBlendColour(r
, bg
, alpha
);
96 g
= wxBlendColour(g
, bg
, alpha
);
97 b
= wxBlendColour(b
, bg
, alpha
);
99 return wxColour((unsigned char)r
, (unsigned char)g
, (unsigned char)b
);
102 #define LIGHT_STEP 160
104 // ----------------------------------------------------------------------------
105 // wxSearchTextCtrl: text control used by search control
106 // ----------------------------------------------------------------------------
108 class wxSearchTextCtrl
: public wxTextCtrl
111 wxSearchTextCtrl(wxSearchCtrl
*search
, const wxString
& value
, int style
)
112 : wxTextCtrl(search
, wxID_ANY
, value
, wxDefaultPosition
, wxDefaultSize
,
116 m_defaultFG
= GetForegroundColour();
118 // remove the default minsize, the searchctrl will have one instead
119 SetSizeHints(wxDefaultCoord
,wxDefaultCoord
);
122 void SetDescriptiveText(const wxString
& text
)
124 if ( GetValue() == m_descriptiveText
)
126 ChangeValue(wxEmptyString
);
129 m_descriptiveText
= text
;
132 wxString
GetDescriptiveText() const
134 return m_descriptiveText
;
138 void OnText(wxCommandEvent
& eventText
)
140 wxCommandEvent
event(eventText
);
141 event
.SetEventObject(m_search
);
142 event
.SetId(m_search
->GetId());
144 m_search
->GetEventHandler()->ProcessEvent(event
);
147 void OnTextUrl(wxTextUrlEvent
& eventText
)
149 // copy constructor is disabled for some reason?
150 //wxTextUrlEvent event(eventText);
151 wxTextUrlEvent
event(
153 eventText
.GetMouseEvent(),
154 eventText
.GetURLStart(),
155 eventText
.GetURLEnd()
157 event
.SetEventObject(m_search
);
159 m_search
->GetEventHandler()->ProcessEvent(event
);
162 void OnIdle(wxIdleEvent
& WXUNUSED(event
))
164 if ( IsEmpty() && !(wxWindow::FindFocus() == this) )
166 ChangeValue(m_descriptiveText
);
167 SetInsertionPoint(0);
168 SetForegroundColour(wxStepColour(m_defaultFG
, LIGHT_STEP
));
172 void OnFocus(wxFocusEvent
& event
)
175 if ( GetValue() == m_descriptiveText
)
177 ChangeValue(wxEmptyString
);
178 SetForegroundColour(m_defaultFG
);
183 wxSearchCtrl
* m_search
;
184 wxString m_descriptiveText
;
185 wxColour m_defaultFG
;
187 DECLARE_EVENT_TABLE()
190 BEGIN_EVENT_TABLE(wxSearchTextCtrl
, wxTextCtrl
)
191 EVT_TEXT(wxID_ANY
, wxSearchTextCtrl::OnText
)
192 EVT_TEXT_ENTER(wxID_ANY
, wxSearchTextCtrl::OnText
)
193 EVT_TEXT_URL(wxID_ANY
, wxSearchTextCtrl::OnTextUrl
)
194 EVT_TEXT_MAXLEN(wxID_ANY
, wxSearchTextCtrl::OnText
)
195 EVT_IDLE(wxSearchTextCtrl::OnIdle
)
196 EVT_SET_FOCUS(wxSearchTextCtrl::OnFocus
)
199 // ----------------------------------------------------------------------------
200 // wxSearchButton: search button used by search control
201 // ----------------------------------------------------------------------------
203 class wxSearchButton
: public wxControl
206 wxSearchButton(wxSearchCtrl
*search
, int eventType
, const wxBitmap
& bmp
)
207 : wxControl(search
, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
, wxNO_BORDER
),
209 m_eventType(eventType
),
213 void SetBitmapLabel(const wxBitmap
& label
) { m_bmp
= label
; }
217 wxSize
DoGetBestSize() const
219 return wxSize(m_bmp
.GetWidth(), m_bmp
.GetHeight());
222 void OnLeftUp(wxMouseEvent
&)
224 wxCommandEvent
event(m_eventType
, m_search
->GetId());
225 event
.SetEventObject(m_search
);
227 GetEventHandler()->ProcessEvent(event
);
229 m_search
->SetFocus();
231 if ( m_eventType
== wxEVT_COMMAND_SEARCHCTRL_SEARCH_BTN
)
233 // this happens automatically, just like on Mac OS X
234 m_search
->PopupSearchMenu();
238 void OnPaint(wxPaintEvent
&)
241 dc
.DrawBitmap(m_bmp
, 0,0, true);
246 wxSearchCtrl
*m_search
;
247 wxEventType m_eventType
;
250 DECLARE_EVENT_TABLE()
253 BEGIN_EVENT_TABLE(wxSearchButton
, wxControl
)
254 EVT_LEFT_UP(wxSearchButton::OnLeftUp
)
255 EVT_PAINT(wxSearchButton::OnPaint
)
258 BEGIN_EVENT_TABLE(wxSearchCtrl
, wxSearchCtrlBase
)
259 EVT_SEARCHCTRL_SEARCH_BTN(wxID_ANY
, wxSearchCtrl::OnSearchButton
)
260 EVT_SET_FOCUS(wxSearchCtrl::OnSetFocus
)
261 EVT_SIZE(wxSearchCtrl::OnSize
)
264 IMPLEMENT_DYNAMIC_CLASS(wxSearchCtrl
, wxSearchCtrlBase
)
266 // ============================================================================
268 // ============================================================================
270 // ----------------------------------------------------------------------------
271 // wxSearchCtrl creation
272 // ----------------------------------------------------------------------------
277 wxSearchCtrl::wxSearchCtrl()
282 wxSearchCtrl::wxSearchCtrl(wxWindow
*parent
, wxWindowID id
,
283 const wxString
& value
,
287 const wxValidator
& validator
,
288 const wxString
& name
)
292 Create(parent
, id
, value
, pos
, size
, style
, validator
, name
);
295 void wxSearchCtrl::Init()
302 m_searchButtonVisible
= true;
303 m_cancelButtonVisible
= false;
305 m_searchMenuBitmapUser
= false;
306 m_searchBitmapUser
= false;
307 m_cancelBitmapUser
= false;
310 bool wxSearchCtrl::Create(wxWindow
*parent
, wxWindowID id
,
311 const wxString
& value
,
315 const wxValidator
& validator
,
316 const wxString
& name
)
318 // force border style for more native appearance
319 style
&= ~wxBORDER_MASK
;
321 style
|= wxBORDER_SUNKEN
;
323 style
|= wxBORDER_SIMPLE
;
325 if ( !wxTextCtrlBase::Create(parent
, id
, pos
, size
, style
, validator
, name
) )
330 m_text
= new wxSearchTextCtrl(this, value
, style
& ~wxBORDER_MASK
);
331 m_text
->SetDescriptiveText(_("Search"));
333 wxSize sizeText
= m_text
->GetBestSize();
335 m_searchButton
= new wxSearchButton(this,
336 wxEVT_COMMAND_SEARCHCTRL_SEARCH_BTN
,
338 m_cancelButton
= new wxSearchButton(this,
339 wxEVT_COMMAND_SEARCHCTRL_CANCEL_BTN
,
342 SetForegroundColour( m_text
->GetForegroundColour() );
343 m_searchButton
->SetForegroundColour( m_text
->GetForegroundColour() );
344 m_cancelButton
->SetForegroundColour( m_text
->GetForegroundColour() );
346 SetBackgroundColour( m_text
->GetBackgroundColour() );
347 m_searchButton
->SetBackgroundColour( m_text
->GetBackgroundColour() );
348 m_cancelButton
->SetBackgroundColour( m_text
->GetBackgroundColour() );
352 SetInitialSize(size
);
357 wxSearchCtrl::~wxSearchCtrl()
360 delete m_searchButton
;
361 delete m_cancelButton
;
366 // search control specific interfaces
367 void wxSearchCtrl::SetMenu( wxMenu
* menu
)
369 if ( menu
== m_menu
)
374 bool hadMenu
= (m_menu
!= NULL
);
378 if ( m_menu
&& !hadMenu
)
380 m_searchButton
->SetBitmapLabel(m_searchMenuBitmap
);
381 m_searchButton
->Refresh();
383 else if ( !m_menu
&& hadMenu
)
385 m_searchButton
->SetBitmapLabel(m_searchBitmap
);
386 if ( m_searchButtonVisible
)
388 m_searchButton
->Refresh();
391 wxRect rect
= GetRect();
392 LayoutControls(0, 0, rect
.GetWidth(), rect
.GetHeight());
395 wxMenu
* wxSearchCtrl::GetMenu()
400 void wxSearchCtrl::ShowSearchButton( bool show
)
402 if ( m_searchButtonVisible
== show
)
407 m_searchButtonVisible
= show
;
408 if ( m_searchButtonVisible
)
413 wxRect rect
= GetRect();
414 LayoutControls(0, 0, rect
.GetWidth(), rect
.GetHeight());
417 bool wxSearchCtrl::IsSearchButtonVisible() const
419 return m_searchButtonVisible
;
423 void wxSearchCtrl::ShowCancelButton( bool show
)
425 if ( m_cancelButtonVisible
== show
)
430 m_cancelButtonVisible
= show
;
432 wxRect rect
= GetRect();
433 LayoutControls(0, 0, rect
.GetWidth(), rect
.GetHeight());
436 bool wxSearchCtrl::IsCancelButtonVisible() const
438 return m_cancelButtonVisible
;
441 void wxSearchCtrl::SetDescriptiveText(const wxString
& text
)
443 m_text
->SetDescriptiveText(text
);
446 wxString
wxSearchCtrl::GetDescriptiveText() const
448 return m_text
->GetDescriptiveText();
451 // ----------------------------------------------------------------------------
453 // ----------------------------------------------------------------------------
455 wxSize
wxSearchCtrl::DoGetBestSize() const
457 wxSize sizeText
= m_text
->GetBestSize();
458 wxSize
sizeSearch(0,0);
459 wxSize
sizeCancel(0,0);
460 int searchMargin
= 0;
461 int cancelMargin
= 0;
462 if ( m_searchButtonVisible
|| m_menu
)
464 sizeSearch
= m_searchButton
->GetBestSize();
465 searchMargin
= MARGIN
;
467 if ( m_cancelButtonVisible
)
469 sizeCancel
= m_cancelButton
->GetBestSize();
470 cancelMargin
= MARGIN
;
473 int horizontalBorder
= 1 + ( sizeText
.y
- sizeText
.y
* 14 / 21 ) / 2;
475 // buttons are square and equal to the height of the text control
476 int height
= sizeText
.y
;
477 return wxSize(sizeSearch
.x
+ searchMargin
+ sizeText
.x
+ cancelMargin
+ sizeCancel
.x
+ 2*horizontalBorder
,
481 void wxSearchCtrl::DoMoveWindow(int x
, int y
, int width
, int height
)
483 wxSearchCtrlBase::DoMoveWindow(x
, y
, width
, height
);
485 LayoutControls(0, 0, width
, height
);
488 void wxSearchCtrl::LayoutControls(int x
, int y
, int width
, int height
)
493 wxSize sizeText
= m_text
->GetBestSize();
494 // make room for the search menu & clear button
495 int horizontalBorder
= ( sizeText
.y
- sizeText
.y
* 14 / 21 ) / 2;
496 x
+= horizontalBorder
;
498 width
-= horizontalBorder
*2;
501 wxSize
sizeSearch(0,0);
502 wxSize
sizeCancel(0,0);
503 int searchMargin
= 0;
504 int cancelMargin
= 0;
505 if ( m_searchButtonVisible
|| m_menu
)
507 sizeSearch
= m_searchButton
->GetBestSize();
508 searchMargin
= MARGIN
;
510 if ( m_cancelButtonVisible
)
512 sizeCancel
= m_cancelButton
->GetBestSize();
513 cancelMargin
= MARGIN
;
515 m_searchButton
->Show( m_searchButtonVisible
|| m_menu
);
516 m_cancelButton
->Show( m_cancelButtonVisible
);
518 if ( sizeSearch
.x
+ sizeCancel
.x
> width
)
520 sizeSearch
.x
= width
/2;
521 sizeCancel
.x
= width
/2;
525 wxCoord textWidth
= width
- sizeSearch
.x
- sizeCancel
.x
- searchMargin
- cancelMargin
;
527 // position the subcontrols inside the client area
529 m_searchButton
->SetSize(x
, y
+ ICON_OFFSET
- 1, sizeSearch
.x
, height
);
530 m_text
->SetSize( x
+ sizeSearch
.x
+ searchMargin
,
531 y
+ ICON_OFFSET
- BORDER
,
534 m_cancelButton
->SetSize(x
+ sizeSearch
.x
+ searchMargin
+ textWidth
+ cancelMargin
,
535 y
+ ICON_OFFSET
- 1, sizeCancel
.x
, height
);
542 wxString
wxSearchCtrl::GetValue() const
544 wxString value
= m_text
->GetValue();
545 if (value
== m_text
->GetDescriptiveText())
546 return wxEmptyString
;
550 void wxSearchCtrl::SetValue(const wxString
& value
)
552 m_text
->SetValue(value
);
555 wxString
wxSearchCtrl::GetRange(long from
, long to
) const
557 return m_text
->GetRange(from
, to
);
560 int wxSearchCtrl::GetLineLength(long lineNo
) const
562 return m_text
->GetLineLength(lineNo
);
564 wxString
wxSearchCtrl::GetLineText(long lineNo
) const
566 return m_text
->GetLineText(lineNo
);
568 int wxSearchCtrl::GetNumberOfLines() const
570 return m_text
->GetNumberOfLines();
573 bool wxSearchCtrl::IsModified() const
575 return m_text
->IsModified();
577 bool wxSearchCtrl::IsEditable() const
579 return m_text
->IsEditable();
582 // more readable flag testing methods
583 bool wxSearchCtrl::IsSingleLine() const
585 return m_text
->IsSingleLine();
587 bool wxSearchCtrl::IsMultiLine() const
589 return m_text
->IsMultiLine();
592 // If the return values from and to are the same, there is no selection.
593 void wxSearchCtrl::GetSelection(long* from
, long* to
) const
595 m_text
->GetSelection(from
, to
);
598 wxString
wxSearchCtrl::GetStringSelection() const
600 return m_text
->GetStringSelection();
607 void wxSearchCtrl::Clear()
611 void wxSearchCtrl::Replace(long from
, long to
, const wxString
& value
)
613 m_text
->Replace(from
, to
, value
);
615 void wxSearchCtrl::Remove(long from
, long to
)
617 m_text
->Remove(from
, to
);
620 // load/save the controls contents from/to the file
621 bool wxSearchCtrl::LoadFile(const wxString
& file
)
623 return m_text
->LoadFile(file
);
625 bool wxSearchCtrl::SaveFile(const wxString
& file
)
627 return m_text
->SaveFile(file
);
630 // sets/clears the dirty flag
631 void wxSearchCtrl::MarkDirty()
635 void wxSearchCtrl::DiscardEdits()
637 m_text
->DiscardEdits();
640 // set the max number of characters which may be entered in a single line
642 void wxSearchCtrl::SetMaxLength(unsigned long len
)
644 m_text
->SetMaxLength(len
);
647 // writing text inserts it at the current position, appending always
648 // inserts it at the end
649 void wxSearchCtrl::WriteText(const wxString
& text
)
651 m_text
->WriteText(text
);
653 void wxSearchCtrl::AppendText(const wxString
& text
)
655 m_text
->AppendText(text
);
658 // insert the character which would have resulted from this key event,
659 // return true if anything has been inserted
660 bool wxSearchCtrl::EmulateKeyPress(const wxKeyEvent
& event
)
662 return m_text
->EmulateKeyPress(event
);
665 // text control under some platforms supports the text styles: these
666 // methods allow to apply the given text style to the given selection or to
667 // set/get the style which will be used for all appended text
668 bool wxSearchCtrl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
670 return m_text
->SetStyle(start
, end
, style
);
672 bool wxSearchCtrl::GetStyle(long position
, wxTextAttr
& style
)
674 return m_text
->GetStyle(position
, style
);
676 bool wxSearchCtrl::SetDefaultStyle(const wxTextAttr
& style
)
678 return m_text
->SetDefaultStyle(style
);
680 const wxTextAttr
& wxSearchCtrl::GetDefaultStyle() const
682 return m_text
->GetDefaultStyle();
685 // translate between the position (which is just an index in the text ctrl
686 // considering all its contents as a single strings) and (x, y) coordinates
687 // which represent column and line.
688 long wxSearchCtrl::XYToPosition(long x
, long y
) const
690 return m_text
->XYToPosition(x
, y
);
692 bool wxSearchCtrl::PositionToXY(long pos
, long *x
, long *y
) const
694 return m_text
->PositionToXY(pos
, x
, y
);
697 void wxSearchCtrl::ShowPosition(long pos
)
699 m_text
->ShowPosition(pos
);
702 // find the character at position given in pixels
704 // NB: pt is in device coords (not adjusted for the client area origin nor
706 wxTextCtrlHitTestResult
wxSearchCtrl::HitTest(const wxPoint
& pt
, long *pos
) const
708 return m_text
->HitTest(pt
, pos
);
710 wxTextCtrlHitTestResult
wxSearchCtrl::HitTest(const wxPoint
& pt
,
712 wxTextCoord
*row
) const
714 return m_text
->HitTest(pt
, col
, row
);
717 // Clipboard operations
718 void wxSearchCtrl::Copy()
722 void wxSearchCtrl::Cut()
726 void wxSearchCtrl::Paste()
731 bool wxSearchCtrl::CanCopy() const
733 return m_text
->CanCopy();
735 bool wxSearchCtrl::CanCut() const
737 return m_text
->CanCut();
739 bool wxSearchCtrl::CanPaste() const
741 return m_text
->CanPaste();
745 void wxSearchCtrl::Undo()
749 void wxSearchCtrl::Redo()
754 bool wxSearchCtrl::CanUndo() const
756 return m_text
->CanUndo();
758 bool wxSearchCtrl::CanRedo() const
760 return m_text
->CanRedo();
764 void wxSearchCtrl::SetInsertionPoint(long pos
)
766 m_text
->SetInsertionPoint(pos
);
768 void wxSearchCtrl::SetInsertionPointEnd()
770 m_text
->SetInsertionPointEnd();
772 long wxSearchCtrl::GetInsertionPoint() const
774 return m_text
->GetInsertionPoint();
776 wxTextPos
wxSearchCtrl::GetLastPosition() const
778 return m_text
->GetLastPosition();
781 void wxSearchCtrl::SetSelection(long from
, long to
)
783 m_text
->SetSelection(from
, to
);
785 void wxSearchCtrl::SelectAll()
790 void wxSearchCtrl::SetEditable(bool editable
)
792 m_text
->SetEditable(editable
);
795 bool wxSearchCtrl::SetFont(const wxFont
& font
)
797 bool result
= wxSearchCtrlBase::SetFont(font
);
798 if ( result
&& m_text
)
800 result
= m_text
->SetFont(font
);
806 // search control generic only
807 void wxSearchCtrl::SetSearchBitmap( const wxBitmap
& bitmap
)
809 m_searchBitmap
= bitmap
;
810 m_searchBitmapUser
= bitmap
.Ok();
811 if ( m_searchBitmapUser
)
813 if ( m_searchButton
&& !m_menu
)
815 m_searchButton
->SetBitmapLabel( m_searchBitmap
);
820 // the user bitmap was just cleared, generate one
825 void wxSearchCtrl::SetSearchMenuBitmap( const wxBitmap
& bitmap
)
827 m_searchMenuBitmap
= bitmap
;
828 m_searchMenuBitmapUser
= bitmap
.Ok();
829 if ( m_searchMenuBitmapUser
)
831 if ( m_searchButton
&& m_menu
)
833 m_searchButton
->SetBitmapLabel( m_searchMenuBitmap
);
838 // the user bitmap was just cleared, generate one
843 void wxSearchCtrl::SetCancelBitmap( const wxBitmap
& bitmap
)
845 m_cancelBitmap
= bitmap
;
846 m_cancelBitmapUser
= bitmap
.Ok();
847 if ( m_cancelBitmapUser
)
849 if ( m_cancelButton
)
851 m_cancelButton
->SetBitmapLabel( m_cancelBitmap
);
856 // the user bitmap was just cleared, generate one
863 // override streambuf method
864 #if wxHAS_TEXT_WINDOW_STREAM
866 #endif // wxHAS_TEXT_WINDOW_STREAM
868 // stream-like insertion operators: these are always available, whether we
869 // were, or not, compiled with streambuf support
870 wxTextCtrl
& operator<<(const wxString
& s
);
871 wxTextCtrl
& operator<<(int i
);
872 wxTextCtrl
& operator<<(long i
);
873 wxTextCtrl
& operator<<(float f
);
874 wxTextCtrl
& operator<<(double d
);
875 wxTextCtrl
& operator<<(const wxChar c
);
878 void wxSearchCtrl::DoSetValue(const wxString
& value
, int flags
)
880 m_text
->ChangeValue( value
);
881 if ( flags
& SetValue_SendEvent
)
882 SendTextUpdatedEvent();
885 // do the window-specific processing after processing the update event
886 void wxSearchCtrl::DoUpdateWindowUI(wxUpdateUIEvent
& event
)
888 wxSearchCtrlBase::DoUpdateWindowUI(event
);
891 bool wxSearchCtrl::ShouldInheritColours() const
896 // icons are rendered at 3-8 times larger than necessary and downscaled for
898 static int GetMultiplier()
901 // speed up bitmap generation by using a small bitmap
904 int depth
= ::wxDisplayDepth();
914 wxBitmap
wxSearchCtrl::RenderSearchBitmap( int x
, int y
, bool renderDrop
)
916 wxColour bg
= GetBackgroundColour();
917 wxColour fg
= wxStepColour(GetForegroundColour(), LIGHT_STEP
-20);
919 //===============================================================================
920 // begin drawing code
921 //===============================================================================
924 // force width:height ratio
936 // glass 11x11, top left corner
937 // handle (9,9)-(13,13)
938 // drop (13,16)-(19,6)-(16,9)
940 int multiplier
= GetMultiplier();
941 int penWidth
= multiplier
* 2;
943 penWidth
= penWidth
* x
/ 20;
945 wxBitmap
bitmap( multiplier
*x
, multiplier
*y
);
947 mem
.SelectObject(bitmap
);
950 mem
.SetBrush( wxBrush(bg
) );
951 mem
.SetPen( wxPen(bg
) );
952 mem
.DrawRectangle(0,0,bitmap
.GetWidth(),bitmap
.GetHeight());
955 mem
.SetBrush( wxBrush(fg
) );
956 mem
.SetPen( wxPen(fg
) );
957 int glassBase
= 5 * x
/ 20;
958 int glassFactor
= 2*glassBase
+ 1;
959 int radius
= multiplier
*glassFactor
/2;
960 mem
.DrawCircle(radius
,radius
,radius
);
961 mem
.SetBrush( wxBrush(bg
) );
962 mem
.SetPen( wxPen(bg
) );
963 mem
.DrawCircle(radius
,radius
,radius
-penWidth
);
966 int lineStart
= radius
+ (radius
-penWidth
/2) * 707 / 1000; // 707 / 1000 = 0.707 = 1/sqrt(2);
968 mem
.SetPen( wxPen(fg
) );
969 mem
.SetBrush( wxBrush(fg
) );
970 int handleCornerShift
= penWidth
* 707 / 1000 / 2; // 707 / 1000 = 0.707 = 1/sqrt(2);
971 handleCornerShift
= WXMAX( handleCornerShift
, 1 );
972 int handleBase
= 4 * x
/ 20;
973 int handleLength
= 2*handleBase
+1;
974 wxPoint handlePolygon
[] =
976 wxPoint(-handleCornerShift
,+handleCornerShift
),
977 wxPoint(+handleCornerShift
,-handleCornerShift
),
978 wxPoint(multiplier
*handleLength
/2+handleCornerShift
,multiplier
*handleLength
/2-handleCornerShift
),
979 wxPoint(multiplier
*handleLength
/2-handleCornerShift
,multiplier
*handleLength
/2+handleCornerShift
),
981 mem
.DrawPolygon(WXSIZEOF(handlePolygon
),handlePolygon
,lineStart
,lineStart
);
983 // draw drop triangle
984 int triangleX
= 13 * x
/ 20;
985 int triangleY
= 5 * x
/ 20;
986 int triangleBase
= 3 * x
/ 20;
987 int triangleFactor
= triangleBase
*2+1;
990 wxPoint dropPolygon
[] =
992 wxPoint(multiplier
*0,multiplier
*0), // triangle left
993 wxPoint(multiplier
*triangleFactor
-1,multiplier
*0), // triangle right
994 wxPoint(multiplier
*triangleFactor
/2,multiplier
*triangleFactor
/2), // triangle bottom
996 mem
.DrawPolygon(WXSIZEOF(dropPolygon
),dropPolygon
,multiplier
*triangleX
,multiplier
*triangleY
);
998 mem
.SelectObject(wxNullBitmap
);
1000 //===============================================================================
1002 //===============================================================================
1004 if ( multiplier
!= 1 )
1006 wxImage image
= bitmap
.ConvertToImage();
1008 bitmap
= wxBitmap( image
);
1012 // Trim the edge where the arrow would have gone
1013 bitmap
= bitmap
.GetSubBitmap(wxRect(0,0, y
,y
));
1019 wxBitmap
wxSearchCtrl::RenderCancelBitmap( int x
, int y
)
1021 wxColour bg
= GetBackgroundColour();
1022 wxColour fg
= wxStepColour(GetForegroundColour(), LIGHT_STEP
);
1024 //===============================================================================
1025 // begin drawing code
1026 //===============================================================================
1043 // cross line starts (4,4)-(10,10)
1044 // drop (13,16)-(19,6)-(16,9)
1046 int multiplier
= GetMultiplier();
1048 int penWidth
= multiplier
* x
/ 14;
1050 wxBitmap
bitmap( multiplier
*x
, multiplier
*y
);
1052 mem
.SelectObject(bitmap
);
1055 mem
.SetBrush( wxBrush(bg
) );
1056 mem
.SetPen( wxPen(bg
) );
1057 mem
.DrawRectangle(0,0,bitmap
.GetWidth(),bitmap
.GetHeight());
1060 mem
.SetBrush( wxBrush(fg
) );
1061 mem
.SetPen( wxPen(fg
) );
1062 int radius
= multiplier
*x
/2;
1063 mem
.DrawCircle(radius
,radius
,radius
);
1066 int lineStartBase
= 4 * x
/ 14;
1067 int lineLength
= x
- 2*lineStartBase
;
1069 mem
.SetPen( wxPen(bg
) );
1070 mem
.SetBrush( wxBrush(bg
) );
1071 int handleCornerShift
= penWidth
/2;
1072 handleCornerShift
= WXMAX( handleCornerShift
, 1 );
1073 wxPoint handlePolygon
[] =
1075 wxPoint(-handleCornerShift
,+handleCornerShift
),
1076 wxPoint(+handleCornerShift
,-handleCornerShift
),
1077 wxPoint(multiplier
*lineLength
+handleCornerShift
,multiplier
*lineLength
-handleCornerShift
),
1078 wxPoint(multiplier
*lineLength
-handleCornerShift
,multiplier
*lineLength
+handleCornerShift
),
1080 mem
.DrawPolygon(WXSIZEOF(handlePolygon
),handlePolygon
,multiplier
*lineStartBase
,multiplier
*lineStartBase
);
1081 wxPoint handlePolygon2
[] =
1083 wxPoint(+handleCornerShift
,+handleCornerShift
),
1084 wxPoint(-handleCornerShift
,-handleCornerShift
),
1085 wxPoint(multiplier
*lineLength
-handleCornerShift
,-multiplier
*lineLength
-handleCornerShift
),
1086 wxPoint(multiplier
*lineLength
+handleCornerShift
,-multiplier
*lineLength
+handleCornerShift
),
1088 mem
.DrawPolygon(WXSIZEOF(handlePolygon2
),handlePolygon2
,multiplier
*lineStartBase
,multiplier
*(x
-lineStartBase
));
1090 //===============================================================================
1092 //===============================================================================
1094 if ( multiplier
!= 1 )
1096 wxImage image
= bitmap
.ConvertToImage();
1098 bitmap
= wxBitmap( image
);
1104 void wxSearchCtrl::RecalcBitmaps()
1110 wxSize sizeText
= m_text
->GetBestSize();
1112 int bitmapHeight
= sizeText
.y
- 2 * ICON_MARGIN
;
1113 int bitmapWidth
= sizeText
.y
* 20 / 14;
1115 if ( !m_searchBitmapUser
)
1118 !m_searchBitmap
.Ok() ||
1119 m_searchBitmap
.GetHeight() != bitmapHeight
||
1120 m_searchBitmap
.GetWidth() != bitmapWidth
1123 m_searchBitmap
= RenderSearchBitmap(bitmapWidth
,bitmapHeight
,false);
1126 m_searchButton
->SetBitmapLabel(m_searchBitmap
);
1129 // else this bitmap was set by user, don't alter
1132 if ( !m_searchMenuBitmapUser
)
1135 !m_searchMenuBitmap
.Ok() ||
1136 m_searchMenuBitmap
.GetHeight() != bitmapHeight
||
1137 m_searchMenuBitmap
.GetWidth() != bitmapWidth
1140 m_searchMenuBitmap
= RenderSearchBitmap(bitmapWidth
,bitmapHeight
,true);
1143 m_searchButton
->SetBitmapLabel(m_searchMenuBitmap
);
1146 // else this bitmap was set by user, don't alter
1149 if ( !m_cancelBitmapUser
)
1152 !m_cancelBitmap
.Ok() ||
1153 m_cancelBitmap
.GetHeight() != bitmapHeight
||
1154 m_cancelBitmap
.GetWidth() != bitmapHeight
1157 m_cancelBitmap
= RenderCancelBitmap(bitmapHeight
-BORDER
,bitmapHeight
-BORDER
); // square
1158 m_cancelButton
->SetBitmapLabel(m_cancelBitmap
);
1160 // else this bitmap was set by user, don't alter
1164 void wxSearchCtrl::OnSearchButton( wxCommandEvent
& event
)
1169 void wxSearchCtrl::OnSetFocus( wxFocusEvent
& /*event*/ )
1177 void wxSearchCtrl::OnSize( wxSizeEvent
& WXUNUSED(event
) )
1180 GetSize(&width
, &height
);
1181 LayoutControls(0, 0, width
, height
);
1184 void wxSearchCtrl::PopupSearchMenu()
1188 wxSize size
= GetSize();
1189 PopupMenu( m_menu
, 0, size
.y
);
1193 #endif // !wxUSE_NATIVE_SEARCH_CONTROL
1195 #endif // wxUSE_SEARCHCTRL