1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
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  * This file incorporates work covered by the following license notice:
10  *
11  *   Licensed to the Apache Software Foundation (ASF) under one or more
12  *   contributor license agreements. See the NOTICE file distributed
13  *   with this work for additional information regarding copyright
14  *   ownership. The ASF licenses this file to you under the Apache
15  *   License, Version 2.0 (the "License"); you may not use this file
16  *   except in compliance with the License. You may obtain a copy of
17  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 #pragma once
20 
21 #include <vcl/weld.hxx>
22 #include "IClipBoardTest.hxx"
23 #include "QEnumTypes.hxx"
24 #include <com/sun/star/sdbc/XDatabaseMetaData.hpp>
25 #include <com/sun/star/util/XNumberFormatter.hpp>
26 #include "TypeInfo.hxx"
27 
28 // field description columns of a table
29 #define FIELD_NAME                      1
30 #define FIELD_TYPE                      2
31 #define HELP_TEXT                       3
32 #define COLUMN_DESCRIPTION              4
33 
34 #define FIELD_FIRST_VIRTUAL_COLUMN      5
35 
36 #define FIELD_PROPERTY_REQUIRED         5
37 #define FIELD_PROPERTY_NUMTYPE          6
38 #define FIELD_PROPERTY_AUTOINC          7
39 #define FIELD_PROPERTY_DEFAULT          8
40 #define FIELD_PROPERTY_TEXTLEN          9
41 #define FIELD_PROPERTY_LENGTH           10
42 #define FIELD_PROPERTY_SCALE            11
43 #define FIELD_PROPERTY_BOOL_DEFAULT     12
44 #define FIELD_PROPERTY_FORMAT           13
45 #define FIELD_PROPERTY_COLUMNNAME       14
46 #define FIELD_PROPERTY_TYPE             15
47 #define FIELD_PROPERTY_AUTOINCREMENT    16
48 
49 namespace dbaui
50 {
51     class OTableDesignHelpBar;
52     class OPropListBoxCtrl;
53     class OPropEditCtrl;
54     class OPropNumericEditCtrl;
55     class OFieldDescription;
56     class OPropColumnEditCtrl;
57 
58     class OFieldDescControl : public IClipboardTest
59     {
60     private:
61         std::unique_ptr<weld::Builder> m_xBuilder;
62         std::unique_ptr<weld::Container> m_xContainer;
63 
64         OTableDesignHelpBar* m_pHelp;
65         weld::Widget* m_pLastFocusWindow;
66         weld::Widget* m_pActFocusWindow;
67 
68         std::unique_ptr<weld::Label>   m_xDefaultText;
69         std::unique_ptr<weld::Label>   m_xRequiredText;
70         std::unique_ptr<weld::Label>   m_xAutoIncrementText;
71         std::unique_ptr<weld::Label>   m_xTextLenText;
72         std::unique_ptr<weld::Label>   m_xNumTypeText;
73         std::unique_ptr<weld::Label>   m_xLengthText;
74         std::unique_ptr<weld::Label>   m_xScaleText;
75         std::unique_ptr<weld::Label>   m_xFormatText;
76         std::unique_ptr<weld::Label>   m_xBoolDefaultText;
77         std::unique_ptr<weld::Label>   m_xColumnNameText;
78         std::unique_ptr<weld::Label>   m_xTypeText;
79         std::unique_ptr<weld::Label>   m_xAutoIncrementValueText;
80 
81         std::unique_ptr<OPropListBoxCtrl> m_xRequired;
82         std::unique_ptr<OPropListBoxCtrl> m_xNumType;
83         std::unique_ptr<OPropListBoxCtrl> m_xAutoIncrement;
84         std::unique_ptr<OPropEditCtrl> m_xDefault;
85         std::unique_ptr<OPropNumericEditCtrl> m_xTextLen;
86         std::unique_ptr<OPropNumericEditCtrl> m_xLength;
87         std::unique_ptr<OPropNumericEditCtrl> m_xScale;
88         std::unique_ptr<OPropEditCtrl> m_xFormatSample;
89         std::unique_ptr<OPropListBoxCtrl> m_xBoolDefault;
90         std::unique_ptr<OPropColumnEditCtrl> m_xColumnName;
91         std::unique_ptr<OPropListBoxCtrl> m_xType;
92         std::unique_ptr<OPropEditCtrl> m_xAutoIncrementValue;
93 
94         std::unique_ptr<weld::Button>  m_xFormat;
95 
96         Link<weld::Widget&, void> m_aControlFocusIn;
97 
98         TOTypeInfoSP            m_pPreviousType;
99         short                   m_nPos;
100         OUString                aYes;
101         OUString                aNo;
102 
103         sal_Int32               m_nEditWidth;
104 
105         OFieldDescription*      pActFieldDescr;
106 
107         DECL_LINK(FormatClickHdl, weld::Button&, void);
108         DECL_LINK(ChangeHdl, weld::ComboBox&, void);
109 
110         // used by ActivatePropertyField
111         DECL_LINK( OnControlFocusLost, weld::Widget&, void );
112         DECL_LINK( OnControlFocusGot, weld::Widget&, void );
113 
114         DECL_LINK( HelpFocusOut, weld::Widget&, void );
115 
116         void                UpdateFormatSample(OFieldDescription const * pFieldDescr);
117 
118         bool                isTextFormat(const OFieldDescription* _pFieldDescr,sal_uInt32& _nFormatKey) const;
119         std::unique_ptr<OPropNumericEditCtrl> CreateNumericControl(const OString& rId, const char* pHelpId, short _nProperty, const OString& _sHelpId);
120         void                InitializeControl(weld::Widget* _pControl,const OString& _sHelpId);
121         void                InitializeControl(OPropListBoxCtrl* _pControl,const OString& _sHelpId,bool _bAddChangeHandler);
122 
123         bool                IsFocusInEditableWidget() const;
124 
125         void                dispose();
126     protected:
saveCurrentFieldDescData()127         void                saveCurrentFieldDescData() { SaveData( pActFieldDescr ); }
getCurrentFieldDescData()128         OFieldDescription*  getCurrentFieldDescData() { return pActFieldDescr; }
setCurrentFieldDescData(OFieldDescription * _pDesc)129         void                setCurrentFieldDescData( OFieldDescription* _pDesc ) { pActFieldDescr = _pDesc; }
130 
131         virtual void        ActivateAggregate( EControlType eType );
132         virtual void        DeactivateAggregate( EControlType eType );
IsReadOnly()133         virtual bool        IsReadOnly() { return false; };
134 
135         virtual css::uno::Reference< css::util::XNumberFormatter > GetFormatter() const = 0;
136 
137         virtual css::lang::Locale               GetLocale() const = 0;
138 
139         virtual void                            CellModified(sal_Int32 nRow, sal_uInt16 nColId ) = 0;
140         virtual void                            SetModified(bool bModified);    // base implementation is empty
141 
142         virtual TOTypeInfoSP                    getTypeInfo(sal_Int32 _nPos)        = 0;
143         virtual const OTypeInfoMap*             getTypeInfo() const  = 0;
144 
145         virtual bool                            isAutoIncrementValueEnabled() const = 0;
146         virtual OUString                        getAutoIncrementValue() const = 0;
147 
148         OUString                                BoolStringPersistent(std::u16string_view rUIString) const;
149         OUString                                BoolStringUI(const OUString& rPersistentString) const;
150 
getColumnCtrl() const151         const OPropColumnEditCtrl*              getColumnCtrl() const { return m_xColumnName.get(); }
152 
153         void    implFocusLost(weld::Widget* _pWhich);
154 
155     public:
156         OFieldDescControl(weld::Container* pPage, OTableDesignHelpBar* pHelpBar);
157         virtual ~OFieldDescControl();
158 
159         void                DisplayData(OFieldDescription* pFieldDescr );
160 
161         void                SaveData( OFieldDescription* pFieldDescr );
162 
163         void                SetControlText( sal_uInt16 nControlId, const OUString& rText );
164         void                SetReadOnly( bool bReadOnly );
165 
Enable(bool bEnable)166         void                Enable(bool bEnable) { m_xContainer->set_sensitive(bEnable); }
SetHelpId(const OString & rId)167         void                SetHelpId(const OString& rId) { m_xContainer->set_help_id(rId); }
168 
169         virtual bool        isCutAllowed() override;
170         virtual bool        isCopyAllowed() override;
171         virtual bool        isPasteAllowed() override;
172 
173         virtual void        cut() override;
174         virtual void        copy() override;
175         virtual void        paste() override;
176 
connect_focus_in(const Link<weld::Widget &,void> & rLink)177         void connect_focus_in(const Link<weld::Widget&, void>& rLink)
178         {
179             m_aControlFocusIn = rLink;
180         }
181 
182         void Init();
183 
184         void GrabFocus();
185 
186         bool HasChildPathFocus() const;
187 
188         virtual css::uno::Reference< css::sdbc::XDatabaseMetaData> getMetaData() = 0;
189         virtual css::uno::Reference< css::sdbc::XConnection> getConnection() = 0;
190 
191         OUString getControlDefault( const OFieldDescription* pFieldDescr, bool _bCheck = true) const;
192         // tdf#138409 take the control default in the UI Locale format, e.g. 12,34 and return a string
193         // suitable as the database default, e.g. 12.34
194         OUString CanonicalizeToControlDefault(const OFieldDescription* pFieldDescr, const OUString& rUserText) const;
195 
setEditWidth(sal_Int32 _nWidth)196         void setEditWidth(sal_Int32 _nWidth) { m_nEditWidth = _nWidth; }
197     };
198 }
199 
200 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
201