Blender V2.61 - r43446

rna_ui.c

Go to the documentation of this file.
00001 /*
00002  * ***** BEGIN GPL LICENSE BLOCK *****
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software Foundation,
00016  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  *
00018  * Contributor(s): Blender Foundation (2009)
00019  *
00020  * ***** END GPL LICENSE BLOCK *****
00021  */
00022 
00028 #include <stdlib.h>
00029 
00030 #include "DNA_screen_types.h"
00031 
00032 #include "RNA_define.h"
00033 
00034 #include "rna_internal.h"
00035 #include "RNA_enum_types.h"
00036 
00037 #include "UI_interface.h"
00038 
00039 #include "WM_types.h"
00040 
00041 /* see WM_types.h */
00042 EnumPropertyItem operator_context_items[] = {
00043     {WM_OP_INVOKE_DEFAULT, "INVOKE_DEFAULT", 0, "Invoke Default", ""},
00044     {WM_OP_INVOKE_REGION_WIN, "INVOKE_REGION_WIN", 0, "Invoke Region Window", ""},
00045     {WM_OP_INVOKE_REGION_CHANNELS, "INVOKE_REGION_CHANNELS", 0, "Invoke Region Channels", ""},
00046     {WM_OP_INVOKE_REGION_PREVIEW, "INVOKE_REGION_PREVIEW", 0, "Invoke Region Preview", ""},
00047     {WM_OP_INVOKE_AREA, "INVOKE_AREA", 0, "Invoke Area", ""},
00048     {WM_OP_INVOKE_SCREEN, "INVOKE_SCREEN", 0, "Invoke Screen", ""},
00049     {WM_OP_EXEC_DEFAULT, "EXEC_DEFAULT", 0, "Exec Default", ""},
00050     {WM_OP_EXEC_REGION_WIN, "EXEC_REGION_WIN", 0, "Exec Region Window", ""},
00051     {WM_OP_EXEC_REGION_CHANNELS, "EXEC_REGION_CHANNELS", 0, "Exec Region Channels", ""},
00052     {WM_OP_EXEC_REGION_PREVIEW, "EXEC_REGION_PREVIEW", 0, "Exec Region Preview", ""},
00053     {WM_OP_EXEC_AREA, "EXEC_AREA", 0, "Exec Area", ""},
00054     {WM_OP_EXEC_SCREEN, "EXEC_SCREEN", 0, "Exec Screen", ""},
00055     {0, NULL, 0, NULL, NULL}};
00056 
00057 #ifdef RNA_RUNTIME
00058 
00059 #include <assert.h>
00060 
00061 #include "MEM_guardedalloc.h"
00062 
00063 #include "RNA_access.h"
00064 
00065 #include "BLI_dynstr.h"
00066 
00067 #include "BKE_context.h"
00068 #include "BKE_report.h"
00069 #include "BKE_screen.h"
00070 
00071 #include "WM_api.h"
00072 
00073 static ARegionType *region_type_find(ReportList *reports, int space_type, int region_type)
00074 {
00075     SpaceType *st;
00076     ARegionType *art;
00077 
00078     st= BKE_spacetype_from_id(space_type);
00079 
00080     for(art= (st)? st->regiontypes.first: NULL; art; art= art->next) {
00081         if (art->regionid==region_type)
00082             break;
00083     }
00084     
00085     /* region type not found? abort */
00086     if (art==NULL) {
00087         BKE_report(reports, RPT_ERROR, "Region not found in spacetype");
00088         return NULL;
00089     }
00090 
00091     return art;
00092 }
00093 
00094 /* Panel */
00095 
00096 static int panel_poll(const bContext *C, PanelType *pt)
00097 {
00098     extern FunctionRNA rna_Panel_poll_func;
00099 
00100     PointerRNA ptr;
00101     ParameterList list;
00102     FunctionRNA *func;
00103     void *ret;
00104     int visible;
00105 
00106     RNA_pointer_create(NULL, pt->ext.srna, NULL, &ptr); /* dummy */
00107     func= &rna_Panel_poll_func; /* RNA_struct_find_function(&ptr, "poll"); */
00108 
00109     RNA_parameter_list_create(&list, &ptr, func);
00110     RNA_parameter_set_lookup(&list, "context", &C);
00111     pt->ext.call((bContext *)C, &ptr, func, &list);
00112 
00113     RNA_parameter_get_lookup(&list, "visible", &ret);
00114     visible= *(int*)ret;
00115 
00116     RNA_parameter_list_free(&list);
00117 
00118     return visible;
00119 }
00120 
00121 static void panel_draw(const bContext *C, Panel *pnl)
00122 {
00123     extern FunctionRNA rna_Panel_draw_func;
00124 
00125     PointerRNA ptr;
00126     ParameterList list;
00127     FunctionRNA *func;
00128 
00129     RNA_pointer_create(&CTX_wm_screen(C)->id, pnl->type->ext.srna, pnl, &ptr);
00130     func= &rna_Panel_draw_func;/* RNA_struct_find_function(&ptr, "draw"); */
00131 
00132     RNA_parameter_list_create(&list, &ptr, func);
00133     RNA_parameter_set_lookup(&list, "context", &C);
00134     pnl->type->ext.call((bContext *)C, &ptr, func, &list);
00135 
00136     RNA_parameter_list_free(&list);
00137 }
00138 
00139 static void panel_draw_header(const bContext *C, Panel *pnl)
00140 {
00141     extern FunctionRNA rna_Panel_draw_header_func;
00142 
00143     PointerRNA ptr;
00144     ParameterList list;
00145     FunctionRNA *func;
00146 
00147     RNA_pointer_create(&CTX_wm_screen(C)->id, pnl->type->ext.srna, pnl, &ptr);
00148     func= &rna_Panel_draw_header_func; /* RNA_struct_find_function(&ptr, "draw_header"); */
00149 
00150     RNA_parameter_list_create(&list, &ptr, func);
00151     RNA_parameter_set_lookup(&list, "context", &C);
00152     pnl->type->ext.call((bContext *)C, &ptr, func, &list);
00153 
00154     RNA_parameter_list_free(&list);
00155 }
00156 
00157 static void rna_Panel_unregister(Main *UNUSED(bmain), StructRNA *type)
00158 {
00159     ARegionType *art;
00160     PanelType *pt= RNA_struct_blender_type_get(type);
00161 
00162     if(!pt)
00163         return;
00164     if(!(art=region_type_find(NULL, pt->space_type, pt->region_type)))
00165         return;
00166     
00167     RNA_struct_free_extension(type, &pt->ext);
00168 
00169     BLI_freelinkN(&art->paneltypes, pt);
00170     RNA_struct_free(&BLENDER_RNA, type);
00171 
00172     /* update while blender is running */
00173     WM_main_add_notifier(NC_SCREEN|NA_EDITED, NULL);
00174 }
00175 
00176 static StructRNA *rna_Panel_register(Main *bmain, ReportList *reports, void *data, const char *identifier,
00177                                      StructValidateFunc validate, StructCallbackFunc call, StructFreeFunc free)
00178 {
00179     ARegionType *art;
00180     PanelType *pt, dummypt = {NULL};
00181     Panel dummypanel= {NULL};
00182     PointerRNA dummyptr;
00183     int have_function[3];
00184 
00185     /* setup dummy panel & panel type to store static properties in */
00186     dummypanel.type= &dummypt;
00187     RNA_pointer_create(NULL, &RNA_Panel, &dummypanel, &dummyptr);
00188 
00189     /* validate the python class */
00190     if(validate(&dummyptr, data, have_function) != 0)
00191         return NULL;
00192         
00193     if(strlen(identifier) >= sizeof(dummypt.idname)) {
00194         BKE_reportf(reports, RPT_ERROR, "registering panel class: '%s' is too long, maximum length is %d",
00195                     identifier, (int)sizeof(dummypt.idname));
00196         return NULL;
00197     }
00198     
00199     if(!(art=region_type_find(reports, dummypt.space_type, dummypt.region_type)))
00200         return NULL;
00201 
00202     /* check if we have registered this panel type before, and remove it */
00203     for(pt=art->paneltypes.first; pt; pt=pt->next) {
00204         if(strcmp(pt->idname, dummypt.idname) == 0) {
00205             if(pt->ext.srna)
00206                 rna_Panel_unregister(bmain, pt->ext.srna);
00207             else
00208                 BLI_freelinkN(&art->paneltypes, pt);
00209             break;
00210         }
00211     }
00212     
00213     /* create a new panel type */
00214     pt= MEM_callocN(sizeof(PanelType), "python buttons panel");
00215     memcpy(pt, &dummypt, sizeof(dummypt));
00216 
00217     pt->ext.srna= RNA_def_struct(&BLENDER_RNA, pt->idname, "Panel"); 
00218     pt->ext.data= data;
00219     pt->ext.call= call;
00220     pt->ext.free= free;
00221     RNA_struct_blender_type_set(pt->ext.srna, pt);
00222     RNA_def_struct_flag(pt->ext.srna, STRUCT_NO_IDPROPERTIES);
00223 
00224     pt->poll= (have_function[0])? panel_poll: NULL;
00225     pt->draw= (have_function[1])? panel_draw: NULL;
00226     pt->draw_header= (have_function[2])? panel_draw_header: NULL;
00227 
00228     /* XXX use "no header" flag for some ordering of panels until we have real panel ordering */
00229     if(pt->flag & PNL_NO_HEADER) {
00230         PanelType *pth = art->paneltypes.first;
00231         while(pth && pth->flag & PNL_NO_HEADER)
00232             pth=pth->next;
00233 
00234         if(pth)
00235             BLI_insertlinkbefore(&art->paneltypes, pth, pt);
00236         else
00237             BLI_addtail(&art->paneltypes, pt);
00238     }
00239     else
00240         BLI_addtail(&art->paneltypes, pt);
00241 
00242     /* update while blender is running */
00243     WM_main_add_notifier(NC_SCREEN|NA_EDITED, NULL);
00244     
00245     return pt->ext.srna;
00246 }
00247 
00248 static StructRNA* rna_Panel_refine(PointerRNA *ptr)
00249 {
00250     Panel *hdr= (Panel*)ptr->data;
00251     return (hdr->type && hdr->type->ext.srna)? hdr->type->ext.srna: &RNA_Panel;
00252 }
00253 
00254 /* Header */
00255 
00256 static void header_draw(const bContext *C, Header *hdr)
00257 {
00258     extern FunctionRNA rna_Header_draw_func;
00259 
00260     PointerRNA htr;
00261     ParameterList list;
00262     FunctionRNA *func;
00263 
00264     RNA_pointer_create(&CTX_wm_screen(C)->id, hdr->type->ext.srna, hdr, &htr);
00265     func= &rna_Header_draw_func; /* RNA_struct_find_function(&htr, "draw"); */
00266 
00267     RNA_parameter_list_create(&list, &htr, func);
00268     RNA_parameter_set_lookup(&list, "context", &C);
00269     hdr->type->ext.call((bContext *)C, &htr, func, &list);
00270 
00271     RNA_parameter_list_free(&list);
00272 }
00273 
00274 static void rna_Header_unregister(Main *UNUSED(bmain), StructRNA *type)
00275 {
00276     ARegionType *art;
00277     HeaderType *ht= RNA_struct_blender_type_get(type);
00278 
00279     if(!ht)
00280         return;
00281     if(!(art=region_type_find(NULL, ht->space_type, RGN_TYPE_HEADER)))
00282         return;
00283     
00284     RNA_struct_free_extension(type, &ht->ext);
00285 
00286     BLI_freelinkN(&art->headertypes, ht);
00287     RNA_struct_free(&BLENDER_RNA, type);
00288 
00289     /* update while blender is running */
00290     WM_main_add_notifier(NC_SCREEN|NA_EDITED, NULL);
00291 }
00292 
00293 static StructRNA *rna_Header_register(Main *bmain, ReportList *reports, void *data, const char *identifier,
00294                                       StructValidateFunc validate, StructCallbackFunc call, StructFreeFunc free)
00295 {
00296     ARegionType *art;
00297     HeaderType *ht, dummyht = {NULL};
00298     Header dummyheader= {NULL};
00299     PointerRNA dummyhtr;
00300     int have_function[1];
00301 
00302     /* setup dummy header & header type to store static properties in */
00303     dummyheader.type= &dummyht;
00304     RNA_pointer_create(NULL, &RNA_Header, &dummyheader, &dummyhtr);
00305 
00306     /* validate the python class */
00307     if(validate(&dummyhtr, data, have_function) != 0)
00308         return NULL;
00309 
00310     if(strlen(identifier) >= sizeof(dummyht.idname)) {
00311         BKE_reportf(reports, RPT_ERROR, "registering header class: '%s' is too long, maximum length is %d",
00312                     identifier, (int)sizeof(dummyht.idname));
00313         return NULL;
00314     }
00315 
00316     if(!(art=region_type_find(reports, dummyht.space_type, RGN_TYPE_HEADER)))
00317         return NULL;
00318 
00319     /* check if we have registered this header type before, and remove it */
00320     for(ht=art->headertypes.first; ht; ht=ht->next) {
00321         if(strcmp(ht->idname, dummyht.idname) == 0) {
00322             if(ht->ext.srna)
00323                 rna_Header_unregister(bmain, ht->ext.srna);
00324             break;
00325         }
00326     }
00327     
00328     /* create a new header type */
00329     ht= MEM_callocN(sizeof(HeaderType), "python buttons header");
00330     memcpy(ht, &dummyht, sizeof(dummyht));
00331 
00332     ht->ext.srna= RNA_def_struct(&BLENDER_RNA, ht->idname, "Header"); 
00333     ht->ext.data= data;
00334     ht->ext.call= call;
00335     ht->ext.free= free;
00336     RNA_struct_blender_type_set(ht->ext.srna, ht);
00337 
00338     ht->draw= (have_function[0])? header_draw: NULL;
00339 
00340     BLI_addtail(&art->headertypes, ht);
00341 
00342     /* update while blender is running */
00343     WM_main_add_notifier(NC_SCREEN|NA_EDITED, NULL);
00344     
00345     return ht->ext.srna;
00346 }
00347 
00348 static StructRNA* rna_Header_refine(PointerRNA *htr)
00349 {
00350     Header *hdr= (Header*)htr->data;
00351     return (hdr->type && hdr->type->ext.srna)? hdr->type->ext.srna: &RNA_Header;
00352 }
00353 
00354 /* Menu */
00355 
00356 static int menu_poll(const bContext *C, MenuType *pt)
00357 {
00358     extern FunctionRNA rna_Menu_poll_func;
00359 
00360     PointerRNA ptr;
00361     ParameterList list;
00362     FunctionRNA *func;
00363     void *ret;
00364     int visible;
00365 
00366     RNA_pointer_create(NULL, pt->ext.srna, NULL, &ptr); /* dummy */
00367     func= &rna_Menu_poll_func; /* RNA_struct_find_function(&ptr, "poll"); */
00368 
00369     RNA_parameter_list_create(&list, &ptr, func);
00370     RNA_parameter_set_lookup(&list, "context", &C);
00371     pt->ext.call((bContext *)C, &ptr, func, &list);
00372 
00373     RNA_parameter_get_lookup(&list, "visible", &ret);
00374     visible= *(int*)ret;
00375 
00376     RNA_parameter_list_free(&list);
00377 
00378     return visible;
00379 }
00380 
00381 static void menu_draw(const bContext *C, Menu *hdr)
00382 {
00383     extern FunctionRNA rna_Menu_draw_func;
00384 
00385     PointerRNA mtr;
00386     ParameterList list;
00387     FunctionRNA *func;
00388 
00389     RNA_pointer_create(&CTX_wm_screen(C)->id, hdr->type->ext.srna, hdr, &mtr);
00390     func= &rna_Menu_draw_func; /* RNA_struct_find_function(&mtr, "draw"); */
00391 
00392     RNA_parameter_list_create(&list, &mtr, func);
00393     RNA_parameter_set_lookup(&list, "context", &C);
00394     hdr->type->ext.call((bContext *)C, &mtr, func, &list);
00395 
00396     RNA_parameter_list_free(&list);
00397 }
00398 
00399 static void rna_Menu_unregister(Main *UNUSED(bmain), StructRNA *type)
00400 {
00401     MenuType *mt= RNA_struct_blender_type_get(type);
00402 
00403     if(!mt)
00404         return;
00405     
00406     RNA_struct_free_extension(type, &mt->ext);
00407 
00408     WM_menutype_freelink(mt);
00409 
00410     RNA_struct_free(&BLENDER_RNA, type);
00411 
00412     /* update while blender is running */
00413     WM_main_add_notifier(NC_SCREEN|NA_EDITED, NULL);
00414 }
00415 
00416 static char _menu_descr[RNA_DYN_DESCR_MAX];
00417 static StructRNA *rna_Menu_register(Main *bmain, ReportList *reports, void *data, const char *identifier,
00418                                     StructValidateFunc validate, StructCallbackFunc call, StructFreeFunc free)
00419 {
00420     MenuType *mt, dummymt = {NULL};
00421     Menu dummymenu= {NULL};
00422     PointerRNA dummymtr;
00423     int have_function[2];
00424     size_t over_alloc= 0; /* warning, if this becomes a bess, we better do another alloc */
00425     size_t description_size= 0;
00426 
00427     /* setup dummy menu & menu type to store static properties in */
00428     dummymenu.type= &dummymt;
00429     dummymenu.type->description= _menu_descr;
00430     RNA_pointer_create(NULL, &RNA_Menu, &dummymenu, &dummymtr);
00431 
00432     /* clear incase they are left unset */
00433     _menu_descr[0]= '\0';
00434 
00435     /* validate the python class */
00436     if(validate(&dummymtr, data, have_function) != 0)
00437         return NULL;
00438     
00439     if(strlen(identifier) >= sizeof(dummymt.idname)) {
00440         BKE_reportf(reports, RPT_ERROR, "registering menu class: '%s' is too long, maximum length is %d",
00441                     identifier, (int)sizeof(dummymt.idname));
00442         return NULL;
00443     }
00444 
00445     /* check if we have registered this menu type before, and remove it */
00446     mt= WM_menutype_find(dummymt.idname, TRUE);
00447     if(mt && mt->ext.srna)
00448         rna_Menu_unregister(bmain, mt->ext.srna);
00449     
00450     /* create a new menu type */
00451     if (_menu_descr[0]) {
00452         description_size= strlen(_menu_descr) + 1;
00453         over_alloc += description_size;
00454     }
00455 
00456     mt= MEM_callocN(sizeof(MenuType) + over_alloc, "python buttons menu");
00457     memcpy(mt, &dummymt, sizeof(dummymt));
00458 
00459     if (_menu_descr[0]) {
00460         char *buf= (char *)(mt + 1);
00461         memcpy(buf, _menu_descr, description_size);
00462         mt->description= buf;
00463     }
00464 
00465     mt->ext.srna= RNA_def_struct(&BLENDER_RNA, mt->idname, "Menu"); 
00466     mt->ext.data= data;
00467     mt->ext.call= call;
00468     mt->ext.free= free;
00469     RNA_struct_blender_type_set(mt->ext.srna, mt);
00470     RNA_def_struct_flag(mt->ext.srna, STRUCT_NO_IDPROPERTIES);
00471 
00472     mt->poll= (have_function[0])? menu_poll: NULL;
00473     mt->draw= (have_function[1])? menu_draw: NULL;
00474 
00475     WM_menutype_add(mt);
00476 
00477     /* update while blender is running */
00478     WM_main_add_notifier(NC_SCREEN|NA_EDITED, NULL);
00479     
00480     return mt->ext.srna;
00481 }
00482 
00483 static StructRNA* rna_Menu_refine(PointerRNA *mtr)
00484 {
00485     Menu *hdr= (Menu*)mtr->data;
00486     return (hdr->type && hdr->type->ext.srna)? hdr->type->ext.srna: &RNA_Menu;
00487 }
00488 
00489 static void rna_Menu_bl_description_set(PointerRNA *ptr, const char *value)
00490 {
00491     Menu *data= (Menu*)(ptr->data);
00492     char *str= (char *)data->type->description;
00493     if(!str[0]) BLI_strncpy(str, value, RNA_DYN_DESCR_MAX);  /* utf8 already ensured */
00494     else        assert(!"setting the bl_description on a non-builtin menu");
00495 }
00496 
00497 static int rna_UILayout_active_get(PointerRNA *ptr)
00498 {
00499     return uiLayoutGetActive(ptr->data);
00500 }
00501 
00502 static void rna_UILayout_active_set(PointerRNA *ptr, int value)
00503 {
00504     uiLayoutSetActive(ptr->data, value);
00505 }
00506 
00507 static int rna_UILayout_alert_get(PointerRNA *ptr)
00508 {
00509     return uiLayoutGetRedAlert(ptr->data);
00510 }
00511 
00512 static void rna_UILayout_alert_set(PointerRNA *ptr, int value)
00513 {
00514     uiLayoutSetRedAlert(ptr->data, value);
00515 }
00516 
00517 static void rna_UILayout_op_context_set(PointerRNA *ptr, int value)
00518 {
00519     uiLayoutSetOperatorContext(ptr->data, value);
00520 }
00521 
00522 static int rna_UILayout_op_context_get(PointerRNA *ptr)
00523 {
00524     return uiLayoutGetOperatorContext(ptr->data);
00525 }
00526 
00527 static int rna_UILayout_enabled_get(PointerRNA *ptr)
00528 {
00529     return uiLayoutGetEnabled(ptr->data);
00530 }
00531 
00532 static void rna_UILayout_enabled_set(PointerRNA *ptr, int value)
00533 {
00534     uiLayoutSetEnabled(ptr->data, value);
00535 }
00536 
00537 #if 0
00538 static int rna_UILayout_red_alert_get(PointerRNA *ptr)
00539 {
00540     return uiLayoutGetRedAlert(ptr->data);
00541 }
00542 
00543 static void rna_UILayout_red_alert_set(PointerRNA *ptr, int value)
00544 {
00545     uiLayoutSetRedAlert(ptr->data, value);
00546 }
00547 
00548 static int rna_UILayout_keep_aspect_get(PointerRNA *ptr)
00549 {
00550     return uiLayoutGetKeepAspect(ptr->data);
00551 }
00552 
00553 static void rna_UILayout_keep_aspect_set(PointerRNA *ptr, int value)
00554 {
00555     uiLayoutSetKeepAspect(ptr->data, value);
00556 }
00557 #endif
00558 
00559 static int rna_UILayout_alignment_get(PointerRNA *ptr)
00560 {
00561     return uiLayoutGetAlignment(ptr->data);
00562 }
00563 
00564 static void rna_UILayout_alignment_set(PointerRNA *ptr, int value)
00565 {
00566     uiLayoutSetAlignment(ptr->data, value);
00567 }
00568 
00569 static float rna_UILayout_scale_x_get(PointerRNA *ptr)
00570 {
00571     return uiLayoutGetScaleX(ptr->data);
00572 }
00573 
00574 static void rna_UILayout_scale_x_set(PointerRNA *ptr, float value)
00575 {
00576     uiLayoutSetScaleX(ptr->data, value);
00577 }
00578 
00579 static float rna_UILayout_scale_y_get(PointerRNA *ptr)
00580 {
00581     return uiLayoutGetScaleY(ptr->data);
00582 }
00583 
00584 static void rna_UILayout_scale_y_set(PointerRNA *ptr, float value)
00585 {
00586     uiLayoutSetScaleY(ptr->data, value);
00587 }
00588 
00589 #else // RNA_RUNTIME
00590 
00591 static void rna_def_ui_layout(BlenderRNA *brna)
00592 {
00593     StructRNA *srna;
00594     PropertyRNA *prop;
00595 
00596     static EnumPropertyItem alignment_items[] = {
00597         {UI_LAYOUT_ALIGN_EXPAND, "EXPAND", 0, "Expand", ""},
00598         {UI_LAYOUT_ALIGN_LEFT, "LEFT", 0, "Left", ""},
00599         {UI_LAYOUT_ALIGN_CENTER, "CENTER", 0, "Center", ""},
00600         {UI_LAYOUT_ALIGN_RIGHT, "RIGHT", 0, "Right", ""},
00601         {0, NULL, 0, NULL, NULL}};
00602     
00603     /* layout */
00604 
00605     srna= RNA_def_struct(brna, "UILayout", NULL);
00606     RNA_def_struct_sdna(srna, "uiLayout");
00607     RNA_def_struct_ui_text(srna, "UI Layout", "User interface layout in a panel or header");
00608 
00609     prop= RNA_def_property(srna, "active", PROP_BOOLEAN, PROP_NONE);
00610     RNA_def_property_boolean_funcs(prop, "rna_UILayout_active_get", "rna_UILayout_active_set");
00611     
00612     prop= RNA_def_property(srna, "operator_context", PROP_ENUM, PROP_NONE);
00613     RNA_def_property_enum_items(prop, operator_context_items);
00614     RNA_def_property_enum_funcs(prop, "rna_UILayout_op_context_get", "rna_UILayout_op_context_set", NULL);
00615     
00616     prop= RNA_def_property(srna, "enabled", PROP_BOOLEAN, PROP_NONE);
00617     RNA_def_property_boolean_funcs(prop, "rna_UILayout_enabled_get", "rna_UILayout_enabled_set");
00618     RNA_def_property_ui_text(prop, "Enabled", "When false, this (sub)layout is greyed out");
00619     
00620     prop= RNA_def_property(srna, "alert", PROP_BOOLEAN, PROP_NONE);
00621     RNA_def_property_boolean_funcs(prop, "rna_UILayout_alert_get", "rna_UILayout_alert_set");
00622 
00623     prop= RNA_def_property(srna, "alignment", PROP_ENUM, PROP_NONE);
00624     RNA_def_property_enum_items(prop, alignment_items);
00625     RNA_def_property_enum_funcs(prop, "rna_UILayout_alignment_get", "rna_UILayout_alignment_set", NULL);
00626 
00627 #if 0
00628     prop= RNA_def_property(srna, "keep_aspect", PROP_BOOLEAN, PROP_NONE);
00629     RNA_def_property_boolean_funcs(prop, "rna_UILayout_keep_aspect_get", "rna_UILayout_keep_aspect_set");
00630 #endif
00631 
00632     prop= RNA_def_property(srna, "scale_x", PROP_FLOAT, PROP_UNSIGNED);
00633     RNA_def_property_float_funcs(prop, "rna_UILayout_scale_x_get", "rna_UILayout_scale_x_set", NULL);
00634     RNA_def_property_ui_text(prop, "Scale X", "Scale factor along the X for items in this (sub)layout");
00635     
00636     prop= RNA_def_property(srna, "scale_y", PROP_FLOAT, PROP_UNSIGNED);
00637     RNA_def_property_float_funcs(prop, "rna_UILayout_scale_y_get", "rna_UILayout_scale_y_set", NULL);
00638     RNA_def_property_ui_text(prop, "Scale Y", "Scale factor along the Y for items in this (sub)layout");
00639     RNA_api_ui_layout(srna);
00640 }
00641 
00642 static void rna_def_panel(BlenderRNA *brna)
00643 {
00644     StructRNA *srna;
00645     PropertyRNA *prop;
00646     PropertyRNA *parm;
00647     FunctionRNA *func;
00648     
00649     static EnumPropertyItem panel_flag_items[] = {
00650             {PNL_DEFAULT_CLOSED, "DEFAULT_CLOSED", 0, "Default Closed",
00651                                  "Defines if the panel has to be open or collapsed at the time of its creation"},
00652             {PNL_NO_HEADER, "HIDE_HEADER", 0, "Show Header",
00653                             "If set to True, the panel shows a header, which contains a clickable "
00654                             "arrow to collapse the panel and the label (see bl_label)"},
00655             {0, NULL, 0, NULL, NULL}};
00656     
00657     srna= RNA_def_struct(brna, "Panel", NULL);
00658     RNA_def_struct_ui_text(srna, "Panel", "Panel containing UI elements");
00659     RNA_def_struct_sdna(srna, "Panel");
00660     RNA_def_struct_refine_func(srna, "rna_Panel_refine");
00661     RNA_def_struct_register_funcs(srna, "rna_Panel_register", "rna_Panel_unregister", NULL);
00662 
00663     /* poll */
00664     func= RNA_def_function(srna, "poll", NULL);
00665     RNA_def_function_ui_description(func, "If this method returns a non-null output, then the panel can be drawn");
00666     RNA_def_function_flag(func, FUNC_NO_SELF|FUNC_REGISTER_OPTIONAL);
00667     RNA_def_function_return(func, RNA_def_boolean(func, "visible", 1, "", ""));
00668     parm= RNA_def_pointer(func, "context", "Context", "", "");
00669     RNA_def_property_flag(parm, PROP_REQUIRED|PROP_NEVER_NULL);
00670 
00671     /* draw */
00672     func= RNA_def_function(srna, "draw", NULL);
00673     RNA_def_function_ui_description(func, "Draw UI elements into the panel UI layout");
00674     RNA_def_function_flag(func, FUNC_REGISTER);
00675     parm= RNA_def_pointer(func, "context", "Context", "", "");
00676     RNA_def_property_flag(parm, PROP_REQUIRED|PROP_NEVER_NULL);
00677 
00678     func= RNA_def_function(srna, "draw_header", NULL);
00679     RNA_def_function_ui_description(func, "Draw UI elements into the panel's header UI layout");
00680     RNA_def_function_flag(func, FUNC_REGISTER);
00681     parm= RNA_def_pointer(func, "context", "Context", "", "");
00682     RNA_def_property_flag(parm, PROP_REQUIRED|PROP_NEVER_NULL);
00683 
00684     prop= RNA_def_property(srna, "layout", PROP_POINTER, PROP_NONE);
00685     RNA_def_property_struct_type(prop, "UILayout");
00686     RNA_def_property_ui_text(prop, "Layout", "Defines the structure of the panel in the UI");
00687     
00688     prop= RNA_def_property(srna, "text", PROP_STRING, PROP_NONE);
00689     RNA_def_property_string_sdna(prop, NULL, "drawname");
00690     RNA_def_property_ui_text(prop, "Text", "XXX todo");
00691     
00692     /* registration */
00693     prop= RNA_def_property(srna, "bl_idname", PROP_STRING, PROP_NONE);
00694     RNA_def_property_string_sdna(prop, NULL, "type->idname");
00695     RNA_def_property_flag(prop, PROP_REGISTER|PROP_NEVER_CLAMP);
00696     RNA_def_property_ui_text(prop, "ID Name",
00697                              "If this is set, the panel gets a custom ID, otherwise it takes the "
00698                              "name of the class used to define the panel. For example, if the "
00699                              "class name is \"OBJECT_PT_hello\", and bl_idname is not set by the "
00700                              "script, then bl_idname = \"OBJECT_PT_hello\"");
00701     
00702     prop= RNA_def_property(srna, "bl_label", PROP_STRING, PROP_NONE);
00703     RNA_def_property_string_sdna(prop, NULL, "type->label");
00704     RNA_def_property_flag(prop, PROP_REGISTER);
00705     RNA_def_property_ui_text(prop, "Label",
00706                              "The panel label, shows up in the panel header at the right of the "
00707                              "triangle used to collapse the panel");
00708     
00709     prop= RNA_def_property(srna, "bl_space_type", PROP_ENUM, PROP_NONE);
00710     RNA_def_property_enum_sdna(prop, NULL, "type->space_type");
00711     RNA_def_property_enum_items(prop, space_type_items);
00712     RNA_def_property_flag(prop, PROP_REGISTER);
00713     RNA_def_property_ui_text(prop, "Space type", "The space where the panel is going to be used in");
00714     
00715     prop= RNA_def_property(srna, "bl_region_type", PROP_ENUM, PROP_NONE);
00716     RNA_def_property_enum_sdna(prop, NULL, "type->region_type");
00717     RNA_def_property_enum_items(prop, region_type_items);
00718     RNA_def_property_flag(prop, PROP_REGISTER);
00719     RNA_def_property_ui_text(prop, "Region Type", "The region where the panel is going to be used in");
00720 
00721     prop= RNA_def_property(srna, "bl_context", PROP_STRING, PROP_NONE);
00722     RNA_def_property_string_sdna(prop, NULL, "type->context");
00723     RNA_def_property_flag(prop, PROP_REGISTER_OPTIONAL); /* should this be optional? - Campbell */
00724     RNA_def_property_ui_text(prop, "Context",
00725                              "The context in which the panel belongs to. (TODO: explain the "
00726                              "possible combinations bl_context/bl_region_type/bl_space_type)");
00727     
00728     prop= RNA_def_property(srna, "bl_options", PROP_ENUM, PROP_NONE);
00729     RNA_def_property_enum_sdna(prop, NULL, "type->flag");
00730     RNA_def_property_enum_items(prop, panel_flag_items);
00731     RNA_def_property_flag(prop, PROP_REGISTER_OPTIONAL|PROP_ENUM_FLAG);
00732     RNA_def_property_ui_text(prop, "Options",  "Options for this panel type");
00733 }
00734 
00735 static void rna_def_header(BlenderRNA *brna)
00736 {
00737     StructRNA *srna;
00738     PropertyRNA *prop;
00739     PropertyRNA *parm;
00740     FunctionRNA *func;
00741     
00742     srna= RNA_def_struct(brna, "Header", NULL);
00743     RNA_def_struct_ui_text(srna, "Header", "Editor header containing UI elements");
00744     RNA_def_struct_sdna(srna, "Header");
00745     RNA_def_struct_refine_func(srna, "rna_Header_refine");
00746     RNA_def_struct_register_funcs(srna, "rna_Header_register", "rna_Header_unregister", NULL);
00747 
00748     /* draw */
00749     func= RNA_def_function(srna, "draw", NULL);
00750     RNA_def_function_ui_description(func, "Draw UI elements into the header UI layout");
00751     RNA_def_function_flag(func, FUNC_REGISTER);
00752     parm= RNA_def_pointer(func, "context", "Context", "", "");
00753     RNA_def_property_flag(parm, PROP_REQUIRED);
00754 
00755     RNA_define_verify_sdna(0); // not in sdna
00756 
00757     prop= RNA_def_property(srna, "layout", PROP_POINTER, PROP_NONE);
00758     RNA_def_property_pointer_sdna(prop, NULL, "layout");
00759     RNA_def_property_struct_type(prop, "UILayout");
00760     RNA_def_property_ui_text(prop, "Layout", "Structure of the header in the UI");
00761 
00762     /* registration */
00763     prop= RNA_def_property(srna, "bl_idname", PROP_STRING, PROP_NONE);
00764     RNA_def_property_string_sdna(prop, NULL, "type->idname");
00765     RNA_def_property_flag(prop, PROP_REGISTER|PROP_NEVER_CLAMP);
00766     RNA_def_property_ui_text(prop, "ID Name",
00767                              "If this is set, the header gets a custom ID, otherwise it takes the "
00768                              "name of the class used to define the panel; for example, if the "
00769                              "class name is \"OBJECT_HT_hello\", and bl_idname is not set by the "
00770                              "script, then bl_idname = \"OBJECT_HT_hello\"");
00771 
00772     prop= RNA_def_property(srna, "bl_space_type", PROP_ENUM, PROP_NONE);
00773     RNA_def_property_enum_sdna(prop, NULL, "type->space_type");
00774     RNA_def_property_enum_items(prop, space_type_items);
00775     RNA_def_property_flag(prop, PROP_REGISTER);
00776     RNA_def_property_ui_text(prop, "Space type", "The space where the header is going to be used in");
00777 
00778     RNA_define_verify_sdna(1);
00779 }
00780 
00781 static void rna_def_menu(BlenderRNA *brna)
00782 {
00783     StructRNA *srna;
00784     PropertyRNA *prop;
00785     PropertyRNA *parm;
00786     FunctionRNA *func;
00787     
00788     srna= RNA_def_struct(brna, "Menu", NULL);
00789     RNA_def_struct_ui_text(srna, "Menu", "Editor menu containing buttons");
00790     RNA_def_struct_sdna(srna, "Menu");
00791     RNA_def_struct_refine_func(srna, "rna_Menu_refine");
00792     RNA_def_struct_register_funcs(srna, "rna_Menu_register", "rna_Menu_unregister", NULL);
00793 
00794     /* poll */
00795     func= RNA_def_function(srna, "poll", NULL);
00796     RNA_def_function_ui_description(func, "If this method returns a non-null output, then the menu can be drawn");
00797     RNA_def_function_flag(func, FUNC_NO_SELF|FUNC_REGISTER_OPTIONAL);
00798     RNA_def_function_return(func, RNA_def_boolean(func, "visible", 1, "", ""));
00799     parm= RNA_def_pointer(func, "context", "Context", "", "");
00800     RNA_def_property_flag(parm, PROP_REQUIRED);
00801 
00802     /* draw */
00803     func= RNA_def_function(srna, "draw", NULL);
00804     RNA_def_function_ui_description(func, "Draw UI elements into the menu UI layout");
00805     RNA_def_function_flag(func, FUNC_REGISTER);
00806     parm= RNA_def_pointer(func, "context", "Context", "", "");
00807     RNA_def_property_flag(parm, PROP_REQUIRED);
00808 
00809     RNA_define_verify_sdna(0); // not in sdna
00810 
00811     prop= RNA_def_property(srna, "layout", PROP_POINTER, PROP_NONE);
00812     RNA_def_property_pointer_sdna(prop, NULL, "layout");
00813     RNA_def_property_struct_type(prop, "UILayout");
00814     RNA_def_property_ui_text(prop, "Layout", "Defines the structure of the menu in the UI");
00815 
00816     /* registration */
00817     prop= RNA_def_property(srna, "bl_idname", PROP_STRING, PROP_NONE);
00818     RNA_def_property_string_sdna(prop, NULL, "type->idname");
00819     RNA_def_property_flag(prop, PROP_REGISTER|PROP_NEVER_CLAMP);
00820     RNA_def_property_ui_text(prop, "ID Name",
00821                              "If this is set, the menu gets a custom ID, otherwise it takes the "
00822                              "name of the class used to define the menu (for example, if the "
00823                              "class name is \"OBJECT_MT_hello\", and bl_idname is not set by the "
00824                              "script, then bl_idname = \"OBJECT_MT_hello\")");
00825 
00826     prop= RNA_def_property(srna, "bl_label", PROP_STRING, PROP_NONE);
00827     RNA_def_property_string_sdna(prop, NULL, "type->label");
00828     RNA_def_property_flag(prop, PROP_REGISTER);
00829     RNA_def_property_ui_text(prop, "Label", "The menu label");
00830 
00831     prop= RNA_def_property(srna, "bl_description", PROP_STRING, PROP_TRANSLATE);
00832     RNA_def_property_string_sdna(prop, NULL, "type->description");
00833     RNA_def_property_string_maxlength(prop, RNA_DYN_DESCR_MAX); /* else it uses the pointer size! */
00834     RNA_def_property_string_funcs(prop, NULL, NULL, "rna_Menu_bl_description_set");
00835     // RNA_def_property_clear_flag(prop, PROP_EDITABLE);
00836     RNA_def_property_flag(prop, PROP_REGISTER_OPTIONAL);
00837 
00838     RNA_define_verify_sdna(1);
00839 }
00840 
00841 void RNA_def_ui(BlenderRNA *brna)
00842 {
00843     rna_def_ui_layout(brna);
00844     rna_def_panel(brna);
00845     rna_def_header(brna);
00846     rna_def_menu(brna);
00847 }
00848 
00849 #endif // RNA_RUNTIME
00850