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_cui.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir // include --------------------------------------------------------------- 32*cdf0e10cSrcweir #include <tools/shl.hxx> 33*cdf0e10cSrcweir #include <tools/date.hxx> 34*cdf0e10cSrcweir #include <tools/time.hxx> 35*cdf0e10cSrcweir #include <vcl/svapp.hxx> 36*cdf0e10cSrcweir #include <vcl/msgbox.hxx> 37*cdf0e10cSrcweir #include <svl/itempool.hxx> 38*cdf0e10cSrcweir #include <svl/itemset.hxx> 39*cdf0e10cSrcweir #include <unotools/useroptions.hxx> 40*cdf0e10cSrcweir #include <unotools/localedatawrapper.hxx> 41*cdf0e10cSrcweir #include <comphelper/processfactory.hxx> 42*cdf0e10cSrcweir #include <svx/svxids.hrc> // SID_ATTR_... 43*cdf0e10cSrcweir #include <svx/dialogs.hrc> // RID_SVXDLG_POSTIT 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir #define _SVX_POSTDLG_CXX 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir #include <cuires.hrc> 48*cdf0e10cSrcweir #include "postdlg.hrc" 49*cdf0e10cSrcweir #include <svx/postattr.hxx> 50*cdf0e10cSrcweir #include "postdlg.hxx" 51*cdf0e10cSrcweir #include <dialmgr.hxx> 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir #include "helpid.hrc" 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir // static ---------------------------------------------------------------- 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir static sal_uInt16 pRanges[] = 58*cdf0e10cSrcweir { 59*cdf0e10cSrcweir SID_ATTR_POSTIT_AUTHOR, 60*cdf0e10cSrcweir SID_ATTR_POSTIT_TEXT, 61*cdf0e10cSrcweir 0 62*cdf0e10cSrcweir }; 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir // class SvxPostItDialog ------------------------------------------------- 65*cdf0e10cSrcweir 66*cdf0e10cSrcweir SvxPostItDialog::SvxPostItDialog( Window* pParent, 67*cdf0e10cSrcweir const SfxItemSet& rCoreSet, 68*cdf0e10cSrcweir sal_Bool bPrevNext, 69*cdf0e10cSrcweir sal_Bool bRedline ) : 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir SfxModalDialog( pParent, CUI_RES( RID_SVXDLG_POSTIT ) ), 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir aPostItFL ( this, CUI_RES( FL_POSTIT ) ), 74*cdf0e10cSrcweir aLastEditLabelFT( this, CUI_RES( FT_LASTEDITLABEL ) ), 75*cdf0e10cSrcweir aLastEditFT ( this, CUI_RES( FT_LASTEDIT ) ), 76*cdf0e10cSrcweir aEditFT ( this, CUI_RES( FT_EDIT ) ), 77*cdf0e10cSrcweir aEditED ( this, CUI_RES( ED_EDIT ) ), 78*cdf0e10cSrcweir aAuthorFT ( this, CUI_RES( FT_AUTHOR) ), 79*cdf0e10cSrcweir aAuthorBtn ( this, CUI_RES( BTN_AUTHOR ) ), 80*cdf0e10cSrcweir aOKBtn ( this, CUI_RES( BTN_POST_OK ) ), 81*cdf0e10cSrcweir aCancelBtn ( this, CUI_RES( BTN_POST_CANCEL ) ), 82*cdf0e10cSrcweir aHelpBtn ( this, CUI_RES( BTN_POST_HELP ) ), 83*cdf0e10cSrcweir aPrevBtn ( this, CUI_RES( BTN_PREV ) ), 84*cdf0e10cSrcweir aNextBtn ( this, CUI_RES( BTN_NEXT ) ), 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir rSet ( rCoreSet ), 87*cdf0e10cSrcweir pOutSet ( 0 ) 88*cdf0e10cSrcweir 89*cdf0e10cSrcweir { 90*cdf0e10cSrcweir if (bRedline) // HelpIDs fuer Redlining 91*cdf0e10cSrcweir { 92*cdf0e10cSrcweir SetHelpId(HID_REDLINING_DLG); 93*cdf0e10cSrcweir aEditED.SetHelpId(HID_REDLINING_EDIT); 94*cdf0e10cSrcweir aPrevBtn.SetHelpId(HID_REDLINING_PREV); 95*cdf0e10cSrcweir aNextBtn.SetHelpId(HID_REDLINING_NEXT); 96*cdf0e10cSrcweir } 97*cdf0e10cSrcweir 98*cdf0e10cSrcweir aPrevBtn.SetClickHdl( LINK( this, SvxPostItDialog, PrevHdl ) ); 99*cdf0e10cSrcweir aNextBtn.SetClickHdl( LINK( this, SvxPostItDialog, NextHdl ) ); 100*cdf0e10cSrcweir aAuthorBtn.SetClickHdl( LINK( this, SvxPostItDialog, Stamp ) ); 101*cdf0e10cSrcweir aOKBtn.SetClickHdl( LINK( this, SvxPostItDialog, OKHdl ) ); 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir Font aFont( aEditED.GetFont() ); 104*cdf0e10cSrcweir aFont.SetWeight( WEIGHT_LIGHT ); 105*cdf0e10cSrcweir aEditED.SetFont( aFont ); 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir sal_Bool bNew = sal_True; 108*cdf0e10cSrcweir sal_uInt16 nWhich = 0; 109*cdf0e10cSrcweir 110*cdf0e10cSrcweir if ( !bPrevNext ) 111*cdf0e10cSrcweir { 112*cdf0e10cSrcweir aPrevBtn.Hide(); 113*cdf0e10cSrcweir aNextBtn.Hide(); 114*cdf0e10cSrcweir } 115*cdf0e10cSrcweir 116*cdf0e10cSrcweir nWhich = rSet.GetPool()->GetWhich( SID_ATTR_POSTIT_AUTHOR ); 117*cdf0e10cSrcweir String aAuthorStr, aDateStr, aTextStr; 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir if ( rSet.GetItemState( nWhich, sal_True ) >= SFX_ITEM_AVAILABLE ) 120*cdf0e10cSrcweir { 121*cdf0e10cSrcweir bNew = sal_False; 122*cdf0e10cSrcweir const SvxPostItAuthorItem& rAuthor = 123*cdf0e10cSrcweir (const SvxPostItAuthorItem&)rSet.Get( nWhich ); 124*cdf0e10cSrcweir aAuthorStr = rAuthor.GetValue(); 125*cdf0e10cSrcweir } 126*cdf0e10cSrcweir else 127*cdf0e10cSrcweir aAuthorStr = SvtUserOptions().GetID(); 128*cdf0e10cSrcweir 129*cdf0e10cSrcweir nWhich = rSet.GetPool()->GetWhich( SID_ATTR_POSTIT_DATE ); 130*cdf0e10cSrcweir 131*cdf0e10cSrcweir if ( rSet.GetItemState( nWhich, sal_True ) >= SFX_ITEM_AVAILABLE ) 132*cdf0e10cSrcweir { 133*cdf0e10cSrcweir const SvxPostItDateItem& rDate = 134*cdf0e10cSrcweir (const SvxPostItDateItem&)rSet.Get( nWhich ); 135*cdf0e10cSrcweir aDateStr = rDate.GetValue(); 136*cdf0e10cSrcweir } 137*cdf0e10cSrcweir else 138*cdf0e10cSrcweir { 139*cdf0e10cSrcweir LocaleDataWrapper aLocaleWrapper( ::comphelper::getProcessServiceFactory(), Application::GetSettings().GetLocale() ); 140*cdf0e10cSrcweir aDateStr = aLocaleWrapper.getDate( Date() ); 141*cdf0e10cSrcweir } 142*cdf0e10cSrcweir 143*cdf0e10cSrcweir nWhich = rSet.GetPool()->GetWhich( SID_ATTR_POSTIT_TEXT ); 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir if ( rSet.GetItemState( nWhich, sal_True ) >= SFX_ITEM_AVAILABLE ) 146*cdf0e10cSrcweir { 147*cdf0e10cSrcweir const SvxPostItTextItem& rText = 148*cdf0e10cSrcweir (const SvxPostItTextItem&)rSet.Get( nWhich ); 149*cdf0e10cSrcweir aTextStr = rText.GetValue(); 150*cdf0e10cSrcweir } 151*cdf0e10cSrcweir 152*cdf0e10cSrcweir ShowLastAuthor(aAuthorStr, aDateStr); 153*cdf0e10cSrcweir aEditED.SetText( aTextStr.ConvertLineEnd() ); 154*cdf0e10cSrcweir 155*cdf0e10cSrcweir if ( !bNew ) 156*cdf0e10cSrcweir SetText( CUI_RESSTR( STR_NOTIZ_EDIT ) ); 157*cdf0e10cSrcweir else 158*cdf0e10cSrcweir // neu anlegen 159*cdf0e10cSrcweir SetText( CUI_RESSTR( STR_NOTIZ_INSERT ) ); 160*cdf0e10cSrcweir 161*cdf0e10cSrcweir FreeResource(); 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir aEditED.SetAccessibleRelationLabeledBy(&aEditFT); 164*cdf0e10cSrcweir aEditED.SetAccessibleRelationMemberOf(&aPostItFL); 165*cdf0e10cSrcweir aAuthorBtn.SetAccessibleRelationMemberOf(&aPostItFL); 166*cdf0e10cSrcweir } 167*cdf0e10cSrcweir 168*cdf0e10cSrcweir // ----------------------------------------------------------------------- 169*cdf0e10cSrcweir 170*cdf0e10cSrcweir SvxPostItDialog::~SvxPostItDialog() 171*cdf0e10cSrcweir { 172*cdf0e10cSrcweir delete pOutSet; 173*cdf0e10cSrcweir pOutSet = 0; 174*cdf0e10cSrcweir } 175*cdf0e10cSrcweir 176*cdf0e10cSrcweir // ----------------------------------------------------------------------- 177*cdf0e10cSrcweir 178*cdf0e10cSrcweir void SvxPostItDialog::ShowLastAuthor(const String& rAuthor, const String& rDate) 179*cdf0e10cSrcweir { 180*cdf0e10cSrcweir String sTxt( rAuthor ); 181*cdf0e10cSrcweir sTxt.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ", " ) ); 182*cdf0e10cSrcweir sTxt += rDate; 183*cdf0e10cSrcweir aLastEditFT.SetText( sTxt ); 184*cdf0e10cSrcweir } 185*cdf0e10cSrcweir 186*cdf0e10cSrcweir // ----------------------------------------------------------------------- 187*cdf0e10cSrcweir 188*cdf0e10cSrcweir sal_uInt16* SvxPostItDialog::GetRanges() 189*cdf0e10cSrcweir { 190*cdf0e10cSrcweir return pRanges; 191*cdf0e10cSrcweir } 192*cdf0e10cSrcweir 193*cdf0e10cSrcweir // ----------------------------------------------------------------------- 194*cdf0e10cSrcweir 195*cdf0e10cSrcweir void SvxPostItDialog::EnableTravel(sal_Bool bNext, sal_Bool bPrev) 196*cdf0e10cSrcweir { 197*cdf0e10cSrcweir aPrevBtn.Enable(bPrev); 198*cdf0e10cSrcweir aNextBtn.Enable(bNext); 199*cdf0e10cSrcweir } 200*cdf0e10cSrcweir 201*cdf0e10cSrcweir // ----------------------------------------------------------------------- 202*cdf0e10cSrcweir 203*cdf0e10cSrcweir IMPL_LINK_INLINE_START( SvxPostItDialog, PrevHdl, Button *, EMPTYARG ) 204*cdf0e10cSrcweir { 205*cdf0e10cSrcweir aPrevHdlLink.Call( this ); 206*cdf0e10cSrcweir return 0; 207*cdf0e10cSrcweir } 208*cdf0e10cSrcweir IMPL_LINK_INLINE_END( SvxPostItDialog, PrevHdl, Button *, EMPTYARG ) 209*cdf0e10cSrcweir 210*cdf0e10cSrcweir // ----------------------------------------------------------------------- 211*cdf0e10cSrcweir 212*cdf0e10cSrcweir IMPL_LINK_INLINE_START( SvxPostItDialog, NextHdl, Button *, EMPTYARG ) 213*cdf0e10cSrcweir { 214*cdf0e10cSrcweir aNextHdlLink.Call( this ); 215*cdf0e10cSrcweir return 0; 216*cdf0e10cSrcweir } 217*cdf0e10cSrcweir IMPL_LINK_INLINE_END( SvxPostItDialog, NextHdl, Button *, EMPTYARG ) 218*cdf0e10cSrcweir 219*cdf0e10cSrcweir // ----------------------------------------------------------------------- 220*cdf0e10cSrcweir 221*cdf0e10cSrcweir IMPL_LINK( SvxPostItDialog, Stamp, Button *, EMPTYARG ) 222*cdf0e10cSrcweir { 223*cdf0e10cSrcweir Date aDate; 224*cdf0e10cSrcweir Time aTime; 225*cdf0e10cSrcweir String aTmp( SvtUserOptions().GetID() ); 226*cdf0e10cSrcweir LocaleDataWrapper aLocaleWrapper( ::comphelper::getProcessServiceFactory(), Application::GetSettings().GetLocale() ); 227*cdf0e10cSrcweir String aStr( aEditED.GetText() ); 228*cdf0e10cSrcweir aStr.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "\n---- " ) ); 229*cdf0e10cSrcweir 230*cdf0e10cSrcweir if ( aTmp.Len() > 0 ) 231*cdf0e10cSrcweir { 232*cdf0e10cSrcweir aStr += aTmp; 233*cdf0e10cSrcweir aStr.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ", " ) ); 234*cdf0e10cSrcweir } 235*cdf0e10cSrcweir aStr += aLocaleWrapper.getDate(aDate); 236*cdf0e10cSrcweir aStr.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ", " ) ); 237*cdf0e10cSrcweir aStr += aLocaleWrapper.getTime(aTime, sal_False, sal_False); 238*cdf0e10cSrcweir aStr.AppendAscii( RTL_CONSTASCII_STRINGPARAM( " ----\n" ) ); 239*cdf0e10cSrcweir 240*cdf0e10cSrcweir 241*cdf0e10cSrcweir aEditED.SetText( aStr.ConvertLineEnd() ); 242*cdf0e10cSrcweir xub_StrLen nLen = aStr.Len(); 243*cdf0e10cSrcweir aEditED.GrabFocus(); 244*cdf0e10cSrcweir aEditED.SetSelection( Selection( nLen, nLen ) ); 245*cdf0e10cSrcweir return 0; 246*cdf0e10cSrcweir } 247*cdf0e10cSrcweir 248*cdf0e10cSrcweir // ----------------------------------------------------------------------- 249*cdf0e10cSrcweir 250*cdf0e10cSrcweir IMPL_LINK( SvxPostItDialog, OKHdl, Button *, EMPTYARG ) 251*cdf0e10cSrcweir { 252*cdf0e10cSrcweir LocaleDataWrapper aLocaleWrapper( ::comphelper::getProcessServiceFactory(), Application::GetSettings().GetLocale() ); 253*cdf0e10cSrcweir pOutSet = new SfxItemSet( rSet ); 254*cdf0e10cSrcweir pOutSet->Put( SvxPostItAuthorItem( SvtUserOptions().GetID(), 255*cdf0e10cSrcweir rSet.GetPool()->GetWhich( SID_ATTR_POSTIT_AUTHOR ) ) ); 256*cdf0e10cSrcweir pOutSet->Put( SvxPostItDateItem( aLocaleWrapper.getDate( Date() ), 257*cdf0e10cSrcweir rSet.GetPool()->GetWhich( SID_ATTR_POSTIT_DATE ) ) ); 258*cdf0e10cSrcweir pOutSet->Put( SvxPostItTextItem( aEditED.GetText(), 259*cdf0e10cSrcweir rSet.GetPool()->GetWhich( SID_ATTR_POSTIT_TEXT ) ) ); 260*cdf0e10cSrcweir EndDialog( RET_OK ); 261*cdf0e10cSrcweir return 0; 262*cdf0e10cSrcweir } 263*cdf0e10cSrcweir 264