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
20 #ifndef INCLUDED_SC_SOURCE_UI_INC_SCUIASCIIOPT_HXX
21 #define INCLUDED_SC_SOURCE_UI_INC_SCUIASCIIOPT_HXX
22
23 #include <svx/langbox.hxx>
24 #include <tools/stream.hxx>
25 #include <vcl/customweld.hxx>
26 #include <vcl/weld.hxx>
27
28 #include "asciiopt.hxx"
29
30 class Button;
31 class CheckBox;
32 class Edit;
33 class FixedText;
34 class RadioButton;
35 class NumericField;
36
37 class ScCsvTableBox;
38 class SvxTextEncodingBox;
39
40 class ScImportAsciiDlg : public weld::GenericDialogController
41 {
42 SvStream* mpDatStream;
43 sal_uLong mnStreamPos;
44 std::unique_ptr<sal_uLong[]> mpRowPosArray;
45 sal_uLong mnRowPosCount;
46
47 OUString maPreviewLine[ CSV_PREVIEW_LINES ];
48
49 OUString maFieldSeparators; // selected field separators
50 sal_Unicode mcTextSep;
51
52 rtl_TextEncoding meCharSet; /// Selected char set.
53 bool mbCharSetSystem; /// Is System char set selected?
54 ScImportAsciiCall const meCall; /// How the dialog is called (see asciiopt.hxx)
55 bool mbDetectSpaceSep; /// Whether to detect a possible space separator.
56
57 std::unique_ptr<weld::Label> mxFtCharSet;
58 std::unique_ptr<SvxTextEncodingBox> mxLbCharSet;
59 std::unique_ptr<weld::Label> mxFtCustomLang;
60 std::unique_ptr<SvxLanguageBox> mxLbCustomLang;
61
62 std::unique_ptr<weld::Label> mxFtRow;
63 std::unique_ptr<weld::SpinButton> mxNfRow;
64
65 std::unique_ptr<weld::RadioButton> mxRbFixed;
66 std::unique_ptr<weld::RadioButton> mxRbSeparated;
67
68 std::unique_ptr<weld::CheckButton> mxCkbTab;
69 std::unique_ptr<weld::CheckButton> mxCkbSemicolon;
70 std::unique_ptr<weld::CheckButton> mxCkbComma;
71 std::unique_ptr<weld::CheckButton> mxCkbRemoveSpace;
72 std::unique_ptr<weld::CheckButton> mxCkbSpace;
73 std::unique_ptr<weld::CheckButton> mxCkbOther;
74 std::unique_ptr<weld::Entry> mxEdOther;
75 std::unique_ptr<weld::CheckButton> mxCkbAsOnce;
76
77 std::unique_ptr<weld::Label> mxFtTextSep;
78 std::unique_ptr<weld::ComboBox> mxCbTextSep;
79
80 std::unique_ptr<weld::CheckButton> mxCkbQuotedAsText;
81 std::unique_ptr<weld::CheckButton> mxCkbDetectNumber;
82 std::unique_ptr<weld::CheckButton> mxCkbSkipEmptyCells;
83
84 std::unique_ptr<weld::Label> mxFtType;
85 std::unique_ptr<weld::ComboBox> mxLbType;
86 std::unique_ptr<weld::Label> mxAltTitle;
87
88 std::unique_ptr<ScCsvTableBox> mxTableBox;
89
90 public:
91 ScImportAsciiDlg(
92 weld::Window* pParent, const OUString& aDatName,
93 SvStream* pInStream, ScImportAsciiCall eCall );
94 virtual ~ScImportAsciiDlg() override;
95
96 void GetOptions( ScAsciiOptions& rOpt );
97 void SaveParameters();
98
99 private:
100 /** Sets the selected char set data to meCharSet and mbCharSetSystem. */
101 void SetSelectedCharSet();
102 /** Set separators in ui from maFieldSeparators */
103 void SetSeparators();
104 /** Returns all separator characters in a string. */
105 OUString GetSeparators() const;
106
107 /** Enables or disables all separator checkboxes and edit fields. */
108 void SetupSeparatorCtrls();
109
110 bool GetLine( sal_uLong nLine, OUString &rText, sal_Unicode& rcDetectSep );
111 void UpdateVertical();
112 inline bool Seek( sal_uLong nPos ); // synced to and from mnStreamPos
113
114 DECL_LINK( CharSetHdl, weld::ComboBox&, void );
115 DECL_LINK( FirstRowHdl, weld::SpinButton&, void );
116 DECL_LINK( RbSepFixHdl, weld::Button&, void );
117 DECL_LINK( SeparatorEditHdl, weld::Entry&, void );
118 DECL_LINK( SeparatorClickHdl, weld::Button&, void );
119 DECL_LINK( SeparatorComboBoxHdl, weld::ComboBox&, void );
120 void SeparatorHdl(const weld::Widget*);
121 DECL_LINK( LbColTypeHdl, weld::ComboBox&, void );
122 DECL_LINK( UpdateTextHdl, ScCsvTableBox&, void );
123 DECL_LINK( ColTypeHdl, ScCsvTableBox&, void );
124 };
125
Seek(sal_uLong nPos)126 inline bool ScImportAsciiDlg::Seek(sal_uLong nPos)
127 {
128 bool bSuccess = true;
129 if (nPos != mnStreamPos && mpDatStream)
130 {
131 if (mpDatStream->Seek( nPos ) != nPos)
132 bSuccess = false;
133 else
134 mnStreamPos = nPos;
135 }
136 return bSuccess;
137 }
138
139 #endif
140
141 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
142