1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <tools/debug.hxx>
#include <svdata.hxx>
#include <window.h>
#include <vcl/event.hxx>
#include <vcl/fixed.hxx>
#include <vcl/layout.hxx>
#include <vcl/svapp.hxx>
#include <vcl/tabpage.hxx>
#include <vcl/tabctrl.hxx>
#include <vcl/tabdlg.hxx>
#include <vcl/button.hxx>
#include <vcl/settings.hxx>
#include <vcl/unohelp.hxx>
#include <com/sun/star/i18n/XCharacterClassification.hpp>
using namespace ::com::sun::star;
static bool ImplHasIndirectTabParent( Window* pWindow )
{
// The window has inderect tab parent if it is included in tab hierarchy
// of the indirect parent window
Window* pNonLayoutParent = getNonLayoutParent(pWindow);
return ( pNonLayoutParent
&& ( pNonLayoutParent->ImplGetWindow()->GetStyle() & WB_CHILDDLGCTRL ) );
}
static Window* ImplGetTopParentOfTabHierarchy( Window* pParent )
{
// The method allows to find the most close parent containing all the
// window from the current tab-hierarchy
// The direct parent should be provided as a parameter here
Window* pResult = pParent;
if ( pResult )
{
Window* pNonLayoutParent = getNonLayoutParent(pResult);
while ( pNonLayoutParent && ( pResult->ImplGetWindow()->GetStyle() & WB_CHILDDLGCTRL ) )
{
pResult = pNonLayoutParent;
pNonLayoutParent = getNonLayoutParent(pResult);
}
}
return pResult;
}
static Window* ImplGetSubChildWindow( Window* pParent, sal_uInt16 n, sal_uInt16& nIndex )
{
Window* pTabPage = NULL;
Window* pFoundWindow = NULL;
Window* pWindow = firstLogicalChildOfParent(pParent);
Window* pNextWindow = pWindow;
while ( pWindow )
{
pWindow = pWindow->ImplGetWindow();
// skip invisible and disabled windows
if ( pTabPage || isVisibleInLayout(pWindow) )
{
// if the last control was a TabControl, take its TabPage
if ( pTabPage )
{
pFoundWindow = ImplGetSubChildWindow( pTabPage, n, nIndex );
pTabPage = NULL;
}
else
{
pFoundWindow = pWindow;
// for a TabControl, remember the current TabPage for later use
if ( pWindow->GetType() == WINDOW_TABCONTROL )
{
TabControl* pTabControl = ((TabControl*)pWindow);
// Check if the TabPage is a Child of the TabControl and still exists (by
// walking all child windows); because it could be that the TabPage has been
// destroyed already by a Dialog-Dtor, event that the TabControl still exists.
TabPage* pTempTabPage = pTabControl->GetTabPage( pTabControl->GetCurPageId() );
if ( pTempTabPage )
{
Window* pTempWindow = pTabControl->GetWindow( WINDOW_FIRSTCHILD );
while ( pTempWindow )
{
if ( pTempWindow->ImplGetWindow() == pTempTabPage )
{
pTabPage = pTempTabPage;
break;
}
pTempWindow = nextLogicalChildOfParent(pTabControl, pTempWindow);
}
}
}
else if ( ( pWindow->GetStyle() & WB_DIALOGCONTROL )
|| ( pWindow->GetStyle() & WB_CHILDDLGCTRL ) )
pFoundWindow = ImplGetSubChildWindow( pWindow, n, nIndex );
}
if ( n == nIndex )
return pFoundWindow;
nIndex++;
}
if ( pTabPage )
pWindow = pTabPage;
else
{
pWindow = nextLogicalChildOfParent(pParent, pNextWindow);
pNextWindow = pWindow;
}
}
nIndex--;
return pFoundWindow;
}
Window* ImplGetChildWindow( Window* pParent, sal_uInt16 n, sal_uInt16& nIndex, bool bTestEnable )
{
pParent = ImplGetTopParentOfTabHierarchy( pParent );
nIndex = 0;
Window* pWindow = ImplGetSubChildWindow( pParent, n, nIndex );
if ( bTestEnable )
{
sal_uInt16 n2 = nIndex;
while ( pWindow && (!isEnabledInLayout(pWindow) || !pWindow->IsInputEnabled()) )
{
n2 = nIndex+1;
nIndex = 0;
pWindow = ImplGetSubChildWindow( pParent, n2, nIndex );
if ( nIndex < n2 )
break;
}
if ( (nIndex < n2) && n )
{
do
{
n--;
nIndex = 0;
pWindow = ImplGetSubChildWindow( pParent, n, nIndex );
}
while ( pWindow && n && (!isEnabledInLayout(pWindow) || !pWindow->IsInputEnabled()) );
}
}
return pWindow;
}
static Window* ImplGetNextWindow( Window* pParent, sal_uInt16 n, sal_uInt16& nIndex, bool bTestEnable )
{
Window* pWindow = ImplGetChildWindow( pParent, n+1, nIndex, bTestEnable );
if ( n == nIndex )
{
n = 0;
pWindow = ImplGetChildWindow( pParent, n, nIndex, bTestEnable );
}
return pWindow;
}
Window* Window::ImplGetDlgWindow( sal_uInt16 nIndex, sal_uInt16 nType,
sal_uInt16 nFormStart, sal_uInt16 nFormEnd,
sal_uInt16* pIndex )
{
DBG_ASSERT( (nIndex >= nFormStart) && (nIndex <= nFormEnd),
"Window::ImplGetDlgWindow() - nIndex not in Form" );
Window* pWindow = NULL;
sal_uInt16 i;
sal_uInt16 nTemp;
sal_uInt16 nStartIndex;
if ( nType == DLGWINDOW_PREV )
{
i = nIndex;
do
{
if ( i > nFormStart )
i--;
else
i = nFormEnd;
pWindow = ImplGetChildWindow( this, i, nTemp, true );
if ( !pWindow )
break;
if ( (i == nTemp) && (pWindow->GetStyle() & WB_TABSTOP) )
break;
}
while ( i != nIndex );
}
else
{
i = nIndex;
pWindow = ImplGetChildWindow( this, i, i, (nType == DLGWINDOW_FIRST) );
if ( pWindow )
{
nStartIndex = i;
if ( nType == DLGWINDOW_NEXT )
{
if ( i < nFormEnd )
{
pWindow = ImplGetNextWindow( this, i, i, true );
if ( (i > nFormEnd) || (i < nFormStart) )
pWindow = ImplGetChildWindow( this, nFormStart, i, true );
}
else
pWindow = ImplGetChildWindow( this, nFormStart, i, true );
}
if ( i <= nFormEnd )
{
// carry the 2nd index, in case all controls are disabled
sal_uInt16 nStartIndex2 = i;
sal_uInt16 nOldIndex = i+1;
do
{
if ( pWindow->GetStyle() & WB_TABSTOP )
break;
if( i == nOldIndex ) // only disabled controls ?
{
i = nStartIndex2;
break;
}
nOldIndex = i;
if ( (i > nFormEnd) || (i < nFormStart) )
pWindow = ImplGetChildWindow( this, nFormStart, i, true );
else
pWindow = ImplGetNextWindow( this, i, i, true );
}
while ( (i != nStartIndex) && (i != nStartIndex2) );
if ( (i == nStartIndex2) &&
(!(pWindow->GetStyle() & WB_TABSTOP) || !isEnabledInLayout(pWindow)) )
i = nStartIndex;
}
}
if ( nType == DLGWINDOW_FIRST )
{
if ( pWindow )
{
if ( pWindow->GetType() == WINDOW_TABCONTROL )
{
Window* pNextWindow = ImplGetDlgWindow( i, DLGWINDOW_NEXT );
if ( pNextWindow )
{
if ( pWindow->IsChild( pNextWindow ) )
pWindow = pNextWindow;
}
}
if ( !(pWindow->GetStyle() & WB_TABSTOP) )
pWindow = NULL;
}
}
}
if ( pIndex )
*pIndex = i;
return pWindow;
}
Window* ImplFindDlgCtrlWindow( Window* pParent, Window* pWindow, sal_uInt16& rIndex,
sal_uInt16& rFormStart, sal_uInt16& rFormEnd )
{
Window* pSWindow;
Window* pSecondWindow = NULL;
Window* pTempWindow = NULL;
sal_uInt16 i;
sal_uInt16 nSecond_i = 0;
sal_uInt16 nFormStart = 0;
sal_uInt16 nSecondFormStart = 0;
sal_uInt16 nFormEnd;
// find focus window in the child list
Window* pFirstChildWindow = pSWindow = ImplGetChildWindow( pParent, 0, i, false );
if( pWindow == NULL )
pWindow = pSWindow;
while ( pSWindow )
{
// the DialogControlStart mark is only accepted for the direct children
if ( !ImplHasIndirectTabParent( pSWindow )
&& pSWindow->ImplGetWindow()->IsDialogControlStart() )
nFormStart = i;
// SecondWindow for composit controls like ComboBoxes and arrays
if ( pSWindow->ImplIsWindowOrChild( pWindow ) )
{
pSecondWindow = pSWindow;
nSecond_i = i;
nSecondFormStart = nFormStart;
if ( pSWindow == pWindow )
break;
}
pSWindow = ImplGetNextWindow( pParent, i, i, false );
if ( !i )
pSWindow = NULL;
}
if ( !pSWindow )
{
// Window not found; we cannot handle it
if ( !pSecondWindow )
return NULL;
else
{
pSWindow = pSecondWindow;
i = nSecond_i;
nFormStart = nSecondFormStart;
}
}
// initialize
rIndex = i;
rFormStart = nFormStart;
// find end of template
nFormEnd = nFormStart;
pTempWindow = pSWindow;
sal_Int32 nIteration = 0;
do
{
nFormEnd = i;
pTempWindow = ImplGetNextWindow( pParent, i, i, false );
// the DialogControlStart mark is only accepted for the direct children
if ( !i
|| ( pTempWindow && !ImplHasIndirectTabParent( pTempWindow )
&& pTempWindow->ImplGetWindow()->IsDialogControlStart() ) )
break;
if ( pTempWindow && pTempWindow == pFirstChildWindow )
{
// It is possible to go through the begin of hierarchy once
// while looking for DialogControlStart mark.
// If it happens second time, it looks like an endless loop,
// that should be impossible, but just for the case...
nIteration++;
if ( nIteration >= 2 )
{
// this is an unexpected scenario
DBG_ASSERT( false, "It seems to be an endless loop!" );
rFormStart = 0;
break;
}
}
}
while ( pTempWindow );
rFormEnd = nFormEnd;
return pSWindow;
}
Window* ImplFindAccelWindow( Window* pParent, sal_uInt16& rIndex, sal_Unicode cCharCode,
sal_uInt16 nFormStart, sal_uInt16 nFormEnd, bool bCheckEnable = true )
{
DBG_ASSERT( (rIndex >= nFormStart) && (rIndex <= nFormEnd),
"Window::ImplFindAccelWindow() - rIndex not in Form" );
sal_Unicode cCompareChar;
sal_uInt16 nStart = rIndex;
sal_uInt16 i = rIndex;
Window* pWindow;
// MT: Where can we keep the CharClass?!
static uno::Reference< i18n::XCharacterClassification > xCharClass;
if ( !xCharClass.is() )
xCharClass = vcl::unohelper::CreateCharacterClassification();
const ::com::sun::star::lang::Locale& rLocale = Application::GetSettings().GetUILanguageTag().getLocale();
cCharCode = xCharClass->toUpper( OUString(cCharCode), 0, 1, rLocale )[0];
if ( i < nFormEnd )
pWindow = ImplGetNextWindow( pParent, i, i, true );
else
pWindow = ImplGetChildWindow( pParent, nFormStart, i, true );
while( pWindow )
{
const OUString aStr = pWindow->GetText();
sal_Int32 nPos = aStr.indexOf( '~' );
while (nPos != -1)
{
cCompareChar = aStr[nPos+1];
cCompareChar = xCharClass->toUpper( OUString(cCompareChar), 0, 1, rLocale )[0];
if ( cCompareChar == cCharCode )
{
if (pWindow->GetType() == WINDOW_FIXEDTEXT)
{
FixedText *pFixedText = static_cast<FixedText*>(pWindow);
Window *pMnemonicWidget = pFixedText->get_mnemonic_widget();
SAL_WARN_IF(isContainerWindow(pFixedText->GetParent()) && !pMnemonicWidget,
"vcl.a11y", "label missing mnemonic_widget?");
if (pMnemonicWidget)
return pMnemonicWidget;
}
// skip Static-Controls
if ( (pWindow->GetType() == WINDOW_FIXEDTEXT) ||
(pWindow->GetType() == WINDOW_FIXEDLINE) ||
(pWindow->GetType() == WINDOW_GROUPBOX) )
pWindow = pParent->ImplGetDlgWindow( i, DLGWINDOW_NEXT );
rIndex = i;
return pWindow;
}
nPos = aStr.indexOf( '~', nPos+1 );
}
// #i93011# it would have made sense to have this really recursive
// right from the start. However this would cause unpredictable side effects now
// so instead we have a style bit for some child windows, that want their
// children checked for accelerators
if( (pWindow->GetStyle() & WB_CHILDDLGCTRL) != 0 )
{
sal_uInt16 nChildIndex;
sal_uInt16 nChildFormStart;
sal_uInt16 nChildFormEnd;
// get form start and end
::ImplFindDlgCtrlWindow( pWindow, NULL,
nChildIndex, nChildFormStart, nChildFormEnd );
Window* pAccelWin = ImplFindAccelWindow( pWindow, nChildIndex, cCharCode,
nChildFormStart, nChildFormEnd,
bCheckEnable );
if( pAccelWin )
return pAccelWin;
}
if ( i == nStart )
break;
if ( i < nFormEnd )
{
pWindow = ImplGetNextWindow( pParent, i, i, bCheckEnable );
if( ! pWindow )
pWindow = ImplGetChildWindow( pParent, nFormStart, i, bCheckEnable );
}
else
pWindow = ImplGetChildWindow( pParent, nFormStart, i, bCheckEnable );
}
return NULL;
}
void Window::ImplControlFocus( sal_uInt16 nFlags )
{
if ( nFlags & GETFOCUS_MNEMONIC )
{
if ( GetType() == WINDOW_RADIOBUTTON )
{
if ( !((RadioButton*)this)->IsChecked() )
((RadioButton*)this)->ImplCallClick( true, nFlags );
else
ImplGrabFocus( nFlags );
}
else
{
ImplGrabFocus( nFlags );
if ( nFlags & GETFOCUS_UNIQUEMNEMONIC )
{
if ( GetType() == WINDOW_CHECKBOX )
((CheckBox*)this)->ImplCheck();
else if ( mpWindowImpl->mbPushButton )
{
((PushButton*)this)->SetPressed( true );
((PushButton*)this)->SetPressed( false );
((PushButton*)this)->Click();
}
}
}
}
else
{
if ( GetType() == WINDOW_RADIOBUTTON )
{
if ( !((RadioButton*)this)->IsChecked() )
((RadioButton*)this)->ImplCallClick( true, nFlags );
else
ImplGrabFocus( nFlags );
}
else
ImplGrabFocus( nFlags );
}
}
namespace
{
bool isSuitableDestination(Window *pWindow)
{
return (pWindow && isVisibleInLayout(pWindow) &&
isEnabledInLayout(pWindow) && pWindow->IsInputEnabled() &&
//Pure window shouldn't get window after controls such as
//buttons.
(pWindow->GetType() != WINDOW_WINDOW && pWindow->GetType() != WINDOW_SYSWINDOW &&
pWindow->GetType() != WINDOW_WORKWINDOW && pWindow->GetType() != WINDOW_CONTROL)
);
}
bool focusNextInGroup(std::vector<RadioButton*>::iterator aStart, std::vector<RadioButton*> &rGroup)
{
std::vector<RadioButton*>::iterator aI(aStart);
if (aStart != rGroup.end())
++aI;
for (; aI != rGroup.end(); ++aI)
{
Window *pWindow = *aI;
if (isSuitableDestination(pWindow))
{
pWindow->ImplControlFocus( GETFOCUS_CURSOR | GETFOCUS_FORWARD );
return true;
}
}
for (aI = rGroup.begin(); aI != aStart; ++aI)
{
Window *pWindow = *aI;
if (isSuitableDestination(pWindow))
{
pWindow->ImplControlFocus( GETFOCUS_CURSOR | GETFOCUS_FORWARD );
return true;
}
}
return false;
}
bool nextInGroup(RadioButton *pSourceWindow, bool bBackward)
{
std::vector<RadioButton*> aGroup(pSourceWindow->GetRadioButtonGroup(true));
if (aGroup.size() == 1) //only one button in group
return false;
if (bBackward)
std::reverse(aGroup.begin(), aGroup.end());
std::vector<RadioButton*>::iterator aStart(std::find(aGroup.begin(), aGroup.end(), pSourceWindow));
assert(aStart != aGroup.end());
return focusNextInGroup(aStart, aGroup);
}
}
bool Window::ImplDlgCtrl( const KeyEvent& rKEvt, bool bKeyInput )
{
KeyCode aKeyCode = rKEvt.GetKeyCode();
sal_uInt16 nKeyCode = aKeyCode.GetCode();
Window* pSWindow;
Window* pTempWindow;
Window* pButtonWindow;
sal_uInt16 i;
sal_uInt16 iButton;
sal_uInt16 iButtonStart;
sal_uInt16 iTemp;
sal_uInt16 nIndex;
sal_uInt16 nFormStart;
sal_uInt16 nFormEnd;
sal_uInt16 nDlgCtrlFlags;
// we cannot take over control without Focus-window
Window* pFocusWindow = Application::GetFocusWindow();
if ( !pFocusWindow || !ImplIsWindowOrChild( pFocusWindow ) )
return false;
// find Focus-Window in the child list
pSWindow = ::ImplFindDlgCtrlWindow( this, pFocusWindow,
nIndex, nFormStart, nFormEnd );
if ( !pSWindow )
return false;
i = nIndex;
nDlgCtrlFlags = 0;
pTempWindow = pSWindow;
do
{
nDlgCtrlFlags |= pTempWindow->GetDialogControlFlags();
if ( pTempWindow == this )
break;
pTempWindow = pTempWindow->ImplGetParent();
}
while ( pTempWindow );
pButtonWindow = NULL;
if ( nKeyCode == KEY_RETURN )
{
// search first for a DefPushButton/CancelButton
pButtonWindow = ImplGetChildWindow( this, nFormStart, iButton, true );
iButtonStart = iButton;
while ( pButtonWindow )
{
if ( (pButtonWindow->GetStyle() & WB_DEFBUTTON) &&
pButtonWindow->mpWindowImpl->mbPushButton )
break;
pButtonWindow = ImplGetNextWindow( this, iButton, iButton, true );
if ( (iButton <= iButtonStart) || (iButton > nFormEnd) )
pButtonWindow = NULL;
}
if ( bKeyInput && !pButtonWindow && (nDlgCtrlFlags & WINDOW_DLGCTRL_RETURN) )
{
sal_uInt16 nType;
sal_uInt16 nGetFocusFlags = GETFOCUS_TAB;
sal_uInt16 nNewIndex;
sal_uInt16 iStart;
if ( aKeyCode.IsShift() )
{
nType = DLGWINDOW_PREV;
nGetFocusFlags |= GETFOCUS_BACKWARD;
}
else
{
nType = DLGWINDOW_NEXT;
nGetFocusFlags |= GETFOCUS_FORWARD;
}
iStart = i;
pTempWindow = ImplGetDlgWindow( i, nType, nFormStart, nFormEnd, &nNewIndex );
while ( pTempWindow && (pTempWindow != pSWindow) )
{
if ( !pTempWindow->mpWindowImpl->mbPushButton )
{
// get Around-Flag
if ( nType == DLGWINDOW_PREV )
{
if ( nNewIndex > iStart )
nGetFocusFlags |= GETFOCUS_AROUND;
}
else
{
if ( nNewIndex < iStart )
nGetFocusFlags |= GETFOCUS_AROUND;
}
pTempWindow->ImplControlFocus( nGetFocusFlags );
return true;
}
else
{
i = nNewIndex;
pTempWindow = ImplGetDlgWindow( i, nType, nFormStart, nFormEnd, &nNewIndex );
}
if ( (i <= iStart) || (i > nFormEnd) )
pTempWindow = NULL;
}
// if this is the same window, simulate a Get/LoseFocus,
// in case AROUND is being processed
if ( pTempWindow && (pTempWindow == pSWindow) )
{
NotifyEvent aNEvt1( EVENT_LOSEFOCUS, pSWindow );
if ( !ImplCallPreNotify( aNEvt1 ) )
pSWindow->LoseFocus();
pSWindow->mpWindowImpl->mnGetFocusFlags = nGetFocusFlags | GETFOCUS_AROUND;
NotifyEvent aNEvt2( EVENT_GETFOCUS, pSWindow );
if ( !ImplCallPreNotify( aNEvt2 ) )
pSWindow->GetFocus();
pSWindow->mpWindowImpl->mnGetFocusFlags = 0;
return true;
}
}
}
else if ( nKeyCode == KEY_ESCAPE )
{
// search first for a DefPushButton/CancelButton
pButtonWindow = ImplGetChildWindow( this, nFormStart, iButton, true );
iButtonStart = iButton;
while ( pButtonWindow )
{
if ( pButtonWindow->GetType() == WINDOW_CANCELBUTTON )
break;
pButtonWindow = ImplGetNextWindow( this, iButton, iButton, true );
if ( (iButton <= iButtonStart) || (iButton > nFormEnd) )
pButtonWindow = NULL;
}
if ( bKeyInput && mpWindowImpl->mpDlgCtrlDownWindow )
{
if ( mpWindowImpl->mpDlgCtrlDownWindow != pButtonWindow )
{
((PushButton*)mpWindowImpl->mpDlgCtrlDownWindow)->SetPressed( false );
mpWindowImpl->mpDlgCtrlDownWindow = NULL;
return true;
}
}
}
else if ( bKeyInput )
{
if ( nKeyCode == KEY_TAB )
{
// do not skip Alt key, for MS Windows
if ( !aKeyCode.IsMod2() )
{
sal_uInt16 nType;
sal_uInt16 nGetFocusFlags = GETFOCUS_TAB;
sal_uInt16 nNewIndex;
bool bFormular = false;
// for Ctrl-Tab check if we want to jump to next template
if ( aKeyCode.IsMod1() )
{
// search group
Window* pFormularFirstWindow = NULL;
Window* pLastFormularFirstWindow = NULL;
pTempWindow = ImplGetChildWindow( this, 0, iTemp, false );
Window* pPrevFirstFormularFirstWindow = NULL;
Window* pFirstFormularFirstWindow = pTempWindow;
while ( pTempWindow )
{
if ( pTempWindow->ImplGetWindow()->IsDialogControlStart() )
{
if ( iTemp != 0 )
bFormular = true;
if ( aKeyCode.IsShift() )
{
if ( iTemp <= nIndex )
pFormularFirstWindow = pPrevFirstFormularFirstWindow;
pPrevFirstFormularFirstWindow = pTempWindow;
}
else
{
if ( (iTemp > nIndex) && !pFormularFirstWindow )
pFormularFirstWindow = pTempWindow;
}
pLastFormularFirstWindow = pTempWindow;
}
pTempWindow = ImplGetNextWindow( this, iTemp, iTemp, false );
if ( !iTemp )
pTempWindow = NULL;
}
if ( bFormular )
{
if ( !pFormularFirstWindow )
{
if ( aKeyCode.IsShift() )
pFormularFirstWindow = pLastFormularFirstWindow;
else
pFormularFirstWindow = pFirstFormularFirstWindow;
}
sal_uInt16 nFoundFormStart = 0;
sal_uInt16 nFoundFormEnd = 0;
sal_uInt16 nTempIndex = 0;
if ( ::ImplFindDlgCtrlWindow( this, pFormularFirstWindow, nTempIndex,
nFoundFormStart, nFoundFormEnd ) )
{
nTempIndex = nFoundFormStart;
pFormularFirstWindow = ImplGetDlgWindow( nTempIndex, DLGWINDOW_FIRST, nFoundFormStart, nFoundFormEnd );
if ( pFormularFirstWindow )
{
pFormularFirstWindow->ImplControlFocus();
return true;
}
}
}
}
if ( !bFormular )
{
// Only use Ctrl-TAB if it was allowed for the whole
// dialog or for the current control (#103667#)
if ( !aKeyCode.IsMod1() || (nDlgCtrlFlags & WINDOW_DLGCTRL_MOD1TAB) ||
( pSWindow->GetStyle() & WINDOW_DLGCTRL_MOD1TAB) )
{
if ( aKeyCode.IsShift() )
{
nType = DLGWINDOW_PREV;
nGetFocusFlags |= GETFOCUS_BACKWARD;
}
else
{
nType = DLGWINDOW_NEXT;
nGetFocusFlags |= GETFOCUS_FORWARD;
}
Window* pWindow = ImplGetDlgWindow( i, nType, nFormStart, nFormEnd, &nNewIndex );
// if this is the same window, simulate a Get/LoseFocus,
// in case AROUND is being processed
if ( pWindow == pSWindow )
{
NotifyEvent aNEvt1( EVENT_LOSEFOCUS, pSWindow );
if ( !ImplCallPreNotify( aNEvt1 ) )
pSWindow->LoseFocus();
pSWindow->mpWindowImpl->mnGetFocusFlags = nGetFocusFlags | GETFOCUS_AROUND;
NotifyEvent aNEvt2( EVENT_GETFOCUS, pSWindow );
if ( !ImplCallPreNotify( aNEvt2 ) )
pSWindow->GetFocus();
pSWindow->mpWindowImpl->mnGetFocusFlags = 0;
return true;
}
else if ( pWindow )
{
// get Around-Flag
if ( nType == DLGWINDOW_PREV )
{
if ( nNewIndex > i )
nGetFocusFlags |= GETFOCUS_AROUND;
}
else
{
if ( nNewIndex < i )
nGetFocusFlags |= GETFOCUS_AROUND;
}
pWindow->ImplControlFocus( nGetFocusFlags );
return true;
}
}
}
}
}
else if ( (nKeyCode == KEY_LEFT) || (nKeyCode == KEY_UP) )
{
if (pSWindow->GetType() == WINDOW_RADIOBUTTON)
return nextInGroup(static_cast<RadioButton*>(pSWindow), true);
else
{
WinBits nStyle = pSWindow->GetStyle();
if ( !(nStyle & WB_GROUP) )
{
Window* pWindow = prevLogicalChildOfParent(this, pSWindow);
while ( pWindow )
{
pWindow = pWindow->ImplGetWindow();
nStyle = pWindow->GetStyle();
if (isSuitableDestination(pWindow))
{
if ( pWindow != pSWindow )
pWindow->ImplControlFocus( GETFOCUS_CURSOR | GETFOCUS_BACKWARD );
return true;
}
if ( nStyle & WB_GROUP )
break;
pWindow = prevLogicalChildOfParent(this, pWindow);
}
}
}
}
else if ( (nKeyCode == KEY_RIGHT) || (nKeyCode == KEY_DOWN) )
{
if (pSWindow->GetType() == WINDOW_RADIOBUTTON)
return nextInGroup(static_cast<RadioButton*>(pSWindow), false);
else
{
Window* pWindow = nextLogicalChildOfParent(this, pSWindow);
while ( pWindow )
{
pWindow = pWindow->ImplGetWindow();
WinBits nStyle = pWindow->GetStyle();
if ( nStyle & WB_GROUP )
break;
if (isSuitableDestination(pWindow))
{
pWindow->ImplControlFocus( GETFOCUS_CURSOR | GETFOCUS_BACKWARD );
return true;
}
pWindow = nextLogicalChildOfParent(this, pWindow);
}
}
}
else
{
sal_Unicode c = rKEvt.GetCharCode();
if ( c )
{
pSWindow = ::ImplFindAccelWindow( this, i, c, nFormStart, nFormEnd );
if ( pSWindow )
{
sal_uInt16 nGetFocusFlags = GETFOCUS_MNEMONIC;
if ( pSWindow == ::ImplFindAccelWindow( this, i, c, nFormStart, nFormEnd ) )
nGetFocusFlags |= GETFOCUS_UNIQUEMNEMONIC;
pSWindow->ImplControlFocus( nGetFocusFlags );
return true;
}
}
}
}
if (isSuitableDestination(pButtonWindow))
{
if ( bKeyInput )
{
if ( mpWindowImpl->mpDlgCtrlDownWindow && (mpWindowImpl->mpDlgCtrlDownWindow != pButtonWindow) )
{
((PushButton*)mpWindowImpl->mpDlgCtrlDownWindow)->SetPressed( false );
mpWindowImpl->mpDlgCtrlDownWindow = NULL;
}
((PushButton*)pButtonWindow)->SetPressed( true );
mpWindowImpl->mpDlgCtrlDownWindow = pButtonWindow;
}
else if ( mpWindowImpl->mpDlgCtrlDownWindow == pButtonWindow )
{
mpWindowImpl->mpDlgCtrlDownWindow = NULL;
((PushButton*)pButtonWindow)->SetPressed( false );
((PushButton*)pButtonWindow)->Click();
}
return true;
}
return false;
}
// checks if this window has dialog control
bool Window::ImplHasDlgCtrl()
{
Window* pDlgCtrlParent;
// lookup window for dialog control
pDlgCtrlParent = ImplGetParent();
while ( pDlgCtrlParent &&
!pDlgCtrlParent->ImplIsOverlapWindow() &&
((pDlgCtrlParent->GetStyle() & (WB_DIALOGCONTROL | WB_NODIALOGCONTROL)) != WB_DIALOGCONTROL) )
pDlgCtrlParent = pDlgCtrlParent->ImplGetParent();
if ( !pDlgCtrlParent || ((pDlgCtrlParent->GetStyle() & (WB_DIALOGCONTROL | WB_NODIALOGCONTROL)) != WB_DIALOGCONTROL) )
return false;
else
return true;
}
void Window::ImplDlgCtrlNextWindow()
{
Window* pDlgCtrlParent;
Window* pDlgCtrl;
Window* pSWindow;
sal_uInt16 nIndex;
sal_uInt16 nFormStart;
sal_uInt16 nFormEnd;
// lookup window for dialog control
pDlgCtrl = this;
pDlgCtrlParent = ImplGetParent();
while ( pDlgCtrlParent &&
!pDlgCtrlParent->ImplIsOverlapWindow() &&
((pDlgCtrlParent->GetStyle() & (WB_DIALOGCONTROL | WB_NODIALOGCONTROL)) != WB_DIALOGCONTROL) )
pDlgCtrlParent = pDlgCtrlParent->ImplGetParent();
if ( !pDlgCtrlParent || (GetStyle() & WB_NODIALOGCONTROL) || ((pDlgCtrlParent->GetStyle() & (WB_DIALOGCONTROL | WB_NODIALOGCONTROL)) != WB_DIALOGCONTROL) )
return;
// lookup window in child list
pSWindow = ::ImplFindDlgCtrlWindow( pDlgCtrlParent, pDlgCtrl,
nIndex, nFormStart, nFormEnd );
if ( !pSWindow )
return;
Window* pWindow = pDlgCtrlParent->ImplGetDlgWindow( nIndex, DLGWINDOW_NEXT, nFormStart, nFormEnd );
if ( pWindow && (pWindow != pSWindow) )
pWindow->ImplControlFocus();
}
static void ImplDlgCtrlUpdateDefButton( Window* pParent, Window* pFocusWindow,
bool bGetFocus )
{
PushButton* pOldDefButton = NULL;
PushButton* pNewDefButton = NULL;
Window* pSWindow;
sal_uInt16 i;
sal_uInt16 nFormStart;
sal_uInt16 nFormEnd;
// find template
pSWindow = ::ImplFindDlgCtrlWindow( pParent, pFocusWindow, i, nFormStart, nFormEnd );
if ( !pSWindow )
{
nFormStart = 0;
nFormEnd = 0xFFFF;
}
pSWindow = ImplGetChildWindow( pParent, nFormStart, i, false );
while ( pSWindow )
{
if ( pSWindow->ImplIsPushButton() )
{
PushButton* pPushButton = (PushButton*)pSWindow;
if ( pPushButton->ImplIsDefButton() )
pOldDefButton = pPushButton;
if ( pPushButton->HasChildPathFocus() )
pNewDefButton = pPushButton;
else if ( !pNewDefButton && (pPushButton->GetStyle() & WB_DEFBUTTON) )
pNewDefButton = pPushButton;
}
pSWindow = ImplGetNextWindow( pParent, i, i, false );
if ( !i || (i > nFormEnd) )
pSWindow = NULL;
}
if ( !bGetFocus )
{
sal_uInt16 nDummy;
Window* pNewFocusWindow = Application::GetFocusWindow();
if ( !pNewFocusWindow || !pParent->ImplIsWindowOrChild( pNewFocusWindow ) )
pNewDefButton = NULL;
else if ( !::ImplFindDlgCtrlWindow( pParent, pNewFocusWindow, i, nDummy, nDummy ) ||
(i < nFormStart) || (i > nFormEnd) )
pNewDefButton = NULL;
}
if ( pOldDefButton != pNewDefButton )
{
if ( pOldDefButton )
pOldDefButton->ImplSetDefButton( false );
if ( pNewDefButton )
pNewDefButton->ImplSetDefButton( true );
}
}
void Window::ImplDlgCtrlFocusChanged( Window* pWindow, bool bGetFocus )
{
if ( mpWindowImpl->mpDlgCtrlDownWindow && !bGetFocus )
{
((PushButton*)mpWindowImpl->mpDlgCtrlDownWindow)->SetPressed( false );
mpWindowImpl->mpDlgCtrlDownWindow = NULL;
}
ImplDlgCtrlUpdateDefButton( this, pWindow, bGetFocus );
}
Window* Window::ImplFindDlgCtrlWindow( Window* pWindow )
{
sal_uInt16 nIndex;
sal_uInt16 nFormStart;
sal_uInt16 nFormEnd;
// find Focus-Window in the Child-List and return
return ::ImplFindDlgCtrlWindow( this, pWindow, nIndex, nFormStart, nFormEnd );
}
Window* Window::GetParentLabelFor( const Window* ) const
{
return NULL;
}
Window* Window::GetParentLabeledBy( const Window* ) const
{
return NULL;
}
sal_Unicode getAccel( const OUString& rStr )
{
sal_Unicode nChar = 0;
sal_Int32 nPos = 0;
do
{
nPos = rStr.indexOf( '~', nPos );
if( nPos != -1 && nPos < rStr.getLength() )
nChar = rStr[ ++nPos ];
else
nChar = 0;
} while( nChar == '~' );
return nChar;
}
KeyEvent Window::GetActivationKey() const
{
KeyEvent aKeyEvent;
sal_Unicode nAccel = getAccel( GetText() );
if( ! nAccel )
{
Window* pWindow = GetAccessibleRelationLabeledBy();
if( pWindow )
nAccel = getAccel( pWindow->GetText() );
}
if( nAccel )
{
sal_uInt16 nCode = 0;
if( nAccel >= 'a' && nAccel <= 'z' )
nCode = KEY_A + (nAccel-'a');
else if( nAccel >= 'A' && nAccel <= 'Z' )
nCode = KEY_A + (nAccel-'A');
else if( nAccel >= '0' && nAccel <= '9' )
nCode = KEY_0 + (nAccel-'0');
else if( nAccel == '.' )
nCode = KEY_POINT;
else if( nAccel == '-' )
nCode = KEY_SUBTRACT;
KeyCode aKeyCode( nCode, false, false, true, false );
aKeyEvent = KeyEvent( nAccel, aKeyCode );
}
return aKeyEvent;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|