This file is indexed.

/usr/include/Nux-4.0/Nux/TextEntry.h is in libnux-4.0-dev 4.0.8+17.10.20170922-0ubuntu1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
#ifndef TEXTENTRY_H
#define TEXTENTRY_H

// Heavily inspired from google gadget code
/*
 * Copyright 2011-2013 Canonical Ltd.
 * Copyright 2010 Inalogic Inc.
 *
 * This program is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License, as
 * published by the  Free Software Foundation; either version 2.1 or 3.0
 * of the License.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranties of
 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
 * PURPOSE.  See the applicable version of the GNU Lesser General Public
 * License for more details.
 *
 * You should have received a copy of both the GNU Lesser General Public
 * License along with this program. If not, see <http://www.gnu.org/licenses/>
 *
 * Copyright 2008 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0(the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "cairo/cairo.h"
#include "pango/pango.h"
#include "pango/pangocairo.h"
#include "NuxGraphics/CairoGraphics.h"

namespace nux
{
  class CairoGraphics;
  class IBusIMEContext;

  class CairoFont
  {
  public:
    enum Style {
      STYLE_NORMAL,
      STYLE_ITALIC
    };

    /**
     * Enum used to specify font weight.
     */
    enum Weight {
      WEIGHT_NORMAL,
      WEIGHT_BOLD
    };

    /**
     * Constructor for CairoFont. Takes a PangoFontDescription object and its
     * ownership. Will free the PangoFontDescription object on destruction.
     */
    CairoFont(const std::string &family,
      /*PangoFontDescription *font,*/
      double size,
      Style style,
      Weight weight);

    virtual ~CairoFont();

    virtual Style GetStyle() const {return style_;}
    virtual Weight GetWeight() const {return weight_;}
    virtual double GetPointSize() const {return size_;}

    virtual void Destroy() {delete this;}

    const PangoFontDescription *GetFontDescription() const {return font_;}

  private:
    PangoFontDescription *font_;
    double size_;
    Style style_;
    Weight weight_;
  };

  class TextEntry: public View
  {
    NUX_DECLARE_OBJECT_TYPE(TextEntry, View);
  public:
    TextEntry(const char* text, NUX_FILE_LINE_PROTO);
    ~TextEntry();

    Area* FindAreaUnderMouse(const Point& mouse_position, NuxEventType event_type);
    virtual void Draw(GraphicsEngine& graphics_engine, bool force_draw);
    virtual void DrawContent(GraphicsEngine& graphics_engine, bool force_draw);

    void PreLayoutManagement();
    long PostLayoutManagement(long layoutResult);

    //  Receivers

    void RecvMouseDoubleClick(int x, int y, unsigned long button_flags, unsigned long key_flags);
    void RecvMouseUp(int x, int y, unsigned long button_flags, unsigned long key_flags);
    void RecvMouseDown(int x, int y, unsigned long button_flags, unsigned long key_flags);
    void RecvMouseDrag(int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags);
    void RecvMouseEnter(int x, int y, unsigned long button_flags, unsigned long key_flags);
    void RecvMouseLeave(int x, int y, unsigned long button_flags, unsigned long key_flags);
    void RecvKeyEvent(
      unsigned long    eventType  ,   /*event type*/
      unsigned long    keysym     ,   /*event keysym*/
      unsigned long    state      ,   /*event state*/
      const char*     character  ,   /*character*/
      unsigned short   keyCount       /*key repeat count*/);

    void RecvStartKeyFocus();
    void RecvEndKeyFocus();

    bool _size_match_text;
    BaseTexture *_texture2D;

    void MainDraw();
    void ProcessMouseEvent(int event_type, int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags);
    void ProcessKeyEvent   (
      unsigned long    eventType  ,   /*event type*/
      unsigned long    keysym     ,   /*event keysym*/
      unsigned long    state      ,   /*event state*/
      const char*     character  ,   /*character*/
      unsigned short   keyCount       /*key repeat count*/);

    void FocusInx();
    void FocusOutx();

    //! Text changed signal
    /*!
        This signal is emitted when the text has changed.
    */
    sigc::signal <void, TextEntry*> text_changed;
    sigc::signal <void> activated;
    sigc::signal <void, int> cursor_moved;

    void SetText(const char* text);
    std::string const& GetText() const;
    std::string GetTextSelection() const;

    void SetCompletion(const char* text); // Should use std::string, does not for consistancy
    std::string const& GetCompletion() const;

    void SetCompletionColor(const Color& color);
    Color const& GetCompletionColor() const;

    void SetTextColor(const Color& color);
    Color GetTextColor() const;
    void SetFontFamily(const char* font);
    void SetFontSize(double font_size);
    void SetFontOptions(const cairo_font_options_t* options);

    /** Select text between start and end. */
    void Select(int start, int end);
    /** Select all text */
    void SelectAll();

    CairoGraphics::Alignment GetAlign() const;
    void SetAlign(CairoGraphics::Alignment align);

    bool im_active();
    bool im_running();

    void MoveCursorToLineStart();
    void MoveCursorToLineEnd();

    void SetToggleCursorVisibilityOnKeyFocus(bool b);
    bool GetToggleCursorVisibilityOnKeyFocus() const;

    /*!
        When the text entry is in single line mode, the keyboard arrow up/down may be used
        to navigate to another view. If the parameter of this function is set to true then
        the text entry returns false on NUX_VK_UP in InspectKeyEvent(). This allows the parent of the
        text entry to look for another view that can receive the keyboard focus. The default value is true.\n
        In multi-line mode, keyboard arrow up/down are used to navigate in the text.

        @param b True to allow the key navigation to move away from the text entry on NUX_VK_UP.
    */
    void SetLoseKeyFocusOnKeyNavDirectionUp(bool b);

    bool GetLoseKeyFocusOnKeyNavDirectionUp() const;

    /*!
        When the text entry is in single line mode, the keyboard arrow up/down may be used
        to navigate to another view. If the parameter of this function is set to true then
        the text entry returns false on NUX_VK_DOWN in InspectKeyEvent(). This allows the parent of the
        text entry to look for another view that can receive the keyboard focus.  The default value is true.\n
        In multi-line mode, keyboard arrow up/down are used to navigate in the text.

        @param b True to allow the key navigation to move away from the text entry on NUX_VK_DOWN.
    */
    void SetLoseKeyFocusOnKeyNavDirectionDown(bool b);

    bool GetLoseKeyFocusOnKeyNavDirectionDown() const;

    /*!
        Return True if the text has been modified after the text entry has received the keyboard focus.\n
        If the text entry already has characters typed in and it gets the keyboard focus, this function return false
        while the text has not been modified. The text can be modified either by typing new characters or addind text
        through TextEntry::SetText, TextEntry::EnterText, TextEntry::DeleteText.
        If this text entry does not have the keyboard focus, this function returns false.

        @return True after the text entry has received the keyboard focus and text has been typed in.
    */
    bool IsInTextInputMode() const;

    /*!
        Insert text at current caret position.
    */
    void EnterText(const char* str);

    /*!
        Delete text in a specified range, in number of characters.
    */
    void DeleteText(int start, int end);

    void SetPasswordMode(bool visible);
    void SetVisibility(bool visible);
    void SetPasswordChar(const char* c);
    bool PasswordMode() const;
    std::string GetPasswordChar();

    void PreeditStarted();
    void UpdatePreedit(std::string const& preedit, int cursor);
    void UpdatePreeditAttribs(PangoAttrList* list);
    void ClearPreedit();

  protected:
    bool _block_focus; // used to selectively ignore focus keyevents

    virtual void GeometryChanged(bool position_has_changed, bool size_has_changed);

    /**
     * Enum used to specify different motion types.
     */
    enum MovementStep {
      VISUALLY,
      WORDS,
      DISPLAY_LINES,
      DISPLAY_LINE_ENDS,
      PAGES,
      BUFFER
    };

    /**
     * Enum used for the search state of the compose list
     */
    enum SearchState {
      NO_MATCH,
      PARTIAL,
      MATCH
    };

    /** Checks for possible composition sequences */
    bool IsInitialCompositionKeySym(unsigned long keysym) const;
    bool IsInCompositionMode() const;
    bool HandleComposition(unsigned long keysym);
    SearchState GetCompositionForList(std::vector<unsigned long> const& input, std::string& composition);

    void QueueTextDraw();
    /** Remove the cached layout. */
    void ResetLayout();
    /**
     * Create pango layout on-demand. If the layout is not changed, return the
     * cached one.
     */
    PangoLayout* EnsureLayout();
    /** Create a new layout containning current edit content */
    PangoLayout* CreateLayout();
    /** Create cairo canvas on-demand. */
    CairoGraphics* EnsureCanvas();
    /** Adjust the scroll information */
    void AdjustScroll();
    /**
     * Send out a request to refresh all informations of the edit control
     * and queue a draw request.
     * If @c relayout is true then the layout will be regenerated.
     * */
    void QueueRefresh(bool relayout, bool adjust_scroll);
    /** Reset the input method context */
    void ResetImContext();
    /** Reset preedit text */
    void ResetPreedit();
    /** Send out a request to blink the cursor if necessary */
    void QueueCursorBlink();
    static bool CursorBlinkCallback(TextEntry* data);

    void ShowCursor();
    void HideCursor();

    /** Draw the Cursor to the canvas */
    void DrawCursor(CairoGraphics* canvas);
    /** Draw the text to the canvas */
    virtual void DrawText(CairoGraphics* canvas);

    void GetCursorRects(Rect* strong, Rect* weak);

    void UpdateCursorRegion();

    void UpdateSelectionRegion();

    /** Move cursor */
    void MoveCursor(MovementStep step, int count, bool extend_selection);
    /** Move cursor visually, meaning left or right */
    int MoveVisually(int current_pos, int count);
    /** Move cursor in words */
    int MoveWords(int current_pos, int count);
    /** Move cursor in display lines */
    int MoveDisplayLines(int current_pos, int count);
    /** Move cursor in pages */
    int MovePages(int current_pos, int count);
    /** Move cursor to the beginning or end of a display line */
    int MoveLineEnds(int current_pos, int count);

    /** Set the current cursor offset, in number of characters. */
    void SetCursor(int cursor);
    /** Get the most reasonable character offset according to the pixel
     * coordinate in the layout */
    int XYToTextIndex(int x, int y);
    /** Get the offset range that is currently selected,in number of characters.*/
    bool GetSelectionBounds(int* start, int* end) const;
    /** Set the offest range that should be selected, in number of characters. */
    void SetSelectionBounds(int selection_bound, int cursor);

    /** Convert index in text_ into index in layout text. */
    int TextIndexToLayoutIndex(int text_index, bool consider_preedit_cursor);

    /** Convert index in layout text into index in text_. */
    int LayoutIndexToTextIndex(int layout_index);

    /** Get char length at index, in number of bytes. */
    int GetCharLength(int index);

    /** Get previous char length before index, in number of bytes. */
    int GetPrevCharLength(int index);

    /** Select the current word under cursor */
    void SelectWord();
    /** Select the current display line under cursor */
    void SelectLine();
    /** Delete the text that is currently selected */
    void DeleteSelection();

    /** Cut the current selected text to the clipboard */
    virtual void CutClipboard();
    /** Copy the current selected text to the clipboard */
    virtual void CopyClipboard();
    /** Paste the text in the clipboard to current offset */
    virtual void PasteClipboard();
#if defined(NUX_OS_LINUX)
    /** Paste the text in the primary clipboard to current offset */
    virtual void PastePrimaryClipboard();
#endif
    /** Delete a character before the offset of the cursor */
    void BackSpace(MovementStep step);
    /** Delete a character at the offset of the cursor */
    void Delete(MovementStep step);
    /** Switch between the overwrite mode and the insert mode*/
    void ToggleOverwrite();

    /** Gets the color of selection background. */
    Color GetSelectionBackgroundColor();
    /** Gets the color of selection text. */
    Color GetSelectionTextColor();

    /**
     * Gets the cursor location in pango layout. The unit is pixel.
     */
    void GetCursorLocationInLayout(int* strong_x, int* strong_y, int* strong_height,
                                   int* weak_x, int* weak_y, int* weak_height);

    /** The CairoCanvas which hold cairo_t inside */
    CairoGraphics* canvas_;

    /** The cached Pango Layout */
    PangoLayout* cached_layout_;

    /** The text content of the edit control */
    std::string text_;
    /** The preedit text of the edit control */
    std::string preedit_;
    /** Attribute list of the preedit text */
    PangoAttrList* preedit_attrs_;

    /**
     *  The character that should be displayed in invisible mode.
     *  If this is empty, then the edit control is visible
     */
    std::string password_char_;

    /** The completion string */
    std::string completion_;

    /** The completion colour */
    Color completion_color_;

    /** Last time of mouse double click event. */
    unsigned long long last_dblclick_time_;

    /** The current cursor position in number of bytes. */
    int cursor_;
    /**
     * The preedit cursor position within the preedit string,
     * in number of bytes.
     */
    int preedit_cursor_;
    /**
     * The current selection bound in number of bytes,
     * range between cursor_ and selection_bound_ are selected.
     */
    int selection_bound_;

    /** X offset of current scroll, in pixels */
    int scroll_offset_x_;
    /** Y offset of current scroll, in pixels */
    int scroll_offset_y_;
    /** Timer id of cursor blink callback */
    int cursor_blink_timer_;
    /**
     * Indicates the status of cursor blinking,
     * 0 means hide cursor
     * otherwise means show cursor.
     * The maximum value would be 2, and decrased by one in each cursor blink
     * callback, then there would be 2/3 visible time and 1/3 invisible time.
     */
    int cursor_blink_status_;

    /*! Whether the text is visible, or its characters are masked by a default char (password mode). */
    bool visible_;
    /** Whether the edit control is focused */
    bool focused_;
    /** Whether the input method should be reset */
    bool need_im_reset_;
    /** Whether the keyboard in overwrite mode */
    bool overwrite_;
    /** Whether the button click should select words */
    bool select_words_;
    /** Whether the button click should select lines */
    bool select_lines_;
    /** Whether the left button is pressed */
    bool button_;
    /** Whether the text should be bold */
    bool bold_;
    /** Whether the text should be underlined */
    bool underline_;
    /** Whether the text should be struck-out */
    bool strikeout_;
    /** Whether the text should be italic */
    bool italic_;
    /** Whether the text could be shown in multilines */
    bool multiline_;
    /** Whether the text should be wrapped */
    bool wrap_;
    /** whether the cursor should be displayed */
    bool cursor_visible_;
    /** whether the edit control is readonly */
    bool readonly_;
    /**
     * Indicates if the content of the edit control has been modified
     * since last draw
     */
    bool content_modified_;

    /** Indicates if the selection region has been changed since last draw. */
    bool selection_changed_;

    /** Indicates if the cursor position has been moved since last draw. */
    bool cursor_moved_;

    /** Indicates if the canvas cache needs updating. */
    bool update_canvas_;

    /** The font family of the text */
    std::string font_family_;
    /** The font size of the text */
    double font_size_;

    cairo_font_options_t* font_options_;
    double font_dpi_;

    /** The text color of the edit control */
    Color _text_color;

    CairoGraphics::Alignment align_;

#if defined(USE_X11)
    Cursor caret_cursor_;
#endif

    std::list<Rect> last_selection_region_;
    std::list<Rect> selection_region_;
    std::list<Rect> last_cursor_region_;
    std::list<Rect> cursor_region_;

#if defined(USE_X11)
    IBusIMEContext* ime_;
    friend class IBusIMEContext;
#endif

    bool ime_active_;

    bool text_input_mode_;    //!< Transient state of the TextEntry. \sa IsInTextInputMode.
    bool key_nav_mode_;

    bool lose_key_focus_on_key_nav_direction_up_;
    bool lose_key_focus_on_key_nav_direction_down_;
    bool cursor_visible_on_key_focus_only_;

    std::vector<unsigned long> composition_list_;

    virtual bool InspectKeyEvent(Event const& event);
    virtual bool InspectKeyEvent(unsigned int eventType, unsigned int keysym, const char* character);
};
}

#endif // TEXTENTRY_H