sciter-sdk / go-sciter

Golang bindings of Sciter: the Embeddable HTML/CSS/script engine for modern UI development
https://sciter.com
2.57k stars 268 forks source link

question about native-textarea #159

Open ying911008 opened 6 years ago

ying911008 commented 6 years ago

I have a question about native-textarea, I run test-child-window.htm width sciter.exe(in sciter-sdk\bin\64),after that, I can find the handle of native-textarea , but when I wtite it width golang, I can't find the handle of native-textarea , why?

package main

import (
    "github.com/sciter-sdk/go-sciter"
    "github.com/sciter-sdk/go-sciter/window"
    "log"
)

func main() {
    w, err := window.New(sciter.SW_TITLEBAR|
        sciter.SW_RESIZEABLE|
        sciter.SW_CONTROLS|
        sciter.SW_MAIN|
        sciter.SW_ENABLE_DEBUG,
        nil);
    if err != nil {
        log.Fatal(err);
    }
    w.LoadFile("index.html");
    w.Show();
    w.Run();
}`

`<html>
    <head>
        <meta charset="utf-8">
        <title>Test</title>
        <style>
           body, html{
             margin: 0; 
             padding: 0;
             overflow: hidden;
             height: 100%;
             background: RED;
           }
           native-textarea {
             behavior: native-textarea; // see /sdk/include/behaviors/behavior_native_textarea.cpp
             display:block;
             size:*;
             width: 100%;
             height: 800;
             border:1dip solid;
           }

        </style>
        <script type="text/tiscript">
          event click $(#set) {
            $(#editor).value = "Hello\r\nworld!";
          }
          event click $(#get) {
            $(#out).value = $(#editor).value;
          }
        </script>
    </head>
    <body>
      <native-textarea #editor />
    </body>
</html>
pravic commented 6 years ago

Because that native-textarea behavior is just an example and it is included explicitly in sciter.exe.

If you want to use any of them, you will need to port them (or create your own). Sciter comes by default only with the following list: https://sciter.com/developers/sciter-docs/native-behaviors/

ying911008 commented 6 years ago

OK, thanks. If I want to create my own , for example , I want to embed my another .exe to Sciter, what should I do? I think about to get a handle in Sciter ,and use win32api “SetParent”,Is there a better way?

pravic commented 6 years ago

There is a tutorial, but for C++: https://sciter.com/using-native-child-windows-in-sciter/

As for Go.. You'd need to create a corresponding EventHandler responsible for, say, native window creation, and attach it to the sciter.CallbackHandler.Behaviors map (similar to this). In that case go-sciter will create it and attach to the DOM element when needed.

ying911008 commented 6 years ago

use setCallbackHandlers(w *window.Window), You means that I should attach my exe in OnDataLoaded?I can't understood that well, if possible, can there an example about this? thanks

pravic commented 6 years ago

https://github.com/sciter-sdk/go-sciter/blob/master/examples/handlers/handlers.go is the closest example.

I could create a behavior example, but can't do it right now. Try to dig it on your own: reread the mentioned article, look on C++ behaviors, try to understand what's going on there.

ying911008 commented 6 years ago

OK, thank you very much, I well try to dig it