aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authornyamatongwe <unknown>2002-11-21 12:35:51 +0000
committernyamatongwe <unknown>2002-11-21 12:35:51 +0000
commit80a672aa76c64c58f5a7571879b83e1e44cd2db6 (patch)
treef3b69c94fcefff4ff2b0828a740940b9d0b96fb6
parent882b4355011c56f17284981bab13ed74ed395284 (diff)
downloadscintilla-mirror-80a672aa76c64c58f5a7571879b83e1e44cd2db6.tar.gz
Patch from Biswa to add icons to autocompletion lists.
-rw-r--r--gtk/PlatGTK.cxx146
-rw-r--r--include/Platform.h4
-rw-r--r--include/Scintilla.h1
-rw-r--r--include/Scintilla.iface3
-rw-r--r--src/AutoComplete.h5
-rw-r--r--src/PropSet.cxx24
-rw-r--r--src/ScintillaBase.cxx4
-rw-r--r--win32/PlatWin.cxx5
8 files changed, 143 insertions, 49 deletions
diff --git a/gtk/PlatGTK.cxx b/gtk/PlatGTK.cxx
index 8d61adde7..2554f3dd4 100644
--- a/gtk/PlatGTK.cxx
+++ b/gtk/PlatGTK.cxx
@@ -186,7 +186,6 @@ void Palette::Allocate(Window &w) {
delete []successPalette;
}
-
static const char *CharacterSetName(int characterSet) {
switch (characterSet) {
case SC_CHARSET_ANSI:
@@ -233,9 +232,9 @@ static const char *CharacterSetName(int characterSet) {
}
static void GenerateFontSpecStrings(const char *fontName, int characterSet,
- char *foundary, int foundary_len,
- char *faceName, int faceName_len,
- char *charset, int charset_len) {
+ char *foundary, int foundary_len,
+ char *faceName, int faceName_len,
+ char *charset, int charset_len) {
// supported font strings include:
// foundary-fontface-isoxxx-x
// fontface-isoxxx-x
@@ -283,7 +282,7 @@ static void SetLogFont(LOGFONT &lf, const char *faceName, int characterSet, int
lf.bold = bold;
lf.italic = italic;
lf.characterSet = characterSet;
- strncpy(lf.faceName, faceName, sizeof(lf.faceName)-1);
+ strncpy(lf.faceName, faceName, sizeof(lf.faceName) - 1);
}
/**
@@ -293,11 +292,11 @@ static void SetLogFont(LOGFONT &lf, const char *faceName, int characterSet, int
*/
static int HashFont(const char *faceName, int characterSet, int size, bool bold, bool italic) {
return
- size ^
- (characterSet << 10) ^
- (bold ? 0x10000000 : 0) ^
- (italic ? 0x20000000 : 0) ^
- faceName[0];
+ size ^
+ (characterSet << 10) ^
+ (bold ? 0x10000000 : 0) ^
+ (italic ? 0x20000000 : 0) ^
+ faceName[0];
}
class FontCached : Font {
@@ -309,8 +308,8 @@ class FontCached : Font {
~FontCached() {}
bool SameAs(const char *faceName_, int characterSet_, int size_, bool bold_, bool italic_);
virtual void Release();
- static FontID CreateNewFont(const char *fontName, int characterSet,
- int size, bool bold, bool italic);
+ static FontID CreateNewFont(const char *fontName, int characterSet,
+ int size, bool bold, bool italic);
static FontCached *first;
public:
static FontID FindOrCreate(const char *faceName_, int characterSet_, int size_, bool bold_, bool italic_);
@@ -320,7 +319,7 @@ public:
FontCached *FontCached::first = 0;
FontCached::FontCached(const char *faceName_, int characterSet_, int size_, bool bold_, bool italic_) :
- next(0), usage(0), hash(0) {
+next(0), usage(0), hash(0) {
::SetLogFont(lf, faceName_, characterSet_, size_, bold_, italic_);
hash = HashFont(faceName_, characterSet_, size_, bold_, italic_);
id = CreateNewFont(faceName_, characterSet_, size_, bold_, italic_);
@@ -329,11 +328,11 @@ FontCached::FontCached(const char *faceName_, int characterSet_, int size_, bool
bool FontCached::SameAs(const char *faceName_, int characterSet_, int size_, bool bold_, bool italic_) {
return
- lf.size == size_ &&
- lf.bold == bold_ &&
- lf.italic == italic_ &&
- lf.characterSet == characterSet_ &&
- 0 == strcmp(lf.faceName,faceName_);
+ lf.size == size_ &&
+ lf.bold == bold_ &&
+ lf.italic == italic_ &&
+ lf.characterSet == characterSet_ &&
+ 0 == strcmp(lf.faceName, faceName_);
}
void FontCached::Release() {
@@ -346,9 +345,9 @@ FontID FontCached::FindOrCreate(const char *faceName_, int characterSet_, int si
FontID ret = 0;
FontMutexLock();
int hashFind = HashFont(faceName_, characterSet_, size_, bold_, italic_);
- for (FontCached *cur=first; cur; cur=cur->next) {
+ for (FontCached *cur = first; cur; cur = cur->next) {
if ((cur->hash == hashFind) &&
- cur->SameAs(faceName_, characterSet_, size_, bold_, italic_)) {
+ cur->SameAs(faceName_, characterSet_, size_, bold_, italic_)) {
cur->usage++;
ret = cur->id;
}
@@ -367,8 +366,8 @@ FontID FontCached::FindOrCreate(const char *faceName_, int characterSet_, int si
void FontCached::ReleaseId(FontID id_) {
FontMutexLock();
- FontCached **pcur=&first;
- for (FontCached *cur=first; cur; cur=cur->next) {
+ FontCached **pcur = &first;
+ for (FontCached *cur = first; cur; cur = cur->next) {
if (cur->id == id_) {
cur->usage--;
if (cur->usage == 0) {
@@ -379,13 +378,13 @@ void FontCached::ReleaseId(FontID id_) {
}
break;
}
- pcur=&cur->next;
+ pcur = &cur->next;
}
FontMutexUnlock();
}
FontID FontCached::CreateNewFont(const char *fontName, int characterSet,
- int size, bool bold, bool italic) {
+ int size, bool bold, bool italic) {
char fontset[1024];
char fontspec[300];
char foundary[50];
@@ -396,7 +395,7 @@ FontID FontCached::CreateNewFont(const char *fontName, int characterSet,
foundary[0] = '\0';
faceName[0] = '\0';
charset[0] = '\0';
- FontID newid = 0;
+ FontID newid = 0;
// If name of the font begins with a '-', assume, that it is
// a full fontspec.
@@ -531,7 +530,6 @@ FontID FontCached::CreateNewFont(const char *fontName, int characterSet,
return newid;
}
-
Font::Font() : id(0) {}
Font::~Font() {}
@@ -547,7 +545,6 @@ void Font::Release() {
id = 0;
}
-
class SurfaceImpl : public Surface {
bool unicodeMode;
GdkDrawable *drawable;
@@ -939,8 +936,10 @@ int SurfaceImpl::Ascent(Font &font_) {
if (!font_.GetID())
return 1;
#ifdef FAST_WAY
+
return PFont(font_)->ascent;
#else
+
gint lbearing;
gint rbearing;
gint width;
@@ -957,8 +956,10 @@ int SurfaceImpl::Descent(Font &font_) {
if (!font_.GetID())
return 1;
#ifdef FAST_WAY
+
return PFont(font_)->descent;
#else
+
gint lbearing;
gint rbearing;
gint width;
@@ -1047,6 +1048,7 @@ void Window::SetPosition(PRectangle rc) {
alloc.height = rc.Height();
gtk_widget_size_allocate(PWidget(id), &alloc);
#else
+
gtk_widget_set_uposition(id, rc.left, rc.top);
gtk_widget_set_usize(id, rc.right - rc.left, rc.bottom - rc.top);
#endif
@@ -1059,6 +1061,7 @@ void Window::SetPositionRelative(PRectangle rc, Window relativeTo) {
gtk_widget_set_uposition(PWidget(id), rc.left + ox, rc.top + oy);
#if 0
+
GtkAllocation alloc;
alloc.x = rc.left + ox;
alloc.y = rc.top + oy;
@@ -1066,6 +1069,7 @@ void Window::SetPositionRelative(PRectangle rc, Window relativeTo) {
alloc.height = rc.bottom - rc.top;
gtk_widget_size_allocate(id, &alloc);
#endif
+
gtk_widget_set_usize(PWidget(id), rc.right - rc.left, rc.bottom - rc.top);
}
@@ -1136,10 +1140,28 @@ void Window::SetTitle(const char *s) {
gtk_window_set_title(GTK_WINDOW(id), s);
}
-ListBox::ListBox() : list(0), current(0), desiredVisibleRows(5), maxItemCharacters(0),
+struct ListImage {
+ const char **xpm_data;
+ GdkPixmap *pixmap;
+ GdkBitmap *bitmap;
+};
+
+ListBox::ListBox() : list(0), current(0), pixhash(NULL), desiredVisibleRows(5), maxItemCharacters(0),
doubleClickAction(NULL), doubleClickActionData(NULL) {}
-ListBox::~ListBox() {}
+static void list_image_free(gpointer, gpointer value, gpointer) {
+ ListImage *list_image = (ListImage *) value;
+ if (list_image->pixmap)
+ gdk_pixmap_unref(list_image->pixmap);
+ if (list_image->bitmap)
+ gdk_bitmap_unref(list_image->bitmap);
+ g_free(list_image);
+}
+
+ListBox::~ListBox() {
+ g_hash_table_foreach((GHashTable *) pixhash, list_image_free, NULL);
+ g_hash_table_destroy((GHashTable *) pixhash);
+}
static void SelectionAC(GtkWidget *, gint row, gint,
GdkEventButton *, gpointer p) {
@@ -1230,8 +1252,10 @@ PRectangle ListBox::GetDesiredRect() {
int height;
#if GTK_MAJOR_VERSION < 2
+
int ythickness = PWidget(list)->style->klass->ythickness;
#else
+
int ythickness = PWidget(list)->style->ythickness;
#endif
// First calculate height of the clist for our desired visible row count otherwise it tries to expand to the total # of rows
@@ -1262,9 +1286,32 @@ void ListBox::Clear() {
maxItemCharacters = 0;
}
-void ListBox::Append(char *s) {
- char *szs[] = { s, 0};
- gtk_clist_append(GTK_CLIST(list), szs);
+static void init_pixmap(ListImage *li, GtkWidget *window) {
+ li->pixmap = gdk_pixmap_colormap_create_from_xpm_d(NULL
+ , gtk_widget_get_colormap(window), &(li->bitmap), NULL
+ , (gchar **) li->xpm_data);
+ if (NULL == li->pixmap) {
+ if (li->bitmap)
+ gdk_bitmap_unref(li->bitmap);
+ li->bitmap = NULL;
+ }
+}
+
+#define SPACING 5
+
+void ListBox::Append(char *s, int type) {
+ char * szs[] = { s, NULL };
+ ListImage *list_image = NULL;
+ if (type >= 0)
+ list_image = (ListImage *) g_hash_table_lookup((GHashTable *) pixhash
+ , (gconstpointer) GINT_TO_POINTER(type));
+ int rownum = gtk_clist_append(GTK_CLIST(list), szs);
+ if (list_image) {
+ if (NULL == list_image->pixmap)
+ init_pixmap(list_image, (GtkWidget *) list);
+ gtk_clist_set_pixtext(GTK_CLIST(list), rownum, 0, s, SPACING
+ , list_image->pixmap, list_image->bitmap);
+ }
size_t len = strlen(s);
if (maxItemCharacters < len)
maxItemCharacters = len;
@@ -1298,8 +1345,18 @@ int ListBox::Find(const char *prefix) {
}
void ListBox::GetValue(int n, char *value, int len) {
- char *text = 0;
- gtk_clist_get_text(GTK_CLIST(list), n, 0, &text);
+ char *text = NULL;
+ GtkCellType type = gtk_clist_get_cell_type(GTK_CLIST(list), n, 0);
+ switch (type) {
+ case GTK_CELL_TEXT:
+ gtk_clist_get_text(GTK_CLIST(list), n, 0, &text);
+ break;
+ case GTK_CELL_PIXTEXT:
+ gtk_clist_get_pixtext(GTK_CLIST(list), n, 0, &text, NULL, NULL, NULL);
+ break;
+ default:
+ break;
+ }
if (text && len > 0) {
strncpy(value, text, len);
value[len - 1] = '\0';
@@ -1312,6 +1369,24 @@ void ListBox::Sort() {
gtk_clist_sort(GTK_CLIST(list));
}
+void ListBox::SetTypeXpm(int type, const char **xpm_data) {
+ ListImage *list_image;
+ g_return_if_fail(xpm_data);
+
+ if (NULL == pixhash)
+ pixhash = g_hash_table_new(g_direct_hash, g_direct_equal);
+ else {
+ list_image = (ListImage *) g_hash_table_lookup((GHashTable *) pixhash
+ , (gconstpointer) GINT_TO_POINTER(type));
+ if (list_image)
+ return;
+ }
+ list_image = g_new0(ListImage, 1);
+ list_image->xpm_data = xpm_data;
+ g_hash_table_insert((GHashTable *) pixhash, GINT_TO_POINTER(type)
+ , (gpointer) list_image);
+}
+
Menu::Menu() : id(0) {}
void Menu::CreatePopUp() {
@@ -1376,6 +1451,7 @@ const char *Platform::DefaultFont() {
#ifdef G_OS_WIN32
return "Lucida Console";
#else
+
return "lucidatypewriter";
#endif
}
@@ -1475,7 +1551,7 @@ int Platform::Clamp(int val, int minVal, int maxVal) {
}
void Platform_Initialise() {
- FontMutexAllocate();
+ FontMutexAllocate();
}
void Platform_Finalise() {
diff --git a/include/Platform.h b/include/Platform.h
index 7e521d63b..53b1dfecc 100644
--- a/include/Platform.h
+++ b/include/Platform.h
@@ -377,6 +377,7 @@ private:
WindowID list;
WindowID scroller;
int current;
+ void *pixhash;
#endif
int desiredVisibleRows;
unsigned int maxItemCharacters;
@@ -393,13 +394,14 @@ public:
void SetVisibleRows(int rows);
PRectangle GetDesiredRect();
void Clear();
- void Append(char *s);
+ void Append(char *s, int type = -1);
int Length();
void Select(int n);
int GetSelection();
int Find(const char *prefix);
void GetValue(int n, char *value, int len);
void Sort();
+ void SetTypeXpm(int type, const char **xpm_data);
void SetDoubleClickAction(CallBackAction action, void *data) {
doubleClickAction = action;
doubleClickActionData = data;
diff --git a/include/Scintilla.h b/include/Scintilla.h
index 7cc9c6aad..4fa58c481 100644
--- a/include/Scintilla.h
+++ b/include/Scintilla.h
@@ -243,6 +243,7 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam,
#define SCI_AUTOCGETAUTOHIDE 2119
#define SCI_AUTOCSETDROPRESTOFWORD 2270
#define SCI_AUTOCGETDROPRESTOFWORD 2271
+#define SCI_REGISTERIMAGE 2405
#define SCI_SETINDENT 2122
#define SCI_GETINDENT 2123
#define SCI_SETUSETABS 2124
diff --git a/include/Scintilla.iface b/include/Scintilla.iface
index d9f9c14f9..eea164f09 100644
--- a/include/Scintilla.iface
+++ b/include/Scintilla.iface
@@ -582,6 +582,9 @@ set void AutoCSetDropRestOfWord=2270(bool dropRestOfWord,)
# after the inserted text upon completion.
get bool AutoCGetDropRestOfWord=2271(,)
+# Register an XPM image for use in autocompletion lists.
+fun void RegisterImage=2405(int type, int xpmData)
+
# Set the number of spaces used for one level of indentation.
set void SetIndent=2122(int indentSize,)
diff --git a/src/AutoComplete.h b/src/AutoComplete.h
index 622a5666e..7983e3611 100644
--- a/src/AutoComplete.h
+++ b/src/AutoComplete.h
@@ -15,6 +15,7 @@ class AutoComplete {
char stopChars[256];
char fillUpChars[256];
char separator;
+ char typesep; // Type seperator
public:
bool ignoreCase;
@@ -48,6 +49,10 @@ public:
void SetSeparator(char separator_);
char GetSeparator();
+ /// The typesep character is used for seperating the word from the type
+ void SetTypesep(char separator_);
+ char GetTypesep();
+
/// The list string contains a sequence of words separated by the separator character
void SetList(const char *list);
diff --git a/src/PropSet.cxx b/src/PropSet.cxx
index b527c385c..60d53088f 100644
--- a/src/PropSet.cxx
+++ b/src/PropSet.cxx
@@ -98,13 +98,13 @@ void PropSet::Set(const char *key, const char *val, int lenKey, int lenVal) {
lenVal = static_cast<int>(strlen(val));
unsigned int hash = HashString(key, lenKey);
for (Property *p = props[hash % hashRoots]; p; p = p->next) {
- if ((hash == p->hash) &&
- ((strlen(p->key) == static_cast<unsigned int>(lenKey)) &&
+ if ((hash == p->hash) &&
+ ((strlen(p->key) == static_cast<unsigned int>(lenKey)) &&
(0 == strncmp(p->key, key, lenKey)))) {
// Replace current value
delete [](p->val);
p->val = StringDup(val, lenVal);
- return ;
+ return;
}
}
// Not found
@@ -257,7 +257,7 @@ SString PropSet::GetWild(const char *keybase, const char *filename) {
if (keyfile == NULL)
keyfile = orgkeyfile;
- for (; ; ) {
+ for (;;) {
char *del = strchr(keyfile, ';');
if (del == NULL)
del = keyfile + strlen(keyfile);
@@ -328,9 +328,9 @@ void PropSet::Clear() {
while (p) {
Property *pNext = p->next;
p->hash = 0;
- delete p->key;
+ delete []p->key;
p->key = 0;
- delete p->val;
+ delete []p->val;
p->val = 0;
delete p;
p = pNext;
@@ -669,13 +669,13 @@ char *WordList::GetNearestWords(
if (!cond) {
// Find first match
while ((pivot > start) &&
- (0 == CompareNCaseInsensitive(wordStart,
+ (0 == CompareNCaseInsensitive(wordStart,
wordsNoCase[pivot-1], searchLen))) {
--pivot;
}
// Grab each match
while ((pivot <= end) &&
- (0 == CompareNCaseInsensitive(wordStart,
+ (0 == CompareNCaseInsensitive(wordStart,
wordsNoCase[pivot], searchLen))) {
wordlen = LengthWord(wordsNoCase[pivot], otherSeparator) + 1;
wordsNear.append(wordsNoCase[pivot], wordlen, ' ');
@@ -695,14 +695,14 @@ char *WordList::GetNearestWords(
if (!cond) {
// Find first match
while ((pivot > start) &&
- (0 == strncmp(wordStart,
- words[pivot-1], searchLen))) {
+ (0 == strncmp(wordStart,
+ words[pivot-1], searchLen))) {
--pivot;
}
// Grab each match
while ((pivot <= end) &&
- (0 == strncmp(wordStart,
- words[pivot], searchLen))) {
+ (0 == strncmp(wordStart,
+ words[pivot], searchLen))) {
wordlen = LengthWord(words[pivot], otherSeparator) + 1;
wordsNear.append(words[pivot], wordlen, ' ');
++pivot;
diff --git a/src/ScintillaBase.cxx b/src/ScintillaBase.cxx
index ab6e9a19b..1c44b0bd6 100644
--- a/src/ScintillaBase.cxx
+++ b/src/ScintillaBase.cxx
@@ -509,6 +509,10 @@ sptr_t ScintillaBase::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lPara
case SCI_AUTOCGETDROPRESTOFWORD:
return ac.dropRestOfWord;
+ case SCI_REGISTERIMAGE:
+ ac.lb.SetTypeXpm(wParam, reinterpret_cast<const char **>(lParam));
+ break;
+
case SCI_CALLTIPSHOW: {
AutoCompleteCancel();
if (!ct.wCallTip.Created()) {
diff --git a/win32/PlatWin.cxx b/win32/PlatWin.cxx
index 5113ab24c..fd8ed249b 100644
--- a/win32/PlatWin.cxx
+++ b/win32/PlatWin.cxx
@@ -826,7 +826,7 @@ void ListBox::Clear() {
maxItemCharacters = 0;
}
-void ListBox::Append(char *s) {
+void ListBox::Append(char *s, int) {
Window_SendMessage(this, LB_ADDSTRING, 0, reinterpret_cast<LPARAM>(s));
unsigned int len = static_cast<unsigned int>(strlen(s));
if (maxItemCharacters < len)
@@ -871,6 +871,9 @@ void ListBox::Sort() {
// Windows keeps sorted so no need to sort
}
+void ListBox::SetTypeXpm(int, const char **) {
+}
+
Menu::Menu() : id(0) {
}