1
/////////////////////////////////////////////////////////////////////////////
3
// Purpose: wxCustomControls (v1.0.8)
4
// Author: Jaakko Salli
6
// Created: Oct-24-2004
8
// Copyright: (c) Jaakko Salli
9
// Licence: wxWindows license
10
/////////////////////////////////////////////////////////////////////////////
12
#ifndef __WX_CUSTCTRL_H__
13
#define __WX_CUSTCTRL_H__
15
#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
16
#pragma interface "custctrl.cpp"
20
#ifndef _WX_WINDOW_H_BASE_
21
# include "cc_dox_mainpage.h"
24
// -----------------------------------------------------------------------
28
#include "wx/renderer.h"
30
// -----------------------------------------------------------------------
32
#if defined(WXMAKINGDLL_CUSTCTRL) || defined(WXMAKINGDLL_PROPGRID)
33
#define WXDLLIMPEXP_CC WXEXPORT
34
//#elif defined(WXUSINGDLL)
35
// #define WXDLLIMPEXP_CC WXIMPORT
36
#else // not making nor using DLL
37
#define WXDLLIMPEXP_CC
40
// If given in button renderer flags, then popup arrow
41
// is drawn on it as well.
42
#define wxCONTROL_POPUP_ARROW wxCONTROL_CHECKED
44
// -----------------------------------------------------------------------
47
// Here are some platform dependent defines
48
// (more in custctrl.cpp)
51
#if defined(__WXMSW__)
55
# include "wx/msw/uxtheme.h"
58
#define wxCC_CUSTOM_IMAGE_MARGIN1 2 // before image
59
#define wxCC_CUSTOM_IMAGE_MARGIN2 7 // after image
61
#define wxCC_TEXTCTRL_YSPACING 2
62
#define wxCC_TEXTCTRL_XSPACING 3
64
#define wxCC_USE_POPUPWIN 1 // 1 if wxPopupWindow can be used.
66
#elif defined(__WXGTK__)
69
#define wxCC_CUSTOM_IMAGE_MARGIN1 2 // before image
70
#define wxCC_CUSTOM_IMAGE_MARGIN2 7 // after image
72
#define wxCC_TEXTCTRL_YSPACING 2
73
#define wxCC_TEXTCTRL_XSPACING 3
75
// Disabled because no proper border support.
76
#define wxCC_USE_POPUPWIN 0 // 1 if wxPopupWindow can be used.
78
#elif defined(__WXMAC__)
81
#define wxCC_CUSTOM_IMAGE_MARGIN1 2 // before image
82
#define wxCC_CUSTOM_IMAGE_MARGIN2 7 // after image
84
#define wxCC_TEXTCTRL_YSPACING 2
85
#define wxCC_TEXTCTRL_XSPACING 3
87
#define wxCC_USE_POPUPWIN 1 // 1 if wxPopupWindow can be used.
92
#define wxCC_CUSTOM_IMAGE_MARGIN1 2 // before image
93
#define wxCC_CUSTOM_IMAGE_MARGIN2 7 // after image
95
#define wxCC_TEXTCTRL_YSPACING 2
96
#define wxCC_TEXTCTRL_XSPACING 3
98
#define wxCC_USE_POPUPWIN 0 // 1 if wxPopupWindow can be used.
102
// Conform to wxUSE_POPUPWIN
104
# undef wxCC_USE_POPUPWIN
105
# define wxCC_USE_POPUPWIN 0
108
/** If 1, then controls will be moved according to scrolling
109
(does not work exactly, so 0 is recommended value).
111
#define wxCC_CORRECT_CONTROL_POSITION 0
113
#if !wxPG_USE_CUSTOM_CONTROLS
114
# undef wxCC_CUSTOM_IMAGE_MARGIN1
115
# undef wxCC_CUSTOM_IMAGE_MARGIN2
118
#if wxPG_USE_CUSTOM_CONTROLS
120
// -----------------------------------------------------------------------
123
class WXDLLIMPEXP_CC wxCustomControl;
124
class WXDLLIMPEXP_CC wxCCustomTextCtrl;
125
class WXDLLIMPEXP_CC wxCCustomButton;
126
class WXDLLIMPEXP_CC wxCCustomComboBox;
127
class WXDLLIMPEXP_CC wxCCustomComboBoxHandler;
128
class WXDLLIMPEXP_CC wxCustomControlManager;
131
// -----------------------------------------------------------------------
133
/** Each wxCustomControl uses 1+ wxCustomControlHandler.
135
class WXDLLIMPEXP_CC wxCustomControlHandler
139
inline void SetControl ( wxCustomControl* pctrl )
144
inline wxCustomControl* GetControl() const { return m_control; }
145
inline bool IsMouseFocused() const;
146
inline void Move ( int x, int y ) { m_rect.x = x; m_rect.y = y; }
147
inline void SetSize ( int width, int height ) { m_rect.width = width; m_rect.height = height; }
149
inline void SetSize ( const wxPoint& pos, const wxSize& sz )
151
m_rect.x = pos.x; m_rect.y = pos.y;
152
m_rect.width = sz.x; m_rect.height = sz.y;
155
inline const wxRect& GetRect() const { return m_rect; }
157
inline void ClearFlag( long flag ) { m_flags &= ~(flag); }
158
inline void SetFlag( long flag ) { m_flags |= flag; }
160
void Create ( wxCustomControl* pctrl, const wxPoint& pos, const wxSize& sz );
163
wxCustomControl* m_control;
165
long m_flags; // barely needed
168
// -----------------------------------------------------------------------
170
class WXDLLIMPEXP_CC wxCustomTextCtrlHandler : public wxCustomControlHandler
174
void Create ( wxCustomControl* pctrl, const wxPoint& pos, const wxSize& sz,
175
const wxString& value );
177
void Draw ( wxDC& dc, const wxRect& rect );
179
bool OnKeyEvent ( wxKeyEvent& event );
181
bool OnMouseEvent ( wxMouseEvent& event );
183
int HitTest ( wxCoord x, int* pCol );
185
bool SetInsertionPoint ( long pos, long first_visible );
187
bool SetSelection ( long from, long to );
189
void SetValue ( const wxString& value );
191
inline int GetPosition () const
196
inline const wxString& GetValue() const { return m_text; }
198
// like DEL key was pressed
199
void DeleteSelection ();
206
//wxString m_textAtPos; // text that begins at position
207
unsigned int m_position;
208
unsigned int m_scrollPosition;
211
int m_itemButDown; // dragging centers around this
213
wxArrayInt m_arrExtents; // cached array of text extents
215
int UpdateExtentCache ( wxString& tempstr, size_t index );
219
// -----------------------------------------------------------------------
221
class WXDLLIMPEXP_CC wxCCustomButtonHandler : public wxCustomControlHandler
223
friend class wxCCustomButton;
226
void Draw ( wxDC& dc, const wxRect& rect );
228
bool OnMouseEvent ( wxMouseEvent& event );
230
inline void SetButtonState ( int state ) { m_down = (unsigned char)state; }
234
unsigned char m_down; // 0 means button is up
238
// -----------------------------------------------------------------------
240
#if wxCC_USE_POPUPWIN
241
# include "wx/popupwin.h"
242
# define wxCustomComboPopupBase wxPopupWindow
244
# define wxCustomComboPopupBase wxWindow
247
class WXDLLIMPEXP_CC wxCustomComboItem
251
virtual ~wxCustomComboItem();
255
// -----------------------------------------------------------------------
257
class WXDLLIMPEXP_CC wxCustomComboPopup : public wxCustomComboPopupBase
259
friend class wxCustomControlManager;
261
wxCustomComboPopup ();
262
virtual ~wxCustomComboPopup();
264
bool Create ( wxWindow* frame, wxCCustomComboBoxHandler* data,
265
const wxRect& ctrl_rect, wxCustomControl* ctrl,
266
const wxSize& size, int sizealign );
268
/*#if wxCC_USE_POPUPWIN
269
inline wxScrolledWindow* GetWindow() const { return m_subWindow; };
271
inline wxScrolledWindow* GetWindow() { return this; };
274
// kbscroll allows forcing to scroll one item at a time.
275
virtual void ShowItem ( const wxCustomComboItem& item, bool kbscroll = FALSE ) = 0;
276
virtual void OnKeyEvent ( wxKeyEvent& event ) = 0;
277
//virtual void SetSelection ( const wxCustomComboItem& item ) = 0;
281
inline wxCustomControl* GetControl () const { return m_control; }
284
void OnMouseEntry( wxMouseEvent& event );
287
wxCustomControl* m_control;
288
wxCustomControlManager* m_manager;
289
wxCCustomComboBoxHandler* m_chData;
291
wxArrayPtrVoid m_labels; // holds pointers to labels
295
unsigned char m_orientation;
297
//unsigned char m_entryStatus;
299
DECLARE_EVENT_TABLE()
302
// -----------------------------------------------------------------------
304
class WXDLLIMPEXP_CC wxCustomComboListItem : public wxCustomComboItem
307
wxCustomComboListItem();
308
wxCustomComboListItem( int index ) { m_index = index; }
309
virtual ~wxCustomComboListItem();
316
// -----------------------------------------------------------------------
318
#include "wx/scrolbar.h"
320
class WXDLLIMPEXP_CC wxComboPopupDefaultList : public wxCustomComboPopup
323
wxComboPopupDefaultList ( wxWindow* frame, wxCCustomComboBoxHandler* data,
324
const wxRect& rect, wxCustomControl* ctrl );
325
virtual ~wxComboPopupDefaultList();
327
virtual void ShowItem ( const wxCustomComboItem& item, bool kbscroll = FALSE );
329
inline void ShowItem ( int index, bool kbscroll = FALSE )
331
wxCustomComboListItem item(index);
332
ShowItem (item,kbscroll);
335
//virtual void SetSelection ( const wxCustomComboItem& item );
337
virtual void OnKeyEvent ( wxKeyEvent& event );
339
int HitTest ( int y );
341
inline void DrawItem ( int index )
343
wxCustomComboListItem item(index);
346
void DrawItem ( const wxCustomComboItem& item );
347
void DrawItem ( wxDC& dc, wxRect& r, unsigned int index );
349
void OnMouseWheelEvent ( wxMouseEvent& event );
351
void OnPaint ( wxPaintEvent& event );
353
void OnMouseDown ( wxMouseEvent& event );
354
void OnMouseMove ( wxMouseEvent& event );
355
void OnScrollEvent ( wxScrollEvent& event );
357
void SetViewStart ( int index, bool adjust_sb );
358
void RecheckHilighted ( int y );
360
//void OnMouseUp ( wxMouseEvent& event );
362
//void SetImagePaintFunction ( wxCustomPaintFunc paintfunc ) { m_paintFunc = paintfunc; }
369
// Scrolling related.
370
wxScrollBar* m_pScrollBar;
373
int m_viewStartIndex;
377
DECLARE_EVENT_TABLE()
380
// -----------------------------------------------------------------------
382
typedef wxSize (*wxCustomPaintFunc) ( wxDC&, const wxRect&, int, void* );
384
class WXDLLIMPEXP_CC wxCustomComboPopup;
385
class WXDLLIMPEXP_CC wxCustomComboItem;
386
class WXDLLIMPEXP_CC wxComboPopupDefaultList;
388
class WXDLLIMPEXP_CC wxCCustomComboBoxHandler : public wxCustomControlHandler
390
friend class wxCCustomComboBox;
391
friend class wxCustomComboPopup;
393
void Create ( wxCustomControl* pctrl, const wxString& value,
394
const wxPoint& pos, const wxSize& sz );
396
inline void SetControl ( wxCustomControl* pctrl )
398
wxCustomControlHandler::SetControl ( pctrl );
399
m_btData.SetControl ( pctrl );
402
virtual void SetSelection ( const wxCustomComboItem& item ) = 0;
404
void Draw ( wxDC& dc, const wxRect& rect, bool item_too );
406
inline wxCustomComboPopup* GetPopupInstance () const
408
return m_listInstance;
411
virtual void OnSelect ( const wxCustomComboItem& item ) = 0;
413
inline void IntOnSelect ( int index )
415
wxCustomComboListItem item(index);
419
virtual bool OnKeyEvent ( wxKeyEvent& event ) = 0;
421
virtual wxCustomComboPopup* CreatePopup ( wxWindow* frame,
422
const wxRect& ctrl_rect, wxCustomControl* ctrl ) = 0;
424
virtual bool OnMouseEvent ( wxMouseEvent& event, wxCustomControlHandler* pdata );
426
inline void Move ( int x, int y )
428
m_rect.x = x; m_rect.y = y;
429
m_btData.Move ( x + m_rect.width - m_buttonWidth, y );
431
inline void SetSize ( int width, int height )
433
m_rect.width = width - m_buttonWidth;
434
m_rect.height = height;
435
m_btData.Move ( m_rect.x + width - m_buttonWidth, m_rect.y );
436
m_btData.SetSize ( m_buttonWidth, height );
439
//inline const wxArrayPtrVoid& GetLabels() const { return m_labels; }
440
inline wxCustomPaintFunc GetPaintFunc() const { return m_paintfunc; }
441
inline void* GetPaintFuncCustomData() const { return m_paintfunc_customdata; }
442
inline const wxSize& GetImageSize() const { return m_imageSize; }
443
//inline int GetSelection() const { return m_selection; }
445
inline void SetValue( const wxString& text ) { m_text = text; }
446
inline const wxString& GetValue() const { return m_text; }
448
inline wxCCustomButtonHandler* GetButtonData() { return &m_btData; }
450
virtual ~wxCCustomComboBoxHandler();
458
wxSize m_imageSize; // size of custom image in the list
460
wxString m_text; // text currently shown
462
//wxArrayPtrVoid m_labels; // holds pointers to labels
464
wxCCustomButtonHandler m_btData;
466
//wxCustomComboItem* m_pItem;
468
wxCustomComboPopup* m_listInstance;
470
wxCustomPaintFunc m_paintfunc;
471
void* m_paintfunc_customdata;
473
unsigned char m_prevMouseFocus; // used detect in which portion of control mouse is
477
// -----------------------------------------------------------------------
479
class WXDLLIMPEXP_CC wxCCustomComboBoxDefaultHandler : public wxCCustomComboBoxHandler
482
void Create ( wxCustomControl* pctrl, const wxString& value,
483
const wxPoint& pos, const wxSize& sz,
484
int n, const wxChar* choices[] );
486
int Append( const wxString& str );
488
virtual void SetSelection ( const wxCustomComboItem& item );
489
virtual void OnSelect ( const wxCustomComboItem& item );
490
virtual bool OnMouseEvent ( wxMouseEvent& event, wxCustomControlHandler* pdata );
491
virtual bool OnKeyEvent ( wxKeyEvent& event );
492
virtual wxCustomComboPopup* CreatePopup ( wxWindow* frame,
493
const wxRect& ctrl_rect, wxCustomControl* ctrl );
495
inline const wxArrayPtrVoid& GetLabels() const { return m_labels; }
496
inline wxArrayPtrVoid& GetWritableLabels() { return m_labels; }
497
inline int GetSelection() const { return m_selection; }
499
virtual ~wxCCustomComboBoxDefaultHandler();
505
wxArrayPtrVoid m_labels; // Holds pointers to labels.
507
wxArrayString m_extraStrings; // Place extra appended strings here.
511
/** wxCustomControlManager's flags
514
/** m_parent is wxScrolledWindow or derivative. */
515
#define wxCCM_FL_SCROLLEDWIN 0x0001
517
/** Notify for the event poller. */
518
#define wxCCM_FL_EVENTREADY 0x0002
520
/** If there is internal-to-control dragging going on. */
521
#define wxCCM_FL_DRAGGING 0x0004
523
/** When mouse cursor is actually inside mouse-focused control. */
524
#define wxCCM_FL_MOUSE_INSIDE 0x0008
526
/** Set by OnParentScrollEvent handler. */
527
#define wxCCM_FL_VIEWSTARTCHANGED 0x0010
529
/** Helper caret info. */
530
#define wxCCM_FL_CARETVISIBLE 0x0020
532
// -----------------------------------------------------------------------
534
/** \class wxCustomControls
536
\brief Static functions for drawing custom controls.
538
class WXDLLIMPEXP_CC wxCustomControlManager
540
friend class wxCustomControl;
541
friend class wxCustomTextCtrlHandler;
542
friend class wxCCustomTextCtrl;
543
friend class wxCCustomButtonHandler;
544
friend class wxCCustomButton;
545
friend class wxCCustomComboBoxHandler;
546
friend class wxCCustomComboBox;
549
wxCustomControlManager();
550
wxCustomControlManager( wxWindow* parent );
551
~wxCustomControlManager();
553
void AddChild ( wxCustomControl* child );
555
void AddChildData ( wxCustomControlHandler* pdata );
557
void AddEvent ( wxCustomControl* child, int eventtype );
561
void Create ( wxWindow* parent );
563
/** When xxData needs to redraw the control in question, use this
564
to create the necessary device context. Then DestroyDC must be
567
wxDC& CreateDC ( wxPoint* palignpt );
569
/** Creates frame etc. for a popup.
571
wxWindow* CreatePopupParent() { return m_parent; }
573
/** Black text on white background, centered vertically in the rect etc.
574
state 0 = no background clearing, 1 = clear bg, 3 = selected, clearbg.
576
void CtrlWriteText ( wxDC& dc, const wxChar* text,
577
const wxRect& rect, wxCustomControl* ctrl, int state );
580
void DestroyDC ( wxDC& dc );
582
wxCustomControlHandler* FindDataByPosition ( int x, int y );
583
wxCustomControl* FindWindowByPosition ( int x, int y );
585
inline void ForceMouseLeave ( wxMouseEvent& event )
587
DoMouseLeave ( event, NULL, TRUE );
590
inline wxEvent& GetEvent ()
592
m_flags &= ~(wxCCM_FL_EVENTREADY);
596
inline wxPoint GetCaretPosition () const
598
wxPoint p = m_pCaret->GetPosition();
599
//TranslatePositionToLogical ( &p.x, &p.y );
603
inline long GetFlags () const { return m_flags; }
605
inline wxWindow* GetPopup () const { return m_openPopup; }
607
inline wxCustomControl* GetFocused () const { return m_ctrlKbFocus; }
608
inline wxCustomControlHandler* GetMouseFocusedData () const { return m_dataMouseFocus; }
610
inline wxWindow* GetWindow () const { return m_parent; }
612
inline const wxColour& GetWindowColour () const { return *(&m_colBackground); }
613
inline const wxColour& GetWindowTextColour () const { return *(&m_colText); }
614
inline const wxColour& GetSelectionColour () const { return *(&m_colSelection); }
615
inline const wxColour& GetSelectionTextColour () const { return *(&m_colSelectionText); }
616
inline const wxColour& GetButtonColour () const { return *(&m_colButton); }
617
inline const wxColour& GetButtonTextColour () const { return *(&m_colButtonText); }
619
inline wxString& GetTempString() { return *(&m_tempStr1); }
621
inline bool HasEvent () const { return (m_flags & wxCCM_FL_EVENTREADY)?TRUE:FALSE; }
623
inline bool HasKbFocus () const { return (m_ctrlKbFocus!=NULL)?TRUE:FALSE; }
625
inline bool HasMouseFocus () const { return (m_ctrlMouseFocus!=NULL)?TRUE:FALSE; }
627
inline bool IsDragging () const { return (m_flags & wxCCM_FL_DRAGGING)?TRUE:FALSE; }
629
void MoveCaret ( const wxRect& ctrl_rect, int x, int y );
630
//void MoveCaretRelative ( int x, int y );
631
void RepositionCaret ();
633
/** Must be called when parent's focus changes. state = TRUE if focused.
635
void OnParentFocusChange ( bool state );
637
/** Must be called when parent wxScrolledWindow gets scrolling event.
639
void OnParentScrollWinEvent ( wxScrollWinEvent &event );
641
void OnParentScrollChange ();
643
bool ProcessKeyboardEvent ( wxKeyEvent& event );
645
/** Relays mouse event to appropriate managed custom control. If processes
646
(i.e. returns TRUE), event's coordinates have been converted to control's
649
Returns TRUE if event was inside some ctrl (some events may actually be processed even in this case).
651
bool ProcessMouseEvent ( wxMouseEvent& event );
653
void RemoveChild ( wxCustomControl* child );
655
void RemoveFocus ( wxCustomControl* child );
657
inline void ShowCaret ()
659
if ( m_pCaret && !(m_flags & wxCCM_FL_CARETVISIBLE) )
661
m_pCaret->Show ( TRUE );
662
m_flags |= wxCCM_FL_CARETVISIBLE;
663
//wxLogDebug ( wxT("ShowCaret( visible_after=%i )"), (int)m_pCaret->IsVisible() );
667
inline void ShowCaretBalanced ()
669
m_pCaret->Show ( TRUE );
672
inline void HideCaretBalanced ()
674
m_pCaret->Show ( FALSE );
677
inline void HideCaret ()
679
if ( m_pCaret && ( m_flags & wxCCM_FL_CARETVISIBLE ) )
681
m_pCaret->Show ( FALSE );
682
m_flags &= ~(wxCCM_FL_CARETVISIBLE);
683
//wxLogDebug ( wxT("HideCaret( visible_after=%i )"), (int)m_pCaret->IsVisible() );
687
inline bool IsCaretVisible () const
690
return m_pCaret->IsVisible();
694
void SetDoubleBuffer ( wxBitmap* buffer ) { m_bmpDoubleBuffer = buffer; }
696
void SetFocus ( wxCustomControl* child );
698
void SetFont ( const wxFont& font ) { m_font = font; }
700
void SetPopup ( wxCustomComboPopup* popup );
702
inline void StartDragging () { m_flags |= wxCCM_FL_DRAGGING; }
704
inline void StopDragging () { m_flags &= ~(wxCCM_FL_DRAGGING); }
706
/** Translates coordinate translation necessary for scrolled window.
708
void TranslatePositionToPhysical ( int* x, int* y ) const;
709
void TranslatePositionToLogical ( int* x, int* y ) const;
713
// returns index to first data of a control
714
int GetControlsFirstData ( wxCustomControl* ctrl );
721
wxBitmap* m_bmpDoubleBuffer; // never owns; just borrows parent's, if available;
723
//wxArrayPtrVoid m_controls;
725
wxArrayPtrVoid m_handlers; // one control may comprise of more than one controldata
727
wxCustomControl* m_ctrlMouseFocus; // which control has mouse focus
728
wxCustomControlHandler* m_dataMouseFocus; // which controldata has mouse focus
729
wxCustomControl* m_ctrlKbFocus; // which control has keyboard focus
733
wxPoint m_caretRelativePos; // caret x inside m_ctrlKbFocus
735
wxColour m_colBackground;
737
wxColour m_colSelection;
738
wxColour m_colSelectionText;
739
wxColour m_colButton;
740
wxColour m_colButtonText;
744
wxCursor m_cursorIBeam;
750
wxCommandEvent m_event;
752
#if wxCC_CORRECT_CONTROL_POSITION
753
wxSize m_prevViewStart; // for wxScrolledWindow scroll management
756
wxWindow* m_openPopup;
758
void DoMouseLeave ( wxMouseEvent& event, wxCustomControlHandler* newdata, bool force );
762
// -----------------------------------------------------------------------
764
#define wxCC_FL_KBFOCUS 0x0001
766
#define wxCC_FL_MOUSEFOCUS 0x0002 // When mouse is over the control and it is not dragging for another control
768
#define wxCC_FL_NEEDSCARET 0x0004
770
#define wxCC_FL_DRAWN 0x0008 // Set by drawing function
772
#define wxCC_FL_MODIFIED 0x0010 // May be needed internally by various controls/datas
774
#define wxCC_FL_REMOVED 0x0020 // Manager's RemoveChild already called on this.
776
#define wxCC_EXTRA_FLAG(N) (1<<(16+N))
778
// -----------------------------------------------------------------------
780
void wxRendererNative_DrawButton (wxWindow* win, wxDC& dc, const wxRect& rect, int flags = wxUP );
782
// -----------------------------------------------------------------------
784
class WXDLLIMPEXP_CC wxCustomControl : public wxObject
786
DECLARE_DYNAMIC_CLASS(wxCustomControl)
788
friend class wxCustomControlManager;
789
friend class wxCustomTextCtrlHandler;
790
friend class wxCCustomButtonHandler;
791
friend class wxCCustomComboBoxHandler;
795
wxCustomControl ( wxCustomControlManager* manager, wxWindowID id,
796
const wxPoint& pos, const wxSize& size, long style = 0 );
797
virtual ~wxCustomControl();
799
virtual void DoMove ( int x, int y );
801
inline const wxColour& GetBackgroundColour() const { return *(&m_manager->m_colBackground);}
803
inline wxFont& GetFont () const { return *m_pFont; }
804
inline int GetFontHeight () const { return m_fontHeight; }
806
inline wxWindowID GetId () const { return m_id; }
808
inline wxCustomControlManager* GetManager () const { return m_manager; }
810
inline wxWindow* GetParent () const { return m_manager->m_parent; }
812
inline wxPoint GetPosition () const { return wxPoint(m_rect.x,m_rect.y); }
814
inline wxRect GetRect () const { return m_rect; }
816
inline wxSize GetSize () const { return wxSize(m_rect.width,m_rect.height); }
818
inline int GetX () const { return m_rect.x; }
820
inline long GetWindowStyle () const { return m_windowStyle; }
822
inline void Move ( const wxPoint& pos ) { DoMove (pos.x,pos.y); }
824
inline void Move ( wxCoord x, wxCoord y ) { DoMove (x,y); }
826
/** Called on keyboard focus.
828
virtual void OnFocus ( bool focused );
830
/** Returns TRUE if processed.
832
virtual bool OnKeyEvent ( wxKeyEvent& event );
834
/** entry is TRUE if mouse enters, FALSE if leaves.
836
virtual bool OnMouseFocus ( bool entry );
838
virtual bool OnMouseEvent ( wxMouseEvent& event, wxCustomControlHandler* pdata );
840
/** Draw control on parent. If dc is NULL, creates one. */
841
void DrawPDC ( wxDC* dc = NULL );
843
inline void Draw () { DrawPDC ( NULL ); }
845
void Draw ( wxDC& dc );
847
/** Draw control on dc. align is control position adjustment on dc (incase
848
of a double-buffer, for example).
850
void Draw ( wxDC& dc, const wxPoint* align );
853
Draws control in to the dc.
855
- On both entry and exit, nothing can be assumed of current Pen or Brush.
856
- May set clipping region to the control rectangle. If so, calls
857
DestroyClippingRegion before exiting.
859
virtual void DoDraw ( wxDC& dc, const wxRect& rect );
861
virtual void DoSetSize ( int width, int height );
863
wxCommandEvent& GetEvent () const { return *(&m_manager->m_event); }
865
inline bool HasFocus () const { return (m_manager->m_ctrlKbFocus == this )?TRUE:FALSE; }
867
inline void Refresh ( bool = FALSE, const wxRect* = (const wxRect*) NULL ) { Draw(); }
869
inline void RemoveFocus ()
871
m_manager->RemoveFocus ( this );
874
inline void ResetFont () { m_pFont = &m_manager->m_font; }
876
inline void SetFocus ()
878
m_manager->SetFocus ( this );
881
inline void SetFocusFromKbd ()
883
m_manager->SetFocus ( this );
886
/** Sets font for the control.
888
Does not copy the font for itself, just pointer to it.
890
virtual void SetFont ( wxFont& font, wxDC* pdc = NULL );
892
inline void SetSize ( int x, int y, int width, int height )
895
DoSetSize ( width, height );
898
inline void SetSize ( const wxRect& rect )
900
DoMove ( rect.x, rect.y );
901
DoSetSize ( rect.width, rect.height );
904
inline void SetSize ( int width, int height )
906
DoSetSize ( width, height );
909
inline void SetSize ( const wxSize& size )
911
DoSetSize ( size.x, size.y );
914
inline void Show() { }
917
wxCustomControlManager *m_manager;
920
//wxSize m_imageSize; // Size of image in front of the control
925
int m_xSplit; // splitting the control into two parts (wxCCustomComboBox needs)
926
unsigned char m_curPart; // which part of the control is focused? (only if m_xSplit)
929
// -----------------------------------------------------------------------
931
inline bool wxCustomControlHandler::IsMouseFocused() const
933
return m_control->GetManager()->GetMouseFocusedData() == this;
936
// -----------------------------------------------------------------------
938
class WXDLLIMPEXP_CC wxCCustomTextCtrl : public wxCustomControl
940
DECLARE_DYNAMIC_CLASS(wxCCustomTextCtrl)
944
wxCCustomTextCtrl () : wxCustomControl() { }
946
wxCCustomTextCtrl ( wxCustomControlManager* manager, wxWindowID id, const wxString& value = wxEmptyString,
947
const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
950
virtual ~wxCCustomTextCtrl();
952
inline wxString GetValue() const { return m_data.GetValue(); }
954
inline void SetSelection(long from, long to)
956
if ( m_data.SetSelection(from,to) )
960
void SetValue ( const wxString& value );
962
inline void SetInsertionPoint ( long pos, long first_visible = -1 )
964
if ( m_data.SetInsertionPoint (pos,first_visible) )
968
virtual void DoDraw ( wxDC& dc, const wxRect& rect );
969
virtual void DoMove ( int x, int y );
970
virtual void DoSetSize ( int width, int height );
971
virtual void OnFocus ( bool focused );
972
virtual bool OnKeyEvent ( wxKeyEvent& event );
973
virtual bool OnMouseFocus ( bool entry );
974
virtual bool OnMouseEvent ( wxMouseEvent& event, wxCustomControlHandler* pdata );
975
virtual void SetFont ( wxFont& font, wxDC* pdc );
978
wxCustomTextCtrlHandler m_data;
981
// -----------------------------------------------------------------------
983
//#define wxCC_BT_DOWN wxCC_EXTRA_FLAG(0)
985
class WXDLLIMPEXP_CC wxCCustomButton : public wxCustomControl
987
DECLARE_DYNAMIC_CLASS(wxCCustomButton)
991
wxCCustomButton () : wxCustomControl() { }
993
wxCCustomButton ( wxCustomControlManager* manager, wxWindowID id, const wxChar* label,
994
const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize );
995
virtual ~wxCCustomButton();
997
inline void SetLabel ( const wxChar* label ) { m_data.m_label = label; }
999
virtual void DoDraw ( wxDC& dc, const wxRect& rect );
1000
virtual void DoMove ( int x, int y );
1001
virtual void DoSetSize ( int width, int height );
1002
virtual bool OnKeyEvent ( wxKeyEvent& event );
1003
virtual bool OnMouseFocus ( bool entry );
1004
virtual bool OnMouseEvent ( wxMouseEvent& event, wxCustomControlHandler* pdata );
1005
//virtual void SetFont ( wxFont& font );
1008
wxCCustomButtonHandler m_data;
1011
// -----------------------------------------------------------------------
1013
#define wxCH_CC_DOUBLE_CLICK_CYCLES 0x0010 // double-clicking cycles the selection
1014
#define wxCH_CC_IMAGE_EXTENDS 0x0020 // image is drawn outside in non-popup portion
1015
#define wxCH_CC_DROPDOWN_ANCHOR_RIGHT 0x0040 // anchor drop-down to right edge of parent window.
1017
class WXDLLIMPEXP_CC wxCCustomComboBox : public wxCustomControl
1019
DECLARE_DYNAMIC_CLASS(wxCCustomComboBox)
1023
wxCCustomComboBox () : wxCustomControl() { }
1025
wxCCustomComboBox ( wxCustomControlManager* manager, wxWindowID id,
1026
const wxString& value = wxEmptyString,
1027
const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
1028
int n = 0, const wxChar* choices[] = NULL, long style = 0,
1029
const wxSize& imagesize = wxDefaultSize );
1030
virtual ~wxCCustomComboBox();
1032
inline int Append( const wxString& str )
1034
return ((wxCCustomComboBoxDefaultHandler*)m_chData)->Append( str );
1037
inline wxWindow* GetPopupInstance() const { return m_chData->GetPopupInstance(); }
1039
inline int GetSelection () const { return ((wxCCustomComboBoxDefaultHandler*)m_chData)->GetSelection(); }
1041
inline const wxString& GetValue () const
1043
return m_chData->m_text;
1046
void SetSelection ( int n );
1048
inline void SetImagePaintFunction ( wxCustomPaintFunc paintfunc, void* userdata )
1050
m_chData->m_paintfunc = paintfunc;
1051
m_chData->m_paintfunc_customdata = userdata;
1054
virtual void DoDraw ( wxDC& dc, const wxRect& rect );
1055
virtual bool OnKeyEvent ( wxKeyEvent& event );
1056
virtual bool OnMouseFocus ( bool entry );
1057
virtual bool OnMouseEvent ( wxMouseEvent& event, wxCustomControlHandler* pdata );
1058
virtual void DoMove ( int x, int y );
1059
virtual void DoSetSize ( int width, int height );
1061
inline void SetValue ( const wxString& text )
1063
m_chData->SetValue(text);
1067
inline const wxString& SetValue () const
1069
return m_chData->GetValue();
1073
wxCCustomComboBoxHandler* m_chData;
1076
class WXDLLIMPEXP_CC wxCCustomChoice : public wxCCustomComboBox
1078
DECLARE_DYNAMIC_CLASS(wxCCustomChoice)
1082
wxCCustomChoice () : wxCCustomComboBox() { }
1084
wxCCustomChoice ( wxCustomControlManager* manager, wxWindowID id,
1085
const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
1086
int n = 0, const wxChar* choices[] = NULL, long style = 0,
1087
const wxSize& imagesize = wxDefaultSize );
1088
virtual ~wxCCustomChoice();
1091
// -----------------------------------------------------------------------
1093
#endif // wxPG_USE_CUSTOM_CONTROLS
1095
#if wxPG_USE_GENERIC_TEXTCTRL
1097
#define wxGTextCtrlBase wxControl
1099
class WXDLLIMPEXP_CC wxGenericTextCtrl : public wxGTextCtrlBase
1105
wxGenericTextCtrl() { Init(); }
1106
wxGenericTextCtrl(wxWindow *parent, wxWindowID id,
1107
const wxString& value = wxEmptyString,
1108
const wxPoint& pos = wxDefaultPosition,
1109
const wxSize& size = wxDefaultSize,
1111
const wxValidator& validator = wxDefaultValidator,
1112
const wxString& name = wxTextCtrlNameStr)
1116
Create(parent, id, value, pos, size, style, validator, name);
1118
~wxGenericTextCtrl();
1120
bool Create(wxWindow *parent, wxWindowID id,
1121
const wxString& value = wxEmptyString,
1122
const wxPoint& pos = wxDefaultPosition,
1123
const wxSize& size = wxDefaultSize,
1125
const wxValidator& validator = wxDefaultValidator,
1126
const wxString& name = wxTextCtrlNameStr);
1128
// implement base class pure virtuals
1129
// ----------------------------------
1130
virtual wxString GetValue() const;
1131
virtual void SetValue(const wxString& value);
1133
virtual wxString GetRange(long from, long to) const;
1135
virtual int GetLineLength(long lineNo) const;
1136
virtual wxString GetLineText(long lineNo) const;
1137
virtual int GetNumberOfLines() const;
1139
virtual bool IsModified() const;
1140
virtual bool IsEditable() const;
1142
virtual void GetSelection(long* from, long* to) const;
1146
virtual void Remove(long from, long to);
1149
void DispatchEvent( int evtId );
1150
bool SetInsertionPoint (long pos,
1151
long first_visible = -1);
1152
void DeleteSelection ();
1153
bool SetSelection ( long from, long to );
1155
inline wxTextPos GetLastPosition() const
1157
return m_text.length();
1160
// Standard wxWindow virtual overrides
1161
virtual void SetFocus();
1165
int HitTest ( wxCoord x, int* pCol );
1166
void RecalculateMetrics();
1168
// common part of all ctors
1173
unsigned int m_position;
1174
unsigned int m_scrollPosition;
1177
int m_itemButDown; // dragging centers around this
1183
wxArrayInt m_arrExtents; // cached array of text extents
1185
//int UpdateExtentCache ( wxString& tempstr, size_t index );
1188
void OnKeyEvent ( wxKeyEvent& event );
1189
void OnMouseEvent ( wxMouseEvent& event );
1190
void OnPaint ( wxPaintEvent& event );
1192
/* inline void ShowCaret ()
1194
if ( m_pCaret && !(m_flags & wxCCM_FL_CARETVISIBLE) )
1196
m_pCaret->Show ( TRUE );
1197
m_flags |= wxCCM_FL_CARETVISIBLE;
1198
//wxLogDebug ( wxT("ShowCaret( visible_after=%i )"), (int)m_pCaret->IsVisible() );
1202
inline void ShowCaretBalanced ()
1204
m_pCaret->Show ( TRUE );
1207
inline void HideCaretBalanced ()
1209
m_pCaret->Show ( FALSE );
1212
//void MoveCaret ( int x, int y );
1214
/* inline void HideCaret ()
1216
if ( m_pCaret && ( m_flags & wxCCM_FL_CARETVISIBLE ) )
1218
m_pCaret->Show ( FALSE );
1219
m_flags &= ~(wxCCM_FL_CARETVISIBLE);
1220
//wxLogDebug ( wxT("HideCaret( visible_after=%i )"), (int)m_pCaret->IsVisible() );
1224
inline bool IsCaretVisible () const
1227
return m_pCaret->IsVisible();
1233
virtual void Clear();
1234
virtual void Replace(long from, long to, const wxString& value);
1235
virtual void Remove(long from, long to);
1237
// load the controls contents from the file
1238
virtual bool LoadFile(const wxString& file);
1240
// clears the dirty flag
1241
virtual void MarkDirty();
1242
virtual void DiscardEdits();
1244
virtual void SetMaxLength(unsigned long len);
1246
// writing text inserts it at the current position, appending always
1247
// inserts it at the end
1248
virtual void WriteText(const wxString& text);
1249
virtual void AppendText(const wxString& text);
1252
virtual bool EmulateKeyPress(const wxKeyEvent& event);
1256
// apply text attribute to the range of text (only works with richedit
1258
virtual bool SetStyle(long start, long end, const wxTextAttr& style);
1259
virtual bool SetDefaultStyle(const wxTextAttr& style);
1260
virtual bool GetStyle(long position, wxTextAttr& style);
1261
#endif // wxUSE_RICHEDIT
1263
// translate between the position (which is just an index in the text ctrl
1264
// considering all its contents as a single strings) and (x, y) coordinates
1265
// which represent column and line.
1266
virtual long XYToPosition(long x, long y) const;
1267
virtual bool PositionToXY(long pos, long *x, long *y) const;
1269
virtual void ShowPosition(long pos);
1270
virtual wxTextCtrlHitTestResult HitTest(const wxPoint& pt, long *pos) const;
1271
virtual wxTextCtrlHitTestResult HitTest(const wxPoint& pt,
1273
wxTextCoord *row) const
1275
return wxTextCtrlBase::HitTest(pt, col, row);
1278
// Clipboard operations
1279
virtual void Copy();
1281
virtual void Paste();
1283
virtual bool CanCopy() const;
1284
virtual bool CanCut() const;
1285
virtual bool CanPaste() const;
1288
virtual void Undo();
1289
virtual void Redo();
1291
virtual bool CanUndo() const;
1292
virtual bool CanRedo() const;
1295
virtual void SetInsertionPoint(long pos);
1296
virtual void SetInsertionPointEnd();
1297
virtual long GetInsertionPoint() const;
1298
virtual wxTextPos GetLastPosition() const;
1300
virtual void SetSelection(long from, long to);
1301
virtual void SetEditable(bool editable);
1303
// Caret handling (Windows only)
1305
bool ShowNativeCaret(bool show = true);
1306
bool HideNativeCaret() { return ShowNativeCaret(false); }
1308
// Implementation from now on
1309
// --------------------------
1311
virtual void SetWindowStyleFlag(long style);
1313
virtual void Command(wxCommandEvent& event);
1314
virtual bool MSWCommand(WXUINT param, WXWORD id);
1315
virtual WXHBRUSH MSWControlColor(WXHDC hDC);
1318
virtual bool MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result);
1320
int GetRichVersion() const { return m_verRichEdit; }
1321
bool IsRich() const { return m_verRichEdit != 0; }
1323
// rich edit controls are not compatible with normal ones and wem ust set
1324
// the colours for them otherwise
1325
virtual bool SetBackgroundColour(const wxColour& colour);
1326
virtual bool SetForegroundColour(const wxColour& colour);
1327
#endif // wxUSE_RICHEDIT
1329
virtual void AdoptAttributesFromHWND();
1331
virtual bool AcceptsFocus() const;
1334
void OnDropFiles(wxDropFilesEvent& event);
1335
void OnChar(wxKeyEvent& event); // Process 'enter' if required
1337
void OnCut(wxCommandEvent& event);
1338
void OnCopy(wxCommandEvent& event);
1339
void OnPaste(wxCommandEvent& event);
1340
void OnUndo(wxCommandEvent& event);
1341
void OnRedo(wxCommandEvent& event);
1342
void OnDelete(wxCommandEvent& event);
1343
void OnSelectAll(wxCommandEvent& event);
1345
void OnUpdateCut(wxUpdateUIEvent& event);
1346
void OnUpdateCopy(wxUpdateUIEvent& event);
1347
void OnUpdatePaste(wxUpdateUIEvent& event);
1348
void OnUpdateUndo(wxUpdateUIEvent& event);
1349
void OnUpdateRedo(wxUpdateUIEvent& event);
1350
void OnUpdateDelete(wxUpdateUIEvent& event);
1351
void OnUpdateSelectAll(wxUpdateUIEvent& event);
1353
// Show a context menu for Rich Edit controls (the standard
1354
// EDIT control has one already)
1355
void OnContextMenu(wxContextMenuEvent& event);
1357
// be sure the caret remains invisible if the user
1358
// called HideNativeCaret() before
1359
void OnSetFocus(wxFocusEvent& event);
1363
// intercept WM_GETDLGCODE
1364
virtual WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
1366
// call this to increase the size limit (will do nothing if the current
1367
// limit is big enough)
1369
// returns true if we increased the limit to allow entering more text,
1370
// false if we hit the limit set by SetMaxLength() and so didn't change it
1371
bool AdjustSpaceLimit();
1373
#if wxUSE_RICHEDIT && (!wxUSE_UNICODE || wxUSE_UNICODE_MSLU)
1374
// replace the selection or the entire control contents with the given text
1375
// in the specified encoding
1376
bool StreamIn(const wxString& value, wxFontEncoding encoding, bool selOnly);
1378
// get the contents of the control out as text in the given encoding
1379
wxString StreamOut(wxFontEncoding encoding, bool selOnly = false) const;
1380
#endif // wxUSE_RICHEDIT
1382
// replace the contents of the selection or of the entire control with the
1384
void DoWriteText(const wxString& text, bool selectionOnly = true);
1386
// set the selection possibly without scrolling the caret into view
1387
void DoSetSelection(long from, long to, bool scrollCaret = true);
1389
// return true if there is a non empty selection in the control
1390
bool HasSelection() const;
1392
// get the length of the line containing the character at the given
1394
long GetLengthOfLineContainingPos(long pos) const;
1396
// send TEXT_UPDATED event, return true if it was handled, false otherwise
1397
bool SendUpdateEvent();
1399
// override some base class virtuals
1400
virtual bool MSWShouldPreProcessMessage(WXMSG* pMsg);
1401
virtual wxSize DoGetBestSize() const;
1403
virtual WXDWORD MSWGetStyle(long style, WXDWORD *exstyle) const;
1406
// we're using RICHEDIT (and not simple EDIT) control if this field is not
1407
// 0, it also gives the version of the RICHEDIT control being used (1, 2 or
1410
#endif // wxUSE_RICHEDIT
1412
// number of EN_UPDATE events sent by Windows when we change the controls
1413
// text ourselves: we want this to be exactly 1
1416
virtual wxVisualAttributes GetDefaultAttributes() const;
1418
wxMenu* m_privateContextMenu;
1420
bool m_isNativeCaretShown;
1424
DECLARE_EVENT_TABLE()
1425
DECLARE_DYNAMIC_CLASS_NO_COPY(wxGenericTextCtrl)
1431
// Undefine macros that are not needed outside library source files
1433
#ifndef __wxCCM_SOURCE_FILE__
1434
# undef WXDLLIMPEXP_CC
1437
#endif // __WX_CUSTCTRL_H__