1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
/***************************************************************************
kbytesedit.cpp - description
-------------------
begin : Die Jul 9 2003
copyright : (C) 2003 by Friedrich W. H. Kossebau
email : Friedrich.W.H@Kossebau.de
***************************************************************************/
/***************************************************************************
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License version 2 as published by the Free Software Foundation. *
* *
***************************************************************************/
// lib specific
#include "kplainbuffer.h"
#include "kbytesedit.h"
#include "kbufferranges.h"
#include "kbuffercursor.h"
using namespace KHE;
KBytesEdit::KBytesEdit( char *D, int DS_, int RS_, bool KM, TQWidget *Parent, const char *Name, WFlags F )
: KHexEdit( 0L, Parent, Name, F ),
AutoDelete( false )
{
setData( D, DS_, RS_, KM );
}
KBytesEdit::KBytesEdit( char *D, int DS_, TQWidget *Parent, const char *Name, WFlags F )
: KHexEdit( 0L, Parent, Name, F ),
AutoDelete( false )
{
setData( D, DS_ );
}
KBytesEdit::KBytesEdit( TQWidget *Parent, const char *Name, WFlags F )
: KHexEdit( 0L, Parent, Name, F ),
AutoDelete( false )
{
setDataBuffer( new KPlainBuffer() );
}
KBytesEdit::~KBytesEdit()
{
clean();
}
void KBytesEdit::setReadOnly( bool RO )
{
KPlainBuffer *Buffer = dynamic_cast<KPlainBuffer *>(DataBuffer);
if( Buffer )
Buffer->setReadOnly( RO );
KHexEdit::setReadOnly( RO );
}
void KBytesEdit::setAutoDelete( bool AD )
{
AutoDelete = AD;
}
char *KBytesEdit::data() const
{
KPlainBuffer *Buffer = dynamic_cast<KPlainBuffer *>(DataBuffer);
return Buffer ? Buffer->data() : 0L;
}
void KBytesEdit::setData( char *D, int S, int RS_, bool KM )
{
KPlainBuffer *NewBuffer = new KPlainBuffer( D, S, RS_, KM );
if( DataBuffer )
{
// take the settings
NewBuffer->setReadOnly( DataBuffer->isReadOnly() );
clean();
}
else
NewBuffer->setReadOnly( isReadOnly() );
setDataBuffer( NewBuffer );
}
int KBytesEdit::dataSize() const
{
KPlainBuffer *Buffer = dynamic_cast<KPlainBuffer *>(DataBuffer);
return Buffer ? Buffer->size() : -1;
}
int KBytesEdit::maxDataSize() const
{
KPlainBuffer *Buffer = dynamic_cast<KPlainBuffer *>(DataBuffer);
return Buffer ? Buffer->maxSize() : -1;
}
void KBytesEdit::setMaxDataSize( int MS )
{
KPlainBuffer *Buffer = dynamic_cast<KPlainBuffer *>(DataBuffer);
if( Buffer )
Buffer->setMaxSize( MS );
}
bool KBytesEdit::keepsMemory() const
{
KPlainBuffer *Buffer = dynamic_cast<KPlainBuffer *>(DataBuffer);
return Buffer ? Buffer->keepsMemory() : false;
}
void KBytesEdit::setKeepsMemory( bool KM )
{
KPlainBuffer *Buffer = dynamic_cast<KPlainBuffer *>(DataBuffer);
if( Buffer )
Buffer->setKeepsMemory( KM );
}
bool KBytesEdit::isAutoDelete() const { return AutoDelete; }
void KBytesEdit::tqrepaintRange( int i1, int i2 )
{
bool ChangeCursor = !(CursorPaused) && KSection(i1,i2).includes( BufferCursor->index() );
if( ChangeCursor )
pauseCursor();
BufferRanges->addChangedRange( i1, i2 );
tqrepaintChanged();
if( ChangeCursor )
unpauseCursor();
}
void KBytesEdit::clean()
{
if( DataBuffer )
{
if( AutoDelete )
{
char *D = data();
if( D )
delete [] D;
}
delete DataBuffer;
}
}
#include "kbytesedit.moc"
|