File: vdkcsortlist.cc

package info (click to toggle)
vdk2 2.4.0-2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 4,524 kB
  • ctags: 4,975
  • sloc: cpp: 26,944; sh: 10,580; ansic: 9,220; makefile: 602; perl: 113
file content (128 lines) | stat: -rw-r--r-- 3,008 bytes parent folder | download | duplicates (8)
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
/*
 * ===========================
 * VDK Visual Development Kit
 * Version 0.4
 * October 1998
 * ===========================
 *   
 * Copyright (C) 1998, Mario Motta
 * Developed by Mario Motta <mmotta@guest.net>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 * 02111-1307, USA.
 *
 */


#include "vdk/vdkcsortlist.h"
#include "vdk/forms.h"
#include <cstring>
VDKCustomSortedList::VDKCustomSortedList(VDKForm* owner,
		      int keyPos,
		      int columns,
		      char **titles,
					 GtkSelectionMode mode):
    VDKCustomList(owner,columns,titles,mode),keypos(keyPos)
{
Unique = false;
oldkey = NULL;
}

bool VDKCustomSortedList::AddKey(char **s, 
				 char** pixdata, 
				 int col)
{
 
  Tuple tuple(columns,keypos);
  int j ;
  for(j = 0; j < tuple.size(); j++)
    tuple[j] = s[j];
  int row = Tuples.insert(tuple,Unique);
  // in case of key clush
  if( row < 0)
    return false;
  row = gtk_clist_insert(GTK_CLIST(custom_widget),row,s);
  SetStyle(row);
  pointer = pointer < 0 ? 0 : pointer;
  if(pixdata)
    _update_pix(row,s[col],pixdata,col);
  return true;
}  
/*
 */
void VDKCustomSortedList::UpdateKey(const char* key, char** s, 
	      char** pixdata, int col)
{
  VDKString k(key); 
  int row = 0;
  TupleListIterator li(Tuples);
  for(;li;li++,row++)
    if (li.current()[keypos] == k)
      break;
  if(row < Tuples.size())
    {
      VDKCustomList::RemoveRow(row);
      AddRow(s,pixdata,col);
    }
}
/*
 */
void VDKCustomSortedList::UpdateCellKey(const char* key, int col, 
		  const char* s, char** pixdata)
{
  VDKString k(key);
  int row = 0;
  TupleListIterator li(Tuples);
  if(col == keypos) 
    return; // changing key not allowed
  for(;li;li++,row++)
    if (li.current()[keypos] == k)
      break;
  if(row < Tuples.size())
	VDKCustomList::UpdateCell(row,col,s,pixdata);
}
/*
 */
void VDKCustomSortedList::RemoveKey(const char* key)
{
  VDKString k(key);
  int row = 0;
  TupleListIterator li(Tuples);
  for(;li;li++,row++)
    if (li.current()[keypos] == k)
      break;
  if(row < Tuples.size())
    VDKCustomList::RemoveRow(row);
}
/*
 */
int
VDKCustomSortedList::FindKey(const char* key)
{
int t = 0;
if(! oldkey)
  return -1;
TupleListIterator li(Tuples);
for(;li;li++,t++)
  {
    char* p = (char*) li.current()[keypos];
    if(!std::strcmp(p,key))
      return t;
  }
return -1;
}