Gtk-WARNING gtktreestore.c:1047: Invalid column number 1 added to iter
[LibreOffice.git] / dbaccess / source / ui / inc / FieldDescControl.hxx
blob410e086116fe6a671bf54b5721ed2d3d436a2658
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #pragma once
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 #include <unotools/resmgr.hxx>
29 // field description columns of a table
30 #define FIELD_NAME 1
31 #define FIELD_TYPE 2
32 #define HELP_TEXT 3
33 #define COLUMN_DESCRIPTION 4
35 #define FIELD_FIRST_VIRTUAL_COLUMN 5
37 #define FIELD_PROPERTY_REQUIRED 5
38 #define FIELD_PROPERTY_NUMTYPE 6
39 #define FIELD_PROPERTY_AUTOINC 7
40 #define FIELD_PROPERTY_DEFAULT 8
41 #define FIELD_PROPERTY_TEXTLEN 9
42 #define FIELD_PROPERTY_LENGTH 10
43 #define FIELD_PROPERTY_SCALE 11
44 #define FIELD_PROPERTY_BOOL_DEFAULT 12
45 #define FIELD_PROPERTY_FORMAT 13
46 #define FIELD_PROPERTY_COLUMNNAME 14
47 #define FIELD_PROPERTY_TYPE 15
48 #define FIELD_PROPERTY_AUTOINCREMENT 16
50 namespace dbaui
52 class OTableDesignHelpBar;
53 class OPropListBoxCtrl;
54 class OPropEditCtrl;
55 class OPropNumericEditCtrl;
56 class OFieldDescription;
57 class OPropColumnEditCtrl;
59 class OFieldDescControl : public IClipboardTest
61 private:
62 std::unique_ptr<weld::Builder> m_xBuilder;
63 std::unique_ptr<weld::Container> m_xContainer;
65 OTableDesignHelpBar* m_pHelp;
66 weld::Widget* m_pLastFocusWindow;
67 weld::Widget* m_pActFocusWindow;
69 std::unique_ptr<weld::Label> m_xDefaultText;
70 std::unique_ptr<weld::Label> m_xRequiredText;
71 std::unique_ptr<weld::Label> m_xAutoIncrementText;
72 std::unique_ptr<weld::Label> m_xTextLenText;
73 std::unique_ptr<weld::Label> m_xNumTypeText;
74 std::unique_ptr<weld::Label> m_xLengthText;
75 std::unique_ptr<weld::Label> m_xScaleText;
76 std::unique_ptr<weld::Label> m_xFormatText;
77 std::unique_ptr<weld::Label> m_xBoolDefaultText;
78 std::unique_ptr<weld::Label> m_xColumnNameText;
79 std::unique_ptr<weld::Label> m_xTypeText;
80 std::unique_ptr<weld::Label> m_xAutoIncrementValueText;
82 std::unique_ptr<OPropListBoxCtrl> m_xRequired;
83 std::unique_ptr<OPropListBoxCtrl> m_xNumType;
84 std::unique_ptr<OPropListBoxCtrl> m_xAutoIncrement;
85 std::unique_ptr<OPropEditCtrl> m_xDefault;
86 std::unique_ptr<OPropNumericEditCtrl> m_xTextLen;
87 std::unique_ptr<OPropNumericEditCtrl> m_xLength;
88 std::unique_ptr<OPropNumericEditCtrl> m_xScale;
89 std::unique_ptr<OPropEditCtrl> m_xFormatSample;
90 std::unique_ptr<OPropListBoxCtrl> m_xBoolDefault;
91 std::unique_ptr<OPropColumnEditCtrl> m_xColumnName;
92 std::unique_ptr<OPropListBoxCtrl> m_xType;
93 std::unique_ptr<OPropEditCtrl> m_xAutoIncrementValue;
95 std::unique_ptr<weld::Button> m_xFormat;
97 Link<weld::Widget&, void> m_aControlFocusIn;
99 TOTypeInfoSP m_pPreviousType;
100 short m_nPos;
101 OUString aYes;
102 OUString aNo;
104 sal_Int32 m_nEditWidth;
106 OFieldDescription* pActFieldDescr;
108 DECL_LINK(FormatClickHdl, weld::Button&, void);
109 DECL_LINK(ChangeHdl, weld::ComboBox&, void);
111 // used by ActivatePropertyField
112 DECL_LINK( OnControlFocusLost, weld::Widget&, void );
113 DECL_LINK( OnControlFocusGot, weld::Widget&, void );
115 DECL_LINK( HelpFocusOut, weld::Widget&, void );
117 void UpdateFormatSample(OFieldDescription const * pFieldDescr);
119 bool isTextFormat(const OFieldDescription* _pFieldDescr,sal_uInt32& _nFormatKey) const;
120 std::unique_ptr<OPropNumericEditCtrl> CreateNumericControl(const OUString& rId, TranslateId pHelpId, short _nProperty, const OUString& _sHelpId);
121 void InitializeControl(weld::Widget* _pControl,const OUString& _sHelpId);
122 void InitializeControl(OPropListBoxCtrl* _pControl,const OUString& _sHelpId,bool _bAddChangeHandler);
124 bool IsFocusInEditableWidget() const;
126 void dispose();
127 protected:
128 void saveCurrentFieldDescData() { SaveData( pActFieldDescr ); }
129 OFieldDescription* getCurrentFieldDescData() { return pActFieldDescr; }
130 void setCurrentFieldDescData( OFieldDescription* _pDesc ) { pActFieldDescr = _pDesc; }
132 virtual void ActivateAggregate( EControlType eType );
133 virtual void DeactivateAggregate( EControlType eType );
134 virtual bool IsReadOnly() { return false; };
136 virtual css::uno::Reference< css::util::XNumberFormatter > GetFormatter() const = 0;
138 virtual css::lang::Locale GetLocale() const = 0;
140 virtual void CellModified(sal_Int32 nRow, sal_uInt16 nColId ) = 0;
141 virtual void SetModified(bool bModified); // base implementation is empty
143 virtual TOTypeInfoSP getTypeInfo(sal_Int32 _nPos) = 0;
144 virtual const OTypeInfoMap* getTypeInfo() const = 0;
146 virtual bool isAutoIncrementValueEnabled() const = 0;
147 virtual OUString getAutoIncrementValue() const = 0;
149 OUString BoolStringPersistent(std::u16string_view rUIString) const;
150 OUString BoolStringUI(const OUString& rPersistentString) const;
152 const OPropColumnEditCtrl* getColumnCtrl() const { return m_xColumnName.get(); }
154 void implFocusLost(weld::Widget* _pWhich);
156 public:
157 OFieldDescControl(weld::Container* pPage, OTableDesignHelpBar* pHelpBar);
158 virtual ~OFieldDescControl();
160 void DisplayData(OFieldDescription* pFieldDescr );
162 void SaveData( OFieldDescription* pFieldDescr );
164 void SetControlText( sal_uInt16 nControlId, const OUString& rText );
165 void SetReadOnly( bool bReadOnly );
167 void Enable(bool bEnable) { m_xContainer->set_sensitive(bEnable); }
168 void SetHelpId(const OUString& rId) { m_xContainer->set_help_id(rId); }
170 virtual bool isCutAllowed() override;
171 virtual bool isCopyAllowed() override;
172 virtual bool isPasteAllowed() override;
174 virtual void cut() override;
175 virtual void copy() override;
176 virtual void paste() override;
178 void connect_focus_in(const Link<weld::Widget&, void>& rLink)
180 m_aControlFocusIn = rLink;
183 void Init();
185 void GrabFocus();
187 bool HasChildPathFocus() const;
189 virtual css::uno::Reference< css::sdbc::XDatabaseMetaData> getMetaData() = 0;
190 virtual css::uno::Reference< css::sdbc::XConnection> getConnection() = 0;
192 OUString getControlDefault( const OFieldDescription* pFieldDescr, bool _bCheck = true) const;
193 // tdf#138409 take the control default in the UI Locale format, e.g. 12,34 and return a string
194 // suitable as the database default, e.g. 12.34
195 OUString CanonicalizeToControlDefault(const OFieldDescription* pFieldDescr, const OUString& rUserText) const;
197 void setEditWidth(sal_Int32 _nWidth) { m_nEditWidth = _nWidth; }
201 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */