From 9e772f2cd9f55a610950a3bf9f02efbb785126e9 Mon Sep 17 00:00:00 2001 From: "smeredith%netscape.com" Date: Tue, 18 Dec 2001 17:56:45 +0000 Subject: [PATCH] Merge with CCK_PREFEDIT branch. git-svn-id: svn://10.0.0.236/trunk@110720 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/cck/driver/StdAfx.h | 1 + mozilla/cck/driver/WizardMachine.aps | Bin 44952 -> 50672 bytes mozilla/cck/driver/WizardMachine.cpp | 9 + mozilla/cck/driver/WizardMachine.h | 1 + mozilla/cck/driver/WizardMachine.ncb | Bin 41984 -> 41984 bytes mozilla/cck/driver/WizardMachine.rc | 1014 ++++++++++++++----------- mozilla/cck/driver/WizardUI.cpp | 91 ++- mozilla/cck/driver/dlgadd.cpp | 46 ++ mozilla/cck/driver/dlgadd.h | 50 ++ mozilla/cck/driver/dlgeditprefstr.cpp | 152 ++++ mozilla/cck/driver/dlgeditprefstr.h | 65 ++ mozilla/cck/driver/dlgfind.cpp | 42 + mozilla/cck/driver/dlgfind.h | 48 ++ mozilla/cck/driver/interpret.cpp | 39 +- mozilla/cck/driver/makefile.win | 7 + mozilla/cck/driver/prefeditview.cpp | 715 +++++++++++++++++ mozilla/cck/driver/prefeditview.h | 106 +++ mozilla/cck/driver/prefelement.cpp | 292 +++++++ mozilla/cck/driver/prefelement.h | 43 ++ mozilla/cck/driver/prefgroup.cpp | 33 + mozilla/cck/driver/prefgroup.h | 23 + mozilla/cck/driver/res/bitmap1.bmp | Bin 1270 -> 790 bytes mozilla/cck/driver/resource.h | 32 +- mozilla/cck/driver/xmldomhelper.cpp | 123 +++ mozilla/cck/driver/xmldomhelper.h | 33 + mozilla/cck/ib/ib.cpp | 131 +++- 26 files changed, 2643 insertions(+), 453 deletions(-) create mode 100644 mozilla/cck/driver/dlgadd.cpp create mode 100644 mozilla/cck/driver/dlgadd.h create mode 100644 mozilla/cck/driver/dlgeditprefstr.cpp create mode 100644 mozilla/cck/driver/dlgeditprefstr.h create mode 100644 mozilla/cck/driver/dlgfind.cpp create mode 100644 mozilla/cck/driver/dlgfind.h create mode 100644 mozilla/cck/driver/prefeditview.cpp create mode 100644 mozilla/cck/driver/prefeditview.h create mode 100644 mozilla/cck/driver/prefelement.cpp create mode 100644 mozilla/cck/driver/prefelement.h create mode 100644 mozilla/cck/driver/prefgroup.cpp create mode 100644 mozilla/cck/driver/prefgroup.h create mode 100644 mozilla/cck/driver/xmldomhelper.cpp create mode 100644 mozilla/cck/driver/xmldomhelper.h diff --git a/mozilla/cck/driver/StdAfx.h b/mozilla/cck/driver/StdAfx.h index 12f69127c68..9576ba560b3 100644 --- a/mozilla/cck/driver/StdAfx.h +++ b/mozilla/cck/driver/StdAfx.h @@ -7,6 +7,7 @@ #include // MFC core and standard components #include // MFC extensions +#include // MFC support for Internet Explorer 4 Common Controls #ifndef _AFX_NO_AFXCMN_SUPPORT #include // MFC support for Windows Common Controls #endif // _AFX_NO_AFXCMN_SUPPORT diff --git a/mozilla/cck/driver/WizardMachine.aps b/mozilla/cck/driver/WizardMachine.aps index 98cd61d4caad439a20ce51f0cd97d388065077ab..1f93fbe1ff134d8dbc05911cd491b01d3797e84c 100644 GIT binary patch delta 6866 zcmdT|dvH|M8UOBvY!Y7KkrzvzAOU&q=ABp}o86nuCY#;3*+ibM%0p;@I6N9!9X6mX zDOw0Uj3UZI37`<6V`eJV(&As$8Qam?KOF0f)oDAZ*!r51QpfG@JLlegB#UFGfA#F# zz2|<9^F7aZzI%_nXZiGzw1HC1eyD8rgg34bxf@n*>G^Jtc*Qx#a;5Rmw$JA1Zf~d~ zs5g_N(oU0zyzZuOD5&e+cBe=01k^#3Nqp9pw;5jFD=9~DG<*GSJXcY! zB6qr6x=#-}LxCU!S5;G4?w}$CXQzRcA;k*93izGvlD&dT z6wnuNwdpX#Zm*L82g76scgGw1*{nLwY+^R@By3Ql&(&UNYDWtfHzI z&<~Hs5H(aS5oTsEaV^ylg`FLpVI~a+_0B+7(50JEud1W(052Zso;kaYZcik21^l64 zz-Ln0kyT5Dx2;fHHvH$bcW=|~7MGW;SQw33C>ni;vc_$r^|YN<)4jBbcF-2Ohwg`U zi}Ab#GosZKgspM6MQuazQe&|>z0tVJoc21~)wI`ytZZ6lPG4@?U`}1GmFDy}u4Z#O z*IjK+ce_i?=@s{CV`_PgL{Oh+JZW!=V|tbO@FzT!iQMKK6Yy8zYc8=>%L2jija7_< zViNg>OcIrKa072Aj)vS4AEohQ5-xFLeK-~!+YQ$wPHoJq=3MTEPm;J=q(o!CeVl}f z=_0fD%dxn`E%3ScojYF~bQa~ImawsA1|`}$K^tSw|Fx~tQE1s#x#trMwa*)CsHFJ< zP7Jh>#xZyLQJTp@w;<}`gg4KcaKhZCiRYSU6{6yx(2hD-667ox(U`kRo&YyH9TMmx zQRo#*Ls=ry`v8g62CMlLD+-wmF=Lr!qGi2EMa=4;BH^H6b&^gW=rPVbLTBb%46zA< zn74*%#Z*s@_@FtUJuj*~#!kx-TRjsrm$>YyAAiq=UE9`gU%Zj{(Up#}FyAt4X*s4< zrr2o!jmk%c#G@vTdl%iA(#_xO)SK7{^`Q^_YAGSCqG71GD1!~{)H|H=3`POhxV|C> z9HfmGQ(KEBXgIqyoYxx8=0&Xq+4;a5$x%VtWD#mzltk0lI;<6nsuzbIC2xIvNd959S&QY2;u8kN0~o23vp7?R9}1&nlOFG^S*V536K z@t3%nlD;Dt@Zi+wGi09II%NPLdA#e z4LPy83tq!7IilEKzW|7M4`OJ^!esN&)D;S;1_}NmvDN<=Lf{G~)>YYBB=E^H0-&Ki zJ6~xYZ!r?6*(5fbJCrK2u-kKE9HA8*x{*DMuV#E?41w3r{gI<4C3jOG;A3oUDy%0M z=;8=C>P&3Bi5Sxv)bqaax`)dHp$s@7xk#x#M%u+07_V2VmjS|p{&aLjVI*?RB9R(; zRS=lzrurI#F;OivTYj;>d!kl1{CM}KCAVZy8l__eD`>~#K7lfk730)?#S@{E5_b(P z9&Y*Zmov1D;`WnsHBG$oOp#c9yin9URz7_74qkoX=hBA zG}0Pb?i#ueYmKLCSgVf#7=5%yTD6AO0XI29SApE4aFnK%HS$y;UGxcXKQeG}6LzIk z!Urd=rSHYu0VNDUyQC5yOC?OI^$=eQ_ea?GTQJ>;j+7%%ibXcUo~_WGyHqve!uO{X z-i)|yj@h4RH1%g~;tl0CweO{BtVw09Hy)sKrWcqVLB<#NGIW z6!3Y10BnD0`EvRtRY16g)aj!DwHd~sAWHmE;6>?^g=;ei!NkbGuRv>+nbrrf_dI(?4=KA-Y7+OK zEoCf5?~Ayr@}#SHU+giojIXtT*Ro21dy_Usoc&g?m(f2{vUjIcB}6|U-q_|QGtIjT z(RdMWemAgIpP@#z*M7M0Ude+YoxrM>VpHXstz36kvCaNIFg*6{$FW zD_*|G)4wFX39;-!VyR)K$SNARNs45t963S*qU6b<>_3376qhP!0|;kH_CyWut{9yB zTWK8!u*)n$8TgPfE0)_#QO-12qgQUP9fnU#?^fbd$pPf*7f{v=j;Z8Z;+111+FRm% z{11rsQ~bZ>)RIYDt$E11cnPUWX<#HWCa!6Mxc|L?%gT8ll!u_z@M z9I*wzozQ5LgqwS9yMf&X${x5qwhKks;DQVnINPXHyf-*ge16)NW~WT?$Y9Z=8oatz z;Ii{2E)OnCdyp22=pfo!tbQxj{O@#F2#yM@W=Hc#rPH61J2GgZotUZr~G)`onDNC1n3;m48(mzfdIMXzBDv&C` z>+qINv|PM@W_qMwBdB6x_DIa7Bv`+MT}^_Wkgx(&fjI9I64sIg`Tv6N`y>$7>Szh%E-=(w=SK*yTyb(> zBChnvr$FBfXfo@oe0qOy1jT(jR=0 z$0gwZ{Qw5&Bfv6!#F&g`V6q2xWk(ff=C>AbQ1UUoA;7rbWc`ur5!USI{ohu=2%8k` z+XedT$^zqlGXcs|m$FCpJ?xeqGVUgQ1k15YV=j^wu<0ZBM?HuL4@?`gqrH*q(xZxA zBH&VH1cju}h|^=5M86MY&?Oqh`Vl!9*+KiVqY=4|nzOIuBP%ol|0^6;my@p`-w>dt zN%YbF{)3V%VIosV0{eLik45AYukXh$C?$#jJ`UGGfRgi=pQo6O0BUszwRb&!UR3V& zsMMXP)%T*>tw+V)$;6c2SB}lI4z+IwmNuJd#$*9Aswoh8=0!SbL}oI77^ zUCpmQO`^E5*!nzXeeI&bQ*51&@*MIDYfG_}zk>{R;5*1H%i)7~ORBK^k#B|K!cd;2 zbU;o&!1Rqn;>J+1<;YQCd%oE6`cct<+r+2DO56?~6N?YqtQAO=YsbV^)rWs?V`=v zk9z#>FGRz|r5m`8Km0OtsZZd{mKY4)AVa@qeCqwd(JZ{e_;@rE`S%0wz9M#CwEYLx C7(K@T delta 1913 zcmZ{kYitx%6vxk<=}v|6*tXjirrk#$Af*VqeNwD$_q}6xyW8!wl!|OjXrl>;ANZmo zC87kd0_7lqQfL)Lpu{M<6rzN*1PmI&!}vud$~U71=?C~?i1pmNtaQ^j$=q}1_rK@N zxo7U3$@k?$ze@XTtZJaNTv<5^;9Z3iEsGRb;smHb^MrNa(9OkK*cI@_y_zc&34o)f z9_9jQUhiY#Ak+Z!04?oBY(Cy(1tw!k*TR9gH$)+|4#-8PRK)TyS2wYI?30R}ri>&t zl&0PR1srtJDu zr;te004m^@o%xl;DXCp|>6%AKE1_gMtL7;h!Hl_C1(F5O*kxu`9O*Vy+4wYXyuBkF zcE#3!qpoHpl&08ftvk-E;II+O0RQYZvvT|=%PdzzC0Yy?*#S$@X)w!nsKVS>30s!f zVz~1xtH(92HCX@;75v4u6|c0E;dZx0*lX?=g?+&j7WR@SCTxS(DeO^iudqvf-NKIg z{K78q*9p7XZxi-w|5|QM--_N&Z`M5-n*&R@$iByYfm-3+A+HqY22JAWH`IbwY;IBM zshk0BZz+@Op#j;T3Fn3*R5_f)m%=KbywQG^q zxYp{AaDmY*6JL_6)#D36HLx5swmpMd+gVnKkJ>iTSjsnB%s}3Iu|}MXy}jR1OkV`} zZd53q!5qxfui>O_#>x&Vro)OCI_gmAti@Poo`KIWVo&EmbWxz40%=zyW_NkA(Pk)N zj>M1gS6Ad`feZ$afM=XdHU}UP-&?7&e%y8HX$%fGSt(JJS_QY^Z>n@2+>@uKwm}ej zU<15PY5RsN6UNg{T2vxBTEUnNe?M!baaLjloi<(uzsRC5VP#vfCsAJ4EpcLpTDlvB zb<+r76Ei)q2{uyhm*F*d16s*$q_+VYl2v#ysbT`>5<1)!-JdnYW)Nupf=+)b`HQbB&C z6iXAp0}XdXEjT%mB?Wijy2~Y)cezm7nR5N){=nVp?00wa_R83|w?Lu4FN6kg>!9kl zP~Wxu*LDkwO9)#QHgVH(i; z>6#w<6Lo0hU|JuZq2Hi{LxXtZxT<_ZV*e0c`c%bRSF_xkkEWw`&4}tEVmp@BchAs2 zp{$3F;dh^@Nt<8 diff --git a/mozilla/cck/driver/WizardMachine.cpp b/mozilla/cck/driver/WizardMachine.cpp index e8dffd9888d..39dd98d0596 100644 --- a/mozilla/cck/driver/WizardMachine.cpp +++ b/mozilla/cck/driver/WizardMachine.cpp @@ -115,6 +115,8 @@ BOOL CWizardMachineApp::InitInstance() // of your final executable, you should remove from the following // the specific initialization routines you do not need. + CoInitialize(NULL); + #ifdef _AFXDLL Enable3dControls(); // Call this when using MFC in a shared DLL #else @@ -1462,3 +1464,10 @@ void CWizardMachineApp::HelpWiz() hlpdlg.DoModal(); } } + +int CWizardMachineApp::ExitInstance() +{ + CoUninitialize(); + + return CWinApp::ExitInstance(); +} diff --git a/mozilla/cck/driver/WizardMachine.h b/mozilla/cck/driver/WizardMachine.h index d0a115ff66e..f9a2e508ed6 100644 --- a/mozilla/cck/driver/WizardMachine.h +++ b/mozilla/cck/driver/WizardMachine.h @@ -78,6 +78,7 @@ public: //{{AFX_VIRTUAL(CWizardMachineApp) public: virtual BOOL InitInstance(); + virtual int ExitInstance(); //}}AFX_VIRTUAL // Implementation diff --git a/mozilla/cck/driver/WizardMachine.ncb b/mozilla/cck/driver/WizardMachine.ncb index 07364eb3cf97ae507d7df9ea1ce03a52542972bd..708d044083c67ad227eccd00da03928eb0ef17a1 100644 GIT binary patch delta 384 zcmZoT!PIbqX@Ujo1HMa)N}C&fjxsa#)i)F)%bFUSi|`@+Z7EV`Tx-CxVPwC4lq; zARk0GK*c+fE-`}S85(rJ>Sh4>N(_Pw%9}Gi<}wR;Fg60^m>4`5j{<2%hKk(H5Vuuwzwb5M+?roar%_SxBFu5vYL)h>rp>BZEG}W(l7c(vx~PSa}$M uB9jwc #include @@ -438,6 +439,7 @@ void CWizardUI::EnableWidget(WIDGET *curWidget) } } +// Copy values from the widget object to the Windows control UI element. void CWizardUI::UpdateScreenWidget(WIDGET *curWidget) { int selRv = CB_ERR; @@ -566,6 +568,11 @@ void CWizardUI::UpdateScreenWidget(WIDGET *curWidget) if (selRv == CB_ERR) selRv = ((CComboBox*)curWidget->control)->SetCurSel(0); } + + else if(curWidget->type == "PrefsTree") + { + } + } void CWizardUI::CreateControls() @@ -778,8 +785,66 @@ void CWizardUI::CreateControls() else if (widgetType == "ProgressBar") { curWidget->control = new CProgressCtrl; rv = ((CProgressCtrl*)curWidget->control)->Create(WS_TABSTOP, tmpRect, this, ID); - } + } + else if (widgetType == "PrefsTree") { + /* + A PrefsTree is a tree control for editing prefs. The ini file section should look like: + [Widget 1] + Type=PrefsTree + Name=PrefsTreeName + Attrib=MetaPrefs.xml + etc... + + where... + Attrib is the xml file which describes the tree control layout. It should + not specifiy a path. If the file doesn't exist in the config directory, + the default in the app Root directory is used. Then it is saved in the + config directory with any modified pref values and used next time. + See PrefsTree.html for prefs file format details. + + You can also create buttons to act on the prefs tree. For example, the + following button open the selected pref for editing, or expands the + group if a group is selected instead of a pref. + + [Widget 4203] + Type=Button + Name=Button4203 + Value=Open + onCommand=OpenPrefTreeItem(PrefsTreeName) + ... + + The other commands are: + FindPrefTreeItem(PrefsTreeName) to open the search dialog + FindNextPrefTreeItem(PrefsTreeName) to find the next matching item + AddPrefTreeItem(PrefsTreeName) to open the add pref dialog + + + PrefsTree is a little different from other widgets, in that it's not derived from a control--it's a CView. + Also, it doesn't have a ->value like some widgets do. So be careful. + + */ + + // If the .XML file exists in the config directory, use it. Otherwise, use the + // default file found at the Root. + CString rootPath = GetGlobal("Root"); + CString configName = GetGlobal("CustomizationList"); + CString localPrefsFile = rootPath + "Configs\\" + configName + "\\" + curWidget->attrib; + CString prefsFile; + if (theApp.FileExists(localPrefsFile)) + prefsFile = localPrefsFile; + else + prefsFile = rootPath + curWidget->attrib; + + curWidget->control = new CPrefEditView(prefsFile); + + // Configure the PrefsTree with any existing globals + //((CPrefEditView*)curWidget->control)->SetPrefValues(curWidget->value); + + rv = ((CPrefEditView*)curWidget->control)->Create(NULL, NULL, WS_BORDER, tmpRect, this, ID); + + + } if (!rv) { @@ -855,15 +920,18 @@ void CWizardUI::DestroyCurrentScreenWidgets() { curWidget = CurrentNode->pageWidgets[i]; - if (curWidget->control) + if (curWidget->control) { BOOL retFalg = curWidget->control->DestroyWindow(); - delete curWidget->control; + if (curWidget->type != "PrefsTree") // PrefsTree is a CView, not a control, and is destroyed automatically above + delete curWidget->control; curWidget->control = NULL; } } } + +// Copies values from the Windows controls to the widgets objects. CString CWizardUI::GetScreenValue(WIDGET *curWidget) { // @@ -1076,6 +1144,12 @@ CString CWizardUI::GetScreenValue(WIDGET *curWidget) } */ + + else if (widgetType == "PrefsTree") + { + //rv = ((CPrefEditView*)curWidget->control)->GetModifiedPrefs(); + } + else rv = curWidget->value; // !!! Fix this so we're not copying strings all the time // Should be able to just pass in an "assign" boolean @@ -1095,6 +1169,17 @@ void CWizardUI::UpdateGlobals() { curWidget = CurrentNode->pageWidgets[i]; curWidget->value = GetScreenValue(curWidget); + + // Save the prefs tree in a file local to the config. This is + // what gets read next time the prefs tree control is created. + if (curWidget->type == "PrefsTree") + { + CString rootPath = GetGlobal("Root"); + CString configName = GetGlobal("CustomizationList"); + CString localPrefsFile = rootPath + "Configs\\" + configName + "\\" + curWidget->attrib; + + ((CPrefEditView*)curWidget->control)->DoSavePrefsTree(localPrefsFile); + } } IsNewValue = TRUE; } diff --git a/mozilla/cck/driver/dlgadd.cpp b/mozilla/cck/driver/dlgadd.cpp new file mode 100644 index 00000000000..8ad7a947967 --- /dev/null +++ b/mozilla/cck/driver/dlgadd.cpp @@ -0,0 +1,46 @@ +// DlgAdd.cpp : implementation file +// + +#include "stdafx.h" +#include "DlgAdd.h" + +#ifdef _DEBUG +#define new DEBUG_NEW +#undef THIS_FILE +static char THIS_FILE[] = __FILE__; +#endif + +///////////////////////////////////////////////////////////////////////////// +// CDlgAdd dialog + + +CDlgAdd::CDlgAdd(CWnd* pParent /*=NULL*/) + : CDialog(CDlgAdd::IDD, pParent) +{ + //{{AFX_DATA_INIT(CDlgAdd) + m_strPrefDesc = _T(""); + m_strPrefName = _T(""); + m_intPrefType = 0; + //}}AFX_DATA_INIT +} + + +void CDlgAdd::DoDataExchange(CDataExchange* pDX) +{ + CDialog::DoDataExchange(pDX); + //{{AFX_DATA_MAP(CDlgAdd) + DDX_Text(pDX, IDC_PREFDESC, m_strPrefDesc); + DDX_Text(pDX, IDC_PREFNAME, m_strPrefName); + DDX_Radio(pDX, IDC_PREFTYPE_STRING, m_intPrefType); + //}}AFX_DATA_MAP +} + + +BEGIN_MESSAGE_MAP(CDlgAdd, CDialog) + //{{AFX_MSG_MAP(CDlgAdd) + // NOTE: the ClassWizard will add message map macros here + //}}AFX_MSG_MAP +END_MESSAGE_MAP() + +///////////////////////////////////////////////////////////////////////////// +// CDlgAdd message handlers diff --git a/mozilla/cck/driver/dlgadd.h b/mozilla/cck/driver/dlgadd.h new file mode 100644 index 00000000000..7151c2f18ed --- /dev/null +++ b/mozilla/cck/driver/dlgadd.h @@ -0,0 +1,50 @@ +#if !defined(AFX_DLGADD_H__55B7BFE0_C8B7_43FA_AFD2_BCB1AA18E820__INCLUDED_) +#define AFX_DLGADD_H__55B7BFE0_C8B7_43FA_AFD2_BCB1AA18E820__INCLUDED_ + +#if _MSC_VER > 1000 +#pragma once +#endif // _MSC_VER > 1000 +// DlgAdd.h : header file +// + +#include "resource.h" + +///////////////////////////////////////////////////////////////////////////// +// CDlgAdd dialog + +class CDlgAdd : public CDialog +{ +// Construction +public: + CDlgAdd(CWnd* pParent = NULL); // standard constructor + +// Dialog Data + //{{AFX_DATA(CDlgAdd) + enum { IDD = IDD_ADDPREF }; + CString m_strPrefDesc; + CString m_strPrefName; + int m_intPrefType; + //}}AFX_DATA + + +// Overrides + // ClassWizard generated virtual function overrides + //{{AFX_VIRTUAL(CDlgAdd) + protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support + //}}AFX_VIRTUAL + +// Implementation +protected: + + // Generated message map functions + //{{AFX_MSG(CDlgAdd) + // NOTE: the ClassWizard will add member functions here + //}}AFX_MSG + DECLARE_MESSAGE_MAP() +}; + +//{{AFX_INSERT_LOCATION}} +// Microsoft Visual C++ will insert additional declarations immediately before the previous line. + +#endif // !defined(AFX_DLGADD_H__55B7BFE0_C8B7_43FA_AFD2_BCB1AA18E820__INCLUDED_) diff --git a/mozilla/cck/driver/dlgeditprefstr.cpp b/mozilla/cck/driver/dlgeditprefstr.cpp new file mode 100644 index 00000000000..37d753b731b --- /dev/null +++ b/mozilla/cck/driver/dlgeditprefstr.cpp @@ -0,0 +1,152 @@ +// DlgEditPrefStr.cpp : implementation file +// + +#include "stdafx.h" +#include "DlgEditPrefStr.h" + +#ifdef _DEBUG +#define new DEBUG_NEW +#undef THIS_FILE +static char THIS_FILE[] = __FILE__; +#endif + +///////////////////////////////////////////////////////////////////////////// +// CDlgEditPrefStr dialog + + +CDlgEditPrefStr::CDlgEditPrefStr(CWnd* pParent /*=NULL*/) + : CDialog(CDlgEditPrefStr::IDD, pParent), m_bChoose(FALSE) +{ + //{{AFX_DATA_INIT(CDlgEditPrefStr) + m_strDescription = _T(""); + m_strPrefName = _T(""); + m_strValue = _T(""); + m_bLocked = FALSE; + m_bValue = FALSE; + m_strInstallFile = _T(""); + m_strPrefFile = _T(""); + //}}AFX_DATA_INIT +} + + +void CDlgEditPrefStr::DoDataExchange(CDataExchange* pDX) +{ + CDialog::DoDataExchange(pDX); + //{{AFX_DATA_MAP(CDlgEditPrefStr) + DDX_Control(pDX, IDC_VALLIST, m_listValue); + DDX_Control(pDX, IDC_VALCHECK, m_checkValue); + DDX_Control(pDX, IDC_VALUE, m_editValue); + DDX_Text(pDX, IDC_DESCRIPTION, m_strDescription); + DDX_Text(pDX, IDC_PREFNAME, m_strPrefName); + DDX_Text(pDX, IDC_VALUE, m_strValue); + DDX_Check(pDX, IDC_LOCKED, m_bLocked); + DDX_Check(pDX, IDC_VALCHECK, m_bValue); + DDX_Text(pDX, IDC_INSTALLFILE, m_strInstallFile); + DDX_Text(pDX, IDC_PREFFILE, m_strPrefFile); + //}}AFX_DATA_MAP +} + + +BEGIN_MESSAGE_MAP(CDlgEditPrefStr, CDialog) + //{{AFX_MSG_MAP(CDlgEditPrefStr) + ON_WM_CREATE() + ON_WM_CANCELMODE() + //}}AFX_MSG_MAP +END_MESSAGE_MAP() + +///////////////////////////////////////////////////////////////////////////// +// CDlgEditPrefStr message handlers + +int CDlgEditPrefStr::OnCreate(LPCREATESTRUCT lpCreateStruct) +{ + if (CDialog::OnCreate(lpCreateStruct) == -1) + return -1; + + SetWindowText(m_strTitle); + + + + return 0; +} + + +BOOL CDlgEditPrefStr::PreCreateWindow(CREATESTRUCT& cs) +{ + BOOL retval = CDialog::PreCreateWindow(cs); + + // TODO: Add your specialized code here and/or call the base class + + + return retval; +} + +BOOL CDlgEditPrefStr::OnInitDialog() +{ + CDialog::OnInitDialog(); + + if (m_bChoose) + { + m_editValue.ShowWindow(SW_HIDE); + m_listValue.ShowWindow(SW_SHOW); + m_checkValue.ShowWindow(SW_HIDE); + + // The list of choices comes in as an array of CStrings, + // terminated with an empty one. + CString *pstrChoice = m_pstrChoices; + while(pstrChoice->GetLength() > 0) + { + m_listValue.AddString(*pstrChoice); + pstrChoice++; + } + + m_listValue.SelectString(0, m_strSelectedChoice); + } + + else if (m_strType.CompareNoCase("bool") == 0) + { + m_editValue.ShowWindow(SW_HIDE); + m_listValue.ShowWindow(SW_HIDE); + m_checkValue.ShowWindow(SW_SHOW); + m_checkValue.SetWindowText(m_strTitle); + + if (m_strValue.CompareNoCase("true") == 0) + m_checkValue.SetCheck(TRUE); + } + + else // string or int type + { + m_editValue.ShowWindow(SW_SHOW); + m_listValue.ShowWindow(SW_HIDE); + m_checkValue.ShowWindow(SW_HIDE); + } + + return TRUE; // return TRUE unless you set the focus to a control + // EXCEPTION: OCX Property Pages should return FALSE +} + +// Caller only has to get value from m_strValue for all types. +void CDlgEditPrefStr::OnOK() +{ + // For bool types, convert back to the data string. + if (m_strType.CompareNoCase("bool") == 0) + { + if (m_checkValue.GetCheck()) + m_editValue.SetWindowText("true"); + else + m_editValue.SetWindowText("false"); + } + // For choose, return the selected list string. + else if (m_bChoose) + { + CString strSelectString; + m_listValue.GetLBText(m_listValue.GetCurSel(), strSelectString); + m_editValue.SetWindowText(strSelectString); + } + + else // string, int type + { + + } + + CDialog::OnOK(); +} diff --git a/mozilla/cck/driver/dlgeditprefstr.h b/mozilla/cck/driver/dlgeditprefstr.h new file mode 100644 index 00000000000..36338479351 --- /dev/null +++ b/mozilla/cck/driver/dlgeditprefstr.h @@ -0,0 +1,65 @@ +#if !defined(AFX_DLGEDITPREFSTR_H__EA62EAF1_9CF9_474F_AC2E_7AE66DCAF863__INCLUDED_) +#define AFX_DLGEDITPREFSTR_H__EA62EAF1_9CF9_474F_AC2E_7AE66DCAF863__INCLUDED_ + +#if _MSC_VER > 1000 +#pragma once +#endif // _MSC_VER > 1000 +// DlgEditPrefStr.h : header file +// + +#include "resource.h" + +///////////////////////////////////////////////////////////////////////////// +// CDlgEditPrefStr dialog + +class CDlgEditPrefStr : public CDialog +{ +// Construction +public: + CString m_strSelectedChoice; + CString* m_pstrChoices; + CString m_strType; + CString m_strTitle; + CDlgEditPrefStr(CWnd* pParent = NULL); // standard constructor + BOOL m_bChoose; + +// Dialog Data + //{{AFX_DATA(CDlgEditPrefStr) + enum { IDD = IDD_EDITPREF }; + CComboBox m_listValue; + CButton m_checkValue; + CEdit m_editValue; + CString m_strDescription; + CString m_strPrefName; + CString m_strValue; + CString m_strInstallFile; + CString m_strPrefFile; + BOOL m_bLocked; + BOOL m_bValue; + //}}AFX_DATA + + +// Overrides + // ClassWizard generated virtual function overrides + //{{AFX_VIRTUAL(CDlgEditPrefStr) + protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support + virtual BOOL PreCreateWindow(CREATESTRUCT& cs); + //}}AFX_VIRTUAL + +// Implementation +protected: + + // Generated message map functions + //{{AFX_MSG(CDlgEditPrefStr) + afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct); + virtual BOOL OnInitDialog(); + virtual void OnOK(); + //}}AFX_MSG + DECLARE_MESSAGE_MAP() +}; + +//{{AFX_INSERT_LOCATION}} +// Microsoft Visual C++ will insert additional declarations immediately before the previous line. + +#endif // !defined(AFX_DLGEDITPREFSTR_H__EA62EAF1_9CF9_474F_AC2E_7AE66DCAF863__INCLUDED_) diff --git a/mozilla/cck/driver/dlgfind.cpp b/mozilla/cck/driver/dlgfind.cpp new file mode 100644 index 00000000000..327baab9dfd --- /dev/null +++ b/mozilla/cck/driver/dlgfind.cpp @@ -0,0 +1,42 @@ +// DlgFind.cpp : implementation file +// + +#include "stdafx.h" +#include "DlgFind.h" + +#ifdef _DEBUG +#define new DEBUG_NEW +#undef THIS_FILE +static char THIS_FILE[] = __FILE__; +#endif + +///////////////////////////////////////////////////////////////////////////// +// CDlgFind dialog + + +CDlgFind::CDlgFind(CWnd* pParent /*=NULL*/) + : CDialog(CDlgFind::IDD, pParent) +{ + //{{AFX_DATA_INIT(CDlgFind) + m_strFind = _T(""); + //}}AFX_DATA_INIT +} + + +void CDlgFind::DoDataExchange(CDataExchange* pDX) +{ + CDialog::DoDataExchange(pDX); + //{{AFX_DATA_MAP(CDlgFind) + DDX_Text(pDX, IDC_FIND, m_strFind); + //}}AFX_DATA_MAP +} + + +BEGIN_MESSAGE_MAP(CDlgFind, CDialog) + //{{AFX_MSG_MAP(CDlgFind) + // NOTE: the ClassWizard will add message map macros here + //}}AFX_MSG_MAP +END_MESSAGE_MAP() + +///////////////////////////////////////////////////////////////////////////// +// CDlgFind message handlers diff --git a/mozilla/cck/driver/dlgfind.h b/mozilla/cck/driver/dlgfind.h new file mode 100644 index 00000000000..581d0de15c8 --- /dev/null +++ b/mozilla/cck/driver/dlgfind.h @@ -0,0 +1,48 @@ +#if !defined(AFX_DLGFIND_H__1A85D3AB_C7B1_4F91_A9A9_6A1DEECD13E2__INCLUDED_) +#define AFX_DLGFIND_H__1A85D3AB_C7B1_4F91_A9A9_6A1DEECD13E2__INCLUDED_ + +#if _MSC_VER > 1000 +#pragma once +#endif // _MSC_VER > 1000 +// DlgFind.h : header file +// + +#include "resource.h" + +///////////////////////////////////////////////////////////////////////////// +// CDlgFind dialog + +class CDlgFind : public CDialog +{ +// Construction +public: + CDlgFind(CWnd* pParent = NULL); // standard constructor + +// Dialog Data + //{{AFX_DATA(CDlgFind) + enum { IDD = IDD_FIND }; + CString m_strFind; + //}}AFX_DATA + + +// Overrides + // ClassWizard generated virtual function overrides + //{{AFX_VIRTUAL(CDlgFind) + protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support + //}}AFX_VIRTUAL + +// Implementation +protected: + + // Generated message map functions + //{{AFX_MSG(CDlgFind) + // NOTE: the ClassWizard will add member functions here + //}}AFX_MSG + DECLARE_MESSAGE_MAP() +}; + +//{{AFX_INSERT_LOCATION}} +// Microsoft Visual C++ will insert additional declarations immediately before the previous line. + +#endif // !defined(AFX_DLGFIND_H__1A85D3AB_C7B1_4F91_A9A9_6A1DEECD13E2__INCLUDED_) diff --git a/mozilla/cck/driver/interpret.cpp b/mozilla/cck/driver/interpret.cpp index 5463fb98abd..8df2ec401ed 100644 --- a/mozilla/cck/driver/interpret.cpp +++ b/mozilla/cck/driver/interpret.cpp @@ -8,6 +8,7 @@ #include "SumDlg.h" #include "NewDialog.h" #include "NewConfigDialog.h" +#include "PrefEditView.h" // The following is included to make // the browse for a dir code compile @@ -346,6 +347,8 @@ BOOL CInterpret::ShowSection(WIDGET *curWidget) return TRUE; } + + BOOL CInterpret::GetRegistryKey( HKEY key, const char *subkey, char *retdata ) { long retval; @@ -1235,15 +1238,47 @@ BOOL CInterpret::interpret(CString cmds, WIDGET *curWidget) else if (strcmp(pcmd, "ShowSection") == 0) { // ShowSection is a way to use a listbox to choose a subset of widgets to display. - // To use, create a listbox widget, and fill it will sectionnames. + // To use, create a listbox widget, and fill it with sectionnames. // Set its onCommand=ShowSection. // Then give the widgets you want in each section a "ShowInSection=sectionname". // When "sectionname" is selected in the listbox, all widgets with matching ShowInSection // are shown, and all widgets with some other sectiion are hidden. Widgets without // the ShowInSection attribute are left alone. - ShowSection(curWidget); } + else if (strcmp(pcmd, "OpenPrefTreeItem") == 0) + { + WIDGET *w = findWidget(parms); + if (w->type == "PrefsTree") + ((CPrefEditView*)w->control)->DoOpenItem(); + + ((CPrefEditView*)w->control)->SetFocus(); + } + else if (strcmp(pcmd, "FindPrefTreeItem") == 0) + { + WIDGET *w = findWidget(parms); + if (w->type == "PrefsTree") + ((CPrefEditView*)w->control)->DoFindFirst(); + + ((CPrefEditView*)w->control)->SetFocus(); + } + else if (strcmp(pcmd, "FindNextPrefTreeItem") == 0) + { + WIDGET *w = findWidget(parms); + if (w->type == "PrefsTree") + ((CPrefEditView*)w->control)->DoFindNext(); + + ((CPrefEditView*)w->control)->SetFocus(); + } + else if (strcmp(pcmd, "AddPrefTreeItem") == 0) + { + WIDGET *w = findWidget(parms); + if (w->type == "PrefsTree") + ((CPrefEditView*)w->control)->DoAdd(); + + ((CPrefEditView*)w->control)->SetFocus(); + } + } // This is an extra free... //free(pcmd); diff --git a/mozilla/cck/driver/makefile.win b/mozilla/cck/driver/makefile.win index 72e263855c4..e60d8825e9c 100644 --- a/mozilla/cck/driver/makefile.win +++ b/mozilla/cck/driver/makefile.win @@ -48,6 +48,7 @@ INCS = -I. \ OBJS = \ + .\$(OBJDIR)\DlgEditPrefStr.obj \ .\$(OBJDIR)\HelpDlg.obj \ .\$(OBJDIR)\ImageDialog.obj \ .\$(OBJDIR)\ImgDlg.obj \ @@ -55,6 +56,8 @@ OBJS = \ .\$(OBJDIR)\NavText.obj \ .\$(OBJDIR)\NewConfigDialog.obj \ .\$(OBJDIR)\NewDialog.obj \ + .\$(OBJDIR)\PrefEditView.obj \ + .\$(OBJDIR)\PrefElement.obj \ .\$(OBJDIR)\ProgDlgThread.obj \ .\$(OBJDIR)\ProgressDialog.obj \ .\$(OBJDIR)\PropSheet.obj \ @@ -65,6 +68,10 @@ OBJS = \ .\$(OBJDIR)\WizardUI.obj \ .\$(OBJDIR)\WizHelp.obj \ .\$(OBJDIR)\wizshell.obj \ + .\$(OBJDIR)\XMLDOMHelper.obj \ + .\$(OBJDIR)\DlgFind.obj \ + .\$(OBJDIR)\DlgAdd.obj \ + .\$(OBJDIR)\PrefGroup.obj \ $(NULL) LLIBS = $(LLIBS) \ diff --git a/mozilla/cck/driver/prefeditview.cpp b/mozilla/cck/driver/prefeditview.cpp new file mode 100644 index 00000000000..4b4d8819c7d --- /dev/null +++ b/mozilla/cck/driver/prefeditview.cpp @@ -0,0 +1,715 @@ +// PrefEditView.cpp : implementation of the CPrefEditView class +// +// In this code, the "tree control" is the just that which lives in the view, +// and the "prefs tree" is an XML DOM tree representing the preferences and +// their layout. +// +// The key to go from a tree control item to it's corresponding object in the +// XML tree is the pref name, which is saved in the tree control item data +// area. The code assumes the pref names are unique. +// + +#include "stdafx.h" +#include "PrefElement.h" +#include "PrefEditView.h" +#include "DlgEditPrefStr.h" +#include "DlgFind.h" +#include "DlgAdd.h" + +#ifdef _DEBUG +#define new DEBUG_NEW +#undef THIS_FILE +static char THIS_FILE[] = __FILE__; +#endif + + +///////////////////////////////////////////////////////////////////////////// +// CPrefEditView + +IMPLEMENT_DYNCREATE(CPrefEditView, CTreeView) + +BEGIN_MESSAGE_MAP(CPrefEditView, CTreeView) + //{{AFX_MSG_MAP(CPrefEditView) + ON_NOTIFY_REFLECT(NM_DBLCLK, OnDblclk) + ON_NOTIFY_REFLECT(NM_RCLICK, OnRclick) + ON_WM_CREATE() + ON_WM_DESTROY() + ON_COMMAND(ID_EDITPREFITEM, OnEditPrefItem) + ON_COMMAND(ID_FINDPREF, OnFindPref) + ON_COMMAND(ID_FINDNEXTPREF, OnFindNextPref) + ON_COMMAND(ID_ADDPREF, OnAddPref) + ON_WM_KEYDOWN() + //}}AFX_MSG_MAP +END_MESSAGE_MAP() + +///////////////////////////////////////////////////////////////////////////// +// CPrefEditView construction/destruction + +// Protected. +CPrefEditView::CPrefEditView() +: m_pPrefXMLTree(NULL), m_pPrefsList(NULL), m_iNextElement(-1) +{ + +} + + +CPrefEditView::CPrefEditView(CString strXMLFile) +: m_pPrefXMLTree(NULL), m_strXMLFile(strXMLFile), m_pPrefsList(NULL), m_iNextElement(-1) +{ + InitXMLTree(); +} + +CPrefEditView::~CPrefEditView() +{ + +} + +BOOL CPrefEditView::PreCreateWindow(CREATESTRUCT& cs) +{ + + cs.style |= TVS_HASLINES | TVS_LINESATROOT | TVS_HASBUTTONS; + return CTreeView::PreCreateWindow(cs); +} + +///////////////////////////////////////////////////////////////////////////// +// CPrefEditView public operations + +// expand the tree, or open the selected item for edit +void CPrefEditView::DoOpenItem() +{ + CTreeCtrl &treeCtrl = GetTreeCtrl(); + HTREEITEM hTreeCtrlItem = treeCtrl.GetSelectedItem(); + if (!treeCtrl.ItemHasChildren(hTreeCtrlItem)) // no children == leaf node == pref + { + EditSelectedPrefsItem(); + } + else + { + treeCtrl.Expand(hTreeCtrlItem, TVE_TOGGLE); + } + +} + +// open the Find Pref dialog +void CPrefEditView::DoFindFirst() +{ + OnFindPref(); +} + +// find next item +void CPrefEditView::DoFindNext() +{ + OnFindNextPref(); +} + +// open the Add Pref dialog +void CPrefEditView::DoAdd() +{ + OnAddPref(); +} + + + +///////////////////////////////////////////////////////////////////////////// +// CPrefEditView diagnostics + +#ifdef _DEBUG +void CPrefEditView::AssertValid() const +{ + CTreeView::AssertValid(); +} + +void CPrefEditView::Dump(CDumpContext& dc) const +{ + CTreeView::Dump(dc); +} + +#endif //_DEBUG + + +BOOL CPrefEditView::InitXMLTree() +{ + // Create XML DOM instance. + HRESULT hr = m_pPrefXMLTree.CreateInstance(__uuidof(DOMDocument)); + if (FAILED(hr)) + { + MessageBox("Error creating MS XML DOM.", "Error", MB_OK); + return FALSE; + } + + // Load the prefs metadata. This is a representation of the prefs tree as + // it should appear in the tree control. + if (m_pPrefXMLTree) + { + CString strPrefsFileURL; + strPrefsFileURL.Format("FILE://%s", m_strXMLFile); + + if (!m_pPrefXMLTree->load(strPrefsFileURL.GetBuffer(0))) + { + CString strError; + strError.Format("Error loading preferences metadata %s.", strPrefsFileURL); + MessageBox(strError, "Error", MB_OK); + m_pPrefXMLTree = NULL; + return FALSE; + } + if (m_pPrefXMLTree->parseError->errorCode != 0) + { + CString strError; + strError.Format("Bad XML in %s.", strPrefsFileURL); + MessageBox(strError, "Error", MB_OK); + m_pPrefXMLTree = NULL; + return FALSE; + } + } + + return TRUE; +} + +// ItemData in each tree control element was created with new, so we need to +// delete it. +void CPrefEditView::DeleteTreeCtrl(HTREEITEM hParent) +{ + ASSERT(hParent); + + CTreeCtrl &treeCtrl = GetTreeCtrl(); + + // Delete the CString ojbect we created with new. + CString* pstr = (CString*)treeCtrl.GetItemData(hParent); + delete pstr; + + // Now call recursively for all children. + HTREEITEM hCurrent = treeCtrl.GetNextItem(hParent, TVGN_CHILD); + while (hCurrent != NULL) + { + DeleteTreeCtrl(hCurrent); + hCurrent = treeCtrl.GetNextItem(hCurrent, TVGN_NEXT); + } +} + + +// Given a pref node, add it to the tree ctrl. The pref name is +// later used to search for the pref node when the name is selected +// for edit. +HTREEITEM CPrefEditView::AddNodeToTreeCtrl(IXMLDOMNodePtr prefsTreeNode, HTREEITEM hTreeCtrlParent) +{ + ASSERT(prefsTreeNode != NULL); + + HTREEITEM hNewItem = NULL; + + //MessageBox(prefsTreeNode->xml, "XML", MB_OK); + if (prefsTreeNode->nodeType == NODE_ELEMENT) + { + IXMLDOMElementPtr prefsTreeElement = (IXMLDOMElementPtr)prefsTreeNode; + CElementNode elementNode(prefsTreeElement); + CString strNodeName = elementNode.GetNodeName(); + + if ((strNodeName.CompareNoCase("PREFSGROUP") == 0) || (strNodeName.CompareNoCase("PREF") == 0)) + { + // Will contain the pref name for pref elements, saved in the tree ctrl. + CString* pstrPrefName = NULL; + + // Put this element in the tree ctrl. + CString strLabel = elementNode.GetAttribute("uiname"); + + int imageIndex = 0; // tree ctrl images + int imageIndexSel = 0; // 0 is a closed folder + + // If this is a PREF element, create tree ctrl text, and save with a + // different image. + if (strNodeName.CompareNoCase("PREF") == 0) + { + + CPrefElement prefElement(prefsTreeElement); + strLabel = prefElement.CreateTreeCtrlLabel(); + + if (prefElement.IsLocked()) + imageIndexSel = imageIndex = 2; // a locked padlock + else + imageIndexSel = imageIndex = 3; // an unlocked padlock + + + // This gets deleted in DeleteTreeCtrl(). This is how we get back to + // pref node when a tree ctrl node is selected for editing. + pstrPrefName = new CString(prefElement.GetAttribute("prefname")); + + } + + CTreeCtrl &treeCtrl = GetTreeCtrl(); + hNewItem = treeCtrl.InsertItem( strLabel, imageIndex, imageIndexSel, hTreeCtrlParent, TVI_LAST); + + // Save a pointer to the prefname string so we can find the node in the + // pref tree from the tree ctrl when the item is selected for edit. + treeCtrl.SetItemData(hNewItem, (DWORD)pstrPrefName); + + } + } + + // Recursively call for children. + IXMLDOMNodeListPtr children = prefsTreeNode->GetchildNodes(); + if (children) + { + int numChildren = children->Getlength(); + for (int i = 0; i < numChildren; i++) + { + IXMLDOMNodePtr child = children->Getitem(i); + AddNodeToTreeCtrl(child, hNewItem); + } + } + + return hNewItem; +} + +///////////////////////////////////////////////////////////////////////////// +// CPrefEditView message handlers + + +// Given the pref name, for example browser.general.example, returns the +// prefs tree element for that pref. +IXMLDOMElementPtr CPrefEditView::FindElementFromPrefname(CString& rstrPrefString) +{ + ASSERT(rstrPrefString.GetLength() > 0); + ASSERT(m_pPrefXMLTree != NULL); + + IXMLDOMNodeListPtr prefsList = m_pPrefXMLTree->getElementsByTagName("PREF"); + for(int i = 0; i < prefsList->length; i++) + { + IXMLDOMElementPtr element = prefsList->Getitem(i); + CPrefElement elementNode(element); + if (rstrPrefString.CompareNoCase(elementNode.GetPrefName()) == 0) + return element; + } + return NULL; +} + +// Given a pref element node, returns the tree control item for it. +HTREEITEM CPrefEditView::FindTreeItemFromPrefname(HTREEITEM hItem, CString& rstrPrefName) +{ + + if(!hItem) + return NULL; + + // Get the pref name associated with this tree ctrl item. + CTreeCtrl &treeCtrl = GetTreeCtrl(); + CString* pstrPrefName = (CString*)treeCtrl.GetItemData(hItem); + + if (pstrPrefName && pstrPrefName->CompareNoCase(rstrPrefName) == 0) + return hItem; + + HTREEITEM hRet = NULL; + HTREEITEM hChild = treeCtrl.GetChildItem(hItem); + if(hChild) + hRet = FindTreeItemFromPrefname(hChild, rstrPrefName); + + if(hRet == NULL) + { + HTREEITEM hSibling = treeCtrl.GetNextSiblingItem(hItem); + if(hSibling) + hRet = FindTreeItemFromPrefname(hSibling, rstrPrefName); + } + + return hRet; + +} + + +// Open a dialog to edit the pref. +void CPrefEditView::OnDblclk(NMHDR* pNMHDR, LRESULT* pResult) +{ + CTreeCtrl &treeCtrl = GetTreeCtrl(); + HTREEITEM hTreeCtrlItem = treeCtrl.GetSelectedItem(); + if (!treeCtrl.ItemHasChildren(hTreeCtrlItem)) // no children == leaf node == pref + { + EditSelectedPrefsItem(); + *pResult = 0; + } + +} + +int CPrefEditView::OnCreate(LPCREATESTRUCT lpCreateStruct) +{ + // InitXMLTree() has to complete successfully first. + ASSERT(m_pPrefXMLTree != NULL); + + if (m_pPrefXMLTree == NULL) + return -1; + + if (CTreeView::OnCreate(lpCreateStruct) == -1) + return -1; + + // Get the tree control. + CTreeCtrl &treeCtrl = GetTreeCtrl(); + + // create the image list for the tree control + m_imageList.Create(IDB_TREEIMAGES, 17, 1, RGB(0,255,255)); + treeCtrl.SetImageList (&m_imageList, TVSIL_NORMAL); + + + HTREEITEM hRoot = treeCtrl.GetRootItem(); + if (hRoot) + DeleteTreeCtrl(hRoot); + + ASSERT(m_pPrefXMLTree != NULL); + + + // Load the tree control so it matches the XML tree. + AddNodeToTreeCtrl(m_pPrefXMLTree->documentElement, NULL); + + treeCtrl.Expand(treeCtrl.GetRootItem(), TVE_EXPAND); + + return 0; +} + + +void CPrefEditView::OnDestroy() +{ + // Clean up tree ctrl pref name memory allocations. + CTreeCtrl &treeCtrl = GetTreeCtrl(); + HTREEITEM hRoot = treeCtrl.GetRootItem(); + if (hRoot) + DeleteTreeCtrl(hRoot); + + CTreeView::OnDestroy(); + +} + +// Find a pref containing a string in one of its fields. +BOOL CPrefEditView::FindFirst(CString& rstrFind) +{ + ASSERT(m_pPrefXMLTree != NULL); + + m_pPrefsList = m_pPrefXMLTree->getElementsByTagName("PREF"); + m_iNextElement = 0; + m_strFind = rstrFind; + + return FindNext(); +} + + +// Assumes FindFirst was called first. +BOOL CPrefEditView::FindNext() +{ + ASSERT(m_pPrefXMLTree != NULL); + + if (m_pPrefsList == NULL || m_iNextElement == -1) + return FALSE; + + while (m_iNextElement < m_pPrefsList->length) + { + IXMLDOMElementPtr pElement = m_pPrefsList->Getitem(m_iNextElement); + + CPrefElement elementNode(pElement); + + // Find the string in any field (pref name, value, description, etc.) + if (elementNode.FindString(m_strFind)) + { + // Select this item. + SelectPref(elementNode.GetPrefName()); + m_iNextElement++; + return TRUE; + } + + m_iNextElement++; + } + + m_iNextElement = -1; + + AfxMessageBox("No more matches.", MB_OK); + + return FALSE; +} + + + +// Save the XML to a file. +BOOL CPrefEditView::DoSavePrefsTree(CString strFile) +{ + ASSERT(m_pPrefXMLTree != NULL); + + CElementNode root(m_pPrefXMLTree->documentElement); + CString strXML = root.GetXML(); + + FILE* fp = fopen(strFile, "w"); + if (!fp) + return FALSE; + + CString strPreamble(""); + if (!fwrite(strPreamble, strPreamble.GetLength(), 1, fp)) + return FALSE; + + if (!fwrite(strXML, strXML.GetLength(), 1, fp)) + return FALSE; + + fclose(fp); + + return TRUE; +} + + + +// Pop up menu for Pref items. +void CPrefEditView::ShowPopupMenu( CPoint& point, int submenu ) +{ + if (point.x == -1 && point.y == -1) + { + //keystroke invocation + CRect rect; + GetClientRect(rect); + ClientToScreen(rect); + + point = rect.TopLeft(); + point.Offset(5, 5); + } + + CMenu menu; + VERIFY(menu.LoadMenu(IDR_POPUP_PREFTREE_MENU)); + + CMenu* pPopup = menu.GetSubMenu(submenu); + ASSERT(pPopup != NULL); + CWnd* pWndPopupOwner = this; + + pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y, pWndPopupOwner); +} + +// "Edit Pref" context menu command selected. +void CPrefEditView::OnEditPrefItem() +{ + EditSelectedPrefsItem(); +} + +// "Find Pref" context menu command selected. +void CPrefEditView::OnFindPref() +{ + CDlgFind dlg; + if (dlg.DoModal() == IDOK) + if (!dlg.m_strFind.IsEmpty()) + FindFirst(dlg.m_strFind); +} + +// "Find Next Pref" context menu command selected. +void CPrefEditView::OnFindNextPref() +{ + // If FindFirst not done before FindNext, call FindFirst first. + if (m_iNextElement == -1) + OnFindPref(); + else + FindNext(); +} + + +// User added prefs go into the root group. +HTREEITEM CPrefEditView::AddPref(CString& rstrPrefName, CString& rstrPrefDesc, CString& rstrPrefType) +{ + IXMLDOMNodePtr prefsTreeRootNode = m_pPrefXMLTree->documentElement; + + // Make sure the node is the root node element. + if (prefsTreeRootNode->nodeType == NODE_ELEMENT) + { + // and that it's a group. + CElementNode group(prefsTreeRootNode); + CString strNodeName = group.GetNodeName(); + if (strNodeName.CompareNoCase("PREFSGROUP") == 0) + { + + // Create an XML element node. + IXMLDOMNodePtr newNode = group.AddNode("PREF"); + + // Modify it. + CPrefElement newPref(newNode); + newPref.Initialize(rstrPrefName, rstrPrefDesc, rstrPrefType); + + // Add it to the tree. + CTreeCtrl &treeCtrl = GetTreeCtrl(); + HTREEITEM hRoot = treeCtrl.GetRootItem(); + ASSERT(hRoot); + if (hRoot) + { + HTREEITEM hNewItem = AddNodeToTreeCtrl(newNode, hRoot); + treeCtrl.SelectItem(hNewItem); + + EditSelectedPrefsItem(); + } + } + } + + + + return NULL; + + +} + +// Open dialog to add a new pref, then open another to edit it. +void CPrefEditView::OnAddPref() +{ + CDlgAdd dlg; + if (dlg.DoModal() == IDOK) + { + if (dlg.m_strPrefName.IsEmpty()) + return; + + CString strPrefType; + if (dlg.m_intPrefType == 0) + strPrefType = "string"; + else if (dlg.m_intPrefType == 1) + strPrefType = "int"; + else + strPrefType = "bool"; + + // Disallow if the pref name already exists. + CTreeCtrl &treeCtrl = GetTreeCtrl(); + HTREEITEM hRoot = treeCtrl.GetRootItem(); + HTREEITEM hTreeCtrlItem = FindTreeItemFromPrefname(hRoot, dlg.m_strPrefName); + if (hTreeCtrlItem) + { + MessageBox("A pref of this name already exists.", MB_OK); + treeCtrl.SelectItem(hTreeCtrlItem); + } + else + { + AddPref(dlg.m_strPrefName, dlg.m_strPrefDesc, strPrefType); + } + + + } + +} + +// Open the edit dialog box for the selected pref item. A pref should be selected, +// not a group. +void CPrefEditView::EditSelectedPrefsItem() +{ + CTreeCtrl &treeCtrl = GetTreeCtrl(); + HTREEITEM hTreeCtrlItem = treeCtrl.GetSelectedItem(); + + ASSERT(!treeCtrl.ItemHasChildren(hTreeCtrlItem)); // no children == leaf node == pref + + // Can't edit a pref group--only a pref (leaf). + if (treeCtrl.ItemHasChildren(hTreeCtrlItem)) + return; + + // Get the pref name associated with this tree ctrl item. + CString* pstrPrefName = (CString*)treeCtrl.GetItemData(hTreeCtrlItem); + + // All prefs should specify the prefname attribute in the XML pref element. + // This assertion means that the pref's prefname attribute was not set, or + // that perhaps a prefgroup doesn't have any children (if should, otherwise + // it shouldn't be a group.) + ASSERT(pstrPrefName); + + if (!pstrPrefName) + return; + + // Get the pref tree node with that same pref name. + IXMLDOMElementPtr prefsTreeElement = FindElementFromPrefname(*pstrPrefName); + if (prefsTreeElement) + { + CPrefElement elementNode(prefsTreeElement); + CString* pstrChoices = elementNode.MakeChoiceStringArray(); + + CDlgEditPrefStr dlg; + dlg.m_strType = elementNode.GetPrefType(); + dlg.m_strTitle = elementNode.GetUIName(); + dlg.m_strDescription = elementNode.GetPrefDescription(); + dlg.m_strPrefName = *pstrPrefName; + dlg.m_strValue = elementNode.GetPrefValue(); + dlg.m_bLocked = elementNode.IsLocked(); + dlg.m_pstrChoices = pstrChoices; + dlg.m_strSelectedChoice = elementNode.GetSelectedChoiceString(); + dlg.m_strPrefFile = elementNode.GetPrefFile(); + dlg.m_strInstallFile = elementNode.GetInstallFile(); + dlg.m_bChoose = elementNode.IsChoose(); + + + if (dlg.DoModal() == IDOK) + { + + // Adjust the prefs tree to reflect the changes. The dialog always + // sets m_strValue to a string which can go directly into the prefs + // tree element. For example, bools set 'true' or 'false' and choices + // set '0' or '1' or whatever the value for the selected choice. + elementNode.SetPrefValue(dlg.m_strValue); + elementNode.SetLocked(dlg.m_bLocked); + elementNode.SetPrefFile(dlg.m_strPrefFile); + elementNode.SetInstallFile(dlg.m_strInstallFile); + + // Adjust the tree control to reflect the changes. + treeCtrl.SetItemText(hTreeCtrlItem, elementNode.CreateTreeCtrlLabel()); + treeCtrl.SetItemImage(hTreeCtrlItem, dlg.m_bLocked? 2 : 3, dlg.m_bLocked? 2 : 3); + + } + + delete [] pstrChoices; + + } +} + +// This is to make context menus work properly--there is a quirk in +// CTreeView where you have to double-right click for context menus +// to work. +void CPrefEditView::OnRclick(NMHDR* pNMHDR, LRESULT* pResult) +{ + CTreeCtrl & treeCtrl = GetTreeCtrl(); + + // Get the cursor position for this message + DWORD dwPos = GetMessagePos(); + + // Convert the coords into a CPoint structure + CPoint pt(LOWORD( dwPos ), HIWORD( dwPos )); + CPoint spt; + + spt = pt; + + // convert to screen coords for the hittesting to work + treeCtrl.ScreenToClient( &spt ); + + UINT test; + HTREEITEM hTreeCtrlItem = treeCtrl.HitTest(spt, &test); + + if (hTreeCtrlItem != NULL) + { + // Is the click actually *on* the item? + if (test & TVHT_ONITEM) + { + // Select the item. + treeCtrl.SelectItem(hTreeCtrlItem); + + int submenu; + if (!treeCtrl.ItemHasChildren(hTreeCtrlItem)) // no children == leaf node == pref + submenu = 0; + else + submenu = 1; + + ShowPopupMenu(pt, submenu); + } + } + + *pResult = 0; +} + +// Given a pref name, select the tree control item with that pref name. +void CPrefEditView::SelectPref(CString& rstrPrefName) +{ + CTreeCtrl &treeCtrl = GetTreeCtrl(); + HTREEITEM hRoot = treeCtrl.GetRootItem(); + + HTREEITEM hTreeCtrlItem = FindTreeItemFromPrefname(hRoot, rstrPrefName); + treeCtrl.SelectItem(hTreeCtrlItem); +} + +void CPrefEditView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) +{ + if (nChar == VK_F3) + { + OnFindNextPref(); + } + + else if ((nChar == 0x46) && GetAsyncKeyState(VK_CONTROL)) // Ctrl+F + { + OnFindPref(); + } + + else + { + CTreeView::OnKeyDown(nChar, nRepCnt, nFlags); + } +} diff --git a/mozilla/cck/driver/prefeditview.h b/mozilla/cck/driver/prefeditview.h new file mode 100644 index 00000000000..2b367aad2c8 --- /dev/null +++ b/mozilla/cck/driver/prefeditview.h @@ -0,0 +1,106 @@ +// PrefEditView.h : interface of the CPrefEditView class +// +///////////////////////////////////////////////////////////////////////////// + +#if !defined(AFX_PREFEDITVIEW_H__6ACBEE69_AA14_43BA_B736_DF17EA66A7CE__INCLUDED_) +#define AFX_PREFEDITVIEW_H__6ACBEE69_AA14_43BA_B736_DF17EA66A7CE__INCLUDED_ + +#if _MSC_VER > 1000 +#pragma once +#endif // _MSC_VER > 1000 + +#import "msxml.dll" +using namespace MSXML; + +#include +#include "XMLDOMHelper.h" + + +class CPrefEditView : public CTreeView +{ +protected: + CPrefEditView(); + +// Attributes +public: + + CPrefEditView(CString strXMLFile); + DECLARE_DYNCREATE(CPrefEditView) + +// Operations +public: + + BOOL DoSavePrefsTree(CString strFileName); // save the XML to a file + void DoOpenItem(); // expand the tree, or open the selected item for edit + void DoFindFirst(); // open the Find Pref dialog + void DoFindNext(); // find next item + void DoAdd(); // open the Add Pref dialog + + +// Overrides + // ClassWizard generated virtual function overrides + //{{AFX_VIRTUAL(CPrefEditView) + public: + virtual BOOL PreCreateWindow(CREATESTRUCT& cs); + //}}AFX_VIRTUAL + +// Implementation +public: + virtual ~CPrefEditView(); +#ifdef _DEBUG + virtual void AssertValid() const; + virtual void Dump(CDumpContext& dc) const; +#endif + +protected: + +// Generated message map functions +protected: + //{{AFX_MSG(CPrefEditView) + afx_msg void OnDblclk(NMHDR* pNMHDR, LRESULT* pResult); + afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct); + afx_msg void OnDestroy(); + afx_msg void OnEditPrefItem(); + afx_msg void OnFindPref(); + afx_msg void OnFindNextPref(); + afx_msg void OnAddPref(); + afx_msg void OnRclick(NMHDR* pNMHDR, LRESULT* pResult); + afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags); + + //}}AFX_MSG + DECLARE_MESSAGE_MAP() + +private: + CImageList m_imageList; // padlocks to show which prefs are locked + IXMLDOMDocumentPtr m_pPrefXMLTree; // the actual XML tree which describes the tree control contents + CString m_strXMLFile; // the XML file used to load the m_pPrefXMLTree, and hence the tree control + + // Stuff for Find and FindNext. + IXMLDOMNodeListPtr m_pPrefsList; + int m_iNextElement; + CString m_strFind; + BOOL FindFirst(CString& rstrFind); + BOOL FindNext(); + + + BOOL InitXMLTree(); + HTREEITEM AddNodeToTreeCtrl(IXMLDOMNodePtr prefsTreeNode, HTREEITEM hTreeCtrlParent); + HTREEITEM FindTreeItemFromPrefname(HTREEITEM hItem, CString& rstrPrefName); + IXMLDOMElementPtr FindElementFromPrefname(CString& rstrPrefString); + void SelectPref(CString& rstrPrefName); + void DeleteTreeCtrl(HTREEITEM hParent); + + HTREEITEM AddPref(CString& rstrPrefName, CString& rstrPrefDesc, CString& rstrPrefType); + + void ShowPopupMenu( CPoint& point, int submenu ); + void EditSelectedPrefsItem(); + +}; + + +///////////////////////////////////////////////////////////////////////////// + +//{{AFX_INSERT_LOCATION}} +// Microsoft Visual C++ will insert additional declarations immediately before the previous line. + +#endif // !defined(AFX_PREFEDITVIEW_H__6ACBEE69_AA14_43BA_B736_DF17EA66A7CE__INCLUDED_) diff --git a/mozilla/cck/driver/prefelement.cpp b/mozilla/cck/driver/prefelement.cpp new file mode 100644 index 00000000000..fa06526696f --- /dev/null +++ b/mozilla/cck/driver/prefelement.cpp @@ -0,0 +1,292 @@ +// PrefElement.cpp: implementation of the CPrefElement class. +// +// This is a class with helper functions for the preferences metadata +// XML. +// +// XML Conventions: +// Element tags are in CAPS. +// Attribute names are in lower case. +// When writing bools, use lower case "true" and "false". +// +////////////////////////////////////////////////////////////////////// + +#include "stdafx.h" +#include "PrefElement.h" + +#ifdef _DEBUG +#undef THIS_FILE +static char THIS_FILE[]=__FILE__; +#define new DEBUG_NEW +#endif + + + +////////////////////////////////////////////////////////////////////// +// Construction/Destruction +////////////////////////////////////////////////////////////////////// + +CPrefElement::CPrefElement(IXMLDOMElementPtr element) +: CElementNode(element) +{ + +} + +CPrefElement::~CPrefElement() +{ + +} + +// For a newly created node, initialize it's settings. +void CPrefElement::Initialize(CString strPrefName, CString strPrefDesc, CString strPrefType) +{ + SetAttribute("uiname", strPrefName); + SetAttribute("prefname", strPrefName); + SetAttribute("description", strPrefDesc); + SetAttribute("type", strPrefType); + SetAttribute("lockable", "true"); + + SetLocked(FALSE); + SetInstallFile("browser.xpi"); + SetPrefFile("bin/defaults/pref/all-ns.js"); + + if (strPrefType.CompareNoCase("int") == 0) + SetPrefValue("0"); + else if (strPrefType.CompareNoCase("bool") == 0) + SetPrefValue("true"); + else + SetPrefValue(""); +} + +// For a pref node element, returns a string which is used for the tree ctrl +// label. +CString CPrefElement::CreateTreeCtrlLabel() +{ + CString strLabel = GetAttribute("uiname"); + CString strValue = GetChildElementValue("VALUE"); + + if (IsChoose()) + { + strValue = GetSelectedChoiceString(); + } + + CString strRetVal; + + strRetVal.Format("%s [%s]", strLabel, strValue); + + return strRetVal; +} + +// Check to see if the pref element is locked. +BOOL CPrefElement::IsLocked() +{ + CString strVal = GetChildElementValue("LOCKED"); + return (strVal.CompareNoCase("true") == 0); +} + +// Lock the pref element. +void CPrefElement::SetLocked(BOOL bLocked) +{ + SetChildElementValue("LOCKED", bLocked? "true": "false"); +} + + +// Build a list of choices from the element to pass to the edit dialog. +// Returns an array of CStrings. Caller must delete. +CString* CPrefElement::MakeChoiceStringArray() +{ + CString* choices = NULL; + + IXMLDOMNodeListPtr choiceNodes = m_element->getElementsByTagName("CHOICE"); + if (choiceNodes) + { + // Create an array of CString pointers. + int numChoices = choiceNodes->length; + choices = new CString[numChoices + 1]; + for (int i = 0; i < numChoices; i++) + { + IXMLDOMElementPtr element = choiceNodes->Getitem(i); + CElementNode elementNode(element); + choices[i] = elementNode.GetAttribute("uiname"); + } + choices[numChoices] = ""; + } + + return choices; +} + +// Get the ui name of the selected choice for this pref. +CString CPrefElement::GetSelectedChoiceString() +{ + CString strVal = GetPrefValue(); + + IXMLDOMNodeListPtr choiceNodes = m_element->getElementsByTagName("CHOICE"); + if (choiceNodes) + { + int numChoices = choiceNodes->length; + for (int i = 0; i < numChoices; i++) + { + IXMLDOMElementPtr element = choiceNodes->Getitem(i); + CElementNode elementNode(element); + if (strVal.CompareNoCase(elementNode.GetAttribute("value")) == 0) + { + return elementNode.GetAttribute("uiname"); + } + } + } + + return ""; +} + +CString CPrefElement::GetValueFromChoiceString(CString strChoiceString) +{ + IXMLDOMNodeListPtr choiceNodes = m_element->getElementsByTagName("CHOICE"); + if (choiceNodes) + { + int numChoices = choiceNodes->length; + for (int i = 0; i < numChoices; i++) + { + IXMLDOMElementPtr element = choiceNodes->Getitem(i); + CElementNode elementNode(element); + if (strChoiceString.CompareNoCase(elementNode.GetAttribute("uiname")) == 0) + { + return elementNode.GetAttribute("value"); + } + } + } + return ""; +} + +// Get the ui name of the pref. +CString CPrefElement::GetUIName() +{ + return GetAttribute("uiname"); +} + +// Get the value of the pref. +CString CPrefElement::GetPrefValue() +{ + return GetChildElementValue("VALUE"); +} + +// Set the value of the pref. For "choose", pass +// the uiname string, and this fuction will convert +// to the correct value. +void CPrefElement::SetPrefValue(CString strValue) +{ + if (IsChoose()) + { + SetChildElementValue("VALUE", GetValueFromChoiceString(strValue)); + } + + else + { + SetChildElementValue("VALUE", strValue); + } +} + + + +// Get the Mozilla name of the pref. +CString CPrefElement::GetPrefName() +{ + return GetAttribute("prefname"); +} + +// Get the type of the pref. bool, string, int +CString CPrefElement::GetPrefType() +{ + return GetAttribute("type"); +} + +// Get a long description of the pref. +CString CPrefElement::GetPrefDescription() +{ + return GetAttribute("description"); +} + + +// Return name of installation file. +CString CPrefElement::GetInstallFile() +{ + return GetChildElementValue("INSTALLATIONFILE"); +} + +// Set name of installation file. +void CPrefElement::SetInstallFile(CString strInstallFile) +{ + SetChildElementValue("INSTALLATIONFILE", strInstallFile); +} + +// Return name of pref file. +CString CPrefElement::GetPrefFile() +{ + return GetChildElementValue("PREFFILE"); +} + +// Set name of pref file. +void CPrefElement::SetPrefFile(CString strPrefFile) +{ + SetChildElementValue("PREFFILE", strPrefFile); +} + +// Return true if this is a chooser type pref. +BOOL CPrefElement::IsChoose() +{ + return ChildExists("CHOICES"); +} + +// Return TRUE if the search string exists in any +// of the prefs fields. +BOOL CPrefElement::FindString(CString strFind) +{ + strFind.MakeUpper(); + + CString str = GetUIName(); + str.MakeUpper(); + if (str.Find(strFind) >= 0) + return TRUE; + + str = GetPrefValue(); + str.MakeUpper(); + if (str.Find(strFind) >= 0) + return TRUE; + + str = GetPrefName(); + str.MakeUpper(); + if (str.Find(strFind) >= 0) + return TRUE; + + str = GetPrefType(); + str.MakeUpper(); + if (str.Find(strFind) >= 0) + return TRUE; + + str = GetPrefDescription(); + str.MakeUpper(); + if (str.Find(strFind) >= 0) + return TRUE; + + str = GetInstallFile(); + str.MakeUpper(); + if (str.Find(strFind) >= 0) + return TRUE; + + str = GetPrefFile(); + str.MakeUpper(); + if (str.Find(strFind) >= 0) + return TRUE; + + return FALSE; +} + +void CPrefElement::SetSelected(BOOL bSelected) +{ + SetChildElementValue("SELECTED", bSelected?"true":"false"); +} + + +BOOL CPrefElement::IsSelected() +{ + CString strVal = GetChildElementValue("SELECTED"); + return (strVal.CompareNoCase("true") == 0); +} diff --git a/mozilla/cck/driver/prefelement.h b/mozilla/cck/driver/prefelement.h new file mode 100644 index 00000000000..04e761bbccb --- /dev/null +++ b/mozilla/cck/driver/prefelement.h @@ -0,0 +1,43 @@ +// PrefElement.h: interface for the CPrefElement class. +// +////////////////////////////////////////////////////////////////////// + +#if !defined(AFX_PREFELEMENT_H__C93E84F5_104A_4218_972D_E2A384749B59__INCLUDED_) +#define AFX_PREFELEMENT_H__C93E84F5_104A_4218_972D_E2A384749B59__INCLUDED_ + +#if _MSC_VER > 1000 +#pragma once +#endif // _MSC_VER > 1000 + +#include "XMLDOMHelper.h" + +class CPrefElement : public CElementNode +{ +public: + CPrefElement(IXMLDOMElementPtr element); + virtual ~CPrefElement(); + + void Initialize(CString strPrefName, CString strPrefDesc, CString strPrefType); + CString CreateTreeCtrlLabel(); + BOOL IsLocked(); + void SetLocked(BOOL bLocked); + CString* MakeChoiceStringArray(); + CString GetSelectedChoiceString(); + CString GetUIName(); + CString GetPrefValue(); + void SetPrefValue(CString strValue); + CString GetPrefName(); + CString GetPrefType(); + CString GetPrefDescription(); + CString GetValueFromChoiceString(CString strChoiceString); + CString GetInstallFile(); + void SetInstallFile(CString strInstallFile); + CString GetPrefFile(); + void SetPrefFile(CString strPrefFile); + BOOL IsChoose(); + BOOL FindString(CString strFind); + void SetSelected(BOOL bExpanded); + BOOL IsSelected(); +}; + +#endif // !defined(AFX_PREFELEMENT_H__C93E84F5_104A_4218_972D_E2A384749B59__INCLUDED_) diff --git a/mozilla/cck/driver/prefgroup.cpp b/mozilla/cck/driver/prefgroup.cpp new file mode 100644 index 00000000000..af7ad570823 --- /dev/null +++ b/mozilla/cck/driver/prefgroup.cpp @@ -0,0 +1,33 @@ +// PrefGroup.cpp: implementation of the CPrefGroup class. +// +////////////////////////////////////////////////////////////////////// + +#include "stdafx.h" +#include "PrefGroup.h" + +#ifdef _DEBUG +#undef THIS_FILE +static char THIS_FILE[]=__FILE__; +#define new DEBUG_NEW +#endif + +////////////////////////////////////////////////////////////////////// +// Construction/Destruction +////////////////////////////////////////////////////////////////////// + +CPrefGroup::CPrefGroup(IXMLDOMElementPtr element) +: CElementNode(element) +{ + +} + +CPrefGroup::~CPrefGroup() +{ + +} + +CString CPrefGroup::GetUIName() +{ + return GetAttribute("uiname"); +} + diff --git a/mozilla/cck/driver/prefgroup.h b/mozilla/cck/driver/prefgroup.h new file mode 100644 index 00000000000..bb732380e01 --- /dev/null +++ b/mozilla/cck/driver/prefgroup.h @@ -0,0 +1,23 @@ +// PrefGroup.h: interface for the CPrefGroup class. +// +////////////////////////////////////////////////////////////////////// + +#if !defined(AFX_PREFGROUP_H__D81DF6AF_427E_4AE4_84E8_86ACFEDBE6D3__INCLUDED_) +#define AFX_PREFGROUP_H__D81DF6AF_427E_4AE4_84E8_86ACFEDBE6D3__INCLUDED_ + +#if _MSC_VER > 1000 +#pragma once +#endif // _MSC_VER > 1000 + +#include "XMLDOMHelper.h" + +class CPrefGroup : public CElementNode +{ +public: + CPrefGroup(IXMLDOMElementPtr element); + virtual ~CPrefGroup(); + + CString GetUIName(); +}; + +#endif // !defined(AFX_PREFGROUP_H__D81DF6AF_427E_4AE4_84E8_86ACFEDBE6D3__INCLUDED_) diff --git a/mozilla/cck/driver/res/bitmap1.bmp b/mozilla/cck/driver/res/bitmap1.bmp index 6e8e840620a27fb2fa28f68c860a5eaa5714167a..6f7e1a243e798da4d5c73aabb024fccd1adf46f1 100644 GIT binary patch literal 790 zcmb7CJ5B>J5FI`eRJh{|90MUsR2+a?P#_#BgP$6Y6Tt=^_G4S`}>$lCB?k*xBnNfxVz5) literal 1270 zcmZ?r{l>xo24z4}1BeZvn2`Y@(EybPD?%X}7#M(vp`ign0ZAZ};lP0dKpG_RAB-6O a{|B*v7zjZ^ApR&A4S~@R7!82|3IPD0SCat% diff --git a/mozilla/cck/driver/resource.h b/mozilla/cck/driver/resource.h index fa21e991612..a265f52ae39 100644 --- a/mozilla/cck/driver/resource.h +++ b/mozilla/cck/driver/resource.h @@ -10,37 +10,61 @@ #define IDS_STRING103 103 #define IDR_MAINFRAME 128 #define IDD_BASE_DIALOG 129 +#define IDD_EDITPREF 130 +#define IDB_TREEIMAGES 131 #define IDD_IMAGE_DIALOG 136 #define IDD_DIALOG1 137 #define IDD_CREATE_DIALOG 138 #define IDD_NEW_DIALOG 140 #define IDD_IMG_DLG 141 +#define IDR_POPUP_PREFTREE_MENU 143 +#define IDD_FIND 144 +#define IDR_ACCELERATOR1 145 #define IDD_PROGRESS_DLG 146 +#define IDD_ADDPREF 147 #define IDD_DIALOG112 153 #define IDD_NEWCONFIG_DIALOG 159 #define IDD_DIALOG131 161 +#define IDC_VALUE 1000 +#define IDC_DESCRIPTION 1001 #define IDC_EDIT1 1001 +#define IDC_PREFNAME 1002 +#define IDC_LOCKED 1003 #define IDC_TITLE_TEXT 1003 +#define IDC_VALCHECK 1004 #define IDC_BASE_TEXT 1004 +#define IDC_VALLIST 1005 #define IDC_HELP_BUTTON 1005 #define IDC_BUTTON1 1007 #define ID_HELP_EDIT 1007 #define IDC_STATIC1 1008 #define IDC_STATIC2 1009 +#define IDC_INSTALLFILE 1010 +#define IDC_FIND 1011 +#define IDC_PREFFILE 1012 +#define IDC_PREFDESC 1014 +#define IDC_PREFTYPE_STRING 1015 +#define IDC_PREFTYPE_INT 1016 +#define IDC_PREFTYPE_BOOL 1017 +#define IDC_PREFTYPEGROUP 1018 #define IDC_PROGRESS1 1036 #define IDC_PROGESSTEXT_STATIC 1037 #define IDD_HELP_DLG 1537 #define IDD_SUMMARY 1538 #define IDD_WIZ_HELP 1539 -#define IDC_FEEDBACK_BUTTON 0x02000 +#define IDC_FEEDBACK_BUTTON 0x02000 +#define ID_EDITPREFITEM 32773 +#define ID_FINDPREF 32774 +#define ID_FINDNEXTPREF 32776 +#define ID_ADDPREF 32777 // Next default values for new objects // #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NEXT_RESOURCE_VALUE 142 -#define _APS_NEXT_COMMAND_VALUE 32771 -#define _APS_NEXT_CONTROL_VALUE 1010 +#define _APS_NEXT_RESOURCE_VALUE 148 +#define _APS_NEXT_COMMAND_VALUE 32778 +#define _APS_NEXT_CONTROL_VALUE 1019 #define _APS_NEXT_SYMED_VALUE 101 #endif #endif diff --git a/mozilla/cck/driver/xmldomhelper.cpp b/mozilla/cck/driver/xmldomhelper.cpp new file mode 100644 index 00000000000..25f37a46241 --- /dev/null +++ b/mozilla/cck/driver/xmldomhelper.cpp @@ -0,0 +1,123 @@ +#include "stdafx.h" +#include "XMLDOMHelper.h" + +#ifdef _DEBUG +#define new DEBUG_NEW +#undef THIS_FILE +static char THIS_FILE[] = __FILE__; +#endif + + +CElementNode::CElementNode(IXMLDOMElementPtr element) +: m_element(element) +{ +} + +BOOL CElementNode::ChildExists(CString strTag) +{ + IXMLDOMNodeListPtr prefValNodes = m_element->getElementsByTagName(strTag.GetBuffer(0)); + if (prefValNodes) + return prefValNodes->Getlength() > 0; + else + return FALSE; +} + +CString CElementNode::GetChildElementValue(CString strTag) +{ + _variant_t value; + + IXMLDOMNodeListPtr prefValNodes = m_element->getElementsByTagName(strTag.GetBuffer(0)); + if (prefValNodes) + { + IXMLDOMNodePtr prefValNode = prefValNodes->Getitem(0); // should be only one + if (prefValNode) + { + if (prefValNode->childNodes->Getlength() > 0) + value = prefValNode->childNodes->Getitem(0)->GetnodeValue(); // get the text node child, which contains the text we want. + } + } + + return (char*)_bstr_t(value); +} + +// Set the text of the child element with the tag strTag. Assumes only one child with this tag. +void CElementNode::SetChildElementValue(CString strTag, CString strValue) +{ + _variant_t value = strValue; + + IXMLDOMNodeListPtr prefValNodes = m_element->getElementsByTagName(strTag.GetBuffer(0)); + if (prefValNodes) + { + IXMLDOMNodePtr prefValNode = prefValNodes->Getitem(0); // should be only one + + if (prefValNode == NULL) + { + _variant_t tag = strTag; + prefValNode = m_element->GetownerDocument()->createElement(_bstr_t(tag)); + m_element->appendChild(prefValNode); + } + + if (prefValNode) + { + if (prefValNode->childNodes->Getlength() == 0) + { + IXMLDOMNodePtr newNode = prefValNode->GetownerDocument()->createTextNode(_bstr_t(value)); + prefValNode->appendChild(newNode); + } + else + { + prefValNode->childNodes->Getitem(0)->PutnodeValue(value); // get the text node child, which contains the text we want. + } + } + } + + return; +} + +IXMLDOMNodePtr CElementNode::AddNode(CString strTag) +{ + _variant_t tag = strTag; + IXMLDOMNodePtr newNode = m_element->GetownerDocument()->createElement(_bstr_t(tag)); + m_element->appendChild(newNode); + return newNode; +} + +// Return the value of the specified attribute. +CString CElementNode::GetAttribute(CString strAttributeName) +{ + _variant_t attribValue = m_element->getAttribute(strAttributeName.GetBuffer(0)); + + if (attribValue.vt == VT_NULL) + return ""; + else + return (char*)_bstr_t(attribValue); +} + +void CElementNode::SetAttribute(CString strAttributeName, CString strAttributeValue) +{ + _variant_t attributeName = strAttributeName; + _variant_t attributeValue = strAttributeValue; + + IXMLDOMAttributePtr attribNode = m_element->getAttributeNode(strAttributeName.GetBuffer(0)); + if (attribNode == NULL) + { + + attribNode = m_element->GetownerDocument()->createAttribute(_bstr_t(attributeName)); + m_element->setAttributeNode(attribNode); + } + + m_element->setAttribute(_bstr_t(attributeName), _bstr_t(attributeValue)); +} + +// The name of the node. +CString CElementNode::GetNodeName() +{ + _bstr_t nodeName = m_element->GetnodeName(); + return (char*)nodeName; +} + +CString CElementNode::GetXML() +{ + _bstr_t xml = m_element->xml; + return (char*)xml; +} \ No newline at end of file diff --git a/mozilla/cck/driver/xmldomhelper.h b/mozilla/cck/driver/xmldomhelper.h new file mode 100644 index 00000000000..a88bdd0fec6 --- /dev/null +++ b/mozilla/cck/driver/xmldomhelper.h @@ -0,0 +1,33 @@ +#ifndef XMLDOMHELPER_H +#define XMLDOMHELPER_H + +#if _MSC_VER > 1000 +#pragma once +#endif // _MSC_VER > 1000 + +#import "msxml.dll" +using namespace MSXML; + +// This is a little class for helping to deal with the XML DOM elements. +// It takes care of funny string types and returns everything as CString for +// the class user. +class CElementNode +{ +public: + CElementNode(IXMLDOMElementPtr element); + + CString GetNodeName(); + CString GetChildElementValue(CString strTag); + void SetChildElementValue(CString strTag, CString strValue); + CString GetAttribute(CString strAttributeName); + void SetAttribute(CString strAttributeName, CString strAttributeValue); + CString GetXML(); + IXMLDOMNodePtr AddNode(CString strTag); + BOOL ChildExists(CString strTag); + +protected: + IXMLDOMElementPtr m_element; + +}; + +#endif \ No newline at end of file diff --git a/mozilla/cck/ib/ib.cpp b/mozilla/cck/ib/ib.cpp index b8ce8f162bb..b1dfdf139fc 100644 --- a/mozilla/cck/ib/ib.cpp +++ b/mozilla/cck/ib/ib.cpp @@ -1,3 +1,5 @@ + +// Includes #include "stdafx.h" #include #include @@ -15,6 +17,10 @@ #define CRVALUE 0x0D #define BUF_SIZE 4096 +// for the xml parser used for PrefsTree +#import "msxml.dll" +using namespace MSXML; + // Required disk space for Win build #define WDISK_SPACE 27577549 // Required disk space for Linux build @@ -690,6 +696,122 @@ int ModifyHashedPref(CString HashedPrefsFile, CString PrefName, CString NewPrefV return TRUE; } +// XML DOM helper. Returns the value of a specified child element. +CString GetElementValue(IXMLDOMElementPtr element, CString strTag) +{ + _variant_t value; + + IXMLDOMNodeListPtr prefValNodes = element->getElementsByTagName(strTag.GetBuffer(0)); + if (prefValNodes) + { + IXMLDOMNodePtr prefValNode = prefValNodes->Getitem(0); // should be only one + if (prefValNode) + { + if (prefValNode->childNodes->Getlength() > 0) + value = prefValNode->childNodes->Getitem(0)->GetnodeValue(); // get the text node child, which contains the text we want. + } + } + + return (char*)_bstr_t(value); +} + +// XML DOM helper. Returns the value of the specified attribute. +CString GetAttribute(IXMLDOMElementPtr element, CString strAttributeName) +{ + _variant_t attribValue = element->getAttribute(strAttributeName.GetBuffer(0)); + + if (attribValue.vt == VT_NULL) + return ""; + else + return (char*)_bstr_t(attribValue); +} + +// This processes a prefs tree XML file, adding preferences to install files +// as specified in the prefs tree XML file. See PrefsTree.html for file +// format details. +// +// This function can easily be rewriten to parse the XML file by hand if it +// needs to be ported to a non-MS OS. The XML is pretty simple. +BOOL ProcessPrefsTree(CString strPrefsTreeFile) +{ + + // Create XML DOM instance. + IXMLDOMDocumentPtr prefXMLTree; + HRESULT hr = prefXMLTree.CreateInstance(__uuidof(DOMDocument)); + if (FAILED(hr)) + { + AfxMessageBox("Error creating MS XML DOM.", MB_OK); + return FALSE; + } + + // Load the prefs metadata. This is a representation of the prefs tree as + // it should appear in the tree control. + if (prefXMLTree) + { + CString strPrefsFileURL; + strPrefsFileURL.Format("FILE://%s", strPrefsTreeFile); + + if (!prefXMLTree->load(strPrefsFileURL.GetBuffer(0))) + { + CString strError; + strError.Format("Error loading preferences metadata %s.", strPrefsFileURL); + AfxMessageBox(strError, MB_OK); + prefXMLTree = NULL; + return FALSE; + } + if (prefXMLTree->parseError->errorCode != 0) + { + CString strError; + strError.Format("Bad XML in %s.", strPrefsFileURL); + AfxMessageBox(strError, MB_OK); + prefXMLTree = NULL; + return FALSE; + } + } + + // Go through the list of prefs in the xml and write to prefs file for each one. + IXMLDOMNodeListPtr prefsList = prefXMLTree->getElementsByTagName("PREF"); + for(int i = 0; i < prefsList->length; i++) + { + IXMLDOMElementPtr element = prefsList->Getitem(i); + + CString strPrefName = GetAttribute(element, "prefname"); + CString strPrefType = GetAttribute(element, "type"); + CString strPrefValue = GetElementValue(element, "VALUE"); + CString strLocked = GetElementValue(element, "LOCKED"); + CString strInstallFile = GetElementValue(element, "INSTALLATIONFILE"); + CString strPrefFile = GetElementValue(element, "PREFFILE"); + + if (strPrefName.IsEmpty() || + strPrefType.IsEmpty() || + strInstallFile.IsEmpty() || + strPrefFile.IsEmpty() ) + continue; + + ExtractXPIFile(strInstallFile, strPrefFile); + + BOOL bLocked = (strLocked == "true"); + + // Should go into a hashed file if prefs file is .cfg. + if (strPrefFile.Find(".cfg") > 0) + { + // hashed + ModifyHashedPref(strPrefFile, strPrefName, strPrefValue, strPrefType, bLocked); + + } + else + { + // not hashed + if ((strPrefType == "int") || (strPrefType == "bool") || (strPrefType == "choose")) + ModifyJS2(strPrefFile, strPrefName, strPrefValue, bLocked); + + else // string + ModifyJS(strPrefFile, strPrefName, strPrefValue, bLocked); + + } + } + return TRUE; +} int interpret(char *cmd) @@ -870,7 +992,7 @@ int interpret(char *cmd) ModifyHashedPref(xpifile,entity,newvalue, "string", bLockPref); else if (strcmp(cmdname, "modifyHashedPrefInt") == 0) ModifyHashedPref(xpifile,entity,newvalue, "int", bLockPref); - else if (strcmp(cmdname, "modifyHashedPrefInt") == 0) + else if (strcmp(cmdname, "modifyHashedPrefBool") == 0) ModifyHashedPref(xpifile,entity,newvalue, "bool", bLockPref); else if (strcmp(cmdname, "modifyJS") == 0) ModifyJS(xpifile,entity,newvalue, bLockPref); @@ -893,6 +1015,13 @@ int interpret(char *cmd) else if (strcmp(cmdname, "wrapXPI") == 0) { } + else if (strcmp(cmdname, "processPrefsTree") == 0) + { + + char *prefsTreeFile = strtok(NULL, ",)"); + CString fileWithPath = configPath + "\\" + prefsTreeFile; + ProcessPrefsTree(fileWithPath); + } else return FALSE;//*** We have to handle this condition better.