diff options
author | nyamatongwe <devnull@localhost> | 2000-07-12 07:21:46 +0000 |
---|---|---|
committer | nyamatongwe <devnull@localhost> | 2000-07-12 07:21:46 +0000 |
commit | a4cde497e296ebdeedeafe2519e75a09c6fd9488 (patch) | |
tree | ad2682d1284348952c3f35cb03eb8a1d24ff9f46 | |
parent | 9bde3adbd08a9f706655f0e0fe1c9adf685408a0 (diff) | |
download | scintilla-mirror-a4cde497e296ebdeedeafe2519e75a09c6fd9488.tar.gz |
Added John's autocompletion changes and fiddled to make autocompletion list
size better.
-rw-r--r-- | gtk/PlatGTK.cxx | 64 | ||||
-rw-r--r-- | include/Platform.h | 13 | ||||
-rw-r--r-- | src/AutoComplete.cxx | 8 | ||||
-rw-r--r-- | src/AutoComplete.h | 2 | ||||
-rw-r--r-- | src/Editor.cxx | 7 | ||||
-rw-r--r-- | src/Editor.h | 1 | ||||
-rw-r--r-- | src/ScintillaBase.cxx | 25 | ||||
-rw-r--r-- | src/ScintillaBase.h | 1 | ||||
-rw-r--r-- | win32/PlatWin.cxx | 38 |
9 files changed, 133 insertions, 26 deletions
diff --git a/gtk/PlatGTK.cxx b/gtk/PlatGTK.cxx index a3a9c27f4..3e59cf6c3 100644 --- a/gtk/PlatGTK.cxx +++ b/gtk/PlatGTK.cxx @@ -525,6 +525,7 @@ PRectangle Window::GetPosition() { } void Window::SetPosition(PRectangle rc) { +#if 0 //gtk_widget_set_uposition(id, rc.left, rc.top); GtkAllocation alloc; alloc.x = rc.left; @@ -532,6 +533,9 @@ void Window::SetPosition(PRectangle rc) { alloc.width = rc.Width(); alloc.height = rc.Height(); gtk_widget_size_allocate(id, &alloc); +#endif + gtk_widget_set_uposition(id, rc.left, rc.top); + gtk_widget_set_usize(id, rc.right - rc.left,rc.bottom - rc.top); } void Window::SetPositionRelative(PRectangle rc, Window relativeTo) { @@ -540,12 +544,15 @@ void Window::SetPositionRelative(PRectangle rc, Window relativeTo) { gdk_window_get_origin(relativeTo.id->window, &ox, &oy); gtk_widget_set_uposition(id, rc.left + ox, rc.top + oy); +#if 0 GtkAllocation alloc; alloc.x = rc.left + ox; alloc.y = rc.top + oy; alloc.width = rc.right - rc.left; alloc.height = rc.bottom - rc.top; gtk_widget_size_allocate(id, &alloc); +#endif + gtk_widget_set_usize(id, rc.right - rc.left,rc.bottom - rc.top); } PRectangle Window::GetClientPosition() { @@ -603,7 +610,7 @@ void Window::SetTitle(const char *s) { gtk_window_set_title(GTK_WINDOW(id), s); } -ListBox::ListBox() : list(0), current(0) {} +ListBox::ListBox() : list(0), current(0), desiredVisibleRows(5), maxItemCharacters(0) {} ListBox::~ListBox() {} @@ -637,13 +644,68 @@ void ListBox::Create(Window &, int) { gtk_widget_realize(id); } +void ListBox::SetFont(Font &scint_font) { + GtkStyle* style; + + style = gtk_widget_get_style(GTK_WIDGET(list)); + if (!gdk_font_equal(style->font, scint_font.GetID())) { + style = gtk_style_copy(style); + gdk_font_unref(style->font); + style->font = scint_font.GetID(); + gdk_font_ref(style->font); + gtk_widget_set_style(GTK_WIDGET(list), style); + gtk_style_unref(style); + } +} + +void ListBox::SetAverageCharWidth(int width) { + aveCharWidth = width; +} + +void ListBox::SetVisibleRows(int rows) { + desiredVisibleRows = rows; +} + +PRectangle ListBox::GetDesiredRect() { + // Before any size allocated pretend its 100 wide so not scrolled + PRectangle rc(0, 0, 100, 100); + if (id) { + GtkRequisition req; + int height; + + // First calculate height of the clist for our desired visible row count otherwise it tries to expand to the total # of rows + height = (desired_visible_rows * GTK_CLIST(list)->row_height + + desired_visible_rows + 1 + + 2 * (list->style->klass->ythickness + + GTK_CONTAINER(list)->border_width)); + gtk_widget_set_usize(GTK_WIDGET(list), -1, height); + + // Get the size of the scroller because we set usize on the window + gtk_widget_size_request(GTK_WIDGET(scroller), &req); + rc.right = req.width; + rc.bottom = req.height; + + gtk_widget_set_usize(GTK_WIDGET(list), -1, -1); + int width = maxItemCharacters; + if (width < 12) + width = 12; + rc.right = width * 8 + 16; + } + return rc; + +} + void ListBox::Clear() { gtk_clist_clear(GTK_CLIST(list)); + maxItemCharacters = 0; } void ListBox::Append(char *s) { char *szs[] = { s, 0}; gtk_clist_append(GTK_CLIST(list), szs); + size_t len = strlen(s); + if (maxItemCharacters < len) + maxItemCharacters = len; } int ListBox::Length() { diff --git a/include/Platform.h b/include/Platform.h index 785bc8923..6fff59afa 100644 --- a/include/Platform.h +++ b/include/Platform.h @@ -328,7 +328,7 @@ public: void Show(bool show=true); void InvalidateAll(); void InvalidateRectangle(PRectangle rc); - void SetFont(Font &font); + virtual void SetFont(Font &font); enum Cursor { cursorText, cursorArrow, cursorUp, cursorWait, cursorHoriz, cursorVert, cursorReverseArrow }; void SetCursor(Cursor curs); void SetTitle(const char *s); @@ -345,14 +345,17 @@ class ListBox : public Window { WindowID scroller; int current; #endif + int desiredVisibleRows; + size_t maxItemCharacters; + unsigned int aveCharWidth; public: ListBox(); virtual ~ListBox(); - ListBox &operator=(WindowID id_) { - id = id_; - return *this; - } void Create(Window &parent, int ctrlID); + virtual void SetFont(Font &font); + void SetAverageCharWidth(int width); + void SetVisibleRows(int rows); + PRectangle GetDesiredRect(); void Clear(); void Append(char *s); int Length(); diff --git a/src/AutoComplete.cxx b/src/AutoComplete.cxx index d45ab27a6..f9dbd4d67 100644 --- a/src/AutoComplete.cxx +++ b/src/AutoComplete.cxx @@ -11,7 +11,6 @@ #include "AutoComplete.h" AutoComplete::AutoComplete() { - lb = 0; active = false; posStart = 0; strcpy(stopChars, ""); @@ -54,8 +53,7 @@ char AutoComplete::GetSeparator() { return separator; } -int AutoComplete::SetList(const char *list) { - int maxStrLen = 12; +void AutoComplete::SetList(const char *list) { lb.Clear(); char *words = new char[strlen(list) + 1]; if (words) { @@ -66,18 +64,15 @@ int AutoComplete::SetList(const char *list) { if (words[i] == separator) { words[i] = '\0'; lb.Append(startword); - maxStrLen = Platform::Maximum(maxStrLen, strlen(startword)); startword = words + i + 1; } } if (startword) { lb.Append(startword); - maxStrLen = Platform::Maximum(maxStrLen, strlen(startword)); } delete []words; } lb.Sort(); - return maxStrLen; } void AutoComplete::Show() { @@ -88,7 +83,6 @@ void AutoComplete::Show() { void AutoComplete::Cancel() { if (lb.Created()) { lb.Destroy(); - lb = 0; active = false; } } diff --git a/src/AutoComplete.h b/src/AutoComplete.h index 96d061f50..37795fce6 100644 --- a/src/AutoComplete.h +++ b/src/AutoComplete.h @@ -35,7 +35,7 @@ public: char GetSeparator(); // The list string contains a sequence of words separated by the separator character - int SetList(const char *list); + void SetList(const char *list); void Show(); void Cancel(); diff --git a/src/Editor.cxx b/src/Editor.cxx index 29037474e..487a4c4f7 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -116,6 +116,7 @@ Editor::~Editor() { } void Editor::Finalise() { + CancelModes(); } void Editor::DropGraphics() { @@ -1950,6 +1951,10 @@ void Editor::LineTranspose() { } } +void Editor::CancelModes() { + SetEmptySelection(currentPos); +} + int Editor::KeyCommand(UINT iMessage) { Point pt = LocationFromPosition(currentPos); @@ -2069,7 +2074,7 @@ int Editor::KeyCommand(UINT iMessage) { break; case SCI_CANCEL: // Cancel any modes - handled in subclass // Also unselect text - SetEmptySelection(currentPos); + CancelModes(); break; case SCI_DELETEBACK: DelCharBack(); diff --git a/src/Editor.h b/src/Editor.h index c39157747..4f42c80a0 100644 --- a/src/Editor.h +++ b/src/Editor.h @@ -246,6 +246,7 @@ protected: // ScintillaBase subclass needs access to much of Editor void PageMove(int direction, bool extend=false); void ChangeCaseOfSelection(bool makeUpperCase); void LineTranspose(); + virtual void CancelModes(); virtual int KeyCommand(UINT iMessage); virtual int KeyDefault(int /* key */, int /*modifiers*/); int KeyDown(int key, bool shift, bool ctrl, bool alt); diff --git a/src/ScintillaBase.cxx b/src/ScintillaBase.cxx index bf1b28394..d381b6739 100644 --- a/src/ScintillaBase.cxx +++ b/src/ScintillaBase.cxx @@ -49,6 +49,7 @@ ScintillaBase::~ScintillaBase() { } void ScintillaBase::Finalise() { + Editor::Finalise(); popup.Destroy(); } @@ -162,7 +163,7 @@ int ScintillaBase::KeyCommand(UINT iMessage) { } void ScintillaBase::AutoCompleteStart(int lenEntered, const char *list) { - //Platform::DebugPrintf("AutoCOmplete %s\n", list); + //Platform::DebugPrintf("AutoComplete %s\n", list); ct.CallTipCancel(); ac.Start(wDraw, idAutoComplete, currentPos, lenEntered); @@ -170,7 +171,6 @@ void ScintillaBase::AutoCompleteStart(int lenEntered, const char *list) { PRectangle rcClient = GetClientRectangle(); Point pt = LocationFromPosition(currentPos-lenEntered); - //Platform::DebugPrintf("Auto complete %x\n", lbAutoComplete); int heightLB = 100; int widthLB = 100; if (pt.x >= rcClient.right - widthLB) { @@ -193,16 +193,18 @@ void ScintillaBase::AutoCompleteStart(int lenEntered, const char *list) { rcac.right = rcac.left + widthLB; rcac.bottom = Platform::Minimum(rcac.top + heightLB, rcClient.bottom); ac.lb.SetPositionRelative(rcac, wMain); - ac.lb.SetFont(vs.styles[0].font); + ac.lb.SetFont(vs.styles[STYLE_DEFAULT].font); + ac.lb.SetAverageCharWidth(vs.styles[STYLE_DEFAULT].aveCharWidth); - int maxStrLen = ac.SetList(list); + ac.SetList(list); // Fiddle the position of the list so it is right next to the target and wide enough for all its strings - PRectangle rcList = ac.lb.GetPosition(); + PRectangle rcList = ac.lb.GetDesiredRect(); int heightAlloced = rcList.bottom - rcList.top; + widthLB = Platform::Maximum(widthLB, rcList.right - rcList.left); // Make an allowance for large strings in list rcList.left = pt.x - 5; - rcList.right = rcList.left + Platform::Maximum(widthLB, maxStrLen * 8 + 16); + rcList.right = rcList.left + widthLB; if (pt.y >= rcClient.bottom - heightLB && // Wont fit below. pt.y >= (rcClient.bottom + rcClient.top) / 2) { // and there is more room above. rcList.top = pt.y - heightAlloced; @@ -249,7 +251,7 @@ void ScintillaBase::AutoCompleteChanged(char ch) { void ScintillaBase::AutoCompleteCompleted() { int item = ac.lb.GetSelection(); - char selected[200]; + char selected[1000]; if (item != -1) { ac.lb.GetValue(item, selected, sizeof(selected)); } @@ -278,9 +280,14 @@ void ScintillaBase::ContextMenu(Point pt) { popup.Show(pt, wMain); } -void ScintillaBase::ButtonDown(Point pt, unsigned int curTime, bool shift, bool ctrl, bool alt) { +void ScintillaBase::CancelModes() { AutoCompleteCancel(); ct.CallTipCancel(); + Editor::CancelModes(); +} + +void ScintillaBase::ButtonDown(Point pt, unsigned int curTime, bool shift, bool ctrl, bool alt) { + CancelModes(); Editor::ButtonDown(pt, curTime, shift, ctrl, alt); } @@ -364,7 +371,7 @@ LRESULT ScintillaBase::WndProc(UINT iMessage, WPARAM wParam, LPARAM lParam) { if (!ct.wCallTip.Created()) { PRectangle rc = ct.CallTipStart(currentPos, LocationFromPosition(wParam), reinterpret_cast<char *>(lParam), - vs.styles[0].fontName, vs.styles[0].size); + vs.styles[STYLE_DEFAULT].fontName, vs.styles[STYLE_DEFAULT].size); // If the call-tip window would be out of the client // space, adjust so it displays above the text. PRectangle rcClient = GetClientRectangle(); diff --git a/src/ScintillaBase.h b/src/ScintillaBase.h index a7aefd8bc..2e7402a1c 100644 --- a/src/ScintillaBase.h +++ b/src/ScintillaBase.h @@ -47,6 +47,7 @@ protected: virtual void AddCharUTF(char *s, unsigned int len); void Command(int cmdId); + virtual void CancelModes(); virtual int KeyCommand(UINT iMessage); void AutoCompleteStart(int lenEntered, const char *list); diff --git a/win32/PlatWin.cxx b/win32/PlatWin.cxx index bea215566..87f90cfa1 100644 --- a/win32/PlatWin.cxx +++ b/win32/PlatWin.cxx @@ -698,7 +698,7 @@ HINSTANCE Window::GetInstance() { ::GetWindowLong(id,GWL_HINSTANCE)); } -ListBox::ListBox() { +ListBox::ListBox() : desiredVisibleRows(5), maxItemCharacters(0), aveCharWidth(8) { } ListBox::~ListBox() { @@ -712,12 +712,45 @@ void ListBox::Create(Window &parent, int ctrlID) { parent.GetInstance(), 0); } +void ListBox::SetFont(Font &font) { + Window::SetFont(font); +} + +void ListBox::SetAverageCharWidth(int width) { + aveCharWidth = width; +} + +void ListBox::SetVisibleRows(int rows) { + desiredVisibleRows = rows; +} + +PRectangle ListBox::GetDesiredRect() { + PRectangle rcDesired = GetPosition(); + int itemHeight = SendMessage(LB_GETITEMHEIGHT, 0); + int rows = Length(); + if ((rows == 0) || (rows > desiredVisibleRows)) + rows = desiredVisibleRows; + // The +6 allows for borders + rcDesired.bottom = rcDesired.top + 6 + itemHeight * rows; + int width = maxItemCharacters; + if (width < 12) + width = 12; + rcDesired.right = rcDesired.left + width * (aveCharWidth+aveCharWidth/3); + if (Length() > rows) + rcDesired.right = rcDesired.right + GetSystemMetrics(SM_CXVSCROLL); + return rcDesired; +} + void ListBox::Clear() { SendMessage(LB_RESETCONTENT); + maxItemCharacters = 0; } void ListBox::Append(char *s) { SendMessage(LB_ADDSTRING, 0, reinterpret_cast<LPARAM>(s)); + size_t len = strlen(s); + if (maxItemCharacters < len) + maxItemCharacters = len; } int ListBox::Length() { @@ -733,7 +766,8 @@ int ListBox::GetSelection() { } int ListBox::Find(const char *prefix) { - return SendMessage(LB_FINDSTRING, 0, reinterpret_cast<LPARAM>(prefix)); + return SendMessage(LB_FINDSTRING, static_cast<WPARAM>(-1), + reinterpret_cast<LPARAM>(prefix)); } void ListBox::GetValue(int n, char *value, int len) { |