4 Одиночная строка редактирования для диалога (как наследник класса Edit)
8 Copyright (c) 1996 Eugene Roshal
9 Copyright (c) 2000 Far Group
12 Redistribution and use in source and binary forms, with or without
13 modification, are permitted provided that the following conditions
15 1. Redistributions of source code must retain the above copyright
16 notice, this list of conditions and the following disclaimer.
17 2. Redistributions in binary form must reproduce the above copyright
18 notice, this list of conditions and the following disclaimer in the
19 documentation and/or other materials provided with the distribution.
20 3. The name of the authors may not be used to endorse or promote products
21 derived from this software without specific prior written permission.
23 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 #include "headers.hpp"
37 #include "dlgedit.hpp"
39 #include "history.hpp"
41 DlgEdit::DlgEdit(Dialog
*pOwner
, unsigned Index
, DLGEDITTYPE Type
)
47 #if defined(PROJECT_DI_MEMOEDIT)
53 case DLGEDIT_MULTILINE
:
54 #if defined(PROJECT_DI_MEMOEDIT)
55 multiEdit
= new Editor(pOwner
, true); // ??? (pOwner) ?
58 case DLGEDIT_SINGLELINE
: {
59 Edit::Callback callback
= {true, EditChange
, this};
65 DialogItemEx
*CurItem
= pOwner
->Item
[Index
];
66 if (Opt
.Dialogs
.AutoComplete
&& CurItem
->Flags
& (DIF_HISTORY
| DIF_EDITPATH
)
67 && !(CurItem
->Flags
& DIF_DROPDOWNLIST
) && !(CurItem
->Flags
& DIF_NOAUTOCOMPLETE
)) {
68 iFlags
= EditControl::EC_ENABLEAUTOCOMPLETE
;
70 if (CurItem
->Flags
& DIF_HISTORY
&& !CurItem
->strHistory
.IsEmpty()) {
71 FARString strHistory
= fmtSavedDialogHistory
;
72 strHistory
+= CurItem
->strHistory
;
73 iHistory
= new History(HISTORYTYPE_DIALOG
, Opt
.DialogsHistoryCount
, strHistory
.GetMB(),
74 &Opt
.Dialogs
.EditHistory
, false);
76 if (CurItem
->Type
== DI_COMBOBOX
) {
77 iList
= CurItem
->ListItems
;
79 if (CurItem
->Flags
& DIF_EDITPATH
) {
80 iFlags
|= EditControl::EC_ENABLEFNCOMPLETE
;
83 lineEdit
= new EditControl(pOwner
, &callback
, true, iHistory
, iList
, iFlags
);
97 #if defined(PROJECT_DI_MEMOEDIT)
105 int DlgEdit::ProcessKey(FarKey Key
)
107 #if defined(PROJECT_DI_MEMOEDIT)
109 if (Type
== DLGEDIT_MULTILINE
)
110 return multiEdit
->ProcessKey(Key
);
113 return lineEdit
->ProcessKey(Key
);
116 int DlgEdit::ProcessMouse(MOUSE_EVENT_RECORD
*MouseEvent
)
118 #if defined(PROJECT_DI_MEMOEDIT)
120 if (Type
== DLGEDIT_MULTILINE
)
121 return multiEdit
->ProcessMouse(MouseEvent
);
124 return lineEdit
->ProcessMouse(MouseEvent
);
127 void DlgEdit::DisplayObject()
129 #if defined(PROJECT_DI_MEMOEDIT)
131 if (Type
== DLGEDIT_MULTILINE
)
132 multiEdit
->DisplayObject();
135 lineEdit
->DisplayObject();
138 void DlgEdit::SetPosition(int X1
, int Y1
, int X2
, int Y2
)
140 #if defined(PROJECT_DI_MEMOEDIT)
142 if (Type
== DLGEDIT_MULTILINE
)
143 multiEdit
->SetPosition(X1
, Y1
, X2
, Y2
);
146 lineEdit
->SetPosition(X1
, Y1
, X2
, Y2
);
151 #if defined(PROJECT_DI_MEMOEDIT)
153 if (Type
== DLGEDIT_MULTILINE
)
160 void DlgEdit::GetPosition(int &X1
, int &Y1
, int &X2
, int &Y2
)
162 #if defined(PROJECT_DI_MEMOEDIT)
164 if (Type
== DLGEDIT_MULTILINE
)
165 multiEdit
->GetPosition(X1
, Y1
, X2
, Y2
);
168 lineEdit
->GetPosition(X1
, Y1
, X2
, Y2
);
171 void DlgEdit::SetDialogParent(DWORD Sets
)
173 #if defined(PROJECT_DI_MEMOEDIT)
175 if (Type
== DLGEDIT_MULTILINE
)
176 multiEdit
->SetDialogParent(Sets
);
179 lineEdit
->SetDialogParent(Sets
);
182 void DlgEdit::SetDropDownBox(int NewDropDownBox
)
184 if (Type
== DLGEDIT_SINGLELINE
)
185 lineEdit
->SetDropDownBox(NewDropDownBox
);
188 int DlgEdit::GetMaxLength()
190 if (Type
== DLGEDIT_SINGLELINE
)
191 return lineEdit
->GetMaxLength();
196 void DlgEdit::SetMaxLength(int Length
)
198 if (Type
== DLGEDIT_SINGLELINE
)
199 lineEdit
->SetMaxLength(Length
);
202 void DlgEdit::SetPasswordMode(int Mode
)
204 if (Type
== DLGEDIT_SINGLELINE
)
205 lineEdit
->SetPasswordMode(Mode
);
208 void DlgEdit::SetOvertypeMode(int Mode
)
210 #if defined(PROJECT_DI_MEMOEDIT)
212 if (Type
== DLGEDIT_MULTILINE
)
213 multiEdit
->SetOvertypeMode(Mode
);
216 lineEdit
->SetOvertypeMode(Mode
);
219 int DlgEdit::GetOvertypeMode()
221 #if defined(PROJECT_DI_MEMOEDIT)
223 if (Type
== DLGEDIT_MULTILINE
)
224 return multiEdit
->GetOvertypeMode();
227 return lineEdit
->GetOvertypeMode();
230 void DlgEdit::SetInputMask(const wchar_t *InputMask
)
232 if (Type
== DLGEDIT_SINGLELINE
)
233 lineEdit
->SetInputMask(InputMask
);
236 const wchar_t *DlgEdit::GetInputMask()
238 if (Type
== DLGEDIT_SINGLELINE
)
239 return lineEdit
->GetInputMask();
244 void DlgEdit::SetEditBeyondEnd(int Mode
)
246 #if defined(PROJECT_DI_MEMOEDIT)
248 if (Type
== DLGEDIT_MULTILINE
)
249 multiEdit
->SetEditBeyondEnd(Mode
);
252 lineEdit
->SetEditBeyondEnd(Mode
);
255 void DlgEdit::SetClearFlag(int Flag
)
257 #if defined(PROJECT_DI_MEMOEDIT)
259 if (Type
== DLGEDIT_MULTILINE
)
260 multiEdit
->SetClearFlag(Flag
);
263 lineEdit
->SetClearFlag(Flag
);
266 int DlgEdit::GetClearFlag()
268 #if defined(PROJECT_DI_MEMOEDIT)
270 if (Type
== DLGEDIT_MULTILINE
)
271 return multiEdit
->GetClearFlag();
274 return lineEdit
->GetClearFlag();
277 const wchar_t *DlgEdit::GetStringAddr()
279 #if defined(PROJECT_DI_MEMOEDIT)
281 if (Type
== DLGEDIT_MULTILINE
) {
282 return nullptr; //??? //multiEdit;
285 return lineEdit
->GetStringAddr();
288 void DlgEdit::SetHiString(const wchar_t *Str
)
290 #if defined(PROJECT_DI_MEMOEDIT)
292 if (Type
== DLGEDIT_MULTILINE
) {
296 lineEdit
->SetHiString(Str
);
299 void DlgEdit::SetString(const wchar_t *Str
)
301 #if defined(PROJECT_DI_MEMOEDIT)
303 if (Type
== DLGEDIT_MULTILINE
) {
307 lineEdit
->SetString(Str
);
310 void DlgEdit::InsertString(const wchar_t *Str
)
312 #if defined(PROJECT_DI_MEMOEDIT)
313 if (Type
== DLGEDIT_MULTILINE
) {
317 lineEdit
->InsertString(Str
);
320 void DlgEdit::GetString(wchar_t *Str
, int MaxSize
, int Row
)
322 #if defined(PROJECT_DI_MEMOEDIT)
324 if (Type
== DLGEDIT_MULTILINE
) {
328 lineEdit
->GetString(Str
, MaxSize
);
331 void DlgEdit::GetString(FARString
&strStr
, int Row
)
333 #if defined(PROJECT_DI_MEMOEDIT)
335 if (Type
== DLGEDIT_MULTILINE
) {
339 lineEdit
->GetString(strStr
);
342 void DlgEdit::SetCurPos(int NewCol
, int NewRow
) // Row==-1 - current line
344 #if defined(PROJECT_DI_MEMOEDIT)
346 if (Type
== DLGEDIT_MULTILINE
)
347 multiEdit
->SetCurPos(NewCol
, NewRow
);
350 lineEdit
->SetCurPos(NewCol
);
353 int DlgEdit::GetCurPos()
355 #if defined(PROJECT_DI_MEMOEDIT)
357 if (Type
== DLGEDIT_MULTILINE
)
358 return multiEdit
->GetCurPos(); // GetCurCol???
361 return lineEdit
->GetCurPos();
364 int DlgEdit::GetCurRow()
366 #if defined(PROJECT_DI_MEMOEDIT)
368 if (Type
== DLGEDIT_MULTILINE
)
369 return multiEdit
->GetCurRow();
375 int DlgEdit::GetCellCurPos()
377 #if defined(PROJECT_DI_MEMOEDIT)
379 if (Type
== DLGEDIT_MULTILINE
)
380 return multiEdit
->GetCurPos(); // GetCurCol???
383 return lineEdit
->GetCellCurPos();
386 void DlgEdit::SetCellCurPos(int NewPos
)
388 #if defined(PROJECT_DI_MEMOEDIT)
390 if (Type
== DLGEDIT_MULTILINE
)
391 multiEdit
->SetCurPos(NewPos
, multiEdit
->GetCurRow()); //???
394 lineEdit
->SetCellCurPos(NewPos
);
397 void DlgEdit::SetPersistentBlocks(int Mode
)
399 #if defined(PROJECT_DI_MEMOEDIT)
401 if (Type
== DLGEDIT_MULTILINE
)
402 multiEdit
->SetPersistentBlocks(Mode
);
405 lineEdit
->SetPersistentBlocks(Mode
);
408 int DlgEdit::GetPersistentBlocks()
410 #if defined(PROJECT_DI_MEMOEDIT)
412 if (Type
== DLGEDIT_MULTILINE
)
413 return multiEdit
->GetPersistentBlocks();
416 return lineEdit
->GetPersistentBlocks();
419 void DlgEdit::SetDelRemovesBlocks(int Mode
)
421 #if defined(PROJECT_DI_MEMOEDIT)
423 if (Type
== DLGEDIT_MULTILINE
)
424 multiEdit
->SetDelRemovesBlocks(Mode
);
427 lineEdit
->SetDelRemovesBlocks(Mode
);
430 int DlgEdit::GetDelRemovesBlocks()
432 #if defined(PROJECT_DI_MEMOEDIT)
434 if (Type
== DLGEDIT_MULTILINE
)
435 return multiEdit
->GetDelRemovesBlocks();
438 return lineEdit
->GetDelRemovesBlocks();
441 void DlgEdit::SetObjectColor(int Color
, int SelColor
, int ColorUnChanged
)
443 #if defined(PROJECT_DI_MEMOEDIT)
445 if (Type
== DLGEDIT_MULTILINE
)
446 multiEdit
->SetObjectColor(Color
, SelColor
, ColorUnChanged
);
449 lineEdit
->SetObjectColor(Color
, SelColor
, ColorUnChanged
);
452 long DlgEdit::GetObjectColor()
454 #if defined(PROJECT_DI_MEMOEDIT)
456 if (Type
== DLGEDIT_MULTILINE
)
457 return 0; // multiEdit->GetObjectColor();
460 return lineEdit
->GetObjectColor();
463 int DlgEdit::GetObjectColorUnChanged()
465 #if defined(PROJECT_DI_MEMOEDIT)
467 if (Type
== DLGEDIT_MULTILINE
)
468 return 0; // multiEdit->GetObjectColorUnChanged();
471 return lineEdit
->GetObjectColorUnChanged();
474 void DlgEdit::FastShow()
476 #if defined(PROJECT_DI_MEMOEDIT)
478 if (Type
== DLGEDIT_MULTILINE
)
479 ; // multiEdit->FastShow();
482 lineEdit
->FastShow();
485 int DlgEdit::GetLeftPos()
487 #if defined(PROJECT_DI_MEMOEDIT)
489 if (Type
== DLGEDIT_MULTILINE
)
490 return 0; // multiEdit->GetLeftPos();
493 return lineEdit
->GetLeftPos();
496 void DlgEdit::SetLeftPos(int NewPos
, int Row
) // Row==-1 - current line
498 #if defined(PROJECT_DI_MEMOEDIT)
500 if (Type
== DLGEDIT_MULTILINE
)
501 ; // multiEdit->SetLeftPos(NewPos,Row);
504 lineEdit
->SetLeftPos(NewPos
);
507 void DlgEdit::DeleteBlock()
509 #if defined(PROJECT_DI_MEMOEDIT)
511 if (Type
== DLGEDIT_MULTILINE
)
512 multiEdit
->DeleteBlock();
515 lineEdit
->DeleteBlock();
518 int DlgEdit::GetLength()
520 #if defined(PROJECT_DI_MEMOEDIT)
522 if (Type
== DLGEDIT_MULTILINE
)
523 return 0; // multiEdit->GetLength();
526 return lineEdit
->GetLength();
529 void DlgEdit::Select(int Start
, int End
)
531 #if defined(PROJECT_DI_MEMOEDIT)
533 if (Type
== DLGEDIT_MULTILINE
)
534 ; // multiEdit->Select(Start,End);
537 lineEdit
->Select(Start
, End
);
540 void DlgEdit::GetSelection(int &Start
, int &End
)
542 #if defined(PROJECT_DI_MEMOEDIT)
544 if (Type
== DLGEDIT_MULTILINE
)
545 ; // multiEdit->GetSelection();
548 lineEdit
->GetSelection(Start
, End
);
551 void DlgEdit::Xlat(bool All
)
553 #if defined(PROJECT_DI_MEMOEDIT)
555 if (Type
== DLGEDIT_MULTILINE
)
562 int DlgEdit::GetStrSize(int Row
)
564 #if defined(PROJECT_DI_MEMOEDIT)
566 if (Type
== DLGEDIT_MULTILINE
)
567 return 0; // multiEdit->
570 return lineEdit
->StrSize
;
573 void DlgEdit::SetCursorType(bool Visible
, DWORD Size
)
575 #if defined(PROJECT_DI_MEMOEDIT)
577 if (Type
== DLGEDIT_MULTILINE
)
578 multiEdit
->SetCursorType(Visible
, Size
);
581 lineEdit
->SetCursorType(Visible
, Size
);
584 void DlgEdit::GetCursorType(bool &Visible
, DWORD
&Size
)
586 #if defined(PROJECT_DI_MEMOEDIT)
588 if (Type
== DLGEDIT_MULTILINE
)
589 multiEdit
->GetCursorType(Visible
, Size
);
592 lineEdit
->GetCursorType(Visible
, Size
);
595 int DlgEdit::GetReadOnly()
597 #if defined(PROJECT_DI_MEMOEDIT)
599 if (Type
== DLGEDIT_MULTILINE
)
600 return multiEdit
->GetReadOnly();
603 return lineEdit
->GetReadOnly();
606 void DlgEdit::SetReadOnly(int NewReadOnly
)
608 #if defined(PROJECT_DI_MEMOEDIT)
610 if (Type
== DLGEDIT_MULTILINE
)
611 multiEdit
->SetReadOnly(NewReadOnly
);
614 lineEdit
->SetReadOnly(NewReadOnly
);
617 BitFlags
&DlgEdit::Flags()
619 #if defined(PROJECT_DI_MEMOEDIT)
621 if (Type
== DLGEDIT_MULTILINE
)
622 return multiEdit
->Flags
;
625 return lineEdit
->Flags
;
630 #if defined(PROJECT_DI_MEMOEDIT)
632 if (Type
== DLGEDIT_MULTILINE
)
639 void DlgEdit::Hide0()
641 #if defined(PROJECT_DI_MEMOEDIT)
643 if (Type
== DLGEDIT_MULTILINE
)
650 void DlgEdit::ShowConsoleTitle()
652 #if defined(PROJECT_DI_MEMOEDIT)
654 if (Type
== DLGEDIT_MULTILINE
)
655 multiEdit
->ShowConsoleTitle();
658 lineEdit
->ShowConsoleTitle();
661 void DlgEdit::SetScreenPosition()
663 #if defined(PROJECT_DI_MEMOEDIT)
665 if (Type
== DLGEDIT_MULTILINE
)
666 multiEdit
->SetScreenPosition();
669 lineEdit
->SetScreenPosition();
672 void DlgEdit::ResizeConsole()
674 #if defined(PROJECT_DI_MEMOEDIT)
676 if (Type
== DLGEDIT_MULTILINE
)
677 multiEdit
->ResizeConsole();
680 lineEdit
->ResizeConsole();
683 int64_t DlgEdit::VMProcess(MacroOpcode OpCode
, void *vParam
, int64_t iParam
)
685 #if defined(PROJECT_DI_MEMOEDIT)
687 if (Type
== DLGEDIT_MULTILINE
)
688 return multiEdit
->VMProcess(OpCode
, vParam
, iParam
);
691 return lineEdit
->VMProcess(OpCode
, vParam
, iParam
);
694 void DlgEdit::EditChange(void *aParam
)
696 static_cast<DlgEdit
*>(aParam
)->DoEditChange();
699 void DlgEdit::DoEditChange()
701 if (m_Dialog
->IsInited()) {
702 SendDlgMessage((HANDLE
)m_Dialog
, DN_EDITCHANGE
, m_Index
, 0);
706 bool DlgEdit::HistoryGetSimilar(FARString
&strStr
, int LastCmdPartLength
, bool bAppend
)
708 return iHistory
? iHistory
->GetSimilar(strStr
, LastCmdPartLength
, bAppend
) : false;