[Bf-blender-cvs] [f1a86441213] master: Cleanup: Move interface_region_search.c to C++

Hans Goudey noreply at git.blender.org
Wed Nov 10 22:50:14 CET 2021


Commit: f1a86441213f24e5c21adf8ecc0ff0c38e6d8f5e
Author: Hans Goudey
Date:   Wed Nov 10 15:49:49 2021 -0600
Branches: master
https://developer.blender.org/rBf1a86441213f24e5c21adf8ecc0ff0c38e6d8f5e

Cleanup: Move interface_region_search.c to C++

This will be helpful for solving a bug with search during animation
playback, T89313. I tested this on all platforms on the buildbot.

===================================================================

M	source/blender/editors/interface/CMakeLists.txt
R091	source/blender/editors/interface/interface_region_search.c	source/blender/editors/interface/interface_region_search.cc
M	source/blender/editors/interface/interface_regions_intern.h

===================================================================

diff --git a/source/blender/editors/interface/CMakeLists.txt b/source/blender/editors/interface/CMakeLists.txt
index 84172c7efce..2a8f40b2631 100644
--- a/source/blender/editors/interface/CMakeLists.txt
+++ b/source/blender/editors/interface/CMakeLists.txt
@@ -66,7 +66,7 @@ set(SRC
   interface_region_menu_popup.c
   interface_region_popover.c
   interface_region_popup.c
-  interface_region_search.c
+  interface_region_search.cc
   interface_region_tooltip.c
   interface_regions.c
   interface_style.c
diff --git a/source/blender/editors/interface/interface_region_search.c b/source/blender/editors/interface/interface_region_search.cc
similarity index 91%
rename from source/blender/editors/interface/interface_region_search.c
rename to source/blender/editors/interface/interface_region_search.cc
index b8a19d06be1..eaf1ed3693b 100644
--- a/source/blender/editors/interface/interface_region_search.c
+++ b/source/blender/editors/interface/interface_region_search.cc
@@ -23,9 +23,9 @@
  * Search Box Region & Interaction
  */
 
-#include <stdarg.h>
-#include <stdlib.h>
-#include <string.h>
+#include <cstdarg>
+#include <cstdlib>
+#include <cstring>
 
 #include "DNA_ID.h"
 #include "MEM_guardedalloc.h"
@@ -84,7 +84,7 @@ struct uiSearchItems {
   void *active;
 };
 
-typedef struct uiSearchboxData {
+struct uiSearchboxData {
   rcti bbox;
   uiFontStyle fstyle;
   uiSearchItems items;
@@ -102,7 +102,7 @@ typedef struct uiSearchboxData {
    * Used so we can show leading text to menu items less prominently (not related to 'use_sep').
    */
   const char *sep_string;
-} uiSearchboxData;
+};
 
 #define SEARCH_ITEMS 10
 
@@ -166,9 +166,9 @@ bool UI_search_item_add(uiSearchItems *items,
 
   if (name_prefix_offset != 0) {
     /* Lazy initialize, as this isn't used often. */
-    if (items->name_prefix_offsets == NULL) {
-      items->name_prefix_offsets = MEM_callocN(
-          items->maxitem * sizeof(*items->name_prefix_offsets), "search name prefix offsets");
+    if (items->name_prefix_offsets == nullptr) {
+      items->name_prefix_offsets = (uint8_t *)MEM_callocN(
+          items->maxitem * sizeof(*items->name_prefix_offsets), __func__);
     }
     items->name_prefix_offsets[items->totitem] = name_prefix_offset;
   }
@@ -198,7 +198,7 @@ int UI_searchbox_size_x(void)
 
 int UI_search_items_find_index(uiSearchItems *items, const char *name)
 {
-  if (items->name_prefix_offsets != NULL) {
+  if (items->name_prefix_offsets != nullptr) {
     for (int i = 0; i < items->totitem; i++) {
       if (STREQ(name, items->names[i] + items->name_prefix_offsets[i])) {
         return i;
@@ -218,7 +218,7 @@ int UI_search_items_find_index(uiSearchItems *items, const char *name)
 /* region is the search box itself */
 static void ui_searchbox_select(bContext *C, ARegion *region, uiBut *but, int step)
 {
-  uiSearchboxData *data = region->regiondata;
+  uiSearchboxData *data = static_cast<uiSearchboxData *>(region->regiondata);
 
   /* apply step */
   data->active += step;
@@ -285,14 +285,14 @@ static void ui_searchbox_butrect(rcti *r_rect, uiSearchboxData *data, int itemnr
 
 int ui_searchbox_find_index(ARegion *region, const char *name)
 {
-  uiSearchboxData *data = region->regiondata;
+  uiSearchboxData *data = static_cast<uiSearchboxData *>(region->regiondata);
   return UI_search_items_find_index(&data->items, name);
 }
 
 /* x and y in screen-coords. */
 bool ui_searchbox_inside(ARegion *region, const int xy[2])
 {
-  uiSearchboxData *data = region->regiondata;
+  uiSearchboxData *data = static_cast<uiSearchboxData *>(region->regiondata);
 
   return BLI_rcti_isect_pt(&data->bbox, xy[0] - region->winrct.xmin, xy[1] - region->winrct.ymin);
 }
@@ -300,12 +300,12 @@ bool ui_searchbox_inside(ARegion *region, const int xy[2])
 /* string validated to be of correct length (but->hardmax) */
 bool ui_searchbox_apply(uiBut *but, ARegion *region)
 {
-  uiSearchboxData *data = region->regiondata;
+  uiSearchboxData *data = static_cast<uiSearchboxData *>(region->regiondata);
   uiButSearch *search_but = (uiButSearch *)but;
 
   BLI_assert(but->type == UI_BTYPE_SEARCH_MENU);
 
-  search_but->item_active = NULL;
+  search_but->item_active = nullptr;
 
   if (data->active != -1) {
     const char *name = data->items.names[data->active] +
@@ -314,7 +314,7 @@ bool ui_searchbox_apply(uiBut *but, ARegion *region)
                             data->items.name_prefix_offsets[data->active] :
                             0);
 
-    const char *name_sep = data->use_shortcut_sep ? strrchr(name, UI_SEP_CHAR) : NULL;
+    const char *name_sep = data->use_shortcut_sep ? strrchr(name, UI_SEP_CHAR) : nullptr;
 
     /* Search button with dynamic string properties may have their own method of applying
      * the search results, so only copy the result if there is a proper space for it. */
@@ -356,7 +356,7 @@ static struct ARegion *wm_searchbox_tooltip_init(struct bContext *C,
       }
 
       ARegion *searchbox_region = UI_region_searchbox_region_get(region);
-      uiSearchboxData *data = searchbox_region->regiondata;
+      uiSearchboxData *data = static_cast<uiSearchboxData *>(searchbox_region->regiondata);
 
       BLI_assert(data->items.pointers[data->active] == search_but->item_active);
 
@@ -367,13 +367,13 @@ static struct ARegion *wm_searchbox_tooltip_init(struct bContext *C,
           C, region, &rect, search_but->arg, search_but->item_active);
     }
   }
-  return NULL;
+  return nullptr;
 }
 
 bool ui_searchbox_event(
     bContext *C, ARegion *region, uiBut *but, ARegion *butregion, const wmEvent *event)
 {
-  uiSearchboxData *data = region->regiondata;
+  uiSearchboxData *data = static_cast<uiSearchboxData *>(region->regiondata);
   uiButSearch *search_but = (uiButSearch *)but;
   int type = event->type, val = event->val;
   bool handled = false;
@@ -481,7 +481,7 @@ static void ui_searchbox_update_fn(bContext *C,
 void ui_searchbox_update(bContext *C, ARegion *region, uiBut *but, const bool reset)
 {
   uiButSearch *search_but = (uiButSearch *)but;
-  uiSearchboxData *data = region->regiondata;
+  uiSearchboxData *data = static_cast<uiSearchboxData *>(region->regiondata);
 
   BLI_assert(but->type == UI_BTYPE_SEARCH_MENU);
 
@@ -499,7 +499,7 @@ void ui_searchbox_update(bContext *C, ARegion *region, uiBut *but, const bool re
     if (search_but->items_update_fn && search_but->item_active) {
       data->items.active = search_but->item_active;
       ui_searchbox_update_fn(C, search_but, but->editstr, &data->items);
-      data->items.active = NULL;
+      data->items.active = nullptr;
 
       /* found active item, calculate real offset by centering it */
       if (data->items.totitem) {
@@ -538,7 +538,7 @@ void ui_searchbox_update(bContext *C, ARegion *region, uiBut *but, const bool re
                          /* Never include the prefix in the button. */
                          (data->items.name_prefix_offsets ? data->items.name_prefix_offsets[a] :
                                                             0);
-      const char *name_sep = data->use_shortcut_sep ? strrchr(name, UI_SEP_CHAR) : NULL;
+      const char *name_sep = data->use_shortcut_sep ? strrchr(name, UI_SEP_CHAR) : nullptr;
       if (STREQLEN(but->editstr, name, name_sep ? (name_sep - name) : data->items.maxstrlen)) {
         data->active = a;
         break;
@@ -558,7 +558,7 @@ void ui_searchbox_update(bContext *C, ARegion *region, uiBut *but, const bool re
 int ui_searchbox_autocomplete(bContext *C, ARegion *region, uiBut *but, char *str)
 {
   uiButSearch *search_but = (uiButSearch *)but;
-  uiSearchboxData *data = region->regiondata;
+  uiSearchboxData *data = static_cast<uiSearchboxData *>(region->regiondata);
   int match = AUTOCOMPLETE_NO_MATCH;
 
   BLI_assert(but->type == UI_BTYPE_SEARCH_MENU);
@@ -569,7 +569,7 @@ int ui_searchbox_autocomplete(bContext *C, ARegion *region, uiBut *but, char *st
     ui_searchbox_update_fn(C, search_but, but->editstr, &data->items);
 
     match = UI_autocomplete_end(data->items.autocpl, str);
-    data->items.autocpl = NULL;
+    data->items.autocpl = nullptr;
   }
 
   return match;
@@ -577,7 +577,7 @@ int ui_searchbox_autocomplete(bContext *C, ARegion *region, uiBut *but, char *st
 
 static void ui_searchbox_region_draw_fn(const bContext *C, ARegion *region)
 {
-  uiSearchboxData *data = region->regiondata;
+  uiSearchboxData *data = static_cast<uiSearchboxData *>(region->regiondata);
 
   /* pixel space */
   wmOrtho2_region_pixelspace(region);
@@ -630,7 +630,7 @@ static void ui_searchbox_region_draw_fn(const bContext *C, ARegion *region)
         const int state = ((a == data->active) ? UI_ACTIVE : 0) | data->items.states[a];
         char *name = data->items.names[a];
         int icon = data->items.icons[a];
-        char *name_sep_test = NULL;
+        char *name_sep_test = nullptr;
 
         uiMenuItemSeparatorType separator_type = UI_MENU_ITEM_SEPARATOR_NONE;
         if (data->use_shortcut_sep) {
@@ -652,15 +652,15 @@ static void ui_searchbox_region_draw_fn(const bContext *C, ARegion *region)
           }
 
           /* Simple menu item. */
-          ui_draw_menu_item(&data->fstyle, &rect, name, icon, state, separator_type, NULL);
+          ui_draw_menu_item(&data->fstyle, &rect, name, icon, state, separator_type, nullptr);
         }
         else {
           /* Split menu item, faded text before the separator. */
-          char *name_sep = NULL;
+          char *name_sep = nullptr;
           do {
             name_sep = name_sep_test;
             name_sep_test = strstr(name_sep + search_sep_len, data->sep_string);
-          } while (name_sep_test != NULL);
+          } while (name_sep_test != nullptr);
 
           name_sep += search_sep_len;
           const char name_sep_prev = *name_sep;
@@ -683,7 +683,7 @@ static void ui_searchbox_region_draw_fn(const bContext *C, ARegion *region)
           }
 
           /* The previous menu item draws the active selection. */
-          ui_draw_menu_item(&data->fstyle, &rect, name_sep, icon, state, separator_type, NULL);
+          ui_draw_menu_item(&data->fstyle, &rect, name_sep, icon, state, separator_type, nullptr);
         }
       }
       /* indicate more */
@@ -705,7 +705,7 @@ static void ui_se

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list