1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_sc.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include "protectiondlg.hxx" 32*cdf0e10cSrcweir #include "protectiondlg.hrc" 33*cdf0e10cSrcweir #include "scresid.hxx" 34*cdf0e10cSrcweir #include "tabprotection.hxx" 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir #include <vcl/msgbox.hxx> 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir // The order must match that of the list box. 40*cdf0e10cSrcweir static const ScTableProtection::Option aOptions[] = { 41*cdf0e10cSrcweir ScTableProtection::SELECT_LOCKED_CELLS, 42*cdf0e10cSrcweir ScTableProtection::SELECT_UNLOCKED_CELLS, 43*cdf0e10cSrcweir }; 44*cdf0e10cSrcweir static const sal_uInt16 nOptionCount = sizeof(aOptions)/sizeof(aOptions[0]); 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir ScTableProtectionDlg::ScTableProtectionDlg(Window* pParent) : 48*cdf0e10cSrcweir ModalDialog(pParent, ScResId(RID_SCDLG_TABPROTECTION)), 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir maBtnProtect (this, ScResId(BTN_PROTECT)), 51*cdf0e10cSrcweir maPassword1Text (this, ScResId(FT_PASSWORD1)), 52*cdf0e10cSrcweir maPassword1Edit (this, ScResId(ED_PASSWORD1)), 53*cdf0e10cSrcweir maPassword2Text (this, ScResId(FT_PASSWORD2)), 54*cdf0e10cSrcweir maPassword2Edit (this, ScResId(ED_PASSWORD2)), 55*cdf0e10cSrcweir maOptionsLine (this, ScResId(FL_OPTIONS)), 56*cdf0e10cSrcweir maOptionsText (this, ScResId(FT_OPTIONS)), 57*cdf0e10cSrcweir maOptionsListBox(this, ScResId(CLB_OPTIONS)), 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir maBtnOk (this, ScResId(BTN_OK)), 60*cdf0e10cSrcweir maBtnCancel (this, ScResId(BTN_CANCEL)), 61*cdf0e10cSrcweir maBtnHelp (this, ScResId(BTN_HELP)), 62*cdf0e10cSrcweir 63*cdf0e10cSrcweir maSelectLockedCells(ScResId(ST_SELECT_LOCKED_CELLS)), 64*cdf0e10cSrcweir maSelectUnlockedCells(ScResId(ST_SELECT_UNLOCKED_CELLS)) 65*cdf0e10cSrcweir { 66*cdf0e10cSrcweir Init(); 67*cdf0e10cSrcweir FreeResource(); 68*cdf0e10cSrcweir } 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir ScTableProtectionDlg::~ScTableProtectionDlg() 71*cdf0e10cSrcweir { 72*cdf0e10cSrcweir } 73*cdf0e10cSrcweir 74*cdf0e10cSrcweir short ScTableProtectionDlg::Execute() 75*cdf0e10cSrcweir { 76*cdf0e10cSrcweir return ModalDialog::Execute(); 77*cdf0e10cSrcweir } 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir void ScTableProtectionDlg::SetDialogData(const ScTableProtection& rData) 80*cdf0e10cSrcweir { 81*cdf0e10cSrcweir for (sal_uInt16 i = 0; i < nOptionCount; ++i) 82*cdf0e10cSrcweir maOptionsListBox.CheckEntryPos(i, rData.isOptionEnabled(aOptions[i])); 83*cdf0e10cSrcweir } 84*cdf0e10cSrcweir 85*cdf0e10cSrcweir void ScTableProtectionDlg::WriteData(ScTableProtection& rData) const 86*cdf0e10cSrcweir { 87*cdf0e10cSrcweir rData.setProtected(maBtnProtect.IsChecked()); 88*cdf0e10cSrcweir 89*cdf0e10cSrcweir // We assume that the two password texts match. 90*cdf0e10cSrcweir rData.setPassword(maPassword1Edit.GetText()); 91*cdf0e10cSrcweir 92*cdf0e10cSrcweir for (sal_uInt16 i = 0; i < nOptionCount; ++i) 93*cdf0e10cSrcweir rData.setOption(aOptions[i], maOptionsListBox.IsChecked(i)); 94*cdf0e10cSrcweir } 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir void ScTableProtectionDlg::Init() 97*cdf0e10cSrcweir { 98*cdf0e10cSrcweir Link aLink = LINK( this, ScTableProtectionDlg, CheckBoxHdl ); 99*cdf0e10cSrcweir maBtnProtect.SetClickHdl(aLink); 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir aLink = LINK( this, ScTableProtectionDlg, OKHdl ); 102*cdf0e10cSrcweir maBtnOk.SetClickHdl(aLink); 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir aLink = LINK( this, ScTableProtectionDlg, PasswordModifyHdl ); 105*cdf0e10cSrcweir maPassword1Edit.SetModifyHdl(aLink); 106*cdf0e10cSrcweir maPassword2Edit.SetModifyHdl(aLink); 107*cdf0e10cSrcweir 108*cdf0e10cSrcweir maOptionsListBox.SetUpdateMode(false); 109*cdf0e10cSrcweir maOptionsListBox.Clear(); 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir maOptionsListBox.InsertEntry(maSelectLockedCells); 112*cdf0e10cSrcweir maOptionsListBox.InsertEntry(maSelectUnlockedCells); 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir maOptionsListBox.CheckEntryPos(0, true); 115*cdf0e10cSrcweir maOptionsListBox.CheckEntryPos(1, true); 116*cdf0e10cSrcweir 117*cdf0e10cSrcweir maOptionsListBox.SetUpdateMode(true); 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir // Set the default state of the dialog. 120*cdf0e10cSrcweir maBtnProtect.Check(true); 121*cdf0e10cSrcweir maPassword1Edit.GrabFocus(); 122*cdf0e10cSrcweir } 123*cdf0e10cSrcweir 124*cdf0e10cSrcweir void ScTableProtectionDlg::EnableOptionalWidgets(bool bEnable) 125*cdf0e10cSrcweir { 126*cdf0e10cSrcweir maPassword1Text.Enable(bEnable); 127*cdf0e10cSrcweir maPassword1Edit.Enable(bEnable); 128*cdf0e10cSrcweir maPassword2Text.Enable(bEnable); 129*cdf0e10cSrcweir maPassword2Edit.Enable(bEnable); 130*cdf0e10cSrcweir maOptionsLine.Enable(bEnable); 131*cdf0e10cSrcweir maOptionsText.Enable(bEnable); 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir maOptionsListBox.Enable(bEnable); 134*cdf0e10cSrcweir maOptionsListBox.Invalidate(); 135*cdf0e10cSrcweir } 136*cdf0e10cSrcweir 137*cdf0e10cSrcweir IMPL_LINK( ScTableProtectionDlg, CheckBoxHdl, CheckBox*, pBtn ) 138*cdf0e10cSrcweir { 139*cdf0e10cSrcweir if (pBtn == &maBtnProtect) 140*cdf0e10cSrcweir { 141*cdf0e10cSrcweir bool bChecked = maBtnProtect.IsChecked(); 142*cdf0e10cSrcweir EnableOptionalWidgets(bChecked); 143*cdf0e10cSrcweir maBtnOk.Enable(bChecked); 144*cdf0e10cSrcweir } 145*cdf0e10cSrcweir 146*cdf0e10cSrcweir return 0; 147*cdf0e10cSrcweir } 148*cdf0e10cSrcweir 149*cdf0e10cSrcweir IMPL_LINK( ScTableProtectionDlg, OKHdl, OKButton*, EMPTYARG ) 150*cdf0e10cSrcweir { 151*cdf0e10cSrcweir EndDialog(RET_OK); 152*cdf0e10cSrcweir return 0; 153*cdf0e10cSrcweir } 154*cdf0e10cSrcweir 155*cdf0e10cSrcweir IMPL_LINK( ScTableProtectionDlg, PasswordModifyHdl, Edit*, EMPTYARG ) 156*cdf0e10cSrcweir { 157*cdf0e10cSrcweir String aPass1 = maPassword1Edit.GetText(); 158*cdf0e10cSrcweir String aPass2 = maPassword2Edit.GetText(); 159*cdf0e10cSrcweir maBtnOk.Enable(aPass1.Equals(aPass2)); 160*cdf0e10cSrcweir return 0; 161*cdf0e10cSrcweir } 162