Bug Summary

File:home/HaikuArchives/ArtPaint/artpaint/paintwindow/StatusView.cpp
Warning:line 51, column 16
Value stored to 'boxLayout' during its initialization is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-unknown-haiku -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name StatusView.cpp -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model static -mframe-pointer=all -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -tune-cpu generic -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /boot/system/lib/clang/12.0.1 -iquote ./ -iquote artpaint/ -iquote artpaint/Utilities/ -iquote artpaint/application/ -iquote artpaint/controls/ -iquote artpaint/layers/ -iquote artpaint/paintwindow/ -iquote artpaint/tools/ -iquote artpaint/viewmanipulators/ -iquote artpaint/windows/ -iquote objects_artpaint/ -isystem /boot/system/develop/headers/private/interface -internal-isystem /system/develop/headers/c++ -internal-isystem /system/develop/headers/c++/x86_64-unknown-haiku -internal-isystem /system/develop/headers/c++/backward -O3 -fdeprecated-macro -fdebug-compilation-dir /boot/home/HaikuArchives/ArtPaint -ferror-limit 19 -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -vectorize-loops -vectorize-slp -analyzer-output=html -faddrsig -o /tmp/scan-build-2022-07-02-122529-1240-1 -x c++ artpaint/paintwindow/StatusView.cpp
1/*
2 * Copyright 2003, Heikki Suhonen
3 * Copyright 2009, Karsten Heimrich
4 * Distributed under the terms of the MIT License.
5 *
6 * Authors:
7 * Heikki Suhonen <heikki.suhonen@gmail.com>
8 * Karsten Heimrich <host.haiku@gmx.de>
9 * Dale Cieslak <dcieslak@yahoo.com>
10 *
11 */
12
13#include "StatusView.h"
14
15#include "ColorPalette.h"
16#include "PaintApplication.h"
17#include "MessageConstants.h"
18#include "HSPictureButton.h"
19#include "Patterns.h"
20#include "MagnificationView.h"
21#include "ResourceServer.h"
22
23
24#include <Catalog.h>
25#include <LayoutBuilder.h>
26#include <Region.h>
27#include <StatusBar.h>
28#include <Window.h>
29
30
31#include <stdio.h>
32
33
34#undef B_TRANSLATION_CONTEXT"StatusView"
35#define B_TRANSLATION_CONTEXT"StatusView" "StatusView"
36
37
38#define TOOLS_VIEW0 0
39#define PROGRESS_VIEW1 1
40
41
42StatusView::StatusView()
43 : BView("status view", B_WILL_DRAW)
44{
45 status_bar = NULL__null;
46
47 // First add the coordinate-view.
48 coordinate_view = new BStringView("coordinate_view","X: , Y:");
49
50 coordinate_box = new BBox("coordinate box");
51 BGroupLayout* boxLayout = BLayoutBuilder::Group<>(coordinate_box, B_HORIZONTAL)
Value stored to 'boxLayout' during its initialization is never read
52 .Add(coordinate_view)
53 .SetInsets(3.0, 5.0, 3.0, 5.0);
54
55 mag_state_view = new MagnificationView();
56
57 // Then we create the message view for displaying help messages.
58 // It will be under the other views and left from the color container.
59 fHelpView = new BStringView("message view", "");
60
61 BRect rect = BRect(0, 0, 50, 50);
62 int32 color_count = ColorSet::currentSet()->sizeOfSet();
63 color_container = new ColorContainer(rect, color_count, 0, true, true);
64
65 selected_colors = new SelectedColorsView(rect);
66 selected_colors->SetExplicitMinSize(BSize(52, 52));
67 selected_colors->SetExplicitMaxSize(BSize(52, 52));
68
69 SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
70
71 status_bar = new BStatusBar("progress indicator");
72
73 BGridLayout* toolsAndColorsCard = BLayoutBuilder::Grid<>(5.0, 0.0)
74 .AddGlue(0, 0)
75 .Add(selected_colors, 1, 0, 1, 2)
76 .Add(color_container, 2, 0, 1, 2)
77 .SetInsets(0.0, 0.0, 0.0, 0.0);
78 toolsAndColorsCard->SetMaxColumnWidth(2, 52);
79
80 BGroupLayout* progressBarCard = BLayoutBuilder::Group<>(B_VERTICAL, 5.0)
81 .Add(status_bar)
82 .SetInsets(2.0, 0.0, 5.0, 0.0);
83
84 fCardLayout = BLayoutBuilder::Cards<>()
85 .Add(toolsAndColorsCard)
86 .Add(progressBarCard);
87
88 fStatusView = BLayoutBuilder::Grid<>(this, 5.0, 0.0)
89 .Add(coordinate_box, 0, 0)
90 .Add(mag_state_view, 1, 0)
91 .AddGlue(2, 0)
92 .Add(fHelpView, 0, 1, 3, 1)
93 .Add(fCardLayout, 3, 0, 2, 2);
94 fStatusView->SetMinColumnWidth(0, StringWidth("X: 9999 (-9999) , Y: 9999 (-9999)"));
95
96 fCardLayout->SetVisibleItem((int32)TOOLS_VIEW0);
97}
98
99
100StatusView::~StatusView()
101{
102 if (coordinate_box->Parent() == NULL__null)
103 delete coordinate_box;
104
105 if (mag_state_view->Parent() == NULL__null)
106 delete mag_state_view;
107
108 if (fHelpView->Parent() == NULL__null)
109 delete fHelpView;
110
111 if (selected_colors->Parent() == NULL__null)
112 delete selected_colors;
113
114 if (color_container->Parent() == NULL__null)
115 delete color_container;
116}
117
118
119BStatusBar*
120StatusView::DisplayProgressIndicator()
121{
122 if (Window()->Lock()) {
123 fCardLayout->SetVisibleItem((int32)PROGRESS_VIEW1);
124 Window()->Unlock();
125 }
126
127 return status_bar;
128}
129
130
131status_t
132StatusView::DisplayToolsAndColors()
133{
134 if (BView* view = Window()->FindView("image_view"))
135 mag_state_view->SetTarget(view);
136
137 fCardLayout->SetVisibleItem((int32)TOOLS_VIEW0);
138
139 return B_OK((int)0);
140}
141
142
143void
144StatusView::SetCoordinates(BPoint point, BPoint reference, bool use_reference)
145{
146 int32 x=(int32)point.x;
147 int32 y=(int32)point.y;
148 char coords[40];
149 if (use_reference) {
150 int32 dx = (int32)fabs(point.x - reference.x) + 1;
151 int32 dy = (int32)fabs(point.y - reference.y) + 1;
152 sprintf(coords,"X: %ld (%ld) Y: %ld (%ld)",x,dx,y,dy);
153 } else {
154 sprintf(coords,"X: %ld Y: %ld",x,y);
155 }
156 coordinate_view->SetText(coords);
157}
158
159
160void
161StatusView::SetMagnifyingScale(float mag)
162{
163 mag_state_view->SetMagnificationLevel(mag);
164}
165
166
167void
168StatusView::SetHelpMessage(const char* s)
169{
170 fHelpView->SetText(s);
171}
172
173
174// #pragma mark -- SelectedColorsView
175
176
177BList SelectedColorsView::list_of_views(10);
178
179
180SelectedColorsView::SelectedColorsView(BRect frame)
181 : BBox(frame, "selected colors view")
182{
183 SetBorder(B_NO_BORDER);
184
185 list_of_views.AddItem(this);
186 ResizeTo(frame.Height(),frame.Height());
187 foreground_color_percentage = 0.6;
188}
189
190
191SelectedColorsView::~SelectedColorsView()
192{
193 // remove ourselves from the list
194 list_of_views.RemoveItem(this);
195}
196
197
198void
199SelectedColorsView::Draw(BRect area)
200{
201 BBox::Draw(area);
202
203 BRect foreground_rect = Bounds();
204 foreground_rect.right = floor(foreground_rect.right*foreground_color_percentage);
205 foreground_rect.bottom = floor(foreground_rect.bottom*foreground_color_percentage);
206 foreground_rect.left += 2;
207 foreground_rect.top += 2;
208
209 BRegion background_region;
210 BRect rect = foreground_rect;
211 rect.OffsetBy(Bounds().right - rect.right - 2, Bounds().bottom - rect.bottom -2);
212 rect.InsetBy(1, 1);
213 background_region.Set(rect);
214 foreground_rect.InsetBy(-1,-1);
215 background_region.Exclude(foreground_rect);
216 foreground_rect.InsetBy(1,1);
217
218 SetHighColor(255, 255, 255, 255);
219 StrokeRect(foreground_rect);
220 foreground_rect.InsetBy(1, 1);
221// foreground_rect = foreground_rect & area;
222
223 SetHighAndLowColors(((PaintApplication*)be_app)->Color(TRUE1));
224 FillRect(foreground_rect, HS_2X2_BLOCKS);
225
226 SetHighColor(0, 0, 0, 255);
227 StrokeLine(BPoint(foreground_rect.right + 2, rect.top - 1),
228 BPoint(rect.right + 1, rect.top - 1));
229 StrokeLine(BPoint(rect.right + 1, rect.top),
230 BPoint(rect.right + 1, rect.bottom));
231 StrokeLine(BPoint(rect.right + 1, rect.bottom + 1),
232 BPoint(rect.left - 1, rect.bottom + 1));
233 StrokeLine(BPoint(rect.left - 1, rect.bottom),
234 BPoint(rect.left - 1, foreground_rect.bottom + 2));
235 StrokeLine(BPoint(rect.left, foreground_rect.bottom + 2),
236 BPoint(foreground_rect.right + 2, foreground_rect.bottom + 2));
237 StrokeLine(BPoint(foreground_rect.right + 2, foreground_rect.bottom + 1),
238 BPoint(foreground_rect.right + 2, rect.top));
239
240 SetHighAndLowColors(((PaintApplication*)be_app)->Color(FALSE0));
241 FillRegion(&background_region, HS_2X2_BLOCKS);
242}
243
244
245void
246SelectedColorsView::MessageReceived(BMessage *message)
247{
248 switch (message->what) {
249 // In this case the color for one of the mousebuttons has changed, draw
250 // again completely. This might come from ColorContainer::MouseDown or
251 // ColorWindow::MessageReceived where it is sent by using the
252 // SendMessageToAll member-function, it informs us that the color for
253 // oneof the mousebuttons has changed
254 case HS_COLOR_CHANGED'CoCH': {
255 Invalidate();
256 } break;
257
258 case B_PASTE: {
259 if (message->WasDropped()) {
260 // Here we see on to which button it was dropped and then
261 // try to extract a color from the message
262 rgb_color *color;
263 ssize_t color_size;
264 if (message->FindData("RGBColor",B_RGB_COLOR_TYPE,
265 (const void**)&color, &color_size) == B_OK((int)0)) {
266 BPoint drop_point = message->DropPoint();
267 drop_point = ConvertFromScreen(drop_point);
268 ((PaintApplication*)be_app)->SetColor(*color,
269 IsPointOverForegroundColor(drop_point));
270 // also inform the selected colors' views
271 SelectedColorsView::SendMessageToAll(HS_COLOR_CHANGED'CoCH');
272 }
273 }
274 } break;
275
276 default: {
277 BBox::MessageReceived(message);
278 } break;
279 }
280}
281
282
283void
284SelectedColorsView::MouseDown(BPoint point)
285{
286 // this function should do something appropriate with the color
287 // that is selected
288 uint32 buttons;
289 GetMouse(&point, &buttons);
290
291 // here check that the point is inside the view
292 if ((buttons & B_PRIMARY_MOUSE_BUTTON) && Bounds().Contains(point)) {
293 bool fore = IsPointOverForegroundColor(point);
294
295 rgb_color c = ((PaintApplication*)be_app)->Color(fore);
296
297 ColorPaletteWindow::showPaletteWindow();
298 ColorPaletteWindow::ChangePaletteColor(c);
299 } else {
300 rgb_color foreground = ((PaintApplication*)be_app)->Color(true);
301 rgb_color background = ((PaintApplication*)be_app)->Color(false);
302
303 ((PaintApplication*)be_app)->SetColor(background,true);
304 ((PaintApplication*)be_app)->SetColor(foreground,false);
305
306 SelectedColorsView::SendMessageToAll(HS_COLOR_CHANGED'CoCH');
307 }
308}
309
310
311void
312SelectedColorsView::MouseMoved(BPoint, uint32 transit, const BMessage*)
313{
314 if (transit == B_ENTERED_VIEW && Window()->IsActive()) {
315 BMessage message(HS_TEMPORARY_HELP_MESSAGE'ThlM');
316 message.AddString("message",
317 B_TRANSLATE("Click here to open color panel.")BLocaleRoster::Default()->GetCatalog()->GetString(("Click here to open color panel."
), "StatusView")
);
318 Window()->PostMessage(&message, Window());
319 }
320
321 if (transit == B_EXITED_VIEW)
322 Window()->PostMessage(HS_TOOL_HELP_MESSAGE'TolM', Window());
323}
324
325
326void
327SelectedColorsView::SendMessageToAll(uint32 what)
328{
329 for (int32 i = 0; i < list_of_views.CountItems(); ++i) {
330 if (SelectedColorsView* view =
331 static_cast<SelectedColorsView*> (list_of_views.ItemAt(i))) {
332 view->Window()->PostMessage(what, view);
333 }
334 }
335}
336
337
338void
339SelectedColorsView::sendMessageToAll(BMessage *message)
340{
341 SelectedColorsView *help;
342
343 for (int32 i=0;i<list_of_views.CountItems();i++) {
344 help = (SelectedColorsView*)list_of_views.ItemAt(i);
345 help->Window()->PostMessage(message,help);
346 }
347}
348
349
350void
351SelectedColorsView::SetHighAndLowColors(const rgb_color &c)
352{
353 rgb_color low = c;
354 rgb_color high = c;
355
356 float coeff = c.alpha / 255.0;
357 low.red = (uint8)(coeff*c.red);
358 low.green = (uint8)(coeff*c.green);
359 low.blue = (uint8)(coeff*c.blue);
360 low.alpha = 255;
361
362 high.red = (uint8)(coeff*c.red + (1-coeff)*255);
363 high.green = (uint8)(coeff*c.green + (1-coeff)*255);
364 high.blue = (uint8)(coeff*c.blue + (1-coeff)*255);
365 high.alpha = 255;
366
367 SetHighColor(high);
368 SetLowColor(low);
369}
370
371
372bool
373SelectedColorsView::IsPointOverForegroundColor(BPoint point)
374{
375 BRect rect = Bounds();
376 rect.right *= foreground_color_percentage;
377 rect.bottom *= foreground_color_percentage;
378 rect.top += 2;
379 rect.left += 2;
380
381 if (rect.Contains(point))
382 return true;
383 return false;
384}