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 SetValue(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 SetValue(m_descriptiveText
);
167 SetInsertionPoint(0);
168 SetForegroundColour(wxStepColour(m_defaultFG
, LIGHT_STEP
));
172 void OnFocus(wxFocusEvent
& event
)
175 if ( GetValue() == m_descriptiveText
)
177 SetValue(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 return m_text
->GetValue();
539 void wxSearchCtrl::SetValue(const wxString
& value
)
541 m_text
->SetValue(value
);
544 wxString
wxSearchCtrl::GetRange(long from
, long to
) const
546 return m_text
->GetRange(from
, to
);
549 int wxSearchCtrl::GetLineLength(long lineNo
) const
551 return m_text
->GetLineLength(lineNo
);
553 wxString
wxSearchCtrl::GetLineText(long lineNo
) const
555 return m_text
->GetLineText(lineNo
);
557 int wxSearchCtrl::GetNumberOfLines() const
559 return m_text
->GetNumberOfLines();
562 bool wxSearchCtrl::IsModified() const
564 return m_text
->IsModified();
566 bool wxSearchCtrl::IsEditable() const
568 return m_text
->IsEditable();
571 // more readable flag testing methods
572 bool wxSearchCtrl::IsSingleLine() const
574 return m_text
->IsSingleLine();
576 bool wxSearchCtrl::IsMultiLine() const
578 return m_text
->IsMultiLine();
581 // If the return values from and to are the same, there is no selection.
582 void wxSearchCtrl::GetSelection(long* from
, long* to
) const
584 m_text
->GetSelection(from
, to
);
587 wxString
wxSearchCtrl::GetStringSelection() const
589 return m_text
->GetStringSelection();
596 void wxSearchCtrl::Clear()
600 void wxSearchCtrl::Replace(long from
, long to
, const wxString
& value
)
602 m_text
->Replace(from
, to
, value
);
604 void wxSearchCtrl::Remove(long from
, long to
)
606 m_text
->Remove(from
, to
);
609 // load/save the controls contents from/to the file
610 bool wxSearchCtrl::LoadFile(const wxString
& file
)
612 return m_text
->LoadFile(file
);
614 bool wxSearchCtrl::SaveFile(const wxString
& file
)
616 return m_text
->SaveFile(file
);
619 // sets/clears the dirty flag
620 void wxSearchCtrl::MarkDirty()
624 void wxSearchCtrl::DiscardEdits()
626 m_text
->DiscardEdits();
629 // set the max number of characters which may be entered in a single line
631 void wxSearchCtrl::SetMaxLength(unsigned long len
)
633 m_text
->SetMaxLength(len
);
636 // writing text inserts it at the current position, appending always
637 // inserts it at the end
638 void wxSearchCtrl::WriteText(const wxString
& text
)
640 m_text
->WriteText(text
);
642 void wxSearchCtrl::AppendText(const wxString
& text
)
644 m_text
->AppendText(text
);
647 // insert the character which would have resulted from this key event,
648 // return true if anything has been inserted
649 bool wxSearchCtrl::EmulateKeyPress(const wxKeyEvent
& event
)
651 return m_text
->EmulateKeyPress(event
);
654 // text control under some platforms supports the text styles: these
655 // methods allow to apply the given text style to the given selection or to
656 // set/get the style which will be used for all appended text
657 bool wxSearchCtrl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
659 return m_text
->SetStyle(start
, end
, style
);
661 bool wxSearchCtrl::GetStyle(long position
, wxTextAttr
& style
)
663 return m_text
->GetStyle(position
, style
);
665 bool wxSearchCtrl::SetDefaultStyle(const wxTextAttr
& style
)
667 return m_text
->SetDefaultStyle(style
);
669 const wxTextAttr
& wxSearchCtrl::GetDefaultStyle() const
671 return m_text
->GetDefaultStyle();
674 // translate between the position (which is just an index in the text ctrl
675 // considering all its contents as a single strings) and (x, y) coordinates
676 // which represent column and line.
677 long wxSearchCtrl::XYToPosition(long x
, long y
) const
679 return m_text
->XYToPosition(x
, y
);
681 bool wxSearchCtrl::PositionToXY(long pos
, long *x
, long *y
) const
683 return m_text
->PositionToXY(pos
, x
, y
);
686 void wxSearchCtrl::ShowPosition(long pos
)
688 m_text
->ShowPosition(pos
);
691 // find the character at position given in pixels
693 // NB: pt is in device coords (not adjusted for the client area origin nor
695 wxTextCtrlHitTestResult
wxSearchCtrl::HitTest(const wxPoint
& pt
, long *pos
) const
697 return m_text
->HitTest(pt
, pos
);
699 wxTextCtrlHitTestResult
wxSearchCtrl::HitTest(const wxPoint
& pt
,
701 wxTextCoord
*row
) const
703 return m_text
->HitTest(pt
, col
, row
);
706 // Clipboard operations
707 void wxSearchCtrl::Copy()
711 void wxSearchCtrl::Cut()
715 void wxSearchCtrl::Paste()
720 bool wxSearchCtrl::CanCopy() const
722 return m_text
->CanCopy();
724 bool wxSearchCtrl::CanCut() const
726 return m_text
->CanCut();
728 bool wxSearchCtrl::CanPaste() const
730 return m_text
->CanPaste();
734 void wxSearchCtrl::Undo()
738 void wxSearchCtrl::Redo()
743 bool wxSearchCtrl::CanUndo() const
745 return m_text
->CanUndo();
747 bool wxSearchCtrl::CanRedo() const
749 return m_text
->CanRedo();
753 void wxSearchCtrl::SetInsertionPoint(long pos
)
755 m_text
->SetInsertionPoint(pos
);
757 void wxSearchCtrl::SetInsertionPointEnd()
759 m_text
->SetInsertionPointEnd();
761 long wxSearchCtrl::GetInsertionPoint() const
763 return m_text
->GetInsertionPoint();
765 wxTextPos
wxSearchCtrl::GetLastPosition() const
767 return m_text
->GetLastPosition();
770 void wxSearchCtrl::SetSelection(long from
, long to
)
772 m_text
->SetSelection(from
, to
);
774 void wxSearchCtrl::SelectAll()
779 void wxSearchCtrl::SetEditable(bool editable
)
781 m_text
->SetEditable(editable
);
784 bool wxSearchCtrl::SetFont(const wxFont
& font
)
786 bool result
= wxSearchCtrlBase::SetFont(font
);
787 if ( result
&& m_text
)
789 result
= m_text
->SetFont(font
);
795 // search control generic only
796 void wxSearchCtrl::SetSearchBitmap( const wxBitmap
& bitmap
)
798 m_searchBitmap
= bitmap
;
799 m_searchBitmapUser
= bitmap
.Ok();
800 if ( m_searchBitmapUser
)
802 if ( m_searchButton
&& !m_menu
)
804 m_searchButton
->SetBitmapLabel( m_searchBitmap
);
809 // the user bitmap was just cleared, generate one
814 void wxSearchCtrl::SetSearchMenuBitmap( const wxBitmap
& bitmap
)
816 m_searchMenuBitmap
= bitmap
;
817 m_searchMenuBitmapUser
= bitmap
.Ok();
818 if ( m_searchMenuBitmapUser
)
820 if ( m_searchButton
&& m_menu
)
822 m_searchButton
->SetBitmapLabel( m_searchMenuBitmap
);
827 // the user bitmap was just cleared, generate one
832 void wxSearchCtrl::SetCancelBitmap( const wxBitmap
& bitmap
)
834 m_cancelBitmap
= bitmap
;
835 m_cancelBitmapUser
= bitmap
.Ok();
836 if ( m_cancelBitmapUser
)
838 if ( m_cancelButton
)
840 m_cancelButton
->SetBitmapLabel( m_cancelBitmap
);
845 // the user bitmap was just cleared, generate one
852 // override streambuf method
853 #if wxHAS_TEXT_WINDOW_STREAM
855 #endif // wxHAS_TEXT_WINDOW_STREAM
857 // stream-like insertion operators: these are always available, whether we
858 // were, or not, compiled with streambuf support
859 wxTextCtrl
& operator<<(const wxString
& s
);
860 wxTextCtrl
& operator<<(int i
);
861 wxTextCtrl
& operator<<(long i
);
862 wxTextCtrl
& operator<<(float f
);
863 wxTextCtrl
& operator<<(double d
);
864 wxTextCtrl
& operator<<(const wxChar c
);
867 void wxSearchCtrl::DoSetValue(const wxString
& value
, int flags
)
869 m_text
->ChangeValue( value
);
870 if ( flags
& SetValue_SendEvent
)
871 SendTextUpdatedEvent();
874 // do the window-specific processing after processing the update event
875 void wxSearchCtrl::DoUpdateWindowUI(wxUpdateUIEvent
& event
)
877 wxSearchCtrlBase::DoUpdateWindowUI(event
);
880 bool wxSearchCtrl::ShouldInheritColours() const
885 // icons are rendered at 3-8 times larger than necessary and downscaled for
887 static int GetMultiplier()
890 // speed up bitmap generation by using a small bitmap
893 int depth
= ::wxDisplayDepth();
903 wxBitmap
wxSearchCtrl::RenderSearchBitmap( int x
, int y
, bool renderDrop
)
905 wxColour bg
= GetBackgroundColour();
906 wxColour fg
= wxStepColour(GetForegroundColour(), LIGHT_STEP
-20);
908 //===============================================================================
909 // begin drawing code
910 //===============================================================================
913 // force width:height ratio
925 // glass 11x11, top left corner
926 // handle (9,9)-(13,13)
927 // drop (13,16)-(19,6)-(16,9)
929 int multiplier
= GetMultiplier();
930 int penWidth
= multiplier
* 2;
932 penWidth
= penWidth
* x
/ 20;
934 wxBitmap
bitmap( multiplier
*x
, multiplier
*y
);
936 mem
.SelectObject(bitmap
);
939 mem
.SetBrush( wxBrush(bg
) );
940 mem
.SetPen( wxPen(bg
) );
941 mem
.DrawRectangle(0,0,bitmap
.GetWidth(),bitmap
.GetHeight());
944 mem
.SetBrush( wxBrush(fg
) );
945 mem
.SetPen( wxPen(fg
) );
946 int glassBase
= 5 * x
/ 20;
947 int glassFactor
= 2*glassBase
+ 1;
948 int radius
= multiplier
*glassFactor
/2;
949 mem
.DrawCircle(radius
,radius
,radius
);
950 mem
.SetBrush( wxBrush(bg
) );
951 mem
.SetPen( wxPen(bg
) );
952 mem
.DrawCircle(radius
,radius
,radius
-penWidth
);
955 int lineStart
= radius
+ (radius
-penWidth
/2) * 707 / 1000; // 707 / 1000 = 0.707 = 1/sqrt(2);
957 mem
.SetPen( wxPen(fg
) );
958 mem
.SetBrush( wxBrush(fg
) );
959 int handleCornerShift
= penWidth
* 707 / 1000 / 2; // 707 / 1000 = 0.707 = 1/sqrt(2);
960 handleCornerShift
= WXMAX( handleCornerShift
, 1 );
961 int handleBase
= 4 * x
/ 20;
962 int handleLength
= 2*handleBase
+1;
963 wxPoint handlePolygon
[] =
965 wxPoint(-handleCornerShift
,+handleCornerShift
),
966 wxPoint(+handleCornerShift
,-handleCornerShift
),
967 wxPoint(multiplier
*handleLength
/2+handleCornerShift
,multiplier
*handleLength
/2-handleCornerShift
),
968 wxPoint(multiplier
*handleLength
/2-handleCornerShift
,multiplier
*handleLength
/2+handleCornerShift
),
970 mem
.DrawPolygon(WXSIZEOF(handlePolygon
),handlePolygon
,lineStart
,lineStart
);
972 // draw drop triangle
973 int triangleX
= 13 * x
/ 20;
974 int triangleY
= 5 * x
/ 20;
975 int triangleBase
= 3 * x
/ 20;
976 int triangleFactor
= triangleBase
*2+1;
979 wxPoint dropPolygon
[] =
981 wxPoint(multiplier
*0,multiplier
*0), // triangle left
982 wxPoint(multiplier
*triangleFactor
-1,multiplier
*0), // triangle right
983 wxPoint(multiplier
*triangleFactor
/2,multiplier
*triangleFactor
/2), // triangle bottom
985 mem
.DrawPolygon(WXSIZEOF(dropPolygon
),dropPolygon
,multiplier
*triangleX
,multiplier
*triangleY
);
987 mem
.SelectObject(wxNullBitmap
);
989 //===============================================================================
991 //===============================================================================
993 if ( multiplier
!= 1 )
995 wxImage image
= bitmap
.ConvertToImage();
997 bitmap
= wxBitmap( image
);
1001 // Trim the edge where the arrow would have gone
1002 bitmap
= bitmap
.GetSubBitmap(wxRect(0,0, y
,y
));
1008 wxBitmap
wxSearchCtrl::RenderCancelBitmap( int x
, int y
)
1010 wxColour bg
= GetBackgroundColour();
1011 wxColour fg
= wxStepColour(GetForegroundColour(), LIGHT_STEP
);
1013 //===============================================================================
1014 // begin drawing code
1015 //===============================================================================
1032 // cross line starts (4,4)-(10,10)
1033 // drop (13,16)-(19,6)-(16,9)
1035 int multiplier
= GetMultiplier();
1037 int penWidth
= multiplier
* x
/ 14;
1039 wxBitmap
bitmap( multiplier
*x
, multiplier
*y
);
1041 mem
.SelectObject(bitmap
);
1044 mem
.SetBrush( wxBrush(bg
) );
1045 mem
.SetPen( wxPen(bg
) );
1046 mem
.DrawRectangle(0,0,bitmap
.GetWidth(),bitmap
.GetHeight());
1049 mem
.SetBrush( wxBrush(fg
) );
1050 mem
.SetPen( wxPen(fg
) );
1051 int radius
= multiplier
*x
/2;
1052 mem
.DrawCircle(radius
,radius
,radius
);
1055 int lineStartBase
= 4 * x
/ 14;
1056 int lineLength
= x
- 2*lineStartBase
;
1058 mem
.SetPen( wxPen(bg
) );
1059 mem
.SetBrush( wxBrush(bg
) );
1060 int handleCornerShift
= penWidth
/2;
1061 handleCornerShift
= WXMAX( handleCornerShift
, 1 );
1062 wxPoint handlePolygon
[] =
1064 wxPoint(-handleCornerShift
,+handleCornerShift
),
1065 wxPoint(+handleCornerShift
,-handleCornerShift
),
1066 wxPoint(multiplier
*lineLength
+handleCornerShift
,multiplier
*lineLength
-handleCornerShift
),
1067 wxPoint(multiplier
*lineLength
-handleCornerShift
,multiplier
*lineLength
+handleCornerShift
),
1069 mem
.DrawPolygon(WXSIZEOF(handlePolygon
),handlePolygon
,multiplier
*lineStartBase
,multiplier
*lineStartBase
);
1070 wxPoint handlePolygon2
[] =
1072 wxPoint(+handleCornerShift
,+handleCornerShift
),
1073 wxPoint(-handleCornerShift
,-handleCornerShift
),
1074 wxPoint(multiplier
*lineLength
-handleCornerShift
,-multiplier
*lineLength
-handleCornerShift
),
1075 wxPoint(multiplier
*lineLength
+handleCornerShift
,-multiplier
*lineLength
+handleCornerShift
),
1077 mem
.DrawPolygon(WXSIZEOF(handlePolygon2
),handlePolygon2
,multiplier
*lineStartBase
,multiplier
*(x
-lineStartBase
));
1079 //===============================================================================
1081 //===============================================================================
1083 if ( multiplier
!= 1 )
1085 wxImage image
= bitmap
.ConvertToImage();
1087 bitmap
= wxBitmap( image
);
1093 void wxSearchCtrl::RecalcBitmaps()
1099 wxSize sizeText
= m_text
->GetBestSize();
1101 int bitmapHeight
= sizeText
.y
- 2 * ICON_MARGIN
;
1102 int bitmapWidth
= sizeText
.y
* 20 / 14;
1104 if ( !m_searchBitmapUser
)
1107 !m_searchBitmap
.Ok() ||
1108 m_searchBitmap
.GetHeight() != bitmapHeight
||
1109 m_searchBitmap
.GetWidth() != bitmapWidth
1112 m_searchBitmap
= RenderSearchBitmap(bitmapWidth
,bitmapHeight
,false);
1115 m_searchButton
->SetBitmapLabel(m_searchBitmap
);
1118 // else this bitmap was set by user, don't alter
1121 if ( !m_searchMenuBitmapUser
)
1124 !m_searchMenuBitmap
.Ok() ||
1125 m_searchMenuBitmap
.GetHeight() != bitmapHeight
||
1126 m_searchMenuBitmap
.GetWidth() != bitmapWidth
1129 m_searchMenuBitmap
= RenderSearchBitmap(bitmapWidth
,bitmapHeight
,true);
1132 m_searchButton
->SetBitmapLabel(m_searchMenuBitmap
);
1135 // else this bitmap was set by user, don't alter
1138 if ( !m_cancelBitmapUser
)
1141 !m_cancelBitmap
.Ok() ||
1142 m_cancelBitmap
.GetHeight() != bitmapHeight
||
1143 m_cancelBitmap
.GetWidth() != bitmapHeight
1146 m_cancelBitmap
= RenderCancelBitmap(bitmapHeight
-BORDER
,bitmapHeight
-BORDER
); // square
1147 m_cancelButton
->SetBitmapLabel(m_cancelBitmap
);
1149 // else this bitmap was set by user, don't alter
1153 void wxSearchCtrl::OnSearchButton( wxCommandEvent
& event
)
1158 void wxSearchCtrl::OnSetFocus( wxFocusEvent
& /*event*/ )
1166 void wxSearchCtrl::OnSize( wxSizeEvent
& WXUNUSED(event
) )
1169 GetSize(&width
, &height
);
1170 LayoutControls(0, 0, width
, height
);
1173 void wxSearchCtrl::PopupSearchMenu()
1177 wxSize size
= GetSize();
1178 PopupMenu( m_menu
, 0, size
.y
);
1182 #endif // !wxUSE_NATIVE_SEARCH_CONTROL
1184 #endif // wxUSE_SEARCHCTRL