diff --git a/README.md b/README.md index be1a588..18651f0 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ DFL is a Win32 windowing library for the D language. ![screen shot](./examples/timer/image/screenshot.png "screen shot") ![screen shot](./examples/contextmenu/image/screenshot.png "screen shot") ![screen shot](./examples/toolbar/image/screenshot.png "screen shot") +![screen shot](./examples/richtextbox/image/screenshot.png "screen shot") ## Recent major features - DUB is available for DFL. diff --git a/examples/richtextbox/.gitignore b/examples/richtextbox/.gitignore new file mode 100644 index 0000000..60a5f2a --- /dev/null +++ b/examples/richtextbox/.gitignore @@ -0,0 +1,16 @@ +.dub +docs.json +__dummy.html +docs/ +/hello_dfl +hello_dfl.so +hello_dfl.dylib +hello_dfl.dll +hello_dfl.a +hello_dfl.lib +hello_dfl-test-* +*.exe +*.pdb +*.o +*.obj +*.lst diff --git a/examples/richtextbox/.vscode/launch.json b/examples/richtextbox/.vscode/launch.json new file mode 100644 index 0000000..c6db41a --- /dev/null +++ b/examples/richtextbox/.vscode/launch.json @@ -0,0 +1,13 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "C++ Launch (Windows) richtextbox", + "type": "cppvsdbg", + "request": "launch", + "cwd": "${workspaceRoot}", + "program": "./bin/richtextbox_sample.exe", + "console": "internalConsole" + } + ] +} \ No newline at end of file diff --git a/examples/richtextbox/.vscode/tasks.json b/examples/richtextbox/.vscode/tasks.json new file mode 100644 index 0000000..ba5b899 --- /dev/null +++ b/examples/richtextbox/.vscode/tasks.json @@ -0,0 +1,23 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "type": "dub", + "run": false, + "cwd": ".", + "compiler": "$current", + "archType": "$current", + "buildType": "$current", + "configuration": "$current", + "problemMatcher": [ + "$dmd" + ], + "group": "build", + "label": "dub: Build richtextbox_sample", + "detail": "dub build --compiler=dmd.EXE -a=x86_64 -b=debug -c=application", + "presentation": { + "clear": true + } + } + ] +} \ No newline at end of file diff --git a/examples/richtextbox/README.md b/examples/richtextbox/README.md new file mode 100644 index 0000000..b1a86ca --- /dev/null +++ b/examples/richtextbox/README.md @@ -0,0 +1,2 @@ +# Screen Shot +![screen shot](./image/screenshot.png "screen shot") diff --git a/examples/richtextbox/dub.json b/examples/richtextbox/dub.json new file mode 100644 index 0000000..9ea257d --- /dev/null +++ b/examples/richtextbox/dub.json @@ -0,0 +1,16 @@ +{ + "authors": ["haru-s"], + "copyright": "Copyright (C) 2023 haru-s", + "description": "DFL sample code.", + "name": "richtextbox_sample", + "targetType": "executable", + "targetPath": "bin", + "dependencies": { + "dfl": { + "path": "../../../dfl" + } + }, + "lflags-windows-x86_omf-dmd": ["/exet:nt/su:windows:6.0"], + "lflags-windows-x86_mscoff-dmd": ["/SUBSYSTEM:WINDOWS", "/ENTRY:mainCRTStartup"], + "lflags-windows-x86_64-dmd": ["/SUBSYSTEM:WINDOWS", "/ENTRY:mainCRTStartup"] +} \ No newline at end of file diff --git a/examples/richtextbox/image/screenshot.png b/examples/richtextbox/image/screenshot.png new file mode 100644 index 0000000..f2ce417 Binary files /dev/null and b/examples/richtextbox/image/screenshot.png differ diff --git a/examples/richtextbox/richtextbox.code-workspace b/examples/richtextbox/richtextbox.code-workspace new file mode 100644 index 0000000..7e696bc --- /dev/null +++ b/examples/richtextbox/richtextbox.code-workspace @@ -0,0 +1,12 @@ +{ + "folders": [ + { + "path": "." + } + ], + "settings": { + "d.projectImportPaths": [ + "..\\..\\..\\dfl\\source" + ] + } +} \ No newline at end of file diff --git a/examples/richtextbox/shell.bat b/examples/richtextbox/shell.bat new file mode 100644 index 0000000..49ab56b --- /dev/null +++ b/examples/richtextbox/shell.bat @@ -0,0 +1,3 @@ +set dmd_path=c:\d\dmd2\windows +set dmc_path=c:\dmc\dm +cmd diff --git a/examples/richtextbox/source/richtextbox_sample.d b/examples/richtextbox/source/richtextbox_sample.d new file mode 100644 index 0000000..19f95b4 --- /dev/null +++ b/examples/richtextbox/source/richtextbox_sample.d @@ -0,0 +1,205 @@ +import dfl; +import std.conv; + +version(Have_dfl) // For DUB. +{ +} +else +{ + pragma(lib, "dfl.lib"); +} + +class MainForm : Form +{ + private RichTextBox _textbox1; + private ToolBar _toolBar; + + this() + { + // Form setting + this.text = "RichTextBox sample"; + this.size = Size(800,400); + + // ToolBar setting + _toolBar = new ToolBar; + _toolBar.parent = this; + _toolBar.dock = DockStyle.TOP; + + ToolBarButton button1 = new ToolBarButton("Bold"); + _toolBar.buttonClick ~= (ToolBar tb, ToolBarButtonClickEventArgs e) { + if (e.button is button1) + _textbox1.selectionBold = !_textbox1.selectionBold; + }; + _toolBar.buttons.add(button1); + + ToolBarButton button2 = new ToolBarButton("UnderLine"); + _toolBar.buttonClick ~= (ToolBar tb, ToolBarButtonClickEventArgs e) { + if (e.button is button2) + _textbox1.selectionUnderline = !_textbox1.selectionUnderline; + }; + _toolBar.buttons.add(button2); + + ToolBarButton button3 = new ToolBarButton("Font"); + _toolBar.buttonClick ~= (ToolBar tb, ToolBarButtonClickEventArgs e) { + if (e.button is button3) + { + auto fontDialog = new FontDialog; + DialogResult dr = fontDialog.showDialog(); + if (dr == DialogResult.OK) + _textbox1.selectionFont = fontDialog.font; + } + }; + _toolBar.buttons.add(button3); + + ToolBarButton button4 = new ToolBarButton("BaseUp"); + _toolBar.buttonClick ~= (ToolBar tb, ToolBarButtonClickEventArgs e) { + if (e.button is button4) + { + if (_textbox1.selectionCharOffset <= 0) + _textbox1.selectionCharOffset = 72; + else + _textbox1.selectionCharOffset = 0; + } + }; + _toolBar.buttons.add(button4); + + ToolBarButton button5 = new ToolBarButton("BaseDown"); + _toolBar.buttonClick ~= (ToolBar tb, ToolBarButtonClickEventArgs e) { + if (e.button is button5) + { + if (_textbox1.selectionCharOffset >= 0) + _textbox1.selectionCharOffset = -72; + else + _textbox1.selectionCharOffset = 0; + } + }; + _toolBar.buttons.add(button5); + + ToolBarButton buton6 = new ToolBarButton("F.Color"); + _toolBar.buttonClick ~= (ToolBar tb, ToolBarButtonClickEventArgs e) { + if (e.button is buton6) + { + auto colorDialog = new ColorDialog; + DialogResult dr = colorDialog.showDialog(); + if (dr == DialogResult.OK) + _textbox1.selectionColor = colorDialog.color; + } + }; + _toolBar.buttons.add(buton6); + + ToolBarButton button7 = new ToolBarButton("B.Color"); + _toolBar.buttonClick ~= (ToolBar tb, ToolBarButtonClickEventArgs e) { + if (e.button is button7) + { + auto colorDialog = new ColorDialog; + DialogResult dr = colorDialog.showDialog(); + if (dr == DialogResult.OK) + _textbox1.selectionBackColor = colorDialog.color; + } + }; + _toolBar.buttons.add(button7); + + ToolBarButton button8 = new ToolBarButton("^X"); + _toolBar.buttonClick ~= (ToolBar tb, ToolBarButtonClickEventArgs e) { + if (e.button is button8) + { + _textbox1.selectionSuperscript = !_textbox1.selectionSuperscript; + } + }; + _toolBar.buttons.add(button8); + + ToolBarButton button9 = new ToolBarButton("_X"); + _toolBar.buttonClick ~= (ToolBar tb, ToolBarButtonClickEventArgs e) { + if (e.button is button9) + { + _textbox1.selectionSubscript = !_textbox1.selectionSubscript; + } + }; + _toolBar.buttons.add(button9); + + ToolBarButton button10 = new ToolBarButton("GetText"); + _toolBar.buttonClick ~= (ToolBar tb, ToolBarButtonClickEventArgs e) { + if (e.button is button10) + { + msgBox(_textbox1.selectedText); + } + }; + _toolBar.buttons.add(button10); + + ToolBarButton button11 = new ToolBarButton("InsText"); + _toolBar.buttonClick ~= (ToolBar tb, ToolBarButtonClickEventArgs e) { + if (e.button is button11) + { + _textbox1.selectedText = "[Insert Text]"; + } + }; + _toolBar.buttons.add(button11); + + ToolBarButton buton12 = new ToolBarButton("GetRtf"); + _toolBar.buttonClick ~= (ToolBar tb, ToolBarButtonClickEventArgs e) { + if (e.button is buton12) + { + static if (1) + { + string rtf = _textbox1.selectedRtf; + } + else + { + string rtf = _textbox1.rtf; + } + msgBox(rtf); + + static if (0) + { + _textbox1.rtf = rtf; + } + } + }; + _toolBar.buttons.add(buton12); + + ToolBarButton button13 = new ToolBarButton("GetSelNum"); + _toolBar.buttonClick ~= (ToolBar tb, ToolBarButtonClickEventArgs e) { + if (e.button is button13) + { + msgBox(to!string(_textbox1.selectionLength)); + } + }; + _toolBar.buttons.add(button13); + + ToolBarButton button14 = new ToolBarButton("SetSel(5)"); + _toolBar.buttonClick ~= (ToolBar tb, ToolBarButtonClickEventArgs e) { + if (e.button is button14) + { + _textbox1.selectionLength = 5; + } + }; + _toolBar.buttons.add(button14); + + // RichTextBox setting + _textbox1 = new RichTextBox(); + _textbox1.dock = DockStyle.FILL; + _textbox1.font = new Font(_textbox1.font.name, 14f); + _textbox1.multiline = true; + _textbox1.scrollBars = RichTextBoxScrollBars.FORCED_VERTICAL; + // _textbox1.acceptsReturn = true; // true: Enables RETURN key. + _textbox1.acceptsTab = true; // false: Disables TAB key. + // true: Enables TAB key. But be changed focus only + // because one line textbox is not able to input TAB char. + _textbox1.wordWrap = false; // false: Do not send words that span the right edge to the next line. + _textbox1.text = "Hello.\nhttp://g/ <- click\nこんにちは。"; + _textbox1.linkClicked ~= (RichTextBox sender, LinkClickedEventArgs e) { + msgBox(e.linkText); + }; + _textbox1.parent = this; + } +} + +static this() +{ + // Application.enableVisualStyles(); +} + +void main() +{ + Application.run(new MainForm()); +}