📄 dyntbar.cpp
字号:
/////////////////////////////////////////////////////////////////////////////// Name: dyntbar.cpp// Purpose: wxDynamicToolBar implementation// Author: Aleksandras Gluchovas// Modified by:// Created: ??/10/98// RCS-ID: $Id: dyntbar.cpp,v 1.16 2005/09/23 12:47:42 MR Exp $// Copyright: (c) Aleksandras Gluchovas// Licence: wxWindows license/////////////////////////////////////////////////////////////////////////////// For compilers that support precompilation, includes "wx/wx.h".#include "wx/wxprec.h"#ifdef __BORLANDC__#pragma hdrstop#endif#ifndef WX_PRECOMP#include "wx/wx.h"#endif#include "wx/utils.h" // import wxMin,wxMax macros#include "wx/fl/dyntbar.h"#include "wx/fl/newbmpbtn.h"IMPLEMENT_DYNAMIC_CLASS( wxDynamicToolBar, wxObject )BEGIN_EVENT_TABLE( wxDynamicToolBar, wxToolBarBase ) EVT_SIZE ( wxDynamicToolBar::OnSize ) EVT_PAINT( wxDynamicToolBar::OnPaint ) //EVT_ERASE_BACKGROUND( wxDynamicToolBar::OnEraseBackground )END_EVENT_TABLE()/***** Implementation for class wxToolLayoutItem *****/IMPLEMENT_DYNAMIC_CLASS(wxToolLayoutItem, wxObject)/***** Implementation for class wxDynToolInfo *****/IMPLEMENT_DYNAMIC_CLASS(wxDynToolInfo, wxToolLayoutItem)/***** Implementation for class wxDynamicToolBar *****/wxDynamicToolBar::wxDynamicToolBar() : mpLayoutMan( NULL ), mSepartorSize( 8 ), mVertGap ( 0 ), mHorizGap( 0 ){}wxDynamicToolBar::wxDynamicToolBar(wxWindow *parent, const wxWindowID id, const wxPoint& pos, const wxSize& size, const long style, const int orientation, const int RowsOrColumns, const wxString& name ) : mpLayoutMan( NULL ), mSepartorSize( 8 ), mVertGap ( 0 ), mHorizGap( 0 ){ Create(parent, id, pos, size, style, orientation, RowsOrColumns, name); SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_3DFACE) );}bool wxDynamicToolBar::Create(wxWindow *parent, const wxWindowID id, const wxPoint& pos, const wxSize& size, const long style, const int WXUNUSED(orientation), const int WXUNUSED(RowsOrColumns), const wxString& name){ // cut&pasted from wxtbatsmpl.h if ( ! wxWindow::Create(parent, id, pos, size, style, name) ) return false; SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_3DFACE )); return true;}bool wxDynamicToolBar::Realize(void){ // FOR NOW:: nothing return true;}wxDynamicToolBar::~wxDynamicToolBar(void){ if ( mpLayoutMan ) delete mpLayoutMan; size_t i; for( i = 0; i != mTools.Count(); ++i ) { delete mTools[i]; }}void wxDynamicToolBar::AddTool( int toolIndex, wxWindow* pToolWindow, const wxSize& WXUNUSED(size) ){ wxDynToolInfo* pInfo = new wxDynToolInfo(); pInfo->mpToolWnd = pToolWindow; pInfo->mIndex = toolIndex; pInfo->mIsSeparator = false; int x,y; pToolWindow->GetSize( &x, &y ); pInfo->mRealSize.x = x; pInfo->mRealSize.y = y; pInfo->mRect.width = x; pInfo->mRect.height = y; mTools.Add( pInfo );}void wxDynamicToolBar::AddTool( int toolIndex, const wxString& imageFileName, wxBitmapType imageFileType, const wxString& labelText, bool alignTextRight, bool isFlat ){ wxNewBitmapButton* pBtn = new wxNewBitmapButton( imageFileName, imageFileType, labelText, ( alignTextRight ) ? NB_ALIGN_TEXT_RIGHT : NB_ALIGN_TEXT_BOTTOM, isFlat ); pBtn->Create( this, toolIndex ); pBtn->Reshape(); AddTool( toolIndex, pBtn );}void wxDynamicToolBar::AddTool( int toolIndex, wxBitmap labelBmp, const wxString& labelText, bool alignTextRight, bool isFlat ){ wxNewBitmapButton* pBtn = new wxNewBitmapButton( labelBmp, labelText, ( alignTextRight ) ? NB_ALIGN_TEXT_RIGHT : NB_ALIGN_TEXT_BOTTOM, isFlat ); pBtn->Create( this, toolIndex ); pBtn->Reshape(); AddTool( toolIndex, pBtn );}wxToolBarToolBase* wxDynamicToolBar::AddTool(const int toolIndex, const wxBitmap& bitmap, const wxBitmap& WXUNUSED(pushedBitmap), const bool WXUNUSED(toggle), const long WXUNUSED(xPos), const long WXUNUSED(yPos), wxObject *WXUNUSED(clientData), const wxString& helpString1, const wxString& WXUNUSED(helpString2)){ wxNewBitmapButton* pBmpBtn = new wxNewBitmapButton( bitmap ); pBmpBtn->Create( this, toolIndex ); pBmpBtn->Reshape();#if wxUSE_TOOLTIPS pBmpBtn->SetToolTip( helpString1 );#else wxUnusedVar( helpString1 );#endif // wxUSE_TOOLTIPS AddTool( toolIndex, pBmpBtn ); return NULL;}wxDynToolInfo* wxDynamicToolBar::GetToolInfo( int toolIndex ){ size_t i; for( i = 0; i != mTools.Count(); ++i ) { if ( mTools[i]->mIndex == toolIndex ) return mTools[i]; } return NULL;}void wxDynamicToolBar::RemveTool( int toolIndex ){ size_t i; for( i = 0; i != mTools.Count(); ++i ) { if ( mTools[i]->mIndex == toolIndex ) { if ( mTools[i]->mpToolWnd ) { mTools[i]->mpToolWnd->Destroy(); } delete mTools[i]; // HVL To be tested!!!#if wxCHECK_VERSION(2,3,2) mTools.RemoveAt(i);#else mTools.Remove(i);#endif Layout(); return; } } // TODO:: if not found, should it be an assertion?}void wxDynamicToolBar::AddSeparator( wxWindow* pSepartorWnd ){ wxDynToolInfo* pInfo = new wxDynToolInfo(); pInfo->mpToolWnd = pSepartorWnd; pInfo->mIndex = -1; pInfo->mIsSeparator = true; // Do we draw a separator or is a other object? if ( pSepartorWnd ) { // hvl => Is there a way to know if it was already created? // hvl => shouldn't the pSepartorWnd be created? (like one should expect?) // pSepartorWnd->Create( this, -1 ); int x,y; pSepartorWnd->GetSize( &x, &y ); pInfo->mRealSize.x = x; pInfo->mRealSize.y = y; pInfo->mRect.width = x; pInfo->mRect.height = y; } else { // Init x and y to the default. pInfo->mRealSize.x = 0; pInfo->mRealSize.y = 0; // Init height and width to the normal size of a separator. pInfo->mRect.width = mSepartorSize; pInfo->mRect.height = mSepartorSize; } mTools.Add( pInfo );}void wxDynamicToolBar::OnEraseBackground( wxEraseEvent& WXUNUSED(event) ){ // FOR NOW:: nothing}void wxDynamicToolBar::OnSize( wxSizeEvent& WXUNUSED(event) ){ //SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_3DFACE ) ); Layout();}void wxDynamicToolBar::DrawSeparator( wxDynToolInfo& info, wxDC& dc ){ // check the orientation of separator if ( info.mRect.width < info.mRect.height ) { int midX = info.mRect.x + info.mRect.width/2 - 1; dc.SetPen( *wxGREY_PEN ); dc.DrawLine( midX, info.mRect.y, midX, info.mRect.y + info.mRect.height+1 ); dc.SetPen( *wxWHITE_PEN ); dc.DrawLine( midX+1, info.mRect.y, midX+1, info.mRect.y + info.mRect.height+1 ); } else { int midY = info.mRect.y + info.mRect.height/2 - 1; dc.SetPen( *wxGREY_PEN ); dc.DrawLine( info.mRect.x, midY, info.mRect.x + info.mRect.width+1, midY ); dc.SetPen( *wxWHITE_PEN ); dc.DrawLine( info.mRect.x, midY + 1, info.mRect.x + info.mRect.width+1, midY + 1 ); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -