GithubHelp home page GithubHelp logo

baradzenka / toolboxctrl Goto Github PK

View Code? Open in Web Editor NEW
10.0 1.0 3.0 65 KB

The control representing a regular ToolBar in the form of a tree. Command buttons are located in tree branches and can be checked and disabled. MFC control, drawing with GDI and GDI+.

License: The Unlicense

C++ 98.11% C 1.89%
windows c-plus-plus visual-studio control gdi tree ui-components unlicense mfc gdi-plus

toolboxctrl's Introduction

ToolBoxCtrl

Example

Introduction

The control is similar to a regular ToolBar. It represents a tree. The command buttons are located in the branches of the tree and you have the ability to check and disable them.

Various uses of the control are possible. For example, as a sidebar for selecting the contents of the main program window or the current page in the settings window. Also, the control is convenient when used in different editors to select a working tool or component that can be dragged with the mouse into the editor field.

The control is derived from CWnd and is a common control based on MFC. It is possible to put it on any window: main frame, dialog, etc.

Using the Code

To create the control and add elements to it, do the following:

#include "ToolBoxCtrl.h"

ToolBoxCtrlEx<ToolBoxCtrlStyle_base_system> m_ToolBox;

...

if( !m_ToolBox.Create(this, WS_VISIBLE, CRect(10,10,100,200), ID_ToolBoxCtrl) )
  return -1;    // error.

// Load images for groups.
m_ToolBox.CreateImages(ToolBoxCtrl::ImageGroup,NULL,ID_PNG_GROUP_IMAGES,true,11);
// Load images for items.
m_ToolBox.CreateImages(ToolBoxCtrl::ImageItem,NULL,ID_PNG_ITEM_IMAGES,true,16);

// Add groups and items.
m_ToolBox.AddGroup(_T("Group 1"));
  m_ToolBox.AddItem(0, 1, _T("Item 1.1"),_T("Description for 'Item 1.1'"),0);
  m_ToolBox.AddItem(0, 2, _T("Item 1.2"),_T("Description for 'Item 1.2'"),1);
m_ToolBox.AddGroup(_T("Group 2");
  m_ToolBox.AddItem(1, 3, _T("Item 2.1"),_T("Description for 'Item 2.1'"),-1);
  m_ToolBox.AddItem(1, 4, _T("Item 2.2"),_T("Description for 'Item 2.2'"),2);
  m_ToolBox.AddItem(1, 5, _T("Item 2.3"),_T("Description for 'Item 2.3'"),3);

// Load state from registry.  
if( !m_ToolBox.LoadState(AfxGetApp(),_T("ToolBoxCtrl"),_T("State")) )
  m_ToolBox.CollapseGroup(1);   // some default state.

m_ToolBox.Update(true);

Class ToolBoxCtrl does not perform any rendering. For its drawing, it calls the functions of ToolBoxCtrl::Draw interface. To draw ToolBoxCtrl, you need to create an object inherited from the ToolBoxCtrl::Draw class, implement its functions, and pass the ToolBoxCtrl::Draw pointer to ToolBoxCtrl using the ToolBoxCtrl::SetDrawManager function call. Similarly, a ToolBoxCtrl::IRecalc interface is used to specify the spacing between ToolBoxCtrl areas. A ToolBoxCtrl::ToolTip interface will help you create tooltips for items. There is also a ToolBoxCtrl::Notify class for notifying about events in ToolBoxCtrl. An implementation of any of these four interfaces must exist for the entire time the control is running.

The ToolBoxCtrl::Draw and ToolBoxCtrl::IRecalc interfaces together define how a control will look, and their implementation can be called a style. The ToolBoxCtrl.cpp/ToolBoxCtrl.h files include four predefined style classes: ToolBoxCtrlStyle_base_system, ToolBoxCtrlStyle_classic_system, ToolBoxCtrlStyle_base_orange, and ToolBoxCtrlStyle_classic_orange. The first two classes use the system colors to draw the ToolBoxCtrl. If you are working with only one style, then use the template class ToolBoxCtrlEx. The name of the style class is specified as a template parameter, for example:

ToolBoxCtrlEx<ToolBoxCtrlStyle_base_system> m_ToolBox;

The user can work with ToolBoxCtrl in one of two ways.

  • When you pass the ActivateModeClick value to the ToolBoxCtrl::SetActivateMode function, tree items behave like regular buttons. When you click on them, the Notify::OnClickItem function is called.

  • When using the ActivateModeDrag value, the tree items must be dragged with the mouse, for example, into the editor area located next to it. At the start of the drag, the Notify::OnDragItemStart function is called. See the OnDragItemStart, OnMouseMove, OnLButtonUp, OnCaptureChanged functions located in the Dialog.cpp file to learn more about the possible implementation of this mechanism in your program.

Tree elements can be checked and/or disabled. You can do this at any time by calling ToolBoxCtrl::CheckItem and ToolBoxCtrl::EnableItem. Also, the control itself is able to send a request to update the state of the items in it. To do this, it calls the Notify::OnUpdateItemState function at short intervals. This mode is enabled by calling ToolBoxCtrl::EnableDynamicItemsUpdate(true). The Notify::OnUpdateItemState function can be called separately for each visible item in the tree, or once for all items. This is determined by the value passed to the ToolBoxCtrl::SetUpdateMode function.

The control requires a call to ToolBoxCtrl::Update() after changing its state, properties, or the number of groups and elements in it.

Good luck! :-)

toolboxctrl's People

Contributors

baradzenka avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.