Merge pull request #2212 from unxed/ctrl_yo
[far2l.git] / far2l / src / dlgedit.cpp
blob360e7a057108ee6936a308c22cc327c52c6b33ab
1 /*
2 dlgedit.cpp
4 Одиночная строка редактирования для диалога (как наследник класса Edit)
5 Мультиредактор
6 */
7 /*
8 Copyright (c) 1996 Eugene Roshal
9 Copyright (c) 2000 Far Group
10 All rights reserved.
12 Redistribution and use in source and binary forms, with or without
13 modification, are permitted provided that the following conditions
14 are met:
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"
38 #include "dialog.hpp"
39 #include "history.hpp"
41 DlgEdit::DlgEdit(Dialog *pOwner, unsigned Index, DLGEDITTYPE Type)
43 LastPartLength(-1),
44 m_Dialog(pOwner),
45 m_Index(Index),
46 Type(Type),
47 #if defined(PROJECT_DI_MEMOEDIT)
48 multiEdit(nullptr),
49 #endif
50 lineEdit(nullptr)
52 switch (Type) {
53 case DLGEDIT_MULTILINE:
54 #if defined(PROJECT_DI_MEMOEDIT)
55 multiEdit = new Editor(pOwner, true); // ??? (pOwner) ?
56 #endif
57 break;
58 case DLGEDIT_SINGLELINE: {
59 Edit::Callback callback = {true, EditChange, this};
61 iHistory = 0;
62 FarList *iList = 0;
63 DWORD iFlags = 0;
64 if (pOwner) {
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);
84 } break;
88 DlgEdit::~DlgEdit()
90 if (iHistory) {
91 delete iHistory;
94 if (lineEdit)
95 delete lineEdit;
97 #if defined(PROJECT_DI_MEMOEDIT)
99 if (multiEdit)
100 delete multiEdit;
102 #endif
105 int DlgEdit::ProcessKey(FarKey Key)
107 #if defined(PROJECT_DI_MEMOEDIT)
109 if (Type == DLGEDIT_MULTILINE)
110 return multiEdit->ProcessKey(Key);
111 else
112 #endif
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);
122 else
123 #endif
124 return lineEdit->ProcessMouse(MouseEvent);
127 void DlgEdit::DisplayObject()
129 #if defined(PROJECT_DI_MEMOEDIT)
131 if (Type == DLGEDIT_MULTILINE)
132 multiEdit->DisplayObject();
133 else
134 #endif
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);
144 else
145 #endif
146 lineEdit->SetPosition(X1, Y1, X2, Y2);
149 void DlgEdit::Show()
151 #if defined(PROJECT_DI_MEMOEDIT)
153 if (Type == DLGEDIT_MULTILINE)
154 multiEdit->Show();
155 else
156 #endif
157 lineEdit->Show();
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);
166 else
167 #endif
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);
177 else
178 #endif
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();
193 return 0;
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);
214 else
215 #endif
216 lineEdit->SetOvertypeMode(Mode);
219 int DlgEdit::GetOvertypeMode()
221 #if defined(PROJECT_DI_MEMOEDIT)
223 if (Type == DLGEDIT_MULTILINE)
224 return multiEdit->GetOvertypeMode();
225 else
226 #endif
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();
241 return L""; //???
244 void DlgEdit::SetEditBeyondEnd(int Mode)
246 #if defined(PROJECT_DI_MEMOEDIT)
248 if (Type == DLGEDIT_MULTILINE)
249 multiEdit->SetEditBeyondEnd(Mode);
250 else
251 #endif
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);
261 else
262 #endif
263 lineEdit->SetClearFlag(Flag);
266 int DlgEdit::GetClearFlag()
268 #if defined(PROJECT_DI_MEMOEDIT)
270 if (Type == DLGEDIT_MULTILINE)
271 return multiEdit->GetClearFlag();
272 else
273 #endif
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;
283 } else
284 #endif
285 return lineEdit->GetStringAddr();
288 void DlgEdit::SetHiString(const wchar_t *Str)
290 #if defined(PROJECT_DI_MEMOEDIT)
292 if (Type == DLGEDIT_MULTILINE) {
293 ; // multiEdit;
294 } else
295 #endif
296 lineEdit->SetHiString(Str);
299 void DlgEdit::SetString(const wchar_t *Str)
301 #if defined(PROJECT_DI_MEMOEDIT)
303 if (Type == DLGEDIT_MULTILINE) {
304 ; // multiEdit;
305 } else
306 #endif
307 lineEdit->SetString(Str);
310 void DlgEdit::InsertString(const wchar_t *Str)
312 #if defined(PROJECT_DI_MEMOEDIT)
313 if (Type == DLGEDIT_MULTILINE) {
314 ; // multiEdit;
315 } else
316 #endif
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) {
325 ; // multiEdit;
326 } else
327 #endif
328 lineEdit->GetString(Str, MaxSize);
331 void DlgEdit::GetString(FARString &strStr, int Row)
333 #if defined(PROJECT_DI_MEMOEDIT)
335 if (Type == DLGEDIT_MULTILINE) {
336 ; // multiEdit;
337 } else
338 #endif
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);
348 else
349 #endif
350 lineEdit->SetCurPos(NewCol);
353 int DlgEdit::GetCurPos()
355 #if defined(PROJECT_DI_MEMOEDIT)
357 if (Type == DLGEDIT_MULTILINE)
358 return multiEdit->GetCurPos(); // GetCurCol???
359 else
360 #endif
361 return lineEdit->GetCurPos();
364 int DlgEdit::GetCurRow()
366 #if defined(PROJECT_DI_MEMOEDIT)
368 if (Type == DLGEDIT_MULTILINE)
369 return multiEdit->GetCurRow();
370 else
371 #endif
372 return 0;
375 int DlgEdit::GetCellCurPos()
377 #if defined(PROJECT_DI_MEMOEDIT)
379 if (Type == DLGEDIT_MULTILINE)
380 return multiEdit->GetCurPos(); // GetCurCol???
381 else
382 #endif
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()); //???
392 else
393 #endif
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);
403 else
404 #endif
405 lineEdit->SetPersistentBlocks(Mode);
408 int DlgEdit::GetPersistentBlocks()
410 #if defined(PROJECT_DI_MEMOEDIT)
412 if (Type == DLGEDIT_MULTILINE)
413 return multiEdit->GetPersistentBlocks();
414 else
415 #endif
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);
425 else
426 #endif
427 lineEdit->SetDelRemovesBlocks(Mode);
430 int DlgEdit::GetDelRemovesBlocks()
432 #if defined(PROJECT_DI_MEMOEDIT)
434 if (Type == DLGEDIT_MULTILINE)
435 return multiEdit->GetDelRemovesBlocks();
436 else
437 #endif
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);
447 else
448 #endif
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();
458 else
459 #endif
460 return lineEdit->GetObjectColor();
463 int DlgEdit::GetObjectColorUnChanged()
465 #if defined(PROJECT_DI_MEMOEDIT)
467 if (Type == DLGEDIT_MULTILINE)
468 return 0; // multiEdit->GetObjectColorUnChanged();
469 else
470 #endif
471 return lineEdit->GetObjectColorUnChanged();
474 void DlgEdit::FastShow()
476 #if defined(PROJECT_DI_MEMOEDIT)
478 if (Type == DLGEDIT_MULTILINE)
479 ; // multiEdit->FastShow();
480 else
481 #endif
482 lineEdit->FastShow();
485 int DlgEdit::GetLeftPos()
487 #if defined(PROJECT_DI_MEMOEDIT)
489 if (Type == DLGEDIT_MULTILINE)
490 return 0; // multiEdit->GetLeftPos();
491 else
492 #endif
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);
502 else
503 #endif
504 lineEdit->SetLeftPos(NewPos);
507 void DlgEdit::DeleteBlock()
509 #if defined(PROJECT_DI_MEMOEDIT)
511 if (Type == DLGEDIT_MULTILINE)
512 multiEdit->DeleteBlock();
513 else
514 #endif
515 lineEdit->DeleteBlock();
518 int DlgEdit::GetLength()
520 #if defined(PROJECT_DI_MEMOEDIT)
522 if (Type == DLGEDIT_MULTILINE)
523 return 0; // multiEdit->GetLength();
524 else
525 #endif
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);
535 else
536 #endif
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();
546 else
547 #endif
548 lineEdit->GetSelection(Start, End);
551 void DlgEdit::Xlat(bool All)
553 #if defined(PROJECT_DI_MEMOEDIT)
555 if (Type == DLGEDIT_MULTILINE)
556 multiEdit->Xlat();
557 else
558 #endif
559 lineEdit->Xlat(All);
562 int DlgEdit::GetStrSize(int Row)
564 #if defined(PROJECT_DI_MEMOEDIT)
566 if (Type == DLGEDIT_MULTILINE)
567 return 0; // multiEdit->
568 else
569 #endif
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);
579 else
580 #endif
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);
590 else
591 #endif
592 lineEdit->GetCursorType(Visible, Size);
595 int DlgEdit::GetReadOnly()
597 #if defined(PROJECT_DI_MEMOEDIT)
599 if (Type == DLGEDIT_MULTILINE)
600 return multiEdit->GetReadOnly();
601 else
602 #endif
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);
612 else
613 #endif
614 lineEdit->SetReadOnly(NewReadOnly);
617 BitFlags &DlgEdit::Flags()
619 #if defined(PROJECT_DI_MEMOEDIT)
621 if (Type == DLGEDIT_MULTILINE)
622 return multiEdit->Flags;
623 else
624 #endif
625 return lineEdit->Flags;
628 void DlgEdit::Hide()
630 #if defined(PROJECT_DI_MEMOEDIT)
632 if (Type == DLGEDIT_MULTILINE)
633 multiEdit->Hide();
634 else
635 #endif
636 lineEdit->Hide();
639 void DlgEdit::Hide0()
641 #if defined(PROJECT_DI_MEMOEDIT)
643 if (Type == DLGEDIT_MULTILINE)
644 multiEdit->Hide0();
645 else
646 #endif
647 lineEdit->Hide0();
650 void DlgEdit::ShowConsoleTitle()
652 #if defined(PROJECT_DI_MEMOEDIT)
654 if (Type == DLGEDIT_MULTILINE)
655 multiEdit->ShowConsoleTitle();
656 else
657 #endif
658 lineEdit->ShowConsoleTitle();
661 void DlgEdit::SetScreenPosition()
663 #if defined(PROJECT_DI_MEMOEDIT)
665 if (Type == DLGEDIT_MULTILINE)
666 multiEdit->SetScreenPosition();
667 else
668 #endif
669 lineEdit->SetScreenPosition();
672 void DlgEdit::ResizeConsole()
674 #if defined(PROJECT_DI_MEMOEDIT)
676 if (Type == DLGEDIT_MULTILINE)
677 multiEdit->ResizeConsole();
678 else
679 #endif
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);
689 else
690 #endif
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;