Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * Copyright 2012 LibreOffice contributors.
4 : *
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/.
8 : */
9 :
10 : #include "inputdlg.hxx"
11 :
12 : #include "inputdlg.hrc"
13 :
14 : #include <sfx2/sfxresid.hxx>
15 : #include <vcl/button.hxx>
16 : #include <vcl/edit.hxx>
17 : #include <vcl/fixed.hxx>
18 :
19 : #define LABEL_TEXT_SPACE 5
20 :
21 0 : InputDialog::InputDialog (const rtl::OUString &rLabelText, Window *pParent)
22 : : ModalDialog(pParent,SfxResId(DLG_INPUT_BOX)),
23 0 : mpEntry(new Edit(this,SfxResId(EDT_INPUT_FIELD))),
24 0 : mpLabel(new FixedText(this,SfxResId(LABEL_INPUT_TEXT))),
25 0 : mpOK(new PushButton(this,SfxResId(BTN_INPUT_OK))),
26 0 : mpCancel(new PushButton(this,SfxResId(BTN_INPUT_CANCEL)))
27 : {
28 0 : SetStyle(GetStyle() | WB_CENTER | WB_VCENTER);
29 :
30 0 : mpLabel->SetText(rLabelText);
31 :
32 : // Fit label size to text and reposition edit box
33 0 : Size aLabelSize = mpLabel->CalcMinimumSize();
34 0 : Size aEditSize = mpEntry->GetSizePixel();
35 0 : Size aBtnSize = mpOK->GetSizePixel();
36 :
37 0 : Point aLabelPos = mpLabel->GetPosPixel();
38 0 : Point aEditPos = mpEntry->GetPosPixel();
39 :
40 0 : aEditPos.setX(aLabelPos.getX() + aLabelSize.getWidth() + LABEL_TEXT_SPACE);
41 :
42 0 : mpLabel->SetPosSizePixel(aLabelPos,aLabelSize);
43 0 : mpEntry->SetPosSizePixel(aEditPos,aEditSize);
44 :
45 : // Resize window if needed
46 0 : Size aWinSize = GetOutputSize();
47 0 : aWinSize.setWidth(aEditPos.getX() + aEditSize.getWidth() + LABEL_TEXT_SPACE);
48 0 : SetSizePixel(aWinSize);
49 :
50 : // Align buttons
51 0 : Point aBtnPos = mpCancel->GetPosPixel();
52 :
53 0 : aBtnPos.setX(aWinSize.getWidth() - aBtnSize.getWidth() - LABEL_TEXT_SPACE);
54 0 : mpCancel->SetPosPixel(aBtnPos);
55 :
56 0 : aBtnPos.setX(aBtnPos.getX() - aBtnSize.getWidth() - LABEL_TEXT_SPACE);
57 0 : mpOK->SetPosPixel(aBtnPos);
58 :
59 0 : mpOK->SetClickHdl(LINK(this,InputDialog,ClickHdl));
60 0 : mpCancel->SetClickHdl(LINK(this,InputDialog,ClickHdl));
61 0 : }
62 :
63 0 : InputDialog::~InputDialog()
64 : {
65 0 : delete mpEntry;
66 0 : delete mpLabel;
67 0 : delete mpOK;
68 0 : delete mpCancel;
69 0 : }
70 :
71 0 : rtl::OUString InputDialog::getEntryText () const
72 : {
73 0 : return mpEntry->GetText();
74 : }
75 :
76 0 : IMPL_LINK(InputDialog,ClickHdl,PushButton*, pButton)
77 : {
78 0 : EndDialog(pButton == mpOK ? true : false);
79 0 : return 0;
80 : }
81 :
82 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
83 :
84 :
|