├── .gitignore ├── LICENSE ├── LICENSE.LGPL ├── README.md ├── examples ├── attrs.go ├── dock.go ├── drawrose.go ├── drawtest.go ├── images │ ├── close.png │ └── liteide128.png ├── keytest.go ├── listtest.go ├── minimal.go ├── minimal2.go └── widgets.go ├── make ├── make.lua ├── makelib.lua └── ui │ ├── action.lua │ ├── actiongroup.lua │ ├── app.lua │ ├── basebutton.lua │ ├── baselayout.lua │ ├── baseslider.lua │ ├── boxlayout.lua │ ├── brush.lua │ ├── button.lua │ ├── checkbox.lua │ ├── combobox.lua │ ├── dial.lua │ ├── dialog.lua │ ├── dockwidget.lua │ ├── font.lua │ ├── frame.lua │ ├── groupbox.lua │ ├── hboxlayout.lua │ ├── icon.lua │ ├── image.lua │ ├── label.lua │ ├── lineedit.lua │ ├── listwidget.lua │ ├── listwidgetitem.lua │ ├── mainwindow.lua │ ├── menu.lua │ ├── menubar.lua │ ├── painter.lua │ ├── pen.lua │ ├── pixmap.lua │ ├── radio.lua │ ├── scrollbar.lua │ ├── slider.lua │ ├── stackedlayout.lua │ ├── statusbar.lua │ ├── systemtray.lua │ ├── tabwidget.lua │ ├── timer.lua │ ├── toolbar.lua │ ├── toolbox.lua │ ├── toolbutton.lua │ ├── vboxlayout.lua │ └── widget.lua ├── qtdrv ├── cdrv.cpp ├── cdrv.h ├── qtapp.cpp ├── qtapp.h ├── qtdrv.pro ├── qtdrv_global.h ├── qtevent.cpp ├── qtevent.h ├── qtshell.h ├── qtsignal.cpp └── qtsignal.h └── ui ├── cdrv.go ├── events.go ├── object.go ├── ui.go ├── uidefs.go └── uiobjs.go /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 2 | *.o 3 | *.a 4 | *.so 5 | *.dll 6 | 7 | # Folders 8 | _obj 9 | _test 10 | 11 | # Architecture specific extensions/prefixes 12 | *.[568vq] 13 | [568vq].out 14 | 15 | *.cgo1.go 16 | *.cgo2.c 17 | _cgo_defun.c 18 | _cgo_gotypes.go 19 | _cgo_export.* 20 | 21 | _testmain.go 22 | 23 | *.exe 24 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 visualfc . All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 15 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 16 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 17 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 18 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 19 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 20 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | -------------------------------------------------------------------------------- /LICENSE.LGPL: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 2.1, February 1999 3 | 4 | Copyright (C) 1991, 1999 Free Software Foundation, Inc. 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | [This is the first released version of the Lesser GPL. It also counts 10 | as the successor of the GNU Library Public License, version 2, hence 11 | the version number 2.1.] 12 | 13 | Preamble 14 | 15 | The licenses for most software are designed to take away your 16 | freedom to share and change it. By contrast, the GNU General Public 17 | Licenses are intended to guarantee your freedom to share and change 18 | free software--to make sure the software is free for all its users. 19 | 20 | This license, the Lesser General Public License, applies to some 21 | specially designated software packages--typically libraries--of the 22 | Free Software Foundation and other authors who decide to use it. You 23 | can use it too, but we suggest you first think carefully about whether 24 | this license or the ordinary General Public License is the better 25 | strategy to use in any particular case, based on the explanations below. 26 | 27 | When we speak of free software, we are referring to freedom of use, 28 | not price. Our General Public Licenses are designed to make sure that 29 | you have the freedom to distribute copies of free software (and charge 30 | for this service if you wish); that you receive source code or can get 31 | it if you want it; that you can change the software and use pieces of 32 | it in new free programs; and that you are informed that you can do 33 | these things. 34 | 35 | To protect your rights, we need to make restrictions that forbid 36 | distributors to deny you these rights or to ask you to surrender these 37 | rights. These restrictions translate to certain responsibilities for 38 | you if you distribute copies of the library or if you modify it. 39 | 40 | For example, if you distribute copies of the library, whether gratis 41 | or for a fee, you must give the recipients all the rights that we gave 42 | you. You must make sure that they, too, receive or can get the source 43 | code. If you link other code with the library, you must provide 44 | complete object files to the recipients, so that they can relink them 45 | with the library after making changes to the library and recompiling 46 | it. And you must show them these terms so they know their rights. 47 | 48 | We protect your rights with a two-step method: (1) we copyright the 49 | library, and (2) we offer you this license, which gives you legal 50 | permission to copy, distribute and/or modify the library. 51 | 52 | To protect each distributor, we want to make it very clear that 53 | there is no warranty for the free library. Also, if the library is 54 | modified by someone else and passed on, the recipients should know 55 | that what they have is not the original version, so that the original 56 | author's reputation will not be affected by problems that might be 57 | introduced by others. 58 | 59 | Finally, software patents pose a constant threat to the existence of 60 | any free program. We wish to make sure that a company cannot 61 | effectively restrict the users of a free program by obtaining a 62 | restrictive license from a patent holder. Therefore, we insist that 63 | any patent license obtained for a version of the library must be 64 | consistent with the full freedom of use specified in this license. 65 | 66 | Most GNU software, including some libraries, is covered by the 67 | ordinary GNU General Public License. This license, the GNU Lesser 68 | General Public License, applies to certain designated libraries, and 69 | is quite different from the ordinary General Public License. We use 70 | this license for certain libraries in order to permit linking those 71 | libraries into non-free programs. 72 | 73 | When a program is linked with a library, whether statically or using 74 | a shared library, the combination of the two is legally speaking a 75 | combined work, a derivative of the original library. The ordinary 76 | General Public License therefore permits such linking only if the 77 | entire combination fits its criteria of freedom. The Lesser General 78 | Public License permits more lax criteria for linking other code with 79 | the library. 80 | 81 | We call this license the "Lesser" General Public License because it 82 | does Less to protect the user's freedom than the ordinary General 83 | Public License. It also provides other free software developers Less 84 | of an advantage over competing non-free programs. These disadvantages 85 | are the reason we use the ordinary General Public License for many 86 | libraries. However, the Lesser license provides advantages in certain 87 | special circumstances. 88 | 89 | For example, on rare occasions, there may be a special need to 90 | encourage the widest possible use of a certain library, so that it becomes 91 | a de-facto standard. To achieve this, non-free programs must be 92 | allowed to use the library. A more frequent case is that a free 93 | library does the same job as widely used non-free libraries. In this 94 | case, there is little to gain by limiting the free library to free 95 | software only, so we use the Lesser General Public License. 96 | 97 | In other cases, permission to use a particular library in non-free 98 | programs enables a greater number of people to use a large body of 99 | free software. For example, permission to use the GNU C Library in 100 | non-free programs enables many more people to use the whole GNU 101 | operating system, as well as its variant, the GNU/Linux operating 102 | system. 103 | 104 | Although the Lesser General Public License is Less protective of the 105 | users' freedom, it does ensure that the user of a program that is 106 | linked with the Library has the freedom and the wherewithal to run 107 | that program using a modified version of the Library. 108 | 109 | The precise terms and conditions for copying, distribution and 110 | modification follow. Pay close attention to the difference between a 111 | "work based on the library" and a "work that uses the library". The 112 | former contains code derived from the library, whereas the latter must 113 | be combined with the library in order to run. 114 | 115 | GNU LESSER GENERAL PUBLIC LICENSE 116 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 117 | 118 | 0. This License Agreement applies to any software library or other 119 | program which contains a notice placed by the copyright holder or 120 | other authorized party saying it may be distributed under the terms of 121 | this Lesser General Public License (also called "this License"). 122 | Each licensee is addressed as "you". 123 | 124 | A "library" means a collection of software functions and/or data 125 | prepared so as to be conveniently linked with application programs 126 | (which use some of those functions and data) to form executables. 127 | 128 | The "Library", below, refers to any such software library or work 129 | which has been distributed under these terms. A "work based on the 130 | Library" means either the Library or any derivative work under 131 | copyright law: that is to say, a work containing the Library or a 132 | portion of it, either verbatim or with modifications and/or translated 133 | straightforwardly into another language. (Hereinafter, translation is 134 | included without limitation in the term "modification".) 135 | 136 | "Source code" for a work means the preferred form of the work for 137 | making modifications to it. For a library, complete source code means 138 | all the source code for all modules it contains, plus any associated 139 | interface definition files, plus the scripts used to control compilation 140 | and installation of the library. 141 | 142 | Activities other than copying, distribution and modification are not 143 | covered by this License; they are outside its scope. The act of 144 | running a program using the Library is not restricted, and output from 145 | such a program is covered only if its contents constitute a work based 146 | on the Library (independent of the use of the Library in a tool for 147 | writing it). Whether that is true depends on what the Library does 148 | and what the program that uses the Library does. 149 | 150 | 1. You may copy and distribute verbatim copies of the Library's 151 | complete source code as you receive it, in any medium, provided that 152 | you conspicuously and appropriately publish on each copy an 153 | appropriate copyright notice and disclaimer of warranty; keep intact 154 | all the notices that refer to this License and to the absence of any 155 | warranty; and distribute a copy of this License along with the 156 | Library. 157 | 158 | You may charge a fee for the physical act of transferring a copy, 159 | and you may at your option offer warranty protection in exchange for a 160 | fee. 161 | 162 | 2. You may modify your copy or copies of the Library or any portion 163 | of it, thus forming a work based on the Library, and copy and 164 | distribute such modifications or work under the terms of Section 1 165 | above, provided that you also meet all of these conditions: 166 | 167 | a) The modified work must itself be a software library. 168 | 169 | b) You must cause the files modified to carry prominent notices 170 | stating that you changed the files and the date of any change. 171 | 172 | c) You must cause the whole of the work to be licensed at no 173 | charge to all third parties under the terms of this License. 174 | 175 | d) If a facility in the modified Library refers to a function or a 176 | table of data to be supplied by an application program that uses 177 | the facility, other than as an argument passed when the facility 178 | is invoked, then you must make a good faith effort to ensure that, 179 | in the event an application does not supply such function or 180 | table, the facility still operates, and performs whatever part of 181 | its purpose remains meaningful. 182 | 183 | (For example, a function in a library to compute square roots has 184 | a purpose that is entirely well-defined independent of the 185 | application. Therefore, Subsection 2d requires that any 186 | application-supplied function or table used by this function must 187 | be optional: if the application does not supply it, the square 188 | root function must still compute square roots.) 189 | 190 | These requirements apply to the modified work as a whole. If 191 | identifiable sections of that work are not derived from the Library, 192 | and can be reasonably considered independent and separate works in 193 | themselves, then this License, and its terms, do not apply to those 194 | sections when you distribute them as separate works. But when you 195 | distribute the same sections as part of a whole which is a work based 196 | on the Library, the distribution of the whole must be on the terms of 197 | this License, whose permissions for other licensees extend to the 198 | entire whole, and thus to each and every part regardless of who wrote 199 | it. 200 | 201 | Thus, it is not the intent of this section to claim rights or contest 202 | your rights to work written entirely by you; rather, the intent is to 203 | exercise the right to control the distribution of derivative or 204 | collective works based on the Library. 205 | 206 | In addition, mere aggregation of another work not based on the Library 207 | with the Library (or with a work based on the Library) on a volume of 208 | a storage or distribution medium does not bring the other work under 209 | the scope of this License. 210 | 211 | 3. You may opt to apply the terms of the ordinary GNU General Public 212 | License instead of this License to a given copy of the Library. To do 213 | this, you must alter all the notices that refer to this License, so 214 | that they refer to the ordinary GNU General Public License, version 2, 215 | instead of to this License. (If a newer version than version 2 of the 216 | ordinary GNU General Public License has appeared, then you can specify 217 | that version instead if you wish.) Do not make any other change in 218 | these notices. 219 | 220 | Once this change is made in a given copy, it is irreversible for 221 | that copy, so the ordinary GNU General Public License applies to all 222 | subsequent copies and derivative works made from that copy. 223 | 224 | This option is useful when you wish to copy part of the code of 225 | the Library into a program that is not a library. 226 | 227 | 4. You may copy and distribute the Library (or a portion or 228 | derivative of it, under Section 2) in object code or executable form 229 | under the terms of Sections 1 and 2 above provided that you accompany 230 | it with the complete corresponding machine-readable source code, which 231 | must be distributed under the terms of Sections 1 and 2 above on a 232 | medium customarily used for software interchange. 233 | 234 | If distribution of object code is made by offering access to copy 235 | from a designated place, then offering equivalent access to copy the 236 | source code from the same place satisfies the requirement to 237 | distribute the source code, even though third parties are not 238 | compelled to copy the source along with the object code. 239 | 240 | 5. A program that contains no derivative of any portion of the 241 | Library, but is designed to work with the Library by being compiled or 242 | linked with it, is called a "work that uses the Library". Such a 243 | work, in isolation, is not a derivative work of the Library, and 244 | therefore falls outside the scope of this License. 245 | 246 | However, linking a "work that uses the Library" with the Library 247 | creates an executable that is a derivative of the Library (because it 248 | contains portions of the Library), rather than a "work that uses the 249 | library". The executable is therefore covered by this License. 250 | Section 6 states terms for distribution of such executables. 251 | 252 | When a "work that uses the Library" uses material from a header file 253 | that is part of the Library, the object code for the work may be a 254 | derivative work of the Library even though the source code is not. 255 | Whether this is true is especially significant if the work can be 256 | linked without the Library, or if the work is itself a library. The 257 | threshold for this to be true is not precisely defined by law. 258 | 259 | If such an object file uses only numerical parameters, data 260 | structure layouts and accessors, and small macros and small inline 261 | functions (ten lines or less in length), then the use of the object 262 | file is unrestricted, regardless of whether it is legally a derivative 263 | work. (Executables containing this object code plus portions of the 264 | Library will still fall under Section 6.) 265 | 266 | Otherwise, if the work is a derivative of the Library, you may 267 | distribute the object code for the work under the terms of Section 6. 268 | Any executables containing that work also fall under Section 6, 269 | whether or not they are linked directly with the Library itself. 270 | 271 | 6. As an exception to the Sections above, you may also combine or 272 | link a "work that uses the Library" with the Library to produce a 273 | work containing portions of the Library, and distribute that work 274 | under terms of your choice, provided that the terms permit 275 | modification of the work for the customer's own use and reverse 276 | engineering for debugging such modifications. 277 | 278 | You must give prominent notice with each copy of the work that the 279 | Library is used in it and that the Library and its use are covered by 280 | this License. You must supply a copy of this License. If the work 281 | during execution displays copyright notices, you must include the 282 | copyright notice for the Library among them, as well as a reference 283 | directing the user to the copy of this License. Also, you must do one 284 | of these things: 285 | 286 | a) Accompany the work with the complete corresponding 287 | machine-readable source code for the Library including whatever 288 | changes were used in the work (which must be distributed under 289 | Sections 1 and 2 above); and, if the work is an executable linked 290 | with the Library, with the complete machine-readable "work that 291 | uses the Library", as object code and/or source code, so that the 292 | user can modify the Library and then relink to produce a modified 293 | executable containing the modified Library. (It is understood 294 | that the user who changes the contents of definitions files in the 295 | Library will not necessarily be able to recompile the application 296 | to use the modified definitions.) 297 | 298 | b) Use a suitable shared library mechanism for linking with the 299 | Library. A suitable mechanism is one that (1) uses at run time a 300 | copy of the library already present on the user's computer system, 301 | rather than copying library functions into the executable, and (2) 302 | will operate properly with a modified version of the library, if 303 | the user installs one, as long as the modified version is 304 | interface-compatible with the version that the work was made with. 305 | 306 | c) Accompany the work with a written offer, valid for at 307 | least three years, to give the same user the materials 308 | specified in Subsection 6a, above, for a charge no more 309 | than the cost of performing this distribution. 310 | 311 | d) If distribution of the work is made by offering access to copy 312 | from a designated place, offer equivalent access to copy the above 313 | specified materials from the same place. 314 | 315 | e) Verify that the user has already received a copy of these 316 | materials or that you have already sent this user a copy. 317 | 318 | For an executable, the required form of the "work that uses the 319 | Library" must include any data and utility programs needed for 320 | reproducing the executable from it. However, as a special exception, 321 | the materials to be distributed need not include anything that is 322 | normally distributed (in either source or binary form) with the major 323 | components (compiler, kernel, and so on) of the operating system on 324 | which the executable runs, unless that component itself accompanies 325 | the executable. 326 | 327 | It may happen that this requirement contradicts the license 328 | restrictions of other proprietary libraries that do not normally 329 | accompany the operating system. Such a contradiction means you cannot 330 | use both them and the Library together in an executable that you 331 | distribute. 332 | 333 | 7. You may place library facilities that are a work based on the 334 | Library side-by-side in a single library together with other library 335 | facilities not covered by this License, and distribute such a combined 336 | library, provided that the separate distribution of the work based on 337 | the Library and of the other library facilities is otherwise 338 | permitted, and provided that you do these two things: 339 | 340 | a) Accompany the combined library with a copy of the same work 341 | based on the Library, uncombined with any other library 342 | facilities. This must be distributed under the terms of the 343 | Sections above. 344 | 345 | b) Give prominent notice with the combined library of the fact 346 | that part of it is a work based on the Library, and explaining 347 | where to find the accompanying uncombined form of the same work. 348 | 349 | 8. You may not copy, modify, sublicense, link with, or distribute 350 | the Library except as expressly provided under this License. Any 351 | attempt otherwise to copy, modify, sublicense, link with, or 352 | distribute the Library is void, and will automatically terminate your 353 | rights under this License. However, parties who have received copies, 354 | or rights, from you under this License will not have their licenses 355 | terminated so long as such parties remain in full compliance. 356 | 357 | 9. You are not required to accept this License, since you have not 358 | signed it. However, nothing else grants you permission to modify or 359 | distribute the Library or its derivative works. These actions are 360 | prohibited by law if you do not accept this License. Therefore, by 361 | modifying or distributing the Library (or any work based on the 362 | Library), you indicate your acceptance of this License to do so, and 363 | all its terms and conditions for copying, distributing or modifying 364 | the Library or works based on it. 365 | 366 | 10. Each time you redistribute the Library (or any work based on the 367 | Library), the recipient automatically receives a license from the 368 | original licensor to copy, distribute, link with or modify the Library 369 | subject to these terms and conditions. You may not impose any further 370 | restrictions on the recipients' exercise of the rights granted herein. 371 | You are not responsible for enforcing compliance by third parties with 372 | this License. 373 | 374 | 11. If, as a consequence of a court judgment or allegation of patent 375 | infringement or for any other reason (not limited to patent issues), 376 | conditions are imposed on you (whether by court order, agreement or 377 | otherwise) that contradict the conditions of this License, they do not 378 | excuse you from the conditions of this License. If you cannot 379 | distribute so as to satisfy simultaneously your obligations under this 380 | License and any other pertinent obligations, then as a consequence you 381 | may not distribute the Library at all. For example, if a patent 382 | license would not permit royalty-free redistribution of the Library by 383 | all those who receive copies directly or indirectly through you, then 384 | the only way you could satisfy both it and this License would be to 385 | refrain entirely from distribution of the Library. 386 | 387 | If any portion of this section is held invalid or unenforceable under any 388 | particular circumstance, the balance of the section is intended to apply, 389 | and the section as a whole is intended to apply in other circumstances. 390 | 391 | It is not the purpose of this section to induce you to infringe any 392 | patents or other property right claims or to contest validity of any 393 | such claims; this section has the sole purpose of protecting the 394 | integrity of the free software distribution system which is 395 | implemented by public license practices. Many people have made 396 | generous contributions to the wide range of software distributed 397 | through that system in reliance on consistent application of that 398 | system; it is up to the author/donor to decide if he or she is willing 399 | to distribute software through any other system and a licensee cannot 400 | impose that choice. 401 | 402 | This section is intended to make thoroughly clear what is believed to 403 | be a consequence of the rest of this License. 404 | 405 | 12. If the distribution and/or use of the Library is restricted in 406 | certain countries either by patents or by copyrighted interfaces, the 407 | original copyright holder who places the Library under this License may add 408 | an explicit geographical distribution limitation excluding those countries, 409 | so that distribution is permitted only in or among countries not thus 410 | excluded. In such case, this License incorporates the limitation as if 411 | written in the body of this License. 412 | 413 | 13. The Free Software Foundation may publish revised and/or new 414 | versions of the Lesser General Public License from time to time. 415 | Such new versions will be similar in spirit to the present version, 416 | but may differ in detail to address new problems or concerns. 417 | 418 | Each version is given a distinguishing version number. If the Library 419 | specifies a version number of this License which applies to it and 420 | "any later version", you have the option of following the terms and 421 | conditions either of that version or of any later version published by 422 | the Free Software Foundation. If the Library does not specify a 423 | license version number, you may choose any version ever published by 424 | the Free Software Foundation. 425 | 426 | 14. If you wish to incorporate parts of the Library into other free 427 | programs whose distribution conditions are incompatible with these, 428 | write to the author to ask for permission. For software which is 429 | copyrighted by the Free Software Foundation, write to the Free 430 | Software Foundation; we sometimes make exceptions for this. Our 431 | decision will be guided by the two goals of preserving the free status 432 | of all derivatives of our free software and of promoting the sharing 433 | and reuse of software generally. 434 | 435 | NO WARRANTY 436 | 437 | 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO 438 | WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. 439 | EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR 440 | OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY 441 | KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE 442 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 443 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE 444 | LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME 445 | THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 446 | 447 | 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN 448 | WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY 449 | AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU 450 | FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR 451 | CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE 452 | LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING 453 | RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A 454 | FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF 455 | SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 456 | DAMAGES. 457 | 458 | END OF TERMS AND CONDITIONS 459 | 460 | How to Apply These Terms to Your New Libraries 461 | 462 | If you develop a new library, and you want it to be of the greatest 463 | possible use to the public, we recommend making it free software that 464 | everyone can redistribute and change. You can do so by permitting 465 | redistribution under these terms (or, alternatively, under the terms of the 466 | ordinary General Public License). 467 | 468 | To apply these terms, attach the following notices to the library. It is 469 | safest to attach them to the start of each source file to most effectively 470 | convey the exclusion of warranty; and each file should have at least the 471 | "copyright" line and a pointer to where the full notice is found. 472 | 473 | 474 | Copyright (C) 475 | 476 | This library is free software; you can redistribute it and/or 477 | modify it under the terms of the GNU Lesser General Public 478 | License as published by the Free Software Foundation; either 479 | version 2.1 of the License, or (at your option) any later version. 480 | 481 | This library is distributed in the hope that it will be useful, 482 | but WITHOUT ANY WARRANTY; without even the implied warranty of 483 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 484 | Lesser General Public License for more details. 485 | 486 | You should have received a copy of the GNU Lesser General Public 487 | License along with this library; if not, write to the Free Software 488 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 489 | 490 | Also add information on how to contact you by electronic and paper mail. 491 | 492 | You should also get your employer (if you work as a programmer) or your 493 | school, if any, to sign a "copyright disclaimer" for the library, if 494 | necessary. Here is a sample; alter the names: 495 | 496 | Yoyodyne, Inc., hereby disclaims all copyright interest in the 497 | library `Frob' (a library for tweaking knobs) written by James Random Hacker. 498 | 499 | , 1 April 1990 500 | Ty Coon, President of Vice 501 | 502 | That's all there is to it! 503 | 504 | 505 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | #go-ui 0.1.1 2 | ===== 3 | 4 | ## This project is closed !!! 5 | ## Please goto new project [GoQt](https://github.com/visualfc/goqt) 6 | 7 | ##Introduction 8 | go-ui is a cross-platform golang ui tool kit, based on qt. 9 | 10 | ##System 11 | Windows / Linux / MacOS X 12 | 13 | ##License 14 | go-ui lib BSD 15 | qtdrv lib LGPL 16 | 17 | ##Build go-ui and examples 18 | 19 | ###1.get go-ui 20 | $ go get github.com/visualfc/go-ui 21 | ###2.build qtdrv, need install QtSDK 22 | $ cd go-ui/qtdrv 23 | $ qmake "CONFIG+=release" 24 | $ make 25 | ###3.build go-ui 26 | $ cd go-ui/ui 27 | $ go install 28 | ###4.build examples 29 | $ cd go-ui/examples 30 | $ go build -ldflags '-r ../lib' minimal.go 31 | $ ./minimal 32 | 33 | ##Examples 34 | 35 | package main 36 | 37 | import ( 38 | "github.com/visualfc/go-ui/ui" 39 | ) 40 | 41 | func main() { 42 | ui.Main(func() { 43 | w := ui.NewWidget() 44 | w.SetWindowTitle(ui.Version()) 45 | w.SetSizev(300, 200) 46 | defer w.Close() 47 | w.Show() 48 | ui.Run() 49 | }) 50 | } 51 | 52 | 53 | -------------------------------------------------------------------------------- /examples/attrs.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "github.com/visualfc/go-ui/ui" 6 | ) 7 | 8 | var exit = make(chan bool) 9 | 10 | func main() { 11 | fmt.Println(ui.Version()) 12 | ui.Main(func() { 13 | go main_ui() 14 | ui.Run() 15 | exit <- true 16 | }) 17 | } 18 | 19 | func main_ui() { 20 | ui.OnInsertObject(func(item interface{}) { 21 | fmt.Println("add item", item) 22 | }) 23 | ui.OnRemoveObject(func(item interface{}) { 24 | fmt.Println("remove item", item) 25 | }) 26 | 27 | w := ui.NewWidget() 28 | defer w.Close() 29 | 30 | w.SetWindowTitle("This is a test") 31 | fmt.Println(w.WindowTitle()) 32 | 33 | vbox := ui.NewVBoxLayout() 34 | fmt.Println(vbox) 35 | w.SetLayout(vbox) 36 | 37 | lbl := ui.NewLabel() 38 | lbl.SetText("

Hello UI

") 39 | lbl.OnLinkActivated(fnTEST) 40 | vbox.AddWidget(lbl) 41 | vbox.AddStretch(0) 42 | 43 | //runtime.GC() 44 | 45 | btn := ui.NewButton() 46 | btn.SetText("WbcdefgwqABCDEFQW") 47 | font := btn.Font() 48 | defer font.Close() 49 | font.SetPointSize(16) 50 | btn.SetFont(font) 51 | fmt.Println("f3->", btn.Font()) 52 | 53 | btn2 := ui.NewButton() 54 | font.SetPointSize(18) 55 | btn2.SetAttr("text", "WbcdefgwqABCDEFQW") 56 | btn2.SetAttr("font", font) 57 | 58 | btn.OnClicked(func() { 59 | fmt.Println(btn) 60 | btn.Close() 61 | }) 62 | btn.OnCloseEvent(func(e *ui.CloseEvent) { 63 | fmt.Println("Close", e) 64 | }) 65 | btn3 := ui.NewButton() 66 | btn3.SetText("Exit") 67 | btn3.OnClicked(func() { 68 | ui.Exit(0) 69 | }) 70 | 71 | l := w.Layout() 72 | fmt.Println("ll", l) 73 | l.AddWidget(btn) 74 | l.AddWidget(btn2) 75 | l.AddWidget(btn3) 76 | //vbox.AddWidget(btn) 77 | f := btn2.Attr("parent") 78 | fmt.Println("parent->", f, f == nil) 79 | 80 | fmt.Println(btn.Font()) 81 | 82 | w.OnResizeEvent(func(e *ui.ResizeEvent) { 83 | fmt.Println(e) 84 | }) 85 | 86 | w.OnPaintEvent(func(ev *ui.PaintEvent) { 87 | fnPaint(ev, w) 88 | }) 89 | 90 | //w.Show() 91 | w.SetVisible(true) 92 | <-exit 93 | } 94 | 95 | func fnPaint(ev *ui.PaintEvent, w *ui.Widget) { 96 | p := ui.NewPainter() 97 | defer p.Close() 98 | p.Begin(w) 99 | p.DrawPoint(ui.Pt(10, 10)) 100 | p.DrawLine(ui.Pt(10, 10), ui.Pt(100, 100)) 101 | p.End() 102 | } 103 | 104 | func fnTEST(link string) { 105 | fmt.Println("link:", link) 106 | } 107 | -------------------------------------------------------------------------------- /examples/dock.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "github.com/visualfc/go-ui/ui" 6 | "runtime" 7 | "time" 8 | ) 9 | 10 | func main() { 11 | runtime.GOMAXPROCS(4) 12 | ui.Main(main_ui) 13 | } 14 | 15 | func main_ui() { 16 | ui.OnInsertObject(func(v interface{}) { 17 | fmt.Println("add item", v) 18 | }) 19 | ui.OnRemoveObject(func(v interface{}) { 20 | fmt.Println("remove item", v) 21 | }) 22 | w := ui.NewMainWindow() 23 | defer w.Close() 24 | go func() { 25 | dock := ui.NewDockWidgetWithTitle("Dock") 26 | dock.SetDock(ui.NewButtonWithText("Hello")) 27 | w.AddDockWidget(ui.LeftDockWidgetArea, dock) 28 | btn := ui.NewButtonWithText("HideDock") 29 | w.SetCentralWidget(btn) 30 | w.SetSize(ui.Sz(200, 200)) 31 | 32 | tb := ui.NewToolBarWithTitle("Standard") 33 | tb.AddWidget(ui.NewButtonWithText("ok")) 34 | w.AddToolBar(tb) 35 | 36 | tb.OnCloseEvent(func(e *ui.CloseEvent) { 37 | fmt.Println("tb close", e) 38 | }) 39 | sb := ui.NewStatusBar() 40 | w.SetStatusBar(sb) 41 | sb.OnCloseEvent(func(e *ui.CloseEvent) { 42 | fmt.Println("sb close", e) 43 | }) 44 | 45 | btn.OnClicked(func() { 46 | dock.Hide() 47 | runtime.GC() 48 | btn.SetText(btn.Text()) 49 | }) 50 | dock.OnCloseEvent(func(e *ui.CloseEvent) { 51 | fmt.Println(e) 52 | }) 53 | 54 | go func() { 55 | for { 56 | timer := time.NewTimer(1) 57 | select { 58 | case <-timer.C: 59 | btn.SetText(btn.Text()) 60 | btn.SetText(btn.Text()) 61 | btn.SetText(btn.Text()) 62 | fmt.Println(">", btn.Text()) 63 | if btn.Text() != "HideDock" { 64 | panic("close") 65 | } 66 | } 67 | } 68 | }() 69 | 70 | dock.OnVisibilityChanged(func(b bool) { 71 | fmt.Println(b) 72 | if !b { 73 | time.AfterFunc(1e9, func() { 74 | if dock.IsValid() { 75 | dock.Show() 76 | } 77 | }) 78 | } 79 | }) 80 | 81 | w.Show() 82 | }() 83 | 84 | ui.Run() 85 | } 86 | -------------------------------------------------------------------------------- /examples/drawrose.go: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | http://www.romancortes.com/blog/1k-rose/ 4 | 5 | with(m = Math) C = cos, 6 | S = sin, 7 | P = pow, 8 | R = random; 9 | c.width = c.height = f = 500; 10 | h = -250; 11 | function p(a, b, c) { 12 | if (c > 60) return [S(a * 7) * (13 + 5 / (.2 + P(b * 4, 4))) - S(b) * 50, b * f + 50, 625 + C(a * 7) * (13 + 5 / (.2 + P(b * 4, 4))) + b * 400, a * 1 - b / 2, a]; 13 | A = a * 2 - 1; 14 | B = b * 2 - 1; 15 | if (A * A + B * B < 1) { 16 | if (c > 37) { 17 | n = (j = c & 1) ? 6 : 4; 18 | o = .5 / (a + .01) + C(b * 125) * 3 - a * 300; 19 | w = b * h; 20 | return [o * C(n) + w * S(n) + j * 610 - 390, o * S(n) - w * C(n) + 550 - j * 350, 1180 + C(B + A) * 99 - j * 300, .4 - a * .1 + P(1 - B * B, -h * 6) * .15 - a * b * .4 + C(a + b) / 5 + P(C((o * (a + 1) + (B > 0 ? w: -w)) / 25), 30) * .1 * (1 - B * B), o / 1e3 + .7 - o * w * 3e-6] 21 | } 22 | if (c > 32) { 23 | c = c * 1.16 - .15; 24 | o = a * 45 - 20; 25 | w = b * b * h; 26 | z = o * S(c) + w * C(c) + 620; 27 | return [o * C(c) - w * S(c), 28 + C(B * .5) * 99 - b * b * b * 60 - z / 2 - h, z, (b * b * .3 + P((1 - (A * A)), 7) * .15 + .3) * b, b * .7] 28 | } 29 | o = A * (2 - b) * (80 - c * 2); 30 | w = 99 - C(A) * 120 - C(b) * ( - h - c * 4.9) + C(P(1 - b, 7)) * 50 + c * 2; 31 | z = o * S(c) + w * C(c) + 700; 32 | return [o * C(c) - w * S(c), B * 99 - C(P(b, 7)) * 50 - c / 3 - z / 1.35 + 450, z, (1 - b / 1.2) * .9 + a * .1, P((1 - b), 20) / 4 + .05] 33 | } 34 | } 35 | setInterval('for(i=0;i<1e4;i++)if(s=p(R(),R(),i%46/.74)){z=s[2];x=~~(s[0]*f/z-h);y=~~(s[1]*f/z-h);if(!m[q=y*f+x]|m[q]>z)m[q]=z,a.fillStyle="rgb("+~(s[3]*h)+","+~(s[4]*h)+","+~(s[3]*s[3]*-80)+")",a.fillRect(x,y,1,1)}',0) 36 | */ 37 | package main 38 | 39 | import ( 40 | "fmt" 41 | "github.com/visualfc/go-ui/ui" 42 | "math" 43 | "math/rand" 44 | ) 45 | 46 | type rect struct { 47 | width, height int 48 | } 49 | 50 | var ( 51 | S = math.Sin 52 | C = math.Cos 53 | P = math.Pow 54 | R = rand.Float64 55 | f float64 = 500 56 | h float64 = -250 57 | m = make(map[float64]float64) 58 | max = 1024 59 | ) 60 | 61 | func main() { 62 | ui.Main(ui_main) 63 | } 64 | 65 | func ui_main() { 66 | w := ui.NewWidget() 67 | defer w.Close() 68 | w.SetWindowTitle("Rose") 69 | 70 | rose := ui.NewWidget() 71 | rose.SetMinimumSize(ui.Sz(510, 510)) 72 | 73 | img := ui.NewImageWithSize(500, 500) 74 | defer img.Close() 75 | 76 | imgPainter := ui.NewPainterWithImage(img) 77 | imgPainter.InitFrom(rose) 78 | defer imgPainter.Close() 79 | 80 | var timerid int = -1 81 | var count int 82 | var timerValue int = 50 83 | 84 | rose.OnTimerEvent(func(e *ui.TimerEvent) { 85 | if e.TimerId() == timerid { 86 | draw(imgPainter) 87 | rose.Update() 88 | count++ 89 | if count >= max { 90 | w.KillTimer(timerid) 91 | } 92 | w.SetWindowTitle(fmt.Sprintf("Rose: %d*1e4", count)) 93 | } 94 | }) 95 | rose.OnPaintEvent(func(e *ui.PaintEvent) { 96 | painter := ui.NewPainter() 97 | defer painter.Close() 98 | painter.Begin(rose) 99 | painter.DrawImageEx(ui.Point{0, 0}, img, img.Rect()) 100 | painter.End() 101 | }) 102 | 103 | load := func() { 104 | if timerid != -1 { 105 | rose.KillTimer(timerid) 106 | } 107 | for k, _ := range m { 108 | delete(m, k) 109 | } 110 | img.Fill(rgb(255, 255, 255)) 111 | count = 0 112 | timerid = rose.StartTimer(timerValue) 113 | } 114 | stop := func() { 115 | rose.KillTimer(timerid) 116 | timerid = -1 117 | } 118 | 119 | vbox := ui.NewVBoxLayout() 120 | 121 | hbox := ui.NewHBoxLayout() 122 | vbox.AddWidget(rose) 123 | vbox.AddLayout(hbox) 124 | 125 | loadBtn := ui.NewButtonWithText("Reload") 126 | stopBtn := ui.NewButtonWithText("Stop") 127 | exitBtn := ui.NewButtonWithText("Exit") 128 | timerLabel := ui.NewLabelWithText("Timer: 50 ") 129 | timerSlider := ui.NewSlider() 130 | timerSlider.SetRange(1, 600) 131 | timerSlider.SetValue(50) 132 | timerSlider.OnValueChanged(func(v int) { 133 | timerValue = v 134 | timerLabel.SetText(fmt.Sprintf("Timer:%4d ", v)) 135 | }) 136 | maxLabel := ui.NewLabelWithText("Max: 1024 ") 137 | maxSlider := ui.NewSlider() 138 | maxSlider.SetRange(10, 10240) 139 | maxSlider.SetValue(1024) 140 | maxSlider.OnValueChanged(func(v int) { 141 | max = v 142 | maxLabel.SetText(fmt.Sprintf("Max:%5d ", v)) 143 | }) 144 | hbox.AddWidget(maxLabel) 145 | hbox.AddWidget(maxSlider) 146 | hbox.AddSpacing(10) 147 | hbox.AddWidget(timerLabel) 148 | hbox.AddWidget(timerSlider) 149 | hbox.AddSpacing(10) 150 | hbox.AddWidget(loadBtn) 151 | hbox.AddWidget(stopBtn) 152 | hbox.AddStretch(0) 153 | hbox.AddWidget(exitBtn) 154 | 155 | loadBtn.OnClicked(load) 156 | stopBtn.OnClicked(stop) 157 | exitBtn.OnClicked(func() { 158 | w.Close() 159 | }) 160 | 161 | w.SetLayout(vbox) 162 | w.Show() 163 | 164 | w.OnCloseEvent(func(e *ui.CloseEvent) { 165 | rose.KillTimer(timerid) 166 | }) 167 | 168 | load() 169 | 170 | ui.Run() 171 | } 172 | 173 | func sel(b bool, v1, v2 float64) float64 { 174 | if b { 175 | return v1 176 | } 177 | return v2 178 | } 179 | func p(a, b, c float64) []float64 { 180 | if c > 60 { 181 | return []float64{S(a*7)*(13+5/(.2+P(b*4, 4))) - S(b)*50, b*f + 50, 625 + C(a*7)*(13+5/(.2+P(b*4, 4))) + b*400, a*1 - b/2, a} 182 | } 183 | A := a*2 - 1 184 | B := b*2 - 1 185 | if A*A+B*B < 1 { 186 | if c > 37 { 187 | var j float64 = float64(int64(c) & 1) 188 | var n float64 = sel(j > 0, 6, 4) 189 | var o float64 = .5/(a+.01) + C(b*125)*3 - a*300 190 | var w float64 = b * h 191 | return []float64{o*C(n) + w*S(n) + j*610 - 390, o*S(n) - w*C(n) + 550 - j*350, 1180 + C(B+A)*99 - j*300, .4 - a*.1 + P(1-B*B, -h*6)*.15 - a*b*.4 + C(a+b)/5 + P(C((o*(a+1)+sel(B > 0, w, -w))/25), 30)*.1*(1-B*B), o/1e3 + .7 - o*w*3e-6} 192 | } 193 | if c > 32 { 194 | c = c*1.16 - .15 195 | var o float64 = a*45 - 20 196 | var w float64 = b * b * h 197 | var z float64 = o*S(c) + w*C(c) + 620 198 | return []float64{o*C(c) - w*S(c), 28 + C(B*.5)*99 - b*b*b*60 - z/2 - h, z, (b*b*.3 + P((1-(A*A)), 7)*.15 + .3) * b, b * .7} 199 | } 200 | var o float64 = A * (2 - b) * (80 - c*2) 201 | var w float64 = 99 - C(A)*120 - C(b)*(-h-c*4.9) + C(P(1-b, 7))*50 + c*2 202 | var z float64 = o*S(c) + w*C(c) + 700 203 | return []float64{o*C(c) - w*S(c), B*99 - C(P(b, 7))*50 - c/3 - z/1.35 + 450, z, (1-b/1.2)*.9 + a*.1, P((1-b), 20)/4 + .05} 204 | } 205 | return nil 206 | } 207 | 208 | func rgb(r, g, b int64) uint { 209 | if r < 0 { 210 | r = -r 211 | } 212 | if g < 0 { 213 | g = -g 214 | } 215 | if b < 0 { 216 | b = -b 217 | } 218 | return uint(r%256*256*256 + g%256*256 + b) 219 | } 220 | 221 | func draw(painter *ui.Painter) { 222 | for i := 0; i < 1e4; i++ { 223 | s := p(R(), R(), float64(i%46)/.74) 224 | if s != nil { 225 | z := s[2] 226 | x := float64(^^int(s[0]*f/z - h)) 227 | y := float64(^^int(s[1]*f/z - h)) 228 | 229 | q := y*f + x 230 | if v, ok := m[q]; !ok || (v > z) { 231 | m[q] = z 232 | clr := rgb(^int64(s[3]*h), ^int64(s[4]*h), ^int64(s[3]*s[3]*-80)) 233 | painter.FillRectF(ui.RcF(x, y, 1, 1), uint(clr)) 234 | } 235 | } 236 | } 237 | } 238 | -------------------------------------------------------------------------------- /examples/drawtest.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "github.com/visualfc/go-ui/ui" 6 | "image/color" 7 | ) 8 | 9 | type rgba uint32 10 | 11 | func (c rgba) RGBA() (r, g, b, a uint32) { 12 | return uint32((c >> 16) & 0xff), uint32((c >> 8) & 0xff), uint32(c & 0xff), uint32(c >> 24) 13 | } 14 | 15 | func make_rgba(c color.Color) rgba { 16 | if c == nil { 17 | return 0 18 | } 19 | r, g, b, a := c.RGBA() 20 | return rgba(((a & 0xff) << 24) | ((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff)) 21 | } 22 | 23 | func main() { 24 | ui.Main(func() { 25 | w := ui.NewWidget() 26 | 27 | w.OnPaintEvent(func(e *ui.PaintEvent) { 28 | paint := ui.NewPainter() 29 | defer paint.Close() 30 | paint.Begin(w) 31 | pen := ui.NewPen() 32 | pen.SetColor(color.RGBA{255, 128, 0, 0}) 33 | pen.SetWidth(2) 34 | fmt.Println(pen, pen.Color(), pen.Width()) 35 | paint.SetPen(pen) 36 | brush := ui.NewBrush() 37 | brush.SetStyle(ui.SolidPattern) 38 | brush.SetColor(color.RGBA{128, 128, 0, 255}) 39 | paint.SetBrush(brush) 40 | paint.DrawRect(ui.Rect{10, 10, 100, 100}) 41 | }) 42 | 43 | w.SetSize(ui.Size{400, 400}) 44 | w.Show() 45 | 46 | ui.Run() 47 | }) 48 | } 49 | -------------------------------------------------------------------------------- /examples/images/close.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/visualfc/go-ui/ae336d1019e2b391bc21a24a42c87f2c53622a15/examples/images/close.png -------------------------------------------------------------------------------- /examples/images/liteide128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/visualfc/go-ui/ae336d1019e2b391bc21a24a42c87f2c53622a15/examples/images/liteide128.png -------------------------------------------------------------------------------- /examples/keytest.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "github.com/visualfc/go-ui/ui" 6 | ) 7 | 8 | func printInfo() { 9 | info := ui.Value("info") 10 | fmt.Println(info) 11 | } 12 | 13 | func setInfo() { 14 | ui.SetValue("info", "new info") 15 | } 16 | 17 | func main() { 18 | ui.Main(ui_main) 19 | } 20 | 21 | func ui_main() { 22 | 23 | w := ui.NewWidget() 24 | 25 | lbox := ui.NewVBoxLayout() 26 | lbl1 := ui.NewLabel() 27 | lbl1.SetText("This is a info1") 28 | lbl2 := ui.NewLabel() 29 | lbl2.SetText("This is a info2") 30 | 31 | ed1 := ui.NewLineEdit() 32 | 33 | printInfo := func() { 34 | info := ui.Value("info") 35 | ed1.SetText(fmt.Sprint(info)) 36 | } 37 | 38 | lbox.AddWidget(lbl1) 39 | lbox.AddWidget(lbl2) 40 | lbox.AddWidget(ed1) 41 | 42 | rbox := ui.NewVBoxLayout() 43 | 44 | btn1 := ui.NewButton() 45 | btn1.SetText("Change") 46 | 47 | btn2 := ui.NewButton() 48 | btn2.SetText("Value") 49 | 50 | btn3 := ui.NewButton() 51 | btn3.SetText("SetValue") 52 | 53 | rbox.AddWidget(btn1) 54 | rbox.AddWidget(btn2) 55 | rbox.AddWidget(btn3) 56 | 57 | b := true 58 | btn1.OnClicked(func() { 59 | var text string 60 | if b { 61 | ui.SetKey(lbl1, "info", "text") 62 | text = "info1" 63 | } else { 64 | ui.SetKey(lbl2, "info", "text") 65 | text = "info2" 66 | } 67 | b = !b 68 | btn1.SetText(text) 69 | }) 70 | 71 | btn2.OnClicked(printInfo) 72 | btn3.OnClicked(setInfo) 73 | 74 | hbox := ui.NewHBoxLayout() 75 | hbox.AddLayout(lbox) 76 | hbox.AddLayout(rbox) 77 | 78 | w.SetLayout(hbox) 79 | 80 | w.Show() 81 | 82 | ui.Run() 83 | } 84 | -------------------------------------------------------------------------------- /examples/listtest.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "github.com/visualfc/go-ui/ui" 6 | ) 7 | 8 | func main() { 9 | ui.Main(ui_main) 10 | } 11 | 12 | func ui_main() { 13 | w := ui.NewWidget() 14 | defer w.Close() 15 | list := ui.NewListWidget() 16 | vbox := ui.NewVBoxLayout() 17 | vbox.AddWidget(list) 18 | w.SetLayout(vbox) 19 | go func() { 20 | list.OnCurrentItemChanged(func(item, old *ui.ListWidgetItem) { 21 | go func() { 22 | fmt.Println(item.Attr("text")) 23 | }() 24 | }) 25 | 26 | item := ui.NewListWidgetItem() 27 | item.SetText("Item1") 28 | list.AddItem(item) 29 | list.AddItem(ui.NewListWidgetItemWithText("Item2")) 30 | }() 31 | 32 | w.Show() 33 | 34 | ui.Run() 35 | } 36 | -------------------------------------------------------------------------------- /examples/minimal.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "github.com/visualfc/go-ui/ui" 6 | ) 7 | 8 | func main() { 9 | fmt.Println(ui.Version()) 10 | ui.Main(func() { 11 | w := ui.NewWidget() 12 | w.SetWindowTitle(ui.Version()) 13 | w.SetSizev(300, 200) 14 | defer w.Close() 15 | w.Show() 16 | ui.Run() 17 | }) 18 | } 19 | -------------------------------------------------------------------------------- /examples/minimal2.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/visualfc/go-ui/ui" 5 | ) 6 | 7 | var exit = make(chan bool) 8 | 9 | func main() { 10 | ui.Main(func() { 11 | go ui_main() 12 | ui.Run() 13 | exit <- true 14 | }) 15 | } 16 | 17 | func ui_main() { 18 | w := ui.NewWidget() 19 | w.SetWindowTitle(ui.Version()) 20 | w.SetSizev(300, 200) 21 | defer w.Close() 22 | w.Show() 23 | <-exit 24 | } 25 | -------------------------------------------------------------------------------- /examples/widgets.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "github.com/visualfc/go-ui/ui" 6 | "io/ioutil" 7 | "runtime" 8 | ) 9 | 10 | type MainWindow struct { 11 | ui.Widget 12 | tab *ui.TabWidget 13 | sbar *ui.StatusBar 14 | } 15 | 16 | func (p *MainWindow) Init() *MainWindow { 17 | if p.Widget.Init() == nil { 18 | return nil 19 | } 20 | p.SetWindowTitle("MainWindow") 21 | 22 | p.tab = ui.NewTabWidget() 23 | 24 | p.tab.AddTab(p.createStdTab(), "Standard", nil) 25 | p.tab.AddTab(p.createMyTab(), "Custom", nil) 26 | p.tab.AddTab(p.createToolBox(), "ToolBox", nil) 27 | 28 | p.sbar = ui.NewStatusBar() 29 | 30 | menubar := ui.NewMenuBar() 31 | menu := ui.NewMenuWithTitle("&File") 32 | //menu.SetTitle("&File") 33 | menubar.AddMenu(menu) 34 | 35 | act := ui.NewAction() 36 | act.SetText("&Quit") 37 | act.OnTriggered(func(bool) { 38 | p.Close() 39 | }) 40 | ic := ui.NewIconWithFile("images/close.png") 41 | //defer ic.Close() 42 | act.SetIcon(ic) 43 | menu.AddAction(act) 44 | 45 | toolBar := ui.NewToolBar() 46 | toolBar.AddAction(act) 47 | toolBar.AddSeparator() 48 | cmb := ui.NewComboBox() 49 | cmb.AddItem("test1") 50 | cmb.AddItem("test2") 51 | cmb.SetToolTip("ComboBox") 52 | cmbAct := toolBar.AddWidget(cmb) 53 | fmt.Println(cmbAct) 54 | 55 | vbox := ui.NewVBoxLayout() 56 | vbox.SetMargin(0) 57 | vbox.SetSpacing(0) 58 | vbox.SetMenuBar(menubar) 59 | vbox.AddWidget(toolBar) 60 | vbox.AddWidget(p.tab) 61 | vbox.AddWidget(p.sbar) 62 | 63 | p.SetLayout(vbox) 64 | 65 | p.tab.OnCurrentChanged(func(index int) { 66 | p.sbar.ShowMessage("current: "+p.tab.TabText(index), 0) 67 | }) 68 | 69 | systray := ui.NewSystemTray() 70 | systray.SetContextMenu(menu) 71 | systray.SetIcon(ic) 72 | systray.SetVisible(true) 73 | systray.ShowMessage("hello", "this is a test", ui.Information, 1000) 74 | ic2 := systray.Icon() 75 | fmt.Println(ic2) 76 | 77 | p.SetWindowIcon(ic2) 78 | 79 | return p 80 | } 81 | 82 | func (p *MainWindow) createStdTab() *ui.Widget { 83 | w := ui.NewWidget() 84 | vbox := ui.NewVBoxLayout() 85 | w.SetLayout(vbox) 86 | 87 | ed := ui.NewLineEdit() 88 | ed.SetInputMask("0000-00-00") 89 | ed.SetText("2012-01-12") 90 | 91 | lbl := ui.NewLabel() 92 | lbl.SetText("Label") 93 | btn := ui.NewButton() 94 | btn.SetText("Button") 95 | chk := ui.NewCheckBox() 96 | chk.SetText("CheckBox") 97 | radio := ui.NewRadio() 98 | radio.SetText("Radio") 99 | cmb := ui.NewComboBox() 100 | cmb.AddItem("001") 101 | cmb.AddItem("002") 102 | cmb.AddItem("003") 103 | cmb.SetCurrentIndex(2) 104 | fmt.Println(cmb.CurrentIndex()) 105 | cmb.OnCurrentIndexChanged(func(v int) { 106 | fmt.Println(cmb.ItemText(v)) 107 | }) 108 | 109 | slider := ui.NewSlider() 110 | slider.SetTickInterval(50) 111 | slider.SetTickPosition(ui.TicksBothSides) 112 | slider.SetSingleStep(1) 113 | 114 | scl := ui.NewScrollBar() 115 | fmt.Println(slider.Range()) 116 | 117 | dial := ui.NewDial() 118 | 119 | dial.SetNotchesVisible(true) 120 | dial.SetNotchTarget(10) 121 | fmt.Println(dial.NotchSize()) 122 | 123 | vbox.AddWidget(ed) 124 | vbox.AddWidget(lbl) 125 | vbox.AddWidget(btn) 126 | vbox.AddWidget(chk) 127 | vbox.AddWidget(radio) 128 | vbox.AddWidget(cmb) 129 | vbox.AddWidget(slider) 130 | vbox.AddWidget(scl) 131 | vbox.AddWidget(dial) 132 | vbox.AddStretch(0) 133 | return w 134 | } 135 | 136 | func (p *MainWindow) createToolBox() ui.IWidget { 137 | tb := ui.NewToolBox() 138 | tb.AddItem(ui.NewButtonWithText("button"), "btn", nil) 139 | tb.AddItem(ui.NewLabelWithText("Label\nInfo"), "Label", nil) 140 | pixmap := ui.NewPixmapWithFile("images/liteide128.png") 141 | //defer pixmap.Close() 142 | lbl := ui.NewLabel() 143 | lbl.SetPixmap(pixmap) 144 | tb.AddItem(lbl, "Lalel Pixmap", nil) 145 | buf, err := ioutil.ReadFile("images/liteide128.png") 146 | if err == nil { 147 | pixmap2 := ui.NewPixmapWithData(buf) 148 | tb.AddItem(ui.NewLabelWithPixmap(pixmap2), "Lalel Pixmap2", nil) 149 | } 150 | return tb 151 | } 152 | 153 | func (p *MainWindow) createMyTab() *ui.Widget { 154 | w := ui.NewWidget() 155 | vbox := ui.NewVBoxLayout() 156 | hbox := ui.NewHBoxLayout() 157 | my := new(MyWidget).Init() 158 | lbl := ui.NewLabel() 159 | lbl.SetText("this is custome widget - draw lines") 160 | btn := ui.NewButton() 161 | btn.SetText("Clear") 162 | btn.OnClicked(func() { 163 | my.Clear() 164 | }) 165 | hbox.AddWidget(lbl) 166 | hbox.AddWidgetWith(btn, 0, ui.AlignRight) 167 | vbox.AddLayout(hbox) 168 | vbox.AddWidgetWith(my, 1, 0) 169 | w.SetLayout(vbox) 170 | return w 171 | } 172 | 173 | func main() { 174 | ui.Main(ui_main) 175 | } 176 | 177 | func ui_main() { 178 | exit := make(chan bool) 179 | go func() { 180 | fmt.Println("vfc/ui") 181 | ui.OnInsertObject(func(v interface{}) { 182 | fmt.Println("add item", v) 183 | }) 184 | ui.OnRemoveObject(func(v interface{}) { 185 | fmt.Println("remove item", v) 186 | }) 187 | w := new(MainWindow).Init() 188 | defer w.Close() 189 | 190 | w.SetSizev(400, 300) 191 | w.OnCloseEvent(func(e *ui.CloseEvent) { 192 | fmt.Println("close", e) 193 | }) 194 | w.Show() 195 | <- exit 196 | }() 197 | ui.Run() 198 | exit <- true 199 | } 200 | 201 | type MyWidget struct { 202 | ui.Widget 203 | lines [][]ui.Point 204 | line []ui.Point 205 | font *ui.Font 206 | } 207 | 208 | func (p *MyWidget) Name() string { 209 | return "MyWidget" 210 | } 211 | 212 | func (p *MyWidget) String() string { 213 | return ui.DumpObject(p) 214 | } 215 | 216 | func (p *MyWidget) Init() *MyWidget { 217 | if p.Widget.Init() == nil { 218 | return nil 219 | } 220 | p.font = ui.NewFontWith("Timer", 16, 87) 221 | p.font.SetItalic(true) 222 | p.Widget.OnPaintEvent(func(e *ui.PaintEvent) { 223 | p.paintEvent(e) 224 | }) 225 | p.Widget.OnMousePressEvent(func(e *ui.MouseEvent) { 226 | p.mousePressEvent(e) 227 | }) 228 | p.Widget.OnMouseMoveEvent(func(e *ui.MouseEvent) { 229 | p.mouseMoveEvent(e) 230 | }) 231 | p.Widget.OnMouseReleaseEvent(func(e *ui.MouseEvent) { 232 | p.mouseReleaseEvent(e) 233 | }) 234 | ui.InsertObject(p) 235 | return p 236 | } 237 | 238 | func (p *MyWidget) Clear() { 239 | p.lines = [][]ui.Point{} 240 | p.Update() 241 | } 242 | 243 | func (p *MyWidget) paintEvent(e *ui.PaintEvent) { 244 | paint := ui.NewPainter() 245 | defer paint.Close() 246 | 247 | paint.Begin(p) 248 | paint.SetFont(p.font) 249 | paint.DrawLines(p.line) 250 | paint.SetFont(p.font) 251 | paint.DrawText(ui.Pt(100, 100), "draw test") 252 | for _, v := range p.lines { 253 | //paint.DrawLines(v) 254 | paint.DrawPolyline(v) 255 | } 256 | paint.End() 257 | runtime.GC() 258 | } 259 | 260 | func (p *MyWidget) mousePressEvent(e *ui.MouseEvent) { 261 | p.line = append(p.line, e.Pos()) 262 | p.Update() 263 | } 264 | 265 | func (p *MyWidget) mouseMoveEvent(e *ui.MouseEvent) { 266 | p.line = append(p.line, e.Pos()) 267 | p.Update() 268 | } 269 | 270 | func (p *MyWidget) mouseReleaseEvent(e *ui.MouseEvent) { 271 | p.line = append(p.line, e.Pos()) 272 | p.lines = append(p.lines, p.line) 273 | p.line = []ui.Point{} 274 | p.Update() 275 | } 276 | -------------------------------------------------------------------------------- /make/make.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | // Copyright 2012 visualfc . All rights reserved. 3 | // Use of this source code is governed by a BSD-style 4 | // license that can be found in the LICENSE file. 5 | --]] 6 | 7 | require "ui.app" 8 | require "ui.timer" 9 | 10 | require "ui.font" 11 | require "ui.icon" 12 | require "ui.pixmap" 13 | require "ui.image" 14 | 15 | require "ui.widget" 16 | require "ui.tabwidget" 17 | require "ui.toolbox" 18 | 19 | require "ui.dialog" 20 | 21 | require "ui.baselayout" 22 | require "ui.boxlayout" 23 | require "ui.hboxlayout" 24 | require "ui.vboxlayout" 25 | require "ui.stackedlayout" 26 | 27 | require "ui.basebutton" 28 | require "ui.button" 29 | require "ui.checkbox" 30 | require "ui.radio" 31 | require "ui.toolbutton" 32 | 33 | require "ui.frame" 34 | require "ui.label" 35 | 36 | require "ui.groupbox" 37 | 38 | require "ui.brush" 39 | require "ui.pen" 40 | require "ui.painter" 41 | 42 | require "ui.menubar" 43 | require "ui.menu" 44 | require "ui.action" 45 | require "ui.actiongroup" 46 | require "ui.toolbar" 47 | require "ui.statusbar" 48 | require "ui.dockwidget" 49 | 50 | require "ui.combobox" 51 | require "ui.lineedit" 52 | 53 | require "ui.systemtray" 54 | 55 | require "ui.baseslider" 56 | require "ui.slider" 57 | require "ui.scrollbar" 58 | require "ui.dial" 59 | 60 | require "ui.listwidgetitem" 61 | require "ui.listwidget" 62 | 63 | require "ui.mainwindow" 64 | 65 | require "makelib" 66 | 67 | function make() 68 | cdrv_type = "qtdrv" 69 | cdrv_func_go2c = lower_title 70 | begin_def() 71 | def(app) 72 | def(timer) 73 | 74 | def(font) 75 | def(pixmap) 76 | def(icon) 77 | def(image) 78 | 79 | def(widget) 80 | 81 | def(action) 82 | def(actiongroup) 83 | def(menu) 84 | def(menubar) 85 | def(toolbar) 86 | def(statusbar) 87 | def(dockwidget) 88 | 89 | def(systemtray) 90 | 91 | def(tabwidget) 92 | def(toolbox) 93 | 94 | def(baselayout) 95 | def(boxlayout) 96 | def(hboxlayout) 97 | def(vboxlayout) 98 | def(stackedlayout) 99 | 100 | def(basebutton) 101 | def(button) 102 | def(checkbox) 103 | def(radio) 104 | def(toolbutton) 105 | 106 | def(frame) 107 | def(label) 108 | def(groupbox) 109 | def(dialog) 110 | 111 | def(combobox) 112 | def(lineedit) 113 | 114 | def(baseslider) 115 | def(slider) 116 | def(scrollbar) 117 | def(dial) 118 | 119 | def(brush) 120 | def(pen) 121 | def(painter) 122 | 123 | def(listwidgetitem) 124 | def(listwidget) 125 | 126 | def(mainwindow) 127 | 128 | end_def() 129 | 130 | local ui = io.open("../ui/uiobjs.go","w") 131 | ui:write(table.concat(go_def.heads,"\n")) 132 | ui:write("\n") 133 | ui:write(table.concat(go_def.drvenum,"\n")) 134 | ui:write("\n") 135 | ui:write(table.concat(go_def.enums,"\n")) 136 | ui:write("\n") 137 | ui:write(table.concat(go_def.newobj,"\n")) 138 | ui:write("\n") 139 | ui:write(table.concat(go_def.funcs,"\n")) 140 | ui:write("\n") 141 | ui:close() 142 | 143 | local cdrv = io.open(string.format("../%s/cdrv.cpp",cdrv_type),"w") 144 | cdrv:write(table.concat(c_def.heads,"\n")) 145 | cdrv:write("\n") 146 | cdrv:write(table.concat(c_def.include,"\n")) 147 | cdrv:write("\n") 148 | cdrv:write(table.concat(c_def.drvenum,"\n")) 149 | cdrv:write("\n") 150 | cdrv:write(table.concat(c_def.enums,"\n")) 151 | cdrv:write("\n") 152 | cdrv:write(table.concat(c_def.funcs,"\n")) 153 | cdrv:write("\n") 154 | cdrv:write(table.concat(c_def.drvfunc,"\n")) 155 | cdrv:write("\n") 156 | cdrv:write(table.concat(c_def._drvfunc,"\n")) 157 | cdrv:write("\n") 158 | cdrv:close() 159 | end 160 | 161 | make() 162 | -------------------------------------------------------------------------------- /make/makelib.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | // Copyright 2012 visualfc . All rights reserved. 3 | // Use of this source code is governed by a BSD-style 4 | // license that can be found in the LICENSE file. 5 | --]] 6 | 7 | -- tag +,-,@,* 8 | function get_func(s) 9 | local tag,name,input,output = string.match(s,"([%+%-%@%*]?)%s*([_%w%*%[%]]+)%s*(%b())%s*(%b())") 10 | if name == nil then 11 | tag,name,input = string.match(s,"([%+%-%@%*]?)%s*([_%w%*%[%]]+)%s*(%b())") 12 | end 13 | if name == nil then 14 | tag,name = string.match(s,"([%+%-%@%*]?)%s*([_%w%*%[%]]+)") 15 | end 16 | 17 | if name == nil then 18 | return nil 19 | end 20 | input = input or "()" 21 | output = output or "()" 22 | 23 | input = string.sub(input,2,-2).."," 24 | output = string.sub(output,2,-2).."," 25 | 26 | local func = {} 27 | func.tag = tag or "" 28 | func.name = name 29 | func.input = {} 30 | func.output = {} 31 | 32 | for v,t in string.gmatch(input,"([_%w]+)%s+([_%w%.%*%[%]%(%),]+),") do 33 | func.input[#func.input+1] = {var=v,type=t} 34 | end 35 | 36 | for v,t in string.gmatch(output,"([_%w]+)%s+([_%w%.%*%[%]%(%),]+),") do 37 | func.output[#func.output+1] = {var=v,type=t} 38 | end 39 | 40 | return func 41 | end 42 | 43 | function get_lines(s) 44 | local i = 0 45 | local j = 0 46 | local lines = {} 47 | while true do 48 | j = string.find(s.."\n","\n",i) 49 | if j == nil then 50 | break 51 | end 52 | local line = string.sub(s,i,j-1) 53 | if line ~= "" then 54 | lines[#lines+1] = line 55 | end 56 | i = j+1 57 | end 58 | return lines 59 | end 60 | 61 | function get_funcs(s) 62 | local lines = get_lines(s) 63 | local funcs = {} 64 | for k,v in ipairs(lines) do 65 | local func = get_func(v) 66 | if func ~= nil then 67 | funcs[#funcs+1] = func 68 | end 69 | end 70 | return funcs 71 | end 72 | 73 | function get_comment(s) 74 | local lines = get_lines(s) 75 | local comment = {} 76 | for k,v in ipairs(lines) do 77 | comment[#comment+1] = "// "..v 78 | end 79 | return table.concat(comment,"\n//\n") 80 | end 81 | 82 | function make_params(t) 83 | local o = {} 84 | for k,v in ipairs(t) do 85 | o[k] = v.var .." ".. v.type 86 | end 87 | return "("..table.concat(o,",")..")" 88 | end 89 | 90 | function print_funcs(funcs) 91 | for k,v in ipairs(funcs) do 92 | print(k,v.tag,v.name,make_params(v.input),make_params(v.output)) 93 | end 94 | end 95 | 96 | function lower_title(s) 97 | return string.lower(string.sub(s,1,1))..string.sub(s,2) 98 | end 99 | 100 | function upper_title(s) 101 | return string.upper(string.sub(s,1,1))..string.sub(s,2) 102 | end 103 | 104 | --cdrv_type = "qtdrv" 105 | 106 | go_def = {} 107 | c_def = {} 108 | 109 | cdrv_func_go2c = function(s) return s end 110 | 111 | function begin_def() 112 | go_def.heads = {} 113 | go_def.drvenum = {} 114 | go_def.enums = {} 115 | go_def.defs = {} 116 | go_def.funcs = {} 117 | go_def.newobj = {} 118 | 119 | c_def.heads = {} 120 | c_def.include = {} 121 | c_def.drvenum = {} 122 | c_def.drvfunc = {} 123 | c_def._drvfunc = {} 124 | c_def.enums = {} 125 | c_def.funcs = {} 126 | 127 | go_def.heads[#go_def.heads+1] = [[ 128 | // Copyright 2012 visualfc . All rights reserved. 129 | // Use of this source code is governed by a BSD-style 130 | // license that can be found in the LICENSE file. 131 | ]] 132 | c_def.heads[#c_def.heads+1] = [[ 133 | /******************************************************************** 134 | ** Copyright 2012 visualfc . All rights reserved. 135 | ** 136 | ** This library is free software; you can redistribute it and/or 137 | ** modify it under the terms of the GNU Lesser General Public 138 | ** License as published by the Free Software Foundation; either 139 | ** version 2.1 of the License, or (at your option) any later version. 140 | ** 141 | ** This library is distributed in the hope that it will be useful, 142 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 143 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 144 | ** Lesser General Public License for more details. 145 | *********************************************************************/ 146 | ]] 147 | 148 | go_def.heads[#go_def.heads+1] = [[ 149 | package ui 150 | 151 | import ( 152 | "runtime" 153 | "unsafe" 154 | "image/color" 155 | ) 156 | ]] 157 | go_def.newobj[#go_def.newobj+1] = [[ 158 | func registerAllClass() { 159 | ]] 160 | 161 | go_def.drvenum[#go_def.drvenum+1] = "// drvclass enums" 162 | go_def.drvenum[#go_def.drvenum+1] = "const (" 163 | go_def.drvenum[#go_def.drvenum+1] = "\tCLASSID_NONE = iota" 164 | 165 | c_def.drvenum[#c_def.drvenum+1] = "// drvclass enums" 166 | c_def.drvenum[#c_def.drvenum+1] = "enum DRVCLASS_ENUM {" 167 | c_def.drvenum[#c_def.drvenum+1] = " DRVCLASS_NONE = 0," 168 | 169 | c_def.include[#c_def.include+1] = [[#include "cdrv.h"]] 170 | c_def.drvfunc[#c_def.drvfunc+1] = [[ 171 | typedef int (*DRV_CALLBACK)(void* fn, void *a1,void* a2,void* a3,void* a4); 172 | typedef int (*DRV_RESULT)(void* ch,int r); 173 | typedef int (*DRV_APPMAIN)(); 174 | typedef void (*UTF8_INFO_COPY)(void *info,const char *data, int size); 175 | 176 | static DRV_CALLBACK pfn_drv_callback; 177 | static DRV_RESULT pfn_drv_result; 178 | static DRV_APPMAIN pfn_drv_appmain; 179 | static UTF8_INFO_COPY pfn_utf8_info_copy; 180 | 181 | int drv_callback(void* fn, void *a1,void* a2,void* a3,void* a4) 182 | { 183 | return pfn_drv_callback(fn,a1,a2,a3,a4); 184 | } 185 | 186 | int drv_result(void* ch, int r) 187 | { 188 | return pfn_drv_result(ch,r); 189 | } 190 | 191 | int drv_appmain() 192 | { 193 | return pfn_drv_appmain(); 194 | } 195 | 196 | void utf8_info_copy(void *info, const char *data, int size) 197 | { 198 | pfn_utf8_info_copy(info,data,size); 199 | } 200 | 201 | int drv(int drvcls, int drvid, void *exp, void *a0, void* a1, void* a2, void* a3, void* a4, void* a5, void* a6) 202 | { 203 | switch(drvcls) { 204 | case -1: 205 | pfn_drv_callback = (DRV_CALLBACK)exp; 206 | return 1; 207 | case -2: 208 | pfn_drv_result = (DRV_RESULT)exp; 209 | return 1; 210 | case -3: 211 | pfn_utf8_info_copy = (UTF8_INFO_COPY)exp; 212 | return 1; 213 | case -4: 214 | pfn_drv_appmain = (DRV_APPMAIN)exp; 215 | return 1;]] 216 | c_def._drvfunc[#c_def._drvfunc+1] = [[ 217 | int _drv(int drvcls, int drvid, void *a0, void* a1, void* a2, void* a3, void* a4, void* a5, void* a6) 218 | { 219 | switch(drvcls) {]] 220 | 221 | end 222 | 223 | function end_def() 224 | go_def.drvenum[#go_def.drvenum+1] = ")" 225 | go_def.newobj[#go_def.newobj+1] = "}" 226 | c_def.drvenum[#c_def.drvenum+1] = " DRVCLASS_LAST" 227 | c_def.drvenum[#c_def.drvenum+1] = "};" 228 | c_def.drvfunc[#c_def.drvfunc+1] = [[ 229 | default: 230 | QMetaObject::invokeMethod(theApp,"drv", 231 | Q_ARG(int,drvcls), 232 | Q_ARG(int,drvid), 233 | Q_ARG(void*,exp), 234 | Q_ARG(void*,a0), 235 | Q_ARG(void*,a1), 236 | Q_ARG(void*,a2), 237 | Q_ARG(void*,a3), 238 | Q_ARG(void*,a4), 239 | Q_ARG(void*,a5), 240 | Q_ARG(void*,a6)); 241 | return 0; 242 | } 243 | return 1; 244 | }]] 245 | c_def._drvfunc[#c_def._drvfunc+1] = [[ 246 | default: 247 | return 0; 248 | } 249 | return 1; 250 | } 251 | ]] 252 | end 253 | 254 | function def(item) 255 | local go = {} 256 | local c = {} 257 | local name = item.name 258 | local base = item.base or "" 259 | local name_tag = string.upper(name) 260 | local name_cls 261 | local export = false 262 | if string.sub(name,1,1) == string.upper(string.sub(name,1,1)) then 263 | export = true 264 | end 265 | 266 | if export then 267 | name_cls = "CLASSID_"..string.upper(name) 268 | else 269 | name_cls = "_CLASSID_"..string.upper(name) 270 | end 271 | 272 | assert(item.funcs ~= nil,string.format("%s funcs not defined!",name)) 273 | 274 | local funcs = get_funcs(item.funcs) 275 | local cdrv = item[cdrv_type] 276 | assert(cdrv ~= nil,string.format("%s not defined!",cdrv_type)) 277 | local cself = "self." 278 | local cdrv_name = string.match(cdrv.name,"([%w_]*)%s*%*") 279 | if cdrv_name ~= nil then 280 | cdrv.name = cdrv_name 281 | cself = "self->" 282 | end 283 | 284 | go.enums = {} 285 | go.defs = {} 286 | go.funcs = {} 287 | go.setattr = {} 288 | go.getattr = {} 289 | 290 | c.enums = {} 291 | c.funcs = {} 292 | 293 | go_def.drvenum[#go_def.drvenum+1] = "\t"..name_cls 294 | c_def.drvenum[#c_def.drvenum+1] = " "..name_cls.."," 295 | 296 | go.enums[#go.enums+1] = string.format("// %s drvid enums",name_cls) 297 | go.enums[#go.enums+1] = "const (" 298 | go.enums[#go.enums+1] = string.format("\t_ID_%s = iota",name_tag.."_NONE") 299 | 300 | c.enums[#c.enums+1] = string.format("// %s drvid enums",name_cls) 301 | c.enums[#c.enums+1] = string.format("enum %s {","DRVID_"..name_tag.."_ENUM") 302 | c.enums[#c.enums+1] = string.format(" _ID_%s = 0,",name_tag.."_NONE") 303 | 304 | c.funcs[#c.funcs+1] = string.format([[ 305 | int drv_%s(int drvid, void *a0, void* a1, void* a2, void* a3, void* a4, void* a5, void* a6)]],string.lower(name)) 306 | c.funcs[#c.funcs+1] = "{" 307 | if cdrv.self ~= nil then 308 | c.funcs[#c.funcs+1] = cdrv.self 309 | elseif cself == "self->" then 310 | c.funcs[#c.funcs+1] = string.format([[ 311 | %s *self = (%s*)drvGetNative(a0);]],cdrv.name,cdrv.name) 312 | else 313 | c.funcs[#c.funcs+1] = string.format([[ 314 | %s self = drvGet%s(a0);]],cdrv.name,name) 315 | end 316 | 317 | c.funcs[#c.funcs+1] = " switch (drvid) {" 318 | 319 | local comment = string.format([[ 320 | // struct %s 321 | //]],name) 322 | if item.comment ~= nil then 323 | comment = comment .. "\n" .. get_comment(item.comment) 324 | end 325 | -- go struct def 326 | go.defs[#go.defs+1] = string.format([[ 327 | %s 328 | type %s struct { 329 | %s 330 | } 331 | ]],comment,name,base) 332 | go.defs[#go.defs+1] = string.format([[ 333 | func (p *%s) Name() string { 334 | return "%s" 335 | } 336 | ]],name,name) 337 | go.defs[#go.defs+1] = string.format([[ 338 | func (p *%s) String() string { 339 | return DumpObject(p) 340 | }]],name) 341 | 342 | go.setattr[#go.setattr+1] = string.format([[ 343 | func (p *%s) SetAttr(attr string, value interface{}) bool { 344 | switch attr {]],name) 345 | go.getattr[#go.getattr+1] = string.format([[ 346 | func (p *%s) Attr(attr string) interface{} { 347 | switch attr {]],name) 348 | 349 | if item.defs ~= nil then 350 | go.defs[#go.defs+1] = item.defs 351 | end 352 | -- funcs enums 353 | for k,v in ipairs(funcs) do 354 | local func = v.name 355 | local tag = v.tag 356 | local enum = "_ID_"..name_tag.."_"..string.upper(v.name) 357 | go.enums[#go.enums+1] = "\t"..enum 358 | c.enums[#c.enums+1] = " "..enum.."," 359 | local go_in = {} 360 | local go_out = {} 361 | local go_var = {} 362 | local go_var_ex = {} 363 | local go_body1 = {} 364 | local go_body2 = {} 365 | local c_in = {} 366 | local c_out = {} 367 | local go_in_type = "" 368 | local go_out_type = "" 369 | local index = 0 370 | for k,v in pairs(v.input) do 371 | index = index+1 372 | local var = v.var 373 | local type = v.type 374 | local _c_type = type 375 | local ptr,typ = string.match(type,"(%*)%s*(%w+)") 376 | if ptr ~= nil then 377 | _c_type = typ 378 | end 379 | local ar,typ = string.match(type,"(%[%])%s*(%w+)") 380 | if ar ~= nil then 381 | _c_type = typ .. "Array" 382 | end 383 | go_in[#go_in+1] = var.." "..type 384 | go_var[#go_var+1] = var 385 | go_in_type = v.type 386 | if type == "string" then 387 | go_var_ex[#go_var_ex+1] = "unsafe.Pointer((*string_info)(unsafe.Pointer(&"..var..")))" 388 | elseif type == "IWidget" or type == "ILayout" or type == "iobj" then 389 | go_var_ex[#go_var_ex+1] = "unsafe.Pointer("..var..".(iobj).info())" 390 | elseif type == "color.Color" then 391 | go_body1[#go_body1+1] = string.format("\tsh_%s := make_rgba(%s)",var,var) 392 | var = "sh_"..var 393 | go_var_ex[#go_var_ex+1] = "unsafe.Pointer(&"..var..")" 394 | elseif ar ~= nil then 395 | go_var_ex[#go_var_ex+1] = "unsafe.Pointer((*slice_info)(unsafe.Pointer(&"..var..")))" 396 | elseif ptr ~= nil then 397 | go_var_ex[#go_var_ex+1] = "unsafe.Pointer("..var..")" 398 | else 399 | go_var_ex[#go_var_ex+1] = "unsafe.Pointer(&"..var..")" 400 | end 401 | 402 | local c_type = "drvGet"..string.upper(string.sub(_c_type,1,1))..string.sub(_c_type,2,-1) 403 | if type == "iobj" then 404 | c_type = "drvGetNative" 405 | elseif type == "IWidget" then 406 | c_type = "drvGetWidget" 407 | elseif type == "ILayout" then 408 | c_type = "drvGetLayout" 409 | elseif type == "color.Color" then 410 | c_type = "drvGetColor" 411 | end 412 | c_in[#c_in+1] = c_type 413 | end 414 | for k,v in pairs(v.output) do 415 | index = index+1 416 | local var = v.var 417 | local type = v.type 418 | local _c_type = type 419 | local ptr,typ = string.match(type,"(%*)%s*(%w+)") 420 | if ptr ~= nil then 421 | _c_type = typ 422 | end 423 | local c_type = "drvSet"..string.upper(string.sub(_c_type,1,1))..string.sub(_c_type,2,-1) 424 | go_out[#go_out+1] = var.." "..type 425 | go_out_type = type 426 | if type == "string" then 427 | var = "sh_"..var 428 | go_body1[#go_body1+1] = string.format("\tvar %s utf8_info",var) 429 | go_body2[#go_body2+1] = string.format("\t%s = %s.String()",v.var,var) 430 | elseif type == "bool" then 431 | var = "b_"..var 432 | go_body1[#go_body1+1] = string.format("\tvar %s int",var) 433 | go_body2[#go_body2+1] = string.format("\t%s = %s != 0",v.var,var) 434 | elseif type == "color.Color" then 435 | var = "sh_"..var 436 | go_body1[#go_body1+1] = string.format("\tvar %s rgba",var) 437 | go_body2[#go_body2+1] = string.format("\t%s = %s",v.var,var) 438 | c_type = "drvSetColor" 439 | elseif type == "IObject" or 440 | type == "IWidget" or 441 | type == "ILayout" then 442 | var = "oi_"..var 443 | go_body1[#go_body1+1] = string.format("\tvar %s obj_info",var) 444 | go_body2[#go_body2+1] = string.format([[ 445 | if %s.native != 0 { 446 | item := FindObject(%s.native) 447 | if item != nil { 448 | %s = item.(%s) 449 | } 450 | }]],var,var,v.var,v.type) 451 | c_type = "drvSetHandle" 452 | elseif ptr then 453 | local id = "CLASSID_"..string.upper(_c_type) 454 | var = "oi_"..var 455 | go_body1[#go_body1+1] = string.format("\tvar %s obj_info",var) 456 | go_body2[#go_body2+1] = string.format([[ 457 | if %s.native != 0 { 458 | v := FindObject(%s.native) 459 | if v == nil { 460 | v = NewObjectWithNative(%s,%s.native) 461 | } 462 | if v != nil { 463 | %s = v.(%s) 464 | } 465 | }]],var,var,id,var,v.var,v.type) 466 | end 467 | go_var[#go_var+1] = "&"..var 468 | if string.match(var,"oi_") then 469 | go_var_ex[#go_var_ex+1] = "unsafe.Pointer(&"..var..")" 470 | elseif type == "string" then 471 | go_var_ex[#go_var_ex+1] = "unsafe.Pointer((*string_info)(unsafe.Pointer(&"..var..")))" 472 | elseif type == "iobj" then 473 | go_var_ex[#go_var_ex+1] = "unsafe.Pointer("..var..".info())" 474 | elseif _c_type == "iobj" and ptr ~= nil then 475 | go_var_ex[#go_var_ex+1] = "unsafe.Pointer((*"..var..").info())" 476 | elseif ar ~= nil then 477 | go_var_ex[#go_var_ex+1] = "unsafe.Pointer((*slice_info)(unsafe.Pointer(&"..var..")))" 478 | elseif ptr ~= nil then 479 | go_var_ex[#go_var_ex+1] = "unsafe.Pointer("..var..")" 480 | else 481 | go_var_ex[#go_var_ex+1] = "unsafe.Pointer(&"..var..")" 482 | end 483 | 484 | c_out[#c_out+1] = c_type 485 | end 486 | 487 | local go_head = string.format("func (p *%s) %s(%s)",name,func,table.concat(go_in,",")) 488 | if #go_out > 0 then 489 | go_head = go_head .. string.format("(%s)",table.concat(go_out,",")) 490 | end 491 | local go_new_head = nil 492 | local body = "" 493 | if tag == "+" then 494 | --"init and new" 495 | go_body1[#go_body1+1] = string.format("\tp.classid = %s",name_cls) 496 | if item.unmap then 497 | go_body2[#go_body2+1] = string.format("\truntime.SetFinalizer(p,(*%s).Close)",name) 498 | else 499 | go_body2[#go_body2+1] = string.format("\tInsertObject(p)") 500 | end 501 | go_head = go_head .. " *"..name 502 | local new = "new_" 503 | if export then 504 | new = "New" 505 | end 506 | go_new_head = "func "..string.gsub(func,"%w[%l]+",new..name,1) .. "("..table.concat(go_in,",") .. ") *"..name 507 | if export and func == "Init" and #v.input == 0 then 508 | go_def.newobj[#go_def.newobj+1] = string.format([[ 509 | RegisterClass(%q,%s,func() IObject { 510 | return New%s() 511 | })]],name,name_cls,name) 512 | go_def.newobj[#go_def.newobj+1] = string.format([[ 513 | RegisterClassNative(%s,func(native uintptr) IObject { 514 | obj := new(%s) 515 | obj.classid = %s 516 | obj.native = native 517 | InsertObject(obj) 518 | return obj 519 | })]],name_cls,name,name_cls,name) 520 | end 521 | elseif tag == "-" then 522 | -- "delete" 523 | go_head = go_head .. "(err error)" 524 | if item.unmap then 525 | go_body1[#go_body1+1] = [[ 526 | if p == nil || p.native == 0 { 527 | return 528 | }]] 529 | go_body2[#go_body2+1] = [[ 530 | p.native = 0 531 | runtime.SetFinalizer(p,nil)]] 532 | else 533 | go_body1[#go_body1+1] = [[ 534 | if p == nil || p.native == 0 { 535 | return 536 | }]] 537 | go_body2[#go_body2+1] = [[ 538 | RemoveObject(p.native) 539 | p.native = 0]] 540 | end 541 | elseif tag == "@" then 542 | -- "attribute" 543 | local set = string.match(func,"^Set(%u%w+)") 544 | if set ~= nil and #go_in == 1 then 545 | local attr = string.lower(set) 546 | go.setattr[#go.setattr+1] = string.format([[ 547 | case %q: 548 | if v, ok := value.(%s); ok { 549 | p.%s(v) 550 | return true 551 | } 552 | return false]],attr,go_in_type,func) 553 | elseif #go_out == 1 then 554 | local attr = string.lower(func) 555 | local is = string.match(func,"^Is(%u%w+)") 556 | if is ~= nil then 557 | attr = string.lower(is) 558 | else 559 | local has = string.match(func,"^Has(%u%w+)") 560 | if has ~= nil then 561 | attr = string.lower(has) 562 | end 563 | end 564 | go.getattr[#go.getattr+1] = string.format([[ 565 | case %q: 566 | return p.%s()]],attr,func) 567 | end 568 | elseif tag == "*" then 569 | -- "event" 570 | else 571 | -- "func" 572 | end 573 | 574 | if tag == "*" then 575 | if name == "app" then 576 | go_body = string.format("\t_drv_event(%s,%s,p",name_cls,enum) 577 | else 578 | go_body = string.format("\t_drv_event_ch(%s,%s,p",name_cls,enum) 579 | end 580 | elseif name == "app" then 581 | go_body = string.format("\t_drv(%s,%s,unsafe.Pointer(p.info())",name_cls,enum) 582 | else 583 | go_body = string.format("\t_drv_ch(%s,%s,unsafe.Pointer(p.info())",name_cls,enum) 584 | end 585 | 586 | 587 | while #go_var_ex < 9 do 588 | go_var_ex[#go_var_ex+1] = "nil" 589 | end 590 | 591 | if tag == "*" then 592 | go_body = go_body..","..table.concat(go_var,",") 593 | else 594 | go_body = go_body..","..table.concat(go_var_ex,",") 595 | end 596 | 597 | go_body = go_body..")" 598 | 599 | local go_func = {} 600 | go_func[#go_func+1] = go_head .. " {" 601 | if #go_body1 > 0 then 602 | go_func[#go_func+1] = table.concat(go_body1,"\n") 603 | end 604 | go_func[#go_func+1] = go_body 605 | if #go_body2 > 0 then 606 | go_func[#go_func+1] = table.concat(go_body2,"\n") 607 | end 608 | if tag == "+" then 609 | go_func[#go_func+1] = "\treturn p" 610 | else 611 | go_func[#go_func+1] = "\treturn" 612 | end 613 | go_func[#go_func+1] = "}" 614 | if go_new_head ~= nil then 615 | local go_new = {} 616 | go_new[#go_new+1] = go_new_head .. "{" 617 | go_new[#go_new+1] = string.format("\treturn new(%s).%s(%s)",name,func,table.concat(go_var,",")) 618 | go_new[#go_new+1] = "}" 619 | go.funcs[#go.funcs+1] = table.concat(go_new,"\n").."\n" 620 | end 621 | go.funcs[#go.funcs+1] = table.concat(go_func,"\n").."\n" 622 | --auto make cdrv[func] 623 | if cdrv[func] == nil then 624 | cdrv[func] = cdrv_func_go2c(func) 625 | end 626 | --assert(cdrv[func] ~= nil,string.format("cdrv <%s> class %s : %s not defined!",cdrv_type,name,func)) 627 | local cbody = cdrv[func] 628 | if string.find(cbody,"[%;%(%)]") == nil then 629 | if #c_out == 0 then 630 | local c_type = {} 631 | for k,v in ipairs(c_in) do 632 | c_type[#c_type+1] = v .. "(a"..k..")" 633 | end 634 | cbody = cself..cbody.."("..table.concat(c_type,",")..");" 635 | elseif #c_out == 1 then 636 | local c_type = {} 637 | for k,v in ipairs(c_in) do 638 | c_type[#c_type+1] = v .. "(a"..k..")" 639 | end 640 | cbody = c_out[1].."(a"..(#c_in+1)..","..cself..cbody.."("..table.concat(c_type,",").."));" 641 | end 642 | end 643 | c.funcs[#c.funcs+1] = string.format([[ 644 | case %s: {]],enum) 645 | --c.funcs[#c.funcs+1] = table.concat(c_var,"\n") 646 | local c_lines = get_lines(cbody) 647 | for k, v in ipairs(c_lines) do 648 | c.funcs[#c.funcs+1] = " "..v 649 | end 650 | c.funcs[#c.funcs+1] = [[ 651 | break; 652 | }]] 653 | end 654 | 655 | go.enums[#go.enums+1] = ")" 656 | go.setattr[#go.setattr+1] = string.format([[ 657 | default: 658 | return p.%s.SetAttr(attr,value) 659 | } 660 | return false 661 | }]],base) 662 | go.getattr[#go.getattr+1] = string.format([[ 663 | default: 664 | return p.%s.Attr(attr) 665 | } 666 | return nil 667 | }]],base) 668 | 669 | c.enums[#c.enums+1] = " _ID_"..name_tag.."_LAST" 670 | c.enums[#c.enums+1] = "};" 671 | 672 | if item.expands ~= nil then 673 | go.funcs[#go.funcs+1] = item.expands 674 | end 675 | 676 | c_def.enums[#c_def.enums+1] = table.concat(c.enums,"\n") 677 | if cdrv.inc ~= nil then 678 | c_def.include[#c_def.include+1] = "#include "..cdrv.inc 679 | end 680 | 681 | go_def.enums[#go_def.enums+1] = table.concat(go.enums,"\n") 682 | 683 | go_def.defs[#go_def.defs+1] = table.concat(go.defs,"\n") 684 | go_def.funcs[#go_def.funcs+1] = table.concat(go.defs,"\n") 685 | go_def.funcs[#go_def.funcs+1] = table.concat(go.setattr,"\n") 686 | go_def.funcs[#go_def.funcs+1] = table.concat(go.getattr,"\n") 687 | go_def.funcs[#go_def.funcs+1] = table.concat(go.funcs,"\n") 688 | 689 | c.funcs[#c.funcs+1] = [[ 690 | default: 691 | return 0; 692 | } 693 | return 1; 694 | } 695 | ]] 696 | c_def.funcs[#c_def.funcs+1] = table.concat(c.funcs,"\n") 697 | if item.sync then 698 | c_def.drvfunc[#c_def.drvfunc+1] = string.format([[ 699 | case %s: 700 | return drv_%s(drvid,a0,a1,a2,a3,a4,a5,a6);]],name_cls,string.lower(name)) 701 | end 702 | c_def._drvfunc[#c_def._drvfunc+1] = string.format([[ 703 | case %s: 704 | return drv_%s(drvid,a0,a1,a2,a3,a4,a5,a6);]],name_cls,string.lower(name)) 705 | end 706 | -------------------------------------------------------------------------------- /make/ui/action.lua: -------------------------------------------------------------------------------- 1 | module("action") 2 | 3 | name = "Action" 4 | base = "object" 5 | 6 | funcs = [[ 7 | + Init() 8 | + InitWithText(text string) 9 | - Close() 10 | @ SetText(text string) 11 | @ Text() (text string) 12 | @ SetIcon(icon *Icon) 13 | @ Icon() (icon *Icon) 14 | @ SetIconText(text string) 15 | @ IconText() (text string) 16 | @ SetToolTip(text string) 17 | @ ToolTip() (text string) 18 | @ SetFont(font *Font) 19 | @ Font() (font *Font) 20 | @ SetCheckable(b bool) 21 | @ IsCheckable() (b bool) 22 | @ SetChecked(b bool) 23 | @ IsChecked() (b bool) 24 | @ SetVisible(b bool) 25 | @ IsVisible() (b bool) 26 | * OnTriggered(fn func(bool)) 27 | ]] 28 | 29 | qtdrv = { 30 | inc = "", 31 | name = "QAction*", 32 | 33 | Init = [[ 34 | drvNewObj(a0, new QAction(qApp)); 35 | ]], 36 | 37 | InitWithText = [[ 38 | drvNewObj(a0, new QAction(drvGetString(a1),qApp)); 39 | ]], 40 | 41 | Close = [[ 42 | drvDelObj(a0,self); 43 | ]], 44 | 45 | SetText = "setText", 46 | Text = "text", 47 | SetIcon = "setIcon", 48 | Icon = "icon", 49 | SetIconText = "setIconText", 50 | IconText = "iconText", 51 | SetToolTip = "setToolTip", 52 | ToolTip = "toolTip", 53 | SetFont = "setFont", 54 | Font = "font", 55 | SetCheckable = "setCheckable", 56 | IsCheckable = "isCheckable", 57 | SetChecked = "setChecked", 58 | IsChecked = "isChecked", 59 | SetVisible = "setVisible", 60 | IsVisible = "isVisible", 61 | 62 | OnTriggered = [[ 63 | QObject::connect(self,SIGNAL(triggered(bool)),drvNewSignal(self,a1,a2),SLOT(call(bool))); 64 | ]] 65 | 66 | } 67 | -------------------------------------------------------------------------------- /make/ui/actiongroup.lua: -------------------------------------------------------------------------------- 1 | module("actiongroup") 2 | 3 | name = "ActionGroup" 4 | base = "object" 5 | 6 | funcs = [[ 7 | + Init() 8 | - Close() 9 | @ SetVisible(b bool) 10 | @ IsVisible() (b bool) 11 | @ SetEnabled(b bool) 12 | @ IsEnabled() (b bool) 13 | @ SetExclusive(b bool) 14 | @ IsExclusive() (b bool) 15 | AddAction(act *Action) 16 | RemoveAction(act *Action) 17 | * OnHovered(fn func(*Action)) 18 | * OnTriggered(fn func(*Action)) 19 | ]] 20 | 21 | qtdrv = { 22 | inc = "", 23 | name = "QActionGroup*", 24 | 25 | Init = [[ 26 | drvNewObj(a0, new QActionGroup(qApp)); 27 | ]], 28 | Close = [[ 29 | drvDelObj(a0,self); 30 | ]], 31 | 32 | OnHovered = [[ 33 | QObject::connect(self,SIGNAL(hovered(QAction*)),drvNewSignal(self,a1,a2),SLOT(call(QAction*))); 34 | ]], 35 | OnTriggered = [[ 36 | QObject::connect(self,SIGNAL(triggered(QAction*)),drvNewSignal(self,a1,a2),SLOT(call(QAction*))); 37 | ]] 38 | 39 | } 40 | -------------------------------------------------------------------------------- /make/ui/app.lua: -------------------------------------------------------------------------------- 1 | module("app") 2 | 3 | name = "app" 4 | base = "object" 5 | sync = true 6 | 7 | defs = [[ 8 | ]] 9 | 10 | funcs = [[ 11 | AppMain()(code int) 12 | Run() (code int) 13 | Exit(code int) 14 | @ SetFont(font *Font) 15 | @ Font() (font *Font) 16 | @ SetActiveWindow(widget IWidget) 17 | @ ActiveWindow() (widget IWidget) 18 | @ SetStyleSheet(style string) 19 | @ StyleSheet() (style string) 20 | CloseAllWindows() 21 | 22 | * onRemoveObject(fn func(uintptr)) 23 | ]] 24 | 25 | qtdrv = { 26 | inc = [["qtapp.h"]], 27 | name = "QtApp*", 28 | 29 | Init = [[ 30 | drvNewObj(a0, new QtApp); 31 | ]], 32 | Close = [[ 33 | drvDelObj(a0,self); 34 | ]], 35 | 36 | AppMain = [[ 37 | QtApp app; 38 | handle_head *head =(handle_head*)a0; 39 | head->native = &app; 40 | drvSetInt(a1,drv_appmain()); 41 | ]], 42 | 43 | Run = "exec", 44 | Exit = "exit", 45 | SetFont = "setFont", 46 | Font = "font", 47 | SetActiveWindow = "setActiveWindow", 48 | ActiveWindow = "activeWindow", 49 | CloseAllWindows = "closeAllWindows", 50 | 51 | onRemoveObject = [[ 52 | self->pfnDeleteObj = a1; 53 | ]], 54 | 55 | } 56 | 57 | wtldrv = { 58 | name = "CApp", 59 | Init = [[ 60 | _Module.Init(NULL,NULL); 61 | ]], 62 | Close = [[ 63 | _Module.Term(); 64 | ]], 65 | } -------------------------------------------------------------------------------- /make/ui/basebutton.lua: -------------------------------------------------------------------------------- 1 | module("basebutton") 2 | 3 | name = "baseButton" 4 | base = "Widget" 5 | 6 | funcs = [[ 7 | @ SetText(text string) 8 | @ Text() (text string) 9 | @ SetIcon(icon *Icon) 10 | @ Icon() (icon *Icon) 11 | @ SetIconSize(sz Size) 12 | @ IconSize() (sz Size) 13 | @ SetCheckable(b bool) 14 | @ IsCheckable() (b bool) 15 | @ SetDown(b bool) 16 | @ IsDown() (b bool) 17 | ]] 18 | 19 | qtdrv = { 20 | inc = "", 21 | name = "QAbstractButton *", 22 | 23 | SetText = "setText", 24 | Text = "text", 25 | SetIcon = "setIcon", 26 | Icon = "icon", 27 | SetIconSize = "setIconSize", 28 | IconSize = "iconSize", 29 | SetCheckable = "setCheckable", 30 | IsCheckable = "isCheckable", 31 | SetDown = "setDown", 32 | IsDown = "isDown", 33 | 34 | } 35 | -------------------------------------------------------------------------------- /make/ui/baselayout.lua: -------------------------------------------------------------------------------- 1 | module("baselayout") 2 | 3 | name = "baseLayout" 4 | base = "object" 5 | 6 | funcs = [[ 7 | @ SetSpacing(spac int) 8 | @ Spacing() (spac int) 9 | @ SetMargins(m Margins) 10 | @ Margins() (m Margins) 11 | @ SetMenuBar(widget IWidget) 12 | @ MenuBar() (widget IWidget) 13 | @ Count() (count int) 14 | AddLayout(layout ILayout) 15 | AddWidget(widget IWidget) 16 | RemoveWidget(widget IWidget) 17 | IndexOf(widget IWidget) (index int) 18 | ]] 19 | 20 | expands = [[ 21 | func (p *baseLayout) SetMargin(v int) { 22 | p.SetMargins(Mr(v,v,v,v)) 23 | } 24 | func (p *baseLayout) SetMarginsv(left,top,right,bottom int) { 25 | p.SetMargins(Mr(left,top,right,bottom)) 26 | } 27 | 28 | func (p *baseLayout) Marginsv() (int,int,int,int) { 29 | return p.Margins().Unpack() 30 | } 31 | ]] 32 | 33 | qtdrv = { 34 | inc = "", 35 | name = "QLayout *", 36 | 37 | AddLayout = "addItem", 38 | AddWidget = "addWidget", 39 | SetSpacing = "setSpacing", 40 | Spacing = "spacing", 41 | SetMargins = "setContentsMargins", 42 | Margins = "contentsMargins", 43 | SetMenuBar = "setMenuBar", 44 | MenuBar = "menuBar", 45 | } 46 | -------------------------------------------------------------------------------- /make/ui/baseslider.lua: -------------------------------------------------------------------------------- 1 | module("baseslider") 2 | 3 | name = "baseSlider" 4 | base = "Widget" 5 | 6 | funcs = [[ 7 | @ SetTracking(b bool) 8 | @ HasTracking() (b bool) 9 | @ SetMaximum(value int) 10 | @ Maximum() (value int) 11 | @ SetMinimum(value int) 12 | @ Minimum() (value int) 13 | @ SetOrientation(value Orientation) 14 | @ Orientation() (value Orientation) 15 | @ SetPageStep(value int) 16 | @ PageStep() (value int) 17 | @ SetSingleStep(value int) 18 | @ SingleStep() (value int) 19 | @ SetSliderDown(b bool) 20 | @ IsSliderDown() (b bool) 21 | @ SetSliderPosition(value int) 22 | @ SliderPosition() (value int) 23 | @ SetValue(value int) 24 | @ Value() (value int) 25 | SetRange(min int, max int) 26 | Range() (min int, max int) 27 | 28 | * OnValueChanged(fn func(int)) 29 | * OnSliderPressed(fn func()) 30 | * OnSliderReleased(fn func()) 31 | * OnSliderMoved(fn func(int)) 32 | ]] 33 | 34 | 35 | qtdrv = { 36 | inc = "", 37 | name = "QAbstractSlider *", 38 | 39 | SetTracking = "setTracking", 40 | HasTracking = "hasTracking", 41 | SetMaximum = "setMaximum", 42 | Maximum = "maximum", 43 | SetMinimum = "setMinimum", 44 | Minimum = "minimum", 45 | SetOrientation = "setOrientation", 46 | Orientation = "orientation", 47 | SetPageStep = "setPageStep", 48 | PageStep = "pageStep", 49 | SetSingleStep = "setSingleStep", 50 | SingleStep = "singleStep", 51 | SetSliderDown = "setSliderDown", 52 | IsSliderDown = "isSliderDown", 53 | SetSliderPosition = "setSliderPosition", 54 | SliderPosition = "sliderPosition", 55 | SetValue = "setValue", 56 | Value = "value", 57 | SetRange = "setRange", 58 | Range = [[ 59 | drvSetInt(a1,self->minimum()); 60 | drvSetInt(a2,self->maximum()); 61 | ]], 62 | 63 | OnValueChanged = [[ 64 | QObject::connect(self,SIGNAL(valueChanged(int)),drvNewSignal(self,a1,a2),SLOT(call(int))); 65 | ]], 66 | 67 | OnSliderPressed = [[ 68 | QObject::connect(self,SIGNAL(sliderPressed()),drvNewSignal(self,a1,a2),SLOT(call())); 69 | ]], 70 | OnSliderReleased = [[ 71 | QObject::connect(self,SIGNAL(sliderReleased()),drvNewSignal(self,a1,a2),SLOT(call())); 72 | ]], 73 | 74 | OnSliderMoved = [[ 75 | QObject::connect(self,SIGNAL(sliderMoved()),drvNewSignal(self,a1,a2),SLOT(call(int))); 76 | ]], 77 | 78 | } 79 | -------------------------------------------------------------------------------- /make/ui/boxlayout.lua: -------------------------------------------------------------------------------- 1 | module("boxlayout") 2 | 3 | name = "BoxLayout" 4 | base = "baseLayout" 5 | 6 | funcs = [[ 7 | + Init() 8 | - Close() 9 | @ SetOrientation(value Orientation) 10 | @ Orientation() (value Orientation) 11 | AddLayoutWith(layout ILayout, stetch int) 12 | AddWidgetWith(widget IWidget, stretch int, alignment Alignment) 13 | AddSpacing(size int) 14 | AddStretch(size int) 15 | ]] 16 | 17 | expands = [[ 18 | ]] 19 | 20 | qtdrv = { 21 | inc = "", 22 | name = "QBoxLayout *", 23 | 24 | Init = [[ 25 | drvNewObj(a0,new QBoxLayout(QBoxLayout::TopToBottom)); 26 | ]], 27 | 28 | Close = [[ 29 | drvDelObj(a0,self); 30 | ]], 31 | 32 | SetOrientation = [[ 33 | switch (drvGetInt(a1)) { 34 | case Qt::Horizontal: { 35 | self->setDirection(QBoxLayout::TopToBottom); 36 | break; 37 | } 38 | case Qt::Vertical: { 39 | self->setDirection(QBoxLayout::LeftToRight); 40 | break; 41 | } 42 | } 43 | ]], 44 | Orientation = [[ 45 | switch((int)self->direction()) { 46 | case QBoxLayout::TopToBottom: { 47 | drvSetInt(a1,Qt::Horizontal); 48 | break; 49 | } 50 | case QBoxLayout::LeftToRight: { 51 | drvSetInt(a1,Qt::Vertical); 52 | break; 53 | } 54 | } 55 | ]], 56 | AddLayoutWith = [[ 57 | self->addLayout((QLayout*)drvGetNative(a1),drvGetInt(a2)); 58 | ]], 59 | AddWidgetWith = [[ 60 | self->addWidget((QWidget*)drvGetNative(a1),drvGetInt(a2),Qt::Alignment(drvGetInt(a3))); 61 | ]], 62 | AddSpacing = "addSpacing", 63 | AddStretch = "addStretch", 64 | } 65 | -------------------------------------------------------------------------------- /make/ui/brush.lua: -------------------------------------------------------------------------------- 1 | module("brush") 2 | 3 | name = "Brush" 4 | base = "object" 5 | 6 | funcs = [[ 7 | + Init() 8 | - Close() 9 | @ SetColor(clr color.Color) 10 | @ Color() (clr color.Color) 11 | @ SetStyle(style BrushStyle) 12 | @ Style() (style BrushStyle) 13 | ]] 14 | 15 | qtdrv = { 16 | inc = "", 17 | name = "QBrush*", 18 | 19 | Init = [[ 20 | drvSetBrush(a0, QBrush()); 21 | ]], 22 | Close = [[ 23 | drvDelBrush(a0,self); 24 | ]], 25 | SetColor = "setColor", 26 | Color = "color", 27 | SetStyle = [[ 28 | self->setStyle((Qt::BrushStyle)drvGetInt(a1)); 29 | ]], 30 | Style = [[ 31 | drvSetInt(a1,self->style()); 32 | ]], 33 | 34 | } -------------------------------------------------------------------------------- /make/ui/button.lua: -------------------------------------------------------------------------------- 1 | module("button") 2 | 3 | name = "Button" 4 | base = "baseButton" 5 | 6 | funcs = [[ 7 | + Init() 8 | + InitWithText(text string) 9 | @ SetFlat(b bool) 10 | @ IsFlat()(b bool) 11 | @ SetDefault(b bool) 12 | @ IsDefault()(b bool) 13 | @ SetMenu(menu *Menu) 14 | @ Menu()(menu *Menu) 15 | * OnClicked(fn func()) 16 | ]] 17 | 18 | 19 | qtdrv = { 20 | inc = "", 21 | name = "QPushButton *", 22 | 23 | Init = [[ 24 | drvNewObj(a0,new QPushButton); 25 | ]], 26 | 27 | InitWithText = [[ 28 | drvNewObj(a0,new QPushButton(drvGetString(a1))); 29 | ]], 30 | 31 | SetFlat ="setFlat", 32 | IsFlat = "isFlat", 33 | SetDefault = "setDefault", 34 | IsDefault = "isDefault", 35 | SetMenu = "setMenu", 36 | Menu = "menu", 37 | 38 | OnClicked = [[ 39 | QObject::connect(self,SIGNAL(clicked()),drvNewSignal(self,a1,a2),SLOT(call())); 40 | ]], 41 | 42 | } 43 | -------------------------------------------------------------------------------- /make/ui/checkbox.lua: -------------------------------------------------------------------------------- 1 | module("checkbox") 2 | 3 | name = "CheckBox" 4 | base = "baseButton" 5 | 6 | funcs = [[ 7 | + Init() 8 | + InitWithText(text string) 9 | @ SetCheck(state int) 10 | @ Check() (state int) 11 | @ SetTristate(b bool) 12 | @ IsTristate() (b bool) 13 | 14 | * OnStateChanged(fn func(int)) 15 | ]] 16 | 17 | 18 | qtdrv = { 19 | inc = "", 20 | name = "QCheckBox *", 21 | 22 | Init = [[ 23 | drvNewObj(a0,new QCheckBox); 24 | ]], 25 | 26 | InitWithText = [[ 27 | drvNewObj(a0,new QCheckBox(drvGetString(a1))); 28 | ]], 29 | 30 | SetCheck = [[ 31 | self->setCheckState((Qt::CheckState)drvGetInt(a1)); 32 | ]], 33 | 34 | Check = [[ 35 | drvSetInt(a1,self->checkState()); 36 | ]], 37 | 38 | SetTristate = "setTristate", 39 | IsTristate = "isTristate", 40 | 41 | OnStateChanged = [[ 42 | QObject::connect(self,SIGNAL(stateChanged(int)),drvNewSignal(self,a1,a2),SLOT(call(int))); 43 | ]] 44 | 45 | } 46 | -------------------------------------------------------------------------------- /make/ui/combobox.lua: -------------------------------------------------------------------------------- 1 | module("combobox") 2 | 3 | name = "ComboBox" 4 | base = "Widget" 5 | 6 | funcs = [[ 7 | + Init() 8 | 9 | @ Count() (count int) 10 | @ SetCurrentIndex(index int) 11 | @ CurrentIndex() (index int) 12 | @ CurrentText() (text string) 13 | @ SetEditable(b bool) 14 | @ IsEditable() (b bool) 15 | @ SetMaxCount(count int) 16 | @ MaxCount() (count int) 17 | @ SetMaxVisibleItems(max int) 18 | @ MaxVisibleItems() (max int) 19 | @ SetMinimumContentsLength(characters int) 20 | @ MinimunContentsLenght() (characters int) 21 | AddItem(text string) 22 | InsertItem(index int, text string) 23 | RemoveItem(index int) 24 | ItemText(index int) (text string) 25 | 26 | * OnCurrentIndexChanged(fn func(int)) 27 | ]] 28 | 29 | 30 | qtdrv = { 31 | inc = "", 32 | name = "QComboBox *", 33 | 34 | Init = [[ 35 | drvNewObj(a0,new QComboBox); 36 | ]], 37 | Count = "count", 38 | SetCurrentIndex = "setCurrentIndex", 39 | CurrentIndex = "currentIndex", 40 | CurrentText = "currentText", 41 | SetEditable = "setEditable", 42 | IsEditable = "isEditable", 43 | SetMaxCount = "setMaxCount", 44 | MaxCount = "maxCount", 45 | SetMaxVisibleItems = "setMaxVisibleItems", 46 | MaxVisibleItems = "maxVisibleItems", 47 | SetMinimumContentsLength = "setMinimumContentsLength", 48 | MinimunContentsLenght = "minimumContentsLength", 49 | AddItem = "addItem", 50 | InsertItem = "insertItem", 51 | RemoveItem = "removeItem", 52 | ItemText = "itemText", 53 | 54 | OnCurrentIndexChanged = [[ 55 | QObject::connect(self,SIGNAL(currentIndexChanged(int)),drvNewSignal(self,a1,a2),SLOT(call(int))); 56 | ]] 57 | 58 | } 59 | -------------------------------------------------------------------------------- /make/ui/dial.lua: -------------------------------------------------------------------------------- 1 | module("dial") 2 | 3 | name = "Dial" 4 | base = "baseSlider" 5 | 6 | funcs = [[ 7 | + Init() 8 | @ NotchSize() (size int) 9 | @ SetNotchTarget(value float64) 10 | @ NotchTarget() (value float64) 11 | @ SetNotchesVisible(b bool) 12 | @ NotchesVisible() (b bool) 13 | @ SetWrapping(b bool) 14 | @ Wrapping() (b bool) 15 | ]] 16 | 17 | qtdrv = { 18 | inc = "", 19 | name = "QDial *", 20 | 21 | Init = [[ 22 | drvNewObj(a0,new QDial); 23 | ]], 24 | 25 | NotchSize = "notchSize", 26 | SetNotchTarget = "setNotchTarget", 27 | NotchTarget = "notchTarget", 28 | SetNotchesVisible = "setNotchesVisible", 29 | NotchesVisible = "notchesVisible", 30 | SetWrapping = "setWrapping", 31 | Wrapping = "wrapping", 32 | 33 | } -------------------------------------------------------------------------------- /make/ui/dialog.lua: -------------------------------------------------------------------------------- 1 | module("dialog") 2 | 3 | name = "Dialog" 4 | base = "Widget" 5 | 6 | funcs = [[ 7 | + Init() 8 | 9 | @ SetModal(b bool) 10 | @ IsModal()(b bool) 11 | @ SetResult(r int) 12 | @ Result() (r int) 13 | Open() 14 | Exec()(r int) 15 | Done(r int) 16 | Accept() 17 | Reject() 18 | 19 | * OnAccepted(fn func()) 20 | * OnRejected(fn func()) 21 | ]] 22 | 23 | qtdrv = { 24 | inc = "", 25 | name = "QDialog *", 26 | 27 | Init = [[ 28 | drvNewObj(a0,new QDialog); 29 | ]], 30 | 31 | SetModal = "setModal", 32 | IsModal = "isModal", 33 | SetResult = "setResult", 34 | Result = "result", 35 | Open = "open", 36 | Exec = "exec", 37 | Done = "done", 38 | Accept = "accept", 39 | Reject = "reject", 40 | 41 | OnAccepted = [[ 42 | QObject::connect(self,SIGNAL(acceped()),drvNewSignal(self,a1,a2),SLOT(call())); 43 | ]], 44 | 45 | OnRejected = [[ 46 | QObject::connect(self,SIGNAL(rejected()),drvNewSignal(self,a1,a2),SLOT(call())); 47 | ]], 48 | 49 | } 50 | -------------------------------------------------------------------------------- /make/ui/dockwidget.lua: -------------------------------------------------------------------------------- 1 | module("dockwidget") 2 | 3 | name = "DockWidget" 4 | base = "Widget" 5 | 6 | funcs = [[ 7 | + Init() 8 | + InitWithTitle(title string) 9 | @ SetDock(widget IWidget) 10 | @ Dock() (widget IWidget) 11 | @ SetTitleBar(widget IWidget) 12 | @ TitleBar() (widget IWidget) 13 | @ SetFloating(b bool) 14 | @ IsFloating() (b bool) 15 | * OnVisibilityChanged(fn func(bool)) 16 | ]] 17 | 18 | qtdrv = { 19 | inc = "", 20 | name = "QDockWidget *", 21 | 22 | Init = [[ 23 | drvNewObj(a0,new QDockWidget,true,false); 24 | ]], 25 | InitWithTitle = [[ 26 | drvNewObj(a0,new QDockWidget(drvGetString(a1)),true,false); 27 | ]], 28 | 29 | SetDock = "setWidget", 30 | Dock = "widget", 31 | SetTitleBar = "setTitleBarWidget", 32 | TitleBar = "titleBarWidget", 33 | SetFloating = "setFloating", 34 | IsFloating = "isFloating", 35 | 36 | OnVisibilityChanged = [[ 37 | QObject::connect(self,SIGNAL(visibilityChanged(bool)),drvNewSignal(self,a1,a2),SLOT(call(bool))); 38 | ]] 39 | } 40 | -------------------------------------------------------------------------------- /make/ui/font.lua: -------------------------------------------------------------------------------- 1 | module("font") 2 | 3 | name = "Font" 4 | base = "object" 5 | 6 | funcs = [[ 7 | + Init() 8 | + InitWith(family string, size int, weight int) 9 | - Close() 10 | @ SetFamily(text string) 11 | @ Family() (text string) 12 | @ SetPointSize(size int) 13 | @ PointSize() (size int) 14 | @ SetPointSizeF(size float64) 15 | @ PointSizeF() (size float64) 16 | @ SetBold(b bool) 17 | @ Bold() (b bool) 18 | @ SetItalic(b bool) 19 | @ Italic() (b bool) 20 | @ SetKerning(b bool) 21 | @ Kerning() (b bool) 22 | @ SetLetterSpacing(typ int, spacing float64) 23 | @ LetterSpacing() (typ int, spacing float64) 24 | @ SetOverline(b bool) 25 | @ Overline() (b bool) 26 | @ SetPixelSize(size int) 27 | @ PixelSize() (size int) 28 | @ SetRawMode(b bool) 29 | @ RawMode() (b bool) 30 | @ SetRawName(name string) 31 | @ RawName() (name string) 32 | @ SetWeight(weight int) 33 | @ Weight() (weight int) 34 | @ SetFixedPitch(b bool) 35 | @ FixedPitch() (b bool) 36 | @ SetStretch(factor int) 37 | @ Stretch() (factor int) 38 | @ SetStrikeOut(b bool) 39 | @ StrikeOut() (b bool) 40 | @ SetUnderline(b bool) 41 | @ Underline() (b bool) 42 | 43 | ]] 44 | 45 | qtdrv = { 46 | inc = "", 47 | name = "QFont*", 48 | 49 | Init = [[ 50 | drvSetFont(a0,QFont()); 51 | ]], 52 | 53 | InitWith = [[ 54 | drvSetFont(a0,QFont(drvGetString(a1),drvGetInt(a2),drvGetInt(a3))); 55 | ]], 56 | 57 | Close = [[ 58 | drvDelFont(a0,self); 59 | ]], 60 | 61 | SetFamily = "setFamily", 62 | Family = "family", 63 | SetPointSize = "setPointSize", 64 | PointSize = "pointSize", 65 | SetPointSizeF = "setPointSizeF", 66 | PointSizeF = "pointSizeF", 67 | SetBold = "setBold", 68 | Bold = "bold", 69 | SetItalic = "setItalic", 70 | Italic = "italic", 71 | SetKerning = "setKerning", 72 | Kerning = "kerning", 73 | SetLetterSpacing = [[ 74 | self->setLetterSpacing((QFont::SpacingType)drvGetInt(a1),drvGetFloat64(a2)); 75 | ]], 76 | LetterSpacing = [[ 77 | drvSetInt(a1,self->letterSpacing()); 78 | drvSetInt(a2,self->letterSpacingType()); 79 | ]], 80 | SetOverline = "setOverline", 81 | Overline = "overline", 82 | SetPixelSize = "setPixelSize", 83 | PixelSize = "pixelSize", 84 | SetRawMode = "setRawMode", 85 | RawMode = "rawMode", 86 | SetRawName = "setRawName", 87 | RawName = "rawName", 88 | SetWeight = "setWeight", 89 | Weight = "weight", 90 | SetFixedPitch = "setFixedPitch", 91 | FixedPitch = "fixedPitch", 92 | SetStretch = "setStretch", 93 | Stretch = "stretch", 94 | SetStrikeOut = "setStrikeOut", 95 | StrikeOut = "strikeOut", 96 | SetUnderline = "setUnderline", 97 | Underline = "underline", 98 | 99 | } -------------------------------------------------------------------------------- /make/ui/frame.lua: -------------------------------------------------------------------------------- 1 | module("frame") 2 | 3 | name = "Frame" 4 | base = "Widget" 5 | 6 | funcs = [[ 7 | + Init() 8 | @ SetFrameStyle(style int) 9 | @ FrameStyle() (style int) 10 | @ SetFrameRect(rc Rect) 11 | @ FrameRect()(rc Rect) 12 | ]] 13 | 14 | expands = [[ 15 | func (p *Frame) SetFrameRectv(x,y,width,height int) { 16 | p.SetFrameRect(Rc(x,y,width,height)) 17 | } 18 | 19 | func (p *Frame) FrameRectv() (int,int,int,int) { 20 | return p.FrameRect().Unpack() 21 | } 22 | ]] 23 | 24 | 25 | qtdrv = { 26 | inc = "", 27 | name = "QFrame *", 28 | 29 | Init = [[ 30 | drvNewObj(a0,new QFrame); 31 | ]], 32 | 33 | SetFrameStyle = "setFrameStyle", 34 | FrameStyle = "frameStyle", 35 | SetFrameRect = "setFrameRect", 36 | FrameRect = "frameRect", 37 | 38 | } 39 | -------------------------------------------------------------------------------- /make/ui/groupbox.lua: -------------------------------------------------------------------------------- 1 | module("groupbox") 2 | 3 | name = "GroupBox" 4 | base = "Widget" 5 | 6 | funcs = [[ 7 | + Init() 8 | + InitWithTitle(text string) 9 | @ SetTitle(text string) 10 | @ Title() (text string) 11 | ]] 12 | 13 | 14 | qtdrv = { 15 | inc = "", 16 | name = "QGroupBox *", 17 | 18 | Init = [[ 19 | drvNewObj(a0,new QGroupBox); 20 | ]], 21 | 22 | InitWithTitle = [[ 23 | drvNewObj(a0, new QGroupBox(drvGetString(a1))); 24 | ]], 25 | 26 | SetTitle = "setTitle", 27 | Title = "title", 28 | 29 | } 30 | -------------------------------------------------------------------------------- /make/ui/hboxlayout.lua: -------------------------------------------------------------------------------- 1 | module("hboxlayout") 2 | 3 | name = "HBoxLayout" 4 | base = "BoxLayout" 5 | 6 | 7 | funcs = [[ 8 | +Init() 9 | ]] 10 | 11 | qtdrv = { 12 | inc = "", 13 | name = "QHBoxLayout *", 14 | 15 | Init = [[ 16 | drvNewObj(a0,new QHBoxLayout); 17 | ]], 18 | 19 | } -------------------------------------------------------------------------------- /make/ui/icon.lua: -------------------------------------------------------------------------------- 1 | module("icon") 2 | 3 | name = "Icon" 4 | base = "object" 5 | 6 | funcs = [[ 7 | + Init() 8 | + InitWithFile(name string) 9 | + InitWithPixmap(pixmap *Pixmap) 10 | - Close() 11 | ]] 12 | 13 | qtdrv = { 14 | inc = "", 15 | name = "QIcon*", 16 | 17 | Init = [[ 18 | drvSetIcon(a0, QIcon()); 19 | ]], 20 | InitWithFile = [[ 21 | drvSetIcon(a0, QIcon(drvGetString(a1))); 22 | ]], 23 | InitWithPixmap = [[ 24 | drvSetIcon(a0, QIcon(drvGetPixmap(a1))); 25 | ]], 26 | Close = [[ 27 | drvDelIcon(a0,self); 28 | ]], 29 | 30 | } -------------------------------------------------------------------------------- /make/ui/image.lua: -------------------------------------------------------------------------------- 1 | module("image") 2 | 3 | name = "Image" 4 | base = "object" 5 | 6 | funcs = [[ 7 | + Init() 8 | + InitWithFile(name string) 9 | + InitWithSize(width int, height int) 10 | - Close() 11 | @ Depth() (n int) 12 | @ Size() (sz Size) 13 | @ Rect() (rc Rect) 14 | Fill(color uint) 15 | 16 | ]] 17 | 18 | 19 | qtdrv = { 20 | inc = "", 21 | name = "QImage *", 22 | 23 | Init = [[ 24 | drvSetImage(a0, QImage()); 25 | ]], 26 | InitWithFile = [[ 27 | drvSetImage(a0, QImage(drvGetString(a1))); 28 | ]], 29 | InitWithSize = [[ 30 | drvSetImage(a0, QImage(drvGetInt(a1),drvGetInt(a2),QImage::Format_ARGB32_Premultiplied)); 31 | ]], 32 | Close = [[ 33 | drvDelImage(a0,self); 34 | ]], 35 | 36 | Depth = "depth", 37 | Size = "size", 38 | Rect = "rect", 39 | Fill = "fill", 40 | } 41 | -------------------------------------------------------------------------------- /make/ui/label.lua: -------------------------------------------------------------------------------- 1 | module("label") 2 | 3 | name = "Label" 4 | base = "Frame" 5 | 6 | funcs = [[ 7 | + Init() 8 | + InitWithText(text string) 9 | + InitWithPixmap(pixmap *Pixmap) 10 | @ SetText(text string) 11 | @ Text() (text string) 12 | @ SetWordWrap(b bool) 13 | @ WordWrap() (b bool) 14 | @ SetTextFormat(format int) 15 | @ TextFormat() (format int) 16 | @ SetPixmap(pixmap *Pixmap) 17 | @ Pixmap() (pixmap *Pixmap) 18 | * OnLinkActivated(fn func(string)) 19 | ]] 20 | 21 | 22 | qtdrv = { 23 | inc = "", 24 | name = "QLabel *", 25 | 26 | Init = [[ 27 | drvNewObj(a0,new QLabel); 28 | ]], 29 | InitWithText = [[ 30 | drvNewObj(a0, new QLabel(drvGetString(a1))); 31 | ]], 32 | InitWithPixmap = [[ 33 | QLabel *label = new QLabel; 34 | label->setPixmap(drvGetPixmap(a1)); 35 | drvNewObj(a0,label); 36 | ]], 37 | 38 | SetText = "setText", 39 | Text = "text", 40 | SetWordWrap = "setWordWrap", 41 | WordWrap = "wordWrap", 42 | SetTextFormat = [[ 43 | self->setTextFormat((Qt::TextFormat)drvGetInt(a1)); 44 | ]], 45 | TextFormat = [[ 46 | drvSetInt(a1,self->textFormat()); 47 | ]], 48 | SetPixmap = "setPixmap", 49 | Pixmap = "pixmap", 50 | 51 | OnLinkActivated = [[ 52 | QObject::connect(self,SIGNAL(linkActivated(QString)),drvNewSignal(self,a1,a2),SLOT(call(QString))); 53 | ]], 54 | 55 | } 56 | -------------------------------------------------------------------------------- /make/ui/lineedit.lua: -------------------------------------------------------------------------------- 1 | module("lineedit") 2 | 3 | name = "LineEdit" 4 | base = "Widget" 5 | 6 | comment = [[ 7 | 8 | InputMask: 9 | 10 | A ASCII alphabetic character required. A-Z, a-z. 11 | a ASCII alphabetic character permitted but not required. 12 | N ASCII alphanumeric character required. A-Z, a-z, 0-9. 13 | n ASCII alphanumeric character permitted but not required. 14 | X Any character required. 15 | x Any character permitted but not required. 16 | 9 ASCII digit required. 0-9. 17 | 0 ASCII digit permitted but not required. 18 | D ASCII digit required. 1-9. 19 | d ASCII digit permitted but not required (1-9). 20 | # ASCII digit or plus/minus sign permitted but not required. 21 | H Hexadecimal character required. A-F, a-f, 0-9. 22 | h Hexadecimal character permitted but not required. 23 | B Binary character required. 0-1. 24 | b Binary character permitted but not required. 25 | > All following alphabetic characters are uppercased. 26 | < All following alphabetic characters are lowercased. 27 | ! Switch off case conversion. 28 | \ Use \ to escape the special characters listed above to use them as separators. 29 | 30 | InputMask Example: 31 | 000.000.000.000;_ IP address; blanks are _. 32 | HH:HH:HH:HH:HH:HH;_ MAC address 33 | 0000-00-00 ISO Date; blanks are space 34 | >AAAAA-AAAAA-AAAAA-AAAAA-AAAAA;# License number; blanks are - and all (alphabetic) characters are converted to uppercase. 35 | 36 | ]] 37 | 38 | funcs = [[ 39 | + Init() 40 | + InitWithText(text string) 41 | @ SetText(text string) 42 | @ Text() (text string) 43 | @ SetInputMask(text string) 44 | @ InputMask() (text string) 45 | @ SetAlignment(value Alignment) 46 | @ Alignment() (value Alignment) 47 | @ SetCursorPos(pos int) 48 | @ CursorPos() (pos int) 49 | @ SetDragEnabled(b bool) 50 | @ DragEnabled() (b bool) 51 | @ SetReadOnly(b bool) 52 | @ IsReadOnly() (b bool) 53 | @ SetFrame(b bool) 54 | @ HasFrame() (b bool) 55 | @ IsRedoAvailable() (b bool) 56 | @ HasSelected() (b bool) 57 | @ SelectedText() (text string) 58 | @ SelStart() (start int) 59 | SetSel(start int,length int) 60 | CancelSel() 61 | SelectAll() 62 | Copy() 63 | Cut() 64 | Paste() 65 | Redo() 66 | Undo() 67 | Clear() 68 | 69 | * OnTextChanged(fn func(string)) 70 | * OnEditingFinished(fn func()) 71 | * OnReturnPressed(fn func()) 72 | ]] 73 | 74 | 75 | qtdrv = { 76 | inc = "", 77 | name = "QLineEdit *", 78 | 79 | Init = [[ 80 | drvNewObj(a0,new QLineEdit); 81 | ]], 82 | InitWithText = [[ 83 | drvNewObj(a0, new QLineEdit(drvGetString(a1))); 84 | ]], 85 | 86 | SetText = "setText", 87 | Text = "text", 88 | SetInputMask = "setInputMask", 89 | InputMask = "inputMask", 90 | SetAlignment = "setAlignment", 91 | Alignment = "alignment", 92 | SetCursorPos = "setCursorPosition", 93 | CursorPos = "cursorPosition", 94 | SetDragEnabled = "setDragEnabled", 95 | DragEnabled = "dragEnabled", 96 | SetReadOnly = "setReadOnly", 97 | IsReadOnly = "isReadOnly", 98 | SetFrame = "setFrame", 99 | HasFrame = "hasFrame", 100 | IsRedoAvailable = "isRedoAvailable", 101 | HasSelected = "hasSelectedText", 102 | SelectedText = "selectedText", 103 | SelStart = "selectionStart", 104 | SetSel = "setSelection", 105 | CancelSel = "deselect", 106 | SelectAll = "selectAll", 107 | Copy = "copy", 108 | Cut = "cut", 109 | Paste = "paste", 110 | Redo = "redo", 111 | Undo = "undo", 112 | Clear = "clear", 113 | 114 | OnTextChanged = [[ 115 | QObject::connect(self,SIGNAL(textChanged(QString)),drvNewSignal(self,a1,a2),SLOT(call(QString))); 116 | ]], 117 | 118 | OnEditingFinished = [[ 119 | QObject::connect(self,SIGNAL(editingFinished(QString)),drvNewSignal(self,a1,a2),SLOT(call(QString))); 120 | ]], 121 | 122 | OnReturnPressed = [[ 123 | QObject::connect(self,SIGNAL(returnPressed(QString)),drvNewSignal(self,a1,a2),SLOT(call(QString))); 124 | ]], 125 | 126 | } 127 | -------------------------------------------------------------------------------- /make/ui/listwidget.lua: -------------------------------------------------------------------------------- 1 | module("listwidget") 2 | 3 | name = "ListWidget" 4 | base = "Widget" 5 | 6 | funcs = [[ 7 | + Init() 8 | @ Count() (count int) 9 | @ SetCurrentItem(item *ListWidgetItem) 10 | @ CurrentItem() (item *ListWidgetItem) 11 | @ SetCurrentRow(row int) 12 | @ CurrentRow() (row int) 13 | AddItem(item *ListWidgetItem) 14 | InsertItem(index int,item *ListWidgetItem) 15 | EditItem(item *ListWidgetItem) 16 | TakeItem(row int) (item *ListWidgetItem) 17 | Item(row int) (item *ListWidgetItem) 18 | Clear() 19 | * OnCurrentItemChanged(fn func(*ListWidgetItem,*ListWidgetItem)) 20 | * OnCurrentRowChanged(fn func(int)) 21 | * OnItemActivated(fn func(*ListWidgetItem)) 22 | * OnItemChanged(fn func(*ListWidgetItem)) 23 | * OnItemClicked(fn func(*ListWidgetItem)) 24 | * OnItemDoubleClicked(fn func(*ListWidgetItem)) 25 | * OnItemEntered(fn func(*ListWidgetItem)) 26 | * OnItemPressed(fn func(*ListWidgetItem)) 27 | * OnItemSelectionChanged(fn func()) 28 | ]] 29 | 30 | qtdrv = { 31 | inc = "", 32 | name = "QListWidget *", 33 | 34 | Init = [[ 35 | drvNewObj(a0,new QListWidget); 36 | ]], 37 | OnCurrentItemChanged = [[ 38 | QObject::connect(self,SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)),drvNewSignal(self,a1,a2),SLOT(call(QListWidgetItem*,QListWidgetItem*))); 39 | ]], 40 | OnCurrentRowChanged = [[ 41 | QObject::connect(self,SIGNAL(currentRowChanged(int)),drvNewSignal(self,a1,a2),SLOT(call(int))); 42 | ]], 43 | OnItemActivated = [[ 44 | QObject::connect(self,SIGNAL(itemActivated(QListWidgetItem*)),drvNewSignal(self,a1,a2),SLOT(call(QListWidgetItem*))); 45 | ]], 46 | OnItemChanged = [[ 47 | QObject::connect(self,SIGNAL(itemChanged(QListWidgetItem*)),drvNewSignal(self,a1,a2),SLOT(call(QListWidgetItem*))); 48 | ]], 49 | OnItemClicked = [[ 50 | QObject::connect(self,SIGNAL(itemClicked(QListWidgetItem*)),drvNewSignal(self,a1,a2),SLOT(call(QListWidgetItem*))); 51 | ]], 52 | OnItemDoubleClicked = [[ 53 | QObject::connect(self,SIGNAL(itemDoubleClicked(QListWidgetItem*)),drvNewSignal(self,a1,a2),SLOT(call(QListWidgetItem*))); 54 | ]], 55 | OnItemEntered = [[ 56 | QObject::connect(self,SIGNAL(itemEntered(QListWidgetItem*)),drvNewSignal(self,a1,a2),SLOT(call(QListWidgetItem*))); 57 | ]], 58 | OnItemPressed = [[ 59 | QObject::connect(self,SIGNAL(itemPressed(QListWidgetItem*)),drvNewSignal(self,a1,a2),SLOT(call(QListWidgetItem*))); 60 | ]], 61 | OnItemSelectionChanged = [[ 62 | QObject::connect(self,SIGNAL(itemSelectionChanged(QListWidgetItem*)),drvNewSignal(self,a1,a2),SLOT(call(QListWidgetItem*))); 63 | ]], 64 | } 65 | -------------------------------------------------------------------------------- /make/ui/listwidgetitem.lua: -------------------------------------------------------------------------------- 1 | module("listwidgetitem") 2 | 3 | name = "ListWidgetItem" 4 | base = "object" 5 | 6 | funcs = [[ 7 | + Init() 8 | + InitWithText(text string) 9 | - Close() 10 | @ SetText(text string) 11 | @ Text() (text string) 12 | @ SetIcon(icon *Icon) 13 | @ Icon() (icon *Icon) 14 | @ SetSelected(b bool) 15 | @ IsSelected() (b bool) 16 | @ SetHidden(b bool) 17 | @ IsHidden() (b bool) 18 | @ SetFont(font *Font) 19 | @ Font() font *Font) 20 | @ SetForeground(brush *Brush) 21 | @ Foreground() (brush *Brush) 22 | @ SetBackground(brush *Brush) 23 | @ Background() (brush *Brush) 24 | @ SetToolTip(tip string) 25 | @ ToolTip() (tip string) 26 | @ SetTextAlignment(value Alignment) 27 | @ TextAlignment() (value Alignment) 28 | @ SetFlags(value ItemFlag) 29 | @ Flags() (value ItemFlag) 30 | ]] 31 | 32 | qtdrv = { 33 | --inc = "", 34 | name = "ShellListWidgetItem *", 35 | 36 | Init = [[ 37 | drvNewObj(a0,new ShellListWidgetItem); 38 | ]], 39 | InitWithText = [[ 40 | drvNewObj(a0, new ShellListWidgetItem(drvGetString(a1))); 41 | ]], 42 | Close = [[ 43 | drvDelObj(a0,self); 44 | ]], 45 | 46 | SetTextAlignment = [[ 47 | self->setTextAlignment((Qt::Alignment)drvGetInt(a1)); 48 | ]], 49 | TextAlignment = [[ 50 | drvSetInt(a1,self->textAlignment()); 51 | ]], 52 | SetFlags = [[ 53 | self->setFlags((Qt::ItemFlag)drvGetInt(a1)); 54 | ]], 55 | Flags = [[ 56 | drvSetInt(a1,self->flags()); 57 | ]], 58 | 59 | } 60 | -------------------------------------------------------------------------------- /make/ui/mainwindow.lua: -------------------------------------------------------------------------------- 1 | module("mainwindow") 2 | 3 | name = "MainWindow" 4 | base = "Widget" 5 | 6 | funcs = [[ 7 | + Init() 8 | @ SetCentralWidget(widget IWidget) 9 | @ CentralWidget() (widget IWidget) 10 | @ SetMenuBar(bar *MenuBar) 11 | @ MenuBar() (bar *MenuBar) 12 | @ SetStatusBar(bar *StatusBar) 13 | @ StatusBar() (bar *StatusBar) 14 | AddToolBar(bar *ToolBar) 15 | InsertToolBar(before *ToolBar, bar *ToolBar) 16 | RemoveToolBar(bar *ToolBar) 17 | AddDockWidget(area DockWidgetArea, dock *DockWidget) 18 | RemoveDockWidget(dock *DockWidget) 19 | ]] 20 | 21 | qtdrv = { 22 | inc = "", 23 | name = "QMainWindow *", 24 | 25 | Init = [[ 26 | drvNewObj(a0,new QMainWindow); 27 | ]], 28 | 29 | SetCentralWidget = "setCentralWidget", 30 | CentralWidget = "centralWidget", 31 | SetMenuBar = "setMenuBar", 32 | MenuBar = "menuBar", 33 | SetStatusBar = "setStatusBar", 34 | StatusBar = "statusBar", 35 | AddToolBar = "addToolBar", 36 | InsertToolBar = "insertToolBar", 37 | RemoveToolBar = "removeToolBar", 38 | AddDockWidget = [[ 39 | self->addDockWidget((Qt::DockWidgetArea)drvGetInt(a1),drvGetDockWidget(a2)); 40 | ]], 41 | RemoveDockWidget = "removeDockWidget", 42 | } 43 | -------------------------------------------------------------------------------- /make/ui/menu.lua: -------------------------------------------------------------------------------- 1 | module("menu") 2 | 3 | name = "Menu" 4 | base = "Widget" 5 | 6 | funcs = [[ 7 | + Init() 8 | + InitWithTitle(text string) 9 | @ SetTitle(text string) 10 | @ Title() (text string) 11 | @ SetIcon(icon *Icon) 12 | @ Icon() (icon *Icon) 13 | @ SetDefaultAction(act *Action) 14 | @ DefaultAction() (act *Action) 15 | @ SetActiveAction(act *Action) 16 | @ ActiveAction() (act *Action) 17 | @ MenuAction() (act *Action) 18 | @ IsEmpty() (b bool) 19 | AddMenu(menu *Menu) (act *Action) 20 | InsertMenu(before *Action, menu *Menu) 21 | AddSeparator() (act *Action) 22 | InsertSeparator(before *Action) (act *Action) 23 | Clear() 24 | Popup(pt Point, act *Action) 25 | 26 | * OnHovered(fn func(*Action)) 27 | * OnTriggered(fn func(*Action)) 28 | ]] 29 | 30 | 31 | qtdrv = { 32 | inc = "", 33 | name = "QMenu *", 34 | 35 | Init = [[ 36 | drvNewObj(a0,new QMenu); 37 | ]], 38 | InitWithTitle = [[ 39 | drvNewObj(a0, new QMenu(drvGetString(a1))); 40 | ]], 41 | 42 | SetTitle = "setTitle", 43 | Title = "title", 44 | SetIcon = "setIcon", 45 | Icon = "icon", 46 | SetDefaultAction = "setDefaultAction", 47 | DefaultAction = "defaultAction", 48 | SetActiveAction = "setActiveAction", 49 | ActiveAction = "activeAction", 50 | MenuAction = "menuAction", 51 | IsEmpty = "isEmpty", 52 | AddMenu = "addMenu", 53 | InsertMenu = "insertMenu", 54 | AddSeparator = "addSeparator", 55 | InsertSeparator = "insertSeparator", 56 | Clear = "clear", 57 | Popup = "popup", 58 | 59 | OnHovered = [[ 60 | QObject::connect(self,SIGNAL(hovered(QAction*)),drvNewSignal(self,a1,a2),SLOT(call(QAction*))); 61 | ]], 62 | 63 | OnTriggered = [[ 64 | QObject::connect(self,SIGNAL(triggered(QAction*)),drvNewSignal(self,a1,a2),SLOT(call(QAction*))); 65 | ]], 66 | } 67 | -------------------------------------------------------------------------------- /make/ui/menubar.lua: -------------------------------------------------------------------------------- 1 | module("menubar") 2 | 3 | name = "MenuBar" 4 | base = "Widget" 5 | 6 | funcs = [[ 7 | + Init() 8 | @ SetActiveAction(act *Action) 9 | @ ActiveAction() (act *Action) 10 | @ SetNativeMenuBar(b bool) 11 | @ IsNativeMenuBar() (b bool) 12 | AddMenu(menu *Menu) (act *Action) 13 | InsertMenu(before *Action, menu *Menu) 14 | AddSeparator() (act *Action) 15 | InsertSeparator(before *Action) (act *Action) 16 | Clear() 17 | 18 | * OnHovered(fn func(*Action)) 19 | * OnTriggered(fn func(*Action)) 20 | ]] 21 | 22 | 23 | qtdrv = { 24 | inc = "", 25 | name = "QMenuBar *", 26 | 27 | Init = [[ 28 | drvNewObj(a0,new QMenuBar); 29 | ]], 30 | 31 | SetActiveAction = "setActiveAction", 32 | ActiveAction = "activeAction", 33 | SetNativeMenuBar = "setNativeMenuBar", 34 | IsNativeMenuBar = "isNativeMenuBar", 35 | AddMenu = "addMenu", 36 | InsertMenu = "insertMenu", 37 | AddSeparator = "addSeparator", 38 | InsertSeparator = "insertSeparator", 39 | Clear = "clear", 40 | 41 | OnHovered = [[ 42 | QObject::connect(self,SIGNAL(hovered(QAction*)),drvNewSignal(self,a1,a2),SLOT(call(QAction*))); 43 | ]], 44 | 45 | OnTriggered = [[ 46 | QObject::connect(self,SIGNAL(triggered(QAction*)),drvNewSignal(self,a1,a2),SLOT(call(QAction*))); 47 | ]], 48 | } 49 | -------------------------------------------------------------------------------- /make/ui/painter.lua: -------------------------------------------------------------------------------- 1 | module("painter") 2 | 3 | name = "Painter" 4 | base = "object" 5 | unmap = true 6 | 7 | funcs = [[ 8 | + Init() 9 | + InitWithImage(image *Image) 10 | - Close() 11 | InitFrom(w IWidget) 12 | Begin(w IWidget) 13 | End() 14 | @ SetFont(font *Font) 15 | @ Font() (font *Font) 16 | @ SetPen(pen *Pen) 17 | @ Pen() (pen *Pen) 18 | @ SetBrush(brush *Brush) 19 | @ Brush() (brush *Brush) 20 | DrawPoint(pt Point) 21 | DrawPoints(pts []Point) 22 | DrawLine(pt1 Point, pt2 Point) 23 | DrawLines(pts []Point) 24 | DrawPolyline(pts []Point) 25 | DrawPolygon(pts []Point) 26 | DrawRect(rc Rect) 27 | DrawRects(rcs []Rect) 28 | DrawRoundedRect(rc Rect, xRadius float64, yRadius float64, sizeMode int) 29 | DrawEllipse(rc Rect) 30 | DrawArc(rc Rect, startAngle int, spanAngle int) 31 | DrawChord(rc Rect, startAngle int, spanAngle int) 32 | DrawPie(rc Rect, startAngle int, spanAngle int) 33 | DrawText(pt Point,text string) 34 | DrawTextRect(rc Rect, flags int, text string) (bound Rect) 35 | DrawPixmap(pt Point,pixmap *Pixmap) 36 | DrawPixmapEx(pt Point,pixmap *Pixmap, source Rect) 37 | DrawPixmapRect(rc Rect,pixmap *Pixmap) 38 | DrawPixmapRectEx(rc Rect,pixmap *Pixmap, source Rect) 39 | DrawImage(pt Point, image *Image) 40 | DrawImageEx(pt Point, image *Image, source Rect) 41 | DrawImageRect(rc Rect, image *Image) 42 | DrawImageRectEx(rc Rect, image *Image, source Rect) 43 | FillRect(rc Rect, color uint) 44 | FillRectF(rc RectF, color uint) 45 | ]] 46 | 47 | qtdrv = { 48 | inc = "", 49 | name = "QPainter *", 50 | 51 | Init = [[ 52 | drvNewObj(a0,new QPainter); 53 | ]], 54 | InitWithImage = [[ 55 | drvNewObj(a0,new QPainter((QImage*)drvGetNative(a1))); 56 | ]], 57 | 58 | Close = [[ 59 | drvDelObj(a0,self); 60 | ]], 61 | 62 | InitFrom = "initFrom", 63 | Begin = "begin", 64 | End = "end", 65 | SetFont = "setFont", 66 | Font = "font", 67 | SetPen = "setPen", 68 | Pen = "pen", 69 | SetBrush = "setBrush", 70 | Brush = "brush", 71 | DrawPoint = "drawPoint", 72 | DrawPoints = "drawPoints", 73 | DrawLine = "drawLine", 74 | DrawLines = "drawLines", 75 | DrawPolyline = "drawPolyline", 76 | DrawPolygon = "drawPolygon", 77 | DrawRect = "drawRect", 78 | DrawRects = "drawRects", 79 | DrawRoundedRect = [[ 80 | self->drawRoundedRect(drvGetRect(a1),drvGetFloat64(a2),drvGetFloat64(a3),(Qt::SizeMode)drvGetInt(a4)); 81 | ]], 82 | DrawEllipse = "drawEllipse", 83 | DrawArc = "drawArc", 84 | DrawChord = "drawChord", 85 | DrawPie = "drawPie", 86 | DrawText = "drawText", 87 | DrawTextRect = [[ 88 | QRect bound; 89 | self->drawText(drvGetRect(a1),drvGetInt(a2),drvGetString(a3),&bound); 90 | drvSetRect(a4,bound); 91 | ]], 92 | DrawPixmap = "drawPixmap", 93 | DrawPixmapEx = "drawPixmap", 94 | DrawPixmapRect = "drawPixmap", 95 | DrawPixmapRectEx = "drawPixmap", 96 | DrawImage = "drawImage", 97 | DrawImageEx = "drawImage", 98 | DrawImageRect = "drawImage", 99 | DrawImageRectEx = "drawImage", 100 | FillRect = "fillRect", 101 | FillRectF = "fillRect", 102 | } -------------------------------------------------------------------------------- /make/ui/pen.lua: -------------------------------------------------------------------------------- 1 | module("pen") 2 | 3 | name = "Pen" 4 | base = "object" 5 | 6 | funcs = [[ 7 | + Init() 8 | - Close() 9 | @ SetColor(clr color.Color) 10 | @ Color() (clr color.Color) 11 | @ SetWidth(width int) 12 | @ Width() (width int) 13 | @ SetStyle(style PenStyle) 14 | @ Style() (style PenStyle) 15 | ]] 16 | 17 | qtdrv = { 18 | inc = "", 19 | name = "QPen*", 20 | 21 | Init = [[ 22 | drvSetPen(a0, QPen()); 23 | ]], 24 | Close = [[ 25 | drvDelPen(a0,self); 26 | ]], 27 | SetColor = "setColor", 28 | Color = "color", 29 | SetWidth = "setWidth", 30 | Width = "width", 31 | SetStyle = [[ 32 | self->setStyle((Qt::PenStyle)drvGetInt(a1)); 33 | ]], 34 | Style = [[ 35 | drvSetInt(a1,self->style()); 36 | ]], 37 | 38 | } -------------------------------------------------------------------------------- /make/ui/pixmap.lua: -------------------------------------------------------------------------------- 1 | module("pixmap") 2 | 3 | name = "Pixmap" 4 | base = "object" 5 | 6 | funcs = [[ 7 | + Init() 8 | + InitWithFile(name string) 9 | + InitWithData(data []byte) 10 | + InitWithSize(width int, height int) 11 | - Close() 12 | @ Depth() (n int) 13 | @ Size() (sz Size) 14 | @ Rect() (rc Rect) 15 | @ HasAlpha() (b bool) 16 | @ HasAlphaChannel() (b bool) 17 | @ IsNull() (b bool) 18 | 19 | ]] 20 | 21 | 22 | qtdrv = { 23 | inc = "", 24 | name = "QPixmap *", 25 | 26 | Init = [[ 27 | drvSetPixmap(a0, QPixmap()); 28 | ]], 29 | InitWithFile = [[ 30 | drvSetPixmap(a0, QPixmap(drvGetString(a1))); 31 | ]], 32 | InitWithSize = [[ 33 | drvSetPixmap(a0, QPixmap(drvGetInt(a1),drvGetInt(a2))); 34 | ]], 35 | InitWithData = [[ 36 | QPixmap pixmap; 37 | if (pixmap.loadFromData(drvGetByteArray(a1))) { 38 | drvSetPixmap(a0, pixmap); 39 | } 40 | ]], 41 | Close = [[ 42 | drvDelPixmap(a0,self); 43 | ]], 44 | 45 | Depth = "depth", 46 | Size = "size", 47 | Rect = "rect", 48 | HasAlpha = "hasAlpha", 49 | HasAlphaChannel = "hasAlphaChannel", 50 | IsNull = "isNull", 51 | 52 | } 53 | -------------------------------------------------------------------------------- /make/ui/radio.lua: -------------------------------------------------------------------------------- 1 | module("radio") 2 | 3 | name = "Radio" 4 | base = "baseButton" 5 | 6 | funcs = [[ 7 | + Init() 8 | + InitWithText(text string) 9 | * OnClicked(fn func()) 10 | ]] 11 | 12 | 13 | qtdrv = { 14 | inc = "", 15 | name = "QRadioButton *", 16 | 17 | Init = [[ 18 | drvNewObj(a0,new QRadioButton); 19 | ]], 20 | 21 | InitWithText = [[ 22 | drvNewObj(a0, new QRadioButton(drvGetString(a1))); 23 | ]], 24 | 25 | OnClicked = [[ 26 | QObject::connect(self,SIGNAL(clicked()),drvNewSignal(self,a1,a2),SLOT(call())); 27 | ]], 28 | 29 | } 30 | -------------------------------------------------------------------------------- /make/ui/scrollbar.lua: -------------------------------------------------------------------------------- 1 | module("scrollbar") 2 | 3 | name = "ScrollBar" 4 | base = "baseSlider" 5 | 6 | funcs = [[ 7 | + Init() 8 | ]] 9 | 10 | qtdrv = { 11 | inc = "", 12 | name = "QScrollBar *", 13 | 14 | Init = [[ 15 | drvNewObj(a0,new QScrollBar(Qt::Horizontal)); 16 | ]], 17 | 18 | } -------------------------------------------------------------------------------- /make/ui/slider.lua: -------------------------------------------------------------------------------- 1 | module("slider") 2 | 3 | name = "Slider" 4 | base = "baseSlider" 5 | 6 | funcs = [[ 7 | + Init() 8 | @ SetTickInterval(value int) 9 | @ TickInterval() (value int) 10 | @ SetTickPosition(value TickPosition) 11 | @ TickPosition() (value TickPosition) 12 | ]] 13 | 14 | qtdrv = { 15 | inc = "", 16 | name = "QSlider *", 17 | 18 | Init = [[ 19 | drvNewObj(a0,new QSlider(Qt::Horizontal)); 20 | ]], 21 | 22 | SetTickInterval = "setTickInterval", 23 | TickInterval = "tickInterval", 24 | SetTickPosition = "setTickPosition", 25 | TickPosition = "tickPosition", 26 | } -------------------------------------------------------------------------------- /make/ui/stackedlayout.lua: -------------------------------------------------------------------------------- 1 | module("stackedlayout") 2 | 3 | name = "StackedLayout" 4 | base = "baseLayout" 5 | 6 | 7 | funcs = [[ 8 | +Init() 9 | @ SetCurrentIndex(index int) 10 | @ CurrentIndex() (index int) 11 | @ SetCurrentWidget(widget IWidget) 12 | @ CurrentWidget() (widget IWidget) 13 | AddWidget(widget IWidget) 14 | InsertWidget(index int, widget IWidget) 15 | Widget(index int) (widget IWidget) 16 | * OnCurrentChanged(fn func(int)) 17 | ]] 18 | 19 | qtdrv = { 20 | inc = "", 21 | name = "QStackedLayout *", 22 | 23 | Init = [[ 24 | drvNewObj(a0,new QStackedLayout); 25 | ]], 26 | 27 | OnCurrentChanged = [[ 28 | QObject::connect(self,SIGNAL(currentChanged(int)),drvNewSignal(self,a1,a2),SLOT(call(int))); 29 | ]], 30 | } -------------------------------------------------------------------------------- /make/ui/statusbar.lua: -------------------------------------------------------------------------------- 1 | module("statusbar") 2 | 3 | name = "StatusBar" 4 | base = "Widget" 5 | 6 | funcs = [[ 7 | + Init() 8 | @ SetSizeGrip(b bool) 9 | @ IsSizeGrip() (b bool) 10 | AddWidget(widget IWidget, stretch int) 11 | AddPermanentWidget(widget IWidget, stretch int) 12 | InsertWidget(index int,widget IWidget, stretch int) 13 | InsertPermanentWidget(index int, widget IWidget, stretch int) 14 | RemoveWidget(widget IWidget) 15 | ShowMessage(text string, timeout int) 16 | CurrentMessage() (text string) 17 | ClearMessage() 18 | ]] 19 | 20 | qtdrv = { 21 | inc = "", 22 | name = "QStatusBar*", 23 | 24 | Init = [[ 25 | drvNewObj(a0, new QStatusBar()); 26 | ]], 27 | 28 | SetSizeGrip = "setSizeGripEnabled", 29 | IsSizeGrip = "isSizeGripEnabled", 30 | AddWidget = "addWidget", 31 | AddPermanentWidget = "addPermanentWidget", 32 | InsertWidget = "insertWidget", 33 | InsertPermanentWidget = "insertPermanentWidget", 34 | RemoveWidget = "removeWidget", 35 | ShowMessage = "showMessage", 36 | CurrentMessage = "currentMessage", 37 | ClearMessage = "clearMessage", 38 | 39 | } 40 | -------------------------------------------------------------------------------- /make/ui/systemtray.lua: -------------------------------------------------------------------------------- 1 | module("systemtray") 2 | 3 | name = "SystemTray" 4 | base = "object" 5 | 6 | funcs = [[ 7 | + Init() 8 | - Close() 9 | @ SetContextMenu(menu *Menu) 10 | @ ContextMenu() (menu *Menu) 11 | @ SetIcon(icon *Icon) 12 | @ Icon() (icon *Icon) 13 | @ SetToolTip(text string) 14 | @ ToolTip() (text string) 15 | @ SetVisible(b bool) 16 | @ IsVisible() (b bool) 17 | ShowMessage(title string, message string, icontype MessageIconType, mstimeouthint int) 18 | * OnActivated(fn func(int)) 19 | * OnMessageClicked(fn func()) 20 | ]] 21 | 22 | qtdrv = { 23 | inc = "", 24 | name = "QSystemTrayIcon*", 25 | 26 | Init = [[ 27 | drvNewObj(a0, new QSystemTrayIcon); 28 | ]], 29 | 30 | Close = [[ 31 | drvDelObj(a0,self); 32 | ]], 33 | 34 | SetContextMenu = "setContextMenu", 35 | ContextMenu = "contextMenu", 36 | SetIcon = "setIcon", 37 | Icon = "icon", 38 | SetToolTip = "setToolTip", 39 | ToolTip = "toolTip", 40 | SetVisible = "setVisible", 41 | IsVisible = "isVisible", 42 | ShowMessage = "showMessage", 43 | 44 | OnActivated = [[ 45 | QObject::connect(self,SIGNAL(activated(int)),drvNewSignal(self,a1,a2),SLOT(call(int))); 46 | ]], 47 | OnMessageClicked = [[ 48 | QObject::connect(self,SIGNAL(messageClicked(int)),drvNewSignal(self,a1,a2),SLOT(call())); 49 | ]], 50 | 51 | } 52 | -------------------------------------------------------------------------------- /make/ui/tabwidget.lua: -------------------------------------------------------------------------------- 1 | module("tabwidget") 2 | 3 | name = "TabWidget" 4 | base = "Widget" 5 | 6 | funcs = [[ 7 | +Init() 8 | @ Count() (n int) 9 | @ CurrentIndex() (index int) 10 | @ CurrentWidget() (w IWidget) 11 | @ SetCurrentIndex(index int) 12 | @ SetCurrentWidget(w IWidget) 13 | AddTab(w IWidget, label string, icon *Icon) 14 | InsertTab(index int, w IWidget, label string, icon *Icon) 15 | RemoveTab(index int) 16 | Clear() 17 | IndexOf(w IWidget) (index int) 18 | WidgetOf(index int) (w IWidget) 19 | SetTabText(index int, label string) 20 | TabText(index int) (label string) 21 | SetTabIcon(index int, icon *Icon) 22 | TabIcon(index int) (icon *Icon) 23 | SetTabToolTip(index int, tip string) 24 | TabToolTip(index int) (tip string) 25 | * OnCurrentChanged(fn func(int)) 26 | ]] 27 | 28 | 29 | qtdrv = { 30 | inc = "", 31 | name = "QTabWidget *", 32 | 33 | Init = [[ 34 | drvNewObj(a0,new QTabWidget); 35 | ]], 36 | 37 | Count = "count", 38 | CurrentIndex = "currentIndex", 39 | CurrentWidget = "currentWidget", 40 | SetCurrentIndex = "setCurrentIndex", 41 | SetCurrentWidget = "setCurrentWidget", 42 | IndexOf = "indexOf", 43 | WidgetOf = "widget", 44 | AddTab = [[ 45 | self->addTab(drvGetWidget(a1),drvGetIcon(a3),drvGetString(a2)); 46 | ]], 47 | InsertTab = [[ 48 | self->insertTab(drvGetInt(a1),drvGetWidget(a2),drvGetIcon(a4),drvGetString(a3)); 49 | ]], 50 | RemoveTab = "removeTab", 51 | Clear = "clear", 52 | SetTabText = "setTabText", 53 | TabText = "tabText", 54 | SetTabIcon = "setTabIcon", 55 | TabIcon = "tabIcon", 56 | SetTabToolTip = "setTabToolTip", 57 | TabToolTip = "tabToolTip", 58 | 59 | 60 | 61 | OnCurrentChanged = [[ 62 | QObject::connect(self,SIGNAL(currentChanged(int)),drvNewSignal(self,a1,a2),SLOT(call(int))); 63 | ]], 64 | 65 | } 66 | -------------------------------------------------------------------------------- /make/ui/timer.lua: -------------------------------------------------------------------------------- 1 | module("timer") 2 | 3 | name = "Timer" 4 | base = "object" 5 | 6 | unmap = true 7 | 8 | funcs = [[ 9 | + Init() 10 | - Close() 11 | @ SetInterval(msec int) 12 | @ Interval() (msec int) 13 | @ SetSingleShot(b bool) 14 | @ IsSingleShot() (b bool) 15 | @ IsActive() (b bool) 16 | @ TimerId() (id int) 17 | Start() 18 | StartWith(msec int) 19 | Stop() 20 | * OnTimeout(fn func()) 21 | ]] 22 | 23 | expands = [[ 24 | 25 | func AfterFunc(ms int,fn func()) *Timer { 26 | timer := NewTimer() 27 | timer.SetSingleShot(true) 28 | timer.StartWith(ms) 29 | timer.OnTimeout(func() { 30 | timer.Close() 31 | fn() 32 | }) 33 | return timer 34 | } 35 | 36 | ]] 37 | 38 | 39 | qtdrv = { 40 | inc = "", 41 | name = "QTimer *", 42 | 43 | Init = [[ 44 | drvNewObj(a0,new QTimer(theApp)); 45 | ]], 46 | Close = [[ 47 | drvDelObj(a0,self); 48 | ]], 49 | SetInterval = "setInterval", 50 | Interval = "interval", 51 | SetSingleShot = "setSingleShot", 52 | IsSingleShot = "isSingleShot", 53 | IsActive = "isActive", 54 | TimerId = "timerId", 55 | Start = "start", 56 | StartWith = "start", 57 | Stop = "stop", 58 | 59 | OnTimeout = [[ 60 | QObject::connect(self,SIGNAL(timeout()),drvNewSignal(self,a1,a2),SLOT(call())); 61 | ]], 62 | 63 | } 64 | -------------------------------------------------------------------------------- /make/ui/toolbar.lua: -------------------------------------------------------------------------------- 1 | module("toolbar") 2 | 3 | name = "ToolBar" 4 | base = "Widget" 5 | 6 | funcs = [[ 7 | + Init() 8 | + InitWithTitle(text string) 9 | @ SetTitle(text string) 10 | @ Title() (text string) 11 | @ SetIconSize(sz Size) 12 | @ IconSize() (sz Size) 13 | @ SetFloatable(b bool) 14 | @ IsFloatable() (b bool) 15 | @ IsFloating() (b bool) 16 | @ SetToolButtonStyle(style ToolButtonStyle) 17 | @ ToolButtonStyle() (style ToolButtonStyle) 18 | AddAction(act *Action) 19 | AddSeparator() (act *Action) 20 | AddWidget(widget IWidget) (act *Action) 21 | Clear() 22 | ]] 23 | 24 | qtdrv = { 25 | inc = "", 26 | name = "QToolBar*", 27 | 28 | Init = [[ 29 | drvNewObj(a0, new QToolBar,true,false); 30 | ]], 31 | InitWithTitle = [[ 32 | drvNewObj(a0, new QToolBar(drvGetString(a1)),true,false); 33 | ]], 34 | 35 | SetTitle = "setWindowTitle", 36 | Title = "windowTitle", 37 | SetIconSize = "setIconSize", 38 | IconSize = "iconSize", 39 | SetFloatable = "setFloatable", 40 | IsFloatable = "isFloatable", 41 | IsFloating = "isFloating", 42 | AddAction = "addAction", 43 | AddSeparator = [[ 44 | drvNewObj(a1,self->addSeparator()); 45 | ]], 46 | AddWidget = [[ 47 | drvNewObj(a2,self->addWidget(drvGetWidget(a1))); 48 | ]], 49 | Clear = "clear", 50 | 51 | } 52 | -------------------------------------------------------------------------------- /make/ui/toolbox.lua: -------------------------------------------------------------------------------- 1 | module("toolbox") 2 | 3 | name = "ToolBox" 4 | base = "Widget" 5 | 6 | funcs = [[ 7 | + Init() 8 | @ SetCurrentIndex(index int) 9 | @ SetCurrentWidget(widget IWidget) 10 | @ CurrentIndex() (n int) 11 | @ CurrentWidget() (widget IWidget) 12 | @ Count() (n int) 13 | AddItem(widget IWidget, text string, icon *Icon) 14 | InsertItem(index int, widget IWidget, text string, icon *Icon) 15 | RemoveItem(index int) 16 | IndexOf(widget IWidget) (index int) 17 | WidgetOf(index int) (widget IWidget) 18 | SetItemText(index int, text string) 19 | ItemText(index int) (text string) 20 | SetItemIcon(index int, icon *Icon) 21 | ItemIcon(index int) (icon *Icon) 22 | SetItemToolTip(index int, text string) 23 | ItemToolTip(index int) (text string) 24 | IsItemEnabled(index int) (b bool) 25 | 26 | * OnCurrentChanged(fn func(int)) 27 | ]] 28 | 29 | qtdrv = { 30 | inc = "", 31 | name = "QToolBox*", 32 | 33 | Init = [[ 34 | drvNewObj(a0, new QToolBox); 35 | ]], 36 | SetCurrentIndex = "setCurrentIndex", 37 | SetCurrentWidget = "setCurrentWidget", 38 | CurrentIndex = "currentIndex", 39 | CurrentWidget = "currentWidget", 40 | Count = "count", 41 | AddItem = [[ 42 | self->addItem(drvGetWidget(a1),drvGetIcon(a3),drvGetString(a2)); 43 | ]], 44 | InsertItem = [[ 45 | self->insertItem(drvGetInt(a1),drvGetWidget(a2),drvGetIcon(a4),drvGetString(a3)); 46 | ]], 47 | RemoveItem = "removeItem", 48 | IndexOf = "indexOf", 49 | WidgetOf = "widget", 50 | SetItemText = "setItemText", 51 | ItemText = "itemText", 52 | SetItemIcon = "setItemIcon", 53 | ItemIcon = "itemIcon", 54 | SetItemToolTip = "setItemToolTip", 55 | ItemToolTip = "itemToolTip", 56 | IsItemEnabled = "isItemEnabled", 57 | 58 | OnCurrentChanged = [[ 59 | QObject::connect(self,SIGNAL(currentChanged(int)),drvNewSignal(self,a1,a2),SLOT(call(int))); 60 | ]] 61 | 62 | } 63 | -------------------------------------------------------------------------------- /make/ui/toolbutton.lua: -------------------------------------------------------------------------------- 1 | module("toolbutton") 2 | 3 | name = "ToolButton" 4 | base = "baseButton" 5 | 6 | funcs = [[ 7 | + Init() 8 | + InitWithText(text string) 9 | @ SetMenu(menu *Menu) 10 | @ Menu()(menu *Menu) 11 | @ SetAutoRaise(b bool) 12 | @ AutoRaise() (b bool) 13 | @ SetToolButtonStyle(style ToolButtonStyle) 14 | @ ToolButtonStyle() (style ToolButtonStyle) 15 | @ SetToolButtonPopupMode(mode ToolButtonPopupMode) 16 | @ ToolButtonPopupMode() (mode ToolButtonPopupMode) 17 | * OnClicked(fn func()) 18 | ]] 19 | 20 | 21 | qtdrv = { 22 | inc = "", 23 | name = "QToolButton *", 24 | 25 | Init = [[ 26 | drvNewObj(a0,new QToolButton); 27 | ]], 28 | 29 | InitWithText = [[ 30 | drvNewObj(a0,new QPushButton(drvGetString(a1))); 31 | ]], 32 | 33 | SetMenu = "setMenu", 34 | Menu = "menu", 35 | SetAutoRaise = "setAutoRaise", 36 | AutoRaise = "autoRaise", 37 | SetToolButtonStyle = "setToolButtonStyle", 38 | ToolButtonStyle = "toolButtonStyle", 39 | SetToolButtonPopupMode = "setPopupMode", 40 | ToolButtonPopupMode = "popupMode", 41 | 42 | OnClicked = [[ 43 | QObject::connect(self,SIGNAL(clicked()),drvNewSignal(self,a1,a2),SLOT(call())); 44 | ]], 45 | 46 | } 47 | -------------------------------------------------------------------------------- /make/ui/vboxlayout.lua: -------------------------------------------------------------------------------- 1 | module("vboxlayout") 2 | 3 | name = "VBoxLayout" 4 | base = "BoxLayout" 5 | 6 | funcs = [[ 7 | +Init() 8 | ]] 9 | 10 | qtdrv = { 11 | inc = "", 12 | name = "QVBoxLayout *", 13 | 14 | Init = [[ 15 | drvNewObj(a0,new QVBoxLayout); 16 | ]], 17 | } -------------------------------------------------------------------------------- /make/ui/widget.lua: -------------------------------------------------------------------------------- 1 | module("widget") 2 | 3 | name = "Widget" 4 | base = "object" 5 | 6 | defs = [[ 7 | ]] 8 | 9 | funcs = [[ 10 | + Init() 11 | - Close() 12 | @ SetAutoClose(b bool) 13 | @ AutoClose() (b bool) 14 | @ SetLayout(layout ILayout) 15 | @ Layout() (layout ILayout) 16 | @ SetParent(parent IWidget) 17 | @ Parent() (parent IWidget) 18 | @ SetVisible(b bool) 19 | @ IsVisible() (b bool) 20 | @ SetWindowTitle(text string) 21 | @ WindowTitle()(text string) 22 | @ SetWindowIcon(icon *Icon) 23 | @ WindowIcon() (icon *Icon) 24 | @ SetPos(pt Point) 25 | @ Pos() (pt Point) 26 | @ SetSize(sz Size) 27 | @ Size() (sz Size) 28 | @ SetMinimumSize(sz Size) 29 | @ MinimumSize() (sz Size) 30 | @ SetMaximumSize(sz Size) 31 | @ MaximumSize() (sz Size) 32 | @ SetFixedSize(sz Size) 33 | @ SetGeometry(rc Rect) 34 | @ Geometry()(rc Rect) 35 | @ SetFont(font *Font) 36 | @ Font() (font *Font) 37 | @ SetToolTip(text string) 38 | @ ToolTip() (text string) 39 | @ SetUpdatesEnabled(b bool) 40 | @ UpdatesEnabled() (b bool) 41 | @ IsActivateWindow() (b bool) 42 | ActivateWindow() 43 | Done() 44 | Update() 45 | Repaint() 46 | StartTimer(millisecond int) (id int) 47 | KillTimer(id int) 48 | AddAction(act *Action) 49 | InsertAction(before *Action, act *Action) 50 | RemoveAction(act *Action) 51 | 52 | * OnShowEvent(fn func(*ShowEvent)) 53 | * OnHideEvent(fn func(*HideEvent)) 54 | * OnCloseEvent(fn func(*CloseEvent)) 55 | * OnKeyPressEvent(fn func(*KeyEvent)) 56 | * OnKeyReleaseEvent(fn func(*KeyEvent)) 57 | * OnMousePressEvent(fn func(*MouseEvent)) 58 | * OnMouseReleaseEvent(fn func(*MouseEvent)) 59 | * OnMouseMoveEvent(fn func(*MouseEvent)) 60 | * OnMouseDoubleClickEvent(fn func(*MouseEvent)) 61 | * OnMoveEvent(fn func(*MoveEvent)) 62 | * OnPaintEvent(fn func(*PaintEvent)) 63 | * OnResizeEvent(fn func(*ResizeEvent)) 64 | * OnEnterEvent(fn func(*EnterEvent)) 65 | * OnLeaveEvent(fn func(*LeaveEvent)) 66 | * OnFocusInEvent(fn func(*FocusEvent)) 67 | * OnFocusOutEvent(fn func(*FocusEvent)) 68 | * OnTimerEvent(fn func(*TimerEvent)) 69 | ]] 70 | 71 | expands = [[ 72 | func (p *Widget) Show() { 73 | p.SetVisible(true) 74 | } 75 | 76 | func (p *Widget) Hide() { 77 | p.SetVisible(false) 78 | } 79 | 80 | func (p *Widget) SetPosv(x,y int) { 81 | p.SetPos(Pt(x,y)) 82 | } 83 | 84 | func (p *Widget) Posv() (int,int) { 85 | return p.Pos().Unpack() 86 | } 87 | 88 | func (p *Widget) SetSizev(width,height int) { 89 | p.SetSize(Sz(width,height)) 90 | } 91 | 92 | func (p *Widget) Sizev() (int,int) { 93 | return p.Size().Unpack() 94 | } 95 | 96 | func (p *Widget) SetGeometryv(x,y,width,height int) { 97 | p.SetGeometry(Rc(x,y,width,height)) 98 | } 99 | 100 | func (p *Widget) Geometryv() (int,int,int,int) { 101 | return p.Geometry().Unpack() 102 | } 103 | 104 | ]] 105 | 106 | qtdrv = { 107 | inc = "", 108 | name = "QWidget *", 109 | 110 | Init = [[ 111 | drvNewObj(a0,new QWidget); 112 | ]], 113 | Close = [[ 114 | if (self->testAttribute(Qt::WA_DeleteOnClose)) { 115 | self->close(); 116 | } else { 117 | self->close(); 118 | drvDelObj(a0,self); 119 | } 120 | ]], 121 | 122 | SetAutoClose = [[ 123 | self->setAttribute(Qt::WA_DeleteOnClose,drvGetBool(a1)); 124 | ]], 125 | AutoClose = [[ 126 | drvSetBool(a1,self->testAttribute(Qt::WA_DeleteOnClose)); 127 | ]], 128 | SetLayout = "setLayout", 129 | Layout = "layout", 130 | SetVisible = "setVisible", 131 | IsVisible = "isVisible", 132 | SetParent = "setParent", 133 | Parent = "parent", 134 | SetWindowTitle = "setWindowTitle", 135 | WindowTitle = "windowTitle", 136 | SetWindowIcon = "setWindowIcon", 137 | WindowIcon = "windowIcon", 138 | SetPos = "move", 139 | Pos = "pos", 140 | SetSize = "resize", 141 | Size = "size", 142 | SetMinimumSize = "setMinimumSize", 143 | MinimumSize = "minimumSize", 144 | SetMaximumSize = "setMaximumSize", 145 | MaximumSize = "maximumSize", 146 | SetFixedSize = "setFixedSize", 147 | SetGeometry = "setGeometry", 148 | Geometry = "geometry", 149 | SetFont = "setFont", 150 | Font = "font", 151 | SetToolTip = "setToolTip", 152 | ToolTip = "toolTip", 153 | SetUpdatesEnabled = "setUpdatesEnabled", 154 | UpdatesEnabled = "updatesEnabled", 155 | IsActivateWindow = "isActiveWindow", 156 | ActivateWindow = "activateWindow", 157 | Done = "close", 158 | Update = "update", 159 | Repaint = "repaint", 160 | StartTimer = "startTimer", 161 | KillTimer = "killTimer", 162 | AddAction = "addAction", 163 | InsertAction = "insertAction", 164 | RemoveAction = "removeAction", 165 | 166 | OnShowEvent = [[ 167 | drvNewEvent(QEvent::Show,a0,a1,a2); 168 | ]], 169 | 170 | OnHideEvent = [[ 171 | drvNewEvent(QEvent::Hide,a0,a1,a2); 172 | ]], 173 | 174 | OnCloseEvent = [[ 175 | drvNewEvent(QEvent::Close,a0,a1,a2); 176 | ]], 177 | 178 | OnKeyPressEvent = [[ 179 | drvNewEvent(QEvent::KeyPress,a0,a1,a2); 180 | ]], 181 | 182 | OnKeyReleaseEvent = [[ 183 | drvNewEvent(QEvent::KeyRelease,a0,a1,a2); 184 | ]], 185 | 186 | OnMousePressEvent = [[ 187 | drvNewEvent(QEvent::MouseButtonPress,a0,a1,a2); 188 | ]], 189 | 190 | OnMouseReleaseEvent = [[ 191 | drvNewEvent(QEvent::MouseButtonRelease,a0,a1,a2); 192 | ]], 193 | 194 | OnMouseMoveEvent = [[ 195 | drvNewEvent(QEvent::MouseMove,a0,a1,a2); 196 | ]], 197 | 198 | OnMouseDoubleClickEvent = [[ 199 | drvNewEvent(QEvent::MouseButtonDblClick,a0,a1,a2); 200 | ]], 201 | 202 | OnMoveEvent = [[ 203 | drvNewEvent(QEvent::Move,a0,a1,a2); 204 | ]], 205 | 206 | OnPaintEvent = [[ 207 | drvNewEvent(QEvent::Paint,a0,a1,a2); 208 | ]], 209 | 210 | OnResizeEvent = [[ 211 | drvNewEvent(QEvent::Resize,a0,a1,a2); 212 | ]], 213 | 214 | OnEnterEvent = [[ 215 | drvNewEvent(QEvent::Enter,a0,a1,a2); 216 | ]], 217 | 218 | OnLeaveEvent = [[ 219 | drvNewEvent(QEvent::Leave,a0,a1,a2); 220 | ]], 221 | 222 | OnFocusInEvent = [[ 223 | drvNewEvent(QEvent::FocusIn,a0,a1,a2); 224 | ]], 225 | 226 | OnFocusOutEvent = [[ 227 | drvNewEvent(QEvent::FocusOut,a0,a1,a2); 228 | ]], 229 | 230 | OnTimerEvent = [[ 231 | drvNewEvent(QEvent::Timer,a0,a1,a2); 232 | ]] 233 | } 234 | -------------------------------------------------------------------------------- /qtdrv/cdrv.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | ** Copyright 2012 visualfc . All rights reserved. 3 | ** 4 | ** This library is free software; you can redistribute it and/or 5 | ** modify it under the terms of the GNU Lesser General Public 6 | ** License as published by the Free Software Foundation; either 7 | ** version 2.1 of the License, or (at your option) any later version. 8 | ** 9 | ** This library is distributed in the hope that it will be useful, 10 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | ** Lesser General Public License for more details. 13 | *********************************************************************/ 14 | #include "qtdrv_global.h" 15 | #include "qtsignal.h" 16 | #include "qtevent.h" 17 | #include "qtapp.h" 18 | #include "qtshell.h" 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | class QDockWidget; 36 | class QToolBar; 37 | class QMenu; 38 | class QMenuBar; 39 | class QAction; 40 | class QLayout; 41 | class QStatusBar; 42 | class QListWidgetItem; 43 | 44 | 45 | #define drvInvalid (void*)-1 46 | 47 | void utf8_info_copy(void*,const char*,int); 48 | 49 | struct handle_head { 50 | void *native; 51 | int classid; 52 | }; 53 | 54 | struct string_head { 55 | char *data; 56 | int len; 57 | }; 58 | 59 | struct slice_head { 60 | const char *data; 61 | int len; 62 | int cap; 63 | }; 64 | 65 | struct point_head { 66 | int x; 67 | int y; 68 | }; 69 | 70 | struct pointf_head { 71 | double x; 72 | double y; 73 | }; 74 | 75 | struct size_head { 76 | int width; 77 | int hegiht; 78 | }; 79 | 80 | struct sizef_head { 81 | double width; 82 | double height; 83 | }; 84 | 85 | struct rect_head { 86 | int x; 87 | int y; 88 | int width; 89 | int height; 90 | }; 91 | 92 | struct rectf_head { 93 | double x; 94 | double y; 95 | double width; 96 | double height; 97 | }; 98 | 99 | struct margins_head { 100 | int left; 101 | int top; 102 | int right; 103 | int bottom; 104 | }; 105 | 106 | struct color_head { 107 | quint32 r; 108 | quint32 g; 109 | quint32 b; 110 | quint32 a; 111 | }; 112 | 113 | typedef unsigned char byte; 114 | 115 | inline QString drvGetString(void *param) 116 | { 117 | if (param == 0) { 118 | return QString(); 119 | } 120 | string_head *h = (string_head*)param; 121 | return QString::fromUtf8(h->data,h->len); 122 | } 123 | 124 | inline void drvSetString(void *param, const QString &s) 125 | { 126 | if (param == 0) { 127 | return; 128 | } 129 | const QByteArray & ar = s.toUtf8(); 130 | utf8_info_copy(param,ar.constData(),ar.length()); 131 | /* 132 | string_head *sh = (string_head*)param; 133 | sh->data = new char[ar.length()]; 134 | memcpy(sh->data,ar.constData(),ar.length()); 135 | sh->len = ar.length(); 136 | */ 137 | } 138 | 139 | inline QColor drvGetColor(void *param) 140 | { 141 | if (param == 0) { 142 | return QColor(); 143 | } 144 | return QColor(*(QRgb*)param); 145 | } 146 | 147 | inline void drvSetColor(void *param, const QColor &clr) 148 | { 149 | if (param == 0) { 150 | return; 151 | } 152 | *(QRgb*)param = clr.rgba(); 153 | } 154 | 155 | inline QPoint drvGetPoint(void *param) 156 | { 157 | if (param == 0) { 158 | return QPoint(); 159 | } 160 | point_head *h = (point_head*)param; 161 | return QPoint(h->x,h->y); 162 | } 163 | 164 | inline QVector drvGetPointArray(void *param) 165 | { 166 | if (param == 0) { 167 | return QVector (); 168 | } 169 | slice_head *sh = (slice_head*)param; 170 | QVector vec(sh->len); 171 | point_head *h = (point_head*)sh->data; 172 | for (int i=0; i < sh->len; i++) { 173 | vec[i] = QPoint(h[i].x,h[i].y); 174 | } 175 | return vec; 176 | } 177 | 178 | inline QVector drvGetRectArray(void *param) 179 | { 180 | if (param == 0) { 181 | return QVector(); 182 | } 183 | slice_head *sh = (slice_head*)param; 184 | QVector vec(sh->len); 185 | rect_head *h = (rect_head*)sh->data; 186 | for (int i=0; i < sh->len; i++) { 187 | vec[i] = QRect(h[i].x,h[i].y,h[i].width,h[i].height); 188 | } 189 | return vec; 190 | } 191 | 192 | inline QByteArray drvGetByteArray(void *param) 193 | { 194 | if (param == 0) { 195 | return QByteArray(); 196 | } 197 | slice_head *sh = (slice_head*)param; 198 | return QByteArray(sh->data,sh->len); 199 | } 200 | 201 | inline void drvSetPoint(void *param, const QPoint &pt) 202 | { 203 | if (param == 0) { 204 | return; 205 | } 206 | point_head *sh = (point_head*)param; 207 | sh->x = pt.x(); 208 | sh->y = pt.y(); 209 | } 210 | 211 | inline QSize drvGetSize(void *param) 212 | { 213 | if (param == 0) { 214 | return QSize(); 215 | } 216 | size_head *h = (size_head*)param; 217 | return QSize(h->width,h->hegiht); 218 | } 219 | 220 | inline void drvSetSize(void *param, const QSize &sz) 221 | { 222 | if (param == 0) { 223 | return; 224 | } 225 | size_head *h = (size_head*)param; 226 | h->width = sz.width(); 227 | h->hegiht = sz.height(); 228 | } 229 | 230 | inline QRect drvGetRect(void *param) 231 | { 232 | if (param == 0) { 233 | return QRect(); 234 | } 235 | rect_head *h = (rect_head*)param; 236 | return QRect(h->x,h->y,h->width,h->height); 237 | } 238 | 239 | inline QRectF drvGetRectF(void *param) 240 | { 241 | if (param == 0) { 242 | return QRectF(); 243 | } 244 | rectf_head *h = (rectf_head*)param; 245 | return QRectF(h->x,h->y,h->width,h->height); 246 | } 247 | 248 | 249 | inline void drvSetRect(void *param, const QRect &rc) 250 | { 251 | if (param == 0) { 252 | return; 253 | } 254 | rect_head *h = (rect_head*)param; 255 | h->x = rc.x(); 256 | h->y = rc.y(); 257 | h->width = rc.width(); 258 | h->height = rc.height(); 259 | } 260 | 261 | inline QMargins drvGetMargins(void *param) 262 | { 263 | if (param == 0) { 264 | return QMargins(); 265 | } 266 | margins_head *h = (margins_head*)param; 267 | return QMargins(h->left,h->top,h->right,h->bottom); 268 | } 269 | 270 | inline void drvSetMargins(void *param, const QMargins &mr) 271 | { 272 | if (param == 0) { 273 | return; 274 | } 275 | margins_head *h = (margins_head*)param; 276 | h->left = mr.left(); 277 | h->top = mr.top(); 278 | h->right = mr.right(); 279 | h->bottom = mr.bottom(); 280 | } 281 | 282 | inline bool drvGetBool(void *param) 283 | { 284 | return *(int*)param != 0; 285 | } 286 | 287 | inline void drvSetBool(void *param, bool b) 288 | { 289 | *(int*)param = b?1:0; 290 | } 291 | 292 | inline int drvGetInt(void *param) 293 | { 294 | return *(int*)param; 295 | } 296 | 297 | inline int drvGetUint(void *param) 298 | { 299 | return *(uint*)param; 300 | } 301 | 302 | inline void drvSetInt(void *param, int value) 303 | { 304 | *(int*)param = value; 305 | } 306 | 307 | inline QSystemTrayIcon::MessageIcon drvGetMessageIconType(void *param) 308 | { 309 | return QSystemTrayIcon::MessageIcon(*(int*)param); 310 | } 311 | 312 | inline Qt::Alignment drvGetAlignment(void *param) 313 | { 314 | return (Qt::Alignment)(*(int*)param); 315 | } 316 | 317 | inline void drvSetAlignment(void *param,Qt::Alignment value) 318 | { 319 | *(int*)param = value; 320 | } 321 | 322 | inline Qt::Orientation drvGetOrientation(void *param) 323 | { 324 | return (Qt::Orientation)(*(int*)param); 325 | } 326 | 327 | inline void drvSetOrientation(void *param, Qt::Orientation value) 328 | { 329 | *(int*)param = value; 330 | } 331 | 332 | inline QSlider::TickPosition drvGetTickPosition(void *param) 333 | { 334 | return (QSlider::TickPosition)(*(int*)param); 335 | } 336 | 337 | inline void drvSetTickPosition(void *param, QSlider::TickPosition value) 338 | { 339 | *(int*)param = value; 340 | } 341 | 342 | inline Qt::ToolButtonStyle drvGetToolButtonStyle(void *param) 343 | { 344 | return (Qt::ToolButtonStyle)(*(int*)param); 345 | } 346 | 347 | inline void drvSetToolButtonStyle(void *param, Qt::ToolButtonStyle value) 348 | { 349 | *(int*)param = value; 350 | } 351 | 352 | inline QToolButton::ToolButtonPopupMode drvGetToolButtonPopupMode(void *param) 353 | { 354 | return (QToolButton::ToolButtonPopupMode)(*(int*)param); 355 | } 356 | 357 | inline void drvSetToolButtonPopupMode(void *param, QToolButton::ToolButtonPopupMode value) 358 | { 359 | *(int*)param = value; 360 | } 361 | 362 | 363 | inline double drvGetFloat64(void *param) 364 | { 365 | return *(double*)param; 366 | } 367 | 368 | inline void drvSetFloat64(void *param, double value) 369 | { 370 | *(double*)param = value; 371 | } 372 | 373 | inline void drvSetHandle(void *param, void *obj) 374 | { 375 | if (obj && param) { 376 | handle_head *head = (handle_head*)param; 377 | head->native = obj; 378 | } 379 | } 380 | 381 | inline void* drvGetNative(void *param) 382 | { 383 | if (param == 0) { 384 | return 0; 385 | } 386 | return ((handle_head*)param)->native; 387 | } 388 | 389 | inline QWidget* drvGetWidget(void *param) 390 | { 391 | if (param == 0) { 392 | return 0; 393 | } 394 | return (QWidget*)((handle_head*)param)->native; 395 | } 396 | 397 | inline QLayout* drvGetLayout(void *param) 398 | { 399 | if (param == 0) { 400 | return 0; 401 | } 402 | return (QLayout*)((handle_head*)param)->native; 403 | } 404 | 405 | inline QMenu* drvGetMenu(void *param) 406 | { 407 | if (param == 0) { 408 | return 0; 409 | } 410 | return (QMenu*)((handle_head*)param)->native; 411 | } 412 | 413 | inline QMenuBar* drvGetMenuBar(void *param) 414 | { 415 | return (QMenuBar*)drvGetNative(param); 416 | } 417 | 418 | inline QAction* drvGetAction(void *param) 419 | { 420 | if (param == 0) { 421 | return 0; 422 | } 423 | return (QAction*)((handle_head*)param)->native; 424 | } 425 | 426 | inline QIcon drvGetIcon(void *param) 427 | { 428 | QIcon *icon = (QIcon*)drvGetNative(param); 429 | if (!icon) { 430 | return QIcon(); 431 | } 432 | return *icon; 433 | } 434 | 435 | inline void drvSetIcon(void *param, const QIcon &icon) 436 | { 437 | drvSetHandle(param,theApp->insertIcon(icon)); 438 | } 439 | 440 | inline QFont drvGetFont(void *param) 441 | { 442 | QFont *font = (QFont*)drvGetNative(param); 443 | if (!font) { 444 | return QFont(); 445 | } 446 | return *font; 447 | } 448 | 449 | inline void drvSetFont(void *param, const QFont &font) 450 | { 451 | drvSetHandle(param,theApp->insertFont(font)); 452 | } 453 | 454 | inline void drvSetAction(void *param, QAction *act) 455 | { 456 | drvSetHandle(param,act); 457 | } 458 | 459 | inline void drvSetMenu(void *param, QMenu *menu) 460 | { 461 | drvSetHandle(param,menu); 462 | } 463 | 464 | inline void drvSetMenuBar(void *param, QMenuBar *bar) 465 | { 466 | drvSetHandle(param,bar); 467 | } 468 | 469 | inline void drvSetStatusBar(void *param, QStatusBar *bar) 470 | { 471 | drvSetHandle(param,bar); 472 | } 473 | 474 | inline QStatusBar* drvGetStatusBar(void *param) 475 | { 476 | return (QStatusBar*)drvGetNative(param); 477 | } 478 | 479 | inline QToolBar* drvGetToolBar(void *param) 480 | { 481 | return (QToolBar*)drvGetNative(param); 482 | } 483 | 484 | inline QDockWidget* drvGetDockWidget(void *param) 485 | { 486 | return (QDockWidget*)drvGetNative(param); 487 | } 488 | 489 | inline QListWidgetItem* drvGetListWidgetItem(void *param) 490 | { 491 | return (QListWidgetItem*)drvGetNative(param); 492 | } 493 | inline void drvSetListWidgetItem(void *param, QListWidgetItem* item) 494 | { 495 | drvSetHandle(param,item); 496 | } 497 | 498 | inline QPixmap drvGetPixmap(void *param) 499 | { 500 | QPixmap *pixmap = (QPixmap*)drvGetNative(param); 501 | if (!pixmap) { 502 | return QPixmap(); 503 | } 504 | return *pixmap; 505 | } 506 | 507 | inline void drvSetPixmap(void *param, const QPixmap &pixmap) 508 | { 509 | drvSetHandle(param,theApp->insertPixmap(pixmap)); 510 | } 511 | 512 | inline void drvSetPixmap(void *param, const QPixmap *pixmap) 513 | { 514 | if (pixmap == 0) { 515 | return; 516 | } 517 | drvSetHandle(param,theApp->insertPixmap(*pixmap)); 518 | } 519 | 520 | inline QImage drvGetImage(void *param) 521 | { 522 | QImage *image = (QImage*)drvGetNative(param); 523 | if (!image) { 524 | return QImage(); 525 | } 526 | return *image; 527 | } 528 | 529 | inline void drvSetImage(void *param, const QImage &image) 530 | { 531 | drvSetHandle(param,theApp->insertImage(image)); 532 | } 533 | 534 | inline void drvSetImage(void *param, const QImage *image) 535 | { 536 | if (image == 0) { 537 | return; 538 | } 539 | drvSetHandle(param,theApp->insertImage(*image)); 540 | } 541 | 542 | inline QPen drvGetPen(void *param) 543 | { 544 | QPen *pen = (QPen*)drvGetNative(param); 545 | if (!pen) { 546 | return QPen(); 547 | } 548 | return *pen; 549 | } 550 | 551 | inline void drvSetPen(void *param, const QPen &pen) 552 | { 553 | drvSetHandle(param,theApp->insertPen(pen)); 554 | } 555 | 556 | inline QBrush drvGetBrush(void *param) 557 | { 558 | QBrush *brush = (QBrush*)drvGetNative(param); 559 | if (!brush) { 560 | return QBrush(); 561 | } 562 | return *brush; 563 | } 564 | 565 | inline void drvSetBrush(void *param, const QBrush &brush) 566 | { 567 | drvSetHandle(param,theApp->insertBrush(brush)); 568 | } 569 | 570 | inline void drvNewObj(void *a0, QObject *obj, bool reg = true) 571 | { 572 | handle_head *head =(handle_head*)a0; 573 | head->native = obj; 574 | if (reg) { 575 | QObject::connect(obj,SIGNAL(destroyed(QObject*)),theApp,SLOT(deleteObject(QObject*))); 576 | } 577 | } 578 | 579 | inline void drvNewObj(void *a0, QWidget *obj, bool reg = true, bool delete_close = true) 580 | { 581 | handle_head *head =(handle_head*)a0; 582 | head->native = obj; 583 | if (delete_close) { 584 | obj->setAttribute(Qt::WA_DeleteOnClose); 585 | } 586 | if (reg) { 587 | QObject::connect(obj,SIGNAL(destroyed(QObject*)),((QtApp*)qApp),SLOT(deleteObject(QObject*))); 588 | } 589 | } 590 | 591 | inline void drvNewObj(void *a0, void *obj) 592 | { 593 | handle_head *head =(handle_head*)a0; 594 | head->native = obj; 595 | } 596 | 597 | template 598 | inline void drvDelObj(void *a0, T *obj) 599 | { 600 | if (a0 == 0 || obj == 0) { 601 | return; 602 | } 603 | handle_head *head =(handle_head*)a0; 604 | if (head->native == 0 || head->native == drvInvalid) { 605 | return; 606 | } 607 | head->native = 0; 608 | delete obj; 609 | } 610 | 611 | inline void drvDelFont(void *a0, QFont *font) 612 | { 613 | theApp->removeFont(font); 614 | drvDelObj(a0,font); 615 | } 616 | 617 | inline void drvDelIcon(void *a0, QIcon *icon) 618 | { 619 | theApp->removeIcon(icon); 620 | drvDelObj(a0,icon); 621 | } 622 | 623 | inline void drvDelPixmap(void *a0, QPixmap *pixmap) 624 | { 625 | theApp->removePixmap(pixmap); 626 | drvDelObj(a0,pixmap); 627 | } 628 | 629 | inline void drvDelImage(void *a0, QImage *image) 630 | { 631 | theApp->removeImage(image); 632 | drvDelObj(a0,image); 633 | } 634 | 635 | inline void drvDelPen(void *a0, QPen *pen) 636 | { 637 | theApp->removePen(pen); 638 | drvDelObj(a0,pen); 639 | } 640 | 641 | inline void drvDelBrush(void *a0, QBrush *brush) 642 | { 643 | theApp->removeBrush(brush); 644 | drvDelObj(a0,brush); 645 | } 646 | 647 | inline QtSignal* drvNewSignal(QObject *parent, void *fn, void *param = 0) 648 | { 649 | QtSignal *s = new QtSignal(0,fn); 650 | s->moveToThread(parent->thread()); 651 | s->setParent(parent); 652 | return s; 653 | } 654 | 655 | inline void drvNewEvent(int type, void *a0, void *a1, void *a2 = 0) 656 | { 657 | handle_head* head = (handle_head*)a0; 658 | QObject *obj = (QObject*)head->native; 659 | QtApp *app = (QtApp*)qApp; 660 | app->eventLock.lock(); 661 | QtEvent *ev = ((QtApp*)qApp)->eventMap.value(obj); 662 | if (ev == 0) { 663 | ev = new QtEvent; 664 | ev->moveToThread(obj->thread()); 665 | ev->setParent(obj); 666 | obj->installEventFilter(ev); 667 | ((QtApp*)qApp)->eventMap.insert(obj,ev); 668 | } 669 | ev->setEvent(type,a1); 670 | app->eventLock.unlock(); 671 | } 672 | 673 | 674 | int drv_callback(void* fn, void *a1,void* a2,void* a3,void* a4); 675 | int drv_result(void* ch, int r); 676 | int drv_appmain(); 677 | 678 | extern "C" 679 | int QTDRVSHARED_EXPORT drv(int drvclass, int drvid, void *exp, void *a0, void* a1, void* a2, void* a3, void* a4, void* a5, void* a6); 680 | 681 | int _drv(int drvclass, int drvid, void *a0, void* a1, void* a2, void* a3, void* a4, void* a5, void* a6); 682 | -------------------------------------------------------------------------------- /qtdrv/qtapp.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | ** Copyright 2012 visualfc . All rights reserved. 3 | ** 4 | ** This library is free software; you can redistribute it and/or 5 | ** modify it under the terms of the GNU Lesser General Public 6 | ** License as published by the Free Software Foundation; either 7 | ** version 2.1 of the License, or (at your option) any later version. 8 | ** 9 | ** This library is distributed in the hope that it will be useful, 10 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | ** Lesser General Public License for more details. 13 | *********************************************************************/ 14 | 15 | #define _private private 16 | #define private public 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | static void* drvGetFontKey(const QFont *font) 24 | { 25 | return font->d.data(); 26 | } 27 | void* drvGetPixmapKey(const QPixmap *pixmap) 28 | { 29 | return pixmap->pixmapData(); 30 | } 31 | void* drvGetImageKey(const QImage *image) 32 | { 33 | return image->d; 34 | } 35 | void* drvGetIconKey(const QIcon *icon) 36 | { 37 | return icon->d; 38 | } 39 | void* drvGetPenKey(const QPen *pen) 40 | { 41 | return pen->d; 42 | } 43 | void* drvGetBrushKey(const QBrush *brush) 44 | { 45 | return brush->d.data(); 46 | } 47 | #undef private 48 | #define private _private 49 | 50 | #include "qtapp.h" 51 | #include "cdrv.h" 52 | 53 | QtApp *theApp = 0; 54 | 55 | QtApp::QtApp(int argc, char **argv) : 56 | QApplication(argc,argv), pfnDeleteObj(0) 57 | { 58 | theApp = this; 59 | } 60 | 61 | int QtApp::drv(int drvclass, int drvid, void *ch, void *a0, void *a1, void *a2, void *a3, void *a4, void *a5, void *a6) 62 | { 63 | int r = _drv(drvclass,drvid,a0,a1,a2,a3,a4,a5,a6); 64 | drv_result(ch,r); 65 | return 0; 66 | } 67 | 68 | void QtApp::deleteObject(QObject *obj) 69 | { 70 | drv_callback(pfnDeleteObj,obj,0,0,0); 71 | } 72 | 73 | void QtApp::deleteObj(void *obj) 74 | { 75 | drv_callback(pfnDeleteObj,obj,0,0,0); 76 | } 77 | 78 | void* QtApp::insertFont(const QFont &font) 79 | { 80 | void *key = drvGetFontKey(&font); 81 | QFont *p = fonts.value(key); 82 | if (p == 0) { 83 | p = new QFont(font); 84 | fonts.insert(key,p); 85 | } 86 | return p; 87 | } 88 | 89 | void QtApp::removeFont(QFont *font) 90 | { 91 | void *key = drvGetFontKey(font); 92 | if (fonts.remove(key)) { 93 | drv_callback(pfnDeleteObj,font,0,0,0); 94 | } 95 | } 96 | 97 | void* QtApp::insertIcon(const QIcon &icon) 98 | { 99 | void *key = drvGetIconKey(&icon); 100 | QIcon *p = icons.value(key); 101 | if (p == 0) { 102 | p = new QIcon(icon); 103 | icons.insert(key,p); 104 | } 105 | return p; 106 | } 107 | 108 | void QtApp::removeIcon(QIcon *icon) 109 | { 110 | void *key = drvGetIconKey(icon); 111 | if (icons.remove(key)) { 112 | drv_callback(pfnDeleteObj,icon,0,0,0); 113 | } 114 | } 115 | 116 | void* QtApp::insertPixmap(const QPixmap &pix) 117 | { 118 | void *key = drvGetPixmapKey(&pix); 119 | QPixmap *p = pixs.value(key); 120 | if (p == 0) { 121 | p = new QPixmap(pix); 122 | pixs.insert(key,p); 123 | } 124 | return p; 125 | } 126 | 127 | void QtApp::removePixmap(QPixmap *pix) 128 | { 129 | void *key = drvGetPixmapKey(pix); 130 | if (pixs.remove(key)) { 131 | drv_callback(pfnDeleteObj,pix,0,0,0); 132 | } 133 | } 134 | 135 | void* QtApp::insertImage(const QImage &img) 136 | { 137 | void *key = drvGetImageKey(&img); 138 | QImage *p = imgs.value(key); 139 | if (p == 0) { 140 | p = new QImage(img); 141 | imgs.insert(key,p); 142 | } 143 | return p; 144 | } 145 | 146 | void QtApp::removeImage(QImage *img) 147 | { 148 | void *key = drvGetImageKey(img); 149 | if (imgs.remove(key)) { 150 | drv_callback(pfnDeleteObj,img,0,0,0); 151 | } 152 | } 153 | 154 | void* QtApp::insertPen(const QPen &v) 155 | { 156 | void *key = drvGetPenKey(&v); 157 | QPen *p = pens.value(key); 158 | if (p == 0) { 159 | p = new QPen(v); 160 | pens.insert(key,p); 161 | } 162 | return p; 163 | } 164 | 165 | void QtApp::removePen(QPen *v) 166 | { 167 | void *key = drvGetPenKey(v); 168 | if (pens.remove(key)) { 169 | drv_callback(pfnDeleteObj,v,0,0,0); 170 | } 171 | } 172 | 173 | void* QtApp::insertBrush(const QBrush &v) 174 | { 175 | void *key = drvGetBrushKey(&v); 176 | QBrush *p = brus.value(key); 177 | if (p == 0) { 178 | p = new QBrush(v); 179 | brus.insert(key,p); 180 | } 181 | return p; 182 | } 183 | 184 | void QtApp::removeBrush(QBrush *v) 185 | { 186 | void *key = drvGetBrushKey(v); 187 | if (brus.remove(key)) { 188 | drv_callback(pfnDeleteObj,v,0,0,0); 189 | } 190 | } 191 | 192 | -------------------------------------------------------------------------------- /qtdrv/qtapp.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | ** Copyright 2012 visualfc . All rights reserved. 3 | ** 4 | ** This library is free software; you can redistribute it and/or 5 | ** modify it under the terms of the GNU Lesser General Public 6 | ** License as published by the Free Software Foundation; either 7 | ** version 2.1 of the License, or (at your option) any later version. 8 | ** 9 | ** This library is distributed in the hope that it will be useful, 10 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | ** Lesser General Public License for more details. 13 | *********************************************************************/ 14 | 15 | 16 | #ifndef QTAPP_H 17 | #define QTAPP_H 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include "qtevent.h" 25 | 26 | struct drv_param { 27 | int classid; 28 | int drvid; 29 | void *a0; 30 | void *a1; 31 | void *a2; 32 | void *a3; 33 | void *a4; 34 | void *a5; 35 | void *a6; 36 | void *a7; 37 | void *a8; 38 | void *a9; 39 | }; 40 | 41 | Q_DECLARE_METATYPE(drv_param) 42 | Q_DECLARE_METATYPE(drv_param*) 43 | 44 | class QtApp : public QApplication 45 | { 46 | Q_OBJECT 47 | public: 48 | explicit QtApp(int argc = 0, char **argv = NULL); 49 | public slots: 50 | int drv(int drvclass, int drvid, void *ch, void *a0, void* a1, void* a2, void* a3, void* a4, void* a5, void* a6); 51 | void deleteObject(QObject *obj); 52 | public: 53 | void deleteObj(void *obj); 54 | public: 55 | void* insertFont(const QFont &font); 56 | void removeFont(QFont *font); 57 | void* insertIcon(const QIcon &icon); 58 | void removeIcon(QIcon *icon); 59 | void* insertPixmap(const QPixmap &pix); 60 | void removePixmap(QPixmap *pix); 61 | void* insertImage(const QImage &img); 62 | void removeImage(QImage *img); 63 | void* insertPen(const QPen &v); 64 | void removePen(QPen *v); 65 | void* insertBrush(const QBrush &v); 66 | void removeBrush(QBrush *v); 67 | protected: 68 | QMap fonts; 69 | QMap icons; 70 | QMap pixs; 71 | QMap imgs; 72 | QMap pens; 73 | QMap brus; 74 | public: 75 | void *pfnDeleteObj; 76 | QMap eventMap; 77 | QMutex eventLock; 78 | }; 79 | 80 | extern QtApp *theApp; 81 | 82 | 83 | #endif // QTAPP_H 84 | -------------------------------------------------------------------------------- /qtdrv/qtdrv.pro: -------------------------------------------------------------------------------- 1 | # Copyright 2012 visualfc . All rights reserved. 2 | # 3 | # This library is free software; you can redistribute it and/or 4 | # modify it under the terms of the GNU Lesser General Public 5 | # License as published by the Free Software Foundation; either 6 | # version 2.1 of the License, or (at your option) any later version. 7 | # 8 | # This library is distributed in the hope that it will be useful, 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | # Lesser General Public License for more details. 12 | 13 | TARGET = qtdrv 14 | TEMPLATE = lib 15 | 16 | DEFINES += QTDRV_LIBRARY 17 | 18 | SOURCES += cdrv.cpp \ 19 | qtsignal.cpp \ 20 | qtevent.cpp \ 21 | qtapp.cpp 22 | 23 | HEADERS += cdrv.h\ 24 | qtdrv_global.h \ 25 | qtsignal.h \ 26 | qtevent.h \ 27 | qtapp.h \ 28 | qtshell.h 29 | 30 | IDE_BUILD_TREE = $$PWD 31 | IDE_LIB_PATH = $$IDE_BUILD_TREE/../lib 32 | 33 | DESTDIR = $$IDE_LIB_PATH 34 | 35 | symbian { 36 | MMP_RULES += EXPORTUNFROZEN 37 | TARGET.UID3 = 0xE1B1CE15 38 | TARGET.CAPABILITY = 39 | TARGET.EPOCALLOWDLLDATA = 1 40 | addFiles.sources = qtdrv.dll 41 | addFiles.path = !:/sys/bin 42 | DEPLOYMENT += addFiles 43 | } 44 | 45 | unix:!symbian { 46 | maemo5 { 47 | target.path = /opt/usr/lib 48 | } else { 49 | target.path = /usr/lib 50 | } 51 | INSTALLS += target 52 | } 53 | -------------------------------------------------------------------------------- /qtdrv/qtdrv_global.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | ** Copyright 2012 visualfc . All rights reserved. 3 | ** 4 | ** This library is free software; you can redistribute it and/or 5 | ** modify it under the terms of the GNU Lesser General Public 6 | ** License as published by the Free Software Foundation; either 7 | ** version 2.1 of the License, or (at your option) any later version. 8 | ** 9 | ** This library is distributed in the hope that it will be useful, 10 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | ** Lesser General Public License for more details. 13 | *********************************************************************/ 14 | 15 | 16 | #ifndef QTDRV_GLOBAL_H 17 | #define QTDRV_GLOBAL_H 18 | 19 | #include 20 | 21 | #if defined(QTDRV_LIBRARY) 22 | # define QTDRVSHARED_EXPORT Q_DECL_EXPORT 23 | #else 24 | # define QTDRVSHARED_EXPORT Q_DECL_IMPORT 25 | #endif 26 | 27 | #endif // QTDRV_GLOBAL_H 28 | -------------------------------------------------------------------------------- /qtdrv/qtevent.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | ** Copyright 2012 visualfc . All rights reserved. 3 | ** 4 | ** This library is free software; you can redistribute it and/or 5 | ** modify it under the terms of the GNU Lesser General Public 6 | ** License as published by the Free Software Foundation; either 7 | ** version 2.1 of the License, or (at your option) any later version. 8 | ** 9 | ** This library is distributed in the hope that it will be useful, 10 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | ** Lesser General Public License for more details. 13 | *********************************************************************/ 14 | 15 | #include "qtevent.h" 16 | #include "cdrv.h" 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | struct base_event { 30 | int accept; 31 | }; 32 | 33 | struct timer_event { 34 | int accept; 35 | int timerid; 36 | }; 37 | 38 | struct move_event { 39 | int accept; 40 | int x; 41 | int y; 42 | int ox; 43 | int oy; 44 | }; 45 | 46 | struct hover_event { 47 | int accept; 48 | int x; 49 | int y; 50 | int ox; 51 | int oy; 52 | }; 53 | 54 | struct resize_event { 55 | int accept; 56 | int w; 57 | int h; 58 | int ow; 59 | int oh; 60 | }; 61 | 62 | struct mouse_event { 63 | int accept; 64 | int modify; 65 | int button; 66 | int buttons; 67 | int gx; 68 | int gy; 69 | int x; 70 | int y; 71 | }; 72 | 73 | struct key_event { 74 | int accept; 75 | int modify; 76 | int count; 77 | int autorepeat; 78 | int key; 79 | quint32 nativeModifiers; 80 | quint32 nativeScanCode; 81 | quint32 nativeVirtualKey; 82 | string_head *sh; 83 | }; 84 | 85 | struct paint_event { 86 | int accept; 87 | int x; 88 | int y; 89 | int w; 90 | int h; 91 | }; 92 | 93 | struct focus_event { 94 | int accept; 95 | int reason; 96 | }; 97 | 98 | QtEvent::QtEvent(QObject *parent) : 99 | QObject(parent) 100 | { 101 | } 102 | 103 | void QtEvent::setEvent(int type, void *func) 104 | { 105 | m_hash.insert(type,func); 106 | } 107 | 108 | bool QtEvent::eventFilter(QObject *target, QEvent *event) 109 | { 110 | int type = event->type(); 111 | void *func = m_hash.value(type); 112 | if (func != 0) { 113 | int accept = event->isAccepted() ? 1 : 0; 114 | switch(type) { 115 | case QEvent::Create: 116 | case QEvent::Close: 117 | case QEvent::Show: 118 | case QEvent::Hide: 119 | case QEvent::Enter: 120 | case QEvent::Leave: { 121 | base_event ev = {accept}; 122 | drv_callback(func,&ev,0,0,0); 123 | event->setAccepted(ev.accept != 0); 124 | break; 125 | } 126 | case QEvent::FocusIn: 127 | case QEvent::FocusOut: { 128 | QFocusEvent *e = (QFocusEvent*)event; 129 | focus_event ev = {accept,e->reason()}; 130 | drv_callback(func,&ev,0,0,0); 131 | event->setAccepted(ev.accept != 0); 132 | break; 133 | } 134 | case QEvent::Timer: { 135 | QTimerEvent *e = (QTimerEvent*)event; 136 | timer_event ev = {accept,e->timerId()}; 137 | drv_callback(func,&ev,0,0,0); 138 | event->setAccepted(ev.accept != 0); 139 | break; 140 | } 141 | case QEvent::HoverEnter: 142 | case QEvent::HoverLeave: 143 | case QEvent::HoverMove: { 144 | QHoverEvent *e = (QHoverEvent*)event; 145 | const QPoint &pt = e->pos(); 146 | const QPoint &opt = e->oldPos(); 147 | hover_event ev = {accept,pt.x(),pt.y(),opt.x(),opt.y()}; 148 | drv_callback(func,&ev,0,0,0); 149 | event->setAccepted(ev.accept != 0); 150 | break; 151 | } 152 | case QEvent::KeyPress: 153 | case QEvent::KeyRelease: { 154 | QKeyEvent *e = (QKeyEvent*)event; 155 | string_head sh; 156 | drvSetString(&sh,e->text()); 157 | key_event ev = {accept,e->modifiers(),e->count(),e->isAutoRepeat()?1:0,e->key(),e->nativeModifiers(),e->nativeScanCode(),e->nativeVirtualKey(),&sh}; 158 | drv_callback(func,&ev,0,0,0); 159 | event->setAccepted(ev.accept != 0); 160 | break; 161 | } 162 | case QEvent::MouseButtonPress: 163 | case QEvent::MouseButtonRelease: 164 | case QEvent::MouseButtonDblClick: 165 | case QEvent::MouseMove: { 166 | QMouseEvent *e = (QMouseEvent*)event; 167 | const QPoint &gpt = e->globalPos(); 168 | const QPoint &pt = e->pos(); 169 | mouse_event ev = {accept,e->modifiers(),e->button(),e->buttons(),gpt.x(),gpt.y(),pt.x(),pt.y()}; 170 | drv_callback(func,&ev,0,0,0); 171 | event->setAccepted(ev.accept != 0); 172 | break; 173 | } 174 | case QEvent::Move: { 175 | QMoveEvent *e = (QMoveEvent*)event; 176 | const QPoint &pt = e->pos(); 177 | const QPoint &opt = e->oldPos(); 178 | move_event ev = {accept,pt.x(),pt.y(),opt.x(),opt.y()}; 179 | drv_callback(func,&ev,0,0,0); 180 | event->setAccepted(ev.accept != 0); 181 | break; 182 | } 183 | case QEvent::Resize: { 184 | QResizeEvent *e = (QResizeEvent*)event; 185 | const QSize &sz = e->size(); 186 | const QSize &osz = e->oldSize(); 187 | resize_event ev = {accept,sz.width(),sz.height(),osz.width(),osz.height()}; 188 | drv_callback(func,&ev,0,0,0); 189 | event->setAccepted(ev.accept != 0); 190 | break; 191 | } 192 | case QEvent::Paint: { 193 | QPaintEvent *e = (QPaintEvent*)event; 194 | const QRect &rc = e->rect(); 195 | paint_event ev = {accept,rc.x(),rc.y(),rc.width(),rc.height()}; 196 | drv_callback(func,&ev,0,0,0); 197 | event->setAccepted(ev.accept != 0); 198 | break; 199 | } 200 | default: { 201 | return QObject::eventFilter(target,event); 202 | } 203 | } 204 | return true; 205 | } 206 | return QObject::eventFilter(target,event); 207 | } 208 | -------------------------------------------------------------------------------- /qtdrv/qtevent.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | ** Copyright 2012 visualfc . All rights reserved. 3 | ** 4 | ** This library is free software; you can redistribute it and/or 5 | ** modify it under the terms of the GNU Lesser General Public 6 | ** License as published by the Free Software Foundation; either 7 | ** version 2.1 of the License, or (at your option) any later version. 8 | ** 9 | ** This library is distributed in the hope that it will be useful, 10 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | ** Lesser General Public License for more details. 13 | *********************************************************************/ 14 | 15 | #ifndef QTEVENT_H 16 | #define QTEVENT_H 17 | 18 | #include 19 | #include 20 | 21 | class QtEvent : public QObject 22 | { 23 | Q_OBJECT 24 | public: 25 | explicit QtEvent(QObject *parent = 0); 26 | void setEvent(int type, void *func); 27 | virtual bool eventFilter(QObject *target, QEvent *event); 28 | protected: 29 | QHash m_hash; 30 | }; 31 | 32 | #endif // QTEVENT_H 33 | -------------------------------------------------------------------------------- /qtdrv/qtshell.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | ** Copyright 2012 visualfc . All rights reserved. 3 | ** 4 | ** This library is free software; you can redistribute it and/or 5 | ** modify it under the terms of the GNU Lesser General Public 6 | ** License as published by the Free Software Foundation; either 7 | ** version 2.1 of the License, or (at your option) any later version. 8 | ** 9 | ** This library is distributed in the hope that it will be useful, 10 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | ** Lesser General Public License for more details. 13 | *********************************************************************/ 14 | 15 | #ifndef QTSHELL_H 16 | #define QTSHELL_H 17 | 18 | #include "qtapp.h" 19 | #include 20 | 21 | class ShellListWidgetItem : public QListWidgetItem 22 | { 23 | public: 24 | ShellListWidgetItem() : QListWidgetItem() 25 | { 26 | } 27 | ShellListWidgetItem(const QString &text) : QListWidgetItem(text) 28 | { 29 | 30 | } 31 | 32 | ~ShellListWidgetItem() 33 | { 34 | theApp->deleteObj(this); 35 | } 36 | }; 37 | 38 | 39 | #endif // QTSHELL_H 40 | -------------------------------------------------------------------------------- /qtdrv/qtsignal.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | ** Copyright 2012 visualfc . All rights reserved. 3 | ** 4 | ** This library is free software; you can redistribute it and/or 5 | ** modify it under the terms of the GNU Lesser General Public 6 | ** License as published by the Free Software Foundation; either 7 | ** version 2.1 of the License, or (at your option) any later version. 8 | ** 9 | ** This library is distributed in the hope that it will be useful, 10 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | ** Lesser General Public License for more details. 13 | *********************************************************************/ 14 | 15 | #include "qtsignal.h" 16 | #include "cdrv.h" 17 | #include 18 | 19 | QtSignal::QtSignal(QObject *parent, void *func) : 20 | QObject(parent), m_func(func) 21 | { 22 | } 23 | 24 | QtSignal::~QtSignal() 25 | { 26 | } 27 | 28 | void QtSignal::call() 29 | { 30 | drv_callback(m_func,0,0,0,0); 31 | } 32 | 33 | void QtSignal::call(bool b) 34 | { 35 | int i = b ? 1:0; 36 | drv_callback(m_func,&i,0,0,0); 37 | } 38 | 39 | void QtSignal::call(int i) 40 | { 41 | drv_callback(m_func,&i,0,0,0); 42 | } 43 | 44 | void QtSignal::call(const QString& s) 45 | { 46 | string_head sh; 47 | drvSetString(&sh,s); 48 | drv_callback(m_func,&sh,0,0,0); 49 | } 50 | 51 | void QtSignal::call(QAction *act) 52 | { 53 | drv_callback(m_func,act,0,0,0); 54 | } 55 | 56 | void QtSignal::call(QListWidgetItem* item) 57 | { 58 | drv_callback(m_func,item,0,0,0); 59 | } 60 | 61 | void QtSignal::call(QListWidgetItem* item,QListWidgetItem* olditem) 62 | { 63 | drv_callback(m_func,item,olditem,0,0); 64 | } 65 | -------------------------------------------------------------------------------- /qtdrv/qtsignal.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | ** Copyright 2012 visualfc . All rights reserved. 3 | ** 4 | ** This library is free software; you can redistribute it and/or 5 | ** modify it under the terms of the GNU Lesser General Public 6 | ** License as published by the Free Software Foundation; either 7 | ** version 2.1 of the License, or (at your option) any later version. 8 | ** 9 | ** This library is distributed in the hope that it will be useful, 10 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | ** Lesser General Public License for more details. 13 | *********************************************************************/ 14 | 15 | #ifndef QTSIGNAL_H 16 | #define QTSIGNAL_H 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | class QtSignal : public QObject 23 | { 24 | Q_OBJECT 25 | public: 26 | explicit QtSignal(QObject *parent,void *func); 27 | virtual ~QtSignal(); 28 | public slots: 29 | void call(); 30 | void call(bool); 31 | void call(int); 32 | void call(const QString&); 33 | void call(QAction*); 34 | void call(QListWidgetItem*); 35 | void call(QListWidgetItem*,QListWidgetItem*); 36 | public: 37 | void *m_func; 38 | }; 39 | 40 | #endif // QTSIGNAL_H 41 | -------------------------------------------------------------------------------- /ui/cdrv.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 visualfc . All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package ui 6 | 7 | /* 8 | #include 9 | extern int drv(int id, int action, void *exp, void *a0, void* a1, void* a2, void* a3, void* a4, void* a5, void* a6); 10 | 11 | static void init_callback(int classid, int drvid) 12 | { 13 | extern int drv_callback(void*,void*,void*,void*,void*); 14 | drv(classid,drvid,&drv_callback,0,0,0,0,0,0,0); 15 | } 16 | 17 | static void init_appmain(int classid, int drvid) 18 | { 19 | extern void drv_appmain(); 20 | drv(classid,drvid,&drv_appmain,0,0,0,0,0,0,0); 21 | } 22 | 23 | static void init_result(int classid, int drvid) 24 | { 25 | extern int drv_result(void*,int); 26 | drv(classid,drvid,&drv_result,0,0,0,0,0,0,0); 27 | } 28 | 29 | static void init_utf8_info(int classid, int drvid) 30 | { 31 | extern void utf8_info_copy(void*,void*,int); 32 | drv(classid,drvid,&utf8_info_copy,0,0,0,0,0,0,0); 33 | } 34 | 35 | */ 36 | // #cgo LDFLAGS: -L../lib -lqtdrv 37 | import "C" 38 | import "unsafe" 39 | import "fmt" 40 | import "os" 41 | import "reflect" 42 | import "image/color" 43 | 44 | type string_info struct { 45 | Data uintptr 46 | Len int 47 | } 48 | 49 | type rgba uint32 50 | 51 | func (c rgba) RGBA() (r, g, b, a uint32) { 52 | return uint32((c >> 16) & 0xff), uint32((c >> 8) & 0xff), uint32(c & 0xff), uint32(c >> 24) 53 | } 54 | 55 | func make_rgba(c color.Color) rgba { 56 | if c == nil { 57 | return 0 58 | } 59 | r, g, b, a := c.RGBA() 60 | return rgba(((a & 0xff) << 24) | ((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff)) 61 | } 62 | 63 | type slice_info struct { 64 | Data uintptr 65 | Len int 66 | Cap int 67 | } 68 | 69 | type utf8_info struct { 70 | data []byte 71 | } 72 | 73 | func (d utf8_info) String() string { 74 | return string(d.data) 75 | } 76 | 77 | //export utf8_info_copy 78 | func utf8_info_copy(p unsafe.Pointer, data unsafe.Pointer, size C.int) { 79 | ((*utf8_info)(p)).data = C.GoBytes(data, size) 80 | } 81 | 82 | func _b(b bool) byte { 83 | if b { 84 | return 1 85 | } 86 | return 0 87 | } 88 | 89 | func _p(a interface{}) uintptr { 90 | if a == nil { 91 | return 0 92 | } 93 | switch v := a.(type) { 94 | case bool: 95 | return uintptr(unsafe.Pointer(&v)) 96 | case uintptr: 97 | return uintptr(unsafe.Pointer(&v)) 98 | case *uintptr: 99 | return uintptr(unsafe.Pointer(v)) 100 | case int: 101 | return uintptr(unsafe.Pointer(&v)) 102 | case *int: 103 | return uintptr(unsafe.Pointer(v)) 104 | case uint: 105 | return uintptr(unsafe.Pointer(&v)) 106 | case *uint: 107 | return uintptr(unsafe.Pointer(v)) 108 | case float32: 109 | return uintptr(unsafe.Pointer(&v)) 110 | case *float32: 111 | return uintptr(unsafe.Pointer(v)) 112 | case float64: 113 | return uintptr(unsafe.Pointer(&v)) 114 | case *float64: 115 | return uintptr(unsafe.Pointer(v)) 116 | case string: 117 | return uintptr(unsafe.Pointer((*string_info)(unsafe.Pointer(&v)))) 118 | case rgba: 119 | return uintptr(unsafe.Pointer(&v)) 120 | case *rgba: 121 | return uintptr(unsafe.Pointer(v)) 122 | case color.Color: 123 | clr := make_rgba(v) 124 | return uintptr(unsafe.Pointer(&clr)) 125 | case *utf8_info: 126 | return uintptr(unsafe.Pointer(v)) 127 | case *obj_info: 128 | return uintptr(unsafe.Pointer(v)) 129 | case iobj: 130 | return uintptr(unsafe.Pointer(v.info())) 131 | case *iobj: 132 | return uintptr(unsafe.Pointer((*v).info())) 133 | case Point: 134 | return uintptr(unsafe.Pointer(&v)) 135 | case *Point: 136 | return uintptr(unsafe.Pointer(v)) 137 | case PointF: 138 | return uintptr(unsafe.Pointer(&v)) 139 | case *PointF: 140 | return uintptr(unsafe.Pointer(v)) 141 | case Size: 142 | return uintptr(unsafe.Pointer(&v)) 143 | case *Size: 144 | return uintptr(unsafe.Pointer(v)) 145 | case SizeF: 146 | return uintptr(unsafe.Pointer(&v)) 147 | case *SizeF: 148 | return uintptr(unsafe.Pointer(v)) 149 | case Rect: 150 | return uintptr(unsafe.Pointer(&v)) 151 | case *Rect: 152 | return uintptr(unsafe.Pointer(v)) 153 | case RectF: 154 | return uintptr(unsafe.Pointer(&v)) 155 | case *RectF: 156 | return uintptr(unsafe.Pointer(v)) 157 | case Margins: 158 | return uintptr(unsafe.Pointer(&v)) 159 | case *Margins: 160 | return uintptr(unsafe.Pointer(v)) 161 | case []Point: 162 | return uintptr(unsafe.Pointer((*slice_info)(unsafe.Pointer(&v)))) 163 | case []Rect: 164 | return uintptr(unsafe.Pointer((*slice_info)(unsafe.Pointer(&v)))) 165 | case []byte: 166 | return uintptr(unsafe.Pointer((*slice_info)(unsafe.Pointer(&v)))) 167 | case Font: 168 | return uintptr(unsafe.Pointer(&v)) 169 | case *Font: 170 | return uintptr(unsafe.Pointer(v)) 171 | case *Icon: 172 | return uintptr(unsafe.Pointer(v)) 173 | case *Pixmap: 174 | return uintptr(unsafe.Pointer(v)) 175 | case *Image: 176 | return uintptr(unsafe.Pointer(v)) 177 | case *Pen: 178 | return uintptr(unsafe.Pointer(v)) 179 | case *Brush: 180 | return uintptr(unsafe.Pointer(v)) 181 | case MessageIconType: 182 | return uintptr(unsafe.Pointer(&v)) 183 | case Alignment: 184 | return uintptr(unsafe.Pointer(&v)) 185 | case *Alignment: 186 | return uintptr(unsafe.Pointer(v)) 187 | case Orientation: 188 | return uintptr(unsafe.Pointer(&v)) 189 | case *Orientation: 190 | return uintptr(unsafe.Pointer(v)) 191 | case TickPosition: 192 | return uintptr(unsafe.Pointer(&v)) 193 | case *TickPosition: 194 | return uintptr(unsafe.Pointer(v)) 195 | case ToolButtonPopupMode: 196 | return uintptr(unsafe.Pointer(&v)) 197 | case *ToolButtonPopupMode: 198 | return uintptr(unsafe.Pointer(v)) 199 | case ToolButtonStyle: 200 | return uintptr(unsafe.Pointer(&v)) 201 | case *ToolButtonStyle: 202 | return uintptr(unsafe.Pointer(v)) 203 | case DockWidgetArea: 204 | return uintptr(unsafe.Pointer(&v)) 205 | case *DockWidgetArea: 206 | return uintptr(unsafe.Pointer(v)) 207 | case PenStyle: 208 | return uintptr(unsafe.Pointer(&v)) 209 | case *PenStyle: 210 | return uintptr(unsafe.Pointer(v)) 211 | case BrushStyle: 212 | return uintptr(unsafe.Pointer(&v)) 213 | case *BrushStyle: 214 | return uintptr(unsafe.Pointer(v)) 215 | default: 216 | warning("Warning drv, param type \"%s\" not match!", reflect.TypeOf(v)) 217 | } 218 | return 0 219 | } 220 | 221 | //func drv10(id int, act int, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) int { 222 | // if id <= _CLASSID_APP { 223 | // return int(C.drv(C.int(id), C.int(act), unsafe.Pointer(a0), unsafe.Pointer(a1), unsafe.Pointer(a2), unsafe.Pointer(a3), unsafe.Pointer(a4), unsafe.Pointer(a5), unsafe.Pointer(a6), unsafe.Pointer(a7), unsafe.Pointer(a8), unsafe.Pointer(a9))) 224 | // } 225 | // ch := make(chan int) 226 | // C.drv(C.int(id), C.int(act), unsafe.Pointer(a0), unsafe.Pointer(a1), unsafe.Pointer(a2), unsafe.Pointer(a3), unsafe.Pointer(a4), unsafe.Pointer(a5), unsafe.Pointer(a6), unsafe.Pointer(&ch), unsafe.Pointer(a8), unsafe.Pointer(a9)) 227 | // <-ch 228 | // return 0 229 | //} 230 | 231 | //func drv(id int, act int, a ...interface{}) int { 232 | // switch len(a) { 233 | // case 0: 234 | // return drv10(id, act, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) 235 | // case 1: 236 | // return drv10(id, act, _p(a[0]), 0, 0, 0, 0, 0, 0, 0, 0, 0) 237 | // case 2: 238 | // return drv10(id, act, _p(a[0]), _p(a[1]), 0, 0, 0, 0, 0, 0, 0, 0) 239 | // case 3: 240 | // return drv10(id, act, _p(a[0]), _p(a[1]), _p(a[2]), 0, 0, 0, 0, 0, 0, 0) 241 | // case 4: 242 | // return drv10(id, act, _p(a[0]), _p(a[1]), _p(a[2]), _p(a[3]), 0, 0, 0, 0, 0, 0) 243 | // case 5: 244 | // return drv10(id, act, _p(a[0]), _p(a[1]), _p(a[2]), _p(a[3]), _p(a[4]), 0, 0, 0, 0, 0) 245 | // case 6: 246 | // return drv10(id, act, _p(a[0]), _p(a[1]), _p(a[2]), _p(a[3]), _p(a[4]), _p(a[5]), 0, 0, 0, 0) 247 | // case 7: 248 | // return drv10(id, act, _p(a[0]), _p(a[1]), _p(a[2]), _p(a[3]), _p(a[4]), _p(a[5]), _p(a[6]), 0, 0, 0) 249 | // case 8: 250 | // return drv10(id, act, _p(a[0]), _p(a[1]), _p(a[2]), _p(a[3]), _p(a[4]), _p(a[5]), _p(a[6]), _p(a[7]), 0, 0) 251 | // case 9: 252 | // return drv10(id, act, _p(a[0]), _p(a[1]), _p(a[2]), _p(a[3]), _p(a[4]), _p(a[5]), _p(a[6]), _p(a[7]), _p(a[9]), 0) 253 | // case 10: 254 | // return drv10(id, act, _p(a[0]), _p(a[1]), _p(a[2]), _p(a[3]), _p(a[4]), _p(a[5]), _p(a[6]), _p(a[7]), _p(a[9]), _p(a[10])) 255 | // default: 256 | // panic("drv param count must <= 10") 257 | // } 258 | // return 0 259 | //} 260 | 261 | func init() { 262 | C.init_callback(-1, 0) 263 | C.init_result(-2, 0) 264 | C.init_utf8_info(-3, 0) 265 | C.init_appmain(-4, 0) 266 | } 267 | 268 | var func_map = make(map[unsafe.Pointer]interface{}) 269 | 270 | func _drv(id int, act int, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9 unsafe.Pointer) int { 271 | return int(C.drv(C.int(id), C.int(act), nil, a0, a1, a2, a3, a4, a5, a6)) 272 | } 273 | 274 | func _drv_ch(id int, act int, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9 unsafe.Pointer) int { 275 | ch := make(chan int) 276 | C.drv(C.int(id), C.int(act), unsafe.Pointer(&ch), a0, a1, a2, a3, a4, a5, a6) 277 | <-ch 278 | return 0 279 | } 280 | 281 | func _drv_event(id int, event int, obj iobj, fn interface{}) { 282 | var pfn unsafe.Pointer = unsafe.Pointer(&fn) 283 | func_map[pfn] = fn 284 | _drv(id, event, unsafe.Pointer(obj.info()), pfn, nil, nil, nil, nil, nil, nil, nil, nil) 285 | } 286 | 287 | func _drv_event_ch(id int, event int, obj iobj, fn interface{}) { 288 | var pfn unsafe.Pointer = unsafe.Pointer(&fn) 289 | func_map[pfn] = fn 290 | _drv_ch(id, event, unsafe.Pointer(obj.info()), pfn, nil, nil, nil, nil, nil, nil, nil, nil) 291 | } 292 | 293 | func nativeToObject(native uintptr, classid int) interface{} { 294 | if native == 0 { 295 | return nil 296 | } 297 | obj := FindObject(native) 298 | if obj == nil { 299 | obj = NewObjectWithNative(classid, native) 300 | } 301 | return obj 302 | } 303 | 304 | //export drv_result 305 | func drv_result(ch unsafe.Pointer, r int) int { 306 | go func() { 307 | *(*chan int)(ch) <- r 308 | }() 309 | return 0 310 | } 311 | 312 | var theApp app 313 | var fnAppMain func() 314 | 315 | //export drv_appmain 316 | func drv_appmain() { 317 | theApp.onRemoveObject(drvRemoveObject) 318 | registerAllClass() 319 | defer clearAllObject() 320 | if fnAppMain != nil { 321 | fnAppMain() 322 | } 323 | } 324 | 325 | //export drv_callback 326 | func drv_callback(pfn unsafe.Pointer, a1, a2, a3, a4 unsafe.Pointer) int { 327 | fn, ok := func_map[pfn] 328 | if !ok { 329 | return 0 330 | } 331 | switch v := (fn).(type) { 332 | case func(): 333 | v() 334 | case func(int): 335 | v(*(*int)(a1)) 336 | case func(uint): 337 | v(*(*uint)(a1)) 338 | case func(bool): 339 | v(*(*int)(a1) != 0) 340 | case func(uintptr): 341 | v(uintptr(a1)) 342 | case func(string): 343 | v(((*utf8_info)(a1)).String()) 344 | case func(*Action): 345 | obj := nativeToObject(uintptr(a1), CLASSID_ACTION) 346 | var act *Action 347 | if v1, ok := obj.(*Action); ok { 348 | act = v1 349 | } 350 | v(act) 351 | case func(*ListWidgetItem): 352 | obj := nativeToObject(uintptr(a1), CLASSID_LISTWIDGETITEM) 353 | var item *ListWidgetItem 354 | if v1, ok := obj.(*ListWidgetItem); ok { 355 | item = v1 356 | } 357 | v(item) 358 | case func(*ListWidgetItem, *ListWidgetItem): 359 | obj1 := nativeToObject(uintptr(a1), CLASSID_LISTWIDGETITEM) 360 | obj2 := nativeToObject(uintptr(a2), CLASSID_LISTWIDGETITEM) 361 | var item *ListWidgetItem 362 | var oldItem *ListWidgetItem 363 | if v1, ok := obj1.(*ListWidgetItem); ok { 364 | item = v1 365 | } 366 | if v2, ok := obj2.(*ListWidgetItem); ok { 367 | oldItem = v2 368 | } 369 | v(item, oldItem) 370 | case func(*ShowEvent): 371 | v((*ShowEvent)(a1)) 372 | case func(*HideEvent): 373 | v((*HideEvent)(a1)) 374 | case func(*CloseEvent): 375 | v((*CloseEvent)(a1)) 376 | case func(*KeyEvent): 377 | v((*KeyEvent)(a1)) 378 | case func(*MouseEvent): 379 | v((*MouseEvent)(a1)) 380 | case func(*MoveEvent): 381 | v((*MoveEvent)(a1)) 382 | case func(*ResizeEvent): 383 | v((*ResizeEvent)(a1)) 384 | case func(*EnterEvent): 385 | v((*EnterEvent)(a1)) 386 | case func(*LeaveEvent): 387 | v((*LeaveEvent)(a1)) 388 | case func(*FocusEvent): 389 | v((*FocusEvent)(a1)) 390 | case func(*PaintEvent): 391 | v((*PaintEvent)(a1)) 392 | case func(*TimerEvent): 393 | v((*TimerEvent)(a1)) 394 | 395 | default: 396 | warning("Warning drv_callback, func type \"%s\" not match!", reflect.TypeOf(v)) 397 | } 398 | return 1 399 | } 400 | 401 | func warning(format string, a ...interface{}) { 402 | fmt.Fprintf(os.Stderr, format, a...) 403 | } 404 | -------------------------------------------------------------------------------- /ui/events.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 visualfc . All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package ui 6 | 7 | type Event interface { 8 | Accept() 9 | Ignore() 10 | IsAccept() bool 11 | } 12 | 13 | type BaseEvent struct { 14 | accept int 15 | } 16 | 17 | func (p *BaseEvent) Accept() { 18 | p.accept = 1 19 | } 20 | 21 | func (p *BaseEvent) Ignore() { 22 | p.accept = 0 23 | } 24 | 25 | func (p *BaseEvent) IsAccept() bool { 26 | return p.accept != 0 27 | } 28 | 29 | type ResizeEvent struct { 30 | BaseEvent 31 | w, h, ow, oh int 32 | } 33 | 34 | func (p *ResizeEvent) Size() Size { 35 | return Sz(p.w, p.h) 36 | } 37 | 38 | func (p *ResizeEvent) OldSize() Size { 39 | return Sz(p.ow, p.oh) 40 | } 41 | 42 | type MoveEvent struct { 43 | BaseEvent 44 | x, y int 45 | ox, oy int 46 | } 47 | 48 | func (p *MoveEvent) Pos() Point { 49 | return Pt(p.x, p.y) 50 | } 51 | 52 | func (p *MoveEvent) OldPos() Point { 53 | return Pt(p.ox, p.oy) 54 | } 55 | 56 | type HoverEvent struct { 57 | BaseEvent 58 | x, y int 59 | ox, oy int 60 | } 61 | 62 | func (p *HoverEvent) Pos() Point { 63 | return Pt(p.x, p.y) 64 | } 65 | 66 | func (p *HoverEvent) OldPos() Point { 67 | return Pt(p.ox, p.oy) 68 | } 69 | 70 | type ShowEvent struct { 71 | BaseEvent 72 | } 73 | 74 | type HideEvent struct { 75 | BaseEvent 76 | } 77 | 78 | type CloseEvent struct { 79 | BaseEvent 80 | } 81 | 82 | type EnterEvent struct { 83 | BaseEvent 84 | } 85 | 86 | type LeaveEvent struct { 87 | BaseEvent 88 | } 89 | 90 | type TimerEvent struct { 91 | BaseEvent 92 | timerid int 93 | } 94 | 95 | func (p *TimerEvent) TimerId() int { 96 | return p.timerid 97 | } 98 | 99 | type MouseEvent struct { 100 | BaseEvent 101 | modifiers int 102 | button int 103 | buttons int 104 | gx, gy int 105 | x, y int 106 | } 107 | 108 | func (p *MouseEvent) Modifiers() int { 109 | return p.modifiers 110 | } 111 | 112 | func (p *MouseEvent) Button() int { 113 | return p.button 114 | } 115 | 116 | func (p *MouseEvent) Buttons() int { 117 | return p.buttons 118 | } 119 | 120 | func (p *MouseEvent) GlobalPos() Point { 121 | return Pt(p.x, p.y) 122 | } 123 | 124 | func (p *MouseEvent) Pos() Point { 125 | return Pt(p.x, p.y) 126 | } 127 | 128 | type PaintEvent struct { 129 | BaseEvent 130 | x, y int 131 | w, h int 132 | } 133 | 134 | func (p *PaintEvent) Rect() Rect { 135 | return Rc(p.x, p.y, p.w, p.h) 136 | } 137 | 138 | type KeyEvent struct { 139 | BaseEvent 140 | modifiers int 141 | count int 142 | autorepeat int 143 | key int 144 | nativeModifiers uint32 145 | nativeScanCode uint32 146 | nativeVirtualKey uint32 147 | text *utf8_info 148 | } 149 | 150 | func (p *KeyEvent) Count() int { 151 | return p.count 152 | } 153 | 154 | func (p *KeyEvent) Modifiers() int { 155 | return p.modifiers 156 | } 157 | 158 | func (p *KeyEvent) Key() int { 159 | return p.key 160 | } 161 | 162 | func (p *KeyEvent) IsAutoRepeat() bool { 163 | return p.autorepeat != 0 164 | } 165 | 166 | func (p *KeyEvent) NativeModifiers() uint32 { 167 | return p.nativeModifiers 168 | } 169 | 170 | func (p *KeyEvent) NativeScanCode() uint32 { 171 | return p.nativeScanCode 172 | } 173 | 174 | func (p *KeyEvent) NativeVirtualKey() uint32 { 175 | return p.nativeVirtualKey 176 | } 177 | 178 | func (p *KeyEvent) Text() string { 179 | return p.text.String() 180 | } 181 | 182 | type FocusEvent struct { 183 | BaseEvent 184 | reason int 185 | } 186 | 187 | func (p *FocusEvent) Reason() int { 188 | return p.reason 189 | } 190 | -------------------------------------------------------------------------------- /ui/object.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 visualfc . All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package ui 6 | 7 | import ( 8 | "fmt" 9 | ) 10 | 11 | const ( 12 | drvInvalid uintptr = ^uintptr(0) 13 | ) 14 | 15 | type IObject interface { 16 | Close() error 17 | IsValid() bool 18 | Name() string 19 | Native() uintptr 20 | String() string 21 | SetAttr(attr string, value interface{}) bool 22 | Attr(attr string) interface{} 23 | Key() (string, string) 24 | } 25 | 26 | type IWidget interface { 27 | IObject 28 | SetLayout(ILayout) 29 | Layout() ILayout 30 | } 31 | 32 | type ILayout interface { 33 | IObject 34 | AddWidget(IWidget) 35 | } 36 | 37 | type obj_info struct { 38 | native uintptr 39 | classid int 40 | } 41 | 42 | type iobj interface { 43 | info() *obj_info 44 | setKey(key string, attr string) 45 | } 46 | 47 | type object struct { 48 | obj_info 49 | key string 50 | key_attr string 51 | } 52 | 53 | func (p *object) info() *obj_info { 54 | return &p.obj_info 55 | } 56 | 57 | func DumpObject(obj IObject) string { 58 | return fmt.Sprintf("&{%s{%p}}", obj.Name(), obj) 59 | } 60 | 61 | func DumpObjectInfo(obj iobj) string { 62 | return fmt.Sprintf("&{{%d %d}}", obj.info().native, obj.info().classid) 63 | } 64 | 65 | func (p *object) String() string { 66 | return DumpObject(p) 67 | } 68 | 69 | func (p *object) Native() uintptr { 70 | return p.native 71 | } 72 | 73 | func (p *object) Name() string { 74 | return "object" 75 | } 76 | 77 | func (p *object) Close() error { 78 | p.native = 0 79 | return nil 80 | } 81 | 82 | func (p *object) IsValid() bool { 83 | return p != nil && p.native != 0 84 | } 85 | 86 | func (p *object) setKey(key string, attr string) { 87 | p.key = key 88 | p.key_attr = attr 89 | } 90 | 91 | func (p *object) Key() (string, string) { 92 | return p.key, p.key_attr 93 | } 94 | 95 | func FindObjectForKey(key string) IObject { 96 | return key_map[key] 97 | } 98 | 99 | func (p *object) SetAttr(attr string, value interface{}) bool { 100 | return false 101 | } 102 | 103 | func (p *object) Attr(attr string) interface{} { 104 | return nil 105 | } 106 | 107 | var obj_map = make(map[uintptr]IObject) 108 | var key_map = make(map[string]IObject) 109 | 110 | func SetKey(obj IObject, key string, attr string) { 111 | k, _ := obj.Key() 112 | if k != "" && k != key { 113 | delete(key_map, k) 114 | } 115 | key_map[key] = obj 116 | if v, ok := obj.(iobj); ok { 117 | v.setKey(key, attr) 118 | } 119 | } 120 | 121 | func Value(key string) interface{} { 122 | if obj, ok := key_map[key]; ok { 123 | _, attr := obj.Key() 124 | return obj.Attr(attr) 125 | } 126 | return nil 127 | } 128 | 129 | func SetValue(key string, value interface{}) bool { 130 | if obj, ok := key_map[key]; ok { 131 | _, attr := obj.Key() 132 | return obj.SetAttr(attr, value) 133 | } 134 | return false 135 | } 136 | 137 | var fnOnInsertObject func(interface{}) 138 | var fnOnRemoveObject func(interface{}) 139 | 140 | func OnInsertObject(fn func(interface{})) { 141 | fnOnInsertObject = fn 142 | } 143 | 144 | func OnRemoveObject(fn func(interface{})) { 145 | fnOnRemoveObject = fn 146 | } 147 | 148 | func InsertObject(obj IObject) { 149 | obj_map[obj.Native()] = obj 150 | if fnOnInsertObject != nil { 151 | fnOnInsertObject(obj) 152 | } 153 | } 154 | 155 | func FindObject(native uintptr) interface{} { 156 | return obj_map[native] 157 | } 158 | 159 | func RemoveObject(native uintptr) { 160 | v := FindObject(native) 161 | if v == nil { 162 | return 163 | } 164 | if fnOnRemoveObject != nil { 165 | fnOnRemoveObject(v) 166 | } 167 | delete(obj_map, native) 168 | } 169 | 170 | func drvRemoveObject(native uintptr) { 171 | v := FindObject(native) 172 | if v == nil { 173 | return 174 | } 175 | if fnOnRemoveObject != nil { 176 | fnOnRemoveObject(v) 177 | } 178 | if obj, ok := v.(iobj); ok { 179 | obj.info().native = 0 180 | } 181 | delete(obj_map, native) 182 | } 183 | 184 | func clearAllObject() { 185 | for k, v := range obj_map { 186 | if fnOnRemoveObject != nil { 187 | fnOnRemoveObject(v) 188 | } 189 | delete(obj_map, k) 190 | v.Close() 191 | } 192 | } 193 | 194 | var newobj_map = make(map[string](func() IObject)) 195 | var newobjid_map = make(map[int](func() IObject)) 196 | var newobjnative_map = make(map[int](func(uintptr) IObject)) 197 | 198 | func RegisterClass(classname string, classid int, fn func() IObject) { 199 | newobj_map[classname] = fn 200 | newobjid_map[classid] = fn 201 | } 202 | 203 | func RegisterClassNative(classid int, fn func(uintptr) IObject) { 204 | newobjnative_map[classid] = fn 205 | } 206 | 207 | func NewObject(classname string) IObject { 208 | if fn, ok := newobj_map[classname]; ok { 209 | return fn() 210 | } 211 | return nil 212 | } 213 | 214 | func NewObjectWithId(classid int) IObject { 215 | if fn, ok := newobjid_map[classid]; ok { 216 | return fn() 217 | } 218 | return nil 219 | } 220 | 221 | func NewObjectWithNative(classid int, native uintptr) IObject { 222 | if fn, ok := newobjnative_map[classid]; ok { 223 | return fn(native) 224 | } 225 | return nil 226 | } 227 | -------------------------------------------------------------------------------- /ui/ui.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 visualfc . All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package ui 6 | 7 | func About() string { 8 | return "go-ui 0.1.1 " 9 | } 10 | 11 | func Version() string { 12 | return "go-ui 0.1.1" 13 | } 14 | 15 | func Main(fn func()) int { 16 | fnAppMain = fn 17 | return theApp.AppMain() 18 | } 19 | 20 | func Run() int { 21 | return theApp.Run() 22 | } 23 | 24 | func Exit(code int) { 25 | theApp.Exit(code) 26 | } 27 | 28 | func CloseAllWindows() { 29 | theApp.CloseAllWindows() 30 | } 31 | 32 | func App() *app { 33 | return &theApp 34 | } 35 | -------------------------------------------------------------------------------- /ui/uidefs.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 visualfc . All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package ui 6 | 7 | import ( 8 | "syscall" 9 | ) 10 | 11 | var ( 12 | EINVAL error = syscall.EINVAL 13 | ) 14 | 15 | type Alignment int 16 | 17 | const ( 18 | AlignLeft Alignment = 0x0001 19 | AlignRight Alignment = 0x0002 20 | AlignHCenter Alignment = 0x0004 21 | AlignJustify Alignment = 0x0008 22 | AlignAbsolute Alignment = 0x0010 23 | AlignHorizontal_Mask Alignment = AlignLeft | AlignRight | AlignHCenter | AlignJustify | AlignAbsolute 24 | 25 | AlignTop Alignment = 0x0020 26 | AlignBottom Alignment = 0x0040 27 | AlignVCenter Alignment = 0x0080 28 | AlignVertical_Mask Alignment = AlignTop | AlignBottom | AlignVCenter 29 | 30 | AlignCenter Alignment = AlignVCenter | AlignHCenter 31 | ) 32 | 33 | type Orientation int 34 | 35 | const ( 36 | Horizontal Orientation = 0x1 37 | Vertical Orientation = 0x2 38 | ) 39 | 40 | type TickPosition int 41 | 42 | const ( 43 | NoTicks TickPosition = iota 44 | TicksAbove 45 | TicksBelow 46 | TicksBothSides 47 | ) 48 | 49 | type DockWidgetArea int 50 | 51 | const ( 52 | NoDockWidgetArea DockWidgetArea = 0 53 | LeftDockWidgetArea DockWidgetArea = 0x01 54 | RightDockWidgetArea DockWidgetArea = 0x02 55 | TopDockWidgetArea DockWidgetArea = 0x04 56 | BottomDockWidgetArea DockWidgetArea = 0x08 57 | AllDockWidgetAreas DockWidgetArea = LeftDockWidgetArea | RightDockWidgetArea | TopDockWidgetArea | BottomDockWidgetArea 58 | ) 59 | 60 | type ItemFlag int 61 | 62 | const ( 63 | NoItemFlags ItemFlag = iota 64 | ItemIsSelectable 65 | ItemIsEditable 66 | ItemIsDragEnabled 67 | ItemIsDropEnabled 68 | ItemIsUserCheckable 69 | ItemIsEnabled 70 | ItemIsTristate 71 | ) 72 | 73 | const ( 74 | Unchecked = 0 75 | PartiallyChecked = 1 76 | Checked = 2 77 | ) 78 | 79 | const ( 80 | PlainText = 0 81 | RichText = 1 82 | AutoText = 2 83 | LogText = 3 84 | ) 85 | 86 | const ( 87 | LightWeight = 25 88 | NormalWeight = 50 89 | DemiBoldWeight = 63 90 | BoldWeight = 75 91 | BlackWeight = 87 92 | ) 93 | 94 | const ( 95 | NoModifier = 0x00000000 96 | ShiftModifier = 0x02000000 97 | ControlModifier = 0x04000000 98 | AltModifier = 0x08000000 99 | MetaModifier = 0x10000000 100 | KeypadModifier = 0x20000000 101 | GroupSwitchModifier = 0x40000000 102 | // Do not extend the mask to include 0x01000000 103 | KeyboardModifierMask = 0xfe000000 104 | ) 105 | 106 | //shorter names for shortcuts 107 | const ( 108 | META = MetaModifier 109 | SHIFT = ShiftModifier 110 | CTRL = ControlModifier 111 | ALT = AltModifier 112 | MODIFIER_MASK = KeyboardModifierMask 113 | UNICODE_ACCEL = 0x00000000 114 | ) 115 | 116 | const ( 117 | NoButton = 0x00000000 118 | LeftButton = 0x00000001 119 | RightButton = 0x00000002 120 | MidButton = 0x00000004 // ### Qt 5: remove me 121 | MiddleButton = MidButton 122 | XButton1 = 0x00000008 123 | XButton2 = 0x00000010 124 | MouseButtonMask = 0x000000ff 125 | ) 126 | 127 | //enum MessageIcon { NoIcon, Information, Warning, Critical }; 128 | type MessageIconType int 129 | 130 | const ( 131 | NoIcon MessageIconType = iota 132 | Information 133 | Warning 134 | Critical 135 | ) 136 | 137 | type ToolButtonStyle int 138 | 139 | const ( 140 | ToolButtonIconOnly ToolButtonStyle = iota 141 | ToolButtonTextOnly 142 | ToolButtonTextBesideIcon 143 | ToolButtonTextUnderIcon 144 | ToolButtonFollowStyle 145 | ) 146 | 147 | type ToolButtonPopupMode int 148 | 149 | const ( 150 | ToolButtonDelayedPopup ToolButtonPopupMode = iota 151 | ToolButtonMenuButtonPopup 152 | ToolButtonInstantPopup 153 | ) 154 | 155 | type PenStyle int 156 | 157 | const ( 158 | NoPen PenStyle = iota 159 | SolidLine 160 | DashLine 161 | DotLine 162 | DashDotLine 163 | DashDotDotLine 164 | CustomDashLine 165 | ) 166 | 167 | type BrushStyle int 168 | 169 | const ( 170 | NoBrush BrushStyle = iota 171 | SolidPattern 172 | Dense1Pattern 173 | Dense2Pattern 174 | Dense3Pattern 175 | Dense4Pattern 176 | Dense5Pattern 177 | Dense6Pattern 178 | Dense7Pattern 179 | HorPattern 180 | VerPattern 181 | CrossPattern 182 | BDiagPattern 183 | FDiagPattern 184 | DiagCrossPattern 185 | LinearGradientPattern 186 | RadialGradientPattern 187 | ConicalGradientPattern 188 | TexturePattern BrushStyle = 24 189 | ) 190 | 191 | type Point struct { 192 | X, Y int 193 | } 194 | 195 | func (p Point) Unpack() (int, int) { 196 | return p.X, p.Y 197 | } 198 | 199 | type PointF struct { 200 | X, Y float64 201 | } 202 | 203 | func (p PointF) Unpack() (float64, float64) { 204 | return p.X, p.Y 205 | } 206 | 207 | type Size struct { 208 | Width, Height int 209 | } 210 | 211 | func (p Size) Unpack() (int, int) { 212 | return p.Width, p.Height 213 | } 214 | 215 | type SizeF struct { 216 | Width, Height float64 217 | } 218 | 219 | func (p SizeF) Unpack() (float64, float64) { 220 | return p.Width, p.Height 221 | } 222 | 223 | type Rect struct { 224 | X, Y int 225 | Width, Height int 226 | } 227 | 228 | func (p Rect) Unpack() (int, int, int, int) { 229 | return p.X, p.Y, p.Width, p.Height 230 | } 231 | 232 | func (p Rect) Point() Point { 233 | return Point{p.X, p.Y} 234 | } 235 | 236 | func (p Rect) Size() Size { 237 | return Size{p.Width, p.Height} 238 | } 239 | 240 | type RectF struct { 241 | X, Y float64 242 | Width, Height float64 243 | } 244 | 245 | func (p RectF) Unpack() (float64, float64, float64, float64) { 246 | return p.X, p.Y, p.Width, p.Height 247 | } 248 | 249 | func (p RectF) PointF() PointF { 250 | return PointF{p.X, p.Y} 251 | } 252 | 253 | func (p RectF) SizeF() SizeF { 254 | return SizeF{p.Width, p.Height} 255 | } 256 | 257 | type Margins struct { 258 | Left, Top, Right, Bottom int 259 | } 260 | 261 | func (p Margins) Unpack() (int, int, int, int) { 262 | return p.Left, p.Top, p.Right, p.Bottom 263 | } 264 | 265 | func Pt(x, y int) Point { 266 | return Point{x, y} 267 | } 268 | 269 | func PtF(x, y float64) PointF { 270 | return PointF{x, y} 271 | } 272 | 273 | func Sz(w, h int) Size { 274 | return Size{w, h} 275 | } 276 | 277 | func SzF(w, h float64) SizeF { 278 | return SizeF{w, h} 279 | } 280 | 281 | func Rc(x, y, w, h int) Rect { 282 | return Rect{x, y, w, h} 283 | } 284 | 285 | func RcF(x, y, w, h float64) RectF { 286 | return RectF{x, y, w, h} 287 | } 288 | 289 | func Mr(left, right, top, bottom int) Margins { 290 | return Margins{left, right, top, bottom} 291 | } 292 | --------------------------------------------------------------------------------