From: Mikko Rasa Date: Sun, 20 Aug 2023 09:55:01 +0000 (+0300) Subject: Use nullptr instead of 0 for pointers X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=81c4024fb6acf37df702a803dc4efdf82a81525a;p=libs%2Fgltk.git Use nullptr instead of 0 for pointers --- diff --git a/source/arrangement.h b/source/arrangement.h index 164a091..2decb3e 100644 --- a/source/arrangement.h +++ b/source/arrangement.h @@ -41,7 +41,7 @@ protected: }; Layout &layout; - Arrangement *parent = 0; + Arrangement *parent = nullptr; Edge edges[4]; Arrangement(Layout &); diff --git a/source/button.h b/source/button.h index 09084f1..962b2e1 100644 --- a/source/button.h +++ b/source/button.h @@ -29,7 +29,7 @@ public: private: Text text; - const GL::Texture2D *icon = 0; + const GL::Texture2D *icon = nullptr; bool pressed = false; public: diff --git a/source/container.cpp b/source/container.cpp index ef837a2..4f4d2a3 100644 --- a/source/container.cpp +++ b/source/container.cpp @@ -35,7 +35,7 @@ void Container::remove(Widget &wdg) if(i==children.end()) throw hierarchy_error("widget not in container"); - wdg.set_parent(0); + wdg.set_parent(nullptr); delete *i; children.erase(i); if(wdg.get_animation_interval()) @@ -92,7 +92,7 @@ Widget *Container::get_child_at(int x, int y) const if((*--i)->widget->is_visible() && (*i)->widget->get_geometry().is_inside(x, y)) return (*i)->widget; - return 0; + return nullptr; } Widget *Container::get_descendant_at(int x, int y) const @@ -209,7 +209,7 @@ void Container::button_release(int x, int y, unsigned btn) { if(child==click_focus && btn==click_button) { - click_focus = 0; + click_focus = nullptr; if(!pointer_focus) set_pointer_focus(get_child_at(x, y)); } @@ -223,7 +223,7 @@ void Container::pointer_motion(int x, int y) { Widget *child = get_pointer_target(x, y, false); if(!pointer_grabbed) - set_pointer_focus((child && child->get_geometry().is_inside(x, y)) ? child : 0); + set_pointer_focus((child && child->get_geometry().is_inside(x, y)) ? child : nullptr); if(child) { @@ -246,14 +246,14 @@ Widget *Container::get_pointer_target(int x, int y, bool touch) const if(child && child->is_enabled()) return child; else - return 0; + return nullptr; } } void Container::pointer_leave() { Widget::pointer_leave(); - set_pointer_focus(0); + set_pointer_focus(nullptr); } void Container::touch_press(int x, int y, unsigned finger) @@ -275,7 +275,7 @@ void Container::touch_release(int x, int y, unsigned finger) { // TODO track focus for each finger separately if(child==touch_focus) - touch_focus = 0; + touch_focus = nullptr; const Geometry &cgeom = child->get_geometry(); child->touch_release(x-cgeom.x, y-cgeom.y, finger); @@ -325,7 +325,7 @@ void Container::focus_in() void Container::focus_out() { saved_input_focus = input_focus; - set_input_focus(0); + set_input_focus(nullptr); Widget::focus_out(); } @@ -394,11 +394,11 @@ void Container::Child::visibility_changed(bool v) if(!v) { if(widget==container.click_focus) - container.click_focus = 0; + container.click_focus = nullptr; if(widget==container.pointer_focus) - container.set_pointer_focus(0); + container.set_pointer_focus(nullptr); if(widget==container.input_focus) - container.set_input_focus(0); + container.set_input_focus(nullptr); } } @@ -424,7 +424,7 @@ void Container::Child::ungrab_pointer() if(container.pointer_grabbed && container.pointer_focus==widget) { // XXX Should set to the widget under pointer - container.set_pointer_focus(0); + container.set_pointer_focus(nullptr); container.signal_ungrab_pointer.emit(); } } diff --git a/source/container.h b/source/container.h index 61502e4..adaee6f 100644 --- a/source/container.h +++ b/source/container.h @@ -24,7 +24,7 @@ protected: struct Child: public sigc::trackable { Container &container; - Widget *widget = 0; + Widget *widget = nullptr; Time::TimeDelta time_since_animate; Child(Container &, Widget *); @@ -39,13 +39,13 @@ protected: }; std::list children; - Widget *click_focus = 0; + Widget *click_focus = nullptr; unsigned click_button = 0; - Widget *pointer_focus = 0; + Widget *pointer_focus = nullptr; bool pointer_grabbed = false; - Widget *input_focus = 0; - Widget *saved_input_focus = 0; - Widget *touch_focus = 0; + Widget *input_focus = nullptr; + Widget *saved_input_focus = nullptr; + Widget *touch_focus = nullptr; bool children_rebuild_needed = false; Container() = default; diff --git a/source/entry.cpp b/source/entry.cpp index 19bbaf9..5aadbc2 100644 --- a/source/entry.cpp +++ b/source/entry.cpp @@ -343,7 +343,7 @@ void Entry::on_style_change() if(!style) { - text_part = 0; + text_part = nullptr; return; } @@ -468,7 +468,7 @@ void Entry::check_view_range() if(!multiline || !text_part) return; - visible_rows = text.get_visible_lines(*text_part, geom, 0); + visible_rows = text.get_visible_lines(*text_part, geom, nullptr); unsigned row, col; text.offset_to_coords(edit_pos, row, col); diff --git a/source/entry.h b/source/entry.h index 871024d..66b3327 100644 --- a/source/entry.h +++ b/source/entry.h @@ -45,8 +45,8 @@ private: unsigned edit_pos = 0; unsigned first_row = 0; unsigned visible_rows = 1; - const Part *text_part = 0; - VSlider *slider = 0; + const Part *text_part = nullptr; + VSlider *slider = nullptr; bool got_key_press = false; bool cursor_blink = true; bool selection_active = false; diff --git a/source/graphic.h b/source/graphic.h index b114d7e..32a0686 100644 --- a/source/graphic.h +++ b/source/graphic.h @@ -33,7 +33,7 @@ public: private: Sides border; Sides shadow; - const GL::Texture2D *texture = 0; + const GL::Texture2D *texture = nullptr; Geometry slice; bool repeat = false; diff --git a/source/image.cpp b/source/image.cpp index 8dbf6cf..655ecc2 100644 --- a/source/image.cpp +++ b/source/image.cpp @@ -61,7 +61,7 @@ void Image::update_icon() if(root) { if(icon_name.empty()) - image = 0; + image = nullptr; else image = &root->get_resources().get(icon_name); signal_autosize_changed.emit(); @@ -70,7 +70,7 @@ void Image::update_icon() } } - image = 0; + image = nullptr; } void Image::rebuild_special(const Part &part) diff --git a/source/image.h b/source/image.h index 026aaca..12e77f2 100644 --- a/source/image.h +++ b/source/image.h @@ -21,12 +21,12 @@ public: }; private: - const GL::Texture2D *image = 0; + const GL::Texture2D *image = nullptr; std::string icon_name; bool keep_aspect = true; public: - Image(const GL::Texture2D * = 0); + Image(const GL::Texture2D * = nullptr); virtual const char *get_class() const { return "image"; } diff --git a/source/layout.cpp b/source/layout.cpp index b6248e6..7fcbf10 100644 --- a/source/layout.cpp +++ b/source/layout.cpp @@ -136,7 +136,7 @@ void Layout::push_arrangement(Arrangement &arr) Arrangement *Layout::get_arrangement() const { if(arrangement_stack.empty()) - return 0; + return nullptr; else return arrangement_stack.back(); } diff --git a/source/layout.h b/source/layout.h index 8b1c527..aa11e96 100644 --- a/source/layout.h +++ b/source/layout.h @@ -172,7 +172,7 @@ private: class LinearProgram; struct Pointers; - Container *container = 0; + Container *container = nullptr; std::list slots; unsigned n_active_slots = 0; unsigned n_slack_vars[2] = { 0, 0 }; diff --git a/source/lineararrangement.cpp b/source/lineararrangement.cpp index 3ac686e..269b68e 100644 --- a/source/lineararrangement.cpp +++ b/source/lineararrangement.cpp @@ -12,7 +12,7 @@ void LinearArrangement::set_uniform(bool u) { uniform = u; if(!uniform) - uniform_ref = 0; + uniform_ref = nullptr; } void LinearArrangement::split() diff --git a/source/lineararrangement.h b/source/lineararrangement.h index 917b595..f0ec245 100644 --- a/source/lineararrangement.h +++ b/source/lineararrangement.h @@ -31,7 +31,7 @@ protected: Side gravity = opposite; bool internal_aligned = false; bool uniform = false; - Widget *uniform_ref = 0; + Widget *uniform_ref = nullptr; int next_spacing = -1; LinearArrangement(Layout &, Side); diff --git a/source/list.cpp b/source/list.cpp index 897ea39..e0d2bd8 100644 --- a/source/list.cpp +++ b/source/list.cpp @@ -118,7 +118,7 @@ void List::items_changed() List::Item *List::create_item(unsigned index) { - Item *item = 0; + Item *item = nullptr; if(item_factory) item = item_factory->create_item(index); else @@ -162,7 +162,7 @@ void List::set_selected_index(int i) { sel_index = -1; focus_index = -1; - set_input_focus(0); + set_input_focus(nullptr); signal_selection_cleared.emit(); } else @@ -330,7 +330,7 @@ bool List::navigate(Navigation nav) void List::on_style_change() { - items_part = (style ? style->get_part("items") : 0); + items_part = (style ? style->get_part("items") : nullptr); } void List::move_focus(Navigation nav, bool select) @@ -567,7 +567,7 @@ void List::DataObserver::refresh_item(unsigned i) { delete list.items[i]; // Avoid stale pointer while create_item is executing - list.items[i] = 0; + list.items[i] = nullptr; list.items[i] = list.create_item(i); list.items_changed(); } diff --git a/source/list.h b/source/list.h index 9bc30c6..d6cb2b5 100644 --- a/source/list.h +++ b/source/list.h @@ -157,10 +157,10 @@ public: sigc::signal signal_selection_cleared; private: - ListData *data = 0; + ListData *data = nullptr; bool own_data = false; - DataObserver *observer = 0; - ItemFactory *item_factory = 0; + DataObserver *observer = nullptr; + ItemFactory *item_factory = nullptr; ViewMode view_mode = LIST; int sel_index = -1; int focus_index = -1; @@ -168,7 +168,7 @@ private: unsigned max_scroll = 0; unsigned view_rows = 5; unsigned view_columns = 5; - const Part *items_part = 0; + const Part *items_part = nullptr; bool ignore_slider_change = false; bool dragging = false; int drag_start_x = 0; diff --git a/source/panel.cpp b/source/panel.cpp index 871d7a2..1556826 100644 --- a/source/panel.cpp +++ b/source/panel.cpp @@ -35,7 +35,7 @@ Panel::Panel() Panel::~Panel() { delete layout; - layout = 0; + layout = nullptr; } void Panel::set_layout(Layout *l) @@ -134,7 +134,7 @@ bool Panel::navigate(Navigation nav) Widget *Panel::find_next_child(int origin_x, int origin_y, int origin_dim, int nav_x, int nav_y) const { - Widget *sibling = 0; + Widget *sibling = nullptr; int best_score = 0; for(const Child *c: children) { @@ -210,7 +210,7 @@ void Panel::on_child_removed(Widget &wdg) Panel::Loader::Loader(Panel &p, map &m): DataFile::DerivedObjectLoader(p), wdg_map(m), - last_widget(0) + last_widget(nullptr) { if(!widget_registry_init_done) { diff --git a/source/panel.h b/source/panel.h index 4b013a8..b5755d0 100644 --- a/source/panel.h +++ b/source/panel.h @@ -67,7 +67,7 @@ private: protected: std::vector nav_order; - Layout *layout = 0; + Layout *layout = nullptr; static TypeRegistry widget_registry; static bool widget_registry_init_done; diff --git a/source/part.cpp b/source/part.cpp index 21dacc6..dbccc06 100644 --- a/source/part.cpp +++ b/source/part.cpp @@ -63,7 +63,7 @@ void Part::Loader::graphic_normal(const string &n) void Part::Loader::graphic(State s, const string &n) { - Graphic *grph = (n.empty() ? 0 : &get_collection().get(n)); + Graphic *grph = (n.empty() ? nullptr : &get_collection().get(n)); for(int i=0; i("ui.glsl")); } @@ -80,7 +80,7 @@ GL::Sampler *Resources::create_sampler(const string &name) return sampler; } - return 0; + return nullptr; } GL::Texture2D *Resources::create_texture(const string &name) @@ -98,7 +98,7 @@ GL::Texture2D *Resources::create_texture(const string &name) return tex; } - return 0; + return nullptr; } diff --git a/source/resources.h b/source/resources.h index 1fd030d..6a1c603 100644 --- a/source/resources.h +++ b/source/resources.h @@ -37,8 +37,8 @@ public: private: FS::Path path; - GL::Font *default_font = 0; - DataFile::DirectorySource *dir_src = 0; + GL::Font *default_font = nullptr; + DataFile::DirectorySource *dir_src = nullptr; public: Resources(); diff --git a/source/root.cpp b/source/root.cpp index 5ea447f..376b9d5 100644 --- a/source/root.cpp +++ b/source/root.cpp @@ -11,7 +11,7 @@ namespace Msp { namespace GLtk { Root::Root(Resources &r, Graphics::Window &window): - Root(r, &window, new Input::Keyboard(window), new Input::Mouse(window), 0) + Root(r, &window, new Input::Keyboard(window), new Input::Mouse(window), nullptr) { own_input = true; } @@ -133,7 +133,7 @@ void Root::render(GL::Renderer &renderer, GL::Tag tag) const renderer.set_camera(camera); renderer.set_shader_program(shprog); renderer.set_blend(&blend); - renderer.set_depth_test(0); + renderer.set_depth_test(nullptr); Widget::render(renderer); } @@ -189,7 +189,7 @@ bool Root::axis_motion_event(unsigned, float, float) { if(lbl_tooltip) lbl_tooltip->set_visible(false); - tooltip_target = 0; + tooltip_target = nullptr; } if(pointer_focus) diff --git a/source/root.h b/source/root.h index 9ebe7cf..0fe624f 100644 --- a/source/root.h +++ b/source/root.h @@ -32,19 +32,19 @@ public: private: Resources &resources; - Input::Keyboard *keyboard = 0; - InputMethod *input_method = 0; - Input::Mouse *mouse = 0; - Input::Touchscreen *touchscreen = 0; + Input::Keyboard *keyboard = nullptr; + InputMethod *input_method = nullptr; + Input::Mouse *mouse = nullptr; + Input::Touchscreen *touchscreen = nullptr; bool own_input = false; - Label *lbl_tooltip = 0; + Label *lbl_tooltip = nullptr; int pointer_x = 0; int pointer_y = 0; Time::TimeStamp tooltip_timeout; Time::TimeStamp last_tick; - Widget *tooltip_target = 0; + Widget *tooltip_target = nullptr; Msp::GL::Camera camera; - Msp::GL::Program *shprog = 0; + Msp::GL::Program *shprog = nullptr; Msp::GL::Blend blend; public: @@ -54,7 +54,7 @@ public: /** Creates a Root widget with custom input devices. If window is not null, it is used to set the widget's initial geometry. */ - Root(Resources &, Graphics::Window *, Input::Keyboard *, Input::Mouse *, Input::Touchscreen * = 0); + Root(Resources &, Graphics::Window *, Input::Keyboard *, Input::Mouse *, Input::Touchscreen * = nullptr); virtual ~Root(); virtual const char *get_class() const { return "root"; } diff --git a/source/style.cpp b/source/style.cpp index d1dea04..a339c0c 100644 --- a/source/style.cpp +++ b/source/style.cpp @@ -32,7 +32,7 @@ const GL::Sampler &Style::get_sampler() const const Part *Style::get_part(const string &name) const { auto i = find_if(parts, [&name](const Part &p){ return p.get_name()==name; }); - return (i!=parts.end() ? &*i : 0); + return (i!=parts.end() ? &*i : nullptr); } bool Style::compare_states(State s1, State s2) const diff --git a/source/style.h b/source/style.h index ee25b25..56870da 100644 --- a/source/style.h +++ b/source/style.h @@ -36,10 +36,10 @@ public: typedef std::list PartSeq; private: - const GL::Font *font = 0; + const GL::Font *font = nullptr; unsigned font_size = 0; GL::Color font_color[N_STATES_]; - const GL::Sampler *sampler = 0; + const GL::Sampler *sampler = nullptr; PartSeq parts; public: diff --git a/source/text.h b/source/text.h index cdde08c..6de3573 100644 --- a/source/text.h +++ b/source/text.h @@ -31,7 +31,7 @@ private: struct RenderData; struct CoordsToGeomData; - const Style *style = 0; + const Style *style = nullptr; std::string text; std::vector lines; diff --git a/source/widget.cpp b/source/widget.cpp index 0181e45..4d99000 100644 --- a/source/widget.cpp +++ b/source/widget.cpp @@ -15,7 +15,7 @@ Widget::~Widget() if(parent) { Container *p = parent; - parent = 0; + parent = nullptr; p->remove(*this); } } @@ -110,7 +110,7 @@ void Widget::set_parent(Container *p) catch(...) { // The container has not yet added the widget as its child - parent = 0; + parent = nullptr; throw; } } @@ -127,7 +127,7 @@ void Widget::update_style() for(top=this; top->parent; top=top->parent) ; Root *root = dynamic_cast(top); if(!root) - style = 0; + style = nullptr; else { string sname = get_class(); diff --git a/source/widget.h b/source/widget.h index 9b86691..14d15fc 100644 --- a/source/widget.h +++ b/source/widget.h @@ -47,11 +47,11 @@ public: protected: Geometry geom; std::string style_name; - const Style *style = 0; + const Style *style = nullptr; State state = NORMAL; bool visible = true; InputType input_type = INPUT_NONE; - Container *parent = 0; + Container *parent = nullptr; std::string tooltip; PartCache part_cache; bool rebuild_needed = false;