combo.h 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: combo.h
  3. // Purpose: interface of wxComboCtrl and wxComboPopup
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. //
  8. // New window styles for wxComboCtrlBase
  9. //
  10. enum
  11. {
  12. // Double-clicking a read-only combo triggers call to popup's OnComboPopup.
  13. // In wxOwnerDrawnComboBox, for instance, it cycles item.
  14. wxCC_SPECIAL_DCLICK = 0x0100,
  15. // Dropbutton acts like standard push button.
  16. wxCC_STD_BUTTON = 0x0200
  17. };
  18. /**
  19. @class wxComboPopup
  20. In order to use a custom popup with wxComboCtrl, an interface class must be
  21. derived from wxComboPopup.
  22. For more information on how to use it, see @ref comboctrl_custompopup.
  23. @library{wxcore}
  24. @category{ctrl}
  25. @see wxComboCtrl
  26. */
  27. class wxComboPopup
  28. {
  29. public:
  30. /**
  31. Default constructor. It is recommended that internal variables are
  32. prepared in Init() instead (because m_combo is not valid in
  33. constructor).
  34. */
  35. wxComboPopup();
  36. /**
  37. The derived class must implement this to create the popup control.
  38. @return @true if the call succeeded, @false otherwise.
  39. */
  40. virtual bool Create(wxWindow* parent) = 0;
  41. /**
  42. You only need to implement this member function if you create
  43. your popup class in non-standard way. The default implementation can
  44. handle both multiple-inherited popup control (as seen in wxComboCtrl
  45. samples) and one allocated separately in heap.
  46. If you do completely re-implement this function, make sure it calls
  47. Destroy() for the popup control and also deletes @a this object
  48. (usually as the last thing).
  49. */
  50. virtual void DestroyPopup();
  51. /**
  52. Utility function that hides the popup.
  53. */
  54. void Dismiss();
  55. /**
  56. Implement to customize matching of value string to an item container
  57. entry.
  58. @param item
  59. String entered, usually by user or from SetValue() call.
  60. @param trueItem
  61. When item matches an entry, but the entry's string representation
  62. is not exactly the same (case mismatch, for example), then the
  63. true item string should be written back to here, if it is not
  64. a NULL pointer.
  65. @remarks
  66. Default implementation always return true and does not alter
  67. trueItem.
  68. */
  69. virtual bool FindItem(const wxString& item, wxString* trueItem=NULL);
  70. /**
  71. The derived class may implement this to return adjusted size for the
  72. popup control, according to the variables given.
  73. @param minWidth
  74. Preferred minimum width.
  75. @param prefHeight
  76. Preferred height. May be -1 to indicate no preference.
  77. @param maxHeight
  78. Max height for window, as limited by screen size.
  79. @remarks This function is called each time popup is about to be shown.
  80. */
  81. virtual wxSize GetAdjustedSize(int minWidth, int prefHeight, int maxHeight);
  82. /**
  83. Returns pointer to the associated parent wxComboCtrl.
  84. */
  85. wxComboCtrl* GetComboCtrl() const;
  86. /**
  87. The derived class must implement this to return pointer to the
  88. associated control created in Create().
  89. */
  90. virtual wxWindow* GetControl() = 0;
  91. /**
  92. The derived class must implement this to return string representation
  93. of the value.
  94. */
  95. virtual wxString GetStringValue() const = 0;
  96. /**
  97. The derived class must implement this to initialize its internal
  98. variables. This method is called immediately after construction
  99. finishes. m_combo member variable has been initialized before the call.
  100. */
  101. virtual void Init();
  102. /**
  103. Utility method that returns @true if Create has been called.
  104. Useful in conjunction with LazyCreate().
  105. */
  106. bool IsCreated() const;
  107. /**
  108. The derived class may implement this to return @true if it wants to
  109. delay call to Create() until the popup is shown for the first time. It
  110. is more efficient, but on the other hand it is often more convenient to
  111. have the control created immediately.
  112. @remarks Base implementation returns @false.
  113. */
  114. virtual bool LazyCreate();
  115. /**
  116. The derived class may implement this to do something when the parent
  117. wxComboCtrl gets double-clicked.
  118. */
  119. virtual void OnComboDoubleClick();
  120. /**
  121. The derived class may implement this to receive key events from the
  122. parent wxComboCtrl.
  123. Events not handled should be skipped, as usual.
  124. */
  125. virtual void OnComboKeyEvent(wxKeyEvent& event);
  126. /**
  127. The derived class may implement this to do special processing when
  128. popup is hidden.
  129. */
  130. virtual void OnDismiss();
  131. /**
  132. The derived class may implement this to do special processing when
  133. popup is shown.
  134. */
  135. virtual void OnPopup();
  136. /**
  137. The derived class may implement this to paint the parent wxComboCtrl.
  138. Default implementation draws value as string.
  139. */
  140. virtual void PaintComboControl(wxDC& dc, const wxRect& rect);
  141. /**
  142. The derived class must implement this to receive string value changes
  143. from wxComboCtrl.
  144. */
  145. virtual void SetStringValue(const wxString& value);
  146. protected:
  147. /**
  148. Parent wxComboCtrl. This member variable is prepared automatically
  149. before Init() is called.
  150. */
  151. wxComboCtrl* m_combo;
  152. };
  153. /**
  154. Features enabled for wxComboCtrl.
  155. @see wxComboCtrl::GetFeatures()
  156. */
  157. struct wxComboCtrlFeatures
  158. {
  159. enum
  160. {
  161. MovableButton = 0x0001, ///< Button can be on either side of control.
  162. BitmapButton = 0x0002, ///< Button may be replaced with bitmap.
  163. ButtonSpacing = 0x0004, ///< Button can have spacing from the edge
  164. ///< of the control.
  165. TextIndent = 0x0008, ///< wxComboCtrl::SetMargins() can be used.
  166. PaintControl = 0x0010, ///< Combo control itself can be custom painted.
  167. PaintWritable = 0x0020, ///< A variable-width area in front of writable
  168. ///< combo control's textctrl can be custom
  169. ///< painted.
  170. Borderless = 0x0040, ///< wxNO_BORDER window style works.
  171. All = MovableButton | BitmapButton | ButtonSpacing |
  172. TextIndent | PaintControl | PaintWritable |
  173. Borderless ///< All features.
  174. };
  175. };
  176. /**
  177. @class wxComboCtrl
  178. A combo control is a generic combobox that allows totally custom popup. In
  179. addition it has other customization features. For instance, position and
  180. size of the dropdown button can be changed.
  181. @section comboctrl_custompopup Setting Custom Popup for wxComboCtrl
  182. wxComboCtrl needs to be told somehow which control to use and this is done
  183. by SetPopupControl(). However, we need something more than just a wxControl
  184. in this method as, for example, we need to call
  185. SetStringValue("initial text value") and wxControl doesn't have such
  186. method. So we also need a wxComboPopup which is an interface which must be
  187. implemented by a control to be usable as a popup.
  188. We couldn't derive wxComboPopup from wxControl as this would make it
  189. impossible to have a class deriving from a wxWidgets control and from it,
  190. so instead it is just a mix-in.
  191. Here's a minimal sample of wxListView popup:
  192. @code
  193. #include <wx/combo.h>
  194. #include <wx/listctrl.h>
  195. class wxListViewComboPopup : public wxListView, public wxComboPopup
  196. {
  197. public:
  198. // Initialize member variables
  199. virtual void Init()
  200. {
  201. m_value = -1;
  202. }
  203. // Create popup control
  204. virtual bool Create(wxWindow* parent)
  205. {
  206. return wxListView::Create(parent,1,wxPoint(0,0),wxDefaultSize);
  207. }
  208. // Return pointer to the created control
  209. virtual wxWindow *GetControl() { return this; }
  210. // Translate string into a list selection
  211. virtual void SetStringValue(const wxString& s)
  212. {
  213. int n = wxListView::FindItem(-1,s);
  214. if ( n >= 0 && n < wxListView::GetItemCount() )
  215. wxListView::Select(n);
  216. }
  217. // Get list selection as a string
  218. virtual wxString GetStringValue() const
  219. {
  220. if ( m_value >= 0 )
  221. return wxListView::GetItemText(m_value);
  222. return wxEmptyString;
  223. }
  224. // Do mouse hot-tracking (which is typical in list popups)
  225. void OnMouseMove(wxMouseEvent& event)
  226. {
  227. // TODO: Move selection to cursor
  228. }
  229. // On mouse left up, set the value and close the popup
  230. void OnMouseClick(wxMouseEvent& WXUNUSED(event))
  231. {
  232. m_value = wxListView::GetFirstSelected();
  233. // TODO: Send event as well
  234. Dismiss();
  235. }
  236. protected:
  237. int m_value; // current item index
  238. private:
  239. wxDECLARE_EVENT_TABLE();
  240. };
  241. wxBEGIN_EVENT_TABLE(wxListViewComboPopup, wxListView)
  242. EVT_MOTION(wxListViewComboPopup::OnMouseMove)
  243. EVT_LEFT_UP(wxListViewComboPopup::OnMouseClick)
  244. wxEND_EVENT_TABLE()
  245. @endcode
  246. Here's how you would create and populate it in a dialog constructor:
  247. @code
  248. wxComboCtrl* comboCtrl = new wxComboCtrl(this, wxID_ANY, wxEmptyString);
  249. wxListViewComboPopup* popupCtrl = new wxListViewComboPopup();
  250. // It is important to call SetPopupControl() as soon as possible
  251. comboCtrl->SetPopupControl(popupCtrl);
  252. // Populate using wxListView methods
  253. popupCtrl->InsertItem(popupCtrl->GetItemCount(), "First Item");
  254. popupCtrl->InsertItem(popupCtrl->GetItemCount(), "Second Item");
  255. popupCtrl->InsertItem(popupCtrl->GetItemCount(), "Third Item");
  256. @endcode
  257. @beginStyleTable
  258. @style{wxCB_READONLY}
  259. Text will not be editable.
  260. @style{wxCB_SORT}
  261. Sorts the entries in the list alphabetically.
  262. @style{wxTE_PROCESS_ENTER}
  263. The control will generate the event @c wxEVT_TEXT_ENTER
  264. (otherwise pressing Enter key is either processed internally by the
  265. control or used for navigation between dialog controls). Windows
  266. only.
  267. @style{wxCC_SPECIAL_DCLICK}
  268. Double-clicking triggers a call to popup's OnComboDoubleClick.
  269. Actual behaviour is defined by a derived class. For instance,
  270. wxOwnerDrawnComboBox will cycle an item. This style only applies if
  271. wxCB_READONLY is used as well.
  272. @style{wxCC_STD_BUTTON}
  273. Drop button will behave more like a standard push button.
  274. @endStyleTable
  275. @beginEventEmissionTable{wxCommandEvent}
  276. @event{EVT_TEXT(id, func)}
  277. Process a @c wxEVT_TEXT event, when the text changes.
  278. @event{EVT_TEXT_ENTER(id, func)}
  279. Process a @c wxEVT_TEXT_ENTER event, when RETURN is pressed in
  280. the combo control.
  281. @event{EVT_COMBOBOX_DROPDOWN(id, func)}
  282. Process a @c wxEVT_COMBOBOX_DROPDOWN event, which is generated
  283. when the popup window is shown (drops down).
  284. @event{EVT_COMBOBOX_CLOSEUP(id, func)}
  285. Process a @c wxEVT_COMBOBOX_CLOSEUP event, which is generated
  286. when the popup window of the combo control disappears (closes up).
  287. You should avoid adding or deleting items in this event.
  288. @endEventTable
  289. @library{wxcore}
  290. @category{ctrl}
  291. @appearance{comboctrl}
  292. @see wxComboBox, wxChoice, wxOwnerDrawnComboBox, wxComboPopup,
  293. wxCommandEvent
  294. */
  295. class wxComboCtrl : public wxControl,
  296. public wxTextEntry
  297. {
  298. public:
  299. /**
  300. Default constructor.
  301. */
  302. wxComboCtrl();
  303. /**
  304. Constructor, creating and showing a combo control.
  305. @param parent
  306. Parent window. Must not be @NULL.
  307. @param id
  308. Window identifier. The value wxID_ANY indicates a default value.
  309. @param value
  310. Initial selection string. An empty string indicates no selection.
  311. @param pos
  312. Window position.
  313. If ::wxDefaultPosition is specified then a default position is chosen.
  314. @param size
  315. Window size.
  316. If ::wxDefaultSize is specified then the window is sized appropriately.
  317. @param style
  318. Window style. See wxComboCtrl.
  319. @param validator
  320. Window validator.
  321. @param name
  322. Window name.
  323. @see Create(), wxValidator
  324. */
  325. wxComboCtrl(wxWindow* parent, wxWindowID id = wxID_ANY,
  326. const wxString& value = wxEmptyString,
  327. const wxPoint& pos = wxDefaultPosition,
  328. const wxSize& size = wxDefaultSize,
  329. long style = 0,
  330. const wxValidator& validator = wxDefaultValidator,
  331. const wxString& name = wxComboBoxNameStr);
  332. /**
  333. Destructor, destroying the combo control.
  334. */
  335. virtual ~wxComboCtrl();
  336. /**
  337. Copies the selected text to the clipboard.
  338. */
  339. virtual void Copy();
  340. /**
  341. Creates the combo control for two-step construction. Derived classes
  342. should call or replace this function. See wxComboCtrl() for further
  343. details.
  344. */
  345. bool Create(wxWindow* parent, wxWindowID id = wxID_ANY,
  346. const wxString& value = wxEmptyString,
  347. const wxPoint& pos = wxDefaultPosition,
  348. const wxSize& size = wxDefaultSize,
  349. long style = 0,
  350. const wxValidator& validator = wxDefaultValidator,
  351. const wxString& name = wxComboBoxNameStr);
  352. /**
  353. Copies the selected text to the clipboard and removes the selection.
  354. */
  355. virtual void Cut();
  356. /**
  357. Dismisses the popup window.
  358. Notice that calling this function will generate a
  359. @c wxEVT_COMBOBOX_CLOSEUP event.
  360. @since 2.9.2
  361. */
  362. virtual void Dismiss();
  363. /**
  364. Enables or disables popup animation, if any, depending on the value of
  365. the argument.
  366. */
  367. void EnablePopupAnimation(bool enable = true);
  368. /**
  369. Returns true if given key combination should toggle the popup.
  370. */
  371. virtual bool IsKeyPopupToggle(const wxKeyEvent& event) const;
  372. /**
  373. Prepare background of combo control or an item in a dropdown list in a
  374. way typical on platform. This includes painting the focus/disabled
  375. background and setting the clipping region.
  376. Unless you plan to paint your own focus indicator, you should always
  377. call this in your wxComboPopup::PaintComboControl implementation. In
  378. addition, it sets pen and text colour to what looks good and proper
  379. against the background.
  380. flags: wxRendererNative flags:
  381. wxCONTROL_ISSUBMENU: is drawing a list item instead of combo control
  382. wxCONTROL_SELECTED: list item is selected
  383. wxCONTROL_DISABLED: control/item is disabled
  384. */
  385. virtual void PrepareBackground( wxDC& dc, const wxRect& rect, int flags ) const;
  386. /**
  387. Returns true if focus indicator should be drawn in the control.
  388. */
  389. bool ShouldDrawFocus() const;
  390. /**
  391. Returns disabled button bitmap that has been set with
  392. SetButtonBitmaps().
  393. @return A reference to the disabled state bitmap.
  394. */
  395. const wxBitmap& GetBitmapDisabled() const;
  396. /**
  397. Returns button mouse hover bitmap that has been set with
  398. SetButtonBitmaps().
  399. @return A reference to the mouse hover state bitmap.
  400. */
  401. const wxBitmap& GetBitmapHover() const;
  402. /**
  403. Returns default button bitmap that has been set with
  404. SetButtonBitmaps().
  405. @return A reference to the normal state bitmap.
  406. */
  407. const wxBitmap& GetBitmapNormal() const;
  408. /**
  409. Returns depressed button bitmap that has been set with
  410. SetButtonBitmaps().
  411. @return A reference to the depressed state bitmap.
  412. */
  413. const wxBitmap& GetBitmapPressed() const;
  414. /**
  415. Returns current size of the dropdown button.
  416. */
  417. wxSize GetButtonSize();
  418. /**
  419. Returns custom painted area in control.
  420. @see SetCustomPaintWidth().
  421. */
  422. int GetCustomPaintWidth() const;
  423. /**
  424. Returns features supported by wxComboCtrl. If needed feature is
  425. missing, you need to instead use wxGenericComboCtrl, which however may
  426. lack a native look and feel (but otherwise sports identical API).
  427. @return Value returned is a combination of the flags defined in
  428. wxComboCtrlFeatures.
  429. */
  430. static int GetFeatures();
  431. /**
  432. Returns the current hint string.
  433. See SetHint() for more information about hints.
  434. @since 2.9.1
  435. */
  436. virtual wxString GetHint() const;
  437. /**
  438. Returns the insertion point for the combo control's text field.
  439. @note Under Windows, this function always returns 0 if the combo
  440. control doesn't have the focus.
  441. */
  442. virtual long GetInsertionPoint() const;
  443. /**
  444. Returns the last position in the combo control text field.
  445. */
  446. virtual long GetLastPosition() const;
  447. /**
  448. Returns the margins used by the control. The @c x field of the returned
  449. point is the horizontal margin and the @c y field is the vertical one.
  450. @remarks If given margin cannot be accurately determined, its value
  451. will be set to -1.
  452. @see SetMargins()
  453. @since 2.9.1
  454. */
  455. wxPoint GetMargins() const;
  456. /**
  457. Returns current popup interface that has been set with
  458. SetPopupControl().
  459. */
  460. wxComboPopup* GetPopupControl();
  461. /**
  462. Returns popup window containing the popup control.
  463. */
  464. wxWindow* GetPopupWindow() const;
  465. /**
  466. Get the text control which is part of the combo control.
  467. */
  468. wxTextCtrl* GetTextCtrl() const;
  469. /**
  470. Returns actual indentation in pixels.
  471. @deprecated Use GetMargins() instead.
  472. */
  473. wxCoord GetTextIndent() const;
  474. /**
  475. Returns area covered by the text field (includes everything except
  476. borders and the dropdown button).
  477. */
  478. const wxRect& GetTextRect() const;
  479. /**
  480. Returns text representation of the current value. For writable combo
  481. control it always returns the value in the text field.
  482. */
  483. virtual wxString GetValue() const;
  484. /**
  485. Dismisses the popup window.
  486. @param generateEvent
  487. Set this to @true in order to generate
  488. @c wxEVT_COMBOBOX_CLOSEUP event.
  489. @deprecated Use Dismiss() instead.
  490. */
  491. virtual void HidePopup(bool generateEvent=false);
  492. /**
  493. Returns @true if the popup is currently shown
  494. */
  495. bool IsPopupShown() const;
  496. /**
  497. Returns @true if the popup window is in the given state. Possible
  498. values are:
  499. @beginTable
  500. @row2col{wxComboCtrl::Hidden, Popup window is hidden.}
  501. @row2col{wxComboCtrl::Animating, Popup window is being shown, but the
  502. popup animation has not yet finished.}
  503. @row2col{wxComboCtrl::Visible, Popup window is fully visible.}
  504. @endTable
  505. */
  506. bool IsPopupWindowState(int state) const;
  507. /**
  508. Implement in a derived class to define what happens on dropdown button
  509. click. Default action is to show the popup.
  510. @note If you implement this to do something else than show the popup,
  511. you must then also implement DoSetPopupControl() to always return
  512. @NULL.
  513. */
  514. virtual void OnButtonClick();
  515. /**
  516. Pastes text from the clipboard to the text field.
  517. */
  518. virtual void Paste();
  519. /**
  520. Shows the popup portion of the combo control.
  521. Notice that calling this function will generate a
  522. @c wxEVT_COMBOBOX_DROPDOWN event.
  523. @since 2.9.2
  524. */
  525. virtual void Popup();
  526. /**
  527. Removes the text between the two positions in the combo control text
  528. field.
  529. @param from
  530. The first position.
  531. @param to
  532. The last position.
  533. */
  534. virtual void Remove(long from, long to);
  535. /**
  536. Replaces the text between two positions with the given text, in the
  537. combo control text field.
  538. @param from
  539. The first position.
  540. @param to
  541. The second position.
  542. @param text
  543. The text to insert.
  544. */
  545. virtual void Replace(long from, long to, const wxString& text);
  546. /**
  547. Sets custom dropdown button graphics.
  548. @param bmpNormal
  549. Default button image.
  550. @param pushButtonBg
  551. If @true, blank push button background is painted below the image.
  552. @param bmpPressed
  553. Depressed button image.
  554. @param bmpHover
  555. Button image when mouse hovers above it. This should be ignored on
  556. platforms and themes that do not generally draw different kind of
  557. button on mouse hover.
  558. @param bmpDisabled
  559. Disabled button image.
  560. */
  561. void SetButtonBitmaps(const wxBitmap& bmpNormal,
  562. bool pushButtonBg = false,
  563. const wxBitmap& bmpPressed = wxNullBitmap,
  564. const wxBitmap& bmpHover = wxNullBitmap,
  565. const wxBitmap& bmpDisabled = wxNullBitmap);
  566. /**
  567. Sets size and position of dropdown button.
  568. @param width
  569. Button width. Value = 0 specifies default.
  570. @param height
  571. Button height. Value = 0 specifies default.
  572. @param side
  573. Indicates which side the button will be placed. Value can be wxLEFT
  574. or wxRIGHT.
  575. @param spacingX
  576. Horizontal spacing around the button. Default is 0.
  577. */
  578. void SetButtonPosition(int width = -1, int height = -1,
  579. int side = wxRIGHT, int spacingX = 0);
  580. /**
  581. Set width, in pixels, of custom painted area in control without
  582. @c wxCB_READONLY style. In read-only wxOwnerDrawnComboBox, this is used
  583. to indicate area that is not covered by the focus rectangle.
  584. */
  585. void SetCustomPaintWidth(int width);
  586. /**
  587. Sets a hint shown in an empty unfocused combo control.
  588. Notice that hints are known as <em>cue banners</em> under MSW or
  589. <em>placeholder strings</em> under OS X.
  590. @see wxTextEntry::SetHint()
  591. @since 2.9.1
  592. */
  593. virtual bool SetHint(const wxString& hint);
  594. /**
  595. Sets the insertion point in the text field.
  596. @param pos
  597. The new insertion point.
  598. */
  599. virtual void SetInsertionPoint(long pos);
  600. /**
  601. Sets the insertion point at the end of the combo control text field.
  602. */
  603. virtual void SetInsertionPointEnd();
  604. //@{
  605. /**
  606. Attempts to set the control margins. When margins are given as wxPoint,
  607. x indicates the left and y the top margin. Use -1 to indicate that
  608. an existing value should be used.
  609. @return
  610. @true if setting of all requested margins was successful.
  611. @since 2.9.1
  612. */
  613. bool SetMargins(const wxPoint& pt);
  614. bool SetMargins(wxCoord left, wxCoord top = -1);
  615. //@}
  616. /**
  617. Set side of the control to which the popup will align itself. Valid
  618. values are @c wxLEFT, @c wxRIGHT and 0. The default value 0 means that
  619. the most appropriate side is used (which, currently, is always
  620. @c wxLEFT).
  621. */
  622. void SetPopupAnchor(int anchorSide);
  623. /**
  624. Set popup interface class derived from wxComboPopup. This method should
  625. be called as soon as possible after the control has been created,
  626. unless OnButtonClick() has been overridden.
  627. */
  628. void SetPopupControl(wxComboPopup* popup);
  629. /**
  630. Extends popup size horizontally, relative to the edges of the combo
  631. control.
  632. @param extLeft
  633. How many pixel to extend beyond the left edge of the control.
  634. Default is 0.
  635. @param extRight
  636. How many pixel to extend beyond the right edge of the control.
  637. Default is 0.
  638. @remarks Popup minimum width may override arguments. It is up to the
  639. popup to fully take this into account.
  640. */
  641. void SetPopupExtents(int extLeft, int extRight);
  642. /**
  643. Sets preferred maximum height of the popup.
  644. @remarks Value -1 indicates the default.
  645. */
  646. void SetPopupMaxHeight(int height);
  647. /**
  648. Sets minimum width of the popup. If wider than combo control, it will
  649. extend to the left.
  650. @remarks Value -1 indicates the default. Also, popup implementation may
  651. choose to ignore this.
  652. */
  653. void SetPopupMinWidth(int width);
  654. /**
  655. Selects the text between the two positions, in the combo control text
  656. field.
  657. @param from
  658. The first position.
  659. @param to
  660. The second position.
  661. */
  662. virtual void SetSelection(long from, long to);
  663. /**
  664. Sets the text for the text field without affecting the popup. Thus,
  665. unlike SetValue(), it works equally well with combo control using
  666. @c wxCB_READONLY style.
  667. */
  668. void SetText(const wxString& value);
  669. /**
  670. Set a custom window style for the embedded wxTextCtrl. Usually you
  671. will need to use this during two-step creation, just before Create().
  672. For example:
  673. @code
  674. wxComboCtrl* comboCtrl = new wxComboCtrl();
  675. // Let's make the text right-aligned
  676. comboCtrl->SetTextCtrlStyle(wxTE_RIGHT);
  677. comboCtrl->Create(parent, wxID_ANY, wxEmptyString);
  678. @endcode
  679. */
  680. void SetTextCtrlStyle( int style );
  681. /**
  682. This will set the space in pixels between left edge of the control and
  683. the text, regardless whether control is read-only or not. Value -1 can
  684. be given to indicate platform default.
  685. @deprecated Use SetMargins() instead.
  686. */
  687. void SetTextIndent(int indent);
  688. /**
  689. Sets the text for the combo control text field.
  690. @note For a combo control with @c wxCB_READONLY style the string must
  691. be accepted by the popup (for instance, exist in the dropdown
  692. list), otherwise the call to SetValue() is ignored.
  693. */
  694. virtual void SetValue(const wxString& value);
  695. /**
  696. Changes value of the control as if user had done it by selecting an
  697. item from a combo box drop-down list.
  698. */
  699. void SetValueByUser(const wxString& value);
  700. /**
  701. Show the popup.
  702. @deprecated Use Popup() instead.
  703. */
  704. virtual void ShowPopup();
  705. /**
  706. Undoes the last edit in the text field. Windows only.
  707. */
  708. virtual void Undo();
  709. /**
  710. Enable or disable usage of an alternative popup window, which
  711. guarantees ability to focus the popup control, and allows common native
  712. controls to function normally. This alternative popup window is usually
  713. a wxDialog, and as such, when it is shown, its parent top-level window
  714. will appear as if the focus has been lost from it.
  715. */
  716. void UseAltPopupWindow(bool enable = true);
  717. protected:
  718. /**
  719. This member function is not normally called in application code.
  720. Instead, it can be implemented in a derived class to create a custom
  721. popup animation.
  722. The parameters are the same as those for DoShowPopup().
  723. @return @true if animation finishes before the function returns,
  724. @false otherwise. In the latter case you need to manually call
  725. DoShowPopup() after the animation ends.
  726. */
  727. virtual bool AnimateShow(const wxRect& rect, int flags);
  728. /**
  729. This member function is not normally called in application code.
  730. Instead, it can be implemented in a derived class to return default
  731. wxComboPopup, in case @a popup is @NULL.
  732. @note If you have implemented OnButtonClick() to do something else than
  733. show the popup, then DoSetPopupControl() must always set @a popup
  734. to @NULL.
  735. */
  736. virtual void DoSetPopupControl(wxComboPopup* popup);
  737. /**
  738. This member function is not normally called in application code.
  739. Instead, it must be called in a derived class to make sure popup is
  740. properly shown after a popup animation has finished (but only if
  741. AnimateShow() did not finish the animation within its function scope).
  742. @param rect
  743. Position to show the popup window at, in screen coordinates.
  744. @param flags
  745. Combination of any of the following:
  746. @beginTable
  747. @row2col{wxComboCtrl::ShowAbove,
  748. Popup is shown above the control instead of below.}
  749. @row2col{wxComboCtrl::CanDeferShow,
  750. Showing the popup can be deferred to happen sometime after
  751. ShowPopup() has finished. In this case, AnimateShow() must
  752. return false.}
  753. @endTable
  754. */
  755. virtual void DoShowPopup(const wxRect& rect, int flags);
  756. };