-
Notifications
You must be signed in to change notification settings - Fork 0
/
DocumentFormUnit.cpp
88 lines (76 loc) · 2.62 KB
/
DocumentFormUnit.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// ---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "DocumentFormUnit.h"
#include "MainWindowUnit.h"
// ---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "SHDocVw_OCX"
#pragma resource "*.dfm"
TDocumentForm *DocumentForm;
// ---------------------------------------------------------------------------
__fastcall TDocumentForm::TDocumentForm(TComponent* Owner) : TForm(Owner) {
}
// Îáíîâëåíèå äîêóìåíòà ïðè îáíîâëåíèèè ñîäåðæèìîãî â RichEdit------------------
void __fastcall TDocumentForm::RichEdit1Change(TObject *Sender) {
if (RichEdit1->Lines->Text != doc->html) {
if (updatetimes > 1)
doc->setchanged(true);
else
updatetimes++;
doc->html = RichEdit1->Lines->Text;
}
if (RichEdit1->Focused()) {
doc->Update(RichEdit1->Lines->Text);
}
}
// ---------------------------------------------------------------------------
void __fastcall TDocumentForm::FormCreate(TObject *Sender) {
RichEdit1->PopupMenu = static_cast<TForm1*>(Application->MainForm)
->PopupMenu1;
browser = new BrowserSys(WebBrowser1, RichEdit1->PopupMenu);
doc = new HTMLDocument(RichEdit1, browser);
doc->setchanged(false);
updatetimes = 0;
}
// ---------------------------------------------------------------------------
void __fastcall TDocumentForm::FormDestroy(TObject *Sender) {
delete doc;
delete browser;
}
// Çàïðîñ íà çàêðûòèå ôîðìû äîêóìåíòà-------------------------------------------
void __fastcall TDocumentForm::FormCloseQuery(TObject *Sender, bool &CanClose) {
if (doc->changed()) {
int qresult;
qresult = MessageDlg("Ñîõðàíèòü òåêóùèé äîêóìåíò [" + Caption +
"] ïåðåä çàêðûòèåì", mtConfirmation,
TMsgDlgButtons() << mbYes << mbNo << mbCancel, 0);
if (qresult == mrNo)
CanClose = true;
else {
CanClose = false;
if (qresult == mrYes) {
TForm1 *form = (TForm1*)(Application->MainForm);
this->Activate();
form->acSaveFile->Execute();
}
}
}
else
CanClose = true;
if (CanClose) {
doc->setchanged(false);
}
}
// Èíèöèàëèçàöèÿ èíòåðôåéñîâ TWebBrowser----------------------------------------
void __fastcall TDocumentForm::WebBrowser1DocumentComplete(TObject *Sender,
LPDISPATCH pDisp, Variant *URL) {
if (browser->InitInterfaces())
browser->EditMode(true);
}
// ---------------------------------------------------------------------------
void __fastcall TDocumentForm::FormClose(TObject *Sender, TCloseAction &Action)
{
Action = caFree; // íåîáõîäèìî äëÿ àâòîóíè÷òîæåíèÿ ôîðìû ïðè çàêðûòèè
}
// ---------------------------------------------------------------------------