📄 odcombo.h
字号:
///////////////////////////////////////////////////////////////////////////////
// Name: odcombo.h
// Purpose: wxPGOwnerDrawnComboBox and related classes interface
// Author: Jaakko Salli
// Modified by:
// Created: Jan-25-2005
// RCS-ID: $Id:
// Copyright: (c) 2005 Jaakko Salli
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_PROPGRID_ODCOMBO_H_
#define _WX_PROPGRID_ODCOMBO_H_
#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
#pragma interface "odcombo.h"
#endif
#include "wx/renderer.h"
// Item counts in GUI components were changed in 2.7.0
#if wxCHECK_VERSION(2,7,0)
#define wxODCCount unsigned int
#define wxODCIndex unsigned int
#else
#define wxODCCount int
#define wxODCIndex int
#endif
// wxRect: Inside(<=2.7.0) or Contains(>2.7.0)?
#if !wxCHECK_VERSION(2,7,1)
#define wxPGRectContains Inside
#else
#define wxPGRectContains Contains
#endif
class WXDLLEXPORT wxTextCtrl;
class WXDLLEXPORT wxButton;
#if defined(__WXMSW__) && defined(WXUSINGDLL) // O.C. > wxPropertyGrid is built-in SAGA
#define WXMAKINGLIB_PROPGRID
#endif
#ifdef WXMAKINGLIB_PROPGRID #define WXDLLEXPORT_PGODC#elif defined(WXMAKINGDLL_PROPGRID) #define WXDLLEXPORT_PGODC WXEXPORT
#elif defined(WXUSINGDLL)
#define WXDLLEXPORT_PGODC WXIMPORT
#else // not making nor using DLL
#define WXDLLEXPORT_PGODC
#endif
class WXDLLEXPORT_PGODC wxPGComboPopup;
class WXDLLEXPORT_PGODC wxPGComboControlBase;
class WXDLLEXPORT_PGODC wxPGOwnerDrawnComboBox;
// ----------------------------------------------------------------------------
// New window styles for wxPGComboControlBase
enum
{
// Double-clicking causes value to cycle (ie. call to popup's CycleValue method).
wxPGCC_DCLICK_CYCLES = 0x0100,
// Use keyboard behaviour alternate to platform default:
// Up an down keys will show popup instead of cycling value.
wxPGCC_ALT_KEYS = 0x0200,
};
#define wxPGCC_PROCESS_ENTER 0
// ----------------------------------------------------------------------------
// wxPGComboControlBase: a base class for generic control that looks like
// a wxComboBox but allows completely custom popup (in addition to other
// customizations).
// ----------------------------------------------------------------------------
// wxComboControl internal flags
enum
{
// First those that can be passed to Customize.
// It is Windows style for all flags to be clear.
// Button is preferred outside the border (GTK style)
wxPGCC_BUTTON_OUTSIDE_BORDER = 0x0001,
// Show popup on mouse up instead of mouse down (which is the Windows style)
wxPGCC_POPUP_ON_MOUSE_UP = 0x0002,
// All text is not automatically selected on click
wxPGCC_NO_TEXT_AUTO_SELECT = 0x0004,
// Drop-button stays depressed while the popup is open
wxPGCC_BUTTON_STAYS_DOWN = 0x0008,
// Button covers the entire control
wxPGCC_FULL_BUTTON = 0x0010,
// Internal use: signals creation is complete
wxPGCC_IFLAG_CREATED = 0x0100,
// Internal use: really put button outside
wxPGCC_IFLAG_BUTTON_OUTSIDE = 0x0200,
// Internal use: SetTextIndent has been called
wxPGCC_IFLAG_INDENT_SET = 0x0400,
// Internal use: Set wxTAB_TRAVERSAL to parent when popup is dismissed
wxPGCC_IFLAG_PARENT_TAB_TRAVERSAL = 0x0800,
// Button has bitmap or has non-standard size
wxPGCC_IFLAG_HAS_NONSTANDARD_BUTTON = 0x1000
};
// Flags used by PreprocessMouseEvent and HandleButtonMouseEvent
enum
{
wxPGCC_MF_ON_BUTTON = 0x0001, // cursor is on dropbutton area
};
// Namespace for wxComboControl feature flags
struct wxPGComboControlFeatures
{
enum
{
MovableButton = 0x0001, // Button can be on either side of control
BitmapButton = 0x0002, // Button may be replace with bitmap
ButtonSpacing = 0x0004, // Non-bitmap button can have spacing from
// the edge of the control
TextIndent = 0x0008, // SetTextIndent can be used
PaintControl = 0x0010, // Combo control itself can be custom painted
PaintWritable = 0x0020, // A variable-width area in front of writable
// combo control's textctrl can be custom
// painted
Borderless = 0x0040, // wxNO_BORDER window style works
// There is no feature flags for...
// PushButtonBitmapBackground - if its in renderer native, then it should be
// not an issue to have it automatically under the bitmap.
All = MovableButton|BitmapButton|
ButtonSpacing|TextIndent|
PaintControl|PaintWritable|
Borderless,
};
};
class wxPGComboPopupWindow;
class WXDLLEXPORT_PGODC wxPGComboControlBase : public wxControl
{
friend class wxPGComboPopup;
friend class wxPGComboPopupWindow;
public:
// ctors and such
wxPGComboControlBase() : wxControl() { Init(); }
bool Create(wxWindow *parent,
wxWindowID id,
const wxString& value,
const wxPoint& pos,
const wxSize& size,
long style,
const wxValidator& validator,
const wxString& name);
virtual ~wxPGComboControlBase();
virtual bool Destroy();
// show/hide popup window
virtual void ShowPopup();
virtual void HidePopup();
// Override for totally custom combo action
virtual void OnButtonClick();
// return true if the popup is currently shown
inline bool IsPopupShown() const { return m_isPopupShown; }
// set interface class instance derived from wxPGComboPopup
void SetPopup( wxPGComboPopup* iface );
// get interface class instance derived from wxPGComboPopup
wxPGComboPopup* GetPopup() const { return m_popupInterface; }
// get the popup window containing the popup control
wxWindow *GetPopupWindow() const { return m_winPopup; }
// get the popup control/panel in window
wxWindow *GetPopupControl() const { return m_popup; }
// Get the text control which is part of the combobox.
inline wxTextCtrl *GetTextCtrl() const { return m_text; }
// get the dropdown button which is part of the combobox
// note: its not necessarily a wxButton or wxBitmapButton
inline wxWindow *GetButton() const { return m_btn; }
// forward these methods to all subcontrols
virtual bool Enable(bool enable = true);
virtual bool Show(bool show = true);
virtual bool SetFont(const wxFont& font);
#if wxUSE_TOOLTIPS
virtual void DoSetToolTip( wxToolTip *tip );
#endif
// wxTextCtrl methods - for readonly combo they should return
// without errors.
virtual wxString GetValue() const;
virtual void SetValue(const wxString& value);
virtual void Copy();
virtual void Cut();
virtual void Paste();
virtual void SetInsertionPoint(long pos);
virtual void SetInsertionPointEnd();
virtual long GetInsertionPoint() const;
virtual long GetLastPosition() const;
virtual void Replace(long from, long to, const wxString& value);
virtual void Remove(long from, long to);
virtual void SetSelection(long from, long to);
virtual void Undo();
// Returns the text field rectangle, including any image that is painted with it.
inline const wxRect& GetTextRect() const
{
return m_tcArea;
}
//
// Popup customization methods
//
// Sets minimum width of the popup. If wider than combo control, it will extend to the left.
// Remarks:
// * Value -1 indicates the default.
// * Custom popup may choose to ignore this (wxPGOwnerDrawnComboBox does not).
inline void SetPopupMinWidth( int width )
{
m_widthMinPopup = width;
}
// Sets preferred maximum height of the popup.
// Remarks:
// * Value -1 indicates the default.
// * Custom popup may choose to ignore this (wxPGOwnerDrawnComboBox does not).
inline void SetPopupMaxHeight( int height )
{
m_heightPopup = height;
}
// Extends popup size horizontally, relative to the edges of the combo control.
// Remarks:
// * Popup minimum width may override extLeft (ie. it has higher precedence).
// * Values 0 indicate default.
// * Custom popup may not take this fully into account (wxPGOwnerDrawnComboBox takes).
inline void SetPopupExtents( int extLeft, int extRight )
{
m_extLeft = extLeft;
m_extRight = extRight;
}
// Set width, in pixels, of custom paint area in writable combo.
// In read-only, used to indicate area that is not covered by the
// focus rectangle (which may or may not be drawn, depending on the
// popup type).
void SetCustomPaintWidth( int width );
inline int GetCustomPaintWidth() const { return m_widthCustomPaint; }
// Set position of dropdown button.
// width: 0 > for specific custom width, negative to adjust to smaller than default
// height: 0 > for specific custom height, negative to adjust to smaller than default
// side: wxLEFT or wxRIGHT, indicates on which side the button will be placed.
// spacingX: empty space on sides of the button. Default is 0.
// Remarks:
// There is no spacingY - the button will be centered vertically.
void SetButtonPosition( int width = 0, int height = 0, int side = wxRIGHT,
int spacingX = 0 /*, int spacingY = 0*/ );
//
// Sets dropbutton to be drawn with custom bitmaps.
//
// bmpNormal: drawn when cursor is not on button
// blankButtonBg: Draw blank button background below the image.
// NOTE! This is only properly supported on platforms with appropriate
// method in wxRendererNative.
// bmpPressed: drawn when button is depressed
// bmpHover: drawn when cursor hovers on button. This is ignored on platforms
// that do not generally display hover differently.
// bmpDisabled: drawn when combobox is disabled.
void SetButtonBitmaps( const wxBitmap& bmpNormal,
bool blankButtonBg = false,
const wxBitmap& bmpPressed = wxNullBitmap,
const wxBitmap& bmpHover = wxNullBitmap,
const wxBitmap& bmpDisabled = wxNullBitmap );
//
// This will set the space in pixels between left edge of the control and the
// text, regardless whether control is read-only (ie. no wxTextCtrl) or not.
// Platform-specific default can be set with value-1.
// Remarks
// * This method may do nothing on some native implementations.
void SetTextIndent( int indent );
// Returns actual indentation in pixels.
inline wxCoord GetTextIndent() const
{
return m_absIndent;
}
//
// Utilies needed by the popups or native implementations
//
// Draws focus background (on combo control) in a way typical on platform.
// Unless you plan to paint your own focus indicator, you should always call this
// in your wxPGComboPopup::PaintComboControl implementation.
// In addition, it sets pen and text colour to what looks good and proper
// against the background.
// flags: wxRendererNative flags: wxCONTROL_ISSUBMENU: is drawing a list item instead of combo control
// wxCONTROL_SELECTED: list item is selected
// wxCONTROL_DISABLED: control/item is disabled
virtual void DrawFocusBackground( wxDC& dc, const wxRect& rect, int flags );
// Returns true if focused. Differs from FindFocus in that takes
// child controls into account.
bool IsFocused() const
{
const wxWindow* curFocus = FindFocus();
if ( curFocus == this || (m_text && curFocus == m_text) )
return true;
return false;
}
// Returns true if focus indicator should be drawn.
inline bool ShouldDrawFocus() const
{
const wxWindow* curFocus = FindFocus();
return ( !m_isPopupShown &&
(curFocus == this || (m_btn && curFocus == m_btn)) &&
(m_windowStyle & wxCB_READONLY) );
}
// These methods return references to appropriate dropbutton bitmaps
inline const wxBitmap& GetBitmapNormal() const { return m_bmpNormal; }
inline const wxBitmap& GetBitmapPressed() const { return m_bmpPressed; }
inline const wxBitmap& GetBitmapHover() const { return m_bmpHover; }
inline const wxBitmap& GetBitmapDisabled() const { return m_bmpDisabled; }
// Return internal flags
inline wxUint32 GetInternalFlags() const { return m_iFlags; }
// Return true if Create has finished
inline bool IsCreated() const { return m_iFlags & wxPGCC_IFLAG_CREATED ? true : false; }
// Popup may use these as callbacks to measure and draw list items.
// (wxPGOwnerDrawnComboBox uses these, obviously)
// item: -1 means item is the combo control itself
// flags: wxPGCC_PAINTING_CONTROL is set if painting to combo control instead of list
// return value: OnDrawListItem must return true if it did anything
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -