File: | system/develop/headers/os/interface/LayoutBuilder.h |
Warning: | line 438, column 2 Returning null reference |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* | |||
2 | * Copyright 2003, Heikki Suhonen | |||
3 | * Distributed under the terms of the MIT License. | |||
4 | * | |||
5 | * Authors: | |||
6 | * Heikki Suhonen <heikki.suhonen@gmail.com> | |||
7 | * | |||
8 | */ | |||
9 | #include <Bitmap.h> | |||
10 | #include <Catalog.h> | |||
11 | #include <LayoutBuilder.h> | |||
12 | #include <Node.h> | |||
13 | #include <StatusBar.h> | |||
14 | #include <Slider.h> | |||
15 | #include <Window.h> | |||
16 | ||||
17 | #include "AddOns.h" | |||
18 | #include "Blur.h" | |||
19 | #include "ManipulatorInformer.h" | |||
20 | #include "Selection.h" | |||
21 | ||||
22 | #include <new> | |||
23 | ||||
24 | #undef B_TRANSLATION_CONTEXT"AddOns_Blur" | |||
25 | #define B_TRANSLATION_CONTEXT"AddOns_Blur" "AddOns_Blur" | |||
26 | ||||
27 | ||||
28 | #ifdef __cplusplus201402L | |||
29 | extern "C" { | |||
30 | #endif | |||
31 | int32 add_on_api_version = ADD_ON_API_VERSION; | |||
32 | char name[255] = B_TRANSLATE_MARK("Blur" B_UTF8_ELLIPSIS)("Blur" "\xE2\x80\xA6"); | |||
33 | char menu_help_string[255] = B_TRANSLATE_MARK("Adds a blur.")("Adds a blur."); | |||
34 | add_on_types add_on_type = BLUR_FILTER_ADD_ON; | |||
35 | #ifdef __cplusplus201402L | |||
36 | } | |||
37 | #endif | |||
38 | ||||
39 | ||||
40 | Manipulator* instantiate_add_on(BBitmap *bm,ManipulatorInformer *i) | |||
41 | { | |||
42 | delete i; | |||
43 | return new BlurManipulator(bm); | |||
44 | } | |||
45 | ||||
46 | ||||
47 | ||||
48 | ||||
49 | BlurManipulator::BlurManipulator(BBitmap *bm) | |||
50 | : WindowGUIManipulator() | |||
51 | { | |||
52 | preview_bitmap = NULL__null; | |||
53 | wide_copy_of_the_preview_bitmap = NULL__null; | |||
54 | tall_copy_of_the_preview_bitmap = NULL__null; | |||
55 | ||||
56 | config_view = NULL__null; | |||
57 | settings.blur_amount = 5; | |||
58 | ||||
59 | SetPreviewBitmap(bm); | |||
60 | } | |||
61 | ||||
62 | ||||
63 | BlurManipulator::~BlurManipulator() | |||
64 | { | |||
65 | if (tall_copy_of_the_preview_bitmap != NULL__null) { | |||
66 | delete tall_copy_of_the_preview_bitmap; | |||
67 | tall_copy_of_the_preview_bitmap = NULL__null; | |||
68 | } | |||
69 | if (wide_copy_of_the_preview_bitmap != NULL__null) { | |||
70 | delete wide_copy_of_the_preview_bitmap; | |||
71 | wide_copy_of_the_preview_bitmap = NULL__null; | |||
72 | } | |||
73 | if (config_view != NULL__null) { | |||
74 | config_view->RemoveSelf(); | |||
75 | delete config_view; | |||
76 | } | |||
77 | } | |||
78 | ||||
79 | ||||
80 | BBitmap* BlurManipulator::ManipulateBitmap(ManipulatorSettings *set,BBitmap *original,Selection *selection,BStatusBar *status_bar) | |||
81 | { | |||
82 | BlurManipulatorSettings *new_settings = dynamic_cast<BlurManipulatorSettings*>(set); | |||
83 | ||||
84 | if (new_settings == NULL__null) | |||
85 | return NULL__null; | |||
86 | ||||
87 | if (original == NULL__null) | |||
88 | return NULL__null; | |||
89 | ||||
90 | if (new_settings->blur_amount < 1) { | |||
91 | return NULL__null; | |||
92 | } | |||
93 | ||||
94 | BBitmap *source_bitmap; | |||
95 | BBitmap *target_bitmap; | |||
96 | BBitmap *new_bitmap = NULL__null; | |||
97 | ||||
98 | if (original == preview_bitmap) { | |||
99 | return original; | |||
100 | } | |||
101 | else { | |||
102 | // target_bitmap = original; | |||
103 | // source_bitmap = | |||
104 | // new_bitmap = source_bitmap; | |||
105 | } | |||
106 | ||||
107 | // CalculateBlur(source_bitmap,target_bitmap,1,new_settings,selection,status_bar); | |||
108 | ||||
109 | return original; | |||
110 | } | |||
111 | ||||
112 | ||||
113 | int32 BlurManipulator::PreviewBitmap(Selection *sel, bool full_quality,BRegion *updated_region) | |||
114 | { | |||
115 | updated_region->Set(preview_bitmap->Bounds()); | |||
116 | // if ((settings == previous_settings) == FALSE) { | |||
117 | // last_calculated_quality = lowest_allowed_quality; | |||
118 | // previous_settings = settings; | |||
119 | // } | |||
120 | // else | |||
121 | // last_calculated_quality = floor(last_calculated_quality/2.0); | |||
122 | // | |||
123 | // if (full_quality == TRUE) { | |||
124 | // if (last_calculated_quality > 1) | |||
125 | // last_calculated_quality = 1; | |||
126 | // } | |||
127 | // | |||
128 | // if (last_calculated_quality == 1) | |||
129 | // CalculateBlur(copy_of_the_preview_bitmap,preview_bitmap,1,&settings,sel,NULL); | |||
130 | // | |||
131 | // else if (last_calculated_quality == 2) | |||
132 | // CalculateBlur(half_preview_bitmap,preview_bitmap,2,&settings,sel,NULL); | |||
133 | // | |||
134 | // else if (last_calculated_quality == 4) | |||
135 | // CalculateBlur(quarter_preview_bitmap,preview_bitmap,4,&settings,sel,NULL); | |||
136 | // | |||
137 | // else if (last_calculated_quality == 8) | |||
138 | // CalculateBlur(eight_preview_bitmap,preview_bitmap,8,&settings,sel,NULL); | |||
139 | // | |||
140 | // return last_calculated_quality; | |||
141 | if ((settings == previous_settings) == FALSE0) { | |||
142 | // The blur will be done separably. First in the vertical direction and then in horizontal | |||
143 | // direction. | |||
144 | thread_count = GetSystemCpuCount(); | |||
145 | tall_bits = (uint32*)tall_copy_of_the_preview_bitmap->Bits(); | |||
146 | wide_bits = (uint32*)wide_copy_of_the_preview_bitmap->Bits(); | |||
147 | final_bits = (uint32*)preview_bitmap->Bits(); | |||
148 | tall_bpr = tall_copy_of_the_preview_bitmap->BytesPerRow()/4; | |||
149 | wide_bpr = wide_copy_of_the_preview_bitmap->BytesPerRow()/4; | |||
150 | final_bpr = preview_bitmap->BytesPerRow()/4; | |||
151 | final_width = preview_bitmap->Bounds().Width(); | |||
152 | final_height = preview_bitmap->Bounds().Height(); | |||
153 | selection = sel; | |||
154 | status_bar = NULL__null; | |||
155 | blur_amount = settings.blur_amount; | |||
156 | previous_settings = settings; | |||
157 | CalculateBlur(); | |||
158 | return 1; | |||
159 | } | |||
160 | else | |||
161 | return DRAW_NOTHING; | |||
162 | } | |||
163 | ||||
164 | ||||
165 | void BlurManipulator::CalculateBlur() | |||
166 | { | |||
167 | thread_id *threads = new thread_id[thread_count]; | |||
168 | ||||
169 | for (int32 i=0;i<thread_count;i++) { | |||
170 | threads[i] = spawn_thread(thread_entrythread_func,"vertical_blur_thread",B_NORMAL_PRIORITY10,this); | |||
171 | resume_thread(threads[i]); | |||
172 | send_data(threads[i],VERTICAL_THREAD,NULL__null,0); | |||
173 | send_data(threads[i],i,NULL__null,0); | |||
174 | } | |||
175 | for (int32 i=0;i<thread_count;i++) { | |||
176 | int32 return_value; | |||
177 | wait_for_thread(threads[i],&return_value); | |||
178 | } | |||
179 | ||||
180 | for (int32 i=0;i<thread_count;i++) { | |||
181 | threads[i] = spawn_thread(thread_entrythread_func,"horizontal_blur_thread",B_NORMAL_PRIORITY10,this); | |||
182 | resume_thread(threads[i]); | |||
183 | send_data(threads[i],HORIZONTAL_THREAD,NULL__null,0); | |||
184 | send_data(threads[i],i,NULL__null,0); | |||
185 | } | |||
186 | for (int32 i=0;i<thread_count;i++) { | |||
187 | int32 return_value; | |||
188 | wait_for_thread(threads[i],&return_value); | |||
189 | } | |||
190 | ||||
191 | delete[] threads; | |||
192 | } | |||
193 | ||||
194 | ||||
195 | int32 BlurManipulator::thread_entrythread_func(void *data) | |||
196 | { | |||
197 | BlurManipulator *this_pointer = (BlurManipulator*)data; | |||
198 | thread_id sender; | |||
199 | int32 type = receive_data(&sender,NULL__null,0); | |||
200 | int32 thread_number = receive_data(&sender,NULL__null,0); | |||
201 | if (this_pointer != NULL__null) { | |||
202 | if (type == VERTICAL_THREAD) { | |||
203 | this_pointer->VerticalBlur(thread_number); | |||
204 | } | |||
205 | else { | |||
206 | this_pointer->HorizontalBlur(thread_number); | |||
207 | } | |||
208 | return B_OK((int)0); | |||
209 | } | |||
210 | return B_ERROR(-1); | |||
211 | } | |||
212 | ||||
213 | ||||
214 | int32 BlurManipulator::VerticalBlur(int32 thread_number) | |||
215 | { | |||
216 | // vertical blur will be done columnwise so that we can use the | |||
217 | // partial sums. | |||
218 | int32 left = (final_width) / thread_count * thread_number; | |||
219 | int32 right = min_c(left + (final_width+1) / thread_count,final_width)((left + (final_width+1) / thread_count)>(final_width)?(final_width ):(left + (final_width+1) / thread_count)); | |||
220 | float status_bar_update_amount = 50.0 / thread_count / (right-left) * 40; | |||
221 | int32 height = final_height; | |||
222 | uint32 *source_bits = tall_bits; | |||
223 | int32 source_bpr = tall_bpr; | |||
224 | uint32 *target_bits = wide_bits; | |||
225 | int32 target_bpr = wide_bpr; | |||
226 | bool blur_alpha = settings.blur_alpha; | |||
227 | ||||
228 | source_bits += MAX_BLUR_AMOUNT30*source_bpr; | |||
229 | union { | |||
230 | uint8 bytes[4]; | |||
231 | uint32 word; | |||
232 | } color; | |||
233 | float red; | |||
234 | float green; | |||
235 | float blue; | |||
236 | float alpha; | |||
237 | float divider = 1.0/(2*blur_amount+1); | |||
238 | BWindow *status_bar_window = NULL__null; | |||
239 | if (status_bar != NULL__null) | |||
240 | status_bar_window = status_bar->Window(); | |||
241 | ||||
242 | for (int32 x=left;x<=right;x++) { | |||
243 | // Calculate the first pixel for this column. | |||
244 | red = green = blue = alpha = 0; | |||
245 | for (int32 dy=-blur_amount;dy<=blur_amount;dy++) { | |||
246 | color.word = *(source_bits + x + dy*source_bpr); | |||
247 | if (color.bytes[3] != 0) { | |||
248 | blue += color.bytes[0]; | |||
249 | green += color.bytes[1]; | |||
250 | red += color.bytes[2]; | |||
251 | } | |||
252 | alpha += color.bytes[3]; | |||
253 | } | |||
254 | color.bytes[0] = blue*divider; | |||
255 | color.bytes[1] = green*divider; | |||
256 | color.bytes[2] = red*divider; | |||
257 | color.bytes[3] = alpha*divider; | |||
258 | *(target_bits + x + MAX_BLUR_AMOUNT30) = color.word; | |||
259 | ||||
260 | int32 positive_source_y_offset = (blur_amount+1) * source_bpr; | |||
261 | int32 negative_source_y_offset = (-blur_amount)*source_bpr; | |||
262 | int32 target_y_offset = 1 * target_bpr; | |||
263 | for (int32 y=1;y<=height;y++) { | |||
264 | color.word = *(source_bits + x + negative_source_y_offset); | |||
265 | if (color.bytes[3] != 0) { | |||
266 | blue -= color.bytes[0]; | |||
267 | green -= color.bytes[1]; | |||
268 | red -= color.bytes[2]; | |||
269 | } | |||
270 | alpha -= color.bytes[3]; | |||
271 | ||||
272 | color.word = *(source_bits + x + positive_source_y_offset); | |||
273 | if (color.bytes[3] != 0) { | |||
274 | blue += color.bytes[0]; | |||
275 | green += color.bytes[1]; | |||
276 | red += color.bytes[2]; | |||
277 | } | |||
278 | alpha += color.bytes[3]; | |||
279 | ||||
280 | color.bytes[0] = blue*divider; | |||
281 | color.bytes[1] = green*divider; | |||
282 | color.bytes[2] = red*divider; | |||
283 | color.bytes[3] = alpha*divider; | |||
284 | *(target_bits + x+MAX_BLUR_AMOUNT30 + target_y_offset) = color.word; | |||
285 | positive_source_y_offset += source_bpr; | |||
286 | negative_source_y_offset += source_bpr; | |||
287 | target_y_offset += target_bpr; | |||
288 | } | |||
289 | if (((x%40) == 0) && (status_bar_window != NULL__null) && (status_bar_window->LockWithTimeout(0) == B_OK((int)0))) { | |||
290 | status_bar->Update(status_bar_update_amount); | |||
291 | status_bar_window->Unlock(); | |||
292 | } | |||
293 | } | |||
294 | return B_OK((int)0); | |||
295 | } | |||
296 | ||||
297 | int32 BlurManipulator::HorizontalBlur(int32 thread_number) | |||
298 | { | |||
299 | int32 top = (final_height) / thread_count * thread_number; | |||
300 | int32 bottom = min_c(top + (final_height+1) / thread_count,final_height)((top + (final_height+1) / thread_count)>(final_height)?(final_height ):(top + (final_height+1) / thread_count)); | |||
301 | float status_bar_update_amount = 50.0 / thread_count / (bottom-top)*40.0; | |||
302 | int32 width = final_width; | |||
303 | uint32 *source_bits = wide_bits; | |||
304 | int32 source_bpr = wide_bpr; | |||
305 | uint32 *target_bits = final_bits; | |||
306 | int32 target_bpr = final_bpr; | |||
307 | bool blur_alpha = settings.blur_alpha; | |||
308 | union { | |||
309 | uint8 bytes[4]; | |||
310 | uint32 word; | |||
311 | } color; | |||
312 | float red; | |||
313 | float green; | |||
314 | float blue; | |||
315 | float alpha; | |||
316 | float divider = 1.0/(2*blur_amount+1); | |||
317 | // In this loop we can use the sums that we already have calculated to remove the innermost | |||
318 | // loop. | |||
319 | ||||
320 | BWindow *status_bar_window = NULL__null; | |||
321 | if (status_bar != NULL__null) | |||
322 | status_bar_window = status_bar->Window(); | |||
323 | ||||
324 | source_bits += top * source_bpr; | |||
325 | target_bits += top * target_bpr; | |||
326 | ||||
327 | if ((selection == NULL__null) || (selection->IsEmpty())) { | |||
328 | for (int32 y=top;y<=bottom;y++) { | |||
329 | for (int32 dx=0;dx<MAX_BLUR_AMOUNT30;dx++) { | |||
330 | *(source_bits + dx) = *(source_bits + MAX_BLUR_AMOUNT30); | |||
331 | *(source_bits + source_bpr - dx - 1) = *(source_bits + source_bpr - MAX_BLUR_AMOUNT30-1); | |||
332 | } | |||
333 | source_bits += MAX_BLUR_AMOUNT30; | |||
334 | // Calculate the first pixel for this row. | |||
335 | red = green = blue = alpha = 0; | |||
336 | for (int32 dx=-blur_amount;dx<=blur_amount;dx++) { | |||
337 | color.word = *(source_bits + dx); | |||
338 | if (color.bytes[3] != 0) { | |||
339 | blue += color.bytes[0]; | |||
340 | green += color.bytes[1]; | |||
341 | red += color.bytes[2]; | |||
342 | } | |||
343 | alpha += color.bytes[3]; | |||
344 | } | |||
345 | color.bytes[0] = blue*divider; | |||
346 | color.bytes[1] = green*divider; | |||
347 | color.bytes[2] = red*divider; | |||
348 | color.bytes[3] = alpha*divider; | |||
349 | *target_bits++ = color.word; | |||
350 | ++source_bits; | |||
351 | for (int32 x=1;x<=width;x++) { | |||
352 | color.word = *(source_bits - blur_amount - 1); | |||
353 | if (color.bytes[3] != 0) { | |||
354 | blue -= color.bytes[0]; | |||
355 | green -= color.bytes[1]; | |||
356 | red -= color.bytes[2]; | |||
357 | } | |||
358 | alpha -= color.bytes[3]; | |||
359 | ||||
360 | color.word = *(source_bits + blur_amount); | |||
361 | if (color.bytes[3] != 0) { | |||
362 | blue += color.bytes[0]; | |||
363 | green += color.bytes[1]; | |||
364 | red += color.bytes[2]; | |||
365 | } | |||
366 | alpha += color.bytes[3]; | |||
367 | ||||
368 | color.bytes[0] = blue*divider; | |||
369 | color.bytes[1] = green*divider; | |||
370 | color.bytes[2] = red*divider; | |||
371 | color.bytes[3] = alpha*divider; | |||
372 | *target_bits++ = color.word; | |||
373 | ++source_bits; | |||
374 | } | |||
375 | source_bits += MAX_BLUR_AMOUNT30; | |||
376 | if (((y%40) == 0) && (status_bar_window != NULL__null) && (status_bar_window->LockWithTimeout(0) == B_OK((int)0))) { | |||
377 | status_bar->Update(status_bar_update_amount); | |||
378 | status_bar_window->Unlock(); | |||
379 | } | |||
380 | } | |||
381 | } | |||
382 | else if (selection->IsEmpty() == false) { | |||
383 | for (int32 y=top;y<=bottom;y++) { | |||
384 | for (int32 dx=0;dx<MAX_BLUR_AMOUNT30;dx++) { | |||
385 | *(source_bits + dx) = *(source_bits + MAX_BLUR_AMOUNT30); | |||
386 | *(source_bits + source_bpr - dx - 1) = *(source_bits + source_bpr - MAX_BLUR_AMOUNT30-1); | |||
387 | } | |||
388 | source_bits += MAX_BLUR_AMOUNT30; | |||
389 | // Calculate the first pixel for this row. | |||
390 | red = green = blue = alpha = 0; | |||
391 | for (int32 dx=-blur_amount;dx<=blur_amount;dx++) { | |||
392 | color.word = *(source_bits + dx); | |||
393 | if (color.bytes[3] != 0) { | |||
394 | blue += color.bytes[0]; | |||
395 | green += color.bytes[1]; | |||
396 | red += color.bytes[2]; | |||
397 | } | |||
398 | alpha += color.bytes[3]; | |||
399 | } | |||
400 | if (selection->ContainsPoint(0,y)) { | |||
401 | color.bytes[0] = blue*divider; | |||
402 | color.bytes[1] = green*divider; | |||
403 | color.bytes[2] = red*divider; | |||
404 | color.bytes[3] = alpha*divider; | |||
405 | *target_bits++ = color.word; | |||
406 | ++source_bits; | |||
407 | } | |||
408 | else { | |||
409 | ++source_bits; | |||
410 | ++target_bits; | |||
411 | } | |||
412 | for (int32 x=1;x<=width;x++) { | |||
413 | color.word = *(source_bits - blur_amount - 1); | |||
414 | if (color.bytes[3] != 0) { | |||
415 | blue -= color.bytes[0]; | |||
416 | green -= color.bytes[1]; | |||
417 | red -= color.bytes[2]; | |||
418 | } | |||
419 | alpha -= color.bytes[3]; | |||
420 | ||||
421 | color.word = *(source_bits + blur_amount); | |||
422 | if (color.bytes[3] != 0) { | |||
423 | blue += color.bytes[0]; | |||
424 | green += color.bytes[1]; | |||
425 | red += color.bytes[2]; | |||
426 | } | |||
427 | alpha += color.bytes[3]; | |||
428 | ||||
429 | if (selection->ContainsPoint(x,y)) { | |||
430 | color.bytes[0] = blue*divider; | |||
431 | color.bytes[1] = green*divider; | |||
432 | color.bytes[2] = red*divider; | |||
433 | color.bytes[3] = alpha*divider; | |||
434 | *target_bits++ = color.word; | |||
435 | ++source_bits; | |||
436 | } | |||
437 | else { | |||
438 | ++target_bits; | |||
439 | ++source_bits; | |||
440 | } | |||
441 | } | |||
442 | source_bits += MAX_BLUR_AMOUNT30; | |||
443 | if (((y%40) == 0) && (status_bar_window != NULL__null) && (status_bar_window->LockWithTimeout(0) == B_OK((int)0))) { | |||
444 | status_bar->Update(status_bar_update_amount); | |||
445 | status_bar_window->Unlock(); | |||
446 | } | |||
447 | } | |||
448 | } | |||
449 | return B_OK((int)0); | |||
450 | } | |||
451 | ||||
452 | ||||
453 | void BlurManipulator::SetPreviewBitmap(BBitmap *bm) | |||
454 | { | |||
455 | if (bm != preview_bitmap) { | |||
456 | if (wide_copy_of_the_preview_bitmap != NULL__null) { | |||
457 | delete wide_copy_of_the_preview_bitmap; | |||
458 | wide_copy_of_the_preview_bitmap = NULL__null; | |||
459 | } | |||
460 | if (tall_copy_of_the_preview_bitmap != NULL__null) { | |||
461 | delete tall_copy_of_the_preview_bitmap; | |||
462 | tall_copy_of_the_preview_bitmap = NULL__null; | |||
463 | } | |||
464 | if (bm != NULL__null) { | |||
465 | preview_bitmap = bm; | |||
466 | BRect bounds = preview_bitmap->Bounds(); | |||
467 | bounds.InsetBy(0,-MAX_BLUR_AMOUNT30); | |||
468 | bounds.OffsetTo(0,0); | |||
469 | tall_copy_of_the_preview_bitmap = new BBitmap(bounds,B_RGB32); | |||
470 | if (tall_copy_of_the_preview_bitmap->IsValid() == FALSE0) { | |||
471 | throw std::bad_alloc(); | |||
472 | } | |||
473 | bounds.InsetBy(-MAX_BLUR_AMOUNT30,MAX_BLUR_AMOUNT30); | |||
474 | bounds.OffsetTo(0,0); | |||
475 | wide_copy_of_the_preview_bitmap = new BBitmap(bounds,B_RGB32); | |||
476 | if (wide_copy_of_the_preview_bitmap->IsValid() == FALSE0) { | |||
477 | delete tall_copy_of_the_preview_bitmap; | |||
478 | throw std::bad_alloc(); | |||
479 | } | |||
480 | ||||
481 | ||||
482 | // After allocating the bitmaps we should copy the data from preview_bitmap to | |||
483 | // tall_copy_of_the_preview_bitmap. | |||
484 | uint32 *source_bits = (uint32*)preview_bitmap->Bits(); | |||
485 | uint32 *target_bits = (uint32*)tall_copy_of_the_preview_bitmap->Bits(); | |||
486 | int32 source_bpr = preview_bitmap->BytesPerRow()/4; | |||
487 | int32 target_bpr = tall_copy_of_the_preview_bitmap->BytesPerRow()/4; | |||
488 | int32 width = preview_bitmap->Bounds().Width(); | |||
489 | int32 height = preview_bitmap->Bounds().Height(); | |||
490 | // First copy the first row MAX_BLUR_AMOUNT times. | |||
491 | for (int32 y=0;y<MAX_BLUR_AMOUNT30;y++) { | |||
492 | for (int32 x=0;x<=width;x++) { | |||
493 | *target_bits++ = *source_bits++; | |||
494 | } | |||
495 | source_bits -= source_bpr; | |||
496 | } | |||
497 | // Then copy the actual bitmap | |||
498 | for (int32 y=0;y<=height;y++) { | |||
499 | for (int32 x=0;x<=width;x++) { | |||
500 | *target_bits++ = *source_bits++; | |||
501 | } | |||
502 | } | |||
503 | // Then copy the last row MAX_BLUR_AMOUNT times | |||
504 | for (int32 y=0;y<MAX_BLUR_AMOUNT30;y++) { | |||
505 | source_bits -= source_bpr; | |||
506 | for (int32 x=0;x<=width;x++) { | |||
507 | *target_bits++ = *source_bits++; | |||
508 | } | |||
509 | } | |||
510 | } | |||
511 | else { | |||
512 | preview_bitmap = NULL__null; | |||
513 | tall_copy_of_the_preview_bitmap = NULL__null; | |||
514 | wide_copy_of_the_preview_bitmap = NULL__null; | |||
515 | } | |||
516 | } | |||
517 | } | |||
518 | ||||
519 | ||||
520 | void BlurManipulator::Reset(Selection*) | |||
521 | { | |||
522 | if (preview_bitmap != NULL__null) { | |||
523 | uint32 *source_bits = (uint32*)tall_copy_of_the_preview_bitmap->Bits(); | |||
524 | uint32 *target_bits = (uint32*)preview_bitmap->Bits(); | |||
525 | int32 source_bpr = tall_copy_of_the_preview_bitmap->BytesPerRow()/4; | |||
526 | int32 target_bpr = preview_bitmap->BytesPerRow()/4; | |||
527 | ||||
528 | for (int32 y=0;y<preview_bitmap->Bounds().Height()+1;y++) { | |||
529 | for (int32 x=0;x<target_bpr;x++) { | |||
530 | *(target_bits + x + y*target_bpr) = *(source_bits + x + (y+MAX_BLUR_AMOUNT30)*source_bpr); | |||
531 | } | |||
532 | } | |||
533 | } | |||
534 | } | |||
535 | ||||
536 | ManipulatorSettings* BlurManipulator::ReturnSettings() | |||
537 | { | |||
538 | return new BlurManipulatorSettings(&settings); | |||
539 | } | |||
540 | ||||
541 | const char* BlurManipulator::ReturnHelpString() | |||
542 | { | |||
543 | return B_TRANSLATE("Adds a blur.")BLocaleRoster::Default()->GetCatalog()->GetString(("Adds a blur." ), "AddOns_Blur"); | |||
544 | } | |||
545 | ||||
546 | ||||
547 | const char* BlurManipulator::ReturnName() | |||
548 | { | |||
549 | return B_TRANSLATE("Blur")BLocaleRoster::Default()->GetCatalog()->GetString(("Blur" ), "AddOns_Blur"); | |||
550 | } | |||
551 | ||||
552 | ||||
553 | void BlurManipulator::ChangeSettings(ManipulatorSettings *set) | |||
554 | { | |||
555 | BlurManipulatorSettings *new_settings = dynamic_cast<BlurManipulatorSettings*>(set); | |||
556 | ||||
557 | if (new_settings != NULL__null) { | |||
558 | settings = *new_settings; | |||
559 | } | |||
560 | } | |||
561 | ||||
562 | BView* BlurManipulator::MakeConfigurationView(const BMessenger& target) | |||
563 | { | |||
564 | config_view = new BlurManipulatorView(BRect(0,0,0,0),this,target); | |||
| ||||
565 | config_view->ChangeSettings(&settings); | |||
566 | return config_view; | |||
567 | } | |||
568 | ||||
569 | ||||
570 | ||||
571 | status_t BlurManipulator::ReadSettings(BNode *node) | |||
572 | { | |||
573 | if (node != NULL__null) { | |||
574 | int32 new_amount; | |||
575 | if (node->ReadAttr("blur_amount",B_INT32_TYPE,0,&new_amount,sizeof(int32)) == sizeof(int32)) { | |||
576 | settings.blur_amount = new_amount; | |||
577 | previous_settings.blur_amount = new_amount-1; | |||
578 | return B_OK((int)0); | |||
579 | } | |||
580 | else | |||
581 | return B_ERROR(-1); | |||
582 | } | |||
583 | else | |||
584 | return B_ERROR(-1); | |||
585 | } | |||
586 | ||||
587 | status_t BlurManipulator::WriteSettings(BNode *node) | |||
588 | { | |||
589 | if (node != NULL__null) { | |||
590 | if (node->WriteAttr("blur_amount",B_INT32_TYPE,0,&settings.blur_amount,sizeof(int32)) == sizeof(int32)) | |||
591 | return B_OK((int)0); | |||
592 | else | |||
593 | return B_ERROR(-1); | |||
594 | } | |||
595 | else | |||
596 | return B_ERROR(-1); | |||
597 | } | |||
598 | ||||
599 | //*************** | |||
600 | ||||
601 | ||||
602 | BlurManipulatorView::BlurManipulatorView(BRect rect,BlurManipulator *manip, | |||
603 | const BMessenger& t) | |||
604 | : WindowGUIManipulatorView() | |||
605 | { | |||
606 | manipulator = manip; | |||
607 | target = new BMessenger(t); | |||
608 | ||||
609 | blur_amount_slider = new BSlider("blur_amount_slider", | |||
610 | B_TRANSLATE("Blur amount:")BLocaleRoster::Default()->GetCatalog()->GetString(("Blur amount:" ), "AddOns_Blur"), new BMessage(BLUR_AMOUNT_CHANGED'Bamc'), 1, MAX_BLUR_AMOUNT30, | |||
611 | B_HORIZONTAL, B_TRIANGLE_THUMB); | |||
612 | blur_amount_slider->SetLimitLabels(B_TRANSLATE("Low")BLocaleRoster::Default()->GetCatalog()->GetString(("Low" ), "AddOns_Blur"), B_TRANSLATE("High")BLocaleRoster::Default()->GetCatalog()->GetString(("High" ), "AddOns_Blur")); | |||
613 | blur_amount_slider->SetHashMarks(B_HASH_MARKS_BOTTOM); | |||
614 | blur_amount_slider->SetHashMarkCount(11); | |||
615 | blur_amount_slider->SetModificationMessage(new BMessage(BLUR_AMOUNT_CHANGE_STARTED'Bacs')); | |||
616 | ||||
617 | // BRect frame_rect = blur_amount_slider->Frame(); | |||
618 | // frame_rect.bottom = frame_rect.top; | |||
619 | // transparency_checkbox = new BCheckBox(frame_rect,"transparency_checkbox","Blur Transparency",new BMessage(BLUR_TRANSPARENCY_CHANGED)); | |||
620 | ||||
621 | BLayoutBuilder::Group<>(this, B_VERTICAL) | |||
622 | .Add(blur_amount_slider) | |||
623 | .SetInsets(B_USE_SMALL_INSETS) | |||
624 | .End(); | |||
625 | ||||
626 | preview_started = FALSE0; | |||
627 | } | |||
628 | ||||
629 | BlurManipulatorView::~BlurManipulatorView() | |||
630 | { | |||
631 | delete target; | |||
632 | } | |||
633 | ||||
634 | ||||
635 | void BlurManipulatorView::AttachedToWindow() | |||
636 | { | |||
637 | WindowGUIManipulatorView::AttachedToWindow(); | |||
638 | blur_amount_slider->SetTarget(BMessenger(this)); | |||
639 | // transparency_checkbox->SetTarget(this); | |||
640 | } | |||
641 | ||||
642 | ||||
643 | void BlurManipulatorView::MessageReceived(BMessage *message) | |||
644 | { | |||
645 | switch (message->what) { | |||
646 | case BLUR_AMOUNT_CHANGE_STARTED'Bacs': | |||
647 | if (preview_started == FALSE0) { | |||
648 | preview_started = TRUE1; | |||
649 | target->SendMessage(HS_MANIPULATOR_ADJUSTING_STARTED'Mast'); | |||
650 | } | |||
651 | settings.blur_amount = blur_amount_slider->Value(); | |||
652 | manipulator->ChangeSettings(&settings); | |||
653 | break; | |||
654 | ||||
655 | case BLUR_AMOUNT_CHANGED'Bamc': | |||
656 | settings.blur_amount = blur_amount_slider->Value(); | |||
657 | manipulator->ChangeSettings(&settings); | |||
658 | preview_started = FALSE0; | |||
659 | target->SendMessage(HS_MANIPULATOR_ADJUSTING_FINISHED'Mafi'); | |||
660 | break; | |||
661 | ||||
662 | // case BLUR_TRANSPARENCY_CHANGED: | |||
663 | // settings.blur_alpha = (transparency_checkbox->Value() == B_CONTROL_ON); | |||
664 | // manipulator->ChangeSettings(&settings); | |||
665 | // break; | |||
666 | ||||
667 | default: | |||
668 | WindowGUIManipulatorView::MessageReceived(message); | |||
669 | break; | |||
670 | } | |||
671 | } | |||
672 | ||||
673 | ||||
674 | void BlurManipulatorView::ChangeSettings(BlurManipulatorSettings *s) | |||
675 | { | |||
676 | settings = *s; | |||
677 | ||||
678 | BWindow *window = Window(); | |||
679 | ||||
680 | if (window != NULL__null) | |||
681 | window->Lock(); | |||
682 | ||||
683 | blur_amount_slider->SetValue(settings.blur_amount); | |||
684 | ||||
685 | if (window != NULL__null) | |||
686 | window->Unlock(); | |||
687 | ||||
688 | } |
1 | /* | |||
2 | * Copyright 2009-2015, Haiku, Inc. All rights reserved. | |||
3 | * Distributed under the terms of the MIT License. | |||
4 | */ | |||
5 | #ifndef _LAYOUT_BUILDER_H | |||
6 | #define _LAYOUT_BUILDER_H | |||
7 | ||||
8 | ||||
9 | #include <new> | |||
10 | ||||
11 | #include <CardLayout.h> | |||
12 | #include <CardView.h> | |||
13 | #include <GridLayout.h> | |||
14 | #include <GridView.h> | |||
15 | #include <GroupLayout.h> | |||
16 | #include <GroupView.h> | |||
17 | #include <Menu.h> | |||
18 | #include <MenuField.h> | |||
19 | #include <MenuItem.h> | |||
20 | #include <SpaceLayoutItem.h> | |||
21 | #include <SplitView.h> | |||
22 | #include <TextControl.h> | |||
23 | #include <Window.h> | |||
24 | ||||
25 | ||||
26 | namespace BLayoutBuilder { | |||
27 | ||||
28 | template<typename ParentBuilder> class Base; | |||
29 | template<typename ParentBuilder = void*> class Group; | |||
30 | template<typename ParentBuilder = void*> class Grid; | |||
31 | template<typename ParentBuilder = void*> class Split; | |||
32 | template<typename ParentBuilder = void*> class Cards; | |||
33 | template<typename ParentBuilder = void*> class Menu; | |||
34 | template<typename ParentBuilder = void*> class MenuItem; | |||
35 | ||||
36 | ||||
37 | template<typename ParentBuilder> | |||
38 | class Base { | |||
39 | protected: | |||
40 | inline Base(); | |||
41 | ||||
42 | public: | |||
43 | inline void SetParent(ParentBuilder* parent); | |||
44 | // conceptually private | |||
45 | inline ParentBuilder& End(); | |||
46 | ||||
47 | protected: | |||
48 | ParentBuilder* fParent; | |||
49 | }; | |||
50 | ||||
51 | ||||
52 | template<typename ParentBuilder> | |||
53 | class Group : public Base<ParentBuilder> { | |||
54 | public: | |||
55 | typedef Group<ParentBuilder> ThisBuilder; | |||
56 | typedef Group<ThisBuilder> GroupBuilder; | |||
57 | typedef Grid<ThisBuilder> GridBuilder; | |||
58 | typedef Split<ThisBuilder> SplitBuilder; | |||
59 | typedef Cards<ThisBuilder> CardBuilder; | |||
60 | ||||
61 | public: | |||
62 | inline Group(orientation orientation = B_HORIZONTAL, | |||
63 | float spacing = B_USE_DEFAULT_SPACING); | |||
64 | inline Group(BWindow* window, | |||
65 | orientation orientation = B_HORIZONTAL, | |||
66 | float spacing = B_USE_DEFAULT_SPACING); | |||
67 | inline Group(BView* view, | |||
68 | orientation orientation = B_HORIZONTAL, | |||
69 | float spacing = B_USE_DEFAULT_SPACING); | |||
70 | inline Group(BGroupLayout* layout); | |||
71 | inline Group(BGroupView* view); | |||
72 | ||||
73 | inline BGroupLayout* Layout() const; | |||
74 | inline BView* View() const; | |||
75 | inline ThisBuilder& GetLayout(BGroupLayout** _layout); | |||
76 | inline ThisBuilder& GetView(BView** _view); | |||
77 | ||||
78 | inline ThisBuilder& Add(BView* view); | |||
79 | inline ThisBuilder& Add(BView* view, float weight); | |||
80 | inline ThisBuilder& Add(BLayoutItem* item); | |||
81 | inline ThisBuilder& Add(BLayoutItem* item, float weight); | |||
82 | ||||
83 | inline GroupBuilder AddGroup(orientation orientation, | |||
84 | float spacing = B_USE_DEFAULT_SPACING, | |||
85 | float weight = 1.0f); | |||
86 | inline GroupBuilder AddGroup(BGroupView* groupView, | |||
87 | float weight = 1.0f); | |||
88 | inline GroupBuilder AddGroup(BGroupLayout* groupLayout, | |||
89 | float weight = 1.0f); | |||
90 | ||||
91 | inline GridBuilder AddGrid(float horizontal | |||
92 | = B_USE_DEFAULT_SPACING, | |||
93 | float vertical = B_USE_DEFAULT_SPACING, | |||
94 | float weight = 1.0f); | |||
95 | inline GridBuilder AddGrid(BGridLayout* gridLayout, | |||
96 | float weight = 1.0f); | |||
97 | inline GridBuilder AddGrid(BGridView* gridView, | |||
98 | float weight = 1.0f); | |||
99 | ||||
100 | inline SplitBuilder AddSplit(orientation orientation, | |||
101 | float spacing = B_USE_DEFAULT_SPACING, | |||
102 | float weight = 1.0f); | |||
103 | inline SplitBuilder AddSplit(BSplitView* splitView, | |||
104 | float weight = 1.0f); | |||
105 | ||||
106 | inline CardBuilder AddCards(float weight = 1.0f); | |||
107 | inline CardBuilder AddCards(BCardLayout* cardLayout, | |||
108 | float weight = 1.0f); | |||
109 | inline CardBuilder AddCards(BCardView* cardView, | |||
110 | float weight = 1.0f); | |||
111 | ||||
112 | inline ThisBuilder& AddGlue(float weight = 1.0f); | |||
113 | inline ThisBuilder& AddStrut(float size); | |||
114 | ||||
115 | inline ThisBuilder& SetInsets(float left, float top, float right, | |||
116 | float bottom); | |||
117 | inline ThisBuilder& SetInsets(float horizontal, float vertical); | |||
118 | inline ThisBuilder& SetInsets(float insets); | |||
119 | ||||
120 | inline ThisBuilder& SetExplicitMinSize(BSize size); | |||
121 | inline ThisBuilder& SetExplicitMaxSize(BSize size); | |||
122 | inline ThisBuilder& SetExplicitPreferredSize(BSize size); | |||
123 | inline ThisBuilder& SetExplicitAlignment(BAlignment alignment); | |||
124 | ||||
125 | inline operator BGroupLayout*(); | |||
126 | ||||
127 | private: | |||
128 | BGroupLayout* fLayout; | |||
129 | }; | |||
130 | ||||
131 | ||||
132 | template<typename ParentBuilder> | |||
133 | class Grid : public Base<ParentBuilder> { | |||
134 | public: | |||
135 | typedef Grid<ParentBuilder> ThisBuilder; | |||
136 | typedef Group<ThisBuilder> GroupBuilder; | |||
137 | typedef Grid<ThisBuilder> GridBuilder; | |||
138 | typedef Split<ThisBuilder> SplitBuilder; | |||
139 | typedef Cards<ThisBuilder> CardBuilder; | |||
140 | ||||
141 | public: | |||
142 | inline Grid(float horizontal | |||
143 | = B_USE_DEFAULT_SPACING, | |||
144 | float vertical = B_USE_DEFAULT_SPACING); | |||
145 | inline Grid(BWindow* window, | |||
146 | float horizontal = B_USE_DEFAULT_SPACING, | |||
147 | float vertical = B_USE_DEFAULT_SPACING); | |||
148 | inline Grid(BView* view, | |||
149 | float horizontal = B_USE_DEFAULT_SPACING, | |||
150 | float vertical = B_USE_DEFAULT_SPACING); | |||
151 | inline Grid(BGridLayout* layout); | |||
152 | inline Grid(BGridView* view); | |||
153 | ||||
154 | inline BGridLayout* Layout() const; | |||
155 | inline BView* View() const; | |||
156 | inline ThisBuilder& GetLayout(BGridLayout** _layout); | |||
157 | inline ThisBuilder& GetView(BView** _view); | |||
158 | ||||
159 | inline ThisBuilder& Add(BView* view, int32 column, int32 row, | |||
160 | int32 columnCount = 1, int32 rowCount = 1); | |||
161 | inline ThisBuilder& Add(BLayoutItem* item, int32 column, int32 row, | |||
162 | int32 columnCount = 1, int32 rowCount = 1); | |||
163 | inline ThisBuilder& AddMenuField(BMenuField* menuField, | |||
164 | int32 column, int32 row, | |||
165 | alignment labelAlignment | |||
166 | = B_ALIGN_HORIZONTAL_UNSET, | |||
167 | int32 labelColumnCount = 1, | |||
168 | int32 fieldColumnCount = 1, | |||
169 | int32 rowCount = 1); | |||
170 | inline ThisBuilder& AddTextControl(BTextControl* textControl, | |||
171 | int32 column, int32 row, | |||
172 | alignment labelAlignment | |||
173 | = B_ALIGN_HORIZONTAL_UNSET, | |||
174 | int32 labelColumnCount = 1, | |||
175 | int32 textColumnCount = 1, | |||
176 | int32 rowCount = 1); | |||
177 | ||||
178 | inline GroupBuilder AddGroup(orientation orientation, | |||
179 | float spacing, int32 column, int32 row, | |||
180 | int32 columnCount = 1, int32 rowCount = 1); | |||
181 | inline GroupBuilder AddGroup(BGroupView* groupView, int32 column, | |||
182 | int32 row, int32 columnCount = 1, | |||
183 | int32 rowCount = 1); | |||
184 | inline GroupBuilder AddGroup(BGroupLayout* groupLayout, | |||
185 | int32 column, int32 row, | |||
186 | int32 columnCount = 1, int32 rowCount = 1); | |||
187 | ||||
188 | inline GridBuilder AddGrid(float horizontalSpacing, | |||
189 | float verticalSpacing, int32 column, | |||
190 | int32 row, int32 columnCount = 1, | |||
191 | int32 rowCount = 1); | |||
192 | inline GridBuilder AddGrid(BGridLayout* gridLayout, | |||
193 | int32 column, int32 row, | |||
194 | int32 columnCount = 1, int32 rowCount = 1); | |||
195 | inline GridBuilder AddGrid(BGridView* gridView, | |||
196 | int32 column, int32 row, | |||
197 | int32 columnCount = 1, int32 rowCount = 1); | |||
198 | ||||
199 | inline SplitBuilder AddSplit(orientation orientation, | |||
200 | float spacing, int32 column, int32 row, | |||
201 | int32 columnCount = 1, int32 rowCount = 1); | |||
202 | inline SplitBuilder AddSplit(BSplitView* splitView, int32 column, | |||
203 | int32 row, int32 columnCount = 1, | |||
204 | int32 rowCount = 1); | |||
205 | ||||
206 | inline CardBuilder AddCards(int32 column, int32 row, | |||
207 | int32 columnCount = 1, int32 rowCount = 1); | |||
208 | inline CardBuilder AddCards(BCardLayout* cardLayout, int32 column, | |||
209 | int32 row, int32 columnCount = 1, | |||
210 | int32 rowCount = 1); | |||
211 | inline CardBuilder AddCards(BCardView* cardView, int32 column, | |||
212 | int32 row, int32 columnCount = 1, | |||
213 | int32 rowCount = 1); | |||
214 | ||||
215 | inline ThisBuilder& AddGlue(int32 column, int32 row, | |||
216 | int32 columnCount = 1, int32 rowCount = 1); | |||
217 | ||||
218 | inline ThisBuilder& SetHorizontalSpacing(float spacing); | |||
219 | inline ThisBuilder& SetVerticalSpacing(float spacing); | |||
220 | inline ThisBuilder& SetSpacing(float horizontal, float vertical); | |||
221 | ||||
222 | inline ThisBuilder& SetColumnWeight(int32 column, float weight); | |||
223 | inline ThisBuilder& SetRowWeight(int32 row, float weight); | |||
224 | ||||
225 | inline ThisBuilder& SetInsets(float left, float top, float right, | |||
226 | float bottom); | |||
227 | inline ThisBuilder& SetInsets(float horizontal, float vertical); | |||
228 | inline ThisBuilder& SetInsets(float insets); | |||
229 | ||||
230 | inline ThisBuilder& SetExplicitMinSize(BSize size); | |||
231 | inline ThisBuilder& SetExplicitMaxSize(BSize size); | |||
232 | inline ThisBuilder& SetExplicitPreferredSize(BSize size); | |||
233 | inline ThisBuilder& SetExplicitAlignment(BAlignment alignment); | |||
234 | ||||
235 | inline operator BGridLayout*(); | |||
236 | ||||
237 | private: | |||
238 | BGridLayout* fLayout; | |||
239 | }; | |||
240 | ||||
241 | ||||
242 | template<typename ParentBuilder> | |||
243 | class Split : public Base<ParentBuilder> { | |||
244 | public: | |||
245 | typedef Split<ParentBuilder> ThisBuilder; | |||
246 | typedef Group<ThisBuilder> GroupBuilder; | |||
247 | typedef Grid<ThisBuilder> GridBuilder; | |||
248 | typedef Split<ThisBuilder> SplitBuilder; | |||
249 | typedef Cards<ThisBuilder> CardBuilder; | |||
250 | ||||
251 | public: | |||
252 | inline Split(orientation orientation = B_HORIZONTAL, | |||
253 | float spacing = B_USE_DEFAULT_SPACING); | |||
254 | inline Split(BSplitView* view); | |||
255 | ||||
256 | inline BSplitView* View() const; | |||
257 | inline ThisBuilder& GetView(BView** _view); | |||
258 | inline ThisBuilder& GetSplitView(BSplitView** _view); | |||
259 | ||||
260 | inline ThisBuilder& Add(BView* view); | |||
261 | inline ThisBuilder& Add(BView* view, float weight); | |||
262 | inline ThisBuilder& Add(BLayoutItem* item); | |||
263 | inline ThisBuilder& Add(BLayoutItem* item, float weight); | |||
264 | ||||
265 | inline GroupBuilder AddGroup(orientation orientation, | |||
266 | float spacing = B_USE_DEFAULT_SPACING, | |||
267 | float weight = 1.0f); | |||
268 | inline GroupBuilder AddGroup(BGroupView* groupView, | |||
269 | float weight = 1.0f); | |||
270 | inline GroupBuilder AddGroup(BGroupLayout* groupLayout, | |||
271 | float weight = 1.0f); | |||
272 | ||||
273 | inline GridBuilder AddGrid(float horizontal | |||
274 | = B_USE_DEFAULT_SPACING, | |||
275 | float vertical = B_USE_DEFAULT_SPACING, | |||
276 | float weight = 1.0f); | |||
277 | inline GridBuilder AddGrid(BGridView* gridView, | |||
278 | float weight = 1.0f); | |||
279 | inline GridBuilder AddGrid(BGridLayout* gridLayout, | |||
280 | float weight = 1.0f); | |||
281 | ||||
282 | inline SplitBuilder AddSplit(orientation orientation, | |||
283 | float spacing = B_USE_DEFAULT_SPACING, | |||
284 | float weight = 1.0f); | |||
285 | inline SplitBuilder AddSplit(BSplitView* splitView, | |||
286 | float weight = 1.0f); | |||
287 | ||||
288 | inline CardBuilder AddCards(float weight = 1.0f); | |||
289 | inline CardBuilder AddCards(BCardLayout* cardLayout, | |||
290 | float weight = 1.0f); | |||
291 | inline CardBuilder AddCards(BCardView* cardView, | |||
292 | float weight = 1.0f); | |||
293 | ||||
294 | inline ThisBuilder& SetCollapsible(bool collapsible); | |||
295 | inline ThisBuilder& SetCollapsible(int32 index, bool collapsible); | |||
296 | inline ThisBuilder& SetCollapsible(int32 first, int32 last, | |||
297 | bool collapsible); | |||
298 | ||||
299 | inline ThisBuilder& SetInsets(float left, float top, float right, | |||
300 | float bottom); | |||
301 | inline ThisBuilder& SetInsets(float horizontal, float vertical); | |||
302 | inline ThisBuilder& SetInsets(float insets); | |||
303 | ||||
304 | inline operator BSplitView*(); | |||
305 | ||||
306 | private: | |||
307 | BSplitView* fView; | |||
308 | }; | |||
309 | ||||
310 | template<typename ParentBuilder> | |||
311 | class Cards : public Base<ParentBuilder> { | |||
312 | public: | |||
313 | typedef Cards<ParentBuilder> ThisBuilder; | |||
314 | typedef Group<ThisBuilder> GroupBuilder; | |||
315 | typedef Grid<ThisBuilder> GridBuilder; | |||
316 | typedef Split<ThisBuilder> SplitBuilder; | |||
317 | typedef Cards<ThisBuilder> CardBuilder; | |||
318 | ||||
319 | public: | |||
320 | inline Cards(); | |||
321 | inline Cards(BWindow* window); | |||
322 | inline Cards(BView* view); | |||
323 | inline Cards(BCardLayout* layout); | |||
324 | inline Cards(BCardView* view); | |||
325 | ||||
326 | inline BCardLayout* Layout() const; | |||
327 | inline BView* View() const; | |||
328 | inline ThisBuilder& GetLayout(BCardLayout** _layout); | |||
329 | inline ThisBuilder& GetView(BView** _view); | |||
330 | ||||
331 | inline ThisBuilder& Add(BView* view); | |||
332 | inline ThisBuilder& Add(BLayoutItem* item); | |||
333 | ||||
334 | inline GroupBuilder AddGroup(orientation orientation, | |||
335 | float spacing = B_USE_DEFAULT_SPACING); | |||
336 | inline GroupBuilder AddGroup(BGroupView* groupView); | |||
337 | inline GroupBuilder AddGroup(BGroupLayout* groupLayout); | |||
338 | ||||
339 | inline GridBuilder AddGrid(float horizontal | |||
340 | = B_USE_DEFAULT_SPACING, | |||
341 | float vertical = B_USE_DEFAULT_SPACING); | |||
342 | inline GridBuilder AddGrid(BGridLayout* gridLayout); | |||
343 | inline GridBuilder AddGrid(BGridView* gridView); | |||
344 | ||||
345 | inline SplitBuilder AddSplit(orientation orientation, | |||
346 | float spacing = B_USE_DEFAULT_SPACING); | |||
347 | inline SplitBuilder AddSplit(BSplitView* splitView); | |||
348 | ||||
349 | inline CardBuilder AddCards(); | |||
350 | inline CardBuilder AddCards(BCardLayout* cardLayout); | |||
351 | inline CardBuilder AddCards(BCardView* cardView); | |||
352 | ||||
353 | inline ThisBuilder& SetExplicitMinSize(BSize size); | |||
354 | inline ThisBuilder& SetExplicitMaxSize(BSize size); | |||
355 | inline ThisBuilder& SetExplicitPreferredSize(BSize size); | |||
356 | inline ThisBuilder& SetExplicitAlignment(BAlignment alignment); | |||
357 | ||||
358 | inline ThisBuilder& SetVisibleItem(int32 index); | |||
359 | ||||
360 | inline operator BCardLayout*(); | |||
361 | ||||
362 | private: | |||
363 | BCardLayout* fLayout; | |||
364 | }; | |||
365 | ||||
366 | ||||
367 | template<typename ParentBuilder> | |||
368 | class Menu : public Base<ParentBuilder> { | |||
369 | public: | |||
370 | typedef Menu<ParentBuilder> ThisBuilder; | |||
371 | typedef MenuItem<ParentBuilder> ItemBuilder; | |||
372 | typedef Menu<ThisBuilder> MenuBuilder; | |||
373 | ||||
374 | public: | |||
375 | inline Menu(BMenu* menu); | |||
376 | ||||
377 | inline ThisBuilder& GetMenu(BMenu*& _menu); | |||
378 | ||||
379 | inline ItemBuilder AddItem(BMenuItem* item); | |||
380 | inline ItemBuilder AddItem(BMenu* menu); | |||
381 | inline ItemBuilder AddItem(const char* label, BMessage* message, | |||
382 | char shortcut = 0, uint32 modifiers = 0); | |||
383 | inline ItemBuilder AddItem(const char* label, uint32 messageWhat, | |||
384 | char shortcut = 0, uint32 modifiers = 0); | |||
385 | ||||
386 | inline MenuBuilder AddMenu(BMenu* menu); | |||
387 | inline MenuBuilder AddMenu(const char* title, | |||
388 | menu_layout layout = B_ITEMS_IN_COLUMN); | |||
389 | ||||
390 | inline ThisBuilder& AddSeparator(); | |||
391 | ||||
392 | private: | |||
393 | BMenu* fMenu; | |||
394 | }; | |||
395 | ||||
396 | ||||
397 | template<typename ParentBuilder> | |||
398 | class MenuItem : public Menu<ParentBuilder> { | |||
399 | public: | |||
400 | typedef MenuItem<ParentBuilder> ThisBuilder; | |||
401 | ||||
402 | public: | |||
403 | inline MenuItem(ParentBuilder* parentBuilder, | |||
404 | BMenu* menu, BMenuItem* item); | |||
405 | ||||
406 | inline ThisBuilder& GetItem(BMenuItem*& _item); | |||
407 | ||||
408 | inline ThisBuilder& SetEnabled(bool enabled); | |||
409 | ||||
410 | private: | |||
411 | BMenuItem* fMenuItem; | |||
412 | }; | |||
413 | ||||
414 | ||||
415 | // #pragma mark - Base | |||
416 | ||||
417 | ||||
418 | template<typename ParentBuilder> | |||
419 | Base<ParentBuilder>::Base() | |||
420 | : | |||
421 | fParent(NULL__null) | |||
422 | { | |||
423 | } | |||
424 | ||||
425 | ||||
426 | template<typename ParentBuilder> | |||
427 | void | |||
428 | Base<ParentBuilder>::SetParent(ParentBuilder* parent) | |||
429 | { | |||
430 | fParent = parent; | |||
431 | } | |||
432 | ||||
433 | ||||
434 | template<typename ParentBuilder> | |||
435 | ParentBuilder& | |||
436 | Base<ParentBuilder>::End() | |||
437 | { | |||
438 | return *fParent; | |||
| ||||
439 | } | |||
440 | ||||
441 | ||||
442 | // #pragma mark - Group | |||
443 | ||||
444 | ||||
445 | template<typename ParentBuilder> | |||
446 | Group<ParentBuilder>::Group(orientation orientation, float spacing) | |||
447 | : | |||
448 | fLayout((new BGroupView(orientation, spacing))->GroupLayout()) | |||
449 | { | |||
450 | } | |||
451 | ||||
452 | ||||
453 | template<typename ParentBuilder> | |||
454 | Group<ParentBuilder>::Group(BWindow* window, orientation orientation, | |||
455 | float spacing) | |||
456 | : | |||
457 | fLayout(new BGroupLayout(orientation, spacing)) | |||
458 | { | |||
459 | window->SetLayout(fLayout); | |||
460 | fLayout->Owner()->AdoptSystemColors(); | |||
461 | } | |||
462 | ||||
463 | ||||
464 | template<typename ParentBuilder> | |||
465 | Group<ParentBuilder>::Group(BView* view, orientation orientation, | |||
466 | float spacing) | |||
467 | : | |||
468 | fLayout(new BGroupLayout(orientation, spacing)) | |||
469 | { | |||
470 | ||||
471 | if (view->HasDefaultColors()) | |||
472 | view->AdoptSystemColors(); | |||
473 | ||||
474 | view->SetLayout(fLayout); | |||
475 | } | |||
476 | ||||
477 | ||||
478 | template<typename ParentBuilder> | |||
479 | Group<ParentBuilder>::Group(BGroupLayout* layout) | |||
480 | : | |||
481 | fLayout(layout) | |||
482 | { | |||
483 | } | |||
484 | ||||
485 | ||||
486 | template<typename ParentBuilder> | |||
487 | Group<ParentBuilder>::Group(BGroupView* view) | |||
488 | : | |||
489 | fLayout(view->GroupLayout()) | |||
490 | { | |||
491 | } | |||
492 | ||||
493 | ||||
494 | template<typename ParentBuilder> | |||
495 | BGroupLayout* | |||
496 | Group<ParentBuilder>::Layout() const | |||
497 | { | |||
498 | return fLayout; | |||
499 | } | |||
500 | ||||
501 | ||||
502 | template<typename ParentBuilder> | |||
503 | BView* | |||
504 | Group<ParentBuilder>::View() const | |||
505 | { | |||
506 | return fLayout->Owner(); | |||
507 | } | |||
508 | ||||
509 | ||||
510 | template<typename ParentBuilder> | |||
511 | typename Group<ParentBuilder>::ThisBuilder& | |||
512 | Group<ParentBuilder>::GetLayout(BGroupLayout** _layout) | |||
513 | { | |||
514 | *_layout = fLayout; | |||
515 | return *this; | |||
516 | } | |||
517 | ||||
518 | ||||
519 | template<typename ParentBuilder> | |||
520 | typename Group<ParentBuilder>::ThisBuilder& | |||
521 | Group<ParentBuilder>::GetView(BView** _view) | |||
522 | { | |||
523 | *_view = fLayout->Owner(); | |||
524 | return *this; | |||
525 | } | |||
526 | ||||
527 | ||||
528 | template<typename ParentBuilder> | |||
529 | typename Group<ParentBuilder>::ThisBuilder& | |||
530 | Group<ParentBuilder>::Add(BView* view) | |||
531 | { | |||
532 | fLayout->AddView(view); | |||
533 | return *this; | |||
534 | } | |||
535 | ||||
536 | ||||
537 | template<typename ParentBuilder> | |||
538 | typename Group<ParentBuilder>::ThisBuilder& | |||
539 | Group<ParentBuilder>::Add(BView* view, float weight) | |||
540 | { | |||
541 | fLayout->AddView(view, weight); | |||
542 | return *this; | |||
543 | } | |||
544 | ||||
545 | ||||
546 | template<typename ParentBuilder> | |||
547 | typename Group<ParentBuilder>::ThisBuilder& | |||
548 | Group<ParentBuilder>::Add(BLayoutItem* item) | |||
549 | { | |||
550 | fLayout->AddItem(item); | |||
551 | return *this; | |||
552 | } | |||
553 | ||||
554 | ||||
555 | template<typename ParentBuilder> | |||
556 | typename Group<ParentBuilder>::ThisBuilder& | |||
557 | Group<ParentBuilder>::Add(BLayoutItem* item, float weight) | |||
558 | { | |||
559 | fLayout->AddItem(item, weight); | |||
560 | return *this; | |||
561 | } | |||
562 | ||||
563 | ||||
564 | template<typename ParentBuilder> | |||
565 | typename Group<ParentBuilder>::GroupBuilder | |||
566 | Group<ParentBuilder>::AddGroup(orientation orientation, float spacing, | |||
567 | float weight) | |||
568 | { | |||
569 | GroupBuilder builder(new BGroupLayout(orientation, spacing)); | |||
570 | builder.SetParent(this); | |||
571 | fLayout->AddItem(builder.Layout(), weight); | |||
572 | return builder; | |||
573 | } | |||
574 | ||||
575 | ||||
576 | template<typename ParentBuilder> | |||
577 | typename Group<ParentBuilder>::GroupBuilder | |||
578 | Group<ParentBuilder>::AddGroup(BGroupView* groupView, float weight) | |||
579 | { | |||
580 | GroupBuilder builder(groupView); | |||
581 | builder.SetParent(this); | |||
582 | fLayout->AddItem(builder.Layout(), weight); | |||
583 | return builder; | |||
584 | } | |||
585 | ||||
586 | ||||
587 | template<typename ParentBuilder> | |||
588 | typename Group<ParentBuilder>::GroupBuilder | |||
589 | Group<ParentBuilder>::AddGroup(BGroupLayout* groupLayout, float weight) | |||
590 | { | |||
591 | GroupBuilder builder(groupLayout); | |||
592 | builder.SetParent(this); | |||
593 | fLayout->AddItem(builder.Layout(), weight); | |||
594 | return builder; | |||
595 | } | |||
596 | ||||
597 | ||||
598 | template<typename ParentBuilder> | |||
599 | typename Group<ParentBuilder>::GridBuilder | |||
600 | Group<ParentBuilder>::AddGrid(float horizontalSpacing, | |||
601 | float verticalSpacing, float weight) | |||
602 | { | |||
603 | GridBuilder builder(new BGridLayout(horizontalSpacing, verticalSpacing)); | |||
604 | builder.SetParent(this); | |||
605 | fLayout->AddItem(builder.Layout(), weight); | |||
606 | return builder; | |||
607 | } | |||
608 | ||||
609 | ||||
610 | template<typename ParentBuilder> | |||
611 | typename Group<ParentBuilder>::GridBuilder | |||
612 | Group<ParentBuilder>::AddGrid(BGridLayout* gridLayout, float weight) | |||
613 | { | |||
614 | GridBuilder builder(gridLayout); | |||
615 | builder.SetParent(this); | |||
616 | fLayout->AddItem(builder.Layout(), weight); | |||
617 | return builder; | |||
618 | } | |||
619 | ||||
620 | ||||
621 | template<typename ParentBuilder> | |||
622 | typename Group<ParentBuilder>::GridBuilder | |||
623 | Group<ParentBuilder>::AddGrid(BGridView* gridView, float weight) | |||
624 | { | |||
625 | GridBuilder builder(gridView); | |||
626 | builder.SetParent(this); | |||
627 | fLayout->AddItem(builder.Layout(), weight); | |||
628 | return builder; | |||
629 | } | |||
630 | ||||
631 | ||||
632 | template<typename ParentBuilder> | |||
633 | typename Group<ParentBuilder>::SplitBuilder | |||
634 | Group<ParentBuilder>::AddSplit(orientation orientation, float spacing, | |||
635 | float weight) | |||
636 | { | |||
637 | SplitBuilder builder(orientation, spacing); | |||
638 | builder.SetParent(this); | |||
639 | fLayout->AddView(builder.View(), weight); | |||
640 | return builder; | |||
641 | } | |||
642 | ||||
643 | ||||
644 | template<typename ParentBuilder> | |||
645 | typename Group<ParentBuilder>::SplitBuilder | |||
646 | Group<ParentBuilder>::AddSplit(BSplitView* splitView, float weight) | |||
647 | { | |||
648 | SplitBuilder builder(splitView); | |||
649 | builder.SetParent(this); | |||
650 | fLayout->AddView(builder.View(), weight); | |||
651 | return builder; | |||
652 | } | |||
653 | ||||
654 | ||||
655 | template<typename ParentBuilder> | |||
656 | typename Group<ParentBuilder>::CardBuilder | |||
657 | Group<ParentBuilder>::AddCards(float weight) | |||
658 | { | |||
659 | CardBuilder builder; | |||
660 | builder.SetParent(this); | |||
661 | fLayout->AddView(builder.View(), weight); | |||
662 | return builder; | |||
663 | } | |||
664 | ||||
665 | ||||
666 | template<typename ParentBuilder> | |||
667 | typename Group<ParentBuilder>::CardBuilder | |||
668 | Group<ParentBuilder>::AddCards(BCardLayout* cardLayout, float weight) | |||
669 | { | |||
670 | CardBuilder builder(cardLayout); | |||
671 | builder.SetParent(this); | |||
672 | fLayout->AddView(builder.View(), weight); | |||
673 | return builder; | |||
674 | } | |||
675 | ||||
676 | ||||
677 | template<typename ParentBuilder> | |||
678 | typename Group<ParentBuilder>::CardBuilder | |||
679 | Group<ParentBuilder>::AddCards(BCardView* cardView, float weight) | |||
680 | { | |||
681 | CardBuilder builder(cardView); | |||
682 | builder.SetParent(this); | |||
683 | fLayout->AddView(builder.View(), weight); | |||
684 | return builder; | |||
685 | } | |||
686 | ||||
687 | ||||
688 | template<typename ParentBuilder> | |||
689 | typename Group<ParentBuilder>::ThisBuilder& | |||
690 | Group<ParentBuilder>::AddGlue(float weight) | |||
691 | { | |||
692 | fLayout->AddItem(BSpaceLayoutItem::CreateGlue(), weight); | |||
693 | return *this; | |||
694 | } | |||
695 | ||||
696 | ||||
697 | template<typename ParentBuilder> | |||
698 | typename Group<ParentBuilder>::ThisBuilder& | |||
699 | Group<ParentBuilder>::AddStrut(float size) | |||
700 | { | |||
701 | if (fLayout->Orientation() == B_HORIZONTAL) | |||
702 | fLayout->AddItem(BSpaceLayoutItem::CreateHorizontalStrut(size)); | |||
703 | else | |||
704 | fLayout->AddItem(BSpaceLayoutItem::CreateVerticalStrut(size)); | |||
705 | ||||
706 | return *this; | |||
707 | } | |||
708 | ||||
709 | ||||
710 | template<typename ParentBuilder> | |||
711 | typename Group<ParentBuilder>::ThisBuilder& | |||
712 | Group<ParentBuilder>::SetInsets(float left, float top, float right, | |||
713 | float bottom) | |||
714 | { | |||
715 | fLayout->SetInsets(left, top, right, bottom); | |||
716 | return *this; | |||
717 | } | |||
718 | ||||
719 | ||||
720 | template<typename ParentBuilder> | |||
721 | typename Group<ParentBuilder>::ThisBuilder& | |||
722 | Group<ParentBuilder>::SetInsets(float horizontal, float vertical) | |||
723 | { | |||
724 | fLayout->SetInsets(horizontal, vertical); | |||
725 | return *this; | |||
726 | } | |||
727 | ||||
728 | ||||
729 | template<typename ParentBuilder> | |||
730 | typename Group<ParentBuilder>::ThisBuilder& | |||
731 | Group<ParentBuilder>::SetInsets(float insets) | |||
732 | { | |||
733 | fLayout->SetInsets(insets); | |||
734 | return *this; | |||
735 | } | |||
736 | ||||
737 | ||||
738 | template<typename ParentBuilder> | |||
739 | typename Group<ParentBuilder>::ThisBuilder& | |||
740 | Group<ParentBuilder>::SetExplicitMinSize(BSize size) | |||
741 | { | |||
742 | fLayout->SetExplicitMinSize(size); | |||
743 | return *this; | |||
744 | } | |||
745 | ||||
746 | ||||
747 | template<typename ParentBuilder> | |||
748 | typename Group<ParentBuilder>::ThisBuilder& | |||
749 | Group<ParentBuilder>::SetExplicitMaxSize(BSize size) | |||
750 | { | |||
751 | fLayout->SetExplicitMaxSize(size); | |||
752 | return *this; | |||
753 | } | |||
754 | ||||
755 | ||||
756 | template<typename ParentBuilder> | |||
757 | typename Group<ParentBuilder>::ThisBuilder& | |||
758 | Group<ParentBuilder>::SetExplicitPreferredSize(BSize size) | |||
759 | { | |||
760 | fLayout->SetExplicitPreferredSize(size); | |||
761 | return *this; | |||
762 | } | |||
763 | ||||
764 | ||||
765 | template<typename ParentBuilder> | |||
766 | typename Group<ParentBuilder>::ThisBuilder& | |||
767 | Group<ParentBuilder>::SetExplicitAlignment(BAlignment alignment) | |||
768 | { | |||
769 | fLayout->SetExplicitAlignment(alignment); | |||
770 | return *this; | |||
771 | } | |||
772 | ||||
773 | ||||
774 | template<typename ParentBuilder> | |||
775 | Group<ParentBuilder>::operator BGroupLayout*() | |||
776 | { | |||
777 | return fLayout; | |||
778 | } | |||
779 | ||||
780 | ||||
781 | // #pragma mark - Grid | |||
782 | ||||
783 | ||||
784 | template<typename ParentBuilder> | |||
785 | Grid<ParentBuilder>::Grid(float horizontalSpacing, float verticalSpacing) | |||
786 | : | |||
787 | fLayout((new BGridView(horizontalSpacing, verticalSpacing))->GridLayout()) | |||
788 | { | |||
789 | } | |||
790 | ||||
791 | ||||
792 | template<typename ParentBuilder> | |||
793 | Grid<ParentBuilder>::Grid(BWindow* window, float horizontalSpacing, | |||
794 | float verticalSpacing) | |||
795 | : | |||
796 | fLayout(new BGridLayout(horizontalSpacing, verticalSpacing)) | |||
797 | { | |||
798 | window->SetLayout(fLayout); | |||
799 | fLayout->Owner()->AdoptSystemColors(); | |||
800 | } | |||
801 | ||||
802 | ||||
803 | template<typename ParentBuilder> | |||
804 | Grid<ParentBuilder>::Grid(BView* view, float horizontalSpacing, | |||
805 | float verticalSpacing) | |||
806 | : | |||
807 | fLayout(new BGridLayout(horizontalSpacing, verticalSpacing)) | |||
808 | { | |||
809 | if (view->HasDefaultColors()) | |||
810 | view->AdoptSystemColors(); | |||
811 | ||||
812 | view->SetLayout(fLayout); | |||
813 | } | |||
814 | ||||
815 | ||||
816 | template<typename ParentBuilder> | |||
817 | Grid<ParentBuilder>::Grid(BGridLayout* layout) | |||
818 | : | |||
819 | fLayout(layout) | |||
820 | { | |||
821 | } | |||
822 | ||||
823 | ||||
824 | template<typename ParentBuilder> | |||
825 | Grid<ParentBuilder>::Grid(BGridView* view) | |||
826 | : | |||
827 | fLayout(view->GridLayout()) | |||
828 | { | |||
829 | } | |||
830 | ||||
831 | ||||
832 | template<typename ParentBuilder> | |||
833 | BGridLayout* | |||
834 | Grid<ParentBuilder>::Layout() const | |||
835 | { | |||
836 | return fLayout; | |||
837 | } | |||
838 | ||||
839 | ||||
840 | template<typename ParentBuilder> | |||
841 | BView* | |||
842 | Grid<ParentBuilder>::View() const | |||
843 | { | |||
844 | return fLayout->Owner(); | |||
845 | } | |||
846 | ||||
847 | ||||
848 | template<typename ParentBuilder> | |||
849 | typename Grid<ParentBuilder>::ThisBuilder& | |||
850 | Grid<ParentBuilder>::GetLayout(BGridLayout** _layout) | |||
851 | { | |||
852 | *_layout = fLayout; | |||
853 | return *this; | |||
854 | } | |||
855 | ||||
856 | ||||
857 | template<typename ParentBuilder> | |||
858 | typename Grid<ParentBuilder>::ThisBuilder& | |||
859 | Grid<ParentBuilder>::GetView(BView** _view) | |||
860 | { | |||
861 | *_view = fLayout->Owner(); | |||
862 | return *this; | |||
863 | } | |||
864 | ||||
865 | ||||
866 | template<typename ParentBuilder> | |||
867 | typename Grid<ParentBuilder>::ThisBuilder& | |||
868 | Grid<ParentBuilder>::Add(BView* view, int32 column, int32 row, | |||
869 | int32 columnCount, int32 rowCount) | |||
870 | { | |||
871 | fLayout->AddView(view, column, row, columnCount, rowCount); | |||
872 | return *this; | |||
873 | } | |||
874 | ||||
875 | ||||
876 | template<typename ParentBuilder> | |||
877 | typename Grid<ParentBuilder>::ThisBuilder& | |||
878 | Grid<ParentBuilder>::Add(BLayoutItem* item, int32 column, int32 row, | |||
879 | int32 columnCount, int32 rowCount) | |||
880 | { | |||
881 | fLayout->AddItem(item, column, row, columnCount, rowCount); | |||
882 | return *this; | |||
883 | } | |||
884 | ||||
885 | ||||
886 | template<typename ParentBuilder> | |||
887 | typename Grid<ParentBuilder>::ThisBuilder& | |||
888 | Grid<ParentBuilder>::AddMenuField(BMenuField* menuField, int32 column, | |||
889 | int32 row, alignment labelAlignment, int32 labelColumnCount, | |||
890 | int32 fieldColumnCount, int32 rowCount) | |||
891 | { | |||
892 | BLayoutItem* item = menuField->CreateLabelLayoutItem(); | |||
893 | item->SetExplicitAlignment( | |||
894 | BAlignment(labelAlignment, B_ALIGN_VERTICAL_UNSET)); | |||
895 | fLayout->AddItem(item, column, row, labelColumnCount, rowCount); | |||
896 | fLayout->AddItem(menuField->CreateMenuBarLayoutItem(), | |||
897 | column + labelColumnCount, row, fieldColumnCount, rowCount); | |||
898 | return *this; | |||
899 | } | |||
900 | ||||
901 | ||||
902 | template<typename ParentBuilder> | |||
903 | typename Grid<ParentBuilder>::ThisBuilder& | |||
904 | Grid<ParentBuilder>::AddTextControl(BTextControl* textControl, int32 column, | |||
905 | int32 row, alignment labelAlignment, int32 labelColumnCount, | |||
906 | int32 textColumnCount, int32 rowCount) | |||
907 | { | |||
908 | BLayoutItem* item = textControl->CreateLabelLayoutItem(); | |||
909 | item->SetExplicitAlignment( | |||
910 | BAlignment(labelAlignment, B_ALIGN_VERTICAL_UNSET)); | |||
911 | fLayout->AddItem(item, column, row, labelColumnCount, rowCount); | |||
912 | fLayout->AddItem(textControl->CreateTextViewLayoutItem(), | |||
913 | column + labelColumnCount, row, textColumnCount, rowCount); | |||
914 | return *this; | |||
915 | } | |||
916 | ||||
917 | ||||
918 | template<typename ParentBuilder> | |||
919 | typename Grid<ParentBuilder>::GroupBuilder | |||
920 | Grid<ParentBuilder>::AddGroup(orientation orientation, float spacing, | |||
921 | int32 column, int32 row, int32 columnCount, int32 rowCount) | |||
922 | { | |||
923 | GroupBuilder builder(new BGroupLayout(orientation, spacing)); | |||
924 | builder.SetParent(this); | |||
925 | fLayout->AddItem(builder.Layout(), column, row, columnCount, rowCount); | |||
926 | return builder; | |||
927 | } | |||
928 | ||||
929 | ||||
930 | template<typename ParentBuilder> | |||
931 | typename Grid<ParentBuilder>::GroupBuilder | |||
932 | Grid<ParentBuilder>::AddGroup(BGroupView* groupView, int32 column, int32 row, | |||
933 | int32 columnCount, int32 rowCount) | |||
934 | { | |||
935 | GroupBuilder builder(groupView); | |||
936 | builder.SetParent(this); | |||
937 | fLayout->AddItem(builder.Layout(), column, row, columnCount, rowCount); | |||
938 | return builder; | |||
939 | } | |||
940 | ||||
941 | ||||
942 | template<typename ParentBuilder> | |||
943 | typename Grid<ParentBuilder>::GroupBuilder | |||
944 | Grid<ParentBuilder>::AddGroup(BGroupLayout* groupLayout, int32 column, | |||
945 | int32 row, int32 columnCount, int32 rowCount) | |||
946 | { | |||
947 | GroupBuilder builder(groupLayout); | |||
948 | builder.SetParent(this); | |||
949 | fLayout->AddItem(builder.Layout(), column, row, columnCount, rowCount); | |||
950 | return builder; | |||
951 | } | |||
952 | ||||
953 | ||||
954 | template<typename ParentBuilder> | |||
955 | typename Grid<ParentBuilder>::GridBuilder | |||
956 | Grid<ParentBuilder>::AddGrid(float horizontalSpacing, float verticalSpacing, | |||
957 | int32 column, int32 row, int32 columnCount, int32 rowCount) | |||
958 | { | |||
959 | GridBuilder builder(new BGridLayout(horizontalSpacing, verticalSpacing)); | |||
960 | builder.SetParent(this); | |||
961 | fLayout->AddItem(builder.Layout(), column, row, columnCount, rowCount); | |||
962 | return builder; | |||
963 | } | |||
964 | ||||
965 | ||||
966 | template<typename ParentBuilder> | |||
967 | typename Grid<ParentBuilder>::GridBuilder | |||
968 | Grid<ParentBuilder>::AddGrid(BGridView* gridView, int32 column, int32 row, | |||
969 | int32 columnCount, int32 rowCount) | |||
970 | { | |||
971 | GridBuilder builder(gridView); | |||
972 | builder.SetParent(this); | |||
973 | fLayout->AddView(builder.View(), column, row, columnCount, rowCount); | |||
974 | return builder; | |||
975 | } | |||
976 | ||||
977 | ||||
978 | template<typename ParentBuilder> | |||
979 | typename Grid<ParentBuilder>::SplitBuilder | |||
980 | Grid<ParentBuilder>::AddSplit(orientation orientation, float spacing, | |||
981 | int32 column, int32 row, int32 columnCount, int32 rowCount) | |||
982 | { | |||
983 | SplitBuilder builder(orientation, spacing); | |||
984 | builder.SetParent(this); | |||
985 | fLayout->AddView(builder.View(), column, row, columnCount, rowCount); | |||
986 | return builder; | |||
987 | } | |||
988 | ||||
989 | ||||
990 | template<typename ParentBuilder> | |||
991 | typename Grid<ParentBuilder>::SplitBuilder | |||
992 | Grid<ParentBuilder>::AddSplit(BSplitView* splitView, int32 column, int32 row, | |||
993 | int32 columnCount, int32 rowCount) | |||
994 | { | |||
995 | SplitBuilder builder(splitView); | |||
996 | builder.SetParent(this); | |||
997 | fLayout->AddView(builder.View(), column, row, columnCount, rowCount); | |||
998 | return builder; | |||
999 | } | |||
1000 | ||||
1001 | ||||
1002 | template<typename ParentBuilder> | |||
1003 | typename Grid<ParentBuilder>::CardBuilder | |||
1004 | Grid<ParentBuilder>::AddCards(int32 column, int32 row, int32 columnCount, | |||
1005 | int32 rowCount) | |||
1006 | { | |||
1007 | CardBuilder builder; | |||
1008 | builder.SetParent(this); | |||
1009 | fLayout->AddView(builder.View(), column, row, columnCount, rowCount); | |||
1010 | return builder; | |||
1011 | } | |||
1012 | ||||
1013 | ||||
1014 | template<typename ParentBuilder> | |||
1015 | typename Grid<ParentBuilder>::CardBuilder | |||
1016 | Grid<ParentBuilder>::AddCards(BCardLayout* cardLayout, int32 column, int32 row, | |||
1017 | int32 columnCount, int32 rowCount) | |||
1018 | { | |||
1019 | CardBuilder builder(cardLayout); | |||
1020 | builder.SetParent(this); | |||
1021 | fLayout->AddView(builder.View(), column, row, columnCount, rowCount); | |||
1022 | return builder; | |||
1023 | } | |||
1024 | ||||
1025 | ||||
1026 | template<typename ParentBuilder> | |||
1027 | typename Grid<ParentBuilder>::CardBuilder | |||
1028 | Grid<ParentBuilder>::AddCards(BCardView* cardView, int32 column, int32 row, | |||
1029 | int32 columnCount, int32 rowCount) | |||
1030 | { | |||
1031 | CardBuilder builder(cardView); | |||
1032 | builder.SetParent(this); | |||
1033 | fLayout->AddView(builder.View(), column, row, columnCount, rowCount); | |||
1034 | return builder; | |||
1035 | } | |||
1036 | ||||
1037 | ||||
1038 | template<typename ParentBuilder> | |||
1039 | typename Grid<ParentBuilder>::ThisBuilder& | |||
1040 | Grid<ParentBuilder>::AddGlue(int32 column, int32 row, int32 columnCount, | |||
1041 | int32 rowCount) | |||
1042 | { | |||
1043 | fLayout->AddItem(BSpaceLayoutItem::CreateGlue(), column, row, columnCount, | |||
1044 | rowCount); | |||
1045 | return *this; | |||
1046 | } | |||
1047 | ||||
1048 | ||||
1049 | template<typename ParentBuilder> | |||
1050 | typename Grid<ParentBuilder>::ThisBuilder& | |||
1051 | Grid<ParentBuilder>::SetHorizontalSpacing(float spacing) | |||
1052 | { | |||
1053 | fLayout->SetHorizontalSpacing(spacing); | |||
1054 | return *this; | |||
1055 | } | |||
1056 | ||||
1057 | ||||
1058 | template<typename ParentBuilder> | |||
1059 | typename Grid<ParentBuilder>::ThisBuilder& | |||
1060 | Grid<ParentBuilder>::SetVerticalSpacing(float spacing) | |||
1061 | { | |||
1062 | fLayout->SetVerticalSpacing(spacing); | |||
1063 | return *this; | |||
1064 | } | |||
1065 | ||||
1066 | ||||
1067 | template<typename ParentBuilder> | |||
1068 | typename Grid<ParentBuilder>::ThisBuilder& | |||
1069 | Grid<ParentBuilder>::SetSpacing(float horizontal, float vertical) | |||
1070 | { | |||
1071 | fLayout->SetSpacing(horizontal, vertical); | |||
1072 | return *this; | |||
1073 | } | |||
1074 | ||||
1075 | ||||
1076 | template<typename ParentBuilder> | |||
1077 | typename Grid<ParentBuilder>::ThisBuilder& | |||
1078 | Grid<ParentBuilder>::SetColumnWeight(int32 column, float weight) | |||
1079 | { | |||
1080 | fLayout->SetColumnWeight(column, weight); | |||
1081 | return *this; | |||
1082 | } | |||
1083 | ||||
1084 | ||||
1085 | template<typename ParentBuilder> | |||
1086 | typename Grid<ParentBuilder>::ThisBuilder& | |||
1087 | Grid<ParentBuilder>::SetRowWeight(int32 row, float weight) | |||
1088 | { | |||
1089 | fLayout->SetRowWeight(row, weight); | |||
1090 | return *this; | |||
1091 | } | |||
1092 | ||||
1093 | ||||
1094 | template<typename ParentBuilder> | |||
1095 | typename Grid<ParentBuilder>::ThisBuilder& | |||
1096 | Grid<ParentBuilder>::SetInsets(float left, float top, float right, | |||
1097 | float bottom) | |||
1098 | { | |||
1099 | fLayout->SetInsets(left, top, right, bottom); | |||
1100 | return *this; | |||
1101 | } | |||
1102 | ||||
1103 | ||||
1104 | template<typename ParentBuilder> | |||
1105 | typename Grid<ParentBuilder>::ThisBuilder& | |||
1106 | Grid<ParentBuilder>::SetInsets(float horizontal, float vertical) | |||
1107 | { | |||
1108 | fLayout->SetInsets(horizontal, vertical); | |||
1109 | return *this; | |||
1110 | } | |||
1111 | ||||
1112 | ||||
1113 | template<typename ParentBuilder> | |||
1114 | typename Grid<ParentBuilder>::ThisBuilder& | |||
1115 | Grid<ParentBuilder>::SetInsets(float insets) | |||
1116 | { | |||
1117 | fLayout->SetInsets(insets); | |||
1118 | return *this; | |||
1119 | } | |||
1120 | ||||
1121 | ||||
1122 | template<typename ParentBuilder> | |||
1123 | typename Grid<ParentBuilder>::ThisBuilder& | |||
1124 | Grid<ParentBuilder>::SetExplicitMinSize(BSize size) | |||
1125 | { | |||
1126 | fLayout->SetExplicitMinSize(size); | |||
1127 | return *this; | |||
1128 | } | |||
1129 | ||||
1130 | ||||
1131 | template<typename ParentBuilder> | |||
1132 | typename Grid<ParentBuilder>::ThisBuilder& | |||
1133 | Grid<ParentBuilder>::SetExplicitMaxSize(BSize size) | |||
1134 | { | |||
1135 | fLayout->SetExplicitMaxSize(size); | |||
1136 | return *this; | |||
1137 | } | |||
1138 | ||||
1139 | ||||
1140 | template<typename ParentBuilder> | |||
1141 | typename Grid<ParentBuilder>::ThisBuilder& | |||
1142 | Grid<ParentBuilder>::SetExplicitPreferredSize(BSize size) | |||
1143 | { | |||
1144 | fLayout->SetExplicitPreferredSize(size); | |||
1145 | return *this; | |||
1146 | } | |||
1147 | ||||
1148 | ||||
1149 | template<typename ParentBuilder> | |||
1150 | typename Grid<ParentBuilder>::ThisBuilder& | |||
1151 | Grid<ParentBuilder>::SetExplicitAlignment(BAlignment alignment) | |||
1152 | { | |||
1153 | fLayout->SetExplicitAlignment(alignment); | |||
1154 | return *this; | |||
1155 | } | |||
1156 | ||||
1157 | ||||
1158 | template<typename ParentBuilder> | |||
1159 | Grid<ParentBuilder>::operator BGridLayout*() | |||
1160 | { | |||
1161 | return fLayout; | |||
1162 | } | |||
1163 | ||||
1164 | ||||
1165 | // #pragma mark - Split | |||
1166 | ||||
1167 | ||||
1168 | template<typename ParentBuilder> | |||
1169 | Split<ParentBuilder>::Split(orientation orientation, float spacing) | |||
1170 | : | |||
1171 | fView(new BSplitView(orientation, spacing)) | |||
1172 | { | |||
1173 | } | |||
1174 | ||||
1175 | ||||
1176 | template<typename ParentBuilder> | |||
1177 | Split<ParentBuilder>::Split(BSplitView* view) | |||
1178 | : | |||
1179 | fView(view) | |||
1180 | { | |||
1181 | } | |||
1182 | ||||
1183 | ||||
1184 | template<typename ParentBuilder> | |||
1185 | BSplitView* | |||
1186 | Split<ParentBuilder>::View() const | |||
1187 | { | |||
1188 | return fView; | |||
1189 | } | |||
1190 | ||||
1191 | ||||
1192 | template<typename ParentBuilder> | |||
1193 | typename Split<ParentBuilder>::ThisBuilder& | |||
1194 | Split<ParentBuilder>::GetView(BView** _view) | |||
1195 | { | |||
1196 | *_view = fView; | |||
1197 | return *this; | |||
1198 | } | |||
1199 | ||||
1200 | ||||
1201 | template<typename ParentBuilder> | |||
1202 | typename Split<ParentBuilder>::ThisBuilder& | |||
1203 | Split<ParentBuilder>::GetSplitView(BSplitView** _view) | |||
1204 | { | |||
1205 | *_view = fView; | |||
1206 | return *this; | |||
1207 | } | |||
1208 | ||||
1209 | ||||
1210 | template<typename ParentBuilder> | |||
1211 | typename Split<ParentBuilder>::ThisBuilder& | |||
1212 | Split<ParentBuilder>::Add(BView* view) | |||
1213 | { | |||
1214 | fView->AddChild(view); | |||
1215 | return *this; | |||
1216 | } | |||
1217 | ||||
1218 | ||||
1219 | template<typename ParentBuilder> | |||
1220 | typename Split<ParentBuilder>::ThisBuilder& | |||
1221 | Split<ParentBuilder>::Add(BView* view, float weight) | |||
1222 | { | |||
1223 | fView->AddChild(view, weight); | |||
1224 | return *this; | |||
1225 | } | |||
1226 | ||||
1227 | ||||
1228 | template<typename ParentBuilder> | |||
1229 | typename Split<ParentBuilder>::ThisBuilder& | |||
1230 | Split<ParentBuilder>::Add(BLayoutItem* item) | |||
1231 | { | |||
1232 | fView->AddChild(item); | |||
1233 | return *this; | |||
1234 | } | |||
1235 | ||||
1236 | ||||
1237 | template<typename ParentBuilder> | |||
1238 | typename Split<ParentBuilder>::ThisBuilder& | |||
1239 | Split<ParentBuilder>::Add(BLayoutItem* item, float weight) | |||
1240 | { | |||
1241 | fView->AddChild(item, weight); | |||
1242 | return *this; | |||
1243 | } | |||
1244 | ||||
1245 | ||||
1246 | template<typename ParentBuilder> | |||
1247 | typename Split<ParentBuilder>::GroupBuilder | |||
1248 | Split<ParentBuilder>::AddGroup(orientation orientation, float spacing, | |||
1249 | float weight) | |||
1250 | { | |||
1251 | GroupBuilder builder(new BGroupLayout(orientation, spacing)); | |||
1252 | builder.SetParent(this); | |||
1253 | fView->AddChild(builder.Layout(), weight); | |||
1254 | return builder; | |||
1255 | } | |||
1256 | ||||
1257 | ||||
1258 | template<typename ParentBuilder> | |||
1259 | typename Split<ParentBuilder>::GroupBuilder | |||
1260 | Split<ParentBuilder>::AddGroup(BGroupView* groupView, float weight) | |||
1261 | { | |||
1262 | GroupBuilder builder(groupView); | |||
1263 | builder.SetParent(this); | |||
1264 | fView->AddChild(builder.Layout(), weight); | |||
1265 | return builder; | |||
1266 | } | |||
1267 | ||||
1268 | ||||
1269 | template<typename ParentBuilder> | |||
1270 | typename Split<ParentBuilder>::GroupBuilder | |||
1271 | Split<ParentBuilder>::AddGroup(BGroupLayout* groupLayout, float weight) | |||
1272 | { | |||
1273 | GroupBuilder builder(groupLayout); | |||
1274 | builder.SetParent(this); | |||
1275 | fView->AddChild(builder.Layout(), weight); | |||
1276 | return builder; | |||
1277 | } | |||
1278 | ||||
1279 | ||||
1280 | template<typename ParentBuilder> | |||
1281 | typename Split<ParentBuilder>::GridBuilder | |||
1282 | Split<ParentBuilder>::AddGrid(float horizontalSpacing, float verticalSpacing, | |||
1283 | float weight) | |||
1284 | { | |||
1285 | GridBuilder builder(new BGridLayout(horizontalSpacing, verticalSpacing)); | |||
1286 | builder.SetParent(this); | |||
1287 | fView->AddChild(builder.Layout(), weight); | |||
1288 | return builder; | |||
1289 | } | |||
1290 | ||||
1291 | ||||
1292 | template<typename ParentBuilder> | |||
1293 | typename Split<ParentBuilder>::GridBuilder | |||
1294 | Split<ParentBuilder>::AddGrid(BGridView* gridView, float weight) | |||
1295 | { | |||
1296 | GridBuilder builder(gridView); | |||
1297 | builder.SetParent(this); | |||
1298 | fView->AddChild(builder.Layout(), weight); | |||
1299 | return builder; | |||
1300 | } | |||
1301 | ||||
1302 | ||||
1303 | template<typename ParentBuilder> | |||
1304 | typename Split<ParentBuilder>::GridBuilder | |||
1305 | Split<ParentBuilder>::AddGrid(BGridLayout* layout, float weight) | |||
1306 | { | |||
1307 | GridBuilder builder(layout); | |||
1308 | builder.SetParent(this); | |||
1309 | fView->AddChild(builder.Layout(), weight); | |||
1310 | return builder; | |||
1311 | } | |||
1312 | ||||
1313 | ||||
1314 | template<typename ParentBuilder> | |||
1315 | typename Split<ParentBuilder>::SplitBuilder | |||
1316 | Split<ParentBuilder>::AddSplit(orientation orientation, float spacing, | |||
1317 | float weight) | |||
1318 | { | |||
1319 | SplitBuilder builder(orientation, spacing); | |||
1320 | builder.SetParent(this); | |||
1321 | fView->AddChild(builder.View(), weight); | |||
1322 | return builder; | |||
1323 | } | |||
1324 | ||||
1325 | ||||
1326 | template<typename ParentBuilder> | |||
1327 | typename Split<ParentBuilder>::CardBuilder | |||
1328 | Split<ParentBuilder>::AddCards(float weight) | |||
1329 | { | |||
1330 | CardBuilder builder; | |||
1331 | builder.SetParent(this); | |||
1332 | fView->AddChild(builder.View(), weight); | |||
1333 | return builder; | |||
1334 | } | |||
1335 | ||||
1336 | ||||
1337 | template<typename ParentBuilder> | |||
1338 | typename Split<ParentBuilder>::CardBuilder | |||
1339 | Split<ParentBuilder>::AddCards(BCardLayout* cardLayout, float weight) | |||
1340 | { | |||
1341 | CardBuilder builder(cardLayout); | |||
1342 | builder.SetParent(this); | |||
1343 | fView->AddChild(builder.View(), weight); | |||
1344 | return builder; | |||
1345 | } | |||
1346 | ||||
1347 | ||||
1348 | template<typename ParentBuilder> | |||
1349 | typename Split<ParentBuilder>::CardBuilder | |||
1350 | Split<ParentBuilder>::AddCards(BCardView* cardView, float weight) | |||
1351 | { | |||
1352 | CardBuilder builder(cardView); | |||
1353 | builder.SetParent(this); | |||
1354 | fView->AddChild(builder.View(), weight); | |||
1355 | return builder; | |||
1356 | } | |||
1357 | ||||
1358 | ||||
1359 | template<typename ParentBuilder> | |||
1360 | typename Split<ParentBuilder>::ThisBuilder& | |||
1361 | Split<ParentBuilder>::SetCollapsible(bool collapsible) | |||
1362 | { | |||
1363 | fView->SetCollapsible(collapsible); | |||
1364 | return *this; | |||
1365 | } | |||
1366 | ||||
1367 | ||||
1368 | template<typename ParentBuilder> | |||
1369 | typename Split<ParentBuilder>::ThisBuilder& | |||
1370 | Split<ParentBuilder>::SetCollapsible(int32 index, bool collapsible) | |||
1371 | { | |||
1372 | fView->SetCollapsible(index, collapsible); | |||
1373 | return *this; | |||
1374 | } | |||
1375 | ||||
1376 | ||||
1377 | template<typename ParentBuilder> | |||
1378 | typename Split<ParentBuilder>::ThisBuilder& | |||
1379 | Split<ParentBuilder>::SetCollapsible(int32 first, int32 last, bool collapsible) | |||
1380 | { | |||
1381 | fView->SetCollapsible(first, last, collapsible); | |||
1382 | return *this; | |||
1383 | } | |||
1384 | ||||
1385 | ||||
1386 | template<typename ParentBuilder> | |||
1387 | typename Split<ParentBuilder>::ThisBuilder& | |||
1388 | Split<ParentBuilder>::SetInsets(float left, float top, float right, | |||
1389 | float bottom) | |||
1390 | { | |||
1391 | fView->SetInsets(left, top, right, bottom); | |||
1392 | return *this; | |||
1393 | } | |||
1394 | ||||
1395 | ||||
1396 | template<typename ParentBuilder> | |||
1397 | typename Split<ParentBuilder>::ThisBuilder& | |||
1398 | Split<ParentBuilder>::SetInsets(float horizontal, float vertical) | |||
1399 | { | |||
1400 | fView->SetInsets(horizontal, vertical); | |||
1401 | return *this; | |||
1402 | } | |||
1403 | ||||
1404 | ||||
1405 | template<typename ParentBuilder> | |||
1406 | typename Split<ParentBuilder>::ThisBuilder& | |||
1407 | Split<ParentBuilder>::SetInsets(float insets) | |||
1408 | { | |||
1409 | fView->SetInsets(insets); | |||
1410 | return *this; | |||
1411 | } | |||
1412 | ||||
1413 | ||||
1414 | template<typename ParentBuilder> | |||
1415 | Split<ParentBuilder>::operator BSplitView*() | |||
1416 | { | |||
1417 | return fView; | |||
1418 | } | |||
1419 | ||||
1420 | ||||
1421 | // #pragma mark - Cards | |||
1422 | ||||
1423 | ||||
1424 | template<typename ParentBuilder> | |||
1425 | Cards<ParentBuilder>::Cards() | |||
1426 | : | |||
1427 | fLayout((new BCardView())->CardLayout()) | |||
1428 | { | |||
1429 | } | |||
1430 | ||||
1431 | ||||
1432 | template<typename ParentBuilder> | |||
1433 | Cards<ParentBuilder>::Cards(BWindow* window) | |||
1434 | : | |||
1435 | fLayout(new BCardLayout()) | |||
1436 | { | |||
1437 | window->SetLayout(fLayout); | |||
1438 | ||||
1439 | fLayout->Owner()->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); | |||
1440 | } | |||
1441 | ||||
1442 | ||||
1443 | template<typename ParentBuilder> | |||
1444 | Cards<ParentBuilder>::Cards(BView* view) | |||
1445 | : | |||
1446 | fLayout(new BCardLayout()) | |||
1447 | { | |||
1448 | view->SetLayout(fLayout); | |||
1449 | view->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); | |||
1450 | } | |||
1451 | ||||
1452 | ||||
1453 | template<typename ParentBuilder> | |||
1454 | Cards<ParentBuilder>::Cards(BCardLayout* layout) | |||
1455 | : | |||
1456 | fLayout(layout) | |||
1457 | { | |||
1458 | } | |||
1459 | ||||
1460 | ||||
1461 | template<typename ParentBuilder> | |||
1462 | Cards<ParentBuilder>::Cards(BCardView* view) | |||
1463 | : | |||
1464 | fLayout(view->CardLayout()) | |||
1465 | { | |||
1466 | } | |||
1467 | ||||
1468 | ||||
1469 | template<typename ParentBuilder> | |||
1470 | BCardLayout* | |||
1471 | Cards<ParentBuilder>::Layout() const | |||
1472 | { | |||
1473 | return fLayout; | |||
1474 | } | |||
1475 | ||||
1476 | ||||
1477 | template<typename ParentBuilder> | |||
1478 | BView* | |||
1479 | Cards<ParentBuilder>::View() const | |||
1480 | { | |||
1481 | return fLayout->Owner(); | |||
1482 | } | |||
1483 | ||||
1484 | ||||
1485 | template<typename ParentBuilder> | |||
1486 | typename Cards<ParentBuilder>::ThisBuilder& | |||
1487 | Cards<ParentBuilder>::GetLayout(BCardLayout** _layout) | |||
1488 | { | |||
1489 | *_layout = fLayout; | |||
1490 | return *this; | |||
1491 | } | |||
1492 | ||||
1493 | ||||
1494 | template<typename ParentBuilder> | |||
1495 | typename Cards<ParentBuilder>::ThisBuilder& | |||
1496 | Cards<ParentBuilder>::GetView(BView** _view) | |||
1497 | { | |||
1498 | *_view = fLayout->Owner(); | |||
1499 | return *this; | |||
1500 | } | |||
1501 | ||||
1502 | ||||
1503 | template<typename ParentBuilder> | |||
1504 | typename Cards<ParentBuilder>::ThisBuilder& | |||
1505 | Cards<ParentBuilder>::Add(BView* view) | |||
1506 | { | |||
1507 | fLayout->AddView(view); | |||
1508 | return *this; | |||
1509 | } | |||
1510 | ||||
1511 | ||||
1512 | template<typename ParentBuilder> | |||
1513 | typename Cards<ParentBuilder>::ThisBuilder& | |||
1514 | Cards<ParentBuilder>::Add(BLayoutItem* item) | |||
1515 | { | |||
1516 | fLayout->AddItem(item); | |||
1517 | return *this; | |||
1518 | } | |||
1519 | ||||
1520 | ||||
1521 | template<typename ParentBuilder> | |||
1522 | typename Cards<ParentBuilder>::GroupBuilder | |||
1523 | Cards<ParentBuilder>::AddGroup(orientation orientation, float spacing) | |||
1524 | { | |||
1525 | GroupBuilder builder(new BGroupLayout(orientation, spacing)); | |||
1526 | builder.SetParent(this); | |||
1527 | fLayout->AddItem(builder.Layout()); | |||
1528 | return builder; | |||
1529 | } | |||
1530 | ||||
1531 | ||||
1532 | template<typename ParentBuilder> | |||
1533 | typename Cards<ParentBuilder>::GroupBuilder | |||
1534 | Cards<ParentBuilder>::AddGroup(BGroupView* groupView) | |||
1535 | { | |||
1536 | GroupBuilder builder(groupView); | |||
1537 | builder.SetParent(this); | |||
1538 | fLayout->AddItem(builder.Layout()); | |||
1539 | return builder; | |||
1540 | } | |||
1541 | ||||
1542 | ||||
1543 | template<typename ParentBuilder> | |||
1544 | typename Cards<ParentBuilder>::GroupBuilder | |||
1545 | Cards<ParentBuilder>::AddGroup(BGroupLayout* groupLayout) | |||
1546 | { | |||
1547 | GroupBuilder builder(groupLayout); | |||
1548 | builder.SetParent(this); | |||
1549 | fLayout->AddItem(builder.Layout()); | |||
1550 | return builder; | |||
1551 | } | |||
1552 | ||||
1553 | ||||
1554 | template<typename ParentBuilder> | |||
1555 | typename Cards<ParentBuilder>::GridBuilder | |||
1556 | Cards<ParentBuilder>::AddGrid(float horizontal, float vertical) | |||
1557 | { | |||
1558 | GridBuilder builder(horizontal, vertical); | |||
1559 | builder.SetParent(this); | |||
1560 | fLayout->AddItem(builder.Layout()); | |||
1561 | return builder; | |||
1562 | } | |||
1563 | ||||
1564 | ||||
1565 | template<typename ParentBuilder> | |||
1566 | typename Cards<ParentBuilder>::GridBuilder | |||
1567 | Cards<ParentBuilder>::AddGrid(BGridLayout* gridLayout) | |||
1568 | { | |||
1569 | GridBuilder builder(gridLayout); | |||
1570 | builder.SetParent(this); | |||
1571 | fLayout->AddItem(builder.Layout()); | |||
1572 | return builder; | |||
1573 | } | |||
1574 | ||||
1575 | ||||
1576 | template<typename ParentBuilder> | |||
1577 | typename Cards<ParentBuilder>::GridBuilder | |||
1578 | Cards<ParentBuilder>::AddGrid(BGridView* gridView) | |||
1579 | { | |||
1580 | GridBuilder builder(gridView); | |||
1581 | builder.SetParent(this); | |||
1582 | fLayout->AddItem(builder.Layout()); | |||
1583 | return builder; | |||
1584 | } | |||
1585 | ||||
1586 | ||||
1587 | template<typename ParentBuilder> | |||
1588 | typename Cards<ParentBuilder>::SplitBuilder | |||
1589 | Cards<ParentBuilder>::AddSplit(orientation orientation, float spacing) | |||
1590 | { | |||
1591 | SplitBuilder builder(orientation, spacing); | |||
1592 | builder.SetParent(this); | |||
1593 | fLayout->AddView(builder.View()); | |||
1594 | return builder; | |||
1595 | } | |||
1596 | ||||
1597 | ||||
1598 | template<typename ParentBuilder> | |||
1599 | typename Cards<ParentBuilder>::SplitBuilder | |||
1600 | Cards<ParentBuilder>::AddSplit(BSplitView* splitView) | |||
1601 | { | |||
1602 | SplitBuilder builder(splitView); | |||
1603 | builder.SetParent(this); | |||
1604 | fLayout->AddView(builder.View()); | |||
1605 | return builder; | |||
1606 | } | |||
1607 | ||||
1608 | ||||
1609 | template<typename ParentBuilder> | |||
1610 | typename Cards<ParentBuilder>::CardBuilder | |||
1611 | Cards<ParentBuilder>::AddCards() | |||
1612 | { | |||
1613 | CardBuilder builder; | |||
1614 | builder.SetParent(this); | |||
1615 | fLayout->AddView(builder.View()); | |||
1616 | return builder; | |||
1617 | } | |||
1618 | ||||
1619 | ||||
1620 | template<typename ParentBuilder> | |||
1621 | typename Cards<ParentBuilder>::CardBuilder | |||
1622 | Cards<ParentBuilder>::AddCards(BCardLayout* cardLayout) | |||
1623 | { | |||
1624 | CardBuilder builder(cardLayout); | |||
1625 | builder.SetParent(this); | |||
1626 | fLayout->AddView(builder.View()); | |||
1627 | return builder; | |||
1628 | } | |||
1629 | ||||
1630 | template<typename ParentBuilder> | |||
1631 | typename Cards<ParentBuilder>::CardBuilder | |||
1632 | Cards<ParentBuilder>::AddCards(BCardView* cardView) | |||
1633 | { | |||
1634 | CardBuilder builder(cardView); | |||
1635 | builder.SetParent(this); | |||
1636 | fLayout->AddView(builder.View()); | |||
1637 | return builder; | |||
1638 | } | |||
1639 | ||||
1640 | ||||
1641 | template<typename ParentBuilder> | |||
1642 | typename Cards<ParentBuilder>::ThisBuilder& | |||
1643 | Cards<ParentBuilder>::SetExplicitMinSize(BSize size) | |||
1644 | { | |||
1645 | fLayout->SetExplicitMinSize(size); | |||
1646 | return *this; | |||
1647 | } | |||
1648 | ||||
1649 | ||||
1650 | template<typename ParentBuilder> | |||
1651 | typename Cards<ParentBuilder>::ThisBuilder& | |||
1652 | Cards<ParentBuilder>::SetExplicitMaxSize(BSize size) | |||
1653 | { | |||
1654 | fLayout->SetExplicitMaxSize(size); | |||
1655 | return *this; | |||
1656 | } | |||
1657 | ||||
1658 | ||||
1659 | template<typename ParentBuilder> | |||
1660 | typename Cards<ParentBuilder>::ThisBuilder& | |||
1661 | Cards<ParentBuilder>::SetExplicitPreferredSize(BSize size) | |||
1662 | { | |||
1663 | fLayout->SetExplicitPreferredSize(size); | |||
1664 | return *this; | |||
1665 | } | |||
1666 | ||||
1667 | ||||
1668 | template<typename ParentBuilder> | |||
1669 | typename Cards<ParentBuilder>::ThisBuilder& | |||
1670 | Cards<ParentBuilder>::SetExplicitAlignment(BAlignment alignment) | |||
1671 | { | |||
1672 | fLayout->SetExplicitAlignment(alignment); | |||
1673 | return *this; | |||
1674 | } | |||
1675 | ||||
1676 | ||||
1677 | template<typename ParentBuilder> | |||
1678 | typename Cards<ParentBuilder>::ThisBuilder& | |||
1679 | Cards<ParentBuilder>::SetVisibleItem(int32 item) | |||
1680 | { | |||
1681 | fLayout->SetVisibleItem(item); | |||
1682 | return *this; | |||
1683 | } | |||
1684 | ||||
1685 | ||||
1686 | template<typename ParentBuilder> | |||
1687 | Cards<ParentBuilder>::operator BCardLayout*() | |||
1688 | { | |||
1689 | return fLayout; | |||
1690 | } | |||
1691 | ||||
1692 | ||||
1693 | // #pragma mark - Menu | |||
1694 | ||||
1695 | ||||
1696 | template<typename ParentBuilder> | |||
1697 | Menu<ParentBuilder>::Menu(BMenu* menu) | |||
1698 | : | |||
1699 | fMenu(menu) | |||
1700 | { | |||
1701 | } | |||
1702 | ||||
1703 | ||||
1704 | template<typename ParentBuilder> | |||
1705 | typename Menu<ParentBuilder>::ThisBuilder& | |||
1706 | Menu<ParentBuilder>::GetMenu(BMenu*& _menu) | |||
1707 | { | |||
1708 | _menu = fMenu; | |||
1709 | return *this; | |||
1710 | } | |||
1711 | ||||
1712 | ||||
1713 | template<typename ParentBuilder> | |||
1714 | typename Menu<ParentBuilder>::ItemBuilder | |||
1715 | Menu<ParentBuilder>::AddItem(BMenuItem* item) | |||
1716 | { | |||
1717 | fMenu->AddItem(item); | |||
1718 | return MenuItem<ParentBuilder>(this->fParent, fMenu, item); | |||
1719 | } | |||
1720 | ||||
1721 | ||||
1722 | template<typename ParentBuilder> | |||
1723 | typename Menu<ParentBuilder>::ItemBuilder | |||
1724 | Menu<ParentBuilder>::AddItem(BMenu* menu) | |||
1725 | { | |||
1726 | if (!fMenu->AddItem(menu)) | |||
1727 | throw std::bad_alloc(); | |||
1728 | ||||
1729 | return MenuItem<ParentBuilder>(this->fParent, fMenu, | |||
1730 | fMenu->ItemAt(fMenu->CountItems() - 1)); | |||
1731 | } | |||
1732 | ||||
1733 | ||||
1734 | template<typename ParentBuilder> | |||
1735 | typename Menu<ParentBuilder>::ItemBuilder | |||
1736 | Menu<ParentBuilder>::AddItem(const char* label, BMessage* message, | |||
1737 | char shortcut, uint32 modifiers) | |||
1738 | { | |||
1739 | BMenuItem* item = new BMenuItem(label, message, shortcut, modifiers); | |||
1740 | if (!fMenu->AddItem(item)) { | |||
1741 | delete item; | |||
1742 | item = NULL__null; | |||
1743 | } | |||
1744 | ||||
1745 | return MenuItem<ParentBuilder>(this->fParent, fMenu, item); | |||
1746 | } | |||
1747 | ||||
1748 | ||||
1749 | template<typename ParentBuilder> | |||
1750 | typename Menu<ParentBuilder>::ItemBuilder | |||
1751 | Menu<ParentBuilder>::AddItem(const char* label, uint32 messageWhat, | |||
1752 | char shortcut, uint32 modifiers) | |||
1753 | { | |||
1754 | BMessage* message = new BMessage(messageWhat); | |||
1755 | BMenuItem* item; | |||
1756 | try { | |||
1757 | item = new BMenuItem(label, message, shortcut, modifiers); | |||
1758 | } catch (...) { | |||
1759 | delete message; | |||
1760 | throw; | |||
1761 | } | |||
1762 | ||||
1763 | if (!fMenu->AddItem(item)) { | |||
1764 | delete item; | |||
1765 | item = NULL__null; | |||
1766 | } | |||
1767 | ||||
1768 | return MenuItem<ParentBuilder>(this->fParent, fMenu, item); | |||
1769 | } | |||
1770 | ||||
1771 | ||||
1772 | template<typename ParentBuilder> | |||
1773 | typename Menu<ParentBuilder>::ThisBuilder& | |||
1774 | Menu<ParentBuilder>::AddSeparator() | |||
1775 | { | |||
1776 | fMenu->AddSeparatorItem(); | |||
1777 | return *this; | |||
1778 | } | |||
1779 | ||||
1780 | ||||
1781 | template<typename ParentBuilder> | |||
1782 | typename Menu<ParentBuilder>::MenuBuilder | |||
1783 | Menu<ParentBuilder>::AddMenu(BMenu* menu) | |||
1784 | { | |||
1785 | if (!fMenu->AddItem(menu)) | |||
1786 | throw std::bad_alloc(); | |||
1787 | ||||
1788 | MenuBuilder builder(menu); | |||
1789 | builder.SetParent(this); | |||
1790 | return builder; | |||
1791 | } | |||
1792 | ||||
1793 | ||||
1794 | template<typename ParentBuilder> | |||
1795 | typename Menu<ParentBuilder>::MenuBuilder | |||
1796 | Menu<ParentBuilder>::AddMenu(const char* title, menu_layout layout) | |||
1797 | { | |||
1798 | BMenu* menu = new BMenu(title, layout); | |||
1799 | if (!fMenu->AddItem(menu)) { | |||
1800 | delete menu; | |||
1801 | throw std::bad_alloc(); | |||
1802 | } | |||
1803 | ||||
1804 | MenuBuilder builder(menu); | |||
1805 | builder.SetParent(this); | |||
1806 | return builder; | |||
1807 | } | |||
1808 | ||||
1809 | ||||
1810 | // #pragma mark - MenuItem | |||
1811 | ||||
1812 | ||||
1813 | template<typename ParentBuilder> | |||
1814 | MenuItem<ParentBuilder>::MenuItem(ParentBuilder* parentBuilder, BMenu* menu, | |||
1815 | BMenuItem* item) | |||
1816 | : | |||
1817 | Menu<ParentBuilder>(menu), | |||
1818 | fMenuItem(item) | |||
1819 | { | |||
1820 | this->SetParent(parentBuilder); | |||
1821 | } | |||
1822 | ||||
1823 | ||||
1824 | template<typename ParentBuilder> | |||
1825 | typename MenuItem<ParentBuilder>::ThisBuilder& | |||
1826 | MenuItem<ParentBuilder>::GetItem(BMenuItem*& _item) | |||
1827 | { | |||
1828 | _item = fMenuItem; | |||
1829 | return *this; | |||
1830 | } | |||
1831 | ||||
1832 | ||||
1833 | template<typename ParentBuilder> | |||
1834 | typename MenuItem<ParentBuilder>::ThisBuilder& | |||
1835 | MenuItem<ParentBuilder>::SetEnabled(bool enabled) | |||
1836 | { | |||
1837 | fMenuItem->SetEnabled(enabled); | |||
1838 | return *this; | |||
1839 | } | |||
1840 | ||||
1841 | ||||
1842 | } // namespace BLayoutBuilder | |||
1843 | ||||
1844 | ||||
1845 | #endif // _LAYOUT_BUILDER_H |