-
Notifications
You must be signed in to change notification settings - Fork 0
/
cEXWB.cs
6008 lines (5438 loc) · 231 KB
/
cEXWB.cs
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//************************************************************************************
// csEXWB control - The most complete C# Webbrowser control.
//
// Auther: MH
// Email: mehr13@hotmail.com
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so.
//
// Although reasonable care has been taken to ensure the correctness of this
// implementation, this code should never be used in
// any application without proper verification and testing.
//************************************************************************************
using System;
using System.ComponentModel;
using System.Windows.Forms;
using System.Drawing;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
using System.Security;
using IfacesEnumsStructsClasses;
using System.Diagnostics;
using System.Threading;
namespace csExWB
{
public class cEXWB :
Control,
IOleClientSite,
IOleInPlaceSite,
IDocHostShowUI,
IDocHostUIHandler,
DWebBrowserEvents2,
IfacesEnumsStructsClasses.IDropTarget,
IfacesEnumsStructsClasses.IServiceProvider,
IHttpSecurity,
IWindowForBindingUI,
INewWindowManager, //WinXP sp2 and up
IAuthenticate,
IOleCommandTarget,
IInternetSecurityManager,
IHTMLEventCallBack,
IProtectFocus, //IE7 + Vista
IHTMLOMWindowServices, //WinXP sp2 and up
IHTMLEditHost //Please refer to IHTMLEditHost.cs for description
{
#region Events and EventArgs Memebrs
public event csExWB.DocumentCompleteEventHandler DocumentComplete = null;
public event csExWB.BeforeNavigate2EventHandler BeforeNavigate2 = null;
public event csExWB.ClientToHostWindowEventHandler ClientToHostWindow = null;
public event csExWB.CommandStateChangeEventHandler CommandStateChange = null;
public event csExWB.DownloadBeginEventHandler DownloadBegin = null;
public event csExWB.DownloadCompleteEventHandler DownloadComplete = null;
public event csExWB.FileDownloadEventHandler FileDownload = null;
public event csExWB.NavigateComplete2EventHandler NavigateComplete2 = null;
public event csExWB.NavigateErrorEventHandler NavigateError = null;
public event csExWB.NewWindow2EventHandler NewWindow2 = null;
public event csExWB.NewWindow3EventHandler NewWindow3 = null;
public event csExWB.PrintTemplateInstantiationEventHandler PrintTemplateInstantiation = null;
public event csExWB.PrintTemplateTeardownEventHandler PrintTemplateTeardown = null;
public event csExWB.PrivacyImpactedStateChangeEventHandler PrivacyImpactedStateChange = null;
public event csExWB.ProgressChangeEventHandler ProgressChange = null;
public event csExWB.PropertyChangeEventHandler PropertyChange = null;
public event csExWB.SetSecureLockIconEventHandler SetSecureLockIcon = null;
public event csExWB.StatusTextChangeEventHandler StatusTextChange = null;
public event csExWB.TitleChangeEventHandler TitleChange = null;
public event csExWB.WindowClosingEventHandler WindowClosing = null;
public event csExWB.WindowSetHeightEventHandler WindowSetHeight = null;
public event csExWB.WindowSetLeftEventHandler WindowSetLeft = null;
public event csExWB.WindowSetResizableEventHandler WindowSetResizable = null;
public event csExWB.WindowSetTopEventHandler WindowSetTop = null;
public event csExWB.WindowSetWidthEventHandler WindowSetWidth = null;
public event csExWB.WBDragEnterEventHandler WBDragEnter = null;
public event csExWB.WBDragLeaveEventHandler WBDragLeave = null;
public event csExWB.WBDragOverEventHandler WBDragOver = null;
public event csExWB.WBDropEventHandler WBDragDrop = null;
public event csExWB.WBKeyDownEventHandler WBKeyDown = null;
public event csExWB.WBKeyUpEventHandler WBKeyUp = null;
public event csExWB.ContextMenuEventHandler WBContextMenu = null;
public event csExWB.GetOptionKeyPathEventHandler WBGetOptionKeyPath = null;
public event csExWB.DocHostShowUIShowMessageEventHandler WBDocHostShowUIShowMessage = null;
public event csExWB.DocumentCompleteExEventHandler DocumentCompleteEX = null;
public event csExWB.AuthenticateEventHandler WBAuthenticate = null;
public event csExWB.SecurityProblemEventHandler WBSecurityProblem = null;
public event csExWB.EvaluateNewWindowEventHandler WBEvaluteNewWindow = null;
public event csExWB.ScriptErrorEventHandler ScriptError = null;
public event csExWB.UpdatePageStatusEventHandler UpdatePageStatus = null;
public event csExWB.RefreshBeginEventHandler RefreshBegin = null;
public event csExWB.RefreshEndEventHandler RefreshEnd = null;
public event csExWB.ProcessUrlActionEventHandler ProcessUrlAction = null;
public event csExWB.AllowFocusChangeEventHandler AllowFocusChange = null;
public event csExWB.HTMLOMWindowServicesEventHandler HTMLOMWindowServices_moveTo = null;
public event csExWB.HTMLOMWindowServicesEventHandler HTMLOMWindowServices_moveBy = null;
public event csExWB.HTMLOMWindowServicesEventHandler HTMLOMWindowServices_resizeTo = null;
public event csExWB.HTMLOMWindowServicesEventHandler HTMLOMWindowServices_resizeBy = null;
public event csExWB.HTMLEventHandler HTMLEvent = null;
private HTMLEventArgs HtmlEventArg = new HTMLEventArgs();
private TitleChangeEventArgs TitleChangeEvent = new TitleChangeEventArgs();
private DocumentCompleteEventArgs DocumentCompleteEvent = new DocumentCompleteEventArgs();
private DocumentCompleteExEventArgs DocumentCompleteExEvent = new DocumentCompleteExEventArgs();
private StatusTextChangeEventArgs StatusTextChangeEvent = new StatusTextChangeEventArgs();
private ProgressChangeEventArgs ProgressChangeEvent = new ProgressChangeEventArgs();
private CommandStateChangeEventArgs CommandStateChangeEvent = new CommandStateChangeEventArgs();
private PropertyChangeEventArgs PropertyChangeEvent = new PropertyChangeEventArgs();
private BeforeNavigate2EventArgs BeforeNavigate2Event = new BeforeNavigate2EventArgs();
private NavigateComplete2EventArgs NavigateComplete2Event = new NavigateComplete2EventArgs();
private NewWindow2EventArgs NewWindow2Event = new NewWindow2EventArgs();
private NewWindow3EventArgs NewWindow3Event = new NewWindow3EventArgs();
private WindowSetResizableEventArgs WindowSetResizableEvent = new WindowSetResizableEventArgs();
private WindowSetLeftEventArgs WindowSetLeftEvent = new WindowSetLeftEventArgs();
private WindowSetTopEventArgs WindowSetTopEvent = new WindowSetTopEventArgs();
private WindowSetWidthEventArgs WindowSetWidthEvent = new WindowSetWidthEventArgs();
private WindowSetHeightEventArgs WindowSetHeightEvent = new WindowSetHeightEventArgs();
private WindowClosingEventArgs WindowClosingEvent = new WindowClosingEventArgs();
private ClientToHostWindowEventArgs ClientToHostWindowEvent = new ClientToHostWindowEventArgs();
private SetSecureLockIconEventArgs SetSecureLockIconEvent = new SetSecureLockIconEventArgs();
private FileDownloadEventArgs FileDownloadEvent = new FileDownloadEventArgs();
private NavigateErrorEventArgs NavigateErrorEvent = new NavigateErrorEventArgs();
private PrintTemplateInstantiationEventArgs PrintTemplateInstantiationEvent = new PrintTemplateInstantiationEventArgs();
private PrintTemplateTeardownEventArgs PrintTemplateTeardownEvent = new PrintTemplateTeardownEventArgs();
private PrivacyImpactedStateChangeEventArgs PrivacyImpactedStateChangeEvent = new PrivacyImpactedStateChangeEventArgs();
private UpdatePageStatusEventArgs UpdatePageStatusEvent = new UpdatePageStatusEventArgs();
private DocHostShowUIShowMessageEventArgs DocHostShowUIShowMessageEvent = new DocHostShowUIShowMessageEventArgs();
private ContextMenuEventArgs ContextMenuEvent = new ContextMenuEventArgs();
private GetOptionKeyPathEventArgs GetOptionKeyPathEvent = new GetOptionKeyPathEventArgs();
private WBKeyDownEventArgs WBKeyDownEvent = new WBKeyDownEventArgs();
private WBKeyUpEventArgs WBKeyUpEvent = new WBKeyUpEventArgs();
private EvaluateNewWindowEventArgs EvaluateNewWindowEvent = new EvaluateNewWindowEventArgs();
private SecurityProblemEventArgs SecurityProblemEvent = new SecurityProblemEventArgs();
private AuthenticateEventArgs AuthenticateEvent = new AuthenticateEventArgs();
private WBDragEnterEventArgs WBDragEnterEvent = new WBDragEnterEventArgs();
private WBDragOverEventArgs WBDragOverEvent = new WBDragOverEventArgs();
private WBDropEventArgs WBDropEvent = new WBDropEventArgs();
private ScriptErrorEventArgs ScriptErrorEvent = new ScriptErrorEventArgs();
private ProcessUrlActionEventArgs ProcessUrlActionEvent = new ProcessUrlActionEventArgs();
private AllowFocusChangeEventArgs AllowFocusChangeEvent = new AllowFocusChangeEventArgs();
private HTMLOMWindowServicesEventArgs HTMLOMWindowServicesEvent = new HTMLOMWindowServicesEventArgs();
#endregion //Events and EventArgs Memebrs
#region Local members
//Required by designer
private System.ComponentModel.IContainer components = null;
//Use the internal dragdrop in combination with WBDrag/Drop events
private bool m_bUseInternalDragDrop = true;
//Fires DocumentCompleteEx, with an additional parameter "docsource"
//containning the source of the incoming document before any scripts
//are executed.
private bool m_bSendSourceOnDocumentCompleteWBEx = false;
//this.Control->ShellEmbedding->ShellDocObj->IEServer
private IntPtr m_hWBServerHandle = (IntPtr)0;
private IntPtr m_hWBShellDocObjHandle = (IntPtr)0;
private IntPtr m_hWBShellEmbeddingHandle = (IntPtr)0;
//Startup URL + LocationUrl
private const string m_AboutBlank = "about:blank";
private string m_sUrl = "about:blank";
private bool m_bCanGoBack = false;
private bool m_bCanGoForward = false;
private TextSizeWB m_enumTextSize = TextSizeWB.Medium; //default
//Default, selecttext+no3dborder+flatscrollbars+themes(xp look)
private DOCHOSTUIFLAG m_DocHostUiFlags = DOCHOSTUIFLAG.NO3DBORDER |
DOCHOSTUIFLAG.FLAT_SCROLLBAR | DOCHOSTUIFLAG.THEME;
private DOCHOSTUIDBLCLK m_DocHostUiDbClkFlag = DOCHOSTUIDBLCLK.DEFAULT;
//DLCTL_DLIMAGES
private DOCDOWNLOADCTLFLAG m_DLCtlFlags = DOCDOWNLOADCTLFLAG.DLIMAGES |
DOCDOWNLOADCTLFLAG.BGSOUNDS | DOCDOWNLOADCTLFLAG.VIDEOS;
//Used in find
private IHTMLTxtRange m_txtrange = null;
private string m_sLastSearch = string.Empty;
//Pointer to our browser interface
private IWebBrowser2 m_WBWebBrowser2 = null;
//IntPtr.Zero
private IntPtr m_NullPointer = IntPtr.Zero;
private tagMSG m_NullMsg = new tagMSG();
private object m_NullObject = null;
//ConnectionPoint Cookie
private int m_dwCookie = 0;
//Keep track of our location + size
private tagRECT m_WBRect = new tagRECT(0, 0, 0, 0);
//WB IUnknown and other ifaces
private object m_WBUnknown = null;
private IOleObject m_WBOleObject = null;
private IOleInPlaceObject m_WBOleInPlaceObject = null;
private IOleCommandTarget m_WBOleCommandTarget = null;
///Taken from article:
///Invoke Hidden Commands in Your Web Browser
///http://www.codeguru.com/cpp/i-n/ieprogram/openfaq/article.php/c8163/
///As I stated above, the IDocHostUIHandler::ShowContextMenu demo of
///"WebBrowser Customization" in the MSDN shows a way to manually build
///IE's context menu from correlative resource file "SHDOCLC.DLL".
///So, open the file "SHDOCLC.DLL" by using some resource explorer software
///such as "eXeScope", we can find all the Command IDs (also menu item IDs)
///used by the WebBrowser Control under menu resources, and all of them are
///the same in IE 4.x/5.x/6.x according to my tesing.
//command send to IE server hwnd
private const int ID_IE_CONTEXTMENU_ADDFAV = 2261;
//comands send to shelldocobject hwnd
private const int ID_IE_FIND = 67;
private const int ID_IE_PAGESETUP = 259;
private const int ID_IE_PRINT = 260;
private const int ID_IE_PRINTPREVIEW = 277;
private const int ID_IE_FILE_NEWMAIL = 279;
private const int ID_IE_FILE_SENDPAGE = 282;
private const int ID_IE_FILE_SENDLINK = 283;
private const int ID_IE_FILE_SENDDESKTOPSHORTCUT = 284;
private const int ID_IE_FILE_IMPORTEXPORT = 374;
private const int ID_IE_FILE_ADDTRUST = 376;
private const int ID_IE_FILE_ADDLOCAL = 377;
private const int ID_IE_FILE_NEWCALL = 395; //Internet call
//To catch Refresh event!
// counter to monitor number of requests to BeforeNavigate2 vs number of requests to DownloadBegin.
private int m_nPageCounter = 0;
// counter to monitor number of DownloadBegin and DownloadEnd calls.
private int m_nObjCounter = 0;
// variable to tell us whether a refresh request has started.
private bool m_bIsRefresh = false;
//browser thumb image cache
private Image m_WBThumbImg = null;
//Used to handle HtmlDocument and HtmlWindow events
private bool m_WantHTMLEvents = false;
private bool m_WantHtmlDocumentEvents = false;
private bool m_WantHtmlWindowEvents = false;
//These instances take care of the toplevel document and window
//For frameset sites, we use a collection of below classes
private cHTMLDocumentEvents m_TopLevelHtmlDocumentevents = new cHTMLDocumentEvents();
private cHTMLWindowEvents m_TopLevelHtmlWindowEvents = new cHTMLWindowEvents();
//Template based lists
private List<cHTMLDocumentEvents> m_HtmlDocumentEventsList = new List<cHTMLDocumentEvents>();
private List<cHTMLWindowEvents> m_HtmlWindowEventsList = new List<cHTMLWindowEvents>();
private int m_SecureLockIcon = (int)SecureLockIconConstants.secureLockIconUnsecure;
private object m_WinExternal = null;
//allow or disallow HTML dialogs launched using showModelessDialog() + showModalDialog() methods!
//Using CBT window hook
private WindowsHookUtil.HookInfo m_CBT = new WindowsHookUtil.HookInfo(CSEXWBDLMANLib.WINDOWSHOOK_TYPES.WHT_CBT);
private const string m_HTMLDlgClassName = "Internet Explorer_TridentDlgFrame";
private IntPtr m_HookHandled = IntPtr.Zero;
private string m_strTemp = string.Empty;
private int m_NCode = 0;
//To subclass Internet Explorer_Server handle in order to catch back and forward buttons
private IEServerWindow m_ieServerWindow = null;
private bool m_DocDone = false;
#endregion //Local members
#region Properties list
[Category("ExWB")]
public bool MainDocumentFullyLoaded
{
get { return m_DocDone; }
}
[Category("DOCDOWNLOADCTLFLAG")]
public int WBDOCDOWNLOADCTLFLAG
{
get { return (int)m_DLCtlFlags; }
set
{
m_DLCtlFlags = (DOCDOWNLOADCTLFLAG)value;
if( ( m_WBUnknown != null ) && (m_WBWebBrowser2 != null) )
{
//Signal change of DL property
//so MSHTML call our Invoke method through Dispatch
//Otherwise refreshing the page will have no effect
//MSHTML does not know of new flags set by us
//QI for IOleControl
IOleControl pOC = m_WBUnknown as IOleControl;
if(pOC != null)
pOC.OnAmbientPropertyChange(HTMLDispIDs.DISPID_AMBIENT_DLCONTROL);
}
}
}
[Category("DOCDOWNLOADCTLFLAG")]
public bool DownloadImages
{
get { return ((m_DLCtlFlags & DOCDOWNLOADCTLFLAG.DLIMAGES) != 0); }
set { SynchDOCDOWNLOADCTLFLAG(DOCDOWNLOADCTLFLAG.DLIMAGES, value); }
}
[Category("DOCDOWNLOADCTLFLAG")]
public bool DownloadSounds
{
get { return ((m_DLCtlFlags & DOCDOWNLOADCTLFLAG.BGSOUNDS) != 0); }
set { SynchDOCDOWNLOADCTLFLAG(DOCDOWNLOADCTLFLAG.BGSOUNDS, value); }
}
[Category("DOCDOWNLOADCTLFLAG")]
public bool DownloadVideo
{
get { return ((m_DLCtlFlags & DOCDOWNLOADCTLFLAG.VIDEOS) != 0); }
set { SynchDOCDOWNLOADCTLFLAG(DOCDOWNLOADCTLFLAG.VIDEOS, value); }
}
[Category("DOCDOWNLOADCTLFLAG")]
public bool DownloadActiveX
{
get { return ((m_DLCtlFlags & DOCDOWNLOADCTLFLAG.NO_DLACTIVEXCTLS) == 0); }
set
{
if (value)
SynchDOCDOWNLOADCTLFLAG(DOCDOWNLOADCTLFLAG.NO_DLACTIVEXCTLS, false);
else
SynchDOCDOWNLOADCTLFLAG(DOCDOWNLOADCTLFLAG.NO_DLACTIVEXCTLS, true);
}
}
[Category("DOCDOWNLOADCTLFLAG")]
public bool DownloadJava
{
get { return ((m_DLCtlFlags & DOCDOWNLOADCTLFLAG.NO_JAVA) == 0); }
set
{
if (value)
SynchDOCDOWNLOADCTLFLAG(DOCDOWNLOADCTLFLAG.NO_JAVA, false);
else
SynchDOCDOWNLOADCTLFLAG(DOCDOWNLOADCTLFLAG.NO_JAVA, true);
}
}
[Category("DOCDOWNLOADCTLFLAG")]
public bool DownloadFrames
{
get { return ((m_DLCtlFlags & DOCDOWNLOADCTLFLAG.NO_FRAMEDOWNLOAD) == 0); }
set
{
if (value)
SynchDOCDOWNLOADCTLFLAG(DOCDOWNLOADCTLFLAG.NO_FRAMEDOWNLOAD, false);
else
SynchDOCDOWNLOADCTLFLAG(DOCDOWNLOADCTLFLAG.NO_FRAMEDOWNLOAD, true);
}
}
[Category("DOCDOWNLOADCTLFLAG")]
public bool DownloadScripts
{
get { return ((m_DLCtlFlags & DOCDOWNLOADCTLFLAG.NO_SCRIPTS) == 0); }
set
{
if (value)
SynchDOCDOWNLOADCTLFLAG(DOCDOWNLOADCTLFLAG.NO_SCRIPTS, false);
else
SynchDOCDOWNLOADCTLFLAG(DOCDOWNLOADCTLFLAG.NO_SCRIPTS, true);
}
}
[Category("DOCHOSTUIFLAG")]
public int WBDOCHOSTUIFLAG
{
get { return (int)m_DocHostUiFlags; }
set { m_DocHostUiFlags = (DOCHOSTUIFLAG)value; }
}
[Category("DOCHOSTUIFLAG")]
public bool Border3DEnabled
{
get { return ((m_DocHostUiFlags & DOCHOSTUIFLAG.NO3DBORDER) == 0); }
set
{
if(value)
SynchDOCHOSTUIFLAG(DOCHOSTUIFLAG.NO3DBORDER, false);
else
SynchDOCHOSTUIFLAG(DOCHOSTUIFLAG.NO3DBORDER, true);
}
}
[Category("DOCHOSTUIFLAG")]
public bool ScrollBarsEnabled
{
get { return ((m_DocHostUiFlags & DOCHOSTUIFLAG.SCROLL_NO) == 0); }
set
{
if (value)
{
SynchDOCHOSTUIFLAG(DOCHOSTUIFLAG.SCROLL_NO, false);
SynchDOCHOSTUIFLAG(DOCHOSTUIFLAG.FLAT_SCROLLBAR, value);
}
else
{
SynchDOCHOSTUIFLAG(DOCHOSTUIFLAG.FLAT_SCROLLBAR, false);
SynchDOCHOSTUIFLAG(DOCHOSTUIFLAG.SCROLL_NO, true);
}
}
}
[Category("DOCHOSTUIDBLCLK")]
public DOCHOSTUIDBLCLK WBDOCHOSTUIDBLCLK
{
get { return m_DocHostUiDbClkFlag; }
set { m_DocHostUiDbClkFlag = value; }
}
[Category("ExWB")]
public SecureLockIconConstants SecureLockIcon
{
get
{
return (SecureLockIconConstants)m_SecureLockIcon;
}
}
[Category("ExWB")]
public TextSizeWB TextSize
{
get
{
if (m_WBOleCommandTarget != null)
{
object retVal = new object(); //VT_NULL
IntPtr pRet = m_NullPointer;
int iZoom = (int)5;
try
{
pRet = Marshal.AllocCoTaskMem((int)1024);
Marshal.GetNativeVariantForObject(retVal, pRet);
//NULL to specify the standard group
int hr = m_WBOleCommandTarget.Exec(m_NullPointer,
(uint)OLECMDID.OLECMDID_ZOOM,
(uint)OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER,
m_NullPointer, pRet);
retVal = Marshal.GetObjectForNativeVariant(pRet);
Marshal.FreeCoTaskMem(pRet);
pRet = m_NullPointer;
if (Type.GetTypeCode(retVal.GetType()) == TypeCode.Int32)
iZoom = int.Parse(retVal.ToString());
//else
// Debug.Write("Incorrect TypeCode!", "Get_TextSizeWB");
}
catch (Exception)
{
}
finally
{
if (pRet != m_NullPointer)
Marshal.FreeCoTaskMem(pRet);
}
if((iZoom > -1) && (iZoom < 5) )
m_enumTextSize = (TextSizeWB)iZoom;
}
return m_enumTextSize;
}
set
{
if (m_WBOleCommandTarget != null)
{
if (((int)value > (int)-1) && ((int)value < (int)5))
{
IntPtr pRet = m_NullPointer;
try
{
pRet = Marshal.AllocCoTaskMem((int)1024);
Marshal.GetNativeVariantForObject((int)value, pRet);
int hr = m_WBOleCommandTarget.Exec(m_NullPointer,
(uint)OLECMDID.OLECMDID_ZOOM,
(uint)OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER,
pRet, m_NullPointer);
Marshal.FreeCoTaskMem(pRet);
pRet = m_NullPointer;
if (hr == Hresults.S_OK)
m_enumTextSize = (TextSizeWB)value;
}
catch (Exception)
{
}
finally
{
if (pRet != m_NullPointer)
Marshal.FreeCoTaskMem(pRet);
}
}
}
}
}
[Category("ExWB")]
public bool CanGoBack
{
get { return m_bCanGoBack; }
}
[Category("ExWB")]
public bool CanGoForward
{
get { return m_bCanGoForward; }
}
[Category("ExWB")]
public IWebBrowser2 WebbrowserObject
{
get { return m_WBWebBrowser2; }
}
[Category("ExWB"), Description("true, fires DocumentCompleteEX instead of DocumentComplete passing source of the pDisp Document.")]
public bool SendSourceOnDocumentCompleteWBEx
{
get { return m_bSendSourceOnDocumentCompleteWBEx; }
set { m_bSendSourceOnDocumentCompleteWBEx = value; }
}
[Category("ExWB"), Description("Internet Explorer_Server HWND")]
public IntPtr IEServerHwnd
{
get {return WBIEServerHandle();}
}
[Category("ExWB"), Description("ShellEmbedding HWND")]
public IntPtr ShellEmbedingHwnd
{
get { return WBShellEmbedingHandle(); }
}
[Category("ExWB"), Description("ShellDocObject HWND")]
public IntPtr ShellDocObjectHwnd
{
get { return WBShellDocObjHandle(); }
}
[Category("ExWB"),
Description("Allows default drag drop operations. Default false. To use internal drag drop, set RegisterForInternalDragDrop to true. Setting this property to true will deactivate internal drag drop.")]
public bool RegisterAsDropTarget
{
get
{
if (m_WBWebBrowser2 != null)
return m_WBWebBrowser2.RegisterAsDropTarget;
else
return false;
}
set
{
if (m_WBWebBrowser2 != null)
m_WBWebBrowser2.RegisterAsDropTarget = value;
if (value)
this.RegisterForInternalDragDrop = false;
}
}
[Category("ExWB"),
Description("Uses internal drag drop events to notify the client. Default true.")]
public bool RegisterForInternalDragDrop
{
get
{
return m_bUseInternalDragDrop;
}
set
{
m_bUseInternalDragDrop = value;
//Make sure we set RegisterAsDropTarget to false
if( (m_bUseInternalDragDrop) && (m_WBWebBrowser2 != null) )
this.RegisterAsDropTarget = false;
}
}
[ Category("ExWB") ]
public bool RegisterAsBrowser
{
//MessageBox(IntPtr.Zero, "", "", 0);
get
{
if (m_WBWebBrowser2 != null)
return m_WBWebBrowser2.RegisterAsBrowser;
else
return false;
}
set
{
if (m_WBWebBrowser2 != null)
m_WBWebBrowser2.RegisterAsBrowser = value;
}
}
[Category("ExWB")]
public bool Silent
{
get
{
if (m_WBWebBrowser2 != null)
return m_WBWebBrowser2.Silent;
else
return false;
}
set
{
if (m_WBWebBrowser2 != null)
m_WBWebBrowser2.Silent = value;
}
}
[Category("ExWB")]
public string LocationName
{
get
{
if (m_WBWebBrowser2 != null)
return m_WBWebBrowser2.LocationName;
else
return "Unavailable";
}
}
[Category("ExWB"), Description("Set or get current LocationURL. Works in design mode as well.")]
public string LocationUrl
{
//Treat it as URL
get
{
if( (!DesignMode) && (m_WBWebBrowser2 != null) )
m_sUrl = m_WBWebBrowser2.LocationURL;
if (m_sUrl.Length == 0)
m_sUrl = "about:blank";
return m_sUrl;
}
set
{
m_sUrl = value;
if( (m_WBWebBrowser2 != null) && (m_sLastSearch.Length > 0) )
this.Navigate(m_sUrl);
}
}
[Category("ExWB")]
public bool Busy
{
get
{
if (m_WBWebBrowser2 != null)
return m_WBWebBrowser2.Busy;
else
return false;
}
}
[Category("ExWB")]
public bool OffLine
{
get
{
if (m_WBWebBrowser2 != null)
return m_WBWebBrowser2.Offline;
else
return false;
}
set
{
if (m_WBWebBrowser2 != null)
m_WBWebBrowser2.Offline = value;
}
}
[Category("ExWB")]
public tagREADYSTATE ReadyState
{
get
{
if (m_WBWebBrowser2 != null)
return m_WBWebBrowser2.ReadyState;
else
return tagREADYSTATE.READYSTATE_UNINITIALIZED;
}
}
[Category("ExWB")]
public Image ThumbImage
{
get
{
if (m_WBThumbImg != null)
return m_WBThumbImg;
else
return new Bitmap(16, 16);
}
}
[Category("ExWB"), Description("Offers same functionality as ObjectForScripting of C# webbrowser wrapper control.")]
public object ObjectForScripting
{
get
{
return m_WinExternal;
}
set
{
m_WinExternal = value;
}
}
[Category("ExWB"), Description("Sets or retrieves the title of the document")]
public string DocumentTitle
{
get { return this.GetTitle(true); }
set
{
if( (this.m_WBWebBrowser2 != null) &&
(m_WBWebBrowser2.Document != null) )
{
IHTMLDocument2 doc2 = m_WBWebBrowser2.Document as IHTMLDocument2;
if (doc2 != null)
doc2.title = value;
}
}
}
[Category("ExWB"), Description("Sets or retrives the HTML source of the document")]
public string DocumentSource
{
get { return this.GetSource(true); }
set { this.LoadHtmlIntoBrowser(value); }
}
#endregion
#region Overriden members
public cEXWB()
{
////Set some styles in regard to painting. We don't
//this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
//this.SetStyle(ControlStyles.ResizeRedraw, true);
//this.SetStyle(ControlStyles.UserPaint, true);
//this.SetStyle(ControlStyles.Selectable, true);
//this.SetStyle(ControlStyles.StandardClick, true);
//this.SetStyle(ControlStyles.Opaque, true);
//this.SetStyle(ControlStyles.ContainerControl, true);
//components = new System.ComponentModel.Container();
//this.SuspendLayout();
//
// csEXWB
//
//this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
//this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
//this.Name = "csEXWB";
//this.Size = new System.Drawing.Size(287, 239);
//this.ResumeLayout(false);
}
protected override void OnGotFocus(EventArgs e)
{
base.OnGotFocus(e);
if (!this.DesignMode)
SetFocus();
}
//protected override void OnPaint(PaintEventArgs e)
//{
// e.Graphics.Clear(this.BackColor);
// //base.OnPaint(e);
//}
protected override void Dispose(bool disposing)
{
if( (disposing) && (!this.DesignMode) )
{
if (m_HookHandled != IntPtr.Zero)
Marshal.FreeHGlobal(m_HookHandled);
if (m_WBThumbImg != null)
m_WBThumbImg.Dispose();
InternalFreeWB();
if((components != null))
components.Dispose();
}
base.Dispose(disposing);
}
protected override void OnResize(EventArgs e)
{
base.OnResize(e);
this.SetLocation();
}
public override bool PreProcessMessage(ref Message msg)
{
bool handled = false;
if ((msg.Msg >= WindowsMessages.WM_KEYFIRST) && (msg.Msg <= WindowsMessages.WM_KEYLAST_NT501))
{
// If it's a key down, first see if the key combo is a command key
if (msg.Msg == WindowsMessages.WM_KEYDOWN)
{
handled = ProcessCmdKey(ref msg, (Keys)(int)msg.WParam | ModifierKeys);
}
if (!handled)
{
int keyCode = (int)msg.WParam;
// Don't let Trident eat Ctrl-PgUp/PgDn
if (((keyCode != (int)Keys.PageUp) &&
(keyCode != (int)Keys.PageDown)) ||
((ModifierKeys & Keys.Control) == 0))
{
tagMSG cm = new tagMSG();
cm.hwnd = msg.HWnd;
cm.message = msg.Msg;
cm.wParam = msg.WParam;
cm.lParam = msg.LParam;
IOleInPlaceActiveObject accele = m_WBUnknown as IOleInPlaceActiveObject;
if( (accele != null) &&
(accele.TranslateAccelerator(ref cm) == Hresults.S_OK) )
handled = true;
}
else
{
// WndProc for Ctrl-PgUp/PgDn is never called so call it directly here
WndProc(ref msg);
handled = true;
}
}
}
if (!handled)
{
handled = base.PreProcessMessage(ref msg);
}
return handled;
}
//private int m_wparam = 0;
//private KBDLLHOOKSTRUCT m_KBLL = new KBDLLHOOKSTRUCT();
//How to handle LLKeyboardHook
/*
if (m.Msg == m_KEYBOARD_LL.UniqueMsgID)
{
//To stop, set to handled
//m.Result = m_HookHandled;
m_wparam = (int)m.WParam;
//Get the structure
m_KBLL.Reset();
Marshal.PtrToStructure(m.LParam, m_KBLL);
//bCtlPressed = (Control.ModifierKeys & Keys.Control) != 0);
if (m_wparam == WindowsMessages.WM_KEYDOWN)
AppendText("KEYBOARD_LL_KEYDOWN=" + m_KBLL.vkCode.ToString() + "\r\n");
else if (m_wparam == WindowsMessages.WM_KEYUP)
AppendText("KEYBOARD_LL_KEYUP=" + m_KBLL.vkCode.ToString() + "\r\n");
else if (m_wparam == WindowsMessages.WM_SYSKEYDOWN)
AppendText("KEYBOARD_LL_SYSKEYDOWN=" + m_KBLL.vkCode.ToString() + "\r\n");
else if (m_wparam == WindowsMessages.WM_SYSKEYUP)
AppendText("KEYBOARD_LL_SYSKEYUP=" + m_KBLL.vkCode.ToString() + "\r\n");
}
*/
//private WindowsHookUtil.CBT_CREATEWND m_CBT_CREATEWND = new CBT_CREATEWND();
//private WindowsHookUtil.CREATESTRUCT m_CREATESTRUCT = new CREATESTRUCT();
protected override void WndProc(ref Message m)
{
if (m.Msg == m_CBT.UniqueMsgID)
{
m_csexwbCOMLib.HookProcNCode(CSEXWBDLMANLib.WINDOWSHOOK_TYPES.WHT_CBT,
ref m_NCode);
if (m_NCode == WindowsHookUtil.HCBT_CREATEWND)
{
//m.WParam contains handle to the new window
//One method of getting new window information
//Marshal.PtrToStructure(m.LParam, m_CBT_CREATEWND);
//Marshal.PtrToStructure(m_CBT_CREATEWND.lpcs, m_CREATESTRUCT);
//if (m_CREATESTRUCT.lpszClass != IntPtr.Zero)
//{
m_strTemp = WinApis.GetWindowClass(m.WParam); //Marshal.PtrToStringAnsi(m_CREATESTRUCT.lpszClass);
if (!string.IsNullOrEmpty(m_strTemp))
{
if (m_strTemp.Equals(m_HTMLDlgClassName, StringComparison.CurrentCultureIgnoreCase))
m.Result = m_HookHandled; //dismiss it
}
//}
}
}
else
base.WndProc(ref m);
}
//public override string ToString()
//{
// return "csEXWB 1.0.0.4";
// //return base.ToString();
//}
protected override void OnVisibleChanged(EventArgs e)
{
base.OnVisibleChanged(e);
if(m_WBOleObject == null)
return;
if(this.Visible)
m_WBOleObject.DoVerb((int)OLEDOVERB.OLEIVERB_SHOW, ref m_NullMsg, this, 0, this.Handle, ref m_WBRect);
else
m_WBOleObject.DoVerb((int)OLEDOVERB.OLEIVERB_HIDE, ref m_NullMsg, this, 0, this.Handle, ref m_WBRect);
}
protected override void OnHandleCreated(EventArgs e)
{
base.OnHandleCreated(e);
if (this.IsHandleCreated)
{
if (!this.DesignMode)
{
//CBT hook return value to stop an HTMLDialog
m_HookHandled = Marshal.AllocHGlobal(Marshal.SizeOf((Int32)1) + 1);
Marshal.WriteInt32(m_HookHandled, 1);
InitCOMLibrary();
}
InternalCreateWB();
}
}
public override void Refresh()
{
base.Refresh();
if( (m_WBWebBrowser2 != null) && (!this.DesignMode) )
m_WBWebBrowser2.Refresh();
}
#endregion
#region Private Method Members
//Called from resize event to adjust the size of browser
private void SetLocation()
{
if (m_WBOleInPlaceObject == null)
return;
bool brect = WinApis.GetClientRect(this.Handle, out m_WBRect);
//Setup H+W
m_WBRect.Right = m_WBRect.Right - m_WBRect.Left; //W
m_WBRect.Bottom = m_WBRect.Bottom - m_WBRect.Top; //H
m_WBRect.Left = 0;
m_WBRect.Top = 0;
m_WBOleInPlaceObject.SetObjectRects(ref m_WBRect, ref m_WBRect);
}
//Returns corresponding string for an HRESULT
private string HresultAsString(int iHRESULT)
{
string sRet = "S_OK";
if (iHRESULT == Hresults.S_OK)
{
return sRet;
}
else if (iHRESULT == Hresults.S_FALSE)
{
sRet = "S_FALSE";
}
else if (iHRESULT == Hresults.E_INVALIDARG)
{
sRet = "E_INVALIDARG";
}
else if (iHRESULT == Hresults.E_NOTIMPL)
{
sRet = "E_NOTIMPL";
}
else if (iHRESULT == Hresults.E_ABORT)
{
sRet = "E_ABORT";
}
else if (iHRESULT == Hresults.E_ACCESSDENIED)
{
sRet = "E_ACCESSDENIED";
}
else if (iHRESULT == Hresults.E_FAIL)
{
sRet = "E_FAIL";
}
else if (iHRESULT == Hresults.E_FLAGS)
{
sRet = "E_FLAGS";
}
else if (iHRESULT == Hresults.E_HANDLE)
{
sRet = "E_HANDLE";
}