xref: /haiku/src/apps/icon-o-matic/generic/selection/Selectable.cpp (revision 2ce8d31d0911191d25b034aa0aa4a3091dfa8c56)
1 /*
2  * Copyright 2006, Haiku.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Stephan Aßmus <superstippi@gmx.de>
7  */
8 
9 #include "Selectable.h"
10 
11 #include <debugger.h>
12 
13 #include "Selection.h"
14 
15 // constructor
Selectable()16 Selectable::Selectable()
17 	: fSelected(false),
18 	  fSelection(NULL)
19 {
20 }
21 
22 // destructor
~Selectable()23 Selectable::~Selectable()
24 {
25 }
26 
27 // SetSelected
28 void
SetSelected(bool selected,bool exclusive)29 Selectable::SetSelected(bool selected, bool exclusive)
30 {
31 	// NOTE: "exclusive" is only useful when selecting,
32 	// it is ignored when deselecting...
33 	if (selected == fSelected)
34 		return;
35 
36 	if (fSelection) {
37 		if (selected)
38 			fSelection->Select(this, !exclusive);
39 		else
40 			fSelection->Deselect(this);
41 	} else {
42 		debugger("Selectable needs to know Selection\n");
43 	}
44 }
45 
46 // SetSelection
47 void
SetSelection(Selection * selection)48 Selectable::SetSelection(Selection* selection)
49 {
50 	fSelection = selection;
51 }
52 
53 // #pragma mark -
54 
55 // SetSelected
56 void
_SetSelected(bool selected)57 Selectable::_SetSelected(bool selected)
58 {
59 	// NOTE: for private use by the Selection object!
60 	if (fSelected != selected) {
61 		fSelected = selected;
62 		SelectedChanged();
63 	}
64 }
65