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
)
319 if ( !wxTextCtrlBase::Create(parent
, id
, pos
, size
, wxSUNKEN_BORDER
| style
, validator
, name
) )
321 if ( !wxTextCtrlBase::Create(parent
, id
, pos
, size
, wxSIMPLE_BORDER
| style
, validator
, name
) )
327 m_text
= new wxSearchTextCtrl(this, value
, style
& ~wxBORDER_MASK
);
328 m_text
->SetDescriptiveText(_("Search"));
330 wxSize sizeText
= m_text
->GetBestSize();
332 m_searchButton
= new wxSearchButton(this,wxEVT_COMMAND_SEARCHCTRL_SEARCH_BTN
,m_searchBitmap
);
333 m_cancelButton
= new wxSearchButton(this,wxEVT_COMMAND_SEARCHCTRL_CANCEL_BTN
,m_cancelBitmap
);
335 SetForegroundColour( m_text
->GetForegroundColour() );
336 m_searchButton
->SetForegroundColour( m_text
->GetForegroundColour() );
337 m_cancelButton
->SetForegroundColour( m_text
->GetForegroundColour() );
339 SetBackgroundColour( m_text
->GetBackgroundColour() );
340 m_searchButton
->SetBackgroundColour( m_text
->GetBackgroundColour() );
341 m_cancelButton
->SetBackgroundColour( m_text
->GetBackgroundColour() );
345 SetInitialSize(size
);
350 wxSearchCtrl::~wxSearchCtrl()
353 delete m_searchButton
;
354 delete m_cancelButton
;
359 // search control specific interfaces
360 void wxSearchCtrl::SetMenu( wxMenu
* menu
)
362 if ( menu
== m_menu
)
367 bool hadMenu
= (m_menu
!= NULL
);
371 if ( m_menu
&& !hadMenu
)
373 m_searchButton
->SetBitmapLabel(m_searchMenuBitmap
);
374 m_searchButton
->Refresh();
376 else if ( !m_menu
&& hadMenu
)
378 m_searchButton
->SetBitmapLabel(m_searchBitmap
);
379 if ( m_searchButtonVisible
)
381 m_searchButton
->Refresh();
384 wxRect rect
= GetRect();
385 LayoutControls(0, 0, rect
.GetWidth(), rect
.GetHeight());
388 wxMenu
* wxSearchCtrl::GetMenu()
393 void wxSearchCtrl::ShowSearchButton( bool show
)
395 if ( m_searchButtonVisible
== show
)
400 m_searchButtonVisible
= show
;
401 if ( m_searchButtonVisible
)
406 wxRect rect
= GetRect();
407 LayoutControls(0, 0, rect
.GetWidth(), rect
.GetHeight());
410 bool wxSearchCtrl::IsSearchButtonVisible() const
412 return m_searchButtonVisible
;
416 void wxSearchCtrl::ShowCancelButton( bool show
)
418 if ( m_cancelButtonVisible
== show
)
423 m_cancelButtonVisible
= show
;
425 wxRect rect
= GetRect();
426 LayoutControls(0, 0, rect
.GetWidth(), rect
.GetHeight());
429 bool wxSearchCtrl::IsCancelButtonVisible() const
431 return m_cancelButtonVisible
;
434 void wxSearchCtrl::SetDescriptiveText(const wxString
& text
)
436 m_text
->SetDescriptiveText(text
);
439 wxString
wxSearchCtrl::GetDescriptiveText() const
441 return m_text
->GetDescriptiveText();
444 // ----------------------------------------------------------------------------
446 // ----------------------------------------------------------------------------
448 wxSize
wxSearchCtrl::DoGetBestSize() const
450 wxSize sizeText
= m_text
->GetBestSize();
451 wxSize
sizeSearch(0,0);
452 wxSize
sizeCancel(0,0);
453 int searchMargin
= 0;
454 int cancelMargin
= 0;
455 if ( m_searchButtonVisible
|| m_menu
)
457 sizeSearch
= m_searchButton
->GetBestSize();
458 searchMargin
= MARGIN
;
460 if ( m_cancelButtonVisible
)
462 sizeCancel
= m_cancelButton
->GetBestSize();
463 cancelMargin
= MARGIN
;
466 int horizontalBorder
= 1 + ( sizeText
.y
- sizeText
.y
* 14 / 21 ) / 2;
468 // buttons are square and equal to the height of the text control
469 int height
= sizeText
.y
;
470 return wxSize(sizeSearch
.x
+ searchMargin
+ sizeText
.x
+ cancelMargin
+ sizeCancel
.x
+ 2*horizontalBorder
,
474 void wxSearchCtrl::DoMoveWindow(int x
, int y
, int width
, int height
)
476 wxSearchCtrlBase::DoMoveWindow(x
, y
, width
, height
);
478 LayoutControls(0, 0, width
, height
);
481 void wxSearchCtrl::LayoutControls(int x
, int y
, int width
, int height
)
486 wxSize sizeText
= m_text
->GetBestSize();
487 // make room for the search menu & clear button
488 int horizontalBorder
= ( sizeText
.y
- sizeText
.y
* 14 / 21 ) / 2;
489 x
+= horizontalBorder
;
491 width
-= horizontalBorder
*2;
494 wxSize
sizeSearch(0,0);
495 wxSize
sizeCancel(0,0);
496 int searchMargin
= 0;
497 int cancelMargin
= 0;
498 if ( m_searchButtonVisible
|| m_menu
)
500 sizeSearch
= m_searchButton
->GetBestSize();
501 searchMargin
= MARGIN
;
503 if ( m_cancelButtonVisible
)
505 sizeCancel
= m_cancelButton
->GetBestSize();
506 cancelMargin
= MARGIN
;
508 m_searchButton
->Show( m_searchButtonVisible
|| m_menu
);
509 m_cancelButton
->Show( m_cancelButtonVisible
);
511 if ( sizeSearch
.x
+ sizeCancel
.x
> width
)
513 sizeSearch
.x
= width
/2;
514 sizeCancel
.x
= width
/2;
518 wxCoord textWidth
= width
- sizeSearch
.x
- sizeCancel
.x
- searchMargin
- cancelMargin
;
520 // position the subcontrols inside the client area
522 m_searchButton
->SetSize(x
, y
+ ICON_OFFSET
- 1, sizeSearch
.x
, height
);
523 m_text
->SetSize( x
+ sizeSearch
.x
+ searchMargin
,
524 y
+ ICON_OFFSET
- BORDER
,
527 m_cancelButton
->SetSize(x
+ sizeSearch
.x
+ searchMargin
+ textWidth
+ cancelMargin
,
528 y
+ ICON_OFFSET
- 1, sizeCancel
.x
, height
);
535 wxString
wxSearchCtrl::GetValue() const
537 wxString value
= m_text
->GetValue();
538 if (value
== m_text
->GetDescriptiveText())
539 return wxEmptyString
;
543 void wxSearchCtrl::SetValue(const wxString
& value
)
545 m_text
->SetValue(value
);
548 wxString
wxSearchCtrl::GetRange(long from
, long to
) const
550 return m_text
->GetRange(from
, to
);
553 int wxSearchCtrl::GetLineLength(long lineNo
) const
555 return m_text
->GetLineLength(lineNo
);
557 wxString
wxSearchCtrl::GetLineText(long lineNo
) const
559 return m_text
->GetLineText(lineNo
);
561 int wxSearchCtrl::GetNumberOfLines() const
563 return m_text
->GetNumberOfLines();
566 bool wxSearchCtrl::IsModified() const
568 return m_text
->IsModified();
570 bool wxSearchCtrl::IsEditable() const
572 return m_text
->IsEditable();
575 // more readable flag testing methods
576 bool wxSearchCtrl::IsSingleLine() const
578 return m_text
->IsSingleLine();
580 bool wxSearchCtrl::IsMultiLine() const
582 return m_text
->IsMultiLine();
585 // If the return values from and to are the same, there is no selection.
586 void wxSearchCtrl::GetSelection(long* from
, long* to
) const
588 m_text
->GetSelection(from
, to
);
591 wxString
wxSearchCtrl::GetStringSelection() const
593 return m_text
->GetStringSelection();
600 void wxSearchCtrl::Clear()
604 void wxSearchCtrl::Replace(long from
, long to
, const wxString
& value
)
606 m_text
->Replace(from
, to
, value
);
608 void wxSearchCtrl::Remove(long from
, long to
)
610 m_text
->Remove(from
, to
);
613 // load/save the controls contents from/to the file
614 bool wxSearchCtrl::LoadFile(const wxString
& file
)
616 return m_text
->LoadFile(file
);
618 bool wxSearchCtrl::SaveFile(const wxString
& file
)
620 return m_text
->SaveFile(file
);
623 // sets/clears the dirty flag
624 void wxSearchCtrl::MarkDirty()
628 void wxSearchCtrl::DiscardEdits()
630 m_text
->DiscardEdits();
633 // set the max number of characters which may be entered in a single line
635 void wxSearchCtrl::SetMaxLength(unsigned long len
)
637 m_text
->SetMaxLength(len
);
640 // writing text inserts it at the current position, appending always
641 // inserts it at the end
642 void wxSearchCtrl::WriteText(const wxString
& text
)
644 m_text
->WriteText(text
);
646 void wxSearchCtrl::AppendText(const wxString
& text
)
648 m_text
->AppendText(text
);
651 // insert the character which would have resulted from this key event,
652 // return true if anything has been inserted
653 bool wxSearchCtrl::EmulateKeyPress(const wxKeyEvent
& event
)
655 return m_text
->EmulateKeyPress(event
);
658 // text control under some platforms supports the text styles: these
659 // methods allow to apply the given text style to the given selection or to
660 // set/get the style which will be used for all appended text
661 bool wxSearchCtrl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
663 return m_text
->SetStyle(start
, end
, style
);
665 bool wxSearchCtrl::GetStyle(long position
, wxTextAttr
& style
)
667 return m_text
->GetStyle(position
, style
);
669 bool wxSearchCtrl::SetDefaultStyle(const wxTextAttr
& style
)
671 return m_text
->SetDefaultStyle(style
);
673 const wxTextAttr
& wxSearchCtrl::GetDefaultStyle() const
675 return m_text
->GetDefaultStyle();
678 // translate between the position (which is just an index in the text ctrl
679 // considering all its contents as a single strings) and (x, y) coordinates
680 // which represent column and line.
681 long wxSearchCtrl::XYToPosition(long x
, long y
) const
683 return m_text
->XYToPosition(x
, y
);
685 bool wxSearchCtrl::PositionToXY(long pos
, long *x
, long *y
) const
687 return m_text
->PositionToXY(pos
, x
, y
);
690 void wxSearchCtrl::ShowPosition(long pos
)
692 m_text
->ShowPosition(pos
);
695 // find the character at position given in pixels
697 // NB: pt is in device coords (not adjusted for the client area origin nor
699 wxTextCtrlHitTestResult
wxSearchCtrl::HitTest(const wxPoint
& pt
, long *pos
) const
701 return m_text
->HitTest(pt
, pos
);
703 wxTextCtrlHitTestResult
wxSearchCtrl::HitTest(const wxPoint
& pt
,
705 wxTextCoord
*row
) const
707 return m_text
->HitTest(pt
, col
, row
);
710 // Clipboard operations
711 void wxSearchCtrl::Copy()
715 void wxSearchCtrl::Cut()
719 void wxSearchCtrl::Paste()
724 bool wxSearchCtrl::CanCopy() const
726 return m_text
->CanCopy();
728 bool wxSearchCtrl::CanCut() const
730 return m_text
->CanCut();
732 bool wxSearchCtrl::CanPaste() const
734 return m_text
->CanPaste();
738 void wxSearchCtrl::Undo()
742 void wxSearchCtrl::Redo()
747 bool wxSearchCtrl::CanUndo() const
749 return m_text
->CanUndo();
751 bool wxSearchCtrl::CanRedo() const
753 return m_text
->CanRedo();
757 void wxSearchCtrl::SetInsertionPoint(long pos
)
759 m_text
->SetInsertionPoint(pos
);
761 void wxSearchCtrl::SetInsertionPointEnd()
763 m_text
->SetInsertionPointEnd();
765 long wxSearchCtrl::GetInsertionPoint() const
767 return m_text
->GetInsertionPoint();
769 wxTextPos
wxSearchCtrl::GetLastPosition() const
771 return m_text
->GetLastPosition();
774 void wxSearchCtrl::SetSelection(long from
, long to
)
776 m_text
->SetSelection(from
, to
);
778 void wxSearchCtrl::SelectAll()
783 void wxSearchCtrl::SetEditable(bool editable
)
785 m_text
->SetEditable(editable
);
788 bool wxSearchCtrl::SetFont(const wxFont
& font
)
790 bool result
= wxSearchCtrlBase::SetFont(font
);
791 if ( result
&& m_text
)
793 result
= m_text
->SetFont(font
);
799 // search control generic only
800 void wxSearchCtrl::SetSearchBitmap( const wxBitmap
& bitmap
)
802 m_searchBitmap
= bitmap
;
803 m_searchBitmapUser
= bitmap
.Ok();
804 if ( m_searchBitmapUser
)
806 if ( m_searchButton
&& !m_menu
)
808 m_searchButton
->SetBitmapLabel( m_searchBitmap
);
813 // the user bitmap was just cleared, generate one
818 void wxSearchCtrl::SetSearchMenuBitmap( const wxBitmap
& bitmap
)
820 m_searchMenuBitmap
= bitmap
;
821 m_searchMenuBitmapUser
= bitmap
.Ok();
822 if ( m_searchMenuBitmapUser
)
824 if ( m_searchButton
&& m_menu
)
826 m_searchButton
->SetBitmapLabel( m_searchMenuBitmap
);
831 // the user bitmap was just cleared, generate one
836 void wxSearchCtrl::SetCancelBitmap( const wxBitmap
& bitmap
)
838 m_cancelBitmap
= bitmap
;
839 m_cancelBitmapUser
= bitmap
.Ok();
840 if ( m_cancelBitmapUser
)
842 if ( m_cancelButton
)
844 m_cancelButton
->SetBitmapLabel( m_cancelBitmap
);
849 // the user bitmap was just cleared, generate one
856 // override streambuf method
857 #if wxHAS_TEXT_WINDOW_STREAM
859 #endif // wxHAS_TEXT_WINDOW_STREAM
861 // stream-like insertion operators: these are always available, whether we
862 // were, or not, compiled with streambuf support
863 wxTextCtrl
& operator<<(const wxString
& s
);
864 wxTextCtrl
& operator<<(int i
);
865 wxTextCtrl
& operator<<(long i
);
866 wxTextCtrl
& operator<<(float f
);
867 wxTextCtrl
& operator<<(double d
);
868 wxTextCtrl
& operator<<(const wxChar c
);
871 void wxSearchCtrl::DoSetValue(const wxString
& value
, int flags
)
873 m_text
->ChangeValue( value
);
874 if ( flags
& SetValue_SendEvent
)
875 SendTextUpdatedEvent();
878 // do the window-specific processing after processing the update event
879 void wxSearchCtrl::DoUpdateWindowUI(wxUpdateUIEvent
& event
)
881 wxSearchCtrlBase::DoUpdateWindowUI(event
);
884 bool wxSearchCtrl::ShouldInheritColours() const
889 // icons are rendered at 3-8 times larger than necessary and downscaled for
891 static int GetMultiplier()
894 // speed up bitmap generation by using a small bitmap
897 int depth
= ::wxDisplayDepth();
907 wxBitmap
wxSearchCtrl::RenderSearchBitmap( int x
, int y
, bool renderDrop
)
909 wxColour bg
= GetBackgroundColour();
910 wxColour fg
= wxStepColour(GetForegroundColour(), LIGHT_STEP
-20);
912 //===============================================================================
913 // begin drawing code
914 //===============================================================================
917 // force width:height ratio
929 // glass 11x11, top left corner
930 // handle (9,9)-(13,13)
931 // drop (13,16)-(19,6)-(16,9)
933 int multiplier
= GetMultiplier();
934 int penWidth
= multiplier
* 2;
936 penWidth
= penWidth
* x
/ 20;
938 wxBitmap
bitmap( multiplier
*x
, multiplier
*y
);
940 mem
.SelectObject(bitmap
);
943 mem
.SetBrush( wxBrush(bg
) );
944 mem
.SetPen( wxPen(bg
) );
945 mem
.DrawRectangle(0,0,bitmap
.GetWidth(),bitmap
.GetHeight());
948 mem
.SetBrush( wxBrush(fg
) );
949 mem
.SetPen( wxPen(fg
) );
950 int glassBase
= 5 * x
/ 20;
951 int glassFactor
= 2*glassBase
+ 1;
952 int radius
= multiplier
*glassFactor
/2;
953 mem
.DrawCircle(radius
,radius
,radius
);
954 mem
.SetBrush( wxBrush(bg
) );
955 mem
.SetPen( wxPen(bg
) );
956 mem
.DrawCircle(radius
,radius
,radius
-penWidth
);
959 int lineStart
= radius
+ (radius
-penWidth
/2) * 707 / 1000; // 707 / 1000 = 0.707 = 1/sqrt(2);
961 mem
.SetPen( wxPen(fg
) );
962 mem
.SetBrush( wxBrush(fg
) );
963 int handleCornerShift
= penWidth
* 707 / 1000 / 2; // 707 / 1000 = 0.707 = 1/sqrt(2);
964 handleCornerShift
= WXMAX( handleCornerShift
, 1 );
965 int handleBase
= 4 * x
/ 20;
966 int handleLength
= 2*handleBase
+1;
967 wxPoint handlePolygon
[] =
969 wxPoint(-handleCornerShift
,+handleCornerShift
),
970 wxPoint(+handleCornerShift
,-handleCornerShift
),
971 wxPoint(multiplier
*handleLength
/2+handleCornerShift
,multiplier
*handleLength
/2-handleCornerShift
),
972 wxPoint(multiplier
*handleLength
/2-handleCornerShift
,multiplier
*handleLength
/2+handleCornerShift
),
974 mem
.DrawPolygon(WXSIZEOF(handlePolygon
),handlePolygon
,lineStart
,lineStart
);
976 // draw drop triangle
977 int triangleX
= 13 * x
/ 20;
978 int triangleY
= 5 * x
/ 20;
979 int triangleBase
= 3 * x
/ 20;
980 int triangleFactor
= triangleBase
*2+1;
983 wxPoint dropPolygon
[] =
985 wxPoint(multiplier
*0,multiplier
*0), // triangle left
986 wxPoint(multiplier
*triangleFactor
-1,multiplier
*0), // triangle right
987 wxPoint(multiplier
*triangleFactor
/2,multiplier
*triangleFactor
/2), // triangle bottom
989 mem
.DrawPolygon(WXSIZEOF(dropPolygon
),dropPolygon
,multiplier
*triangleX
,multiplier
*triangleY
);
991 mem
.SelectObject(wxNullBitmap
);
993 //===============================================================================
995 //===============================================================================
997 if ( multiplier
!= 1 )
999 wxImage image
= bitmap
.ConvertToImage();
1001 bitmap
= wxBitmap( image
);
1005 // Trim the edge where the arrow would have gone
1006 bitmap
= bitmap
.GetSubBitmap(wxRect(0,0, y
,y
));
1012 wxBitmap
wxSearchCtrl::RenderCancelBitmap( int x
, int y
)
1014 wxColour bg
= GetBackgroundColour();
1015 wxColour fg
= wxStepColour(GetForegroundColour(), LIGHT_STEP
);
1017 //===============================================================================
1018 // begin drawing code
1019 //===============================================================================
1036 // cross line starts (4,4)-(10,10)
1037 // drop (13,16)-(19,6)-(16,9)
1039 int multiplier
= GetMultiplier();
1041 int penWidth
= multiplier
* x
/ 14;
1043 wxBitmap
bitmap( multiplier
*x
, multiplier
*y
);
1045 mem
.SelectObject(bitmap
);
1048 mem
.SetBrush( wxBrush(bg
) );
1049 mem
.SetPen( wxPen(bg
) );
1050 mem
.DrawRectangle(0,0,bitmap
.GetWidth(),bitmap
.GetHeight());
1053 mem
.SetBrush( wxBrush(fg
) );
1054 mem
.SetPen( wxPen(fg
) );
1055 int radius
= multiplier
*x
/2;
1056 mem
.DrawCircle(radius
,radius
,radius
);
1059 int lineStartBase
= 4 * x
/ 14;
1060 int lineLength
= x
- 2*lineStartBase
;
1062 mem
.SetPen( wxPen(bg
) );
1063 mem
.SetBrush( wxBrush(bg
) );
1064 int handleCornerShift
= penWidth
/2;
1065 handleCornerShift
= WXMAX( handleCornerShift
, 1 );
1066 wxPoint handlePolygon
[] =
1068 wxPoint(-handleCornerShift
,+handleCornerShift
),
1069 wxPoint(+handleCornerShift
,-handleCornerShift
),
1070 wxPoint(multiplier
*lineLength
+handleCornerShift
,multiplier
*lineLength
-handleCornerShift
),
1071 wxPoint(multiplier
*lineLength
-handleCornerShift
,multiplier
*lineLength
+handleCornerShift
),
1073 mem
.DrawPolygon(WXSIZEOF(handlePolygon
),handlePolygon
,multiplier
*lineStartBase
,multiplier
*lineStartBase
);
1074 wxPoint handlePolygon2
[] =
1076 wxPoint(+handleCornerShift
,+handleCornerShift
),
1077 wxPoint(-handleCornerShift
,-handleCornerShift
),
1078 wxPoint(multiplier
*lineLength
-handleCornerShift
,-multiplier
*lineLength
-handleCornerShift
),
1079 wxPoint(multiplier
*lineLength
+handleCornerShift
,-multiplier
*lineLength
+handleCornerShift
),
1081 mem
.DrawPolygon(WXSIZEOF(handlePolygon2
),handlePolygon2
,multiplier
*lineStartBase
,multiplier
*(x
-lineStartBase
));
1083 //===============================================================================
1085 //===============================================================================
1087 if ( multiplier
!= 1 )
1089 wxImage image
= bitmap
.ConvertToImage();
1091 bitmap
= wxBitmap( image
);
1097 void wxSearchCtrl::RecalcBitmaps()
1103 wxSize sizeText
= m_text
->GetBestSize();
1105 int bitmapHeight
= sizeText
.y
- 2 * ICON_MARGIN
;
1106 int bitmapWidth
= sizeText
.y
* 20 / 14;
1108 if ( !m_searchBitmapUser
)
1111 !m_searchBitmap
.Ok() ||
1112 m_searchBitmap
.GetHeight() != bitmapHeight
||
1113 m_searchBitmap
.GetWidth() != bitmapWidth
1116 m_searchBitmap
= RenderSearchBitmap(bitmapWidth
,bitmapHeight
,false);
1119 m_searchButton
->SetBitmapLabel(m_searchBitmap
);
1122 // else this bitmap was set by user, don't alter
1125 if ( !m_searchMenuBitmapUser
)
1128 !m_searchMenuBitmap
.Ok() ||
1129 m_searchMenuBitmap
.GetHeight() != bitmapHeight
||
1130 m_searchMenuBitmap
.GetWidth() != bitmapWidth
1133 m_searchMenuBitmap
= RenderSearchBitmap(bitmapWidth
,bitmapHeight
,true);
1136 m_searchButton
->SetBitmapLabel(m_searchMenuBitmap
);
1139 // else this bitmap was set by user, don't alter
1142 if ( !m_cancelBitmapUser
)
1145 !m_cancelBitmap
.Ok() ||
1146 m_cancelBitmap
.GetHeight() != bitmapHeight
||
1147 m_cancelBitmap
.GetWidth() != bitmapHeight
1150 m_cancelBitmap
= RenderCancelBitmap(bitmapHeight
-BORDER
,bitmapHeight
-BORDER
); // square
1151 m_cancelButton
->SetBitmapLabel(m_cancelBitmap
);
1153 // else this bitmap was set by user, don't alter
1157 void wxSearchCtrl::OnSearchButton( wxCommandEvent
& event
)
1162 void wxSearchCtrl::OnSetFocus( wxFocusEvent
& /*event*/ )
1170 void wxSearchCtrl::OnSize( wxSizeEvent
& WXUNUSED(event
) )
1173 GetSize(&width
, &height
);
1174 LayoutControls(0, 0, width
, height
);
1177 void wxSearchCtrl::PopupSearchMenu()
1181 wxSize size
= GetSize();
1182 PopupMenu( m_menu
, 0, size
.y
);
1186 #endif // !wxUSE_NATIVE_SEARCH_CONTROL
1188 #endif // wxUSE_SEARCHCTRL