vfs: check userland buffers before reading them.
[haiku.git] / src / apps / cortex / DiagramView / DiagramItem.cpp
blob9e0b3ea5abce4bfcfe991d35f96ffa315f1da4c8
1 /*
2 * Copyright (c) 1999-2000, Eric Moon.
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions, and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions, and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
27 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 // DiagramItem.cpp
34 #include "DiagramItem.h"
35 #include "DiagramView.h"
37 __USE_CORTEX_NAMESPACE
39 #include <Debug.h>
40 #define D_METHOD(x) //PRINT(x)
42 // -------------------------------------------------------- //
43 // *** static member initialization
44 // -------------------------------------------------------- //
46 bigtime_t DiagramItem::m_lastSelectionTime = 0;
47 int32 DiagramItem::m_countSelected = 0;
49 // -------------------------------------------------------- //
50 // *** ctor/dtor (public)
51 // -------------------------------------------------------- //
53 DiagramItem::DiagramItem(
54 uint32 itemType)
55 : m_type(itemType),
56 m_view(0),
57 m_group(0),
58 m_draggable(false),
59 m_selectable(true),
60 m_selected(false),
61 m_selectionTime(system_time())
63 D_METHOD(("DiagramItem::DiagramItem()\n"));
66 DiagramItem::~DiagramItem()
68 D_METHOD(("DiagramItem::~DiagramItem()\n"));
71 // -------------------------------------------------------- //
72 // *** operations (public)
73 // -------------------------------------------------------- //
75 void DiagramItem::select()
77 D_METHOD(("DiagramItem::select()\n"));
78 if (!m_selected)
80 m_selected = true;
81 m_lastSelectionTime = m_selectionTime = system_time();
82 m_countSelected = 1;
83 selected();
84 view()->Invalidate(Frame());
88 void DiagramItem::selectAdding()
90 D_METHOD(("DiagramItem::selectAdding()\n"));
91 if (!m_selected)
93 m_selected = true;
94 m_selectionTime = m_lastSelectionTime - m_countSelected++;
95 selected();
96 view()->Invalidate(Frame());
100 void DiagramItem::deselect()
102 D_METHOD(("DiagramItem::deselect()\n"));
103 if (m_selected)
105 m_selected = false;
106 deselected();
107 view()->Invalidate(Frame());
111 // -------------------------------------------------------- //
112 // *** hook functions (public)
113 // -------------------------------------------------------- //
115 float DiagramItem::howCloseTo(
116 BPoint point) const
118 D_METHOD(("DiagramItem::howCloseTo()\n"));
119 if (Frame().Contains(point))
121 return 1.0;
123 return 0.0;
126 // -------------------------------------------------------- //
127 // *** compare functions (friend)
128 // -------------------------------------------------------- //
130 int __CORTEX_NAMESPACE__ compareSelectionTime(
131 const void *lValue,
132 const void *rValue)
134 D_METHOD(("compareSelectionTime()\n"));
135 int returnValue = 0;
136 const DiagramItem *lItem = *(reinterpret_cast<const DiagramItem* const*>(reinterpret_cast<const void* const*>(lValue)));
137 const DiagramItem *rItem = *(reinterpret_cast<const DiagramItem* const*>(reinterpret_cast<const void* const*>(rValue)));
138 if (lItem->m_selectionTime < rItem->m_selectionTime)
140 returnValue = 1;
142 else if (lItem->m_selectionTime > rItem->m_selectionTime)
144 returnValue = -1;
146 return returnValue;
149 // END -- DiagramItem.cpp --