From c81b17c1cbd6dbbfc700f2ff7ffd1eb06ac4dcd4 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Wed, 7 Aug 2013 11:20:12 +0200 Subject: [PATCH] Some more reformatting and adding copyright notices. --- common/tool/context_menu.cpp | 64 +++-- common/tool/tool_base.cpp | 39 ++- common/tool/tool_event.cpp | 110 +++++--- common/tool/tool_interactive.cpp | 47 +++- include/tool/context_menu.h | 15 +- include/tool/tool_base.h | 48 ++-- include/tool/tool_event.h | 449 ++++++++++++++++--------------- include/tool/tool_interactive.h | 12 +- include/view/view.h | 2 +- 9 files changed, 444 insertions(+), 342 deletions(-) diff --git a/common/tool/context_menu.cpp b/common/tool/context_menu.cpp index 2649b2056e..7e791d195b 100644 --- a/common/tool/context_menu.cpp +++ b/common/tool/context_menu.cpp @@ -1,3 +1,27 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2013 CERN + * @author Tomasz Wlostowski + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + #include #include @@ -10,7 +34,7 @@ class CONTEXT_MENU::CMEventHandler : public wxEvtHandler { public: - CMEventHandler( CONTEXT_MENU *aMenu ): + CMEventHandler( CONTEXT_MENU* aMenu ): m_menu(aMenu) {}; void onEvent( wxEvent & aEvent ) @@ -18,54 +42,58 @@ public: TOOL_EVENT evt; wxEventType type = aEvent.GetEventType(); - if(type == wxEVT_MENU_HIGHLIGHT) - evt = TOOL_EVENT (TC_Command, TA_ContextMenuUpdate, aEvent.GetId() ); - else if (type == wxEVT_COMMAND_MENU_SELECTED) - evt = TOOL_EVENT (TC_Command, TA_ContextMenuChoice, aEvent.GetId() ); + if( type == wxEVT_MENU_HIGHLIGHT ) + evt = TOOL_EVENT( TC_Command, TA_ContextMenuUpdate, aEvent.GetId() ); + else if ( type == wxEVT_COMMAND_MENU_SELECTED ) + evt = TOOL_EVENT( TC_Command, TA_ContextMenuChoice, aEvent.GetId() ); - m_menu->m_tool->GetManager()->ProcessEvent(evt); + m_menu->m_tool->GetManager()->ProcessEvent( evt ); } private: - CONTEXT_MENU *m_menu; + CONTEXT_MENU* m_menu; }; -CONTEXT_MENU::CONTEXT_MENU ( ) +CONTEXT_MENU::CONTEXT_MENU() { m_tool = NULL; m_menu = new wxMenu(); - m_handler = new CMEventHandler(this); - m_menu->Connect (wxEVT_MENU_HIGHLIGHT, wxEventHandler( CMEventHandler::onEvent ), NULL, m_handler ); - m_menu->Connect (wxEVT_COMMAND_MENU_SELECTED, wxEventHandler( CMEventHandler::onEvent ), NULL, m_handler ); + m_handler = new CMEventHandler( this ); + m_menu->Connect( wxEVT_MENU_HIGHLIGHT, wxEventHandler( CMEventHandler::onEvent ), NULL, m_handler ); + m_menu->Connect( wxEVT_COMMAND_MENU_SELECTED, wxEventHandler( CMEventHandler::onEvent ), NULL, m_handler ); m_titleSet = false; } -CONTEXT_MENU::~CONTEXT_MENU ( ) + +CONTEXT_MENU::~CONTEXT_MENU() { delete m_menu; delete m_handler; } + void CONTEXT_MENU::SetTitle( const wxString& aTitle ) { - if(m_titleSet) + if( m_titleSet ) { - m_menu->Delete(m_menu->FindItemByPosition(0)); // fixme: this is LAME! - m_menu->Delete(m_menu->FindItemByPosition(0)); + m_menu->Delete( m_menu->FindItemByPosition( 0 ) ); // fixme: this is LAME! + m_menu->Delete( m_menu->FindItemByPosition( 0 ) ); } - m_menu->InsertSeparator(0); - m_menu->Insert(0, new wxMenuItem( m_menu, -1, aTitle, wxEmptyString, wxITEM_NORMAL ) ); + m_menu->InsertSeparator( 0 ); + m_menu->Insert( 0, new wxMenuItem( m_menu, -1, aTitle, wxEmptyString, wxITEM_NORMAL ) ); m_titleSet = true; } + void CONTEXT_MENU::Add ( const wxString& aItem, int aId ) { m_menu->Append( new wxMenuItem( m_menu, aId, aItem, wxEmptyString, wxITEM_NORMAL ) ); } + void CONTEXT_MENU::Clear() { m_titleSet = false; -} \ No newline at end of file +} diff --git a/common/tool/tool_base.cpp b/common/tool/tool_base.cpp index 82b1f1ac55..15409d1a8c 100644 --- a/common/tool/tool_base.cpp +++ b/common/tool/tool_base.cpp @@ -1,22 +1,49 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2013 CERN + * @author Tomasz Wlostowski + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + #include #include -KiGfx::VIEW *TOOL_BASE::getView() +KiGfx::VIEW* TOOL_BASE::getView() { return m_toolMgr->GetView(); } -KiGfx::VIEW_CONTROLS *TOOL_BASE::getViewControls() + +KiGfx::VIEW_CONTROLS* TOOL_BASE::getViewControls() { return m_toolMgr->GetViewControls(); } - -wxWindow * TOOL_BASE::getEditFrameInt() + + +wxWindow* TOOL_BASE::getEditFrameInt() { return m_toolMgr->GetEditFrame(); } -EDA_ITEM * TOOL_BASE::getModelInt() + +EDA_ITEM* TOOL_BASE::getModelInt() { return m_toolMgr->GetModel(); -} \ No newline at end of file +} diff --git a/common/tool/tool_event.cpp b/common/tool/tool_event.cpp index d10822f9c4..3d03692b82 100644 --- a/common/tool/tool_event.cpp +++ b/common/tool/tool_event.cpp @@ -1,3 +1,27 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2013 CERN + * @author Tomasz Wlostowski + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + #include #include @@ -10,12 +34,14 @@ using namespace std; -struct FlagString { +struct FlagString +{ int flag; std::string str; }; -static const std::string flag2string(int flag, const FlagString *exps) + +static const std::string flag2string( int flag, const FlagString* exps ) { std::string rv; for(int i = 0; exps[i].str.length(); i++) @@ -24,78 +50,80 @@ static const std::string flag2string(int flag, const FlagString *exps) return rv; } + const std::string TOOL_EVENT::Format() const { std::string ev; const FlagString categories[] = { - {TC_Mouse, "mouse"}, - {TC_Command, "command"}, - {TC_Message, "message"}, - {TC_View, "view"}, - {0, ""} + { TC_Mouse, "mouse" }, + { TC_Command, "command" }, + { TC_Message, "message" }, + { TC_View, "view" }, + { 0, "" } }; const FlagString actions[] = { - {TA_MouseClick, "click"}, - {TA_MouseUp, "button-up"}, - {TA_MouseDown, "button-down"}, - {TA_MouseDrag, "drag"}, - {TA_MouseMotion, "motion"}, - {TA_MouseWheel, "wheel"}, - {TA_ViewRefresh, "view-refresh"}, - {TA_ViewZoom, "view-zoom"}, - {TA_ViewPan, "view-pan"}, - {TA_ViewDirty, "view-dirty"}, - {TA_ChangeLayer, "change-layer"}, - {TA_CancelTool, "cancel-tool"}, - {TA_ActivateTool, "activate-tool"}, - {TA_ContextMenuUpdate, "context-menu-update"}, - {TA_ContextMenuChoice, "context-menu-choice"}, - {0, ""} + { TA_MouseClick, "click" }, + { TA_MouseUp, "button-up" }, + { TA_MouseDown, "button-down" }, + { TA_MouseDrag, "drag" }, + { TA_MouseMotion, "motion" }, + { TA_MouseWheel, "wheel" }, + { TA_ViewRefresh, "view-refresh" }, + { TA_ViewZoom, "view-zoom" }, + { TA_ViewPan, "view-pan" }, + { TA_ViewDirty, "view-dirty" }, + { TA_ChangeLayer, "change-layer" }, + { TA_CancelTool, "cancel-tool" }, + { TA_ActivateTool, "activate-tool" }, + { TA_ContextMenuUpdate, "context-menu-update" }, + { TA_ContextMenuChoice, "context-menu-choice" }, + { 0, "" } }; const FlagString buttons[] = { - {MB_None, "none"}, - {MB_Left, "left"}, - {MB_Right, "right"}, - {MB_Middle, "middle"}, - {MB_ModShift, "shift"}, - {MB_ModCtrl, "ctrl"}, - {MB_ModAlt, "alt"}, - {0, ""} + { MB_None, "none" }, + { MB_Left, "left" }, + { MB_Right, "right" }, + { MB_Middle, "middle" }, + { MB_ModShift, "shift" }, + { MB_ModCtrl, "ctrl" }, + { MB_ModAlt, "alt" }, + { 0, "" } }; ev = "category: "; - ev += flag2string(m_category, categories); + ev += flag2string( m_category, categories ); ev +=" action: "; - ev += flag2string(m_actions, actions); + ev += flag2string( m_actions, actions ); - if(m_actions & TA_Mouse) + if( m_actions & TA_Mouse ) { ev +=" btns: "; - ev += flag2string(m_mouseButtons, buttons); + ev += flag2string( m_mouseButtons, buttons ); }; - if(m_commandId) + if( m_commandId ) { char tmp[128]; - sprintf(tmp,"cmd-id: %d", *m_commandId); + sprintf( tmp, "cmd-id: %d", *m_commandId ); ev += tmp; } - if(m_commandStr) - ev += "cmd-str: " + (*m_commandStr); + if( m_commandStr ) + ev += "cmd-str: " + ( *m_commandStr ); return ev; } + const std::string TOOL_EVENT_LIST::Format() const { string s; - BOOST_FOREACH(TOOL_EVENT e, m_events) - s+=e.Format()+" "; + BOOST_FOREACH( TOOL_EVENT e, m_events ) + s += e.Format() + " "; return s; } diff --git a/common/tool/tool_interactive.cpp b/common/tool/tool_interactive.cpp index 2389c33eed..4e2d51e562 100644 --- a/common/tool/tool_interactive.cpp +++ b/common/tool/tool_interactive.cpp @@ -1,3 +1,27 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2013 CERN + * @author Tomasz Wlostowski + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + #include #include @@ -5,37 +29,40 @@ #include #include -TOOL_INTERACTIVE::TOOL_INTERACTIVE( TOOL_ID aId, const std::string& aName ): - TOOL_BASE(TOOL_Interactive, aId, aName) +TOOL_INTERACTIVE::TOOL_INTERACTIVE( TOOL_ID aId, const std::string& aName ) : + TOOL_BASE( TOOL_Interactive, aId, aName ) {}; -TOOL_INTERACTIVE::TOOL_INTERACTIVE( const std::string& aName ): - TOOL_BASE(TOOL_Interactive, TOOL_MANAGER::MakeToolId(aName), aName) + +TOOL_INTERACTIVE::TOOL_INTERACTIVE( const std::string& aName ) : + TOOL_BASE( TOOL_Interactive, TOOL_MANAGER::MakeToolId( aName ), aName ) {}; TOOL_INTERACTIVE::~TOOL_INTERACTIVE() { - } + OPT_TOOL_EVENT TOOL_INTERACTIVE::Wait ( const TOOL_EVENT_LIST & aEventList ) { - return m_toolMgr->ScheduleWait(this, aEventList); + return m_toolMgr->ScheduleWait( this, aEventList ); } + void TOOL_INTERACTIVE::goInternal( TOOL_STATE_FUNC& aState, const TOOL_EVENT_LIST& aConditions ) { - m_toolMgr->ScheduleNextState(this, aState, aConditions); + m_toolMgr->ScheduleNextState( this, aState, aConditions ); } + void TOOL_INTERACTIVE::Reset() { - } + void TOOL_INTERACTIVE::SetContextMenu( CONTEXT_MENU *aMenu, TOOL_ContextMenuTrigger aTrigger ) { - aMenu->setTool(this); - m_toolMgr->ScheduleContextMenu(this, aMenu, aTrigger); + aMenu->setTool( this ); + m_toolMgr->ScheduleContextMenu( this, aMenu, aTrigger ); } diff --git a/include/tool/context_menu.h b/include/tool/context_menu.h index a8d2f4292a..63122b5b94 100644 --- a/include/tool/context_menu.h +++ b/include/tool/context_menu.h @@ -41,8 +41,8 @@ class CONTEXT_MENU public: - CONTEXT_MENU ( ); - ~CONTEXT_MENU ( ); + CONTEXT_MENU(); + ~CONTEXT_MENU(); void SetTitle( const wxString& aTitle ); void Add ( const wxString& aItem, int aId ); @@ -52,27 +52,26 @@ public: void Clear(); - wxMenu *GetMenu() const + wxMenu* GetMenu() const { return m_menu; } private: - class CMEventHandler; friend class TOOL_INTERACTIVE; - void setTool ( TOOL_INTERACTIVE *aTool ) + void setTool ( TOOL_INTERACTIVE* aTool ) { m_tool = aTool; } bool m_titleSet; - wxMenu *m_menu; - CMEventHandler *m_handler; - TOOL_INTERACTIVE *m_tool; + wxMenu* m_menu; + CMEventHandler* m_handler; + TOOL_INTERACTIVE* m_tool; }; #endif diff --git a/include/tool/tool_base.h b/include/tool/tool_base.h index fd9658f06b..ca686b0ddb 100644 --- a/include/tool/tool_base.h +++ b/include/tool/tool_base.h @@ -26,9 +26,7 @@ #define __TOOL_BASE_H #include - -// for KICAD_T. -#include +#include // for KICAD_T #include #include @@ -36,15 +34,16 @@ class EDA_ITEM; class TOOL_MANAGER; -namespace KiGfx { - class VIEW; - class VIEW_CONTROLS; +namespace KiGfx +{ +class VIEW; +class VIEW_CONTROLS; }; - -enum TOOL_Type { - TOOL_Interactive = 0x1, - TOOL_Batch = 0x2 +enum TOOL_Type +{ + TOOL_Interactive = 0x1, + TOOL_Batch = 0x2 }; typedef int TOOL_ID; @@ -60,10 +59,10 @@ class TOOL_BASE { public: - TOOL_BASE(TOOL_Type aType, TOOL_ID aId, const std::string& aName = std::string("")) : - m_type(aType), - m_toolId(aId), - m_toolName(aName) {}; + TOOL_BASE( TOOL_Type aType, TOOL_ID aId, const std::string& aName = std::string( "" ) ) : + m_type( aType ), + m_toolId( aId ), + m_toolName( aName ) {}; virtual ~TOOL_BASE() {}; @@ -82,13 +81,12 @@ public: return m_toolName; } - TOOL_MANAGER *GetManager() + TOOL_MANAGER* GetManager() { return m_toolMgr; } protected: - friend class TOOL_MANAGER; /** @@ -99,8 +97,8 @@ protected: */ void attachManager( TOOL_MANAGER *aManager ); - KiGfx::VIEW *getView(); - KiGfx::VIEW_CONTROLS *getViewControls(); + KiGfx::VIEW* getView(); + KiGfx::VIEW_CONTROLS* getViewControls(); /** * Function getEditFrame() @@ -111,7 +109,7 @@ protected: template T *getEditFrame() { - return static_cast (getEditFrameInt()); + return static_cast( getEditFrameInt() ); } /** @@ -124,24 +122,20 @@ protected: { EDA_ITEM *m = getModelInt(); // assert(modelType == m->Type()); - return static_cast (m); + return static_cast( m ); } protected: - - TOOL_Type m_type; TOOL_ID m_toolId; std::string m_toolName; - TOOL_MANAGER *m_toolMgr; + TOOL_MANAGER* m_toolMgr; private: - // hide the implementation to avoid spreading half of // kicad and wxWidgets headers to the tools that may not need them at all! - EDA_ITEM *getModelInt(); - wxWindow *getEditFrameInt(); + EDA_ITEM* getModelInt(); + wxWindow* getEditFrameInt(); }; - #endif diff --git a/include/tool/tool_event.h b/include/tool/tool_event.h index 4811fa1cfb..d5dec8525d 100644 --- a/include/tool/tool_event.h +++ b/include/tool/tool_event.h @@ -38,7 +38,8 @@ class TOOL_MANAGER; * Internal (GUI-independent) event definitions. * Enums are mostly self-explanatory. */ -enum TOOL_EventCategory { +enum TOOL_EventCategory +{ TC_None = 0x0, TC_Mouse = 0x1, TC_Command = 0x2, @@ -47,7 +48,8 @@ enum TOOL_EventCategory { TC_Any = 0xffffffff }; -enum TOOL_Actions { +enum TOOL_Actions +{ TA_None = 0x0, TA_MouseClick = 0x1, TA_MouseUp = 0x2, @@ -77,7 +79,8 @@ enum TOOL_Actions { TA_Any = 0xffffffff }; -enum TOOL_MouseButtons { +enum TOOL_MouseButtons +{ MB_None = 0x0, MB_Left = 0x1, MB_Right = 0x2, @@ -92,7 +95,8 @@ enum TOOL_MouseButtons { // Defines when a context menu is opened. -enum TOOL_ContextMenuTrigger { +enum TOOL_ContextMenuTrigger +{ CMENU_BUTTON = 0, // On the right button CMENU_NOW, // Right now (after TOOL_INTERACTIVE::SetContxtMenu) CMENU_OFF // Never @@ -105,155 +109,149 @@ enum TOOL_ContextMenuTrigger { */ class TOOL_EVENT { - public: +public: + const std::string Format() const; - const std::string Format ( ) const; + TOOL_EVENT( TOOL_EventCategory aCategory = TC_None, TOOL_Actions aAction = TA_None ): + m_category( aCategory ), + m_actions( aAction ), + m_mouseButtons( 0 ) {} - TOOL_EVENT(TOOL_EventCategory aCategory = TC_None, TOOL_Actions aAction = TA_None ): - m_category (aCategory), - m_actions (aAction), - m_mouseButtons(0) {}; - - TOOL_EVENT(TOOL_EventCategory aCategory, TOOL_Actions aAction, int aExtraParam ): - m_category (aCategory), - m_actions (aAction) - { - if(aCategory == TC_Mouse) - m_mouseButtons = aExtraParam; - else if (aCategory == TC_Command) - m_commandId = aExtraParam; - }; + TOOL_EVENT( TOOL_EventCategory aCategory, TOOL_Actions aAction, int aExtraParam ): + m_category( aCategory ), + m_actions( aAction ) + { + if( aCategory == TC_Mouse ) + m_mouseButtons = aExtraParam; + else if ( aCategory == TC_Command ) + m_commandId = aExtraParam; + } - TOOL_EVENT(TOOL_EventCategory aCategory, TOOL_Actions aAction, const std::string& aExtraParam ): - m_category (aCategory), - m_actions (aAction), - m_mouseButtons(0) - { - if(aCategory == TC_Command) - m_commandStr = aExtraParam; - } - - - TOOL_EventCategory Category ( ) const - { - return m_category; - } - - TOOL_Actions Action ( ) const - { - return m_actions; - } - - const VECTOR2D Delta() const - { - return m_mouseDelta; - } - - const VECTOR2D& Position() const - { - return m_mousePos; - } - - const VECTOR2D& DragOrigin() const - { - return m_mouseDragOrigin; - } - - int Buttons() const - { - return m_mouseButtons; - } - - bool IsClick ( int aButtonMask = MB_Any ) const - { - return (m_actions == TA_MouseClick) && ((m_mouseButtons & aButtonMask) == aButtonMask); - } - - bool IsDrag ( int aButtonMask = MB_Any ) const - { - return (m_actions == TA_MouseDrag) && ((m_mouseButtons & aButtonMask) == aButtonMask); - } - - bool IsMouseUp ( int aButtonMask = MB_Any ) const - { - return (m_actions == TA_MouseUp) && ((m_mouseButtons & aButtonMask) == aButtonMask); - } - - bool IsMotion ( ) const - { - return (m_actions == TA_MouseMotion); - } - - bool IsCancel ( ) const - { - return m_actions == TA_CancelTool; - } - - bool Modifier ( int aMask = MB_ModifierMask ) const - { - return (m_mouseButtons & aMask); - } - - - void Ignore(); - - void SetMouseDragOrigin( const VECTOR2D &aP ) - { - m_mouseDragOrigin = aP; - } - - void SetMousePosition( const VECTOR2D& aP ) - { - m_mousePos = aP; - } - - void SetMouseDelta( const VECTOR2D& aP ) - { - m_mouseDelta = aP; - } - - bool Matches ( const TOOL_EVENT& aEvent ) const - { - if (! (m_category & aEvent.m_category)) - return false; - - if (! (m_actions & aEvent.m_actions)) - return false; - - if( m_category == TC_Command) - { - if(m_commandStr && aEvent.m_commandStr) - return (*m_commandStr == *aEvent.m_commandStr); - if(m_commandId && aEvent.m_commandId) - return (*m_commandId == *aEvent.m_commandId); - } - - return true; - } - - boost::optional GetCommandId() - { - return m_commandId; - } + TOOL_EVENT( TOOL_EventCategory aCategory, TOOL_Actions aAction, const std::string& aExtraParam ): + m_category( aCategory ), + m_actions( aAction ), + m_mouseButtons( 0 ) + { + if( aCategory == TC_Command ) + m_commandStr = aExtraParam; + } - private: + TOOL_EventCategory Category() const + { + return m_category; + } - friend class TOOL_MANAGER; + TOOL_Actions Action() const + { + return m_actions; + } - TOOL_EventCategory m_category; - TOOL_Actions m_actions; - - VECTOR2D m_mouseDelta; - VECTOR2D m_mousePos; - VECTOR2D m_mouseDragOrigin; - - int m_mouseButtons; - boost::optional m_commandId; - boost::optional m_commandStr; - + const VECTOR2D Delta() const + { + return m_mouseDelta; + } + const VECTOR2D& Position() const + { + return m_mousePos; + } + const VECTOR2D& DragOrigin() const + { + return m_mouseDragOrigin; + } + + int Buttons() const + { + return m_mouseButtons; + } + + bool IsClick( int aButtonMask = MB_Any ) const + { + return ( m_actions == TA_MouseClick ) + && ( ( m_mouseButtons & aButtonMask ) == aButtonMask ); + } + + bool IsDrag( int aButtonMask = MB_Any ) const + { + return ( m_actions == TA_MouseDrag ) && ( ( m_mouseButtons & aButtonMask ) == aButtonMask ); + } + + bool IsMouseUp( int aButtonMask = MB_Any ) const + { + return ( m_actions == TA_MouseUp ) && ( ( m_mouseButtons & aButtonMask ) == aButtonMask ); + } + + bool IsMotion() const + { + return ( m_actions == TA_MouseMotion ); + } + + bool IsCancel() const + { + return m_actions == TA_CancelTool; + } + + bool Modifier( int aMask = MB_ModifierMask ) const + { + return ( m_mouseButtons & aMask ); + } + + void Ignore(); + + void SetMouseDragOrigin( const VECTOR2D &aP ) + { + m_mouseDragOrigin = aP; + } + + void SetMousePosition( const VECTOR2D& aP ) + { + m_mousePos = aP; + } + + void SetMouseDelta( const VECTOR2D& aP ) + { + m_mouseDelta = aP; + } + + bool Matches( const TOOL_EVENT& aEvent ) const + { + if( ! ( m_category & aEvent.m_category ) ) + return false; + + if( ! ( m_actions & aEvent.m_actions ) ) + return false; + + if( m_category == TC_Command ) + { + if( m_commandStr && aEvent.m_commandStr ) + return ( *m_commandStr == *aEvent.m_commandStr ); + if( m_commandId && aEvent.m_commandId ) + return ( *m_commandId == *aEvent.m_commandId ); + } + + return true; + } + + boost::optional GetCommandId() + { + return m_commandId; + } + +private: + friend class TOOL_MANAGER; + + TOOL_EventCategory m_category; + TOOL_Actions m_actions; + + VECTOR2D m_mouseDelta; + VECTOR2D m_mousePos; + VECTOR2D m_mouseDragOrigin; + + int m_mouseButtons; + boost::optional m_commandId; + boost::optional m_commandStr; }; typedef boost::optional OPT_TOOL_EVENT; @@ -265,109 +263,112 @@ typedef boost::optional OPT_TOOL_EVENT; * concatenating TOOL_EVENTs with little code. */ class TOOL_EVENT_LIST { +public: + typedef TOOL_EVENT value_type; + typedef std::deque::iterator iterator; + typedef std::deque::const_iterator const_iterator; - public: - typedef TOOL_EVENT value_type; - typedef std::deque::iterator iterator; - typedef std::deque::const_iterator const_iterator; + TOOL_EVENT_LIST() {}; + TOOL_EVENT_LIST( const TOOL_EVENT& aSingleEvent ) + { + m_events.push_back(aSingleEvent); + } - TOOL_EVENT_LIST() {}; - TOOL_EVENT_LIST( const TOOL_EVENT& aSingleEvent ) - { - m_events.push_back(aSingleEvent); - } + const std::string Format() const; - const std::string Format ( ) const; + boost::optional Matches( const TOOL_EVENT &b ) const + { + for( const_iterator i = m_events.begin(); i != m_events.end(); ++i ) + if ( i->Matches( b ) ) + return *i; + return boost::optional(); + } - boost::optional Matches( const TOOL_EVENT &b ) const - { - for(const_iterator i = m_events.begin(); i != m_events.end(); ++i) - if (i->Matches(b)) - return *i; - return boost::optional (); - } - - void Add ( const TOOL_EVENT& aEvent ) - { - m_events.push_back(aEvent); - } + void Add( const TOOL_EVENT& aEvent ) + { + m_events.push_back( aEvent ); + } - iterator begin() - { - return m_events.begin(); - } - - iterator end() - { - return m_events.end(); - } + iterator begin() + { + return m_events.begin(); + } - const_iterator cbegin() const - { - return m_events.begin(); - } - - const_iterator cend() const - { - return m_events.end(); - } + iterator end() + { + return m_events.end(); + } - int size() const - { - return m_events.size(); - } + const_iterator cbegin() const + { + return m_events.begin(); + } - void clear() - { - m_events.clear(); - } + const_iterator cend() const + { + return m_events.end(); + } - TOOL_EVENT_LIST& operator=(const TOOL_EVENT_LIST& b) - { - m_events.clear(); - for(std::deque::const_iterator i = b.m_events.begin(); i != b.m_events.end(); ++i) - m_events.push_back(*i); - return *this; - } + int size() const + { + return m_events.size(); + } - TOOL_EVENT_LIST& operator=(const TOOL_EVENT& b) - { - m_events.clear(); - m_events.push_back(b); - return *this; - } - - TOOL_EVENT_LIST& operator||(const TOOL_EVENT& b) - { - Add(b); - return *this; - } + void clear() + { + m_events.clear(); + } - TOOL_EVENT_LIST& operator||(const TOOL_EVENT_LIST& b) - { - - return *this; - } + TOOL_EVENT_LIST& operator=( const TOOL_EVENT_LIST& b ) + { + m_events.clear(); - private: - std::deque m_events; + for( std::deque::const_iterator i = b.m_events.begin(); + i != b.m_events.end(); ++i ) + { + m_events.push_back(*i); + } + + return *this; + } + + TOOL_EVENT_LIST& operator=( const TOOL_EVENT& b ) + { + m_events.clear(); + m_events.push_back( b ); + return *this; + } + + TOOL_EVENT_LIST& operator||( const TOOL_EVENT& b ) + { + Add( b ); + return *this; + } + + TOOL_EVENT_LIST& operator||( const TOOL_EVENT_LIST& b ) + { + return *this; + } + +private: + std::deque m_events; }; -inline const TOOL_EVENT_LIST operator || (const TOOL_EVENT& a, const TOOL_EVENT &b ) +inline const TOOL_EVENT_LIST operator||( const TOOL_EVENT& a, const TOOL_EVENT &b ) { TOOL_EVENT_LIST l; - l.Add(a); - l.Add(b); + l.Add( a ); + l.Add( b ); return l; } -inline const TOOL_EVENT_LIST operator || (const TOOL_EVENT & a, const TOOL_EVENT_LIST &b ) +inline const TOOL_EVENT_LIST operator||( const TOOL_EVENT & a, const TOOL_EVENT_LIST &b ) { - TOOL_EVENT_LIST l(b); + TOOL_EVENT_LIST l( b ); - l.Add(a); + l.Add( a ); return l; } diff --git a/include/tool/tool_interactive.h b/include/tool/tool_interactive.h index 679ab5588e..10b7250588 100644 --- a/include/tool/tool_interactive.h +++ b/include/tool/tool_interactive.h @@ -32,9 +32,9 @@ class CONTEXT_MENU; -class TOOL_INTERACTIVE : public TOOL_BASE { +class TOOL_INTERACTIVE : public TOOL_BASE +{ public: - TOOL_INTERACTIVE( TOOL_ID aId, const std::string& aName ); /** @@ -87,20 +87,18 @@ public: void Yield ( const T& returnValue ); protected: - /* helper functions for constructing events for Wait() and Go() with less typing */ const TOOL_EVENT evActivate( std::string aToolName = "" ); const TOOL_EVENT evCommand( int aCommandId = -1 ); const TOOL_EVENT evCommand( std::string aCommandStr = ""); const TOOL_EVENT evMotion(); - const TOOL_EVENT evClick(int aButton = MB_Any ); - const TOOL_EVENT evDrag(int aButton = MB_Any ); + const TOOL_EVENT evClick( int aButton = MB_Any ); + const TOOL_EVENT evDrag( int aButton = MB_Any ); const TOOL_EVENT evButtonUp( int aButton = MB_Any ); const TOOL_EVENT evButtonDown(int aButton = MB_Any ); private: - void goInternal( TOOL_STATE_FUNC& aState, const TOOL_EVENT_LIST& aConditions ); }; @@ -108,7 +106,7 @@ private: template void TOOL_INTERACTIVE::Go( int (T::*aStateFunc)( TOOL_EVENT& ), const TOOL_EVENT_LIST& aConditions ) { - TOOL_STATE_FUNC sptr (static_cast(this), aStateFunc); + TOOL_STATE_FUNC sptr (static_cast( this ), aStateFunc); goInternal( sptr, aConditions ); } diff --git a/include/view/view.h b/include/view/view.h index 7a3a7603de..d9f5ed5190 100644 --- a/include/view/view.h +++ b/include/view/view.h @@ -281,7 +281,7 @@ public: } /** - * Function SetLayerOrder() + * Function SetLayerOrder() * Sets rendering order of a particular layer. * @param aLayer: the layer * @param aRenderingOrder: arbitrary number denoting the rendering order.