home *** CD-ROM | disk | FTP | other *** search
- /* Project toolctrl
- DHB Software
- Copyright ⌐ 1996. All Rights Reserved.
-
- SUBSYSTEM: listree.apx Application
- FILE: toolbar.cpp
- AUTHOR: David H. Borg
-
-
- OVERVIEW
- ========
- Source file for implementation of ToolBar (TWindow).
- */
-
-
- #include <owl\owlpch.h>
- #pragma hdrstop
-
- #include "toolbar.h"
-
-
- // A command enabler for the toolbar. This makes the toolbar automatically
- // enable and disable the buttons, just like the OWL TControlBar.
- class ToolBarButtonEnabler : public TCommandEnabler {
- public:
- ToolBarButtonEnabler(HWND hWndReceiver, ToolBar* tb, uint id)
- : TCommandEnabler( id, hWndReceiver) {
- toolBar = tb;
- }
-
- // override member functions of TCommandEnabler
- void Enable (bool enable);
- void SetText (const char far* text);
- void SetCheck (int state);
-
- protected:
- ToolBar* toolBar;
- };
-
-
- void ToolBarButtonEnabler::Enable(bool enable)
- {
- TCommandEnabler::Enable(enable);
- toolBar->SendMessage( TB_ENABLEBUTTON, Id, enable);
- }
-
-
- void ToolBarButtonEnabler::SetText(const char far* /*text*/)
- {
- // implement later, do nothing for now
- }
-
-
- void ToolBarButtonEnabler::SetCheck(int state)
- {
- toolBar->SendMessage( TB_CHECKBUTTON, Id, state);
- }
-
- // Initialization parameters for tbButton array. Include one line per button.
- // A better way to do this would be to implement a ToolBar::InsertButton(...)
- // function to insert each button in TApplication::InitMainWindow()
- static TBBUTTON tbButton[] = {
- { STD_FILENEW, CM_FILENEW, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0,0}, 0, 0 },
- { STD_FILEOPEN, CM_FILEOPEN, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0,0}, 0, 0},
- { STD_FILESAVE, CM_FILESAVE1, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0,0}, 0, 0},
- { 0, 0, 0, TBSTYLE_SEP, {0,0}, 0, 0},
- { STD_PRINT, CM_FILEPRINT, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0,0}, 0, 0},
- { 0, 0, 0, TBSTYLE_SEP, {0,0}, 0, 0},
- { STD_UNDO, CM_EDITUNDO, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0,0}, 0, 0},
- { STD_CUT, CM_EDITCUT, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0,0}, 0, 0},
- { STD_COPY, CM_EDITCOPY, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0,0}, 0, 0},
- { STD_PASTE, CM_EDITPASTE, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0,0}, 0, 0},
- { 0, 0, 0, TBSTYLE_SEP, {0,0}, 0, 0},
- { STD_DELETE, CM_EDITDELETE, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0,0}, 0, 0},
- { 0, 0, 0, TBSTYLE_SEP, {0,0}, 0, 0},
- { STD_FIND, CM_EDITFIND, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0,0}, 0, 0},
- { STD_REPLACE, CM_EDITREPLACE, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0,0}, 0, 0}
- }; // end of inittbbuttontemplate
-
- const int toolBarItems = sizeof( tbButton) / sizeof( tbButton[0]);
- const int nStdItems = 14; // there are 15 standard bitmap items
- const int nViewItems = 12; // there are 12 view bitmap items
- const int firstViewButton = 4; // first view button in structure
-
- //
- // Build a response table for all messages/commands handled
- // by the application.
- //
- DEFINE_RESPONSE_TABLE1(ToolBar, TWindow)
- //{{ToolBarRSP_TBL_BEGIN}}
- EV_NOTIFY_AT_CHILD(BN_CLICKED, BnClicked),
- EV_MESSAGE( WM_NOTIFY, EvCommonControlNotify),
- EV_WM_PAINT,
- //{{ToolBarRSP_TBL_END}}
- END_RESPONSE_TABLE;
-
-
- //{{ToolBar Implementation}}
-
-
- // the tab control is derived from TWindow with specific Attributes
- ToolBar::ToolBar (TWindow* parent, int id, int w, int h, TModule* module):
- TWindow(parent, 0, module)
- {
- Attr.Id = id;
- Attr.X = 0;
- Attr.Y = 0;
- Attr.W = w;
- Attr.H = h;
- Attr.ExStyle = 0;
- Attr.Style = WS_CHILD | WS_VISIBLE | TBSTYLE_TOOLTIPS | CCS_NOMOVEY;
- }
-
-
- // the default constructor is not used
- ToolBar::ToolBar (TWindow* parent, const char far* title, TModule* module):
- TWindow(parent, title, module)
- {
- // INSERT>> Your constructor code here.
-
- }
-
-
- ToolBar::~ToolBar ()
- {
- Destroy();
-
- // INSERT>> Your destructor code here.
-
- }
-
-
- void ToolBar::EvPaint ()
- {
- // Let Common Control paint the window, don't call TWindow::EvPaint()
- DefaultProcessing();
- }
-
-
- char far* ToolBar::GetClassName ()
- {
- // return the Windows 95 Toolbar common control class name
- // this is what makes the window a tool bar
- return TOOLBARCLASSNAME;
- }
-
-
- void ToolBar::SetupWindow ()
- {
- TWindow::SetupWindow();
-
- // INSERT>> Your code here.
-
- SetupToolBar();
- }
-
-
- // Create the toolbar control and add the buttons and commands.
- void ToolBar::SetupToolBar ()
- {
- // Tell the control the size of button structure.
- SendMessage( TB_BUTTONSTRUCTSIZE, (WPARAM) sizeof(TBBUTTON), 0);
-
- // Initialize structures that identify the bitmaps.
- tbStandardBmp.hInst = HINST_COMMCTRL;
- tbStandardBmp.nID = IDB_STD_SMALL_COLOR;
-
- // initialize toolbar with large bitmaps
- stdBitmap = SendMessage( TB_ADDBITMAP, (WPARAM)nStdItems, (LPARAM)&tbStandardBmp);
-
- // Add the standard bitmap base number to the view offsets from the template.
- // note: this is not needed for the standard bitmaps if added first.
- // for( int j = firstViewButton; j < toolBarItems; j++){
- // tbButton[j].iBitmap += viewBitmap;
- // }
-
- // Send the initialized buttons structure to the common controls dll.
- SendMessage( TB_ADDBUTTONS, (WPARAM)toolBarItems, (LPARAM)(LPTBBUTTON)tbButton);
-
- // Automatically size of the toolbar to the button size.
- SendMessage( TB_AUTOSIZE, 0, 0);
- }
-
-
- // This function handles the messages sent by Windows 95 common controls.
- LRESULT ToolBar::EvCommonControlNotify( WPARAM /*wParam*/, LPARAM lParam)
- {
- LRESULT retVal = false;
- NMHDR FAR *pNmhdr = (NMHDR FAR *)lParam;
- LPTBNOTIFY lpTbNotify = (LPTBNOTIFY)lParam;
-
- switch( pNmhdr->code){
- case TTN_NEEDTEXT: // process tool tip control message
- {
- LPTOOLTIPTEXT lpText;
-
- lpText = (LPTOOLTIPTEXT)lParam;
- lpText->hinst = GetModule()->GetInstance();
- lpText->lpszText = MAKEINTRESOURCE(lpText->hdr.idFrom);
- }
- break;
- case TBN_GETBUTTONINFO: // Customize Toolbar dialog nees this info
- if (lpTbNotify->iItem < toolBarItems) {
- lpTbNotify->tbButton = tbButton[lpTbNotify->iItem];
- retVal = true;
- }
- break;
- case TBN_QUERYINSERT: // Can Customize Dialog insert?
- retVal = true;
- break;
- case TBN_QUERYDELETE: // Can Customize Dialog delete?
- retVal = true;
- break;
- default:
- break;
- }
- return retVal;
- }
-
-
- // Pressing a toolbar button causes a BN_CLICKED message to be sent.
- // Re-transmit the BN_CLICKED Id as CM_... message to simulate menu selections.
- void ToolBar::BnClicked()
- {
- TCurrentEvent& currentEvent = GetCurrentEvent();
-
- // Post button Id to simulate a menu command.
- Parent->PostMessage( WM_COMMAND, LOWORD(currentEvent.WParam));
- }
-
-
- // IdleAction takes care of button enabling through ToolBarButtonEnabler.
- bool ToolBar::IdleAction (long idleCount)
- {
- if (idleCount == 0) {
- for( int i=0; i < toolBarItems; i++){
- if( tbButton[i].fsStyle != TBSTYLE_BUTTON)
- continue;
- // Must use SendMessage here since a ptr to a temp is passed
- Parent->SendMessage( WM_COMMAND_ENABLE, 0,
- (LPARAM)&ToolBarButtonEnabler( Parent->HWindow, this,
- tbButton[i].idCommand));
- }
- }
- return TWindow::IdleAction(idleCount);
- }
-
-
-