⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 custctrl.cpp

📁 非常好用的可移植的多平台C/C++源代码编辑器
💻 CPP
📖 第 1 页 / 共 5 页
字号:
/////////////////////////////////////////////////////////////////////////////
// Name:        custctrl.cpp
// Purpose:     wxCustomControls (non-wxWindow based)
// Author:      Jaakko Salli
// Modified by:
// Created:     Oct-24-2004
// RCS-ID:      $Id:
// Copyright:   (c) Jaakko Salli
// Licence:     wxWindows license
/////////////////////////////////////////////////////////////////////////////

#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
    #pragma implementation "custctrl.h"
#endif

// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"

#ifdef __BORLANDC__
    #pragma hdrstop
#endif

#ifndef WX_PRECOMP
    #include "wx/defs.h"
    #include "wx/object.h"
    #include "wx/string.h"
    #include "wx/dynarray.h"
    #include "wx/log.h"
    #include "wx/event.h"
    #include "wx/window.h"
    #include "wx/panel.h"
    #include "wx/frame.h"
    #include "wx/dc.h"
    #include "wx/dcclient.h"
    #include "wx/dcmemory.h"
    #include "wx/pen.h"
    #include "wx/brush.h"
    #include "wx/button.h"
    #include "wx/stattext.h"
    #include "wx/cursor.h"
    #include "wx/dialog.h"
    #include "wx/settings.h"
    #include "wx/choice.h"
    #include "wx/textctrl.h"
    #include "wx/scrolwin.h"
    #include "wx/combobox.h"
#endif

// This define is necessary to prevent macro clearing
#define __wxCCM_SOURCE_FILE__

#if wxMINOR_VERSION < 5 || ( wxMINOR_VERSION == 5 && wxRELEASE_NUMBER < 3 )
# undef wxUSE_UXTHEME
#endif

//#include <wx/propertygrid/custctrl.h>
#define __wxPG_SOURCE_FILE__
#include <wx/propgrid/propgrid.h>

#include "wx/renderer.h"

#include "wx/clipbrd.h"

#define __INTENSE_DEBUGGING__       0
#define __PAINT_DEBUGGING__         0
#define __MOUSE_DEBUGGING__         0

#define DRAW_CTRL_IN_DATA_FUNC(MANAGER) \
            ctrl->Draw();


//
// Here are some extra platform dependent defines.
//

#if defined(__WXMSW__)
    // tested

    #define wxPG_TEXTCTRL_DOUBLE_CLICK_MODE     2 // 0 = as left click, 1 = select word (GTK), 2 = select word and following spaces (MSW)

    #define wxPG_DROPDOWN_BUTTON_MAX_WIDTH      17

#elif defined(__WXGTK__)
    // tested

    #define wxPG_TEXTCTRL_DOUBLE_CLICK_MODE     1 // 0 = as left click, 1 = select word (GTK), 2 = select word and following spaces (MSW)

    #define wxPG_DROPDOWN_BUTTON_MAX_WIDTH      19

#elif defined(__WXMAC__)
    // *not* tested

    #define wxPG_TEXTCTRL_DOUBLE_CLICK_MODE     1 // 0 = as left click, 1 = select word (GTK), 2 = select word and following spaces (MSW)

    #define wxPG_DROPDOWN_BUTTON_MAX_WIDTH      17

#else
    // defaults

    #define wxPG_TEXTCTRL_DOUBLE_CLICK_MODE     1 // 0 = as left click, 1 = select word (GTK), 2 = select word and following spaces (MSW)

    #define wxPG_DROPDOWN_BUTTON_MAX_WIDTH      21

#endif

// -----------------------------------------------------------------------
// Extra Native Rendering
// -----------------------------------------------------------------------

// Only for wxWidgets 2.5.4 and earlier
#if wxMINOR_VERSION < 5 || ( wxMINOR_VERSION == 5 && wxRELEASE_NUMBER < 5 ) || wxPG_USE_CUSTOM_CONTROLS

#define wxCC_DROPDOWN_BUTTON_WIDTH  17 // for font with height of one below
#define wxCC_DROPDOWN_BUTTON_WIDTH_WITH_FONT_HEIGHT 13

#ifndef __WX_CUSTCTRL_H__
# define wxCONTROL_POPUP_ARROW       wxCONTROL_CHECKED
# if defined(__WXMSW__) && wxUSE_UXTHEME
#  include "wx/msw/uxtheme.h"
# endif
#endif

//
// TODO: After its sure that both MSW and GTK have native dropdown button
//   rendering in wx lib, change code here to support it (retain old code
//   for < 2.5.4 support).
//

#if defined(__WXGTK__)
//#if defined(__WXMSW__)

// wxGTK native button.
//# if defined(__WXGTK20__)

#include <gtk/gtk.h>
#include "wx/gtk/win_gtk.h"

void wxRendererNative_DrawButton ( wxWindow* win, wxDC& dc, const wxRect& rect,
                                   int flags )
{

    static GtkWidget *s_button = NULL;
    static GtkWidget *s_window = NULL;
    if (s_button == NULL)
    {
        s_window = gtk_window_new( GTK_WINDOW_POPUP );
        gtk_widget_realize( s_window );
        s_button = gtk_button_new();
        gtk_container_add( GTK_CONTAINER(s_window), s_button );
        gtk_widget_realize( s_button );
    }

    // Device context must inherit from wxWindowDC
    // (so it must be wxClientDC, wxMemoryDC or wxPaintDC).
    wxWindowDC* wdc = wxDynamicCast(&dc,wxWindowDC);
    wxASSERT ( wdc );

    GtkStateType state = GTK_STATE_NORMAL;
    GtkShadowType shadow = GTK_SHADOW_OUT;

    if ( flags & wxCONTROL_PRESSED )
        shadow = GTK_SHADOW_IN;
    else if ( flags & wxCONTROL_CURRENT )
        state = GTK_STATE_PRELIGHT;
    else if ( flags & wxCONTROL_DISABLED )
        state = GTK_STATE_INSENSITIVE;
    
    gtk_paint_box
    (
        s_button->style,
        //GTK_PIZZA(wdc->m_window)->bin_window,
        wdc->m_window,
        state,
        shadow,
        NULL,
        s_button,
        "button",
        //dc.XLOG2DEV(rect.x) -1, rect.y -1, rect.width +2, rect.height +2
        //rect.x -1, rect.y -1, rect.width +2, rect.height +2
        rect.x, rect.y, rect.width, rect.height
    );

    if ( flags & wxCONTROL_POPUP_ARROW )
    {
        // Arrow on button.

        int arr_wid = rect.width/2;
        int arr_hei = rect.height/2;
        if ( arr_wid & 1 ) arr_wid++;
        if ( arr_hei & 1 ) arr_hei++;

        gtk_paint_arrow
        (
            s_button->style,
            //GTK_PIZZA(wdc->m_window)->bin_window,
            wdc->m_window,
            state,
            shadow,
            NULL,
            s_button,
            "arrow",
            GTK_ARROW_DOWN,
            TRUE,
            rect.x + (rect.width/2-arr_wid/2) + 1,
            rect.y + (rect.height/2-arr_hei/2) + 1,
            arr_wid,
            arr_hei
        );
    }

    /*
    GtkWidget* widget = wnd->GetHandle();

    GtkStateType state = GTK_STATE_NORMAL;

    if ( flags & wxCONTROL_CURRENT )
        state = GTK_STATE_PRELIGHT;
    else if ( flags & wxCONTROL_PRESSED )
        state = GTK_STATE_ACTIVE;

    GdkRectangle clip_rect;

    wxRect r2 = wnd->GetClientRect();

    clip_rect.x = r2.x;
    clip_rect.y = r2.y;
    clip_rect.width = r2.width;
    clip_rect.height = r2.height;

    gtk_paint_box (widget->style, widget->window,
			 state, GTK_SHADOW_IN,
			 &clip_rect, widget, "buttondefault",
			 r1.x, r1.y, r1.width, r1.height);
    */
}

/*# else // defined(__WXGTK20__)

void wxRendererNative_DrawButton ( wxWindow*, wxDC& dc, const wxRect& r1,
                                   int flags )
{
    wxColour face_colour = wxSystemSettings::GetColour ( wxSYS_COLOUR_BTNFACE );

    if ( flags & wxCONTROL_PRESSED )
    {
#  define __LIGHTER__ (-18)
            face_colour.Set ( face_colour.Red()>(-__LIGHTER__)?face_colour.Red()+__LIGHTER__:0,
                          face_colour.Green()>(-__LIGHTER__)?face_colour.Green()+__LIGHTER__:0,
                          face_colour.Blue()>(-__LIGHTER__)?face_colour.Blue()+__LIGHTER__:0
                        );
#  undef __LIGHTER__
    }
    else if ( flags & wxCONTROL_CURRENT )
    {
#  define __LIGHTER__ 18
            face_colour.Set ( face_colour.Red()<(255-__LIGHTER__)?face_colour.Red()+__LIGHTER__:255,
                          face_colour.Green()<(255-__LIGHTER__)?face_colour.Green()+__LIGHTER__:255,
                          face_colour.Blue()<(255-__LIGHTER__)?face_colour.Blue()+__LIGHTER__:255
                        );
#  undef __LIGHTER__
    }
   //     face_colour = wxSystemSettings::GetColour ( wxSYS_COLOUR_3DLIGHT );

    dc.SetBrush ( face_colour );

    dc.SetPen ( wxSystemSettings::GetColour ( wxSYS_COLOUR_3DDKSHADOW ) );

    dc.DrawRectangle ( r1 );
    
    wxRect r2(r1);
    r2.Deflate ( 1 );

    dc.SetPen ( wxSystemSettings::GetColour ( wxSYS_COLOUR_BTNSHADOW ) );

    if ( !(flags & wxCONTROL_PRESSED) )
    {
        dc.DrawRectangle ( r2 );

        dc.SetPen ( wxSystemSettings::GetColour ( wxSYS_COLOUR_BTNHIGHLIGHT ) );
        dc.DrawLine ( r2.x, r2.y, r2.x, r2.y + r2.height - 1 );
        dc.DrawLine ( r2.x, r2.y, r2.x + r2.width, r2.y );
    }
    else
    {
        dc.SetPen ( wxSystemSettings::GetColour ( wxSYS_COLOUR_BTNSHADOW ) );
        dc.DrawLine ( r2.x, r2.y, r2.x, r2.y + r2.height );
        dc.DrawLine ( r2.x, r2.y, r2.x + r2.width, r2.y );
    }

    if ( flags & wxCONTROL_POPUP_ARROW )
    {
        // Arrow on button.

        wxBitmap* bmp = gs_bmp_gtk_arrow.m_bmp;
        if ( !bmp )
            bmp = gs_bmp_gtk_arrow.SetXpm((const char**)gs_xpm_gtk_arrow);

        wxASSERT ( bmp );
        dc.DrawBitmap(*bmp,
            r1.x + (r1.width/2-bmp->GetWidth()/2),
            r1.y + (r1.height/2-bmp->GetHeight()/2) + 1,
            TRUE);

    }
}

# endif // !defined(__WXGTK20__)*/

#else

#if wxUSE_UXTHEME
    #include <commctrl.h>
    //#include <tmschema.h>

    // Since tmschema.h is in Win32 Platform SDK,
    // we need to define some values from it here.
    #ifndef BP_PUSHBUTTON

    # define BP_PUSHBUTTON      1

    # define PBS_NORMAL         1
    # define PBS_HOT            2
    # define PBS_PRESSED        3
    # define PBS_DISABLED       4
    # define PBS_DEFAULTED      5

    # define CP_DROPDOWNBUTTON  1

    # define CBXS_NORMAL        1
    # define CBXS_HOT           2
    # define CBXS_PRESSED       3
    # define CBXS_DISABLED      4

    #endif

#endif

static wxPoint dropdown_arrow_points[3];

// wxMSW native button (default for platforms without their own)
#if wxUSE_UXTHEME
void wxRendererNative_DrawButton (wxWindow* win, wxDC& dc, const wxRect& r1,
                                  int flags )
#else
void wxRendererNative_DrawButton (wxWindow*, wxDC& dc, const wxRect& r1,
                                  int flags )
#endif
{

#if wxUSE_UXTHEME

    const wchar_t *classes = L"ComboBox";

    if ( !(flags & wxCONTROL_POPUP_ARROW) )
        classes = L"Button";

    wxUxThemeHandle themeHandle(win, classes);
#if wxMINOR_VERSION < 5 || ( wxMINOR_VERSION == 5 && wxRELEASE_NUMBER < 4 )
    WXHTHEME hTheme = themeHandle;
#else
    HTHEME hTheme = themeHandle;
#endif

    //wxLogDebug(wxT("%i,%i,%i,%i,%i"),PBS_PRESSED,PBS_HOT,PBS_DEFAULTED,
    //    PBS_DISABLED,BP_PUSHBUTTON);

    if ( hTheme )
    {
        int iState;

        int col_ind;

        int component_ind;

        tagRECT trect;
        trect.left = r1.x;
        trect.top = r1.y;
        trect.right = r1.x + r1.width - 1;
        trect.bottom = r1.y + r1.height - 1;

        if ( !(flags & wxCONTROL_POPUP_ARROW) )
        {
            // Normal XP button.

            //col_ind = 1606; // TMT_WINDOW
            col_ind = wxSYS_COLOUR_BTNFACE;

            component_ind = BP_PUSHBUTTON;

            trect.left -= 1;
            trect.top -= 1;
            trect.right += 2;
            trect.bottom += 2;

            iState = PBS_NORMAL;

            if ( flags & wxCONTROL_PRESSED )
                iState = PBS_PRESSED;
            else if ( flags & wxCONTROL_CURRENT )
                iState = PBS_HOT;
            else if ( flags & wxCONTROL_FOCUSED )
                iState = PBS_DEFAULTED;
            else if ( flags & wxCONTROL_DISABLED )
                iState = PBS_DISABLED;

        }
        else
        {
            // Dropdown XP button.

            //col_ind = 1623; // TMT_LIGHT3D
            //col_ind = TMT_LIGHT3D;
            //col_ind = TMT_BUTTONALTERNATEFACE;
            trect.bottom += 1;
            col_ind = wxSYS_COLOUR_WINDOW;

            component_ind = CP_DROPDOWNBUTTON;

            iState = CBXS_NORMAL;

            if ( flags & wxCONTROL_PRESSED )
                iState = CBXS_PRESSED;
            else if ( flags & wxCONTROL_CURRENT )
                iState = CBXS_HOT;
            else if ( flags & wxCONTROL_DISABLED )
                iState = CBXS_DISABLED;

        }

        //wxColour bg_col(wxUxThemeEngine::Get()->GetThemeSysColor(hTheme,col_ind));
        //wxColour bg_col(*wxWHITE);
        wxColour bg_col(::wxSystemSettings::GetColour((wxSystemColour)col_ind));

        dc.SetBrush ( bg_col );
        dc.SetPen ( bg_col );
        dc.DrawRectangle ( r1 );

        wxUxThemeEngine::Get()->DrawThemeBackground( hTheme, dc.GetHDC(),
                                                     component_ind, iState,
                                                     &trect, NULL);

        return;
    }

#endif

    //
    // Draw button in traditional style.
    //

    dc.SetBrush ( wxSystemSettings::GetColour ( wxSYS_COLOUR_BTNFACE ) );

    if ( !(flags & wxCONTROL_PRESSED) )
    {

        dc.SetPen ( wxSystemSettings::GetColour ( wxSYS_COLOUR_3DDKSHADOW ) );
        dc.DrawRectangle ( r1 );
    
        dc.SetBrush ( *wxTRANSPARENT_BRUSH );

        wxRect r2(r1);
        r2.Deflate ( 1 );

        dc.SetPen ( wxSystemSettings::GetColour ( wxSYS_COLOUR_BTNSHADOW ) );

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -