├── examples ├── example0.tcl ├── example0.cc ├── example1.cc ├── example2.cc ├── example3.cc ├── example4.cc ├── example5.cc └── example6.cc ├── LICENSE ├── cpptk.pc.in ├── README.md ├── configure.ac ├── test ├── test2.cc └── test.cc ├── Makefile.am ├── cpptkconstants.x ├── cpptkoptions.x ├── base ├── cpptkbase.cc └── cpptkbase.h └── cpptk.cc /examples/example0.tcl: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | proc hello {} { 7 | puts "Hello C++/Tk!" 8 | } 9 | 10 | 11 | 12 | 13 | 14 | button ".b" -text "Say Hello" -command hello 15 | pack ".b" -padx 20 -pady 6 16 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Permission to copy, use, modify, sell and distribute this software 2 | is granted provided this copyright notice appears in all copies. 3 | This software is provided "as is" without express or implied 4 | warranty, and with no claim as to its suitability for any purpose. 5 | -------------------------------------------------------------------------------- /examples/example0.cc: -------------------------------------------------------------------------------- 1 | #include "cpptk.h" 2 | #include 3 | 4 | using namespace Tk; 5 | 6 | void hello() { 7 | puts("Hello C++/Tk!"); 8 | } 9 | 10 | int main(int, char *argv[]) 11 | { 12 | init(argv[0]); 13 | 14 | button(".b") -text("Say Hello") -command(hello); 15 | pack(".b") -padx(20) -pady(6); 16 | 17 | runEventLoop(); 18 | } 19 | -------------------------------------------------------------------------------- /examples/example1.cc: -------------------------------------------------------------------------------- 1 | #include "cpptk.h" 2 | #include 3 | 4 | using namespace Tk; 5 | using namespace std; 6 | 7 | int main(int, char *argv[]) 8 | { 9 | try 10 | { 11 | init(argv[0]); 12 | 13 | label(".l") -text("Hello C++/Tk!"); 14 | pack(".l") -padx(20) -pady(6); 15 | 16 | runEventLoop(); 17 | } 18 | catch (exception const &e) 19 | { 20 | cerr << "Error: " << e.what() << '\n'; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /examples/example2.cc: -------------------------------------------------------------------------------- 1 | #include "cpptk.h" 2 | #include 3 | 4 | using namespace Tk; 5 | using namespace std; 6 | 7 | void sayHello() 8 | { 9 | cout << "Hello C++/Tk!" << endl; 10 | } 11 | 12 | int main(int, char *argv[]) 13 | { 14 | try 15 | { 16 | init(argv[0]); 17 | 18 | button(".b") -text("Say Hello") -command(sayHello); 19 | pack(".b") -padx(20) -pady(6); 20 | 21 | runEventLoop(); 22 | } 23 | catch (exception const &e) 24 | { 25 | cerr << "Error: " << e.what() << '\n'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /cpptk.pc.in: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2017 Declan Hoare 3 | # 4 | # Permission to copy, use, modify, sell and distribute this software 5 | # is granted provided this copyright notice appears in all copies. 6 | # This software is provided "as is" without express or implied 7 | # warranty, and with no claim as to its suitability for any purpose. 8 | # 9 | 10 | prefix=@prefix@ 11 | exec_prefix=@exec_prefix@ 12 | libdir=@libdir@ 13 | includedir=@includedir@ 14 | 15 | Name: cpptk 16 | Description: a complete C++ interface to the Tk GUI toolkit 17 | Version: 1.0.3 18 | URL: https://github.com/RogueAI42/cpptk 19 | Requires: tk 20 | Libs: -L${libdir} -lcpptk 21 | Cflags: -I${includedir}/@PACKAGE@ 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # C++/Tk 2 | C++/Tk (cpptk) is a complete C++ interface to the Tk GUI toolkit. 3 | It aims to replicate Tcl syntax within C++. 4 | It was created by Maciej Sobczak and modified by me for compatibility 5 | with Tcl 8.6 and g++ 6, and for Autotools support. 6 | It is licensed under permissive terms similar to the MIT license (see 7 | the LICENSE file). 8 | 9 | The recommended installation method is with Autotools. Run 10 | ``` 11 | autoreconf -i 12 | ./configure 13 | make 14 | ``` 15 | to build the library and then `make install` as root to install. You can 16 | then link against the library using pkg-config. 17 | 18 | Complete documentation can be found in the "doc" directory. 19 | 20 | ## TODO 21 | * Some tests are currently disabled due to floating point errors. 22 | There may be a way to fix them properly. 23 | * Remove Boost dependency if at all possible. 24 | -------------------------------------------------------------------------------- /configure.ac: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2017 Declan Hoare 3 | # 4 | # Permission to copy, use, modify, sell and distribute this software 5 | # is granted provided this copyright notice appears in all copies. 6 | # This software is provided "as is" without express or implied 7 | # warranty, and with no claim as to its suitability for any purpose. 8 | # 9 | 10 | AC_INIT([cpptk], [1.0.3], [https://github.com/RogueAI42/cpptk/issues], [cpptk], [https://github.com/RogueAI42/cpptk]) 11 | AC_CONFIG_SRCDIR([cpptk.cc]) 12 | AC_CONFIG_MACRO_DIRS([m4]) 13 | AC_CONFIG_AUX_DIR([build-aux]) 14 | AC_ARG_ENABLE([examples], 15 | AS_HELP_STRING([--enable-examples], [Build example programs])) 16 | AM_INIT_AUTOMAKE([1.11 -Wall foreign subdir-objects]) 17 | AM_CONDITIONAL([ENABLE_EXAMPLES], [test "$enable_examples" = "yes"]) 18 | AC_CONFIG_FILES([Makefile cpptk.pc]) 19 | AC_PROG_CXX 20 | AM_PROG_AR 21 | PKG_CHECK_MODULES([TK], [tk]) 22 | PKG_INSTALLDIR 23 | LT_INIT 24 | AC_OUTPUT 25 | -------------------------------------------------------------------------------- /examples/example3.cc: -------------------------------------------------------------------------------- 1 | #include "cpptk.h" 2 | #include 3 | 4 | using namespace Tk; 5 | using namespace std; 6 | 7 | // these variables are used to communicate with widgets 8 | string str; 9 | int len; 10 | 11 | // 'check' validates user input 12 | bool check(string const &s) 13 | { 14 | return s.size() <= 12; 15 | } 16 | 17 | void compute() 18 | { 19 | len = static_cast(str.size()); 20 | } 21 | 22 | int main(int, char *argv[]) 23 | { 24 | try 25 | { 26 | init(argv[0]); 27 | 28 | label(".lab1") -text("strlen("); 29 | 30 | // create entry widget with validation 31 | entry(".e1") -textvariable(str) -validate(key) 32 | -validatecommand(check, valid_P) -width(20); 33 | 34 | label(".lab2") -text(")"); 35 | 36 | button(".b") -text(" = ") -command(compute); 37 | 38 | entry(".e2") -textvariable(len) -width(5) -justify(Tk::right); 39 | 40 | pack(".lab1", ".e1", ".lab2", ".b", ".e2") -side(Tk::left) -padx(5); 41 | 42 | runEventLoop(); 43 | } 44 | catch (exception const &e) 45 | { 46 | cerr << "Error: " << e.what() << '\n'; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /test/test2.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2004-2006, Maciej Sobczak 3 | // 4 | // Permission to copy, use, modify, sell and distribute this software 5 | // is granted provided this copyright notice appears in all copies. 6 | // This software is provided "as is" without express or implied 7 | // warranty, and with no claim as to its suitability for any purpose. 8 | // 9 | 10 | #include "../cpptk.h" 11 | #include 12 | #include 13 | #include 14 | 15 | using namespace Tk; 16 | 17 | int main(int, char *argv[]) 18 | { 19 | try 20 | { 21 | init(argv[0]); 22 | 23 | std::string str; 24 | int i; 25 | 26 | str = std::string(eval("return \"ala ma kota\"")); 27 | assert(str == "ala ma kota"); 28 | 29 | i = eval("return 5"); 30 | assert(i == 5); 31 | 32 | double d = eval("return 3.14159"); 33 | assert(std::fabs(d - 3.14159) < 0.00001); 34 | 35 | Point p = eval("return {3 4}"); 36 | assert(p.x == 3 && p.y == 4); 37 | 38 | Box b = eval("return {6 7 8 9}"); 39 | assert(b.x1 == 6 && b.y1 == 7 && b.x2 == 8 && b.y2 == 9); 40 | 41 | std::pair p2 = eval("return {3 4}"); 42 | assert(p2.first == 3 && p2.second == 4); 43 | 44 | std::pair p3 = eval("return {ala ma}"); 45 | assert(p3.first == "ala" && p3.second == "ma"); 46 | 47 | std::vector v1 = eval("return {1 2 3 4 5 6 7}"); 48 | assert(v1.size() == 7); 49 | assert(v1[0] == 1 && v1[1] == 2 && v1[2] == 3 && v1[3] == 4 50 | && v1[4] == 5 && v1[5] == 6 && v1[6] == 7); 51 | 52 | std::vector v2 = eval("return {ala ma {nowego kota}}"); 53 | assert(v2.size() == 3); 54 | assert(v2[0] == "ala"); 55 | assert(v2[1] == "ma"); 56 | assert(v2[2] == "nowego kota"); 57 | 58 | 59 | std::cout << "conversion test OK\n"; 60 | } 61 | catch(std::exception const &e) 62 | { 63 | std::cerr << "Error: " << e.what() << '\n'; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /examples/example4.cc: -------------------------------------------------------------------------------- 1 | #include "cpptk.h" 2 | #include 3 | #include 4 | 5 | using namespace Tk; 6 | 7 | // this procedure will support the "File->Open" menu command 8 | void openFile() 9 | { 10 | // open standard "Open File" dialog 11 | 12 | std::string fileName(tk_getOpenFile()); 13 | 14 | // read the file 15 | 16 | std::ifstream f(fileName.c_str()); 17 | std::string fileContent( 18 | std::istreambuf_iterator(f.rdbuf()), 19 | std::istreambuf_iterator()); 20 | 21 | // put the file content into the text widget 22 | 23 | ".t" << deletetext(txt(1,0), end); 24 | ".t" << insert(end, fileContent); 25 | } 26 | 27 | // this procedure will support the "File->Save" menu command 28 | void saveFile() 29 | { 30 | // open standard "Save File" dialog 31 | 32 | std::string fileName(tk_getSaveFile()); 33 | 34 | // get the content from the text widget 35 | 36 | std::string content(".t" << get(txt(1,0), end)); 37 | 38 | // write the file 39 | 40 | std::ofstream f(fileName.c_str()); 41 | f << content; 42 | } 43 | 44 | int main(int, char *argv[]) 45 | { 46 | try 47 | { 48 | init(argv[0]); 49 | 50 | // create the menubar 51 | 52 | frame(".mbar") -borderwidth(1) -relief(raised); 53 | pack(".mbar") -Tk::fill(x); 54 | 55 | // create the menu File entry 56 | 57 | menubutton(".mbar.file") -text("File") -submenu(".mbar.file.m"); 58 | pack(".mbar.file") -side(Tk::left); 59 | 60 | // create the drop-down menu 61 | 62 | std::string drop(menu(".mbar.file.m")); 63 | drop << add(command) -menulabel("Open") -command(openFile); 64 | drop << add(command) -menulabel("Save") -command(saveFile); 65 | drop << add(command) -menulabel("Exit") -command(std::string("exit")); 66 | 67 | // create the text widget with its scrollbar 68 | 69 | textw(".t") -background("white") -yscrollcommand(".s set"); 70 | scrollbar(".s") -command(std::string(".t yview")); 71 | pack(".s") -side(Tk::right) -Tk::fill(y); 72 | pack(".t") -expand(true) -Tk::fill(both); 73 | 74 | runEventLoop(); 75 | } 76 | catch (std::exception const &e) 77 | { 78 | std::cerr << "Error: " << e.what() << '\n'; 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2017 Declan Hoare 3 | # 4 | # Permission to copy, use, modify, sell and distribute this software 5 | # is granted provided this copyright notice appears in all copies. 6 | # This software is provided "as is" without express or implied 7 | # warranty, and with no claim as to its suitability for any purpose. 8 | # 9 | 10 | ACLOCAL_AMFLAGS = -I m4 11 | 12 | # the library 13 | lib_LTLIBRARIES = libcpptk.la 14 | nobase_pkginclude_HEADERS = base/cpptkbase.h cpptkoptions.x cpptkconstants.x cpptk.h 15 | libcpptk_la_SOURCES = base/cpptkbase.cc cpptk.cc 16 | libcpptk_la_CXXFLAGS = @TK_CFLAGS@ 17 | libcpptk_la_LDFLAGS = -version-info 0:0:0 @TK_LIBS@ 18 | 19 | # pkg-config information 20 | pkgconfig_DATA = cpptk.pc 21 | 22 | # test suite 23 | check_PROGRAMS = cpptktest cpptktest2 24 | cpptktest_SOURCES = base/cpptkbase.cc cpptk.cc test/test.cc 25 | cpptktest_CXXFLAGS = @TK_CFLAGS@ -DCPPTK_DUMP_COMMANDS -DCPPTK_DONT_EVALUATE 26 | cpptktest_LDFLAGS = @TK_LIBS@ 27 | cpptktest2_SOURCES = test/test2.cc 28 | cpptktest2_CXXFLAGS = @TK_CFLAGS@ 29 | cpptktest2_LDFLAGS = @TK_LIBS@ -lcpptk 30 | TESTS = $(check_PROGRAMS) 31 | 32 | # example programs 33 | if ENABLE_EXAMPLES 34 | bin_PROGRAMS = cpptk-example0 cpptk-example1 cpptk-example2 cpptk-example3 cpptk-example4 cpptk-example5 cpptk-example6 35 | cpptk_example0_SOURCES = examples/example0.cc 36 | cpptk_example0_CXXFLAGS = @TK_CFLAGS@ 37 | cpptk_example0_LDFLAGS = @TK_LIBS@ -lcpptk 38 | EXTRA_cpptk_example0_DEPENDENCIES = libcpptk.la 39 | cpptk_example1_SOURCES = examples/example1.cc 40 | cpptk_example1_CXXFLAGS = @TK_CFLAGS@ 41 | cpptk_example1_LDFLAGS = @TK_LIBS@ -lcpptk 42 | EXTRA_cpptk_example1_DEPENDENCIES = libcpptk.la 43 | cpptk_example2_SOURCES = examples/example2.cc 44 | cpptk_example2_CXXFLAGS = @TK_CFLAGS@ 45 | cpptk_example2_LDFLAGS = @TK_LIBS@ -lcpptk 46 | EXTRA_cpptk_example2_DEPENDENCIES = libcpptk.la 47 | cpptk_example3_SOURCES = examples/example3.cc 48 | cpptk_example3_CXXFLAGS = @TK_CFLAGS@ 49 | cpptk_example3_LDFLAGS = @TK_LIBS@ -lcpptk 50 | EXTRA_cpptk_example3_DEPENDENCIES = libcpptk.la 51 | cpptk_example4_SOURCES = examples/example4.cc 52 | cpptk_example4_CXXFLAGS = @TK_CFLAGS@ 53 | cpptk_example4_LDFLAGS = @TK_LIBS@ -lcpptk 54 | EXTRA_cpptk_example4_DEPENDENCIES = libcpptk.la 55 | cpptk_example5_SOURCES = examples/example5.cc 56 | cpptk_example5_CXXFLAGS = @TK_CFLAGS@ 57 | cpptk_example5_LDFLAGS = @TK_LIBS@ -lcpptk 58 | EXTRA_cpptk_example5_DEPENDENCIES = libcpptk.la 59 | cpptk_example6_SOURCES = examples/example6.cc 60 | cpptk_example6_CXXFLAGS = @TK_CFLAGS@ 61 | cpptk_example6_LDFLAGS = @TK_LIBS@ -lcpptk 62 | EXTRA_cpptk_example6_DEPENDENCIES = libcpptk.la 63 | endif 64 | 65 | # documentation 66 | html_DATA = doc/doc.html 67 | -------------------------------------------------------------------------------- /examples/example5.cc: -------------------------------------------------------------------------------- 1 | #include "cpptk.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | using namespace Tk; 8 | using namespace std; 9 | 10 | // parameters of the animation 11 | int initLen = 100; 12 | int delay = 50; 13 | double x1d = 0.02; 14 | double y1d = 0.03; 15 | double x2d = 0.04; 16 | double y2d = 0.05; 17 | double rd = 0.01; 18 | double gd = 0.02; 19 | double bd = 0.03; 20 | 21 | // queue of lines 22 | queue lines; 23 | 24 | // this function creates and draws a new line 25 | void newLine() 26 | { 27 | static double x1a = 0.0; 28 | static double y1a = 0.0; 29 | static double x2a = 0.0; 30 | static double y2a = 0.0; 31 | static double ra = 0.0; 32 | static double ga = 0.0; 33 | static double ba = 0.0; 34 | 35 | // get the current size of the canvas 36 | int w = winfo(width, ".c"); 37 | int h = winfo(height, ".c"); 38 | 39 | // compute the coordinates of the new line 40 | Point p1(static_cast(w / 2 * (1 + sin(x1a))), 41 | static_cast(h / 2 * (1 + sin(y1a)))); 42 | Point p2(static_cast(w / 2 * (1 + sin(x2a))), 43 | static_cast(h / 2 * (1 + sin(y2a)))); 44 | 45 | // compute the color of the new line 46 | int r = static_cast(127 * (1 + sin(ra))); 47 | int g = static_cast(127 * (1 + sin(ga))); 48 | int b = static_cast(127 * (1 + sin(ba))); 49 | 50 | // draw the line and add its id to the queue 51 | lines.push(".c" << create(line, p1, p2) -Tk::fill(rgb(r, g, b))); 52 | 53 | x1a += x1d; 54 | y1a += y1d; 55 | x2a += x2d; 56 | y2a += y2d; 57 | ra += rd; 58 | ga += gd; 59 | ba += ::bd; 60 | } 61 | 62 | // note: this is used so that there is 63 | // only one callback registration 64 | string afterCommand; 65 | 66 | // this function makes each step of the animation 67 | void nextStep() 68 | { 69 | newLine(); 70 | 71 | // remove the oldest line from the queue and from the screen 72 | ".c" << deleteitem(lines.front()); 73 | lines.pop(); 74 | 75 | // call me again 76 | after(delay, afterCommand); 77 | } 78 | 79 | int main(int, char *argv[]) 80 | { 81 | try 82 | { 83 | init(argv[0]); 84 | 85 | // create the canvas widget 86 | 87 | pack(canvas(".c") -background("black")) 88 | -expand(true) -Tk::fill(both); 89 | update(); 90 | 91 | // create the first initLen lines 92 | for (int i = 0; i != initLen; ++i) 93 | { 94 | newLine(); 95 | } 96 | 97 | // register the callback function 98 | afterCommand = callback(nextStep); 99 | 100 | // start animation 101 | after(delay, afterCommand); 102 | 103 | runEventLoop(); 104 | } 105 | catch (exception const &e) 106 | { 107 | cerr << "Error: " << e.what() << '\n'; 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /examples/example6.cc: -------------------------------------------------------------------------------- 1 | #include "cpptk.h" 2 | #include 3 | 4 | using namespace Tk; 5 | 6 | // parameters of the array 7 | int const arrayWidth = 30; 8 | int const arrayHeight = 30; 9 | int squareSize = 10; 10 | 11 | // logical array (on/off) 12 | bool cells[arrayWidth][arrayHeight]; 13 | 14 | // array of canvas elements id 15 | std::string squares[arrayWidth][arrayHeight]; 16 | 17 | void setCell(int i, int j, bool state) 18 | { 19 | ::cells[i][j] = state; 20 | if (state) 21 | { 22 | ".c" << itemconfigure(squares[i][j]) -Tk::fill("red"); 23 | } 24 | else 25 | { 26 | ".c" << itemconfigure(squares[i][j]) -Tk::fill("white"); 27 | } 28 | } 29 | 30 | // clears the whole array 31 | void clear() 32 | { 33 | for (int i = 0; i != arrayWidth; ++i) 34 | { 35 | for (int j = 0; j != arrayHeight; ++j) 36 | { 37 | setCell(i, j, false); 38 | } 39 | } 40 | } 41 | 42 | // changes the state of some cell (in response to mouse click) 43 | void click(int x, int y) 44 | { 45 | // find the logical coordinates 46 | int i = (x - 1) / squareSize; 47 | int j = (y - 1) / squareSize; 48 | 49 | // toggle the state 50 | bool newState = !::cells[i][j]; 51 | setCell(i, j, newState); 52 | } 53 | 54 | // computes the next generation 55 | void nextStep() 56 | { 57 | int neighbours[arrayWidth][arrayHeight]; 58 | 59 | // initialize the neighbours counters 60 | for (int i = 1; i != arrayWidth - 1; ++i) 61 | { 62 | for (int j = 1; j != arrayHeight - 1; ++j) 63 | { 64 | neighbours[i][j] = 0; 65 | } 66 | } 67 | 68 | // count the neighbours of each cell 69 | for (int i = 1; i != arrayWidth - 1; ++i) 70 | { 71 | for (int j = 1; j != arrayHeight - 1; ++j) 72 | { 73 | if (::cells[i-1][j-1]) ++neighbours[i][j]; 74 | if (::cells[i ][j-1]) ++neighbours[i][j]; 75 | if (::cells[i+1][j-1]) ++neighbours[i][j]; 76 | if (::cells[i-1][j ]) ++neighbours[i][j]; 77 | if (::cells[i+1][j ]) ++neighbours[i][j]; 78 | if (::cells[i-1][j+1]) ++neighbours[i][j]; 79 | if (::cells[i ][j+1]) ++neighbours[i][j]; 80 | if (::cells[i+1][j+1]) ++neighbours[i][j]; 81 | } 82 | } 83 | 84 | // update the cells (kill or give birth) 85 | for (int i = 1; i != arrayWidth - 1; ++i) 86 | { 87 | for (int j = 1; j != arrayHeight - 1; ++j) 88 | { 89 | if (::cells[i][j] == false && neighbours[i][j] == 3) 90 | { 91 | // new cell is born 92 | setCell(i, j, true); 93 | } 94 | else if (::cells[i][j] == true && 95 | (neighbours[i][j] == 2 || neighbours[i][j] == 3)) 96 | { 97 | // remains alive 98 | } 99 | else 100 | { 101 | // dies from overcrowding or loneliness or remains dead 102 | setCell(i, j, false); 103 | } 104 | } 105 | } 106 | } 107 | 108 | int main(int, char *argv[]) 109 | { 110 | try 111 | { 112 | init(argv[0]); 113 | 114 | // create the control buttons 115 | 116 | frame(".f") -relief(raised) -borderwidth(1); 117 | button(".f.clear") -text("Clear") -command(::clear); 118 | button(".f.next") -text("Next") -command(nextStep); 119 | pack(".f") -side(bottom) -Tk::fill(x); 120 | pack(".f.clear", ".f.next") -side(Tk::left) -pady(5) -expand(true); 121 | 122 | // create the canvas widget 123 | 124 | canvas(".c") -background("white") 125 | -width(squareSize * arrayWidth) 126 | -height(squareSize * arrayHeight); 127 | pack(".c") -side(top); 128 | 129 | // create and initialize the array of cells 130 | 131 | for (int i = 0; i != arrayWidth; ++i) 132 | { 133 | for (int j = 0; j != arrayHeight; ++j) 134 | { 135 | ::cells[i][j] = false; 136 | 137 | Point p1(i * squareSize, j * squareSize); 138 | Point p2((i + 1) * squareSize, (j + 1) * squareSize); 139 | 140 | std::string squareId( 141 | ".c" << create(rectangle, p1, p2) 142 | -outline("black") -Tk::fill("white") 143 | ); 144 | squares[i][j] = squareId; 145 | } 146 | } 147 | 148 | // bind the mouse click so that it is possible 149 | // to interact with the cells 150 | 151 | bind(".c", "", click, event_x, event_y); 152 | 153 | wm(resizable, ".", false, false); 154 | 155 | runEventLoop(); 156 | } 157 | catch (std::exception const &e) 158 | { 159 | std::cerr << "Error: " << e.what() << '\n'; 160 | } 161 | } 162 | -------------------------------------------------------------------------------- /cpptkconstants.x: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2004-2006, Maciej Sobczak 3 | // 4 | // Permission to copy, use, modify, sell and distribute this software 5 | // is granted provided this copyright notice appears in all copies. 6 | // This software is provided "as is" without express or implied 7 | // warranty, and with no claim as to its suitability for any purpose. 8 | // 9 | 10 | CPPTK_CONSTANT(abortretryignore) 11 | CPPTK_CONSTANT(above) 12 | CPPTK_CONSTANT(accessory) 13 | CPPTK_CONSTANT(active) 14 | CPPTK_CONSTANT(adjust) 15 | CPPTK_CONSTANT(application) 16 | CPPTK_CONSTANT(append) 17 | CPPTK_CONSTANT(arc) 18 | CPPTK_CONSTANT(arrow1) 19 | CPPTK_CONSTANT(arrow2) 20 | CPPTK_CONSTANT(atom) 21 | CPPTK_CONSTANT(atomname) 22 | CPPTK_CONSTANT(baseline) 23 | CPPTK_CONSTANT(below) 24 | CPPTK_CONSTANT(bevel) 25 | CPPTK_CONSTANT(bezier) 26 | CPPTK_CONSTANT(both) 27 | CPPTK_CONSTANT(bottom) 28 | CPPTK_CONSTANT(browse) 29 | CPPTK_CONSTANT(butt) 30 | CPPTK_CONSTANT(cancel) 31 | CPPTK_CONSTANT(cascade) 32 | CPPTK_CONSTANT(caution) 33 | CPPTK_CONSTANT(cdrom) 34 | CPPTK_CONSTANT(cells) 35 | CPPTK_CONSTANT(center) 36 | CPPTK_CONSTANT(children) 37 | CPPTK_CONSTANT(chord) 38 | CPPTK_CONSTANT(clear) 39 | CPPTK_CONSTANT(client) 40 | CPPTK_CONSTANT(closest) 41 | CPPTK_CONSTANT(color) 42 | CPPTK_CONSTANT(colormapfull) 43 | CPPTK_CONSTANT(columnconfigure) 44 | CPPTK_CONSTANT(containing) 45 | CPPTK_CONSTANT(coord) 46 | CPPTK_CONSTANT(current) 47 | CPPTK_CONSTANT(deiconify) 48 | CPPTK_CONSTANT(depth) 49 | CPPTK_CONSTANT(disabled) 50 | CPPTK_CONSTANT(document) 51 | CPPTK_CONSTANT(dotbox) 52 | CPPTK_CONSTANT(dragto) 53 | CPPTK_CONSTANT(e) 54 | CPPTK_CONSTANT(edition) 55 | CPPTK_CONSTANT(element) 56 | CPPTK_CONSTANT(enclosed) 57 | CPPTK_CONSTANT(end) 58 | CPPTK_CONSTANT(error) 59 | CPPTK_CONSTANT(exists) 60 | CPPTK_CONSTANT(extended) 61 | CPPTK_CONSTANT(families) 62 | CPPTK_CONSTANT(first) 63 | CPPTK_CONSTANT(flat) 64 | CPPTK_CONSTANT(floppy) 65 | CPPTK_CONSTANT(focusin) 66 | CPPTK_CONSTANT(focusmodel) 67 | CPPTK_CONSTANT(focusout) 68 | CPPTK_CONSTANT(folder) 69 | CPPTK_CONSTANT(fpixels) 70 | CPPTK_CONSTANT(geometry) 71 | CPPTK_CONSTANT(gravity) 72 | CPPTK_CONSTANT(gray) 73 | CPPTK_CONSTANT(gray12) 74 | CPPTK_CONSTANT(gray25) 75 | CPPTK_CONSTANT(gray50) 76 | CPPTK_CONSTANT(gray75) 77 | CPPTK_CONSTANT(groove) 78 | CPPTK_CONSTANT(group) 79 | CPPTK_CONSTANT(guesthead) 80 | CPPTK_CONSTANT(hidden) 81 | CPPTK_CONSTANT(hourglass) 82 | CPPTK_CONSTANT(horizontal) 83 | CPPTK_CONSTANT(iconbitmap) 84 | CPPTK_CONSTANT(iconic) 85 | CPPTK_CONSTANT(iconify) 86 | CPPTK_CONSTANT(iconmask) 87 | CPPTK_CONSTANT(iconname) 88 | CPPTK_CONSTANT(iconposition) 89 | CPPTK_CONSTANT(iconwindow) 90 | CPPTK_CONSTANT(id) 91 | CPPTK_CONSTANT(idletasks) 92 | CPPTK_CONSTANT(ignore) 93 | CPPTK_CONSTANT(includes) 94 | CPPTK_CONSTANT(info) 95 | CPPTK_CONSTANT(inside) 96 | CPPTK_CONSTANT(interactive) 97 | CPPTK_CONSTANT(inuse) 98 | CPPTK_CONSTANT(isabove) 99 | CPPTK_CONSTANT(isbelow) 100 | CPPTK_CONSTANT(ismapped) 101 | CPPTK_CONSTANT(item) 102 | CPPTK_CONSTANT(key) 103 | CPPTK_CONSTANT(last) 104 | CPPTK_CONSTANT(left) 105 | CPPTK_CONSTANT(line) 106 | CPPTK_CONSTANT(lineend) 107 | CPPTK_CONSTANT(linestart) 108 | CPPTK_CONSTANT(location) 109 | CPPTK_CONSTANT(manager) 110 | CPPTK_CONSTANT(maxsize) 111 | CPPTK_CONSTANT(menubar) 112 | CPPTK_CONSTANT(miter) 113 | CPPTK_CONSTANT(modified) 114 | CPPTK_CONSTANT(mono) 115 | CPPTK_CONSTANT(n) 116 | CPPTK_CONSTANT(names) 117 | CPPTK_CONSTANT(ne) 118 | CPPTK_CONSTANT(next) 119 | CPPTK_CONSTANT(nextrange) 120 | CPPTK_CONSTANT(none) 121 | CPPTK_CONSTANT(normal) 122 | CPPTK_CONSTANT(note) 123 | CPPTK_CONSTANT(nw) 124 | CPPTK_CONSTANT(ok) 125 | CPPTK_CONSTANT(okcancel) 126 | CPPTK_CONSTANT(outside) 127 | CPPTK_CONSTANT(oval) 128 | CPPTK_CONSTANT(overlapping) 129 | CPPTK_CONSTANT(overlay) 130 | CPPTK_CONSTANT(overrideredirect) 131 | CPPTK_CONSTANT(pages) 132 | CPPTK_CONSTANT(passive) 133 | CPPTK_CONSTANT(pathname) 134 | CPPTK_CONSTANT(pfolder) 135 | CPPTK_CONSTANT(photo) 136 | CPPTK_CONSTANT(pieslice) 137 | CPPTK_CONSTANT(pixels) 138 | CPPTK_CONSTANT(pointerx) 139 | CPPTK_CONSTANT(pointerxy) 140 | CPPTK_CONSTANT(pointery) 141 | CPPTK_CONSTANT(polygon) 142 | CPPTK_CONSTANT(positionfrom) 143 | CPPTK_CONSTANT(preferences) 144 | CPPTK_CONSTANT(present) 145 | CPPTK_CONSTANT(previous) 146 | CPPTK_CONSTANT(prevrange) 147 | CPPTK_CONSTANT(program) 148 | CPPTK_CONSTANT(projecting) 149 | CPPTK_CONSTANT(propagate) 150 | CPPTK_CONSTANT(querydoc) 151 | CPPTK_CONSTANT(question) 152 | CPPTK_CONSTANT(raised) 153 | CPPTK_CONSTANT(ramdisk) 154 | CPPTK_CONSTANT(range) 155 | CPPTK_CONSTANT(ranges) 156 | CPPTK_CONSTANT(readfile) 157 | CPPTK_CONSTANT(readonly) 158 | CPPTK_CONSTANT(rectangle) 159 | CPPTK_CONSTANT(redo) 160 | CPPTK_CONSTANT(regheight) 161 | CPPTK_CONSTANT(regwidth) 162 | CPPTK_CONSTANT(release) 163 | CPPTK_CONSTANT(remove) 164 | CPPTK_CONSTANT(reset) 165 | CPPTK_CONSTANT(resizable) 166 | CPPTK_CONSTANT(retrycancel) 167 | CPPTK_CONSTANT(ridge) 168 | CPPTK_CONSTANT(right) 169 | CPPTK_CONSTANT(rootx) 170 | CPPTK_CONSTANT(rooty) 171 | CPPTK_CONSTANT(round) 172 | CPPTK_CONSTANT(rowconfigure) 173 | CPPTK_CONSTANT(s) 174 | CPPTK_CONSTANT(screencells) 175 | CPPTK_CONSTANT(screendepth) 176 | CPPTK_CONSTANT(screenheight) 177 | CPPTK_CONSTANT(screenmmheight) 178 | CPPTK_CONSTANT(screenmmwidth) 179 | CPPTK_CONSTANT(screenvisual) 180 | CPPTK_CONSTANT(screenwidth) 181 | CPPTK_CONSTANT(se) 182 | CPPTK_CONSTANT(selfirst) 183 | CPPTK_CONSTANT(sellast) 184 | CPPTK_CONSTANT(separator) 185 | CPPTK_CONSTANT(server) 186 | CPPTK_CONSTANT(simple) 187 | CPPTK_CONSTANT(sizefrom) 188 | CPPTK_CONSTANT(slaves) 189 | CPPTK_CONSTANT(slider) 190 | CPPTK_CONSTANT(solid) 191 | CPPTK_CONSTANT(stackorder) 192 | CPPTK_CONSTANT(startupFile) 193 | CPPTK_CONSTANT(stationery) 194 | CPPTK_CONSTANT(status) 195 | CPPTK_CONSTANT(stop) 196 | CPPTK_CONSTANT(sunken) 197 | CPPTK_CONSTANT(sw) 198 | CPPTK_CONSTANT(top) 199 | CPPTK_CONSTANT(transient) 200 | CPPTK_CONSTANT(trash) 201 | CPPTK_CONSTANT(trough1) 202 | CPPTK_CONSTANT(trough2) 203 | CPPTK_CONSTANT(types) 204 | CPPTK_CONSTANT(units) 205 | CPPTK_CONSTANT(unset) 206 | CPPTK_CONSTANT(user) 207 | CPPTK_CONSTANT(userDefault) 208 | CPPTK_CONSTANT(vertical) 209 | CPPTK_CONSTANT(viewable) 210 | CPPTK_CONSTANT(visibility) 211 | CPPTK_CONSTANT(visual) 212 | CPPTK_CONSTANT(visualid) 213 | CPPTK_CONSTANT(visualsavailable) 214 | CPPTK_CONSTANT(vrootheight) 215 | CPPTK_CONSTANT(vrootwidth) 216 | CPPTK_CONSTANT(vrootx) 217 | CPPTK_CONSTANT(vrooty) 218 | CPPTK_CONSTANT(w) 219 | CPPTK_CONSTANT(warning) 220 | CPPTK_CONSTANT(widgetDefault) 221 | CPPTK_CONSTANT(withdraw) 222 | CPPTK_CONSTANT(withdrawn) 223 | CPPTK_CONSTANT(withtag) 224 | CPPTK_CONSTANT(wordstart) 225 | CPPTK_CONSTANT(wordend) 226 | CPPTK_CONSTANT(yesno) 227 | CPPTK_CONSTANT(yesnocancel) 228 | CPPTK_CONSTANT(zoomed) 229 | -------------------------------------------------------------------------------- /cpptkoptions.x: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2004-2006, Maciej Sobczak 3 | // 4 | // Permission to copy, use, modify, sell and distribute this software 5 | // is granted provided this copyright notice appears in all copies. 6 | // This software is provided "as is" without express or implied 7 | // warranty, and with no claim as to its suitability for any purpose. 8 | // 9 | 10 | CPPTK_OPTION(accelerator, true) 11 | CPPTK_OPTION(activebackground, false) 12 | CPPTK_OPTION(activebitmap, false) 13 | CPPTK_OPTION(activeborderwidth, false) 14 | CPPTK_OPTION(activedash, true) 15 | CPPTK_OPTION(activefill, false) 16 | CPPTK_OPTION(activeforeground, false) 17 | CPPTK_OPTION(activeimage, false) 18 | CPPTK_OPTION(activeoutline, false) 19 | CPPTK_OPTION(activeoutlinestipple, false) 20 | CPPTK_OPTION(activerelief, false) 21 | CPPTK_OPTION(activestipple, false) 22 | CPPTK_OPTION(activestyle, false) 23 | CPPTK_OPTION(activewidth, false) 24 | CPPTK_OPTION(align, false) 25 | CPPTK_OPTION(anchor, false) 26 | CPPTK_OPTION(arrow, false) 27 | CPPTK_OPTION(aspect, false) 28 | CPPTK_OPTION(autoseparators, false) 29 | CPPTK_OPTION(background, false) 30 | CPPTK_OPTION(bd, false) 31 | CPPTK_OPTION(before, false) 32 | CPPTK_OPTION(bg, false) 33 | CPPTK_OPTION(bgstipple, false) 34 | CPPTK_OPTION(bigincrement, false) 35 | CPPTK_OPTION(bitmap, false) 36 | CPPTK_OPTION(bordermode, false) 37 | CPPTK_OPTION(borderwidth, false) 38 | CPPTK_OPTION(buttonbackground, false) 39 | CPPTK_OPTION(buttoncursor, false) 40 | CPPTK_OPTION(buttondownrelief, false) 41 | CPPTK_OPTION(buttonuprelief, false) 42 | CPPTK_OPTION(capstyle, false) 43 | CPPTK_OPTION(closeenough, false) 44 | // TODO: colormap option of the canvas postscript command 45 | CPPTK_OPTION(colormap, false) 46 | CPPTK_OPTION(colormode, false) 47 | CPPTK_OPTION(column, false) 48 | CPPTK_OPTION(columnbreak, false) 49 | CPPTK_OPTION(columnspan, false) 50 | CPPTK_OPTION(compositingrule, false) 51 | CPPTK_OPTION(compound, false) 52 | CPPTK_OPTION(confine, false) 53 | CPPTK_OPTION(container, false) 54 | CPPTK_OPTION(cursor, false) 55 | CPPTK_OPTION(dash, true) 56 | CPPTK_OPTION(dashoffset, false) 57 | CPPTK_OPTION(defaultextension, true) 58 | CPPTK_OPTION(digits, false) 59 | CPPTK_OPTION(direction, false) 60 | CPPTK_OPTION(disabledbackground, false) 61 | CPPTK_OPTION(disabledbitmap, false) 62 | CPPTK_OPTION(disableddash, true) 63 | CPPTK_OPTION(disabledfill, false) 64 | CPPTK_OPTION(disabledforeground, false) 65 | CPPTK_OPTION(disabledimage, false) 66 | CPPTK_OPTION(disabledoutline, false) 67 | CPPTK_OPTION(disabledoutlinestipple, false) 68 | CPPTK_OPTION(disabledstipple, false) 69 | CPPTK_OPTION(disabledwidth, false) 70 | CPPTK_OPTION(displayof, false) 71 | CPPTK_OPTION(elementborderwidth, false) 72 | CPPTK_OPTION(expand, false) 73 | CPPTK_OPTION(exportselection, false) 74 | CPPTK_OPTION(extent, false) 75 | CPPTK_OPTION(family, false) 76 | CPPTK_OPTION(fg, false) 77 | CPPTK_OPTION(fgstipple, false) 78 | CPPTK_OPTION(file, true) 79 | CPPTK_OPTION(fill, false) 80 | CPPTK_OPTION(font, false) 81 | // TODO: fontmap option of the canvas postscript command 82 | CPPTK_OPTION(force, false) 83 | CPPTK_OPTION(foreground, false) 84 | CPPTK_OPTION(format, false) 85 | CPPTK_OPTION(gamma, false) 86 | CPPTK_OPTION(handlepad, false) 87 | CPPTK_OPTION(handlesize, false) 88 | CPPTK_OPTION(height, false) 89 | CPPTK_OPTION(hidemargin, false) 90 | CPPTK_OPTION(highlightbackground, false) 91 | CPPTK_OPTION(highlightcolor, false) 92 | CPPTK_OPTION(highlightthickness, false) 93 | CPPTK_OPTION(icon, false) 94 | CPPTK_OPTION(in, false) 95 | CPPTK_OPTION(increment, false) 96 | CPPTK_OPTION(indicatoron, false) 97 | CPPTK_OPTION(initialcolor, false) 98 | CPPTK_OPTION(initialdir, true) 99 | CPPTK_OPTION(initialfile, true) 100 | CPPTK_OPTION(insertbackground, false) 101 | CPPTK_OPTION(insertborderwidth, false) 102 | CPPTK_OPTION(insertofftime, false) 103 | CPPTK_OPTION(insertontime, false) 104 | CPPTK_OPTION(insertwidth, false) 105 | CPPTK_OPTION(ipadx, false) 106 | CPPTK_OPTION(ipady, false) 107 | CPPTK_OPTION(joinstyle, false) 108 | CPPTK_OPTION(jump, false) 109 | CPPTK_OPTION(justify, false) 110 | CPPTK_OPTION(labelanchor, false) 111 | CPPTK_OPTION(labelwidget, false) 112 | CPPTK_OPTION(lastfor, false) 113 | CPPTK_OPTION(length, false) 114 | CPPTK_OPTION(lmargin1, false) 115 | CPPTK_OPTION(lmargin2, false) 116 | CPPTK_OPTION(maskfile, true) 117 | CPPTK_OPTION(maxundo, false) 118 | CPPTK_OPTION(minsize, false) 119 | CPPTK_OPTION(mustexist, false) 120 | CPPTK_OPTION(name, false) 121 | CPPTK_OPTION(offrelief, false) 122 | CPPTK_OPTION(offset, false) 123 | CPPTK_OPTION(offvalue, false) 124 | CPPTK_OPTION(onvalue, false) 125 | CPPTK_OPTION(opaqueresize, false) 126 | CPPTK_OPTION(orient, false) 127 | CPPTK_OPTION(outline, false) 128 | CPPTK_OPTION(outlinestipple, false) 129 | CPPTK_OPTION(overrelief, false) 130 | CPPTK_OPTION(overstrike, false) 131 | CPPTK_OPTION(pad, false) 132 | CPPTK_OPTION(padx, false) 133 | CPPTK_OPTION(pady, false) 134 | CPPTK_OPTION(pageanchor, false) 135 | CPPTK_OPTION(pageheight, false) 136 | CPPTK_OPTION(pagewidth, false) 137 | CPPTK_OPTION(pagex, false) 138 | CPPTK_OPTION(pagey, false) 139 | CPPTK_OPTION(palette, false) 140 | CPPTK_OPTION(parent, false) 141 | CPPTK_OPTION(readonlybackground, false) 142 | CPPTK_OPTION(relheight, false) 143 | CPPTK_OPTION(relief, false) 144 | CPPTK_OPTION(relwidth, false) 145 | CPPTK_OPTION(relx, false) 146 | CPPTK_OPTION(rely, false) 147 | CPPTK_OPTION(repeatdelay, false) 148 | CPPTK_OPTION(repeatinterval, false) 149 | CPPTK_OPTION(resolution, false) 150 | CPPTK_OPTION(rmargin, false) 151 | CPPTK_OPTION(rotate, false) 152 | CPPTK_OPTION(row, false) 153 | CPPTK_OPTION(rowspan, false) 154 | CPPTK_OPTION(sashcursor, false) 155 | CPPTK_OPTION(sashpad, false) 156 | CPPTK_OPTION(sashrelief, false) 157 | CPPTK_OPTION(sashwidth, false) 158 | CPPTK_OPTION(screen, true) 159 | CPPTK_OPTION(sel, false) 160 | CPPTK_OPTION(selectbackground, false) 161 | CPPTK_OPTION(selectborderwidth, false) 162 | CPPTK_OPTION(selectcolor, false) 163 | CPPTK_OPTION(selectforeground, false) 164 | CPPTK_OPTION(selectimage, false) 165 | CPPTK_OPTION(selectmode, false) 166 | CPPTK_OPTION(setgrid, false) 167 | CPPTK_OPTION(show, true) 168 | CPPTK_OPTION(showvalue, false) 169 | CPPTK_OPTION(showhandle, false) 170 | CPPTK_OPTION(side, false) 171 | CPPTK_OPTION(size, false) 172 | CPPTK_OPTION(slant, false) 173 | CPPTK_OPTION(sliderlength, false) 174 | CPPTK_OPTION(sliderrelief, false) 175 | CPPTK_OPTION(smooth, false) 176 | CPPTK_OPTION(spacing1, false) 177 | CPPTK_OPTION(spacing2, false) 178 | CPPTK_OPTION(spacing3, false) 179 | CPPTK_OPTION(splinesteps, false) 180 | CPPTK_OPTION(start, false) 181 | CPPTK_OPTION(state, false) 182 | CPPTK_OPTION(sticky, false) 183 | CPPTK_OPTION(stipple, false) 184 | CPPTK_OPTION(stretch, false) 185 | CPPTK_OPTION(style, false) 186 | CPPTK_OPTION(tabs, true) 187 | CPPTK_OPTION(takefocus, false) 188 | CPPTK_OPTION(tearoff, false) 189 | CPPTK_OPTION(tickinterval, false) 190 | CPPTK_OPTION(title, true) 191 | CPPTK_OPTION(troughcolor, false) 192 | CPPTK_OPTION(underline, false) 193 | CPPTK_OPTION(undo, false) 194 | CPPTK_OPTION(uniform, false) 195 | CPPTK_OPTION(use, false) 196 | CPPTK_OPTION(value, true) 197 | CPPTK_OPTION(values, true) 198 | CPPTK_OPTION(weight, false) 199 | CPPTK_OPTION(width, false) 200 | CPPTK_OPTION(wrap, false) 201 | CPPTK_OPTION(wraplength, false) 202 | CPPTK_OPTION(x, false) 203 | CPPTK_OPTION(xscrollcommand, true) 204 | CPPTK_OPTION(y, false) 205 | CPPTK_OPTION(yscrollcommand, true) 206 | CPPTK_OPTION(xscrollincrement, false) 207 | CPPTK_OPTION(yscrollincrement, false) 208 | -------------------------------------------------------------------------------- /base/cpptkbase.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2004-2006, Maciej Sobczak 3 | // Copyright 2017 Declan Hoare 4 | // 5 | // Permission to copy, use, modify, sell and distribute this software 6 | // is granted provided this copyright notice appears in all copies. 7 | // This software is provided "as is" without express or implied 8 | // warranty, and with no claim as to its suitability for any purpose. 9 | // 10 | 11 | #include "cpptkbase.h" 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | using namespace Tk; 21 | using namespace Tk::details; 22 | 23 | namespace { // anonymous 24 | 25 | class Interp 26 | { 27 | public: 28 | Interp() 29 | { 30 | interp_ = Tcl_CreateInterp(); 31 | 32 | int cc = Tcl_Init(interp_); 33 | if (cc != TCL_OK) 34 | { 35 | throw TkError(Tcl_GetStringResult(interp_)); 36 | } 37 | 38 | cc = Tk_Init(interp_); 39 | if (cc != TCL_OK) 40 | { 41 | throw TkError(Tcl_GetStringResult(interp_)); 42 | } 43 | 44 | cc = Tcl_Eval(interp_, "namespace eval CppTk {}"); 45 | if (cc != TCL_OK) 46 | { 47 | throw TkError(Tcl_GetStringResult(interp_)); 48 | } 49 | } 50 | 51 | ~Interp() 52 | { 53 | // GUI programs are supposed to exit by calling "exit" 54 | // then - explicit delete here is harmful 55 | //Tcl_DeleteInterp(interp_); 56 | } 57 | 58 | Tcl_Interp * get() const { return interp_; } 59 | 60 | private: 61 | Tcl_Interp * interp_; 62 | }; 63 | 64 | // lazy-initialization of Tcl interpreter 65 | Tcl_Interp * getInterp() 66 | { 67 | static Interp interp; 68 | return interp.get(); 69 | } 70 | 71 | // output stream for dumping Tk commands 72 | // (useful for automated testing) 73 | std::ostream *dumpstream = &std::cerr; 74 | 75 | void do_eval(std::string const &str) 76 | { 77 | #ifdef CPPTK_DUMP_COMMANDS 78 | *dumpstream << str << '\n'; 79 | #endif // CPPTK_DUMP_COMMANDS 80 | 81 | #ifndef CPPTK_DONT_EVALUATE 82 | int cc = Tcl_Eval(getInterp(), str.c_str()); 83 | if (cc != TCL_OK) 84 | { 85 | throw TkError(Tcl_GetStringResult(getInterp())); 86 | } 87 | #endif 88 | } 89 | 90 | // map for callbacks 91 | typedef std::map > CallbacksMap; 92 | CallbacksMap callbacks; 93 | 94 | // callback id 95 | int callbackId = 0; 96 | 97 | char const *callbackPrefix = "CppTk::callback"; 98 | 99 | typedef std::map IntLinks; 100 | typedef std::map DoubleLinks; 101 | typedef std::map StringLinks; 102 | 103 | IntLinks intLinks; 104 | DoubleLinks doubleLinks; 105 | StringLinks stringLinks; 106 | 107 | typedef std::map StringLinkBuffers; 108 | StringLinkBuffers stringLinkBuffers; 109 | 110 | int linkId = 0; 111 | 112 | char const *linkVarPrefix = "CppTk::variable"; 113 | 114 | // this function refreshes Tcl variables from C++ variables 115 | void linkCpptoTcl() 116 | { 117 | // synchronize C++ variables with Tcl variables 118 | // it is enough to refresh string buffers and update links 119 | 120 | // refresh string buffers 121 | for (StringLinks::iterator it = stringLinks.begin(); 122 | it != stringLinks.end(); ++it) 123 | { 124 | std::string *ps = it->first; // pointer to C++ string (original value) 125 | 126 | StringLinkBuffers::iterator itb = stringLinkBuffers.find(ps); 127 | char *&pb = itb->second; // pointer to Tcl buffer (destination) 128 | 129 | if (pb != NULL) 130 | { 131 | Tcl_Free(pb); 132 | } 133 | pb = Tcl_Alloc(static_cast(ps->size()) + 1); 134 | std::copy(ps->begin(), ps->end(), pb); 135 | pb[ps->size()] = '\0'; 136 | 137 | Tcl_UpdateLinkedVar(getInterp(), it->second.c_str()); 138 | } 139 | 140 | // update other (int and double) Tcl links 141 | for (IntLinks::iterator it = intLinks.begin(); 142 | it != intLinks.end(); ++it) 143 | { 144 | Tcl_UpdateLinkedVar(getInterp(), it->second.c_str()); 145 | } 146 | for (DoubleLinks::iterator it = doubleLinks.begin(); 147 | it != doubleLinks.end(); ++it) 148 | { 149 | Tcl_UpdateLinkedVar(getInterp(), it->second.c_str()); 150 | } 151 | } 152 | 153 | // this function refreshes C++ variables from Tcl variables 154 | void linkTcltoCpp() 155 | { 156 | // it is enough to refresh strings from their buffers 157 | for (StringLinks::iterator it = stringLinks.begin(); 158 | it != stringLinks.end(); ++it) 159 | { 160 | std::string *ps = it->first; // pointer to C++ string (destination) 161 | 162 | StringLinkBuffers::iterator itb = stringLinkBuffers.find(ps); 163 | char *pb = itb->second; // pointer to Tcl buffer (original value) 164 | 165 | if (pb != NULL) 166 | { 167 | ps->assign(pb); 168 | } 169 | else 170 | { 171 | ps->clear(); 172 | } 173 | } 174 | } 175 | 176 | } // namespace // anonymous 177 | 178 | 179 | // global flag for avoiding multiple-error problem 180 | bool Tk::TkError::inTkError = false; 181 | 182 | 183 | // generic callback handler 184 | 185 | extern "C" 186 | int callbackHandler(ClientData cd, Tcl_Interp *interp, 187 | int objc, Tcl_Obj *CONST objv[]) 188 | { 189 | int slot = static_cast(reinterpret_cast(cd)); 190 | 191 | CallbacksMap::iterator it = callbacks.find(slot); 192 | if (it == callbacks.end()) 193 | { 194 | Tcl_SetResult(interp, 195 | (char*)"Trying to invoke non-existent callback", TCL_STATIC); 196 | return TCL_ERROR; 197 | } 198 | 199 | try 200 | { 201 | // refresh C++ variables 202 | linkTcltoCpp(); 203 | 204 | Params p(objc, reinterpret_cast( 205 | const_cast(objv))); 206 | it->second->invoke(p); 207 | 208 | // refresh Tcl variables 209 | linkCpptoTcl(); 210 | } 211 | catch (std::exception const &e) 212 | { 213 | Tcl_SetResult(interp, const_cast(e.what()), TCL_VOLATILE); 214 | return TCL_ERROR; 215 | } 216 | return TCL_OK; 217 | } 218 | 219 | // generic callback deleter 220 | 221 | extern "C" 222 | void callbackDeleter(ClientData cd) 223 | { 224 | int slot = static_cast(reinterpret_cast(cd)); 225 | callbacks.erase(slot); 226 | } 227 | 228 | std::string Tk::details::addCallback(std::shared_ptr cb) 229 | { 230 | int newSlot = callbackId++; 231 | callbacks[newSlot] = cb; 232 | 233 | std::string newCmd(callbackPrefix); 234 | newCmd += std::to_string(newSlot); 235 | 236 | Tcl_CreateObjCommand(getInterp(), newCmd.c_str(), 237 | callbackHandler, reinterpret_cast( 238 | static_cast(newSlot)), 239 | callbackDeleter); 240 | 241 | return newCmd; 242 | } 243 | 244 | std::string Tk::details::addLinkVar(int &i) 245 | { 246 | int newLink = linkId++; 247 | std::string newLinkVar(linkVarPrefix); 248 | newLinkVar += std::to_string(newLink); 249 | 250 | int cc = Tcl_LinkVar(getInterp(), newLinkVar.c_str(), 251 | reinterpret_cast(&i), TCL_LINK_INT); 252 | if (cc != TCL_OK) 253 | { 254 | throw TkError(Tcl_GetStringResult(getInterp())); 255 | } 256 | 257 | intLinks[&i] = newLinkVar; 258 | return newLinkVar; 259 | } 260 | 261 | std::string Tk::details::addLinkVar(double &d) 262 | { 263 | int newLink = linkId++; 264 | std::string newLinkVar(linkVarPrefix); 265 | newLinkVar += std::to_string(newLink); 266 | 267 | int cc = Tcl_LinkVar(getInterp(), newLinkVar.c_str(), 268 | reinterpret_cast(&d), TCL_LINK_DOUBLE); 269 | if (cc != TCL_OK) 270 | { 271 | throw TkError(Tcl_GetStringResult(getInterp())); 272 | } 273 | 274 | doubleLinks[&d] = newLinkVar; 275 | return newLinkVar; 276 | } 277 | 278 | std::string Tk::details::addLinkVar(std::string &s) 279 | { 280 | int newLink = linkId++; 281 | std::string newLinkVar(linkVarPrefix); 282 | newLinkVar += std::to_string(newLink); 283 | 284 | std::pair::iterator, bool> it = 285 | stringLinkBuffers.insert(make_pair(&s, static_cast(NULL))); 286 | 287 | char *&pb = it.first->second; 288 | pb = Tcl_Alloc(static_cast(s.size()) + 1); 289 | copy(s.begin(), s.end(), pb); 290 | pb[s.size()] = '\0'; 291 | 292 | int cc = Tcl_LinkVar(getInterp(), newLinkVar.c_str(), 293 | reinterpret_cast(&it.first->second), TCL_LINK_STRING); 294 | if (cc != TCL_OK) 295 | { 296 | throw TkError(Tcl_GetStringResult(getInterp())); 297 | } 298 | 299 | stringLinks[&s] = newLinkVar; 300 | return newLinkVar; 301 | } 302 | 303 | void Tk::details::deleteLinkVar(int &i) 304 | { 305 | IntLinks::iterator it = intLinks.find(&i); 306 | if (it == intLinks.end()) 307 | { 308 | return; 309 | } 310 | 311 | Tcl_UnlinkVar(getInterp(), it->second.c_str()); 312 | intLinks.erase(it); 313 | } 314 | 315 | void Tk::details::deleteLinkVar(double &d) 316 | { 317 | DoubleLinks::iterator it = doubleLinks.find(&d); 318 | if (it == doubleLinks.end()) 319 | { 320 | return; 321 | } 322 | 323 | Tcl_UnlinkVar(getInterp(), it->second.c_str()); 324 | doubleLinks.erase(it); 325 | } 326 | 327 | void Tk::details::deleteLinkVar(std::string &s) 328 | { 329 | StringLinks::iterator it = stringLinks.find(&s); 330 | if (it == stringLinks.end()) 331 | { 332 | return; 333 | } 334 | 335 | Tcl_UnlinkVar(getInterp(), it->second.c_str()); 336 | stringLinks.erase(it); 337 | 338 | StringLinkBuffers::iterator itb = stringLinkBuffers.find(&s); 339 | char *pb = itb->second; 340 | if (pb != NULL) 341 | { 342 | Tcl_Free(pb); 343 | } 344 | 345 | stringLinkBuffers.erase(itb); 346 | } 347 | 348 | void Tk::details::setResult(bool b) 349 | { 350 | Tcl_SetObjResult(getInterp(), Tcl_NewBooleanObj(b)); 351 | } 352 | 353 | void Tk::details::setResult(long i) 354 | { 355 | Tcl_SetObjResult(getInterp(), Tcl_NewLongObj(i)); 356 | } 357 | 358 | void Tk::details::setResult(double d) 359 | { 360 | Tcl_SetObjResult(getInterp(), Tcl_NewDoubleObj(d)); 361 | } 362 | 363 | void Tk::details::setResult(std::string const &s) 364 | { 365 | Tcl_SetObjResult(getInterp(), 366 | Tcl_NewStringObj(s.data(), static_cast(s.size()))); 367 | } 368 | 369 | int Tk::details::getResultLen() 370 | { 371 | Tcl_Interp *interp = getInterp(); 372 | 373 | Tcl_Obj *list = Tcl_GetObjResult(interp); 374 | int len, cc; 375 | 376 | cc = Tcl_ListObjLength(interp, list, &len); 377 | if (cc != TCL_OK) 378 | { 379 | throw TkError(Tcl_GetStringResult(interp)); 380 | } 381 | 382 | return len; 383 | } 384 | 385 | template <> 386 | int Tk::details::getResultElem(int indx) 387 | { 388 | Tcl_Interp *interp = getInterp(); 389 | 390 | Tcl_Obj *list = Tcl_GetObjResult(interp); 391 | Tcl_Obj *obj; 392 | 393 | int cc = Tcl_ListObjIndex(interp, list, indx, &obj); 394 | if (cc != TCL_OK) 395 | { 396 | throw TkError(Tcl_GetStringResult(interp)); 397 | } 398 | 399 | int val; 400 | cc = Tcl_GetIntFromObj(interp, obj, &val); 401 | if (cc != TCL_OK) 402 | { 403 | throw TkError(Tcl_GetStringResult(interp)); 404 | } 405 | 406 | return val; 407 | } 408 | 409 | template <> 410 | double Tk::details::getResultElem(int indx) 411 | { 412 | Tcl_Interp *interp = getInterp(); 413 | 414 | Tcl_Obj *list = Tcl_GetObjResult(interp); 415 | Tcl_Obj *obj; 416 | 417 | int cc = Tcl_ListObjIndex(interp, list, indx, &obj); 418 | if (cc != TCL_OK) 419 | { 420 | throw TkError(Tcl_GetStringResult(interp)); 421 | } 422 | 423 | double val; 424 | cc = Tcl_GetDoubleFromObj(interp, obj, &val); 425 | if (cc != TCL_OK) 426 | { 427 | throw TkError(Tcl_GetStringResult(interp)); 428 | } 429 | 430 | return val; 431 | } 432 | 433 | template <> 434 | std::string Tk::details::getResultElem(int indx) 435 | { 436 | Tcl_Interp *interp = getInterp(); 437 | 438 | Tcl_Obj *list = Tcl_GetObjResult(interp); 439 | Tcl_Obj *obj; 440 | 441 | int cc = Tcl_ListObjIndex(interp, list, indx, &obj); 442 | if (cc != TCL_OK) 443 | { 444 | throw TkError(Tcl_GetStringResult(interp)); 445 | } 446 | 447 | return Tcl_GetString(obj); 448 | } 449 | 450 | details::Command::Command(std::string const &str, std::string const &postfix) 451 | : invoked_(false), str_(str), postfix_(postfix) 452 | { 453 | } 454 | 455 | details::Command::~Command() 456 | { 457 | if (!TkError::inTkError) 458 | { 459 | invokeOnce(); 460 | } 461 | } 462 | 463 | std::string Tk::details::Command::invoke() const 464 | { 465 | invokeOnce(); 466 | return Tcl_GetStringResult(getInterp()); 467 | } 468 | 469 | void Tk::details::Command::invokeOnce() const 470 | { 471 | if (invoked_ == false) 472 | { 473 | invoked_ = true; 474 | 475 | std::string cmd(str_); 476 | cmd += postfix_; 477 | 478 | do_eval(cmd); 479 | } 480 | } 481 | 482 | details::Expr::Expr(std::string const &str, bool starter) 483 | { 484 | if (starter) 485 | { 486 | cmd_.reset(new Command(str)); 487 | } 488 | else 489 | { 490 | str_ = str; 491 | } 492 | } 493 | 494 | details::Expr::Expr(std::string const &str, std::string const &postfix) 495 | { 496 | cmd_.reset(new Command(str, postfix)); 497 | } 498 | 499 | std::string Tk::details::Expr::getValue() const 500 | { 501 | if (!str_.empty()) 502 | { 503 | return str_; 504 | } 505 | else 506 | { 507 | return cmd_->getValue(); 508 | } 509 | } 510 | 511 | details::Expr::operator std::string() const 512 | { 513 | return cmd_->invoke(); 514 | } 515 | 516 | details::Expr::operator int() const 517 | { 518 | cmd_->invokeOnce(); 519 | 520 | Tcl_Interp *interp = getInterp(); 521 | Tcl_Obj *obj = Tcl_GetObjResult(interp); 522 | 523 | int val, cc; 524 | cc = Tcl_GetIntFromObj(interp, obj, &val); 525 | if (cc != TCL_OK) 526 | { 527 | throw TkError(Tcl_GetStringResult(interp)); 528 | } 529 | 530 | return val; 531 | } 532 | 533 | details::Expr::operator double() const 534 | { 535 | cmd_->invokeOnce(); 536 | 537 | Tcl_Interp *interp = getInterp(); 538 | Tcl_Obj *obj = Tcl_GetObjResult(interp); 539 | 540 | double val; 541 | int cc = Tcl_GetDoubleFromObj(interp, obj, &val); 542 | if (cc != TCL_OK) 543 | { 544 | throw TkError(Tcl_GetStringResult(interp)); 545 | } 546 | 547 | return val; 548 | } 549 | 550 | details::Expr::operator Tk::Point() const 551 | { 552 | std::string ret(cmd_->invoke()); 553 | if (ret.empty()) 554 | { 555 | return Tk::Point(0, 0); 556 | } 557 | 558 | int len = getResultLen(); 559 | if (len < 2) 560 | { 561 | throw TkError("Cannot convert the result list to Point\n"); 562 | } 563 | 564 | int x = getResultElem(0); 565 | int y = getResultElem(1); 566 | 567 | return Point(x, y); 568 | } 569 | 570 | details::Expr::operator Tk::Box() const 571 | { 572 | std::string ret(cmd_->invoke()); 573 | if (ret.empty()) 574 | { 575 | return Tk::Box(0, 0, 0, 0); 576 | } 577 | 578 | int len = getResultLen(); 579 | if (len < 4) 580 | { 581 | throw TkError("Cannot convert the result list to Box\n"); 582 | } 583 | 584 | int x1 = getResultElem(0); 585 | int y1 = getResultElem(1); 586 | int x2 = getResultElem(2); 587 | int y2 = getResultElem(3); 588 | 589 | return Box(x1, y1, x2, y2); 590 | } 591 | 592 | // these two specializations are used to extract parameter 593 | // with the requested type 594 | 595 | template <> 596 | int Tk::details::Params::get(int argno) const 597 | { 598 | if (argno < 1 || argno >= argc_) 599 | { 600 | throw TkError("Parameter number out of valid range"); 601 | } 602 | 603 | Tcl_Obj *CONST *objv = reinterpret_cast(objv_); 604 | 605 | int res, cc; 606 | cc = Tcl_GetIntFromObj(getInterp(), objv[argno], &res); 607 | if (cc != TCL_OK) 608 | { 609 | throw TkError(Tcl_GetStringResult(getInterp())); 610 | } 611 | 612 | return res; 613 | } 614 | 615 | template <> 616 | std::string Tk::details::Params::get(int argno) const 617 | { 618 | if (argno < 1 || argno >= argc_) 619 | { 620 | throw TkError("Parameter number out of valid range"); 621 | } 622 | 623 | Tcl_Obj *CONST *objv = reinterpret_cast(objv_); 624 | 625 | std::string res = Tcl_GetString(objv[argno]); 626 | return res; 627 | } 628 | 629 | std::ostream & Tk::details::operator<<(std::ostream &os, BasicToken const &token) 630 | { 631 | return os << static_cast(token); 632 | } 633 | 634 | namespace { // anonymous 635 | 636 | void doSingleQuote(std::string &s, char c) 637 | { 638 | std::string::size_type pos = 0; 639 | while ((pos = s.find(c, pos)) != std::string::npos) 640 | { 641 | s.insert(pos, "\\"); 642 | pos += 2; 643 | } 644 | } 645 | 646 | } // namespace anonymous 647 | 648 | // this function is used to quote quotation marks in string values' 649 | // in later version, it will not be needed 650 | std::string Tk::details::quote(std::string const &s) 651 | { 652 | std::string ret(s); 653 | doSingleQuote(ret, '\\'); 654 | doSingleQuote(ret, '\"'); 655 | doSingleQuote(ret, '$'); 656 | doSingleQuote(ret, '['); 657 | doSingleQuote(ret, ']'); 658 | 659 | return ret; 660 | } 661 | 662 | // basic Tk expression operations 663 | 664 | Expr Tk::operator-(Expr const &lhs, Expr const &rhs) 665 | { 666 | std::shared_ptr cmd(lhs.getCmd()); 667 | cmd->append(rhs.getValue()); 668 | 669 | return Expr(cmd); 670 | } 671 | 672 | Expr Tk::operator<<(std::string const &w, Expr const &rhs) 673 | { 674 | std::shared_ptr cmd(rhs.getCmd()); 675 | cmd->prepend(" "); 676 | cmd->prepend(w); 677 | 678 | return Expr(cmd); 679 | } 680 | 681 | // helper functions 682 | 683 | void Tk::deleteCallback(std::string const &name) 684 | { 685 | std::string::size_type pos = name.find_first_not_of(callbackPrefix); 686 | if (pos == std::string::npos) return; 687 | 688 | int slot = std::stoi(name.substr(pos, name.size())); 689 | callbacks.erase(slot); 690 | 691 | int cc = Tcl_DeleteCommand(getInterp(), name.c_str()); 692 | if (cc != TCL_OK) 693 | { 694 | throw TkError(Tcl_GetStringResult(getInterp())); 695 | } 696 | } 697 | 698 | Tk::CallbackHandle::CallbackHandle(std::string const &name) : name_(name) {} 699 | 700 | Tk::CallbackHandle::~CallbackHandle() { deleteCallback(name_); } 701 | 702 | Expr Tk::eval(std::string const &str) 703 | { 704 | return Expr(str); 705 | } 706 | 707 | void Tk::init(char *argv0) 708 | { 709 | Tcl_FindExecutable(argv0); 710 | } 711 | 712 | void Tk::runEventLoop() 713 | { 714 | // refresh Tcl variables 715 | linkCpptoTcl(); 716 | 717 | Tk_MainLoop(); 718 | } 719 | 720 | void Tk::setDumpStream(std::ostream &os) 721 | { 722 | dumpstream = &os; 723 | } 724 | -------------------------------------------------------------------------------- /base/cpptkbase.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2004-2006, Maciej Sobczak 3 | // Copyright 2017 Declan Hoare 4 | // 5 | // Permission to copy, use, modify, sell and distribute this software 6 | // is granted provided this copyright notice appears in all copies. 7 | // This software is provided "as is" without express or implied 8 | // warranty, and with no claim as to its suitability for any purpose. 9 | // 10 | 11 | #ifndef CPPTKBASE_H_INCLUDED 12 | #define CPPTKBASE_H_INCLUDED 13 | 14 | # if defined _MSC_VER 15 | # if (_MSC_VER >= 1300) 16 | # pragma warning (disable : 4127 4511 4512 4701) 17 | # endif 18 | # endif 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | namespace Tk 30 | { 31 | 32 | // exception class used for reporting all Tk errors 33 | 34 | class TkError : public std::runtime_error 35 | { 36 | public: 37 | explicit TkError(std::string const &msg) 38 | : std::runtime_error(msg) 39 | { 40 | inTkError = true; 41 | } 42 | 43 | ~TkError() throw() 44 | { 45 | inTkError = false; 46 | } 47 | 48 | static bool inTkError; 49 | }; 50 | 51 | // for functions returning point and box (or windows) coordinates 52 | struct Point 53 | { 54 | Point(int a, int b) : x(a), y(b) {} 55 | int x, y; 56 | }; 57 | 58 | struct Box 59 | { 60 | Box(int a, int b, int c, int d) : x1(a), y1(b), x2(c), y2(d) {} 61 | int x1, y1, x2, y2; 62 | }; 63 | 64 | // The CallbackTraits class keeps basic information about 65 | // callback functors. 66 | // By default, functor is supposed to define its result_type. 67 | // Users can provide their own specializations of this class. 68 | 69 | template 70 | struct CallbackTraits 71 | { 72 | typedef typename Functor::result_type result_type; 73 | }; 74 | 75 | // partial specializations for pointers to functions 76 | 77 | template 78 | struct CallbackTraits 79 | { 80 | typedef R result_type; 81 | }; 82 | 83 | template 84 | struct CallbackTraits 85 | { 86 | typedef R result_type; 87 | }; 88 | 89 | template 90 | struct CallbackTraits 91 | { 92 | typedef R result_type; 93 | }; 94 | 95 | template 96 | struct CallbackTraits 97 | { 98 | typedef R result_type; 99 | }; 100 | 101 | template 102 | struct CallbackTraits 103 | { 104 | typedef R result_type; 105 | }; 106 | 107 | template 109 | struct CallbackTraits 110 | { 111 | typedef R result_type; 112 | }; 113 | 114 | template 116 | struct CallbackTraits 117 | { 118 | typedef R result_type; 119 | }; 120 | 121 | template 123 | struct CallbackTraits 124 | { 125 | typedef R result_type; 126 | }; 127 | 128 | template 130 | struct CallbackTraits 131 | { 132 | typedef R result_type; 133 | }; 134 | 135 | template 137 | struct CallbackTraits 138 | { 139 | typedef R result_type; 140 | }; 141 | 142 | template 145 | struct CallbackTraits 146 | { 147 | typedef R result_type; 148 | }; 149 | 150 | namespace details 151 | { 152 | 153 | // The Command class gathers everything on its road while 154 | // it travels the Tk expression 155 | // It executes the command when destroyed, which is at the end 156 | // of full Tk expression 157 | 158 | class Command 159 | { 160 | public: 161 | explicit Command(std::string const &str, 162 | std::string const &posfix = std::string()); 163 | ~Command(); 164 | 165 | std::string invoke() const; 166 | void append(std::string const &str) { str_ += str; } 167 | void prepend(std::string const &str) { str_.insert(0, str); } 168 | std::string getValue() const { return str_; } 169 | 170 | void invokeOnce() const; 171 | 172 | private: 173 | 174 | mutable bool invoked_; 175 | std::string str_; 176 | std::string postfix_; 177 | }; 178 | 179 | // returns the length of the result list 180 | int getResultLen(); 181 | 182 | // retrieves the result list element at the given index 183 | template T getResultElem(int indx); 184 | 185 | // available specializations 186 | template <> int getResultElem(int indx); 187 | template <> double getResultElem(int indx); 188 | template <> std::string getResultElem(int indx); 189 | 190 | 191 | // The Expr object is a result of executing Tk expression. 192 | // The intent is that the Expr object is a temporary. 193 | // There may be many Expr objects flying around and 194 | // accumulating state in a single Command object. 195 | 196 | class Expr 197 | { 198 | public: 199 | explicit Expr(std::string const &str, bool starter = true); 200 | Expr(std::string const &str, std::string const &postfix); 201 | Expr(std::shared_ptr const &cmd) : cmd_(cmd) {} 202 | 203 | std::shared_ptr getCmd() const { return cmd_; } 204 | std::string getValue() const; 205 | 206 | operator std::string() const; 207 | operator int() const; 208 | operator double() const; 209 | operator Tk::Point() const; 210 | operator Tk::Box() const; 211 | 212 | template 213 | operator std::pair() const 214 | { 215 | std::string ret(cmd_->invoke()); 216 | if (ret.empty()) 217 | { 218 | return std::make_pair(T1(), T2()); 219 | } 220 | 221 | int len = getResultLen(); 222 | if (len < 2) 223 | { 224 | throw TkError("Cannot convert the result list into pair\n"); 225 | } 226 | 227 | return std::make_pair(getResultElem(0), getResultElem(1)); 228 | } 229 | 230 | template 231 | operator std::vector() const 232 | { 233 | std::string ret(cmd_->invoke()); 234 | if (ret.empty()) 235 | { 236 | return std::vector(); 237 | } 238 | 239 | int len = getResultLen(); 240 | std::vector v; 241 | v.reserve(len); 242 | for(int i = 0; i != len; ++i) 243 | { 244 | v.push_back(getResultElem(i)); 245 | } 246 | 247 | return v; 248 | } 249 | 250 | private: 251 | std::string str_; 252 | std::shared_ptr cmd_; 253 | }; 254 | 255 | // The Params is used to encapsulate the list of parameters 256 | // that will be passed to the callback functions. 257 | // It is needed to isolate this header from Tcl/Tk headers. 258 | 259 | class Params 260 | { 261 | public: 262 | Params(int argc, void *objv) : argc_(argc), objv_(objv) {} 263 | 264 | template T get(int argno) const; 265 | 266 | private: 267 | int argc_; 268 | void *objv_; 269 | }; 270 | 271 | // available specializations for Params::get 272 | template <> int Params::get(int argno) const; 273 | template <> std::string Params::get(int argno) const; 274 | 275 | 276 | // The CallbackBase is used to store callback handlers 277 | // in the polymorphic map 278 | 279 | class CallbackBase 280 | { 281 | public: 282 | virtual ~CallbackBase() {} 283 | virtual void invoke(Params const &) = 0; 284 | }; 285 | 286 | std::string addCallback(std::shared_ptr cb); 287 | 288 | // helpers for setting result in the interpreter 289 | void setResult(bool b); 290 | void setResult(long i); 291 | void setResult(double d); 292 | void setResult(std::string const &s); 293 | 294 | // The Dispatch class is used to execute the callback functor 295 | // and to capture their results. 296 | // The DispatchN classes can capture results of functors 297 | // with up to 10 parameters 298 | 299 | template 300 | struct Dispatch0 301 | { 302 | static void doDispatch(Functor f) 303 | { 304 | R result = f(); 305 | setResult(result); 306 | } 307 | }; 308 | 309 | // partial specialization for functors that return nothing 310 | template 311 | struct Dispatch0 312 | { 313 | static void doDispatch(Functor f) 314 | { 315 | f(); 316 | } 317 | }; 318 | 319 | template 320 | struct Dispatch1 321 | { 322 | static void doDispatch(Functor f, T1 const &t1) 323 | { 324 | R result = f(t1); 325 | setResult(result); 326 | } 327 | }; 328 | 329 | // partial specialization for functors that return nothing 330 | template 331 | struct Dispatch1 332 | { 333 | static void doDispatch(Functor f, T1 const &t1) 334 | { 335 | f(t1); 336 | } 337 | }; 338 | 339 | template 340 | struct Dispatch2 341 | { 342 | static void doDispatch(Functor f, T1 const &t1, T2 const &t2) 343 | { 344 | R result = f(t1, t2); 345 | setResult(result); 346 | } 347 | }; 348 | 349 | // partial specialization for functors that return nothing 350 | template 351 | struct Dispatch2 352 | { 353 | static void doDispatch(Functor f, T1 const &t1, T2 const &t2) 354 | { 355 | f(t1, t2); 356 | } 357 | }; 358 | 359 | template 360 | struct Dispatch3 361 | { 362 | static void doDispatch(Functor f, T1 const &t1, T2 const &t2, 363 | T3 const &t3) 364 | { 365 | R result = f(t1, t2, t3); 366 | setResult(result); 367 | } 368 | }; 369 | 370 | // partial specialization for functors that return nothing 371 | template 372 | struct Dispatch3 373 | { 374 | static void doDispatch(Functor f, T1 const &t1, T2 const &t2, 375 | T3 const &t3) 376 | { 377 | f(t1, t2, t3); 378 | } 379 | }; 380 | 381 | template 383 | struct Dispatch4 384 | { 385 | static void doDispatch(Functor f, T1 const &t1, T2 const &t2, 386 | T3 const &t3, T4 const &t4) 387 | { 388 | R result = f(t1, t2, t3, t4); 389 | setResult(result); 390 | } 391 | }; 392 | 393 | // partial specialization for functors that return nothing 394 | template 395 | struct Dispatch4 396 | { 397 | static void doDispatch(Functor f, T1 const &t1, T2 const &t2, 398 | T3 const &t3, T4 const &t4) 399 | { 400 | f(t1, t2, t3, t4); 401 | } 402 | }; 403 | 404 | template 406 | struct Dispatch5 407 | { 408 | static void doDispatch(Functor f, T1 const &t1, T2 const &t2, 409 | T3 const &t3, T4 const &t4, T5 const &t5) 410 | { 411 | R result = f(t1, t2, t3, t4, t5); 412 | setResult(result); 413 | } 414 | }; 415 | 416 | // partial specialization for functors that return nothing 417 | template 419 | struct Dispatch5 420 | { 421 | static void doDispatch(Functor f, T1 const &t1, T2 const &t2, 422 | T3 const &t3, T4 const &t4, T5 const &t5) 423 | { 424 | f(t1, t2, t3, t4, t5); 425 | } 426 | }; 427 | 428 | template 430 | struct Dispatch6 431 | { 432 | static void doDispatch(Functor f, T1 const &t1, T2 const &t2, 433 | T3 const &t3, T4 const &t4, T5 const &t5, T6 const &t6) 434 | { 435 | R result = f(t1, t2, t3, t4, t5, t6); 436 | setResult(result); 437 | } 438 | }; 439 | 440 | // partial specialization for functors that return nothing 441 | template 443 | struct Dispatch6 444 | { 445 | static void doDispatch(Functor f, T1 const &t1, T2 const &t2, 446 | T3 const &t3, T4 const &t4, T5 const &t5, T6 const &t6) 447 | { 448 | f(t1, t2, t3, t4, t5, t6); 449 | } 450 | }; 451 | 452 | template 454 | struct Dispatch7 455 | { 456 | static void doDispatch(Functor f, T1 const &t1, T2 const &t2, 457 | T3 const &t3, T4 const &t4, T5 const &t5, T6 const &t6, 458 | T7 const &t7) 459 | { 460 | R result = f(t1, t2, t3, t4, t5, t6, t7); 461 | setResult(result); 462 | } 463 | }; 464 | 465 | // partial specialization for functors that return nothing 466 | template 468 | struct Dispatch7 469 | { 470 | static void doDispatch(Functor f, T1 const &t1, T2 const &t2, 471 | T3 const &t3, T4 const &t4, T5 const &t5, T6 const &t6, 472 | T7 const &t7) 473 | { 474 | f(t1, t2, t3, t4, t5, t6, t7); 475 | } 476 | }; 477 | 478 | template 480 | struct Dispatch8 481 | { 482 | static void doDispatch(Functor f, T1 const &t1, T2 const &t2, 483 | T3 const &t3, T4 const &t4, T5 const &t5, T6 const &t6, 484 | T7 const &t7, T8 const &t8) 485 | { 486 | R result = f(t1, t2, t3, t4, t5, t6, t7, t8); 487 | setResult(result); 488 | } 489 | }; 490 | 491 | // partial specialization for functors that return nothing 492 | template 494 | struct Dispatch8 495 | { 496 | static void doDispatch(Functor f, T1 const &t1, T2 const &t2, 497 | T3 const &t3, T4 const &t4, T5 const &t5, T6 const &t6, 498 | T7 const &t7, T8 const &t8) 499 | { 500 | f(t1, t2, t3, t4, t5, t6, t7, t8); 501 | } 502 | }; 503 | 504 | template 507 | struct Dispatch9 508 | { 509 | static void doDispatch(Functor f, T1 const &t1, T2 const &t2, 510 | T3 const &t3, T4 const &t4, T5 const &t5, T6 const &t6, 511 | T7 const &t7, T8 const &t8, T9 const &t9) 512 | { 513 | R result = f(t1, t2, t3, t4, t5, t6, t7, t8, t9); 514 | setResult(result); 515 | } 516 | }; 517 | 518 | // partial specialization for functors that return nothing 519 | template 521 | struct Dispatch9 522 | { 523 | static void doDispatch(Functor f, T1 const &t1, T2 const &t2, 524 | T3 const &t3, T4 const &t4, T5 const &t5, T6 const &t6, 525 | T7 const &t7, T8 const &t8, T9 const &t9) 526 | { 527 | f(t1, t2, t3, t4, t5, t6, t7, t8, t9); 528 | } 529 | }; 530 | 531 | template 534 | struct Dispatch10 535 | { 536 | static void doDispatch(Functor f, T1 const &t1, T2 const &t2, 537 | T3 const &t3, T4 const &t4, T5 const &t5, T6 const &t6, 538 | T7 const &t7, T8 const &t8, T9 const &t9, T10 const &t10) 539 | { 540 | R result = f(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10); 541 | setResult(result); 542 | } 543 | }; 544 | 545 | // partial specialization for functors that return nothing 546 | template 549 | struct Dispatch10 550 | { 551 | static void doDispatch(Functor f, T1 const &t1, T2 const &t2, 552 | T3 const &t3, T4 const &t4, T5 const &t5, T6 const &t6, 553 | T7 const &t7, T8 const &t8, T9 const &t9, T10 const &t10) 554 | { 555 | f(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10); 556 | } 557 | }; 558 | 559 | // The Callback is used as an envelope for the actual 560 | // callback object 561 | // The CallbackN classes wrap functors with up to 10 parameters 562 | 563 | template 564 | class Callback0 : public CallbackBase 565 | { 566 | public: 567 | Callback0(Functor f) : f_(f) {} 568 | 569 | virtual void invoke(Params const &) 570 | { 571 | Dispatch0::doDispatch(f_); 572 | } 573 | 574 | private: 575 | typedef typename CallbackTraits::result_type result_type; 576 | Functor f_; 577 | }; 578 | 579 | template 580 | class Callback1 : public CallbackBase 581 | { 582 | public: 583 | Callback1(Functor f) : f_(f) {} 584 | 585 | virtual void invoke(Params const &p) 586 | { 587 | Dispatch1 588 | ::doDispatch(f_, p.template get(1)); 589 | } 590 | 591 | private: 592 | typedef typename CallbackTraits::result_type result_type; 593 | Functor f_; 594 | }; 595 | 596 | template 597 | class Callback2 : public CallbackBase 598 | { 599 | public: 600 | Callback2(Functor f) : f_(f) {} 601 | 602 | virtual void invoke(Params const &p) 603 | { 604 | Dispatch2 605 | ::doDispatch(f_, 606 | p.template get(1), 607 | p.template get(2)); 608 | } 609 | 610 | private: 611 | typedef typename CallbackTraits::result_type result_type; 612 | Functor f_; 613 | }; 614 | 615 | template 616 | class Callback3 : public CallbackBase 617 | { 618 | public: 619 | Callback3(Functor f) : f_(f) {} 620 | 621 | virtual void invoke(Params const &p) 622 | { 623 | Dispatch3 624 | ::doDispatch(f_, 625 | p.template get(1), 626 | p.template get(2), 627 | p.template get(3)); 628 | } 629 | 630 | private: 631 | typedef typename CallbackTraits::result_type result_type; 632 | Functor f_; 633 | }; 634 | 635 | template 636 | class Callback4 : public CallbackBase 637 | { 638 | public: 639 | Callback4(Functor f) : f_(f) {} 640 | 641 | virtual void invoke(Params const &p) 642 | { 643 | Dispatch4 644 | ::doDispatch(f_, 645 | p.template get(1), 646 | p.template get(2), 647 | p.template get(3), 648 | p.template get(4)); 649 | } 650 | 651 | private: 652 | typedef typename CallbackTraits::result_type result_type; 653 | Functor f_; 654 | }; 655 | 656 | template 658 | class Callback5 : public CallbackBase 659 | { 660 | public: 661 | Callback5(Functor f) : f_(f) {} 662 | 663 | virtual void invoke(Params const &p) 664 | { 665 | Dispatch5 666 | ::doDispatch(f_, 667 | p.template get(1), 668 | p.template get(2), 669 | p.template get(3), 670 | p.template get(4), 671 | p.template get(5)); 672 | } 673 | 674 | private: 675 | typedef typename CallbackTraits::result_type result_type; 676 | Functor f_; 677 | }; 678 | 679 | template 681 | class Callback6 : public CallbackBase 682 | { 683 | public: 684 | Callback6(Functor f) : f_(f) {} 685 | 686 | virtual void invoke(Params const &p) 687 | { 688 | Dispatch6 689 | ::doDispatch(f_, 690 | p.template get(1), 691 | p.template get(2), 692 | p.template get(3), 693 | p.template get(4), 694 | p.template get(5), 695 | p.template get(6)); 696 | } 697 | 698 | private: 699 | typedef typename CallbackTraits::result_type result_type; 700 | Functor f_; 701 | }; 702 | 703 | template 705 | class Callback7 : public CallbackBase 706 | { 707 | public: 708 | Callback7(Functor f) : f_(f) {} 709 | 710 | virtual void invoke(Params const &p) 711 | { 712 | Dispatch7 713 | ::doDispatch(f_, 714 | p.template get(1), 715 | p.template get(2), 716 | p.template get(3), 717 | p.template get(4), 718 | p.template get(5), 719 | p.template get(6), 720 | p.template get(7)); 721 | } 722 | 723 | private: 724 | typedef typename CallbackTraits::result_type result_type; 725 | Functor f_; 726 | }; 727 | 728 | template 730 | class Callback8 : public CallbackBase 731 | { 732 | public: 733 | Callback8(Functor f) : f_(f) {} 734 | 735 | virtual void invoke(Params const &p) 736 | { 737 | Dispatch8 738 | ::doDispatch(f_, 739 | p.template get(1), 740 | p.template get(2), 741 | p.template get(3), 742 | p.template get(4), 743 | p.template get(5), 744 | p.template get(6), 745 | p.template get(7), 746 | p.template get(8)); 747 | } 748 | 749 | private: 750 | typedef typename CallbackTraits::result_type result_type; 751 | Functor f_; 752 | }; 753 | 754 | template 756 | class Callback9 : public CallbackBase 757 | { 758 | public: 759 | Callback9(Functor f) : f_(f) {} 760 | 761 | virtual void invoke(Params const &p) 762 | { 763 | Dispatch9 764 | ::doDispatch(f_, 765 | p.template get(1), 766 | p.template get(2), 767 | p.template get(3), 768 | p.template get(4), 769 | p.template get(5), 770 | p.template get(6), 771 | p.template get(7), 772 | p.template get(8), 773 | p.template get(9)); 774 | } 775 | 776 | private: 777 | typedef typename CallbackTraits::result_type result_type; 778 | Functor f_; 779 | }; 780 | 781 | template 784 | class Callback10 : public CallbackBase 785 | { 786 | public: 787 | Callback10(Functor f) : f_(f) {} 788 | 789 | virtual void invoke(Params const &p) 790 | { 791 | Dispatch10 793 | ::doDispatch(f_, 794 | p.template get(1), 795 | p.template get(2), 796 | p.template get(3), 797 | p.template get(4), 798 | p.template get(5), 799 | p.template get(6), 800 | p.template get(7), 801 | p.template get(8), 802 | p.template get(9), 803 | p.template get(10)); 804 | } 805 | 806 | private: 807 | typedef typename CallbackTraits::result_type result_type; 808 | Functor f_; 809 | }; 810 | 811 | std::string addLinkVar(int &i); 812 | std::string addLinkVar(double &d); 813 | std::string addLinkVar(std::string &s); 814 | void deleteLinkVar(int &i); 815 | void deleteLinkVar(double &d); 816 | void deleteLinkVar(std::string &s); 817 | 818 | // helper functions for later definitions 819 | 820 | template 821 | inline std::string toString(T const &t) 822 | { return boost::lexical_cast(t); } 823 | 824 | inline std::string toString(std::string const &str) { return str; } 825 | inline std::string toString(char const *str) { return str; } 826 | 827 | // this function is used to quote quotation marks in string values' 828 | // in later version, it will not be needed 829 | std::string quote(std::string const &s); 830 | 831 | class BasicToken 832 | { 833 | public: 834 | BasicToken(std::string const &n) : name_(n) {} 835 | operator std::string() const { return name_; } 836 | 837 | protected: 838 | std::string name_; 839 | }; 840 | 841 | std::ostream & operator<<(std::ostream &os, BasicToken const &token); 842 | 843 | // this class allows to use the same option name when configuring and 844 | // querying, for example: 845 | // 1. button(".b") -text("Hello") -foreground("blue"); 846 | // 2. string color(".b" << cget(foreground)); 847 | class Option : public details::BasicToken 848 | { 849 | public: 850 | explicit Option(char const *name, bool quote = false) 851 | : BasicToken(name), quote_(quote) {} 852 | 853 | template 854 | Expr operator()(T const &t) const 855 | { 856 | std::string str(" -"); 857 | str += name_; str += " "; 858 | str += (quote_ ? "\"" : ""); 859 | str += toString(t); 860 | str += (quote_ ? "\"" : ""); 861 | return Expr(str, false); 862 | } 863 | 864 | private: 865 | bool quote_; 866 | }; 867 | 868 | // these classes are used for substitution specification 869 | 870 | template 871 | class SubstAttr 872 | { 873 | public: 874 | SubstAttr(std::string const &spec) : spec_(spec) {} 875 | 876 | std::string get() const { return spec_; } 877 | 878 | private: 879 | std::string spec_; 880 | }; 881 | 882 | template 883 | class EventAttr : public SubstAttr 884 | { 885 | public: 886 | typedef T attrType; 887 | 888 | EventAttr(std::string const &spec) : SubstAttr(spec) {} 889 | }; 890 | 891 | template 892 | class ValidateAttr : public SubstAttr 893 | { 894 | public: 895 | typedef T validType; 896 | 897 | ValidateAttr(std::string const &spec) : SubstAttr(spec) {} 898 | }; 899 | 900 | } // namespace details 901 | 902 | // basic operations for Tk expressions 903 | 904 | details::Expr operator-(details::Expr const &lhs, details::Expr const &rhs); 905 | details::Expr operator<<(std::string const &w, details::Expr const &rhs); 906 | 907 | // for defining callbacks 908 | template std::string callback(Functor f) 909 | { 910 | return details::addCallback( 911 | std::shared_ptr( 912 | new details::Callback0(f))); 913 | } 914 | 915 | // for deleting callbacks 916 | void deleteCallback(std::string const &name); 917 | 918 | // RAII handle for callback (calls deleteCallback in its destructor) 919 | class CallbackHandle 920 | { 921 | public: 922 | explicit CallbackHandle(std::string const &name); 923 | ~CallbackHandle(); 924 | 925 | std::string const & get() const { return name_; } 926 | 927 | private: 928 | std::string name_; 929 | }; 930 | 931 | // for linking variable 932 | template std::string linkVar(T &t) 933 | { 934 | return details::addLinkVar(t); 935 | } 936 | 937 | // for unlinking variable 938 | template void unLinkVar(T &t) { details::deleteLinkVar(t); } 939 | 940 | // RAII handle for linking variables (calls unLinkVar in its destructor) 941 | template 942 | class LinkHandle 943 | { 944 | public: 945 | explicit LinkHandle(T &t) :t_(t) { var_ = details::addLinkVar(t); } 946 | ~LinkHandle() { details::deleteLinkVar(t_); } 947 | 948 | std::string const & get() const { return var_; } 949 | 950 | private: 951 | T &t_; 952 | std::string var_; 953 | }; 954 | 955 | // for brute-force evaluation of simple scripts 956 | details::Expr eval(std::string const &str); 957 | 958 | // for initializing Tcl environment 959 | void init(char *argv0); 960 | 961 | // for falling into the event loop 962 | void runEventLoop(); 963 | 964 | // for setting command output stream 965 | void setDumpStream(std::ostream &os); 966 | 967 | } // namespace Tk 968 | 969 | #endif // CPPTKBASE_H_INCLUDED 970 | -------------------------------------------------------------------------------- /cpptk.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2004-2006, Maciej Sobczak 3 | // Copyright 2017 Declan Hoare 4 | // 5 | // Permission to copy, use, modify, sell and distribute this software 6 | // is granted provided this copyright notice appears in all copies. 7 | // This software is provided "as is" without express or implied 8 | // warranty, and with no claim as to its suitability for any purpose. 9 | // 10 | 11 | #include "cpptk.h" 12 | #include 13 | 14 | using namespace Tk; 15 | using namespace Tk::details; 16 | 17 | // various Tk bits and pieces 18 | 19 | // starter pieces (genuine Tk commands) 20 | 21 | Expr Tk::bell() { return Expr("bell"); } 22 | 23 | Expr Tk::bindtags(std::string const &name, std::string const &tags) 24 | { 25 | std::string str("bindtags "); 26 | str += name; 27 | if (tags.empty()) 28 | { 29 | return Expr(str); 30 | } 31 | else 32 | { 33 | str += " { "; str += tags; str += " }"; 34 | return Expr(str); 35 | } 36 | } 37 | 38 | Expr Tk::button(std::string const &name) 39 | { 40 | std::string str("button "); 41 | str += name; 42 | return Expr(str); 43 | } 44 | 45 | Expr Tk::canvas(std::string const &name) 46 | { 47 | std::string str("canvas "); 48 | str += name; 49 | return Expr(str); 50 | } 51 | 52 | Expr Tk::clipboard(std::string const &option) 53 | { 54 | std::string str("clipboard "); 55 | str += option; 56 | return Expr(str); 57 | } 58 | 59 | Expr Tk::clipboard(std::string const &option, std::string const &data) 60 | { 61 | std::string str("clipboard "); 62 | str += option; 63 | std::string postfix(" -- \""); 64 | postfix += quote(data); 65 | postfix += "\""; 66 | return Expr(str, postfix); 67 | } 68 | 69 | Expr Tk::destroy(std::string const &name) 70 | { 71 | std::string str("destroy "); 72 | str += name; 73 | return Expr(str); 74 | } 75 | 76 | Expr Tk::entry(std::string const &name) 77 | { 78 | std::string str("entry "); 79 | str += name; 80 | return Expr(str); 81 | } 82 | 83 | Expr Tk::fonts(std::string const &option, std::string const &name) 84 | { 85 | std::string str("font "); 86 | str += option; 87 | if (name.empty()) 88 | { 89 | return Expr(str); 90 | } 91 | else 92 | { 93 | str += " "; 94 | str += name; 95 | return Expr(str); 96 | } 97 | } 98 | 99 | Expr Tk::grab(std::string const &option, std::string const &name) 100 | { 101 | std::string str("grab "); 102 | str += option; 103 | if (name.empty()) 104 | { 105 | return Expr(str); 106 | } 107 | else 108 | { 109 | str += " "; 110 | str += name; 111 | return Expr(str); 112 | } 113 | } 114 | 115 | Expr Tk::images(std::string const &option, std::string const &tn, std::string const &name) 116 | { 117 | std::string str("image "); 118 | str += option; 119 | if (tn.empty()) 120 | { 121 | return Expr(str); 122 | } 123 | str += " "; str += tn; 124 | if (name.empty()) 125 | { 126 | return Expr(str); 127 | } 128 | str += " "; 129 | if (option == "cget") 130 | { 131 | str += '-'; 132 | } 133 | str += name; 134 | return Expr(str); 135 | } 136 | 137 | Expr Tk::label(std::string const &name) 138 | { 139 | std::string str("label "); 140 | str += name; 141 | return Expr(str); 142 | } 143 | 144 | Expr Tk::labelframe(std::string const &name) 145 | { 146 | std::string str("labelframe "); 147 | str += name; 148 | return Expr(str); 149 | } 150 | 151 | Expr Tk::listbox(std::string const &name) 152 | { 153 | std::string str("listbox "); 154 | str += name; 155 | return Expr(str); 156 | } 157 | 158 | Expr Tk::menu(std::string const &name) 159 | { 160 | std::string str("menu "); 161 | str += name; 162 | return Expr(str); 163 | } 164 | 165 | Expr Tk::menubutton(std::string const &name) 166 | { 167 | std::string str("menubutton "); 168 | str += name; 169 | return Expr(str); 170 | } 171 | 172 | Expr Tk::message(std::string const &name) 173 | { 174 | std::string str("message "); 175 | str += name; 176 | return Expr(str); 177 | } 178 | 179 | Expr Tk::option(std::string const &todo, std::string const &s1, 180 | std::string const &s2, std::string const &s3) 181 | { 182 | std::string str("option "); 183 | str += todo; 184 | if (s1.empty()) 185 | { 186 | return Expr(str); 187 | } 188 | str += " \""; str += s1; str += '\"'; 189 | if (s2.empty()) 190 | { 191 | return Expr(str); 192 | } 193 | str += " \""; str += s2; str += '\"'; 194 | if (s3.empty()) 195 | { 196 | return Expr(str); 197 | } 198 | str += " "; str += s3; 199 | return Expr(str); 200 | } 201 | 202 | Expr Tk::pack(std::string const &w1, 203 | std::string const &w2, 204 | std::string const &w3, 205 | std::string const &w4, 206 | std::string const &w5, 207 | std::string const &w6, 208 | std::string const &w7, 209 | std::string const &w8, 210 | std::string const &w9, 211 | std::string const &w10) 212 | { 213 | std::string str("pack "); 214 | str += w1; 215 | if (!w2.empty()) { str += " "; str += w2; } 216 | if (!w3.empty()) { str += " "; str += w3; } 217 | if (!w4.empty()) { str += " "; str += w4; } 218 | if (!w5.empty()) { str += " "; str += w5; } 219 | if (!w6.empty()) { str += " "; str += w6; } 220 | if (!w7.empty()) { str += " "; str += w7; } 221 | if (!w8.empty()) { str += " "; str += w8; } 222 | if (!w9.empty()) { str += " "; str += w9; } 223 | if (!w10.empty()) { str += " "; str += w10; } 224 | 225 | return Expr(str); 226 | } 227 | 228 | Expr Tk::panedwindow(std::string const &name) 229 | { 230 | std::string str("panedwindow "); 231 | str += name; 232 | return Expr(str); 233 | } 234 | 235 | Expr Tk::scale(std::string const &name) 236 | { 237 | std::string str("scale "); 238 | str += name; 239 | return Expr(str); 240 | } 241 | 242 | Expr Tk::scrollbar(std::string const &name) 243 | { 244 | std::string str("scrollbar "); 245 | str += name; 246 | return Expr(str); 247 | } 248 | 249 | Expr Tk::spinbox(std::string const &name) 250 | { 251 | std::string str("spinbox "); 252 | str += name; 253 | return Expr(str); 254 | } 255 | 256 | Expr Tk::textw(std::string const &name) 257 | { 258 | std::string str("text "); 259 | str += name; 260 | return Expr(str); 261 | } 262 | 263 | Expr Tk::tk_chooseColor() 264 | { 265 | return Expr("tk_chooseColor"); 266 | } 267 | 268 | Expr Tk::tk_chooseDirectory() 269 | { 270 | return Expr("tk_chooseDirectory"); 271 | } 272 | 273 | Expr Tk::tk_dialog(std::string const &window, std::string const &title, 274 | std::string const &text, std::string const &bitmap, std::string const &def, 275 | std::string const &but1, std::string const &but2, std::string const &but3, 276 | std::string const &but4) 277 | { 278 | std::string str("tk_dialog "); 279 | str += window; str += " \""; 280 | str += title; str += "\" \""; 281 | str += quote(text); str += "\" "; 282 | str += bitmap; str += " \""; 283 | str += def; str += "\" \""; 284 | str += but1; str += "\""; 285 | if (but2.empty()) 286 | { 287 | return Expr(str); 288 | } 289 | str += " \""; 290 | str += but2; str += "\""; 291 | if (but3.empty()) 292 | { 293 | return Expr(str); 294 | } 295 | str += " \""; 296 | str += but3; str += "\""; 297 | if (but4.empty()) 298 | { 299 | return Expr(str); 300 | } 301 | str += " \""; 302 | str += but4; str += "\""; 303 | return Expr(str); 304 | } 305 | 306 | Expr Tk::tk_focusNext(std::string const &window) 307 | { 308 | std::string str("tk_focusNext "); 309 | str += window; 310 | return Expr(str); 311 | } 312 | 313 | Expr Tk::tk_focusPrev(std::string const &window) 314 | { 315 | std::string str("tk_focusPrev "); 316 | str += window; 317 | return Expr(str); 318 | } 319 | 320 | Expr Tk::tk_getOpenFile() 321 | { 322 | return Expr("tk_getOpenFile"); 323 | } 324 | 325 | Expr Tk::tk_getSaveFile() 326 | { 327 | return Expr("tk_getSaveFile"); 328 | } 329 | 330 | Expr Tk::tk_menuSetFocus(std::string const &menu) 331 | { 332 | std::string str("tk_menuSetFocus "); 333 | str += menu; 334 | return Expr(str); 335 | } 336 | 337 | Expr Tk::tk_messageBox() 338 | { 339 | return Expr("tk_messageBox"); 340 | } 341 | 342 | Expr Tk::tk_setPalette(std::string const &color) 343 | { 344 | std::string str("tk_setPalette "); 345 | str += color; 346 | return Expr(str); 347 | } 348 | 349 | Expr Tk::tk_textCopy(std::string const &w) 350 | { 351 | std::string str("tk_textCopy "); 352 | str += w; 353 | return Expr(str); 354 | } 355 | 356 | Expr Tk::tk_textCut(std::string const &w) 357 | { 358 | std::string str("tk_textCut "); 359 | str += w; 360 | return Expr(str); 361 | } 362 | 363 | Expr Tk::tk_textPaste(std::string const &w) 364 | { 365 | std::string str("tk_textPaste "); 366 | str += w; 367 | return Expr(str); 368 | } 369 | 370 | Expr Tk::tkwait(std::string const &option, std::string const &w) 371 | { 372 | std::string str("tkwait "); 373 | str += option; str += " "; 374 | str += w; 375 | return Expr(str); 376 | } 377 | 378 | Expr Tk::winfo(std::string const &option, std::string const &w) 379 | { 380 | std::string str("winfo "); 381 | str += option; 382 | std::string postfix(" "); 383 | postfix += w; 384 | return Expr(str, postfix); 385 | } 386 | 387 | Expr Tk::wm(std::string const &option, std::string const &w) 388 | { 389 | std::string str("wm "); 390 | str += option; str += " "; 391 | str += w; 392 | return Expr(str); 393 | } 394 | 395 | Expr Tk::wmprotocol(std::string const &w, std::string const &proto) 396 | { 397 | std::string str("wm protocol "); 398 | str += w; 399 | if (proto.empty()) 400 | { 401 | return Expr(str); 402 | } 403 | str += " "; 404 | str += proto; 405 | return Expr(str); 406 | } 407 | 408 | // widget commands 409 | 410 | Expr Tk::addtag(std::string const &tag, std::string const &spec) 411 | { 412 | std::string str("addtag "); 413 | str += tag; str += " "; 414 | str += spec; 415 | return Expr(str); 416 | } 417 | 418 | Expr Tk::blank() 419 | { 420 | return Expr("blank"); 421 | } 422 | 423 | Expr Tk::clone(std::string const &newpath, std::string const &type) 424 | { 425 | std::string str("clone "); 426 | str += newpath; 427 | if (type.empty()) 428 | { 429 | return Expr(str); 430 | } 431 | str += " "; str += type; 432 | return Expr(str); 433 | } 434 | 435 | Expr Tk::compare(std::string const &indx1, std::string const &oper, std::string const &indx2) 436 | { 437 | std::string str("compare "); 438 | str += indx1; str += " "; 439 | str += oper; str += " "; 440 | str += indx2; 441 | return Expr(str); 442 | } 443 | 444 | Expr Tk::coords() 445 | { 446 | return Expr("coords"); 447 | } 448 | 449 | Expr Tk::coords(std::string const &item, int x, int y) 450 | { 451 | std::string str("coords "); 452 | str += item; str += " "; 453 | str += toString(x); str += " "; 454 | str += toString(y); 455 | return Expr(str); 456 | } 457 | 458 | Expr Tk::coords(std::string const &item, Point const &p) 459 | { 460 | return coords(item, p.x, p.y); 461 | } 462 | 463 | Expr Tk::coords(std::string const &item, int x1, int y1, int x2, int y2) 464 | { 465 | std::string str("coords "); 466 | str += item; str += " "; 467 | str += toString(x1); str += " "; 468 | str += toString(y1); str += " "; 469 | str += toString(x2); str += " "; 470 | str += toString(y2); 471 | return Expr(str); 472 | } 473 | 474 | Expr Tk::coords(std::string const &item, Point const &p1, Point const &p2) 475 | { 476 | return coords(item, p1.x, p1.y, p2.x, p2.y); 477 | } 478 | 479 | Expr Tk::coords(std::string const &item, Box const &b) 480 | { 481 | return coords(item, b.x1, b.y1, b.x2, b.y2); 482 | } 483 | 484 | Expr Tk::copy(std::string const &photo) 485 | { 486 | std::string str("copy "); 487 | str += photo; 488 | return Expr(str); 489 | } 490 | 491 | Expr Tk::curselection() 492 | { 493 | return Expr("curselection"); 494 | } 495 | 496 | Expr Tk::debug() 497 | { 498 | return Expr("debug"); 499 | } 500 | 501 | Expr Tk::debug(bool d) 502 | { 503 | std::string str("debug "); 504 | str += toString(d); 505 | return Expr(str); 506 | } 507 | 508 | Expr Tk::deselect() 509 | { 510 | return Expr("deselect"); 511 | } 512 | 513 | Expr Tk::dlineinfo(std::string const &indx) 514 | { 515 | std::string str("dlineinfo "); 516 | str += indx; 517 | return Expr(str); 518 | } 519 | 520 | Expr Tk::dtag(std::string const &tag, std::string const &todel) 521 | { 522 | std::string str("dtag "); 523 | str += tag; 524 | if (todel.empty()) 525 | { 526 | return Expr(str); 527 | } 528 | else 529 | { 530 | str += " "; str += todel; 531 | return Expr(str); 532 | } 533 | } 534 | 535 | Expr Tk::dump(std::string const &indx1, std::string const &indx2) 536 | { 537 | std::string str("dump"); 538 | std::string postfix(" "); 539 | postfix += indx1; 540 | if (indx2.empty() == false) 541 | { 542 | postfix += " "; 543 | postfix += indx2; 544 | } 545 | return Expr("dump", postfix); 546 | } 547 | 548 | Expr Tk::edit(std::string const &option) 549 | { 550 | std::string str("edit "); 551 | str += option; 552 | return Expr(str); 553 | } 554 | 555 | Expr Tk::find(std::string const &spec) 556 | { 557 | std::string str("find "); 558 | str += spec; 559 | return Expr(str); 560 | } 561 | 562 | Expr Tk::flash() 563 | { 564 | return Expr("flash"); 565 | } 566 | 567 | Expr Tk::getsize() 568 | { 569 | return Expr("size"); 570 | } 571 | 572 | Expr Tk::gettags(std::string const &item) 573 | { 574 | std::string str("gettags "); 575 | str += item; 576 | return Expr(str); 577 | } 578 | 579 | Expr Tk::insert(std::string const &indx, std::string const &txt, std::string const &tag) 580 | { 581 | std::string str("insert "); 582 | str += indx; str += " \""; 583 | str += quote(txt); str += "\""; 584 | if (tag.empty()) 585 | { 586 | return Expr(str); 587 | } 588 | str += " "; 589 | str += tag; 590 | return Expr(str); 591 | } 592 | 593 | Expr Tk::invoke() 594 | { 595 | return Expr("invoke"); 596 | } 597 | 598 | Expr Tk::move(std::string const &item, int x, int y) 599 | { 600 | std::string str("move "); 601 | str += item; str += " "; 602 | str += toString(x); str += " "; 603 | str += toString(y); 604 | return Expr(str); 605 | } 606 | 607 | Expr Tk::panecget(std::string const &w, std::string const &option) 608 | { 609 | std::string str("panecget "); 610 | str += w; str += " -"; 611 | str += option; 612 | return Expr(str); 613 | } 614 | 615 | Expr Tk::paneconfigure(std::string const &w) 616 | { 617 | std::string str("paneconfigure "); 618 | str += w; 619 | return Expr(str); 620 | } 621 | 622 | Expr Tk::panes() 623 | { 624 | return Expr("panes"); 625 | } 626 | 627 | Expr Tk::postscript() 628 | { 629 | return Expr("postscript"); 630 | } 631 | 632 | Expr Tk::proxy(std::string const &option) 633 | { 634 | std::string str("proxy "); 635 | str += option; 636 | return Expr(str); 637 | } 638 | 639 | Expr Tk::put(std::string const &color) 640 | { 641 | std::string str("put "); 642 | str += color; 643 | return Expr(str); 644 | } 645 | 646 | Expr Tk::read(std::string const &file) 647 | { 648 | std::string str("read \""); 649 | str += file; str += '\"'; 650 | return Expr(str); 651 | } 652 | 653 | Expr Tk::redither() 654 | { 655 | return Expr("redither"); 656 | } 657 | 658 | Expr Tk::sash(std::string const &option, int index) 659 | { 660 | std::string str("sash "); 661 | str += option; str += " "; 662 | str += toString(index); 663 | return Expr(str); 664 | } 665 | 666 | Expr Tk::search(std::string const &pattern, 667 | std::string const &indx1, std::string const &indx2) 668 | { 669 | std::string str("search \""); 670 | str += quote(pattern); str += '\"'; 671 | std::string postfix(" -- "); 672 | postfix += indx1; 673 | if (indx2.empty()) 674 | { 675 | return Expr(str, postfix); 676 | } 677 | postfix += " "; 678 | postfix += indx2; 679 | return Expr(str, postfix); 680 | } 681 | 682 | Expr Tk::select() 683 | { 684 | return Expr("select"); 685 | } 686 | 687 | Expr Tk::select(std::string const &option) 688 | { 689 | std::string str("select "); 690 | str += option; 691 | return Expr(str); 692 | } 693 | 694 | Expr Tk::selection(std::string const &option) 695 | { 696 | std::string str("selection "); 697 | str += option; 698 | return Expr(str); 699 | } 700 | 701 | Expr Tk::tag(std::string const &option, std::string const &tagname) 702 | { 703 | std::string str("tag "); 704 | str += option; 705 | if (tagname.empty()) 706 | { 707 | return Expr(str); 708 | } 709 | str += " "; 710 | str += tagname; 711 | return Expr(str); 712 | } 713 | 714 | Expr Tk::tag(std::string const &option, std::string const &tagname, 715 | std::string const &indx1, std::string const &indx2) 716 | { 717 | std::string str("tag "); 718 | str += option; str += " "; 719 | str += tagname; str += " "; 720 | if (option == "cget") 721 | { 722 | str += '-'; 723 | str += indx1; 724 | return Expr(str); 725 | } 726 | str += indx1; 727 | if (indx2.empty()) 728 | { 729 | return Expr(str); 730 | } 731 | str += " "; 732 | str += indx2; 733 | return Expr(str); 734 | } 735 | 736 | Expr Tk::tag(std::string const &option, std::string const &tagname, 737 | std::string const &indx1, char const *indx2) 738 | { 739 | return Tk::tag(option, tagname, indx1, std::string(indx2)); 740 | } 741 | 742 | Expr Tk::toggle() 743 | { 744 | return Expr("toggle"); 745 | } 746 | 747 | Expr Tk::transparency(std::string const &option, int x, int y) 748 | { 749 | std::string str("transparency "); 750 | str += option; str += " "; 751 | str += toString(x); str += " "; 752 | str += toString(y); 753 | return Expr(str); 754 | } 755 | 756 | Expr Tk::transparency(std::string const &option, int x, int y, bool tr) 757 | { 758 | std::string str("transparency "); 759 | str += option; str += " "; 760 | str += toString(x); str += " "; 761 | str += toString(y); str += " "; 762 | str += toString(tr); 763 | return Expr(str); 764 | } 765 | 766 | Expr Tk::windows(std::string const &option, std::string const &indx, std::string const &name) 767 | { 768 | std::string str("window "); 769 | str += option; 770 | if (indx.empty()) 771 | { 772 | return Expr(str); 773 | } 774 | str += " "; 775 | str += indx; 776 | if (name.empty()) 777 | { 778 | return Expr(str); 779 | } 780 | str += " "; 781 | str += name; 782 | return Expr(str); 783 | } 784 | 785 | Expr Tk::write(std::string const &file) 786 | { 787 | std::string str("write \""); 788 | str += file; str += '\"'; 789 | return Expr(str); 790 | } 791 | 792 | Expr Tk::xview() 793 | { 794 | return Expr("xview"); 795 | } 796 | 797 | Expr Tk::xview(std::string const &option, double fraction) 798 | { 799 | std::string str("xview "); 800 | str += option; str += " "; 801 | str += toString(fraction); 802 | return Expr(str); 803 | } 804 | 805 | Expr Tk::xview(std::string const option, int number, std::string const &what) 806 | { 807 | std::string str("xview "); 808 | str += option; str += " "; 809 | str += toString(number); str += " "; 810 | str += what; 811 | return Expr(str); 812 | } 813 | 814 | Expr Tk::yview() 815 | { 816 | return Expr("yview"); 817 | } 818 | 819 | Expr Tk::yview(std::string const &option, double fraction) 820 | { 821 | std::string str("yview "); 822 | str += option; str += " "; 823 | str += toString(fraction); 824 | return Expr(str); 825 | } 826 | 827 | Expr Tk::yview(std::string const option, int number, std::string const &what) 828 | { 829 | std::string str("yview "); 830 | str += option; str += " "; 831 | str += toString(number); str += " "; 832 | str += what; 833 | return Expr(str); 834 | } 835 | 836 | // options 837 | 838 | #define CPPTK_OPTION(name, quote) Option Tk::name(#name, quote); 839 | #include "cpptkoptions.x" 840 | #undef CPPTK_OPTION 841 | 842 | // other options, requiring special syntax or compilation 843 | 844 | Expr Tk::backwards() 845 | { 846 | return Expr(" -backwards", false); 847 | } 848 | 849 | Expr Tk::cliptype(std::string const &type) 850 | { 851 | std::string str(" -type "); 852 | str += type; 853 | return Expr(str, false); 854 | } 855 | 856 | Expr Tk::count(int &i) 857 | { 858 | std::string str(" -count "); 859 | str += details::addLinkVar(i); 860 | return details::Expr(str, false); 861 | } 862 | 863 | Expr Tk::count(std::string const &name) 864 | { 865 | std::string str(" -count "); 866 | str += name; 867 | return Expr(str, false); 868 | } 869 | 870 | Expr Tk::defaultbutton(std::string const &but) 871 | { 872 | std::string str(" -default \""); 873 | str += but; str += '\"'; 874 | return Expr(str, false); 875 | } 876 | 877 | Expr Tk::defaultstate(std::string const &name) 878 | { 879 | std::string str(" -default "); 880 | str += name; 881 | return Expr(str, false); 882 | } 883 | 884 | Expr Tk::exact() 885 | { 886 | return Expr(" -exact", false); 887 | } 888 | 889 | Expr Tk::filetypes(std::string const &types) 890 | { 891 | std::string str(" -filetypes {"); 892 | str += types; 893 | str += "}"; 894 | return Expr(str, false); 895 | } 896 | 897 | Expr Tk::forwards() 898 | { 899 | return Expr(" -forwards", false); 900 | } 901 | 902 | Expr Tk::grayscale() 903 | { 904 | return Expr(" -grayscale", false); 905 | } 906 | 907 | Expr Tk::invalidcommand(char const *name) 908 | { 909 | std::string str(" -invalidcommand { "); 910 | str += name; str += " }"; 911 | return Expr(str, false); 912 | } 913 | 914 | Expr Tk::invalidcommand(std::string const &name) 915 | { 916 | std::string str(" -invalidcommand { "); 917 | str += name; str += " }"; 918 | return Expr(str, false); 919 | } 920 | 921 | Expr Tk::invalidcommand(CallbackHandle const &handle) 922 | { 923 | std::string str(" -invalidcommand { "); 924 | str += handle.get(); str += " }"; 925 | return Expr(str, false); 926 | } 927 | 928 | Expr Tk::menutype(std::string const &type) 929 | { 930 | std::string str(" -type "); 931 | str += type; 932 | return Expr(str, false); 933 | } 934 | 935 | Expr Tk::messagetext(std::string const &txt) 936 | { 937 | std::string str(" -message \""); 938 | str += txt; str += '\"'; 939 | return Expr(str, false); 940 | } 941 | 942 | Expr Tk::messagetype(std::string const &type) 943 | { 944 | std::string str(" -type "); 945 | str += type; 946 | return Expr(str, false); 947 | } 948 | 949 | Expr Tk::multiple() 950 | { 951 | return Expr(" -multiple", false); 952 | } 953 | 954 | Expr Tk::nocase() 955 | { 956 | return Expr(" -nocase", false); 957 | } 958 | 959 | Expr Tk::postcommand(std::string const &name) 960 | { 961 | std::string str(" -postcommand { "); 962 | str += name; str += " }"; 963 | return Expr(str, false); 964 | } 965 | 966 | Expr Tk::postcommand(CallbackHandle const &handle) 967 | { 968 | std::string str(" -postcommand { "); 969 | str += handle.get(); str += " }"; 970 | return Expr(str, false); 971 | } 972 | 973 | Expr Tk::regexp() 974 | { 975 | return Expr(" -regexp", false); 976 | } 977 | 978 | Expr Tk::shrink() 979 | { 980 | return Expr(" -shrink", false); 981 | } 982 | 983 | Expr Tk::submenu(std::string const &menu) 984 | { 985 | std::string str(" -menu "); 986 | str += menu; 987 | return Expr(str, false); 988 | } 989 | 990 | Expr Tk::subsample(int x, int y) 991 | { 992 | std::string str(" -subsample "); 993 | str += toString(x); str += " "; 994 | str += toString(y); 995 | return Expr(str, false); 996 | } 997 | 998 | Expr Tk::tags() 999 | { 1000 | return Expr(" -tag", false); 1001 | } 1002 | 1003 | Expr Tk::tearoffcommand(std::string const &name) 1004 | { 1005 | std::string str(" -tearoffcommand { "); 1006 | str += name; str += " }"; 1007 | return Expr(str, false); 1008 | } 1009 | 1010 | Expr Tk::tearoffcommand(CallbackHandle const &handle) 1011 | { 1012 | std::string str(" -tearoffcommand { "); 1013 | str += handle.get(); str += " }"; 1014 | return Expr(str, false); 1015 | } 1016 | 1017 | Expr Tk::textvariable(std::string const &name) 1018 | { 1019 | std::string str(" -textvariable "); 1020 | str += name; 1021 | return Expr(str, false); 1022 | } 1023 | 1024 | Expr Tk::variable(std::string const &name) 1025 | { 1026 | std::string str(" -variable "); 1027 | str += name; 1028 | return Expr(str, false); 1029 | } 1030 | 1031 | Expr Tk::zoom(double x, double y) 1032 | { 1033 | std::string str(" -zoom "); 1034 | str += toString(x); str += " "; 1035 | str += toString(y); 1036 | return Expr(str, false); 1037 | } 1038 | 1039 | // event attribute specifiers 1040 | 1041 | EventAttr Tk::event_A("%A"); // %A - character 1042 | EventAttr Tk::event_b("%b"); // %b - button number 1043 | EventAttr Tk::event_D("%D"); // %D - delta for mouse wheel 1044 | EventAttr Tk::event_f("%f"); // %f - focus flag 1045 | EventAttr Tk::event_h("%h"); // %h - height 1046 | EventAttr Tk::event_k("%k"); // %k - keycode 1047 | EventAttr Tk::event_K("%K"); // %K - keysym 1048 | EventAttr Tk::event_m("%m"); // %m - mode 1049 | EventAttr Tk::event_N("%N"); // %N - keysym, numeric value 1050 | EventAttr Tk::event_s("%s"); // %s - state 1051 | EventAttr Tk::event_T("%T"); // %T - type 1052 | EventAttr Tk::event_w("%w"); // %w - width 1053 | EventAttr Tk::event_W("%W"); // %W - window name 1054 | EventAttr Tk::event_x("%x"); // %x - x coordinate 1055 | EventAttr Tk::event_X("%X"); // %X - root x coordinate 1056 | EventAttr Tk::event_y("%y"); // %x - y coordinate 1057 | EventAttr Tk::event_Y("%Y"); // %Y - root y coordinate 1058 | 1059 | ValidateAttr Tk::valid_d("%d"); // %d - type of action 1060 | ValidateAttr Tk::valid_i("%i"); // %i - index of char 1061 | ValidateAttr Tk::valid_P("%P"); // %P - new value 1062 | ValidateAttr Tk::valid_s("%s"); // %s - current value 1063 | ValidateAttr Tk::valid_S("%S"); // %S - diff 1064 | ValidateAttr Tk::valid_v("%v"); // %v - current type of valid. 1065 | ValidateAttr Tk::valid_V("%V"); // %V - type of trigger 1066 | ValidateAttr Tk::valid_W("%W"); // %W - name of entry widget 1067 | 1068 | 1069 | // constants 1070 | 1071 | #define CPPTK_CONSTANT(c) char const * Tk::c = #c; 1072 | #include "cpptkconstants.x" 1073 | #undef CPPTK_CONSTANT 1074 | 1075 | // additional constants 1076 | 1077 | char const * Tk::deletefont = "delete"; // instead of conflicting 'delete' 1078 | char const * Tk::deleteimg = "delete"; // instead of conflicting 'delete' 1079 | char const * Tk::deletetag = "delete"; // instead of conflicting 'delete' 1080 | char const * Tk::setglobal = "set -global"; 1081 | char const * Tk::wrapchar = "char"; // instead of conflicting 'char' 1082 | char const * Tk::wrapword = "word"; // for consistency 1083 | 1084 | // additional functions 1085 | 1086 | Expr Tk::afteridle(std::string const &cmd) 1087 | { 1088 | std::string str("after idle { "); 1089 | str += cmd; str += " }"; 1090 | return Expr(str); 1091 | } 1092 | 1093 | Expr Tk::update(std::string const &option) 1094 | { 1095 | std::string str("update"); 1096 | if (option.empty()) 1097 | { 1098 | return Expr(str); 1099 | } 1100 | str += " "; 1101 | str += option; 1102 | return Expr(str); 1103 | } 1104 | 1105 | // multipurpose tokens 1106 | 1107 | Tk::details::BindToken::BindToken() : BasicToken("bind") {} 1108 | 1109 | Expr Tk::details::BindToken::operator()(std::string const &name, 1110 | std::string const &seq) const 1111 | { 1112 | std::string str("bind "); 1113 | str += name; str += " "; 1114 | str += seq; str += " {}"; 1115 | return Expr(str); 1116 | } 1117 | 1118 | BindToken Tk::bind; 1119 | 1120 | Tk::details::CheckButtonToken::CheckButtonToken() 1121 | : BasicToken("checkbutton") {} 1122 | 1123 | Expr Tk::details::CheckButtonToken::operator()(std::string const &name) const 1124 | { 1125 | std::string str("checkbutton "); 1126 | str += name; 1127 | return Expr(str); 1128 | } 1129 | 1130 | CheckButtonToken Tk::checkbutton; 1131 | 1132 | Tk::details::FrameToken::FrameToken() : BasicToken("frame") {} 1133 | 1134 | Expr Tk::details::FrameToken::operator()(std::string const &name) const 1135 | { 1136 | std::string str("frame "); 1137 | str += name; 1138 | return Expr(str); 1139 | } 1140 | 1141 | FrameToken Tk::frame; 1142 | 1143 | Tk::details::GridToken::GridToken() : BasicToken("grid") {} 1144 | 1145 | Expr Tk::details::GridToken::operator()(std::string const &option, 1146 | std::string const &name) const 1147 | { 1148 | std::string str("grid "); 1149 | str += option; str += " "; 1150 | str += name; 1151 | return Expr(str); 1152 | } 1153 | 1154 | Expr Tk::details::GridToken::operator()(std::string const &option, 1155 | std::string const &name, int x, int y) const 1156 | { 1157 | std::string str("grid "); 1158 | str += option; str += " "; 1159 | str += name; str += " "; 1160 | str += toString(x); str += " "; 1161 | str += toString(y); 1162 | return Expr(str); 1163 | } 1164 | 1165 | Expr Tk::details::GridToken::operator()(std::string const &option, 1166 | std::string const &name, int col1, int row1, int col2, int row2) const 1167 | { 1168 | std::string str("grid "); 1169 | str += option; str += " "; 1170 | str += name; str += " "; 1171 | str += toString(col1); str += " "; 1172 | str += toString(row1); str += " "; 1173 | str += toString(col2); str += " "; 1174 | str += toString(row2); 1175 | return Expr(str); 1176 | } 1177 | 1178 | GridToken Tk::grid; 1179 | 1180 | Tk::details::LowerToken::LowerToken() : BasicToken("lower") {} 1181 | 1182 | Expr Tk::details::LowerToken::operator()(std::string const &name, 1183 | std::string const &belowthis) const 1184 | { 1185 | std::string str("lower "); 1186 | str += name; 1187 | if (belowthis.empty()) 1188 | { 1189 | return Expr(str); 1190 | } 1191 | str += " "; str += belowthis; 1192 | return Expr(str); 1193 | } 1194 | 1195 | LowerToken Tk::lower; 1196 | 1197 | Tk::details::PlaceToken::PlaceToken() : BasicToken("place") {} 1198 | 1199 | Expr Tk::details::PlaceToken::operator()(std::string const &w) const 1200 | { 1201 | std::string str("place "); 1202 | str += w; 1203 | return Expr(str); 1204 | } 1205 | 1206 | Expr Tk::details::PlaceToken::operator()(std::string const &option, 1207 | std::string const &w) const 1208 | { 1209 | std::string str("place "); 1210 | str += option; str += " "; 1211 | str += w; 1212 | return Expr(str); 1213 | } 1214 | 1215 | PlaceToken Tk::place; 1216 | 1217 | Tk::details::RadioButtonToken::RadioButtonToken() 1218 | : BasicToken("radiobutton") {} 1219 | 1220 | Expr Tk::details::RadioButtonToken::operator()(std::string const &name) const 1221 | { 1222 | std::string str("radiobutton "); 1223 | str += name; 1224 | return Expr(str); 1225 | } 1226 | 1227 | RadioButtonToken Tk::radiobutton; 1228 | 1229 | Tk::details::RaiseToken::RaiseToken() : BasicToken("raise") {} 1230 | 1231 | Expr Tk::details::RaiseToken::operator()(std::string const &name, 1232 | std::string const &abovethis) const 1233 | { 1234 | std::string str("raise "); 1235 | str += name; 1236 | if (abovethis.empty()) 1237 | { 1238 | return Expr(str); 1239 | } 1240 | str += " "; str += abovethis; 1241 | return Expr(str); 1242 | } 1243 | 1244 | RaiseToken Tk::raise; 1245 | 1246 | Tk::details::ToplevelToken::ToplevelToken() : BasicToken("toplevel") {} 1247 | 1248 | Expr Tk::details::ToplevelToken::operator()(std::string const &w) const 1249 | { 1250 | std::string str("toplevel "); 1251 | str += w; 1252 | return Expr(str); 1253 | } 1254 | 1255 | ToplevelToken Tk::toplevel; 1256 | 1257 | Tk::details::AddToken::AddToken() : BasicToken("add") {} 1258 | 1259 | Expr Tk::details::AddToken::operator()(std::string const &tn) const 1260 | { 1261 | std::string str("add "); 1262 | str += tn; 1263 | return Expr(str); 1264 | } 1265 | 1266 | AddToken Tk::add; 1267 | 1268 | Tk::details::BboxToken::BboxToken() : BasicToken("bbox") {} 1269 | 1270 | BboxToken Tk::bbox; 1271 | 1272 | Tk::details::CgetToken::CgetToken() : BasicToken("cget") {} 1273 | 1274 | Expr Tk::details::CgetToken::operator()(std::string const &name) const 1275 | { 1276 | std::string str("cget -"); 1277 | str += name; 1278 | return Expr(str); 1279 | } 1280 | 1281 | CgetToken Tk::cget; 1282 | 1283 | Tk::details::ConfigureToken::ConfigureToken() : BasicToken("configure") {} 1284 | 1285 | Expr Tk::details::ConfigureToken::operator()() const 1286 | { 1287 | return Expr("configure"); 1288 | } 1289 | 1290 | ConfigureToken Tk::configure; 1291 | 1292 | Tk::details::CreateToken::CreateToken() : BasicToken("create") {} 1293 | 1294 | Expr Tk::details::CreateToken::operator()(std::string const &type, 1295 | int x, int y) const 1296 | { 1297 | std::string str("create "); 1298 | str += type; str += " "; 1299 | str += toString(x); str += " "; 1300 | str += toString(y); 1301 | return Expr(str); 1302 | } 1303 | 1304 | Expr Tk::details::CreateToken::operator()(std::string const &type, 1305 | Point const &p) const 1306 | { 1307 | return create(type, p.x, p.y); 1308 | } 1309 | 1310 | Expr Tk::details::CreateToken::operator()(std::string const &type, 1311 | int x1, int y1, int x2, int y2) const 1312 | { 1313 | std::string str("create "); 1314 | str += type; str += " "; 1315 | str += toString(x1); str += " "; 1316 | str += toString(y1); str += " "; 1317 | str += toString(x2); str += " "; 1318 | str += toString(y2); 1319 | return Expr(str); 1320 | } 1321 | 1322 | Expr Tk::details::CreateToken::operator()(std::string const &type, 1323 | Point const &p1, Point const &p2) const 1324 | { 1325 | return create(type, p1.x, p1.y, p2.x, p2.y); 1326 | } 1327 | 1328 | Expr Tk::details::CreateToken::operator()(std::string const &type, 1329 | Box const &b) const 1330 | { 1331 | return create(type, b.x1, b.y1, b.x2, b.y2); 1332 | } 1333 | 1334 | CreateToken Tk::create; 1335 | 1336 | Tk::details::FocusToken::FocusToken() : BasicToken("focus") {} 1337 | 1338 | Expr Tk::details::FocusToken::operator()(std::string const &name) const 1339 | { 1340 | std::string str("focus"); 1341 | if (name.empty()) 1342 | { 1343 | return Expr(str); 1344 | } 1345 | else 1346 | { 1347 | str += " "; str += name; 1348 | return Expr(str); 1349 | } 1350 | } 1351 | 1352 | FocusToken Tk::focus; 1353 | 1354 | Tk::details::ForgetToken::ForgetToken() : BasicToken("forget") {} 1355 | 1356 | Expr Tk::details::ForgetToken::operator()(std::string const &name) const 1357 | { 1358 | std::string str("forget "); 1359 | str += name; 1360 | return Expr(str); 1361 | } 1362 | 1363 | ForgetToken Tk::forget; 1364 | 1365 | Tk::details::GetToken::GetToken() : BasicToken("get") {} 1366 | 1367 | Expr Tk::details::GetToken::operator()() const 1368 | { 1369 | return Expr("get"); 1370 | } 1371 | 1372 | GetToken Tk::get; 1373 | 1374 | Tk::details::MoveToToken::MoveToToken() : BasicToken("moveto") {} 1375 | 1376 | Expr Tk::details::MoveToToken::operator()(double fraction) const 1377 | { 1378 | std::string str("moveto "); 1379 | str += toString(fraction); 1380 | return Expr(str); 1381 | } 1382 | 1383 | MoveToToken Tk::moveto; 1384 | 1385 | Tk::details::ScrollToken::ScrollToken() : BasicToken("scroll") {} 1386 | 1387 | Expr Tk::details::ScrollToken::operator()(int n, std::string const &what) const 1388 | { 1389 | std::string str("scroll "); 1390 | str += toString(n); str += " "; 1391 | str += what; 1392 | return Expr(str); 1393 | } 1394 | 1395 | ScrollToken Tk::scroll; 1396 | 1397 | Tk::details::SetToken::SetToken() : BasicToken("set") {} 1398 | 1399 | Expr Tk::details::SetToken::operator()() const 1400 | { 1401 | return Expr("set"); 1402 | } 1403 | 1404 | Expr Tk::details::SetToken::operator()(double first, double last) const 1405 | { 1406 | std::string str("set "); 1407 | str += toString(first); str += " "; 1408 | str += toString(last); 1409 | return Expr(str); 1410 | } 1411 | 1412 | SetToken Tk::set; 1413 | 1414 | Tk::details::TypeToken::TypeToken() : BasicToken("type") {} 1415 | 1416 | TypeToken Tk::type; 1417 | 1418 | Tk::details::ValidateToken::ValidateToken() : BasicToken("validate") {} 1419 | 1420 | Expr Tk::details::ValidateToken::operator()() const 1421 | { 1422 | return Expr("validate"); 1423 | } 1424 | 1425 | Expr Tk::details::ValidateToken::operator()(std::string const &when) const 1426 | { 1427 | std::string str(" -validate "); 1428 | str += when; 1429 | return Expr(str, false); 1430 | } 1431 | 1432 | ValidateToken Tk::validate; 1433 | 1434 | Tk::details::AllToken::AllToken() : BasicToken("all") {} 1435 | 1436 | Expr Tk::details::AllToken::operator()() const 1437 | { 1438 | return Expr(" -all", false); 1439 | } 1440 | 1441 | AllToken Tk::all; 1442 | 1443 | Tk::details::CommandToken::CommandToken() : BasicToken("command") {} 1444 | 1445 | Expr Tk::details::CommandToken::operator()(std::string const &name) const 1446 | { 1447 | std::string str(" -command { "); 1448 | str += name; str += " }"; 1449 | return Expr(str, false); 1450 | } 1451 | 1452 | Expr Tk::details::CommandToken::operator()(CallbackHandle const &handle) const 1453 | { 1454 | std::string str(" -command { "); 1455 | str += handle.get(); str += " }"; 1456 | return Expr(str, false); 1457 | } 1458 | 1459 | CommandToken Tk::command; 1460 | 1461 | Tk::details::ElideToken::ElideToken() : BasicToken("elide") {} 1462 | 1463 | Expr Tk::details::ElideToken::operator()() const 1464 | { 1465 | return Expr(" -elide", false); 1466 | } 1467 | 1468 | Expr Tk::details::ElideToken::operator()(bool b) const 1469 | { 1470 | std::string str(" -elide "); 1471 | str += toString(b); 1472 | return Expr(str, false); 1473 | } 1474 | 1475 | ElideToken Tk::elide; 1476 | 1477 | Tk::details::FromToken::FromToken() : BasicToken("from") {} 1478 | 1479 | Expr Tk::details::FromToken::operator()(int val) const 1480 | { 1481 | std::string str(" -from "); 1482 | str += toString(val); 1483 | return Expr(str, false); 1484 | } 1485 | 1486 | Expr Tk::details::FromToken::operator()(int x1, int y1, int x2, int y2) const 1487 | { 1488 | std::string str(" -from "); 1489 | str += toString(x1); str += " "; 1490 | str += toString(y1); str += " "; 1491 | str += toString(x2); str += " "; 1492 | str += toString(y2); 1493 | return Expr(str, false); 1494 | } 1495 | 1496 | FromToken Tk::from; 1497 | 1498 | Tk::details::ImageToken::ImageToken() : BasicToken("image") {} 1499 | 1500 | Expr Tk::details::ImageToken::operator()() const 1501 | { 1502 | return Expr(" -image", false); 1503 | } 1504 | 1505 | Expr Tk::details::ImageToken::operator()(std::string const &name) const 1506 | { 1507 | std::string str(" -image "); 1508 | str += name; 1509 | return Expr(str, false); 1510 | } 1511 | 1512 | ImageToken Tk::image; 1513 | 1514 | Tk::details::MarkToken::MarkToken() : BasicToken("mark") {} 1515 | 1516 | Expr Tk::details::MarkToken::operator()() const 1517 | { 1518 | return Expr(" -mark", false); 1519 | } 1520 | 1521 | Expr Tk::details::MarkToken::operator()(std::string const &option, 1522 | std::string const &markname, std::string const &dir) const 1523 | { 1524 | std::string str("mark "); 1525 | str += option; 1526 | if (markname.empty()) 1527 | { 1528 | return Expr(str); 1529 | } 1530 | str += " "; 1531 | str += markname; 1532 | if (dir.empty()) 1533 | { 1534 | return Expr(str); 1535 | } 1536 | str += " "; 1537 | str += dir; 1538 | return Expr(str); 1539 | } 1540 | 1541 | MarkToken Tk::mark; 1542 | 1543 | Tk::details::MenuLabelToken::MenuLabelToken() : BasicToken("label") {} 1544 | 1545 | Expr Tk::details::MenuLabelToken::operator()(std::string const &label) const 1546 | { 1547 | std::string str(" -label \""); 1548 | str += label; str += '\"'; 1549 | return Expr(str, false); 1550 | } 1551 | 1552 | MenuLabelToken Tk::menulabel; 1553 | 1554 | Tk::details::TextToken::TextToken() : BasicToken("text") {} 1555 | 1556 | Expr Tk::details::TextToken::operator()() const 1557 | { 1558 | return Expr(" -text", false); 1559 | } 1560 | 1561 | Expr Tk::details::TextToken::operator()(std::string const &t) const 1562 | { 1563 | std::string str(" -text \""); 1564 | str += quote(t); str += '\"'; 1565 | return Expr(str, false); 1566 | } 1567 | 1568 | TextToken Tk::text; 1569 | 1570 | Tk::details::ToToken::ToToken() : BasicToken("to") {} 1571 | 1572 | Expr Tk::details::ToToken::operator()(int val) const 1573 | { 1574 | std::string str(" -to "); 1575 | str += toString(val); 1576 | return Expr(str, false); 1577 | } 1578 | 1579 | Expr Tk::details::ToToken::operator()(int x, int y) const 1580 | { 1581 | std::string str(" -to "); 1582 | str += toString(x); str += " "; 1583 | str += toString(y); 1584 | return Expr(str, false); 1585 | } 1586 | 1587 | Expr Tk::details::ToToken::operator()(int x1, int y1, int x2, int y2) const 1588 | { 1589 | std::string str(" -to "); 1590 | str += toString(x1); str += " "; 1591 | str += toString(y1); str += " "; 1592 | str += toString(x2); str += " "; 1593 | str += toString(y2); 1594 | return Expr(str, false); 1595 | } 1596 | 1597 | ToToken Tk::to; 1598 | 1599 | Tk::details::WindowToken::WindowToken() : BasicToken("window") {} 1600 | 1601 | Expr Tk::details::WindowToken::operator()(std::string const &name) const 1602 | { 1603 | std::string str(" -window"); 1604 | if (name.empty()) 1605 | { 1606 | return Expr(str, false); 1607 | } 1608 | str += " "; str += name; 1609 | return Expr(str, false); 1610 | } 1611 | 1612 | WindowToken Tk::window; 1613 | 1614 | Tk::details::WndClassToken::WndClassToken() : BasicToken("class") {} 1615 | 1616 | Expr Tk::details::WndClassToken::operator()(std::string const &name) const 1617 | { 1618 | std::string str(" -class "); 1619 | str += name; 1620 | return Expr(str, false); 1621 | } 1622 | 1623 | WndClassToken Tk::wndclass; 1624 | 1625 | Tk::details::AfterToken::AfterToken() : BasicToken("after") {} 1626 | 1627 | Expr Tk::details::AfterToken::operator()(int time) const 1628 | { 1629 | std::string str("after "); 1630 | str += toString(time); 1631 | return Expr(str); 1632 | } 1633 | 1634 | Expr Tk::details::AfterToken::operator()(std::string const &name) const 1635 | { 1636 | std::string str(" -after "); 1637 | str += name; 1638 | return Expr(str, false); 1639 | } 1640 | 1641 | Expr Tk::details::AfterToken::operator()(int time, std::string const &name) const 1642 | { 1643 | std::string str("after "); 1644 | str += toString(time); str += " "; 1645 | str += name; 1646 | return Expr(str); 1647 | } 1648 | 1649 | Expr Tk::details::AfterToken::operator()(std::string const &option, 1650 | std::string const &id) const 1651 | { 1652 | std::string str("after "); 1653 | str += option; str += " "; 1654 | str += id; 1655 | return Expr(str); 1656 | } 1657 | 1658 | AfterToken Tk::after; 1659 | 1660 | Tk::details::RGBToken::RGBToken() : BasicToken("rgb") {} 1661 | 1662 | std::string Tk::details::RGBToken::operator()(int r, int g, int b) const 1663 | { 1664 | if (r < 0) r = 0; 1665 | if (r > 255) r = 255; 1666 | if (g < 0) g = 0; 1667 | if (g > 255) g = 255; 1668 | if (b < 0) b = 0; 1669 | if (b > 255) b = 255; 1670 | std::ostringstream ss; 1671 | ss << '#' << std::setw(2) << std::setfill('0') << std::hex << r 1672 | << std::setw(2) << std::setfill('0') << std::hex << g 1673 | << std::setw(2) << std::setfill('0') << std::hex << b; 1674 | return ss.str(); 1675 | } 1676 | 1677 | RGBToken Tk::rgb; 1678 | 1679 | -------------------------------------------------------------------------------- /test/test.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2004-2006, Maciej Sobczak 3 | // 4 | // Permission to copy, use, modify, sell and distribute this software 5 | // is granted provided this copyright notice appears in all copies. 6 | // This software is provided "as is" without express or implied 7 | // warranty, and with no claim as to its suitability for any purpose. 8 | // 9 | 10 | #include "../cpptk.h" 11 | #include 12 | #include 13 | #include 14 | 15 | using namespace Tk; 16 | 17 | std::ostringstream ss; 18 | 19 | #define CHECK(expected) if (ss.str() != expected "\n") \ 20 | { \ 21 | std::cout << "in line : " << __LINE__ << "\n" \ 22 | << "expected: " << expected << '\n' \ 23 | << "was : " << ss.str(); \ 24 | assert(false); \ 25 | } \ 26 | else \ 27 | { \ 28 | ss.str(std::string()); \ 29 | } 30 | 31 | // various callbacks 32 | 33 | void cb0() {} 34 | void cb1(int) {} 35 | void cb2(std::string const &, int, int, int, int, 36 | std::string const &, std::string const &, 37 | std::string const &, int) {} 38 | void cb3(std::string const &, 39 | std::string const &, int, std::string const &, 40 | int, int, int, int) {} 41 | 42 | bool cbb0(std::string const &) { return true; } 43 | 44 | void commandsTest() 45 | { 46 | bell(); 47 | CHECK("bell");; 48 | 49 | bind(".f", ""); 50 | CHECK("bind .f {}"); 51 | bind(".f", "", cb0); 52 | CHECK("bind .f { CppTk::callback0 }"); 53 | bind(".f", "", cb1, event_x); 54 | CHECK("bind .f { CppTk::callback1 %x }"); 55 | bind(".f", "", cb2, event_A, event_b, event_D, 56 | event_f, event_h, event_k, event_K, event_m, event_N); 57 | CHECK("bind .f { CppTk::callback2 %A %b %D %f %h %k %K " 58 | "%m %N }"); 59 | bind(".f", "", cb3, event_s, event_T, event_w, event_W, 60 | event_x, event_y, event_X, event_Y); 61 | CHECK("bind .f { CppTk::callback3 %s %T %w %W %x %y %X %Y }"); 62 | 63 | bindtags(".w"); 64 | CHECK("bindtags .w"); 65 | bindtags(".b1", "all . Button b1"); 66 | CHECK("bindtags .b1 { all . Button b1 }"); 67 | 68 | button(".b"); 69 | CHECK("button .b"); 70 | button(".b") -text("Hello"); 71 | CHECK("button .b -text \"Hello\""); 72 | 73 | canvas(".c"); 74 | CHECK("canvas .c"); 75 | 76 | checkbutton(".cb") -text("check me"); 77 | CHECK("checkbutton .cb -text \"check me\""); 78 | 79 | clipboard(clear); 80 | CHECK("clipboard clear"); 81 | clipboard(clear) -displayof(".top"); 82 | CHECK("clipboard clear -displayof .top"); 83 | clipboard(append, "ala ma kota") -format("STRING") -cliptype("STRING"); 84 | CHECK("clipboard append -format STRING -type STRING -- \"ala ma kota\""); 85 | clipboard(get); 86 | CHECK("clipboard get"); 87 | 88 | destroy(".b"); 89 | CHECK("destroy .b"); 90 | 91 | entry(".e"); 92 | CHECK("entry .e"); 93 | 94 | focus() -displayof("."); 95 | CHECK("focus -displayof ."); 96 | focus(".e"); 97 | CHECK("focus .e"); 98 | focus() -force(".e"); 99 | CHECK("focus -force .e"); 100 | focus() -lastfor("."); 101 | CHECK("focus -lastfor ."); 102 | 103 | fonts(create, "myfont"); 104 | CHECK("font create myfont"); 105 | fonts(configure, "myfont") -size(20) -underline(true); 106 | CHECK("font configure myfont -size 20 -underline 1"); 107 | fonts(deletefont, "myfont"); 108 | CHECK("font delete myfont"); 109 | fonts(families); 110 | CHECK("font families"); 111 | 112 | frame(".f") -wndclass("myclass") -colormap("new") -container(true); 113 | CHECK("frame .f -class myclass -colormap new -container 1"); 114 | 115 | grab(current); 116 | CHECK("grab current"); 117 | grab(current, ".f"); 118 | CHECK("grab current .f"); 119 | grab(release, ".f"); 120 | CHECK("grab release .f"); 121 | grab(set, ".f"); 122 | CHECK("grab set .f"); 123 | grab(setglobal, ".f"); 124 | CHECK("grab set -global .f"); 125 | grab(status, ".f"); 126 | CHECK("grab status .f"); 127 | 128 | grid(bbox, "."); 129 | CHECK("grid bbox ."); 130 | grid(bbox, ".", 2, 3); 131 | CHECK("grid bbox . 2 3"); 132 | grid(bbox, ".", 2, 3, 4, 5); 133 | CHECK("grid bbox . 2 3 4 5"); 134 | grid(columnconfigure, ".", 3) -minsize(5) -weight(2) -uniform("abc") 135 | -pad(5); 136 | CHECK("grid columnconfigure . 3 -minsize 5 -weight 2 -uniform abc" 137 | " -pad 5"); 138 | grid(configure, ".b") -column(3) -columnspan(2) -in(".") -row(2) 139 | -rowspan(2) -sticky("ne"); 140 | CHECK("grid configure .b -column 3 -columnspan 2 -in . -row 2" 141 | " -rowspan 2 -sticky ne"); 142 | grid(forget, ".e"); 143 | CHECK("grid forget .e"); 144 | grid(info, ".e"); 145 | CHECK("grid info .e"); 146 | grid(location, ".e", 25, 30); 147 | CHECK("grid location .e 25 30"); 148 | grid(propagate, "."); 149 | CHECK("grid propagate ."); 150 | grid(propagate, ".", false); 151 | CHECK("grid propagate . 0"); 152 | grid(rowconfigure, ".", 3) -minsize(5) -weight(2) -uniform("abc") 153 | -pad(5); 154 | CHECK("grid rowconfigure . 3 -minsize 5 -weight 2 -uniform abc -pad 5"); 155 | grid(Tk::remove, ".e"); 156 | CHECK("grid remove .e"); 157 | grid(size, "."); 158 | CHECK("grid size ."); 159 | grid(slaves, ".") -row(3) -column(4); 160 | CHECK("grid slaves . -row 3 -column 4"); 161 | 162 | images(create, bitmap); 163 | CHECK("image create bitmap"); 164 | images(create, photo) -Tk::gamma(1.5) -palette(10); 165 | CHECK("image create photo -gamma 1.5 -palette 10"); 166 | images(create, photo, "myimg") -file("myimg.jpg"); 167 | CHECK("image create photo myimg -file \"myimg.jpg\""); 168 | images(deleteimg, "myimg"); 169 | CHECK("image delete myimg"); 170 | images(height, "myimg"); 171 | CHECK("image height myimg"); 172 | images(inuse, "myimg"); 173 | CHECK("image inuse myimg"); 174 | images(names); 175 | CHECK("image names"); 176 | images(type, "myimg"); 177 | CHECK("image type myimg"); 178 | images(types); 179 | CHECK("image types"); 180 | images(width, "myimg"); 181 | CHECK("image width myimg"); 182 | 183 | label(".l"); 184 | CHECK("label .l"); 185 | 186 | labelframe(".lf") -labelanchor(nw) -labelwidget(".lf.w"); 187 | CHECK("labelframe .lf -labelanchor nw -labelwidget .lf.w"); 188 | 189 | listbox(".lb") -setgrid(true) -activestyle(underline) 190 | -selectmode(browse); 191 | CHECK("listbox .lb -setgrid 1 -activestyle underline" 192 | " -selectmode browse"); 193 | 194 | lower(".e"); 195 | CHECK("lower .e"); 196 | lower(".e", ".f"); 197 | CHECK("lower .e .f"); 198 | 199 | menu(".m") -activeborderwidth(3) -postcommand(cb0) -tearoff(true) 200 | -title("My title"); 201 | CHECK("menu .m -activeborderwidth 3 -postcommand CppTk::callback4" 202 | " -tearoff 1 -title \"My title\""); 203 | 204 | menubutton(".mb") -direction(above); 205 | CHECK("menubutton .mb -direction above"); 206 | 207 | message(".msg") -aspect(200); 208 | CHECK("message .msg -aspect 200"); 209 | 210 | option(add, "abc", "def"); 211 | CHECK("option add \"abc\" \"def\""); 212 | option(add, "abc", "def", interactive); 213 | CHECK("option add \"abc\" \"def\" interactive"); 214 | option(clear); 215 | CHECK("option clear"); 216 | option(get, ".w", "abc", "def"); 217 | CHECK("option get \".w\" \"abc\" def"); 218 | option(readfile, "file"); 219 | CHECK("option readfile \"file\""); 220 | 221 | pack(".b") -expand(true) -fill(x) -fill(both) -in(".f") -side(left); 222 | CHECK("pack .b -expand 1 -fill x -fill both -in .f -side left"); 223 | pack(".b1", ".b2", ".b3"); 224 | CHECK("pack .b1 .b2 .b3"); 225 | pack(configure, ".b1") -after(".b2") -before(".b3"); 226 | CHECK("pack configure .b1 -after .b2 -before .b3"); 227 | pack(forget, ".b"); 228 | CHECK("pack forget .b"); 229 | pack(info, ".b"); 230 | CHECK("pack info .b"); 231 | pack(propagate, ".f"); 232 | CHECK("pack propagate .f"); 233 | pack(propagate, ".f", true); 234 | CHECK("pack propagate .f 1"); 235 | pack(slaves, ".f"); 236 | CHECK("pack slaves .f"); 237 | 238 | panedwindow(".pw") -orient(horizontal); 239 | CHECK("panedwindow .pw -orient horizontal"); 240 | panedwindow(".pw") -orient(vertical) -handlepad(50) -handlesize(10) 241 | -opaqueresize(true) -sashcursor("mycursor") -sashpad(5) 242 | -sashrelief(raised) -sashwidth(10) -showhandle(true); 243 | CHECK("panedwindow .pw -orient vertical -handlepad 50 -handlesize 10" 244 | " -opaqueresize 1 -sashcursor mycursor -sashpad 5" 245 | " -sashrelief raised -sashwidth 10 -showhandle 1"); 246 | 247 | place(".b") -bordermode(inside) -x(10) -y(30); 248 | CHECK("place .b -bordermode inside -x 10 -y 30"); 249 | // FIXME Floating Point Imprecision 250 | // place(configure, ".b") -relx(5) -rely(6) -relheight(0.5) -relwidth(0.6); 251 | // CHECK("place configure .b -relx 5 -rely 6 -relheight 0.5 -relwidth 0.6"); 252 | place(forget, ".b"); 253 | CHECK("place forget .b"); 254 | place(info, ".b"); 255 | CHECK("place info .b"); 256 | place(slaves, ".f"); 257 | CHECK("place slaves .f"); 258 | 259 | radiobutton(".rb"); 260 | CHECK("radiobutton .rb"); 261 | 262 | raise(".b"); 263 | CHECK("raise .b"); 264 | raise(".b", ".f"); 265 | CHECK("raise .b .f"); 266 | 267 | scale(".s") -troughcolor("blue") -bigincrement(10) -digits(3) -from(5) 268 | -to(500) -length(100) -resolution(10) -showvalue(true) 269 | -sliderlength(100) -sliderrelief(raised) -tickinterval(20); 270 | CHECK("scale .s -troughcolor blue -bigincrement 10 -digits 3 -from 5" 271 | " -to 500 -length 100 -resolution 10 -showvalue 1" 272 | " -sliderlength 100 -sliderrelief raised -tickinterval 20"); 273 | 274 | scrollbar(".sb") -jump(true) -activerelief(raised) 275 | -elementborderwidth(5); 276 | CHECK("scrollbar .sb -jump 1 -activerelief raised" 277 | " -elementborderwidth 5"); 278 | 279 | selection(clear) -displayof(".w") -sel("PRIMARY"); 280 | CHECK("selection clear -displayof .w -sel PRIMARY"); 281 | selection(get) -cliptype("STRING"); 282 | CHECK("selection get -type STRING"); 283 | 284 | // FIXME Floating Point Imprecision 285 | // spinbox(".sp") -buttonbackground("blue") -buttoncursor("mycursor") 286 | // -buttondownrelief(sunken) -buttonuprelief(raised) -format("%0.3f") 287 | // -from(0) -to(10) -increment(0.1) -values("a b c d") -wrap(true); 288 | // CHECK("spinbox .sp -buttonbackground blue -buttoncursor mycursor" 289 | // " -buttondownrelief sunken -buttonuprelief raised -format %0.3f" 290 | // " -from 0 -to 10 -increment 0.1 -values \"a b c d\" -wrap 1"); 291 | 292 | textw(".t") -autoseparators(true) -maxundo(100) -spacing1(5) -spacing2(6) 293 | -spacing3(7) -tabs("2c left 4c 6c center") -undo(true) 294 | -wrap(wrapchar); 295 | CHECK("text .t -autoseparators 1 -maxundo 100 -spacing1 5 -spacing2 6" 296 | " -spacing3 7 -tabs \"2c left 4c 6c center\" -undo 1 -wrap char"); 297 | 298 | tk_chooseColor() -initialcolor("blue") -parent(".") 299 | -title("select color"); 300 | CHECK("tk_chooseColor -initialcolor blue -parent ." 301 | " -title \"select color\""); 302 | 303 | tk_chooseDirectory() -initialdir("/usr/home") -mustexist(true); 304 | CHECK("tk_chooseDirectory -initialdir \"/usr/home\" -mustexist 1"); 305 | 306 | tk_dialog(".d", "some title", "some text", warning, "OK", "OK", 307 | "Cancel"); 308 | CHECK("tk_dialog .d \"some title\" \"some text\" warning \"OK\" \"OK\"" 309 | " \"Cancel\""); 310 | 311 | tk_focusNext(".b"); 312 | CHECK("tk_focusNext .b"); 313 | tk_focusPrev(".b"); 314 | CHECK("tk_focusPrev .b"); 315 | 316 | tk_getOpenFile() -defaultextension(".txt") 317 | -filetypes("{{Text files} {.txt}}") -initialfile("file.txt") 318 | -multiple(); 319 | CHECK("tk_getOpenFile -defaultextension \".txt\"" 320 | " -filetypes {{{Text files} {.txt}}} -initialfile \"file.txt\"" 321 | " -multiple"); 322 | 323 | tk_getSaveFile(); 324 | CHECK("tk_getSaveFile"); 325 | 326 | tk_menuSetFocus(".m"); 327 | CHECK("tk_menuSetFocus .m"); 328 | 329 | tk_messageBox() -defaultbutton("OK") -icon(question) 330 | -messagetext("some text") -messagetype(yesnocancel); 331 | CHECK("tk_messageBox -default \"OK\" -icon question" 332 | " -message \"some text\" -type yesnocancel"); 333 | 334 | std::vector values; 335 | values.push_back("ala"); 336 | values.push_back("ma"); 337 | values.push_back("kota"); 338 | std::string menuVal; 339 | tk_optionMenu(".m", menuVal, values.begin(), values.end()); 340 | CHECK("tk_optionMenu .m CppTk::variable0 \"ala\" \"ma\" \"kota\""); 341 | 342 | tk_popup(".m", 50, 60); 343 | CHECK("tk_popup .m 50 60"); 344 | tk_popup(".m", 50, 60, 3); 345 | CHECK("tk_popup .m 50 60 3"); 346 | 347 | tk_setPalette("blue"); 348 | CHECK("tk_setPalette blue"); 349 | 350 | tk_textCopy(".t"); 351 | CHECK("tk_textCopy .t") 352 | tk_textCut(".t"); 353 | CHECK("tk_textCut .t") 354 | tk_textPaste(".t"); 355 | CHECK("tk_textPaste .t") 356 | 357 | tkwait(visibility, ".w"); 358 | CHECK("tkwait visibility .w"); 359 | tkwait(window, ".w"); 360 | CHECK("tkwait window .w"); 361 | 362 | toplevel(".w") -screen("scr") -use("1234"); 363 | CHECK("toplevel .w -screen \"scr\" -use 1234"); 364 | 365 | winfo(atom, "name"); 366 | CHECK("winfo atom name"); 367 | winfo(atom, "name") -displayof(".w"); 368 | CHECK("winfo atom -displayof .w name"); 369 | winfo(atomname, "id"); 370 | CHECK("winfo atomname id"); 371 | winfo(cells, "name"); 372 | CHECK("winfo cells name"); 373 | winfo(children, "name"); 374 | CHECK("winfo children name"); 375 | winfo(wndclass, "name"); 376 | CHECK("winfo class name"); 377 | winfo(colormapfull, "name"); 378 | CHECK("winfo colormapfull name"); 379 | winfo(containing, 100, 200); 380 | CHECK("winfo containing 100 200"); 381 | winfo(depth, "name"); 382 | CHECK("winfo depth name"); 383 | winfo(exists, "name"); 384 | CHECK("winfo exists name"); 385 | winfo(fpixels, "name", 100); 386 | CHECK("winfo fpixels name 100"); 387 | winfo(geometry, "name"); 388 | CHECK("winfo geometry name"); 389 | winfo(height, "name"); 390 | CHECK("winfo height name"); 391 | winfo(id, "name"); 392 | CHECK("winfo id name"); 393 | winfo(ismapped, "name"); 394 | CHECK("winfo ismapped name"); 395 | winfo(manager, "name"); 396 | CHECK("winfo manager name"); 397 | winfo(name, "name"); 398 | CHECK("winfo name name"); 399 | winfo(parent, "name"); 400 | CHECK("winfo parent name"); 401 | winfo(pathname, "name"); 402 | CHECK("winfo pathname name"); 403 | winfo(pixels, "name", 100); 404 | CHECK("winfo pixels name 100"); 405 | winfo(pointerx, "name"); 406 | CHECK("winfo pointerx name"); 407 | winfo(pointerxy, "name"); 408 | CHECK("winfo pointerxy name"); 409 | winfo(pointery, "name"); 410 | CHECK("winfo pointery name"); 411 | winfo(regheight, "name"); 412 | CHECK("winfo regheight name"); 413 | winfo(regwidth, "name"); 414 | CHECK("winfo regwidth name"); 415 | winfo(rgb, "name", "blue"); 416 | CHECK("winfo rgb name blue"); 417 | winfo(rootx, "name"); 418 | CHECK("winfo rootx name"); 419 | winfo(rooty, "name"); 420 | CHECK("winfo rooty name"); 421 | winfo(screen, "name"); 422 | CHECK("winfo screen name"); 423 | winfo(screencells, "name"); 424 | CHECK("winfo screencells name"); 425 | winfo(screendepth, "name"); 426 | CHECK("winfo screendepth name"); 427 | winfo(screenheight, "name"); 428 | CHECK("winfo screenheight name"); 429 | winfo(screenmmheight, "name"); 430 | CHECK("winfo screenmmheight name"); 431 | winfo(screenmmwidth, "name"); 432 | CHECK("winfo screenmmwidth name"); 433 | winfo(screenvisual, "name"); 434 | CHECK("winfo screenvisual name"); 435 | winfo(screenwidth, "name"); 436 | CHECK("winfo screenwidth name"); 437 | winfo(server, "name"); 438 | CHECK("winfo server name"); 439 | winfo(toplevel, "name"); 440 | CHECK("winfo toplevel name"); 441 | winfo(viewable, "name"); 442 | CHECK("winfo viewable name"); 443 | winfo(visual, "name"); 444 | CHECK("winfo visual name"); 445 | winfo(visualid, "name"); 446 | CHECK("winfo visualid name"); 447 | winfo(visualsavailable, "name"); 448 | CHECK("winfo visualsavailable name"); 449 | winfo(vrootheight, "name"); 450 | CHECK("winfo vrootheight name"); 451 | winfo(vrootwidth, "name"); 452 | CHECK("winfo vrootwidth name"); 453 | winfo(vrootx, "name"); 454 | CHECK("winfo vrootx name"); 455 | winfo(vrooty, "name"); 456 | CHECK("winfo vrooty name"); 457 | winfo(width, "name"); 458 | CHECK("winfo width name"); 459 | winfo(x, "name"); 460 | CHECK("winfo x name"); 461 | winfo(y, "name"); 462 | CHECK("winfo y name"); 463 | 464 | wm(aspect, ".w"); 465 | CHECK("wm aspect .w"); 466 | wm(aspect, ".w", 10, 20, 30, 40); 467 | CHECK("wm aspect .w \"10\" \"20\" \"30\" \"40\""); 468 | wm(aspect, ".w", "", "", "", ""); 469 | CHECK("wm aspect .w \"\" \"\" \"\" \"\""); 470 | wm(client, ".w"); 471 | CHECK("wm client .w"); 472 | wm(client, ".w", "name"); 473 | CHECK("wm client .w \"name\""); 474 | wm(deiconify, ".w"); 475 | CHECK("wm deiconify .w"); 476 | wm(focusmodel, ".w"); 477 | CHECK("wm focusmodel .w"); 478 | wm(focusmodel, ".w", active); 479 | CHECK("wm focusmodel .w \"active\""); 480 | wm(focusmodel, ".w", passive); 481 | CHECK("wm focusmodel .w \"passive\""); 482 | wm(frame, ".w"); 483 | CHECK("wm frame .w"); 484 | wm(geometry, ".w"); 485 | CHECK("wm geometry .w"); 486 | wm(geometry, ".w", "=100x200+50+60"); 487 | CHECK("wm geometry .w \"=100x200+50+60\""); 488 | wm(grid, ".w"); 489 | CHECK("wm grid .w"); 490 | wm(grid, ".w", 10, 20, 30, 40); 491 | CHECK("wm grid .w \"10\" \"20\" \"30\" \"40\""); 492 | wm(group, ".w"); 493 | CHECK("wm group .w"); 494 | wm(group, ".w", ".w2"); 495 | CHECK("wm group .w \".w2\""); 496 | wm(group, ".w", ""); 497 | CHECK("wm group .w \"\""); 498 | wm(iconbitmap, ".w"); 499 | CHECK("wm iconbitmap .w"); 500 | wm(iconbitmap, ".w", "mybitmap"); 501 | CHECK("wm iconbitmap .w \"mybitmap\""); 502 | wm(iconify, ".w"); 503 | CHECK("wm iconify .w"); 504 | wm(iconmask, ".w"); 505 | CHECK("wm iconmask .w"); 506 | wm(iconmask, ".w", "mybitmap"); 507 | CHECK("wm iconmask .w \"mybitmap\""); 508 | wm(iconname, ".w"); 509 | CHECK("wm iconname .w"); 510 | wm(iconname, ".w", "myicon"); 511 | CHECK("wm iconname .w \"myicon\""); 512 | wm(iconposition, ".w"); 513 | CHECK("wm iconposition .w"); 514 | wm(iconposition, ".w", 50, 60); 515 | CHECK("wm iconposition .w \"50\" \"60\""); 516 | wm(iconwindow, ".w"); 517 | CHECK("wm iconwindow .w"); 518 | wm(iconwindow, ".w", ".i"); 519 | CHECK("wm iconwindow .w \".i\""); 520 | wm(maxsize, ".w"); 521 | CHECK("wm maxsize .w"); 522 | wm(maxsize, ".w", 200, 300); 523 | CHECK("wm maxsize .w \"200\" \"300\""); 524 | wm(minsize, ".w"); 525 | CHECK("wm minsize .w"); 526 | wm(minsize, ".w", 200, 300); 527 | CHECK("wm minsize .w \"200\" \"300\""); 528 | wm(overrideredirect, ".w"); 529 | CHECK("wm overrideredirect .w"); 530 | wm(overrideredirect, ".w", true); 531 | CHECK("wm overrideredirect .w \"1\""); 532 | wm(positionfrom, ".w"); 533 | CHECK("wm positionfrom .w"); 534 | wm(positionfrom, ".w", program); 535 | CHECK("wm positionfrom .w \"program\""); 536 | wm(positionfrom, ".w", user); 537 | CHECK("wm positionfrom .w \"user\""); 538 | wm(resizable, ".w"); 539 | CHECK("wm resizable .w"); 540 | wm(resizable, ".w", false, false); 541 | CHECK("wm resizable .w \"0\" \"0\""); 542 | wm(sizefrom, ".w"); 543 | CHECK("wm sizefrom .w"); 544 | wm(sizefrom, ".w", program); 545 | CHECK("wm sizefrom .w \"program\""); 546 | wm(sizefrom, ".w", user); 547 | CHECK("wm sizefrom .w \"user\""); 548 | wm(stackorder, ".w1"); 549 | CHECK("wm stackorder .w1"); 550 | wm(stackorder, ".w1", isabove, ".w2"); 551 | CHECK("wm stackorder .w1 \"isabove\" \".w2\""); 552 | wm(stackorder, ".w1", isbelow, ".w2"); 553 | CHECK("wm stackorder .w1 \"isbelow\" \".w2\""); 554 | wm(state, ".w"); 555 | CHECK("wm state .w"); 556 | wm(state, ".w", normal); 557 | CHECK("wm state .w \"normal\""); 558 | wm(state, ".w", iconic); 559 | CHECK("wm state .w \"iconic\""); 560 | wm(state, ".w", withdrawn); 561 | CHECK("wm state .w \"withdrawn\""); 562 | wm(state, ".w", icon); 563 | CHECK("wm state .w \"icon\""); 564 | wm(state, ".w", zoomed); 565 | CHECK("wm state .w \"zoomed\""); 566 | wm(title, ".w"); 567 | CHECK("wm title .w"); 568 | wm(title, ".w", "some title"); 569 | CHECK("wm title .w \"some title\""); 570 | wm(transient, ".w"); 571 | CHECK("wm transient .w"); 572 | wm(transient, ".w", ".w1"); 573 | CHECK("wm transient .w \".w1\""); 574 | wm(withdraw, ".w"); 575 | CHECK("wm withdraw .w"); 576 | 577 | wmprotocol(".w"); 578 | CHECK("wm protocol .w"); 579 | wmprotocol(".w", "WM_DELETE_WINDOW"); 580 | CHECK("wm protocol .w WM_DELETE_WINDOW"); 581 | wmprotocol(".w", "WM_DELETE_WINDOW", cb0); 582 | CHECK("wm protocol .w WM_DELETE_WINDOW { CppTk::callback5 }"); 583 | 584 | 585 | std::cout << "commands test OK\n"; 586 | } 587 | 588 | void widgetCommandsTest() 589 | { 590 | ".lb" << activate(5); 591 | CHECK(".lb activate 5"); 592 | ".sb" << activate(arrow1); 593 | CHECK(".sb activate arrow1"); 594 | 595 | ".m" << add(cascade) -submenu(".m.m"); 596 | CHECK(".m add cascade -menu .m.m"); 597 | ".m" << add(checkbutton) -hidemargin(true); 598 | CHECK(".m add checkbutton -hidemargin 1"); 599 | ".m" << add(command) -accelerator("Ctrl-x") -menulabel("select me"); 600 | CHECK(".m add command -accelerator \"Ctrl-x\" -label \"select me\""); 601 | ".m" << add(radiobutton) -columnbreak(true) -value(5); 602 | CHECK(".m add radiobutton -columnbreak 1 -value \"5\""); 603 | ".m" << add(separator); 604 | CHECK(".m add separator"); 605 | ".pw" << add(".b"); 606 | CHECK(".pw add .b"); 607 | 608 | ".c" << addtag("mytag", above, "item"); 609 | CHECK(".c addtag mytag above item"); 610 | ".c" << addtag("mytag", all); 611 | CHECK(".c addtag mytag all"); 612 | ".c" << addtag("mytag", below, "item"); 613 | CHECK(".c addtag mytag below item"); 614 | ".c" << addtag("mytag", closest, 10, 20); 615 | CHECK(".c addtag mytag closest 10 20"); 616 | ".c" << addtag("mytag", closest, 10, 20, 5); 617 | CHECK(".c addtag mytag closest 10 20 5"); 618 | ".c" << addtag("mytag", closest, 10, 20, 5, "item"); 619 | CHECK(".c addtag mytag closest 10 20 5 item"); 620 | ".c" << addtag("mytag", enclosed, 10, 20, 30, 40); 621 | CHECK(".c addtag mytag enclosed 10 20 30 40"); 622 | ".c" << addtag("mytag", overlapping, 10, 20, 30, 40); 623 | CHECK(".c addtag mytag overlapping 10 20 30 40"); 624 | ".c" << addtag("mytag", withtag, "item"); 625 | CHECK(".c addtag mytag withtag item"); 626 | 627 | ".c" << bbox("item"); 628 | CHECK(".c bbox item"); 629 | ".e" << bbox(5); 630 | CHECK(".e bbox 5"); 631 | ".e" << bbox(at(25)); 632 | CHECK(".e bbox @25"); 633 | 634 | std::vector items; 635 | items.push_back("item1"); 636 | items.push_back("item2"); 637 | items.push_back("item3"); 638 | ".c" << bbox(items.begin(), items.end()); 639 | CHECK(".c bbox item1 item2 item3"); 640 | 641 | ".c" << bind("item", ""); 642 | CHECK(".c bind item {}"); 643 | 644 | "myphoto" << blank(); 645 | CHECK("myphoto blank"); 646 | 647 | ".c" << canvasx(20); 648 | CHECK(".c canvasx 20"); 649 | ".c" << canvasx(20, 5); 650 | CHECK(".c canvasx 20 5"); 651 | 652 | ".c" << canvasy(20); 653 | CHECK(".c canvasy 20"); 654 | ".c" << canvasy(20, 5); 655 | CHECK(".c canvasy 20 5"); 656 | 657 | ".b" << cget(text); 658 | CHECK(".b cget -text"); 659 | 660 | ".m" << clone(".m2"); 661 | CHECK(".m clone .m2"); 662 | ".m" << clone(".m2", tearoff); 663 | CHECK(".m clone .m2 tearoff"); 664 | 665 | ".t" << compare(txt(5,6), "<", txt(6,5)); 666 | CHECK(".t compare 5.6 < 6.5"); 667 | 668 | ".b" << configure() -text("Hello") -height(10); 669 | CHECK(".b configure -text \"Hello\" -height 10"); 670 | 671 | ".c" << coords("item"); 672 | CHECK(".c coords item"); 673 | ".c" << coords("item", 10, 20); 674 | CHECK(".c coords item 10 20"); 675 | ".c" << coords("item", Point(10, 20)); 676 | CHECK(".c coords item 10 20"); 677 | ".c" << coords("item", 10, 20, 30, 40); 678 | CHECK(".c coords item 10 20 30 40"); 679 | ".c" << coords("item", Point(10, 20), Point(30, 40)); 680 | CHECK(".c coords item 10 20 30 40"); 681 | ".c" << coords("item", Box(10, 20, 30, 40)); 682 | CHECK(".c coords item 10 20 30 40"); 683 | std::vector crds; 684 | crds.push_back(10); 685 | crds.push_back(20); 686 | crds.push_back(30); 687 | crds.push_back(40); 688 | ".c" << coords("item", crds.begin(), crds.end()); 689 | CHECK(".c coords item 10 20 30 40"); 690 | ".s" << coords(); 691 | CHECK(".s coords"); 692 | ".s" << coords(150); 693 | CHECK(".s coords 150"); 694 | 695 | "photo1" << copy("photo2") -from(10, 20, 30, 40) -to(10, 20, 30, 40) 696 | -shrink() -zoom(2, 3) -subsample(3, 4) -compositingrule(overlay); 697 | CHECK("photo1 copy photo2 -from 10 20 30 40 -to 10 20 30 40" 698 | " -shrink -zoom 2 3 -subsample 3 4 -compositingrule overlay"); 699 | 700 | ".c" << create(text, 10, 20); 701 | CHECK(".c create text 10 20"); 702 | ".c" << create(text, Point(10, 20)); 703 | CHECK(".c create text 10 20"); 704 | ".c" << create(rectangle, 10, 20, 30, 40); 705 | CHECK(".c create rectangle 10 20 30 40"); 706 | ".c" << create(rectangle, Point(10, 20), Point(30, 40)); 707 | CHECK(".c create rectangle 10 20 30 40"); 708 | ".c" << create(rectangle, Box(10, 20, 30, 40)); 709 | CHECK(".c create rectangle 10 20 30 40"); 710 | ".c" << create(line, crds.begin(), crds.end()); 711 | CHECK(".c create line 10 20 30 40"); 712 | 713 | ".lb" << curselection(); 714 | CHECK(".lb curselection"); 715 | 716 | ".c" << dchars("item", 5); 717 | CHECK(".c dchars item 5"); 718 | ".c" << dchars("item", 5, 7); 719 | CHECK(".c dchars item 5 7"); 720 | ".c" << dchars("item", at(5, 6)); 721 | CHECK(".c dchars item @5,6"); 722 | 723 | ".t" << debug(); 724 | CHECK(".t debug"); 725 | ".t" << debug(true); 726 | CHECK(".t debug 1"); 727 | 728 | ".m" << deleteentry(5); 729 | CHECK(".m delete 5"); 730 | ".m" << deleteentry(5, 8); 731 | CHECK(".m delete 5 8"); 732 | 733 | ".lb" << deleteitem(5); 734 | CHECK(".lb delete 5"); 735 | ".c" << deleteitem("item"); 736 | CHECK(".c delete item"); 737 | ".c" << deleteitem(items.begin(), items.end()); 738 | CHECK(".c delete item1 item2 item3"); 739 | 740 | ".e" << deletetext(5); 741 | CHECK(".e delete 5"); 742 | ".e" << deletetext(5, end); 743 | CHECK(".e delete 5 end"); 744 | 745 | ".sb" << delta(50, 60); 746 | CHECK(".sb delta 50 60"); 747 | 748 | ".cb" << deselect(); 749 | CHECK(".cb deselect"); 750 | 751 | ".t" << dlineinfo(txt(5,6)); 752 | CHECK(".t dlineinfo 5.6"); 753 | 754 | ".c" << dtag("mytag"); 755 | CHECK(".c dtag mytag"); 756 | ".c" << dtag("mytag", "myothertag"); 757 | CHECK(".c dtag mytag myothertag"); 758 | 759 | ".t" << dump(txt(5,6)) -all() -image() -mark() -tags() -text() -window(); 760 | CHECK(".t dump -all -image -mark -tag -text -window 5.6"); 761 | ".t" << dump(txt(5,6), txt(7,end)) -all(); 762 | CHECK(".t dump -all 5.6 7.end"); 763 | 764 | ".t" << edit(modified); 765 | CHECK(".t edit modified"); 766 | ".t" << edit(modified, false); 767 | CHECK(".t edit modified 0"); 768 | ".t" << edit(redo); 769 | CHECK(".t edit redo"); 770 | ".t" << edit(reset); 771 | CHECK(".t edit reset"); 772 | ".t" << edit(separator); 773 | CHECK(".t edit separator"); 774 | ".t" << edit(undo); 775 | CHECK(".t edit undo"); 776 | 777 | ".m" << entrycget(5, foreground); 778 | CHECK(".m entrycget 5 -foreground"); 779 | ".m" << entrycget(5, menulabel); 780 | CHECK(".m entrycget 5 -label"); 781 | 782 | ".m" << entryconfigure(5) -menulabel("select me"); 783 | CHECK(".m entryconfigure 5 -label \"select me\""); 784 | 785 | ".c" << find(above, "item"); 786 | CHECK(".c find above item"); 787 | ".c" << find(all); 788 | CHECK(".c find all"); 789 | ".c" << find(below, "item"); 790 | CHECK(".c find below item"); 791 | ".c" << find(closest, 10, 20); 792 | CHECK(".c find closest 10 20"); 793 | ".c" << find(closest, 10, 20, 5); 794 | CHECK(".c find closest 10 20 5"); 795 | ".c" << find(closest, 10, 20, 5, "item"); 796 | CHECK(".c find closest 10 20 5 item"); 797 | ".c" << find(enclosed, 10, 20, 30, 40); 798 | CHECK(".c find enclosed 10 20 30 40"); 799 | ".c" << find(overlapping, 10, 20, 30, 40); 800 | CHECK(".c find overlapping 10 20 30 40"); 801 | ".c" << find(withtag, "item"); 802 | CHECK(".c find withtag item"); 803 | 804 | ".c" << focus(); 805 | CHECK(".c focus"); 806 | ".c" << focus("item"); 807 | CHECK(".c focus item"); 808 | 809 | ".pw" << forget(".b"); 810 | CHECK(".pw forget .b"); 811 | 812 | ".b" << flash(); 813 | CHECK(".b flash"); 814 | 815 | ".sb" << fraction(50, 60); 816 | CHECK(".sb fraction 50 60"); 817 | 818 | ".e" << get(); 819 | CHECK(".e get"); 820 | ".lb" << get(5); 821 | CHECK(".lb get 5"); 822 | ".lb" << get(5, 8); 823 | CHECK(".lb get 5 8"); 824 | ".t" << get(txt(5,6)); 825 | CHECK(".t get 5.6"); 826 | ".t" << get(txt(5,6), txt(7,end)); 827 | CHECK(".t get 5.6 7.end"); 828 | 829 | ".lb" << getsize(); 830 | CHECK(".lb size"); 831 | 832 | ".c" << gettags("item"); 833 | CHECK(".c gettags item"); 834 | 835 | ".e" << icursor(5); 836 | CHECK(".e icursor 5"); 837 | ".c" << icursor("item", 5); 838 | CHECK(".c icursor item 5"); 839 | 840 | ".pw" << identify(50, 60); 841 | CHECK(".pw identify 50 60"); 842 | 843 | ".t" << images(cget, txt(5,6), align); 844 | CHECK(".t image cget 5.6 -align"); 845 | ".t" << images(cget, txt(5,6), image); 846 | CHECK(".t image cget 5.6 -image"); 847 | ".t" << images(cget, txt(5,6), name); 848 | CHECK(".t image cget 5.6 -name"); 849 | ".t" << images(cget, txt(5,6), padx); 850 | CHECK(".t image cget 5.6 -padx"); 851 | ".t" << images(cget, txt(5,6), pady); 852 | CHECK(".t image cget 5.6 -pady"); 853 | ".t" << images(configure, txt(5,6)) -align(bottom); 854 | CHECK(".t image configure 5.6 -align bottom"); 855 | ".t" << images(create, txt(5,6)) -name("myimage"); 856 | CHECK(".t image create 5.6 -name myimage"); 857 | ".t" << images(names); 858 | CHECK(".t image names"); 859 | 860 | ".e" << index(5); 861 | CHECK(".e index 5"); 862 | ".c" << index("item", end); 863 | CHECK(".c index item end"); 864 | ".t" << index(txt(5,end)); 865 | CHECK(".t index 5.end"); 866 | 867 | ".e" << insert(5, "hello world"); 868 | CHECK(".e insert 5 \"hello world\""); 869 | ".c" << insert("item", 5, "hello world"); 870 | CHECK(".c insert item 5 \"hello world\""); 871 | ".lb" << insert(end, items.begin(), items.end()); 872 | CHECK(".lb insert end \"item1\" \"item2\" \"item3\""); 873 | ".m" << insert(5, checkbutton); 874 | CHECK(".m insert 5 \"checkbutton\""); 875 | ".t" << insert(end, "ala ma kota"); 876 | CHECK(".t insert end \"ala ma kota\""); 877 | ".t" << insert(end, std::string("ala ma kota"), "mytag"); 878 | CHECK(".t insert end \"ala ma kota\" mytag"); 879 | 880 | // Note: this is a trap - both strings will be treated as iterators 881 | //".t" << insert(end, "ala ma kota", "mytag"); 882 | //CHECK(".t insert end \"ala ma kota\" mytag"); 883 | 884 | ".b" << invoke(); 885 | CHECK(".b invoke"); 886 | ".m" << invoke(5); 887 | CHECK(".m invoke 5"); 888 | 889 | ".c" << itemcget("item", text); 890 | CHECK(".c itemcget item -text"); 891 | ".lb" << itemcget(5, background); 892 | CHECK(".lb itemcget 5 -background"); 893 | 894 | ".c" << itemconfigure("item") -text("hello"); 895 | CHECK(".c itemconfigure item -text \"hello\""); 896 | ".lb" << itemconfigure(5) -background("blue"); 897 | CHECK(".lb itemconfigure 5 -background blue"); 898 | 899 | ".c" << lower("item"); 900 | CHECK(".c lower item"); 901 | ".c" << lower("item1", "item2"); 902 | CHECK(".c lower item1 item2"); 903 | 904 | ".t" << mark(gravity, "mymark"); 905 | CHECK(".t mark gravity mymark"); 906 | ".t" << mark(gravity, "mymark", left); 907 | CHECK(".t mark gravity mymark left"); 908 | ".t" << mark(names); 909 | CHECK(".t mark names"); 910 | ".t" << mark(next, txt(5,6)); 911 | CHECK(".t mark next 5.6"); 912 | ".t" << mark(previous, txt(5,6)); 913 | CHECK(".t mark previous 5.6"); 914 | ".t" << mark(set, "mymark", txt(5,6)); 915 | CHECK(".t mark set mymark 5.6"); 916 | ".t" << mark(unset, "mymark"); 917 | CHECK(".t mark unset mymark"); 918 | 919 | ".c" << move("item", 10, 20); 920 | CHECK(".c move item 10 20"); 921 | 922 | // FIXME Floating Point Imprecision 923 | // ".sb" << moveto(0.2); 924 | // CHECK(".sb moveto 0.2"); 925 | 926 | ".lb" << nearest(25); 927 | CHECK(".lb nearest 25"); 928 | 929 | ".pw" << panecget(".b", width); 930 | CHECK(".pw panecget .b -width"); 931 | 932 | ".pw" << paneconfigure(".b") -after(".b2") -before(".b3") -height(20) 933 | -minsize(5) -padx(5) -pady(5) -sticky(w) -width(50); 934 | CHECK(".pw paneconfigure .b -after .b2 -before .b3 -height 20" 935 | " -minsize 5 -padx 5 -pady 5 -sticky w -width 50"); 936 | 937 | ".pw" << panes(); 938 | CHECK(".pw panes"); 939 | 940 | ".m" << post(100, 150); 941 | CHECK(".m post 100 150"); 942 | 943 | ".m" << postcascade(5); 944 | CHECK(".m postcascade 5"); 945 | 946 | ".c" << postscript() -colormode(color) -file("file.eps"); 947 | CHECK(".c postscript -colormode color -file \"file.eps\""); 948 | ".c" << postscript() -pageanchor(center); 949 | CHECK(".c postscript -pageanchor center"); 950 | ".c" << postscript() -pageheight(10) -pagewidth("20i"); 951 | CHECK(".c postscript -pageheight 10 -pagewidth 20i"); 952 | ".c" << postscript() -pagex(10) -pagey(20); 953 | CHECK(".c postscript -pagex 10 -pagey 20"); 954 | ".c" << postscript() -rotate(true); 955 | CHECK(".c postscript -rotate 1"); 956 | ".c" << postscript() -x(10) -y(20); 957 | CHECK(".c postscript -x 10 -y 20"); 958 | 959 | ".pw" << proxy(coord); 960 | CHECK(".pw proxy coord"); 961 | ".pw" << proxy(forget); 962 | CHECK(".pw proxy forget"); 963 | ".pw" << proxy(place, 50, 60); 964 | CHECK(".pw proxy place 50 60"); 965 | 966 | "photo1" << put("red") -to(10, 20, 11, 21); 967 | CHECK("photo1 put red -to 10 20 11 21"); 968 | 969 | ".c" << raise("item"); 970 | CHECK(".c raise item"); 971 | ".c" << raise("item1", "item2"); 972 | CHECK(".c raise item1 item2"); 973 | 974 | "photo1" << read("photo.gif") -to(10, 20); 975 | CHECK("photo1 read \"photo.gif\" -to 10 20"); 976 | 977 | "photo1" << redither(); 978 | CHECK("photo1 redither"); 979 | 980 | ".pw" << sash(coord, 5); 981 | CHECK(".pw sash coord 5"); 982 | ".pw" << sash(dragto, 5, 50, 60); 983 | CHECK(".pw sash dragto 5 50 60"); 984 | ".pw" << sash(mark, 5, 50, 60); 985 | CHECK(".pw sash mark 5 50 60"); 986 | ".pw" << sash(place, 5, 50, 60); 987 | CHECK(".pw sash place 5 50 60"); 988 | 989 | // FIXME Floating Point Imprecision 990 | // ".c" << scale("item", 10, 20, 1.5, 1.6); 991 | // CHECK(".c scale item 10 20 1.5 1.6"); 992 | 993 | ".e" << scan(mark, 10); 994 | CHECK(".e scan mark 10"); 995 | ".e" << scan(dragto, 30); 996 | CHECK(".e scan dragto 30"); 997 | ".c" << scan(mark, 10, 20); 998 | CHECK(".c scan mark 10 20"); 999 | ".c" << scan(dragto, 30, 40); 1000 | CHECK(".c scan dragto 30 40"); 1001 | ".c" << scan(dragto, 30, 40, 5); 1002 | CHECK(".c scan dragto 30 40 5"); 1003 | 1004 | ".sb" << scroll(5, units); 1005 | CHECK(".sb scroll 5 units"); 1006 | ".sb" << scroll(6, pages); 1007 | CHECK(".sb scroll 6 pages"); 1008 | 1009 | int charcount; 1010 | ".t" << search("pattern", txt(5,6)) -count(charcount); 1011 | CHECK(".t search \"pattern\" -count CppTk::variable1 -- 5.6"); 1012 | ".t" << search("pattern", txt(5,6), txt(5,end)) -forwards() -backwards() 1013 | -exact() -regexp() -nocase() -elide(); 1014 | CHECK(".t search \"pattern\" -forwards -backwards -exact -regexp" 1015 | " -nocase -elide -- 5.6 5.end"); 1016 | 1017 | ".lb" << see(5); 1018 | CHECK(".lb see 5"); 1019 | ".t" << see(txt(5,6)); 1020 | CHECK(".t see 5.6"); 1021 | 1022 | ".cb" << select(); 1023 | CHECK(".cb select"); 1024 | ".c" << select(adjust, "item", 5); 1025 | CHECK(".c select adjust item 5"); 1026 | ".c" << select(clear); 1027 | CHECK(".c select clear"); 1028 | ".c" << select(from, "item", 5); 1029 | CHECK(".c select from item 5"); 1030 | ".c" << select(item); 1031 | CHECK(".c select item"); 1032 | ".c" << select(to, "item", 5); 1033 | CHECK(".c select to item 5"); 1034 | 1035 | ".e" << selection(adjust, 5); 1036 | CHECK(".e selection adjust 5"); 1037 | ".e" << selection(clear); 1038 | CHECK(".e selection clear"); 1039 | ".e" << selection(from, 5); 1040 | CHECK(".e selection from 5"); 1041 | ".e" << selection(present); 1042 | CHECK(".e selection present"); 1043 | ".e" << selection(range, 5, 8); 1044 | CHECK(".e selection range 5 8"); 1045 | ".e" << selection(to, 5); 1046 | CHECK(".e selection to 5"); 1047 | ".lb" << selection(anchor, 5); 1048 | CHECK(".lb selection anchor 5"); 1049 | ".lb" << selection(clear, 5); 1050 | CHECK(".lb selection clear 5"); 1051 | ".lb" << selection(clear, 5, 8); 1052 | CHECK(".lb selection clear 5 8"); 1053 | ".lb" << selection(includes, 5); 1054 | CHECK(".lb selection includes 5"); 1055 | ".lb" << selection(set, 5); 1056 | CHECK(".lb selection set 5"); 1057 | ".lb" << selection(set, 5, 8); 1058 | CHECK(".lb selection set 5 8"); 1059 | ".sp" << selection(element); 1060 | CHECK(".sp selection element"); 1061 | ".sp" << selection(element, 5); 1062 | CHECK(".sp selection element 5"); 1063 | ".sp" << selection(range, 5, 7); 1064 | CHECK(".sp selection range 5 7"); 1065 | 1066 | ".s" << set(150); 1067 | CHECK(".s set 150"); 1068 | // FIXME Floating Point Imprecision 1069 | // ".sb" << set(0.2, 0.4); 1070 | // CHECK(".sb set 0.2 0.4"); 1071 | ".sp" << set(); 1072 | CHECK(".sp set"); 1073 | 1074 | ".t" << tag(add, "mytag", txt(5,6)); 1075 | CHECK(".t tag add mytag 5.6"); 1076 | ".t" << tag(add, "mytag", txt(5,6), txt(5,end)); 1077 | CHECK(".t tag add mytag 5.6 5.end"); 1078 | ".t" << tag(add, "mytag", txt(5,6), end); 1079 | CHECK(".t tag add mytag 5.6 end"); 1080 | ".t" << tag(bind, "mytag", ""); 1081 | CHECK(".t tag bind mytag "); 1082 | ".t" << tag(bind, "mytag", "", cb0); 1083 | CHECK(".t tag bind mytag { CppTk::callback6 }"); 1084 | ".t" << tag(bind, "mytag", "", cb1, event_x); 1085 | CHECK(".t tag bind mytag { CppTk::callback7 %x }"); 1086 | ".t" << tag(bind, "mytag", "", cb2, event_A, event_b, event_D, 1087 | event_f, event_h, event_k, event_K, event_m, event_N); 1088 | CHECK(".t tag bind mytag { CppTk::callback8 %A %b %D %f %h" 1089 | " %k %K %m %N }"); 1090 | ".t" << tag(bind, "mytag", "", cb3, event_s, event_T, event_w, 1091 | event_W, event_x, event_y, event_X, event_Y); 1092 | CHECK(".t tag bind mytag { CppTk::callback9 %s %T %w %W %x" 1093 | " %y %X %Y }"); 1094 | ".t" << tag(cget, "mytag", background); 1095 | CHECK(".t tag cget mytag -background"); 1096 | ".t" << tag(cget, "mytag", bgstipple); 1097 | CHECK(".t tag cget mytag -bgstipple"); 1098 | ".t" << tag(cget, "mytag", borderwidth); 1099 | CHECK(".t tag cget mytag -borderwidth"); 1100 | ".t" << tag(cget, "mytag", elide); 1101 | CHECK(".t tag cget mytag -elide"); 1102 | ".t" << tag(cget, "mytag", fgstipple); 1103 | CHECK(".t tag cget mytag -fgstipple"); 1104 | ".t" << tag(cget, "mytag", font); 1105 | CHECK(".t tag cget mytag -font"); 1106 | ".t" << tag(cget, "mytag", foreground); 1107 | CHECK(".t tag cget mytag -foreground"); 1108 | ".t" << tag(cget, "mytag", justify); 1109 | CHECK(".t tag cget mytag -justify"); 1110 | ".t" << tag(cget, "mytag", lmargin1); 1111 | CHECK(".t tag cget mytag -lmargin1"); 1112 | ".t" << tag(cget, "mytag", lmargin2); 1113 | CHECK(".t tag cget mytag -lmargin2"); 1114 | ".t" << tag(cget, "mytag", offset); 1115 | CHECK(".t tag cget mytag -offset"); 1116 | ".t" << tag(cget, "mytag", overstrike); 1117 | CHECK(".t tag cget mytag -overstrike"); 1118 | ".t" << tag(cget, "mytag", relief); 1119 | CHECK(".t tag cget mytag -relief"); 1120 | ".t" << tag(cget, "mytag", rmargin); 1121 | CHECK(".t tag cget mytag -rmargin"); 1122 | ".t" << tag(cget, "mytag", spacing1); 1123 | CHECK(".t tag cget mytag -spacing1"); 1124 | ".t" << tag(cget, "mytag", spacing2); 1125 | CHECK(".t tag cget mytag -spacing2"); 1126 | ".t" << tag(cget, "mytag", spacing3); 1127 | CHECK(".t tag cget mytag -spacing3"); 1128 | ".t" << tag(cget, "mytag", tabs); 1129 | CHECK(".t tag cget mytag -tabs"); 1130 | ".t" << tag(cget, "mytag", underline); 1131 | CHECK(".t tag cget mytag -underline"); 1132 | ".t" << tag(cget, "mytag", wrap); 1133 | CHECK(".t tag cget mytag -wrap"); 1134 | ".t" << tag(configure, "mytag") -foreground("blue"); 1135 | CHECK(".t tag configure mytag -foreground blue"); 1136 | ".t" << tag(deletetag, "mytag"); 1137 | CHECK(".t tag delete mytag"); 1138 | ".t" << tag(lower, "mytag"); 1139 | CHECK(".t tag lower mytag"); 1140 | ".t" << tag(lower, "mytag", "belowthis"); 1141 | CHECK(".t tag lower mytag belowthis"); 1142 | ".t" << tag(names); 1143 | CHECK(".t tag names"); 1144 | ".t" << tag(names, txt(5,6)); 1145 | CHECK(".t tag names 5.6"); 1146 | ".t" << tag(nextrange, "mytag", txt(5,6)); 1147 | CHECK(".t tag nextrange mytag 5.6"); 1148 | ".t" << tag(nextrange, "mytag", txt(5,6), txt(5,end)); 1149 | CHECK(".t tag nextrange mytag 5.6 5.end"); 1150 | ".t" << tag(prevrange, "mytag", txt(5,6)); 1151 | CHECK(".t tag prevrange mytag 5.6"); 1152 | ".t" << tag(prevrange, "mytag", txt(5,6), txt(5,end)); 1153 | CHECK(".t tag prevrange mytag 5.6 5.end"); 1154 | ".t" << tag(raise, "mytag"); 1155 | CHECK(".t tag raise mytag"); 1156 | ".t" << tag(raise, "mytag", "belowthis"); 1157 | CHECK(".t tag raise mytag belowthis"); 1158 | ".t" << tag(ranges, "mytag"); 1159 | CHECK(".t tag ranges mytag"); 1160 | ".t" << tag(Tk::remove, "mytag", txt(5,6)); 1161 | CHECK(".t tag remove mytag 5.6"); 1162 | ".t" << tag(Tk::remove, "mytag", txt(5,6), txt(5,end)); 1163 | CHECK(".t tag remove mytag 5.6 5.end"); 1164 | 1165 | ".cb" << toggle(); 1166 | CHECK(".cb toggle"); 1167 | 1168 | "photo1" << transparency(get, 10, 20); 1169 | CHECK("photo1 transparency get 10 20"); 1170 | "photo1" << transparency(set, 10, 20, true); 1171 | CHECK("photo1 transparency set 10 20 1"); 1172 | 1173 | ".c" << type("item"); 1174 | CHECK(".c type item"); 1175 | ".m" << type(5); 1176 | CHECK(".m type 5"); 1177 | 1178 | ".e" << validate(); 1179 | CHECK(".e validate"); 1180 | 1181 | ".t" << windows(cget, txt(5,6), align); 1182 | CHECK(".t window cget 5.6 align"); 1183 | ".t" << windows(configure, txt(5,6)) -align(center); 1184 | CHECK(".t window configure 5.6 -align center"); 1185 | ".t" << windows(create, txt(5,6)); 1186 | CHECK(".t window create 5.6"); 1187 | ".t" << windows(names); 1188 | CHECK(".t window names"); 1189 | 1190 | "photo1" << write("photo.gif") -grayscale(); 1191 | CHECK("photo1 write \"photo.gif\" -grayscale"); 1192 | 1193 | std::pair(".c" << xview()); 1194 | CHECK(".c xview"); 1195 | ".e" << xview(5); 1196 | CHECK(".e xview 5"); 1197 | ".c" << xview(moveto, 0.5); 1198 | CHECK(".c xview moveto 0.5"); 1199 | ".c" << xview(scroll, 5, units); 1200 | CHECK(".c xview scroll 5 units"); 1201 | ".c" << xview(scroll, 5, pages); 1202 | CHECK(".c xview scroll 5 pages"); 1203 | 1204 | ".m" << yposition(5); 1205 | CHECK(".m yposition 5"); 1206 | 1207 | std::pair(".c" << yview()); 1208 | CHECK(".c yview"); 1209 | ".c" << yview(moveto, 0.5); 1210 | CHECK(".c yview moveto 0.5"); 1211 | ".c" << yview(scroll, 5, units); 1212 | CHECK(".c yview scroll 5 units"); 1213 | ".c" << yview(scroll, 5, pages); 1214 | CHECK(".c yview scroll 5 pages"); 1215 | 1216 | 1217 | std::cout << "widget commands test OK\n"; 1218 | } 1219 | 1220 | void optionsTest() 1221 | { 1222 | button(".b") -activebackground("blue") -activeforeground("red"); 1223 | CHECK("button .b -activebackground blue -activeforeground red"); 1224 | 1225 | ".c" << itemconfigure("item") -dash("-.-") -activedash("-.") 1226 | -disableddash(".-."); 1227 | CHECK(".c itemconfigure item -dash \"-.-\" -activedash \"-.\"" 1228 | " -disableddash \".-.\""); 1229 | 1230 | button(".b") -anchor(w) -background("blue"); 1231 | CHECK("button .b -anchor w -background blue"); 1232 | 1233 | ".c" << create(line, 10, 20, 30, 40) -arrow(both) 1234 | -arrowshape(10, 20, 30); 1235 | CHECK(".c create line 10 20 30 40 -arrow both -arrowshape {10 20 30}"); 1236 | 1237 | button(".b") -bitmap(warning) -borderwidth(10) -bg(20); 1238 | CHECK("button .b -bitmap warning -borderwidth 10 -bg 20"); 1239 | ".c" << create(bitmap, 10, 20) -bitmap("bmp") -activebitmap("bmp") 1240 | -disabledbitmap("bmp"); 1241 | CHECK(".c create bitmap 10 20 -bitmap bmp -activebitmap bmp" 1242 | " -disabledbitmap bmp"); 1243 | 1244 | ".c" << create(line, 10, 20, 30, 40) -capstyle(projecting); 1245 | CHECK(".c create line 10 20 30 40 -capstyle projecting"); 1246 | 1247 | canvas(".c") -closeenough(1.5); 1248 | CHECK("canvas .c -closeenough 1.5"); 1249 | 1250 | button(".b") -command(cb0); 1251 | CHECK("button .b -command CppTk::callback10"); 1252 | CallbackHandle cmd(callback(cb0)); 1253 | button(".b") -command(cmd); 1254 | CHECK("button .b -command { CppTk::callback11 }"); 1255 | 1256 | button(".b") -compound(left); 1257 | CHECK("button .b -compound left"); 1258 | 1259 | canvas(".c") -confine(true); 1260 | CHECK("canvas .c -confine 1"); 1261 | 1262 | button(".b") -cursor("abc") -disabledforeground("blue"); 1263 | CHECK("button .b -cursor abc -disabledforeground blue"); 1264 | 1265 | ".c" << itemconfigure("item") -dashoffset(5); 1266 | CHECK(".c itemconfigure item -dashoffset 5"); 1267 | 1268 | button(".b") -defaultstate(active); 1269 | CHECK("button .b -default active"); 1270 | 1271 | ".e" << configure() -exportselection(true); 1272 | CHECK(".e configure -exportselection 1"); 1273 | 1274 | ".c" << create(arc, 10, 20, 30, 40) -start(180) -extent(90) 1275 | -style(pieslice); 1276 | CHECK(".c create arc 10 20 30 40 -start 180 -extent 90 -style pieslice"); 1277 | 1278 | ".c" << itemconfigure("item") -fill("red") -activefill("red") 1279 | -disabledfill("red"); 1280 | CHECK(".c itemconfigure item -fill red -activefill red" 1281 | " -disabledfill red"); 1282 | 1283 | button(".b") -font("courier") -foreground("blue") -fg("red"); 1284 | CHECK("button .b -font courier -foreground blue -fg red"); 1285 | 1286 | button(".b") -height(10); 1287 | CHECK("button .b -height 10"); 1288 | 1289 | button(".b") -highlightbackground("blue") -highlightcolor("red"); 1290 | CHECK("button .b -highlightbackground blue -highlightcolor red"); 1291 | 1292 | button(".b") -highlightthickness(10) -image("abc"); 1293 | CHECK("button .b -highlightthickness 10 -image abc"); 1294 | 1295 | ".c" << create(image, 10, 20) -image("img") -activeimage("img") 1296 | -disabledimage("img"); 1297 | CHECK(".c create image 10 20 -image img -activeimage img" 1298 | " -disabledimage img"); 1299 | 1300 | checkbutton(".cb") -indicatoron(false) -offrelief(raised); 1301 | CHECK("checkbutton .cb -indicatoron 0 -offrelief raised"); 1302 | 1303 | canvas(".c") -insertbackground("blue") -insertborderwidth(3); 1304 | CHECK("canvas .c -insertbackground blue -insertborderwidth 3"); 1305 | 1306 | canvas(".c") -insertofftime(100) -insertontime(150) -insertwidth(2); 1307 | CHECK("canvas .c -insertofftime 100 -insertontime 150 -insertwidth 2"); 1308 | 1309 | ".e" << configure() -invalidcommand(cb0); 1310 | CHECK(".e configure -invalidcommand CppTk::callback12"); 1311 | ".e" << configure() -invalidcommand("bell"); 1312 | CHECK(".e configure -invalidcommand { bell }"); 1313 | 1314 | ".c" << create(line, 10, 20, 30, 40) -joinstyle(bevel); 1315 | CHECK(".c create line 10 20 30 40 -joinstyle bevel"); 1316 | 1317 | button(".b") -justify(left) -padx(10) -pady(15); 1318 | CHECK("button .b -justify left -padx 10 -pady 15"); 1319 | 1320 | ".c" << itemconfigure("item") -offset(n); 1321 | CHECK(".c itemconfigure item -offset n"); 1322 | 1323 | ".cb" << configure() -offrelief(raised) -offvalue(0) -onvalue(7) 1324 | -selectcolor("blue"); 1325 | CHECK(".cb configure -offrelief raised -offvalue 0 -onvalue 7" 1326 | " -selectcolor blue"); 1327 | 1328 | ".c" << itemconfigure("item") -outline("red") -activeoutline("red") 1329 | -disabledoutline("red"); 1330 | CHECK(".c itemconfigure item -outline red -activeoutline red" 1331 | " -disabledoutline red"); 1332 | 1333 | ".c" << itemconfigure("item") -outlinestipple("bmp") 1334 | -activeoutlinestipple("bmp") -disabledoutlinestipple("bmp"); 1335 | CHECK(".c itemconfigure item -outlinestipple bmp" 1336 | " -activeoutlinestipple bmp -disabledoutlinestipple bmp"); 1337 | 1338 | menu(".m") -menutype(menubar) -menutype(tearoff) -menutype(normal); 1339 | CHECK("menu .m -type menubar -type tearoff -type normal"); 1340 | 1341 | button(".b") -overrelief(raised); 1342 | CHECK("button .b -overrelief raised"); 1343 | 1344 | ".e" << configure() -readonlybackground("blue"); 1345 | CHECK(".e configure -readonlybackground blue"); 1346 | 1347 | button(".b") -relief(ridge) -repeatdelay(100) -repeatinterval(150); 1348 | CHECK("button .b -relief ridge -repeatdelay 100 -repeatinterval 150"); 1349 | 1350 | canvas(".c") -scrollregion(10, 20, 30, 40); 1351 | CHECK("canvas .c -scrollregion 10 20 30 40"); 1352 | 1353 | canvas(".c") -selectbackground("blue") -selectborderwidth(3) 1354 | -selectforeground("red"); 1355 | CHECK("canvas .c -selectbackground blue -selectborderwidth 3" 1356 | " -selectforeground red"); 1357 | 1358 | ".cb" << configure() -selectcolor("blue") -selectimage("img"); 1359 | CHECK(".cb configure -selectcolor blue -selectimage img"); 1360 | 1361 | ".e" << configure() -show("*"); 1362 | CHECK(".e configure -show \"*\""); 1363 | 1364 | ".c" << create(line, 10, 20, 30, 40) -smooth(bezier) -splinesteps(30); 1365 | CHECK(".c create line 10 20 30 40 -smooth bezier -splinesteps 30"); 1366 | ".c" << create(line, 10, 20, 30, 40) -smooth(true); 1367 | CHECK(".c create line 10 20 30 40 -smooth 1"); 1368 | 1369 | button(".b") -state(disabled); 1370 | CHECK("button .b -state disabled"); 1371 | 1372 | ".c" << itemconfigure("item") -stipple("bmp") -activestipple("bmp") 1373 | -disabledstipple("bmp"); 1374 | CHECK(".c itemconfigure item -stipple bmp -activestipple bmp" 1375 | " -disabledstipple bmp"); 1376 | 1377 | std::vector sometags; 1378 | sometags.push_back("tag1"); 1379 | sometags.push_back("tag2"); 1380 | sometags.push_back("tag3"); 1381 | ".c" << itemconfigure("item") -tags(sometags.begin(), sometags.end()); 1382 | CHECK(".c itemconfigure item -tags { tag1 tag2 tag3}"); 1383 | 1384 | button(".b") -takefocus(1) -text("Hello"); 1385 | CHECK("button .b -takefocus 1 -text \"Hello\""); 1386 | 1387 | int i; 1388 | double d; 1389 | std::string s; 1390 | button(".b") -textvariable(i); 1391 | CHECK("button .b -textvariable CppTk::variable2"); 1392 | button(".b") -textvariable(d); 1393 | CHECK("button .b -textvariable CppTk::variable3"); 1394 | button(".b") -textvariable(s); 1395 | CHECK("button .b -textvariable CppTk::variable4"); 1396 | 1397 | checkbutton(".cb") -variable(i); 1398 | CHECK("checkbutton .cb -variable CppTk::variable5"); 1399 | 1400 | button(".b") -underline(3) -wraplength(100); 1401 | CHECK("button .b -underline 3 -wraplength 100"); 1402 | 1403 | ".e" << configure() -validate(focus) -validatecommand(cbb0, valid_P); 1404 | CHECK(".e configure -validate focus -validatecommand " 1405 | "{ CppTk::callback13 %P }"); 1406 | 1407 | button(".b") -width(10); 1408 | CHECK("button .b -width 10"); 1409 | ".c" << itemconfigure("item") -width(2) -activewidth(2) 1410 | -disabledwidth(2); 1411 | CHECK(".c itemconfigure item -width 2 -activewidth 2 -disabledwidth 2"); 1412 | 1413 | ".c" << create(window, 10, 20) -window(".e"); 1414 | CHECK(".c create window 10 20 -window .e"); 1415 | 1416 | canvas(".c") -xscrollcommand("xcmd") -yscrollcommand("ycmd"); 1417 | CHECK("canvas .c -xscrollcommand \"xcmd\" -yscrollcommand \"ycmd\""); 1418 | 1419 | canvas(".c") -xscrollincrement(10) -yscrollincrement(20); 1420 | CHECK("canvas .c -xscrollincrement 10 -yscrollincrement 20"); 1421 | 1422 | 1423 | std::cout << "options test OK\n"; 1424 | } 1425 | 1426 | void additionalTclTest() 1427 | { 1428 | after(500); 1429 | CHECK("after 500"); 1430 | after(500, cb0); 1431 | CHECK("after 500 CppTk::callback14"); 1432 | after(500, std::string("bell")); 1433 | CHECK("after 500 bell"); 1434 | after(cancel, std::string("someid")); 1435 | CHECK("after cancel someid"); 1436 | afteridle(cb0); 1437 | CHECK("after idle CppTk::callback15"); 1438 | 1439 | update(); 1440 | CHECK("update"); 1441 | update(idletasks); 1442 | CHECK("update idletasks"); 1443 | 1444 | eval("some explicit Tcl/Tk command"); 1445 | CHECK("some explicit Tcl/Tk command"); 1446 | 1447 | 1448 | std::cout << "additional Tcl test OK\n"; 1449 | } 1450 | 1451 | int main(int, char *argv[]) 1452 | { 1453 | try 1454 | { 1455 | init(argv[0]); 1456 | setDumpStream(ss); 1457 | 1458 | commandsTest(); 1459 | widgetCommandsTest(); 1460 | optionsTest(); 1461 | additionalTclTest(); 1462 | } 1463 | catch (std::exception const &e) 1464 | { 1465 | std::cerr << "Error: " << e.what() << '\n'; 1466 | } 1467 | } 1468 | --------------------------------------------------------------------------------