1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/srchctlg.cpp
3 // Purpose: implements wxSearchCtrl as a composite control
4 // Author: Vince Harron
7 // Copyright: Vince Harron
8 // Licence: 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 #define LIGHT_STEP 160
55 // ----------------------------------------------------------------------------
56 // wxSearchTextCtrl: text control used by search control
57 // ----------------------------------------------------------------------------
59 class wxSearchTextCtrl
: public wxTextCtrl
62 wxSearchTextCtrl(wxSearchCtrl
*search
, const wxString
& value
, int style
)
63 : wxTextCtrl(search
, wxID_ANY
, value
, wxDefaultPosition
, wxDefaultSize
,
64 (style
& ~wxBORDER_MASK
) | wxNO_BORDER
)
70 // remove the default minsize, the searchctrl will have one instead
71 SetSizeHints(wxDefaultCoord
,wxDefaultCoord
);
75 // provide access to the base class protected methods to wxSearchCtrl which
76 // needs to forward to them
77 void DoSetValue(const wxString
& value
, int flags
)
79 wxTextCtrl::DoSetValue(value
, flags
);
82 bool DoLoadFile(const wxString
& file
, int fileType
)
84 return wxTextCtrl::DoLoadFile(file
, fileType
);
87 bool DoSaveFile(const wxString
& file
, int fileType
)
89 return wxTextCtrl::DoSaveFile(file
, fileType
);
93 void OnText(wxCommandEvent
& eventText
)
95 wxCommandEvent
event(eventText
);
96 event
.SetEventObject(m_search
);
97 event
.SetId(m_search
->GetId());
99 m_search
->GetEventHandler()->ProcessEvent(event
);
102 void OnTextUrl(wxTextUrlEvent
& eventText
)
104 // copy constructor is disabled for some reason?
105 //wxTextUrlEvent event(eventText);
106 wxTextUrlEvent
event(
108 eventText
.GetMouseEvent(),
109 eventText
.GetURLStart(),
110 eventText
.GetURLEnd()
112 event
.SetEventObject(m_search
);
114 m_search
->GetEventHandler()->ProcessEvent(event
);
118 wxSearchCtrl
* m_search
;
120 DECLARE_EVENT_TABLE()
123 BEGIN_EVENT_TABLE(wxSearchTextCtrl
, wxTextCtrl
)
124 EVT_TEXT(wxID_ANY
, wxSearchTextCtrl::OnText
)
125 EVT_TEXT_ENTER(wxID_ANY
, wxSearchTextCtrl::OnText
)
126 EVT_TEXT_URL(wxID_ANY
, wxSearchTextCtrl::OnTextUrl
)
127 EVT_TEXT_MAXLEN(wxID_ANY
, wxSearchTextCtrl::OnText
)
130 // ----------------------------------------------------------------------------
131 // wxSearchButton: search button used by search control
132 // ----------------------------------------------------------------------------
134 class wxSearchButton
: public wxControl
137 wxSearchButton(wxSearchCtrl
*search
, int eventType
, const wxBitmap
& bmp
)
138 : wxControl(search
, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
, wxNO_BORDER
),
140 m_eventType(eventType
),
144 void SetBitmapLabel(const wxBitmap
& label
) { m_bmp
= label
; }
146 // The buttons in wxSearchCtrl shouldn't accept focus from keyboard because
147 // this would interfere with the usual TAB processing: the user expects
148 // that pressing TAB in the search control should switch focus to the next
149 // control and not give it to the button inside the same control. Besides,
150 // the search button can be already activated by pressing "Enter" so there
151 // is really no reason for it to be able to get focus from keyboard.
152 virtual bool AcceptsFocusFromKeyboard() const { return false; }
155 wxSize
DoGetBestSize() const
157 return wxSize(m_bmp
.GetWidth(), m_bmp
.GetHeight());
160 void OnLeftUp(wxMouseEvent
&)
162 wxCommandEvent
event(m_eventType
, m_search
->GetId());
163 event
.SetEventObject(m_search
);
165 if ( m_eventType
== wxEVT_COMMAND_SEARCHCTRL_SEARCH_BTN
)
167 // it's convenient to have the string to search for directly in the
168 // event instead of having to retrieve it from the control in the
169 // event handler code later, so provide it here
170 event
.SetString(m_search
->GetValue());
173 GetEventHandler()->ProcessEvent(event
);
175 m_search
->SetFocus();
178 if ( m_eventType
== wxEVT_COMMAND_SEARCHCTRL_SEARCH_BTN
)
180 // this happens automatically, just like on Mac OS X
181 m_search
->PopupSearchMenu();
183 #endif // wxUSE_MENUS
186 void OnPaint(wxPaintEvent
&)
189 dc
.DrawBitmap(m_bmp
, 0,0, true);
194 wxSearchCtrl
*m_search
;
195 wxEventType m_eventType
;
198 DECLARE_EVENT_TABLE()
201 BEGIN_EVENT_TABLE(wxSearchButton
, wxControl
)
202 EVT_LEFT_UP(wxSearchButton::OnLeftUp
)
203 EVT_PAINT(wxSearchButton::OnPaint
)
206 BEGIN_EVENT_TABLE(wxSearchCtrl
, wxSearchCtrlBase
)
207 EVT_SEARCHCTRL_SEARCH_BTN(wxID_ANY
, wxSearchCtrl::OnSearchButton
)
208 EVT_SET_FOCUS(wxSearchCtrl::OnSetFocus
)
209 EVT_SIZE(wxSearchCtrl::OnSize
)
212 IMPLEMENT_DYNAMIC_CLASS(wxSearchCtrl
, wxSearchCtrlBase
)
214 // ============================================================================
216 // ============================================================================
218 // ----------------------------------------------------------------------------
219 // wxSearchCtrl creation
220 // ----------------------------------------------------------------------------
225 wxSearchCtrl::wxSearchCtrl()
230 wxSearchCtrl::wxSearchCtrl(wxWindow
*parent
, wxWindowID id
,
231 const wxString
& value
,
235 const wxValidator
& validator
,
236 const wxString
& name
)
240 Create(parent
, id
, value
, pos
, size
, style
, validator
, name
);
243 void wxSearchCtrl::Init()
246 m_searchButton
= NULL
;
247 m_cancelButton
= NULL
;
250 #endif // wxUSE_MENUS
252 m_searchButtonVisible
= true;
253 m_cancelButtonVisible
= false;
255 m_searchBitmapUser
= false;
256 m_cancelBitmapUser
= false;
258 m_searchMenuBitmapUser
= false;
259 #endif // wxUSE_MENUS
262 bool wxSearchCtrl::Create(wxWindow
*parent
, wxWindowID id
,
263 const wxString
& value
,
267 const wxValidator
& validator
,
268 const wxString
& name
)
270 // force border style for more native appearance
271 style
&= ~wxBORDER_MASK
;
273 style
|= wxBORDER_SUNKEN
;
274 #elif defined(__WXMSW__)
275 // Don't set the style explicitly, let GetDefaultBorder() work it out, unless
276 // we will get a sunken border (e.g. on Windows 200) in which case we must
277 // override with a simple border.
278 if (GetDefaultBorder() == wxBORDER_SUNKEN
)
279 style
|= wxBORDER_SIMPLE
;
281 style
|= wxBORDER_SIMPLE
;
283 if ( !wxSearchCtrlBaseBaseClass::Create(parent
, id
, pos
, size
,
284 style
, validator
, name
) )
289 m_text
= new wxSearchTextCtrl(this, value
, style
);
291 m_searchButton
= new wxSearchButton(this,
292 wxEVT_COMMAND_SEARCHCTRL_SEARCH_BTN
,
294 m_cancelButton
= new wxSearchButton(this,
295 wxEVT_COMMAND_SEARCHCTRL_CANCEL_BTN
,
298 SetForegroundColour( m_text
->GetForegroundColour() );
299 m_searchButton
->SetForegroundColour( m_text
->GetForegroundColour() );
300 m_cancelButton
->SetForegroundColour( m_text
->GetForegroundColour() );
302 SetBackgroundColour( m_text
->GetBackgroundColour() );
303 m_searchButton
->SetBackgroundColour( m_text
->GetBackgroundColour() );
304 m_cancelButton
->SetBackgroundColour( m_text
->GetBackgroundColour() );
308 SetInitialSize(size
);
313 wxSearchCtrl::~wxSearchCtrl()
316 delete m_searchButton
;
317 delete m_cancelButton
;
320 #endif // wxUSE_MENUS
324 // search control specific interfaces
327 void wxSearchCtrl::SetMenu( wxMenu
* menu
)
329 if ( menu
== m_menu
)
334 bool hadMenu
= (m_menu
!= NULL
);
338 if ( m_menu
&& !hadMenu
)
340 m_searchButton
->SetBitmapLabel(m_searchMenuBitmap
);
341 m_searchButton
->Refresh();
343 else if ( !m_menu
&& hadMenu
)
345 m_searchButton
->SetBitmapLabel(m_searchBitmap
);
346 if ( m_searchButtonVisible
)
348 m_searchButton
->Refresh();
351 wxRect rect
= GetRect();
352 LayoutControls(0, 0, rect
.GetWidth(), rect
.GetHeight());
355 wxMenu
* wxSearchCtrl::GetMenu()
360 #endif // wxUSE_MENUS
362 void wxSearchCtrl::ShowSearchButton( bool show
)
364 if ( m_searchButtonVisible
== show
)
369 m_searchButtonVisible
= show
;
370 if ( m_searchButtonVisible
)
375 wxRect rect
= GetRect();
376 LayoutControls(0, 0, rect
.GetWidth(), rect
.GetHeight());
379 bool wxSearchCtrl::IsSearchButtonVisible() const
381 return m_searchButtonVisible
;
385 void wxSearchCtrl::ShowCancelButton( bool show
)
387 if ( m_cancelButtonVisible
== show
)
392 m_cancelButtonVisible
= show
;
394 wxRect rect
= GetRect();
395 LayoutControls(0, 0, rect
.GetWidth(), rect
.GetHeight());
398 bool wxSearchCtrl::IsCancelButtonVisible() const
400 return m_cancelButtonVisible
;
403 void wxSearchCtrl::SetDescriptiveText(const wxString
& text
)
405 m_text
->SetHint(text
);
408 wxString
wxSearchCtrl::GetDescriptiveText() const
410 return m_text
->GetHint();
413 // ----------------------------------------------------------------------------
415 // ----------------------------------------------------------------------------
417 wxSize
wxSearchCtrl::DoGetBestSize() const
419 wxSize sizeText
= m_text
->GetBestSize();
420 wxSize
sizeSearch(0,0);
421 wxSize
sizeCancel(0,0);
422 int searchMargin
= 0;
423 int cancelMargin
= 0;
424 if ( m_searchButtonVisible
|| HasMenu() )
426 sizeSearch
= m_searchButton
->GetBestSize();
427 searchMargin
= MARGIN
;
429 if ( m_cancelButtonVisible
)
431 sizeCancel
= m_cancelButton
->GetBestSize();
432 cancelMargin
= MARGIN
;
435 int horizontalBorder
= 1 + ( sizeText
.y
- sizeText
.y
* 14 / 21 ) / 2;
437 // buttons are square and equal to the height of the text control
438 int height
= sizeText
.y
;
439 return wxSize(sizeSearch
.x
+ searchMargin
+ sizeText
.x
+ cancelMargin
+ sizeCancel
.x
+ 2*horizontalBorder
,
443 void wxSearchCtrl::DoMoveWindow(int x
, int y
, int width
, int height
)
445 wxSearchCtrlBase::DoMoveWindow(x
, y
, width
, height
);
447 LayoutControls(0, 0, width
, height
);
450 void wxSearchCtrl::LayoutControls(int x
, int y
, int width
, int height
)
455 wxSize sizeText
= m_text
->GetBestSize();
456 // make room for the search menu & clear button
457 int horizontalBorder
= ( sizeText
.y
- sizeText
.y
* 14 / 21 ) / 2;
458 x
+= horizontalBorder
;
460 width
-= horizontalBorder
*2;
462 if (width
< 0) width
= 0;
463 if (height
< 0) height
= 0;
465 wxSize
sizeSearch(0,0);
466 wxSize
sizeCancel(0,0);
467 int searchMargin
= 0;
468 int cancelMargin
= 0;
469 if ( m_searchButtonVisible
|| HasMenu() )
471 sizeSearch
= m_searchButton
->GetBestSize();
472 searchMargin
= MARGIN
;
474 if ( m_cancelButtonVisible
)
476 sizeCancel
= m_cancelButton
->GetBestSize();
477 cancelMargin
= MARGIN
;
479 m_searchButton
->Show( m_searchButtonVisible
|| HasMenu() );
480 m_cancelButton
->Show( m_cancelButtonVisible
);
482 if ( sizeSearch
.x
+ sizeCancel
.x
> width
)
484 sizeSearch
.x
= width
/2;
485 sizeCancel
.x
= width
/2;
489 wxCoord textWidth
= width
- sizeSearch
.x
- sizeCancel
.x
- searchMargin
- cancelMargin
- 1;
490 if (textWidth
< 0) textWidth
= 0;
492 // position the subcontrols inside the client area
494 m_searchButton
->SetSize(x
, y
+ ICON_OFFSET
- 1, sizeSearch
.x
, height
);
495 m_text
->SetSize( x
+ sizeSearch
.x
+ searchMargin
,
496 y
+ ICON_OFFSET
- BORDER
,
499 m_cancelButton
->SetSize(x
+ sizeSearch
.x
+ searchMargin
+ textWidth
+ cancelMargin
,
500 y
+ ICON_OFFSET
- 1, sizeCancel
.x
, height
);
507 wxString
wxSearchCtrl::DoGetValue() const
509 return m_text
->GetValue();
511 wxString
wxSearchCtrl::GetRange(long from
, long to
) const
513 return m_text
->GetRange(from
, to
);
516 int wxSearchCtrl::GetLineLength(long lineNo
) const
518 return m_text
->GetLineLength(lineNo
);
520 wxString
wxSearchCtrl::GetLineText(long lineNo
) const
522 return m_text
->GetLineText(lineNo
);
524 int wxSearchCtrl::GetNumberOfLines() const
526 return m_text
->GetNumberOfLines();
529 bool wxSearchCtrl::IsModified() const
531 return m_text
->IsModified();
533 bool wxSearchCtrl::IsEditable() const
535 return m_text
->IsEditable();
538 // more readable flag testing methods
539 bool wxSearchCtrl::IsSingleLine() const
541 return m_text
->IsSingleLine();
543 bool wxSearchCtrl::IsMultiLine() const
545 return m_text
->IsMultiLine();
548 // If the return values from and to are the same, there is no selection.
549 void wxSearchCtrl::GetSelection(long* from
, long* to
) const
551 m_text
->GetSelection(from
, to
);
554 wxString
wxSearchCtrl::GetStringSelection() const
556 return m_text
->GetStringSelection();
563 void wxSearchCtrl::Clear()
567 void wxSearchCtrl::Replace(long from
, long to
, const wxString
& value
)
569 m_text
->Replace(from
, to
, value
);
571 void wxSearchCtrl::Remove(long from
, long to
)
573 m_text
->Remove(from
, to
);
576 // load/save the controls contents from/to the file
577 bool wxSearchCtrl::LoadFile(const wxString
& file
)
579 return m_text
->LoadFile(file
);
581 bool wxSearchCtrl::SaveFile(const wxString
& file
)
583 return m_text
->SaveFile(file
);
586 // sets/clears the dirty flag
587 void wxSearchCtrl::MarkDirty()
591 void wxSearchCtrl::DiscardEdits()
593 m_text
->DiscardEdits();
596 // set the max number of characters which may be entered in a single line
598 void wxSearchCtrl::SetMaxLength(unsigned long len
)
600 m_text
->SetMaxLength(len
);
603 // writing text inserts it at the current position, appending always
604 // inserts it at the end
605 void wxSearchCtrl::WriteText(const wxString
& text
)
607 m_text
->WriteText(text
);
609 void wxSearchCtrl::AppendText(const wxString
& text
)
611 m_text
->AppendText(text
);
614 // insert the character which would have resulted from this key event,
615 // return true if anything has been inserted
616 bool wxSearchCtrl::EmulateKeyPress(const wxKeyEvent
& event
)
618 return m_text
->EmulateKeyPress(event
);
621 // text control under some platforms supports the text styles: these
622 // methods allow to apply the given text style to the given selection or to
623 // set/get the style which will be used for all appended text
624 bool wxSearchCtrl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
626 return m_text
->SetStyle(start
, end
, style
);
628 bool wxSearchCtrl::GetStyle(long position
, wxTextAttr
& style
)
630 return m_text
->GetStyle(position
, style
);
632 bool wxSearchCtrl::SetDefaultStyle(const wxTextAttr
& style
)
634 return m_text
->SetDefaultStyle(style
);
636 const wxTextAttr
& wxSearchCtrl::GetDefaultStyle() const
638 return m_text
->GetDefaultStyle();
641 // translate between the position (which is just an index in the text ctrl
642 // considering all its contents as a single strings) and (x, y) coordinates
643 // which represent column and line.
644 long wxSearchCtrl::XYToPosition(long x
, long y
) const
646 return m_text
->XYToPosition(x
, y
);
648 bool wxSearchCtrl::PositionToXY(long pos
, long *x
, long *y
) const
650 return m_text
->PositionToXY(pos
, x
, y
);
653 void wxSearchCtrl::ShowPosition(long pos
)
655 m_text
->ShowPosition(pos
);
658 // find the character at position given in pixels
660 // NB: pt is in device coords (not adjusted for the client area origin nor
662 wxTextCtrlHitTestResult
wxSearchCtrl::HitTest(const wxPoint
& pt
, long *pos
) const
664 return m_text
->HitTest(pt
, pos
);
666 wxTextCtrlHitTestResult
wxSearchCtrl::HitTest(const wxPoint
& pt
,
668 wxTextCoord
*row
) const
670 return m_text
->HitTest(pt
, col
, row
);
673 // Clipboard operations
674 void wxSearchCtrl::Copy()
678 void wxSearchCtrl::Cut()
682 void wxSearchCtrl::Paste()
687 bool wxSearchCtrl::CanCopy() const
689 return m_text
->CanCopy();
691 bool wxSearchCtrl::CanCut() const
693 return m_text
->CanCut();
695 bool wxSearchCtrl::CanPaste() const
697 return m_text
->CanPaste();
701 void wxSearchCtrl::Undo()
705 void wxSearchCtrl::Redo()
710 bool wxSearchCtrl::CanUndo() const
712 return m_text
->CanUndo();
714 bool wxSearchCtrl::CanRedo() const
716 return m_text
->CanRedo();
720 void wxSearchCtrl::SetInsertionPoint(long pos
)
722 m_text
->SetInsertionPoint(pos
);
724 void wxSearchCtrl::SetInsertionPointEnd()
726 m_text
->SetInsertionPointEnd();
728 long wxSearchCtrl::GetInsertionPoint() const
730 return m_text
->GetInsertionPoint();
732 long wxSearchCtrl::GetLastPosition() const
734 return m_text
->GetLastPosition();
737 void wxSearchCtrl::SetSelection(long from
, long to
)
739 m_text
->SetSelection(from
, to
);
741 void wxSearchCtrl::SelectAll()
746 void wxSearchCtrl::SetEditable(bool editable
)
748 m_text
->SetEditable(editable
);
751 bool wxSearchCtrl::SetFont(const wxFont
& font
)
753 bool result
= wxSearchCtrlBase::SetFont(font
);
754 if ( result
&& m_text
)
756 result
= m_text
->SetFont(font
);
762 // search control generic only
763 void wxSearchCtrl::SetSearchBitmap( const wxBitmap
& bitmap
)
765 m_searchBitmap
= bitmap
;
766 m_searchBitmapUser
= bitmap
.IsOk();
767 if ( m_searchBitmapUser
)
769 if ( m_searchButton
&& !HasMenu() )
771 m_searchButton
->SetBitmapLabel( m_searchBitmap
);
776 // the user bitmap was just cleared, generate one
783 void wxSearchCtrl::SetSearchMenuBitmap( const wxBitmap
& bitmap
)
785 m_searchMenuBitmap
= bitmap
;
786 m_searchMenuBitmapUser
= bitmap
.IsOk();
787 if ( m_searchMenuBitmapUser
)
789 if ( m_searchButton
&& m_menu
)
791 m_searchButton
->SetBitmapLabel( m_searchMenuBitmap
);
796 // the user bitmap was just cleared, generate one
801 #endif // wxUSE_MENUS
803 void wxSearchCtrl::SetCancelBitmap( const wxBitmap
& bitmap
)
805 m_cancelBitmap
= bitmap
;
806 m_cancelBitmapUser
= bitmap
.IsOk();
807 if ( m_cancelBitmapUser
)
809 if ( m_cancelButton
)
811 m_cancelButton
->SetBitmapLabel( m_cancelBitmap
);
816 // the user bitmap was just cleared, generate one
823 // override streambuf method
824 #if wxHAS_TEXT_WINDOW_STREAM
826 #endif // wxHAS_TEXT_WINDOW_STREAM
828 // stream-like insertion operators: these are always available, whether we
829 // were, or not, compiled with streambuf support
830 wxTextCtrl
& operator<<(const wxString
& s
);
831 wxTextCtrl
& operator<<(int i
);
832 wxTextCtrl
& operator<<(long i
);
833 wxTextCtrl
& operator<<(float f
);
834 wxTextCtrl
& operator<<(double d
);
835 wxTextCtrl
& operator<<(const wxChar c
);
838 void wxSearchCtrl::DoSetValue(const wxString
& value
, int flags
)
840 m_text
->DoSetValue(value
, flags
);
843 bool wxSearchCtrl::DoLoadFile(const wxString
& file
, int fileType
)
845 return m_text
->DoLoadFile(file
, fileType
);
848 bool wxSearchCtrl::DoSaveFile(const wxString
& file
, int fileType
)
850 return m_text
->DoSaveFile(file
, fileType
);
853 // do the window-specific processing after processing the update event
854 void wxSearchCtrl::DoUpdateWindowUI(wxUpdateUIEvent
& event
)
856 wxSearchCtrlBase::DoUpdateWindowUI(event
);
859 bool wxSearchCtrl::ShouldInheritColours() const
864 // icons are rendered at 3-8 times larger than necessary and downscaled for
866 static int GetMultiplier()
869 // speed up bitmap generation by using a small bitmap
872 int depth
= ::wxDisplayDepth();
882 wxBitmap
wxSearchCtrl::RenderSearchBitmap( int x
, int y
, bool renderDrop
)
884 wxColour bg
= GetBackgroundColour();
885 wxColour fg
= GetForegroundColour().ChangeLightness(LIGHT_STEP
-20);
887 //===============================================================================
888 // begin drawing code
889 //===============================================================================
892 // force width:height ratio
904 // glass 11x11, top left corner
905 // handle (9,9)-(13,13)
906 // drop (13,16)-(19,6)-(16,9)
908 int multiplier
= GetMultiplier();
909 int penWidth
= multiplier
* 2;
911 penWidth
= penWidth
* x
/ 20;
913 wxBitmap
bitmap( multiplier
*x
, multiplier
*y
);
915 mem
.SelectObject(bitmap
);
918 mem
.SetBrush( wxBrush(bg
) );
919 mem
.SetPen( wxPen(bg
) );
920 mem
.DrawRectangle(0,0,bitmap
.GetWidth(),bitmap
.GetHeight());
923 mem
.SetBrush( wxBrush(fg
) );
924 mem
.SetPen( wxPen(fg
) );
925 int glassBase
= 5 * x
/ 20;
926 int glassFactor
= 2*glassBase
+ 1;
927 int radius
= multiplier
*glassFactor
/2;
928 mem
.DrawCircle(radius
,radius
,radius
);
929 mem
.SetBrush( wxBrush(bg
) );
930 mem
.SetPen( wxPen(bg
) );
931 mem
.DrawCircle(radius
,radius
,radius
-penWidth
);
934 int lineStart
= radius
+ (radius
-penWidth
/2) * 707 / 1000; // 707 / 1000 = 0.707 = 1/sqrt(2);
936 mem
.SetPen( wxPen(fg
) );
937 mem
.SetBrush( wxBrush(fg
) );
938 int handleCornerShift
= penWidth
* 707 / 1000 / 2; // 707 / 1000 = 0.707 = 1/sqrt(2);
939 handleCornerShift
= WXMAX( handleCornerShift
, 1 );
940 int handleBase
= 4 * x
/ 20;
941 int handleLength
= 2*handleBase
+1;
942 wxPoint handlePolygon
[] =
944 wxPoint(-handleCornerShift
,+handleCornerShift
),
945 wxPoint(+handleCornerShift
,-handleCornerShift
),
946 wxPoint(multiplier
*handleLength
/2+handleCornerShift
,multiplier
*handleLength
/2-handleCornerShift
),
947 wxPoint(multiplier
*handleLength
/2-handleCornerShift
,multiplier
*handleLength
/2+handleCornerShift
),
949 mem
.DrawPolygon(WXSIZEOF(handlePolygon
),handlePolygon
,lineStart
,lineStart
);
951 // draw drop triangle
952 int triangleX
= 13 * x
/ 20;
953 int triangleY
= 5 * x
/ 20;
954 int triangleBase
= 3 * x
/ 20;
955 int triangleFactor
= triangleBase
*2+1;
958 wxPoint dropPolygon
[] =
960 wxPoint(multiplier
*0,multiplier
*0), // triangle left
961 wxPoint(multiplier
*triangleFactor
-1,multiplier
*0), // triangle right
962 wxPoint(multiplier
*triangleFactor
/2,multiplier
*triangleFactor
/2), // triangle bottom
964 mem
.DrawPolygon(WXSIZEOF(dropPolygon
),dropPolygon
,multiplier
*triangleX
,multiplier
*triangleY
);
966 mem
.SelectObject(wxNullBitmap
);
968 //===============================================================================
970 //===============================================================================
972 if ( multiplier
!= 1 )
974 wxImage image
= bitmap
.ConvertToImage();
976 bitmap
= wxBitmap( image
);
980 // Trim the edge where the arrow would have gone
981 bitmap
= bitmap
.GetSubBitmap(wxRect(0,0, y
,y
));
987 wxBitmap
wxSearchCtrl::RenderCancelBitmap( int x
, int y
)
989 wxColour bg
= GetBackgroundColour();
990 wxColour fg
= GetForegroundColour().ChangeLightness(LIGHT_STEP
);
992 //===============================================================================
993 // begin drawing code
994 //===============================================================================
1011 // cross line starts (4,4)-(10,10)
1012 // drop (13,16)-(19,6)-(16,9)
1014 int multiplier
= GetMultiplier();
1016 int penWidth
= multiplier
* x
/ 14;
1018 wxBitmap
bitmap( multiplier
*x
, multiplier
*y
);
1020 mem
.SelectObject(bitmap
);
1023 mem
.SetBrush( wxBrush(bg
) );
1024 mem
.SetPen( wxPen(bg
) );
1025 mem
.DrawRectangle(0,0,bitmap
.GetWidth(),bitmap
.GetHeight());
1028 mem
.SetBrush( wxBrush(fg
) );
1029 mem
.SetPen( wxPen(fg
) );
1030 int radius
= multiplier
*x
/2;
1031 mem
.DrawCircle(radius
,radius
,radius
);
1034 int lineStartBase
= 4 * x
/ 14;
1035 int lineLength
= x
- 2*lineStartBase
;
1037 mem
.SetPen( wxPen(bg
) );
1038 mem
.SetBrush( wxBrush(bg
) );
1039 int handleCornerShift
= penWidth
/2;
1040 handleCornerShift
= WXMAX( handleCornerShift
, 1 );
1041 wxPoint handlePolygon
[] =
1043 wxPoint(-handleCornerShift
,+handleCornerShift
),
1044 wxPoint(+handleCornerShift
,-handleCornerShift
),
1045 wxPoint(multiplier
*lineLength
+handleCornerShift
,multiplier
*lineLength
-handleCornerShift
),
1046 wxPoint(multiplier
*lineLength
-handleCornerShift
,multiplier
*lineLength
+handleCornerShift
),
1048 mem
.DrawPolygon(WXSIZEOF(handlePolygon
),handlePolygon
,multiplier
*lineStartBase
,multiplier
*lineStartBase
);
1049 wxPoint handlePolygon2
[] =
1051 wxPoint(+handleCornerShift
,+handleCornerShift
),
1052 wxPoint(-handleCornerShift
,-handleCornerShift
),
1053 wxPoint(multiplier
*lineLength
-handleCornerShift
,-multiplier
*lineLength
-handleCornerShift
),
1054 wxPoint(multiplier
*lineLength
+handleCornerShift
,-multiplier
*lineLength
+handleCornerShift
),
1056 mem
.DrawPolygon(WXSIZEOF(handlePolygon2
),handlePolygon2
,multiplier
*lineStartBase
,multiplier
*(x
-lineStartBase
));
1058 //===============================================================================
1060 //===============================================================================
1062 if ( multiplier
!= 1 )
1064 wxImage image
= bitmap
.ConvertToImage();
1066 bitmap
= wxBitmap( image
);
1072 void wxSearchCtrl::RecalcBitmaps()
1078 wxSize sizeText
= m_text
->GetBestSize();
1080 int bitmapHeight
= sizeText
.y
- 2 * ICON_MARGIN
;
1081 int bitmapWidth
= sizeText
.y
* 20 / 14;
1083 if ( !m_searchBitmapUser
)
1086 !m_searchBitmap
.IsOk() ||
1087 m_searchBitmap
.GetHeight() != bitmapHeight
||
1088 m_searchBitmap
.GetWidth() != bitmapWidth
1091 m_searchBitmap
= RenderSearchBitmap(bitmapWidth
,bitmapHeight
,false);
1094 m_searchButton
->SetBitmapLabel(m_searchBitmap
);
1097 // else this bitmap was set by user, don't alter
1101 if ( !m_searchMenuBitmapUser
)
1104 !m_searchMenuBitmap
.IsOk() ||
1105 m_searchMenuBitmap
.GetHeight() != bitmapHeight
||
1106 m_searchMenuBitmap
.GetWidth() != bitmapWidth
1109 m_searchMenuBitmap
= RenderSearchBitmap(bitmapWidth
,bitmapHeight
,true);
1112 m_searchButton
->SetBitmapLabel(m_searchMenuBitmap
);
1115 // else this bitmap was set by user, don't alter
1117 #endif // wxUSE_MENUS
1119 if ( !m_cancelBitmapUser
)
1122 !m_cancelBitmap
.IsOk() ||
1123 m_cancelBitmap
.GetHeight() != bitmapHeight
||
1124 m_cancelBitmap
.GetWidth() != bitmapHeight
1127 m_cancelBitmap
= RenderCancelBitmap(bitmapHeight
-BORDER
-1,bitmapHeight
-BORDER
-1); // square
1128 m_cancelButton
->SetBitmapLabel(m_cancelBitmap
);
1130 // else this bitmap was set by user, don't alter
1134 void wxSearchCtrl::OnSearchButton( wxCommandEvent
& event
)
1139 void wxSearchCtrl::OnSetFocus( wxFocusEvent
& /*event*/ )
1147 void wxSearchCtrl::OnSize( wxSizeEvent
& WXUNUSED(event
) )
1150 GetSize(&width
, &height
);
1151 LayoutControls(0, 0, width
, height
);
1156 void wxSearchCtrl::PopupSearchMenu()
1160 wxSize size
= GetSize();
1161 PopupMenu( m_menu
, 0, size
.y
);
1165 #endif // wxUSE_MENUS
1167 #endif // !wxUSE_NATIVE_SEARCH_CONTROL
1169 #endif // wxUSE_SEARCHCTRL