Page 1 of 1

WebGadget edit mode resurrection!

Posted: Fri Aug 18, 2006 7:41 pm
by mrjiles
Hi all, I'm pretty new to Purebasic but I definitely like the power in such a small space. I got into VB for 1+ years, but the move to .NET killed me. I have a couple of app ideas that I would like to program in PB but a lot of it circles around a VERY simple WYSIWYG editor (basic bold, italic, etc. - possibly color features in the future).

I have been searching the forums for quite a while but have been unable to find much (to learn from) in implementing this. I did find this post but am unable to compile:

http://www.purebasic.fr/english/viewtop ... +edit+mode


I'm not looking for a hand out, just being pointed in the right direction.



Any help would be greatly appreciated!

Posted: Fri Aug 18, 2006 8:08 pm
by Flype
hello and welcome to the purebasic forum.

the code you pointed is for PureBasic 3.9x
i guess you use PB4 so here is a quick update.

and thanks to reveals me this cool feature of IE (i didn't know it)

Code: Select all

Enumeration 1 
  #olecmdid_open          
  #olecmdid_new        
  #olecmdid_save          
  #olecmdid_saveas            
  #olecmdid_savecopyas    
  #olecmdid_print        
  #olecmdid_printpreview        
  #olecmdid_pagesetup        
  #olecmdid_spell            
  #olecmdid_properties  
  #olecmdid_cut          
  #olecmdid_copy        
  #olecmdid_paste            
  #olecmdid_pastespecial    
  #olecmdid_undo            
  #olecmdid_redo          
  #olecmdid_selectall        
  #olecmdid_clearselection 
  #olecmdid_zoom            
  #olecmdid_getzoomrange      
  #olecmdid_updatecommands  
  #olecmdid_refresh            
  #olecmdid_stop              
  #olecmdid_hidetoolbars      
  #olecmdid_setprogressmax    
  #olecmdid_setprogresspos  
  #olecmdid_setprogresstext    
  #olecmdid_settitle          
  #olecmdid_setdownloadstate  
  #olecmdid_stopdownload    
  #olecmdid_ontoolbaractivated 
  #olecmdid_find 
  #olecmdid_delete 
  #olecmdid_httpequiv 
  #olecmdid_httpequiv_done 
  #olecmdid_enable_interaction 
  #olecmdid_onunload 
  #olecmdid_propertybag2 
  #olecmdid_prerefresh 
  #olecmdid_showscripterror 
  #olecmdid_showmessage 
  #olecmdid_showfind 
  #olecmdid_showpagesetup 
  #olecmdid_showprint 
  #olecmdid_clos 
  #olecmdid_allowuilesssaveas 
  #olecmdid_dontdownloadcss 
  #olecmdid_updatepagestatus 
  #olecmdid_print2 
  #olecmdid_printpreview2 
  #olecmdid_setprinttemplate 
  #olecmdid_getprinttemplate 
  #olecmdid_pageactionblocked      = 55; no 53 or 54 
  #olecmdid_pageactionuiquery      
  #olecmdid_focusviewcontrols      
  #olecmdid_focusviewcontrolsquery 
  #olecmdid_showpageactionmenu    
EndEnumeration 

Enumeration 0 
  #olecmdexecopt_dodefault      
  #olecmdexecopt_promptuser        
  #olecmdexecopt_dontpromptuser    
  #olecmdexecopt_showhelp        
EndEnumeration 


Enumeration 
  #idm_alignbottom              
  #idm_alignhorizontalcenters  
  #idm_alignleft                
  #idm_alignright              
  #idm_aligntogrid              
  #idm_aligntop                
  #idm_alignverticalcenters    
  #idm_arrangebottom            
  #idm_arrangeright            
  #idm_bringforward            
  #idm_bringtofront            
  #idm_centerhorizontally      
  #idm_centervertically        
  #idm_code                    
  #idm_delete     =17              
  #idm_fontname                
  #idm_fontsize                
  #idm_group                    
  #idm_horizspaceconcatenate    
  #idm_horizspacedecrease      
  #idm_horizspaceincrease      
  #idm_horizspacemakeequal      
  #idm_insertobject            
  #idm_multilevelredo     =30      
  #idm_sendbackward        =32      
  #idm_sendtoback              
  #idm_showtable                
  #idm_sizetocontrol            
  #idm_sizetocontrolheight      
  #idm_sizetocontrolwidth      
  #idm_sizetofit                
  #idm_sizetogrid              
  #idm_snaptogrid              
  #idm_taborder                
  #idm_toolbox                  
  #idm_multilevelundo      =44    
  #idm_ungroup                
  #idm_vertspaceconcatenate    
  #idm_vertspacedecrease        
  #idm_vertspaceincrease        
  #idm_vertspacemakeequal      
  #idm_justifyfull              
  #idm_backcolor                
  #idm_bold                    
  #idm_bordercolor              
  #idm_flat                    
  #idm_forecolor                
  #idm_italic                  
  #idm_justifycenter            
  #idm_justifygeneral          
  #idm_justifyleft              
  #idm_justifyright            
  #idm_raised                  
  #idm_sunken                  
  #idm_underline                
  #idm_chiseled                
  #idm_etched                  
  #idm_shadowed                
  #idm_find                    
  #idm_showgrid               = 69 
EndEnumeration 
#idm_2d_position = 2394 

;#msocmdexecopt_dodefault = 0 
Debug "#IDM_BOLD  = "+Str(#idm_bold ) 

If OpenWindow(0, 0, 0, 640, 480, "WebGadget Edit", #PB_Window_ScreenCentered|#PB_Window_SystemMenu) 
  If CreateGadgetList(WindowID(0))  
    
    WebGadget(0, 5, 5, 630, 340, "www.google.com") 
    ButtonGadget(1, 5, 350, 100, 25, "Bold") 
    ButtonGadget(2, 110, 350, 100, 25, "Test") 
    ButtonGadget(3, 210, 350, 100, 25, "Delete") 
    
    ; get webgadgets IWebBrowser2 interface: 
    Browser.IWebBrowser2 = GetWindowLong_(GadgetID(0), #GWL_USERDATA)    
    
    ; wait For page To be loaded.. 
    Repeat 
      While WindowEvent(): Wend 
      Delay(1) 
      Browser\get_Busy(@IsBusy.l) 
    Until IsBusy = 0 
    
    ; get the document interface 
    If Browser\get_Document(@DocumentDispatch.IDispatch) = #S_OK 
      
      ; query For IHTMLDocument3: 
      If DocumentDispatch\QueryInterface(?IID_IHTMLDocument2, @Document.IHTMLDocument2) = #S_OK 
        
        ; here you have a IHTMLDocument2 pointer,  can work with it... 
        Document\put_designMode("On") ; Turns on Edit Mode 
        ;Document\put_designMode(Ansi2Uni("On")) ; Turns on Edit Mode ; 
        CmdTarget.IOleCommandTarget 
        If DocumentDispatch\QueryInterface(?IID_IOleCommandTarget, @CmdTarget.IOleCommandTarget) = #S_OK 
          
          CmdTarget\Exec(?CGID_MSHTML, #idm_2d_position, #olecmdexecopt_dontpromptuser, @var, NULL) ;Lets you drag  drop items 
          ; CmdTarget\Release() 
        EndIf 
        
        Document\Release() 
      EndIf 
      
      DocumentDispatch\Release()    
    EndIf 
    
    vb.l 
    
    Repeat 
      EventID = WaitWindowEvent() 
      
      If EventID = #PB_Event_Gadget ;checks For the events 
        Select EventGadget() ;Checks For Gadget Events 
          Case 0 
            
            Debug "Web Gadget " 
            
          Case 1 
            Debug "bold button " 
            ;Document\execCommand(Ansi2Uni("Delete"), #False, #Null, @vOut) 
            CmdTarget\Exec(?CGID_MSHTML, #idm_bold,#olecmdexecopt_dontpromptuser  , 0, 0) 
            ; Document\execCommand(Ansi2Uni("Bold"), #False, #Null, @vOut)      
            
          Case 2 
            Debug "test button " 
            Document\queryCommandState("Bold", @vb) 
            ;Document\queryCommandState(Ansi2Uni("Bold"), @vb) 
            MessageRequester("Bold State", Str(vb)) 
            
          Case 3 
            Debug "delete button " 
            CmdTarget\Exec(?CGID_MSHTML, #idm_delete, #olecmdexecopt_dontpromptuser, 0, 0) 
            
        EndSelect 
      EndIf 
      
      If GetForegroundWindow_() = WindowID(0) 
        If GetAsyncKeyState_(#VK_DELETE) 
          
          CmdTarget\Exec(?CGID_MSHTML, #idm_delete, #olecmdexecopt_dontpromptuser, 0, 0) 
        EndIf 
      EndIf 
      
    Until EventID = #PB_Event_CloseWindow 
    If CmdTarget 
      CmdTarget\Release() 
    EndIf 
  EndIf 
EndIf 

End 


DataSection 

IID_IHTMLDocument2:  ; {332c4425-26cb-11d0-b483-00c04fd90119} 
Data.l $332C4425 
Data.w $26CB, $11D0 
Data.b $B4, $83, $00, $C0, $4F, $D9, $01, $19 

IID_IOleCommandTarget:  ; {b722bccb-4e68-101b-a2bc-00aa00404770} 
Data.l $B722BCCB 
Data.w $4E68, $101B 
Data.b $A2, $BC, $00, $AA, $00, $40, $47, $70 
  
CGID_MSHTML: ; { 0xDE4BA900, 0x59CA, 0x11CF, { 0x95, 0x92, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00 } } 
Data.l $DE4BA900 
Data.w $59CA, $11CF 
Data.b $95, $92, $44, $45, $53, $54, $00, $00 
EndDataSection

Posted: Fri Aug 18, 2006 10:53 pm
by mrjiles
Awesome!

Posted: Fri Aug 18, 2006 11:05 pm
by Flype
yes, isn't it ?

for now, you can move objects, cut, copy, bold.

impressive.

now it's time to go to MSDN to extends the features of this sample code.

Posted: Sat Aug 19, 2006 10:19 am
by Num3
Woow!!!

I didn't know the IE control was editor enabled!
This is excellent. You can make an easy text editor with this...

Posted: Sun Aug 20, 2006 4:48 pm
by srod
now it's time to go to MSDN to extends the features of this sample code.
Please post post post post...... :)

How would you save changes in a separate html file?

Posted: Sun Aug 20, 2006 9:56 pm
by Flype
as it is still a classic webgadget, you can use all stuff provided in this thread (i presume) :

http://www.purebasic.fr/english/viewtop ... =webgadget

Posted: Mon Aug 21, 2006 12:01 am
by Dare
Very nice!

Posted: Mon Aug 21, 2006 11:06 pm
by utopiomania
Cool stuff! Replace "www.google.com" with "about:blank" in

Code: Select all

WebGadget(0, 5, 5, 630, 340, "www.google.com")
then right click/view source, then edit and check the source again.

Seems to be possible to save too..

Code: Select all

  #olecmdid_save 

Posted: Tue Oct 10, 2006 2:32 am
by Dare
Hi,

Revisiting, or re-resurrecting.

Can someone kind explain how to store a string in PureBasic's internal VARIANT structure?

And can someone kind also explain how to use #olecmdid_save, #olecmdid_selectall, and #olecmdid_copy parameters with the code above?

Thanks!


Edit:

I am looking for a handout (at least on those questions) as I don't have a clue.

Compiler error

Posted: Tue Oct 10, 2006 7:37 pm
by laborde
When trying to compile the above program, I get a compiler error.
POLINK: error: Unresolved external symbol "_SYS_ToBSTR"??

Re: Compiler error

Posted: Tue Oct 10, 2006 9:23 pm
by oldBear
laborde wrote:When trying to compile the above program, I get a compiler error.
POLINK: error: Unresolved external symbol "_SYS_ToBSTR"??
Are you using the full (non demo) version of PB version 4?

cheers

Posted: Mon Apr 23, 2007 3:35 pm
by Progi1984
Small question : how can i get the design mode ? How can we use the procedure get_designmode of the interface ? I try but without success....