📄 tbarwce.cpp
字号:
/////////////////////////////////////////////////////////////////////////////
// Name: msw/wince/tbarwce.cpp
// Purpose: wxToolBar for Windows CE
// Author: Julian Smart
// Modified by:
// Created: 2003-07-12
// RCS-ID: $Id: tbarwce.cpp,v 1.27.2.2 2006/03/15 09:57:00 JS Exp $
// Copyright: (c) Julian Smart
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// ============================================================================
// declarations
// ============================================================================
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
#pragma implementation "tbarwce.h"
#endif
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include "wx/frame.h"
#include "wx/log.h"
#include "wx/intl.h"
#include "wx/dynarray.h"
#include "wx/settings.h"
#include "wx/bitmap.h"
#include "wx/dcmemory.h"
#include "wx/control.h"
#endif
// Use the WinCE-specific toolbar only if we're either compiling
// with a WinCE earlier than 4, or we wish to emulate a PocketPC-style UI
#if wxUSE_TOOLBAR && wxUSE_TOOLBAR_NATIVE && (_WIN32_WCE < 400 || defined(__POCKETPC__) || defined(__SMARTPHONE__))
#include "wx/toolbar.h"
#if !defined(__GNUWIN32__) && !defined(__SALFORDC__)
#include "malloc.h"
#endif
#include "wx/msw/private.h"
#include <windows.h>
#include <windowsx.h>
#include <tchar.h>
#include <ole2.h>
#include <shellapi.h>
#include <commctrl.h>
#if defined(WINCE_WITHOUT_COMMANDBAR)
#include <aygshell.h>
#endif
#include "wx/msw/wince/missing.h"
#include "wx/msw/winundef.h"
#if !defined(__SMARTPHONE__)
///////////// This implementation is for PocketPC.
///////////// See later for the Smartphone dummy toolbar class.
// ----------------------------------------------------------------------------
// Event table
// ----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC_CLASS(wxToolMenuBar, wxToolBar)
BEGIN_EVENT_TABLE(wxToolMenuBar, wxToolBar)
END_EVENT_TABLE()
// ----------------------------------------------------------------------------
// private classes
// ----------------------------------------------------------------------------
class wxToolMenuBarTool : public wxToolBarToolBase
{
public:
wxToolMenuBarTool(wxToolBar *tbar,
int id,
const wxString& label,
const wxBitmap& bmpNormal,
const wxBitmap& bmpDisabled,
wxItemKind kind,
wxObject *clientData,
const wxString& shortHelp,
const wxString& longHelp)
: wxToolBarToolBase(tbar, id, label, bmpNormal, bmpDisabled, kind,
clientData, shortHelp, longHelp)
{
m_nSepCount = 0;
m_bitmapIndex = -1;
}
wxToolMenuBarTool(wxToolBar *tbar, wxControl *control)
: wxToolBarToolBase(tbar, control)
{
m_nSepCount = 1;
m_bitmapIndex = -1;
}
virtual void SetLabel(const wxString& label)
{
if ( label == m_label )
return;
wxToolBarToolBase::SetLabel(label);
// we need to update the label shown in the toolbar because it has a
// pointer to the internal buffer of the old label
//
// TODO: use TB_SETBUTTONINFO
}
// set/get the number of separators which we use to cover the space used by
// a control in the toolbar
void SetSeparatorsCount(size_t count) { m_nSepCount = count; }
size_t GetSeparatorsCount() const { return m_nSepCount; }
void SetBitmapIndex(int idx) { m_bitmapIndex = idx; }
int GetBitmapIndex() const { return m_bitmapIndex; }
private:
size_t m_nSepCount;
int m_bitmapIndex;
};
// ============================================================================
// implementation
// ============================================================================
// ----------------------------------------------------------------------------
// wxToolBarTool
// ----------------------------------------------------------------------------
wxToolBarToolBase *wxToolMenuBar::CreateTool(int id,
const wxString& label,
const wxBitmap& bmpNormal,
const wxBitmap& bmpDisabled,
wxItemKind kind,
wxObject *clientData,
const wxString& shortHelp,
const wxString& longHelp)
{
return new wxToolMenuBarTool(this, id, label, bmpNormal, bmpDisabled, kind,
clientData, shortHelp, longHelp);
}
wxToolBarToolBase *wxToolMenuBar::CreateTool(wxControl *control)
{
return new wxToolMenuBarTool(this, control);
}
// ----------------------------------------------------------------------------
// wxToolBar construction
// ----------------------------------------------------------------------------
void wxToolMenuBar::Init()
{
wxToolBar::Init();
m_nButtons = 0;
m_menuBar = NULL;
}
bool wxToolMenuBar::Create(wxWindow *parent,
wxWindowID id,
const wxPoint& pos,
const wxSize& size,
long style,
const wxString& name,
wxMenuBar* menuBar)
{
// common initialisation
if ( !CreateControl(parent, id, pos, size, style, wxDefaultValidator, name) )
return false;
// MSW-specific initialisation
if ( !MSWCreateToolbar(pos, size, menuBar) )
return false;
// set up the colors and fonts
SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_MENUBAR));
SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
return true;
}
bool wxToolMenuBar::MSWCreateToolbar(const wxPoint& WXUNUSED(pos), const wxSize& WXUNUSED(size), wxMenuBar* menuBar)
{
SetMenuBar(menuBar);
if (m_menuBar)
m_menuBar->SetToolBar(this);
#if defined(WINCE_WITHOUT_COMMANDBAR)
// Create the menubar.
SHMENUBARINFO mbi;
memset (&mbi, 0, sizeof (SHMENUBARINFO));
mbi.cbSize = sizeof (SHMENUBARINFO);
mbi.hwndParent = (HWND) GetParent()->GetHWND();
#ifdef __SMARTPHONE__
mbi.nToolBarId = 5002;
#else
mbi.nToolBarId = 5000;
#endif
mbi.nBmpId = 0;
mbi.cBmpImages = 0;
mbi.dwFlags = 0 ; // SHCMBF_EMPTYBAR;
mbi.hInstRes = wxGetInstance();
if (!SHCreateMenuBar(&mbi))
{
wxFAIL_MSG( _T("SHCreateMenuBar failed") );
return false;
}
SetHWND((WXHWND) mbi.hwndMB);
#else
HWND hWnd = CommandBar_Create(wxGetInstance(), (HWND) GetParent()->GetHWND(), GetId());
SetHWND((WXHWND) hWnd);
#endif
// install wxWidgets window proc for this window
SubclassWin(m_hWnd);
if (menuBar)
menuBar->Create();
return true;
}
void wxToolMenuBar::Recreate()
{
// TODO
}
wxToolMenuBar::~wxToolMenuBar()
{
if (GetMenuBar())
GetMenuBar()->SetToolBar(NULL);
}
// Return HMENU for the menu associated with the commandbar
WXHMENU wxToolMenuBar::GetHMenu()
{
#if defined(__HANDHELDPC__)
return 0;
#else
if (GetHWND())
{
return (WXHMENU) (HMENU)::SendMessage((HWND) GetHWND(), SHCMBM_GETMENU, (WPARAM)0, (LPARAM)0);
}
else
return 0;
#endif
}
// ----------------------------------------------------------------------------
// adding/removing tools
// ----------------------------------------------------------------------------
bool wxToolMenuBar::DoInsertTool(size_t WXUNUSED(pos), wxToolBarToolBase *tool)
{
// nothing special to do here - we really create the toolbar buttons in
// Realize() later
tool->Attach(this);
return true;
}
bool wxToolMenuBar::DoDeleteTool(size_t pos, wxToolBarToolBase *tool)
{
// the main difficulty we have here is with the controls in the toolbars:
// as we (sometimes) use several separators to cover up the space used by
// them, the indices are not the same for us and the toolbar
// first determine the position of the first button to delete: it may be
// different from pos if we use several separators to cover the space used
// by a control
wxToolBarToolsList::compatibility_iterator node;
for ( node = m_tools.GetFirst(); node; node = node->GetNext() )
{
wxToolBarToolBase *tool2 = node->GetData();
if ( tool2 == tool )
{
// let node point to the next node in the list
node = node->GetNext();
break;
}
if ( tool2->IsControl() )
{
pos += ((wxToolMenuBarTool *)tool2)->GetSeparatorsCount() - 1;
}
}
// now determine the number of buttons to delete and the area taken by them
size_t nButtonsToDelete = 1;
// get the size of the button we're going to delete
RECT r;
if ( !::SendMessage(GetHwnd(), TB_GETITEMRECT, pos, (LPARAM)&r) )
{
wxLogLastError(_T("TB_GETITEMRECT"));
}
int width = r.right - r.left;
if ( tool->IsControl() )
{
nButtonsToDelete = ((wxToolMenuBarTool *)tool)->GetSeparatorsCount();
width *= nButtonsToDelete;
}
// do delete all buttons
m_nButtons -= nButtonsToDelete;
while ( nButtonsToDelete-- > 0 )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -