merge the formfield patch from ooo-build
[ooovba.git] / svtools / source / dialogs / property.cxx
blobc8d049163e0870d1bb7b7ac7fc71fff54453c666
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: property.cxx,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svtools.hxx"
35 #ifndef GCC
36 #endif
38 //------------------------------------------------------------------
40 //#include "Svitems.hxx"
42 #include "property.hxx"
44 #include "property.hrc"
45 #include "Scresid.hxx"
47 #define FRAME_OFFSET 4
50 SvXPropertyControl::SvXPropertyControl( Window* pParent, WinBits nWinStyle)
51 : Control(pParent,nWinStyle)
55 SvXPropertyControl::SvXPropertyControl( Window* pParent, const ResId& rResId )
56 : Control(pParent,rResId )
60 //------------------------------------------------------------------
62 SvXPropertyEdit::SvXPropertyEdit( Window* pParent, WinBits nWinStyle)
63 : SvXPropertyControl(pParent,nWinStyle),
64 aEdit(this,WB_BORDER | WB_TABSTOP)
66 pListener=NULL;
67 aEdit.SetModifyHdl(
68 LINK( this, SvXPropertyEdit, ModifiedHdl ));
69 aEdit.SetGetFocusHdl(
70 LINK( this, SvXPropertyEdit, GetFocusHdl));
71 aEdit.SetLoseFocusHdl(
72 LINK( this, SvXPropertyEdit, LoseFocusHdl));
74 aEdit.Show();
77 SvXPropertyEdit::SvXPropertyEdit( Window* pParent, const ResId& rResId)
78 : SvXPropertyControl(pParent,rResId),
79 aEdit(this,WB_BORDER | WB_TABSTOP)
81 pListener=NULL;
82 aEdit.SetModifyHdl(
83 LINK( this, SvXPropertyEdit, ModifiedHdl ));
84 aEdit.SetGetFocusHdl(
85 LINK( this, SvXPropertyEdit, GetFocusHdl));
86 aEdit.SetLoseFocusHdl(
87 LINK( this, SvXPropertyEdit, LoseFocusHdl));
89 Size aSize=GetSizePixel();
90 SetCtrSize(aSize);
91 aEdit.Show();
94 void SvXPropertyEdit::SetSvXPropertyCtrListener(SvXPropertyCtrListener* pCtrListener)
96 pListener=pCtrListener;
99 SvXPropertyCtrListener* SvXPropertyEdit::GetSvXPropertyCtrListener()
101 return pListener;
105 void SvXPropertyEdit::SetCtrSize(const Size& rSize)
107 SetSizePixel(rSize);
108 Size aSize=GetOutputSizePixel();
109 Point aPos(0,0);
110 aEdit.SetPosPixel(aPos);
111 aEdit.SetSizePixel(aSize);
114 void SvXPropertyEdit::SetLocked(BOOL bLocked)
116 if(bLocked)
117 Disable();
118 else
119 Enable();
122 void SvXPropertyEdit::SetProperty(const String &rString)
124 aEdit.SetText(rString);
127 String SvXPropertyEdit::GetProperty() const
129 return aEdit.GetText();
132 BOOL SvXPropertyEdit::HasList()
134 return FALSE;
138 void SvXPropertyEdit::ClearList()
140 return;
142 void SvXPropertyEdit::InsertEntry( const String&,USHORT )
144 return;
147 void SvXPropertyEdit::SetMyName(const String &rString)
149 aName=rString;
152 String SvXPropertyEdit::GetMyName()const
154 return aName;
157 void SvXPropertyEdit::SetMyData(void* pDat)
159 pData=pDat;
162 void* SvXPropertyEdit::GetMyData()
164 return pData;
168 IMPL_LINK( SvXPropertyEdit, ModifiedHdl, Edit*, EMPTYARG )
170 if(pListener!=NULL)
171 pListener->Modified(this);
172 return 0;
175 IMPL_LINK( SvXPropertyEdit, GetFocusHdl, Edit*, EMPTYARG )
177 if(pListener!=NULL)
178 pListener->GetFocus(this);
179 return 0;
182 IMPL_LINK( SvXPropertyEdit, LoseFocusHdl, Edit*, EMPTYARG )
184 if(pListener!=NULL)
185 pListener->LoseFocus(this);
186 return 0;
189 //------------------------------------------------------------------
191 SvXPropertyListBox::SvXPropertyListBox( Window* pParent, WinBits nWinStyle)
192 : SvXPropertyControl(pParent,nWinStyle),
193 aListBox(this,WB_BORDER | WB_DROPDOWN | WB_TABSTOP)
195 pListener=NULL;
196 aListBox.SetSelectHdl(
197 LINK( this, SvXPropertyListBox, ModifiedHdl ));
198 aListBox.SetGetFocusHdl(
199 LINK( this, SvXPropertyListBox, GetFocusHdl));
200 aListBox.SetLoseFocusHdl(
201 LINK( this, SvXPropertyListBox, LoseFocusHdl));
202 aListBox.Show();
205 SvXPropertyListBox::SvXPropertyListBox( Window* pParent, const ResId& rResId)
206 : SvXPropertyControl(pParent,rResId),
207 aListBox(this,WB_BORDER | WB_DROPDOWN | WB_TABSTOP)
209 pListener=NULL;
210 aListBox.SetSelectHdl(
211 LINK( this, SvXPropertyListBox, ModifiedHdl ));
212 aListBox.SetGetFocusHdl(
213 LINK( this, SvXPropertyListBox, GetFocusHdl));
214 aListBox.SetLoseFocusHdl(
215 LINK( this, SvXPropertyListBox, LoseFocusHdl));
217 Size aSize=GetSizePixel();
218 SetCtrSize(aSize);
219 aListBox.Show();
222 void SvXPropertyListBox::SetSvXPropertyCtrListener(SvXPropertyCtrListener* pCtrListener)
224 pListener=pCtrListener;
227 SvXPropertyCtrListener* SvXPropertyListBox::GetSvXPropertyCtrListener()
229 return pListener;
233 void SvXPropertyListBox::SetCtrSize(const Size& rSize)
235 SetSizePixel(rSize);
236 Size aSize=GetOutputSizePixel();
237 Point aPos(0,0);
238 aListBox.SetPosPixel(aPos);
239 aListBox.SetSizePixel(aSize);
242 void SvXPropertyListBox::SetLocked(BOOL bLocked)
244 if(bLocked)
245 Disable();
246 else
247 Enable();
250 void SvXPropertyListBox::SetProperty(const String &rString)
252 aListBox.SelectEntry(rString);
255 String SvXPropertyListBox::GetProperty()const
257 return aListBox.GetSelectEntry();
260 BOOL SvXPropertyListBox::HasList()
262 return TRUE;
266 void SvXPropertyListBox::ClearList()
268 aListBox.Clear();
271 void SvXPropertyListBox::InsertEntry( const String& rString,USHORT nPos)
273 aListBox.InsertEntry(rString,nPos);
276 void SvXPropertyListBox::SetMyName(const String &rString)
278 aName=rString;
281 String SvXPropertyListBox::GetMyName()const
283 return aName;
286 void SvXPropertyListBox::SetMyData(void* pDat)
288 pData=pDat;
291 void* SvXPropertyListBox::GetMyData()
293 return pData;
296 IMPL_LINK( SvXPropertyListBox, ModifiedHdl, ListBox*, EMPTYARG )
298 if(pListener!=NULL)
299 pListener->Modified(this);
300 return 0;
303 IMPL_LINK( SvXPropertyListBox, GetFocusHdl, ListBox*, EMPTYARG )
305 if(pListener!=NULL)
306 pListener->GetFocus(this);
307 return 0;
310 IMPL_LINK( SvXPropertyListBox, LoseFocusHdl, ListBox*, EMPTYARG )
312 if(pListener!=NULL)
313 pListener->LoseFocus(this);
314 return 0;
317 //------------------------------------------------------------------
320 SvXPropertyComboBox::SvXPropertyComboBox( Window* pParent, WinBits nWinStyle)
321 : SvXPropertyControl(pParent,nWinStyle),
322 aComboBox(this,WB_BORDER | WB_DROPDOWN | WB_TABSTOP)
324 pListener=NULL;
325 aComboBox.SetModifyHdl(
326 LINK( this, SvXPropertyComboBox, ModifiedHdl ));
327 aComboBox.SetGetFocusHdl(
328 LINK( this, SvXPropertyComboBox, GetFocusHdl));
329 aComboBox.SetLoseFocusHdl(
330 LINK( this, SvXPropertyComboBox, LoseFocusHdl));
331 aComboBox.Show();
334 SvXPropertyComboBox::SvXPropertyComboBox( Window* pParent, const ResId& rResId)
335 : SvXPropertyControl(pParent,rResId),
336 aComboBox(this,WB_BORDER | WB_DROPDOWN | WB_TABSTOP)
338 pListener=NULL;
339 aComboBox.SetModifyHdl(
340 LINK( this, SvXPropertyComboBox, ModifiedHdl ));
341 aComboBox.SetGetFocusHdl(
342 LINK( this, SvXPropertyComboBox, GetFocusHdl));
343 aComboBox.SetLoseFocusHdl(
344 LINK( this, SvXPropertyComboBox, LoseFocusHdl));
346 Size aSize=GetSizePixel();
347 SetCtrSize(aSize);
348 aComboBox.Show();
351 void SvXPropertyComboBox::SetLocked(BOOL bLocked)
353 if(bLocked)
354 Disable();
355 else
356 Enable();
359 void SvXPropertyComboBox::SetSvXPropertyCtrListener(SvXPropertyCtrListener* pCtrListener)
361 pListener=pCtrListener;
364 SvXPropertyCtrListener* SvXPropertyComboBox::GetSvXPropertyCtrListener()
366 return pListener;
370 void SvXPropertyComboBox::SetCtrSize(const Size& rSize)
372 SetSizePixel(rSize);
373 Size aSize=GetOutputSizePixel();
374 Point aPos(0,0);
375 aComboBox.SetPosPixel(aPos);
376 aComboBox.SetSizePixel(aSize);
380 void SvXPropertyComboBox::SetProperty(const String &rString)
382 aComboBox.SetText(rString);
385 String SvXPropertyComboBox::GetProperty() const
387 return aComboBox.GetText();
390 BOOL SvXPropertyComboBox::HasList()
392 return TRUE;
395 void SvXPropertyComboBox::ClearList()
397 aComboBox.Clear();
400 void SvXPropertyComboBox::InsertEntry( const String& rString,USHORT nPos)
402 aComboBox.InsertEntry(rString,nPos);
405 void SvXPropertyComboBox::SetMyName(const String &rString)
407 aName=rString;
410 String SvXPropertyComboBox::GetMyName()const
412 return aName;
415 void SvXPropertyComboBox::SetMyData(void* pDat)
417 pData=pDat;
420 void* SvXPropertyComboBox::GetMyData()
422 return pData;
425 IMPL_LINK( SvXPropertyComboBox, ModifiedHdl, ComboBox*, EMPTYARG )
427 if(pListener!=NULL)
428 pListener->Modified(this);
429 return 0;
432 IMPL_LINK( SvXPropertyComboBox, GetFocusHdl, ComboBox*, EMPTYARG )
434 if(pListener!=NULL)
435 pListener->GetFocus(this);
436 return 0;
439 IMPL_LINK( SvXPropertyComboBox, LoseFocusHdl, ComboBox*, EMPTYARG )
441 if(pListener!=NULL)
442 pListener->LoseFocus(this);
443 return 0;
445 //------------------------------------------------------------------
447 SvPropertyLine::SvPropertyLine( Window* pParent,WinBits nWinStyle)
448 : Control(pParent,nWinStyle),
449 aName(this,WB_BORDER),
450 pSvXPropertyControl(NULL),
451 aXButton(this,WB_BORDER),
452 bIsLocked(FALSE),
453 bIsHyperlink(FALSE)
455 bNeedsRepaint = TRUE;
456 bHasXButton = FALSE;
457 aXButton.SetText( XubString( RTL_CONSTASCII_USTRINGPARAM( "..." ) ) );
458 aName.Show();
459 aXButton.Show();
460 eKindOfCtr = KOC_UNDEFINED;
461 Wallpaper aWall = GetBackground();
462 aWall.SetColor( Color( COL_TRANSPARENT ) );
463 SetBackground( aWall );
466 SvPropertyLine::SvPropertyLine( Window* pParent,const ResId& rResId )
467 : Control(pParent,rResId),
468 aName (this,WB_BORDER),
469 pSvXPropertyControl(NULL),
470 aXButton (this,WB_BORDER),
471 bIsLocked(FALSE),
472 bIsHyperlink(FALSE)
474 bNeedsRepaint = TRUE;
475 bHasXButton = FALSE;
476 eKindOfCtr = KOC_UNDEFINED;
477 aXButton.SetText( XubString( RTL_CONSTASCII_USTRINGPARAM( "..." ) ) );
478 aName.Show();
479 aXButton.Show();
480 Wallpaper aWall = GetBackground();
481 aWall.SetColor( Color( COL_TRANSPARENT ) );
482 SetBackground( aWall );
483 Resize();
486 void SvPropertyLine::SetSvXPropertyControl(SvXPropertyControl* pXControl)
488 pSvXPropertyControl=pXControl;
489 pSvXPropertyControl->Show();
490 Resize();
493 SvXPropertyControl* SvPropertyLine::GetSvXPropertyControl()
495 return pSvXPropertyControl;
498 void SvPropertyLine::Resize()
500 Size aSize=GetOutputSizePixel();
501 Size a2Size=aSize;
503 aSize.Width()=nNameWidth;
504 a2Size.Width()-=nNameWidth;
506 Point aPos(0,0);
507 aName.SetPosPixel(aPos);
508 aName.SetSizePixel(aSize);
510 USHORT nXButtonWidth=0;
512 if(bHasXButton)
514 nXButtonWidth=(USHORT)aSize.Height();
516 a2Size.Width()=a2Size.Width()-nXButtonWidth;
518 aPos.X()+=aSize.Width();
520 if(pSvXPropertyControl!=NULL)
522 pSvXPropertyControl->SetPosPixel(aPos);
523 pSvXPropertyControl->SetCtrSize(a2Size);
526 if(bHasXButton)
528 aPos.X()=GetOutputSizePixel().Width()
529 -nXButtonWidth;
530 aSize.Width()=nXButtonWidth;
531 aXButton .SetSizePixel(aSize);
532 aXButton .SetPosPixel(aPos);
536 void SvPropertyLine::SetNeedsRepaint(BOOL bFlag)
538 bNeedsRepaint=bFlag;
541 BOOL SvPropertyLine::NeedsRepaint()
543 return bNeedsRepaint;
546 void SvPropertyLine::SetName(const String& rString )
548 aName.SetText(rString);
549 aName.Invalidate();
552 String SvPropertyLine::GetName() const
554 return aName.GetText();
557 void SvPropertyLine::SetKindOfControl(eKindOfControl eKOC)
559 eKindOfCtr=eKOC;
562 eKindOfControl SvPropertyLine::GetKindOfControl()
564 return eKindOfCtr;
567 void SvPropertyLine::ShowXButton()
569 bHasXButton=TRUE;
570 aXButton.Show();
571 Resize();
573 void SvPropertyLine::HideXButton()
575 bHasXButton=FALSE;
576 aXButton.Hide();
577 Resize();
579 BOOL SvPropertyLine::IsVisibleXButton()
581 return bHasXButton;
584 void SvPropertyLine::ShowAsHyperLink(BOOL nFlag)
586 bIsHyperlink=nFlag;
587 if(nFlag)
589 Font aFont=GetFont();
590 aFont.SetUnderline(UNDERLINE_SINGLE);
591 aFont.SetColor(Color(COL_BLUE));
592 aName.SetFont(aFont);
594 else
596 Font aFont=GetFont();
597 aName.SetFont(aFont);
601 BOOL SvPropertyLine::IsShownAsHyperlink()
603 return bIsHyperlink;
606 void SvPropertyLine::Locked(BOOL nFlag)
608 bIsLocked=nFlag;
609 if(pSvXPropertyControl!=NULL)
610 pSvXPropertyControl->SetLocked(nFlag);
613 BOOL SvPropertyLine::IsLineLocked()
615 return bIsLocked;
618 void SvPropertyLine::SetNameWidth(USHORT nWidth)
620 nNameWidth=nWidth;
621 Resize();
624 void SvPropertyLine::SetClickHdl(const Link& rLink)
626 aXButton.SetClickHdl(rLink );
629 //----------------------------------------------------------
631 SvXPropEvListener::SvXPropEvListener()
633 pTheActiveControl=NULL;
636 SvXPropEvListener::~SvXPropEvListener()
640 void SvXPropEvListener::Modified (SvXPropertyControl *pSvXPCtr)
642 pTheActiveControl=pSvXPCtr;
643 aModifyLink.Call(this);
646 void SvXPropEvListener::GetFocus (SvXPropertyControl *pSvXPCtr)
648 pTheActiveControl=pSvXPCtr;
649 aGetFocusLink.Call(this);
652 void SvXPropEvListener::LoseFocus (SvXPropertyControl *pSvXPCtr)
654 pTheActiveControl=pSvXPCtr;
655 aLoseFocusLink.Call(this);
658 void SvXPropEvListener::KeyInput (SvXPropertyControl *pSvXPCtr,const KeyCode& theKeyCode)
660 pTheActiveControl=pSvXPCtr;
661 aKeyCode=theKeyCode;
662 aKeyInputLink.Call(this);
665 SvXPropertyControl * SvXPropEvListener::GetPropertyControl()
667 return pTheActiveControl;
670 KeyCode SvXPropEvListener::GetKeyCode() const
672 return aKeyCode;
675 //------------------------------------------------------------------
677 SvListBoxForProperties::SvListBoxForProperties( Window* pParent, WinBits nWinStyle)
678 : Control(pParent,nWinStyle),
679 aPlayGround(this,WB_DIALOGCONTROL),
680 aVScroll(this,WB_VSCROLL|WB_REPEAT|WB_DRAG),
681 pPropDataControl(NULL)
684 aListener.SetModifyHdl (LINK( this, SvListBoxForProperties, ModifyHdl));
685 aListener.SetGetFocusHdl (LINK( this, SvListBoxForProperties, GetFocusHdl));
686 aListener.SetLoseFocusHdl(LINK( this, SvListBoxForProperties,LoseFocusHdl));
687 aListener.SetKeyInputHdl (LINK( this, SvListBoxForProperties, KeyInputHdl));
689 nYOffset=0;
690 nTheNameSize=0;
691 ListBox aListBox(this,WB_DROPDOWN);
692 aListBox.SetPosSizePixel(Point(0,0),Size(100,100));
693 nRowHeight=(USHORT)aListBox.GetSizePixel().Height();
694 Wallpaper aWall = aPlayGround.GetBackground();
695 aWall.SetColor( Color( COL_TRANSPARENT ) );
696 aPlayGround.SetBackground( aWall );
697 aPlayGround.Show();
698 aVScroll.Hide();
699 aVScroll.SetScrollHdl(
700 LINK( this, SvListBoxForProperties, ScrollHdl ));
705 SvListBoxForProperties::SvListBoxForProperties( Window* pParent, const ResId& rResId )
706 : Control(pParent,rResId),
707 aPlayGround(this,0),
708 aVScroll(this,WB_VSCROLL|WB_REPEAT|WB_DRAG),
709 pPropDataControl(NULL)
711 nTheNameSize=0;
712 nYOffset=0;
713 ListBox aListBox(this,WB_DROPDOWN);
714 aListBox.SetPosSizePixel(Point(0,0),Size(100,100));
715 nRowHeight=(USHORT)aListBox.GetSizePixel().Height();
716 Wallpaper aWall = aPlayGround.GetBackground();
717 aWall.SetColor( Color( COL_TRANSPARENT ) );
718 aPlayGround.SetBackground( aWall );
719 aPlayGround.Show();
720 aVScroll.Hide();
721 aVScroll.SetScrollHdl( LINK( this, SvListBoxForProperties, ScrollHdl ) );
722 UpdateVScroll();
723 Resize();
726 SvListBoxForProperties::~SvListBoxForProperties()
728 Clear();
731 void SvListBoxForProperties::Clear()
733 for(USHORT i=0;i<PLineArray.Count();i++)
735 SvPropertyLine* pPropLine=PLineArray[i];
737 switch(pPropLine->GetKindOfControl())
739 case KOC_LISTBOX:
740 case KOC_COMBOBOX:
741 case KOC_EDIT: delete pPropLine->GetSvXPropertyControl();
742 break;
743 default:
744 break;
746 delete pPropLine;
748 PLineArray.Remove(0,PLineArray.Count());
752 void SvListBoxForProperties::Resize()
754 Size aSize=GetOutputSizePixel();
755 Size a2Size=aSize;
756 Size aVScrollSize;
758 if(aVScroll.IsVisible())
760 Point aPos(0,0);
761 aVScrollSize=aVScroll.GetSizePixel();
762 aVScrollSize.Height()=aSize.Height();
763 a2Size.Width()-=aVScrollSize.Width();
764 aPos.X()=a2Size.Width();
765 aVScroll.SetPosPixel(aPos);
766 aVScroll.SetSizePixel(aVScrollSize);
769 aPlayGround.SetPosPixel(Point(0,0));
770 aPlayGround.SetSizePixel(a2Size);
771 UpdatePosNSize();
774 void SvListBoxForProperties::SetController( SvPropertyDataControl *pPDC)
776 pPropDataControl=pPDC;
779 USHORT SvListBoxForProperties::CalcVisibleLines()
781 Size aSize=aPlayGround.GetOutputSizePixel();
782 USHORT nResult=0;
783 if(nRowHeight!=0)
784 nResult=(USHORT) aSize.Height()/nRowHeight;
786 return nResult;
789 void SvListBoxForProperties::UpdateVScroll()
791 USHORT nLines=CalcVisibleLines();
792 aVScroll.SetPageSize(nLines-1);
793 aVScroll.SetVisibleSize(nLines-1);
794 aVScroll.SetRange(Range(0,PLineArray.Count()-1));
795 if(PLineArray.Count()<=nLines)
797 aVScroll.Hide();
799 else
801 BOOL bFlag=aVScroll.IsVisible();
802 aVScroll.Show();
803 if(!bFlag)Resize();
809 void SvListBoxForProperties::UpdatePosNSize()
811 Point aPos(0,nYOffset);
813 for(USHORT i=0; i<PLineArray.Count();i++)
815 if((PLineArray[i])->NeedsRepaint())
817 (PLineArray[i])->SetPosPixel(aPos);
818 Size aSize=aPlayGround.GetOutputSizePixel();
819 aSize.Height()=nRowHeight;
820 (PLineArray[i])->SetSizePixel(aSize);
821 (PLineArray[i])->SetNameWidth(nTheNameSize+2*FRAME_OFFSET);
822 (PLineArray[i])->Invalidate();
823 (PLineArray[i])->Update();
824 (PLineArray[i])->Show();
825 (PLineArray[i])->SetNeedsRepaint(FALSE);
827 else
829 if((PLineArray[i])->IsVisible())
831 Size aSize=aPlayGround.GetOutputSizePixel();
832 aSize.Height()=nRowHeight;
833 (PLineArray[i])->SetSizePixel(aSize);
834 (PLineArray[i])->SetNameWidth(nTheNameSize+2*FRAME_OFFSET);
835 (PLineArray[i])->Invalidate();
839 aPos.Y()+=nRowHeight;
841 aPlayGround.Invalidate();
842 aPlayGround.Update();
845 void SvListBoxForProperties::UpdatePlayGround()
847 Point aPos(0,0);
848 long nThumbPos=aVScroll.GetThumbPos();
849 long nLines=aVScroll.GetPageSize();
850 long nDelta=aVScroll.GetDelta();
852 USHORT nStart,nEnd;
853 Size aSize=aPlayGround.GetOutputSizePixel();
854 Point aPEnd;
855 aPEnd.X()=aSize.Width();
857 if(nDelta>0)
859 nStart=(USHORT)(nThumbPos+nLines+1-nDelta);
860 nEnd=(USHORT)(nThumbPos+nLines);
861 aPos.Y()=(nLines+1-nDelta)*nRowHeight;
863 else
865 nStart=(USHORT)nThumbPos;
866 nEnd=(USHORT)(nThumbPos-nDelta);
867 aPEnd.Y()=(nThumbPos-nDelta)*nRowHeight;;
870 aSize.Height()=nRowHeight;
872 nDelta=-nDelta*nRowHeight;
874 aPlayGround.Scroll(0,nDelta,SCROLL_CHILDREN);
876 for(USHORT i=nStart; i<=nEnd;i++)
878 (PLineArray[i])->SetPosSizePixel(aPos,aSize);
879 (PLineArray[i])->SetNameWidth(nTheNameSize+2*FRAME_OFFSET);
880 (PLineArray[i])->Show();
881 aPos.Y()+=nRowHeight;
883 aPlayGround.Update();
886 void SvListBoxForProperties::UpdateAll()
888 UpdatePosNSize();
889 UpdatePlayGround();
890 //UpdateVScroll();
893 void SvListBoxForProperties::DisableUpdate()
895 bUpdate=FALSE;
898 void SvListBoxForProperties::EnableUpdate()
900 bUpdate=TRUE;
901 UpdateAll();
904 void SvListBoxForProperties::SetPropertyValue( const String & rEntryName, const String & rValue )
906 USHORT i, iEnd = PLineArray.Count();
907 for( i = 0 ; i < iEnd ; i++ )
909 SvPropertyLine* pPropLine = PLineArray[ i ];
910 SvXPropertyControl* pSvXPCtr=pPropLine->GetSvXPropertyControl();
911 if( pSvXPCtr && pSvXPCtr->GetMyName() == rEntryName )
913 pSvXPCtr->SetProperty( rValue );
918 USHORT SvListBoxForProperties::AppendEntry( const SvPropertyData& aPropData)
920 return InsertEntry(aPropData);
923 USHORT SvListBoxForProperties::InsertEntry( const SvPropertyData& aPropData, USHORT nPos)
925 USHORT nInsPos=nPos;
926 SvPropertyLine* pPropLine=new SvPropertyLine(&aPlayGround,WB_TABSTOP | WB_DIALOGCONTROL);
928 if(nPos==LISTBOX_APPEND)
930 nInsPos=PLineArray.Count();
931 PLineArray.Insert(pPropLine,nInsPos);
933 else
935 PLineArray.Insert(pPropLine,nPos);
937 pPropLine->SetNameWidth(nTheNameSize);
938 UpdateVScroll();
939 UpdatePosNSize();
940 ChangeEntry(aPropData,nInsPos);
941 return nInsPos;
944 void SvListBoxForProperties::ChangeEntry( const SvPropertyData& aPropData, USHORT nPos)
946 if(nPos<PLineArray.Count())
948 SvPropertyLine* pPropLine=PLineArray[nPos];
950 switch(pPropLine->GetKindOfControl())
952 case KOC_LISTBOX:
953 case KOC_COMBOBOX:
954 case KOC_EDIT: delete pPropLine->GetSvXPropertyControl();
955 break;
956 default:
957 break;
960 switch(aPropData.eKind)
962 case KOC_LISTBOX:
963 pPropLine->SetSvXPropertyControl(
964 new SvXPropertyComboBox(pPropLine,WB_TABSTOP));
965 pPropLine->SetKindOfControl(aPropData.eKind);
966 break;
967 case KOC_COMBOBOX:
968 pPropLine->SetSvXPropertyControl(
969 new SvXPropertyComboBox(pPropLine,WB_TABSTOP));
970 pPropLine->SetKindOfControl(aPropData.eKind);
971 break;
972 case KOC_EDIT:
973 pPropLine->SetSvXPropertyControl(
974 new SvXPropertyEdit(pPropLine,WB_TABSTOP));
975 pPropLine->SetKindOfControl(aPropData.eKind);
976 break;
977 case KOC_USERDEFINED:
978 pPropLine->SetSvXPropertyControl(aPropData.pControl);
979 aPropData.pControl->SetParent(pPropLine);
980 pPropLine->SetKindOfControl(aPropData.eKind);
981 break;
982 default:
983 pPropLine->SetSvXPropertyControl(NULL);
984 pPropLine->SetKindOfControl(KOC_UNDEFINED);
985 break;
988 SvXPropertyControl* pSvXPCtr=pPropLine->GetSvXPropertyControl();
990 if(pSvXPCtr!=NULL)
992 pSvXPCtr->SetSvXPropertyCtrListener(&aListener);
993 pSvXPCtr->SetProperty(aPropData.aValue);
994 pSvXPCtr->SetMyData(aPropData.pDataPtr);
995 pSvXPCtr->SetMyName(aPropData.aName);
997 if(pSvXPCtr->HasList())
999 for(USHORT i=0;i<aPropData.theValues.Count();i++)
1001 pSvXPCtr->InsertEntry(*(aPropData.theValues[i]));
1006 pPropLine->SetName(aPropData.aName);
1008 USHORT nTextWidth=(USHORT)aPlayGround.GetTextWidth(aPropData.aName);
1010 if ( nTheNameSize < nTextWidth )
1011 nTheNameSize = nTextWidth;
1013 if ( aPropData.bHasVisibleXButton )
1015 pPropLine->SetClickHdl(LINK( this, SvListBoxForProperties, ClickHdl ) );
1016 pPropLine->ShowXButton();
1018 else
1019 pPropLine->HideXButton();
1021 pPropLine->Locked(aPropData.bIsLocked);
1023 pPropLine->ShowAsHyperLink(aPropData.bIsHyperLink);
1024 pPropLine->SetData(aPropData.pDataPtr);
1028 USHORT SvListBoxForProperties::GetFirstVisibleEntry()
1030 return 0;
1032 void SvListBoxForProperties::SetFirstVisibleEntry(USHORT)
1034 return;
1037 void SvListBoxForProperties::SetSelectedEntry(USHORT)
1039 return;
1042 USHORT SvListBoxForProperties::GetSelectedEntry()
1044 return 0;
1047 IMPL_LINK( SvListBoxForProperties, ScrollHdl, ScrollBar*, pSB )
1049 if(pSB!=NULL)
1051 long nDelta=aVScroll.GetDelta();
1052 nYOffset=-aVScroll.GetThumbPos()*nRowHeight;
1053 //aPlayGround.SetUpdateMode(FALSE);
1055 long nThumbPos=aVScroll.GetThumbPos();
1056 long nLines=aVScroll.GetPageSize();
1058 UpdatePlayGround();
1060 for(long i=nThumbPos-nDelta; i<nThumbPos+nLines-nDelta;i++)
1062 if(i>=nThumbPos && i<=nThumbPos+nLines)
1064 (PLineArray[sal::static_int_cast< USHORT >(i)])->
1065 SetNeedsRepaint(TRUE);
1067 else
1069 (PLineArray[sal::static_int_cast< USHORT >(i)])->Hide();
1070 (PLineArray[sal::static_int_cast< USHORT >(i)])->
1071 SetNeedsRepaint(FALSE);
1075 return 0;
1078 IMPL_LINK( SvListBoxForProperties, ClickHdl, PushButton*,pPB)
1080 if(pPB!=NULL)
1082 SvPropertyLine *pPropLine=(SvPropertyLine *)pPB->GetParent();
1083 SvXPropertyControl* pSvXPCtr=pPropLine->GetSvXPropertyControl();
1084 pPropDataControl->Clicked(pSvXPCtr->GetMyName(),
1085 pSvXPCtr->GetProperty(),pSvXPCtr->GetMyData());
1087 return 0;
1090 IMPL_LINK( SvListBoxForProperties, ModifyHdl,SvXPropEvListener*, pSvXPEvL)
1092 if(pSvXPEvL!=NULL && pPropDataControl!=NULL)
1095 SvXPropertyControl* pSvXPCtr=aListener.GetPropertyControl();
1097 pPropDataControl->Modified(pSvXPCtr->GetMyName(),
1098 pSvXPCtr->GetProperty(),pSvXPCtr->GetMyData());
1101 return 0;
1104 IMPL_LINK( SvListBoxForProperties, GetFocusHdl,SvXPropEvListener*, pSvXPEvL)
1106 if(pSvXPEvL!=NULL && pPropDataControl!=NULL)
1108 SvXPropertyControl* pSvXPCtr=aListener.GetPropertyControl();
1110 pPropDataControl->Select(pSvXPCtr->GetMyName(),pSvXPCtr->GetMyData());
1112 return 0;
1115 IMPL_LINK( SvListBoxForProperties, LoseFocusHdl,SvXPropEvListener*, pSvXPEvL)
1117 if(pSvXPEvL!=NULL && pPropDataControl!=NULL)
1119 SvXPropertyControl* pSvXPCtr=aListener.GetPropertyControl();
1121 pPropDataControl->Commit(pSvXPCtr->GetMyName(),
1122 pSvXPCtr->GetProperty(),pSvXPCtr->GetMyData());
1125 pSvXPCtr->SetProperty(
1126 pPropDataControl->GetTheCorrectProperty());
1130 return 0;
1133 IMPL_LINK( SvListBoxForProperties, KeyInputHdl,SvXPropEvListener*, pSvXPEvL)
1135 // FIXME - This code does not make a lot of sense.
1136 if(pSvXPEvL!=NULL && pPropDataControl!=NULL)
1138 /*SvXPropertyControl* pSvXPCtr=*/aListener.GetPropertyControl();
1140 return 0;
1146 SvTabPageForProperties::SvTabPageForProperties(Window* pParent,WinBits nWinStyle)
1147 : TabPage(pParent,nWinStyle),
1148 aLbProp(this)
1150 aLbProp.Show();
1153 void SvTabPageForProperties::Resize()
1155 Point aPos(3,3);
1156 Size aSize=GetOutputSizePixel();
1157 aSize.Width()-=6;
1158 aSize.Height()-=6;
1160 aLbProp.SetPosSizePixel(aPos,aSize);
1163 SvListBoxForProperties* SvTabPageForProperties::GetTheListBox()
1165 return &aLbProp;
1169 SvPropertyBox::SvPropertyBox( Window* pParent, WinBits nWinStyle)
1170 : Control(pParent,nWinStyle),
1171 aTabControl(this)
1173 aTabControl.Show();
1176 SvPropertyBox::SvPropertyBox( Window* pParent, const ResId& rResId )
1177 : Control(pParent,rResId),
1178 aTabControl(this)
1180 aTabControl.Show();
1181 Resize();
1184 SvPropertyBox::~SvPropertyBox()
1186 ClearAll();
1190 void SvPropertyBox::ClearAll()
1192 USHORT nCount=aTabControl.GetPageCount();
1194 for(USHORT i=nCount;i>=1;i--)
1196 SvTabPageForProperties* pPage=(SvTabPageForProperties*)
1197 aTabControl.GetTabPage(i);
1198 aTabControl.RemovePage(i);
1199 delete pPage;
1204 void SvPropertyBox::Resize()
1206 Point aPos(3,3);
1207 Size aSize=GetOutputSizePixel();
1208 aSize.Width()-=6;
1209 aSize.Height()-=6;
1211 aTabControl.SetPosSizePixel(aPos,aSize);
1213 USHORT nCount=aTabControl.GetPageCount();
1215 aSize=aTabControl.GetTabPageSizePixel();
1216 for(USHORT i=1;i<=nCount;i++)
1218 SvTabPageForProperties* pPage=(SvTabPageForProperties*)
1219 aTabControl.GetTabPage(i);
1220 pPage->SetSizePixel(aSize);
1226 USHORT SvPropertyBox::AppendPage( const String & rText )
1228 USHORT nId=aTabControl.GetPageCount()+1;
1229 aTabControl.InsertPage( nId,rText);
1230 SvTabPageForProperties* pPage=new SvTabPageForProperties(&aTabControl);
1231 pPage->SetSizePixel(aTabControl.GetTabPageSizePixel());
1232 pPage->GetTheListBox()->SetController(pThePropDataCtr);
1233 aTabControl.SetTabPage( nId, pPage);
1234 aTabControl.SetCurPageId(nId);
1235 return nId;
1238 void SvPropertyBox::SetPage( USHORT nId)
1240 aTabControl.SetCurPageId(nId);
1243 USHORT SvPropertyBox::GetCurPage()
1245 return aTabControl.GetCurPageId();
1248 USHORT SvPropertyBox::CalcVisibleLines()
1250 SvTabPageForProperties* pPage=(SvTabPageForProperties*)
1251 aTabControl.GetTabPage(aTabControl.GetCurPageId());
1252 return pPage->GetTheListBox()->CalcVisibleLines();
1254 void SvPropertyBox::EnableUpdate()
1256 SvTabPageForProperties* pPage=(SvTabPageForProperties*)
1257 aTabControl.GetTabPage(aTabControl.GetCurPageId());
1258 pPage->GetTheListBox()->EnableUpdate();
1261 void SvPropertyBox::DisableUpdate()
1263 SvTabPageForProperties* pPage=(SvTabPageForProperties*)
1264 aTabControl.GetTabPage(aTabControl.GetCurPageId());
1265 pPage->GetTheListBox()->DisableUpdate();
1268 void SvPropertyBox::SetController(SvPropertyDataControl *pDataCtr)
1270 pThePropDataCtr=pDataCtr;
1271 USHORT nCount=aTabControl.GetPageCount();
1273 for(USHORT i=1;i<=nCount;i++)
1275 SvTabPageForProperties* pPage=(SvTabPageForProperties*)
1276 aTabControl.GetTabPage(i);
1278 pPage->GetTheListBox()->SetController(pThePropDataCtr);
1283 USHORT SvPropertyBox::InsertEntry( const SvPropertyData& rData, USHORT nPos)
1285 SvTabPageForProperties* pPage=(SvTabPageForProperties*)
1286 aTabControl.GetTabPage(aTabControl.GetCurPageId());
1287 return pPage->GetTheListBox()->InsertEntry(rData,nPos);
1290 void SvPropertyBox::ChangeEntry( const SvPropertyData& rData, USHORT nPos)
1292 SvTabPageForProperties* pPage=(SvTabPageForProperties*)
1293 aTabControl.GetTabPage(aTabControl.GetCurPageId());
1294 pPage->GetTheListBox()->ChangeEntry(rData,nPos);
1297 USHORT SvPropertyBox::AppendEntry( const SvPropertyData& rData)
1299 SvTabPageForProperties* pPage=(SvTabPageForProperties*)
1300 aTabControl.GetTabPage(aTabControl.GetCurPageId());
1301 return pPage->GetTheListBox()->AppendEntry(rData);
1304 void SvPropertyBox::SetPropertyValue( const String & rEntryName, const String & rValue )
1306 SvTabPageForProperties* pPage=(SvTabPageForProperties*)
1307 aTabControl.GetTabPage(aTabControl.GetCurPageId());
1308 pPage->GetTheListBox()->SetPropertyValue( rEntryName, rValue );
1311 void SvPropertyBox::SetFirstVisibleEntry(USHORT nPos)
1313 SvTabPageForProperties* pPage=(SvTabPageForProperties*)
1314 aTabControl.GetTabPage(aTabControl.GetCurPageId());
1315 pPage->GetTheListBox()->SetFirstVisibleEntry(nPos);
1317 USHORT SvPropertyBox::GetFirstVisibleEntry()
1319 SvTabPageForProperties* pPage=(SvTabPageForProperties*)
1320 aTabControl.GetTabPage(aTabControl.GetCurPageId());
1321 return pPage->GetTheListBox()->GetFirstVisibleEntry();
1324 void SvPropertyBox::SetSelectedEntry(USHORT nPos)
1326 SvTabPageForProperties* pPage=(SvTabPageForProperties*)
1327 aTabControl.GetTabPage(aTabControl.GetCurPageId());
1328 pPage->GetTheListBox()->SetSelectedEntry(nPos);
1330 USHORT SvPropertyBox::GetSelectedEntry()
1332 SvTabPageForProperties* pPage=(SvTabPageForProperties*)
1333 aTabControl.GetTabPage(aTabControl.GetCurPageId());
1334 return pPage->GetTheListBox()->GetSelectedEntry();
1337 void SvPropertyBox::ClearTable()
1339 SvTabPageForProperties* pPage=(SvTabPageForProperties*)
1340 aTabControl.GetTabPage(aTabControl.GetCurPageId());
1341 pPage->GetTheListBox()->Clear();
1344 SvBasicPropertyDataControl::~SvBasicPropertyDataControl()
1348 void SvBasicPropertyDataControl::Modified(const String& aName,
1349 const String& aVal,void* pData)
1351 aEntryName=aName;
1352 aEntryProperty=aVal;
1353 pTheData=pData;
1354 aModifyLink.Call(this);
1357 void SvBasicPropertyDataControl::Clicked( const String& aName,
1358 const String& aVal,
1359 void* pData) //Xtension-Button pressed
1361 aEntryName=aName;
1362 aEntryProperty=aVal;
1363 pTheData=pData;
1364 aClickedLink.Call(this);
1367 void SvBasicPropertyDataControl::Commit( const String& aName,
1368 const String& aVal,
1369 void* pData) //User accept changes
1371 aEntryName=aName;
1372 aEntryProperty=aVal;
1373 pTheData=pData;
1374 aCommitLink.Call(this);
1377 void SvBasicPropertyDataControl::Select( const String& aName,
1378 void* pData) //User select new Row
1380 aEntryName=aName;
1381 pTheData=pData;
1382 aSelectLink.Call(this);
1385 void SvBasicPropertyDataControl::LinkClicked(const String&, void*)
1390 String SvBasicPropertyDataControl::GetName() const //Tell's the name of the Property
1392 return aEntryName;
1395 String SvBasicPropertyDataControl::GetProperty() const //Tell's the content of the Property
1397 return aEntryProperty;
1400 void* SvBasicPropertyDataControl::GetData() //Tell's the storage
1402 return pTheData;
1406 String SvBasicPropertyDataControl::GetTheCorrectProperty() const
1408 return aCorrectProperty;
1412 void SvBasicPropertyDataControl::SetTheCorrectProperty(const String& aString)
1414 aCorrectProperty=aString;
1417 void SvBasicPropertyDataControl::SetIsCorrect(BOOL nFlag)
1419 bCorrectness=nFlag;
1424 //========================================================================
1425 // Property-Dialog:
1426 /* zum TESTEN im CALC*/
1427 //========================================================================
1429 ScPropertyDlg::ScPropertyDlg( Window* pParent) :
1430 ModalDialog ( pParent, ScResId( RID_SCDLG_PROPERTIES) ),
1431 aPropListBox ( this, ResId( CTR_PROPLINE) ),
1432 aKindOfListBox (this,ResId( LB_KIND_OF_PROP)),
1433 aModAnswer (this,ResId(FT_ANSMOD )),
1434 aClickAnswer (this,ResId(FT_ANSCLICK )),
1435 aCommitAnswer (this,ResId(FT_ANSCOMMIT)),
1436 aSelectAnswer (this,ResId(FT_ANSSELECT)),
1437 anOk(this,ResId( BTN_OK)),
1438 aCancel(this,ResId( BTN_CANCEL))
1440 FreeResource();
1442 aKindOfListBox.SelectEntryPos(0);
1443 aKindOfListBox.SetSelectHdl(
1444 LINK( this, ScPropertyDlg, ModifiedHdl ));
1445 nCount=0;
1446 nClickCount=0;
1448 String aString("Don't know ");
1450 aBaProDatCtr.SetModifyHdl (LINK( this, ScPropertyDlg, RowModifiedHdl ));
1451 aBaProDatCtr.SetClickedHdl(LINK( this, ScPropertyDlg, ClickHdl ));
1452 aBaProDatCtr.SetCommitHdl (LINK( this, ScPropertyDlg, SelectHdl ));
1453 aBaProDatCtr.SetSelectHdl (LINK( this, ScPropertyDlg, CommitHdl ));
1455 aPropListBox.SetController(&aBaProDatCtr);
1457 USHORT nPageId=aPropListBox.AppendPage("YabbaDabbaDo");
1458 aPropListBox.SetPage(nPageId);
1459 aProperty.eKind=KOC_EDIT;
1460 aProperty.aName=aString;
1461 aProperty.aName+=String((USHORT)++nCount);
1462 aProperty.aValue=sizeof ComboBox;
1463 aProperty.bHasVisibleXButton=FALSE;
1464 aProperty.bIsHyperLink=FALSE;
1465 aProperty.bIsLocked=FALSE;
1466 aProperty.pDataPtr=NULL;
1467 aProperty.pControl=NULL;
1468 aProperty.theValues.Insert(new String("1"),aProperty.theValues.Count());
1469 aProperty.theValues.Insert(new String("2"),aProperty.theValues.Count());
1470 aProperty.theValues.Insert(new String("3"),aProperty.theValues.Count());
1471 aProperty.theValues.Insert(new String("4"),aProperty.theValues.Count());
1472 aPropListBox.InsertEntry(aProperty);
1473 aProperty.bHasVisibleXButton=TRUE;
1474 aProperty.aName=aString;
1475 aProperty.aName+=String((USHORT)++nCount);
1476 aProperty.aValue="42";
1477 aProperty.eKind=KOC_LISTBOX;
1478 aPropListBox.InsertEntry(aProperty);
1479 aProperty.aName=aString;
1480 aProperty.aName+=String((USHORT)++nCount);
1481 aProperty.eKind=KOC_COMBOBOX;
1482 aProperty.bHasVisibleXButton=FALSE;
1483 aPropListBox.InsertEntry(aProperty);
1486 ScPropertyDlg::~ScPropertyDlg()
1488 delete aProperty.theValues[0];
1489 delete aProperty.theValues[1];
1490 delete aProperty.theValues[2];
1491 delete aProperty.theValues[3];
1494 IMPL_LINK( ScPropertyDlg, ModifiedHdl, ListBox*, pLB )
1496 if(pLB!=NULL)
1498 String aString("Don't know ");
1499 aProperty.aName=aString;
1500 aProperty.aName+=String((USHORT)++nCount);
1501 if(nCount>20)
1503 String aStr("Yabba ");
1504 aStr+=aPropListBox.GetCurPage();
1505 USHORT nPageId=aPropListBox.AppendPage(aStr);
1506 aPropListBox.SetPage(nPageId);
1507 nCount=0;
1510 aProperty.eKind=(eKindOfControl)(aKindOfListBox.GetSelectEntryPos()+1);
1511 aProperty.bHasVisibleXButton=FALSE;
1512 if((nCount % 5)==0) aProperty.bHasVisibleXButton=TRUE;
1513 aPropListBox.InsertEntry(aProperty);
1515 return 0;
1518 IMPL_LINK( ScPropertyDlg, RowModifiedHdl, SvBasicPropertyDataControl* ,pProCtr)
1520 if(pProCtr!=NULL)
1522 aModAnswer.SetText(aBaProDatCtr.GetProperty());
1523 aModAnswer.Invalidate();
1524 aBaProDatCtr.SetIsCorrect(TRUE);
1526 return 0;
1529 IMPL_LINK( ScPropertyDlg, CommitHdl, SvBasicPropertyDataControl*,pProCtr)
1531 if(pProCtr!=NULL)
1533 aCommitAnswer.SetText(aBaProDatCtr.GetProperty());
1534 aCommitAnswer.Invalidate();
1535 aBaProDatCtr.SetIsCorrect(TRUE);
1537 return 0;
1540 IMPL_LINK( ScPropertyDlg, ClickHdl, SvBasicPropertyDataControl*,pProCtr)
1542 if(pProCtr!=NULL)
1544 aClickAnswer.SetText(aBaProDatCtr.GetName());
1545 aClickAnswer.Invalidate();
1546 aBaProDatCtr.SetIsCorrect(TRUE);
1548 return 0;
1551 IMPL_LINK( ScPropertyDlg, SelectHdl, SvBasicPropertyDataControl*,pProCtr)
1553 if(pProCtr!=NULL)
1555 aSelectAnswer.SetText(aBaProDatCtr.GetName());
1556 aSelectAnswer.Invalidate();
1557 aBaProDatCtr.SetIsCorrect(TRUE);
1559 return 0;