Kaydet (Commit) 873b1e16 authored tarafından Caolán McNamara's avatar Caolán McNamara

cppcheck: zerodivcond gold, address preview crash on key input

which never happened in practice because the entry never got
the keyboard events.

fix the col/row logic and let it get keyboard input, pass
unhandled events up the chain as normal.

Change-Id: I9fdf73808ef516284edb81f3cd04ccb1a24b8fe5
üst 24d62e2a
...@@ -197,7 +197,7 @@ SwAddressPreview::SwAddressPreview(vcl::Window* pParent, WinBits nStyle) ...@@ -197,7 +197,7 @@ SwAddressPreview::SwAddressPreview(vcl::Window* pParent, WinBits nStyle)
extern "C" SAL_DLLPUBLIC_EXPORT vcl::Window* SAL_CALL makeSwAddressPreview(vcl::Window *pParent, VclBuilder::stringmap &rMap) extern "C" SAL_DLLPUBLIC_EXPORT vcl::Window* SAL_CALL makeSwAddressPreview(vcl::Window *pParent, VclBuilder::stringmap &rMap)
{ {
WinBits nWinStyle = WB_DIALOGCONTROL; WinBits nWinStyle = WB_TABSTOP;
OString sBorder = VclBuilder::extractCustomProperty(rMap); OString sBorder = VclBuilder::extractCustomProperty(rMap);
if (!sBorder.isEmpty()) if (!sBorder.isEmpty())
nWinStyle |= WB_BORDER; nWinStyle |= WB_BORDER;
...@@ -378,28 +378,33 @@ void SwAddressPreview::MouseButtonDown( const MouseEvent& rMEvt ) ...@@ -378,28 +378,33 @@ void SwAddressPreview::MouseButtonDown( const MouseEvent& rMEvt )
void SwAddressPreview::KeyInput( const KeyEvent& rKEvt ) void SwAddressPreview::KeyInput( const KeyEvent& rKEvt )
{ {
sal_uInt16 nKey = rKEvt.GetKeyCode().GetCode(); sal_uInt16 nKey = rKEvt.GetKeyCode().GetCode();
if(pImpl->nRows || pImpl->nColumns) bool bHandled = false;
if (pImpl->nRows && pImpl->nColumns)
{ {
sal_uInt32 nSelectedRow = (pImpl->nSelectedAddress + 1)/ pImpl->nColumns; sal_uInt32 nSelectedRow = pImpl->nSelectedAddress / pImpl->nColumns;
sal_uInt32 nSelectedColumn = pImpl->nSelectedAddress % nSelectedRow; sal_uInt32 nSelectedColumn = pImpl->nSelectedAddress - (nSelectedRow * pImpl->nColumns);
switch(nKey) switch(nKey)
{ {
case KEY_UP: case KEY_UP:
if(nSelectedRow) if(nSelectedRow)
--nSelectedRow; --nSelectedRow;
bHandled = true;
break; break;
case KEY_DOWN: case KEY_DOWN:
if(pImpl->aAddresses.size() > sal_uInt32(pImpl->nSelectedAddress + pImpl->nColumns)) if(pImpl->aAddresses.size() > sal_uInt32(pImpl->nSelectedAddress + pImpl->nColumns))
++nSelectedRow; ++nSelectedRow;
bHandled = true;
break; break;
case KEY_LEFT: case KEY_LEFT:
if(nSelectedColumn) if(nSelectedColumn)
--nSelectedColumn; --nSelectedColumn;
bHandled = true;
break; break;
case KEY_RIGHT: case KEY_RIGHT:
if(nSelectedColumn < sal_uInt32(pImpl->nColumns - 1) && if(nSelectedColumn < sal_uInt32(pImpl->nColumns - 1) &&
pImpl->aAddresses.size() - 1 > pImpl->nSelectedAddress ) pImpl->aAddresses.size() - 1 > pImpl->nSelectedAddress )
++nSelectedColumn; ++nSelectedColumn;
bHandled = true;
break; break;
} }
sal_uInt32 nSelect = nSelectedRow * pImpl->nColumns + nSelectedColumn; sal_uInt32 nSelect = nSelectedRow * pImpl->nColumns + nSelectedColumn;
...@@ -411,7 +416,7 @@ void SwAddressPreview::KeyInput( const KeyEvent& rKEvt ) ...@@ -411,7 +416,7 @@ void SwAddressPreview::KeyInput( const KeyEvent& rKEvt )
Invalidate(); Invalidate();
} }
} }
else if (!bHandled)
Window::KeyInput(rKEvt); Window::KeyInput(rKEvt);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment