vcl: move CommandEvent functions from header to cxx file

Moving functions from commandevent.hxx to commandevent.cxx, this means
they are no longer inline, but there was no clear reason as to why they
were inline in the first place!

I've also reordered the header to ensure that CommandEvent is the first
fully declared class, the data classes get declared after this (hence the
forward declarations). This makes reading this header much easier.

One more small thing: a few if statements had braces in the primary if
block, but not in the else block, which is IMO bad style and can possibly
lead to errors. I've made the else block use braces.

Change-Id: I79b010bd66d3c9f4a74d4fa470f62d0263c811f4
This commit is contained in:
Chris Sherlock
2016-02-10 16:54:47 +11:00
parent 574482123b
commit 3ff9dd6ff3
4 changed files with 203 additions and 222 deletions

View File

@@ -117,7 +117,7 @@ void MediaChildWindow::KeyUp( const KeyEvent& rKEvt )
void MediaChildWindow::Command( const CommandEvent& rCEvt ) void MediaChildWindow::Command( const CommandEvent& rCEvt )
{ {
const CommandEvent aTransformedEvent( GetParent()->ScreenToOutputPixel( OutputToScreenPixel( rCEvt.GetMousePosPixel() ) ), const CommandEvent aTransformedEvent( GetParent()->ScreenToOutputPixel( OutputToScreenPixel( rCEvt.GetMousePosPixel() ) ),
rCEvt.GetCommand(), rCEvt.IsMouseEvent(), rCEvt.GetEventData() ); rCEvt.GetCommand(), rCEvt.IsMouseEvent(), rCEvt.GetEventData() );
SystemChildWindow::Command( rCEvt ); SystemChildWindow::Command( rCEvt );
GetParent()->Command( aTransformedEvent ); GetParent()->Command( aTransformedEvent );

View File

@@ -38,6 +38,45 @@
#define EXTTEXTINPUT_CURSOR_INVISIBLE ((sal_uInt16)0x0001) #define EXTTEXTINPUT_CURSOR_INVISIBLE ((sal_uInt16)0x0001)
#define EXTTEXTINPUT_CURSOR_OVERWRITE ((sal_uInt16)0x0002) #define EXTTEXTINPUT_CURSOR_OVERWRITE ((sal_uInt16)0x0002)
class CommandExtTextInputData;
class CommandWheelData;
class CommandScrollData;
class CommandModKeyData;
class CommandDialogData;
class CommandMediaData;
class CommandSelectionChangeData;
class CommandSwipeData;
class CommandLongPressData;
enum class CommandEventId;
class VCL_DLLPUBLIC CommandEvent
{
private:
Point maPos;
void* mpData;
CommandEventId mnCommand;
bool mbMouseEvent;
public:
CommandEvent();
CommandEvent( const Point& rMousePos, CommandEventId nCmd,
bool bMEvt = false, const void* pCmdData = nullptr );
CommandEventId GetCommand() const { return mnCommand; }
const Point& GetMousePosPixel() const { return maPos; }
bool IsMouseEvent() const { return mbMouseEvent; }
void* GetEventData() const { return mpData; }
const CommandExtTextInputData* GetExtTextInputData() const;
const CommandWheelData* GetWheelData() const;
const CommandScrollData* GetAutoScrollData() const;
const CommandModKeyData* GetModKeyData() const;
const CommandDialogData* GetDialogData() const;
CommandMediaData* GetMediaData() const;
const CommandSelectionChangeData* GetSelectionChangeData() const;
const CommandSwipeData* GetSwipeData() const;
const CommandLongPressData* GetLongPressData() const;
};
class VCL_DLLPUBLIC CommandExtTextInputData class VCL_DLLPUBLIC CommandExtTextInputData
{ {
@@ -66,7 +105,6 @@ public:
bool IsOnlyCursorChanged() const { return mbOnlyCursor; } bool IsOnlyCursorChanged() const { return mbOnlyCursor; }
}; };
class VCL_DLLPUBLIC CommandInputContextData class VCL_DLLPUBLIC CommandInputContextData
{ {
private: private:
@@ -77,19 +115,6 @@ public:
CommandInputContextData( LanguageType eLang ); CommandInputContextData( LanguageType eLang );
}; };
inline CommandInputContextData::CommandInputContextData()
{
meLanguage = LANGUAGE_DONTKNOW;
}
inline CommandInputContextData::CommandInputContextData( LanguageType eLang )
{
meLanguage = eLang;
}
enum class CommandWheelMode enum class CommandWheelMode
{ {
NONE = 0, NONE = 0,
@@ -99,7 +124,6 @@ enum class CommandWheelMode
DATAZOOM = 4 DATAZOOM = 4
}; };
// Magic value used in mnLines field in CommandWheelData // Magic value used in mnLines field in CommandWheelData
#define COMMAND_WHEEL_PAGESCROLL ((sal_uLong)0xFFFFFFFF) #define COMMAND_WHEEL_PAGESCROLL ((sal_uLong)0xFFFFFFFF)
@@ -139,34 +163,6 @@ public:
{ return ((mnCode & KEY_MOD2) != 0); } { return ((mnCode & KEY_MOD2) != 0); }
}; };
inline CommandWheelData::CommandWheelData()
{
mnDelta = 0;
mnNotchDelta = 0;
mnLines = 0;
mnWheelMode = CommandWheelMode::NONE;
mnCode = 0;
mbHorz = false;
mbDeltaIsPixel = false;
}
inline CommandWheelData::CommandWheelData( long nWheelDelta, long nWheelNotchDelta,
sal_uLong nScrollLines,
CommandWheelMode nWheelMode, sal_uInt16 nKeyModifier,
bool bHorz, bool bDeltaIsPixel )
{
mnDelta = nWheelDelta;
mnNotchDelta = nWheelNotchDelta;
mnLines = nScrollLines;
mnWheelMode = nWheelMode;
mnCode = nKeyModifier;
mbHorz = bHorz;
mbDeltaIsPixel = bDeltaIsPixel;
}
class VCL_DLLPUBLIC CommandScrollData class VCL_DLLPUBLIC CommandScrollData
{ {
private: private:
@@ -181,21 +177,6 @@ public:
long GetDeltaY() const { return mnDeltaY; } long GetDeltaY() const { return mnDeltaY; }
}; };
inline CommandScrollData::CommandScrollData()
{
mnDeltaX = 0;
mnDeltaY = 0;
}
inline CommandScrollData::CommandScrollData( long nDeltaX, long nDeltaY )
{
mnDeltaX = nDeltaX;
mnDeltaY = nDeltaY;
}
class VCL_DLLPUBLIC CommandModKeyData class VCL_DLLPUBLIC CommandModKeyData
{ {
private: private:
@@ -211,26 +192,12 @@ public:
bool IsRightShift() const { return (mnCode & MODKEY_RSHIFT) != 0; } bool IsRightShift() const { return (mnCode & MODKEY_RSHIFT) != 0; }
}; };
inline CommandModKeyData::CommandModKeyData()
{
mnCode = 0L;
}
inline CommandModKeyData::CommandModKeyData( sal_uInt16 nCode )
{
mnCode = nCode;
}
enum class ShowDialogId enum class ShowDialogId
{ {
Preferences = 1, Preferences = 1,
About = 2, About = 2,
}; };
class VCL_DLLPUBLIC CommandDialogData class VCL_DLLPUBLIC CommandDialogData
{ {
ShowDialogId m_nDialogId; ShowDialogId m_nDialogId;
@@ -242,7 +209,6 @@ public:
ShowDialogId GetDialogId() const { return m_nDialogId; } ShowDialogId GetDialogId() const { return m_nDialogId; }
}; };
// Media Commands // Media Commands
enum class MediaCommand enum class MediaCommand
{ {
@@ -270,7 +236,6 @@ enum class MediaCommand
PreviousTrackHold = 22,// Button Left holding pressed. PreviousTrackHold = 22,// Button Left holding pressed.
}; };
class VCL_DLLPUBLIC CommandMediaData class VCL_DLLPUBLIC CommandMediaData
{ {
MediaCommand m_nMediaId; MediaCommand m_nMediaId;
@@ -286,7 +251,6 @@ public:
bool GetPassThroughToOS() const { return m_bPassThroughToOS; } bool GetPassThroughToOS() const { return m_bPassThroughToOS; }
}; };
class VCL_DLLPUBLIC CommandSelectionChangeData class VCL_DLLPUBLIC CommandSelectionChangeData
{ {
private: private:
@@ -301,21 +265,6 @@ public:
sal_uLong GetEnd() const { return mnEnd; } sal_uLong GetEnd() const { return mnEnd; }
}; };
inline CommandSelectionChangeData::CommandSelectionChangeData()
{
mnStart = mnEnd = 0;
}
inline CommandSelectionChangeData::CommandSelectionChangeData( sal_uLong nStart,
sal_uLong nEnd )
{
mnStart = nStart;
mnEnd = nEnd;
}
class VCL_DLLPUBLIC CommandSwipeData class VCL_DLLPUBLIC CommandSwipeData
{ {
double mnVelocityX; double mnVelocityX;
@@ -351,7 +300,6 @@ public:
double getY() const { return mnY; } double getY() const { return mnY; }
}; };
enum class CommandEventId enum class CommandEventId
{ {
NONE = 0, NONE = 0,
@@ -378,135 +326,6 @@ enum class CommandEventId
LongPress = 22, LongPress = 22,
}; };
class VCL_DLLPUBLIC CommandEvent
{
private:
Point maPos;
void* mpData;
CommandEventId mnCommand;
bool mbMouseEvent;
public:
CommandEvent();
CommandEvent( const Point& rMousePos, CommandEventId nCmd,
bool bMEvt = false, const void* pCmdData = nullptr );
CommandEventId GetCommand() const { return mnCommand; }
const Point& GetMousePosPixel() const { return maPos; }
bool IsMouseEvent() const { return mbMouseEvent; }
void* GetEventData() const { return mpData; }
const CommandExtTextInputData* GetExtTextInputData() const;
const CommandWheelData* GetWheelData() const;
const CommandScrollData* GetAutoScrollData() const;
const CommandModKeyData* GetModKeyData() const;
const CommandDialogData* GetDialogData() const;
CommandMediaData* GetMediaData() const;
const CommandSelectionChangeData* GetSelectionChangeData() const;
const CommandSwipeData* GetSwipeData() const;
const CommandLongPressData* GetLongPressData() const;
};
inline CommandEvent::CommandEvent()
{
mpData = nullptr;
mnCommand = CommandEventId::NONE;
mbMouseEvent = false;
}
inline CommandEvent::CommandEvent( const Point& rMousePos,
CommandEventId nCmd, bool bMEvt, const void* pCmdData ) :
maPos( rMousePos )
{
mpData = const_cast<void*>(pCmdData);
mnCommand = nCmd;
mbMouseEvent = bMEvt;
}
inline const CommandExtTextInputData* CommandEvent::GetExtTextInputData() const
{
if ( mnCommand == CommandEventId::ExtTextInput )
return static_cast<const CommandExtTextInputData*>(mpData);
else
return nullptr;
}
inline const CommandWheelData* CommandEvent::GetWheelData() const
{
if ( mnCommand == CommandEventId::Wheel )
return static_cast<const CommandWheelData*>(mpData);
else
return nullptr;
}
inline const CommandScrollData* CommandEvent::GetAutoScrollData() const
{
if ( mnCommand == CommandEventId::AutoScroll )
return static_cast<const CommandScrollData*>(mpData);
else
return nullptr;
}
inline const CommandModKeyData* CommandEvent::GetModKeyData() const
{
if( mnCommand == CommandEventId::ModKeyChange )
return static_cast<const CommandModKeyData*>(mpData);
else
return nullptr;
}
inline const CommandDialogData* CommandEvent::GetDialogData() const
{
if( mnCommand == CommandEventId::ShowDialog )
return static_cast<const CommandDialogData*>(mpData);
else
return nullptr;
}
inline CommandMediaData* CommandEvent::GetMediaData() const
{
if( mnCommand == CommandEventId::Media )
return static_cast<CommandMediaData*>(mpData);
else
return nullptr;
}
inline const CommandSelectionChangeData* CommandEvent::GetSelectionChangeData() const
{
if( mnCommand == CommandEventId::SelectionChange )
return static_cast<const CommandSelectionChangeData*>(mpData);
else
return nullptr;
}
inline const CommandSwipeData* CommandEvent::GetSwipeData() const
{
if( mnCommand == CommandEventId::Swipe )
return static_cast<const CommandSwipeData*>(mpData);
else
return nullptr;
}
inline const CommandLongPressData* CommandEvent::GetLongPressData() const
{
if( mnCommand == CommandEventId::LongPress )
return static_cast<const CommandLongPressData*>(mpData);
else
return nullptr;
}
#endif // INCLUDED_VCL_COMMANDEVENT_HXX #endif // INCLUDED_VCL_COMMANDEVENT_HXX
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View File

@@ -107,7 +107,7 @@ void SdrMediaWindow::Command( const CommandEvent& rCEvt )
if( pWindow && getWindow() ) if( pWindow && getWindow() )
{ {
const CommandEvent aTransformedEvent( pWindow->ScreenToOutputPixel( getWindow()->OutputToScreenPixel( rCEvt.GetMousePosPixel() ) ), const CommandEvent aTransformedEvent( pWindow->ScreenToOutputPixel( getWindow()->OutputToScreenPixel( rCEvt.GetMousePosPixel() ) ),
rCEvt.GetCommand(), rCEvt.IsMouseEvent(), rCEvt.GetEventData() ); rCEvt.GetCommand(), rCEvt.IsMouseEvent(), rCEvt.GetEventData() );
pWindow->Command( aTransformedEvent ); pWindow->Command( aTransformedEvent );
} }

View File

@@ -32,7 +32,10 @@ CommandExtTextInputData::CommandExtTextInputData( const OUString& rText,
memcpy( mpTextAttr, pTextAttr, maText.getLength()*sizeof(sal_uInt16) ); memcpy( mpTextAttr, pTextAttr, maText.getLength()*sizeof(sal_uInt16) );
} }
else else
{
mpTextAttr = nullptr; mpTextAttr = nullptr;
}
mnCursorPos = nCursorPos; mnCursorPos = nCursorPos;
mnCursorFlags = nCursorFlags; mnCursorFlags = nCursorFlags;
mbOnlyCursor = bOnlyCursor; mbOnlyCursor = bOnlyCursor;
@@ -47,7 +50,10 @@ CommandExtTextInputData::CommandExtTextInputData( const CommandExtTextInputData&
memcpy( mpTextAttr, rData.mpTextAttr, maText.getLength()*sizeof(sal_uInt16) ); memcpy( mpTextAttr, rData.mpTextAttr, maText.getLength()*sizeof(sal_uInt16) );
} }
else else
{
mpTextAttr = nullptr; mpTextAttr = nullptr;
}
mnCursorPos = rData.mnCursorPos; mnCursorPos = rData.mnCursorPos;
mnCursorFlags = rData.mnCursorFlags; mnCursorFlags = rData.mnCursorFlags;
mbOnlyCursor = rData.mbOnlyCursor; mbOnlyCursor = rData.mbOnlyCursor;
@@ -58,4 +64,160 @@ CommandExtTextInputData::~CommandExtTextInputData()
delete [] mpTextAttr; delete [] mpTextAttr;
} }
CommandInputContextData::CommandInputContextData()
{
meLanguage = LANGUAGE_DONTKNOW;
}
CommandInputContextData::CommandInputContextData( LanguageType eLang )
{
meLanguage = eLang;
}
CommandWheelData::CommandWheelData()
{
mnDelta = 0;
mnNotchDelta = 0;
mnLines = 0;
mnWheelMode = CommandWheelMode::NONE;
mnCode = 0;
mbHorz = false;
mbDeltaIsPixel = false;
}
CommandWheelData::CommandWheelData( long nWheelDelta, long nWheelNotchDelta,
sal_uLong nScrollLines,
CommandWheelMode nWheelMode, sal_uInt16 nKeyModifier,
bool bHorz, bool bDeltaIsPixel )
{
mnDelta = nWheelDelta;
mnNotchDelta = nWheelNotchDelta;
mnLines = nScrollLines;
mnWheelMode = nWheelMode;
mnCode = nKeyModifier;
mbHorz = bHorz;
mbDeltaIsPixel = bDeltaIsPixel;
}
CommandScrollData::CommandScrollData()
{
mnDeltaX = 0;
mnDeltaY = 0;
}
CommandScrollData::CommandScrollData( long nDeltaX, long nDeltaY )
{
mnDeltaX = nDeltaX;
mnDeltaY = nDeltaY;
}
CommandModKeyData::CommandModKeyData()
{
mnCode = 0L;
}
CommandModKeyData::CommandModKeyData( sal_uInt16 nCode )
{
mnCode = nCode;
}
CommandSelectionChangeData::CommandSelectionChangeData()
{
mnStart = mnEnd = 0;
}
CommandSelectionChangeData::CommandSelectionChangeData( sal_uLong nStart, sal_uLong nEnd )
{
mnStart = nStart;
mnEnd = nEnd;
}
CommandEvent::CommandEvent()
{
mpData = nullptr;
mnCommand = CommandEventId::NONE;
mbMouseEvent = false;
}
CommandEvent::CommandEvent( const Point& rMousePos,
CommandEventId nCmd, bool bMEvt, const void* pCmdData ) :
maPos( rMousePos )
{
mpData = const_cast<void*>(pCmdData);
mnCommand = nCmd;
mbMouseEvent = bMEvt;
}
const CommandExtTextInputData* CommandEvent::GetExtTextInputData() const
{
if ( mnCommand == CommandEventId::ExtTextInput )
return static_cast<const CommandExtTextInputData*>(mpData);
else
return nullptr;
}
const CommandWheelData* CommandEvent::GetWheelData() const
{
if ( mnCommand == CommandEventId::Wheel )
return static_cast<const CommandWheelData*>(mpData);
else
return nullptr;
}
const CommandScrollData* CommandEvent::GetAutoScrollData() const
{
if ( mnCommand == CommandEventId::AutoScroll )
return static_cast<const CommandScrollData*>(mpData);
else
return nullptr;
}
const CommandModKeyData* CommandEvent::GetModKeyData() const
{
if( mnCommand == CommandEventId::ModKeyChange )
return static_cast<const CommandModKeyData*>(mpData);
else
return nullptr;
}
const CommandDialogData* CommandEvent::GetDialogData() const
{
if( mnCommand == CommandEventId::ShowDialog )
return static_cast<const CommandDialogData*>(mpData);
else
return nullptr;
}
CommandMediaData* CommandEvent::GetMediaData() const
{
if( mnCommand == CommandEventId::Media )
return static_cast<CommandMediaData*>(mpData);
else
return nullptr;
}
const CommandSelectionChangeData* CommandEvent::GetSelectionChangeData() const
{
if( mnCommand == CommandEventId::SelectionChange )
return static_cast<const CommandSelectionChangeData*>(mpData);
else
return nullptr;
}
const CommandSwipeData* CommandEvent::GetSwipeData() const
{
if( mnCommand == CommandEventId::Swipe )
return static_cast<const CommandSwipeData*>(mpData);
else
return nullptr;
}
const CommandLongPressData* CommandEvent::GetLongPressData() const
{
if( mnCommand == CommandEventId::LongPress )
return static_cast<const CommandLongPressData*>(mpData);
else
return nullptr;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */