1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/srchctlg.cpp
3 // Purpose: implements wxSearchCtrl as a composite control
4 // Author: Vince Harron
8 // Copyright: Vince Harron
9 // License: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "srchctlg.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
32 #include "wx/button.h"
33 #include "wx/dcclient.h"
35 #include "wx/dcmemory.h"
40 #include "wx/srchctrl.h"
42 #if !USE_NATIVE_SEARCH_CONTROL
46 #define WXMIN(a,b) (a)<(b)?(a):(b)
47 #define WXMAX(a,b) (a)>(b)?(a):(b)
49 // ----------------------------------------------------------------------------
51 // ----------------------------------------------------------------------------
53 // the margin between the text control and the search/cancel buttons
54 static const wxCoord MARGIN
= 2;
56 // border around all controls to compensate for wxSIMPLE_BORDER
57 #if defined(__WXMSW__)
58 static const wxCoord BORDER
= 0;
59 static const wxCoord ICON_MARGIN
= 2;
60 static const wxCoord ICON_OFFSET
= 2;
62 static const wxCoord BORDER
= 2;
63 static const wxCoord ICON_MARGIN
= 0;
64 static const wxCoord ICON_OFFSET
= 0;
67 // ----------------------------------------------------------------------------
68 // wxSearchTextCtrl: text control used by search control
69 // ----------------------------------------------------------------------------
71 class wxSearchTextCtrl
: public wxTextCtrl
74 wxSearchTextCtrl(wxSearchCtrl
*search
, const wxString
& value
, int style
)
75 : wxTextCtrl(search
, wxID_ANY
, value
, wxDefaultPosition
, wxDefaultSize
,
80 // remove the default minsize, the searchctrl will have one instead
81 SetSizeHints(wxDefaultCoord
,wxDefaultCoord
);
85 void OnText(wxCommandEvent
& eventText
)
87 wxCommandEvent
event(eventText
);
88 event
.SetEventObject(m_search
);
89 event
.SetId(m_search
->GetId());
91 m_search
->GetEventHandler()->ProcessEvent(event
);
94 void OnTextUrl(wxTextUrlEvent
& eventText
)
96 // copy constructor is disabled for some reason?
97 //wxTextUrlEvent event(eventText);
100 eventText
.GetMouseEvent(),
101 eventText
.GetURLStart(),
102 eventText
.GetURLEnd()
104 event
.SetEventObject(m_search
);
106 m_search
->GetEventHandler()->ProcessEvent(event
);
110 wxSearchCtrl
* m_search
;
112 DECLARE_EVENT_TABLE()
115 BEGIN_EVENT_TABLE(wxSearchTextCtrl
, wxTextCtrl
)
116 EVT_TEXT(wxID_ANY
, wxSearchTextCtrl::OnText
)
117 EVT_TEXT_ENTER(wxID_ANY
, wxSearchTextCtrl::OnText
)
118 EVT_TEXT_URL(wxID_ANY
, wxSearchTextCtrl::OnTextUrl
)
119 EVT_TEXT_MAXLEN(wxID_ANY
, wxSearchTextCtrl::OnText
)
122 // ----------------------------------------------------------------------------
123 // wxSearchButton: search button used by search control
124 // ----------------------------------------------------------------------------
126 class wxSearchButton
: public wxControl
129 wxSearchButton(wxSearchCtrl
*search
, int eventType
, const wxBitmap
& bmp
)
130 : wxControl(search
, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
, wxNO_BORDER
),
132 m_eventType(eventType
),
136 void SetBitmapLabel(const wxBitmap
& label
) { m_bmp
= label
; }
140 wxSize
DoGetBestSize() const
142 return wxSize(m_bmp
.GetWidth(), m_bmp
.GetHeight());
145 void OnLeftUp(wxMouseEvent
&)
147 wxCommandEvent
event(m_eventType
, m_search
->GetId());
148 event
.SetEventObject(m_search
);
150 GetEventHandler()->ProcessEvent(event
);
152 m_search
->SetFocus();
154 if ( m_eventType
== wxEVT_COMMAND_SEARCHCTRL_SEARCH
)
156 // this happens automatically, just like on Mac OS X
157 m_search
->PopupSearchMenu();
161 void OnPaint(wxPaintEvent
&)
164 dc
.DrawBitmap(m_bmp
, 0,0, true);
169 wxSearchCtrl
*m_search
;
170 wxEventType m_eventType
;
173 DECLARE_EVENT_TABLE()
176 BEGIN_EVENT_TABLE(wxSearchButton
, wxButton
)
177 EVT_LEFT_UP(wxSearchButton::OnLeftUp
)
178 EVT_PAINT(wxSearchButton::OnPaint
)
181 BEGIN_EVENT_TABLE(wxSearchCtrl
, wxSearchCtrlBase
)
182 EVT_SEARCHCTRL_SEARCH(wxID_ANY
, wxSearchCtrl::OnSearchButton
)
183 EVT_SET_FOCUS(wxSearchCtrl::OnSetFocus
)
186 IMPLEMENT_DYNAMIC_CLASS(wxSearchCtrl
, wxSearchCtrlBase
)
188 // ============================================================================
190 // ============================================================================
192 // ----------------------------------------------------------------------------
193 // wxSearchCtrl creation
194 // ----------------------------------------------------------------------------
199 wxSearchCtrl::wxSearchCtrl()
204 wxSearchCtrl::wxSearchCtrl(wxWindow
*parent
, wxWindowID id
,
205 const wxString
& value
,
209 const wxValidator
& validator
,
210 const wxString
& name
)
214 Create(parent
, id
, value
, pos
, size
, style
, validator
, name
);
217 void wxSearchCtrl::Init()
224 m_searchButtonVisible
= true;
225 m_cancelButtonVisible
= false;
227 m_searchMenuBitmapUser
= false;
228 m_searchBitmapUser
= false;
229 m_cancelBitmapUser
= false;
232 bool wxSearchCtrl::Create(wxWindow
*parent
, wxWindowID id
,
233 const wxString
& value
,
237 const wxValidator
& validator
,
238 const wxString
& name
)
240 if ( !wxTextCtrlBase::Create(parent
, id
, pos
, size
, wxSIMPLE_BORDER
| style
, validator
, name
) )
245 m_text
= new wxSearchTextCtrl(this, value
, style
& ~wxBORDER_MASK
);
247 wxSize sizeText
= m_text
->GetBestSize();
249 m_searchButton
= new wxSearchButton(this,wxEVT_COMMAND_SEARCHCTRL_SEARCH
,m_searchBitmap
);
250 m_cancelButton
= new wxSearchButton(this,wxEVT_COMMAND_SEARCHCTRL_CANCEL
,m_cancelBitmap
);
252 SetForegroundColour( m_text
->GetForegroundColour() );
253 m_searchButton
->SetForegroundColour( m_text
->GetForegroundColour() );
254 m_cancelButton
->SetForegroundColour( m_text
->GetForegroundColour() );
256 SetBackgroundColour( m_text
->GetBackgroundColour() );
257 m_searchButton
->SetBackgroundColour( m_text
->GetBackgroundColour() );
258 m_cancelButton
->SetBackgroundColour( m_text
->GetBackgroundColour() );
262 SetInitialSize(size
);
267 wxSearchCtrl::~wxSearchCtrl()
270 delete m_searchButton
;
271 delete m_cancelButton
;
276 // search control specific interfaces
277 void wxSearchCtrl::SetMenu( wxMenu
* menu
)
279 if ( menu
== m_menu
)
285 bool hadMenu
= (m_menu
!=0);
288 if ( m_menu
&& !hadMenu
)
290 m_searchButton
->SetBitmapLabel(m_searchMenuBitmap
);
291 m_searchButton
->Refresh();
292 if ( !m_searchButtonVisible
)
294 // adding the menu will force the search button to be visible
295 wxRect rect
= GetRect();
296 LayoutControls(0, 0, rect
.GetWidth(), rect
.GetHeight());
299 else if ( !m_menu
&& hadMenu
)
301 m_searchButton
->SetBitmapLabel(m_searchBitmap
);
302 if ( m_searchButtonVisible
)
304 m_searchButton
->Refresh();
308 wxRect rect
= GetRect();
309 LayoutControls(0, 0, rect
.GetWidth(), rect
.GetHeight());
314 wxMenu
* wxSearchCtrl::GetMenu()
319 void wxSearchCtrl::SetSearchButtonVisible( bool show
)
321 if ( m_searchButtonVisible
== show
)
326 m_searchButtonVisible
= show
;
327 if ( m_searchButtonVisible
)
332 wxRect rect
= GetRect();
333 LayoutControls(0, 0, rect
.GetWidth(), rect
.GetHeight());
336 bool wxSearchCtrl::GetSearchButtonVisible() const
338 return m_searchButtonVisible
;
342 void wxSearchCtrl::SetCancelButtonVisible( bool show
)
344 if ( m_cancelButtonVisible
== show
)
349 m_cancelButtonVisible
= show
;
351 wxRect rect
= GetRect();
352 LayoutControls(0, 0, rect
.GetWidth(), rect
.GetHeight());
355 bool wxSearchCtrl::GetCancelButtonVisible() const
357 return m_cancelButtonVisible
;
361 // ----------------------------------------------------------------------------
363 // ----------------------------------------------------------------------------
365 wxSize
wxSearchCtrl::DoGetBestSize() const
367 wxSize sizeText
= m_text
->GetBestSize();
368 wxSize
sizeSearch(0,0);
369 wxSize
sizeCancel(0,0);
370 int searchMargin
= 0;
371 int cancelMargin
= 0;
372 if ( m_searchButtonVisible
|| m_menu
)
374 sizeSearch
= m_searchButton
->GetBestSize();
375 searchMargin
= MARGIN
;
377 if ( m_cancelButtonVisible
)
379 sizeCancel
= m_cancelButton
->GetBestSize();
380 cancelMargin
= MARGIN
;
383 int horizontalBorder
= 1 + ( sizeText
.y
- sizeText
.y
* 14 / 21 ) / 2;
385 // buttons are square and equal to the height of the text control
386 int height
= sizeText
.y
;
387 return wxSize(sizeSearch
.x
+ searchMargin
+ sizeText
.x
+ cancelMargin
+ sizeCancel
.x
+ 2*horizontalBorder
,
391 void wxSearchCtrl::DoMoveWindow(int x
, int y
, int width
, int height
)
393 wxSearchCtrlBase::DoMoveWindow(x
, y
, width
, height
);
395 LayoutControls(0, 0, width
, height
);
398 void wxSearchCtrl::LayoutControls(int x
, int y
, int width
, int height
)
400 wxSize sizeText
= m_text
->GetBestSize();
401 // make room for the search menu & clear button
402 int horizontalBorder
= 1 + ( sizeText
.y
- sizeText
.y
* 14 / 21 ) / 2;
403 x
+= horizontalBorder
;
405 width
-= horizontalBorder
*2;
408 wxSize
sizeSearch(0,0);
409 wxSize
sizeCancel(0,0);
410 int searchMargin
= 0;
411 int cancelMargin
= 0;
412 if ( m_searchButtonVisible
|| m_menu
)
414 sizeSearch
= m_searchButton
->GetBestSize();
415 searchMargin
= MARGIN
;
417 if ( m_cancelButtonVisible
)
419 sizeCancel
= m_cancelButton
->GetBestSize();
420 cancelMargin
= MARGIN
;
422 m_searchButton
->Show( m_searchButtonVisible
|| m_menu
);
423 m_cancelButton
->Show( m_cancelButtonVisible
);
425 if ( sizeSearch
.x
+ sizeCancel
.x
> width
)
427 sizeSearch
.x
= width
/2;
428 sizeCancel
.x
= width
/2;
432 wxCoord textWidth
= width
- sizeSearch
.x
- sizeCancel
.x
- searchMargin
- cancelMargin
;
434 // position the subcontrols inside the client area
436 m_searchButton
->SetSize(x
, y
+ ICON_OFFSET
, sizeSearch
.x
, height
);
437 m_text
->SetSize(x
+ sizeSearch
.x
+ searchMargin
, y
+ ICON_OFFSET
, textWidth
, height
);
438 m_cancelButton
->SetSize(x
+ sizeSearch
.x
+ searchMargin
+ textWidth
+ cancelMargin
,
439 y
+ ICON_OFFSET
, sizeCancel
.x
, height
);
446 wxString
wxSearchCtrl::GetValue() const
448 return m_text
->GetValue();
450 void wxSearchCtrl::SetValue(const wxString
& value
)
452 m_text
->SetValue(value
);
455 wxString
wxSearchCtrl::GetRange(long from
, long to
) const
457 return m_text
->GetRange(from
, to
);
460 int wxSearchCtrl::GetLineLength(long lineNo
) const
462 return m_text
->GetLineLength(lineNo
);
464 wxString
wxSearchCtrl::GetLineText(long lineNo
) const
466 return m_text
->GetLineText(lineNo
);
468 int wxSearchCtrl::GetNumberOfLines() const
470 return m_text
->GetNumberOfLines();
473 bool wxSearchCtrl::IsModified() const
475 return m_text
->IsModified();
477 bool wxSearchCtrl::IsEditable() const
479 return m_text
->IsEditable();
482 // more readable flag testing methods
483 bool wxSearchCtrl::IsSingleLine() const
485 return m_text
->IsSingleLine();
487 bool wxSearchCtrl::IsMultiLine() const
489 return m_text
->IsMultiLine();
492 // If the return values from and to are the same, there is no selection.
493 void wxSearchCtrl::GetSelection(long* from
, long* to
) const
495 m_text
->GetSelection(from
, to
);
498 wxString
wxSearchCtrl::GetStringSelection() const
500 return m_text
->GetStringSelection();
507 void wxSearchCtrl::Clear()
511 void wxSearchCtrl::Replace(long from
, long to
, const wxString
& value
)
513 m_text
->Replace(from
, to
, value
);
515 void wxSearchCtrl::Remove(long from
, long to
)
517 m_text
->Remove(from
, to
);
520 // load/save the controls contents from/to the file
521 bool wxSearchCtrl::LoadFile(const wxString
& file
)
523 return m_text
->LoadFile(file
);
525 bool wxSearchCtrl::SaveFile(const wxString
& file
)
527 return m_text
->SaveFile(file
);
530 // sets/clears the dirty flag
531 void wxSearchCtrl::MarkDirty()
535 void wxSearchCtrl::DiscardEdits()
537 m_text
->DiscardEdits();
540 // set the max number of characters which may be entered in a single line
542 void wxSearchCtrl::SetMaxLength(unsigned long len
)
544 m_text
->SetMaxLength(len
);
547 // writing text inserts it at the current position, appending always
548 // inserts it at the end
549 void wxSearchCtrl::WriteText(const wxString
& text
)
551 m_text
->WriteText(text
);
553 void wxSearchCtrl::AppendText(const wxString
& text
)
555 m_text
->AppendText(text
);
558 // insert the character which would have resulted from this key event,
559 // return true if anything has been inserted
560 bool wxSearchCtrl::EmulateKeyPress(const wxKeyEvent
& event
)
562 return m_text
->EmulateKeyPress(event
);
565 // text control under some platforms supports the text styles: these
566 // methods allow to apply the given text style to the given selection or to
567 // set/get the style which will be used for all appended text
568 bool wxSearchCtrl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
570 return m_text
->SetStyle(start
, end
, style
);
572 bool wxSearchCtrl::GetStyle(long position
, wxTextAttr
& style
)
574 return m_text
->GetStyle(position
, style
);
576 bool wxSearchCtrl::SetDefaultStyle(const wxTextAttr
& style
)
578 return m_text
->SetDefaultStyle(style
);
580 const wxTextAttr
& wxSearchCtrl::GetDefaultStyle() const
582 return m_text
->GetDefaultStyle();
585 // translate between the position (which is just an index in the text ctrl
586 // considering all its contents as a single strings) and (x, y) coordinates
587 // which represent column and line.
588 long wxSearchCtrl::XYToPosition(long x
, long y
) const
590 return m_text
->XYToPosition(x
, y
);
592 bool wxSearchCtrl::PositionToXY(long pos
, long *x
, long *y
) const
594 return m_text
->PositionToXY(pos
, x
, y
);
597 void wxSearchCtrl::ShowPosition(long pos
)
599 m_text
->ShowPosition(pos
);
602 // find the character at position given in pixels
604 // NB: pt is in device coords (not adjusted for the client area origin nor
606 wxTextCtrlHitTestResult
wxSearchCtrl::HitTest(const wxPoint
& pt
, long *pos
) const
608 return m_text
->HitTest(pt
, pos
);
610 wxTextCtrlHitTestResult
wxSearchCtrl::HitTest(const wxPoint
& pt
,
612 wxTextCoord
*row
) const
614 return m_text
->HitTest(pt
, col
, row
);
617 // Clipboard operations
618 void wxSearchCtrl::Copy()
622 void wxSearchCtrl::Cut()
626 void wxSearchCtrl::Paste()
631 bool wxSearchCtrl::CanCopy() const
633 return m_text
->CanCopy();
635 bool wxSearchCtrl::CanCut() const
637 return m_text
->CanCut();
639 bool wxSearchCtrl::CanPaste() const
641 return m_text
->CanPaste();
645 void wxSearchCtrl::Undo()
649 void wxSearchCtrl::Redo()
654 bool wxSearchCtrl::CanUndo() const
656 return m_text
->CanUndo();
658 bool wxSearchCtrl::CanRedo() const
660 return m_text
->CanRedo();
664 void wxSearchCtrl::SetInsertionPoint(long pos
)
666 m_text
->SetInsertionPoint(pos
);
668 void wxSearchCtrl::SetInsertionPointEnd()
670 m_text
->SetInsertionPointEnd();
672 long wxSearchCtrl::GetInsertionPoint() const
674 return m_text
->GetInsertionPoint();
676 wxTextPos
wxSearchCtrl::GetLastPosition() const
678 return m_text
->GetLastPosition();
681 void wxSearchCtrl::SetSelection(long from
, long to
)
683 m_text
->SetSelection(from
, to
);
685 void wxSearchCtrl::SelectAll()
690 void wxSearchCtrl::SetEditable(bool editable
)
692 m_text
->SetEditable(editable
);
695 bool wxSearchCtrl::SetFont(const wxFont
& font
)
697 bool result
= wxSearchCtrlBase::SetFont(font
);
698 if ( result
&& m_text
)
700 result
&= m_text
->SetFont(font
);
706 // search control generic only
707 void wxSearchCtrl::SetSearchBitmap( const wxBitmap
& bitmap
)
709 m_searchBitmap
= bitmap
;
710 m_searchBitmapUser
= bitmap
.Ok();
711 if ( m_searchBitmapUser
)
713 if ( m_searchButton
&& !m_menu
)
715 m_searchButton
->SetBitmapLabel( m_searchBitmap
);
720 // the user bitmap was just cleared, generate one
725 void wxSearchCtrl::SetSearchMenuBitmap( const wxBitmap
& bitmap
)
727 m_searchMenuBitmap
= bitmap
;
728 m_searchMenuBitmapUser
= bitmap
.Ok();
729 if ( m_searchMenuBitmapUser
)
731 if ( m_searchButton
&& m_menu
)
733 m_searchButton
->SetBitmapLabel( m_searchMenuBitmap
);
738 // the user bitmap was just cleared, generate one
743 void wxSearchCtrl::SetCancelBitmap( const wxBitmap
& bitmap
)
745 m_cancelBitmap
= bitmap
;
746 m_cancelBitmapUser
= bitmap
.Ok();
747 if ( m_cancelBitmapUser
)
749 if ( m_cancelButton
)
751 m_cancelButton
->SetBitmapLabel( m_cancelBitmap
);
756 // the user bitmap was just cleared, generate one
763 // override streambuf method
764 #if wxHAS_TEXT_WINDOW_STREAM
766 #endif // wxHAS_TEXT_WINDOW_STREAM
768 // stream-like insertion operators: these are always available, whether we
769 // were, or not, compiled with streambuf support
770 wxTextCtrl
& operator<<(const wxString
& s
);
771 wxTextCtrl
& operator<<(int i
);
772 wxTextCtrl
& operator<<(long i
);
773 wxTextCtrl
& operator<<(float f
);
774 wxTextCtrl
& operator<<(double d
);
775 wxTextCtrl
& operator<<(const wxChar c
);
778 void wxSearchCtrl::DoSetValue(const wxString
& value
, int flags
)
780 m_text
->ChangeValue( value
);
781 if ( flags
& SetValue_SendEvent
)
782 SendTextUpdatedEvent();
785 // do the window-specific processing after processing the update event
786 void wxSearchCtrl::DoUpdateWindowUI(wxUpdateUIEvent
& event
)
788 wxSearchCtrlBase::DoUpdateWindowUI(event
);
791 bool wxSearchCtrl::ShouldInheritColours() const
796 // icons are rendered at 3-8 times larger than necessary and downscaled for
798 static int GetMultiplier()
801 // speed up bitmap generation by using a small bitmap
804 int depth
= ::wxDisplayDepth();
814 wxBitmap
wxSearchCtrl::RenderSearchBitmap( int x
, int y
, bool renderDrop
)
816 wxColour bg
= GetBackgroundColour();
817 wxColour fg
= GetForegroundColour();
819 //===============================================================================
820 // begin drawing code
821 //===============================================================================
824 // force width:height ratio
836 // glass 11x11, top left corner
837 // handle (9,9)-(13,13)
838 // drop (13,16)-(19,6)-(16,9)
840 int multiplier
= GetMultiplier();
841 int penWidth
= multiplier
* 2;
843 penWidth
= penWidth
* x
/ 20;
845 wxBitmap
bitmap( multiplier
*x
, multiplier
*y
);
847 mem
.SelectObject(bitmap
);
850 mem
.SetBrush( wxBrush(bg
) );
851 mem
.SetPen( wxPen(bg
) );
852 mem
.DrawRectangle(0,0,bitmap
.GetWidth(),bitmap
.GetHeight());
855 mem
.SetBrush( wxBrush(fg
) );
856 mem
.SetPen( wxPen(fg
) );
857 int glassBase
= 5 * x
/ 20;
858 int glassFactor
= 2*glassBase
+ 1;
859 int radius
= multiplier
*glassFactor
/2;
860 mem
.DrawCircle(radius
,radius
,radius
);
861 mem
.SetBrush( wxBrush(bg
) );
862 mem
.SetPen( wxPen(bg
) );
863 mem
.DrawCircle(radius
,radius
,radius
-penWidth
);
866 int lineStart
= radius
+ (radius
-penWidth
/2) * 707 / 1000; // 707 / 1000 = 0.707 = 1/sqrt(2);
868 mem
.SetPen( wxPen(fg
) );
869 mem
.SetBrush( wxBrush(fg
) );
870 int handleCornerShift
= penWidth
* 707 / 1000 / 2; // 707 / 1000 = 0.707 = 1/sqrt(2);
871 handleCornerShift
= WXMAX( handleCornerShift
, 1 );
872 int handleBase
= 4 * x
/ 20;
873 int handleLength
= 2*handleBase
+1;
874 wxPoint handlePolygon
[] =
876 wxPoint(-handleCornerShift
,+handleCornerShift
),
877 wxPoint(+handleCornerShift
,-handleCornerShift
),
878 wxPoint(multiplier
*handleLength
/2+handleCornerShift
,multiplier
*handleLength
/2-handleCornerShift
),
879 wxPoint(multiplier
*handleLength
/2-handleCornerShift
,multiplier
*handleLength
/2+handleCornerShift
),
881 mem
.DrawPolygon(WXSIZEOF(handlePolygon
),handlePolygon
,lineStart
,lineStart
);
883 // draw drop triangle
884 int triangleX
= 13 * x
/ 20;
885 int triangleY
= 5 * x
/ 20;
886 int triangleBase
= 3 * x
/ 20;
887 int triangleFactor
= triangleBase
*2+1;
890 wxPoint dropPolygon
[] =
892 wxPoint(multiplier
*0,multiplier
*0), // triangle left
893 wxPoint(multiplier
*triangleFactor
-1,multiplier
*0), // triangle right
894 wxPoint(multiplier
*triangleFactor
/2,multiplier
*triangleFactor
/2), // triangle bottom
896 mem
.DrawPolygon(WXSIZEOF(dropPolygon
),dropPolygon
,multiplier
*triangleX
,multiplier
*triangleY
);
899 //===============================================================================
901 //===============================================================================
903 if ( multiplier
!= 1 )
905 wxImage image
= bitmap
.ConvertToImage();
907 bitmap
= wxBitmap( image
);
913 wxBitmap
wxSearchCtrl::RenderCancelBitmap( int x
, int y
)
915 wxColour bg
= GetBackgroundColour();
916 wxColour fg
= GetForegroundColour();
918 //===============================================================================
919 // begin drawing code
920 //===============================================================================
937 // cross line starts (4,4)-(10,10)
938 // drop (13,16)-(19,6)-(16,9)
940 int multiplier
= GetMultiplier();
942 int penWidth
= multiplier
* x
/ 14;
944 wxBitmap
bitmap( multiplier
*x
, multiplier
*y
);
946 mem
.SelectObject(bitmap
);
949 mem
.SetBrush( wxBrush(bg
) );
950 mem
.SetPen( wxPen(bg
) );
951 mem
.DrawRectangle(0,0,bitmap
.GetWidth(),bitmap
.GetHeight());
954 mem
.SetBrush( wxBrush(fg
) );
955 mem
.SetPen( wxPen(fg
) );
956 int radius
= multiplier
*x
/2;
957 mem
.DrawCircle(radius
,radius
,radius
);
960 int lineStartBase
= 4 * x
/ 14;
961 int lineLength
= x
- 2*lineStartBase
;
963 mem
.SetPen( wxPen(bg
) );
964 mem
.SetBrush( wxBrush(bg
) );
965 int handleCornerShift
= penWidth
/2;
966 handleCornerShift
= WXMAX( handleCornerShift
, 1 );
967 wxPoint handlePolygon
[] =
969 wxPoint(-handleCornerShift
,+handleCornerShift
),
970 wxPoint(+handleCornerShift
,-handleCornerShift
),
971 wxPoint(multiplier
*lineLength
+handleCornerShift
,multiplier
*lineLength
-handleCornerShift
),
972 wxPoint(multiplier
*lineLength
-handleCornerShift
,multiplier
*lineLength
+handleCornerShift
),
974 mem
.DrawPolygon(WXSIZEOF(handlePolygon
),handlePolygon
,multiplier
*lineStartBase
,multiplier
*lineStartBase
);
975 wxPoint handlePolygon2
[] =
977 wxPoint(+handleCornerShift
,+handleCornerShift
),
978 wxPoint(-handleCornerShift
,-handleCornerShift
),
979 wxPoint(multiplier
*lineLength
-handleCornerShift
,-multiplier
*lineLength
-handleCornerShift
),
980 wxPoint(multiplier
*lineLength
+handleCornerShift
,-multiplier
*lineLength
+handleCornerShift
),
982 mem
.DrawPolygon(WXSIZEOF(handlePolygon2
),handlePolygon2
,multiplier
*lineStartBase
,multiplier
*(x
-lineStartBase
));
984 //===============================================================================
986 //===============================================================================
988 if ( multiplier
!= 1 )
990 wxImage image
= bitmap
.ConvertToImage();
992 bitmap
= wxBitmap( image
);
998 void wxSearchCtrl::RecalcBitmaps()
1004 wxSize sizeText
= m_text
->GetBestSize();
1006 int bitmapHeight
= sizeText
.y
- 2 * ICON_MARGIN
;
1007 int bitmapWidth
= sizeText
.y
* 20 / 14;
1009 if ( !m_searchBitmapUser
)
1012 !m_searchBitmap
.Ok() ||
1013 m_searchBitmap
.GetHeight() != bitmapHeight
||
1014 m_searchBitmap
.GetWidth() != bitmapWidth
1017 m_searchBitmap
= RenderSearchBitmap(bitmapWidth
,bitmapHeight
,false);
1020 m_searchButton
->SetBitmapLabel(m_searchBitmap
);
1023 // else this bitmap was set by user, don't alter
1026 if ( !m_searchMenuBitmapUser
)
1029 !m_searchMenuBitmap
.Ok() ||
1030 m_searchMenuBitmap
.GetHeight() != bitmapHeight
||
1031 m_searchMenuBitmap
.GetWidth() != bitmapWidth
1034 m_searchMenuBitmap
= RenderSearchBitmap(bitmapWidth
,bitmapHeight
,true);
1037 m_searchButton
->SetBitmapLabel(m_searchMenuBitmap
);
1040 // else this bitmap was set by user, don't alter
1043 if ( !m_cancelBitmapUser
)
1046 !m_cancelBitmap
.Ok() ||
1047 m_cancelBitmap
.GetHeight() != bitmapHeight
||
1048 m_cancelBitmap
.GetWidth() != bitmapHeight
1051 m_cancelBitmap
= RenderCancelBitmap(bitmapHeight
-BORDER
,bitmapHeight
-BORDER
); // square
1052 m_cancelButton
->SetBitmapLabel(m_cancelBitmap
);
1054 // else this bitmap was set by user, don't alter
1058 void wxSearchCtrl::OnSearchButton( wxCommandEvent
& event
)
1063 void wxSearchCtrl::OnSetFocus( wxFocusEvent
& /*event*/ )
1071 void wxSearchCtrl::PopupSearchMenu()
1075 wxSize size
= GetSize();
1076 PopupMenu( m_menu
, 0, size
.y
);
1080 #endif // !USE_NATIVE_SEARCH_CONTROL
1082 #endif // wxUSE_SEARCHCTRL