Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
dhtml editor
#1
i am trying to get the current selection, in the triedit documentation they say:

Code:
Copy      Help
Private Sub GetElementUnderInsertionPoint()
   Dim rg As IHTMLTxtRange
   Dim ctlRg As IHTMLControlRange
   Select Case DHTMLEdit1.DOM.selection.Type
      Case "None", "Text"
         ' This reduces the selection to just the insertion
         ' point. The parentElement method will then return the
         ' element directly under the mouse pointer.
         Set rg = DHTMLEdit1.DOM.selection.createRange
         rg.collapse
         MsgBox rg.parentElement.outerHTML
      Case "Control"
         ' A form or image is selected. The commonParentElement
         ' will return the site selected element.
         Set ctlRg = DHTMLEdit1.DOM.selection.createRange
         MsgBox ctlRg.commonParentElement.outerHTML
   End Select
End Sub

when i control click on dh4.DOM i get
Code:
Copy      Help
IHTMLDocument2  DOM()   .   Property,  read-only
property Document Object Model
.

but where and how do i access DOM.selection ?

thanks
pi
#2
To work with DOM, is used MSHTML type library.

Code:
Copy      Help
,,MSHTML.IHTMLDocument2 doc=dh4.DOM
,,sel(doc.selection.type) ...
#3
ay caramba !
thank you.
pi
#4
i think i asked this before, but can't find the answer.
how do i give a qm dialog my own icon (taskbar and titlebar) ?
pi
#5
Search for WM_SETICON.
#6
:oops: now i remember

i have another question regarding toolbar.

which is better:

place combos in the toolbar or place them on top and add some button spacers ?
(label+combo)

and what is the style for making static text transparent ?

[Image: qm_dhtml_editor_01.jpg]
pi
#7
In QM window, the trigger edit control is child of the toolbar. I don't remember, but I think toolbar relays messages to its parent window. But, if possible, placing the combobox directly on the dialog would be easier.

Don't know about static control. It should be transparent automatically.
#8
There is one problem with dialogs with toolbars. Dialog size, and coordinates of controls depend on font size. To make everything stable, you would have to move/resize all controls, and resize dialog itself. You can use function MoveWindow. Do it on WM_INITDIALOG or/and on WM_SIZE.
#9
for static control bg i found out that it is related to my xp theme.

[Image: qm_dhtml_editor_01_xp.jpg]

and for using a placeholder for combo on top i have to use something like -60
Code:
Copy      Help
DT_TbAddButtons id(4 hDlg) 1101 "[][]-60[][][]" "$qm$\de_ctrl.bmp" styles

-60 is 60px without button, right ?
pi
#10
Quote:-60 is 60px without button, right ?

Yes, it is separator width in pixels.

As you probably know, in dialog template are used not pixels, but "dialog box units". They depend on font size, and even have different width and height.
#11
i was too quick on your sel answer.

i get error:
Error in dhtml: expected IHTMLDocument2
tip: to cast type (query interface), use operator +.

can you take a look on my code please ?
button sel (case 5) is the dummy for the code.

the icl is here

function dhtml

Code:
Copy      Help
\Dialog_Editor
function# hDlg message wParam lParam
;str template.getmacro("dhtml_template")
str template=
;<html>
;<style type="text/css">
;BODY {
;background: #ffffff;
;color: #000000;
;margin: 0px 0px 0px 0px;
;font-family: Arial, Helvetica, sans-serif;
;font-size: 12px;
;color:#666666;
;width: 640px;
;overflow: auto;
;}
;</style>
;<body>
;This is a test
;</body>
;</html>

if(hDlg) goto messages

typelib DHTMLEDLib {683364A1-B37D-11D1-ADC5-006008A5848C} 1.0
type TBBUTTON iBitmap idCommand !fsState !fsStyle !bReserved[2] dwData iString

;declare type and variable for "dialog scope" data
type DHTML_DIALOG_DATA VARIANT'doc txt

DHTML_DIALOG_DATA _d
DHTML_DIALOG_DATA& d=_d
;d.doc="C:\apache2triad\htdocs\emis\varpass.htm"
;d.doc=_s.expandpath("$desktop$\index.html")


if(!ShowDialog("dhtml" &dhtml 0 0 0 0 0 &d)) ret

;BEGIN DIALOG
;0 "" 0x90C80A44 0x100 0 0 370 167 "QM DHTML Editor"
;5 Button 0x54032000 0x0 170 0 48 14 "sel"
;3 Static 0x54000000 0x0 70 3 16 10 "Size"
;9 ComboBox 0x54230243 0x0 88 1 28 213 "Textsize"
;6 ToolbarWindow32 0x5400000D 0x0 2 0 364 14 ""
;4 ActiveX 0x54000000 0x10 2 14 364 148 "DHTMLEDLib.DHTMLEdit"
;END DIALOG
;DIALOG EDITOR: "" 0x2010804 "" ""


ret
;messages
if(message=WM_INITDIALOG) DT_Init(hDlg lParam)
&d=+DT_GetParam(hDlg)
sel message
,case WM_INITDIALOG
,int-- hicon
,hicon=GetIcon("qm_red.ico")
,SendMessage hDlg WM_SETICON 0 hicon
,DHTMLEDLib.DHTMLEdit dh4._getcontrol(id(4 hDlg))
,;dh4.LoadDocument(d.doc)
,dh4.DocumentHTML=template
,dh4.AbsoluteDropMode=1

,;dh4._setevents("dh4__DHTMLEditEvents")
,int styles=WINAPI.TBSTYLE_FLAT
,str icl="editor.icl";str icons labels;_i=0
,rep 3
,,labels.formata("[]")
,,icons.formata("%s,%i[]" icl _i)
,,_i+1
,DT_TbAddButtons id(6 hDlg) 1001 labels icons styles|WINAPI.TBSTYLE_LIST 1
,TO_CBFill(id(9 hDlg) "1[]&2[]3[]4[]5[]6") ;;tip: make copy of this function, as well as for any other function that is not shown in the main popup list when you press .

,ret 1
,case WM_DESTROY
,,DT_DeleteData(hDlg)
,,DestroyIcon hicon
,,DestroyIcon(SendMessage(id(3 hDlg) BM_GETIMAGE IMAGE_ICON 0))
,,DestroyIcon(SendMessage(id(5 hDlg) BM_GETIMAGE IMAGE_ICON 0))
,case WM_COMMAND goto messages2
ret
;messages2
dh4._getcontrol(id(4 hDlg))
VARIANT fz option
sel wParam
,case CBN_SELENDOK<<16|9
,,fz=CB_SelectedItem(lParam)
,,option=DECMD_SETFONTSIZE
,,dh4.ExecCommand(option 0 fz)
,case 1001
,,option=DECMD_BOLD
,,dh4.ExecCommand(option 0)
,case 1002
,,option=DECMD_ITALIC
,,dh4.ExecCommand(option 0)
,case 1003
,,option=DECMD_UNDERLINE
,,dh4.ExecCommand(option 0)
,case 1004
,,option=DECMD_HYPERLINK
,,dh4.ExecCommand(option 0)    

,case 5
,,;MSHTML.IHTMLDocument2 doc=dh4.DOM
,,;sel(doc.selection.type)

,,
,case IDOK DT_Ok hDlg
,case IDCANCEL DT_Cancel hDlg
ret 1

;err+ out _error.description
pi
#12
Shouldn't be such error. I testes, compiles ok, but when I click, gives "no such interface" error. Works well in VB. Some day I'll implement more interfaces for QM ActiveX control container.
#13
what exactly is 'tip: to cast type (query interface), use operator +.' ?

i have to admit that there are some terms in qmscript which i currently don't understand.
pi
#14
read about unary operators in qm help

something1=something2

if error, try

something1=+something2
#15
Web browser control also supports editing. Works better for me.

Code:
Copy      Help
\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages

;declare type and variable for "dialog scope" data
type DHTML_DIALOG_DATA VARIANT'doc txt hicon

DHTML_DIALOG_DATA _d
DHTML_DIALOG_DATA& d=_d
;d.doc="C:\apache2triad\htdocs\emis\varpass.htm"
;d.doc=_s.expandpath("$desktop$\index.html")


if(!ShowDialog("dhtmlpi3" &dhtmlpi3 0 0 0 0 0 &d)) ret

;BEGIN DIALOG
;0 "" 0x90C80A44 0x100 0 0 370 167 "QM DHTML Editor"
;7 Button 0x54012003 0x0 314 2 44 12 "Edit mode"
;5 Button 0x54032000 0x0 170 0 48 14 "HTML"
;3 Static 0x54000000 0x0 70 3 16 10 "Size"
;9 ComboBox 0x54230243 0x0 88 1 28 213 "Textsize"
;6 ToolbarWindow32 0x5400000D 0x0 2 0 364 14 ""
;4 ActiveX 0x54000000 0x10 2 14 364 148 "SHDocVw.WebBrowser"
;END DIALOG
;DIALOG EDITOR: "" 0x2010805 "" ""


ret
;messages
if(message=WM_INITDIALOG) DT_Init(hDlg lParam)
&d=+DT_GetParam(hDlg)
sel message
,case WM_INITDIALOG
,d.hicon=GetIcon("qm_red.ico"); SendMessage hDlg WM_SETICON 0 d.hicon
,SHDocVw.WebBrowser dh4._getcontrol(id(4 hDlg))
,;dh4._setevents("dh4__DHTMLEditEvents")
,
,;str template.getmacro("dhtml_template")
,str template=
;<html>
;<style type="text/css">
;BODY {
;background: #ffffff;
;color: #000000;
;margin: 0px 0px 0px 0px;
;font-family: Arial, Helvetica, sans-serif;
;font-size: 12px;
;color:#666666;
;width: 640px;
;overflow: auto;
;}
;</style>
;<body>
;This is a test
;</body>
;</html>

,str tempfile.expandpath("$temp$\pi dhtml template.htm")
,template.setfile(tempfile)
,tempfile.setwintext(id(4 hDlg))
,but id(7 hDlg) ;;edit mode by default

,int styles=WINAPI.TBSTYLE_FLAT
,str icons labels; for(_i 0 4) labels+"[]"; icons.formata("%s,%i[]" "editor.icl" _i)
,DT_TbAddButtons id(6 hDlg) 1001 labels icons styles|WINAPI.TBSTYLE_LIST 1
,TO_CBFill(id(9 hDlg) "1[]&2[]3[]4[]5[]6") ;;tip: make copy of this function, as well as for any other function that is not shown in the main popup list when you press .

,ret 1
,case WM_DESTROY
,,DT_DeleteData(hDlg)
,,DestroyIcon d.hicon
,case WM_COMMAND goto messages2
ret
;messages2
dh4._getcontrol(id(4 hDlg))
MSHTML.IHTMLDocument2 doc=dh4.Document
VARIANT fz option
sel wParam
,case 7
,_s=iif(but(lParam) "On" "Off")
,doc.designMode=_s; err mes "failed" ;;once was exception

,case CBN_SELENDOK<<16|9 doc.execCommand("FontSize" 0 CB_SelectedItem(lParam))
,case 1001: doc.execCommand("Bold" 0)
,case 1002: doc.execCommand("Italic" 0)
,case 1003: doc.execCommand("Underline" 0)
,case 1004 doc.execCommand("CreateLink" TRUE)
;
,case 5
,MSHTML.IHTMLDocument3 doc3=+doc
,str html=doc3.documentElement.outerHTML
,ShowText "" html
,
,case IDOK DT_Ok hDlg
,case IDCANCEL DT_Cancel hDlg
ret 1

;err+ mes "Error: %s[][9]in: %s" "dhtml editor" "i" _error.description _error.line
#16
Web browser control is nice and has a lot of options 8)

how do i supress the 'document has changed ... save ?' dialog ?

in your example i have to work with static hmtl files, is there a way
to set the document text from a variable ?
i collect the content from a database.
pi
#17
this could be it ?

IHTMLDocument2::write Method
http://msdn.microsoft.com/workshop/brow ... /write.asp[/code]

Code:
Copy      Help
Writes one or more HTML expressions to a document in the specified window.

Syntax

    HRESULT write(      
        SAFEARRAY *psarray
    );

Parameters

    psarray
        [in] BSTRthat specifies the text and HTML tags to write.

Return Value

    Returns S_OK if successful, or an error value otherwise.

Example

    This example shows how to write a string to the document.

        IHTMLDocument2 *document; // Declared earlier in the code
        HRESULT hresult = S_OK;
        VARIANT *param;
        SAFEARRAY *sfArray;
        BSTR bstr = SysAllocString(OLESTR("Written by IHTMLDocument2::write()."));

        // Creates a new one-dimensional array
        sfArray = SafeArrayCreateVector(VT_VARIANT, 0, 1);
        
        if (sfArray == NULL || document == NULL) {
            goto cleanup;
        }

        hresult = SafeArrayAccessData(sfArray,(LPVOID*) & param);
        param->vt = VT_BSTR;
        param->bstrVal = bstr;
        hresult = SafeArrayUnaccessData(sfArray);
        hresult = document->write(sfArray);

    cleanup:
        SysFreeString(bstr);
        if (sfArray != NULL) {
            SafeArrayDestroy(sfArray);
        }
pi
#18
about: protocol can be used. MSDN library knowledge base article "INFO: The "About:" Protocol in Internet Explorer".

Code:
Copy      Help
,str template=
;about:
;<style type="text/css">
;BODY {
;background: #ffffff;
;color: #000000;
;margin: 0px 0px 0px 0px;
;font-family: Arial, Helvetica, sans-serif;
;font-size: 12px;
;color:#666666;
;width: 640px;
;overflow: auto;
;}
;</style>
;<body>
;This is a test
;</body>

,template.setwintext(id(4 hDlg))
#19
Should be without <html> </html>, because about: adds them even if exist.


Forum Jump:


Users browsing this thread: 1 Guest(s)