Browse Source

Text selection in chat

* Remove fancy stuff from background
* Improve text windows
* More improvements to textedit
Eduardo Bart 8 years ago
parent
commit
c28596292f

+ 0
- 62
modules/client_background/background.otui View File

@@ -9,68 +9,6 @@ Panel
9 9
   anchors.bottom: parent.bottom
10 10
   margin-top: 1
11 11
   focusable: false
12
-  @onSetup: |
13
-    scheduleEvent(function()
14
-      local count = 0
15
-      cycleEvent(function()
16
-        if count > 360 then return end
17
-        self:setRotation(count)
18
-        count = count + 5
19
-      end, 10)
20
-    end, 10)
21
-
22
-  UIParticles
23
-    anchors.fill: parent
24
-    effect: background-effect
25
-    reference-pos: 0.5 0.25
26
-
27
-  Label
28
-    text: :O Just For Fun LOL ^.^
29
-    font: sans-bold-16px
30
-    color: black
31
-    background: #ffffff60
32
-    anchors.top: parent.top
33
-    anchors.horizontalCenter: parent.horizontalCenter
34
-    margin-left: 10
35
-    margin-top: 40
36
-    height: 24
37
-    rotation: -15
38
-    @onSetup: |
39
-      local count = 0
40
-      cycleEvent(function()
41
-        local text = ':O Just For Fun LOL ^.^'
42
-        self:setText(string.sub(text, 0, count))
43
-        if count > #text + 10 then count = 0 end
44
-        count = count + 1
45
-      end, 100)
46
-
47
-  Label
48
-    text: PLEASE REMOVE THAT SHIT!
49
-    font: sans-bold-16px
50
-    color: black
51
-    background: #ffffff60
52
-    anchors.bottom: parent.bottom
53
-    anchors.horizontalCenter: parent.horizontalCenter
54
-    margin-left: 10
55
-    margin-bottom: 40
56
-    height: 24
57
-    rotation: 15
58
-    visible: false
59
-    @onSetup: scheduleEvent(function() self:show() end, 4000)
60
-
61
-  Label
62
-    text: WTF IS WRONG WITH THIS BACKGROUND?
63
-    font: sans-bold-16px
64
-    color: pink
65
-    background: #ffffff99
66
-    anchors.top: parent.top
67
-    anchors.right: parent.right
68
-    margin-left: 10
69
-    margin-top: 80
70
-    height: 24
71
-    rotation: 10
72
-    visible: false
73
-    @onSetup: scheduleEvent(function() self:show() end, 8000)
74 12
 
75 13
   UILabel
76 14
     id: clientVersionLabel

+ 19
- 3
modules/game_console/console.lua View File

@@ -87,6 +87,22 @@ function init()
87 87
   consoleTabBar:setTabSpacing(-1)
88 88
   channels = {}
89 89
 
90
+  consolePanel.onKeyPress = function(self, keyCode, keyboardModifiers)
91
+    if not (keyboardModifiers == KeyboardCtrlModifier and keyCode == KeyC) then return false end
92
+
93
+    local tab = consoleTabBar:getCurrentTab()
94
+    if not tab then return false end
95
+
96
+    local consoleBuffer = tab.tabPanel:getChildById('consoleBuffer')
97
+    if not consoleBuffer then return false end
98
+
99
+    local consoleLabel = consoleBuffer:getFocusedChild()
100
+    if not consoleLabel or not consoleLabel:hasSelection() then return false end
101
+
102
+    g_window.setClipboardText(consoleLabel:getSelection())
103
+    return true
104
+  end
105
+
90 106
   defaultTab = addTab(tr('Default'), true)
91 107
   serverTab = addTab(tr('Server Log'), false)
92 108
 
@@ -355,16 +371,16 @@ function addTabText(text, speaktype, tab, creatureName)
355 371
   local panel = consoleTabBar:getTabPanel(tab)
356 372
   local consoleBuffer = panel:getChildById('consoleBuffer')
357 373
   local label = g_ui.createWidget('ConsoleLabel', consoleBuffer)
358
-  label:setId('consoleLabel' .. panel:getChildCount())
374
+  label:setId('consoleLabel' .. consoleBuffer:getChildCount())
359 375
   label:setText(text)
360 376
   label:setColor(speaktype.color)
361 377
   consoleTabBar:blinkTab(tab)
362 378
 
363 379
   -- Overlay for consoleBuffer which shows highlighted words only
364 380
   local consoleBufferHighlight = panel:getChildById('consoleBufferHighlight')
365
-  local labelHighlight = g_ui.createWidget('ConsoleLabel', consoleBufferHighlight)
381
+  local labelHighlight = g_ui.createWidget('ConsolePhantomLabel', consoleBufferHighlight)
366 382
 
367
-  labelHighlight:setId('consoleLabel' .. panel:getChildCount())
383
+  labelHighlight:setId('consoleLabel' .. consoleBufferHighlight:getChildCount())
368 384
   labelHighlight:setColor("#1f9ffe")
369 385
 
370 386
   local player = g_game.getLocalPlayer()

+ 14
- 1
modules/game_console/console.otui View File

@@ -1,10 +1,22 @@
1
-ConsoleLabel < UILabel
1
+ConsoleLabel < UITextEdit
2 2
   font: verdana-11px-antialised
3 3
   height: 14
4 4
   color: yellow
5 5
   margin-left: 2
6 6
   text-wrap: true
7 7
   text-auto-resize: true
8
+  selection-color: #111416
9
+  selection-background-color: #999999
10
+
11
+ConsolePhantomLabel < UILabel
12
+  font: verdana-11px-antialised
13
+  height: 14
14
+  color: yellow
15
+  margin-left: 2
16
+  text-wrap: true
17
+  text-auto-resize: true
18
+  selection-color: #111416
19
+  selection-background-color: #999999
8 20
 
9 21
 ConsoleTabBar < TabBar
10 22
 ConsoleTabBarPanel < TabBarPanel
@@ -168,3 +180,4 @@ Panel
168 180
     margin-left: 6
169 181
     margin-bottom: 6
170 182
     shift-navigation: true
183
+    max-length: 255

+ 0
- 1
modules/game_textwindow/textwindow.lua View File

@@ -40,7 +40,6 @@ function onGameEditText(id, itemId, maxLength, text, writter, time)
40 40
   textEdit:setText(text)
41 41
   textEdit:setEditable(writeable)
42 42
   textEdit:setCursorVisible(writeable)
43
-  textEdit:wrapText()
44 43
   
45 44
   local desc = ''
46 45
   if #writter > 0 then

+ 1
- 0
modules/game_textwindow/textwindow.otui View File

@@ -25,6 +25,7 @@ TextWindow < MainWindow
25 25
     anchors.right: textScroll.left
26 26
     anchors.bottom: textScroll.bottom
27 27
     vertical-scrollbar: textScroll
28
+    text-wrap: true
28 29
 
29 30
   VerticalScrollBar
30 31
     id: textScroll

+ 0
- 2
src/framework/CMakeLists.txt View File

@@ -360,8 +360,6 @@ if(FRAMEWORK_GRAPHICS)
360 360
         ${CMAKE_CURRENT_LIST_DIR}/ui/uimanager.h
361 361
         ${CMAKE_CURRENT_LIST_DIR}/ui/uiparticles.cpp
362 362
         ${CMAKE_CURRENT_LIST_DIR}/ui/uiparticles.h
363
-        ${CMAKE_CURRENT_LIST_DIR}/ui/uirichtext.cpp
364
-        ${CMAKE_CURRENT_LIST_DIR}/ui/uirichtext.h
365 363
         ${CMAKE_CURRENT_LIST_DIR}/ui/uitextedit.cpp
366 364
         ${CMAKE_CURRENT_LIST_DIR}/ui/uitextedit.h
367 365
         ${CMAKE_CURRENT_LIST_DIR}/ui/uitranslator.cpp

+ 0
- 24
src/framework/ui/uirichtext.cpp View File

@@ -1,24 +0,0 @@
1
-/*
2
- * Copyright (c) 2010-2013 OTClient <https://github.com/edubart/otclient>
3
- *
4
- * Permission is hereby granted, free of charge, to any person obtaining a copy
5
- * of this software and associated documentation files (the "Software"), to deal
6
- * in the Software without restriction, including without limitation the rights
7
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- * copies of the Software, and to permit persons to whom the Software is
9
- * furnished to do so, subject to the following conditions:
10
- *
11
- * The above copyright notice and this permission notice shall be included in
12
- * all copies or substantial portions of the Software.
13
- *
14
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
- * THE SOFTWARE.
21
- */
22
-
23
-#include "uirichtext.h"
24
-

+ 0
- 33
src/framework/ui/uirichtext.h View File

@@ -1,33 +0,0 @@
1
-/*
2
- * Copyright (c) 2010-2013 OTClient <https://github.com/edubart/otclient>
3
- *
4
- * Permission is hereby granted, free of charge, to any person obtaining a copy
5
- * of this software and associated documentation files (the "Software"), to deal
6
- * in the Software without restriction, including without limitation the rights
7
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- * copies of the Software, and to permit persons to whom the Software is
9
- * furnished to do so, subject to the following conditions:
10
- *
11
- * The above copyright notice and this permission notice shall be included in
12
- * all copies or substantial portions of the Software.
13
- *
14
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
- * THE SOFTWARE.
21
- */
22
-
23
-#ifndef UIRICHTEXT_H
24
-#define UIRICHTEXT_H
25
-
26
-#include <framework/ui/uiwidget.h>
27
-
28
-
29
-class UIRichText : public UIWidget
30
-{
31
-};
32
-
33
-#endif // UIRICHTEXT_H

+ 116
- 65
src/framework/ui/uitextedit.cpp View File

@@ -136,6 +136,17 @@ void UITextEdit::update(bool focusCursor)
136 136
     const Size *glyphsSize = m_font->getGlyphsSize();
137 137
     int glyph;
138 138
 
139
+    // update rect size
140
+    if(!m_rect.isValid() || m_textAutoResize) {
141
+        textBoxSize += Size(m_padding.left + m_padding.right, m_padding.top + m_padding.bottom) + m_textOffset.toSize();
142
+        Size size = getSize();
143
+        if(size.width() <= 0 || (m_textAutoResize && !m_textWrap))
144
+            size.setWidth(textBoxSize.width());
145
+        if(size.height() <= 0 || m_textAutoResize)
146
+            size.setHeight(textBoxSize.height());
147
+        setSize(size);
148
+    }
149
+
139 150
     // resize just on demand
140 151
     if(textLength > (int)m_glyphsCoords.size()) {
141 152
         m_glyphsCoords.resize(textLength);
@@ -144,6 +155,11 @@ void UITextEdit::update(bool focusCursor)
144 155
 
145 156
     Point oldTextAreaOffset = m_textVirtualOffset;
146 157
 
158
+    if(textBoxSize.width() <= getPaddingRect().width())
159
+        m_textVirtualOffset.x = 0;
160
+    if(textBoxSize.height() <= getPaddingRect().height())
161
+        m_textVirtualOffset.y = 0;
162
+
147 163
     // readjust start view area based on cursor position
148 164
     m_cursorInRange = false;
149 165
     if(focusCursor) {
@@ -331,8 +347,6 @@ void UITextEdit::setSelection(int start, int end)
331 347
 
332 348
     m_selectionStart = std::min(std::max(start, 0), (int)m_text.length());
333 349
     m_selectionEnd = std::min(std::max(end, 0), (int)m_text.length());
334
-
335
-    onSelectionChange(getSelection(), m_selectionStart, m_selectionEnd);
336 350
 }
337 351
 
338 352
 void UITextEdit::setTextHidden(bool hidden)
@@ -355,8 +369,9 @@ void UITextEdit::appendText(std::string text)
355 369
     if(m_cursorPos >= 0) {
356 370
         // replace characters that are now allowed
357 371
         if(!m_multiline)
358
-            stdext::replace_all(text, "\n", "");
359
-        stdext::replace_all(text, "\r", "    ");
372
+            stdext::replace_all(text, "\n", " ");
373
+        stdext::replace_all(text, "\r", "");
374
+        stdext::replace_all(text, "\t", "    ");
360 375
 
361 376
         if(text.length() > 0) {
362 377
             // only add text if textedit can add it
@@ -371,10 +386,10 @@ void UITextEdit::appendText(std::string text)
371 386
                 }
372 387
             }
373 388
 
374
-            std::string oldText = m_text;
375
-            m_text.insert(m_cursorPos, text);
389
+            std::string tmp = m_text;
390
+            tmp.insert(m_cursorPos, text);
376 391
             m_cursorPos += text.length();
377
-            onTextChange(m_text, oldText);
392
+            setText(tmp);
378 393
         }
379 394
     }
380 395
 }
@@ -396,26 +411,26 @@ void UITextEdit::appendCharacter(char c)
396 411
 
397 412
         std::string tmp;
398 413
         tmp = c;
399
-        std::string oldText = m_text;
400
-        m_text.insert(m_cursorPos, tmp);
414
+        std::string tmp2 = m_text;
415
+        tmp2.insert(m_cursorPos, tmp);
401 416
         m_cursorPos++;
402
-        onTextChange(m_text, oldText);
417
+        setText(tmp2);
403 418
     }
404 419
 }
405 420
 
406 421
 void UITextEdit::removeCharacter(bool right)
407 422
 {
408
-    std::string oldText = m_text;
409
-    if(m_cursorPos >= 0 && m_text.length() > 0) {
410
-        if((uint)m_cursorPos >= m_text.length()) {
411
-            m_text.erase(m_text.begin() + (--m_cursorPos));
423
+    std::string tmp = m_text;
424
+    if(m_cursorPos >= 0 && tmp.length() > 0) {
425
+        if((uint)m_cursorPos >= tmp.length()) {
426
+            tmp.erase(tmp.begin() + (--m_cursorPos));
412 427
         } else {
413 428
             if(right)
414
-                m_text.erase(m_text.begin() + m_cursorPos);
429
+                tmp.erase(tmp.begin() + m_cursorPos);
415 430
             else if(m_cursorPos > 0)
416
-                m_text.erase(m_text.begin() + --m_cursorPos);
431
+                tmp.erase(tmp.begin() + --m_cursorPos);
417 432
         }
418
-        onTextChange(m_text, oldText);
433
+        setText(tmp);
419 434
     }
420 435
 }
421 436
 
@@ -428,12 +443,12 @@ void UITextEdit::blinkCursor()
428 443
 void UITextEdit::del(bool right)
429 444
 {
430 445
     if(hasSelection()) {
431
-        std::string oldText = m_text;
432
-        m_text.erase(m_selectionStart, m_selectionEnd - m_selectionStart);
446
+        std::string tmp = m_text;
447
+        tmp.erase(m_selectionStart, m_selectionEnd - m_selectionStart);
433 448
 
434 449
         setCursorPos(m_selectionStart);
435 450
         clearSelection();
436
-        onTextChange(m_text, oldText);
451
+        setText(tmp);
437 452
     } else
438 453
         removeCharacter(right);
439 454
 }
@@ -494,28 +509,51 @@ int UITextEdit::getTextPos(Point pos)
494 509
 
495 510
     // find any glyph that is actually on the
496 511
     int candidatePos = -1;
512
+    Rect firstGlyphRect, lastGlyphRect;
497 513
     for(int i=0;i<textLength;++i) {
498 514
         Rect clickGlyphRect = m_glyphsCoords[i];
515
+        if(!clickGlyphRect.isValid())
516
+            continue;
517
+        if(!firstGlyphRect.isValid())
518
+            firstGlyphRect = clickGlyphRect;
519
+        lastGlyphRect = clickGlyphRect;
499 520
         clickGlyphRect.expandTop(m_font->getYOffset() + m_font->getGlyphSpacing().height());
500 521
         clickGlyphRect.expandLeft(m_font->getGlyphSpacing().width()+1);
501
-        if(clickGlyphRect.contains(pos))
502
-            return i;
522
+        if(clickGlyphRect.contains(pos)) {
523
+            candidatePos = i;
524
+            break;
525
+        }
503 526
         else if(pos.y >= clickGlyphRect.top() && pos.y <= clickGlyphRect.bottom()) {
504
-            if(pos.x <= clickGlyphRect.left())
527
+            if(pos.x <= clickGlyphRect.left()) {
505 528
                 candidatePos = i;
506
-            else if(pos.x >= clickGlyphRect.right())
529
+                break;
530
+            } else if(pos.x >= clickGlyphRect.right())
507 531
                 candidatePos = i+1;
508 532
         }
509 533
     }
534
+
535
+    if(textLength > 0) {
536
+        if(pos.y < firstGlyphRect.top())
537
+            return 0;
538
+        else if(pos.y > lastGlyphRect.bottom())
539
+            return textLength;
540
+    }
541
+
510 542
     return candidatePos;
511 543
 }
512 544
 
513 545
 std::string UITextEdit::getDisplayedText()
514 546
 {
547
+    std::string text;
515 548
     if(m_textHidden)
516
-        return std::string(m_text.length(), '*');
549
+        text = std::string(m_text.length(), '*');
517 550
     else
518
-        return m_text;
551
+        text = m_text;
552
+
553
+    if(m_textWrap && m_rect.isValid())
554
+        text = m_font->wrapText(text, getWidth() - m_textOffset.x);
555
+
556
+    return text;
519 557
 }
520 558
 
521 559
 std::string UITextEdit::getSelection()
@@ -525,35 +563,27 @@ std::string UITextEdit::getSelection()
525 563
     return m_text.substr(m_selectionStart, m_selectionEnd - m_selectionStart);
526 564
 }
527 565
 
528
-void UITextEdit::onHoverChange(bool hovered)
566
+void UITextEdit::updateText()
529 567
 {
530
-    if(hovered)
531
-        g_mouse.setTextCursor();
532
-    else
533
-        g_mouse.restoreCursor();
534
-}
535
-
536
-void UITextEdit::onTextChange(const std::string& text, const std::string& oldText)
537
-{
538
-    if(m_cursorPos > (int)text.length())
539
-        m_cursorPos = text.length();
568
+    if(m_cursorPos > (int)m_text.length())
569
+        m_cursorPos = m_text.length();
540 570
 
541 571
     // any text changes reset the selection
542 572
     if(m_selectable) {
543 573
         m_selectionEnd = 0;
544 574
         m_selectionStart = 0;
545
-        onSelectionChange(std::string(), 0, 0);
546 575
     }
547 576
 
548 577
     blinkCursor();
549 578
     update(true);
550
-    UIWidget::onTextChange(text, oldText);
551 579
 }
552 580
 
553
-void UITextEdit::onFontChange(const std::string& font)
581
+void UITextEdit::onHoverChange(bool hovered)
554 582
 {
555
-    update(true);
556
-    UIWidget::onFontChange(font);
583
+    if(hovered)
584
+        g_mouse.setTextCursor();
585
+    else
586
+        g_mouse.restoreCursor();
557 587
 }
558 588
 
559 589
 void UITextEdit::onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode)
@@ -615,11 +645,15 @@ bool UITextEdit::onKeyPress(uchar keyCode, int keyboardModifiers, int autoRepeat
615 645
 
616 646
     if(keyboardModifiers == Fw::KeyboardNoModifier) {
617 647
         if(keyCode == Fw::KeyDelete && m_editable) { // erase right character
618
-            del(true);
619
-            return true;
620
-        } else if(keyCode == Fw::KeyBackspace && m_editable) { // erase left character {
621
-            del(false);
622
-            return true;
648
+            if(hasSelection() || !m_text.empty()) {
649
+                del(true);
650
+                return true;
651
+            }
652
+        } else if(keyCode == Fw::KeyBackspace && m_editable) { // erase left character
653
+            if(hasSelection() || !m_text.empty()) {
654
+                del(false);
655
+                return true;
656
+            }
623 657
         } else if(keyCode == Fw::KeyRight && !m_shiftNavigation) { // move cursor right
624 658
             clearSelection();
625 659
             moveCursorHorizontally(true);
@@ -629,13 +663,17 @@ bool UITextEdit::onKeyPress(uchar keyCode, int keyboardModifiers, int autoRepeat
629 663
             moveCursorHorizontally(false);
630 664
             return true;
631 665
         } else if(keyCode == Fw::KeyHome) { // move cursor to first character
632
-            clearSelection();
633
-            setCursorPos(0);
634
-            return true;
666
+            if(m_cursorPos != 0) {
667
+                clearSelection();
668
+                setCursorPos(0);
669
+                return true;
670
+            }
635 671
         } else if(keyCode == Fw::KeyEnd) { // move cursor to last character
636
-            clearSelection();
637
-            setCursorPos(m_text.length());
638
-            return true;
672
+            if(m_cursorPos != (int)m_text.length()) {
673
+                clearSelection();
674
+                setCursorPos(m_text.length());
675
+                return true;
676
+            }
639 677
         } else if(keyCode == Fw::KeyTab && !m_shiftNavigation) {
640 678
             clearSelection();
641 679
             if(UIWidgetPtr parent = getParent())
@@ -656,14 +694,20 @@ bool UITextEdit::onKeyPress(uchar keyCode, int keyboardModifiers, int autoRepeat
656 694
             paste(g_window.getClipboardText());
657 695
             return true;
658 696
         } else if(keyCode == Fw::KeyX && m_editable && m_selectable) {
659
-            cut();
660
-            return true;
697
+            if(hasSelection()) {
698
+                cut();
699
+                return true;
700
+            }
661 701
         } else if(keyCode == Fw::KeyC && m_selectable) {
662
-            copy();
663
-            return true;
702
+            if(hasSelection()) {
703
+                copy();
704
+                return true;
705
+            }
664 706
         } else if(keyCode == Fw::KeyA && m_selectable) {
665
-            selectAll();
666
-            return true;
707
+            if(m_text.length() > 0) {
708
+                selectAll();
709
+                return true;
710
+            }
667 711
         }
668 712
     } else if(keyboardModifiers == Fw::KeyboardShiftModifier) {
669 713
         if(keyCode == Fw::KeyTab && !m_shiftNavigation) {
@@ -708,6 +752,9 @@ bool UITextEdit::onKeyText(const std::string& keyText)
708 752
 
709 753
 bool UITextEdit::onMousePress(const Point& mousePos, Fw::MouseButton button)
710 754
 {
755
+    if(UIWidget::onMousePress(mousePos, button))
756
+        return true;
757
+
711 758
     if(button == Fw::MouseLeftButton) {
712 759
         int pos = getTextPos(mousePos);
713 760
         if(pos >= 0) {
@@ -720,7 +767,8 @@ bool UITextEdit::onMousePress(const Point& mousePos, Fw::MouseButton button)
720 767
         }
721 768
         return true;
722 769
     }
723
-    return UIWidget::onMousePress(mousePos, button);
770
+
771
+    return false;
724 772
 }
725 773
 
726 774
 bool UITextEdit::onMouseRelease(const Point& mousePos, Fw::MouseButton button)
@@ -741,13 +789,16 @@ bool UITextEdit::onMouseMove(const Point& mousePos, const Point& mouseMoved)
741 789
     return UIWidget::onMouseMove(mousePos, mouseMoved);
742 790
 }
743 791
 
744
-void UITextEdit::onTextAreaUpdate(const Point& offset, const Size& visibleSize, const Size& totalSize)
792
+bool UITextEdit::onDoubleClick(const Point& mousePos)
745 793
 {
746
-    callLuaField("onTextAreaUpdate", offset, visibleSize, totalSize);
794
+    if(m_selectable && m_text.length() > 0) {
795
+        selectAll();
796
+        return true;
797
+    }
798
+    return UIWidget::onDoubleClick(mousePos);
747 799
 }
748 800
 
749
-void UITextEdit::onSelectionChange(const std::string& text, int start, int end)
801
+void UITextEdit::onTextAreaUpdate(const Point& offset, const Size& visibleSize, const Size& totalSize)
750 802
 {
751
-    update(true);
752
-    callLuaField("onSelectionChange", text, start, end);
803
+    callLuaField("onTextAreaUpdate", offset, visibleSize, totalSize);
753 804
 }

+ 3
- 3
src/framework/ui/uitextedit.h View File

@@ -88,9 +88,9 @@ public:
88 88
     bool isSelectable() { return m_selectable; }
89 89
 
90 90
 protected:
91
+    void updateText();
92
+
91 93
     virtual void onHoverChange(bool hovered);
92
-    virtual void onTextChange(const std::string& text, const std::string& oldText);
93
-    virtual void onFontChange(const std::string& font);
94 94
     virtual void onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode);
95 95
     virtual void onGeometryChange(const Rect& oldRect, const Rect& newRect);
96 96
     virtual void onFocusChange(bool focused, Fw::FocusReason reason);
@@ -99,8 +99,8 @@ protected:
99 99
     virtual bool onMousePress(const Point& mousePos, Fw::MouseButton button);
100 100
     virtual bool onMouseRelease(const Point& mousePos, Fw::MouseButton button);
101 101
     virtual bool onMouseMove(const Point& mousePos, const Point& mouseMoved);
102
+    virtual bool onDoubleClick(const Point& mousePos);
102 103
     virtual void onTextAreaUpdate(const Point& vitualOffset, const Size& virtualSize, const Size& totalSize);
103
-    virtual void onSelectionChange(const std::string& text, int start, int end);
104 104
 
105 105
 private:
106 106
     void disableUpdates() { m_updatesEnabled = false; }

+ 1
- 1
src/framework/ui/uiwidget.cpp View File

@@ -1513,7 +1513,7 @@ bool UIWidget::onKeyUp(uchar keyCode, int keyboardModifiers)
1513 1513
 bool UIWidget::onMousePress(const Point& mousePos, Fw::MouseButton button)
1514 1514
 {
1515 1515
     if(button == Fw::MouseLeftButton) {
1516
-        if(m_clickTimer.running() && m_clickTimer.ticksElapsed() <= 500) {
1516
+        if(m_clickTimer.running() && m_clickTimer.ticksElapsed() <= 200) {
1517 1517
             if(onDoubleClick(mousePos))
1518 1518
                 return true;
1519 1519
             m_clickTimer.stop();

+ 1
- 1
src/framework/ui/uiwidget.h View File

@@ -456,7 +456,6 @@ public:
456 456
 // text related
457 457
 private:
458 458
     void initText();
459
-    void updateText();
460 459
     void parseTextStyle(const OTMLNodePtr& styleNode);
461 460
 
462 461
     stdext::boolean<true> m_textMustRecache;
@@ -464,6 +463,7 @@ private:
464 463
     Rect m_textCachedScreenCoords;
465 464
 
466 465
 protected:
466
+    virtual void updateText();
467 467
     void drawText(const Rect& screenCoords);
468 468
 
469 469
     virtual void onTextChange(const std::string& text, const std::string& oldText);

+ 1
- 0
src/framework/ui/uiwidgettext.cpp View File

@@ -120,6 +120,7 @@ void UIWidget::setText(std::string text)
120 120
     m_text = text;
121 121
     updateText();
122 122
 
123
+    text = m_text;
123 124
     onTextChange(text, oldText);
124 125
 }
125 126
 

Loading…
Cancel
Save