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

📄 tbarwce.cpp

📁 很牛的GUI源码wxWidgets-2.8.0.zip 可在多种平台下运行.
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    {        if ( !::SendMessage(GetHwnd(), TB_DELETEBUTTON, pos, 0) )        {            wxLogLastError(wxT("TB_DELETEBUTTON"));            return false;        }    }    tool->Detach();    // and finally reposition all the controls after this button (the toolbar    // takes care of all normal items)    for ( /* node -> first after deleted */ ; node; node = node->GetNext() )    {        wxToolBarToolBase *tool2 = node->GetData();        if ( tool2->IsControl() )        {            int x;            wxControl *control = tool2->GetControl();            control->GetPosition(&x, NULL);            control->Move(x - width, wxDefaultCoord);        }    }    return true;}bool wxToolMenuBar::Realize(){    const size_t nTools = GetToolsCount();    if ( nTools == 0 )    {        // nothing to do        return true;    }#if 0    // delete all old buttons, if any    for ( size_t pos = 0; pos < m_nButtons; pos++ )    {        if ( !::SendMessage(GetHwnd(), TB_DELETEBUTTON, 0, 0) )        {            wxLogDebug(wxT("TB_DELETEBUTTON failed"));        }    }#endif // 0    bool lastWasRadio = false;    wxToolBarToolsList::Node* node;    for ( node = m_tools.GetFirst(); node; node = node->GetNext() )    {        wxToolMenuBarTool *tool = (wxToolMenuBarTool*) node->GetData();        TBBUTTON buttons[1] ;        TBBUTTON& button = buttons[0];        wxZeroMemory(button);        bool isRadio = false;        switch ( tool->GetStyle() )        {            case wxTOOL_STYLE_CONTROL:                button.idCommand = tool->GetId();                // fall through: create just a separator too                // TODO: controls are not yet supported on wxToolMenuBar.            case wxTOOL_STYLE_SEPARATOR:                button.fsState = TBSTATE_ENABLED;                button.fsStyle = TBSTYLE_SEP;                break;            case wxTOOL_STYLE_BUTTON:                if ( HasFlag(wxTB_TEXT) )                {                    const wxString& label = tool->GetLabel();                    if ( !label.empty() )                    {                        button.iString = (int)label.c_str();                    }                }                const wxBitmap& bmp = tool->GetNormalBitmap();                wxBitmap bmpToUse = bmp;                if (bmp.GetWidth() < 16 || bmp.GetHeight() < 16 || bmp.GetMask() != NULL)                {                    wxMemoryDC memDC;                    wxBitmap b(16,16);                    memDC.SelectObject(b);                    wxColour col = wxColour(192,192,192);                    memDC.SetBackground(wxBrush(col));                    memDC.Clear();                    int x = (16 - bmp.GetWidth())/2;                    int y = (16 - bmp.GetHeight())/2;                    memDC.DrawBitmap(bmp, x, y, true);                    memDC.SelectObject(wxNullBitmap);                    bmpToUse = b;                    tool->SetNormalBitmap(b);                }                int n = 0;                if ( bmpToUse.Ok() )                {                    n = ::CommandBar_AddBitmap( (HWND) GetHWND(), NULL, (int) (HBITMAP) bmpToUse.GetHBITMAP(),                                                    1, 16, 16 );                }                button.idCommand = tool->GetId();                button.iBitmap = n;                if ( tool->IsEnabled() )                    button.fsState |= TBSTATE_ENABLED;                if ( tool->IsToggled() )                    button.fsState |= TBSTATE_CHECKED;                switch ( tool->GetKind() )                {                    case wxITEM_RADIO:                        button.fsStyle = TBSTYLE_CHECKGROUP;                        if ( !lastWasRadio )                        {                            // the first item in the radio group is checked by                            // default to be consistent with wxGTK and the menu                            // radio items                            button.fsState |= TBSTATE_CHECKED;                            tool->Toggle(true);                        }                        isRadio = true;                        break;                    case wxITEM_CHECK:                        button.fsStyle = TBSTYLE_CHECK;                        break;                    default:                        wxFAIL_MSG( _T("unexpected toolbar button kind") );                        // fall through                    case wxITEM_NORMAL:                        button.fsStyle = TBSTYLE_BUTTON;                }                break;        }        if ( !::CommandBar_AddButtons( (HWND) GetHWND(), 1, buttons ) )        {            wxFAIL_MSG( wxT("Could not add toolbar button."));        }        lastWasRadio = isRadio;    }    return true;}bool wxToolMenuBar::MSWCommand(WXUINT WXUNUSED(cmd), WXWORD id){    wxToolBarToolBase *tool = FindById((int)id);    if ( !tool )    {        if (m_menuBar)        {            wxMenuItem *item = m_menuBar->FindItem(id);            if (item && item->IsCheckable())            {                item->Toggle();            }        }        wxCommandEvent event(wxEVT_COMMAND_MENU_SELECTED);        event.SetEventObject(this);        event.SetId(id);        event.SetInt(id);        return GetEventHandler()->ProcessEvent(event);    }    if ( tool->CanBeToggled() )    {        LRESULT state = ::SendMessage(GetHwnd(), TB_GETSTATE, id, 0);        tool->Toggle((state & TBSTATE_CHECKED) != 0);    }    bool toggled = tool->IsToggled();    // avoid sending the event when a radio button is released, this is not    // interesting    if ( !tool->CanBeToggled() || tool->GetKind() != wxITEM_RADIO || toggled )    {        // OnLeftClick() can veto the button state change - for buttons which        // may be toggled only, of couse        if ( !OnLeftClick((int)id, toggled) && tool->CanBeToggled() )        {            // revert back            toggled = !toggled;            tool->SetToggle(toggled);            ::SendMessage(GetHwnd(), TB_CHECKBUTTON, id, MAKELONG(toggled, 0));        }    }    return true;}WXLRESULT wxToolMenuBar::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam){    switch ( nMsg )    {        case WM_SIZE:            break;        case WM_MOUSEMOVE:            // we don't handle mouse moves, so always pass the message to            // wxControl::MSWWindowProc            HandleMouseMove(wParam, lParam);            break;        case WM_PAINT:            break;    }    return MSWDefWindowProc(nMsg, wParam, lParam);}#else////////////// For Smartphone// ----------------------------------------------------------------------------// Event table// ----------------------------------------------------------------------------IMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxToolBarBase)BEGIN_EVENT_TABLE(wxToolBar, wxToolBarBase)END_EVENT_TABLE()wxToolBarToolBase *wxToolBar::CreateTool(int id,                                         const wxString& label,                                         const wxBitmap& bmpNormal,                                         const wxBitmap& bmpDisabled,                                         wxItemKind kind,                                         wxObject *clientData,                                         const wxString& shortHelp,                                         const wxString& longHelp){    return new wxToolBarToolBase(this, id, label, bmpNormal, bmpDisabled, kind,                             clientData, shortHelp, longHelp);}wxToolBarToolBase *wxToolBar::CreateTool(wxControl *control){    return new wxToolBarToolBase(this, control);}bool wxToolBar::Create(wxWindow *parent,                       wxWindowID WXUNUSED(id),                       const wxPoint& WXUNUSED(pos),                       const wxSize& WXUNUSED(size),                       long style,                       const wxString& name){    // TODO: we may need to make this a dummy hidden window to    // satisfy other parts of wxWidgets.    parent->AddChild(this);    SetWindowStyle(style);    SetName(name);    return true;}// ----------------------------------------------------------------------------// adding/removing tools// ----------------------------------------------------------------------------bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), wxToolBarToolBase *tool){    tool->Attach(this);    return true;}bool wxToolBar::DoDeleteTool(size_t WXUNUSED(pos), wxToolBarToolBase *tool){    tool->Detach();    return true;}wxToolBarToolBase *wxToolBar::FindToolForPosition(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y)) const{    return NULL;}// ----------------------------------------------------------------------------// tool state// ----------------------------------------------------------------------------void wxToolBar::DoEnableTool(wxToolBarToolBase *WXUNUSED(tool), bool WXUNUSED(enable)){}void wxToolBar::DoToggleTool(wxToolBarToolBase *WXUNUSED(tool), bool WXUNUSED(toggle)){}void wxToolBar::DoSetToggle(wxToolBarToolBase *WXUNUSED(tool), bool WXUNUSED(toggle)){    wxFAIL_MSG( _T("not implemented") );}#endif    // !__SMARTPHONE__#endif // wxUSE_TOOLBAR

⌨️ 快捷键说明

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