summaryrefslogtreecommitdiffstats
path: root/kate/part/katecodecompletion.h
blob: 34d6205991b223de071629e7847f2621d1e7bf43 (plain)
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
163
164
/* This file is part of the KDE libraries

   Copyright (C) 2001 Joseph Wenninger <jowenn@kde.org>
   Copyright (C) 2002 John Firebaugh <jfirebaugh@kde.org>
   Copyright (C) 2001 by Victor Röder <Victor_Roeder@GMX.de>
   Copyright (C) 2002 by Roberto Raggi <roberto@kdevelop.org>

   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.

   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; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
*/

/******** Partly based on the ArgHintWidget of Qt3 by Trolltech AS *********/
/* Trolltech doesn't mind, if we license that piece of code as LGPL, because there isn't much
 * left from the desigener code */


#ifndef __KateCodeCompletion_H__
#define __KateCodeCompletion_H__

#include <ktexteditor/codecompletioninterface.h>

#include <tqvaluelist.h>
#include <tqstringlist.h>
#include <tqlabel.h>
#include <tqframe.h>
#include <tqmap.h>
#include <tqintdict.h>

class KateView;
class KateArgHint;
class KateCCListBox;

class TQLayout;
class TQVBox;

class KateCodeCompletionCommentLabel : public QLabel
{
  Q_OBJECT

  public:
    KateCodeCompletionCommentLabel( TQWidget* parent, const TQString& text) : TQLabel( parent, "toolTipTip",
             WStyle_StaysOnTop | WStyle_Customize | WStyle_NoBorder | WStyle_Tool | WX11BypassWM )
    {
        setMargin(1);
        setIndent(0);
        setAutoMask( false );
        setFrameStyle( TQFrame::Plain | TQFrame::Box );
        setLineWidth( 1 );
        setAlignment( AlignAuto | AlignTop );
        polish();
        setText(text);
        adjustSize();
    }
};

class KateCodeCompletion : public QObject
{
  Q_OBJECT

  friend class KateViewInternal;

  public:
    KateCodeCompletion(KateView *view);
    ~KateCodeCompletion();

    bool codeCompletionVisible ();

    void showArgHint(
        TQStringList functionList, const TQString& strWrapping, const TQString& strDelimiter );
    void showCompletionBox(
        TQValueList<KTextEditor::CompletionEntry> entries, int offset = 0, bool casesensitive = true );
    bool eventFilter( TQObject* o, TQEvent* e );

    void handleKey (TQKeyEvent *e);

  public slots:
    void slotCursorPosChanged();
    void showComment();
    void updateBox () { updateBox(false); }

  signals:
    void completionAborted();
    void completionDone();
    void argHintHidden();
    void completionDone(KTextEditor::CompletionEntry);
    void filterInsertString(KTextEditor::CompletionEntry*,TQString *);

  private:
    void doComplete();
    void abortCompletion();
    void complete( KTextEditor::CompletionEntry );
    void updateBox( bool newCoordinate );

    KateArgHint*    m_pArgHint;
    KateView*       m_view;
    TQVBox*          m_completionPopup;
    KateCCListBox*       m_completionListBox;
    TQValueList<KTextEditor::CompletionEntry> m_complList;
    uint            m_lineCursor;
    uint            m_colCursor;
    int             m_offset;
    bool            m_caseSensitive;
    KateCodeCompletionCommentLabel* m_commentLabel;
};

class KateArgHint: public QFrame
{
  Q_OBJECT

  public:
      KateArgHint( KateView* =0, const char* =0 );
      virtual ~KateArgHint();

      virtual void setCurrentFunction( int );
      virtual int currentFunction() const { return m_currentFunction; }

      void setArgMarkInfos( const TQString&, const TQString& );

      virtual void addFunction( int, const TQString& );
      TQString functionAt( int id ) const { return m_functionMap[ id ]; }

      virtual void show();
      virtual void adjustSize();
      virtual bool eventFilter( TQObject*, TQEvent* );

  signals:
      void argHintHidden();
      void argHintCompleted();
      void argHintAborted();

  public slots:
      virtual void reset( int, int );
      virtual void cursorPositionChanged( KateView*, int, int );

  private slots:
      void slotDone(bool completed);

  private:
      TQMap<int, TQString> m_functionMap;
      int m_currentFunction;
      TQString m_wrapping;
      TQString m_delimiter;
      bool m_markCurrentFunction;
      int m_currentLine;
      int m_currentCol;
      KateView* editorView;
      TQIntDict<TQLabel> labelDict;
      TQLayout* layout;
};

#endif

// kate: space-indent on; indent-width 2; replace-tabs on;