OSDN Git Service

タグを打ち忘れていたついでに、html版ドキュメントを追加しました。
[ring-lang-081/ring.git] / docs / build / html / _sources / codegenerator.txt
1 .. index:: 
2         single: コード生成器; はじめに
3
4 ==================================
5 C/C++ ライブラリ接続用コード生成器
6 ==================================
7
8 コード生成器で Ring アプリケーションへ C/C++ ライブラリを接続する方法を学びます。
9
10 .. index:: 
11         pair: コード生成器; ツールの用法
12
13 ツールの用法
14 ============
15
16 コード生成プログラムは parsec.ring であり、
17 Ring で別の Ring コードを実行できます
18
19 URL : https://github.com/ring-lang/ring/tree/master/extensions/codegen
20
21 例えば、設定ファイル test.cf を読み込んでソースコードファイル test.c を生成するには、 parsec.ring を実行します。
22
23 .. code-block:: ring
24
25         ring parsec.ring test.cf test.c
26
27 .. index:: 
28         pair: コード生成器; 設定ファイル
29
30
31 設定ファイル
32 ============
33
34 設定ファイル (\*.cf) は、コード生成器への入力ファイルです。
35 このファイルは C/C++ ライブラリから呼び出す関数プロトタイプを決定します。
36
37 設定ファイルの記述方法は次の規則に従います。
38
39 .. index:: 
40         pair: コード生成器; 関数プロトタイプの用法
41
42 関数プロトタイプの用法
43 ======================
44
45 * C 関数の接続用コードを生成するには、 C 関数プロトタイプを記述します。
46
47 用例:
48
49 .. code-block:: ring
50
51         ALLEGRO_DISPLAY *al_create_display(int w, int h)
52         void al_destroy_display(ALLEGRO_DISPLAY *display)
53         int al_get_new_display_flags(void)
54         void al_set_new_display_flags(int flags)
55         int al_get_new_display_option(int option, int *importance)
56
57 前述の用例では al_create_display(), al_destroy_display(), al_get_new_display_flags(),
58 al_set_new_diplay_flas() および al_get_new_display_option()
59 関数の接続に五本の関数生成をコード生成器に指示します。
60
61 生成コードの一例は、
62
63 用例:
64
65 .. code-block:: ring
66
67         RING_FUNC(ring_al_create_display)
68         {
69                 if ( RING_API_PARACOUNT != 2 ) {
70                         RING_API_ERROR(RING_API_MISS2PARA);
71                         return ;
72                 }
73                 if ( ! RING_API_ISNUMBER(1) ) {
74                         RING_API_ERROR(RING_API_BADPARATYPE);
75                         return ;
76                 }
77                 if ( ! RING_API_ISNUMBER(2) ) {
78                         RING_API_ERROR(RING_API_BADPARATYPE);
79                         return ;
80                 }
81                 RING_API_RETCPOINTER(al_create_display( (int ) RING_API_GETNUMBER(1),
82                                          (int ) RING_API_GETNUMBER(2)),"ALLEGRO_DISPLAY");
83         }
84
85
86         RING_FUNC(ring_al_destroy_display)
87         {
88           if ( RING_API_PARACOUNT != 1 ) {
89                 RING_API_ERROR(RING_API_MISS1PARA);
90                 return ;
91           }
92           if ( ! RING_API_ISPOINTER(1) ) {
93                 RING_API_ERROR(RING_API_BADPARATYPE);
94                 return ;
95           }
96           al_destroy_display((ALLEGRO_DISPLAY *) RING_API_GETCPOINTER(1,"ALLEGRO_DISPLAY"));
97         }
98
99
100         RING_FUNC(ring_al_get_new_display_flags)
101         {
102                 if ( RING_API_PARACOUNT != 0 ) {
103                         RING_API_ERROR(RING_API_BADPARACOUNT);
104                         return ;
105                 }
106                 RING_API_RETNUMBER(al_get_new_display_flags());
107         }
108
109
110         RING_FUNC(ring_al_set_new_display_flags)
111         {
112                 if ( RING_API_PARACOUNT != 1 ) {
113                         RING_API_ERROR(RING_API_MISS1PARA);
114                         return ;
115                 }
116                 if ( ! RING_API_ISNUMBER(1) ) {
117                         RING_API_ERROR(RING_API_BADPARATYPE);
118                         return ;
119                 }
120                 al_set_new_display_flags( (int ) RING_API_GETNUMBER(1));
121         }
122
123
124         RING_FUNC(ring_al_get_new_display_option)
125         {
126                 if ( RING_API_PARACOUNT != 2 ) {
127                         RING_API_ERROR(RING_API_MISS2PARA);
128                         return ;
129                 }
130                 if ( ! RING_API_ISNUMBER(1) ) {
131                         RING_API_ERROR(RING_API_BADPARATYPE);
132                         return ;
133                 }
134                 if ( ! RING_API_ISSTRING(2) ) {
135                         RING_API_ERROR(RING_API_BADPARATYPE);
136                         return ;
137                 }
138                 RING_API_RETNUMBER(al_get_new_display_option( (int ) RING_API_GETNUMBER(1),
139                                         RING_API_GETINTPOINTER(2)));
140                 RING_API_ACCEPTINTVALUE(2) ;
141         }
142
143 前述の用例から、コード生成器は時間と手間の節約になることがわかります。
144
145 .. index:: 
146         pair: コード生成器; コードの追加
147
148 コードの追加
149 ============
150         
151 * コードを直接生成するには <code> ~ </code> に追加したいコードを記述してください。
152
153 用例 :
154
155 .. code-block:: ring
156
157         <code>
158                 /* こちらへ C コードを書いてください。 */
159         </code>
160
161 この機能はコード生成器で処理を行わないコードの記述時に使用します。
162 例えば、ヘッダファイルやマクロによる定数の定義などです。
163
164 .. index:: 
165         pair: コード生成器; 関数名の接頭辞
166
167 関数名の接頭辞
168 ==============
169
170 * 全ての関数に付ける接頭辞を決定するには <funcstart> ~ </funcstart> に指定したい接頭辞を記述してください。
171         例えば、 Allegro ゲームプログラミング・ライブラリを接続した後に全てのライブラリ関数名が
172         “al” で始まるようにするためには、このコードを設定ファイルへ記述します。
173
174 .. code-block:: ring
175
176         <funcstart>
177         al
178         </funcstart>
179
180 .. index:: 
181         pair: コード生成器; 構造体を接続する関数の生成
182
183 構造体を接続する関数の生成
184 ==========================
185
186 * 構造体の接続用関数を生成するには (構造体メンバの作成、削除、取得)
187         <struct> ~ </struct> に指定したい構造体名を記述してください。
188         なお、構造体名を記述してから { ~ } に構造体メンバをコンマで区切って記述します。
189
190 用例:
191
192 .. code-block:: ring
193
194         <struct>
195         ALLEGRO_COLOR
196         ALLEGRO_EVENT { type , keyboard.keycode , mouse.x , mouse.y }
197         </struct>
198
199 前述の用例では ALLEGRO_COLOR 構造体の作成と削除を行う二本の関数を生成します。
200 また ALLEGRO_EVENT 構造体の作成と削除を行う二本の関数、および
201 ALLEGRO_EVENT のメンバ (type, keyboard.keycode, mouse.x, mouse.y) を受け取る四本の関数を生成します。
202
203 .. index:: 
204         pair: コード生成器; 構造体メンバ型の決定
205
206 構造体メンバ型の決定
207 ====================
208
209 構造体メンバ名の先頭にポインタの名前を決定できます。
210
211 用例:
212
213 .. code-block:: none
214
215         SDL_Surface {flags,SDL_PixelFormat *format,w,h,pitch,void *pixels}
216
217 .. index:: 
218         pair: コード生成器; 定数の定義
219
220 定数の定義
221 ==========
222
223 <constant> ~ </constant> で定数を定義します。
224
225 生成器は定数の値を取得するのに必要な関数を生成します。
226
227 また、 Ring ヘッダファイル (\*.rh) から同一ファイル名の Ring コードで用いる定数の定義も生成します。
228
229 用例:
230
231 .. code-block:: ring
232
233         <constant>
234         MIX_DEFAULT_FORMAT
235         SDL_QUIT
236         SDL_BUTTON_LEFT
237         SDL_BUTTON_MIDDLE
238         SDL_BUTTON_RIGHT
239         </constant>
240
241 .. note:: 生成されたソースファイルの後には必ず parsec.ring へ \*.rh ファイル名を渡してください。
242
243 用例:
244
245 .. code-block:: ring
246
247         ring ..\codegen\parsec.ring libsdl.cf ring_libsdl.c ring_libsdl.rh
248
249 .. index:: 
250         pair: コード生成器; 新しい関数の登録
251
252 新しい関数の登録
253 ================
254
255 <register> ~ </register> に関数プロトタイプを記述することで、関数を登録できます。
256 このような関数のコードは、関数プロトタイプを直接記述しない場合に限り記述が必要です。
257
258 用例:
259
260 .. code-block:: ring
261
262         <register>
263         void al_exit(void)
264         </register>
265
266         <code>
267         RING_FUNC(ring_al_exit)
268         {
269                 if ( RING_API_PARACOUNT != 0 ) {
270                         RING_API_ERROR(RING_API_BADPARACOUNT);
271                         return ;
272         }
273         exit(0);
274         }
275         </code>
276
277 前述の用例では al_exit() 関数を登録しました。この関数は Allegro ライブラリの一部ではありませんが、必要なので追加した関数です。この関数が <code> ~ </code> にある場合はコードとして扱われます。この関数は C 言語ライブラリから exit() 関数を呼び出します。
278
279 .. index:: 
280         pair: コード生成器; 設定ファイルにコメントを書くには
281
282 設定ファイルにコメントを書くには
283 ================================
284
285 * コメントは <comment> ~ </comment> に記述します。
286
287 用例:
288
289 .. code-block:: ring
290
291         <comment>
292         設定ファイル
293         </comment>
294
295 .. index:: 
296         pair: コード生成器; コードの生成時にコード実行するには
297
298 コードの生成時にコード実行するには
299 ==================================
300
301 * コード生成器で設定ファイルを読み込むときに Ring コードの実行を要求するには
302         <runcode> ~ </runcode> にコードを書きます。
303
304 用例:
305
306 .. code-block:: ring
307
308         <runcode>
309         aNumberTypes + "al_fixed"
310         </runcode>
311
312 前述の行は文字列“al_fixed”をリスト NumberTypes へ追加するためのコードです。
313 このリストには、関数プロトタイプにおいてコード生成器が検出したときに数値としてみなせる型があります。
314
315 .. index:: 
316         pair: コード生成器; 列挙型と数値
317
318 列挙型と数値
319 ============
320
321 関数プロトタイプで使用する列挙型の追加用に aEnumTypes リストがあります。
322
323 用例:
324
325 .. code-block:: ring
326
327         <runcode>
328         aNumberTypes + "qreal"
329         aNumberTypes + "qint64"
330         aEnumTypes + "Qt::GestureType"
331         aEnumTypes + "Qt::GestureFlag"
332         </runcode>
333
334
335 .. index:: 
336         pair: コード生成器; 条件式による篩い分け
337
338 条件式による篩い分け
339 ====================
340
341 <filter> ~ </filter> は、
342 条件に基づいて設定ファイルの一部を包含または除外します。例えば、
343
344 .. code-block:: ring
345
346                 <filter> iswindows() 
347                         ... functions related to windows
348                 </filter>
349
350 .. index:: 
351         pair: コード生成器; 定数型
352
353 定数型
354 ======
355
356 デフォルトの定数型は数値です。
357 しかし、定数は別の型でも良いです。例えば、 (ポインタ : void \*)
358
359 <constant> ~ </constant> の使用前に <runcode> ~ </runcode> を記述することで、
360 コード生成器で使われる二つのグローバル変数を用いて定数の型を決定します。
361
362 最初の変数は $nDefaultConstantType であり、この定数を指定できます。
363
364 * C_CONSTANT_TYPE_NUMBER
365 * C_CONSTANT_TYPE_STRING
366 * C_CONSTANT_TYPE_POINTER
367
368 C_CONSTANT_TYPE_POINTER の使用時は、
369 $cDefaultConstantPointerType の二つ目にあるグローバル変数のポインタ型の決定が必要です。
370
371 用例 :
372
373 この用例では、この機能を FreeGLUT ライブラリーにおける定数の定義で使用しています。
374
375 .. code-block:: ring
376
377         <runcode>
378         $nDefaultConstantType = C_CONSTANT_TYPE_POINTER 
379         $cDefaultConstantPointerType = "void"
380         </runcode>
381         <constant>
382                 GLUT_STROKE_ROMAN  
383                 GLUT_STROKE_MONO_ROMAN
384                 GLUT_BITMAP_9_BY_15   
385                 GLUT_BITMAP_8_BY_13   
386                 GLUT_BITMAP_TIMES_ROMAN_10
387                 GLUT_BITMAP_TIMES_ROMAN_24 
388                 GLUT_BITMAP_HELVETICA_10   
389                 GLUT_BITMAP_HELVETICA_12   
390                 GLUT_BITMAP_HELVETICA_18   
391         </constant>
392
393 .. index:: 
394         pair: コード生成器; Allegro ライブラリ用の設定ファイル
395
396 Allegro ライブラリ用の設定ファイル
397 ==================================
398
399 この設定ファイル (1000行以下) は Allegro ライブラリの関数用です。
400 このファイルをコード生成器で処理したときに生成される C 言語コードは約 12000 行です!
401
402 この設定ファイルはコード生成器の完全な用例として参照できます。
403 また 2D ゲームの作成で実装済みの
404 RingAllegro 関数の確認にも使えます!
405
406 .. code-block:: ring
407
408         <code>
409         #define ALLEGRO_NO_MAGIC_MAIN
410
411         #include <allegro5/allegro.h>
412         #include "allegro5/allegro_image.h"
413         #include <allegro5/allegro_font.h>
414         #include <allegro5/allegro_ttf.h>
415         #include <allegro5/allegro_audio.h>
416         #include <allegro5/allegro_acodec.h>
417         #include <allegro5/allegro_opengl.h>
418         #include <allegro5/allegro_direct3d.h>
419         #include <allegro5/allegro_color.h>
420         #include <allegro5/allegro_memfile.h>
421         #include "allegro5/allegro_native_dialog.h"
422         #include <allegro5/allegro_physfs.h>
423         #include <allegro5/allegro_primitives.h>
424         </code>
425
426         <funcstart>
427         al
428         </funcstart>
429
430         <struct>
431         ALLEGRO_EVENT { type , keyboard.keycode , mouse.x , mouse.y }
432         ALLEGRO_TIMEOUT
433         ALLEGRO_SAMPLE_ID
434         ALLEGRO_COLOR
435         </struct>
436
437         <register>
438         void al_exit(void)
439         </register>
440
441         <code>
442         RING_FUNC(ring_al_exit)
443         {
444                 if ( RING_API_PARACOUNT != 0 ) {
445                         RING_API_ERROR(RING_API_BADPARACOUNT);
446                         return ;
447                 }
448                 exit(0);
449         }
450         </code>
451
452         int al_init(void)
453
454         <comment>
455         configuration files
456         </comment>
457
458         <runcode>
459         aNumberTypes + "al_fixed"
460         </runcode>
461
462         ALLEGRO_CONFIG *al_create_config(void)
463         void al_destroy_config(ALLEGRO_CONFIG *config)
464         ALLEGRO_CONFIG *al_load_config_file(const char *filename)
465         ALLEGRO_CONFIG *al_load_config_file_f(ALLEGRO_FILE *file)
466         bool al_save_config_file(const char *filename, const ALLEGRO_CONFIG *config)
467         bool al_save_config_file_f(ALLEGRO_FILE *file, const ALLEGRO_CONFIG *config)
468         void al_add_config_section(ALLEGRO_CONFIG *config, const char *name)
469
470 .. note:: 
471         これは設定ファイルの引用です。
472         完全なコピーは Ring ソースコードの配布物をご確認ください。
473
474 .. index:: 
475         pair: コード生成器; スレッドへの対応
476
477 スレッドへの対応
478 ================
479
480 この設定ファイルの別の部分は、スレッドライブラリで Ring アプリケーションへスレッドを
481 追加する方法について学ぶことができるため重要です。
482
483 考えかたとして Ring コードを実行するために ring_vm_mutexfunctions() および ring_vm_runcodefromthread() を使用します。
484
485 .. code-block:: ring
486
487         <comment>
488         Threads
489         </comment>
490
491         <code>
492         void *al_func_thread(ALLEGRO_THREAD *thread, void *pPointer) 
493         {  
494                 List *pList;
495                 VM *pVM;
496                 const char *cStr;
497                 pList = (List *) pPointer ;
498                 pVM = (VM *) ring_list_getpointer(pList,2);
499                 cStr = ring_list_getstring(pList,1);
500                 ring_vm_runcodefromthread(pVM,cStr);    
501                 ring_list_delete(pList);
502                 return NULL;
503         }
504
505         RING_FUNC(ring_al_create_thread)
506         {
507                 ALLEGRO_THREAD *pThread;
508                 List *pList;
509                 if ( RING_API_PARACOUNT != 1 ) {
510                         RING_API_ERROR(RING_API_MISS1PARA);
511                         return ;
512                 }
513                 if ( ! RING_API_ISSTRING(1) ) {
514                         RING_API_ERROR(RING_API_BADPARATYPE);
515                         return ;
516                 }       
517                 pList = ring_list_new(0);
518                 ring_list_addstring(pList,RING_API_GETSTRING(1));
519                 ring_list_addpointer(pList,pPointer);
520                 ring_vm_mutexfunctions((VM *) pPointer,al_create_mutex,
521                         al_lock_mutex,al_unlock_mutex,al_destroy_mutex);
522                 pThread = al_create_thread(al_func_thread, pList);
523                 al_start_thread(pThread);
524                 RING_API_RETCPOINTER(pThread,"ALLEGRO_THREAD"); 
525         }
526
527         RING_FUNC(ring_al_run_detached_thread)
528         {
529                 List *pList;
530                 if ( RING_API_PARACOUNT != 1 ) {
531                         RING_API_ERROR(RING_API_MISS1PARA);
532                         return ;
533                 }
534                 if ( ! RING_API_ISSTRING(1) ) {
535                         RING_API_ERROR(RING_API_BADPARATYPE);
536                         return ;
537                 }       
538                 pList = ring_list_new(0);
539                 ring_list_addstring(pList,RING_API_GETSTRING(1));
540                 ring_list_addpointer(pList,pPointer);
541                 ring_vm_mutexfunctions((VM *) pPointer,al_create_mutex,
542                         al_lock_mutex,al_unlock_mutex,al_destroy_mutex);
543                 al_run_detached_thread(al_func_thread, pList);
544         }
545         </code>
546
547         <register>
548         ALLEGRO_THREAD *al_create_thread(void)
549         void al_run_detached_thread(void)
550         </register>
551
552         void al_start_thread(ALLEGRO_THREAD *thread)
553         void al_join_thread(ALLEGRO_THREAD *thread, void **ret_value)
554         void al_set_thread_should_stop(ALLEGRO_THREAD *thread)
555         bool al_get_thread_should_stop(ALLEGRO_THREAD *thread)
556         void al_destroy_thread(ALLEGRO_THREAD *thread)
557         ALLEGRO_MUTEX *al_create_mutex(void)
558         ALLEGRO_MUTEX *al_create_mutex_recursive(void)
559         void al_lock_mutex(ALLEGRO_MUTEX *mutex)
560         void al_unlock_mutex(ALLEGRO_MUTEX *mutex)
561         void al_destroy_mutex(ALLEGRO_MUTEX *mutex)
562         ALLEGRO_COND *al_create_cond(void)
563         void al_destroy_cond(ALLEGRO_COND *cond)
564         void al_wait_cond(ALLEGRO_COND *cond, ALLEGRO_MUTEX *mutex)
565
566 .. index:: 
567         pair: コード生成器; C++ クラスの接続に関するコード生成器の規則
568
569 C++ クラスの接続に関するコード生成器の規則
570 ==========================================
571
572 * <class> ~ </class> にクラスを定義します。
573 * <class> ~ </class> に“name, nonew, para, parent, codename,
574   passvmpointer, abstract および staticmethods”などの属性を設定できます。
575 * 値が不要な場合に限り、属性名:値 (attributename:value)、
576   または属性名 (attributename) による記法で属性を設定します。
577 * “name” 属性は C++ コードのクラス名を決定します。
578   また、この名前は Ring コードにおけるデフォルトの名前になります。
579 * nonew 命令はメソッドの新規作成または削除は不要であることを意味します。
580 * parent 属性は親クラス名を決定します。
581 * codename 属性は C++ コードで別のクラス名を決定します。
582 * passvmpointer 命令は新しいオブジェクトの作成時にクラスのコンストラクタへ
583   Ring 仮想計算機のポインタを渡すことを意味します。これは codename 属性をクラス定義として設定するときに発生するため、
584   このクラスでは仮想計算機のポインタが必要です
585   (例えば C++ から Ring コードの実行のために使用)。
586 * abstract 命令は、このクラスでは“オブジェクトが作成されない”ため、新しいメソッドは不要であることを意味します。
587 * staticmethods 命令はメソッドを呼び出すためのオブジェ       クトを用意する必要はないことを意味します。
588 * <nodllstartup> により #include “ring.h” を回避できます。これはスタートアップコードを記述するために必要です。
589 * <libinitfunc> によりライブラリ関数へ登録する関数名を変更できます。
590 * <ignorecpointertype> はポインタ型の検査を無視します。
591 * aStringTypes リストは const char \* として扱われる新しい型を定義します。
592 * aBeforeReturn リストは関数から変数を返すときに変数名末尾に挿入される
593   コードを定義できます。
594 * aNewMethodName リストは C++ のメソッドを呼び出すときに Ring のコードで使用されるメソッドの別名を定義できます。
595   この機能は、 C++ メソッドで “load”, ”next”, ”end” および “done” など
596   Ring のキーワードと同一名称であるため必要となるものです。
597 * メソッドのプロトタイプでは - メソッド名に @ を使うときは、
598   同じメソッドで様々な仮引数 (C++ のように) があることを意味します。
599
600 .. index:: 
601         pair: コード生成器; C++ ライブラリ接続用設定ファイルの用法
602
603 C++ ライブラリ接続用設定ファイルの用法
604 ======================================
605
606 Ring アプリケーションから C++ ライブラリを使うにはコード生成器でコードを生成します。
607 C ライブラリで使うと、 \*.c ファイルではなく \*.cpp ファイルを生成します。
608 また、生成ファイルも決定します (\*.ring)。
609 このファイルには C++ のクラスとオブジェクトを使用する C++ 関数と接続するための Ring コードによるクラスがあります。
610
611 .. code-block:: ring
612
613         ring parsec.ring generator\qt.cf ring_qt.cpp ring_qt.ring
614
615
616 .. index:: 
617         pair: コード生成器; Qt フレームワーク用の設定ファイル
618
619 Qt フレームワーク用の設定ファイル
620 =================================
621
622 これは Qt クラスとの接続に用いる設定ファイルです。
623 設定ファイルは約 3500 行であり、生成されるコードは約 56000 行の C++ コード、
624 および約 9000 行の Ring コードとなります。
625
626 .. code-block:: ring
627
628         <nodllstartup>
629
630         <libinitfunc> ring_qt_start
631
632         <ignorecpointertype>
633
634         <code>
635
636         extern "C" {
637                 #include "ring.h"
638         }
639
640         #include "ring_qt.h"
641         #include "gpushbutton.h"
642         #include "gaction.h"
643         #include "glineedit.h"
644         #include "gtextedit.h"
645         #include "glistwidget.h"
646         #include "gtreeview.h"
647         #include "gtreewidget.h"
648         #include "gcombobox.h"
649         #include "gtabwidget.h"
650         #include "gtablewidget.h"
651         #include "gprogressbar.h"
652         #include "gspinbox.h"
653         #include "gslider.h"
654         #include "gdial.h"
655         #include "gwebview.h"
656         #include "gcheckbox.h"
657         #include "gradiobutton.h"
658         #include "gbuttongroup.h"
659         #include "gvideowidget.h"
660         #include "gtimer.h"
661         #include "gtcpserver.h"
662         #include "giodevice.h"
663         #include "gabstractsocket.h"
664         #include "gtcpsocket.h"
665         #include "gcolordialog.h"
666         #include "gallevents.h"
667         #include <QApplication>
668         #include <QObject>
669         #include <QWidget>
670         #include <QLabel>
671         #include <QPixmap>
672         #include <QIcon>
673         #include <QSize>
674         #include <QPushButton>
675         #include <QMainWindow>
676         #include <QVBoxLayout>
677         #include <QHBoxLayout>
678         #include <QLineEdit>
679         #include <QTextEdit>
680         #include <QListWidget>
681         #include <QTreeView>
682         #include <QDir>
683         #include <QFileSystemModel>
684         #include <QTreeWidget>
685         #include <QTreeWidgetItem>
686         #include <QComboBox>
687         #include <QVariant>
688         #include <QMenuBar>
689         #include <QMenu>
690         #include <QToolBar>
691         #include <QMainWindow>
692         #include <QStatusBar>
693         #include <QDockWidget>
694         #include <QTabWidget>
695         #include <QTableWidget>
696         #include <QTableWidgetItem>
697         #include <QSizePolicy>
698         #include <QFrame>
699         #include <QAbstractScrollArea>
700         #include <QAbstractItemView>
701         #include <QProgressBar>
702         #include <QSpinBox>
703         #include <QSlider>
704         #include <QAbstractSlider>
705         #include <QDateEdit>
706         #include <QDateTimeEdit>
707         #include <QAbstractSpinBox>
708         #include <QDial>
709         #include <QWebView>
710         #include <QUrl>
711         #include <QCheckBox>
712         #include <QRadioButton>
713         #include <QButtonGroup>
714         #include <QMediaPlayer>
715         #include <QMediaPlaylist>
716         #include <QVideoWidget>
717         #include <QPrinter>
718         #include <QAction>
719         #include <QEvent>
720         #include <QMessageBox>
721         #include <QTimer>
722         #include <QFileDialog>
723         #include <QPainter>
724         #include <QPicture>
725         #include <QPen>
726         #include <QColor>
727         #include <QPrinter>
728         #include <QFont>
729         #include <QWebSettings>
730         #include <QBrush>
731         #include <QByteArray>
732         #include <QIODevice>
733         #include <QAbstractSocket>
734         #include <QTcpSocket>
735         #include <QTcpServer>
736         #include <QNetworkProxy>
737         #include <QHostAddress>
738         #include <QHostInfo>
739         #include <QList>
740         #include <QFileInfo>
741         #include <QDirModel>
742         #include <QModelIndex>
743         #include <QFontDialog>
744         #include <QDialog>
745         #include <QTextCursor>
746         #include <QTextBlock>
747         #include <QTextDocumentFragment>
748         #include <QColorDialog>
749         #include <QHeaderView>
750         #include <QStringList>
751         #include <QKeySequence>
752         #include <QLCDNumber>
753         #include <QInputDialog>
754         #include <QDesktopWidget>
755         #include <QRect>
756         #include <QTextDocument>
757
758         extern "C" {
759
760                 #define RING_DLL __declspec(dllexport)
761
762                 RING_DLL void ringlib_init(RingState *pRingState)
763                 {
764
765                         new QApplication(pRingState->argc,pRingState->argv);
766                         ring_qt_start(pRingState) ;
767                 }
768
769         }
770         </code>
771
772
773         <runcode>
774         aStringTypes + "QString"
775         aBeforeReturn + ["QString",".toStdString().c_str()"]
776         aNewMethodName + ["QWebView","load","loadpage"]
777         aNewMethodName + ["QMediaPlaylist","load","loadfile"]
778         aNewMethodName + ["QMediaPlaylist","next","movenext"]
779         aNewMethodName + ["QPainter","end","endpaint"]
780         aNewMethodName + ["QPicture","load","loadfile"]
781         aNewMethodName + ["QLineEdit","end","endtext"]
782         aNewMethodName + ["QDialog","done","donedialog"]
783         aNewMethodName + ["QTextDocument","end","enddoc"]
784         aNewMethodName + ["QTextBlock","next","nextblock"]
785         </runcode>
786
787         <class>
788         name: qApp
789         nonew
790         </class>
791
792         <register>
793         void exec(void)
794         void quit(void)
795         void processEvents(void)
796         </register>
797
798         <code>
799
800         RING_FUNC(ring_qApp_quit)
801         {
802                 qApp->quit();
803         }
804
805         RING_FUNC(ring_qApp_exec)
806         {
807                 qApp->exec();
808         }
809
810         RING_FUNC(ring_qApp_processEvents)
811         {
812                 qApp->processEvents();
813         }
814
815         </code>
816
817         <class>
818         name: QObject
819         para: void
820         </class>
821
822         bool blockSignals(bool block)
823         QObjectList children(void)
824         void dumpObjectInfo(void)
825         void dumpObjectTree(void)
826         bool inherits(const char *className)
827         void installEventFilter(QObject *filterObj)
828         bool isWidgetType(void)
829         void killTimer(int id)
830         void moveToThread(QThread *targetThread)
831         QString objectName(void)
832         QObject *parent(void)
833         QVariant property(const char *name)
834         void removeEventFilter(QObject *obj)
835         void setObjectName(QString)
836         void setParent(QObject *parent)
837         bool setProperty(const char *name, QVariant)
838         bool signalsBlocked(void)
839         int startTimer(int interval)
840         QThread *thread(void)
841         void deleteLater(void)
842
843         <class>
844         name: QWidget
845         para: void
846         parent: QObject
847         </class>
848
849         bool acceptDrops(void)
850         QString accessibleDescription(void)
851         QString accessibleName(void)
852         void activateWindow(void)
853         void addAction(QAction *action)
854         void adjustSize(void)
855         bool autoFillBackground(void)
856         int backgroundRole(void)
857         QSize baseSize(void)
858         QWidget *childAt(int x, int y)
859         QRect childrenRect(void)
860         QRegion childrenRegion(void)
861         void clearFocus(void)
862         void clearMask(void)
863         QMargins contentsMargins(void)
864         QRect contentsRect(void)
865         int contextMenuPolicy(void)
866         QCursor cursor(void)
867         int effectiveWinId(void)
868         void ensurePolished(void)
869         int focusPolicy(void)
870         QWidget *focusProxy(void)
871         QWidget *focusWidget(void)
872         QFont font(void)
873         QFontInfo fontInfo(void)
874         QFontMetrics fontMetrics(void)
875         int foregroundRole(void)
876         QRect frameGeometry(void)
877         QSize frameSize(void)
878         QRect geometry(void)
879         void getContentsMargins(int *left, int *top, int *right, int *bottom)
880         void grabGesture(int gesture, int flags)
881         void grabKeyboard(void)
882         void grabMouse(void)
883         int grabShortcut(QKeySequence , int context)
884         QGraphicsEffect *graphicsEffect(void)
885         QGraphicsProxyWidget *graphicsProxyWidget(void)
886         bool hasFocus(void)
887         bool hasMouseTracking(void)
888         int height(void)
889         int heightForWidth(int w)
890         int inputMethodHints(void)
891         QVariant inputMethodQuery(int query)
892         void insertAction(QAction *before, QAction *action)
893         bool isActiveWindow(void)
894         bool isAncestorOf(QWidget *child)
895         bool isEnabled(void)
896         bool isEnabledTo(QWidget *ancestor)
897         bool isFullScreen(void)
898         bool isHidden(void)
899         bool isMaximized(void)
900         bool isMinimized(void)
901         bool isModal(void)
902         bool isVisible(void)
903         bool isVisibleTo(QWidget *ancestor)
904         bool isWindow(void)
905         bool isWindowModified(void)
906         QLayout *layout(void)
907         int layoutDirection(void)
908         QLocale locale(void)
909         QPoint mapFrom(QWidget *parent, QPoint)
910         QPoint mapFromGlobal(QPoint)
911         QPoint mapFromParent(QPoint)
912         QPoint mapTo(QWidget *parent, QPoint)
913         QPoint mapToGlobal(QPoint pos)
914         QPoint mapToParent(QPoint pos)
915         QRegion mask(void)
916         int maximumHeight(void)
917         QSize maximumSize(void)
918         int maximumWidth(void)
919         int minimumHeight(void)
920         QSize minimumSize(void)
921         int minimumWidth(void)
922         void move(int x, int y)
923         QWidget *nativeParentWidget(void)
924         QWidget *nextInFocusChain(void)
925         QRect normalGeometry(void)
926         void overrideWindowFlags(int flags)
927         QPalette palette(void)
928         QWidget *parentWidget(void)
929         QPoint pos(void)
930         QWidget *previousInFocusChain(void)
931         QRect rect(void)
932         void releaseKeyboard(void)
933         void releaseMouse(void)
934         void releaseShortcut(int id)
935         void removeAction(QAction *action)
936         void render(QPaintDevice *target, QPoint,QRegion, int)
937         void repaint(int x, int y, int w, int h)
938         void resize(int w, int h)
939         bool restoreGeometry(QByteArray)
940         QByteArray saveGeometry(void)
941         void scroll(int dx, int dy)
942         void setAcceptDrops(bool on)
943         void setAccessibleDescription(QString)
944         void setAccessibleName(QString)
945         void setAttribute(int attribute, bool on)
946         void setAutoFillBackground(bool enabled)
947         void setBackgroundRole(int role)
948         void setBaseSize(int basew, int baseh)
949         void setContentsMargins(int left, int top, int right, int bottom)
950         void setContextMenuPolicy(int policy)
951         void setCursor(QCursor)
952         void setFixedHeight(int h)
953         void setFixedSize(int w, int h)
954         void setFixedWidth(int w)
955         void setFocus(int reason)
956         void setFocusPolicy(int policy)
957         void setFocusProxy(QWidget *w)
958         void setFont(QFont)
959         void setForegroundRole(int role)
960         void setGeometry(int x, int y, int w, int h)
961         void setGraphicsEffect(QGraphicsEffect *effect)
962         void setInputMethodHints(int hints)
963         void setLayout(QLayout *layout)
964         void setLayoutDirection(int direction)
965         void setLocale(QLocale)
966         void setMask(QBitmap)
967         void setMaximumHeight(int maxh)
968         void setMaximumSize(int maxw, int maxh)
969         void setMaximumWidth(int maxw)
970         void setMinimumHeight(int minh)
971         void setMinimumSize(int minw, int minh)
972         void setMinimumWidth(int minw)
973         void setMouseTracking(bool enable)
974         void setPalette(QPalette)
975         void setParent(QWidget *parent)
976         void setShortcutAutoRepeat(int id, bool enable)
977         void setShortcutEnabled(int id, bool enable)
978         void setSizeIncrement(int w, int h)
979         void setSizePolicy(int horizontal, int vertical)
980         void setStatusTip(QString)
981         void setStyle(QStyle *style)
982         void setToolTip(QString)
983         void setUpdatesEnabled(bool enable)
984         void setWhatsThis(QString)
985         void setWindowFilePath(QString)
986         void setWindowFlags(int type)
987         void setWindowIcon(QIcon)
988         void setWindowIconText(QString)
989         void setWindowModality(int windowModality)
990         void setWindowOpacity(double level)
991         void setWindowRole(QString)
992         void setWindowState(int windowState)
993         QSize size(void)
994         QSize sizeIncrement(void)
995         QSizePolicy sizePolicy(void)
996         void stackUnder(QWidget *w)
997         QString statusTip(void)
998         QStyle *style(void)
999         QString styleSheet(void)
1000         bool testAttribute(int attribute)
1001         QString toolTip(void)
1002         bool underMouse(void)
1003         void ungrabGesture(int gesture)
1004         void unsetCursor(void)
1005         void unsetLayoutDirection(void)
1006         void unsetLocale(void)
1007         void update(int x, int y, int w, int h)
1008         void updateGeometry(void)
1009         bool updatesEnabled(void)
1010         QRegion visibleRegion(void)
1011         QString whatsThis(void)
1012         int width(void)
1013         int winId(void)
1014         QWidget *window(void)
1015         QString windowFilePath(void)
1016         int windowFlags(void)
1017         QIcon windowIcon(void)
1018         QString windowIconText(void)
1019         int windowModality(void)
1020         double windowOpacity(void)
1021         QString windowRole(void)
1022         int windowState(void)
1023         QString windowTitle(void)
1024         int windowType(void)
1025         int x(void)
1026         int y(void)
1027         bool close(void)
1028         void hide(void)
1029         void lower(void)
1030         void raise(void)
1031         void setDisabled(bool disable)
1032         void setEnabled(bool)
1033         void setHidden(bool hidden)
1034         void setStyleSheet(QString)
1035         void setWindowModified(bool)
1036         void setWindowTitle(QString)
1037         void show(void)
1038         void showFullScreen(void)
1039         void showMaximized(void)
1040         void showMinimized(void)
1041         void showNormal(void)
1042         QWidget *find(int id)
1043         QWidget *keyboardGrabber(void)
1044         QWidget *mouseGrabber(void)
1045         void setTabOrder(QWidget *first, QWidget *second)
1046
1047         <class>
1048         name: QLabel
1049         para: QWidget *
1050         parent: QWidget
1051         </class>
1052
1053         int alignment(void)
1054         QWidget *buddy(void)
1055         bool hasScaledContents(void)
1056         bool hasSelectedText(void)
1057         int indent(void)
1058         int margin(void)
1059         QMovie *movie(void)
1060         bool openExternalLinks(void)
1061         QPicture *picture(void)
1062         QPixmap *pixmap(void)
1063         QString selectedText(void)
1064         int selectionStart(void)
1065         void setAlignment(int)
1066         void setBuddy(QWidget *buddy)
1067         void setIndent(int)
1068         void setMargin(int)
1069         void setOpenExternalLinks(bool open)
1070         void setScaledContents(bool)
1071         void setSelection(int start, int length)
1072         void setTextFormat(int)
1073         void setTextInteractionFlags(int flags)
1074         void setWordWrap(bool on)
1075         QString text(void)
1076         int textFormat(void)
1077         int textInteractionFlags(void)
1078         bool wordWrap(void)
1079         void clear(void)
1080         void setMovie(QMovie *movie)
1081         void setNum(double num)
1082         void setPicture(QPicture)
1083         void setPixmap(QPixmap)
1084         void setText(QString)
1085
1086         <class>
1087         name: QPushButton
1088         para: QWidget *
1089         parent: QWidget
1090         codename: GPushButton
1091         passvmpointer
1092         </class>
1093
1094         void setText(const char *)
1095         void setClickEvent(const char *)
1096         void setIcon(QIcon)
1097         void setIconSize(QSize)
1098
1099         <class>
1100         name: QLineEdit
1101         para: QWidget *
1102         parent: QWidget
1103         codename: GLineEdit
1104         passvmpointer
1105         </class>
1106
1107         int alignment(void)
1108         void backspace(void)
1109         QCompleter *completer(void)
1110         QMenu *createStandardContextMenu(void)
1111         void cursorBackward(bool mark, int steps)
1112         void cursorForward(bool mark, int steps)
1113         int cursorMoveStyle(void)
1114         int cursorPosition(void)
1115         int cursorPositionAt(QPoint)
1116         void cursorWordBackward(bool mark)
1117         void cursorWordForward(bool mark)
1118         void del(void)
1119         void deselect(void)
1120         QString displayText(void)
1121         bool dragEnabled(void)
1122         int echoMode(void)
1123         void end(bool mark)
1124         void getTextMargins(int *left, int *top, int *right, int *bottom)
1125         bool hasAcceptableInput(void)
1126         bool hasFrame(void)
1127         bool hasSelectedText(void)
1128         void home(bool mark)
1129         QString inputMask(void)
1130         void insert(QString)
1131         bool isModified(void)
1132         bool isReadOnly(void)
1133         bool isRedoAvailable(void)
1134         bool isUndoAvailable(void)
1135         int maxLength(void)
1136         QString placeholderText(void)
1137         QString selectedText(void)
1138         int selectionStart(void)
1139         void setAlignment(int flag)
1140         void setCompleter(QCompleter *c)
1141         void setCursorMoveStyle(int style)
1142         void setCursorPosition(int)
1143         void setDragEnabled(bool b)
1144         void setEchoMode(int)
1145         void setFrame(bool)
1146         void setInputMask(QString)
1147         void setMaxLength(int)
1148         void setModified(bool)
1149         void setPlaceholderText(QString)
1150         void setReadOnly(bool)
1151         void setSelection(int start, int length)
1152         void setTextMargins(int left, int top, int right, int bottom)
1153         void setValidator(QValidator *v)
1154         QString text(void)
1155         QMargins textMargins(void)
1156         QValidator *validator(void)
1157
1158         void clear(void)
1159         void copy(void) 
1160         void cut(void)
1161         void paste(void)
1162         void redo(void)
1163         void selectAll(void)
1164         void setText(QString)
1165         void undo(void)
1166
1167         void setTextChangedEvent(const char *)
1168         void setcursorPositionChangedEvent(const char *)
1169         void seteditingFinishedEvent(const char *)
1170         void setreturnPressedEvent(const char *)
1171         void setselectionChangedEvent(const char *)
1172         void settextEditedEvent(const char *)
1173
1174 .. note:: ソースコード全文は Ring ソースコードの配布物にあるため、
1175         この取扱説明書からは前述の設定ファイルにおける内容の大部分を割愛しています。
1176
1177
1178 .. index:: 
1179         pair: コード生成器; 静的メソッド
1180
1181 静的メソッド
1182 ============
1183
1184 Ring 1.8 からコード生成器は staticmethods オプションに対応しました。
1185
1186 これにより、コード生成器はクラスでメソッドを呼び出すためのオブジェクトの準備は不要であることを検出できるようになりました。
1187
1188 用例:
1189
1190 .. code-block:: none
1191
1192         <class>
1193         name: QStandardPaths
1194         para: void
1195         nonew
1196         staticmethods
1197         </class>
1198
1199         QString displayName(QStandardPaths::StandardLocation type)
1200         QString findExecutable(QString executableName, QStringList paths))
1201
1202 .. index:: 
1203         pair: コード生成器; ファイルの読み込み
1204
1205 ファイルの読み込み
1206 ==================
1207
1208 コード生成器は <loadfile> 命令に対応しました (Ring 1.9 以降)。
1209
1210 .. code-block:: ring
1211
1212         <loadfile> filename.cf
1213
1214 これは、拡張機能設定ファイルを複数のファイルへ分割するのに便利です。
1215
1216 用例:
1217
1218 ファイル : RingQt 拡張機能の qt_module_network.cf より引用
1219
1220 .. code-block:: ring
1221
1222         <comment>
1223                                         モジュール (ネットワーク)
1224         </comment>
1225
1226         <loadfile> qabstractsocket.cf
1227         <loadfile> qnetworkproxy.cf
1228         <loadfile> qtcpsocket.cf
1229         <loadfile> qtcpserver.cf
1230         <loadfile> qhostaddress.cf
1231         <loadfile> qhostinfo.cf
1232         <loadfile> qnetworkrequest.cf
1233         <loadfile> qnetworkaccessmanager.cf
1234         <loadfile> qnetworkreply.cf
1235
1236 .. index:: 
1237         pair: コード生成器; マネージドクラス
1238
1239 マネージドクラス
1240 ================
1241
1242 コード生成器は、クラス定義時の <managed> オプションに対応しました (Ring 1.9 以降)。
1243
1244 このオプションにより、生成器は C ポインタを返すために RING_API_RETMANAGEDCPOINTER() を使用します。
1245
1246 これにより、ガベージコレクターは C ポインタを管理対象にします。
1247
1248 用例:
1249
1250 .. code-block:: ring
1251
1252         <class>
1253         name: QFont
1254         para: QString, int, int, bool
1255         managed
1256         </class>
1257
1258
1259 .. index:: 
1260         pair: コード生成器; 設定ファイルの用例
1261
1262 設定ファイルの用例
1263 ==================
1264
1265 この用例から学ぶことができます。
1266
1267 * RingAllegro : https://github.com/ring-lang/ring/blob/master/extensions/ringallegro/allegro.cf
1268 * RingQt : https://github.com/ring-lang/ring/blob/master/extensions/ringqt/classes/qt.cf
1269 * RingLibSDL : https://github.com/ring-lang/ring/blob/master/extensions/ringsdl/libsdl.cf
1270
1271 設定ファイルの変更後に、必ずコードの生成をしてください。
1272 この用例から学ぶことができます。
1273
1274 * RingAllegro : https://github.com/ring-lang/ring/blob/master/extensions/ringallegro/gencode.bat
1275 * RingQt : https://github.com/ring-lang/ring/blob/master/extensions/ringqt/gencode.bat
1276 * RingLibSDL : https://github.com/ring-lang/ring/blob/master/extensions/ringsdl/gencode.bat
1277
1278 コード生成後にライブラリのビルドを必ずしてください。この用例から学ぶことができます。
1279
1280 * RingAllegro : https://github.com/ring-lang/ring/blob/master/extensions/ringallegro/buildvc.bat
1281 * RingQt : https://github.com/ring-lang/ring/blob/master/extensions/ringqt/buildmingw32.bat
1282 * RingLibSDL : https://github.com/ring-lang/ring/blob/master/extensions/ringsdl/buildvc.bat