1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #include "inputdlg.hxx"
12 #include "inputdlg.hrc"
14 #include <sfx2/sfxresid.hxx>
15 #include <vcl/button.hxx>
16 #include <vcl/edit.hxx>
17 #include <vcl/fixed.hxx>
19 #define LABEL_TEXT_SPACE 5
21 InputDialog::InputDialog (const OUString
&rLabelText
, Window
*pParent
)
22 : ModalDialog(pParent
,SfxResId(DLG_INPUT_BOX
)),
23 mpEntry(new Edit(this,SfxResId(EDT_INPUT_FIELD
))),
24 mpLabel(new FixedText(this,SfxResId(LABEL_INPUT_TEXT
))),
25 mpOK(new PushButton(this,SfxResId(BTN_INPUT_OK
))),
26 mpCancel(new PushButton(this,SfxResId(BTN_INPUT_CANCEL
)))
28 SetStyle(GetStyle() | WB_CENTER
| WB_VCENTER
);
30 mpLabel
->SetText(rLabelText
);
32 // Fit label size to text and reposition edit box
33 Size aLabelSize
= mpLabel
->CalcMinimumSize();
34 Size aEditSize
= mpEntry
->GetSizePixel();
35 Size aBtnSize
= mpOK
->GetSizePixel();
37 Point aLabelPos
= mpLabel
->GetPosPixel();
38 Point aEditPos
= mpEntry
->GetPosPixel();
40 aEditPos
.setX(aLabelPos
.getX() + aLabelSize
.getWidth() + LABEL_TEXT_SPACE
);
42 mpLabel
->SetPosSizePixel(aLabelPos
,aLabelSize
);
43 mpEntry
->SetPosSizePixel(aEditPos
,aEditSize
);
45 // Resize window if needed
46 Size aWinSize
= GetOutputSize();
47 aWinSize
.setWidth(aEditPos
.getX() + aEditSize
.getWidth() + LABEL_TEXT_SPACE
);
48 SetSizePixel(aWinSize
);
51 Point aBtnPos
= mpCancel
->GetPosPixel();
53 aBtnPos
.setX(aWinSize
.getWidth() - aBtnSize
.getWidth() - LABEL_TEXT_SPACE
);
54 mpCancel
->SetPosPixel(aBtnPos
);
56 aBtnPos
.setX(aBtnPos
.getX() - aBtnSize
.getWidth() - LABEL_TEXT_SPACE
);
57 mpOK
->SetPosPixel(aBtnPos
);
59 mpOK
->SetClickHdl(LINK(this,InputDialog
,ClickHdl
));
60 mpCancel
->SetClickHdl(LINK(this,InputDialog
,ClickHdl
));
63 InputDialog::~InputDialog()
71 OUString
InputDialog::getEntryText () const
73 return mpEntry
->GetText();
76 IMPL_LINK(InputDialog
,ClickHdl
,PushButton
*, pButton
)
78 EndDialog(pButton
== mpOK
? true : false);
82 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */