diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml new file mode 100644 index 00000000..2f58b012 --- /dev/null +++ b/.github/workflows/codeql-analysis.yml @@ -0,0 +1,74 @@ +# For most projects, this workflow file will not need changing; you simply need +# to commit it to your repository. +# +# You may wish to alter this file to override the set of languages analyzed, +# or to provide custom queries or build logic. +name: "CodeQL" + +on: + push: + branches: [master] + pull_request: + # The branches below must be a subset of the branches above + branches: [master] + schedule: + - cron: '0 7 * * 2' + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + # Override automatic language detection by changing the below list + # Supported options are ['csharp', 'cpp', 'go', 'java', 'javascript', 'python'] + language: ['cpp'] + # Learn more... + # https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#overriding-automatic-language-detection + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + with: + # We must fetch at least the immediate parents so that if this is + # a pull request then we can checkout the head. + fetch-depth: 2 + + # If this run was triggered by a pull request event, then checkout + # the head of the pull request instead of the merge commit. + - run: git checkout HEAD^2 + if: ${{ github.event_name == 'pull_request' }} + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v1 + with: + languages: ${{ matrix.language }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + # queries: ./path/to/local/query, your-org/your-repo/queries@main + + # ℹī¸ Command-line programs to run using the OS shell. + # 📚 https://git.io/JvXDl + + # ✏ī¸ If the Autobuild fails above, remove it and uncomment the following three lines + # and modify them (or add more) to build your code if your project + # uses a compiled language + + - name: Build dependencies + run: sudo apt-get install autoconf-archive + + - name: Create configure file + run: autoreconf -v --install --force + + - name: Create makefiles + run: ./configure --prefix=/usr CPPFLAGS="-DDEBUG" CXXFLAGS="-g -O0 -DDEBUG -W -Wall -pedantic" + + - name: Build + run: make V=1 -j10 + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v1 diff --git a/.travis.yml b/.travis.yml index dfeb55a3..fcabedb0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,5 @@ language: cpp dist: xenial -sudo: required compiler: - gcc @@ -41,7 +40,7 @@ env: bL/epiiMBKJ37X1UcRU4WZYq+peLME8EefcPcXOSWNLwJtR7mtON8uMBrLL9CWmRMFD5Hy lQYALW2DhCnDBROKB3gxB/VkBGFNE0IPGeDtBGbLqDtKWPQoL125I= -matrix: +jobs: include: # # Coverity Scan diff --git a/ChangeLog b/ChangeLog index 4b93c1e1..4b6ab317 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,50 @@ +2020-10-11 Markus Gans + * Solaris build fix + * Added saving and restoring xterm titles to the stack + for vte terminals + * Menu key - activates the menu bar + * Shift-Menu - opens the dialog menu + +2020-10-08 Markus Gans + * Better keyboard support for urxvt terminals + * Screen reports (like Secondary DA) are now read directly + * Report Cursor Position (DECXCPR) support + * FListView and FListBox now have direct access to the list of client + elements via data() + +2020-10-05 Markus Gans + * Now hides the input cursor when a widget gets hidden + +2020-10-04 Markus Gans + * Replaces some C-style arrays with std::array + * Now you can use the arrow keys to move a window into the visible area + * Removes FData memory leak in FListBoxItem and FListViewItem + +2020-09-27 Markus Gans + * An explanation of the widget tree was added to the document + of the first steps + +2020-09-26 Markus Gans + * FData improvements + * The number of FObject children can now be limited with + setMaxChildren() + * FApplication can now have no more than one child widget + +2020-09-25 Markus Gans + * std::clog now streams everything to the FLogger object + * Added a unit test for the FData class + +2020-09-23 Markus Gans + * Bugfix: empty FString() + wchar_t + +2020-09-22 Markus Gans + * Bugfix in FDialog::setSize(): Automatic size adjustment and + simultaneous widget movement are now possible. + +2020-09-18 Markus Gans + * The generic data type FDataPtr is now deprecated and was + completely replaced by the template class FData + 2020-09-11 Markus Gans * Fixes a problem with mouse input in Cygwin in non-blocking read mode diff --git a/README.md b/README.md index a4fbc267..23fd22ab 100644 --- a/README.md +++ b/README.md @@ -136,7 +136,10 @@ printf(...) ## Class digramm
-              1┌──────────────┐
+              1┌────────────┐
+   ┌-----------┤ FTermLinux │
+   :           └────────────┘
+   :          1┌──────────────┐
    ┌-----------┤ FTermFreeBSD │
    :           └──────────────┘
    :          1┌──────────────┐
@@ -172,12 +175,15 @@ printf(...)
    :          1┌───────────────┐   │    ┌─────────────┐
    ┌-----------┤ FMouseControl │   ├────┤ FTimerEvent │
    :           └───────────────┘   │    └─────────────┘
-   :          1┌─────────┐         │       ┌──────┐   ┌─────────┐
-   ┌-----------┤ FSystem │         │       │ FLog │◄──┤ FLogger │
-   :           └─────────┘         │       └──â”Ŧ───┘   └─────────┘
-   :          *┌─────────┐         │          :1
-   :  ┌--------┤ FString │         │       ┌──┴───────────┐
-   :  :        └─────────┘         │  ┌────┤ FApplication │
+   :          1┌─────────┐         │    ┌────────────┐1    1┌───────┐
+   ┌-----------┤ FSystem │         ├────┤ FUserEvent ├------┤ FData │
+   :           └─────────┘         │    └────────────┘      └───────┘
+   :          *┌─────────┐         │       ┌──────┐   ┌─────────┐
+   :  ┌--------┤ FString │         │       │ FLog │◄──┤ FLogger │
+   :  :        └─────────┘         │       └──â”Ŧ───┘   └─────────┘
+   :  :       *┌───────────────┐   │          :1
+   :  ┌--------┤ FStringStream │   │       ┌──┴───────────┐
+   :  :        └───────────────┘   │  ┌────┤ FApplication │
    :  :       *┌────────┐          │  │    └──────────────┘
    :  ┌--------┤ FPoint │          │  │    ┌────────┐
    :  :        └────────┘          │  ├────┤ FLabel │
@@ -209,15 +215,16 @@ printf(...)
                                       │    ┌───────────┐1    1┌──────────────────┐
                                       ├────┤ FComboBox ├------┤ FDropDownListBox │
                                       │    └───────────┘      └──────────────────┘
- ┌─────────────┐1                     │    ┌──────────┐1     *┌──────────────┐
- │ FTermBuffer ├----------------------├────┤ FListBox ├-------┤ FListBoxItem │
- └─────────────┘                      │    └──────────┘       └──────────────┘
-                                      │   1┌───────────┐1    *┌───────────────┐
-                                      ├────┤ FListView ├------┤ FListViewItem │
-                                      │    └───────────┘      └───────────────┘
-                                      │    ┌─────────────┐
-                                      ├────┤ FScrollView │
-                                      │    └─────────────┘
+ ┌─────────────┐1                     │    ┌──────────┐1     *┌──────────────┐1
+ │ FTermBuffer ├----------------------├────┤ FListBox ├-------┤ FListBoxItem ├--┐
+ └─────────────┘                      │    └──────────┘       └──────────────┘  :
+                                      │   1┌───────────┐1    *┌───────────────┐ :
+                                      ├────┤ FListView ├------┤ FListViewItem │ :
+                                      │    └───────────┘      └────────â”Ŧ──────┘ :
+                                      │    ┌─────────────┐             :1       :
+                                      ├────┤ FScrollView │         ┌───┴───┐1   :
+                                      │    └─────────────┘         │ FData ├----┘
+                                      │                            └───────┘
                                       │    ┌────────────┐1   *┌────────────┐
                                       │ ┌──┤ FStatusBar ├-----┤ FStatusKey │
                                       │ │  └────────────┘     └────────────┘
diff --git a/doc/class-diagram.txt b/doc/class-diagram.txt
index a34f10e0..4dbf7181 100644
--- a/doc/class-diagram.txt
+++ b/doc/class-diagram.txt
@@ -1,7 +1,10 @@
 ══════════════════════════════════════════════════════════════════════════════
                                  Class digramm
 ══════════════════════════════════════════════════════════════════════════════
-              1┌──────────────┐
+              1┌────────────┐
+   ┌-----------┤ FTermLinux │
+   :           └────────────┘
+   :          1┌──────────────┐
    ┌-----------┤ FTermFreeBSD │
    :           └──────────────┘
    :          1┌──────────────┐
@@ -37,12 +40,15 @@
    :          1┌───────────────┐   │    ┌─────────────┐
    ┌-----------┤ FMouseControl │   ├────┤ FTimerEvent │
    :           └───────────────┘   │    └─────────────┘
-   :          1┌─────────┐         │       ┌──────┐   ┌─────────┐
-   ┌-----------┤ FSystem │         │       │ FLog │◄──┤ FLogger │
-   :           └─────────┘         │       └──â”Ŧ───┘   └─────────┘
-   :          *┌─────────┐         │          :1
-   :  ┌--------┤ FString │         │       ┌──┴───────────┐
-   :  :        └─────────┘         │  ┌────┤ FApplication │
+   :          1┌─────────┐         │    ┌────────────┐1    1┌───────┐
+   ┌-----------┤ FSystem │         ├────┤ FUserEvent ├------┤ FData │
+   :           └─────────┘         │    └────────────┘      └───────┘
+   :          *┌─────────┐         │       ┌──────┐   ┌─────────┐
+   :  ┌--------┤ FString │         │       │ FLog │◄──┤ FLogger │
+   :  :        └─────────┘         │       └──â”Ŧ───┘   └─────────┘
+   :  :       *┌───────────────┐   │          :1
+   :  ┌--------┤ FStringStream │   │       ┌──┴───────────┐
+   :  :        └───────────────┘   │  ┌────┤ FApplication │
    :  :       *┌────────┐          │  │    └──────────────┘
    :  ┌--------┤ FPoint │          │  │    ┌────────┐
    :  :        └────────┘          │  ├────┤ FLabel │
@@ -74,15 +80,16 @@
                                       │    ┌───────────┐1    1┌──────────────────┐
                                       ├────┤ FComboBox ├------┤ FDropDownListBox │
                                       │    └───────────┘      └──────────────────┘
- ┌─────────────┐1                     │    ┌──────────┐1     *┌──────────────┐
- │ FTermBuffer ├----------------------├────┤ FListBox ├-------┤ FListBoxItem │
- └─────────────┘                      │    └──────────┘       └──────────────┘
-                                      │   1┌───────────┐1    *┌───────────────┐
-                                      ├────┤ FListView ├------┤ FListViewItem │
-                                      │    └───────────┘      └───────────────┘
-                                      │    ┌─────────────┐
-                                      ├────┤ FScrollView │
-                                      │    └─────────────┘
+ ┌─────────────┐1                     │    ┌──────────┐1     *┌──────────────┐1
+ │ FTermBuffer ├----------------------├────┤ FListBox ├-------┤ FListBoxItem ├--┐
+ └─────────────┘                      │    └──────────┘       └──────────────┘  :
+                                      │   1┌───────────┐1    *┌───────────────┐ :
+                                      ├────┤ FListView ├------┤ FListViewItem │ :
+                                      │    └───────────┘      └────────â”Ŧ──────┘ :
+                                      │    ┌─────────────┐             :1       :
+                                      ├────┤ FScrollView │         ┌───┴───┐1   :
+                                      │    └─────────────┘         │ FData ├----┘
+                                      │                            └───────┘
                                       │    ┌────────────┐1   *┌────────────┐
                                       │ ┌──┤ FStatusBar ├-----┤ FStatusKey │
                                       │ │  └────────────┘     └────────────┘
diff --git a/doc/faq.md b/doc/faq.md
index 47164336..d8304638 100644
--- a/doc/faq.md
+++ b/doc/faq.md
@@ -85,6 +85,7 @@ You need three things:
     * autoconf
     * autoconf-archive
     * libtool
+    * pkg-config
 
 3. Development packages for following libraries:
 
diff --git a/doc/final-cut-widget tree.svg b/doc/final-cut-widget tree.svg
new file mode 100644
index 00000000..eeb7eeae
--- /dev/null
+++ b/doc/final-cut-widget tree.svg	
@@ -0,0 +1,324 @@
+
+
+  
+    
+      
+        image/svg+xml
+        
+        
+      
+    
+  
+  
+  
+    
+  
+  
+    
+  
+  
+    
+  
+  
+    
+  
+  
+    
+  
+  
+    
+      
+      
+        FApplication
+      
+    
+    
+      
+      
+        FDialog
+      
+    
+    
+      
+      
+        FDialog
+      
+    
+    
+      
+      
+        FLabel
+      
+    
+    
+      
+      
+        FListBox
+      
+    
+  
+  
+    etc.
+  
+  
+  
+  
+  
+  
+  
+    
+      Parent:
+    
+    
+      Child:
+    
+    
+      Subchild:
+    
+    
+      Sub-subchild:
+    
+  
+  
+    
+      Application widget (= 1)
+    
+    
+      Main widget (= 1)
+    
+    
+      Widget(s) of the main widget (â‰Ĩ 0)
+    
+    
+      Widget(s) from the parent widget (â‰Ĩ 0)
+    
+  
+
diff --git a/doc/first-steps.md b/doc/first-steps.md
index 67c99515..7cafbacb 100644
--- a/doc/first-steps.md
+++ b/doc/first-steps.md
@@ -7,6 +7,8 @@ Table of Contents
 
 
 - [Basic functions](#basic-functions)
+- [Widgets](#widgets)
+- [Widget tree](#widget-tree)
 - [How to use the library](#how-to-use-the-library)
 - [Memory Management](#memory-management)
 - [Event Processing](#event-processing)
@@ -55,6 +57,49 @@ emulator. It uses various optimization methods to improve the drawing speed.
 
 
 
+Widgets
+-------
+
+FINAL CUT has many widgets. It offers buttons, input fields, menus, and 
+dialog boxes that cover the most common use cases. Widgets are visual 
+elements that are combined to create user interfaces. Own widgets can be 
+easily created by creating a derived class of `FWidget` or other existing 
+widgets. All widgets are instances of 
+[FWidget](https://codedocs.xyz/gansm/finalcut/classfinalcut_1_1FWidget.html) 
+or its subclasses.
+
+A widget can contain any number of child widgets. Child widgets are displayed 
+in the display area of the parent widget. Window widgets based on `FWindow` 
+have their own virtual display area and are independent of the parent widget.
+
+When a parent widget is disabled, hidden, or deleted, the same operation is 
+used recursively to all its child widgets. The base class `FObject` implements 
+the self-organized object tree behavior. For example, `addChild()` removes 
+the child ownership from an existing parent object before assigning it to 
+the new target. When a child becomes deleted, the parent-child relationship 
+causes its reference in the parent object to be removed. An explicit 
+`delChild()` is no longer required here.
+
+
+Widget tree
+-----------
+
+An `FApplication` widget is the top-level widget of an application. It is 
+unique and can not have a parent widget. The class `FApplication` manages 
+all settings and assigns keyboard and mouse input to the different widgets.
+
+
+ widget tree +
Figure 2. Widget tree of a FINAL CUT application
+
+

+ +The main widget of a FINAL CUT application is the only object that +`FApplication` can have as a child. This main widget is usually a window +object that contains all sub-widgets of the application. A sub-widget can +also be another window. + + How to use the library ---------------------- @@ -82,7 +127,7 @@ int main (int argc, char* argv[]) ```
dialog.cpp -
Figure 2. A blank dialog
+
Figure 3. A blank dialog


@@ -92,8 +137,8 @@ int main (int argc, char* argv[]) After entering the source code in *dialog.cpp* you can compile the above program with gcc: -```cpp -g++ -O2 -lfinal dialog.cpp -o dialog +```bash +g++ dialog.cpp -o dialog -O2 -lfinal ``` @@ -229,7 +274,7 @@ int main (int argc, char* argv[]) ```
memory.cpp -
Figure 3. FObject manages its child objects
+
Figure 4. FObject manages its child objects


@@ -239,8 +284,8 @@ int main (int argc, char* argv[]) After entering the source code in *memory.cpp* you can compile the above program with gcc: -```cpp -g++ -O2 -lfinal memory.cpp -o memory +```bash +g++ memory.cpp -o memory -O2 -lfinal ``` @@ -369,7 +414,7 @@ int main (int argc, char* argv[]) ```
timer.cpp -
Figure 4. FObject::onTimer event handler
+
Figure 5. FObject::onTimer event handler


@@ -379,8 +424,8 @@ int main (int argc, char* argv[]) After entering the source code in *timer.cpp* you can compile the above program with gcc: -```cpp -g++ -O2 -lfinal -std=c++11 timer.cpp -o timer +```bash +g++ timer.cpp -o timer -O2 -lfinal -std=c++11 ``` @@ -431,7 +476,7 @@ class extendedApplication : public FApplication || last_avg[2] != load_avg[2] ) { FUserEvent user_event(fc::User_Event, 0); - user_event.setData (FDataPtr(&load_avg)); + user_event.setData (load_avg); FApplication::sendEvent (getMainWidget(), &user_event); } @@ -458,8 +503,7 @@ class dialogWidget final : public FDialog private: void onUserEvent (FUserEvent* ev) override { - FDataPtr dataPtr = ev->getData(); - auto& lavg = *(reinterpret_cast(dataPtr)); + const auto& lavg = ev->getData(); std::setlocale(LC_NUMERIC, "C"); loadavg_label.clear(); loadavg_label << "Load average: " << lavg[0] << ", " @@ -483,7 +527,7 @@ int main (int argc, char* argv[]) ```
user-event.cpp -
Figure 5. User event generation
+
Figure 6. User event generation


@@ -493,8 +537,8 @@ int main (int argc, char* argv[]) After entering the source code in *user-event.cpp* you can compile the above program with gcc: -```cpp -g++ -O2 -lfinal -std=c++11 user-event.cpp -o user-event +```bash +g++ user-event.cpp -o user-event -O2 -lfinal -std=c++11 ``` @@ -530,9 +574,9 @@ to other widget objects. 1. For calling functions or static methods via a pointer: ```cpp -template::type = nullptr - , typename... Args> +template< typename Function + , typename FunctionPointer::type = nullptr + , typename... Args > void FWidget::addCallback ( const FString& cb_signal , Function&& cb_function , Args&&... args) @@ -542,9 +586,9 @@ void FWidget::addCallback ( const FString& cb_signal 2. For calling functions or static methods via a reference: ```cpp -template::type = nullptr - , typename... Args> +template< typename Function + , typename FunctionReference::type = nullptr + , typename... Args > void FWidget::addCallback ( const FString& cb_signal , Function& cb_function , Args&&... args) @@ -554,11 +598,11 @@ void FWidget::addCallback ( const FString& cb_signal 3. For calling a member method of a specific instance: ```cpp -template::type = nullptr - , typename MemberFunctionPointer::type = nullptr - , typename... Args> +template< typename Object + , typename Function + , typename ObjectPointer::type = nullptr + , typename MemberFunctionPointer::type = nullptr + , typename... Args > void FWidget::addCallback ( const FString& cb_signal , Object&& cb_instance , Function&& cb_member @@ -568,9 +612,9 @@ void FWidget::addCallback ( const FString& cb_signal 4. For calling a std::bind call wrapper or a lambda expression: ```cpp -template::type = nullptr - , typename... Args> +template< typename Function + , typename ClassObject::type = nullptr + , typename... Args > void FWidget::addCallback ( const FString& cb_signal , Function&& cb_function , Args&&... args) @@ -580,11 +624,11 @@ void FWidget::addCallback ( const FString& cb_signal 5. For calling a std::bind call wrapper to a specific instance: ```cpp -template::type = nullptr - , typename ClassObject::type = nullptr - , typename... Args> +template< typename Object + , typename Function + , typename ObjectPointer::type = nullptr + , typename ClassObject::type = nullptr + , typename... Args > void FWidget::addCallback ( const FString& cb_signal , Object&& cb_instance , Function&& cb_function @@ -596,9 +640,9 @@ void FWidget::addCallback ( const FString& cb_signal with the keyword auto: ```cpp -template::type = nullptr - , typename... Args> +template< typename Function + , typename ClassObject::type = nullptr + , typename... Args > void FWidget::addCallback ( const FString& cb_signal , Function& cb_function , Args&&... args) @@ -612,8 +656,8 @@ remove all existing callbacks from an object. 1. To delete functions or static methods callbacks via a pointer: ```cpp -template::type = nullptr> +template< typename FunctionPtr + , typename FunctionPointer::type = nullptr > void FWidget::delCallback (FunctionPtr&& cb_func_ptr) {...} ``` @@ -621,8 +665,8 @@ void FWidget::delCallback (FunctionPtr&& cb_func_ptr) 2. To delete functions or static methods callbacks via a reference: ```cpp -template::type = nullptr> +template< typename Function + , typename FunctionReference::type = nullptr > void FWidget::delCallback (Function& cb_function) {...} ``` @@ -630,8 +674,8 @@ void FWidget::delCallback (Function& cb_function) 3. To delete all callbacks from a specific instance: ```cpp -template::type = nullptr> +template< typename Object + , typename ObjectPointer::type = nullptr > void FWidget::delCallback (Object&& cb_instance) {...} ``` @@ -646,8 +690,8 @@ void delCallback (const FString& cb_signal) 5. To delete all callbacks of a signal and specific instance: ```cpp -template::type = nullptr> +template< typename Object + , typename ObjectPointer::type = nullptr > void delCallback (const FString& cb_signal, Object&& cb_instance) {...} ``` @@ -754,7 +798,7 @@ int main (int argc, char* argv[]) ```
callback-function.cpp -
Figure 6. Button with a callback function
+
Figure 7. Button with a callback function


@@ -764,8 +808,8 @@ int main (int argc, char* argv[]) After entering the source code in *callback-function.cpp* you can compile the above program with gcc: -```cpp -g++ -O2 -lfinal callback-function.cpp -o callback-function +```bash +g++ callback-function.cpp -o callback-function -O2 -lfinal ```   @@ -817,7 +861,7 @@ int main (int argc, char* argv[]) ```
callback-lambda.cpp -
Figure 7. Button with lambda expression callback.
+
Figure 8. Button with lambda expression callback.


@@ -827,8 +871,8 @@ int main (int argc, char* argv[]) After entering the source code in *callback-lambda.cpp* you can compile the above program with gcc: -```cpp -g++ -O2 -lfinal -std=c++11 callback-lambda.cpp -o callback-lambda +```bash +g++ callback-lambda.cpp -o callback-lambda -O2 -lfinal -std=c++11 ```   @@ -876,7 +920,7 @@ int main (int argc, char* argv[]) ```
callback-method.cpp -
Figure 8. Button with a callback method
+
Figure 9. Button with a callback method


@@ -886,8 +930,8 @@ int main (int argc, char* argv[]) After entering the source code in *callback-method.cpp* you can compile the above program with gcc: -```cpp -g++ -O2 -lfinal -std=c++11 callback-method.cpp -o callback-method +```bash +g++ callback-method.cpp -o callback-method -O2 -lfinal -std=c++11 ```   @@ -997,7 +1041,7 @@ int main (int argc, char* argv[]) ```
emit-signal.cpp -
Figure 9. Callbacks with custom signals
+
Figure 10. Callbacks with custom signals


@@ -1007,8 +1051,8 @@ int main (int argc, char* argv[]) After entering the source code in *emit-signal.cpp* you can compile the above program with gcc: -```cpp -g++ -O2 -lfinal -std=c++11 emit-signal.cpp -o emit-signal +```bash +g++ emit-signal.cpp -o emit-signal -O2 -lfinal -std=c++11 ``` @@ -1038,7 +1082,7 @@ If you want to ignore padding spaces, you must force this with the
widget coordinates -
Figure 10. Widget coordinates
+
Figure 11. Widget coordinates


@@ -1088,7 +1132,7 @@ methods.
widget lengths -
Figure 11. Width and height of a widget
+
Figure 12. Width and height of a widget


@@ -1141,7 +1185,7 @@ absolute geometry values as a `FRect` object, you can call the method
widget geometry -
Figure 12. Geometry of widgets
+
Figure 13. Geometry of widgets


@@ -1237,19 +1281,12 @@ class dialogWidget : public FDialog FDialog::adjustSize(); // Centers the dialog in the terminal centerDialog(); - } - - void setSize (const FSize& size, bool) override - { - // Calling super class methods setSize() + adjustSize() - FDialog::setSize (size, false); - FDialog::adjustSize(); + // Adjust widgets before drawing + adjustWidgets(); } void draw() override { - adjustWidgets(); // Adjust widgets before drawing - // Calling super class method draw() FDialog::draw(); @@ -1275,7 +1312,7 @@ int main (int argc, char* argv[]) ```
size-adjustment.cpp -
Figure 13. Dynamic layout
+
Figure 14. Dynamic layout


@@ -1285,8 +1322,8 @@ int main (int argc, char* argv[]) After entering the source code in *size-adjustment.cpp* you can compile the above program with gcc: -```cpp -g++ -O2 -lfinal -std=c++11 size-adjustment.cpp -o size-adjustment +```bash +g++ size-adjustment.cpp -o size-adjustment -O2 -lfinal -std=c++11 ``` @@ -1403,7 +1440,7 @@ int main (int argc, char* argv[]) ```
scrollview.cpp -
Figure 14. Dialog with a scrolling viewport
+
Figure 15. Dialog with a scrolling viewport


@@ -1413,6 +1450,6 @@ int main (int argc, char* argv[]) After entering the source code in *scrollview.cpp* you can compile the above program with gcc: -```cpp -g++ -O2 -lfinal -std=c++11 scrollview.cpp -o scrollview +```bash +g++ scrollview.cpp -o scrollview -O2 -lfinal -std=c++11 ``` diff --git a/doc/user-theme.md b/doc/user-theme.md index fc59dd45..18156010 100644 --- a/doc/user-theme.md +++ b/doc/user-theme.md @@ -27,7 +27,7 @@ class myWidgetColors final : public finalcut::FWidgetColors ~myWidgetColors() override { } - const finalcut::FString getClassName() const override + finalcut::FString getClassName() const override { return "myWidgetColors"; } @@ -68,7 +68,7 @@ class BeeColorTheme final : public finalcut::FWidgetColors ~BeeColorTheme() override { } - const finalcut::FString getClassName() const override + finalcut::FString getClassName() const override { return "BeeColorTheme"; } @@ -216,7 +216,7 @@ class myColorPalette final : public finalcut::FColorPalette ~myColorPalette() { } - const finalcut::FString getClassName() const override + finalcut::FString getClassName() const override { return "myColorPalette"; } @@ -299,7 +299,7 @@ class BeeColorPalette final : public finalcut::FColorPalette ~BeeColorPalette() { } - const finalcut::FString getClassName() const override + finalcut::FString getClassName() const override { return "BeeColorPalette"; } @@ -437,7 +437,7 @@ int main (int argc, char* argv[]) After entering the source code in *theme.cpp* you can compile the above program with gcc: -```cpp -g++ -O2 -lfinal -std=c++11 theme.cpp -o theme +```bash +g++ theme.cpp -o theme -O2 -lfinal -std=c++11 ``` diff --git a/examples/7segment.cpp b/examples/7segment.cpp index 89991113..6a16fd6c 100644 --- a/examples/7segment.cpp +++ b/examples/7segment.cpp @@ -20,6 +20,7 @@ * . * ***********************************************************************/ +#include #include #include @@ -39,9 +40,6 @@ using finalcut::FSize; class SegmentView final : public finalcut::FDialog { public: - // Using-declaration - using FDialog::setGeometry; - // Constructor explicit SegmentView (finalcut::FWidget* = nullptr); @@ -64,12 +62,11 @@ class SegmentView final : public finalcut::FDialog void get7Segment (const wchar_t); void draw() override; - // Data members std::map code{}; - finalcut::FString line[3]{}; - finalcut::FLineEdit Input{"0123", this}; - finalcut::FButton Exit{"E&xit", this}; + std::array line{}; + finalcut::FLineEdit input{"0123", this}; + finalcut::FButton exit{"E&xit", this}; }; //---------------------------------------------------------------------- @@ -86,18 +83,18 @@ SegmentView::SegmentView (finalcut::FWidget* parent) hexEncoding(); // Input field - Input.setGeometry (FPoint(2, 2), FSize{12, 1}); - Input.setLabelText (L"&Hex value"); - Input.setLabelText (L"&Hex-digits or (.) (:) (H) (L) (P) (U)"); - Input.setLabelOrientation(finalcut::FLineEdit::label_above); - Input.setMaxLength(9); - Input.setInputFilter("[:.hHlLpPuU[:xdigit:]]"); + input.setGeometry (FPoint(2, 2), FSize{12, 1}); + input.setLabelText (L"&Hex value"); + input.setLabelText (L"&Hex-digits or (.) (:) (H) (L) (P) (U)"); + input.setLabelOrientation(finalcut::FLineEdit::label_above); + input.setMaxLength(9); + input.setInputFilter("[:.hHlLpPuU[:xdigit:]]"); // Exit button - Exit.setGeometry(FPoint{28, 11}, FSize{10, 1}); + exit.setGeometry(FPoint{28, 11}, FSize{10, 1}); // Add some function callbacks - Input.addCallback + input.addCallback ( "changed", [] (SegmentView& dialog) @@ -107,7 +104,7 @@ SegmentView::SegmentView (finalcut::FWidget* parent) std::ref(*this) ); - Exit.addCallback + exit.addCallback ( "clicked", finalcut::getFApplication(), @@ -140,7 +137,7 @@ void SegmentView::hexEncoding() //---------------------------------------------------------------------- void SegmentView::get7Segment (const wchar_t c) { - for (int i{0}; i < 3; i++) + for (std::size_t i{0}; i < 3; i++) line[i].clear(); switch ( c ) @@ -186,8 +183,8 @@ void SegmentView::get7Segment (const wchar_t c) if ( code.find(c) != code.end() ) { const sevenSegment& s = code[c]; - constexpr char h[2]{' ', '_'}; - constexpr char v[2]{' ', '|'}; + constexpr std::array h{{' ', '_'}}; + constexpr std::array v{{' ', '|'}}; line[0] << ' ' << h[s.a] << ' '; line[1] << v[s.f] << h[s.g] << v[s.b]; @@ -206,7 +203,7 @@ void SegmentView::draw() setColor(fc::LightGray, fc::Black); finalcut::drawBorder(this, FRect(FPoint{3, 6}, FPoint{40, 11})); - for (auto&& ch : Input.getText().toUpper()) + for (auto&& ch : input.getText().toUpper()) { const FColorPair color{fc::LightRed, fc::Black}; get7Segment(ch); diff --git a/examples/Makefile.clang b/examples/Makefile.clang index 8f0825f7..7f1a5005 100644 --- a/examples/Makefile.clang +++ b/examples/Makefile.clang @@ -24,7 +24,7 @@ endif # $@ = name of the targets # $^ = all dependency (without double entries) .cpp: - $(CXX) $(CCXFLAGS) $(INCLUDES) $(LDFLAGS) -o $@ $^ + $(CXX) $^ -o $@ $(CCXFLAGS) $(INCLUDES) $(LDFLAGS) all: $(OBJS) diff --git a/examples/Makefile.gcc b/examples/Makefile.gcc index 072db0da..724b4c2d 100644 --- a/examples/Makefile.gcc +++ b/examples/Makefile.gcc @@ -24,7 +24,7 @@ endif # $@ = name of the targets # $^ = all dependency (without double entries) .cpp: - $(CXX) $(CCXFLAGS) $(INCLUDES) $(LDFLAGS) -o $@ $^ + $(CXX) $^ -o $@ $(CCXFLAGS) $(INCLUDES) $(LDFLAGS) all: $(OBJS) diff --git a/examples/background-color.cpp b/examples/background-color.cpp index 0894b8ea..e215f7d7 100644 --- a/examples/background-color.cpp +++ b/examples/background-color.cpp @@ -38,9 +38,6 @@ using finalcut::FSize; class Background final : public finalcut::FDialog { public: - // Using-declaration - using FDialog::setGeometry; - // Typedef typedef std::tuple RGB; @@ -108,8 +105,7 @@ Background::Background (finalcut::FWidget* parent) for (auto& c : color_list) { - FDataPtr data_ptr = reinterpret_cast(&c.second); - finalcut::FListBoxItem item (c.first, data_ptr); + finalcut::FListBoxItem item (c.first, c.second); color_choice.insert(item); } @@ -199,9 +195,8 @@ void Background::cb_choice() uChar r{}; uChar g{}; uChar b{}; - const FDataPtr data_ptr = color_choice.getItemData(); - const RGB* rgb = reinterpret_cast(data_ptr); - std::tie(r, g, b) = *rgb; + const RGB rgb = color_choice.getItemData(); + std::tie(r, g, b) = rgb; red.setValue(r); green.setValue(g); blue.setValue(b); diff --git a/examples/busy.cpp b/examples/busy.cpp index 24e3bf22..4e06d2ae 100644 --- a/examples/busy.cpp +++ b/examples/busy.cpp @@ -89,13 +89,13 @@ Dialog::Dialog (FWidget* parent) void Dialog::adjustSize() { finalcut::FDialog::adjustSize(); - int X = int((getDesktopWidth() - getWidth()) / 2); - const int Y = 5; + auto x = int((getDesktopWidth() - getWidth()) / 2); + const int y = 5; - if ( X < 1 ) - X = 1; + if ( x < 1 ) + x = 1; - setPos (FPoint{X, Y}, false); + setPos (FPoint{x, y}, false); } //---------------------------------------------------------------------- diff --git a/examples/calculator.cpp b/examples/calculator.cpp index 8160f41e..77e1479b 100644 --- a/examples/calculator.cpp +++ b/examples/calculator.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -36,7 +37,7 @@ using finalcut::FRect; using finalcut::FSize; using finalcut::FColorPair; -constexpr lDouble PI{3.141592653589793238L}; +constexpr lDouble pi_value{3.141592653589793238L}; //---------------------------------------------------------------------- @@ -213,6 +214,7 @@ class Calc final : public finalcut::FDialog // Event handlers void onKeyPress (finalcut::FKeyEvent*) override; + void onShow (finalcut::FShowEvent*) override; void onClose (finalcut::FCloseEvent*) override; // Callback method @@ -230,15 +232,15 @@ class Calc final : public finalcut::FDialog char infix_operator{'\0'}; char last_infix_operator{'\0'}; finalcut::FString input{""}; - button button_no[Calc::NUM_OF_BUTTONS]{}; + std::array button_no{}; - struct stack_data + struct StackData { lDouble term; char infix_operator; }; - std::stack bracket_stack{}; + std::stack bracket_stack{}; std::map > calculator_buttons{}; std::map key_map{}; }; @@ -255,7 +257,6 @@ Calc::Calc (FWidget* parent) mapKeyFunctions(); clearInfixOperator(); - std::setlocale(LC_NUMERIC, "C"); for (button key{Sine}; key < Calc::NUM_OF_BUTTONS; key = button(key + 1)) { @@ -357,6 +358,13 @@ void Calc::onKeyPress (finalcut::FKeyEvent* ev) } } +//---------------------------------------------------------------------- +void Calc::onShow (finalcut::FShowEvent*) +{ + // Overwrites the initialized value of LC_NUMERIC + std::setlocale(LC_NUMERIC, "C"); +} + //---------------------------------------------------------------------- void Calc::onClose (finalcut::FCloseEvent* ev) { @@ -696,14 +704,14 @@ void Calc::percent (lDouble& x) //---------------------------------------------------------------------- void Calc::pi (lDouble& x) { - x = PI; + x = pi_value; setDisplay(x); } //---------------------------------------------------------------------- void Calc::open_bracket (const lDouble&) { - const stack_data d{ a, infix_operator }; + const StackData d{ a, infix_operator }; bracket_stack.push(d); clearInfixOperator(); input = ""; @@ -719,7 +727,7 @@ void Calc::close_bracket (const lDouble&) calcInfixOperator(); setDisplay(a); - const stack_data d = bracket_stack.top(); + const StackData d = bracket_stack.top(); bracket_stack.pop(); b = d.term; infix_operator = d.infix_operator; @@ -828,11 +836,11 @@ void Calc::sine (lDouble& x) else { if ( arcus_mode ) - x = std::asin(x) * 180.0L / PI; + x = std::asin(x) * 180.0L / pi_value; else if ( std::fabs(std::fmod(x, 180.0L)) < LDBL_EPSILON ) // x / 180 = 0 x = 0.0L; else - x = std::sin(x * PI / 180.0L); + x = std::sin(x * pi_value / 180.0L); } if ( errno == EDOM ) @@ -866,11 +874,11 @@ void Calc::cosine (lDouble& x) else { if ( arcus_mode ) - x = std::acos(x) * 180.0L / PI; + x = std::acos(x) * 180.0L / pi_value; else if ( std::fabs(std::fmod(x - 90.0L, 180.0L)) < LDBL_EPSILON ) // (x - 90) / 180 == 0 x = 0.0L; else - x = std::cos(x * PI / 180.0L); + x = std::cos(x * pi_value / 180.0L); } if ( errno == EDOM ) @@ -904,7 +912,7 @@ void Calc::tangent (lDouble& x) else { if ( arcus_mode ) - x = std::atan(x) * 180.0L / PI; + x = std::atan(x) * 180.0L / pi_value; else { // Test if (x / 180) != 0 and x / 90 == 0 @@ -914,7 +922,7 @@ void Calc::tangent (lDouble& x) else if ( std::fabs(std::fmod(x, 180.0L)) < LDBL_EPSILON ) // x / 180 == 0 x = 0.0L; else - x = std::tan(x * PI / 180.0L); + x = std::tan(x * pi_value / 180.0L); } } @@ -943,8 +951,8 @@ void Calc::draw() bool Calc::isDataEntryKey (int key) const { // Test if key is in {'.', '0'..'9'} - const int data_entry_keys[] = - { + constexpr std::array key_list = + {{ Decimal_point, Zero, One, @@ -956,11 +964,11 @@ bool Calc::isDataEntryKey (int key) const Seven, Eight, Nine - }; + }}; - const int* iter = std::find (data_entry_keys, data_entry_keys + 11, key); + const auto& iter = std::find (key_list.begin(), key_list.end(), key); - if ( iter != data_entry_keys + 11 ) + if ( iter != key_list.end() ) return true; else return false; @@ -970,19 +978,19 @@ bool Calc::isDataEntryKey (int key) const bool Calc::isOperatorKey(int key) const { // Test if key is in {'*', '/', '+', '-', '^', '='} - const int operators[] = - { + constexpr std::array operators = + {{ Multiply, Divide, Add, Subtract, Power, Equals - }; + }}; - const int* iter = std::find (operators, operators + 6, key); + const auto& iter = std::find (operators.begin(), operators.end(), key); - if ( iter != operators + 6 ) + if ( iter != operators.end() ) return true; else return false; @@ -1092,8 +1100,8 @@ void Calc::adjustSize() //---------------------------------------------------------------------- const wchar_t* Calc::getButtonText (const std::size_t key) const { - static const wchar_t* const button_text[Calc::NUM_OF_BUTTONS] = - { + constexpr std::array button_text = + {{ L"&Sin", L"&Cos", L"&Tan", @@ -1128,7 +1136,7 @@ const wchar_t* Calc::getButtonText (const std::size_t key) const L"&.", L"&Âą", L"&=" - }; + }}; return button_text[key]; } diff --git a/examples/checklist.cpp b/examples/checklist.cpp index 6304866a..6469a68e 100644 --- a/examples/checklist.cpp +++ b/examples/checklist.cpp @@ -20,6 +20,7 @@ * . * ***********************************************************************/ +#include #include #include #include @@ -58,6 +59,7 @@ class CheckList final : public finalcut::FDialog private: // Method void populate(); + void adjustSize() override; // Event handlers void onKeyPress (finalcut::FKeyEvent*) override; @@ -67,7 +69,7 @@ class CheckList final : public finalcut::FDialog void cb_showList(); // Data members - finalcut::FListView listView{this}; + finalcut::FListView listview{this}; finalcut::FStatusBar status_bar{this}; }; @@ -80,25 +82,24 @@ CheckList::CheckList (finalcut::FWidget* parent) // (CERT, OOP50-CPP) FDialog::setText (L"Shopping list"); const std::size_t nf_offset = ( finalcut::FTerm::isNewFont() ) ? 1 : 0; - FDialog::setGeometry ( FPoint{int(1 + (parent->getWidth() - 28) / 2), 5} - , FSize{28 + nf_offset, 13} ); - setShadow(); - listView.ignorePadding(); - listView.setGeometry ( FPoint{1 + int(nf_offset), 2} + FDialog::setSize (FSize{28 + nf_offset, 13} ); + setShadow(); // Instead of the transparent window shadow + listview.ignorePadding(); + listview.setGeometry ( FPoint{1 + int(nf_offset), 2} , FSize{getWidth() - nf_offset, getHeight() - 1} ); // Add columns to the view - listView.addColumn ("Item"); - listView.addColumn ("Priority", 9); + listview.addColumn ("Item"); + listview.addColumn ("Priority", 9); // Set the type of sorting - listView.setColumnSortType (1, fc::by_name); - listView.setColumnSortType (2, fc::by_name); + listview.setColumnSortType (1, fc::by_name); + listview.setColumnSortType (2, fc::by_name); // Statusbar at the bottom finalcut::FString separator{}; separator << ' ' << fc::BoxDrawingsVertical << ' '; - listView.setStatusbarMessage ( finalcut::FString{} + listview.setStatusbarMessage ( finalcut::FString{} << " exit" << separator << " select an item" << separator << " see your pick list"); @@ -107,7 +108,7 @@ CheckList::CheckList (finalcut::FWidget* parent) populate(); // Add callback method - listView.addCallback + listview.addCallback ( "clicked", this, &CheckList::cb_showList @@ -121,29 +122,36 @@ CheckList::~CheckList() // destructor //---------------------------------------------------------------------- void CheckList::populate() { - const std::string list[][2] = - { - { "Milk", "Highest" }, - { "Cheese", "High" }, - { "Yoghurt", "Medium" }, - { "Bread", "Low" }, - { "Eggs", "High" }, - { "Toothpaste", "Medium" }, - { "Apples", "Lowest" }, - { "Bananas", "Medium" }, - { "Fish", "Medium" }, - { "Lemons", "Low" } - }; + constexpr std::array, 10> list = + {{ + {{ "Milk", "Highest" }}, + {{ "Cheese", "High" }}, + {{ "Yoghurt", "Medium" }}, + {{ "Bread", "Low" }}, + {{ "Eggs", "High" }}, + {{ "Toothpaste", "Medium" }}, + {{ "Apples", "Lowest" }}, + {{ "Bananas", "Medium" }}, + {{ "Fish", "Medium" }}, + {{ "Lemons", "Low" }} + }}; for (const auto& line : list) { - const finalcut::FStringList string_line (&line[0], &line[0] + 2); - auto iter = listView.insert (string_line); + const finalcut::FStringList string_line (line.begin(), line.end()); + auto iter = listview.insert (string_line); auto item = static_cast(*iter); item->setCheckable(true); } } +//---------------------------------------------------------------------- +void CheckList::adjustSize() +{ + finalcut::FDialog::adjustSize(); + setPos(FPoint{int(1 + (getDesktopWidth() - getWidth()) / 2), 5}); +} + //---------------------------------------------------------------------- void CheckList::onKeyPress (finalcut::FKeyEvent* ev) { @@ -170,18 +178,12 @@ void CheckList::onClose (finalcut::FCloseEvent* ev) //---------------------------------------------------------------------- void CheckList::cb_showList() { - auto iter = listView.beginOfList(); finalcut::FString shopping_list{}; - while ( iter != listView.endOfList() ) + for (auto item : listview.getData()) { - const auto item = static_cast(*iter); - if ( item->isChecked() ) - shopping_list << fc::Bullet << ' ' - << item->getText(1) << '\n'; - - ++iter; + shopping_list << fc::Bullet << ' ' << item->getText(1) << '\n'; } if ( shopping_list.isEmpty() ) diff --git a/examples/event-log.cpp b/examples/event-log.cpp index ee9284c8..0153d1d7 100644 --- a/examples/event-log.cpp +++ b/examples/event-log.cpp @@ -51,7 +51,7 @@ class EventDialog final : public finalcut::FDialog EventDialog (const EventDialog&) = delete; // Destructor - ~EventDialog(); + ~EventDialog() override; // Disable copy assignment operator (=) EventDialog& operator = (const EventDialog&) = delete; @@ -162,8 +162,10 @@ void EventDialog::onKeyPress (finalcut::FKeyEvent* ev) if ( key_name.isEmpty() ) key_name = wchar_t(key_id); - log << finalcut::FLog::Info - << "Key " << key_name << " (id " << key_id << ")" << std::flush; + // std::clog redirects all stream data to FLogger + std::clog << finalcut::FLog::Info + << "Key " << key_name + << " (id " << key_id << ")" << std::flush; finalcut::FDialog::onKeyPress(ev); } @@ -243,7 +245,7 @@ class EventLog final : public finalcut::FDialog, public std::ostringstream EventLog (const EventLog&) = delete; // Destructor - ~EventLog(); + ~EventLog() override; // Disable copy assignment operator (=) EventLog& operator = (const EventLog&) = delete; @@ -257,7 +259,7 @@ class EventLog final : public finalcut::FDialog, public std::ostringstream void adjustSize() override; // Data members - finalcut::FTextView scrollText{this}; + finalcut::FTextView scrolltext{this}; EventDialog* event_dialog{new EventDialog(this)}; }; @@ -273,8 +275,8 @@ EventLog::EventLog (finalcut::FWidget* parent) FDialog::setResizeable(); setMinimumSize (FSize{75, 5}); setShadow(); - scrollText.ignorePadding(); - scrollText.setGeometry (FPoint{1, 2}, FSize{getWidth(), getHeight() - 1}); + scrolltext.ignorePadding(); + scrolltext.setGeometry (FPoint{1, 2}, FSize{getWidth(), getHeight() - 1}); event_dialog->setFocus(); addTimer(250); // Starts the timer every 250 milliseconds } @@ -288,9 +290,9 @@ void EventLog::onTimer (finalcut::FTimerEvent*) { if ( ! str().empty() ) { - scrollText.append(str()); + scrolltext.append(str()); str(""); - scrollText.scrollToEnd(); + scrolltext.scrollToEnd(); redraw(); updateTerminal(); } @@ -306,7 +308,7 @@ void EventLog::onClose (finalcut::FCloseEvent* ev) void EventLog::adjustSize() { finalcut::FDialog::adjustSize(); - scrollText.setGeometry (FPoint{1, 2}, FSize(getWidth(), getHeight() - 1)); + scrolltext.setGeometry (FPoint{1, 2}, FSize(getWidth(), getHeight() - 1)); } diff --git a/examples/input-dialog.cpp b/examples/input-dialog.cpp index e977d60d..c4bb2245 100644 --- a/examples/input-dialog.cpp +++ b/examples/input-dialog.cpp @@ -65,7 +65,7 @@ int main (int argc, char* argv[]) finalcut::FDialog dgl{&app}; dgl.setText ("Data input"); dgl.setGeometry (FPoint{4, 2}, FSize{37, 22}); - dgl.setShadow(); + dgl.setShadow(); // Instead of the transparent window shadow // Create input fields finalcut::FLineEdit name_field {&dgl}; @@ -93,22 +93,22 @@ int main (int argc, char* argv[]) c_field.setGeometry (FPoint{11, 11}, FSize{4, 1}); // Create the button group - finalcut::FButtonGroup radioButtonGroup {"Sex", &dgl}; - radioButtonGroup.setGeometry(FPoint{2, 13}, FSize{13, 4}); + finalcut::FButtonGroup radiobutton_group {"Sex", &dgl}; + radiobutton_group.setGeometry(FPoint{2, 13}, FSize{13, 4}); // Create radio buttons - finalcut::FRadioButton male {"&Male", &radioButtonGroup}; - finalcut::FRadioButton female {"&Female", &radioButtonGroup}; + finalcut::FRadioButton male {"&Male", &radiobutton_group}; + finalcut::FRadioButton female {"&Female", &radiobutton_group}; male.setGeometry (FPoint{1, 1}, FSize{8, 1}); female.setGeometry (FPoint{1, 2}, FSize{10, 1}); // Create another button group - finalcut::FButtonGroup checkButtonGroup {"&Data options", &dgl}; - checkButtonGroup.setGeometry(FPoint{16, 13}, FSize{19, 4}); + finalcut::FButtonGroup checkbutton_group {"&Data options", &dgl}; + checkbutton_group.setGeometry(FPoint{16, 13}, FSize{19, 4}); // Create checkbox buttons - finalcut::FCheckBox check1 {"Save data", &checkButtonGroup}; - finalcut::FCheckBox check2 {"Encrypt data", &checkButtonGroup}; + finalcut::FCheckBox check1 {"Save data", &checkbutton_group}; + finalcut::FCheckBox check2 {"Encrypt data", &checkbutton_group}; check1.setGeometry (FPoint{1, 1}, FSize{13, 1}); check2.setGeometry (FPoint{1, 2}, FSize{16, 1}); check2.setDisable(); diff --git a/examples/listbox.cpp b/examples/listbox.cpp index da66a48b..3c5cef26 100644 --- a/examples/listbox.cpp +++ b/examples/listbox.cpp @@ -38,8 +38,8 @@ static std::weak_ptr temp_str; // Function prototypes void doubleToItem ( FListBoxItem& - , FDataPtr container - , int index); + , FDataAccess* container + , std::size_t index); FString& doubleToString (std::list::const_iterator iter); FString& mapToString ( std::map::const_iterator iter ); @@ -47,14 +47,15 @@ FString& mapToString ( std::map* double_list_ptr; - double_list_ptr dbllist = static_cast(container); - std::list::iterator iter = dbllist->begin(); + typedef std::list DblList; + DblList& dbl_list = flistboxhelper::getContainer(container); + std::list::iterator iter = dbl_list.begin(); std::advance (iter, index); item.setText (FString() << *iter); - item.setData (FDataPtr(&(*iter))); + item.setData (*iter); } // Insert converter functions @@ -100,7 +101,7 @@ class Listbox final : public FDialog FListBox list1{this}; FListBox list2{this}; FListBox list3{this}; - FButton Quit{this}; + FButton quit{this}; }; //---------------------------------------------------------------------- @@ -129,7 +130,7 @@ Listbox::Listbox (FWidget* parent) // // Insert via lazy conversion on print // - list2.insert (&double_list, doubleToItem); + list2.insert (double_list, doubleToItem); // (container, converter) // // Direct insert of the complete list @@ -150,11 +151,11 @@ Listbox::Listbox (FWidget* parent) list3.setText ("key: value"); // Quit button - Quit.setGeometry(FPoint{42, 12}, FSize{10, 1}); - Quit.setText (L"&Quit"); + quit.setGeometry(FPoint{42, 12}, FSize{10, 1}); + quit.setText (L"&Quit"); // Add quit button function callback - Quit.addCallback + quit.addCallback ( "clicked", finalcut::getFApplication(), diff --git a/examples/listview.cpp b/examples/listview.cpp index 6f7c905a..a0478895 100644 --- a/examples/listview.cpp +++ b/examples/listview.cpp @@ -20,6 +20,7 @@ * . * ***********************************************************************/ +#include #include #include #include @@ -62,8 +63,8 @@ class Listview final : public finalcut::FDialog void cb_showInMessagebox(); // Data members - finalcut::FListView listView{this}; - finalcut::FButton Quit{this}; + finalcut::FListView listview{this}; + finalcut::FButton quit{this}; }; //---------------------------------------------------------------------- @@ -71,44 +72,44 @@ Listview::Listview (finalcut::FWidget* parent) : finalcut::FDialog{parent} { // Set FListView geometry - listView.setGeometry(FPoint{2, 1}, FSize{33, 14}); + listview.setGeometry(FPoint{2, 1}, FSize{33, 14}); // Add columns to the view - listView.addColumn ("City"); - listView.addColumn ("Condition"); - listView.addColumn ("Temp."); - listView.addColumn ("Humidity"); - listView.addColumn ("Pressure", 10); + listview.addColumn ("City"); + listview.addColumn ("Condition"); + listview.addColumn ("Temp."); + listview.addColumn ("Humidity"); + listview.addColumn ("Pressure", 10); // Set right alignment for the third, fourth, and fifth column - listView.setColumnAlignment (3, fc::alignRight); - listView.setColumnAlignment (4, fc::alignRight); - listView.setColumnAlignment (5, fc::alignRight); + listview.setColumnAlignment (3, fc::alignRight); + listview.setColumnAlignment (4, fc::alignRight); + listview.setColumnAlignment (5, fc::alignRight); // Set the type of sorting - listView.setColumnSortType (1, fc::by_name); - listView.setColumnSortType (2, fc::by_name); - listView.setColumnSortType (3, fc::by_number); - listView.setColumnSortType (4, fc::by_number); - listView.setColumnSortType (5, fc::by_number); + listview.setColumnSortType (1, fc::by_name); + listview.setColumnSortType (2, fc::by_name); + listview.setColumnSortType (3, fc::by_number); + listview.setColumnSortType (4, fc::by_number); + listview.setColumnSortType (5, fc::by_number); // Sort in ascending order by the 1st column - listView.setColumnSort (1, fc::ascending); + listview.setColumnSort (1, fc::ascending); // Sorting follows later automatically on insert(). // Otherwise you could start the sorting directly with sort() // Allways show the sort indicator (â–ŧ/▲) - listView.hideSortIndicator(false); + listview.hideSortIndicator(false); // Populate FListView with a list of items populate(); // Quit button - Quit.setGeometry(FPoint{24, 16}, FSize{10, 1}); - Quit.setText (L"&Quit"); + quit.setGeometry(FPoint{24, 16}, FSize{10, 1}); + quit.setText (L"&Quit"); // Add some function callbacks - Quit.addCallback + quit.addCallback ( "clicked", finalcut::getFApplication(), @@ -116,7 +117,7 @@ Listview::Listview (finalcut::FWidget* parent) this ); - listView.addCallback + listview.addCallback ( "clicked", this, &Listview::cb_showInMessagebox @@ -130,55 +131,55 @@ Listview::~Listview() // destructor //---------------------------------------------------------------------- void Listview::populate() { - const std::string weather[][5] = - { - { "Alexandria", "Sunny", "31°C", "61%", "1006.4 mb" }, - { "Amsterdam", "Cloudy", "21°C", "82%", "1021.3 mb" }, - { "Baghdad", "Fair", "47°C", "9%", "1001.0 mb" }, - { "Bangkok", "Partly Cloudy", "30°C", "69%", "1002.0 mb" }, - { "Beijing", "Fair", "31°C", "68%", "1007.1 mb" }, - { "Berlin", "Cloudy", "22°C", "53%", "1022.0 mb" }, - { "BogotÃĄ", "Fair", "9°C", "95%", "1028.5 mb" }, - { "Budapest", "Partly Cloudy", "23°C", "37%", "1020.7 mb" }, - { "Buenos Aires", "Cloudy", "7°C", "73%", "1019.0 mb" }, - { "Cairo", "Fair", "39°C", "22%", "1006.1 mb" }, - { "Cape Town", "Partly Cloudy", "12°C", "45%", "1030.1 mb" }, - { "Chicago", "Mostly Cloudy", "21°C", "81%", "1014.9 mb" }, - { "Delhi", "Haze", "33°C", "68%", "998.0 mb" }, - { "Dhaka", "Haze", "32°C", "64%", "996.3 mb" }, - { "Houston", "Cloudy", "23°C", "100%", "1014.2 mb" }, - { "Istanbul", "Mostly Cloudy", "27°C", "61%", "1011.2 mb" }, - { "Jakarta", "Fair", "28°C", "71%", "1009.1 mb" }, - { "Jerusalem", "Sunny", "35°C", "17%", "1005.8 mb" }, - { "Johannesburg", "Fair", "18°C", "16%", "1020.0 mb" }, - { "Karachi", "Mostly Cloudy", "29°C", "76%", "998.0 mb" }, - { "Lagos", "Mostly Cloudy", "27°C", "86%", "1014.6 mb" }, - { "Lima", "Cloudy", "17°C", "83%", "1017.3 mb" }, - { "London", "Cloudy", "23°C", "71%", "1023.0 mb" }, - { "Los Angeles", "Fair", "21°C", "78%", "1011.9 mb" }, - { "Madrid", "Fair", "32°C", "35%", "1020.0 mb" }, - { "Mexico City", "Partly Cloudy", "14°C", "79%", "1028.5 mb" }, - { "Moscow", "Partly Cloudy", "24°C", "54%", "1014.2 mb" }, - { "Mumbai", "Haze", "28°C", "77%", "1003.0 mb" }, - { "New York City", "Sunny", "21°C", "80%", "1014.2 mb" }, - { "Paris", "Partly Cloudy", "27°C", "57%", "1024.4 mb" }, - { "Reykjavík", "Mostly Cloudy", "11°C", "76%", "998.6 mb" }, - { "Rio de Janeiro", "Fair", "24°C", "64%", "1022.0 mb" }, - { "Rome", "Fair", "32°C", "18%", "1014.2 mb" }, - { "Saint Petersburg", "Mostly Cloudy", "18°C", "55%", "1014.6 mb" }, - { "SÃŖo Paulo", "Fair", "19°C", "53%", "1024.0 mb" }, - { "Seoul", "Cloudy", "26°C", "87%", "1012.2 mb" }, - { "Shanghai", "Fair", "32°C", "69%", "1009.1 mb" }, - { "Singapore", "Mostly Cloudy", "29°C", "73%", "1009.1 mb" }, - { "Tehran", "Fair", "36°C", "14%", "1013.2 mb" }, - { "Tokyo", "Mostly Cloudy", "28°C", "67%", "1009.1 mb" }, - { "Zurich", "Mostly Cloudy", "23°C", "44%", "1023.7 mb" } - }; + constexpr std::array, 41> weather = + {{ + {{ "Alexandria", "Sunny", "31°C", "61%", "1006.4 mb" }}, + {{ "Amsterdam", "Cloudy", "21°C", "82%", "1021.3 mb" }}, + {{ "Baghdad", "Fair", "47°C", "9%", "1001.0 mb" }}, + {{ "Bangkok", "Partly Cloudy", "30°C", "69%", "1002.0 mb" }}, + {{ "Beijing", "Fair", "31°C", "68%", "1007.1 mb" }}, + {{ "Berlin", "Cloudy", "22°C", "53%", "1022.0 mb" }}, + {{ "BogotÃĄ", "Fair", "9°C", "95%", "1028.5 mb" }}, + {{ "Budapest", "Partly Cloudy", "23°C", "37%", "1020.7 mb" }}, + {{ "Buenos Aires", "Cloudy", "7°C", "73%", "1019.0 mb" }}, + {{ "Cairo", "Fair", "39°C", "22%", "1006.1 mb" }}, + {{ "Cape Town", "Partly Cloudy", "12°C", "45%", "1030.1 mb" }}, + {{ "Chicago", "Mostly Cloudy", "21°C", "81%", "1014.9 mb" }}, + {{ "Delhi", "Haze", "33°C", "68%", "998.0 mb" }}, + {{ "Dhaka", "Haze", "32°C", "64%", "996.3 mb" }}, + {{ "Houston", "Cloudy", "23°C", "100%", "1014.2 mb" }}, + {{ "Istanbul", "Mostly Cloudy", "27°C", "61%", "1011.2 mb" }}, + {{ "Jakarta", "Fair", "28°C", "71%", "1009.1 mb" }}, + {{ "Jerusalem", "Sunny", "35°C", "17%", "1005.8 mb" }}, + {{ "Johannesburg", "Fair", "18°C", "16%", "1020.0 mb" }}, + {{ "Karachi", "Mostly Cloudy", "29°C", "76%", "998.0 mb" }}, + {{ "Lagos", "Mostly Cloudy", "27°C", "86%", "1014.6 mb" }}, + {{ "Lima", "Cloudy", "17°C", "83%", "1017.3 mb" }}, + {{ "London", "Cloudy", "23°C", "71%", "1023.0 mb" }}, + {{ "Los Angeles", "Fair", "21°C", "78%", "1011.9 mb" }}, + {{ "Madrid", "Fair", "32°C", "35%", "1020.0 mb" }}, + {{ "Mexico City", "Partly Cloudy", "14°C", "79%", "1028.5 mb" }}, + {{ "Moscow", "Partly Cloudy", "24°C", "54%", "1014.2 mb" }}, + {{ "Mumbai", "Haze", "28°C", "77%", "1003.0 mb" }}, + {{ "New York City", "Sunny", "21°C", "80%", "1014.2 mb" }}, + {{ "Paris", "Partly Cloudy", "27°C", "57%", "1024.4 mb" }}, + {{ "Reykjavík", "Mostly Cloudy", "11°C", "76%", "998.6 mb" }}, + {{ "Rio de Janeiro", "Fair", "24°C", "64%", "1022.0 mb" }}, + {{ "Rome", "Fair", "32°C", "18%", "1014.2 mb" }}, + {{ "Saint Petersburg", "Mostly Cloudy", "18°C", "55%", "1014.6 mb" }}, + {{ "SÃŖo Paulo", "Fair", "19°C", "53%", "1024.0 mb" }}, + {{ "Seoul", "Cloudy", "26°C", "87%", "1012.2 mb" }}, + {{ "Shanghai", "Fair", "32°C", "69%", "1009.1 mb" }}, + {{ "Singapore", "Mostly Cloudy", "29°C", "73%", "1009.1 mb" }}, + {{ "Tehran", "Fair", "36°C", "14%", "1013.2 mb" }}, + {{ "Tokyo", "Mostly Cloudy", "28°C", "67%", "1009.1 mb" }}, + {{ "Zurich", "Mostly Cloudy", "23°C", "44%", "1023.7 mb" }} + }}; for (const auto& place : weather) { - const finalcut::FStringList line (&place[0], &place[0] + 5); - listView.insert (line); + const finalcut::FStringList line (place.begin(), place.end()); + listview.insert (line); } } @@ -191,13 +192,16 @@ void Listview::onClose (finalcut::FCloseEvent* ev) //---------------------------------------------------------------------- void Listview::cb_showInMessagebox() { - const auto& item = listView.getCurrentItem(); + const auto& item = listview.getCurrentItem(); finalcut::FMessageBox info ( "Weather in " + item->getText(1) , " Condition: " + item->getText(2) + "\n" "Temperature: " + item->getText(3) + "\n" " Humidity: " + item->getText(4) + "\n" " Pressure: " + item->getText(5) - , finalcut::FMessageBox::Ok, 0, 0, this ); + , finalcut::FMessageBox::Ok + , finalcut::FMessageBox::Reject + , finalcut::FMessageBox::Reject + , this ); info.show(); } diff --git a/examples/mandelbrot.cpp b/examples/mandelbrot.cpp index fe9d1c44..e087776a 100644 --- a/examples/mandelbrot.cpp +++ b/examples/mandelbrot.cpp @@ -75,8 +75,8 @@ void Mandelbrot::draw() const int xoffset{2}; const int yoffset{2}; - const int Cols = int(getClientWidth()); - const int Lines = int(getClientHeight()); + const auto Cols = int(getClientWidth()); + const auto Lines = int(getClientHeight()); int current_line{0}; if ( Cols < 2 || Lines < 2 ) @@ -167,7 +167,7 @@ int main (int argc, char* argv[]) // Create a simple dialog box Mandelbrot mb{&app}; mb.setGeometry (FPoint{6, 1}, FSize{70, 23}); - mb.setShadow(); + mb.setShadow(); // Instead of the transparent window shadow // Set the mandelbrot object as main widget finalcut::FWidget::setMainWidget(&mb); diff --git a/examples/menu.cpp b/examples/menu.cpp index 216c630f..a60dd65e 100644 --- a/examples/menu.cpp +++ b/examples/menu.cpp @@ -151,8 +151,10 @@ Menu::Menu (finalcut::FWidget* parent) // Info label Info << " Activate menu bar\n" << "+ Activate menu bar\n" + << " Activate menu bar\n" + << "+ Open dialog menu\n" << "+ Exit"; - Info.setGeometry(FPoint{2, 1}, FSize{36, 3}); + Info.setGeometry(FPoint{2, 1}, FSize{36, 5}); } //---------------------------------------------------------------------- @@ -291,8 +293,8 @@ void Menu::defaultCallback (const finalcut::FMenuList* mb) //---------------------------------------------------------------------- void Menu::adjustSize() { - const int pw = int(getDesktopWidth()); - const int ph = int(getDesktopHeight()); + const auto pw = int(getDesktopWidth()); + const auto ph = int(getDesktopHeight()); setX (1 + (pw - int(getWidth())) / 2, false); setY (1 + (ph - int(getHeight())) / 4, false); finalcut::FDialog::adjustSize(); @@ -327,8 +329,7 @@ int main (int argc, char* argv[]) // Create main dialog object Menu main_dlg {&app}; main_dlg.setText ("Menu example"); - main_dlg.setGeometry ( FPoint{int(1 + (app.getWidth() - 40) / 2), 2} - , FSize{40, 6} ); + main_dlg.setSize ({40, 8}); main_dlg.setShadow(); // Set dialog main_dlg as main widget diff --git a/examples/mouse.cpp b/examples/mouse.cpp index e986e937..5d76c3d3 100644 --- a/examples/mouse.cpp +++ b/examples/mouse.cpp @@ -428,7 +428,7 @@ void MouseDraw::onClose (finalcut::FCloseEvent* ev) //---------------------------------------------------------------------- void MouseDraw::draw() { - const int y_max = int(getHeight()); + const auto y_max = int(getHeight()); finalcut::FDialog::draw(); setColor(); @@ -463,8 +463,8 @@ void MouseDraw::draw() //---------------------------------------------------------------------- void MouseDraw::drawBrush (int x, int y, bool swap_color) { - const int Cols = int(getWidth()); - const int Lines = int(getHeight()); + const auto Cols = int(getWidth()); + const auto Lines = int(getHeight()); if ( x > 10 && x < Cols && y > 2 && y < Lines ) { @@ -537,8 +537,8 @@ void MouseDraw::adjustSize() { const std::size_t w{60}; const std::size_t h{18}; - const int x = 1 + int((getParentWidget()->getWidth() - w) / 2); - const int y = 1 + int((getParentWidget()->getHeight() - h) / 2); + const int x = 1 + int((getDesktopWidth() - w) / 2); + const int y = 1 + int((getDesktopHeight() - h) / 2); setGeometry (FPoint{x, y}, FSize{w, h}, false); finalcut::FDialog::adjustSize(); } @@ -590,7 +590,6 @@ int main (int argc, char* argv[]) // Create a simple dialog box MouseDraw mouse_draw{&app}; - mouse_draw.setGeometry (FPoint{12, 4}, FSize{60, 18}); // Set dialog object mouse_draw as main widget finalcut::FWidget::setMainWidget(&mouse_draw); diff --git a/examples/opti-move.cpp b/examples/opti-move.cpp index ddb33701..79f9c359 100644 --- a/examples/opti-move.cpp +++ b/examples/opti-move.cpp @@ -20,6 +20,7 @@ * . * ***********************************************************************/ +#include #include #include #include @@ -65,8 +66,8 @@ bool keyPressed() void term_boundaries (int& x, int& y) { // checks and corrects the terminal boundaries - const int term_width = int(app->getDesktopWidth()); - const int term_height = int(app->getDesktopHeight()); + const auto term_width = int(app->getDesktopWidth()); + const auto term_height = int(app->getDesktopHeight()); if ( x < 0 ) x = 0; @@ -93,14 +94,15 @@ void move (int xold, int yold, int xnew, int ynew) finalcut::FString from{}; finalcut::FString to{}; finalcut::FString byte{}; - const std::string ctrl_character[] = - { + + constexpr std::array ctrl_character = + {{ "NUL", "SOH", "STX", "ETX", "EOT", "ENQ", "ACK", "BEL", "BS", "Tab", "LF", "VT", "FF", "CR", "SO", "SI", "DLE", "DC1", "DC2", "DC3", "DC4", "NAK", "SYN", "ETB", "CAN", "EM", "SUB", "Esc", "FS", "GS", "RS", "US", "Space" - }; + }}; term_boundaries(xold, yold); term_boundaries(xnew, ynew); @@ -209,8 +211,11 @@ DirectLogger::~DirectLogger() // destructor //---------------------------------------------------------------------- int main (int argc, char* argv[]) { - // Disable mouse - finalcut::FStartOptions::getFStartOptions().mouse_support = false; + // Disable mouse, color palette changes and terminal data requests + auto& start_options = finalcut::FStartOptions::getFStartOptions(); + start_options.mouse_support = false; + start_options.color_change = false; + start_options.terminal_data_request = false; // Create the application object finalcut::FApplication term_app{argc, argv}; @@ -225,8 +230,8 @@ int main (int argc, char* argv[]) app = &term_app; // Get screen dimension - int xmax = int(term_app.getDesktopWidth() - 1); - int ymax = int(term_app.getDesktopHeight() - 1); + auto xmax = int(term_app.getDesktopWidth() - 1); + auto ymax = int(term_app.getDesktopHeight() - 1); finalcut::FString line{std::size_t(xmax) + 1, '-'}; // Place the cursor in the upper left corner diff --git a/examples/rotozoomer.cpp b/examples/rotozoomer.cpp index 270c3346..31d6d9c5 100644 --- a/examples/rotozoomer.cpp +++ b/examples/rotozoomer.cpp @@ -20,10 +20,11 @@ * . * ***********************************************************************/ +#include + #include #include - -#include +#include #include @@ -74,7 +75,7 @@ class RotoZoomer final : public finalcut::FDialog bool benchmark{false}; int loops{0}; int path{0}; - wchar_t data[256]{}; + std::wstring data{std::wstring(256, L'\0')}; finalcut::FString report{}; time_point start{}; time_point end{}; @@ -89,31 +90,35 @@ RotoZoomer::RotoZoomer (finalcut::FWidget* parent, bool b, int l) { FDialog::setText ("Rotozoomer effect"); - int h{0}; + std::size_t h{0}; - for (int j{0}; j < 8; j++) + for (std::size_t j{0}; j < 8; j++) { - for (int i{0}; i < 8; i++) + for (std::size_t i{0}; i < 8; i++) { - data[h++] = L' '; + data[h] = L' '; + h++; } - for (int i{0}; i < 8; i++) + for (std::size_t i{0}; i < 8; i++) { - data[h++] = L'+'; + data[h] = L'+'; + h++; } } - for (int j{0}; j < 8; j++) + for (std::size_t j{0}; j < 8; j++) { - for (int i{0}; i < 8; i++) + for (std::size_t i{0}; i < 8; i++) { - data[h++] = L'x'; + data[h] = L'x'; + h++; } - for (int i{0}; i < 8; i++) + for (std::size_t i{0}; i < 8; i++) { - data[h++] = L' '; + data[h] = L' '; + h++; } } } @@ -129,24 +134,24 @@ void RotoZoomer::draw() start = system_clock::now(); finalcut::FDialog::draw(); - double cx = double(80.0 / 2.0 + (80.0 / 2.0 * std::sin(double(path) / 50.0))); - double cy = double(23.0 + (23.0 * std::cos(double(path) / 50.0))); - double r = double(128.0 + 96.0 * std::cos(double(path) / 10.0)); - double a = double(path) / 50.0; + auto cx = double(80.0 / 2.0 + (80.0 / 2.0 * std::sin(double(path) / 50.0))); + auto cy = double(23.0 + (23.0 * std::cos(double(path) / 50.0))); + auto r = double(128.0 + 96.0 * std::cos(double(path) / 10.0)); + auto a = double(path) / 50.0; rotozoomer (cx, cy, r, a); } //---------------------------------------------------------------------- void RotoZoomer::rotozoomer (double cx, double cy, double r, double a) { - const int Cols = int(getClientWidth()); - const int Lines = int(getClientHeight()); - int Ax = int(4096.0 * (cx + r * std::cos(a))); - int Ay = int(4096.0 * (cy + r * std::sin(a))); - int Bx = int(4096.0 * (cx + r * std::cos(a + 2.02358))); - int By = int(4096.0 * (cy + r * std::sin(a + 2.02358))); - int Cx = int(4096.0 * (cx + r * std::cos(a - 1.11701))); - int Cy = int(4096.0 * (cy + r * std::sin(a - 1.11701))); + const auto Cols = int(getClientWidth()); + const auto Lines = int(getClientHeight()); + auto Ax = int(4096.0 * (cx + r * std::cos(a))); + auto Ay = int(4096.0 * (cy + r * std::sin(a))); + auto Bx = int(4096.0 * (cx + r * std::cos(a + 2.02358))); + auto By = int(4096.0 * (cy + r * std::sin(a + 2.02358))); + auto Cx = int(4096.0 * (cx + r * std::cos(a - 1.11701))); + auto Cy = int(4096.0 * (cy + r * std::sin(a - 1.11701))); int dxdx = (Bx - Ax) / 80; int dydx = (By - Ay) / 80; int dxdy = (Cx - Ax) / 23; @@ -160,7 +165,7 @@ void RotoZoomer::rotozoomer (double cx, double cy, double r, double a) for (int x = 0; x < Cols; x++) { - wchar_t ch = data[((Cy >> 14) & 0xf) + ((Cx >> 10) & 0xf0)]; + auto ch = data[((Cy >> 14) & 0xf) + ((Cx >> 10) & 0xf0)]; if ( ch == '+' ) print() << finalcut::FColorPair{fc::Black, fc::Red}; @@ -226,7 +231,7 @@ void RotoZoomer::onShow (finalcut::FShowEvent*) end = system_clock::now(); generateReport(); flush(); - quit(); + close(); } } @@ -261,7 +266,9 @@ void RotoZoomer::onKeyPress (finalcut::FKeyEvent* ev) //---------------------------------------------------------------------- void RotoZoomer::onClose (finalcut::FCloseEvent* ev) { - if ( ! benchmark ) + if ( benchmark ) + ev->accept(); + else finalcut::FApplication::closeConfirmationDialog (this, ev); } @@ -305,6 +312,9 @@ int main (int argc, char* argv[]) || strcmp(argv[1], "-b") == 0 ) ) { benchmark = true; + // Disable terminal data requests + auto& start_options = finalcut::FStartOptions::getFStartOptions(); + start_options.terminal_data_request = false; } { // Create the application object in this scope @@ -317,10 +327,8 @@ int main (int argc, char* argv[]) if ( benchmark ) roto.setGeometry (FPoint{1, 1}, FSize{80, 24}); - else - roto.setGeometry (FPoint{5, 1}, FSize{72, 23}); - roto.setShadow(); + roto.setShadow(); // Instead of the transparent window shadow // Set the RotoZoomer object as main widget finalcut::FWidget::setMainWidget(&roto); diff --git a/examples/scrollview.cpp b/examples/scrollview.cpp index 22bbac87..6ef8b54f 100644 --- a/examples/scrollview.cpp +++ b/examples/scrollview.cpp @@ -118,8 +118,8 @@ Scrollview::~Scrollview() void Scrollview::setScrollSize (const FSize& size) { FScrollView::setScrollSize (size); - const int width = int(size.getWidth()); - const int height = int(size.getHeight()); + const auto width = int(size.getWidth()); + const auto height = int(size.getHeight()); go_south.setPos (FPoint{width - 5, 1}); go_west.setPos (FPoint{width - 5, height - 1}); go_north.setPos (FPoint{1, height - 1}); diff --git a/examples/string-operations.cpp b/examples/string-operations.cpp index a9ef2794..faacd892 100644 --- a/examples/string-operations.cpp +++ b/examples/string-operations.cpp @@ -481,9 +481,9 @@ void stringSplittingExample() void fromatStringExample() { // Test: format a string with sprintf - finalcut::FString formatStr{""}; + finalcut::FString format_str{""}; std::cout << " formatted: " - << formatStr.sprintf("sqrt(%d) = %d", 16, 4) + << format_str.sprintf("sqrt(%d) = %d", 16, 4) << std::endl; } diff --git a/examples/term-attributes.cpp b/examples/term-attributes.cpp index 65ec75dd..f7da8ef3 100644 --- a/examples/term-attributes.cpp +++ b/examples/term-attributes.cpp @@ -63,7 +63,7 @@ class AttribDlg final : public finalcut::FDialog private: // Constants - static constexpr FColor UNDEFINED = static_cast(-2); + static constexpr auto UNDEFINED = static_cast(-2); // Method void adjustSize() override; @@ -177,8 +177,8 @@ void AttribDlg::cb_back() //---------------------------------------------------------------------- void AttribDlg::adjustSize() { - int x = int((getDesktopWidth() - getWidth()) / 2); - int y = int((getDesktopHeight() - getHeight()) / 2) + 1; + auto x = int((getDesktopWidth() - getWidth()) / 2); + auto y = int((getDesktopHeight() - getHeight()) / 2) + 1; if ( x < 1 ) x = 1; @@ -498,9 +498,8 @@ int main (int argc, char* argv[]) // This object will be automatically deleted by // the parent object "app" (FObject destructor). AttribDlg dialog{&app}; - - dialog.setGeometry (FPoint{6, 2}, FSize{69, 21}); - dialog.setShadow(); + dialog.setSize (FSize{69, 21}); + dialog.setShadow(); // Instead of the transparent window shadow // Create the attribute demo widget as a child object from the dialog AttribDemo demo(&dialog); diff --git a/examples/termcap.cpp b/examples/termcap.cpp index bbe7f067..f93935f7 100644 --- a/examples/termcap.cpp +++ b/examples/termcap.cpp @@ -20,6 +20,7 @@ * . * ***********************************************************************/ +#include #include #include #include @@ -42,22 +43,22 @@ void string(); // struct data //---------------------------------------------------------------------- -struct data +struct Data { - struct alignas(alignof(std::string)) termcap_string + struct alignas(alignof(std::string)) TermcapString { const std::string name; const fc::termcaps cap; }; - static termcap_string strings[]; + static std::array strings; }; //---------------------------------------------------------------------- // struct data - string data array //---------------------------------------------------------------------- -data::termcap_string data::strings[] = -{ +std::array Data::strings = +{{ { "t_bell", fc::t_bell }, { "t_erase_chars", fc::t_erase_chars }, { "t_clear_screen", fc::t_clear_screen }, @@ -99,6 +100,7 @@ data::termcap_string data::strings[] = { "t_parm_right_cursor", fc::t_parm_right_cursor }, { "t_save_cursor", fc::t_save_cursor }, { "t_restore_cursor", fc::t_restore_cursor }, + { "t_cursor_style", fc::t_cursor_style }, { "t_scroll_forward", fc::t_scroll_forward }, { "t_scroll_reverse", fc::t_scroll_reverse }, { "t_enter_ca_mode", fc::t_enter_ca_mode }, @@ -140,7 +142,7 @@ data::termcap_string data::strings[] = { "t_keypad_xmit", fc::t_keypad_xmit }, { "t_keypad_local", fc::t_keypad_local }, { "t_key_mouse", fc::t_key_mouse } -}; +}}; //---------------------------------------------------------------------- @@ -174,11 +176,11 @@ void tcapString (const std::string& name, const char cap_str[]) return; } - const uInt len = uInt(std::strlen(cap_str)); + const auto len = uInt(std::strlen(cap_str)); for (uInt i{0}; i < len; i++) { - const uChar c = uChar(cap_str[i]); + const auto c = uChar(cap_str[i]); if ( c > 127 ) { @@ -282,10 +284,9 @@ void numeric() void string() { std::cout << "\r\n[String]\r\n"; - const finalcut::FTermcap::tcap_map (&tcap_strings)[] \ - = finalcut::FTermcap::strings; + const auto& tcap_strings = finalcut::FTermcap::strings; - for (const auto& entry : data::strings) + for (const auto& entry : Data::strings) { const std::string name = entry.name; const fc::termcaps cap = entry.cap; diff --git a/examples/transparent.cpp b/examples/transparent.cpp index ac8d5644..80e91e7b 100644 --- a/examples/transparent.cpp +++ b/examples/transparent.cpp @@ -213,7 +213,7 @@ MainWindow::MainWindow (finalcut::FWidget* parent) ibg->unsetTransparentShadow(); // Set statusbar text for this window - setStatusbarMessage("Press Q to quit"); + FDialog::setStatusbarMessage("Press Q to quit"); unsetTransparentShadow(); activateDialog(); @@ -256,12 +256,11 @@ void MainWindow::onShow (finalcut::FShowEvent*) //---------------------------------------------------------------------- void MainWindow::onTimer (finalcut::FTimerEvent*) { - wchar_t first_Char[2]; std::size_t length = line1.getLength(); - first_Char[0] = line1[0]; - first_Char[1] = line2[0]; - line1 = line1.right(length - 1) + first_Char[0]; - line2 = line2.right(length - 1) + first_Char[1]; + const wchar_t first_char1 = line1[0]; + const wchar_t first_char2 = line2[0]; + line1 = line1.right(length - 1) + first_char1; + line2 = line2.right(length - 1) + first_char2; redraw(); flush(); } diff --git a/examples/treeview.cpp b/examples/treeview.cpp index 438ab0f3..3f3d8123 100644 --- a/examples/treeview.cpp +++ b/examples/treeview.cpp @@ -33,7 +33,7 @@ using finalcut::FSize; // Function prototypes -sInt64 StringToNumber (const finalcut::FString&); +sInt64 stringToNumber (const finalcut::FString&); bool sortAscending (const finalcut::FObject*, const finalcut::FObject*); bool sortDescending (const finalcut::FObject*, const finalcut::FObject*); bool isLessThanInteger (const finalcut::FString&, const finalcut::FString&); @@ -44,13 +44,13 @@ bool isGreaterThanDouble (const finalcut::FString&, const finalcut::FString&); // non-member functions //---------------------------------------------------------------------- -sInt64 StringToNumber (const finalcut::FString& str) +sInt64 stringToNumber (const finalcut::FString& str) { // Cut off one character (because LONG_MAX = 2147483647) - auto NumString = str.left(str.getLength() - 1); - NumString = NumString.replace(",", ""); - NumString = NumString.replace('.', ""); - sInt64 number = sInt64(NumString.toLong()); + auto num_string = str.left(str.getLength() - 1); + num_string = num_string.replace(",", ""); + num_string = num_string.replace('.', ""); + auto number = sInt64(num_string.toLong()); return number; } @@ -58,8 +58,8 @@ sInt64 StringToNumber (const finalcut::FString& str) inline bool isLessThanInteger ( const finalcut::FString& lhs , const finalcut::FString& rhs ) { - const sInt64 l_number = StringToNumber(lhs); - const sInt64 r_number = StringToNumber(rhs); + const sInt64 l_number = stringToNumber(lhs); + const sInt64 r_number = stringToNumber(rhs); return bool( l_number < r_number ); // lhs < rhs } @@ -77,8 +77,8 @@ inline bool isLessThanDouble ( const finalcut::FString& lhs inline bool isGreaterThanInteger ( const finalcut::FString& lhs , const finalcut::FString& rhs ) { - const sInt64 l_number = StringToNumber(lhs); - const sInt64 r_number = StringToNumber(rhs); + const sInt64 l_number = stringToNumber(lhs); + const sInt64 r_number = stringToNumber(rhs); return bool( l_number > r_number ); // lhs > rhs } @@ -168,8 +168,8 @@ class Treeview final : public finalcut::FDialog // Data members bool initialized{false}; - finalcut::FListView listView{this}; - finalcut::FButton Quit{this}; + finalcut::FListView listview{this}; + finalcut::FButton quit{this}; static TreeItem africa[]; static TreeItem asia[]; static TreeItem europe[]; @@ -329,26 +329,26 @@ Treeview::Treeview (finalcut::FWidget* parent) : finalcut::FDialog{parent} { // Set FListView geometry - listView.setGeometry(FPoint{2, 1}, FSize{53, 14}); + listview.setGeometry(FPoint{2, 1}, FSize{53, 14}); // Add columns to the view - listView.addColumn ("Name", 23); - listView.addColumn ("Population"); - listView.addColumn ("Density/km²"); + listview.addColumn ("Name", 23); + listview.addColumn ("Population"); + listview.addColumn ("Density/km²"); // Set right alignment for the second and third column - listView.setColumnAlignment (2, fc::alignRight); - listView.setColumnAlignment (3, fc::alignRight); + listview.setColumnAlignment (2, fc::alignRight); + listview.setColumnAlignment (3, fc::alignRight); // Set the type of sorting - listView.setColumnSortType (1, fc::by_name); - listView.setColumnSortType (2, fc::user_defined); - listView.setColumnSortType (3, fc::user_defined); - listView.setUserAscendingCompare(sortAscending); - listView.setUserDescendingCompare(sortDescending); + listview.setColumnSortType (1, fc::by_name); + listview.setColumnSortType (2, fc::user_defined); + listview.setColumnSortType (3, fc::user_defined); + listview.setUserAscendingCompare(sortAscending); + listview.setUserDescendingCompare(sortDescending); // Activate tree view - listView.setTreeView(); + listview.setTreeView(); // Populate FListView with a list of items static TreeItem continent_list[] = @@ -367,23 +367,23 @@ Treeview::Treeview (finalcut::FWidget* parent) const TreeItem* country_list = continent.child_element; finalcut::FStringList continent_line ( continent.begin() , continent.end() ); - auto iter = listView.insert (continent_line); + auto iter = listview.insert (continent_line); while ( country_list && country_list->name ) { finalcut::FStringList country_line ( country_list->begin() , country_list->end() ); - listView.insert (country_line, iter); + listview.insert (country_line, iter); country_list++; } } - // Quit button - Quit.setGeometry(FPoint{24, 16}, FSize{10, 1}); - Quit.setText (L"&Quit"); + // quit button + quit.setGeometry(FPoint{24, 16}, FSize{10, 1}); + quit.setText (L"&Quit"); // Callback function - Quit.addCallback + quit.addCallback ( "clicked", finalcut::getFApplication(), @@ -401,22 +401,22 @@ Treeview::~Treeview() // destructor //---------------------------------------------------------------------- void Treeview::adjustSize() { + finalcut::FDialog::adjustSize(); + std::size_t h = getDesktopHeight() - 4; setHeight (h, false); - int X = int((getDesktopWidth() - getWidth()) / 2); + auto x = int((getDesktopWidth() - getWidth()) / 2); - if ( X < 1 ) - X = 1; + if ( x < 1 ) + x = 1; - setX (X, false); + setPos (FPoint{x, 3}, false); if ( initialized ) { - listView.setHeight (getHeight() - 6, false); - Quit.setY(int(getHeight()) - 4); + listview.setHeight (getHeight() - 6, true); + quit.setY(int(getHeight()) - 4); } - - finalcut::FDialog::adjustSize(); } //---------------------------------------------------------------------- @@ -438,8 +438,7 @@ int main (int argc, char* argv[]) // Create main dialog object Treeview d{&app}; d.setText (L"Continents"); - d.setGeometry ( FPoint{int(1 + (app.getWidth() - 57) / 2), 3} - , FSize{57, 20} ); + d.setSize (FSize{57, 20}); d.setShadow(); // Set dialog d as main widget diff --git a/examples/ui.cpp b/examples/ui.cpp index a6638197..6e429bac 100644 --- a/examples/ui.cpp +++ b/examples/ui.cpp @@ -68,7 +68,7 @@ class ProgressDialog final : public finalcut::FDialog void cb_exit_bar(); // Data members - finalcut::FProgressbar progressBar{this}; + finalcut::FProgressbar progressbar{this}; finalcut::FButton reset{this}; finalcut::FButton more{this}; finalcut::FButton quit{this}; @@ -100,8 +100,8 @@ ProgressDialog::ProgressDialog (finalcut::FWidget* parent) quit.setGeometry(FPoint{28, 6}, FSize{8, 1}, false); quit.setDisable(); - progressBar.setGeometry(FPoint{2, 3}, FSize{34, 1}, false); - //progressBar.setPercentage(78); + progressbar.setGeometry(FPoint{2, 3}, FSize{34, 1}, false); + //progressbar.setPercentage(78); reset.addCallback ( @@ -140,9 +140,9 @@ void ProgressDialog::onShow (finalcut::FShowEvent*) //---------------------------------------------------------------------- void ProgressDialog::onTimer (finalcut::FTimerEvent*) { - auto p = progressBar.getPercentage(); + auto p = progressbar.getPercentage(); p++; - progressBar.setPercentage(p); + progressbar.setPercentage(p); flush(); if ( p != 100 ) @@ -167,15 +167,15 @@ void ProgressDialog::onTimer (finalcut::FTimerEvent*) //---------------------------------------------------------------------- void ProgressDialog::cb_reset_bar() { - progressBar.reset(); + progressbar.reset(); } //---------------------------------------------------------------------- void ProgressDialog::cb_more_bar() { - auto p = progressBar.getPercentage(); + auto p = progressbar.getPercentage(); p++; - progressBar.setPercentage(p); + progressbar.setPercentage(p); } //---------------------------------------------------------------------- @@ -212,25 +212,25 @@ class TextWindow final : public finalcut::FDialog void adjustSize() override; // Data members - finalcut::FTextView scrollText{this}; + finalcut::FTextView scrolltext{this}; }; //---------------------------------------------------------------------- TextWindow::TextWindow (finalcut::FWidget* parent) : finalcut::FDialog{parent} { - scrollText.ignorePadding(); - scrollText.setGeometry (FPoint{1, 2}, FSize{getWidth(), getHeight() - 1}); + scrolltext.ignorePadding(); + scrolltext.setGeometry (FPoint{1, 2}, FSize{getWidth(), getHeight() - 1}); setMinimumSize (FSize{51, 6}); - scrollText.setFocus(); - scrollText.insert(" -----------------------------------------------\n" + scrolltext.setFocus(); + scrolltext.insert(" -----------------------------------------------\n" " line 1\n" " -----------------------------------------------\n" " line 3\n" " line 4" , -1); - scrollText.replaceRange(" File viewer", 1, 1); - scrollText.deleteRange(3, 4); + scrolltext.replaceRange(" File viewer", 1, 1); + scrolltext.deleteRange(3, 4); } //---------------------------------------------------------------------- @@ -240,14 +240,14 @@ TextWindow::~TextWindow() // destructor //---------------------------------------------------------------------- void TextWindow::append (const finalcut::FString& str) { - scrollText.append(str); + scrolltext.append(str); } //---------------------------------------------------------------------- void TextWindow::adjustSize() { finalcut::FDialog::adjustSize(); - scrollText.setGeometry (FPoint{1, 2}, FSize(getWidth(), getHeight() - 1)); + scrolltext.setGeometry (FPoint{1, 2}, FSize(getWidth(), getHeight() - 1)); } @@ -305,8 +305,7 @@ class MyDialog final : public finalcut::FDialog , const finalcut::FLineEdit& ) const; void cb_setTitlebar (const finalcut::FLineEdit&); void cb_showProgressBar(); - void cb_updateNumber ( const finalcut::FListBox& - , finalcut::FLabel& ) const; + void cb_updateNumber(); void cb_activateButton ( const finalcut::FRadioButton& , finalcut::FButton& ) const; void cb_view (const finalcut::FMenuItem*); @@ -774,27 +773,25 @@ void MyDialog::initWidgetsCallbacks() myList.addCallback ( "row-selected", - this, &MyDialog::cb_updateNumber, - std::ref(myList), std::ref(tagged_count) + this, &MyDialog::cb_updateNumber ); } //---------------------------------------------------------------------- void MyDialog::adjustSize() { - const auto h = getParentWidget()->getHeight() - 4; + const auto h = getDesktopHeight() - 4; setHeight (h, false); - int X = int((getDesktopWidth() - getWidth()) / 2); + finalcut::FDialog::adjustSize(); // with new client area size + auto x = int((getDesktopWidth() - getWidth()) / 2); - if ( X < 1 ) - X = 1; + if ( x < 1 ) + x = 1; - setX (X, false); + setPos (FPoint{x, 2}, false); if ( initialized ) - myList.setHeight (getHeight() - 3, false); - - finalcut::FDialog::adjustSize(); + myList.setHeight (h - 3, true); } //---------------------------------------------------------------------- @@ -823,7 +820,10 @@ void MyDialog::cb_about() , line + L" FINAL CUT " + line + L"\n\n" L"Version " + libver + L"\n\n" L"(c) 2020 by Markus Gans" - , finalcut::FMessageBox::Ok, 0, 0, this ); + , finalcut::FMessageBox::Ok + , finalcut::FMessageBox::Reject + , finalcut::FMessageBox::Reject + , this ); info.setCenterText(); info.show(); } @@ -843,7 +843,10 @@ void MyDialog::cb_terminfo() << " Size: " << x << fc::Times << y << "\n" << "Colors: " << finalcut::FTerm::getMaxColor() - , finalcut::FMessageBox::Ok, 0, 0, this + , finalcut::FMessageBox::Ok + , finalcut::FMessageBox::Reject + , finalcut::FMessageBox::Reject + , this ); info1.setHeadline("Terminal:"); info1.exec(); @@ -858,7 +861,10 @@ void MyDialog::cb_drives() , "Generic: \n\n" "Network: \n\n" " CD:" - , finalcut::FMessageBox::Ok, 0, 0, this + , finalcut::FMessageBox::Ok + , finalcut::FMessageBox::Reject + , finalcut::FMessageBox::Reject + , this ); if ( finalcut::FTerm::isNewFont() ) @@ -968,19 +974,17 @@ void MyDialog::cb_showProgressBar() } //---------------------------------------------------------------------- -void MyDialog::cb_updateNumber ( const finalcut::FListBox& list - , finalcut::FLabel& num) const +void MyDialog::cb_updateNumber() { - const auto count = list.getCount(); int select_num = 0; - for (std::size_t n{1}; n <= count; n++) - if ( list.isSelected(n) ) + for (auto&& item : myList.getData() ) + if ( item.isSelected() ) select_num++; - num.clear(); - num << select_num; - num.redraw(); + tagged_count.clear(); + tagged_count << select_num; + tagged_count.redraw(); } //---------------------------------------------------------------------- @@ -1057,9 +1061,8 @@ int main (int argc, char* argv[]) // Create main dialog object d MyDialog d{&app}; d.setText (title); - d.setGeometry ( FPoint{int((app.getWidth() - 56) / 2), 2} - , FSize{56, app.getHeight() - 4} ); - d.setShadow(); + d.setSize (FSize{56, app.getHeight() - 4}); + d.setShadow(); // Instead of the transparent window shadow // Set the dialog object d as the main widget of the application. // When you close the main widget, the application will be closed. diff --git a/examples/watch.cpp b/examples/watch.cpp index 92359dc6..89adc220 100644 --- a/examples/watch.cpp +++ b/examples/watch.cpp @@ -79,8 +79,7 @@ Watch::Watch (FWidget* parent) // Avoids calling a virtual function from the constructor // (CERT, OOP50-CPP) FDialog::setText ("Watch"); - const int pw = int(getParentWidget()->getWidth()); - FDialog::setGeometry (FPoint{1 + (pw - 22) / 2, 3}, FSize{22, 13}); + FDialog::setSize ({22, 13}); // Labels time_label.setGeometry(FPoint{5, 2}, FSize{5, 1}); @@ -193,8 +192,9 @@ void Watch::cb_seconds() //---------------------------------------------------------------------- void Watch::adjustSize() { - const int pw = int(getParentWidget()->getWidth()); + const auto pw = int(getDesktopWidth()); setX (1 + (pw - 22) / 2, false); + setY (3, false); finalcut::FDialog::adjustSize(); } diff --git a/examples/windows.cpp b/examples/windows.cpp index e7785f23..b3ee3827 100644 --- a/examples/windows.cpp +++ b/examples/windows.cpp @@ -122,7 +122,7 @@ void SmallWindow::adjustSize() else { top_right_label = "zoom"; - bottom_label.setVisible(); + bottom_label.show(); } finalcut::FDialog::adjustSize(); @@ -199,7 +199,9 @@ class Window final : public finalcut::FDialog void configureDialogButtons(); void activateWindow (finalcut::FDialog*) const; void adjustSize() override; - template + template void addClickedCallback ( finalcut::FWidget* , InstanceT&&, CallbackT&&, Args&&... ); template @@ -241,6 +243,8 @@ class Window final : public finalcut::FDialog Window::Window (finalcut::FWidget* parent) : finalcut::FDialog{parent} { + FDialog::setSize ({40, 6}); + // Menu bar item File.setStatusbarMessage ("File management commands"); @@ -257,10 +261,10 @@ Window::Window (finalcut::FWidget* parent) Statusbar.setMessage("Status bar message"); // Generate data vector for the windows - for (int n{1}; n <= 6; n++) + for (uInt n{1}; n < 7; n++) { auto win_dat = new win_data; - win_dat->title.sprintf("Window %1d", n); + win_dat->title.sprintf("Window %1u", n); windows.push_back(win_dat); } } @@ -347,10 +351,12 @@ void Window::activateWindow (finalcut::FDialog* win) const //---------------------------------------------------------------------- void Window::adjustSize() { + finalcut::FDialog::adjustSize(); + const std::size_t w = getDesktopWidth(); const std::size_t h = getDesktopHeight(); - const int X = int(1 + (w - 40) / 2); - int Y = int(1 + (h - 22) / 2); + const auto X = int(1 + (w - 40) / 2); + auto Y = int(1 + (h - 22) / 2); const int dx = ( w > 80 ) ? int(w - 80) / 2 : 0; const int dy = ( h > 24 ) ? int(h - 24) / 2 : 0; @@ -365,7 +371,7 @@ void Window::adjustSize() { if ( (*iter)->is_open ) { - const int n = int(std::distance(first, iter)); + const auto n = int(std::distance(first, iter)); const int x = dx + 5 + (n % 3) * 25 + int(n / 3) * 3; const int y = dy + 11 + int(n / 3) * 3; (*iter)->dgl->setPos (FPoint{x, y}); @@ -373,12 +379,12 @@ void Window::adjustSize() ++iter; } - - finalcut::FDialog::adjustSize(); } //---------------------------------------------------------------------- -template +template void Window::addClickedCallback ( finalcut::FWidget* widget , InstanceT&& instance , CallbackT&& callback @@ -463,7 +469,7 @@ void Window::cb_createWindows() win_dat->dgl = win; win_dat->is_open = true; win->setText(win_dat->title); - const int n = int(std::distance(first, iter)); + const auto n = int(std::distance(first, iter)); const int x = dx + 5 + (n % 3) * 25 + int(n / 3) * 3; const int y = dy + 11 + int(n / 3) * 3; win->setGeometry (FPoint{x, y}, FSize{20, 8}); @@ -570,8 +576,6 @@ int main (int argc, char* argv[]) // Create main dialog object Window main_dlg {&app}; main_dlg.setText ("Main window"); - main_dlg.setGeometry ( FPoint{int(1 + (app.getWidth() - 40) / 2), 2} - , FSize{40, 6} ); // Set dialog main_dlg as main widget finalcut::FWidget::setMainWidget (&main_dlg); diff --git a/fonts/bdf2code.sh b/fonts/bdf2code.sh index 9c842194..1a2922f3 100755 --- a/fonts/bdf2code.sh +++ b/fonts/bdf2code.sh @@ -10,7 +10,7 @@ function create_code_file () echo -e "#define ${INCLUDE_GUARD}\\n" echo -e "namespace finalcut\\n{\\n" echo -e "namespace fc\\n{\\n" - echo -e "static unsigned char ${NAME}[] =\\n{" + echo -e "constexpr unsigned char ${NAME}[] =\\n{" grep -A"${HEIGHT}" "^BITMAP" "$NEWFONTFILE" \ | tr '\n' ',' \ diff --git a/fonts/newfont_8x16.h b/fonts/newfont_8x16.h index bc24802b..e9f377bc 100644 --- a/fonts/newfont_8x16.h +++ b/fonts/newfont_8x16.h @@ -9,7 +9,7 @@ namespace finalcut namespace fc { -static unsigned char __8x16graph[] = +constexpr unsigned char __8x16graph[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0 */ 0x00, 0x00, 0x7e, 0x81, 0xa5, 0x81, 0x81, 0xbd, 0x99, 0x81, 0x81, 0x7e, 0x00, 0x00, 0x00, 0x00, /* 1 */ diff --git a/fonts/newfont_9x16.h b/fonts/newfont_9x16.h index cfec8120..78f6a8aa 100644 --- a/fonts/newfont_9x16.h +++ b/fonts/newfont_9x16.h @@ -9,7 +9,7 @@ namespace finalcut namespace fc { -static unsigned char __9x16graph[] = +constexpr unsigned char __9x16graph[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0 */ 0x00, 0x00, 0x7e, 0x81, 0xa5, 0x81, 0x81, 0xbd, 0x99, 0x81, 0x81, 0x7e, 0x00, 0x00, 0x00, 0x00, /* 1 */ diff --git a/fonts/unicodemap.h b/fonts/unicodemap.h index 8b01d63d..24d80d69 100644 --- a/fonts/unicodemap.h +++ b/fonts/unicodemap.h @@ -11,14 +11,16 @@ #include #endif +#include + namespace finalcut { namespace fc { -static struct unipair unicode_cp437_pairs[] = -{ +constexpr std::array unicode_cp437_pairs = +{{ // .----------- unicode // | .---- fontpos // | | @@ -304,10 +306,10 @@ static struct unipair unicode_cp437_pairs[] = {0x266a, 0x0d}, {0x266b, 0x0e}, {0x266c, 0x0e} -}; +}}; -static struct unipair unicode_newfont_pairs[] = -{ +constexpr std::array unicode_newfont_pairs = +{{ // .----------- unicode // | .---- fontpos // | | @@ -610,7 +612,7 @@ static struct unipair unicode_newfont_pairs[] = {0xe1f9, 0xf9}, {0xe1fb, 0xfb}, {0xe1fc, 0xfc} -}; +}}; } // namespace fc diff --git a/fonts/vgafont.h b/fonts/vgafont.h index bd0852ec..c4532aad 100644 --- a/fonts/vgafont.h +++ b/fonts/vgafont.h @@ -9,7 +9,7 @@ namespace finalcut namespace fc { -static unsigned char __8x16std[] = +constexpr unsigned char __8x16std[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0 */ 0x00, 0x00, 0x7e, 0x81, 0xa5, 0x81, 0x81, 0xbd, 0x99, 0x81, 0x81, 0x7e, 0x00, 0x00, 0x00, 0x00, /* 1 */ diff --git a/src/Makefile.am b/src/Makefile.am index 6eb26cfc..b85607e3 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -20,6 +20,7 @@ libfinal_la_SOURCES = \ fbutton.cpp \ fbuttongroup.cpp \ fcallback.cpp \ + fdata.cpp \ ftogglebutton.cpp \ fradiobutton.cpp \ fcheckbox.cpp \ diff --git a/src/Makefile.clang b/src/Makefile.clang index 00547773..b81d7c26 100644 --- a/src/Makefile.clang +++ b/src/Makefile.clang @@ -13,6 +13,7 @@ INCLUDE_HEADERS = \ fbuttongroup.h \ fbutton.h \ fcallback.h \ + fdata.h \ fcolorpair.h \ fstyle.h \ ftogglebutton.h \ @@ -93,6 +94,7 @@ OBJS = \ fsize.o \ frect.o \ fcallback.o \ + fdata.o \ fscrollbar.o \ fprogressbar.o \ flineedit.o \ @@ -172,7 +174,7 @@ endif $(CXX) -c $(CCXFLAGS) $(INCLUDES) -fpic -o $@ $< all: dep $(OBJS) - $(CXX) $(CCXFLAGS) $(INCLUDES) $(LDFLAGS) -shared -Wl,-soname,$(LIB).$(MAJOR) -o $(LIB).$(VERSION) $(OBJS) + $(CXX) $(OBJS) -o $(LIB).$(VERSION) $(CCXFLAGS) $(INCLUDES) $(LDFLAGS) -shared -Wl,-soname,$(LIB).$(MAJOR) ln -s -f $(LIB).$(VERSION) libfinal.so.$(MAJOR) ln -s -f $(LIB).$(MAJOR) libfinal.so diff --git a/src/Makefile.gcc b/src/Makefile.gcc index 6ab87c5b..ebe8df58 100644 --- a/src/Makefile.gcc +++ b/src/Makefile.gcc @@ -13,6 +13,7 @@ INCLUDE_HEADERS = \ fbuttongroup.h \ fbutton.h \ fcallback.h \ + fdata.h \ fcolorpair.h \ fstyle.h \ ftogglebutton.h \ @@ -93,6 +94,7 @@ OBJS = \ fsize.o \ frect.o \ fcallback.o \ + fdata.o \ fscrollbar.o \ fprogressbar.o \ flineedit.o \ @@ -172,7 +174,7 @@ endif $(CXX) -c $(CCXFLAGS) $(INCLUDES) -fpic -o $@ $< all: dep $(OBJS) - $(CXX) $(CCXFLAGS) $(INCLUDES) $(LDFLAGS) -shared -Wl,-soname,$(LIB).$(MAJOR) -o $(LIB).$(VERSION) $(OBJS) + $(CXX) $(OBJS) -o $(LIB).$(VERSION) $(CCXFLAGS) $(INCLUDES) $(LDFLAGS) -shared -Wl,-soname,$(LIB).$(MAJOR) ln -s -f $(LIB).$(VERSION) libfinal.so.$(MAJOR) ln -s -f $(LIB).$(MAJOR) libfinal.so diff --git a/src/fapplication.cpp b/src/fapplication.cpp index ec2b6680..e2c80028 100644 --- a/src/fapplication.cpp +++ b/src/fapplication.cpp @@ -22,7 +22,9 @@ #include #include +#include #include +#include #include #include @@ -63,9 +65,35 @@ FMouseControl* FApplication::mouse {nullptr}; // mouse control int FApplication::loop_level {0}; // event loop level int FApplication::quit_code {EXIT_SUCCESS}; bool FApplication::quit_now {false}; -uInt64 FApplication::next_event_wait {5000}; // preset to 5 ms /200 Hz +uInt64 FApplication::next_event_wait {5000}; // preset to 5 ms (200 Hz) struct timeval FApplication::time_last_event{}; + +const std::vector FApplication::long_options = +{ + {"encoding", required_argument, nullptr, 'e' }, + {"log-file", required_argument, nullptr, 'l' }, + {"no-mouse", no_argument, nullptr, 'm' }, + {"no-optimized-cursor", no_argument, nullptr, 'o' }, + {"no-terminal-detection", no_argument, nullptr, 'd' }, + {"no-terminal-data-request", no_argument, nullptr, 'r' }, + {"no-color-change", no_argument, nullptr, 'c' }, + {"no-sgr-optimizer", no_argument, nullptr, 's' }, + {"vgafont", no_argument, nullptr, 'v' }, + {"newfont", no_argument, nullptr, 'n' }, + {"dark-theme", no_argument, nullptr, 't' }, + +#if defined(__FreeBSD__) || defined(__DragonFly__) + {"no-esc-for-alt-meta", no_argument, nullptr, 'E' }, + {"no-cursorstyle-change", no_argument, nullptr, 'C' }, +#elif defined(__NetBSD__) || defined(__OpenBSD__) + {"no-esc-for-alt-meta", no_argument, nullptr, 'E' }, +#endif + + {nullptr, 0, nullptr, 0 } +}; + + //---------------------------------------------------------------------- // class FApplication //---------------------------------------------------------------------- @@ -94,9 +122,10 @@ FApplication::FApplication (const int& _argc, char* _argv[]) if ( ! (_argc && _argv) ) { - static char empty_str[1] = ""; + typedef char* CString; + static std::array empty{{CString("")}}; app_argc = 0; - app_argv = reinterpret_cast(&empty_str); + app_argv = empty.data(); } init(); @@ -122,21 +151,37 @@ FApplication* FApplication::getApplicationObject() } //---------------------------------------------------------------------- -FApplication::FLogPtr& FApplication::getLog() +FWidget* FApplication::getKeyboardWidget() { - // Global logger object - static FLogPtr* logger = new FLogPtr(); - - if ( logger && logger->get() == nullptr ) - *logger = std::make_shared(); - - return *logger; + return keyboard_widget; } //---------------------------------------------------------------------- -void FApplication::setLog (const FLogPtr& logger) +FApplication::FLogPtr& FApplication::getLog() { - getLog() = logger; + // Global logger object + static auto logger_ptr = new FLogPtr(); + + if ( logger_ptr && logger_ptr->get() == nullptr ) + { + *logger_ptr = std::make_shared(); + + // Set the logger as rdbuf of clog + std::clog.rdbuf(logger_ptr->get()); + } + + return *logger_ptr; +} + +//---------------------------------------------------------------------- +void FApplication::setLog (const FLogPtr& log) +{ + FLogPtr& logger = getLog(); + logger.reset(); + logger = log; + + // Set the logger as rdbuf of clog + std::clog.rdbuf(logger.get()); } //---------------------------------------------------------------------- @@ -306,6 +351,35 @@ void FApplication::setDarkTheme() setColorTheme(); } +//---------------------------------------------------------------------- +void FApplication::setLogFile (const FString& filename) +{ + auto& log_stream = getStartOptions().logfile_stream; + log_stream.open(filename, std::ofstream::out); + + if ( log_stream.is_open() ) + { + // Get the global logger object + FLog& log = *FApplication::getLog(); + log.setOutputStream(log_stream); + log.enableTimestamp(); + log.setLineEnding (finalcut::FLog::LF); + } + else + { + auto ftermdata = FTerm::getFTermData(); + ftermdata->setExitMessage ( "Could not open log file \"" + + filename + "\"" ); + exit(EXIT_FAILURE); + } +} + +//---------------------------------------------------------------------- +void FApplication::setKeyboardWidget (FWidget* widget) +{ + keyboard_widget = widget; +} + //---------------------------------------------------------------------- void FApplication::closeConfirmationDialog (FWidget* w, FCloseEvent* ev) { @@ -333,7 +407,9 @@ void FApplication::closeConfirmationDialog (FWidget* w, FCloseEvent* ev) void FApplication::processExternalUserEvent() { // This method can be overloaded and replaced by own code - std::this_thread::sleep_for(std::chrono::milliseconds(5)); + + if ( FKeyboard::getReadBlockingTime() < 10000 ) + std::this_thread::sleep_for(std::chrono::milliseconds(5)); } @@ -341,6 +417,9 @@ void FApplication::processExternalUserEvent() //---------------------------------------------------------------------- void FApplication::init() { + // FApplication cannot have a second child widget + setMaxChildren(1); + // Initialize the last event time time_last_event.tv_sec = 0; time_last_event.tv_usec = 0; @@ -405,113 +484,70 @@ void FApplication::setTerminalEncoding (const FString& enc_str) } //---------------------------------------------------------------------- -void FApplication::setLogFile (const FString& filename) +inline FApplication::CmdMap& FApplication::mapCmdOptions() { - auto& log_stream = getStartOptions().logfile_stream; - log_stream.open(filename, std::ofstream::out); + using std::placeholders::_1; + auto enc = std::bind(&FApplication::setTerminalEncoding, _1); + auto log = std::bind(&FApplication::setLogFile, _1); + auto opt = &FApplication::getStartOptions; + static CmdMap cmd_map{}; - if ( log_stream.is_open() ) - { - // Get the global logger object - FLog& log = *FApplication::getLog(); - log.setOutputStream(log_stream); - log.enableTimestamp(); - log.setLineEnding (finalcut::FLog::LF); - } - else - { - auto ftermdata = FTerm::getFTermData(); - ftermdata->setExitMessage ( "Could not open log file \"" - + filename + "\"" ); - exit(EXIT_FAILURE); - } + // --encoding + cmd_map['e'] = [enc] (const char* arg) { enc(FString(arg)); }; + // --log-file + cmd_map['l'] = [log] (const char* arg) { log(FString(arg)); }; + // --no-mouse + cmd_map['m'] = [opt] (const char*) { opt().mouse_support = false; }; + // --no-optimized-cursor + cmd_map['o'] = [opt] (const char*) { opt().cursor_optimisation = false; }; + // --no-terminal-detection + cmd_map['d'] = [opt] (const char*) { opt().terminal_detection = false; }; + // --no-terminal-data-request + cmd_map['r'] = [opt] (const char*) { opt().terminal_data_request = false; }; + // --no-color-change + cmd_map['c'] = [opt] (const char*) { opt().color_change = false; }; + // --no-sgr-optimizer + cmd_map['s'] = [opt] (const char*) { opt().sgr_optimizer = false; }; + // --vgafont + cmd_map['v'] = [opt] (const char*) { opt().vgafont = true; }; + // --newfont + cmd_map['n'] = [opt] (const char*) { opt().newfont = true; }; + // --dark-theme + cmd_map['t'] = [opt] (const char*) { opt().dark_theme = true; }; +#if defined(__FreeBSD__) || defined(__DragonFly__) + // --no-esc-for-alt-meta + cmd_map['E'] = [opt] (const char*) { opt().meta_sends_escape = false; }; + // --no-cursorstyle-change + cmd_map['C'] = [opt] (const char*) { opt().change_cursorstyle = false; }; +#elif defined(__NetBSD__) || defined(__OpenBSD__) + // --no-esc-for-alt-meta + cmd_map['E'] = [opt] (const char*) { opt().meta_sends_escape = false; }; +#endif + return cmd_map; } //---------------------------------------------------------------------- -void FApplication::cmd_options (const int& argc, char* argv[]) +void FApplication::cmdOptions (const int& argc, char* argv[]) { // Interpret the command line options + auto& cmd_map = mapCmdOptions(); + while ( true ) { - static struct option long_options[] = - { - {"encoding", required_argument, nullptr, 0 }, - {"log-file", required_argument, nullptr, 0 }, - {"no-mouse", no_argument, nullptr, 0 }, - {"no-optimized-cursor", no_argument, nullptr, 0 }, - {"no-terminal-detection", no_argument, nullptr, 0 }, - {"no-terminal-data-request", no_argument, nullptr, 0 }, - {"no-color-change", no_argument, nullptr, 0 }, - {"no-sgr-optimizer", no_argument, nullptr, 0 }, - {"vgafont", no_argument, nullptr, 0 }, - {"newfont", no_argument, nullptr, 0 }, - {"dark-theme", no_argument, nullptr, 0 }, - - #if defined(__FreeBSD__) || defined(__DragonFly__) - {"no-esc-for-alt-meta", no_argument, nullptr, 0 }, - {"no-cursorstyle-change", no_argument, nullptr, 0 }, - #elif defined(__NetBSD__) || defined(__OpenBSD__) - {"no-esc-for-alt-meta", no_argument, nullptr, 0 }, - #endif - - {nullptr, 0, nullptr, 0 } - }; - opterr = 0; int idx{0}; - const int c = getopt_long (argc, argv, "", long_options, &idx); + auto p = reinterpret_cast(long_options.data()); + const int opt = getopt_long (argc, argv, "", p, &idx); - if ( c == -1 ) + if ( opt == -1 ) break; - if ( c == 0 ) - { - if ( std::strcmp(long_options[idx].name, "encoding") == 0 ) - setTerminalEncoding(FString(optarg)); - - if ( std::strcmp(long_options[idx].name, "log-file") == 0 ) - setLogFile(FString(optarg)); - - if ( std::strcmp(long_options[idx].name, "no-mouse") == 0 ) - getStartOptions().mouse_support = false; - - if ( std::strcmp(long_options[idx].name, "no-optimized-cursor") == 0 ) - getStartOptions().cursor_optimisation = false; - - if ( std::strcmp(long_options[idx].name, "no-terminal-detection") == 0 ) - getStartOptions().terminal_detection = false; - - if ( std::strcmp(long_options[idx].name, "no-terminal-data-request") == 0 ) - getStartOptions().terminal_data_request = false; - - if ( std::strcmp(long_options[idx].name, "no-color-change") == 0 ) - getStartOptions().color_change = false; - - if ( std::strcmp(long_options[idx].name, "no-sgr-optimizer") == 0 ) - getStartOptions().sgr_optimizer = false; - - if ( std::strcmp(long_options[idx].name, "vgafont") == 0 ) - getStartOptions().vgafont = true; - - if ( std::strcmp(long_options[idx].name, "newfont") == 0 ) - getStartOptions().newfont = true; - - if ( std::strcmp(long_options[idx].name, "dark-theme") == 0 ) - getStartOptions().dark_theme = true; - - #if defined(__FreeBSD__) || defined(__DragonFly__) - if ( std::strcmp(long_options[idx].name, "no-esc-for-alt-meta") == 0 ) - getStartOptions().meta_sends_escape = false; - - if ( std::strcmp(long_options[idx].name, "no-cursorstyle-change") == 0 ) - getStartOptions().change_cursorstyle = false; - #elif defined(__NetBSD__) || defined(__OpenBSD__) - if ( std::strcmp(long_options[idx].name, "no-esc-for-alt-meta") == 0 ) - getStartOptions().meta_sends_escape = false; - #endif - } + if ( cmd_map.find(opt) != cmd_map.end() ) + cmd_map[opt](optarg); } + + cmd_map.clear(); } //---------------------------------------------------------------------- @@ -574,6 +610,10 @@ void FApplication::showParameterUsage() //---------------------------------------------------------------------- inline void FApplication::destroyLog() { + // Reset the rdbuf of clog + std::clog.rdbuf(default_clog_rdbuf); + + // Delete the logger const FLogPtr* logger = &(getLog()); delete logger; } @@ -796,34 +836,30 @@ bool FApplication::processAccelerator (const FWidget* const& widget) const { bool accpt{false}; - if ( widget - && ! widget->getAcceleratorList().empty() ) + if ( ! widget || widget->getAcceleratorList().empty() ) + return accpt; + + for (auto&& item : widget->getAcceleratorList()) { - auto iter = widget->getAcceleratorList().begin(); - const auto& last = widget->getAcceleratorList().end(); - - while ( iter != last && ! quit_now && ! app_exit_loop ) + if ( item.key == keyboard->getKey() ) { - if ( iter->key == keyboard->getKey() ) + // unset the move/size mode + auto move_size = getMoveSizeWidget(); + + if ( move_size ) { - // unset the move/size mode - auto move_size = getMoveSizeWidget(); - - if ( move_size ) - { - auto w = move_size; - setMoveSizeWidget(nullptr); - w->redraw(); - } - - FAccelEvent a_ev (fc::Accelerator_Event, getFocusWidget()); - sendEvent (iter->object, &a_ev); - accpt = a_ev.isAccepted(); - break; + setMoveSizeWidget(nullptr); + move_size->redraw(); } - ++iter; + FAccelEvent a_ev (fc::Accelerator_Event, getFocusWidget()); + sendEvent (item.object, &a_ev); + accpt = a_ev.isAccepted(); + break; } + + if ( quit_now || app_exit_loop ) + break; } return accpt; @@ -1173,7 +1209,7 @@ FWidget* FApplication::processParameters (const int& argc, char* argv[]) FApplication::exit(EXIT_SUCCESS); } - cmd_options (argc, argv); + cmdOptions (argc, argv); return nullptr; } @@ -1342,4 +1378,13 @@ bool FApplication::isNextEventTimeout() return FObject::isTimeout (&time_last_event, next_event_wait); } + +// FLog non-member operators +//---------------------------------------------------------------------- +std::ostream& operator << (std::ostream& outstr, FLog::LogLevel l) +{ + *FApplication::getLog() << l; + return outstr; +} + } // namespace finalcut diff --git a/src/fbusyindicator.cpp b/src/fbusyindicator.cpp index 63f24e66..59bc3bdd 100644 --- a/src/fbusyindicator.cpp +++ b/src/fbusyindicator.cpp @@ -20,6 +20,7 @@ * . * ***********************************************************************/ +#include #include "final/fbusyindicator.h" namespace finalcut @@ -75,11 +76,11 @@ void FBusyIndicator::init() //---------------------------------------------------------------------- void FBusyIndicator::createIndicatorText() { - FString line[4]{}; + std::array line{}; if ( FTerm::getEncoding() == fc::UTF8 ) { - const wchar_t (&p)[8] = uni_pattern; + const auto& p = uni_pattern; line[0] << " " << p[7] << " " << p[0] << " \n"; line[1] << " " << p[6] << " " << p[1] << " \n"; line[2] << " " << p[5] << " " << p[2] << " \n"; @@ -87,7 +88,7 @@ void FBusyIndicator::createIndicatorText() } else { - const char (&p)[8] = pattern; + const auto& p = pattern; line[0] << " " << p[7] << " " << p[0] << " \n"; line[1] << " " << p[6] << " " << p[1] << " \n"; line[2] << " " << p[5] << " " << p[2] << " \n"; diff --git a/src/fbuttongroup.cpp b/src/fbuttongroup.cpp index 1ae70041..0d9c3362 100644 --- a/src/fbuttongroup.cpp +++ b/src/fbuttongroup.cpp @@ -309,40 +309,7 @@ void FButtonGroup::onAccel (FAccelEvent*) void FButtonGroup::onFocusIn (FFocusEvent* in_ev) { in_ev->ignore(); // Change default value to ignore - - if ( hasCheckedButton() && ! buttonlist.empty() ) - { - for (auto&& item : buttonlist) - { - auto toggle_button = static_cast(item); - - if ( toggle_button->isChecked() ) - { - if ( isRadioButton(toggle_button) ) - { - auto prev_element = getFocusWidget(); - - toggle_button->setFocus(); - - FFocusEvent cfi (fc::ChildFocusIn_Event); - FApplication::sendEvent(this, &cfi); - - FFocusEvent in (fc::FocusIn_Event); - FApplication::sendEvent(toggle_button, &in); - - if ( in.isAccepted() ) - in_ev->accept(); - - if ( prev_element ) - prev_element->redraw(); - - toggle_button->redraw(); - } - - break; - } - } // end of range-based for loop - } + focusInRadioButton (in_ev); if ( ! in_ev->isAccepted() ) { @@ -483,54 +450,63 @@ void FButtonGroup::drawText ( const FString& label_text setReverse(true); } +//---------------------------------------------------------------------- +bool FButtonGroup::directFocusCheckedRadioButton (FToggleButton* item) const +{ + if ( ! isRadioButton(item) ) + return false; + + auto focused_widget = getFocusWidget(); + item->setFocus(); + + if ( focused_widget ) + focused_widget->redraw(); + + focused_widget = getFocusWidget(); + + if ( focused_widget ) + focused_widget->redraw(); + + return true; +} + +//---------------------------------------------------------------------- +bool FButtonGroup::directFocusRadioButton() const +{ + if ( ! hasCheckedButton() || buttonlist.empty() ) + return false; + + bool found_checked{false}; + + for (auto&& item : buttonlist) + { + auto toggle_button = static_cast(item); + + if ( toggle_button->isChecked() ) + { + found_checked = directFocusCheckedRadioButton(toggle_button); + break; + } + } + + return found_checked; +} + //---------------------------------------------------------------------- void FButtonGroup::directFocus() { - if ( ! hasFocusedButton() ) + if ( ! hasFocusedButton() && ! directFocusRadioButton() ) { - bool found_checked{false}; + auto focused_widget = getFocusWidget(); + focusFirstChild(); - if ( hasCheckedButton() && ! buttonlist.empty() ) - { - for (auto&& item : buttonlist) - { - auto toggle_button = static_cast(item); + if ( focused_widget ) + focused_widget->redraw(); - if ( toggle_button->isChecked() ) - { - if ( isRadioButton(toggle_button) ) - { - found_checked = true; - auto focused_widget = getFocusWidget(); - toggle_button->setFocus(); + focused_widget = getFocusWidget(); - if ( focused_widget ) - focused_widget->redraw(); - - focused_widget = getFocusWidget(); - - if ( focused_widget ) - focused_widget->redraw(); - } - - break; - } - } // end of range-based for loop - } - - if ( ! found_checked ) - { - auto focused_widget = getFocusWidget(); - focusFirstChild(); - - if ( focused_widget ) - focused_widget->redraw(); - - focused_widget = getFocusWidget(); - - if ( focused_widget ) - focused_widget->redraw(); - } + if ( focused_widget ) + focused_widget->redraw(); } if ( getStatusBar() ) @@ -541,6 +517,49 @@ void FButtonGroup::directFocus() } } +//---------------------------------------------------------------------- +void FButtonGroup::focusCheckedRadioButton ( FToggleButton* toggle_button + , FFocusEvent* in_ev ) +{ + auto prev_element = getFocusWidget(); + + toggle_button->setFocus(); + + FFocusEvent cfi (fc::ChildFocusIn_Event); + FApplication::sendEvent(this, &cfi); + + FFocusEvent in (fc::FocusIn_Event); + FApplication::sendEvent(toggle_button, &in); + + if ( in.isAccepted() ) + in_ev->accept(); + + if ( prev_element ) + prev_element->redraw(); + + toggle_button->redraw(); +} + +//---------------------------------------------------------------------- +void FButtonGroup::focusInRadioButton (FFocusEvent* in_ev) +{ + if ( ! hasCheckedButton() || buttonlist.empty() ) + return; + + for (auto&& item : buttonlist) + { + auto toggle_button = static_cast(item); + + if ( toggle_button->isChecked() ) + { + if ( isRadioButton(toggle_button) ) + focusCheckedRadioButton (toggle_button, in_ev); + + break; + } + } +} + //---------------------------------------------------------------------- void FButtonGroup::cb_buttonToggled (const FToggleButton* button) const { diff --git a/src/fcharmap.cpp b/src/fcharmap.cpp index 23bb8753..7c6c2097 100644 --- a/src/fcharmap.cpp +++ b/src/fcharmap.cpp @@ -3,7 +3,7 @@ * * * This file is part of the FINAL CUT widget toolkit * * * -* Copyright 2015-2019 Markus Gans * +* Copyright 2015-2020 Markus Gans * * * * FINAL CUT is free software; you can redistribute it and/or modify * * it under the terms of the GNU Lesser General Public License as * @@ -20,6 +20,8 @@ * . * ***********************************************************************/ +#include + #include "final/fc.h" #include "final/ftypes.h" #include "final/fcharmap.h" @@ -30,690 +32,676 @@ namespace finalcut namespace fc { -uInt character[][fc::NUM_OF_ENCODINGS] = -{ +std::array, 115> character = +{{ // .--------------------- Unicode (UTF-8) // | .--------------- VT100 // | | .--------- PC (IBM-437) // | | | .---- ASCII (7-Bit) // | | | | - {0x20ac, 0, 0xee, 'E'}, // â‚Ŧ - Euro - {0x00a3, '}', 0x9c, 'P'}, // ÂŖ - Pound - {0x00a7, '$', 0x15, '$'}, // § - Section - {0x25d8, '*', 0x08, '*'}, // ◘ - InverseBullet - {0x25d9, '*', 0x0a, '*'}, // ◙ - InverseWhiteCircle - {0x203c, '!', 0x13, '!'}, // â€ŧ - DoubleExclamationMark - {0x2195, 'I', 0x12, 'I'}, // ↕ - UpDownArrow - {0x2194, '-', 0x1d, '-'}, // ↔ - LeftRightArrow - {0x25ac, '_', 0x16, '_'}, // â–Ŧ - BlackRectangle - {0x2191, '^', 0x18, '^'}, // ↑ - UpwardsArrow - {0x2193, 'v', 0x19, 'v'}, // ↓ - DownwardsArrow - {0x2192, '>', 0x1a, '>'}, // → - RightwardsArrow - {0x2190, '<', 0x1b, '<'}, // ← - LeftwardsArrow - {0x203a, '>', 0xaf, '>'}, // â€ē - SingleRightAngleQuotationMark - {0x2039, '<', 0xae, '<'}, // ‹ - SingleLeftAngleQuotationMark - {0x2026, '.', '.', '.'}, // â€Ļ - HorizontalEllipsis - {0x03c0, '{', 0xe3, 'n'}, // Ī€ - Pi - {0x207F, 'I', 0xfc, ' '}, // âŋ - SuperscriptLatinSmallLetterN - {0x2265, 'z', 0xf2, '>'}, // â‰Ĩ - GreaterThanOrEqualTo - {0x2264, 'y', 0xf3, '<'}, // ≤ - LessThanOrEqualTo - {0x2260, 0, 0xd8, '#'}, // ≠ - NotEqualTo - {0x00b1, 'g', 0xf1, '#'}, // Âą - PlusMinus - {0x00f7, '/', 0xf6, '/'}, // Ãˇ - Division sign - {0x00d7, 0, 'x', 'x'}, // × - Multiplication sign - {0x02e3, '~', 0xfc, '`'}, // ËŖ - Modifier letter small x - {0x00b0, 'f', 0xb0, 'o'}, // ° - Degree - {0x2022, '`', 0x04, '*'}, // â€ĸ - Bullet - {0x00b7, '`', 0xfa, '.'}, // ¡ - small Bullet - {0x25cf, '`', 0x04, '*'}, // ● - BlackCircle - {0x2666, '`', 0x04, '*'}, // ◆ - BlackDiamondSuit - {0x2424, 'h', ' ', ' '}, // ␤ - SymbolForNewline (1) - {0x240b, 'i', ' ', ' '}, // ␋ - SymbolForVerticalTab (1) - {0x2409, 'b', ' ', ' '}, // ␉ - SymbolForHorizontalTab (1) - {0x240c, 'c', ' ', ' '}, // ␌ - SymbolForFormFeed (1) - {0x240d, 'd', ' ', ' '}, // ␍ - SymbolForCarriageReturn (1) - {0x240a, 'e', ' ', ' '}, // ␊ - SymbolForLineFeed (1) - {0x2592, 'a', 0xb0, '#'}, // ▒ - MediumShade - {0x2588, '0', 0xdb, '#'}, // █ - FullBlock - {0x25ae, '_', 0xfe, '#'}, // ▮ - BlackVerticalRectangle (1) - {0x258c, 0, 0xdd, ' '}, // ▌ - LeftHalfBlock - {0x2590, 0, 0xde, ' '}, // ▐ - RightHalfBlock - {0x2584, 0, 0xdc, ' '}, // ▄ - LowerHalfBlock - {0x2580, 0, 0xdf, ' '}, // ▀ - UpperHalfBlock - {0x2500, 'q', 0xc4, '-'}, // ─ - BoxDrawingsHorizontal - {0x2502, 'x', 0xb3, '|'}, // │ - BoxDrawingsVertical - {0x250c, 'l', 0xda, '.'}, // ┌ - BoxDrawingsDownAndRight - {0x2510, 'k', 0xbf, '.'}, // ┐ - BoxDrawingsDownAndLeft - {0x2514, 'm', 0xc0, '`'}, // └ - BoxDrawingsUpAndRight - {0x2518, 'j', 0xd9, '\''}, // ┘ - BoxDrawingsUpAndLeft - {0x253c, 'n', 0xc5, '+'}, // â”ŧ - BoxDrawingsCross - {0x252c, 'w', 0xc2, '+'}, // â”Ŧ - BoxDrawingsDownAndHorizontal - {0x2524, 'u', 0xb4, '+'}, // ┤ - BoxDrawingsVerticalAndLeft - {0x251c, 't', 0xc3, '+'}, // ├ - BoxDrawingsVerticalAndRight - {0x2534, 'v', 0xc1, '+'}, // ┴ - BoxDrawingsUpAndHorizontal - {0x23ba, 'o', '~', '~'}, // âŽē - HorizontalScanLine1 (1) - {0x23bb, 'p', 0xc4, '-'}, // âŽģ - HorizontalScanLine3 (1) - {0x23bc, 'r', 0xc4, '-'}, // âŽŧ - HorizontalScanLine7 (1) - {0x23bd, 's', '_', '_'}, // âŽŊ - HorizontalScanLine9 (1) - {0x25b2, '-', 0x1e, '^'}, // ▲ - BlackUpPointingTriangle - {0x25bc, '.', 0x1f, 'v'}, // â–ŧ - BlackDownPointingTriangle - {0x25b6, '+', 0x10, '>'}, // â–ļ - BlackRightPointingTriangle - {0x25c0, ',', 0x11, '<'}, // ◀ - BlackLeftPointingTriangle (1) - {0x25ba, '+', 0x10, '>'}, // â–ē - BlackRightPointingPointer (1) - {0x25c4, ',', 0x11, '<'}, // ◄ - BlackLeftPointingPointer - {0xe1b3, 'x', 0xb3, '|'}, // │ - NF_border_line_vertical (2) - {0xe1b4, 0, 0xb4, 0}, // ⊐ - NF_rev_left_arrow2 (2) - {0xe1b5, 0, 0xb5, 0}, // â–ē - NF_rev_right_arrow2 (2) - {0xe1b6, 0, 0xb6, 0}, // â•ĩ - NF_border_line_left_up (2) - {0xe1b7, 0, 0xb7, 0}, // ) - NF_radio_button3 (2) - {0xe1b8, 0, 0xb8, 0}, // ⎤ - NF_rev_border_corner_upper_right (2) - {0xe1b9, 0, 0xb9, 0}, // ⎚ - NF_rev_border_line_right (2) - {0xe1ba, 0, 0xba, 0}, // ┤ - NF_rev_border_line_vertical_left (2) - {0xe1bb, 0, 0xbb, 0}, // âŽĻ - NF_rev_border_corner_lower_right (2) - {0xe1bc, 0, 0xbc, 0}, // ⎸ - NF_border_line_left (2) - {0xe1bd, 0, 0xbd, 0}, //⎚â—Ŗ - NF_rev_up_arrow2 (2) - {0xe1be, 0, 0xbe, 0}, //⎹◤ - NF_rev_down_arrow2 (2) - {0xe1bf, 0, 0xbf, 0}, // ╷ - NF_border_line_left_down (2) - {0xe1c0, 0, 0xc0, 0}, // └ - NF_border_corner_middle_lower_left (2) - {0xe1c1, 0, 0xc1, 0}, // â—ĸ⎸ - NF_rev_up_arrow1 (2) - {0xe1c2, 0, 0xc2, 0}, // â—Ĩ⎸ - NF_rev_down_arrow1 (2) - {0xe1c3, 0, 0xc3, 0}, // ├ - NF_border_line_vertical_right (2) - {0xe1c4, 'q', 0xc4, '-'}, // ─ - NF_border_line_horizontal (2) - {0xe1c5, 0, 0xc5, 0}, // = - NF_border_line_up_and_down (2) - {0xe1c6, 0, 0xc6, 0}, // = - NF_shadow_box_middle (2) - {0xe1c7, 0, 0xc7, 0}, // = - NF_shadow_box_hdd (2) - {0xe1c8, 0, 0xc8, 0}, // ◄ - NF_rev_left_arrow1 (2) - {0xe1c9, 0, 0xc9, 0}, // ⊏ - NF_rev_right_arrow1 (2) - {0xe1ca, 0, 0xca, 0}, // [ - NF_rev_menu_button1 (2) - {0xe1cb, 0, 0xcb, 0}, // - - NF_rev_menu_button2 (2) - {0xe1cc, 0, 0xcc, 0}, // ┌ - NF_border_corner_middle_upper_left (2) - {0xe1cd, 0, 0xcd, 0}, // = - NF_shadow_box_cd (2) - {0xe1ce, 0, 0xce, 0}, // [ - NF_shadow_box_left (2) - {0xe1cf, 0, 0xcf, 0}, // ┌ - NF_border_line_middle_left_down (2) - {0xe1d0, 0, 0xd0, 0}, // └ - NF_border_line_middle_right_up (2) - {0xe1d1, 0, 0xd1, 0}, // = - NF_shadow_box_net (2) - {0xe1d2, 0, 0xd2, 0}, // â—ĸ - NF_rev_up_pointing_triangle1 (2) - {0xe1d3, 0, 0xd3, 0}, // âŽŖ - NF_border_corner_lower_left (2) - {0xe1d4, 0, 0xd4, 0}, // _ - NF_border_line_bottom (2) - {0xe1d5, 0, 0xd5, 0}, // O - NF_radio_button2 (2) - {0xe1d6, 0, 0xd6, 0}, // ● - NF_radio_button2_checked (2) - {0xe1d7, 0, 0xd7, 0}, // â—Ĩ - NF_rev_down_pointing_triangle1 (2) - {0xe1d8, 0, 0xd8, 0}, // ¯ - NF_border_line_upper (2) - {0xe1d9, 0, 0xd9, 0}, // ( - NF_radio_button1 (2) - {0xe1da, 0, 0xda, 0}, // ⎡ - NF_border_corner_upper_left (2) - {0xe1dc, 0, 0xdc, 0}, // ✓ - NF_shadow_box_checked (2) - {0xe1e7, 0, 0xe7, 0}, // ║ - NF_rev_border_line_right_and_left (2) - {0xe1e8, 0, 0xe8, 0}, // â—Ŗ - NF_rev_up_pointing_triangle2 (2) - {0xe1e9, 0, 0xe9, 0}, // ◤ - NF_rev_down_pointing_triangle2 (2) - {0xe1ea, 0, 0xea, 0}, // ┘ - NF_border_corner_middle_lower_right (2) - {0xe1eb, 0, 0xeb, 0}, // ┐ - NF_border_corner_middle_upper_right (2) - {0xe1f4, 0, 0xf4, 0}, // ] - NF_rev_menu_button3 (2) - {0xe1f5, 0, 0xf5, 0}, // ] - NF_shadow_box_right (2) - {0xe1fb, 0, 0xfb, 0}, // ✓ - NF_check_mark (2) - {0xe1fc, '~', 0xfc, '`'}, // ËŖ - NF_xsuperior (2) - {0x221a, 0, 0xfb, 'x'} // √ - square root -}; + {{0x20ac, 0, 0xee, 'E'}}, // â‚Ŧ - Euro + {{0x00a3, '}', 0x9c, 'P'}}, // ÂŖ - Pound + {{0x00a7, '$', 0x15, '$'}}, // § - Section + {{0x25d8, '*', 0x08, '*'}}, // ◘ - InverseBullet + {{0x25d9, '*', 0x0a, '*'}}, // ◙ - InverseWhiteCircle + {{0x203c, '!', 0x13, '!'}}, // â€ŧ - DoubleExclamationMark + {{0x2195, 'I', 0x12, 'I'}}, // ↕ - UpDownArrow + {{0x2194, '-', 0x1d, '-'}}, // ↔ - LeftRightArrow + {{0x25ac, '_', 0x16, '_'}}, // â–Ŧ - BlackRectangle + {{0x2191, '^', 0x18, '^'}}, // ↑ - UpwardsArrow + {{0x2193, 'v', 0x19, 'v'}}, // ↓ - DownwardsArrow + {{0x2192, '>', 0x1a, '>'}}, // → - RightwardsArrow + {{0x2190, '<', 0x1b, '<'}}, // ← - LeftwardsArrow + {{0x203a, '>', 0xaf, '>'}}, // â€ē - SingleRightAngleQuotationMark + {{0x2039, '<', 0xae, '<'}}, // ‹ - SingleLeftAngleQuotationMark + {{0x2026, '.', '.', '.'}}, // â€Ļ - HorizontalEllipsis + {{0x03c0, '{', 0xe3, 'n'}}, // Ī€ - Pi + {{0x207F, 'I', 0xfc, ' '}}, // âŋ - SuperscriptLatinSmallLetterN + {{0x2265, 'z', 0xf2, '>'}}, // â‰Ĩ - GreaterThanOrEqualTo + {{0x2264, 'y', 0xf3, '<'}}, // ≤ - LessThanOrEqualTo + {{0x2260, 0, 0xd8, '#'}}, // ≠ - NotEqualTo + {{0x00b1, 'g', 0xf1, '#'}}, // Âą - PlusMinus + {{0x00f7, '/', 0xf6, '/'}}, // Ãˇ - Division sign + {{0x00d7, 0, 'x', 'x'}}, // × - Multiplication sign + {{0x02e3, '~', 0xfc, '`'}}, // ËŖ - Modifier letter small x + {{0x00b0, 'f', 0xb0, 'o'}}, // ° - Degree + {{0x2022, '`', 0x04, '*'}}, // â€ĸ - Bullet + {{0x00b7, '`', 0xfa, '.'}}, // ¡ - small Bullet + {{0x25cf, '`', 0x04, '*'}}, // ● - BlackCircle + {{0x2666, '`', 0x04, '*'}}, // ◆ - BlackDiamondSuit + {{0x2424, 'h', ' ', ' '}}, // ␤ - SymbolForNewline (1) + {{0x240b, 'i', ' ', ' '}}, // ␋ - SymbolForVerticalTab (1) + {{0x2409, 'b', ' ', ' '}}, // ␉ - SymbolForHorizontalTab (1) + {{0x240c, 'c', ' ', ' '}}, // ␌ - SymbolForFormFeed (1) + {{0x240d, 'd', ' ', ' '}}, // ␍ - SymbolForCarriageReturn (1) + {{0x240a, 'e', ' ', ' '}}, // ␊ - SymbolForLineFeed (1) + {{0x2592, 'a', 0xb0, '#'}}, // ▒ - MediumShade + {{0x2588, '0', 0xdb, '#'}}, // █ - FullBlock + {{0x25ae, '_', 0xfe, '#'}}, // ▮ - BlackVerticalRectangle (1) + {{0x258c, 0, 0xdd, ' '}}, // ▌ - LeftHalfBlock + {{0x2590, 0, 0xde, ' '}}, // ▐ - RightHalfBlock + {{0x2584, 0, 0xdc, ' '}}, // ▄ - LowerHalfBlock + {{0x2580, 0, 0xdf, ' '}}, // ▀ - UpperHalfBlock + {{0x2500, 'q', 0xc4, '-'}}, // ─ - BoxDrawingsHorizontal + {{0x2502, 'x', 0xb3, '|'}}, // │ - BoxDrawingsVertical + {{0x250c, 'l', 0xda, '.'}}, // ┌ - BoxDrawingsDownAndRight + {{0x2510, 'k', 0xbf, '.'}}, // ┐ - BoxDrawingsDownAndLeft + {{0x2514, 'm', 0xc0, '`'}}, // └ - BoxDrawingsUpAndRight + {{0x2518, 'j', 0xd9, '\''}}, // ┘ - BoxDrawingsUpAndLeft + {{0x253c, 'n', 0xc5, '+'}}, // â”ŧ - BoxDrawingsCross + {{0x252c, 'w', 0xc2, '+'}}, // â”Ŧ - BoxDrawingsDownAndHorizontal + {{0x2524, 'u', 0xb4, '+'}}, // ┤ - BoxDrawingsVerticalAndLeft + {{0x251c, 't', 0xc3, '+'}}, // ├ - BoxDrawingsVerticalAndRight + {{0x2534, 'v', 0xc1, '+'}}, // ┴ - BoxDrawingsUpAndHorizontal + {{0x23ba, 'o', '~', '~'}}, // âŽē - HorizontalScanLine1 (1) + {{0x23bb, 'p', 0xc4, '-'}}, // âŽģ - HorizontalScanLine3 (1) + {{0x23bc, 'r', 0xc4, '-'}}, // âŽŧ - HorizontalScanLine7 (1) + {{0x23bd, 's', '_', '_'}}, // âŽŊ - HorizontalScanLine9 (1) + {{0x25b2, '-', 0x1e, '^'}}, // ▲ - BlackUpPointingTriangle + {{0x25bc, '.', 0x1f, 'v'}}, // â–ŧ - BlackDownPointingTriangle + {{0x25b6, '+', 0x10, '>'}}, // â–ļ - BlackRightPointingTriangle + {{0x25c0, ',', 0x11, '<'}}, // ◀ - BlackLeftPointingTriangle (1) + {{0x25ba, '+', 0x10, '>'}}, // â–ē - BlackRightPointingPointer (1) + {{0x25c4, ',', 0x11, '<'}}, // ◄ - BlackLeftPointingPointer + {{0xe1b3, 'x', 0xb3, '|'}}, // │ - NF_border_line_vertical (2) + {{0xe1b4, 0, 0xb4, 0}}, // ⊐ - NF_rev_left_arrow2 (2) + {{0xe1b5, 0, 0xb5, 0}}, // â–ē - NF_rev_right_arrow2 (2) + {{0xe1b6, 0, 0xb6, 0}}, // â•ĩ - NF_border_line_left_up (2) + {{0xe1b7, 0, 0xb7, 0}}, // ) - NF_radio_button3 (2) + {{0xe1b8, 0, 0xb8, 0}}, // ⎤ - NF_rev_border_corner_upper_right (2) + {{0xe1b9, 0, 0xb9, 0}}, // ⎚ - NF_rev_border_line_right (2) + {{0xe1ba, 0, 0xba, 0}}, // ┤ - NF_rev_border_line_vertical_left (2) + {{0xe1bb, 0, 0xbb, 0}}, // âŽĻ - NF_rev_border_corner_lower_right (2) + {{0xe1bc, 0, 0xbc, 0}}, // ⎸ - NF_border_line_left (2) + {{0xe1bd, 0, 0xbd, 0}}, //⎚â—Ŗ - NF_rev_up_arrow2 (2) + {{0xe1be, 0, 0xbe, 0}}, //⎹◤ - NF_rev_down_arrow2 (2) + {{0xe1bf, 0, 0xbf, 0}}, // ╷ - NF_border_line_left_down (2) + {{0xe1c0, 0, 0xc0, 0}}, // └ - NF_border_corner_middle_lower_left (2) + {{0xe1c1, 0, 0xc1, 0}}, // â—ĸ⎸ - NF_rev_up_arrow1 (2) + {{0xe1c2, 0, 0xc2, 0}}, // â—Ĩ⎸ - NF_rev_down_arrow1 (2) + {{0xe1c3, 0, 0xc3, 0}}, // ├ - NF_border_line_vertical_right (2) + {{0xe1c4, 'q', 0xc4, '-'}}, // ─ - NF_border_line_horizontal (2) + {{0xe1c5, 0, 0xc5, 0}}, // = - NF_border_line_up_and_down (2) + {{0xe1c6, 0, 0xc6, 0}}, // = - NF_shadow_box_middle (2) + {{0xe1c7, 0, 0xc7, 0}}, // = - NF_shadow_box_hdd (2) + {{0xe1c8, 0, 0xc8, 0}}, // ◄ - NF_rev_left_arrow1 (2) + {{0xe1c9, 0, 0xc9, 0}}, // ⊏ - NF_rev_right_arrow1 (2) + {{0xe1ca, 0, 0xca, 0}}, // [ - NF_rev_menu_button1 (2) + {{0xe1cb, 0, 0xcb, 0}}, // - - NF_rev_menu_button2 (2) + {{0xe1cc, 0, 0xcc, 0}}, // ┌ - NF_border_corner_middle_upper_left (2) + {{0xe1cd, 0, 0xcd, 0}}, // = - NF_shadow_box_cd (2) + {{0xe1ce, 0, 0xce, 0}}, // [ - NF_shadow_box_left (2) + {{0xe1cf, 0, 0xcf, 0}}, // ┌ - NF_border_line_middle_left_down (2) + {{0xe1d0, 0, 0xd0, 0}}, // └ - NF_border_line_middle_right_up (2) + {{0xe1d1, 0, 0xd1, 0}}, // = - NF_shadow_box_net (2) + {{0xe1d2, 0, 0xd2, 0}}, // â—ĸ - NF_rev_up_pointing_triangle1 (2) + {{0xe1d3, 0, 0xd3, 0}}, // âŽŖ - NF_border_corner_lower_left (2) + {{0xe1d4, 0, 0xd4, 0}}, // _ - NF_border_line_bottom (2) + {{0xe1d5, 0, 0xd5, 0}}, // O - NF_radio_button2 (2) + {{0xe1d6, 0, 0xd6, 0}}, // ● - NF_radio_button2_checked (2) + {{0xe1d7, 0, 0xd7, 0}}, // â—Ĩ - NF_rev_down_pointing_triangle1 (2) + {{0xe1d8, 0, 0xd8, 0}}, // ¯ - NF_border_line_upper (2) + {{0xe1d9, 0, 0xd9, 0}}, // ( - NF_radio_button1 (2) + {{0xe1da, 0, 0xda, 0}}, // ⎡ - NF_border_corner_upper_left (2) + {{0xe1dc, 0, 0xdc, 0}}, // ✓ - NF_shadow_box_checked (2) + {{0xe1e7, 0, 0xe7, 0}}, // ║ - NF_rev_border_line_right_and_left (2) + {{0xe1e8, 0, 0xe8, 0}}, // â—Ŗ - NF_rev_up_pointing_triangle2 (2) + {{0xe1e9, 0, 0xe9, 0}}, // ◤ - NF_rev_down_pointing_triangle2 (2) + {{0xe1ea, 0, 0xea, 0}}, // ┘ - NF_border_corner_middle_lower_right (2) + {{0xe1eb, 0, 0xeb, 0}}, // ┐ - NF_border_corner_middle_upper_right (2) + {{0xe1f4, 0, 0xf4, 0}}, // ] - NF_rev_menu_button3 (2) + {{0xe1f5, 0, 0xf5, 0}}, // ] - NF_shadow_box_right (2) + {{0xe1fb, 0, 0xfb, 0}}, // ✓ - NF_check_mark (2) + {{0xe1fc, '~', 0xfc, '`'}}, // ËŖ - NF_xsuperior (2) + {{0x221a, 0, 0xfb, 'x'}} // √ - square root +}}; /* * (1) Not defined in Windows Glyph List 4 (WGL4) * (2) Only supported in use with newfont */ -const std::size_t lastCharItem = \ - std::size_t((sizeof(character) / sizeof(character[0])) - 1); +constexpr std::array, 39> vt100_key_to_utf8 = +{{ + {{fc::vt100_key_rarrow , fc::BlackRightPointingPointer}}, // â–ē + {{fc::vt100_key_larrow , fc::BlackLeftPointingPointer}}, // ◄ + {{fc::vt100_key_uarrow , fc::BlackUpPointingTriangle}}, // ▲ + {{fc::vt100_key_darrow , fc::BlackDownPointingTriangle}}, // â–ŧ + {{fc::vt100_key_block , fc::FullBlock}}, // █ + {{fc::vt100_key_nsup , fc::SuperscriptLatinSmallLetterN}}, // âŋ + {{fc::vt100_key_blackrect, fc::BlackVerticalRectangle}}, // ▮ + {{fc::vt100_key_diamond , fc::BlackDiamondSuit}}, // ◆ + {{fc::vt100_key_ckboard , fc::MediumShade}}, // ▒ + {{fc::vt100_key_htab , fc::SymbolForHorizontalTab}}, // ␉ + {{fc::vt100_key_ff , fc::SymbolForFormFeed}}, // ␌ + {{fc::vt100_key_cr , fc::SymbolForCarriageReturn}}, // ␍ + {{fc::vt100_key_lf , fc::SymbolForLineFeed}}, // ␊ + {{fc::vt100_key_degree , fc::Degree}}, // ° + {{fc::vt100_key_plminus , fc::PlusMinus}}, // Âą + {{fc::vt100_key_board , fc::SymbolForNewline}}, // ␤ + {{fc::vt100_key_lantern , fc::SymbolForVerticalTab}}, // ␋ + {{fc::vt100_key_lrcorner , fc::BoxDrawingsUpAndLeft}}, // ┘ + {{fc::vt100_key_urcorner , fc::BoxDrawingsDownAndLeft}}, // ┐ + {{fc::vt100_key_ulcorner , fc::BoxDrawingsDownAndRight}}, // ┌ + {{fc::vt100_key_llcorner , fc::BoxDrawingsUpAndRight}}, // └ + {{fc::vt100_key_plus , fc::BoxDrawingsCross}}, // â”ŧ + {{fc::vt100_key_s1 , fc::HorizontalScanLine1}}, // âŽē + {{fc::vt100_key_s3 , fc::HorizontalScanLine3}}, // âŽģ + {{fc::vt100_key_hline , fc::BoxDrawingsHorizontal}}, // ─ + {{fc::vt100_key_s7 , fc::HorizontalScanLine7}}, // âŽŧ + {{fc::vt100_key_s9 , fc::HorizontalScanLine9}}, // âŽŊ + {{fc::vt100_key_ltee , fc::BoxDrawingsVerticalAndRight}}, // ├ + {{fc::vt100_key_rtee , fc::BoxDrawingsVerticalAndLeft}}, // ┤ + {{fc::vt100_key_btee , fc::BoxDrawingsUpAndHorizontal}}, // ┴ + {{fc::vt100_key_ttee , fc::BoxDrawingsDownAndHorizontal}}, // â”Ŧ + {{fc::vt100_key_vline , fc::BoxDrawingsVertical}}, // │ + {{fc::vt100_key_lequal , fc::LessThanOrEqualTo}}, // ≤ + {{fc::vt100_key_gequal , fc::GreaterThanOrEqualTo}}, // â‰Ĩ + {{fc::vt100_key_pi , fc::Pi}}, // Ī€ + {{fc::vt100_key_nequal , fc::NotEqualTo}}, // ≠ + {{fc::vt100_key_sterling , fc::Pound}}, // ÂŖ + {{fc::vt100_key_bullet , fc::SmallBullet}}, // ¡ + {{fc::vt100_key_diamond , fc::Bullet}} // ◆ +}}; - -int vt100_key_to_utf8[][2] = -{ - {fc::vt100_key_rarrow , fc::BlackRightPointingPointer}, // â–ē - {fc::vt100_key_larrow , fc::BlackLeftPointingPointer}, // ◄ - {fc::vt100_key_uarrow , fc::BlackUpPointingTriangle}, // ▲ - {fc::vt100_key_darrow , fc::BlackDownPointingTriangle}, // â–ŧ - {fc::vt100_key_block , fc::FullBlock}, // █ - {fc::vt100_key_nsup , fc::SuperscriptLatinSmallLetterN}, // âŋ - {fc::vt100_key_blackrect, fc::BlackVerticalRectangle}, // ▮ - {fc::vt100_key_diamond , fc::BlackDiamondSuit}, // ◆ - {fc::vt100_key_ckboard , fc::MediumShade}, // ▒ - {fc::vt100_key_htab , fc::SymbolForHorizontalTab}, // ␉ - {fc::vt100_key_ff , fc::SymbolForFormFeed}, // ␌ - {fc::vt100_key_cr , fc::SymbolForCarriageReturn}, // ␍ - {fc::vt100_key_lf , fc::SymbolForLineFeed}, // ␊ - {fc::vt100_key_degree , fc::Degree}, // ° - {fc::vt100_key_plminus , fc::PlusMinus}, // Âą - {fc::vt100_key_board , fc::SymbolForNewline}, // ␤ - {fc::vt100_key_lantern , fc::SymbolForVerticalTab}, // ␋ - {fc::vt100_key_lrcorner , fc::BoxDrawingsUpAndLeft}, // ┘ - {fc::vt100_key_urcorner , fc::BoxDrawingsDownAndLeft}, // ┐ - {fc::vt100_key_ulcorner , fc::BoxDrawingsDownAndRight}, // ┌ - {fc::vt100_key_llcorner , fc::BoxDrawingsUpAndRight}, // └ - {fc::vt100_key_plus , fc::BoxDrawingsCross}, // â”ŧ - {fc::vt100_key_s1 , fc::HorizontalScanLine1}, // âŽē - {fc::vt100_key_s3 , fc::HorizontalScanLine3}, // âŽģ - {fc::vt100_key_hline , fc::BoxDrawingsHorizontal}, // ─ - {fc::vt100_key_s7 , fc::HorizontalScanLine7}, // âŽŧ - {fc::vt100_key_s9 , fc::HorizontalScanLine9}, // âŽŊ - {fc::vt100_key_ltee , fc::BoxDrawingsVerticalAndRight}, // ├ - {fc::vt100_key_rtee , fc::BoxDrawingsVerticalAndLeft}, // ┤ - {fc::vt100_key_btee , fc::BoxDrawingsUpAndHorizontal}, // ┴ - {fc::vt100_key_ttee , fc::BoxDrawingsDownAndHorizontal}, // â”Ŧ - {fc::vt100_key_vline , fc::BoxDrawingsVertical}, // │ - {fc::vt100_key_lequal , fc::LessThanOrEqualTo}, // ≤ - {fc::vt100_key_gequal , fc::GreaterThanOrEqualTo}, // â‰Ĩ - {fc::vt100_key_pi , fc::Pi}, // Ī€ - {fc::vt100_key_nequal , fc::NotEqualTo}, // ≠ - {fc::vt100_key_sterling , fc::Pound}, // ÂŖ - {fc::vt100_key_bullet , fc::SmallBullet}, // ¡ - {fc::vt100_key_diamond , fc::Bullet} // ◆ -}; - -const std::size_t lastKeyItem = \ - std::size_t((sizeof(vt100_key_to_utf8) / sizeof(vt100_key_to_utf8[0])) - 1); - - -wchar_t cp437_ucs[][2] = -{ - {0x00, 0x0000}, // null - {0x01, 0x263a}, // white smiling face - {0x02, 0x263b}, // black smiling face - {0x03, 0x2665}, // black heart suit - {0x04, 0x2666}, // black diamond suit - {0x05, 0x2663}, // black club suit - {0x06, 0x2660}, // black spade suit - {0x07, 0x2022}, // bullet - {0x08, 0x25d8}, // inverse bullet - {0x09, 0x25cb}, // white circle - {0x0a, 0x25d9}, // inverse white circle - {0x0b, 0x2642}, // male sign - {0x0c, 0x2640}, // female sign - {0x0d, 0x266a}, // eighth note - {0x0e, 0x266b}, // beamed eighth notes - {0x0f, 0x263c}, // white sun with rays - {0x10, 0x25ba}, // black right-pointing pointer - {0x11, 0x25c4}, // black left-pointing pointer - {0x12, 0x2195}, // up down arrow - {0x13, 0x203c}, // double exclamation mark - {0x14, 0x00b6}, // pilcrow sign - {0x15, 0x00a7}, // section sign - {0x16, 0x25ac}, // black rectangle - {0x17, 0x21a8}, // up down arrow with base - {0x18, 0x2191}, // upwards arrow - {0x19, 0x2193}, // downwards arrow - {0x1a, 0x2192}, // rightwards arrow - {0x1b, 0x2190}, // leftwards arrow - {0x1c, 0x221f}, // right angle - {0x1d, 0x2194}, // left right arrow - {0x1e, 0x25b2}, // black up-pointing triangle - {0x1f, 0x25bc}, // black down-pointing triangle - {0x20, 0x0020}, // space - {0x21, 0x0021}, // exclamation mark - {0x22, 0x0022}, // quotation mark - {0x23, 0x0023}, // number sign - {0x24, 0x0024}, // dollar sign - {0x25, 0x0025}, // percent sign - {0x26, 0x0026}, // ampersand - {0x27, 0x0027}, // apostrophe - {0x28, 0x0028}, // left parenthesis - {0x29, 0x0029}, // right parenthesis - {0x2a, 0x002a}, // asterisk - {0x2b, 0x002b}, // plus sign - {0x2c, 0x002c}, // comma - {0x2d, 0x002d}, // hyphen-minus - {0x2e, 0x002e}, // full stop - {0x2f, 0x002f}, // solidus - {0x30, 0x0030}, // digit zero - {0x31, 0x0031}, // digit one - {0x32, 0x0032}, // digit two - {0x33, 0x0033}, // digit three - {0x34, 0x0034}, // digit four - {0x35, 0x0035}, // digit five - {0x36, 0x0036}, // digit six - {0x37, 0x0037}, // digit seven - {0x38, 0x0038}, // digit eight - {0x39, 0x0039}, // digit nine - {0x3a, 0x003a}, // colon - {0x3b, 0x003b}, // semicolon - {0x3c, 0x003c}, // less-than sign - {0x3d, 0x003d}, // equals sign - {0x3e, 0x003e}, // greater-than sign - {0x3f, 0x003f}, // question mark - {0x40, 0x0040}, // commercial at - {0x41, 0x0041}, // latin capital letter a - {0x42, 0x0042}, // latin capital letter b - {0x43, 0x0043}, // latin capital letter c - {0x44, 0x0044}, // latin capital letter d - {0x45, 0x0045}, // latin capital letter e - {0x46, 0x0046}, // latin capital letter f - {0x47, 0x0047}, // latin capital letter g - {0x48, 0x0048}, // latin capital letter h - {0x49, 0x0049}, // latin capital letter i - {0x4a, 0x004a}, // latin capital letter j - {0x4b, 0x004b}, // latin capital letter k - {0x4c, 0x004c}, // latin capital letter l - {0x4d, 0x004d}, // latin capital letter m - {0x4e, 0x004e}, // latin capital letter n - {0x4f, 0x004f}, // latin capital letter o - {0x50, 0x0050}, // latin capital letter p - {0x51, 0x0051}, // latin capital letter q - {0x52, 0x0052}, // latin capital letter r - {0x53, 0x0053}, // latin capital letter s - {0x54, 0x0054}, // latin capital letter t - {0x55, 0x0055}, // latin capital letter u - {0x56, 0x0056}, // latin capital letter v - {0x57, 0x0057}, // latin capital letter w - {0x58, 0x0058}, // latin capital letter x - {0x59, 0x0059}, // latin capital letter y - {0x5a, 0x005a}, // latin capital letter z - {0x5b, 0x005b}, // left square bracket - {0x5c, 0x005c}, // reverse solidus - {0x5d, 0x005d}, // right square bracket - {0x5e, 0x005e}, // circumflex accent - {0x5f, 0x005f}, // low line - {0x60, 0x0060}, // grave accent - {0x61, 0x0061}, // latin small letter a - {0x62, 0x0062}, // latin small letter b - {0x63, 0x0063}, // latin small letter c - {0x64, 0x0064}, // latin small letter d - {0x65, 0x0065}, // latin small letter e - {0x66, 0x0066}, // latin small letter f - {0x67, 0x0067}, // latin small letter g - {0x68, 0x0068}, // latin small letter h - {0x69, 0x0069}, // latin small letter i - {0x6a, 0x006a}, // latin small letter j - {0x6b, 0x006b}, // latin small letter k - {0x6c, 0x006c}, // latin small letter l - {0x6d, 0x006d}, // latin small letter m - {0x6e, 0x006e}, // latin small letter n - {0x6f, 0x006f}, // latin small letter o - {0x70, 0x0070}, // latin small letter p - {0x71, 0x0071}, // latin small letter q - {0x72, 0x0072}, // latin small letter r - {0x73, 0x0073}, // latin small letter s - {0x74, 0x0074}, // latin small letter t - {0x75, 0x0075}, // latin small letter u - {0x76, 0x0076}, // latin small letter v - {0x77, 0x0077}, // latin small letter w - {0x78, 0x0078}, // latin small letter x - {0x79, 0x0079}, // latin small letter y - {0x7a, 0x007a}, // latin small letter z - {0x7b, 0x007b}, // left curly bracket - {0x7c, 0x007c}, // vertical line - {0x7d, 0x007d}, // right curly bracket - {0x7e, 0x007e}, // tilde - {0x7f, 0x007f}, // house - {0x80, 0x00c7}, // latin capital letter c with cedilla - {0x81, 0x00fc}, // latin small letter u with diaeresis - {0x82, 0x00e9}, // latin small letter e with acute - {0x83, 0x00e2}, // latin small letter a with circumflex - {0x84, 0x00e4}, // latin small letter a with diaeresis - {0x85, 0x00e0}, // latin small letter a with grave - {0x86, 0x00e5}, // latin small letter a with ring above - {0x87, 0x00e7}, // latin small letter c with cedilla - {0x88, 0x00ea}, // latin small letter e with circumflex - {0x89, 0x00eb}, // latin small letter e with diaeresis - {0x8a, 0x00e8}, // latin small letter e with grave - {0x8b, 0x00ef}, // latin small letter i with diaeresis - {0x8c, 0x00ee}, // latin small letter i with circumflex - {0x8d, 0x00ec}, // latin small letter i with grave - {0x8e, 0x00c4}, // latin capital letter a with diaeresis - {0x8f, 0x00c5}, // latin capital letter a with ring above - {0x90, 0x00c9}, // latin capital letter e with acute - {0x91, 0x00e6}, // latin small ligature ae - {0x92, 0x00c6}, // latin capital ligature ae - {0x93, 0x00f4}, // latin small letter o with circumflex - {0x94, 0x00f6}, // latin small letter o with diaeresis - {0x95, 0x00f2}, // latin small letter o with grave - {0x96, 0x00fb}, // latin small letter u with circumflex - {0x97, 0x00f9}, // latin small letter u with grave - {0x98, 0x00ff}, // latin small letter y with diaeresis - {0x99, 0x00d6}, // latin capital letter o with diaeresis - {0x9a, 0x00dc}, // latin capital letter u with diaeresis - {0x9b, 0x00a2}, // cent sign - {0x9c, 0x00a3}, // pound sign - {0x9d, 0x00a5}, // yen sign - {0x9e, 0x20a7}, // peseta sign - {0x9f, 0x0192}, // latin small letter f with hook - {0xa0, 0x00e1}, // latin small letter a with acute - {0xa1, 0x00ed}, // latin small letter i with acute - {0xa2, 0x00f3}, // latin small letter o with acute - {0xa3, 0x00fa}, // latin small letter u with acute - {0xa4, 0x00f1}, // latin small letter n with tilde - {0xa5, 0x00d1}, // latin capital letter n with tilde - {0xa6, 0x00aa}, // feminine ordinal indicator - {0xa7, 0x00ba}, // masculine ordinal indicator - {0xa8, 0x00bf}, // inverted question mark - {0xa9, 0x2310}, // reversed not sign - {0xaa, 0x00ac}, // not sign - {0xab, 0x00bd}, // vulgar fraction one half - {0xac, 0x00bc}, // vulgar fraction one quarter - {0xad, 0x00a1}, // inverted exclamation mark - {0xae, 0x00ab}, // left-pointing double angle quotation mark - {0xaf, 0x00bb}, // right-pointing double angle quotation mark - {0xb0, 0x2591}, // light shade - {0xb1, 0x2592}, // medium shade - {0xb2, 0x2593}, // dark shade - {0xb3, 0x2502}, // box drawings light vertical - {0xb4, 0x2524}, // box drawings light vertical and left - {0xb5, 0x2561}, // box drawings vertical single and left double - {0xb6, 0x2562}, // box drawings vertical double and left single - {0xb7, 0x2556}, // box drawings down double and left single - {0xb8, 0x2555}, // box drawings down single and left double - {0xb9, 0x2563}, // box drawings double vertical and left - {0xba, 0x2551}, // box drawings double vertical - {0xbb, 0x2557}, // box drawings double down and left - {0xbc, 0x255d}, // box drawings double up and left - {0xbd, 0x255c}, // box drawings up double and left single - {0xbe, 0x255b}, // box drawings up single and left double - {0xbf, 0x2510}, // box drawings light down and left - {0xc0, 0x2514}, // box drawings light up and right - {0xc1, 0x2534}, // box drawings light up and horizontal - {0xc2, 0x252c}, // box drawings light down and horizontal - {0xc3, 0x251c}, // box drawings light vertical and right - {0xc4, 0x2500}, // box drawings light horizontal - {0xc5, 0x253c}, // box drawings light vertical and horizontal - {0xc6, 0x255e}, // box drawings vertical single and right double - {0xc7, 0x255f}, // box drawings vertical double and right single - {0xc8, 0x255a}, // box drawings double up and right - {0xc9, 0x2554}, // box drawings double down and right - {0xca, 0x2569}, // box drawings double up and horizontal - {0xcb, 0x2566}, // box drawings double down and horizontal - {0xcc, 0x2560}, // box drawings double vertical and right - {0xcd, 0x2550}, // box drawings double horizontal - {0xce, 0x256c}, // box drawings double vertical and horizontal - {0xcf, 0x2567}, // box drawings up single and horizontal double - {0xd0, 0x2568}, // box drawings up double and horizontal single - {0xd1, 0x2564}, // box drawings down single and horizontal double - {0xd2, 0x2565}, // box drawings down double and horizontal single - {0xd3, 0x2559}, // box drawings up double and right single - {0xd4, 0x2558}, // box drawings up single and right double - {0xd5, 0x2552}, // box drawings down single and right double - {0xd6, 0x2553}, // box drawings down double and right single - {0xd7, 0x256b}, // box drawings vertical double and horizontal single - {0xd8, 0x256a}, // box drawings vertical single and horizontal double - {0xd9, 0x2518}, // box drawings light up and left - {0xda, 0x250c}, // box drawings light down and right - {0xdb, 0x2588}, // full block - {0xdc, 0x2584}, // lower half block - {0xdd, 0x258c}, // left half block - {0xde, 0x2590}, // right half block - {0xdf, 0x2580}, // upper half block - {0xe0, 0x03b1}, // greek small letter alpha - {0xe1, 0x00df}, // latin small letter sharp s - {0xe2, 0x0393}, // greek capital letter gamma - {0xe3, 0x03c0}, // greek small letter pi - {0xe4, 0x03a3}, // greek capital letter sigma - {0xe5, 0x03c3}, // greek small letter sigma - {0xe6, 0x00b5}, // micro sign - {0xe7, 0x03c4}, // greek small letter tau - {0xe8, 0x03a6}, // greek capital letter phi - {0xe9, 0x0398}, // greek capital letter theta - {0xea, 0x03a9}, // greek capital letter omega - {0xeb, 0x03b4}, // greek small letter delta - {0xec, 0x221e}, // infinity - {0xed, 0x03c6}, // greek small letter phi - {0xee, 0x03b5}, // greek small letter epsilon - {0xef, 0x2229}, // intersection - {0xf0, 0x2261}, // identical to - {0xf1, 0x00b1}, // plus-minus sign - {0xf2, 0x2265}, // greater-than or equal to - {0xf3, 0x2264}, // less-than or equal to - {0xf4, 0x2320}, // top half integral - {0xf5, 0x2321}, // bottom half integral - {0xf6, 0x00f7}, // division sign - {0xf7, 0x2248}, // almost equal to - {0xf8, 0x00b0}, // degree sign - {0xf9, 0x2219}, // bullet operator - {0xfa, 0x00b7}, // middle dot - {0xfb, 0x221a}, // square root - {0xfc, 0x207f}, // superscript latin small letter n - {0xfd, 0x00b2}, // superscript two - {0xfe, 0x25a0}, // black square - {0xff, 0x00a0} // no-break space -}; - -const std::size_t lastCP437Item = \ - std::size_t((sizeof(cp437_ucs) / sizeof(cp437_ucs[0])) - 1); +constexpr std::array, 256> cp437_ucs = +{{ + {{0x00, 0x0000}}, // null + {{0x01, 0x263a}}, // white smiling face + {{0x02, 0x263b}}, // black smiling face + {{0x03, 0x2665}}, // black heart suit + {{0x04, 0x2666}}, // black diamond suit + {{0x05, 0x2663}}, // black club suit + {{0x06, 0x2660}}, // black spade suit + {{0x07, 0x2022}}, // bullet + {{0x08, 0x25d8}}, // inverse bullet + {{0x09, 0x25cb}}, // white circle + {{0x0a, 0x25d9}}, // inverse white circle + {{0x0b, 0x2642}}, // male sign + {{0x0c, 0x2640}}, // female sign + {{0x0d, 0x266a}}, // eighth note + {{0x0e, 0x266b}}, // beamed eighth notes + {{0x0f, 0x263c}}, // white sun with rays + {{0x10, 0x25ba}}, // black right-pointing pointer + {{0x11, 0x25c4}}, // black left-pointing pointer + {{0x12, 0x2195}}, // up down arrow + {{0x13, 0x203c}}, // double exclamation mark + {{0x14, 0x00b6}}, // pilcrow sign + {{0x15, 0x00a7}}, // section sign + {{0x16, 0x25ac}}, // black rectangle + {{0x17, 0x21a8}}, // up down arrow with base + {{0x18, 0x2191}}, // upwards arrow + {{0x19, 0x2193}}, // downwards arrow + {{0x1a, 0x2192}}, // rightwards arrow + {{0x1b, 0x2190}}, // leftwards arrow + {{0x1c, 0x221f}}, // right angle + {{0x1d, 0x2194}}, // left right arrow + {{0x1e, 0x25b2}}, // black up-pointing triangle + {{0x1f, 0x25bc}}, // black down-pointing triangle + {{0x20, 0x0020}}, // space + {{0x21, 0x0021}}, // exclamation mark + {{0x22, 0x0022}}, // quotation mark + {{0x23, 0x0023}}, // number sign + {{0x24, 0x0024}}, // dollar sign + {{0x25, 0x0025}}, // percent sign + {{0x26, 0x0026}}, // ampersand + {{0x27, 0x0027}}, // apostrophe + {{0x28, 0x0028}}, // left parenthesis + {{0x29, 0x0029}}, // right parenthesis + {{0x2a, 0x002a}}, // asterisk + {{0x2b, 0x002b}}, // plus sign + {{0x2c, 0x002c}}, // comma + {{0x2d, 0x002d}}, // hyphen-minus + {{0x2e, 0x002e}}, // full stop + {{0x2f, 0x002f}}, // solidus + {{0x30, 0x0030}}, // digit zero + {{0x31, 0x0031}}, // digit one + {{0x32, 0x0032}}, // digit two + {{0x33, 0x0033}}, // digit three + {{0x34, 0x0034}}, // digit four + {{0x35, 0x0035}}, // digit five + {{0x36, 0x0036}}, // digit six + {{0x37, 0x0037}}, // digit seven + {{0x38, 0x0038}}, // digit eight + {{0x39, 0x0039}}, // digit nine + {{0x3a, 0x003a}}, // colon + {{0x3b, 0x003b}}, // semicolon + {{0x3c, 0x003c}}, // less-than sign + {{0x3d, 0x003d}}, // equals sign + {{0x3e, 0x003e}}, // greater-than sign + {{0x3f, 0x003f}}, // question mark + {{0x40, 0x0040}}, // commercial at + {{0x41, 0x0041}}, // latin capital letter a + {{0x42, 0x0042}}, // latin capital letter b + {{0x43, 0x0043}}, // latin capital letter c + {{0x44, 0x0044}}, // latin capital letter d + {{0x45, 0x0045}}, // latin capital letter e + {{0x46, 0x0046}}, // latin capital letter f + {{0x47, 0x0047}}, // latin capital letter g + {{0x48, 0x0048}}, // latin capital letter h + {{0x49, 0x0049}}, // latin capital letter i + {{0x4a, 0x004a}}, // latin capital letter j + {{0x4b, 0x004b}}, // latin capital letter k + {{0x4c, 0x004c}}, // latin capital letter l + {{0x4d, 0x004d}}, // latin capital letter m + {{0x4e, 0x004e}}, // latin capital letter n + {{0x4f, 0x004f}}, // latin capital letter o + {{0x50, 0x0050}}, // latin capital letter p + {{0x51, 0x0051}}, // latin capital letter q + {{0x52, 0x0052}}, // latin capital letter r + {{0x53, 0x0053}}, // latin capital letter s + {{0x54, 0x0054}}, // latin capital letter t + {{0x55, 0x0055}}, // latin capital letter u + {{0x56, 0x0056}}, // latin capital letter v + {{0x57, 0x0057}}, // latin capital letter w + {{0x58, 0x0058}}, // latin capital letter x + {{0x59, 0x0059}}, // latin capital letter y + {{0x5a, 0x005a}}, // latin capital letter z + {{0x5b, 0x005b}}, // left square bracket + {{0x5c, 0x005c}}, // reverse solidus + {{0x5d, 0x005d}}, // right square bracket + {{0x5e, 0x005e}}, // circumflex accent + {{0x5f, 0x005f}}, // low line + {{0x60, 0x0060}}, // grave accent + {{0x61, 0x0061}}, // latin small letter a + {{0x62, 0x0062}}, // latin small letter b + {{0x63, 0x0063}}, // latin small letter c + {{0x64, 0x0064}}, // latin small letter d + {{0x65, 0x0065}}, // latin small letter e + {{0x66, 0x0066}}, // latin small letter f + {{0x67, 0x0067}}, // latin small letter g + {{0x68, 0x0068}}, // latin small letter h + {{0x69, 0x0069}}, // latin small letter i + {{0x6a, 0x006a}}, // latin small letter j + {{0x6b, 0x006b}}, // latin small letter k + {{0x6c, 0x006c}}, // latin small letter l + {{0x6d, 0x006d}}, // latin small letter m + {{0x6e, 0x006e}}, // latin small letter n + {{0x6f, 0x006f}}, // latin small letter o + {{0x70, 0x0070}}, // latin small letter p + {{0x71, 0x0071}}, // latin small letter q + {{0x72, 0x0072}}, // latin small letter r + {{0x73, 0x0073}}, // latin small letter s + {{0x74, 0x0074}}, // latin small letter t + {{0x75, 0x0075}}, // latin small letter u + {{0x76, 0x0076}}, // latin small letter v + {{0x77, 0x0077}}, // latin small letter w + {{0x78, 0x0078}}, // latin small letter x + {{0x79, 0x0079}}, // latin small letter y + {{0x7a, 0x007a}}, // latin small letter z + {{0x7b, 0x007b}}, // left curly bracket + {{0x7c, 0x007c}}, // vertical line + {{0x7d, 0x007d}}, // right curly bracket + {{0x7e, 0x007e}}, // tilde + {{0x7f, 0x007f}}, // house + {{0x80, 0x00c7}}, // latin capital letter c with cedilla + {{0x81, 0x00fc}}, // latin small letter u with diaeresis + {{0x82, 0x00e9}}, // latin small letter e with acute + {{0x83, 0x00e2}}, // latin small letter a with circumflex + {{0x84, 0x00e4}}, // latin small letter a with diaeresis + {{0x85, 0x00e0}}, // latin small letter a with grave + {{0x86, 0x00e5}}, // latin small letter a with ring above + {{0x87, 0x00e7}}, // latin small letter c with cedilla + {{0x88, 0x00ea}}, // latin small letter e with circumflex + {{0x89, 0x00eb}}, // latin small letter e with diaeresis + {{0x8a, 0x00e8}}, // latin small letter e with grave + {{0x8b, 0x00ef}}, // latin small letter i with diaeresis + {{0x8c, 0x00ee}}, // latin small letter i with circumflex + {{0x8d, 0x00ec}}, // latin small letter i with grave + {{0x8e, 0x00c4}}, // latin capital letter a with diaeresis + {{0x8f, 0x00c5}}, // latin capital letter a with ring above + {{0x90, 0x00c9}}, // latin capital letter e with acute + {{0x91, 0x00e6}}, // latin small ligature ae + {{0x92, 0x00c6}}, // latin capital ligature ae + {{0x93, 0x00f4}}, // latin small letter o with circumflex + {{0x94, 0x00f6}}, // latin small letter o with diaeresis + {{0x95, 0x00f2}}, // latin small letter o with grave + {{0x96, 0x00fb}}, // latin small letter u with circumflex + {{0x97, 0x00f9}}, // latin small letter u with grave + {{0x98, 0x00ff}}, // latin small letter y with diaeresis + {{0x99, 0x00d6}}, // latin capital letter o with diaeresis + {{0x9a, 0x00dc}}, // latin capital letter u with diaeresis + {{0x9b, 0x00a2}}, // cent sign + {{0x9c, 0x00a3}}, // pound sign + {{0x9d, 0x00a5}}, // yen sign + {{0x9e, 0x20a7}}, // peseta sign + {{0x9f, 0x0192}}, // latin small letter f with hook + {{0xa0, 0x00e1}}, // latin small letter a with acute + {{0xa1, 0x00ed}}, // latin small letter i with acute + {{0xa2, 0x00f3}}, // latin small letter o with acute + {{0xa3, 0x00fa}}, // latin small letter u with acute + {{0xa4, 0x00f1}}, // latin small letter n with tilde + {{0xa5, 0x00d1}}, // latin capital letter n with tilde + {{0xa6, 0x00aa}}, // feminine ordinal indicator + {{0xa7, 0x00ba}}, // masculine ordinal indicator + {{0xa8, 0x00bf}}, // inverted question mark + {{0xa9, 0x2310}}, // reversed not sign + {{0xaa, 0x00ac}}, // not sign + {{0xab, 0x00bd}}, // vulgar fraction one half + {{0xac, 0x00bc}}, // vulgar fraction one quarter + {{0xad, 0x00a1}}, // inverted exclamation mark + {{0xae, 0x00ab}}, // left-pointing double angle quotation mark + {{0xaf, 0x00bb}}, // right-pointing double angle quotation mark + {{0xb0, 0x2591}}, // light shade + {{0xb1, 0x2592}}, // medium shade + {{0xb2, 0x2593}}, // dark shade + {{0xb3, 0x2502}}, // box drawings light vertical + {{0xb4, 0x2524}}, // box drawings light vertical and left + {{0xb5, 0x2561}}, // box drawings vertical single and left double + {{0xb6, 0x2562}}, // box drawings vertical double and left single + {{0xb7, 0x2556}}, // box drawings down double and left single + {{0xb8, 0x2555}}, // box drawings down single and left double + {{0xb9, 0x2563}}, // box drawings double vertical and left + {{0xba, 0x2551}}, // box drawings double vertical + {{0xbb, 0x2557}}, // box drawings double down and left + {{0xbc, 0x255d}}, // box drawings double up and left + {{0xbd, 0x255c}}, // box drawings up double and left single + {{0xbe, 0x255b}}, // box drawings up single and left double + {{0xbf, 0x2510}}, // box drawings light down and left + {{0xc0, 0x2514}}, // box drawings light up and right + {{0xc1, 0x2534}}, // box drawings light up and horizontal + {{0xc2, 0x252c}}, // box drawings light down and horizontal + {{0xc3, 0x251c}}, // box drawings light vertical and right + {{0xc4, 0x2500}}, // box drawings light horizontal + {{0xc5, 0x253c}}, // box drawings light vertical and horizontal + {{0xc6, 0x255e}}, // box drawings vertical single and right double + {{0xc7, 0x255f}}, // box drawings vertical double and right single + {{0xc8, 0x255a}}, // box drawings double up and right + {{0xc9, 0x2554}}, // box drawings double down and right + {{0xca, 0x2569}}, // box drawings double up and horizontal + {{0xcb, 0x2566}}, // box drawings double down and horizontal + {{0xcc, 0x2560}}, // box drawings double vertical and right + {{0xcd, 0x2550}}, // box drawings double horizontal + {{0xce, 0x256c}}, // box drawings double vertical and horizontal + {{0xcf, 0x2567}}, // box drawings up single and horizontal double + {{0xd0, 0x2568}}, // box drawings up double and horizontal single + {{0xd1, 0x2564}}, // box drawings down single and horizontal double + {{0xd2, 0x2565}}, // box drawings down double and horizontal single + {{0xd3, 0x2559}}, // box drawings up double and right single + {{0xd4, 0x2558}}, // box drawings up single and right double + {{0xd5, 0x2552}}, // box drawings down single and right double + {{0xd6, 0x2553}}, // box drawings down double and right single + {{0xd7, 0x256b}}, // box drawings vertical double and horizontal single + {{0xd8, 0x256a}}, // box drawings vertical single and horizontal double + {{0xd9, 0x2518}}, // box drawings light up and left + {{0xda, 0x250c}}, // box drawings light down and right + {{0xdb, 0x2588}}, // full block + {{0xdc, 0x2584}}, // lower half block + {{0xdd, 0x258c}}, // left half block + {{0xde, 0x2590}}, // right half block + {{0xdf, 0x2580}}, // upper half block + {{0xe0, 0x03b1}}, // greek small letter alpha + {{0xe1, 0x00df}}, // latin small letter sharp s + {{0xe2, 0x0393}}, // greek capital letter gamma + {{0xe3, 0x03c0}}, // greek small letter pi + {{0xe4, 0x03a3}}, // greek capital letter sigma + {{0xe5, 0x03c3}}, // greek small letter sigma + {{0xe6, 0x00b5}}, // micro sign + {{0xe7, 0x03c4}}, // greek small letter tau + {{0xe8, 0x03a6}}, // greek capital letter phi + {{0xe9, 0x0398}}, // greek capital letter theta + {{0xea, 0x03a9}}, // greek capital letter omega + {{0xeb, 0x03b4}}, // greek small letter delta + {{0xec, 0x221e}}, // infinity + {{0xed, 0x03c6}}, // greek small letter phi + {{0xee, 0x03b5}}, // greek small letter epsilon + {{0xef, 0x2229}}, // intersection + {{0xf0, 0x2261}}, // identical to + {{0xf1, 0x00b1}}, // plus-minus sign + {{0xf2, 0x2265}}, // greater-than or equal to + {{0xf3, 0x2264}}, // less-than or equal to + {{0xf4, 0x2320}}, // top half integral + {{0xf5, 0x2321}}, // bottom half integral + {{0xf6, 0x00f7}}, // division sign + {{0xf7, 0x2248}}, // almost equal to + {{0xf8, 0x00b0}}, // degree sign + {{0xf9, 0x2219}}, // bullet operator + {{0xfa, 0x00b7}}, // middle dot + {{0xfb, 0x221a}}, // square root + {{0xfc, 0x207f}}, // superscript latin small letter n + {{0xfd, 0x00b2}}, // superscript two + {{0xfe, 0x25a0}}, // black square + {{0xff, 0x00a0}} // no-break space +}}; // Based on http://www.unicode.org/charts/PDF/UFF00.pdf -const wchar_t halfWidth_fullWidth[][2] = -{ +constexpr std::array, 227> halfwidth_fullwidth = +{{ // Fullwidth ASCII variants - {0x0020, 0x3000}, // ' ' -> ' ' - {0x0021, 0xff01}, // ! -> īŧ - {0x0022, 0xff02}, // " -> īŧ‚ - {0x0023, 0xff03}, // # -> īŧƒ - {0x0024, 0xff04}, // $ -> īŧ„ - {0x0025, 0xff05}, // % -> īŧ… - {0x0026, 0xff06}, // & -> īŧ† - {0x0027, 0xff07}, // ' -> īŧ‡ - {0x0028, 0xff08}, // ( -> īŧˆ - {0x0029, 0xff09}, // ) -> īŧ‰ - {0x002a, 0xff0a}, // * -> īŧŠ - {0x002b, 0xff0b}, // + -> īŧ‹ - {0x002c, 0xff0c}, // , -> īŧŒ - {0x002d, 0xff0d}, // - -> īŧ - {0x002e, 0xff0e}, // . -> īŧŽ - {0x002f, 0xff0f}, // / -> īŧ - {0x0030, 0xff10}, // 0 -> īŧ - {0x0031, 0xff11}, // 1 -> īŧ‘ - {0x0032, 0xff12}, // 2 -> īŧ’ - {0x0033, 0xff13}, // 3 -> īŧ“ - {0x0034, 0xff14}, // 4 -> īŧ” - {0x0035, 0xff15}, // 5 -> īŧ• - {0x0036, 0xff16}, // 6 -> īŧ– - {0x0037, 0xff17}, // 7 -> īŧ— - {0x0038, 0xff18}, // 8 -> īŧ˜ - {0x0039, 0xff19}, // 9 -> īŧ™ - {0x003a, 0xff1a}, // : -> īŧš - {0x003b, 0xff1b}, // ; -> īŧ› - {0x003c, 0xff1c}, // < -> īŧœ - {0x003d, 0xff1d}, // = -> īŧ - {0x003e, 0xff1e}, // > -> īŧž - {0x003f, 0xff1f}, // ? -> īŧŸ - {0x0040, 0xff20}, // @ -> īŧ  - {0x0041, 0xff21}, // A -> īŧĄ - {0x0042, 0xff22}, // B -> īŧĸ - {0x0043, 0xff23}, // C -> īŧŖ - {0x0044, 0xff24}, // D -> īŧ¤ - {0x0045, 0xff25}, // E -> īŧĨ - {0x0046, 0xff26}, // F -> īŧĻ - {0x0047, 0xff27}, // G -> īŧ§ - {0x0048, 0xff28}, // H -> īŧ¨ - {0x0049, 0xff29}, // I -> īŧŠ - {0x004a, 0xff2a}, // J -> īŧĒ - {0x004b, 0xff2b}, // K -> īŧĢ - {0x004c, 0xff2c}, // L -> īŧŦ - {0x004d, 0xff2d}, // M -> īŧ­ - {0x004e, 0xff2e}, // N -> īŧŽ - {0x004f, 0xff2f}, // O -> īŧ¯ - {0x0050, 0xff30}, // P -> īŧ° - {0x0051, 0xff31}, // Q -> īŧą - {0x0052, 0xff32}, // R -> īŧ˛ - {0x0053, 0xff33}, // S -> īŧŗ - {0x0054, 0xff34}, // T -> īŧ´ - {0x0055, 0xff35}, // U -> īŧĩ - {0x0056, 0xff36}, // V -> īŧļ - {0x0057, 0xff37}, // W -> īŧˇ - {0x0058, 0xff38}, // X -> īŧ¸ - {0x0059, 0xff39}, // Y -> īŧš - {0x005a, 0xff3a}, // Z -> īŧē - {0x005b, 0xff3b}, // [ -> īŧģ - {0x005c, 0xff3c}, // \ -> īŧŧ - {0x005d, 0xff3c}, // ] -> īŧŊ - {0x005e, 0xff3e}, // ^ -> īŧž - {0x005f, 0xff3f}, // _ -> īŧŋ - {0x0060, 0xff40}, // ` -> īŊ€ - {0x0061, 0xff41}, // a -> īŊ - {0x0062, 0xff42}, // b -> īŊ‚ - {0x0063, 0xff43}, // c -> īŊƒ - {0x0064, 0xff44}, // d -> īŊ„ - {0x0065, 0xff45}, // e -> īŊ… - {0x0066, 0xff46}, // f -> īŊ† - {0x0067, 0xff47}, // g -> īŊ‡ - {0x0068, 0xff48}, // h -> īŊˆ - {0x0069, 0xff49}, // i -> īŊ‰ - {0x006a, 0xff4a}, // j -> īŊŠ - {0x006b, 0xff4b}, // k -> īŊ‹ - {0x006c, 0xff4c}, // l -> īŊŒ - {0x006d, 0xff4d}, // m -> īŊ - {0x006e, 0xff4e}, // n -> īŊŽ - {0x006f, 0xff4f}, // o -> īŊ - {0x0070, 0xff50}, // p -> īŊ - {0x0071, 0xff51}, // q -> īŊ‘ - {0x0072, 0xff52}, // r -> īŊ’ - {0x0073, 0xff53}, // s -> īŊ“ - {0x0074, 0xff54}, // t -> īŊ” - {0x0075, 0xff55}, // u -> īŊ• - {0x0076, 0xff56}, // v -> īŊ– - {0x0077, 0xff57}, // w -> īŊ— - {0x0078, 0xff58}, // x -> īŊ˜ - {0x0079, 0xff59}, // y -> īŊ™ - {0x007a, 0xff5a}, // z -> īŊš - {0x007b, 0xff5b}, // { -> īŊ› - {0x007c, 0xff5c}, // | -> īŊœ - {0x007d, 0xff5d}, // } -> īŊ - {0x007e, 0xff5e}, // ~ -> īŊž - {0x007e, 0x0301}, // ~ -> 〜 + {{0x0020, 0x3000}}, // ' ' -> ' ' + {{0x0021, 0xff01}}, // ! -> īŧ + {{0x0022, 0xff02}}, // " -> īŧ‚ + {{0x0023, 0xff03}}, // # -> īŧƒ + {{0x0024, 0xff04}}, // $ -> īŧ„ + {{0x0025, 0xff05}}, // % -> īŧ… + {{0x0026, 0xff06}}, // & -> īŧ† + {{0x0027, 0xff07}}, // ' -> īŧ‡ + {{0x0028, 0xff08}}, // ( -> īŧˆ + {{0x0029, 0xff09}}, // ) -> īŧ‰ + {{0x002a, 0xff0a}}, // * -> īŧŠ + {{0x002b, 0xff0b}}, // + -> īŧ‹ + {{0x002c, 0xff0c}}, // , -> īŧŒ + {{0x002d, 0xff0d}}, // - -> īŧ + {{0x002e, 0xff0e}}, // . -> īŧŽ + {{0x002f, 0xff0f}}, // / -> īŧ + {{0x0030, 0xff10}}, // 0 -> īŧ + {{0x0031, 0xff11}}, // 1 -> īŧ‘ + {{0x0032, 0xff12}}, // 2 -> īŧ’ + {{0x0033, 0xff13}}, // 3 -> īŧ“ + {{0x0034, 0xff14}}, // 4 -> īŧ” + {{0x0035, 0xff15}}, // 5 -> īŧ• + {{0x0036, 0xff16}}, // 6 -> īŧ– + {{0x0037, 0xff17}}, // 7 -> īŧ— + {{0x0038, 0xff18}}, // 8 -> īŧ˜ + {{0x0039, 0xff19}}, // 9 -> īŧ™ + {{0x003a, 0xff1a}}, // : -> īŧš + {{0x003b, 0xff1b}}, // ; -> īŧ› + {{0x003c, 0xff1c}}, // < -> īŧœ + {{0x003d, 0xff1d}}, // = -> īŧ + {{0x003e, 0xff1e}}, // > -> īŧž + {{0x003f, 0xff1f}}, // ? -> īŧŸ + {{0x0040, 0xff20}}, // @ -> īŧ  + {{0x0041, 0xff21}}, // A -> īŧĄ + {{0x0042, 0xff22}}, // B -> īŧĸ + {{0x0043, 0xff23}}, // C -> īŧŖ + {{0x0044, 0xff24}}, // D -> īŧ¤ + {{0x0045, 0xff25}}, // E -> īŧĨ + {{0x0046, 0xff26}}, // F -> īŧĻ + {{0x0047, 0xff27}}, // G -> īŧ§ + {{0x0048, 0xff28}}, // H -> īŧ¨ + {{0x0049, 0xff29}}, // I -> īŧŠ + {{0x004a, 0xff2a}}, // J -> īŧĒ + {{0x004b, 0xff2b}}, // K -> īŧĢ + {{0x004c, 0xff2c}}, // L -> īŧŦ + {{0x004d, 0xff2d}}, // M -> īŧ­ + {{0x004e, 0xff2e}}, // N -> īŧŽ + {{0x004f, 0xff2f}}, // O -> īŧ¯ + {{0x0050, 0xff30}}, // P -> īŧ° + {{0x0051, 0xff31}}, // Q -> īŧą + {{0x0052, 0xff32}}, // R -> īŧ˛ + {{0x0053, 0xff33}}, // S -> īŧŗ + {{0x0054, 0xff34}}, // T -> īŧ´ + {{0x0055, 0xff35}}, // U -> īŧĩ + {{0x0056, 0xff36}}, // V -> īŧļ + {{0x0057, 0xff37}}, // W -> īŧˇ + {{0x0058, 0xff38}}, // X -> īŧ¸ + {{0x0059, 0xff39}}, // Y -> īŧš + {{0x005a, 0xff3a}}, // Z -> īŧē + {{0x005b, 0xff3b}}, // [ -> īŧģ + {{0x005c, 0xff3c}}, // \ -> īŧŧ + {{0x005d, 0xff3c}}, // ] -> īŧŊ + {{0x005e, 0xff3e}}, // ^ -> īŧž + {{0x005f, 0xff3f}}, // _ -> īŧŋ + {{0x0060, 0xff40}}, // ` -> īŊ€ + {{0x0061, 0xff41}}, // a -> īŊ + {{0x0062, 0xff42}}, // b -> īŊ‚ + {{0x0063, 0xff43}}, // c -> īŊƒ + {{0x0064, 0xff44}}, // d -> īŊ„ + {{0x0065, 0xff45}}, // e -> īŊ… + {{0x0066, 0xff46}}, // f -> īŊ† + {{0x0067, 0xff47}}, // g -> īŊ‡ + {{0x0068, 0xff48}}, // h -> īŊˆ + {{0x0069, 0xff49}}, // i -> īŊ‰ + {{0x006a, 0xff4a}}, // j -> īŊŠ + {{0x006b, 0xff4b}}, // k -> īŊ‹ + {{0x006c, 0xff4c}}, // l -> īŊŒ + {{0x006d, 0xff4d}}, // m -> īŊ + {{0x006e, 0xff4e}}, // n -> īŊŽ + {{0x006f, 0xff4f}}, // o -> īŊ + {{0x0070, 0xff50}}, // p -> īŊ + {{0x0071, 0xff51}}, // q -> īŊ‘ + {{0x0072, 0xff52}}, // r -> īŊ’ + {{0x0073, 0xff53}}, // s -> īŊ“ + {{0x0074, 0xff54}}, // t -> īŊ” + {{0x0075, 0xff55}}, // u -> īŊ• + {{0x0076, 0xff56}}, // v -> īŊ– + {{0x0077, 0xff57}}, // w -> īŊ— + {{0x0078, 0xff58}}, // x -> īŊ˜ + {{0x0079, 0xff59}}, // y -> īŊ™ + {{0x007a, 0xff5a}}, // z -> īŊš + {{0x007b, 0xff5b}}, // { -> īŊ› + {{0x007c, 0xff5c}}, // | -> īŊœ + {{0x007d, 0xff5d}}, // } -> īŊ + {{0x007e, 0xff5e}}, // ~ -> īŊž + {{0x007e, 0x0301}}, // ~ -> 〜 // Fullwidth brackets - {0xff5f, 0x2e28}, // īŊŸ -> ⸨ - {0xff60, 0x2e29}, // īŊ  -> ⸊ + {{0xff5f, 0x2e28}}, // īŊŸ -> ⸨ + {{0xff60, 0x2e29}}, // īŊ  -> ⸊ // Halfwidth CJK punctuation - {0xff61, 0x3002}, // īŊĄ -> 。 - {0xff62, 0x300c}, // īŊĸ -> 「 - {0xff63, 0x300d}, // īŊŖ -> 」 - {0xff64, 0x3001}, // īŊ¤ -> 、 + {{0xff61, 0x3002}}, // īŊĄ -> 。 + {{0xff62, 0x300c}}, // īŊĸ -> 「 + {{0xff63, 0x300d}}, // īŊŖ -> 」 + {{0xff64, 0x3001}}, // īŊ¤ -> 、 // Halfwidth Katakana variants - {0xff65, 0x30fb}, // īŊĨ -> ãƒģ - {0xff66, 0x30f2}, // īŊĻ -> ãƒ˛ - {0xff67, 0x30a1}, // īŊ§ -> ã‚Ą - {0xff68, 0x30a3}, // īŊ¨ -> ã‚Ŗ - {0xff69, 0x30a5}, // īŊŠ -> ã‚Ĩ - {0xff6a, 0x30a7}, // īŊĒ -> ェ - {0xff6b, 0x30a9}, // īŊĢ -> ã‚Š - {0xff6c, 0x30e3}, // īŊŦ -> ãƒŖ - {0xff6d, 0x30e5}, // īŊ­ -> ãƒĨ - {0xff6e, 0x30e7}, // īŊŽ -> ョ - {0xff6f, 0x30c3}, // īŊ¯ -> ッ - {0xff70, 0x30fc}, // īŊ° -> ãƒŧ - {0xff71, 0x30a2}, // īŊą -> ã‚ĸ - {0xff72, 0x30a4}, // īŊ˛ -> イ - {0xff73, 0x30a6}, // īŊŗ -> ã‚Ļ - {0xff74, 0x30a8}, // īŊ´ -> エ - {0xff75, 0x30aa}, // īŊĩ -> ã‚Ē - {0xff76, 0x30ab}, // īŊļ -> ã‚Ģ - {0xff77, 0x30ad}, // īŊˇ -> キ - {0xff78, 0x30af}, // īŊ¸ -> ク - {0xff79, 0x30b1}, // īŊš -> ã‚ą - {0xff7a, 0x30b3}, // īŊē -> ã‚ŗ - {0xff7b, 0x30b5}, // īŊģ -> ã‚ĩ - {0xff7c, 0x30b7}, // īŊŧ -> ã‚ˇ - {0xff7d, 0x30b9}, // īŊŊ -> ã‚š - {0xff7e, 0x30bb}, // īŊž -> ã‚ģ - {0xff7f, 0x30bd}, // īŊŋ -> ã‚Ŋ - {0xff80, 0x30bf}, // īž€ -> ã‚ŋ - {0xff81, 0x30c1}, // īž -> チ - {0xff82, 0x30c4}, // īž‚ -> ツ - {0xff83, 0x30c6}, // īžƒ -> テ - {0xff84, 0x30c8}, // īž„ -> ト - {0xff85, 0x30ca}, // īž… -> ナ - {0xff86, 0x30cb}, // īž† -> ニ - {0xff87, 0x30cc}, // īž‡ -> ヌ - {0xff88, 0x30cd}, // īžˆ -> ネ - {0xff89, 0x30ce}, // īž‰ -> ノ - {0xff8a, 0x30cf}, // īžŠ -> ハ - {0xff8b, 0x30d2}, // īž‹ -> ヒ - {0xff8c, 0x30d5}, // īžŒ -> フ - {0xff8d, 0x30d8}, // īž -> ヘ - {0xff8e, 0x30db}, // īžŽ -> ホ - {0xff8f, 0x30de}, // īž -> マ - {0xff90, 0x30df}, // īž -> ミ - {0xff91, 0x30e0}, // īž‘ -> ム - {0xff92, 0x30e1}, // īž’ -> ãƒĄ - {0xff93, 0x30e2}, // īž“ -> ãƒĸ - {0xff94, 0x30e4}, // īž” -> ヤ - {0xff95, 0x30e6}, // īž• -> ãƒĻ - {0xff96, 0x30e8}, // īž– -> ヨ - {0xff97, 0x30e9}, // īž— -> ナ - {0xff98, 0x30ea}, // īž˜ -> ãƒĒ - {0xff99, 0x30eb}, // īž™ -> ãƒĢ - {0xff9a, 0x30ec}, // īžš -> ãƒŦ - {0xff9b, 0x30ed}, // īž› -> ロ - {0xff9c, 0x30ef}, // īžœ -> ワ - {0xff9d, 0x30f3}, // īž -> ãƒŗ - {0xff9e, 0x3099}, // īžž -> ゙ - {0xff9f, 0x309a}, // īžŸ -> ゚ + {{0xff65, 0x30fb}}, // īŊĨ -> ãƒģ + {{0xff66, 0x30f2}}, // īŊĻ -> ãƒ˛ + {{0xff67, 0x30a1}}, // īŊ§ -> ã‚Ą + {{0xff68, 0x30a3}}, // īŊ¨ -> ã‚Ŗ + {{0xff69, 0x30a5}}, // īŊŠ -> ã‚Ĩ + {{0xff6a, 0x30a7}}, // īŊĒ -> ェ + {{0xff6b, 0x30a9}}, // īŊĢ -> ã‚Š + {{0xff6c, 0x30e3}}, // īŊŦ -> ãƒŖ + {{0xff6d, 0x30e5}}, // īŊ­ -> ãƒĨ + {{0xff6e, 0x30e7}}, // īŊŽ -> ョ + {{0xff6f, 0x30c3}}, // īŊ¯ -> ッ + {{0xff70, 0x30fc}}, // īŊ° -> ãƒŧ + {{0xff71, 0x30a2}}, // īŊą -> ã‚ĸ + {{0xff72, 0x30a4}}, // īŊ˛ -> イ + {{0xff73, 0x30a6}}, // īŊŗ -> ã‚Ļ + {{0xff74, 0x30a8}}, // īŊ´ -> エ + {{0xff75, 0x30aa}}, // īŊĩ -> ã‚Ē + {{0xff76, 0x30ab}}, // īŊļ -> ã‚Ģ + {{0xff77, 0x30ad}}, // īŊˇ -> キ + {{0xff78, 0x30af}}, // īŊ¸ -> ク + {{0xff79, 0x30b1}}, // īŊš -> ã‚ą + {{0xff7a, 0x30b3}}, // īŊē -> ã‚ŗ + {{0xff7b, 0x30b5}}, // īŊģ -> ã‚ĩ + {{0xff7c, 0x30b7}}, // īŊŧ -> ã‚ˇ + {{0xff7d, 0x30b9}}, // īŊŊ -> ã‚š + {{0xff7e, 0x30bb}}, // īŊž -> ã‚ģ + {{0xff7f, 0x30bd}}, // īŊŋ -> ã‚Ŋ + {{0xff80, 0x30bf}}, // īž€ -> ã‚ŋ + {{0xff81, 0x30c1}}, // īž -> チ + {{0xff82, 0x30c4}}, // īž‚ -> ツ + {{0xff83, 0x30c6}}, // īžƒ -> テ + {{0xff84, 0x30c8}}, // īž„ -> ト + {{0xff85, 0x30ca}}, // īž… -> ナ + {{0xff86, 0x30cb}}, // īž† -> ニ + {{0xff87, 0x30cc}}, // īž‡ -> ヌ + {{0xff88, 0x30cd}}, // īžˆ -> ネ + {{0xff89, 0x30ce}}, // īž‰ -> ノ + {{0xff8a, 0x30cf}}, // īžŠ -> ハ + {{0xff8b, 0x30d2}}, // īž‹ -> ヒ + {{0xff8c, 0x30d5}}, // īžŒ -> フ + {{0xff8d, 0x30d8}}, // īž -> ヘ + {{0xff8e, 0x30db}}, // īžŽ -> ホ + {{0xff8f, 0x30de}}, // īž -> マ + {{0xff90, 0x30df}}, // īž -> ミ + {{0xff91, 0x30e0}}, // īž‘ -> ム + {{0xff92, 0x30e1}}, // īž’ -> ãƒĄ + {{0xff93, 0x30e2}}, // īž“ -> ãƒĸ + {{0xff94, 0x30e4}}, // īž” -> ヤ + {{0xff95, 0x30e6}}, // īž• -> ãƒĻ + {{0xff96, 0x30e8}}, // īž– -> ヨ + {{0xff97, 0x30e9}}, // īž— -> ナ + {{0xff98, 0x30ea}}, // īž˜ -> ãƒĒ + {{0xff99, 0x30eb}}, // īž™ -> ãƒĢ + {{0xff9a, 0x30ec}}, // īžš -> ãƒŦ + {{0xff9b, 0x30ed}}, // īž› -> ロ + {{0xff9c, 0x30ef}}, // īžœ -> ワ + {{0xff9d, 0x30f3}}, // īž -> ãƒŗ + {{0xff9e, 0x3099}}, // īžž -> ゙ + {{0xff9f, 0x309a}}, // īžŸ -> ゚ // Halfwidth Hangul variants - {0xffa0, 0x3164}, // īž -> ᅠ - {0xffa1, 0x3131}, // īžĄ -> ã„ą - {0xffa2, 0x3132}, // īžĸ -> ã„˛ - {0xffa3, 0x3133}, // īžŖ -> ã„ŗ - {0xffa4, 0x3134}, // īž¤ -> ㄴ - {0xffa5, 0x3135}, // īžĨ -> ã„ĩ - {0xffa6, 0x3136}, // īžĻ -> ã„ļ - {0xffa7, 0x3137}, // īž§ -> ã„ˇ - {0xffa8, 0x3138}, // īž¨ -> ㄸ - {0xffa9, 0x3139}, // īžŠ -> ã„š - {0xffaa, 0x313a}, // īžĒ -> ã„ē - {0xffab, 0x313b}, // īžĢ -> ã„ģ - {0xffac, 0x313c}, // īžŦ -> ã„ŧ - {0xffad, 0x313d}, // īž­ -> ã„Ŋ - {0xffae, 0x313e}, // īžŽ -> ã„ž - {0xffaf, 0x313f}, // īž¯ -> ã„ŋ - {0xffb0, 0x3140}, // īž° -> ㅀ - {0xffb1, 0x3141}, // īžą -> ㅁ - {0xffb2, 0x3142}, // īž˛ -> ㅂ - {0xffb3, 0x3143}, // īžŗ -> ㅃ - {0xffb4, 0x3144}, // īž´ -> ㅄ - {0xffb5, 0x3145}, // īžĩ -> ㅅ - {0xffb6, 0x3146}, // īžļ -> ㅆ - {0xffb7, 0x3147}, // īžˇ -> ㅇ - {0xffb8, 0x3148}, // īž¸ -> ㅈ - {0xffb9, 0x3149}, // īžš -> ㅉ - {0xffba, 0x314a}, // īžē -> ㅊ - {0xffbb, 0x314b}, // īžģ -> ㅋ - {0xffbc, 0x314c}, // īžŧ -> ㅌ - {0xffbd, 0x314d}, // īžŊ -> ㅍ - {0xffbe, 0x314e}, // īžž -> ㅎ - {0xffc2, 0x314f}, // īŋ‚ -> ㅏ - {0xffc3, 0x3150}, // īŋƒ -> ㅐ - {0xffc4, 0x3151}, // īŋ„ -> ㅑ - {0xffc5, 0x3152}, // īŋ… -> ㅒ - {0xffc6, 0x3153}, // īŋ† -> ㅓ - {0xffc7, 0x3154}, // īŋ‡ -> ㅔ - {0xffca, 0x3155}, // īŋŠ -> ㅕ - {0xffcb, 0x3156}, // īŋ‹ -> ㅖ - {0xffcc, 0x3157}, // īŋŒ -> ㅗ - {0xffcd, 0x3158}, // īŋ -> ㅘ - {0xffce, 0x3159}, // īŋŽ -> ㅙ - {0xffcf, 0x315a}, // īŋ -> ㅚ - {0xffd2, 0x315b}, // īŋ’ -> ㅛ - {0xffd3, 0x315c}, // īŋ“ -> ㅜ - {0xffd4, 0x315d}, // īŋ” -> ㅝ - {0xffd5, 0x315e}, // īŋ• -> ㅞ - {0xffd6, 0x315f}, // īŋ– -> ㅟ - {0xffd7, 0x3160}, // īŋ— -> ㅠ - {0xffda, 0x3161}, // īŋš -> ã…Ą - {0xffdb, 0x3162}, // īŋ› -> ã…ĸ - {0xffdc, 0x3163}, // īŋœ -> ã…Ŗ + {{0xffa0, 0x3164}}, // īž -> ᅠ + {{0xffa1, 0x3131}}, // īžĄ -> ã„ą + {{0xffa2, 0x3132}}, // īžĸ -> ã„˛ + {{0xffa3, 0x3133}}, // īžŖ -> ã„ŗ + {{0xffa4, 0x3134}}, // īž¤ -> ㄴ + {{0xffa5, 0x3135}}, // īžĨ -> ã„ĩ + {{0xffa6, 0x3136}}, // īžĻ -> ã„ļ + {{0xffa7, 0x3137}}, // īž§ -> ã„ˇ + {{0xffa8, 0x3138}}, // īž¨ -> ㄸ + {{0xffa9, 0x3139}}, // īžŠ -> ã„š + {{0xffaa, 0x313a}}, // īžĒ -> ã„ē + {{0xffab, 0x313b}}, // īžĢ -> ã„ģ + {{0xffac, 0x313c}}, // īžŦ -> ã„ŧ + {{0xffad, 0x313d}}, // īž­ -> ã„Ŋ + {{0xffae, 0x313e}}, // īžŽ -> ã„ž + {{0xffaf, 0x313f}}, // īž¯ -> ã„ŋ + {{0xffb0, 0x3140}}, // īž° -> ㅀ + {{0xffb1, 0x3141}}, // īžą -> ㅁ + {{0xffb2, 0x3142}}, // īž˛ -> ㅂ + {{0xffb3, 0x3143}}, // īžŗ -> ㅃ + {{0xffb4, 0x3144}}, // īž´ -> ㅄ + {{0xffb5, 0x3145}}, // īžĩ -> ㅅ + {{0xffb6, 0x3146}}, // īžļ -> ㅆ + {{0xffb7, 0x3147}}, // īžˇ -> ㅇ + {{0xffb8, 0x3148}}, // īž¸ -> ㅈ + {{0xffb9, 0x3149}}, // īžš -> ㅉ + {{0xffba, 0x314a}}, // īžē -> ㅊ + {{0xffbb, 0x314b}}, // īžģ -> ㅋ + {{0xffbc, 0x314c}}, // īžŧ -> ㅌ + {{0xffbd, 0x314d}}, // īžŊ -> ㅍ + {{0xffbe, 0x314e}}, // īžž -> ㅎ + {{0xffc2, 0x314f}}, // īŋ‚ -> ㅏ + {{0xffc3, 0x3150}}, // īŋƒ -> ㅐ + {{0xffc4, 0x3151}}, // īŋ„ -> ㅑ + {{0xffc5, 0x3152}}, // īŋ… -> ㅒ + {{0xffc6, 0x3153}}, // īŋ† -> ㅓ + {{0xffc7, 0x3154}}, // īŋ‡ -> ㅔ + {{0xffca, 0x3155}}, // īŋŠ -> ㅕ + {{0xffcb, 0x3156}}, // īŋ‹ -> ㅖ + {{0xffcc, 0x3157}}, // īŋŒ -> ㅗ + {{0xffcd, 0x3158}}, // īŋ -> ㅘ + {{0xffce, 0x3159}}, // īŋŽ -> ㅙ + {{0xffcf, 0x315a}}, // īŋ -> ㅚ + {{0xffd2, 0x315b}}, // īŋ’ -> ㅛ + {{0xffd3, 0x315c}}, // īŋ“ -> ㅜ + {{0xffd4, 0x315d}}, // īŋ” -> ㅝ + {{0xffd5, 0x315e}}, // īŋ• -> ㅞ + {{0xffd6, 0x315f}}, // īŋ– -> ㅟ + {{0xffd7, 0x3160}}, // īŋ— -> ㅠ + {{0xffda, 0x3161}}, // īŋš -> ã…Ą + {{0xffdb, 0x3162}}, // īŋ› -> ã…ĸ + {{0xffdc, 0x3163}}, // īŋœ -> ã…Ŗ // Fullwidth symbol variants - {0x00a2, 0xffe0}, // Âĸ -> īŋ  - {0x00a3, 0xffe1}, // ÂŖ -> īŋĄ - {0x00ac, 0xffe2}, // ÂŦ -> īŋĸ - {0x00af, 0xffe3}, // ¯ -> īŋŖ - {0x00a6, 0xffe4}, // ÂĻ -> īŋ¤ - {0x00a5, 0xffe5}, // ÂĨ -> īŋĨ - {0x20a9, 0xffe6}, // ₩ -> īŋĻ + {{0x00a2, 0xffe0}}, // Âĸ -> īŋ  + {{0x00a3, 0xffe1}}, // ÂŖ -> īŋĄ + {{0x00ac, 0xffe2}}, // ÂŦ -> īŋĸ + {{0x00af, 0xffe3}}, // ¯ -> īŋŖ + {{0x00a6, 0xffe4}}, // ÂĻ -> īŋ¤ + {{0x00a5, 0xffe5}}, // ÂĨ -> īŋĨ + {{0x20a9, 0xffe6}}, // ₩ -> īŋĻ // Halfwidth symbol variants - {0xffe8, 0x2502}, // īŋ¨ -> │ - {0xffe9, 0x2190}, // īŋŠ -> ← - {0xffea, 0x2191}, // īŋĒ -> ↑ - {0xffeb, 0x2192}, // īŋĢ -> → - {0xffec, 0x2193}, // īŋŦ -> ↓ - {0xffed, 0x25a0}, // īŋ­ -> ■ - {0xffee, 0x25cb} // īŋŽ -> ○ -}; - -const std::size_t lastHalfWidthItem = \ - std::size_t((sizeof(halfWidth_fullWidth) / sizeof(halfWidth_fullWidth[0])) - 1); + {{0xffe8, 0x2502}}, // īŋ¨ -> │ + {{0xffe9, 0x2190}}, // īŋŠ -> ← + {{0xffea, 0x2191}}, // īŋĒ -> ↑ + {{0xffeb, 0x2192}}, // īŋĢ -> → + {{0xffec, 0x2193}}, // īŋŦ -> ↓ + {{0xffed, 0x25a0}}, // īŋ­ -> ■ + {{0xffee, 0x25cb}} // īŋŽ -> ○ +}}; } // namespace fc diff --git a/src/fcombobox.cpp b/src/fcombobox.cpp index 3d16be66..8ee8ca44 100644 --- a/src/fcombobox.cpp +++ b/src/fcombobox.cpp @@ -29,7 +29,6 @@ #include "final/flabel.h" #include "final/flineedit.h" #include "final/flistbox.h" -#include "final/flog.h" #include "final/fmouse.h" #include "final/fpoint.h" #include "final/fsize.h" diff --git a/src/fdata.cpp b/src/fdata.cpp new file mode 100644 index 00000000..f39345d9 --- /dev/null +++ b/src/fdata.cpp @@ -0,0 +1,42 @@ +/*********************************************************************** +* fdata.cpp - A general-purpose data wrapper * +* * +* This file is part of the FINAL CUT widget toolkit * +* * +* Copyright 2020 Markus Gans * +* * +* FINAL CUT 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 3 of * +* the License, or (at your option) any later version. * +* * +* FINAL CUT 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 Lesser General Public License for more details. * +* * +* You should have received a copy of the GNU Lesser General Public * +* License along with this program. If not, see * +* . * +***********************************************************************/ + +#include "final/fdata.h" + +namespace finalcut +{ + +//---------------------------------------------------------------------- +// class FDataAccess +//---------------------------------------------------------------------- + +// constructors and destructor +//---------------------------------------------------------------------- +FDataAccess::FDataAccess() +{ } + +//---------------------------------------------------------------------- +FDataAccess::~FDataAccess() // destructor +{ } + +} // namespace finalcut + diff --git a/src/fdialog.cpp b/src/fdialog.cpp index d87708cb..b4c6be82 100644 --- a/src/fdialog.cpp +++ b/src/fdialog.cpp @@ -226,8 +226,8 @@ void FDialog::setPos (const FPoint& pos, bool) if ( getTermGeometry().overlap(old_geometry) ) { FRect restore{}; - const std::size_t d_width = std::size_t(std::abs(dx)); - const std::size_t d_height = std::size_t(std::abs(dy)); + const auto d_width = std::size_t(std::abs(dx)); + const auto d_height = std::size_t(std::abs(dy)); // dx > 0 : move left // dx = 0 : move vertical @@ -282,7 +282,16 @@ void FDialog::move (const FPoint& d_pos) //---------------------------------------------------------------------- inline bool FDialog::moveUp (int n) { - move ({0, -n}); + if ( isBottomOutside() ) + { + const auto y_max = int(getMaxHeight()); + FWindow::setY(y_max, false); + putArea (getTermPos(), getVWin()); + restoreOverlaidWindows(); + } + else + move ({0, -n}); + return ! setPos_error; } @@ -296,7 +305,16 @@ inline bool FDialog::moveDown (int n) //---------------------------------------------------------------------- inline bool FDialog::moveLeft (int n) { - move ({-n, 0}); + if ( isLeftOutside() ) + { + const auto x_max = int(getMaxWidth()); + FWindow::setX(x_max, false); + putArea (getTermPos(), getVWin()); + restoreOverlaidWindows(); + } + else + move ({-n, 0}); + return ! setPos_error; } @@ -323,7 +341,7 @@ void FDialog::setSize (const FSize& size, bool adjust) const int dw = int(getWidth()) - int(size.getWidth()); const int dh = int(getHeight()) - int(size.getHeight()); const auto& shadow = getShadow(); - FWindow::setSize (size, adjust); + FWindow::setSize (size, false); // get adjust width and height const std::size_t w = getWidth() + shadow.getWidth(); @@ -336,8 +354,8 @@ void FDialog::setSize (const FSize& size, bool adjust) // dh = 0 : scale only width // dh < 0 : scale up height - const std::size_t d_width = std::size_t(dw); - const std::size_t d_height = std::size_t(dh); + const auto d_width = std::size_t(dw); + const auto d_height = std::size_t(dh); // restoring the non-covered terminal areas if ( dw > 0 ) @@ -346,6 +364,9 @@ void FDialog::setSize (const FSize& size, bool adjust) if ( dh > 0 ) restoreVTerm ({x, y + int(h), w + d_width, d_height}); // restore bottom + if ( adjust ) // Adjust the size after restoreVTerm(), + adjustSize(); // because adjustSize() can also change x and y + redraw(); // handle overlaid windows @@ -438,8 +459,9 @@ void FDialog::onKeyPress (FKeyEvent* ev) cancelMouseResize(); - if ( ev->key() == fc::Fckey_caret // Ctrl+^ (Ctrl+6) - || ev->key() == fc::Fkey_f22 ) // Shift+F10 + if ( ev->key() == fc::Fckey_caret // Ctrl+^ (Ctrl+6) + || ev->key() == fc::Fkey_f22 // Shift+F10 + || ev->key() == fc::Fkey_smenu ) // Shift+Menu { ev->accept(); // open the titlebar menu @@ -455,8 +477,9 @@ void FDialog::onKeyPress (FKeyEvent* ev) if ( this == getMainWidget() ) return; - if ( ev->key() == fc::Fkey_escape - || ev->key() == fc::Fkey_escape_mintty ) + if ( ! ev->isAccepted() + && ( ev->key() == fc::Fkey_escape + || ev->key() == fc::Fkey_escape_mintty) ) { ev->accept(); @@ -470,9 +493,9 @@ void FDialog::onKeyPress (FKeyEvent* ev) //---------------------------------------------------------------------- void FDialog::onMouseDown (FMouseEvent* ev) { - const int width = int(getWidth()); + const auto width = int(getWidth()); - const mouseStates ms = + const MouseStates ms = { ev->getX(), ev->getY(), @@ -531,7 +554,7 @@ void FDialog::onMouseDown (FMouseEvent* ev) //---------------------------------------------------------------------- void FDialog::onMouseUp (FMouseEvent* ev) { - const mouseStates ms = + const MouseStates ms = { ev->getX(), ev->getY(), @@ -580,7 +603,7 @@ void FDialog::onMouseUp (FMouseEvent* ev) //---------------------------------------------------------------------- void FDialog::onMouseMove (FMouseEvent* ev) { - const mouseStates ms = + const MouseStates ms = { ev->getX(), ev->getY(), @@ -610,7 +633,7 @@ void FDialog::onMouseMove (FMouseEvent* ev) //---------------------------------------------------------------------- void FDialog::onMouseDoubleClick (FMouseEvent* ev) { - const mouseStates ms = + const MouseStates ms = { ev->getX(), ev->getY(), @@ -1069,13 +1092,13 @@ inline void FDialog::drawRestoreSizeButton() if ( FTerm::isMonochron() ) { print ('['); - print (fc::BlackDownPointingTriangle); // â–ŧ + print (fc::BlackDiamondSuit); // ◆ print (']'); } else { print (' '); - print (fc::BlackDownPointingTriangle); // â–ŧ + print (fc::BlackDiamondSuit); // ◆ print (' '); } } @@ -1295,7 +1318,7 @@ inline void FDialog::deactivateZoomButton() } //---------------------------------------------------------------------- -inline void FDialog::activateZoomButton (const mouseStates& ms) +inline void FDialog::activateZoomButton (const MouseStates& ms) { if ( ms.mouse_x <= int(getWidth() - ms.zoom_btn) || ms.mouse_y != 1 ) @@ -1307,7 +1330,7 @@ inline void FDialog::activateZoomButton (const mouseStates& ms) } //---------------------------------------------------------------------- -inline void FDialog::leaveZoomButton (const mouseStates& ms) +inline void FDialog::leaveZoomButton (const MouseStates& ms) { bool zoom_button_pressed_before = zoom_button_pressed; @@ -1324,7 +1347,7 @@ inline void FDialog::leaveZoomButton (const mouseStates& ms) } //---------------------------------------------------------------------- -void FDialog::pressZoomButton (const mouseStates& ms) +void FDialog::pressZoomButton (const MouseStates& ms) { if ( ms.mouse_x <= int(getWidth() - ms.zoom_btn) || ms.mouse_y != 1 @@ -1348,7 +1371,7 @@ inline bool FDialog::isMouseOverMenu (const FPoint& termpos) const } //---------------------------------------------------------------------- -inline void FDialog::passEventToSubMenu ( const mouseStates& ms +inline void FDialog::passEventToSubMenu ( const MouseStates& ms , const FMouseEvent* ev ) { // Mouse event handover to the dialog menu @@ -1382,48 +1405,58 @@ inline void FDialog::moveSizeKey (FKeyEvent* ev) { case fc::Fkey_up: moveUp(1); + ev->accept(); break; case fc::Fkey_down: moveDown(1); + ev->accept(); break; case fc::Fkey_left: moveLeft(1); + ev->accept(); break; case fc::Fkey_right: moveRight(1); + ev->accept(); break; case fc::Fmkey_up: case fc::Fkey_sr: reduceHeight(1); + ev->accept(); break; case fc::Fmkey_down: case fc::Fkey_sf: expandHeight(1); + ev->accept(); break; case fc::Fmkey_left: case fc::Fkey_sleft: reduceWidth(1); + ev->accept(); break; case fc::Fmkey_right: case fc::Fkey_sright: expandWidth(1); + ev->accept(); break; case fc::Fkey_return: case fc::Fkey_enter: acceptMoveSize(); + ev->accept(); break; case fc::Fkey_escape: case fc::Fkey_escape_mintty: cancelMoveSize(); + ev->accept(); return; default: @@ -1468,7 +1501,25 @@ bool FDialog::isOutsideTerminal (const FPoint& pos) const } //---------------------------------------------------------------------- -bool FDialog::isLowerRightResizeCorner (const mouseStates& ms) const +bool FDialog::isLeftOutside() const +{ + if ( getX() > int(getMaxWidth()) ) + return true; + + return false; +} + +//---------------------------------------------------------------------- +bool FDialog::isBottomOutside() const +{ + if ( getY() > int(getMaxHeight()) ) + return true; + + return false; +} + +//---------------------------------------------------------------------- +bool FDialog::isLowerRightResizeCorner (const MouseStates& ms) const { // 3 characters in the lower right corner | // x @@ -1487,7 +1538,7 @@ bool FDialog::isLowerRightResizeCorner (const mouseStates& ms) const } //---------------------------------------------------------------------- -void FDialog::resizeMouseDown (const mouseStates& ms) +void FDialog::resizeMouseDown (const MouseStates& ms) { // Click on the lower right resize corner @@ -1512,7 +1563,7 @@ void FDialog::resizeMouseDown (const mouseStates& ms) } //---------------------------------------------------------------------- -void FDialog::resizeMouseUpMove (const mouseStates& ms, bool mouse_up) +void FDialog::resizeMouseUpMove (const MouseStates& ms, bool mouse_up) { // Resize the dialog if ( isResizeable() && ! resize_click_pos.isOrigin() ) diff --git a/src/fevent.cpp b/src/fevent.cpp index d9d1468f..e3885c76 100644 --- a/src/fevent.cpp +++ b/src/fevent.cpp @@ -21,7 +21,6 @@ ***********************************************************************/ #include - #include "final/fevent.h" namespace finalcut @@ -372,12 +371,4 @@ FUserEvent::~FUserEvent() // destructor int FUserEvent::getUserId() const { return uid; } -//---------------------------------------------------------------------- -FDataPtr FUserEvent::getData() const -{ return data_pointer; } - -//---------------------------------------------------------------------- -void FUserEvent::setData (FDataPtr data) -{ data_pointer = data; } - } // namespace finalcut diff --git a/src/ffiledialog.cpp b/src/ffiledialog.cpp index 66a4c70f..5b456fae 100644 --- a/src/ffiledialog.cpp +++ b/src/ffiledialog.cpp @@ -25,6 +25,7 @@ #include // need for strcasecmp #endif +#include #include #include "final/fevent.h" @@ -55,10 +56,10 @@ bool sortDirFirst ( const FFileDialog::FDirEntry& lhs } //---------------------------------------------------------------------- -const FString fileChooser ( FWidget* parent - , const FString& dirname - , const FString& filter - , FFileDialog::DialogType type ) +FString fileChooser ( FWidget* parent + , const FString& dirname + , const FString& filter + , FFileDialog::DialogType type ) { FString ret{}; FString path{dirname}; @@ -165,9 +166,9 @@ FFileDialog& FFileDialog::operator = (const FFileDialog& fdlg) } //---------------------------------------------------------------------- -const FString FFileDialog::getSelectedFile() const +FString FFileDialog::getSelectedFile() const { - const uLong n = uLong(filebrowser.currentItem() - 1); + const auto n = uLong(filebrowser.currentItem() - 1); if ( dir_entries[n].directory ) return FString{""}; @@ -179,7 +180,7 @@ const FString FFileDialog::getSelectedFile() const void FFileDialog::setPath (const FString& dir) { const char* const dirname = dir.c_str(); - char resolved_path[MAXPATHLEN]{}; + std::array resolved_path{}; FString r_dir{}; struct stat sb{}; @@ -201,8 +202,8 @@ void FFileDialog::setPath (const FString& dir) return; } - if ( fsystem && fsystem->realpath(dir.c_str(), resolved_path) != nullptr ) - r_dir.setString(resolved_path); + if ( fsystem && fsystem->realpath(dir.c_str(), resolved_path.data()) != nullptr ) + r_dir.setString(resolved_path.data()); else r_dir.setString(dir); @@ -257,17 +258,17 @@ void FFileDialog::onKeyPress (FKeyEvent* ev) } //---------------------------------------------------------------------- -const FString FFileDialog::fileOpenChooser ( FWidget* parent - , const FString& dirname - , const FString& filter ) +FString FFileDialog::fileOpenChooser ( FWidget* parent + , const FString& dirname + , const FString& filter ) { return fileChooser (parent, dirname, filter, FFileDialog::Open); } //---------------------------------------------------------------------- -const FString FFileDialog::fileSaveChooser ( FWidget* parent - , const FString& dirname - , const FString& filter ) +FString FFileDialog::fileSaveChooser ( FWidget* parent + , const FString& dirname + , const FString& filter ) { return fileChooser (parent, dirname, filter, FFileDialog::Save); } @@ -418,20 +419,20 @@ void FFileDialog::initCallbacks() inline bool FFileDialog::patternMatch ( const char* const pattern , const char fname[] ) const { - char search[128]{}; + std::array search{}; if ( show_hidden && fname[0] == '.' && fname[1] != '\0' ) // hidden files { search[0] = '.'; search[1] = '\0'; - std::strncat(search, pattern, sizeof(search) - std::strlen(search) - 1); + std::strncat(search.data(), pattern, search.size() - std::strlen(search.data()) - 1); } else - std::strncpy(search, pattern, sizeof(search)); + std::strncpy(search.data(), pattern, search.size() - 1); - search[sizeof(search) - 1] = '\0'; + search[search.size() - 1] = '\0'; - if ( fnmatch (search, fname, FNM_PERIOD) == 0 ) + if ( fnmatch (search.data(), fname, FNM_PERIOD) == 0 ) return true; else return false; @@ -595,24 +596,24 @@ void FFileDialog::followSymLink (const char* const dir, FDirEntry& entry) const if ( ! entry.symbolic_link ) return; // No symbolic link - char resolved_path[MAXPATHLEN]{}; - char symLink[MAXPATHLEN]{}; + std::array resolved_path{}; + std::array symLink{}; struct stat sb{}; if ( ! fsystem ) fsystem = FTerm::getFSystem(); - std::strncpy (symLink, dir, sizeof(symLink)); - symLink[sizeof(symLink) - 1] = '\0'; - std::strncat ( symLink + std::strncpy (symLink.data(), dir, symLink.size() - 1); + symLink[symLink.size() - 1] = '\0'; + std::strncat ( symLink.data() , entry.name.c_str() - , sizeof(symLink) - std::strlen(symLink) - 1); - symLink[sizeof(symLink) - 1] = '\0'; + , symLink.size() - std::strlen(symLink.data()) - 1); + symLink[symLink.size() - 1] = '\0'; - if ( fsystem->realpath(symLink, resolved_path) == nullptr ) + if ( fsystem->realpath(symLink.data(), resolved_path.data()) == nullptr ) return; // Cannot follow the symlink - if ( lstat(resolved_path, &sb) == -1 ) + if ( lstat(resolved_path.data(), &sb) == -1 ) return; // Cannot get file status if ( S_ISDIR(sb.st_mode) ) @@ -736,18 +737,18 @@ void FFileDialog::printPath (const FString& txt) } //---------------------------------------------------------------------- -const FString FFileDialog::getHomeDir() +FString FFileDialog::getHomeDir() { struct passwd pwd{}; struct passwd* pwd_ptr{}; - char buf[1024]{}; + std::array buf{}; if ( ! fsystem ) fsystem = FTerm::getFSystem(); const uid_t euid = fsystem->geteuid(); - if ( fsystem->getpwuid_r(euid, &pwd, buf, sizeof(buf), &pwd_ptr) ) + if ( fsystem->getpwuid_r(euid, &pwd, buf.data(), buf.size(), &pwd_ptr) ) return FString{""}; else return FString{pwd.pw_dir}; @@ -823,7 +824,7 @@ void FFileDialog::cb_processRowChanged() //---------------------------------------------------------------------- void FFileDialog::cb_processClicked() { - const uLong n = uLong(filebrowser.currentItem() - 1); + const auto n = uLong(filebrowser.currentItem() - 1); if ( dir_entries[n].directory ) changeDir(dir_entries[n].name); diff --git a/src/fkey_map.cpp b/src/fkey_map.cpp index 95a291f0..14e06150 100644 --- a/src/fkey_map.cpp +++ b/src/fkey_map.cpp @@ -20,9 +20,10 @@ * . * ***********************************************************************/ +#include + #include "final/fc.h" #include "final/fkey_map.h" -#include "final/ftypes.h" namespace finalcut { @@ -30,14 +31,13 @@ namespace finalcut namespace fc { -FKeyMap fkey[] = -{ +std::array fkey +{{ { fc::Fkey_backspace , nullptr, "kb" }, // backspace key { fc::Fkey_catab , nullptr, "ka" }, // clear-all-tabs key { fc::Fkey_clear , nullptr, "kC" }, // clear-screen or erase key { fc::Fkey_ctab , nullptr, "kt" }, // clear-tab key { fc::Fkey_dc , nullptr, "kD" }, // delete-character key - { fc::Fkey_dc , nullptr, "kDx"}, // keypad delete { fc::Fkey_dl , nullptr, "kL" }, // delete-line key { fc::Fkey_down , nullptr, "kd" }, // down-arrow key { fc::Fkey_eic , nullptr, "kM" }, // sent by rmir or smir in insert mode @@ -184,38 +184,52 @@ FKeyMap fkey[] = { fc::Fkey_f63 , nullptr, "Fr" }, // F63 function key // Some terminals (e.g. PuTTY) send vt100 key codes // when the arrow and function keys are pressed - { fc::Fkey_down , CSI "B", "kdx"}, // down-arrow key (standard mode) - { fc::Fkey_down , ESC "OB", "kdX"}, // down-arrow key (application mode) - { fc::Fkey_f1 , ESC "OP", "k1X"}, // PF1 (application mode) - { fc::Fkey_f2 , ESC "OQ", "k2X"}, // PF2 (application mode) - { fc::Fkey_f3 , ESC "OR", "k3X"}, // PF3 (application mode) - { fc::Fkey_f4 , ESC "OS", "k4X"}, // PF4 (application mode) + { fc::Fkey_f1 , ESC "OP", "k1x"}, // PF1 (application mode) + { fc::Fkey_f2 , ESC "OQ", "k2x"}, // PF2 (application mode) + { fc::Fkey_f3 , ESC "OR", "k3x"}, // PF3 (application mode) + { fc::Fkey_f4 , ESC "OS", "k4x"}, // PF4 (application mode) { fc::Fkey_left , CSI "D", "klx"}, // left-arrow key (standard mode) { fc::Fkey_left , ESC "OD", "klX"}, // left-arrow key (application mode) { fc::Fkey_right , CSI "C", "krx"}, // right-arrow key (standard mode) { fc::Fkey_right , ESC "OC", "krX"}, // right-arrow key (application mode) { fc::Fkey_up , CSI "A", "kux"}, // up-arrow key (standard mode) { fc::Fkey_up , ESC "OA", "kuX"}, // up-arrow key (application mode) + { fc::Fkey_down , CSI "B", "kdx"}, // down-arrow key (standard mode) + { fc::Fkey_down , ESC "OB", "kdX"}, // down-arrow key (application mode) + { fc::Fkey_sf , CSI "a", "kFx"}, // scroll-forward key (shift-up) + { fc::Fkey_sr , CSI "b", "kRx"}, // scroll-backward key (shift-down) // Fallback for rxvt with TERM=xterm { fc::Fkey_home , CSI "7~", "khx"}, // home key { fc::Fkey_end , CSI "8~", "@7x"}, // end key - { fc::Fkey_f1 , CSI "11~", "k1x"}, // F1 function key - { fc::Fkey_f2 , CSI "12~", "k2x"}, // F2 function key - { fc::Fkey_f3 , CSI "13~", "k3x"}, // F3 function key - { fc::Fkey_f4 , CSI "14~", "k4x"}, // F4 function key + { fc::Fkey_f1 , CSI "11~", "k1X"}, // F1 function key + { fc::Fkey_f2 , CSI "12~", "k2X"}, // F2 function key + { fc::Fkey_f3 , CSI "13~", "k3X"}, // F3 function key + { fc::Fkey_f4 , CSI "14~", "k4X"}, // F4 function key // Fallback for TERM=ansi - { fc::Fkey_end , CSI "K", "@7X"}, // end key + { fc::Fkey_home , CSI "H", "khX"}, // home key + { fc::Fkey_end , CSI "F", "@7X"}, // end key + { fc::Fkey_end , CSI "K", "@7y"}, // end key (Microsoft HyperTerminal) // Keypad keys { fc::Fkey_enter , ESC "OM", "@8x"}, // enter key { fc::Fkey_slash , ESC "Oo", "KP1"}, // keypad slash { fc::Fkey_asterisk , ESC "Oj", "KP2"}, // keypad asterisk { fc::Fkey_minus_sign, ESC "Om", "KP3"}, // keypad minus sign { fc::Fkey_plus_sign , ESC "Ok", "KP4"}, // keypad plus sign - { 0 , nullptr, "\0" } -}; + { fc::Fkey_ic , ESC "Op", "kIx"}, // keypad insert + { fc::Fkey_dc , ESC "On", "kDx"}, // keypad delete + { fc::Fkey_left , ESC "Ot", "kly"}, // keypad left-arrow + { fc::Fkey_right , ESC "Ov", "kry"}, // keypad right-arrow + { fc::Fkey_up , ESC "Ox", "kuy"}, // keypad up-arrow + { fc::Fkey_down , ESC "Or", "kdy"}, // keypad down-arrow + { fc::Fkey_a1 , ESC "Ow", "K1x"}, // keypad upper left + { fc::Fkey_a3 , ESC "Oy", "K3x"}, // keypad upper right + { fc::Fkey_b2 , ESC "Ou", "K2x"}, // keypad center + { fc::Fkey_c1 , ESC "Oq", "K4x"}, // keypad lower left + { fc::Fkey_c3 , ESC "Os", "K5x"} // keypad lower right +}}; -FMetakeyMap fmetakey[] = -{ +constexpr std::array fmetakey = +{{ { fc::Fmkey_ic , "\033[2;3~" }, // M-insert { fc::Fmkey_ic , "\033\033[2~" }, // M-insert { fc::Fmkey_dc , "\033[3;3~" }, // M-delete @@ -289,9 +303,13 @@ FMetakeyMap fmetakey[] = { fc::Fckey_ppage , "\033[5;5~" }, // ctrl-prev-page { fc::Fckey_npage , "\033[6;5~" }, // ctrl-next-page { fc::Fckey_up , "\033[1;5A" }, // ctrl-up + { fc::Fckey_up , "\033Oa" }, // ctrl-up { fc::Fckey_down , "\033[1;5B" }, // ctrl-down + { fc::Fckey_down , "\033Ob" }, // ctrl-down { fc::Fckey_right , "\033[1;5C" }, // ctrl-right + { fc::Fckey_right , "\033Oc" }, // ctrl-right { fc::Fckey_left , "\033[1;5D" }, // ctrl-left + { fc::Fckey_left , "\033Od" }, // ctrl-left { fc::Fckey_sic , "\033[2;6~" }, // shift-ctrl-M-insert { fc::Fckey_sdc , "\033[3;6~" }, // shift-ctrl-M-delete { fc::Fckey_shome , "\033[1;6H" }, // shift-ctrl-M-home @@ -443,12 +461,11 @@ FMetakeyMap fmetakey[] = { fc::Fmkey_left_curly_bracket , "\033{" }, // M-{ { fc::Fmkey_vertical_bar , "\033|" }, // M-| { fc::Fmkey_right_curly_bracket , "\033}" }, // M-} - { fc::Fmkey_tilde , "\033~" }, // M-~ - { 0 , "\0" } -}; + { fc::Fmkey_tilde , "\033~" } // M-~ +}}; -FKeyName fkeyname[] = -{ +constexpr std::array fkeyname = +{{ { fc::Fckey_a , "Ctrl+A" }, { fc::Fckey_b , "Ctrl+B" }, { fc::Fckey_c , "Ctrl+C" }, @@ -836,9 +853,8 @@ FKeyName fkeyname[] = { fc::Fkey_mouse , "xterm mouse" }, { fc::Fkey_extended_mouse , "SGR extended mouse" }, { fc::Fkey_urxvt_mouse , "urxvt mouse extension" }, - { fc::Fkey_incomplete , "incomplete key string" }, - { 0 , "\0" } -}; + { fc::Fkey_incomplete , "incomplete key string" } +}}; } // namespace fc diff --git a/src/fkeyboard.cpp b/src/fkeyboard.cpp index d7ea5801..f0d9d2db 100644 --- a/src/fkeyboard.cpp +++ b/src/fkeyboard.cpp @@ -26,6 +26,8 @@ #include // need for FD_ZERO, FD_SET, FD_CLR, ... #endif +#include +#include #include #include "final/fkeyboard.h" @@ -86,11 +88,20 @@ void FKeyboard::fetchKeyCode() } //---------------------------------------------------------------------- -const FString FKeyboard::getKeyName (const FKey keynum) const +FString FKeyboard::getKeyName (const FKey keynum) const { - for (std::size_t i{0}; fc::fkeyname[i].string[0] != 0; i++) - if ( fc::fkeyname[i].num && fc::fkeyname[i].num == keynum ) - return FString{fc::fkeyname[i].string}; + const auto& found_key = std::find_if + ( + fc::fkeyname.begin(), + fc::fkeyname.end(), + [&keynum] (const fc::FKeyName& kn) + { + return (kn.num > 0 && kn.num == keynum); + } + ); + + if ( found_key != fc::fkeyname.end() ) + return FString{found_key->string}; if ( keynum > 32 && keynum < 127 ) return FString{char(keynum)}; @@ -99,9 +110,27 @@ const FString FKeyboard::getKeyName (const FKey keynum) const } //---------------------------------------------------------------------- -void FKeyboard::setTermcapMap (fc::FKeyMap* keymap) +bool FKeyboard::setNonBlockingInput (bool enable) { - key_map = keymap; + if ( enable == non_blocking_stdin ) + return non_blocking_stdin; + + if ( enable ) // make stdin non-blocking + { + stdin_status_flags |= O_NONBLOCK; + + if ( fcntl (FTermios::getStdIn(), F_SETFL, stdin_status_flags) != -1 ) + non_blocking_stdin = true; + } + else + { + stdin_status_flags &= ~O_NONBLOCK; + + if ( fcntl (FTermios::getStdIn(), F_SETFL, stdin_status_flags) != -1 ) + non_blocking_stdin = false; + } + + return non_blocking_stdin; } //---------------------------------------------------------------------- @@ -221,12 +250,12 @@ inline FKey FKeyboard::getTermcapKey() assert ( FIFO_BUF_SIZE > 0 ); - if ( ! key_map ) + if ( key_map.use_count() == 0 ) return NOT_SET; - for (std::size_t i{0}; key_map[i].tname[0] != 0; i++) + for (auto&& entry : *key_map) { - const char* k = key_map[i].string; + const char* k = entry.string; const std::size_t len = ( k ) ? std::strlen(k) : 0; if ( k && std::strncmp(k, fifo_buf, len) == 0 ) // found @@ -240,7 +269,7 @@ inline FKey FKeyboard::getTermcapKey() fifo_buf[n] = '\0'; input_data_pending = bool(fifo_buf[0] != '\0'); - return fc::fkey[i].num; + return entry.num; } } @@ -254,9 +283,9 @@ inline FKey FKeyboard::getMetaKey() assert ( FIFO_BUF_SIZE > 0 ); - for (std::size_t i{0}; fc::fmetakey[i].string[0] != 0; i++) + for (auto&& entry : fc::fmetakey) { - const char* kmeta = fc::fmetakey[i].string; // The string is never null + const char* kmeta = entry.string; // The string is never null const std::size_t len = std::strlen(kmeta); if ( std::strncmp(kmeta, fifo_buf, len) == 0 ) // found @@ -279,7 +308,7 @@ inline FKey FKeyboard::getMetaKey() fifo_buf[n] = '\0'; input_data_pending = bool(fifo_buf[0] != '\0'); - return fc::fmetakey[i].num; + return entry.num; } } @@ -293,13 +322,13 @@ inline FKey FKeyboard::getSingleKey() std::size_t n{}; std::size_t len{1}; - const uChar firstchar = uChar(fifo_buf[0]); + const auto firstchar = uChar(fifo_buf[0]); FKey keycode{}; // Look for a utf-8 character if ( utf8_input && (firstchar & 0xc0) == 0xc0 ) { - char utf8char[5]{}; // Init array with '\0' + std::array utf8char{}; // Init array with '\0' const std::size_t buf_len = std::strlen(fifo_buf); if ( (firstchar & 0xe0) == 0xc0 ) @@ -315,7 +344,7 @@ inline FKey FKeyboard::getSingleKey() for (std::size_t i{0}; i < len ; i++) utf8char[i] = char(fifo_buf[i] & 0xff); - keycode = UTF8decode(utf8char); + keycode = UTF8decode(utf8char.data()); } else keycode = uChar(fifo_buf[0] & 0xff); @@ -334,30 +363,6 @@ inline FKey FKeyboard::getSingleKey() return FKey(keycode == 127 ? fc::Fkey_backspace : keycode); } -//---------------------------------------------------------------------- -bool FKeyboard::setNonBlockingInput (bool enable) -{ - if ( enable == non_blocking_stdin ) - return non_blocking_stdin; - - if ( enable ) // make stdin non-blocking - { - stdin_status_flags |= O_NONBLOCK; - - if ( fcntl (FTermios::getStdIn(), F_SETFL, stdin_status_flags) != -1 ) - non_blocking_stdin = true; - } - else - { - stdin_status_flags &= ~O_NONBLOCK; - - if ( fcntl (FTermios::getStdIn(), F_SETFL, stdin_status_flags) != -1 ) - non_blocking_stdin = false; - } - - return non_blocking_stdin; -} - //---------------------------------------------------------------------- inline bool FKeyboard::isKeypressTimeout() { @@ -382,7 +387,7 @@ FKey FKeyboard::UTF8decode (const char utf8[]) const for (std::size_t i{0}; i < len; ++i) { - const uChar ch = uChar(utf8[i]); + const auto ch = uChar(utf8[i]); if ( (ch & 0xc0) == 0x80 ) { @@ -475,7 +480,7 @@ void FKeyboard::parseKeyBuffer() //---------------------------------------------------------------------- FKey FKeyboard::parseKeyString() { - const uChar firstchar = uChar(fifo_buf[0]); + const auto firstchar = uChar(fifo_buf[0]); if ( firstchar == ESC[0] ) { diff --git a/src/flineedit.cpp b/src/flineedit.cpp index 317b784e..47ac36cf 100644 --- a/src/flineedit.cpp +++ b/src/flineedit.cpp @@ -20,13 +20,14 @@ * . * ***********************************************************************/ +#include #include #include "final/fapplication.h" #include "final/fevent.h" #include "final/flabel.h" -#include "final/flog.h" #include "final/flineedit.h" +#include "final/flog.h" #include "final/fpoint.h" #include "final/fsize.h" #include "final/fstatusbar.h" @@ -752,9 +753,9 @@ void FLineEdit::drawInputField() // set the cursor to the insert pos. const auto cursor_pos_column = getCursorColumnPos(); - const int xpos = int(2 + cursor_pos_column - - text_offset_column - + char_width_offset); + const auto xpos = int(2 + cursor_pos_column + - text_offset_column + + char_width_offset); setCursorPos ({xpos, 1}); } @@ -802,7 +803,7 @@ inline std::size_t FLineEdit::getCursorColumnPos() const } //---------------------------------------------------------------------- -inline const FString FLineEdit::getPasswordText() const +inline FString FLineEdit::getPasswordText() const { return FString{text.getLength(), fc::Bullet}; // â€ĸ } @@ -833,8 +834,8 @@ inline FLineEdit::offsetPair FLineEdit::endPosToOffset (std::size_t pos) } catch (const std::out_of_range& ex) { - *FApplication::getLog() << FLog::Error - << "Out of Range error: " << ex.what() << std::endl; + std::clog << FLog::Error + << "Out of Range error: " << ex.what() << std::endl; } if ( input_width >= char_width ) @@ -857,8 +858,8 @@ inline FLineEdit::offsetPair FLineEdit::endPosToOffset (std::size_t pos) } catch (const std::out_of_range& ex) { - *FApplication::getLog() << FLog::Error - << "Out of Range error: " << ex.what() << std::endl; + std::clog << FLog::Error + << "Out of Range error: " << ex.what() << std::endl; } } @@ -893,8 +894,8 @@ std::size_t FLineEdit::clickPosToCursorPos (std::size_t pos) } catch (const std::out_of_range& ex) { - *FApplication::getLog() << FLog::Error - << "Out of Range error: " << ex.what() << std::endl; + std::clog << FLog::Error + << "Out of Range error: " << ex.what() << std::endl; } idx++; @@ -927,8 +928,8 @@ void FLineEdit::adjustTextOffset() } catch (const std::out_of_range& ex) { - *FApplication::getLog() << FLog::Error - << "Out of Range error: " << ex.what() << std::endl; + std::clog << FLog::Error + << "Out of Range error: " << ex.what() << std::endl; } } @@ -940,8 +941,8 @@ void FLineEdit::adjustTextOffset() } catch (const std::out_of_range& ex) { - *FApplication::getLog() << FLog::Error - << "Out of Range error: " << ex.what() << std::endl; + std::clog << FLog::Error + << "Out of Range error: " << ex.what() << std::endl; } } @@ -1109,9 +1110,9 @@ inline wchar_t FLineEdit::characterFilter (const wchar_t c) const if ( input_filter.empty() ) return c; - const wchar_t character[2]{c, L'\0'}; + std::array character{{c, L'\0'}}; - if ( regex_match(character, std::wregex(input_filter)) ) + if ( regex_match(character.data(), std::wregex(input_filter)) ) return c; else return L'\0'; diff --git a/src/flistbox.cpp b/src/flistbox.cpp index 163f03ba..c3eb068a 100644 --- a/src/flistbox.cpp +++ b/src/flistbox.cpp @@ -51,12 +51,6 @@ FListBoxItem::FListBoxItem (const FListBoxItem& item) , selected{item.selected} { } -//---------------------------------------------------------------------- -FListBoxItem::FListBoxItem (const FString& txt, FDataPtr data) - : text{txt} - , data_pointer{data} -{ } - //---------------------------------------------------------------------- FListBoxItem::~FListBoxItem() // destructor { } @@ -95,6 +89,9 @@ FListBox::FListBox (FWidget* parent) //---------------------------------------------------------------------- FListBox::~FListBox() // destructor { + if ( source_container ) + delete source_container; // for lazy conversion + delOwnTimers(); } @@ -123,7 +120,7 @@ void FListBox::setCurrentItem (std::size_t index) } //---------------------------------------------------------------------- -void FListBox::setCurrentItem (listBoxItems::iterator iter) +void FListBox::setCurrentItem (FListBoxItems::iterator iter) { const auto index = std::size_t(std::distance(itemlist.begin(), iter)) + 1; setCurrentItem(index); @@ -644,7 +641,7 @@ void FListBox::adjustSize() // private methods of FListBox //---------------------------------------------------------------------- -inline FString FListBox::getString (listBoxItems::iterator iter) +inline FString FListBox::getString (FListBoxItems::iterator iter) { return iter->getText(); } @@ -695,7 +692,7 @@ inline void FListBox::mapKeyFunctions() //---------------------------------------------------------------------- void FListBox::processKeyAction (FKeyEvent* ev) { - const int idx = int(ev->key()); + const auto idx = int(ev->key()); if ( key_map.find(idx) != key_map.end() ) { @@ -837,7 +834,7 @@ void FListBox::drawList() const bool lineHasBrackets = hasBrackets(iter); // Import data via lazy conversion - lazyConvert (iter, int(y)); + lazyConvert (iter, y); // Set screen position and attributes setLineAttributes ( int(y), isSelected(iter), lineHasBrackets @@ -863,7 +860,7 @@ void FListBox::drawList() //---------------------------------------------------------------------- inline void FListBox::drawListLine ( int y - , listBoxItems::iterator iter + , FListBoxItems::iterator iter , bool serach_mark ) { const std::size_t inc_len = inc_search.getLength(); @@ -918,7 +915,7 @@ inline void FListBox::printRightBracket (fc::brackets_type bracket_type) //---------------------------------------------------------------------- inline void FListBox::drawListBracketsLine ( int y - , listBoxItems::iterator iter + , FListBoxItems::iterator iter , bool serach_mark ) { std::size_t b{0}; @@ -936,7 +933,7 @@ inline void FListBox::drawListBracketsLine ( int y printLeftBracket (iter->brackets); } - const std::size_t first = std::size_t(xoffset); + const auto first = std::size_t(xoffset); const std::size_t max_width = getWidth() - nf_offset - 4 - b; const FString element(getColumnSubString (getString(iter), first, max_width)); std::size_t column_width = getColumnWidth(element); @@ -1236,7 +1233,7 @@ void FListBox::wheelUp (int pagesize) void FListBox::wheelDown (int pagesize) { const std::size_t element_count = getCount(); - int yoffset_end = int(element_count - getClientHeight()); + auto yoffset_end = int(element_count - getClientHeight()); if ( yoffset_end < 0 ) yoffset_end = 0; @@ -1369,7 +1366,7 @@ void FListBox::prevListItem (int distance) void FListBox::nextListItem (int distance) { const std::size_t element_count = getCount(); - const int yoffset_end = int(element_count - getClientHeight()); + const auto yoffset_end = int(element_count - getClientHeight()); if ( current == element_count ) return; @@ -1410,7 +1407,7 @@ void FListBox::scrollToX (int val) void FListBox::scrollToY (int val) { const std::size_t element_count = getCount(); - const int yoffset_end = int(element_count - getClientHeight()); + const auto yoffset_end = int(element_count - getClientHeight()); if ( yoffset == val ) return; @@ -1519,7 +1516,7 @@ inline void FListBox::firstPos() inline void FListBox::lastPos() { const std::size_t element_count = getCount(); - const int yoffset_end = int(element_count - getClientHeight()); + const auto yoffset_end = int(element_count - getClientHeight()); current = element_count; if ( current > getClientHeight() ) @@ -1625,31 +1622,29 @@ inline bool FListBox::deletePreviousCharacter() { const std::size_t inc_len = inc_search.getLength(); - if ( inc_len > 0 ) + if ( inc_len == 0 ) + return false; + + inc_search.remove(inc_len - 1, 1); + + if ( inc_len > 1 ) { - inc_search.remove(inc_len - 1, 1); + auto iter = itemlist.begin(); - if ( inc_len > 1 ) + while ( iter != itemlist.end() ) { - auto iter = itemlist.begin(); - - while ( iter != itemlist.end() ) + if ( inc_search.toLower() + == iter->getText().left(inc_len - 1).toLower() ) { - if ( inc_search.toLower() - == iter->getText().left(inc_len - 1).toLower() ) - { - setCurrentItem(iter); - break; - } - - ++iter; + setCurrentItem(iter); + break; } - } - return true; + ++iter; + } } - return false; + return true; } //---------------------------------------------------------------------- @@ -1729,12 +1724,12 @@ void FListBox::changeOnResize() const } //---------------------------------------------------------------------- -void FListBox::lazyConvert(listBoxItems::iterator iter, int y) +void FListBox::lazyConvert(FListBoxItems::iterator iter, std::size_t y) { if ( conv_type != lazy_convert || ! iter->getText().isNull() ) return; - lazy_inserter (*iter, source_container, y + yoffset); + lazy_inserter (*iter, source_container, y + std::size_t(yoffset)); const auto column_width = getColumnWidth(iter->text); recalculateHorizontalBar (column_width, hasBrackets(iter)); diff --git a/src/flistview.cpp b/src/flistview.cpp index 77fb518d..3b55d8fb 100644 --- a/src/flistview.cpp +++ b/src/flistview.cpp @@ -198,21 +198,6 @@ FListViewItem::FListViewItem (iterator parent_iter) insert (this, parent_iter); } -//---------------------------------------------------------------------- -FListViewItem::FListViewItem ( const FStringList& cols - , FDataPtr data - , iterator parent_iter ) - : FObject{nullptr} - , column_list{cols} - , data_pointer{data} -{ - if ( cols.empty() ) - return; - - replaceControlCodes(); - insert (this, parent_iter); -} - //---------------------------------------------------------------------- FListViewItem::~FListViewItem() // destructor { @@ -254,7 +239,7 @@ FString FListViewItem::getText (int column) const return fc::emptyFString::get(); // Convert column position to address offset (index) - const std::size_t index = std::size_t(column - 1); + const auto index = std::size_t(column - 1); return column_list[index]; } @@ -290,7 +275,7 @@ void FListViewItem::setText (int column, const FString& text) if ( ! listview->header[index].fixed_width ) { - const int column_width = int(getColumnWidth(text)); + const auto column_width = int(getColumnWidth(text)); if ( column_width > listview->header[index].width ) listview->header[index].width = column_width; @@ -720,7 +705,7 @@ fc::text_alignment FListView::getColumnAlignment (int column) const return fc::alignLeft; // Convert column position to address offset (index) - const std::size_t index = std::size_t(column - 1); + const auto index = std::size_t(column - 1); return header[index].alignment; } @@ -733,7 +718,7 @@ FString FListView::getColumnText (int column) const return fc::emptyFString::get(); // Convert column position to address offset (index) - const std::size_t index = std::size_t(column - 1); + const auto index = std::size_t(column - 1); return header[index].name; } @@ -741,7 +726,7 @@ FString FListView::getColumnText (int column) const fc::sorting_type FListView::getColumnSortType (int column) const { fc::sorting_type type; - const std::size_t col = std::size_t(column); + const auto col = std::size_t(column); try { @@ -779,7 +764,7 @@ void FListView::setColumnAlignment (int column, fc::text_alignment align) return; // Convert column position to address offset (index) - const std::size_t index = std::size_t(column - 1); + const auto index = std::size_t(column - 1); header[index].alignment = align; } @@ -792,11 +777,11 @@ void FListView::setColumnText (int column, const FString& label) return; // Convert column position to address offset (index) - std::size_t index = std::size_t(column - 1); + auto index = std::size_t(column - 1); if ( ! header[index].fixed_width ) { - const int column_width = int(getColumnWidth(label)); + const auto column_width = int(getColumnWidth(label)); if ( column_width > header[index].width ) header[index].width = column_width; @@ -895,33 +880,6 @@ FObject::iterator FListView::insert ( FListViewItem* item return item_iter; } -//---------------------------------------------------------------------- -FObject::iterator FListView::insert ( const FStringList& cols - , FDataPtr d - , iterator parent_iter ) -{ - FListViewItem* item; - - if ( cols.empty() || parent_iter == getNullIterator() ) - return getNullIterator(); - - if ( ! *parent_iter ) - parent_iter = root; - - try - { - item = new FListViewItem (cols, d, getNullIterator()); - } - catch (const std::bad_alloc&) - { - badAllocOutput ("FListViewItem"); - return getNullIterator(); - } - - item->replaceControlCodes(); - return insert(item, parent_iter); -} - //---------------------------------------------------------------------- void FListView::remove (FListViewItem* item) { @@ -1417,7 +1375,7 @@ void FListView::onFocusOut (FFocusEvent*) //---------------------------------------------------------------------- void FListView::adjustViewport (const int element_count) { - const int height = int(getClientHeight()); + const auto height = int(getClientHeight()); if ( height <= 0 || element_count == 0 ) return; @@ -1553,7 +1511,7 @@ inline void FListView::mapKeyFunctions() //---------------------------------------------------------------------- void FListView::processKeyAction (FKeyEvent* ev) { - const int idx = int(ev->key()); + const auto idx = int(ev->key()); if ( key_map.find(idx) != key_map.end() ) { @@ -1704,7 +1662,7 @@ void FListView::drawHeadlines() || max_line_width < 1 ) return; - headerItems::const_iterator iter = header.begin(); + HeaderItems::const_iterator iter = header.begin(); headerline.clear(); if ( hasCheckableItems() ) @@ -1802,7 +1760,7 @@ void FListView::drawListLine ( const FListViewItem* item { static constexpr std::size_t ellipsis_length = 2; const auto& text = item->column_list[col]; - std::size_t width = std::size_t(header[col].width); + auto width = std::size_t(header[col].width); const std::size_t column_width = getColumnWidth(text); // Increment the value of col for the column position // and the next iteration @@ -2025,16 +1983,16 @@ inline void FListView::drawHeaderBorder (std::size_t length) //---------------------------------------------------------------------- -void FListView::drawHeadlineLabel (const headerItems::const_iterator& iter) +void FListView::drawHeadlineLabel (const HeaderItems::const_iterator& iter) { // Print label text static constexpr std::size_t leading_space = 1; const auto& text = iter->name; FString txt{" " + text}; - const std::size_t width = std::size_t(iter->width); + const auto width = std::size_t(iter->width); std::size_t column_width = getColumnWidth(txt); const std::size_t column_max = leading_space + width; - const headerItems::const_iterator first = header.begin(); + const HeaderItems::const_iterator first = header.begin(); const int column = int(std::distance(first, iter)) + 1; const bool has_sort_indicator( sort_column == column && ! hide_sort_indicator ); const auto& wc = getColorTheme(); @@ -2161,7 +2119,7 @@ void FListView::drawBufferedHeadline() } //---------------------------------------------------------------------- -void FListView::drawColumnEllipsis ( const headerItems::const_iterator& iter +void FListView::drawColumnEllipsis ( const HeaderItems::const_iterator& iter , const FString& text ) { // Print label ellipsis @@ -2211,7 +2169,7 @@ std::size_t FListView::determineLineWidth (FListViewItem* item) for (auto&& header_item : header) { - const std::size_t width = std::size_t(header_item.width); + const auto width = std::size_t(header_item.width); const bool fixed_width = header_item.fixed_width; if ( ! fixed_width ) @@ -2318,7 +2276,7 @@ void FListView::mouseHeaderClicked() { static constexpr int leading_space = 1; const bool has_sort_indicator( column == sort_column ); - int click_width = int(getColumnWidth(item.name)); + auto click_width = int(getColumnWidth(item.name)); if ( has_sort_indicator ) click_width += 2; @@ -2377,7 +2335,7 @@ void FListView::wheelDown (int pagesize) if ( itemlist.empty() ) return; - const int element_count = int(getCount()); + const auto element_count = int(getCount()); if ( current_iter.getPosition() + 1 == element_count ) return; @@ -2416,7 +2374,7 @@ bool FListView::dragScrollUp (int position_before) //---------------------------------------------------------------------- bool FListView::dragScrollDown (int position_before) { - const int element_count = int(getCount()); + const auto element_count = int(getCount()); if ( position_before + 1 == element_count ) { @@ -2635,7 +2593,7 @@ inline void FListView::lastPos() if ( itemlist.empty() ) return; - const int element_count = int(getCount()); + const auto element_count = int(getCount()); current_iter += element_count - current_iter.getPosition() - 1; const int difference = element_count - last_visible_line.getPosition() - 1; first_visible_line += difference; @@ -2730,7 +2688,7 @@ void FListView::stepForward (int distance) if ( itemlist.empty() ) return; - const int element_count = int(getCount()); + const auto element_count = int(getCount()); if ( current_iter.getPosition() + 1 == element_count ) return; @@ -2811,7 +2769,7 @@ void FListView::scrollToX (int x) void FListView::scrollToY (int y) { const int pagesize = int(getClientHeight()) - 1; - const int element_count = int(getCount()); + const auto element_count = int(getCount()); if ( first_visible_line.getPosition() == y ) return; diff --git a/src/flog.cpp b/src/flog.cpp index 9a244551..c06e1d2c 100644 --- a/src/flog.cpp +++ b/src/flog.cpp @@ -47,6 +47,7 @@ FLog& FLog::operator << (LogLevel l) { using std::placeholders::_1; sync(); + std::lock_guard lock_guard(mut); switch ( l ) { @@ -77,6 +78,7 @@ int FLog::sync() { if ( ! str().empty() ) { + std::lock_guard lock_guard(mut); current_log (str()); str(""); } diff --git a/src/flogger.cpp b/src/flogger.cpp index daec3cea..6f1bf2a7 100644 --- a/src/flogger.cpp +++ b/src/flogger.cpp @@ -20,6 +20,7 @@ * . * ***********************************************************************/ +#include #include #include "final/flogger.h" @@ -58,21 +59,23 @@ void FLogger::newlineReplace ( std::string& str } //---------------------------------------------------------------------- -const std::string FLogger::getTimeString() const +std::string FLogger::getTimeString() const { - char str[100]; + std::array str; const auto& now = std::chrono::system_clock::now(); const auto& t = std::chrono::system_clock::to_time_t(now); // Print RFC 2822 date struct tm time{}; localtime_r (&t, &time); - std::strftime (str, sizeof(str), "%a, %d %b %Y %T %z", &time); - return std::string(str); + std::strftime (str.data(), str.size(), "%a, %d %b %Y %T %z", &time); + return std::string(str.data()); } //---------------------------------------------------------------------- -const std::string FLogger::getEOL() const +std::string FLogger::getEOL() { + std::lock_guard lock_guard(getMutex()); + if ( getEnding() == FLog::LF ) return "\n"; else if ( getEnding() == FLog::CR ) @@ -88,6 +91,8 @@ void FLogger::printLogLine (const std::string& msg) { const std::string& log_level = [this] () { + std::lock_guard lock_guard(getMutex()); + switch ( getLevel() ) { case Info: diff --git a/src/fmenu.cpp b/src/fmenu.cpp index 83f823b5..0c8d5401 100644 --- a/src/fmenu.cpp +++ b/src/fmenu.cpp @@ -136,13 +136,8 @@ void FMenu::onKeyPress (FKeyEvent* ev) // looking for menu bar hotkey auto menu_bar = getMenuBar(); - if ( menu_bar ) - { - auto mbar = static_cast(menu_bar); - - if ( mbar->hotkeyMenu(ev) ) - return; - } + if ( menu_bar && menu_bar->hotkeyMenu(ev) ) + return; switch ( ev->key() ) { @@ -272,7 +267,7 @@ void FMenu::onMouseMove (FMouseEvent* ev) if ( ! mouse_down || getItemList().empty() ) return; - mouseStates ms = + MouseStates ms = { false, // focus_changed false, // hide_sub_menu @@ -824,7 +819,7 @@ bool FMenu::mouseUpOverList (const FPoint& mouse_pos) } //---------------------------------------------------------------------- -void FMenu::mouseMoveOverList (const FPoint& mouse_pos, mouseStates& ms) +void FMenu::mouseMoveOverList (const FPoint& mouse_pos, MouseStates& ms) { FPoint pos{mouse_pos}; pos -= FPoint{getRightPadding(), getTopPadding()}; @@ -845,7 +840,7 @@ void FMenu::mouseMoveOverList (const FPoint& mouse_pos, mouseStates& ms) } //---------------------------------------------------------------------- -void FMenu::mouseMoveSelection (FMenuItem* m_item, mouseStates& ms) +void FMenu::mouseMoveSelection (FMenuItem* m_item, MouseStates& ms) { if ( ! m_item->isEnabled() || m_item->isSelected() @@ -878,7 +873,7 @@ void FMenu::mouseMoveSelection (FMenuItem* m_item, mouseStates& ms) } //---------------------------------------------------------------------- -void FMenu::mouseMoveDeselection (FMenuItem* m_item, mouseStates& ms) +void FMenu::mouseMoveDeselection (FMenuItem* m_item, MouseStates& ms) { if ( ! ms.mouse_over_menu || ! m_item->isEnabled() @@ -907,7 +902,7 @@ void FMenu::mouseUpOverBorder() } //---------------------------------------------------------------------- -void FMenu::mouseMoveOverBorder (mouseStates& ms) const +void FMenu::mouseMoveOverBorder (MouseStates& ms) const { // Mouse is moved over border or separator line @@ -989,9 +984,8 @@ void FMenu::passEventToMenuBar (FMouseEvent* const& ev) const const auto& _ev = \ std::make_shared(fc::MouseMove_Event, p, t, b); setClickedWidget(menu_bar); - auto& mbar = *(static_cast(menu_bar)); - mbar.mouse_down = true; - mbar.onMouseMove(_ev.get()); + menu_bar->mouse_down = true; + menu_bar->onMouseMove(_ev.get()); } catch (const std::bad_alloc&) { @@ -1060,7 +1054,7 @@ bool FMenu::selectNextItem() ++next_element; if ( next_element == list.end() ) next_element = list.begin(); - next = static_cast(*next_element); + next = *next_element; } while ( ! next->isEnabled() || ! next->acceptFocus() @@ -1110,7 +1104,7 @@ bool FMenu::selectPrevItem() if ( prev_element == list.begin() ) prev_element = list.end(); --prev_element; - prev = static_cast(*prev_element); + prev = *prev_element; } while ( ! prev->isEnabled() || ! prev->acceptFocus() @@ -1277,7 +1271,7 @@ inline void FMenu::drawSeparator (int y) inline void FMenu::drawMenuLine (FMenuItem* m_item, int y) { FString txt{m_item->getText()}; - menuText txtdata{}; + MenuText txtdata{}; std::size_t column_width = getColumnWidth(txt); const FKey accel_key = m_item->accel_key; const bool is_enabled = m_item->isEnabled(); @@ -1367,7 +1361,7 @@ inline void FMenu::drawCheckMarkPrefix (const FMenuItem* m_item) } //---------------------------------------------------------------------- -inline void FMenu::drawMenuText (menuText& data) +inline void FMenu::drawMenuText (MenuText& data) { // Print menu text diff --git a/src/fmenubar.cpp b/src/fmenubar.cpp index 756dc48e..347a20fa 100644 --- a/src/fmenubar.cpp +++ b/src/fmenubar.cpp @@ -50,7 +50,7 @@ FMenuBar::FMenuBar(FWidget* parent) //---------------------------------------------------------------------- FMenuBar::~FMenuBar() // destructor { - setMenuBar(nullptr); + FWidget::setMenuBar(nullptr); } @@ -256,6 +256,7 @@ void FMenuBar::init() addAccelerator (fc::Fkey_f10); addAccelerator (fc::Fckey_space); + addAccelerator (fc::Fkey_menu); resetColors(); unsetFocusable(); } @@ -268,17 +269,17 @@ void FMenuBar::calculateDimensions() const // find the maximum item width for (auto&& item : getItemList()) { - int len = int(item->getTextWidth()); - int item_width = len + 2; + auto len = item->getTextWidth(); + auto item_width = len + 2; // set item geometry - item->setGeometry (item_pos, FSize{std::size_t(item_width), 1}, false); + item->setGeometry (item_pos, FSize{item_width, 1}, false); // set menu position if ( item->hasMenu() ) item->getMenu()->setPos (item_pos, false); - item_pos.x_ref() += item_width; + item_pos.x_ref() += int(item_width); } } @@ -302,7 +303,7 @@ bool FMenuBar::selectNextItem() if ( next_element == list.end() ) next_element = list.begin(); - next = static_cast(*next_element); + next = *next_element; } while ( ! next->isEnabled() || ! next->acceptFocus() || ! next->isShown() @@ -365,7 +366,7 @@ bool FMenuBar::selectPrevItem() prev_element = list.end(); --prev_element; - prev = static_cast(*prev_element); + prev = *prev_element; } while ( ! prev->isEnabled() || ! prev->acceptFocus() @@ -681,7 +682,7 @@ void FMenuBar::adjustItems() const for (auto&& item : getItemList()) { // get item width - int item_width = int(item->getWidth()); + auto item_width = item->getWidth(); if ( item->hasMenu() ) { @@ -694,7 +695,7 @@ void FMenuBar::adjustItems() const menu->adjustItems(); } - item_X += item_width; + item_X += int(item_width); } } diff --git a/src/fmenuitem.cpp b/src/fmenuitem.cpp index 1ebc09c4..5da65bb1 100644 --- a/src/fmenuitem.cpp +++ b/src/fmenuitem.cpp @@ -605,47 +605,42 @@ void FMenuItem::createDialogList (FMenu* winmenu) const while ( iter != getDialogList()->end() && *iter ) { auto win = static_cast(*iter); + FMenuItem* win_item{}; + const auto n = uInt32(std::distance(first, iter)); + // get the dialog title + const auto& name = win->getText(); - if ( win ) + try { - FMenuItem* win_item{}; - const uInt32 n = uInt32(std::distance(first, iter)); - // get the dialog title - const auto& name = win->getText(); - - try - { - // create a new dialog list item - win_item = new FMenuItem (name, winmenu); - } - catch (const std::bad_alloc&) - { - badAllocOutput ("FMenuItem"); - return; - } - - if ( n < 9 ) - win_item->addAccelerator (fc::Fmkey_1 + n); // Meta + 1..9 - - win_item->addCallback - ( - "clicked", - static_cast::type>(win_item), - &FMenuItem::cb_switchToDialog, - win - ); - - win->addCallback - ( - "destroy", - static_cast::type>(win_item), - &FMenuItem::cb_destroyDialog, - win - ); - - win_item->associated_window = win; + // create a new dialog list item + win_item = new FMenuItem (name, winmenu); + } + catch (const std::bad_alloc&) + { + badAllocOutput ("FMenuItem"); + return; } + if ( n < 9 ) + win_item->addAccelerator (fc::Fmkey_1 + n); // Meta + 1..9 + + win_item->addCallback + ( + "clicked", + static_cast::type>(win_item), + &FMenuItem::cb_switchToDialog, + win + ); + + win->addCallback + ( + "destroy", + static_cast::type>(win_item), + &FMenuItem::cb_destroyDialog, + win + ); + + win_item->associated_window = win; ++iter; } } diff --git a/src/fmessagebox.cpp b/src/fmessagebox.cpp index 1e720423..d707e89f 100644 --- a/src/fmessagebox.cpp +++ b/src/fmessagebox.cpp @@ -21,6 +21,7 @@ ***********************************************************************/ #include +#include #include "final/fapplication.h" #include "final/fbutton.h" @@ -30,8 +31,8 @@ namespace finalcut { -static const char* const button_text[] = -{ +constexpr std::array button_text = +{{ nullptr, "&OK", "&Cancel", @@ -39,9 +40,8 @@ static const char* const button_text[] = "&No", "&Abort", "&Retry", - "&Ignore", - nullptr -}; + "&Ignore" +}}; //---------------------------------------------------------------------- // class FMessageBox @@ -51,7 +51,7 @@ static const char* const button_text[] = //---------------------------------------------------------------------- FMessageBox::FMessageBox (FWidget* parent) : FDialog{parent} - , button_digit{FMessageBox::Ok, 0, 0} + , button_digit{FMessageBox::Ok, FMessageBox::Reject, FMessageBox::Reject} { setTitlebarText("Message for you"); init(); @@ -79,9 +79,9 @@ FMessageBox::FMessageBox (const FMessageBox& mbox) //---------------------------------------------------------------------- FMessageBox::FMessageBox ( const FString& caption , const FString& message - , int button0 - , int button1 - , int button2 + , ButtonType button0 + , ButtonType button1 + , ButtonType button2 , FWidget* parent ) : FDialog{parent} , text{message} @@ -158,10 +158,10 @@ void FMessageBox::setText (const FString& txt) if ( button[0] ) button[0]->setY (int(getHeight()) - 4, false); - if ( button[1] && button_digit[1] != 0 ) + if ( button[1] && button_digit[1] != FMessageBox::Reject ) button[1]->setY (int(getHeight()) - 4, false); - if ( button[2] && button_digit[2] != 0 ) + if ( button[2] && button_digit[2] != FMessageBox::Reject ) button[2]->setY (int(getHeight()) - 4, false); adjustButtons(); @@ -195,9 +195,9 @@ void FMessageBox::adjustSize() } //---------------------------------------------------------------------- -void FMessageBox::cb_processClick (int reply) +void FMessageBox::cb_processClick (ButtonType reply) { - done(reply); + done(int(reply)); } @@ -207,18 +207,21 @@ void FMessageBox::init() { calculateDimensions(); - if ( (button_digit[2] && ! button_digit[1]) - || (button_digit[1] && ! button_digit[0]) ) + if ( (button_digit[2] != Reject && button_digit[1] == Reject) + || (button_digit[1] != Reject && button_digit[0] == Reject) ) { - button_digit[0] = button_digit[1] = button_digit[2] = 0; + button_digit[0] = button_digit[1] \ + = button_digit[2] \ + = FMessageBox::Reject; } - if ( button_digit[0] == 0 ) + if ( button_digit[0] == FMessageBox::Reject ) button_digit[0] = FMessageBox::Ok; - if ( button_digit[1] == 0 && button_digit[2] == 0 ) + if ( button_digit[1] == FMessageBox::Reject + && button_digit[2] == FMessageBox::Reject ) num_buttons = 1; - else if ( button_digit[2] == 0 ) + else if ( button_digit[2] == FMessageBox::Reject ) num_buttons = 2; else num_buttons = 3; @@ -242,7 +245,7 @@ inline void FMessageBox::allocation() button[0]->setHeight(1, false); button[0]->setFocus(); - if ( button_digit[1] > 0 ) + if ( button_digit[1] > FMessageBox::Reject ) { button[1] = new FButton(this); button[1]->setText(button_text[button_digit[1]]); @@ -251,7 +254,7 @@ inline void FMessageBox::allocation() button[1]->setHeight(1, false); } - if ( button_digit[2] > 0 ) + if ( button_digit[2] > FMessageBox::Reject ) { button[2] = new FButton(this); button[2]->setText(button_text[button_digit[2]]); @@ -278,7 +281,7 @@ inline void FMessageBox::deallocation() //---------------------------------------------------------------------- inline void FMessageBox::initCallbacks() { - if ( button[0] && button_digit[0] != 0 ) + if ( button[0] && button_digit[0] != FMessageBox::Reject ) { button[0]->addCallback ( @@ -288,7 +291,7 @@ inline void FMessageBox::initCallbacks() ); } - if ( button[1] && button_digit[1] != 0 ) + if ( button[1] && button_digit[1] != FMessageBox::Reject ) { button[1]->addCallback ( @@ -298,7 +301,7 @@ inline void FMessageBox::initCallbacks() ); } - if ( button[2] && button_digit[2] != 0 ) + if ( button[2] && button_digit[2] != FMessageBox::Reject ) { button[2]->addCallback ( @@ -350,7 +353,7 @@ void FMessageBox::draw() int head_offset{0}; int center_x{0}; // center the whole block - const int msg_x = int((getWidth() - max_line_width) / 2); + const auto msg_x = int((getWidth() - max_line_width) / 2); if ( FTerm::isMonochron() ) setReverse(true); @@ -388,7 +391,7 @@ void FMessageBox::draw() //---------------------------------------------------------------------- void FMessageBox::resizeButtons() const { - std::size_t len[3]{}; + std::array len{}; std::size_t max_size{}; for (std::size_t n{0}; n < num_buttons && n < MAX_BUTTONS; n++) @@ -447,7 +450,7 @@ void FMessageBox::adjustButtons() setX (int((max_width - getWidth()) / 2)); } - const int btn_x = int((getWidth() - btn_width) / 2); + const auto btn_x = int((getWidth() - btn_width) / 2); for (std::size_t n{0}; n < num_buttons && n < MAX_BUTTONS; n++) { @@ -458,7 +461,7 @@ void FMessageBox::adjustButtons() button[n]->setX(btn_x); else { - const int btn_size = int(button[n]->getWidth()); + const auto btn_size = int(button[n]->getWidth()); button[n]->setX(btn_x + int(n) * (btn_size + int(gap))); } } diff --git a/src/fmouse.cpp b/src/fmouse.cpp index f6a01da3..843c668a 100644 --- a/src/fmouse.cpp +++ b/src/fmouse.cpp @@ -54,7 +54,7 @@ FMouse::FMouse() // public methods of FMouse //---------------------------------------------------------------------- -const FString FMouse::getClassName() const +FString FMouse::getClassName() const { return "FMouse"; } @@ -287,7 +287,7 @@ FMouseGPM::~FMouseGPM() // destructor // public methods of FMouseX11 //---------------------------------------------------------------------- -const FString FMouseGPM::getClassName() const +FString FMouseGPM::getClassName() const { return "FMouseGPM"; } @@ -306,7 +306,9 @@ bool FMouseGPM::hasData() //---------------------------------------------------------------------- void FMouseGPM::setRawData (FKeyboard::keybuffer&) -{ } +{ + // This method need not be implemented for FMouseGPM +} //---------------------------------------------------------------------- void FMouseGPM::processEvent (struct timeval*) @@ -520,7 +522,7 @@ int FMouseGPM::gpmEvent (bool clear) const // public methods of FMouseX11 //---------------------------------------------------------------------- -const FString FMouseX11::getClassName() const +FString FMouseX11::getClassName() const { return "FMouseX11"; } @@ -563,8 +565,8 @@ void FMouseX11::processEvent (struct timeval* time) // Parse and interpret the X11 xterm mouse string const auto& mouse_position = getPos(); - const uChar x = uChar(x11_mouse[1] - 0x20); - const uChar y = uChar(x11_mouse[2] - 0x20); + const auto x = uChar(x11_mouse[1] - 0x20); + const auto y = uChar(x11_mouse[2] - 0x20); const int btn = x11_mouse[0]; setNewPos (x, y); clearButtonState(); @@ -698,7 +700,7 @@ void FMouseX11::setButtonState (const int btn, const struct timeval* time) // public methods of FMouseSGR //---------------------------------------------------------------------- -const FString FMouseSGR::getClassName() const +FString FMouseSGR::getClassName() const { return "FMouseSGR"; } @@ -928,7 +930,7 @@ void FMouseSGR::setReleasedButtonState (const int btn) // public methods of FMouseUrxvt //---------------------------------------------------------------------- -const FString FMouseUrxvt::getClassName() const +FString FMouseUrxvt::getClassName() const { return "FMouseUrxvt"; } diff --git a/src/fobject.cpp b/src/fobject.cpp index f10a8adc..c29ab4e9 100644 --- a/src/fobject.cpp +++ b/src/fobject.cpp @@ -48,7 +48,6 @@ FObject::FObject (FObject* parent) if ( parent ) // add object to parent { parent->addChild(this); - has_parent = true; } else { @@ -107,7 +106,7 @@ FObject* FObject::getChild (int index) const if ( ! hasChildren() ) return nullptr; - if ( index <= 0 || index > numOfChildren() ) + if ( index <= 0 || index > int(numOfChildren()) ) return nullptr; auto iter = begin(); @@ -148,6 +147,9 @@ void FObject::addChild (FObject* obj) if ( ! obj ) return; + if ( max_children != UNLIMITED && max_children <= numOfChildren() ) + throw std::length_error ("max. child objects reached"); + if ( obj->parent_obj ) obj->parent_obj->delChild(obj); @@ -252,7 +254,7 @@ bool FObject::isTimeout (const timeval* time, uInt64 timeout) diff.tv_usec += 1000000; } - const uInt64 diff_usec = uInt64((diff.tv_sec * 1000000) + diff.tv_usec); + const auto diff_usec = uInt64((diff.tv_sec * 1000000) + diff.tv_usec); return ( diff_usec > timeout ); } @@ -380,11 +382,17 @@ bool FObject::delAllTimers() const // protected methods of FObject //---------------------------------------------------------------------- void FObject::onTimer (FTimerEvent*) -{ } +{ + // This event handler can be reimplemented in a subclass + // to receive timer events for this object +} //---------------------------------------------------------------------- void FObject::onUserEvent (FUserEvent*) -{ } +{ + // This event handler can be reimplemented in a subclass + // to receive user events for this object +} //---------------------------------------------------------------------- uInt FObject::processTimerEvent() @@ -427,6 +435,9 @@ uInt FObject::processTimerEvent() //---------------------------------------------------------------------- void FObject::performTimerAction (FObject*, FEvent*) -{ } +{ + // This method must be reimplemented in a subclass + // to process the passed object and timer event +} } // namespace finalcut diff --git a/src/foptiattr.cpp b/src/foptiattr.cpp index 9f6680dd..4c03b929 100644 --- a/src/foptiattr.cpp +++ b/src/foptiattr.cpp @@ -20,6 +20,7 @@ * . * ***********************************************************************/ +#include #include #include "final/fc.h" @@ -53,7 +54,7 @@ FOptiAttr::~FOptiAttr() // destructor // public methods of FOptiAttr //---------------------------------------------------------------------- -void FOptiAttr::setTermEnvironment (const termEnv& term_env) +void FOptiAttr::setTermEnvironment (const TermEnv& term_env) { // Set all required termcap values at once // and initialize the FOptiAttr environment @@ -531,11 +532,11 @@ FColor FOptiAttr::vga2ansi (FColor color) color = 0; else if ( color < 16 ) { - static const FColor lookup_table[] = - { + constexpr std::array lookup_table = + {{ 0, 4, 2, 6, 1, 5, 3, 7, 8, 12, 10, 14, 9, 13, 11, 15 - }; + }}; color = lookup_table[color]; } @@ -551,7 +552,7 @@ const char* FOptiAttr::changeAttribute (FChar*& term, FChar*& next) attr_buf[0] = '\0'; if ( ! (term && next) ) - return attr_buf; + return attr_buf.data(); prevent_no_color_video_attributes (term, next_has_color); prevent_no_color_video_attributes (next); @@ -583,7 +584,7 @@ const char* FOptiAttr::changeAttribute (FChar*& term, FChar*& next) if ( FStartOptions::getFStartOptions().sgr_optimizer ) sgr_optimizer.optimize(); - return attr_buf; + return attr_buf.data(); } @@ -1086,8 +1087,8 @@ bool FOptiAttr::setTermDefaultColor (FChar*& term) return true; else if ( ansi_default_color ) { - char sgr_39_49[] = CSI "39;49m"; - append_sequence (sgr_39_49); + std::string sgr_39_49{CSI "39;49m"}; + append_sequence (sgr_39_49.c_str()); return true; } else @@ -1453,8 +1454,8 @@ inline void FOptiAttr::change_to_default_color ( FChar*& term } else if ( fg == fc::Default && term->fg_color != fc::Default ) { - char sgr_39[]{ CSI "39m" }; - append_sequence (sgr_39); + std::string sgr_39{CSI "39m"}; + append_sequence (sgr_39.c_str()); term->fg_color = fc::Default; } else if ( bg == fc::Default && term->bg_color != fc::Default ) @@ -1667,8 +1668,9 @@ inline bool FOptiAttr::append_sequence (const char seq[]) if ( ! seq ) return false; - std::strncat (attr_ptr, seq, sizeof(attr_buf) - std::strlen(attr_ptr)); - attr_buf[sizeof(attr_buf) - 1] = '\0'; + char* attr_ptr{attr_buf.data()}; + std::strncat (attr_ptr, seq, attr_buf.size() - std::strlen(attr_ptr)); + attr_buf[attr_buf.size() - 1] = '\0'; return true; } diff --git a/src/foptimove.cpp b/src/foptimove.cpp index 6f815346..38e05c20 100644 --- a/src/foptimove.cpp +++ b/src/foptimove.cpp @@ -20,11 +20,11 @@ * . * ***********************************************************************/ +#include #include #include "final/fapplication.h" #include "final/fc.h" -#include "final/flog.h" #include "final/foptimove.h" #include "final/ftermcap.h" @@ -83,7 +83,7 @@ void FOptiMove::setTermSize (std::size_t w, std::size_t h) } //---------------------------------------------------------------------- -void FOptiMove::setTermEnvironment (const termEnv& term_env) +void FOptiMove::setTermEnvironment (const TermEnv& term_env) { // Set all required termcap values at once @@ -607,7 +607,7 @@ int FOptiMove::capDurationToLength (int duration) const } //---------------------------------------------------------------------- -int FOptiMove::repeatedAppend ( const capability& o +int FOptiMove::repeatedAppend ( const Capability& o , volatile int count , char* dst ) const { @@ -801,7 +801,7 @@ inline void FOptiMove::rightMove ( char hmove[], int& htime if ( F_cursor_right.cap ) { - char str[BUF_SIZE]{}; + std::array str{}; int htime_r{0}; str[0] = '\0'; @@ -817,7 +817,7 @@ inline void FOptiMove::rightMove ( char hmove[], int& htime if ( tab_pos > to_x ) break; - htime_r += repeatedAppend (F_tab, 1, str); + htime_r += repeatedAppend (F_tab, 1, str.data()); if ( htime_r >= LONG_DURATION ) break; @@ -828,11 +828,11 @@ inline void FOptiMove::rightMove ( char hmove[], int& htime num = to_x - pos; } - htime_r += repeatedAppend (F_cursor_right, num, str); + htime_r += repeatedAppend (F_cursor_right, num, str.data()); if ( htime_r < htime ) { - std::strncpy (hmove, str, BUF_SIZE); + std::strncpy (hmove, str.data(), BUF_SIZE); hmove[BUF_SIZE - 1] = '\0'; htime = htime_r; } @@ -856,7 +856,7 @@ inline void FOptiMove::leftMove ( char hmove[], int& htime if ( F_cursor_left.cap ) { - char str[BUF_SIZE]{}; + std::array str{}; int htime_l{0}; str[0] = '\0'; @@ -872,7 +872,7 @@ inline void FOptiMove::leftMove ( char hmove[], int& htime if ( tab_pos < to_x ) break; - htime_l += repeatedAppend (F_back_tab, 1, str); + htime_l += repeatedAppend (F_back_tab, 1, str.data()); if ( htime_l >= LONG_DURATION ) break; @@ -883,11 +883,11 @@ inline void FOptiMove::leftMove ( char hmove[], int& htime num = pos - to_x; } - htime_l += repeatedAppend (F_cursor_left, num, str); + htime_l += repeatedAppend (F_cursor_left, num, str.data()); if ( htime_l < htime ) { - std::strncpy (hmove, str, BUF_SIZE); + std::strncpy (hmove, str.data(), BUF_SIZE); hmove[BUF_SIZE - 1] = '\0'; htime = htime_l; } @@ -933,8 +933,8 @@ inline bool FOptiMove::isMethod1Faster ( int& move_time if ( xold >= 0 && yold >= 0 ) { - char null_result[BUF_SIZE]; - const int new_time = relativeMove (null_result, xold, yold, xnew, ynew); + std::array null_result{}; + const int new_time = relativeMove (null_result.data(), xold, yold, xnew, ynew); if ( new_time < LONG_DURATION && new_time < move_time ) { @@ -955,8 +955,8 @@ inline bool FOptiMove::isMethod2Faster ( int& move_time if ( yold >= 0 && F_carriage_return.cap ) { - char null_result[BUF_SIZE]; - const int new_time = relativeMove (null_result, 0, yold, xnew, ynew); + std::array null_result{}; + const int new_time = relativeMove (null_result.data(), 0, yold, xnew, ynew); if ( new_time < LONG_DURATION && F_carriage_return.duration + new_time < move_time ) @@ -977,8 +977,8 @@ inline bool FOptiMove::isMethod3Faster ( int& move_time if ( F_cursor_home.cap ) { - char null_result[BUF_SIZE]; - const int new_time = relativeMove (null_result, 0, 0, xnew, ynew); + std::array null_result{}; + const int new_time = relativeMove (null_result.data(), 0, 0, xnew, ynew); if ( new_time < LONG_DURATION && F_cursor_home.duration + new_time < move_time ) @@ -998,8 +998,8 @@ inline bool FOptiMove::isMethod4Faster ( int& move_time // Test method 4: home-down + local movement if ( F_cursor_to_ll.cap ) { - char null_result[BUF_SIZE]; - const int new_time = relativeMove ( null_result + std::array null_result{}; + const int new_time = relativeMove ( null_result.data() , 0, int(screen_height) - 1 , xnew, ynew ); @@ -1025,8 +1025,8 @@ inline bool FOptiMove::isMethod5Faster ( int& move_time && yold > 0 && F_cursor_left.cap ) { - char null_result[BUF_SIZE]; - const int new_time = relativeMove ( null_result + std::array null_result{}; + const int new_time = relativeMove ( null_result.data() , int(screen_width) - 1, yold - 1 , xnew, ynew ); @@ -1107,43 +1107,42 @@ void FOptiMove::moveByMethod ( int method //---------------------------------------------------------------------- void printDurations (const FOptiMove& om) { - finalcut::FLog& log = *FApplication::getLog(); - log << " speed: " - << om.baudrate << " baud" << std::flush; - log << " char_duration: " - << om.char_duration << " ms" << std::flush; - log << " cursor_home: " - << om.F_cursor_home.duration << " ms" << std::flush; - log << " cursor_to_ll: " - << om.F_cursor_to_ll.duration << " ms" << std::flush; - log << " carriage_return: " - << om.F_carriage_return.duration << " ms" << std::flush; - log << " tab: " - << om.F_tab.duration << " ms" << std::flush; - log << " back_tab: " - << om.F_back_tab.duration << " ms" << std::flush; - log << " cursor_up: " - << om.F_cursor_up.duration << " ms" << std::flush; - log << " cursor_down: " - << om.F_cursor_down.duration << " ms" << std::flush; - log << " cursor_left: " - << om.F_cursor_left.duration << " ms" << std::flush; - log << " cursor_right: " - << om.F_cursor_right.duration << " ms" << std::flush; - log << " cursor_address: " - << om.F_cursor_address.duration << " ms" << std::flush; - log << " column_address: " - << om.F_column_address.duration << " ms" << std::flush; - log << " row_address: " - << om.F_row_address.duration << " ms" << std::flush; - log << " parm_up_cursor: " - << om.F_parm_up_cursor.duration << " ms" << std::flush; - log << " parm_down_cursor: " - << om.F_parm_down_cursor.duration << " ms" << std::flush; - log << " parm_left_cursor: " - << om.F_parm_left_cursor.duration << " ms" << std::flush; - log << "parm_right_cursor: " - << om.F_parm_right_cursor.duration << " ms" << std::flush; + std::clog << " speed: " + << om.baudrate << " baud" << std::flush; + std::clog << " char_duration: " + << om.char_duration << " ms" << std::flush; + std::clog << " cursor_home: " + << om.F_cursor_home.duration << " ms" << std::flush; + std::clog << " cursor_to_ll: " + << om.F_cursor_to_ll.duration << " ms" << std::flush; + std::clog << " carriage_return: " + << om.F_carriage_return.duration << " ms" << std::flush; + std::clog << " tab: " + << om.F_tab.duration << " ms" << std::flush; + std::clog << " back_tab: " + << om.F_back_tab.duration << " ms" << std::flush; + std::clog << " cursor_up: " + << om.F_cursor_up.duration << " ms" << std::flush; + std::clog << " cursor_down: " + << om.F_cursor_down.duration << " ms" << std::flush; + std::clog << " cursor_left: " + << om.F_cursor_left.duration << " ms" << std::flush; + std::clog << " cursor_right: " + << om.F_cursor_right.duration << " ms" << std::flush; + std::clog << " cursor_address: " + << om.F_cursor_address.duration << " ms" << std::flush; + std::clog << " column_address: " + << om.F_column_address.duration << " ms" << std::flush; + std::clog << " row_address: " + << om.F_row_address.duration << " ms" << std::flush; + std::clog << " parm_up_cursor: " + << om.F_parm_up_cursor.duration << " ms" << std::flush; + std::clog << " parm_down_cursor: " + << om.F_parm_down_cursor.duration << " ms" << std::flush; + std::clog << " parm_left_cursor: " + << om.F_parm_left_cursor.duration << " ms" << std::flush; + std::clog << "parm_right_cursor: " + << om.F_parm_right_cursor.duration << " ms" << std::flush; } } // namespace finalcut diff --git a/src/frect.cpp b/src/frect.cpp index d861f836..e62c8c40 100644 --- a/src/frect.cpp +++ b/src/frect.cpp @@ -84,37 +84,37 @@ bool FRect::isEmpty() const } //---------------------------------------------------------------------- -const FPoint FRect::getPos() const +FPoint FRect::getPos() const { return { X1, Y1 }; } //---------------------------------------------------------------------- -const FPoint FRect::getUpperLeftPos() const +FPoint FRect::getUpperLeftPos() const { return { X1, Y1 }; } //---------------------------------------------------------------------- -const FPoint FRect::getUpperRightPos() const +FPoint FRect::getUpperRightPos() const { return { X2, Y1 }; } //---------------------------------------------------------------------- -const FPoint FRect::getLowerLeftPos() const +FPoint FRect::getLowerLeftPos() const { return { X1, Y2 }; } //---------------------------------------------------------------------- -const FPoint FRect::getLowerRightPos() const +FPoint FRect::getLowerRightPos() const { return { X2, Y2 }; } //---------------------------------------------------------------------- -const FSize FRect::getSize() const +FSize FRect::getSize() const { return { getWidth(), getHeight() }; } @@ -338,7 +338,7 @@ FRect FRect::combined (const FRect& r) const // FRect non-member operators //---------------------------------------------------------------------- -const FRect operator + (const FRect& r, const FSize& s) +FRect operator + (const FRect& r, const FSize& s) { return { r.X1 , r.Y1 @@ -347,7 +347,7 @@ const FRect operator + (const FRect& r, const FSize& s) } //---------------------------------------------------------------------- -const FRect operator - (const FRect& r, const FSize& s) +FRect operator - (const FRect& r, const FSize& s) { return { r.X1 , r.Y1 diff --git a/src/fscrollbar.cpp b/src/fscrollbar.cpp index e5895cad..fef5ace8 100644 --- a/src/fscrollbar.cpp +++ b/src/fscrollbar.cpp @@ -40,7 +40,7 @@ FScrollbar::FScrollbar(FWidget* parent) : FWidget{parent} { // The default scrollbar orientation is vertical - setGeometry(FPoint{1, 1}, FSize{1, length}, false); + FScrollbar::setGeometry(FPoint{1, 1}, FSize{1, length}, false); init(); } @@ -411,7 +411,7 @@ void FScrollbar::onTimer (FTimerEvent*) || ( scroll_type == FScrollbar::scrollPageForward && slider_pos == slider_click_stop_pos ) ) { - const int max_slider_pos = int(bar_length - slider_length); + const auto max_slider_pos = int(bar_length - slider_length); if ( scroll_type == FScrollbar::scrollPageBackward && slider_pos == 0 ) diff --git a/src/fscrollview.cpp b/src/fscrollview.cpp index 235cad83..d0483e76 100644 --- a/src/fscrollview.cpp +++ b/src/fscrollview.cpp @@ -139,8 +139,8 @@ void FScrollView::setScrollSize (const FSize& size) setChildPrintArea (viewport); } - const int xoffset_end = int(getScrollWidth() - getViewportWidth()); - const int yoffset_end = int(getScrollHeight() - getViewportHeight()); + const auto xoffset_end = int(getScrollWidth() - getViewportWidth()); + const auto yoffset_end = int(getScrollHeight() - getViewportHeight()); setTopPadding (1 - getScrollY()); setLeftPadding (1 - getScrollX()); setBottomPadding (1 - (yoffset_end - getScrollY())); @@ -352,8 +352,8 @@ void FScrollView::scrollTo (int x, int y) int& yoffset = viewport_geometry.y1_ref(); const int xoffset_before = xoffset; const int yoffset_before = yoffset; - const int xoffset_end = int(getScrollWidth() - getViewportWidth()); - const int yoffset_end = int(getScrollHeight() - getViewportHeight()); + const auto xoffset_end = int(getScrollWidth() - getViewportWidth()); + const auto yoffset_end = int(getScrollHeight() - getViewportHeight()); const std::size_t save_width = viewport_geometry.getWidth(); const std::size_t save_height = viewport_geometry.getHeight(); x--; @@ -462,7 +462,7 @@ void FScrollView::drawBorder() //---------------------------------------------------------------------- void FScrollView::onKeyPress (FKeyEvent* ev) { - const int idx = int(ev->key()); + const auto idx = int(ev->key()); if ( key_map.find(idx) != key_map.end() ) { @@ -658,8 +658,8 @@ void FScrollView::copy2area() const int ay = getTermY() - printarea->offset_top; const int dx = viewport_geometry.getX(); const int dy = viewport_geometry.getY(); - int y_end = int(getViewportHeight()); - int x_end = int(getViewportWidth()); + auto y_end = int(getViewportHeight()); + auto x_end = int(getViewportWidth()); // viewport width does not fit into the printarea if ( printarea->width <= ax + x_end ) @@ -694,7 +694,7 @@ void FScrollView::copy2area() // private methods of FScrollView //---------------------------------------------------------------------- -inline const FPoint FScrollView::getViewportCursorPos() const +inline FPoint FScrollView::getViewportCursorPos() const { const auto& window = FWindow::getWindowWidget(this); @@ -726,8 +726,8 @@ void FScrollView::init() resetColors(); setGeometry (FPoint{1, 1}, FSize{4, 4}); setMinimumSize (FSize{4, 4}); - const int xoffset_end = int(getScrollWidth() - getViewportWidth()); - const int yoffset_end = int(getScrollHeight() - getViewportHeight()); + const auto xoffset_end = int(getScrollWidth() - getViewportWidth()); + const auto yoffset_end = int(getScrollHeight() - getViewportHeight()); nf_offset = FTerm::isNewFont() ? 1 : 0; setTopPadding (1 - getScrollY()); setLeftPadding (1 - getScrollX()); @@ -767,7 +767,7 @@ inline void FScrollView::mapKeyFunctions() key_map[fc::Fkey_end] = \ [this] () { - int yoffset_end = int(getScrollHeight() - getViewportHeight()); + auto yoffset_end = int(getScrollHeight() - getViewportHeight()); scrollToY (1 + yoffset_end); }; } diff --git a/src/fstatusbar.cpp b/src/fstatusbar.cpp index 56b7951c..ab53e32b 100644 --- a/src/fstatusbar.cpp +++ b/src/fstatusbar.cpp @@ -516,7 +516,7 @@ void FStatusBar::init() { const auto& r = getRootWidget(); const std::size_t w = r->getWidth(); - const int h = int(r->getHeight()); + const auto h = int(r->getHeight()); // initialize geometry values setGeometry (FPoint{1, h}, FSize{w, 1}, false); setAlwaysOnTop(); @@ -602,7 +602,7 @@ void FStatusBar::drawKeys() } //---------------------------------------------------------------------- -void FStatusBar::drawKey (keyList::const_iterator iter) +void FStatusBar::drawKey (FKeyList::const_iterator iter) { // Draw not active key @@ -660,7 +660,7 @@ void FStatusBar::drawKey (keyList::const_iterator iter) } //---------------------------------------------------------------------- -void FStatusBar::drawActiveKey (keyList::const_iterator iter) +void FStatusBar::drawActiveKey (FKeyList::const_iterator iter) { // Draw active key diff --git a/src/fstring.cpp b/src/fstring.cpp index 0caa249d..a28918eb 100644 --- a/src/fstring.cpp +++ b/src/fstring.cpp @@ -409,13 +409,13 @@ char* FString::c_str() } //---------------------------------------------------------------------- -const std::string FString::toString() const +std::string FString::toString() const { return std::string(c_str(), length); } //---------------------------------------------------------------------- -const FString FString::toLower() const +FString FString::toLower() const { FString s{*this}; auto to_lower = [] (wchar_t& c) @@ -427,7 +427,7 @@ const FString FString::toLower() const } //---------------------------------------------------------------------- -const FString FString::toUpper() const +FString FString::toUpper() const { FString s{*this}; auto to_upper = [] (wchar_t& c) @@ -455,7 +455,7 @@ sInt16 FString::toShort() const //---------------------------------------------------------------------- uInt16 FString::toUShort() const { - const uLong num = uLong(toULong()); + const uLong num = toULong(); if ( num > USHRT_MAX ) throw std::overflow_error ("overflow"); @@ -466,7 +466,7 @@ uInt16 FString::toUShort() const //---------------------------------------------------------------------- int FString::toInt() const { - long num = toLong(); + const long num = toLong(); if ( num > INT_MAX ) throw std::overflow_error ("overflow"); @@ -480,7 +480,7 @@ int FString::toInt() const //---------------------------------------------------------------------- uInt FString::toUInt() const { - const uLong num = uLong(toULong()); + const uLong num = toULong(); if ( num > UINT_MAX ) throw std::overflow_error ("overflow"); @@ -518,7 +518,7 @@ long FString::toLong() const while ( std::iswdigit(std::wint_t(*p)) ) { - uChar d = uChar(*p - L'0'); + auto d = uChar(*p - L'0'); if ( num > tenth_limit || (num == tenth_limit && d > tenth_limit_digit) ) @@ -568,7 +568,7 @@ uLong FString::toULong() const while ( std::iswdigit(std::wint_t(*p)) ) { - const uChar d = uChar(*p - L'0'); + const auto d = uChar(*p - L'0'); if ( num > tenth_limit || (num == tenth_limit && d > tenth_limit_digit) ) @@ -628,7 +628,7 @@ double FString::toDouble() const } //---------------------------------------------------------------------- -const FString FString::ltrim() const +FString FString::ltrim() const { const FString s{*this}; @@ -645,7 +645,7 @@ const FString FString::ltrim() const } //---------------------------------------------------------------------- -const FString FString::rtrim() const +FString FString::rtrim() const { FString s{*this}; @@ -668,7 +668,7 @@ const FString FString::rtrim() const } //---------------------------------------------------------------------- -const FString FString::trim() const +FString FString::trim() const { // handle NULL and empty string if ( ! (string && *string) ) @@ -679,7 +679,7 @@ const FString FString::trim() const } //---------------------------------------------------------------------- -const FString FString::left (std::size_t len) const +FString FString::left (std::size_t len) const { FString s{*this}; @@ -697,7 +697,7 @@ const FString FString::left (std::size_t len) const } //---------------------------------------------------------------------- -const FString FString::right (std::size_t len) const +FString FString::right (std::size_t len) const { const FString s{*this}; @@ -714,7 +714,7 @@ const FString FString::right (std::size_t len) const } //---------------------------------------------------------------------- -const FString FString::mid (std::size_t pos, std::size_t len) const +FString FString::mid (std::size_t pos, std::size_t len) const { const FString s{*this}; @@ -771,7 +771,7 @@ FString& FString::setNumber (sInt64 num) { wchar_t buf[30]{}; wchar_t* s = &buf[29]; // Pointer to the last character - uInt64 abs_num = static_cast(num); + auto abs_num = static_cast(num); if ( num < 0 ) abs_num = static_cast(-num); @@ -847,7 +847,7 @@ FString& FString::setFormatedNumber (sInt64 num, char separator) int n{0}; wchar_t buf[30]{}; wchar_t* s = &buf[29]; // Pointer to the last character - uInt64 abs_num = static_cast(num); + auto abs_num = static_cast(num); if ( separator == 0 ) separator = ' '; @@ -1001,7 +1001,7 @@ const FString& FString::insert (const FString& s, std::size_t pos) } //---------------------------------------------------------------------- -FString const FString::replace (const FString& from, const FString& to) const +FString FString::replace (const FString& from, const FString& to) const { FString s{*this}; @@ -1040,7 +1040,7 @@ FString const FString::replace (const FString& from, const FString& to) const } //---------------------------------------------------------------------- -const FString FString::replaceControlCodes() const +FString FString::replaceControlCodes() const { FString s{*this}; @@ -1066,7 +1066,7 @@ const FString FString::replaceControlCodes() const } //---------------------------------------------------------------------- -const FString FString::expandTabs (int tabstop) const +FString FString::expandTabs (int tabstop) const { FString instr{string}; FString outstr{}; @@ -1079,8 +1079,8 @@ const FString FString::expandTabs (int tabstop) const for (std::size_t i{0}; i < last; i++) { - const std::size_t len = tab_split[i].getLength(); - const std::size_t tab_len = std::size_t(tabstop); + const auto len = tab_split[i].getLength(); + const auto tab_len = std::size_t(tabstop); if ( i == last - 1 ) outstr += tab_split[i]; @@ -1212,7 +1212,7 @@ inline void FString::_initLength (std::size_t len) try { - string = new wchar_t[bufsize](); + string = new wchar_t[bufsize]; std::wmemset (string, L'\0', bufsize); } catch (const std::bad_alloc&) @@ -1244,7 +1244,7 @@ void FString::_assign (const wchar_t s[]) try { - string = new wchar_t[bufsize](); + string = new wchar_t[bufsize]; } catch (const std::bad_alloc&) { @@ -1272,7 +1272,7 @@ void FString::_insert (std::size_t len, const wchar_t s[]) try { - string = new wchar_t[bufsize](); + string = new wchar_t[bufsize]; } catch (const std::bad_alloc&) { @@ -1319,7 +1319,7 @@ void FString::_insert ( std::size_t pos try { - sptr = new wchar_t[bufsize](); // generate new string + sptr = new wchar_t[bufsize]; // generate new string } catch (const std::bad_alloc&) { @@ -1363,7 +1363,7 @@ void FString::_remove (std::size_t pos, std::size_t len) try { - sptr = new wchar_t[bufsize](); // generate new string + sptr = new wchar_t[bufsize]; // generate new string } catch (const std::bad_alloc&) { @@ -1417,7 +1417,7 @@ inline const char* FString::_to_cstring (const wchar_t s[]) const try { - c_string = new char[size](); + c_string = new char[size]; // pre-initialiaze the whole string with '\0' std::memset (c_string, '\0', size); @@ -1467,7 +1467,7 @@ inline const wchar_t* FString::_to_wcstring (const char s[]) const try { - dest = new wchar_t[size](); + dest = new wchar_t[size]; // pre-initialiaze the whole string with '\0' std::wmemset (dest, L'\0', size); } @@ -1527,7 +1527,7 @@ inline const wchar_t* FString::_extractToken ( wchar_t* rest[] // FString non-member operators //---------------------------------------------------------------------- -const FString operator + (const FString& s1, const FString& s2) +FString operator + (const FString& s1, const FString& s2) { FString tmp{s1}; tmp._insert (tmp.length, s2.length, s2.wc_str()); @@ -1535,15 +1535,18 @@ const FString operator + (const FString& s1, const FString& s2) } //---------------------------------------------------------------------- -const FString operator + (const FString& s, const wchar_t c) +FString operator + (const FString& s, const wchar_t c) { - FString tmp{s}; - tmp._insert (tmp.length, 1, &c); - return tmp; + FString tmp1{s}; + wchar_t tmp2[2]; + tmp2[0] = c; + tmp2[1] = L'\0'; + tmp1._insert (tmp1.length, 1, tmp2); + return tmp1; } //---------------------------------------------------------------------- -const FString operator + (const std::wstring& s1, const FString& s2) +FString operator + (const std::wstring& s1, const FString& s2) { FString tmp{s1}; tmp._insert (tmp.length, s2.length, s2.wc_str()); @@ -1551,7 +1554,7 @@ const FString operator + (const std::wstring& s1, const FString& s2) } //---------------------------------------------------------------------- -const FString operator + (const wchar_t s1[], const FString& s2) +FString operator + (const wchar_t s1[], const FString& s2) { FString tmp{s1}; tmp._insert (tmp.length, s2.length, s2.wc_str()); @@ -1559,7 +1562,7 @@ const FString operator + (const wchar_t s1[], const FString& s2) } //---------------------------------------------------------------------- -const FString operator + (const std::string& s1, const FString& s2) +FString operator + (const std::string& s1, const FString& s2) { FString tmp{s1}; tmp._insert (tmp.length, s2.length, s2.wc_str()); @@ -1567,7 +1570,7 @@ const FString operator + (const std::string& s1, const FString& s2) } //---------------------------------------------------------------------- -const FString operator + (const char s1[], const FString& s2) +FString operator + (const char s1[], const FString& s2) { FString tmp{s1}; tmp._insert (tmp.length, s2.length, s2.wc_str()); @@ -1575,7 +1578,7 @@ const FString operator + (const char s1[], const FString& s2) } //---------------------------------------------------------------------- -const FString operator + (const wchar_t c, const FString& s) +FString operator + (const wchar_t c, const FString& s) { FString tmp{c}; tmp._insert (1, s.length, s.wc_str()); @@ -1583,7 +1586,7 @@ const FString operator + (const wchar_t c, const FString& s) } //---------------------------------------------------------------------- -const FString operator + (const char c, const FString& s) +FString operator + (const char c, const FString& s) { FString tmp{c}; tmp._insert (1, s.length, s.wc_str()); @@ -1591,20 +1594,20 @@ const FString operator + (const char c, const FString& s) } //---------------------------------------------------------------------- -const FString operator + (const FString& s, const char c) +FString operator + (const FString& s, const char c) { FString tmp1{s}; wchar_t tmp2[2]; tmp2[0] = wchar_t(c & 0xff); tmp2[1] = L'\0'; - tmp1._insert (s.length, 1, tmp2); + tmp1._insert (tmp1.length, 1, tmp2); return tmp1; } //---------------------------------------------------------------------- std::ostream& operator << (std::ostream& outstr, const FString& s) { - const std::size_t width = std::size_t(outstr.width()); + const auto width = std::size_t(outstr.width()); if ( s.length > 0 ) { @@ -1638,7 +1641,7 @@ std::istream& operator >> (std::istream& instr, FString& s) //---------------------------------------------------------------------- std::wostream& operator << (std::wostream& outstr, const FString& s) { - const std::size_t width = std::size_t(outstr.width()); + const auto width = std::size_t(outstr.width()); if ( s.length > 0 ) { diff --git a/src/fswitch.cpp b/src/fswitch.cpp index 58274d2d..b3d4618f 100644 --- a/src/fswitch.cpp +++ b/src/fswitch.cpp @@ -141,15 +141,15 @@ void FSwitch::drawCheckButton() //---------------------------------------------------------------------- inline void FSwitch::drawChecked() { - wchar_t on[6]{L" On "}; - const wchar_t off[6]{L" Off "}; + FString on{L" On "}; + const FString off{L" Off "}; const auto& wc = getColorTheme(); if ( hasFocus() && ! button_pressed ) { if ( FTerm::isMonochron() ) { - std::wcsncpy (on, L" ", 6); + on.setString(L" "); setBold(true); } else if ( FTerm::getMaxColor() < 16 ) @@ -191,8 +191,8 @@ inline void FSwitch::drawChecked() //---------------------------------------------------------------------- inline void FSwitch::drawUnchecked() { - const wchar_t on[6]{L" On "}; - wchar_t off[6]{L" Off "}; + const FString on{L" On "}; + FString off{L" Off "}; const auto& wc = getColorTheme(); setColor (wc->button_inactive_fg, wc->button_inactive_bg); @@ -206,7 +206,7 @@ inline void FSwitch::drawUnchecked() { if ( FTerm::isMonochron() ) { - std::wcsncpy (off, L"", 6); + off.setString(L""); setBold(true); } else if ( FTerm::getMaxColor() < 16 ) diff --git a/src/fterm.cpp b/src/fterm.cpp index f896f6f3..f4c9b047 100644 --- a/src/fterm.cpp +++ b/src/fterm.cpp @@ -20,6 +20,7 @@ * . * ***********************************************************************/ +#include #include #include #include @@ -158,7 +159,7 @@ std::size_t FTerm::getColumnNumber() } //---------------------------------------------------------------------- -const FString FTerm::getKeyName (FKey keynum) +FString FTerm::getKeyName (FKey keynum) { return keyboard->getKeyName (keynum); } @@ -202,7 +203,7 @@ int FTerm::getMaxColor() //---------------------------------------------------------------------- FTerm::FColorPalettePtr& FTerm::getColorPaletteTheme() { - static FColorPalettePtr* color_theme = new FColorPalettePtr(); + static auto color_theme = new FColorPalettePtr(); return *color_theme; } @@ -712,6 +713,7 @@ bool FTerm::setVGAFont() data->setVGAFont(true); // Set font in xterm to vga getFTermXTerminal()->setFont("vga"); + data->setTermEncoding (fc::PC); data->setNewFont(false); } #if defined(__linux__) @@ -767,7 +769,7 @@ bool FTerm::setNewFont() } //---------------------------------------------------------------------- -bool FTerm::setOldFont() +bool FTerm::resetFont() { bool retval{false}; @@ -820,16 +822,15 @@ int FTerm::openConsole() int fd = data->getTTYFileDescriptor(); const char* termfilename = data->getTermFileName(); - static const char* terminal_devices[] = - { + constexpr std::array terminal_devices = + {{ "/proc/self/fd/0", "/dev/tty", "/dev/tty0", "/dev/vc/0", "/dev/systty", - "/dev/console", - nullptr - }; + "/dev/console" + }}; if ( fd >= 0 ) // console is already opened return 0; @@ -837,9 +838,9 @@ int FTerm::openConsole() if ( ! *termfilename || ! fsys ) return 0; - for (std::size_t i{0}; terminal_devices[i] != nullptr; i++) + for (auto&& entry : terminal_devices) { - fd = fsys->open(terminal_devices[i], O_RDWR, 0); + fd = fsys->open(entry, O_RDWR, 0); data->setTTYFileDescriptor(fd); if ( fd >= 0 ) @@ -1191,11 +1192,11 @@ wchar_t FTerm::charEncode (wchar_t c, fc::encoding enc) { wchar_t ch_enc = c; - for (std::size_t i{0}; i <= fc::lastCharItem; i++) + for (auto&& entry : fc::character) { - if ( fc::character[i][fc::UTF8] == uInt(c) ) + if ( entry[fc::UTF8] == uInt(c) ) { - ch_enc = wchar_t(fc::character[i][enc]); + ch_enc = wchar_t(entry[enc]); break; } } @@ -1235,7 +1236,7 @@ bool FTerm::scrollTermReverse() //---------------------------------------------------------------------- FTerm::defaultPutChar& FTerm::putchar() { - static defaultPutChar* fputchar = new defaultPutChar(); + static auto fputchar = new defaultPutChar(); return *fputchar; } @@ -1362,13 +1363,13 @@ void FTerm::init_global_values() //---------------------------------------------------------------------- void FTerm::init_terminal_device_path() { - char termfilename[256]{}; + std::array termfilename{}; const int stdout_no = FTermios::getStdOut(); - if ( ttyname_r(stdout_no, termfilename, sizeof(termfilename)) ) + if ( ttyname_r(stdout_no, termfilename.data(), termfilename.size()) ) termfilename[0] = '\0'; - data->setTermFileName(termfilename); + data->setTermFileName(termfilename.data()); } //---------------------------------------------------------------------- @@ -1408,8 +1409,8 @@ void FTerm::init_alt_charset() for (std::size_t n{0}; TCAP(fc::t_acs_chars)[n]; n += 2) { // insert the VT100 key/value pairs into a map - const uChar p1 = uChar(TCAP(fc::t_acs_chars)[n]); - const uChar p2 = uChar(TCAP(fc::t_acs_chars)[n + 1]); + const auto p1 = uChar(TCAP(fc::t_acs_chars)[n]); + const auto p2 = uChar(TCAP(fc::t_acs_chars)[n + 1]); vt100_alt_char[p1] = p2; } } @@ -1421,19 +1422,18 @@ void FTerm::init_alt_charset() }; // Update array 'character' with discovered VT100 pairs - for (std::size_t n{0}; n <= fc::lastKeyItem; n++ ) + for (auto&& pair : fc::vt100_key_to_utf8) { - const uChar keyChar = uChar(fc::vt100_key_to_utf8[n][vt100_key]); - const uChar altChar = uChar(vt100_alt_char[keyChar]); - const uInt utf8char = uInt(fc::vt100_key_to_utf8[n][utf8_char]); - const fc::encoding num{fc::NUM_OF_ENCODINGS}; - - uInt* p = std::find ( fc::character[0] - , fc::character[fc::lastCharItem] + num - , utf8char ); - if ( p != fc::character[fc::lastCharItem] + num ) // found in character + const auto keyChar = uChar(pair[vt100_key]); + const auto altChar = uChar(vt100_alt_char[keyChar]); + const auto utf8char = uInt(pair[utf8_char]); + const auto p = std::find_if ( fc::character.begin() + , fc::character.end() + , [&utf8char] (std::array entry) + { return entry[0] == utf8char; } ); + if ( p != fc::character.end() ) // found in character { - const int item = int(std::distance(fc::character[0], p) / num); + const auto item = std::size_t(std::distance(fc::character.begin(), p)); if ( altChar ) // update alternate character set fc::character[item][fc::VT100] = altChar; @@ -1506,24 +1506,24 @@ void FTerm::init_cygwin_charmap() return; // PC encoding changes - for (std::size_t i{0}; i <= fc::lastCharItem; i++ ) + for (auto&& entry : fc::character) { - if ( fc::character[i][fc::UTF8] == fc::BlackUpPointingTriangle ) // ▲ - fc::character[i][fc::PC] = 0x18; + if ( entry[fc::UTF8] == fc::BlackUpPointingTriangle ) // ▲ + entry[fc::PC] = 0x18; - if ( fc::character[i][fc::UTF8] == fc::BlackDownPointingTriangle ) // â–ŧ - fc::character[i][fc::PC] = 0x19; + if ( entry[fc::UTF8] == fc::BlackDownPointingTriangle ) // â–ŧ + entry[fc::PC] = 0x19; - if ( fc::character[i][fc::UTF8] == fc::InverseBullet // ◘ - || fc::character[i][fc::UTF8] == fc::InverseWhiteCircle // ◙ - || fc::character[i][fc::UTF8] == fc::UpDownArrow // ↕ - || fc::character[i][fc::UTF8] == fc::LeftRightArrow // ↔ - || fc::character[i][fc::UTF8] == fc::DoubleExclamationMark // â€ŧ - || fc::character[i][fc::UTF8] == fc::BlackRectangle // â–Ŧ - || fc::character[i][fc::UTF8] == fc::RightwardsArrow // → - || fc::character[i][fc::UTF8] == fc::Section // § - || fc::character[i][fc::UTF8] == fc::SquareRoot ) // SquareRoot √ - fc::character[i][fc::PC] = fc::character[i][fc::ASCII]; + if ( entry[fc::UTF8] == fc::InverseBullet // ◘ + || entry[fc::UTF8] == fc::InverseWhiteCircle // ◙ + || entry[fc::UTF8] == fc::UpDownArrow // ↕ + || entry[fc::UTF8] == fc::LeftRightArrow // ↔ + || entry[fc::UTF8] == fc::DoubleExclamationMark // â€ŧ + || entry[fc::UTF8] == fc::BlackRectangle // â–Ŧ + || entry[fc::UTF8] == fc::RightwardsArrow // → + || entry[fc::UTF8] == fc::Section // § + || entry[fc::UTF8] == fc::SquareRoot ) // SquareRoot √ + entry[fc::PC] = entry[fc::ASCII]; } // General encoding changes @@ -1560,9 +1560,9 @@ void FTerm::init_teraterm_charmap() if ( ! isTeraTerm() ) return; - for (std::size_t i{0}; i <= fc::lastCharItem; i++ ) - if ( fc::character[i][fc::PC] < 0x20 ) - fc::character[i][fc::PC] = fc::character[i][fc::ASCII]; + for (auto&& entry : fc::character) + if ( entry[fc::PC] < 0x20 ) + entry[fc::PC] = entry[fc::ASCII]; } //---------------------------------------------------------------------- @@ -1592,7 +1592,7 @@ void FTerm::init_optiMove() { // Duration precalculation of the cursor movement strings - FOptiMove::termEnv optimove_env = + FOptiMove::TermEnv optimove_env = { TCAP(fc::t_cursor_home), TCAP(fc::t_carriage_return), @@ -1627,7 +1627,7 @@ void FTerm::init_optiAttr() { // Setting video attribute optimization - FOptiAttr::termEnv optiattr_env = + FOptiAttr::TermEnv optiattr_env = { TCAP(fc::t_enter_bold_mode), TCAP(fc::t_exit_bold_mode), @@ -2006,21 +2006,22 @@ const char* FTerm::enableCursorString() // Returns the cursor enable string static constexpr std::size_t SIZE = 32; - static char enable_str[SIZE]{}; + static std::array enable_str{}; const auto& vs = TCAP(fc::t_cursor_visible); const auto& ve = TCAP(fc::t_cursor_normal); if ( ve ) - std::strncpy (enable_str, ve, SIZE - 1); + std::strncpy (enable_str.data(), ve, SIZE - 1); else if ( vs ) - std::strncpy (enable_str, vs, SIZE - 1); + std::strncpy (enable_str.data(), vs, SIZE - 1); #if defined(__linux__) if ( isLinuxTerm() ) { // Restore the last used Linux console cursor style const char* cstyle = linux->getCursorStyleString(); - std::strncat (enable_str, cstyle, SIZE - std::strlen(enable_str) - 1); + std::size_t length = std::strlen(enable_str.data()); + std::strncat (enable_str.data(), cstyle, SIZE - length - 1); } #endif // defined(__linux__) @@ -2034,7 +2035,7 @@ const char* FTerm::enableCursorString() } #endif // defined(__FreeBSD__) || defined(__DragonFly__) || defined(UNIT_TEST) - return enable_str; + return enable_str.data(); } //---------------------------------------------------------------------- @@ -2471,12 +2472,10 @@ void FTerm::initBaudRate() const void FTerm::finish() const { // Set default signal handler - - const auto& title = data->getXtermTitle(); resetSignalHandler(); - if ( title && isXTerminal() && ! isRxvtTerminal() ) - setTermTitle (title); + if ( isXTerminal() && ! isRxvtTerminal() ) + getFTermXTerminal()->resetTitle(); // Restore the saved termios settings FTermios::restoreTTYsettings(); @@ -2531,7 +2530,7 @@ void FTerm::finish() const finish_encoding(); if ( data->isNewFont() || data->isVGAFont() ) - setOldFont(); + resetFont(); } //---------------------------------------------------------------------- diff --git a/src/fterm_functions.cpp b/src/fterm_functions.cpp index 6f838725..0d9dba11 100644 --- a/src/fterm_functions.cpp +++ b/src/fterm_functions.cpp @@ -25,6 +25,7 @@ #endif #include +#include #include #include #include @@ -32,8 +33,10 @@ #include "final/fapplication.h" #include "final/fcharmap.h" #include "final/flog.h" +#include "final/fpoint.h" #include "final/fterm.h" #include "final/ftermbuffer.h" +#include "final/ftermios.h" namespace finalcut @@ -274,11 +277,11 @@ wchar_t cp437_to_unicode (uChar c) constexpr std::size_t UNICODE = 1; wchar_t ucs = c; - for (std::size_t i{0}; i <= fc::lastCP437Item; i++) + for (auto&& entry : fc::cp437_ucs) { - if ( fc::cp437_ucs[i][CP437] == c ) // found + if ( entry[CP437] == c ) // found { - ucs = fc::cp437_ucs[i][UNICODE]; + ucs = entry[UNICODE]; break; } } @@ -293,11 +296,11 @@ uChar unicode_to_cp437 (wchar_t ucs) constexpr std::size_t UNICODE = 1; uChar c{'?'}; - for (std::size_t i{0}; i <= fc::lastCP437Item; i++) + for (auto&& entry : fc::cp437_ucs) { - if ( fc::cp437_ucs[i][UNICODE] == ucs ) // found + if ( entry[UNICODE] == ucs ) // found { - c = uChar(fc::cp437_ucs[i][CP437]); + c = uChar(entry[CP437]); break; } } @@ -306,7 +309,7 @@ uChar unicode_to_cp437 (wchar_t ucs) } //---------------------------------------------------------------------- -const FString getFullWidth (const FString& str) +FString getFullWidth (const FString& str) { // Converts half-width to full-width characters @@ -322,10 +325,10 @@ const FString getFullWidth (const FString& str) } else { - for (std::size_t i{0}; i <= fc::lastHalfWidthItem; i++) + for (auto&& entry : fc::halfwidth_fullwidth) { - if ( fc::halfWidth_fullWidth[i][HALF] == c ) // found - c = fc::halfWidth_fullWidth[i][FULL]; + if ( entry[HALF] == c ) // found + c = entry[FULL]; } } } @@ -334,7 +337,7 @@ const FString getFullWidth (const FString& str) } //---------------------------------------------------------------------- -const FString getHalfWidth (const FString& str) +FString getHalfWidth (const FString& str) { // Converts full-width to half-width characters @@ -350,10 +353,10 @@ const FString getHalfWidth (const FString& str) } else { - for (std::size_t i{0}; i <= fc::lastHalfWidthItem; i++) + for (auto&& entry : fc::halfwidth_fullwidth) { - if ( fc::halfWidth_fullWidth[i][FULL] == c ) // found - c = fc::halfWidth_fullWidth[i][HALF]; + if ( entry[FULL] == c ) // found + c = entry[HALF]; } } } @@ -362,9 +365,9 @@ const FString getHalfWidth (const FString& str) } //---------------------------------------------------------------------- -const FString getColumnSubString ( const FString& str - , std::size_t col_pos - , std::size_t col_len ) +FString getColumnSubString ( const FString& str + , std::size_t col_pos + , std::size_t col_len ) { FString s{str}; std::size_t col_first{1}; @@ -457,8 +460,8 @@ std::size_t getColumnWidth (const FString& s, std::size_t pos) } catch (const std::out_of_range& ex) { - *FApplication::getLog() << FLog::Error - << "Out of Range error: " << ex.what() << std::endl; + std::clog << FLog::Error + << "Out of Range error: " << ex.what() << std::endl; } } @@ -530,4 +533,52 @@ std::size_t getColumnWidth (const FTermBuffer& tb) ); } +//---------------------------------------------------------------------- +FPoint readCursorPos() +{ + int x{-1}; + int y{-1}; + const int stdin_no{FTermios::getStdIn()}; + const int stdout_no{FTermios::getStdOut()}; + fd_set ifds{}; + struct timeval tv{}; + constexpr auto& DECXCPR{ESC "[6n"}; + + // Report Cursor Position (DECXCPR) + if ( write(stdout_no, DECXCPR, std::strlen(DECXCPR)) < 1 ) + return FPoint{x, y}; + + std::fflush(stdout); + FD_ZERO(&ifds); + FD_SET(stdin_no, &ifds); + tv.tv_sec = 0; + tv.tv_usec = 100000; // 100 ms + std::array temp{}; + std::size_t pos{0}; + + // Read the answer + if ( select (stdin_no + 1, &ifds, nullptr, nullptr, &tv) != 1 ) + return FPoint{x, y}; + + do + { + std::size_t bytes_free = temp.size() - pos - 1; + const ssize_t bytes = read(stdin_no, &temp[pos], bytes_free); + + if ( bytes <= 0 ) + break; + + pos += std::size_t(bytes); + } + while ( pos < temp.size() && ! std::strchr(temp.data(), 'R') ); + + if ( pos > 4 ) + { + constexpr auto parse = "\033[%4d;%4dR"; + std::sscanf(temp.data(), parse, &x, &y); + } + + return FPoint{x, y}; +} + } // namespace finalcut diff --git a/src/ftermbuffer.cpp b/src/ftermbuffer.cpp index 81c3ec88..f5b61a9c 100644 --- a/src/ftermbuffer.cpp +++ b/src/ftermbuffer.cpp @@ -43,7 +43,7 @@ FTermBuffer::~FTermBuffer() // destructor // public methods of FTermBuffer //---------------------------------------------------------------------- -const FString FTermBuffer::toString() const +FString FTermBuffer::toString() const { std::wstring wide_string{}; wide_string.reserve(data.size()); @@ -62,7 +62,7 @@ const FString FTermBuffer::toString() const int FTermBuffer::write (const FString& string) { assert ( ! string.isNull() ); - const int len = int(string.getLength()); + const auto len = int(string.getLength()); for (auto&& c : string) { diff --git a/src/ftermcap.cpp b/src/ftermcap.cpp index 8c695bc1..ae2f712e 100644 --- a/src/ftermcap.cpp +++ b/src/ftermcap.cpp @@ -27,6 +27,7 @@ #include "final/emptyfstring.h" #include "final/fc.h" #include "final/fkey_map.h" +#include "final/flog.h" #include "final/fsystem.h" #include "final/fterm.h" #include "final/ftermdata.h" @@ -90,7 +91,7 @@ void FTermcap::termcap() // Open termcap file #if defined(__sun) && defined(__SVR4) - char* termtype = fterm_data->getTermType(); + char* termtype = const_cast(fterm_data->getTermType()); #else const char* termtype = fterm_data->getTermType(); #endif @@ -127,23 +128,22 @@ void FTermcap::termcapError (int status) static constexpr int no_entry = 0; static constexpr int db_not_found = -1; static constexpr int uninitialized = -2; - finalcut::FLog& log = *FApplication::getLog(); if ( status == no_entry || status == uninitialized ) { const char* termtype = fterm_data->getTermType(); - log << FLog::Error - << "Unknown terminal: \"" << termtype << "\". " - << "Check the TERM environment variable. " - << "Also make sure that the terminal " - << "is defined in the termcap/terminfo database." - << std::endl; + std::clog << FLog::Error + << "Unknown terminal: \"" << termtype << "\". " + << "Check the TERM environment variable. " + << "Also make sure that the terminal " + << "is defined in the termcap/terminfo database." + << std::endl; std::abort(); } else if ( status == db_not_found ) { - log << "The termcap/terminfo database could not be found." - << std::endl; + std::clog << "The termcap/terminfo database could not be found." + << std::endl; std::abort(); } } @@ -224,8 +224,9 @@ void FTermcap::termcapStrings() // Get termcap strings // Read termcap output strings - for (std::size_t i{0}; strings[i].tname[0] != 0; i++) - strings[i].string = getString(strings[i].tname); + + for (auto&& entry : strings) + entry.string = getString(entry.tname); const auto& ho = TCAP(fc::t_cursor_home); @@ -239,10 +240,13 @@ void FTermcap::termcapKeys() // Get termcap keys // Read termcap key sequences up to the self-defined values - for ( std::size_t i{0}; - fc::fkey[i].string == nullptr && fc::fkey[i].tname[0] != 0; - i++ ) - fc::fkey[i].string = getString(fc::fkey[i].tname); + for (auto&& entry : fc::fkey) + { + if ( entry.string != nullptr ) + break; + + entry.string = getString(entry.tname); + } } //---------------------------------------------------------------------- @@ -257,8 +261,8 @@ int FTermcap::_tputs (const char* str, int affcnt, fn_putc putc) // private Data Member of FTermcap - termcap capabilities //---------------------------------------------------------------------- -FTermcap::tcap_map FTermcap::strings[] = -{ +FTermcap::TCapMapType FTermcap::strings = +{{ // .------------- term string // | .-------- Tcap-code // | | // variable name -> description @@ -347,9 +351,8 @@ FTermcap::tcap_map FTermcap::strings[] = { nullptr, "ac" }, // acs_chars -> graphics charset pairs (vt100) { nullptr, "ks" }, // keypad_xmit -> enter 'key-board_transmit' mode { nullptr, "ke" }, // keypad_local -> leave 'key-board_transmit' mode - { nullptr, "Km" }, // key_mouse -> Mouse event has occurred - { nullptr, "\0" } -}; + { nullptr, "Km" } // key_mouse -> Mouse event has occurred +}}; /* * (P) indicates that padding may be specified diff --git a/src/ftermcapquirks.cpp b/src/ftermcapquirks.cpp index 07faf1bd..ca93d2a8 100644 --- a/src/ftermcapquirks.cpp +++ b/src/ftermcapquirks.cpp @@ -20,6 +20,7 @@ * . * ***********************************************************************/ +#include #include #include "final/fc.h" @@ -267,6 +268,25 @@ void FTermcapQuirks::vte() // set exit underline for gnome terminal TCAP(fc::t_exit_underline_mode) = \ CSI "24m"; + + if ( term_detection->getGnomeTerminalID() >= 5300 ) // vte >= 0.53.0 + { + if ( ! std::strstr(TCAP(fc::t_enter_ca_mode), "\033[22;0;0t") ) + { + // Save the cursor position, enter alternate screen buffer + // and save xterm icon and window title on stack + TCAP(fc::t_enter_ca_mode) = \ + CSI "?1049h" CSI "22;0;0t"; + } + + if ( ! std::strstr(TCAP(fc::t_exit_ca_mode), "\033[23;0;0t") ) + { + // Use normal screen buffer, restore the cursor position + // and restore xterm icon and window title from stack + TCAP(fc::t_exit_ca_mode) = \ + CSI "?1049l" CSI "23;0;0t"; + } + } } //---------------------------------------------------------------------- diff --git a/src/ftermdetection.cpp b/src/ftermdetection.cpp index 5f552054..d4d545de 100644 --- a/src/ftermdetection.cpp +++ b/src/ftermdetection.cpp @@ -24,10 +24,13 @@ #include "final/fconfig.h" // includes _GNU_SOURCE for fd_set #endif +#include + #include "final/emptyfstring.h" #include "final/fapplication.h" #include "final/fc.h" #include "final/flog.h" +#include "final/fkeyboard.h" #include "final/fsystem.h" #include "final/fterm.h" #include "final/ftermcap.h" @@ -53,6 +56,7 @@ FTermDetection::colorEnv FTermDetection::color_env{}; FTermDetection::secondaryDA FTermDetection::secondary_da{}; FTermData* FTermDetection::fterm_data{nullptr}; FSystem* FTermDetection::fsystem{nullptr}; +FKeyboard* FTermDetection::keyboard{nullptr}; char FTermDetection::termtype[256]{}; char FTermDetection::ttytypename[256]{}; bool FTermDetection::decscusr_support{}; @@ -130,6 +134,7 @@ void FTermDetection::detect() { fterm_data = FTerm::getFTermData(); fsystem = FTerm::getFSystem(); + keyboard = FTerm::getFKeyboard(); deallocation(); // Set the variable 'termtype' to the predefined type of the terminal @@ -320,6 +325,14 @@ void FTermDetection::termtypeAnalysis() if ( std::strncmp(termtype, "mlterm", 6) == 0 ) terminal_type.mlterm = true; + // rxvt + if ( std::strncmp(termtype, "rxvt", 4) == 0 ) + terminal_type.rxvt = true; + + // urxvt + if ( std::strncmp(termtype, "rxvt-unicode", 12) == 0 ) + terminal_type.urxvt = true; + // screen/tmux if ( std::strncmp(termtype, "screen", 6) == 0 ) { @@ -350,6 +363,7 @@ void FTermDetection::detectTerminal() if ( terminal_detection ) { FTermios::setCaptureSendCharacters(); + keyboard->setNonBlockingInput(); // Initialize 256 colors terminals new_termtype = init_256colorTerminal(); @@ -363,6 +377,7 @@ void FTermDetection::detectTerminal() // Determines the maximum number of colors new_termtype = determineMaxColor(new_termtype); + keyboard->unsetNonBlockingInput(); FTermios::unsetCaptureSendCharacters(); } @@ -517,6 +532,7 @@ const char* FTermDetection::determineMaxColor (const char current_termtype[]) // Determine xterm maximum number of colors via OSC 4 const char* new_termtype = current_termtype; + keyboard->setNonBlockingInput(); if ( ! color256 && ! isCygwinTerminal() @@ -544,13 +560,15 @@ const char* FTermDetection::determineMaxColor (const char current_termtype[]) } } + keyboard->unsetNonBlockingInput(); return new_termtype; } //---------------------------------------------------------------------- -const FString FTermDetection::getXTermColorName (FColor color) +FString FTermDetection::getXTermColorName (FColor color) { FString color_str{""}; + std::array buf{}; fd_set ifds{}; struct timeval tv{}; const int stdin_no = FTermios::getStdIn(); @@ -558,28 +576,44 @@ const FString FTermDetection::getXTermColorName (FColor color) // get color std::fprintf (stdout, OSC "4;%hu;?" BEL, color); std::fflush (stdout); - - char temp[512]{}; FD_ZERO(&ifds); FD_SET(stdin_no, &ifds); tv.tv_sec = 0; tv.tv_usec = 150000; // 150 ms // read the terminal answer - if ( select (stdin_no + 1, &ifds, nullptr, nullptr, &tv) > 0 - && std::scanf("\033]4;%10hu;%509[^\n]s", &color, temp) == 2 ) + if ( select (stdin_no + 1, &ifds, nullptr, nullptr, &tv) < 1 ) + return color_str; + + constexpr auto parse = "\033]4;%10hu;%509[^\n]s"; + std::array temp{}; + std::size_t pos{0}; + + do { - std::size_t n = std::strlen(temp); + std::size_t bytes_free = temp.size() - pos - 1; + const ssize_t bytes = read(stdin_no, &temp[pos], bytes_free); + + if ( bytes <= 0 ) + break; + + pos += std::size_t(bytes); + } + while ( pos < temp.size() ); + + if ( pos > 4 && std::sscanf(temp.data(), parse, &color, buf.data()) == 2 ) + { + std::size_t n = std::strlen(buf.data()); // BEL + '\0' = string terminator - if ( n >= 6 && temp[n - 1] == BEL[0] && temp[n] == '\0' ) - temp[n - 1] = '\0'; + if ( n >= 6 && buf[n - 1] == BEL[0] && buf[n] == '\0' ) + buf[n - 1] = '\0'; // Esc + \ = OSC string terminator (mintty) - if ( n >= 6 && temp[n - 2] == ESC[0] && temp[n - 1] == '\\' ) - temp[n - 2] = '\0'; + if ( n >= 6 && buf[n - 2] == ESC[0] && buf[n - 1] == '\\' ) + buf[n - 2] = '\0'; - color_str = temp; + color_str = buf.data(); } return color_str; @@ -589,11 +623,14 @@ const FString FTermDetection::getXTermColorName (FColor color) const char* FTermDetection::parseAnswerbackMsg (const char current_termtype[]) { const char* new_termtype = current_termtype; - + keyboard->setNonBlockingInput(); // send ENQ and read the answerback message + const auto& ans = getAnswerbackMsg(); + keyboard->unsetNonBlockingInput(); + try { - answer_back = new FString(getAnswerbackMsg()); + answer_back = new FString(ans); } catch (const std::bad_alloc&) { @@ -611,9 +648,10 @@ const char* FTermDetection::parseAnswerbackMsg (const char current_termtype[]) new_termtype = "putty"; } - // cygwin needs a backspace to delete the 'â™Ŗ' char - if ( isCygwinTerminal() || isWindowsTerminal() ) - FTerm::putstring (BS " " BS); + // Some terminals like cygwin or the Windows terminal + // have to delete the printed character 'â™Ŗ' + std::fprintf (stdout, "\r " BS); + std::fflush (stdout); #if DEBUG if ( new_termtype ) @@ -629,26 +667,41 @@ const char* FTermDetection::parseAnswerbackMsg (const char current_termtype[]) } //---------------------------------------------------------------------- -const FString FTermDetection::getAnswerbackMsg() +FString FTermDetection::getAnswerbackMsg() { FString answerback{""}; fd_set ifds{}; struct timeval tv{}; - char temp[10]{}; const int stdin_no = FTermios::getStdIn(); - - std::putchar (ENQ[0]); // Send enquiry character + // Send enquiry character + std::putchar (ENQ[0]); std::fflush(stdout); - FD_ZERO(&ifds); FD_SET(stdin_no, &ifds); tv.tv_sec = 0; tv.tv_usec = 150000; // 150 ms // Read the answerback message - if ( select (stdin_no + 1, &ifds, nullptr, nullptr, &tv) > 0 - && std::fgets (temp, sizeof(temp) - 1, stdin) != nullptr ) - answerback = temp; + if ( select (stdin_no + 1, &ifds, nullptr, nullptr, &tv) < 1 ) + return answerback; + + std::array temp{}; + std::size_t pos{0}; + + do + { + std::size_t bytes_free = temp.size() - pos - 1; + const ssize_t bytes = read(stdin_no, &temp[pos], bytes_free); + + if ( bytes <= 0 ) + break; + + pos += std::size_t(bytes); + } + while ( pos < temp.size() ); + + if ( pos > 0 ) + answerback = temp.data(); return answerback; } @@ -660,10 +713,13 @@ const char* FTermDetection::parseSecDA (const char current_termtype[]) if ( isLinuxTerm() || isCygwinTerminal() ) return current_termtype; + // Secondary device attributes (SEC_DA) <- decTerminalID string + const auto& ans = getSecDA(); + try { // Secondary device attributes (SEC_DA) <- decTerminalID string - sec_da = new FString(getSecDA()); + sec_da = new FString(ans); } catch (const std::bad_alloc&) { @@ -746,7 +802,7 @@ int FTermDetection::str2int (const FString& s) } //---------------------------------------------------------------------- -const FString FTermDetection::getSecDA() +FString FTermDetection::getSecDA() { FString sec_da_str{""}; @@ -757,11 +813,10 @@ const FString FTermDetection::getSecDA() const int stdout_no{FTermios::getStdOut()}; fd_set ifds{}; struct timeval tv{}; + constexpr auto& SECDA{ESC "[>c"}; // Get the secondary device attributes - const ssize_t ret = write(stdout_no, SECDA, std::strlen(SECDA)); - - if ( ret == -1 ) + if ( write(stdout_no, SECDA, std::strlen(SECDA)) == -1 ) return sec_da_str; std::fflush(stdout); @@ -771,9 +826,27 @@ const FString FTermDetection::getSecDA() tv.tv_usec = 600000; // 600 ms // Read the answer - if ( select (stdin_no + 1, &ifds, nullptr, nullptr, &tv) == 1 - && std::scanf("\033[>%10d;%10d;%10dc", &a, &b, &c) == 3 ) - sec_da_str.sprintf("\033[>%d;%d;%dc", a, b, c); + if ( select (stdin_no + 1, &ifds, nullptr, nullptr, &tv) < 1 ) + return sec_da_str; + + constexpr auto parse = "\033[>%10d;%10d;%10dc"; + std::array temp{}; + std::size_t pos{0}; + + do + { + std::size_t bytes_free = temp.size() - pos - 1; + const ssize_t bytes = read(stdin_no, &temp[pos], bytes_free); + + if ( bytes <= 0 ) + break; + + pos += std::size_t(bytes); + } + while ( pos < temp.size() && ! std::strchr(temp.data(), 'c') ); + + if ( pos > 3 && std::sscanf(temp.data(), parse, &a, &b, &c) == 3 ) + sec_da_str.sprintf("\033[>%d;%d;%dc", a, b, c); return sec_da_str; } diff --git a/src/ftermfreebsd.cpp b/src/ftermfreebsd.cpp index 69edb8a9..ee6a08cc 100644 --- a/src/ftermfreebsd.cpp +++ b/src/ftermfreebsd.cpp @@ -171,9 +171,9 @@ void FTermFreeBSD::initCharMap() if ( ! isFreeBSDConsole() ) return; - for (std::size_t i{0}; i <= fc::lastCharItem; i++) - if ( fc::character[i][fc::PC] < 0x1c ) - fc::character[i][fc::PC] = fc::character[i][fc::ASCII]; + for (auto&& entry : fc::character) + if ( entry[fc::PC] < 0x1c ) + entry[fc::PC] = entry[fc::ASCII]; } //---------------------------------------------------------------------- @@ -195,11 +195,11 @@ void FTermFreeBSD::finish() //---------------------------------------------------------------------- void FTermFreeBSD::warnNotInitialized() { - *FApplication::getLog() << FLog::Warn - << "The FTermFreeBSD object has " - << "not yet been initialized! " - << "Please call the init() method first." - << std::endl; + std::clog << FLog::Warn + << "The FTermFreeBSD object has " + << "not yet been initialized! " + << "Please call the init() method first." + << std::endl; } //---------------------------------------------------------------------- diff --git a/src/ftermios.cpp b/src/ftermios.cpp index c3c17765..6abb3249 100644 --- a/src/ftermios.cpp +++ b/src/ftermios.cpp @@ -153,7 +153,7 @@ void FTermios::setCaptureSendCharacters() struct termios t{}; tcgetattr (stdin_no, &t); t.c_lflag &= uInt(~(ICANON | ECHO)); - t.c_cc[VTIME] = 1; // Timeout in deciseconds + t.c_cc[VTIME] = 10; // Timeout in deciseconds t.c_cc[VMIN] = 0; // Minimum number of characters tcsetattr (stdin_no, TCSANOW, &t); } diff --git a/src/ftermlinux.cpp b/src/ftermlinux.cpp index 8023a248..fa1534a6 100644 --- a/src/ftermlinux.cpp +++ b/src/ftermlinux.cpp @@ -20,6 +20,7 @@ * . * ***********************************************************************/ +#include #include #include "final/fapplication.h" @@ -75,10 +76,10 @@ char* FTermLinux::getCursorStyleString() { // Gets the current cursor style string of the Linux console - static char buf[16]{}; + static std::array buf{}; std::fill (std::begin(buf), std::end(buf), '\0'); - std::snprintf (buf, sizeof(buf), CSI "?%dc", getCursorStyle()); - return buf; + std::snprintf (buf.data(), buf.size(), CSI "?%dc", getCursorStyle()); + return buf.data(); } //---------------------------------------------------------------------- @@ -202,7 +203,7 @@ void FTermLinux::init() } else { - FApplication::getLog()->error("Can not open the console."); + std::clog << FLog::Error << "Can not open the console." << std::endl; std::abort(); } } @@ -217,14 +218,14 @@ void FTermLinux::initCharMap() if ( screen_unicode_map.entry_ct > 0 && screen_unicode_map.entries ) { - for (std::size_t i{0}; i <= fc::lastCharItem; i++ ) + for (auto&& entry : fc::character) { - const auto ucs = wchar_t(fc::character[i][fc::UTF8]); + const auto ucs = wchar_t(entry[fc::UTF8]); const sInt16 fontpos = getFontPos(ucs); // Fix for a non-cp437 Linux console with PC charset encoding if ( fontpos > 255 || fontpos == NOT_FOUND ) - fc::character[i][fc::PC] = fc::character[i][fc::ASCII]; + entry[fc::PC] = entry[fc::ASCII]; // Character substitutions for missing characters if ( fontpos == NOT_FOUND ) @@ -278,7 +279,7 @@ bool FTermLinux::loadVGAFont() struct unimapdesc unimap; unimap.entry_ct = uInt16 ( sizeof(fc::unicode_cp437_pairs) / sizeof(unipair) ); - unimap.entries = &fc::unicode_cp437_pairs[0]; + unimap.entries = const_cast(&fc::unicode_cp437_pairs[0]); setUnicodeMap(&unimap); } else @@ -315,9 +316,11 @@ bool FTermLinux::loadNewFont() // Set the graphical font int ret; +#if defined(ISA_SYSCTL_SUPPORT) if ( has9BitCharacters() ) ret = setScreenFont(fc::__9x16graph, 256, 8, 16); // set 9×16 else +#endif ret = setScreenFont(fc::__8x16graph, 256, 8, 16); // set 8×16 if ( ret != 0 ) @@ -327,7 +330,7 @@ bool FTermLinux::loadNewFont() struct unimapdesc unimap; unimap.entry_ct = uInt16 ( sizeof(fc::unicode_newfont_pairs) / sizeof(unipair) ); - unimap.entries = &fc::unicode_newfont_pairs[0]; + unimap.entries = const_cast(&fc::unicode_newfont_pairs[0]); setUnicodeMap(&unimap); } else @@ -460,7 +463,7 @@ FKey FTermLinux::modifierKeyCorrection (const FKey& key_id) if ( ! fsystem ) fsystem = FTerm::getFSystem(); - const modifier_key& m = getModifierKey(); + const ModifierKey& m = getModifierKey(); if ( ! (m.shift || m.ctrl || m.alt) ) { @@ -631,7 +634,7 @@ bool FTermLinux::getUnicodeMap() } //---------------------------------------------------------------------- -FTermLinux::modifier_key& FTermLinux::getModifierKey() +FTermLinux::ModifierKey& FTermLinux::getModifierKey() { // Get Linux console shift state @@ -660,7 +663,7 @@ FTermLinux::modifier_key& FTermLinux::getModifierKey() } //---------------------------------------------------------------------- -int FTermLinux::setScreenFont ( uChar fontdata[], uInt count +int FTermLinux::setScreenFont ( const uChar fontdata[], uInt count , uInt fontwidth, uInt fontheight , bool direct) { @@ -681,7 +684,7 @@ int FTermLinux::setScreenFont ( uChar fontdata[], uInt count font.charcount = count; if ( direct ) - font.data = fontdata; + font.data = const_cast(fontdata); else { const std::size_t bytes_per_line = font.width / 8; @@ -698,9 +701,9 @@ int FTermLinux::setScreenFont ( uChar fontdata[], uInt count } for (std::size_t i{0}; i < count; i++) - std::memcpy ( const_cast(font.data + bytes_per_line * 32 * i) + std::memcpy ( font.data + bytes_per_line * 32 * i , &fontdata[i * font.height] - , font.height); + , font.height ); } // Font operation @@ -932,8 +935,8 @@ void FTermLinux::getVGAPalette() //---------------------------------------------------------------------- void FTermLinux::setVGADefaultPalette() { - constexpr rgb defaultColor[16] = - { + constexpr std::array defaultColor = + {{ {0x00, 0x00, 0x00}, {0xaa, 0x00, 0x00}, {0x00, 0xaa, 0x00}, {0xaa, 0x55, 0x00}, {0x00, 0x00, 0xaa}, {0xaa, 0x00, 0xaa}, @@ -942,7 +945,7 @@ void FTermLinux::setVGADefaultPalette() {0x55, 0xff, 0x55}, {0xff, 0xff, 0x55}, {0x55, 0x55, 0xff}, {0xff, 0x55, 0xff}, {0x55, 0xff, 0xff}, {0xff, 0xff, 0xff} - }; + }}; for (std::size_t index{0}; index < 16; index++) { diff --git a/src/ftermopenbsd.cpp b/src/ftermopenbsd.cpp index 8d12b856..6b789543 100644 --- a/src/ftermopenbsd.cpp +++ b/src/ftermopenbsd.cpp @@ -162,11 +162,11 @@ bool FTermOpenBSD::resetBeep() //---------------------------------------------------------------------- void FTermOpenBSD::warnNotInitialized() { - *FApplication::getLog() << FLog::Warn - << "The FTermOpenBSD object has " - << "not yet been initialized! " - << "Please call the init() method first." - << std::endl; + std::clog << FLog::Warn + << "The FTermOpenBSD object has " + << "not yet been initialized! " + << "Please call the init() method first." + << std::endl; } //---------------------------------------------------------------------- diff --git a/src/ftermxterminal.cpp b/src/ftermxterminal.cpp index 9c19ee5d..d9651dd6 100644 --- a/src/ftermxterminal.cpp +++ b/src/ftermxterminal.cpp @@ -24,9 +24,12 @@ #include "final/fconfig.h" // includes _GNU_SOURCE for fd_set #endif +#include + #include "final/fapplication.h" #include "final/fc.h" #include "final/flog.h" +#include "final/fkeyboard.h" #include "final/fstring.h" #include "final/fterm.h" #include "final/ftermcap.h" @@ -49,8 +52,9 @@ namespace finalcut { // static class attributes -bool FTermXTerminal::mouse_support{false}; -FSystem* FTermXTerminal::fsystem{nullptr}; +bool FTermXTerminal::mouse_support{false}; +FSystem* FTermXTerminal::fsystem{nullptr}; +FKeyboard* FTermXTerminal::keyboard{nullptr}; //---------------------------------------------------------------------- @@ -63,6 +67,7 @@ FTermXTerminal::FTermXTerminal() { // Get FSystem object fsystem = FTerm::getFSystem(); + keyboard = FTerm::getFKeyboard(); } //---------------------------------------------------------------------- @@ -290,6 +295,13 @@ void FTermXTerminal::resetDefaults() } } +//---------------------------------------------------------------------- +void FTermXTerminal::resetTitle() +{ + if ( title_was_changed ) + setTitle(xterm_title); +} + //---------------------------------------------------------------------- void FTermXTerminal::captureFontAndTitle() { @@ -300,8 +312,10 @@ void FTermXTerminal::captureFontAndTitle() && ! term_detection->isRxvtTerminal() ) { FTermios::setCaptureSendCharacters(); + keyboard->setNonBlockingInput(); xterm_font = captureXTermFont(); xterm_title = captureXTermTitle(); + keyboard->unsetNonBlockingInput(); FTermios::unsetCaptureSendCharacters(); } } @@ -311,11 +325,11 @@ void FTermXTerminal::captureFontAndTitle() //---------------------------------------------------------------------- void FTermXTerminal::warnNotInitialized() const { - *FApplication::getLog() << FLog::Warn - << "The FTermXTerminal object has " - << "not yet been initialized! " - << "Please call the init() method first." - << std::endl; + std::clog << FLog::Warn + << "The FTermXTerminal object has " + << "not yet been initialized! " + << "Please call the init() method first." + << std::endl; } //---------------------------------------------------------------------- @@ -356,15 +370,21 @@ void FTermXTerminal::setXTermTitle() if ( term_detection->isXTerminal() || term_detection->isScreenTerm() + || term_detection->isUrxvtTerminal() || term_detection->isCygwinTerminal() || term_detection->isMinttyTerm() || term_detection->isPuttyTerminal() || FTermcap::osc_support ) { oscPrefix(); + + if ( xterm_title.isNull() ) + xterm_title = ""; + FTerm::putstringf (OSC "0;%s" BEL, xterm_title.c_str()); oscPostfix(); std::fflush(stdout); + title_was_changed = true; } } @@ -743,51 +763,69 @@ void FTermXTerminal::oscPostfix() const } //---------------------------------------------------------------------- -const FString FTermXTerminal::captureXTermFont() const +FString FTermXTerminal::captureXTermFont() const { initCheck(FString{}); - if ( term_detection->isXTerminal() - || term_detection->isScreenTerm() - || FTermcap::osc_support ) + if ( ! term_detection->isXTerminal() + && ! term_detection->isScreenTerm() + && ! FTermcap::osc_support ) { - fd_set ifds{}; - struct timeval tv{}; - const int stdin_no = FTermios::getStdIn(); + return FString{}; + } - oscPrefix(); - FTerm::putstring (OSC "50;?" BEL); // get font - oscPostfix(); - std::fflush(stdout); + fd_set ifds{}; + struct timeval tv{}; + const int stdin_no = FTermios::getStdIn(); - FD_ZERO(&ifds); - FD_SET(stdin_no, &ifds); - tv.tv_sec = 0; - tv.tv_usec = 150000; // 150 ms + // Querying the terminal font + oscPrefix(); + FTerm::putstring (OSC "50;?" BEL); + oscPostfix(); + std::fflush(stdout); + FD_ZERO(&ifds); + FD_SET(stdin_no, &ifds); + tv.tv_sec = 0; + tv.tv_usec = 150000; // 150 ms - // Read the terminal answer - if ( select(stdin_no + 1, &ifds, nullptr, nullptr, &tv) > 0 ) - { - char temp[150]{}; + // Read the terminal answer + if ( select(stdin_no + 1, &ifds, nullptr, nullptr, &tv) < 1 ) + return FString{}; - if ( std::scanf("\033]50;%148[^\n]s", temp) == 1 ) - { - const std::size_t n = std::strlen(temp); + std::array temp{}; + std::size_t pos{0}; - // BEL + '\0' = string terminator - if ( n >= 5 && temp[n - 1] == BEL[0] && temp[n] == '\0' ) - temp[n - 1] = '\0'; + do + { + std::size_t bytes_free = temp.size() - pos - 1; + const ssize_t bytes = read(stdin_no, &temp[pos], bytes_free); - return FString{temp}; - } - } + if ( bytes <= 0 ) + break; + + pos += std::size_t(bytes); + } + while ( pos < temp.size() && ! std::strchr(temp.data(), '\a') ); + + if ( pos > 5 && temp[0] == ESC[0] && temp[1] == ']' && temp[2] == '5' + && temp[3] == '0' && temp[4] == ';' ) + { + // Skip leading Esc ] 5 0 ; + char* str = &temp[5]; + const std::size_t n = std::strlen(str); + + // BEL + '\0' = string terminator + if ( n >= 5 && str[n - 1] == BEL[0] && str[n] == '\0' ) + str[n - 1] = '\0'; + + return FString{str}; } return FString{}; } //---------------------------------------------------------------------- -const FString FTermXTerminal::captureXTermTitle() const +FString FTermXTerminal::captureXTermTitle() const { initCheck(FString{}); @@ -796,34 +834,49 @@ const FString FTermXTerminal::captureXTermTitle() const fd_set ifds{}; struct timeval tv{}; - const int stdin_no = FTermios::getStdIn(); + const int stdin_no{FTermios::getStdIn()}; - FTerm::putstring (CSI "21t"); // get title + // Report window title + FTerm::putstring (CSI "21t"); std::fflush(stdout); - FD_ZERO(&ifds); FD_SET(stdin_no, &ifds); tv.tv_sec = 0; tv.tv_usec = 150000; // 150 ms // read the terminal answer - if ( select (stdin_no + 1, &ifds, nullptr, nullptr, &tv) > 0 ) + if ( select (stdin_no + 1, &ifds, nullptr, nullptr, &tv) < 1 ) + return FString{}; + + std::array temp{}; + std::size_t pos{0}; + + do { - char temp[512]{}; + std::size_t bytes_free = temp.size() - pos - 1; + const ssize_t bytes = read(stdin_no, &temp[pos], bytes_free); - if ( std::scanf("\033]l%509[^\n]s", temp) == 1 ) + if ( bytes <= 0 ) + break; + + pos += std::size_t(bytes); + } + while ( pos < temp.size() && std::strstr(temp.data(), ESC "\\") == nullptr ); + + if ( pos > 6 && temp[0] == ESC[0] && temp[1] == ']' && temp[2] == 'l' ) + { + // Skip leading Esc + ] + l = OSC l + char* str = &temp[3]; + const std::size_t n = std::strlen(str); + + // Esc + \ = OSC string terminator + if ( n >= 2 && str[n - 2] == ESC[0] && str[n - 1] == '\\' ) { - const std::size_t n = std::strlen(temp); + if ( n < 4 ) + return FString{}; - // Esc + \ = OSC string terminator - if ( n >= 2 && temp[n - 2] == ESC[0] && temp[n - 1] == '\\' ) - { - if ( n < 4 ) - return FString{}; - - temp[n - 2] = '\0'; - return FString{temp}; - } + str[n - 2] = '\0'; + return FString{str}; } } diff --git a/src/ftextview.cpp b/src/ftextview.cpp index 7671fa09..961ce175 100644 --- a/src/ftextview.cpp +++ b/src/ftextview.cpp @@ -54,7 +54,7 @@ FTextView::~FTextView() // destructor // public methods of FTextView //---------------------------------------------------------------------- -const FString FTextView::getText() const +FString FTextView::getText() const { if ( data.empty() ) return FString{""}; @@ -149,7 +149,7 @@ void FTextView::scrollTo (int x, int y) if ( changeX && isHorizontallyScrollable() ) { - const int xoffset_end = int(max_line_width - getTextWidth()); + const auto xoffset_end = int(max_line_width - getTextWidth()); xoffset = x; if ( xoffset < 0 ) @@ -167,7 +167,7 @@ void FTextView::scrollTo (int x, int y) if ( changeY && isVerticallyScrollable() ) { - const int yoffset_end = int(getRows() - getTextHeight()); + const auto yoffset_end = int(getRows() - getTextHeight()); yoffset = y; if ( yoffset < 0 ) @@ -335,7 +335,7 @@ void FTextView::clear() //---------------------------------------------------------------------- void FTextView::onKeyPress (FKeyEvent* ev) { - const int idx = int(ev->key()); + const auto idx = int(ev->key()); if ( key_map.find(idx) != key_map.end() ) { @@ -504,8 +504,8 @@ void FTextView::adjustSize() FWidget::adjustSize(); const std::size_t width = getWidth(); const std::size_t height = getHeight(); - const int last_line = int(getRows()); - const int max_width = int(max_line_width); + const auto last_line = int(getRows()); + const auto max_width = int(max_line_width); if ( xoffset >= max_width - int(width) - nf_offset ) xoffset = max_width - int(width) - nf_offset - 1; @@ -535,7 +535,7 @@ void FTextView::adjustSize() if ( width < 3 ) return; - const int hmax = ( max_width > int(width) - nf_offset - 2 ) + const int hmax = ( max_width >= int(width) - nf_offset - 1 ) ? max_width - int(width) + nf_offset + 2 : 0; hbar->setMaximum (hmax); diff --git a/src/fvterm.cpp b/src/fvterm.cpp index 0b94b853..77d02a23 100644 --- a/src/fvterm.cpp +++ b/src/fvterm.cpp @@ -111,7 +111,7 @@ FVTerm& FVTerm::operator << (const FTermBuffer& term_buffer) // public methods of FVTerm //---------------------------------------------------------------------- -const FPoint FVTerm::getPrintCursor() +FPoint FVTerm::getPrintCursor() { const auto& win = getPrintArea(); @@ -130,8 +130,8 @@ void FVTerm::setTermXY (int x, int y) const if ( term_pos->getX() == x && term_pos->getY() == y ) return; - const int term_width = int(FTerm::getColumnNumber()); - const int term_height = int(FTerm::getLineNumber()); + const auto term_width = int(FTerm::getColumnNumber()); + const auto term_height = int(FTerm::getLineNumber()); if ( x >= term_width && term_width > 0 ) { @@ -434,7 +434,7 @@ int FVTerm::print (const std::vector& term_string) int FVTerm::print (FTermArea* area, const std::vector& term_string) { int len{0}; - const uInt tabstop = uInt(FTerm::getTabstop()); + const auto tabstop = uInt(FTerm::getTabstop()); if ( ! area ) return -1; @@ -734,10 +734,10 @@ void FVTerm::resizeArea ( const FRect& box const int offset_left = box.getX(); const int offset_top = box.getY(); - const int width = int(box.getWidth()); - const int height = int(box.getHeight()); - const int rsw = int(shadow.getWidth()); - const int bsh = int(shadow.getHeight()); + const auto width = int(box.getWidth()); + const auto height = int(box.getHeight()); + const auto rsw = int(shadow.getWidth()); + const auto bsh = int(shadow.getHeight()); assert ( offset_top >= 0 ); assert ( width > 0 && width + rsw > 0 ); @@ -800,23 +800,23 @@ void FVTerm::removeArea (FTermArea*& area) { // remove the virtual window - if ( area != nullptr ) + if ( area == nullptr ) + return; + + if ( area->changes != nullptr ) { - if ( area->changes != nullptr ) - { - delete[] area->changes; - area->changes = nullptr; - } - - if ( area->data != nullptr ) - { - delete[] area->data; - area->data = nullptr; - } - - delete area; - area = nullptr; + delete[] area->changes; + area->changes = nullptr; } + + if ( area->data != nullptr ) + { + delete[] area->data; + area->data = nullptr; + } + + delete area; + area = nullptr; } //---------------------------------------------------------------------- @@ -827,8 +827,8 @@ void FVTerm::restoreVTerm (const FRect& box) int x = box.getX() - 1; int y = box.getY() - 1; - int w = int(box.getWidth()); - int h = int(box.getHeight()); + auto w = int(box.getWidth()); + auto h = int(box.getHeight()); if ( x < 0 ) x = 0; @@ -876,7 +876,7 @@ bool FVTerm::updateVTermCursor (const FTermArea* area) const if ( ! area ) return false; - if ( area != active_area ) + if ( ! isActive(area) ) return false; if ( ! area->visible ) @@ -970,8 +970,8 @@ void FVTerm::getArea (const FRect& box, const FTermArea* area) const int x = box.getX(); const int y = box.getY(); - const int w = int(box.getWidth()); - const int h = int(box.getHeight()); + const auto w = int(box.getWidth()); + const auto h = int(box.getHeight()); const int dx = x - area->offset_left + 1; const int dy = y - area->offset_top + 1; int y_end{}; @@ -1040,8 +1040,8 @@ void FVTerm::putArea (const FTermArea* area) const for (int y{0}; y < y_end; y++) // Line loop { bool modified{false}; - int line_xmin = int(area->changes[y].xmin); - int line_xmax = int(area->changes[y].xmax); + auto line_xmin = int(area->changes[y].xmin); + auto line_xmax = int(area->changes[y].xmax); if ( line_xmin > line_xmax ) continue; @@ -1289,7 +1289,7 @@ void FVTerm::clearArea (FTermArea* area, int fillchar) const return; } - const uInt w = uInt(area->width + area->right_shadow); + const auto w = uInt(area->width + area->right_shadow); if ( area->right_shadow == 0 ) { @@ -1471,20 +1471,17 @@ FVTerm::covered_state FVTerm::isCovered ( const FPoint& pos if ( FWidget::getWindowList() && ! FWidget::getWindowList()->empty() ) { - bool found( area == vdesktop ); + bool found{ area == vdesktop }; for (auto& win_obj : *FWidget::getWindowList()) { const auto& win = win_obj->getVWin(); - if ( ! win ) + if ( ! (win && win->visible) ) continue; - if ( ! win->visible ) - continue; - - const int win_x = win->offset_left; - const int win_y = win->offset_top; + const int& win_x = win->offset_left; + const int& win_y = win->offset_top; const FRect geometry { win_x , win_y , std::size_t(win->width) + std::size_t(win->right_shadow) , std::size_t(win->height) + std::size_t(win->bottom_shadow) }; @@ -1492,9 +1489,9 @@ FVTerm::covered_state FVTerm::isCovered ( const FPoint& pos if ( found && geometry.contains(pos) ) { const int width = win->width + win->right_shadow; - const int x = pos.getX(); - const int y = pos.getY(); - auto tmp = &win->data[(y - win_y) * width + (x - win_x)]; + const int& x = pos.getX(); + const int& y = pos.getY(); + const auto& tmp = &win->data[(y - win_y) * width + (x - win_x)]; if ( tmp->attr.bit.color_overlay ) { @@ -1709,9 +1706,10 @@ void FVTerm::updateVTerm() const vdesktop->has_changes = false; } - const FWidget* widget = static_cast(vterm->widget); + const FWidget* widget = vterm->widget; - if ( ! widget->getWindowList() || widget->getWindowList()->empty() ) + if ( ! widget || ! widget->getWindowList() + || widget->getWindowList()->empty() ) return; for (auto&& window : *(widget->getWindowList())) @@ -1797,7 +1795,7 @@ bool FVTerm::isInsideArea (const FPoint& pos, const FTermArea* area) } //---------------------------------------------------------------------- -const FChar FVTerm::generateCharacter (const FPoint& pos) +FChar FVTerm::generateCharacter (const FPoint& pos) { // Generates characters for a given position considering all areas @@ -1867,7 +1865,7 @@ const FChar FVTerm::generateCharacter (const FPoint& pos) } //---------------------------------------------------------------------- -const FChar FVTerm::getCharacter ( character_type char_type +FChar FVTerm::getCharacter ( character_type char_type , const FPoint& pos , FVTerm* obj ) { @@ -1927,14 +1925,14 @@ const FChar FVTerm::getCharacter ( character_type char_type } //---------------------------------------------------------------------- -const FChar FVTerm::getCoveredCharacter (const FPoint& pos, FVTerm* obj) +FChar FVTerm::getCoveredCharacter (const FPoint& pos, FVTerm* obj) { // Gets the covered character for a given position return getCharacter (covered_character, pos, obj); } //---------------------------------------------------------------------- -const FChar FVTerm::getOverlappedCharacter (const FPoint& pos, FVTerm* obj) +FChar FVTerm::getOverlappedCharacter (const FPoint& pos, FVTerm* obj) { // Gets the overlapped character for a given position return getCharacter (overlapped_character, pos, obj); diff --git a/src/fwidget.cpp b/src/fwidget.cpp index d3afc904..279f9c8c 100644 --- a/src/fwidget.cpp +++ b/src/fwidget.cpp @@ -102,13 +102,16 @@ FWidget::~FWidget() // destructor { processDestroy(); delCallback(); - auto app_object = FApplication::getApplicationObject(); - app_object->removeQueuedEvent(this); + removeQueuedEvent(); // unset clicked widget if ( this == getClickedWidget() ) setClickedWidget(nullptr); + // unset keyboard widget + if ( this == FApplication::getKeyboardWidget() ) + FApplication::setKeyboardWidget(nullptr); + // unset the local window widget focus if ( flags.focus ) { @@ -239,7 +242,7 @@ std::vector& FWidget::doubleFlatLine_ref (fc::sides side) } //---------------------------------------------------------------------- -const FPoint FWidget::getPrintPos() +FPoint FWidget::getPrintPos() { const auto& cur = getPrintCursor(); return { cur.getX() - woffset.getX1() - getX() + 1 @@ -635,7 +638,7 @@ bool FWidget::setCursorPos (const FPoint& pos) widget_cursor_position.setPoint(pos); - if ( ! flags.focus || isWindowWidget() ) + if ( ! flags.focus || flags.hidden || isWindowWidget() ) return false; if ( ! FWindow::getWindowWidget(this) ) @@ -718,7 +721,7 @@ void FWidget::setDoubleFlatLine (fc::sides side, int pos, bool bit) assert ( pos >= 1 ); uLong length{}; - const uLong index = uLong(pos - 1); + const auto index = uLong(pos - 1); switch ( side ) { @@ -954,7 +957,8 @@ void FWidget::show() show_root_widget = this; } - draw(); // Draw the widget + adjustSize(); // Alignment before drawing + draw(); // Draw the widget flags.hidden = false; flags.shown = true; @@ -962,13 +966,10 @@ void FWidget::show() { for (auto&& child : getChildren()) { - if ( child->isWidget() ) - { - auto widget = static_cast(child); + auto widget = static_cast(child); - if ( ! widget->flags.hidden ) - widget->show(); - } + if ( child->isWidget() && ! widget->flags.hidden ) + widget->show(); } } @@ -995,6 +996,11 @@ void FWidget::hide() { flags.shown = false; + if ( flags.visible_cursor && FWidget::getFocusWidget() == this ) + { + getPrintArea()->input_cursor_visible = false; + } + if ( ! isDialogWidget() && FWidget::getFocusWidget() == this && ! focusPrevChild() ) @@ -1206,8 +1212,8 @@ void FWidget::setParentOffset() void FWidget::setTermOffset() { const auto& r = getRootWidget(); - const int w = int(r->getWidth()); - const int h = int(r->getHeight()); + const auto w = int(r->getWidth()); + const auto h = int(r->getHeight()); woffset.setCoordinates (0, 0, w - 1, h - 1); } @@ -1307,13 +1313,10 @@ void FWidget::adjustSize() { for (auto&& child : getChildren()) { - if ( child->isWidget() ) - { - auto widget = static_cast(child); + auto widget = static_cast(child); - if ( ! widget->isWindowWidget() ) - widget->adjustSize(); - } + if ( child->isWidget() && ! widget->isWindowWidget() ) + widget->adjustSize(); } } } @@ -1582,55 +1585,94 @@ bool FWidget::event (FEvent* ev) //---------------------------------------------------------------------- void FWidget::onKeyPress (FKeyEvent*) -{ } +{ + // This event handler can be reimplemented in a subclass + // to receive key press events for the widget +} //---------------------------------------------------------------------- void FWidget::onKeyUp (FKeyEvent*) -{ } +{ + // This event handler can be reimplemented in a subclass + // to receive key up events for the widget +} //---------------------------------------------------------------------- void FWidget::onKeyDown (FKeyEvent*) -{ } +{ + // This event handler can be reimplemented in a subclass + // to receive key down events for the widget +} //---------------------------------------------------------------------- void FWidget::onMouseDown (FMouseEvent*) -{ } +{ + // This event handler can be reimplemented in a subclass + // to receive mouse down events for the widget +} //---------------------------------------------------------------------- void FWidget::onMouseUp (FMouseEvent*) -{ } +{ + // This event handler can be reimplemented in a subclass + // to receive mouse up events for the widget +} //---------------------------------------------------------------------- void FWidget::onMouseDoubleClick (FMouseEvent*) -{ } +{ + // This event handler can be reimplemented in a subclass + // to receive mouse double clicks events for the widget +} //---------------------------------------------------------------------- void FWidget::onWheel (FWheelEvent*) -{ } +{ + // This event handler can be reimplemented in a subclass + // to receive mouse wheel events for the widget +} //---------------------------------------------------------------------- void FWidget::onMouseMove (FMouseEvent*) -{ } +{ + // This event handler can be reimplemented in a subclass + // to receive mouse move events for the widget +} //---------------------------------------------------------------------- void FWidget::onFocusIn (FFocusEvent*) -{ } +{ + // This event handler can be reimplemented in a subclass + // to receive a widget focus event (get focus) +} //---------------------------------------------------------------------- void FWidget::onFocusOut (FFocusEvent*) -{ } +{ + // This event handler can be reimplemented in a subclass + // to receive a widget focus event (lost focus) +} //---------------------------------------------------------------------- void FWidget::onChildFocusIn (FFocusEvent*) -{ } +{ + // This event handler can be reimplemented in a subclass + // to receive a child widget focus event (get focus) +} //---------------------------------------------------------------------- void FWidget::onChildFocusOut (FFocusEvent*) -{ } +{ + // This event handler can be reimplemented in a subclass + // to receive a child widget focus event (lost focus) +} //---------------------------------------------------------------------- void FWidget::onAccel (FAccelEvent*) -{ } +{ + // This event handler can be reimplemented in a subclass to receive + // an event when an acceleration key is pressed for this widget +} //---------------------------------------------------------------------- void FWidget::onResize (FResizeEvent* ev) @@ -1643,15 +1685,23 @@ void FWidget::onResize (FResizeEvent* ev) //---------------------------------------------------------------------- void FWidget::onShow (FShowEvent*) -{ } +{ + // This event handler can be reimplemented in a subclass + // to receive a widget show event +} //---------------------------------------------------------------------- void FWidget::onHide (FHideEvent*) -{ } +{ + // This event handler can be reimplemented in a subclass + // to receive a widget hide event +} //---------------------------------------------------------------------- void FWidget::onClose (FCloseEvent* ev) { + // This event handler can be reimplemented in a subclass + // to receive a widget close event ev->accept(); } @@ -1742,21 +1792,23 @@ inline void FWidget::insufficientSpaceAdjust() // move left if not enough space while ( getTermX() + int(getWidth()) - padding.right > woffset.getX2() + 2 ) { - adjust_wsize.x1_ref()--; - adjust_wsize.x2_ref()--; - - if ( adjust_wsize.x1_ref() < 1 ) + if ( adjust_wsize.x1_ref() < 2 ) adjust_wsize.x1_ref() = 1; + else + adjust_wsize.x1_ref()--; + + adjust_wsize.x2_ref()--; } // move up if not enough space while ( getTermY() + int(getHeight()) - padding.bottom > woffset.getY2() + 2 ) { - adjust_wsize.y1_ref()--; - adjust_wsize.y2_ref()--; - - if ( adjust_wsize.y1_ref() < 1 ) + if ( adjust_wsize.y1_ref() < 2 ) adjust_wsize.y1_ref() = 1; + else + adjust_wsize.y1_ref()--; + + adjust_wsize.y2_ref()--; } // reduce the width if not enough space @@ -1911,7 +1963,10 @@ bool FWidget::changeFocus ( FWidget* follower, FWidget* parent //---------------------------------------------------------------------- void FWidget::draw() -{ } +{ + // This method must be reimplemented in a subclass + // for drawing the widget +} //---------------------------------------------------------------------- void FWidget::drawWindows() const @@ -2011,6 +2066,15 @@ void FWidget::destroyColorTheme() delete theme; } +//---------------------------------------------------------------------- +void FWidget::removeQueuedEvent() const +{ + auto app_object = FApplication::getApplicationObject(); + + if ( app_object ) + app_object->removeQueuedEvent(this); +} + //---------------------------------------------------------------------- void FWidget::setStatusbarText (bool enable) const { diff --git a/src/fwidget_functions.cpp b/src/fwidget_functions.cpp index b8072edb..b3d60d80 100644 --- a/src/fwidget_functions.cpp +++ b/src/fwidget_functions.cpp @@ -97,7 +97,7 @@ std::size_t getHotkeyPos (const FString& src, FString& dest) // Find hotkey position in string // + generate a new string without the '&'-sign - constexpr std::size_t NOT_SET = static_cast(-1); + constexpr auto NOT_SET = static_cast(-1); std::size_t hotkeypos{NOT_SET}; std::size_t i{0}; diff --git a/src/fwindow.cpp b/src/fwindow.cpp index d8d6c8cf..b1b50c8d 100644 --- a/src/fwindow.cpp +++ b/src/fwindow.cpp @@ -278,8 +278,17 @@ void FWindow::show() //---------------------------------------------------------------------- void FWindow::hide() { + const auto& virtual_win = getVWin(); + + if ( isActive(virtual_win) + && virtual_win->visible + && virtual_win->input_cursor_visible ) + { + hideVTermCursor(); + } + if ( isVirtualWindow() ) - getVWin()->visible = false; + virtual_win->visible = false; FWidget::hide(); const auto& t_geometry = getTermGeometryWithShadow(); @@ -428,13 +437,12 @@ FWindow* FWindow::getWindowWidgetAt (int x, int y) do { --iter; - if ( *iter ) - { - auto w = static_cast(*iter); + auto w = static_cast(*iter); - if ( ! w->isWindowHidden() - && w->getTermGeometry().contains(x, y) ) - return w; + if ( *iter && ! w->isWindowHidden() + && w->getTermGeometry().contains(x, y) ) + { + return w; } } while ( iter != begin ); @@ -681,7 +689,6 @@ void FWindow::switchToPrevWindow (const FWidget* widget) const bool is_activated = activatePrevWindow(); auto active_win = static_cast(getActiveWindow()); - if ( ! is_activated && getWindowList() && getWindowList()->size() > 1 ) { @@ -815,19 +822,31 @@ bool FWindow::event (FEvent* ev) //---------------------------------------------------------------------- void FWindow::onWindowActive (FEvent*) -{ } +{ + // This event handler can be reimplemented in a subclass + // to receive activation events for this window +} //---------------------------------------------------------------------- void FWindow::onWindowInactive (FEvent*) -{ } +{ + // This event handler can be reimplemented in a subclass + // to receive deactivation events for this window +} //---------------------------------------------------------------------- void FWindow::onWindowRaised (FEvent*) -{ } +{ + // This event handler can be reimplemented in a subclass + // to receive window raising events for this window +} //---------------------------------------------------------------------- void FWindow::onWindowLowered (FEvent*) -{ } +{ + // This event handler can be reimplemented in a subclass + // to receive window lowering events for this window +} // private methods of FWindow diff --git a/src/include/final/emptyfstring.h b/src/include/final/emptyfstring.h index b11cf9f8..c6ab6f97 100644 --- a/src/include/final/emptyfstring.h +++ b/src/include/final/emptyfstring.h @@ -35,7 +35,8 @@ #error "Only can be included directly." #endif -#include "final/fapplication.h" +#include + #include "final/flog.h" #include "final/fstring.h" @@ -61,7 +62,7 @@ public: // Disable copy assignment operator (=) emptyFString& operator = (const emptyFString&) = delete; - static const FString getClassName(); + static FString getClassName(); static bool isNull(); static const FString& get(); static void clear(); @@ -73,7 +74,7 @@ private: // emptyFString inline functions //---------------------------------------------------------------------- -inline const FString emptyFString::getClassName() +inline FString emptyFString::getClassName() { return "emptyFString"; } //---------------------------------------------------------------------- diff --git a/src/include/final/fapplication.h b/src/include/final/fapplication.h index 40a49f8b..e9803d9d 100644 --- a/src/include/final/fapplication.h +++ b/src/include/final/fapplication.h @@ -64,6 +64,8 @@ #include #include #include +#include +#include #include "final/ftypes.h" #include "final/fwidget.h" @@ -110,10 +112,11 @@ class FApplication : public FWidget FApplication& operator = (const FApplication&) = delete; // Accessors - const FString getClassName() const override; + FString getClassName() const override; int getArgc() const; char** getArgv() const; static FApplication* getApplicationObject(); + static FWidget* getKeyboardWidget(); static FLogPtr& getLog(); // Mutator @@ -136,6 +139,8 @@ class FApplication : public FWidget void initTerminal() override; static void setDefaultTheme(); static void setDarkTheme(); + static void setLogFile (const FString&); + static void setKeyboardWidget (FWidget*); static void closeConfirmationDialog (FWidget*, FCloseEvent*); // Callback method @@ -148,12 +153,13 @@ class FApplication : public FWidget // Typedefs typedef std::pair EventPair; typedef std::deque FEventQueue; + typedef std::unordered_map> CmdMap; // Methods void init(); static void setTerminalEncoding (const FString&); - static void setLogFile (const FString&); - static void cmd_options (const int&, char*[]); + static CmdMap& mapCmdOptions(); + static void cmdOptions (const int&, char*[]); static FStartOptions& getStartOptions(); static void showParameterUsage(); void destroyLog(); @@ -205,6 +211,7 @@ class FApplication : public FWidget char** app_argv{}; uInt64 key_timeout{100000}; // 100 ms uInt64 dblclick_interval{500000}; // 500 ms + std::streambuf* default_clog_rdbuf{std::clog.rdbuf()}; FEventQueue event_queue{}; static uInt64 next_event_wait; static timeval time_last_event; @@ -215,6 +222,20 @@ class FApplication : public FWidget static FMouseControl* mouse; static FKeyboard* keyboard; static FWidget* keyboard_widget; + +#if defined(__sun) && defined(__SVR4) + struct CmdOption + { + const char* name; // <- name is without 'const' in Solaris + int has_arg; + int* flag; + int val; + }; +#else + using CmdOption = struct option; +#endif + + static const std::vector long_options; }; @@ -226,7 +247,7 @@ FApplication* getFApplication(); // FApplication inline functions //---------------------------------------------------------------------- -inline const FString FApplication::getClassName() const +inline FString FApplication::getClassName() const { return "FApplication"; } //---------------------------------------------------------------------- diff --git a/src/include/final/fbusyindicator.h b/src/include/final/fbusyindicator.h index a73618b1..00babea3 100644 --- a/src/include/final/fbusyindicator.h +++ b/src/include/final/fbusyindicator.h @@ -76,13 +76,13 @@ class FBusyIndicator : public FToolTip FBusyIndicator (const FBusyIndicator&) = delete; // Destructor - ~FBusyIndicator(); + ~FBusyIndicator() override; // Disable copy assignment operator (=) FBusyIndicator& operator = (const FBusyIndicator&) = delete; // Accessors - const FString getClassName() const override; + FString getClassName() const override; // Inquiries bool isRunning() const; @@ -113,7 +113,7 @@ class FBusyIndicator : public FToolTip // FBusyIndicator inline functions //---------------------------------------------------------------------- -inline const FString FBusyIndicator::getClassName() const +inline FString FBusyIndicator::getClassName() const { return "FBusyIndicator"; } //---------------------------------------------------------------------- diff --git a/src/include/final/fbutton.h b/src/include/final/fbutton.h index 36ba2ae1..2e1b4aea 100644 --- a/src/include/final/fbutton.h +++ b/src/include/final/fbutton.h @@ -77,7 +77,7 @@ class FButton : public FWidget FButton& operator = (const FString&); // Accessors - const FString getClassName() const override; + FString getClassName() const override; FString getText() const; // Mutators @@ -134,7 +134,7 @@ class FButton : public FWidget private: // Constants - static constexpr std::size_t NOT_SET = static_cast(-1); + static constexpr auto NOT_SET = static_cast(-1); // Methods void init(); @@ -174,7 +174,7 @@ class FButton : public FWidget // FButton inline functions //---------------------------------------------------------------------- -inline const FString FButton::getClassName() const +inline FString FButton::getClassName() const { return "FButton"; } //---------------------------------------------------------------------- diff --git a/src/include/final/fbuttongroup.h b/src/include/final/fbuttongroup.h index f59e05fd..d2c59f0c 100644 --- a/src/include/final/fbuttongroup.h +++ b/src/include/final/fbuttongroup.h @@ -78,7 +78,7 @@ class FButtonGroup : public FScrollView FButtonGroup& operator = (const FButtonGroup&) = delete; // Accessor - const FString getClassName() const override; + FString getClassName() const override; FToggleButton* getFirstButton(); FToggleButton* getLastButton(); FToggleButton* getButton (int) const; @@ -119,7 +119,7 @@ class FButtonGroup : public FScrollView private: // Constants - static constexpr std::size_t NOT_SET = static_cast(-1); + static constexpr auto NOT_SET = static_cast(-1); // Inquiries bool isRadioButton (const FToggleButton*) const; @@ -127,7 +127,11 @@ class FButtonGroup : public FScrollView // Methods void init(); void drawText (const FString&, std::size_t); + bool directFocusCheckedRadioButton (FToggleButton*) const; + bool directFocusRadioButton() const; void directFocus(); + void focusCheckedRadioButton (FToggleButton*, FFocusEvent*); + void focusInRadioButton (FFocusEvent*); // Callback method void cb_buttonToggled (const FToggleButton*) const; @@ -139,7 +143,7 @@ class FButtonGroup : public FScrollView // FButtonGroup inline functions //---------------------------------------------------------------------- -inline const FString FButtonGroup::getClassName() const +inline FString FButtonGroup::getClassName() const { return "FButtonGroup"; } //---------------------------------------------------------------------- diff --git a/src/include/final/fc.h b/src/include/final/fc.h index aa1585c4..735b89a0 100644 --- a/src/include/final/fc.h +++ b/src/include/final/fc.h @@ -33,15 +33,14 @@ #define C_STR const_cast // ASCII sequences -#define ESC "\033" // Escape -#define CSI ESC "[" // Control sequence introducer (7-bit) -#define ENQ "\005" // Enquiry -#define BEL "\007" // Bell (ctrl‐g) -#define BS "\010" // Backspace -#define SO "\016" // Shift out (alternative character set) -#define SI "\017" // Shift in (regular character set) -#define OSC ESC "]" // Operating system command (7-bit) -#define SECDA ESC "[>c" // Secondary Device Attributes +#define ESC "\033" // Escape +#define CSI ESC "[" // Control sequence introducer (7-bit) +#define ENQ "\005" // Enquiry +#define BEL "\007" // Bell (ctrl‐g) +#define BS "\010" // Backspace +#define SO "\016" // Shift out (alternative character set) +#define SI "\017" // Shift in (regular character set) +#define OSC ESC "]" // Operating system command (7-bit) namespace finalcut { diff --git a/src/include/final/fcallback.h b/src/include/final/fcallback.h index 765c8b38..32de081b 100644 --- a/src/include/final/fcallback.h +++ b/src/include/final/fcallback.h @@ -58,7 +58,7 @@ struct FCallbackData FCallbackData() { } - template + template FCallbackData (const FString& s, FWidget* i, FuncPtr m, const FCall& c) : cb_signal(s) , cb_instance(i) @@ -88,7 +88,7 @@ class FCallback { public: // Using-declaration - template + template using ObjectPointer = typename std::enable_if< ! std::is_member_function_pointer::value && ! std::is_function::type>::value @@ -97,7 +97,7 @@ class FCallback && std::is_object::value && ! std::is_class::value , std::nullptr_t >; - template + template using ClassObject = typename std::enable_if< ! std::is_member_function_pointer::value && ! std::is_function::type>::value @@ -106,7 +106,7 @@ class FCallback && std::is_object::value && std::is_class::value , std::nullptr_t >; - template + template using MemberFunctionPointer = typename std::enable_if< std::is_member_function_pointer::value && ! std::is_function::type>::value @@ -115,7 +115,7 @@ class FCallback && std::is_object::value && ! std::is_class::value , std::nullptr_t >; - template + template using FunctionPointer = typename std::enable_if< ! std::is_member_function_pointer::value && std::is_function::type>::value @@ -124,7 +124,7 @@ class FCallback && std::is_object::value && ! std::is_class::value , std::nullptr_t >; - template + template using FunctionReference = typename std::enable_if< ! std::is_member_function_pointer::value && std::is_function::type>::value @@ -147,65 +147,65 @@ class FCallback FCallback& operator = (const FCallback&) = delete; // Accessors - const FString getClassName() const; + FString getClassName() const; std::size_t getCallbackCount() const; // Methods - template::type = nullptr - , typename MemberFunctionPointer::type = nullptr - , typename... Args> + template ::type = nullptr + , typename MemberFunctionPointer::type = nullptr + , typename... Args> void addCallback ( const FString& cb_signal , Object&& cb_instance , Function&& cb_member , Args&&... args) noexcept; - template::type = nullptr - , typename ClassObject::type = nullptr - , typename... Args> + template ::type = nullptr + , typename ClassObject::type = nullptr + , typename... Args> void addCallback ( const FString& cb_signal , Object&& cb_instance , Function&& cb_function , Args&&... args) noexcept; - template::type = nullptr - , typename... Args> + template < typename Function + , typename ClassObject::type = nullptr + , typename... Args> void addCallback ( const FString& cb_signal , Function&& cb_function , Args&&... args) noexcept; - template::type = nullptr - , typename... Args> + template ::type = nullptr + , typename... Args> void addCallback ( const FString& cb_signal , Function& cb_function , Args&&... args) noexcept; - template::type = nullptr - , typename... Args> + template ::type = nullptr + , typename... Args> void addCallback ( const FString& cb_signal , Function& cb_function , Args&&... args) noexcept; - template::type = nullptr - , typename... Args> + template ::type = nullptr + , typename... Args> void addCallback ( const FString& cb_signal , Function&& cb_function , Args&&... args) noexcept; - template::type = nullptr> + template ::type = nullptr> void delCallback (Object&& cb_instance) noexcept; void delCallback (const FString& cb_signal); - template::type = nullptr> + template ::type = nullptr> void delCallback ( const FString& cb_signal , Object&& cb_instance ) noexcept; - template::type = nullptr> + template ::type = nullptr> void delCallback (FunctionPtr&& cb_func_ptr) noexcept; - template::type = nullptr> + template ::type = nullptr> void delCallback (const Function& cb_function); void delCallback(); void emitCallback (const FString& emit_signal) const; @@ -220,7 +220,7 @@ class FCallback // FCallback inline functions //---------------------------------------------------------------------- -inline const FString FCallback::getClassName() const +inline FString FCallback::getClassName() const { return "FCallback"; } //---------------------------------------------------------------------- @@ -228,11 +228,11 @@ inline std::size_t FCallback::getCallbackCount() const { return callback_objects.size(); } //---------------------------------------------------------------------- -template::type - , typename FCallback::MemberFunctionPointer::type - , typename... Args> +template ::type + , typename FCallback::MemberFunctionPointer::type + , typename... Args> inline void FCallback::addCallback ( const FString& cb_signal , Object&& cb_instance , Function&& cb_member @@ -249,11 +249,11 @@ inline void FCallback::addCallback ( const FString& cb_signal } //---------------------------------------------------------------------- -template::type - , typename FCallback::ClassObject::type - , typename... Args> +template ::type + , typename FCallback::ClassObject::type + , typename... Args> inline void FCallback::addCallback ( const FString& cb_signal , Object&& cb_instance , Function&& cb_function @@ -267,9 +267,9 @@ inline void FCallback::addCallback ( const FString& cb_signal } //---------------------------------------------------------------------- -template::type - , typename... Args> +template ::type + , typename... Args> inline void FCallback::addCallback ( const FString& cb_signal , Function&& cb_function , Args&&... args) noexcept @@ -283,9 +283,9 @@ inline void FCallback::addCallback ( const FString& cb_signal } //---------------------------------------------------------------------- -template::type - , typename... Args> +template ::type + , typename... Args> inline void FCallback::addCallback ( const FString& cb_signal , Function& cb_function , Args&&... args) noexcept @@ -298,9 +298,9 @@ inline void FCallback::addCallback ( const FString& cb_signal } //---------------------------------------------------------------------- -template::type - , typename... Args> +template ::type + , typename... Args> inline void FCallback::addCallback ( const FString& cb_signal , Function& cb_function , Args&&... args) noexcept @@ -314,9 +314,9 @@ inline void FCallback::addCallback ( const FString& cb_signal } //---------------------------------------------------------------------- -template::type - , typename... Args> +template ::type + , typename... Args> inline void FCallback::addCallback ( const FString& cb_signal , Function&& cb_function , Args&&... args) noexcept @@ -331,8 +331,8 @@ inline void FCallback::addCallback ( const FString& cb_signal } //---------------------------------------------------------------------- -template::type> +template ::type> inline void FCallback::delCallback (Object&& cb_instance) noexcept { // Deletes entries with the given instance from the callback list @@ -352,8 +352,8 @@ inline void FCallback::delCallback (Object&& cb_instance) noexcept } //---------------------------------------------------------------------- -template::type> +template ::type> inline void FCallback::delCallback ( const FString& cb_signal , Object&& cb_instance ) noexcept { @@ -376,8 +376,8 @@ inline void FCallback::delCallback ( const FString& cb_signal } //---------------------------------------------------------------------- -template::type> +template ::type> inline void FCallback::delCallback (FunctionPtr&& cb_func_ptr) noexcept { // Deletes entries with the given function pointer @@ -399,8 +399,8 @@ inline void FCallback::delCallback (FunctionPtr&& cb_func_ptr) noexcept } //---------------------------------------------------------------------- -template::type> +template ::type> inline void FCallback::delCallback (const Function& cb_function) { // Deletes entries with the given function reference diff --git a/src/include/final/fcharmap.h b/src/include/final/fcharmap.h index 009c4a76..8aafa7e8 100644 --- a/src/include/final/fcharmap.h +++ b/src/include/final/fcharmap.h @@ -3,7 +3,7 @@ * * * This file is part of the FINAL CUT widget toolkit * * * -* Copyright 2015-2019 Markus Gans * +* Copyright 2015-2020 Markus Gans * * * * FINAL CUT is free software; you can redistribute it and/or modify * * it under the terms of the GNU Lesser General Public License as * @@ -27,6 +27,8 @@ #error "Only can be included directly." #endif +#include + #include "final/fc.h" #include "final/ftypes.h" @@ -36,17 +38,10 @@ namespace finalcut namespace fc { -extern uInt character[][fc::NUM_OF_ENCODINGS]; -extern const std::size_t lastCharItem; - -extern int vt100_key_to_utf8[][2]; -extern const std::size_t lastKeyItem; - -extern wchar_t cp437_ucs[][2]; -extern const std::size_t lastCP437Item; - -extern const wchar_t halfWidth_fullWidth[][2]; -extern const std::size_t lastHalfWidthItem; +extern std::array, 115> character; +extern const std::array, 39> vt100_key_to_utf8; +extern const std::array, 256> cp437_ucs; +extern const std::array, 227> halfwidth_fullwidth; } // namespace fc diff --git a/src/include/final/fcheckbox.h b/src/include/final/fcheckbox.h index 07c5626d..40e74bb7 100644 --- a/src/include/final/fcheckbox.h +++ b/src/include/final/fcheckbox.h @@ -78,7 +78,7 @@ class FCheckBox : public FToggleButton FCheckBox& operator = (const FCheckBox&) = delete; // Accessor - const FString getClassName() const override; + FString getClassName() const override; private: // Methods @@ -91,7 +91,7 @@ class FCheckBox : public FToggleButton // FCheckBox inline functions //---------------------------------------------------------------------- -inline const FString FCheckBox::getClassName() const +inline FString FCheckBox::getClassName() const { return "FCheckBox"; } } // namespace finalcut diff --git a/src/include/final/fcheckmenuitem.h b/src/include/final/fcheckmenuitem.h index f313c41d..c5ea112b 100644 --- a/src/include/final/fcheckmenuitem.h +++ b/src/include/final/fcheckmenuitem.h @@ -40,9 +40,9 @@ * ▕▁▁▁▁▁▁▁▁▁▁▁▏ * ▲ * │ - * ▕▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▏* 1▕▔▔▔▔▔▔▔▏ - * ▕ FCheckMenuItem ▏- - - - -▕ FMenu ▏ - * ▕▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▏ ▕▁▁▁▁▁▁▁▏ + * ▕▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▏* 1▕▔▔▔▔▔▔▔▏ + * ▕ FCheckMenuItem ▏- - - -▕ FMenu ▏ + * ▕▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▏ ▕▁▁▁▁▁▁▁▏ */ #ifndef FCHECKMENUITEM_H @@ -78,7 +78,7 @@ class FCheckMenuItem : public FMenuItem FCheckMenuItem& operator = (const FCheckMenuItem&) = delete; // Accessor - const FString getClassName() const override; + FString getClassName() const override; private: // Methods @@ -89,7 +89,7 @@ class FCheckMenuItem : public FMenuItem // FCheckMenuItem inline functions //---------------------------------------------------------------------- -inline const FString FCheckMenuItem::getClassName() const +inline FString FCheckMenuItem::getClassName() const { return "FCheckMenuItem"; } } // namespace finalcut diff --git a/src/include/final/fcolorpair.h b/src/include/final/fcolorpair.h index badcf497..7309fc54 100644 --- a/src/include/final/fcolorpair.h +++ b/src/include/final/fcolorpair.h @@ -65,7 +65,7 @@ class FColorPair FColorPair& operator = (const FColorPair& pair) = default; // Accessor - const FString getClassName() const + FString getClassName() const { return "FColorPair"; } FColor getForegroundColor() const diff --git a/src/include/final/fcolorpalette.h b/src/include/final/fcolorpalette.h index 606ab79c..ed22b4f1 100644 --- a/src/include/final/fcolorpalette.h +++ b/src/include/final/fcolorpalette.h @@ -59,7 +59,7 @@ class FColorPalette virtual ~FColorPalette(); // Accessor - virtual const FString getClassName() const; + virtual FString getClassName() const; // Methods virtual void setColorPalette() = 0; @@ -76,7 +76,7 @@ class FColorPalette // FColorPalette inline functions //---------------------------------------------------------------------- -inline const FString FColorPalette::getClassName() const +inline FString FColorPalette::getClassName() const { return "FColorPalette"; } @@ -104,10 +104,10 @@ class default8ColorPalette final : public FColorPalette explicit default8ColorPalette (const FSetPalette&); // Destructor - ~default8ColorPalette(); + ~default8ColorPalette() override; // Accessor - const FString getClassName() const override; + FString getClassName() const override; // Methods void setColorPalette() override; @@ -116,7 +116,7 @@ class default8ColorPalette final : public FColorPalette // default8ColorPalette inline functions //---------------------------------------------------------------------- -inline const FString default8ColorPalette::getClassName() const +inline FString default8ColorPalette::getClassName() const { return "default8ColorPalette"; } @@ -144,10 +144,10 @@ class default16ColorPalette final : public FColorPalette explicit default16ColorPalette (const FSetPalette&); // Destructor - ~default16ColorPalette(); + ~default16ColorPalette() override; // Accessor - const FString getClassName() const override; + FString getClassName() const override; // Methods void setColorPalette() override; @@ -156,7 +156,7 @@ class default16ColorPalette final : public FColorPalette // default16ColorPalette inline functions //---------------------------------------------------------------------- -inline const FString default16ColorPalette::getClassName() const +inline FString default16ColorPalette::getClassName() const { return "default16ColorPalette"; } /* Inheritance diagram @@ -183,10 +183,10 @@ class default16DarkColorPalette final : public FColorPalette explicit default16DarkColorPalette (const FSetPalette&); // Destructor - ~default16DarkColorPalette(); + ~default16DarkColorPalette() override; // Accessor - const FString getClassName() const override; + FString getClassName() const override; // Methods void setColorPalette() override; @@ -195,7 +195,7 @@ class default16DarkColorPalette final : public FColorPalette // default16ColorPalette inline functions //---------------------------------------------------------------------- -inline const FString default16DarkColorPalette::getClassName() const +inline FString default16DarkColorPalette::getClassName() const { return "default16DarkColorPalette"; } } // namespace finalcut diff --git a/src/include/final/fcombobox.h b/src/include/final/fcombobox.h index 8078a85b..ec23e70f 100644 --- a/src/include/final/fcombobox.h +++ b/src/include/final/fcombobox.h @@ -47,6 +47,9 @@ #error "Only can be included directly." #endif +#include + +#include "final/fdata.h" #include "final/flineedit.h" #include "final/flistbox.h" #include "final/fwidget.h" @@ -83,7 +86,7 @@ class FDropDownListBox : public FWindow FDropDownListBox& operator = (const FDropDownListBox&) = delete; // Accessors - const FString getClassName() const override; + FString getClassName() const override; // Mutators void setGeometry ( const FPoint&, const FSize& @@ -114,7 +117,7 @@ class FDropDownListBox : public FWindow // FDropDownListBox inline functions //---------------------------------------------------------------------- -inline const FString FDropDownListBox::getClassName() const +inline FString FDropDownListBox::getClassName() const { return "FDropDownListBox"; } //---------------------------------------------------------------------- @@ -147,10 +150,11 @@ class FComboBox : public FWidget // Overloaded operators // Accessors - const FString getClassName() const override; + FString getClassName() const override; std::size_t getCount() const; FString getText() const; - FDataPtr getItemData(); + template + clean_fdata_t
& getItemData(); FLineEdit::label_o getLabelOrientation() const; // Mutators @@ -182,11 +186,13 @@ class FComboBox : public FWidget // Methods void insert (const FListBoxItem&); - template + template void insert ( const std::initializer_list& list - , FDataPtr = nullptr ); - template - void insert (const ItemT&, FDataPtr = nullptr); + , DT&& = DT() ); + template + void insert (const ItemT&, DT&& = DT()); void remove (std::size_t); void reserve (std::size_t); void clear(); @@ -235,7 +241,7 @@ bool closeComboBox (FDropDownListBox*, const FPoint&); // FComboBox inline functions //---------------------------------------------------------------------- -inline const FString FComboBox::getClassName() const +inline FString FComboBox::getClassName() const { return "FComboBox"; } //---------------------------------------------------------------------- @@ -247,10 +253,11 @@ inline FString FComboBox::getText() const { return input_field.getText(); } //---------------------------------------------------------------------- -inline FDataPtr FComboBox::getItemData() +template +inline clean_fdata_t
& FComboBox::getItemData() { const std::size_t index = list_window.list.currentItem(); - return list_window.list.getItem(index).getData(); + return list_window.list.getItem(index).getData
(); } //---------------------------------------------------------------------- @@ -298,21 +305,23 @@ inline bool FComboBox::hasShadow() const { return getFlags().shadow; } //---------------------------------------------------------------------- -template -void FComboBox::insert (const std::initializer_list& list, FDataPtr d) +template +void FComboBox::insert (const std::initializer_list& list, DT&& d) { for (auto& item : list) { - FListBoxItem listItem (FString() << item, d); + FListBoxItem listItem (FString() << item, std::forward
(d)); insert (listItem); } } //---------------------------------------------------------------------- -template -void FComboBox::insert (const ItemT& item, FDataPtr d) +template +void FComboBox::insert (const ItemT& item, DT&& d) { - FListBoxItem listItem (FString() << item, d); + FListBoxItem listItem (FString() << item, std::forward
(d)); insert (listItem); } diff --git a/src/include/final/fdata.h b/src/include/final/fdata.h index 02e974eb..9b47169d 100644 --- a/src/include/final/fdata.h +++ b/src/include/final/fdata.h @@ -20,6 +20,19 @@ * . * ***********************************************************************/ +/* Inheritance diagram + * ═══════════════════ + * + * ▕▔▔▔▔▔▔▔▔▔▔▔▔▔▏ + * ▕ FDataAccess ▏ + * ▕▁▁▁▁▁▁▁▁▁▁▁▁▁▏ + * ▲ + * │ + * ▕▔▔▔▔▔▔▔▏ + * ▕ FData ▏ + * ▕▁▁▁▁▁▁▁▏ + */ + #ifndef FDATA_H #define FDATA_H @@ -29,76 +42,233 @@ #include -template -struct FData +#include "final/fstring.h" + +namespace finalcut { - explicit FData (T v) // constructor - : value{v} - { } - ~FData() // destructor - { } +template +class FData; // Class forward declaration - FData (const FData& d) // Copy constructor - : value{d.value} - { } +// non-member functions +//---------------------------------------------------------------------- +namespace internal +{ - FData& operator = (const FData& d) // Copy assignment operator (=) - { - value = d.value; - return *this; - } +template ::value + , bool isFunction = std::is_function::value> +struct cleanCondition; - FData (FData&& d) noexcept // Move constructor - : value{std::move(d.value)} - { } - - FData& operator = (FData&& d) noexcept // Move assignment operator (=) - { - value = std::move(d.value); - return *this; - } - - T operator () () const - { - return value; - } - - template - T operator () (Args... args) const - { - return value(args...); - } - - explicit operator T () const - { - return value; - } - - T& get() - { - return value; - } - - void set (const T& v) - { - value = v; - } - - FData& operator << (const T& v) - { - value = v; - return *this; - } - - friend std::ostream& operator << (std::ostream &os, const FData& data) - { - os << data.value; - return os; - } - - T value; +//---------------------------------------------------------------------- +template +struct cleanCondition +{ + // Leave the type untouched + typedef T type; }; -#endif // FDATA_H +//---------------------------------------------------------------------- +template +struct cleanCondition +{ + // Array to pointer + typedef typename std::remove_extent::type* type; +}; +//---------------------------------------------------------------------- +template +struct cleanCondition +{ + // Add pointer to function + typedef typename std::add_pointer::type type; +}; + +} // namespace internal + +//---------------------------------------------------------------------- +template +class cleanFData +{ + private: + typedef typename std::remove_reference::type remove_ref; + + public: + // Similar to std::decay, but keeps const and volatile + typedef typename internal::cleanCondition::type type; +}; + +//---------------------------------------------------------------------- +template +using clean_fdata_t = typename cleanFData::type; + +//---------------------------------------------------------------------- +template +constexpr FData>* makeFData (T&& data) +{ + return new FData>(std::forward(data)); +} + + +//---------------------------------------------------------------------- +// class FDataAccess +//---------------------------------------------------------------------- + +class FDataAccess +{ + public: + // Constructor + FDataAccess(); + + // Destructor + virtual ~FDataAccess(); + + // Accessors + virtual FString getClassName() const + { + return "FDataAccess"; + } + + template + clean_fdata_t& get() + { + return static_cast>&>(*this).get(); + } + + // Mutator + template + void set (V&& data) + { + static_cast&>(*this).set(std::forward(data)); + } +}; + + +//---------------------------------------------------------------------- +// class FData +//---------------------------------------------------------------------- + +template +class FData : public FDataAccess +{ + public: + typedef typename std::remove_cv::type T_nocv; + + // Constructors + explicit FData (T& v) // constructor + : value_ref{v} + { } + + explicit FData (T&& v) // constructor + : value{std::move(v)} + , value_ref{value} + { } + + // Destructor + ~FData() override + { } + + FData (const FData& d) // Copy constructor + : value{d.value} + , value_ref{d.isInitializedCopy() ? std::ref(value) : d.value_ref} + { } + + FData (FData&& d) noexcept // Move constructor + : value{std::move(d.value)} + , value_ref{d.isInitializedCopy() ? std::ref(value) : std::move(d.value_ref)} + { } + + // Overloaded operators + FData& operator = (const FData& d) // Copy assignment operator (=) + { + if ( &d != this ) + { + value = d.value; + + if ( d.isInitializedCopy() ) + value_ref = value; + else + value_ref = d.value_ref; + } + + return *this; + } + + FData& operator = (FData&& d) noexcept // Move assignment operator (=) + { + if ( &d != this ) + { + value = std::move(d.value); + + if ( d.isInitializedCopy() ) + value_ref = value; + else + value_ref = std::move(d.value_ref); + } + + return *this; + } + + T operator () () const + { + return value_ref; + } + + explicit operator T () const + { + return value_ref; + } + + FData& operator << (const T& v) + { + value_ref.get() = v; + return *this; + } + + // Accessors + FString getClassName() const override + { + return "FData"; + } + + T& get() const + { + return value_ref; + } + + // Mutator + void set (const T& v) + { + value_ref.get() = v; + } + + // Inquiries + bool isInitializedCopy() const + { + const auto& v = reinterpret_cast(const_cast(&value)); + const auto& r = reinterpret_cast(const_cast(&value_ref.get())); + return bool( v == r ); + } + + bool isInitializedReference() const + { + return ! isInitializedCopy(); + } + + // Friend Non-member operator functions + friend std::ostream& operator << (std::ostream &os, const FData& data) + { + os << data.value_ref.get(); + return os; + } + + private: + // Data members + T value{}; + std::reference_wrapper value_ref; +}; + +} // namespace finalcut + +#endif // FDATA_H diff --git a/src/include/final/fdialog.h b/src/include/final/fdialog.h index 64e903d4..16ac4f30 100644 --- a/src/include/final/fdialog.h +++ b/src/include/final/fdialog.h @@ -91,8 +91,8 @@ class FDialog : public FWindow FDialog& operator = (const FDialog&) = delete; // Accessors - const FString getClassName() const override; - virtual const FString getText() const; + FString getClassName() const override; + virtual FString getText() const; // Mutators bool setDialogWidget (bool); @@ -163,7 +163,7 @@ class FDialog : public FWindow FPoint termPos; std::size_t zoom_btn; bool mouse_over_menu; - } mouseStates; + } MouseStates; // Constant static constexpr std::size_t MENU_BTN = 3; @@ -189,20 +189,22 @@ class FDialog : public FWindow void selectFirstMenuItem(); void setZoomItem(); std::size_t getZoomButtonWidth() const; - void activateZoomButton (const mouseStates&); + void activateZoomButton (const MouseStates&); void deactivateZoomButton(); - void leaveZoomButton (const mouseStates&); - void pressZoomButton (const mouseStates&); + void leaveZoomButton (const MouseStates&); + void pressZoomButton (const MouseStates&); bool isMouseOverMenu (const FPoint&) const; - void passEventToSubMenu ( const mouseStates& + void passEventToSubMenu ( const MouseStates& , const FMouseEvent* ); void moveSizeKey (FKeyEvent*); void raiseActivateDialog(); void lowerActivateDialog(); bool isOutsideTerminal (const FPoint&) const; - bool isLowerRightResizeCorner (const mouseStates&) const; - void resizeMouseDown (const mouseStates&); - void resizeMouseUpMove (const mouseStates&, bool = false); + bool isLeftOutside() const; + bool isBottomOutside() const; + bool isLowerRightResizeCorner (const MouseStates&) const; + void resizeMouseDown (const MouseStates&); + void resizeMouseUpMove (const MouseStates&, bool = false); void cancelMouseResize(); void acceptMoveSize(); void cancelMoveSize(); @@ -237,11 +239,11 @@ class FDialog : public FWindow // FDialog inline functions //---------------------------------------------------------------------- -inline const FString FDialog::getClassName() const +inline FString FDialog::getClassName() const { return "FDialog"; } //---------------------------------------------------------------------- -inline const FString FDialog::getText() const +inline FString FDialog::getText() const { return tb_text; } //---------------------------------------------------------------------- diff --git a/src/include/final/fdialoglistmenu.h b/src/include/final/fdialoglistmenu.h index e80f8953..f753242e 100644 --- a/src/include/final/fdialoglistmenu.h +++ b/src/include/final/fdialoglistmenu.h @@ -84,7 +84,7 @@ class FDialogListMenu : public FMenu FDialogListMenu& operator = (const FDialogListMenu&) = delete; // Accessors - const FString getClassName() const override; + FString getClassName() const override; private: // Method @@ -94,7 +94,7 @@ class FDialogListMenu : public FMenu // FDialogListMenu inline functions //---------------------------------------------------------------------- -inline const FString FDialogListMenu::getClassName() const +inline FString FDialogListMenu::getClassName() const { return "FDialogListMenu"; } } // namespace finalcut diff --git a/src/include/final/fevent.h b/src/include/final/fevent.h index b4c8873b..d59610ac 100644 --- a/src/include/final/fevent.h +++ b/src/include/final/fevent.h @@ -68,9 +68,9 @@ * ├─────▏FTimerEvent ▏ * │ ▕▁▁▁▁▁▁▁▁▁▁▁▁▁▏ * │ - * │ ▕▔▔▔▔▔▔▔▔▔▔▔▔▔▏ - * └─────▏FUserEvent ▏ - * ▕▁▁▁▁▁▁▁▁▁▁▁▁▁▏ + * │ ▕▔▔▔▔▔▔▔▔▔▔▔▔▏1 1▕▔▔▔▔▔▔▔▏ + * └─────▏FUserEvent ▏- - - -▕ FData ▏ + * ▕▁▁▁▁▁▁▁▁▁▁▁▁▏ ▕▁▁▁▁▁▁▁▏ */ #ifndef FEVENT_H @@ -80,7 +80,11 @@ #error "Only can be included directly." #endif +#include +#include + #include "final/fc.h" +#include "final/fdata.h" #include "final/fpoint.h" #include "final/ftypes.h" @@ -184,9 +188,9 @@ class FWheelEvent : public FEvent // wheel event int getWheel() const; private: - FPoint p; - FPoint tp; - int w; + FPoint p{}; + FPoint tp{}; + int w{}; }; @@ -342,15 +346,53 @@ class FUserEvent : public FEvent // user event // Disable copy assignment operator (=) FUserEvent& operator = (const FUserEvent&) = delete; - int getUserId() const; - FDataPtr getData() const; - void setData (FDataPtr); + int getUserId() const; + template + FData&& getFDataObject() const; + template + clean_fdata_t& getData() const; + template + void setFDataObject (T&&); + template + void setData (T&&); private: - int uid{0}; - FDataPtr data_pointer{nullptr}; + // Using-declaration + using FDataAccessPtr = std::shared_ptr; + + // Data members + int uid{0}; + FDataAccessPtr data_pointer{nullptr}; }; +//---------------------------------------------------------------------- +template +inline FData&& FUserEvent::getFDataObject() const +{ + return static_cast&&>(*data_pointer); +} + +//---------------------------------------------------------------------- +template +inline clean_fdata_t& FUserEvent::getData() const +{ + return static_cast>&>(*data_pointer).get(); +} + +//---------------------------------------------------------------------- +template +inline void FUserEvent::setFDataObject (T&& fdata) +{ + data_pointer.reset(&(std::forward(fdata))); +} + +//---------------------------------------------------------------------- +template +inline void FUserEvent::setData (T&& data) +{ + data_pointer.reset(makeFData(std::forward(data))); +} + } // namespace finalcut #endif // FEVENT_H diff --git a/src/include/final/ffiledialog.h b/src/include/final/ffiledialog.h index eb4ab939..04e366e6 100644 --- a/src/include/final/ffiledialog.h +++ b/src/include/final/ffiledialog.h @@ -112,10 +112,10 @@ class FFileDialog : public FDialog FFileDialog& operator = (const FFileDialog&); // Accessors - const FString getClassName() const override; - const FString getPath() const; - const FString getFilter() const; - const FString getSelectedFile() const; + FString getClassName() const override; + FString getPath() const; + FString getFilter() const; + FString getSelectedFile() const; bool getShowHiddenFiles() const; // Mutators @@ -129,12 +129,12 @@ class FFileDialog : public FDialog void onKeyPress (FKeyEvent*) override; // Methods - static const FString fileOpenChooser ( FWidget* - , const FString& = FString() - , const FString& = FString() ); - static const FString fileSaveChooser ( FWidget* - , const FString& = FString() - , const FString& = FString() ); + static FString fileOpenChooser ( FWidget* + , const FString& = FString() + , const FString& = FString() ); + static FString fileSaveChooser ( FWidget* + , const FString& = FString() + , const FString& = FString() ); protected: // Method @@ -186,7 +186,7 @@ class FFileDialog : public FDialog uChar : 1; // padding bits }; - typedef std::vector dirEntries; + typedef std::vector DirEntries; // Methods void init(); @@ -203,7 +203,7 @@ class FFileDialog : public FDialog void selectDirectoryEntry (const char* const); int changeDir (const FString&); void printPath (const FString&); - static const FString getHomeDir(); + static FString getHomeDir(); // Callback methods void cb_processActivate(); @@ -216,7 +216,7 @@ class FFileDialog : public FDialog // Data members static FSystem* fsystem; DIR* directory_stream{nullptr}; - dirEntries dir_entries{}; + DirEntries dir_entries{}; FString directory{}; FString filter_pattern{}; FLineEdit filename{this}; @@ -232,23 +232,23 @@ class FFileDialog : public FDialog , const FFileDialog::FDirEntry& ); friend bool sortDirFirst ( const FFileDialog::FDirEntry& , const FFileDialog::FDirEntry& ); - friend const FString fileChooser ( FWidget* - , const FString& - , const FString& - , FFileDialog::DialogType); + friend FString fileChooser ( FWidget* + , const FString& + , const FString& + , FFileDialog::DialogType); }; // FMessageBox inline functions //---------------------------------------------------------------------- -inline const FString FFileDialog::getClassName() const +inline FString FFileDialog::getClassName() const { return "FFileDialog"; } //---------------------------------------------------------------------- -inline const FString FFileDialog::getPath() const +inline FString FFileDialog::getPath() const { return directory; } //---------------------------------------------------------------------- -inline const FString FFileDialog::getFilter() const +inline FString FFileDialog::getFilter() const { return filter_pattern; } //---------------------------------------------------------------------- diff --git a/src/include/final/final.h b/src/include/final/final.h index dc363458..248f5627 100644 --- a/src/include/final/final.h +++ b/src/include/final/final.h @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include diff --git a/src/include/final/fkey_map.h b/src/include/final/fkey_map.h index 5a623e42..ea5b6d47 100644 --- a/src/include/final/fkey_map.h +++ b/src/include/final/fkey_map.h @@ -3,7 +3,7 @@ * * * This file is part of the FINAL CUT widget toolkit * * * -* Copyright 2015-2019 Markus Gans * +* Copyright 2015-2020 Markus Gans * * * * FINAL CUT is free software; you can redistribute it and/or modify * * it under the terms of the GNU Lesser General Public License as * @@ -27,15 +27,19 @@ #error "Only can be included directly." #endif +#include + +#include "final/ftypes.h" + namespace finalcut { namespace fc { -extern FKeyMap fkey[]; -extern FMetakeyMap fmetakey[]; -extern FKeyName fkeyname[]; +extern std::array fkey; +extern const std::array fmetakey; +extern const std::array fkeyname; } // namespace fc diff --git a/src/include/final/fkeyboard.h b/src/include/final/fkeyboard.h index 6f090aa7..77bd0969 100644 --- a/src/include/final/fkeyboard.h +++ b/src/include/final/fkeyboard.h @@ -36,7 +36,12 @@ #endif #include + +#include #include +#include + +#include "final/fkey_map.h" #include "final/fstring.h" #include "final/ftypes.h" @@ -99,18 +104,22 @@ class FKeyboard final FKeyboard& operator = (const FKeyboard&) = delete; // Accessors - const FString getClassName() const; + FString getClassName() const; FKey getKey() const; - const FString getKeyName (const FKey) const; + FString getKeyName (const FKey) const; keybuffer& getKeyBuffer(); timeval* getKeyPressedTime(); static uInt64 getKeypressTimeout(); static uInt64 getReadBlockingTime(); // Mutators - void setTermcapMap (fc::FKeyMap*); + template + void setTermcapMap (const T&); static void setKeypressTimeout (const uInt64); static void setReadBlockingTime (const uInt64); + bool setNonBlockingInput (bool); + bool setNonBlockingInput(); + bool unsetNonBlockingInput(); void enableUTF8(); void disableUTF8(); void enableMouseSequences(); @@ -132,6 +141,9 @@ class FKeyboard final void escapeKeyHandling(); private: + // Using-declaration + using FKeyMapPtr = std::shared_ptr; + // Constants static constexpr FKey NOT_SET = static_cast(-1); @@ -141,11 +153,6 @@ class FKeyboard final FKey getMetaKey(); FKey getSingleKey(); - // Mutators - bool setNonBlockingInput (bool); - bool setNonBlockingInput(); - bool unsetNonBlockingInput(); - // Inquiry static bool isKeypressTimeout(); static bool isIntervalTimeout(); @@ -176,7 +183,7 @@ class FKeyboard final static uInt64 read_blocking_time; static uInt64 key_timeout; static uInt64 interval_timeout; - fc::FKeyMap* key_map{nullptr}; + FKeyMapPtr key_map{}; FKey key{0}; uChar read_character{}; char fifo_buf[FIFO_BUF_SIZE]{'\0'}; @@ -191,7 +198,7 @@ class FKeyboard final // FKeyboard inline functions //---------------------------------------------------------------------- -inline const FString FKeyboard::getClassName() const +inline FString FKeyboard::getClassName() const { return "FKeyboard"; } //---------------------------------------------------------------------- @@ -214,6 +221,11 @@ inline uInt64 FKeyboard::getKeypressTimeout() inline uInt64 FKeyboard::getReadBlockingTime() { return read_blocking_time; } +//---------------------------------------------------------------------- +template +inline void FKeyboard::setTermcapMap (const T& keymap) +{ key_map = std::make_shared(keymap); } + //---------------------------------------------------------------------- inline void FKeyboard::setKeypressTimeout (const uInt64 timeout) { key_timeout = timeout; } @@ -222,6 +234,18 @@ inline void FKeyboard::setKeypressTimeout (const uInt64 timeout) inline void FKeyboard::setReadBlockingTime (const uInt64 blocking_time) { read_blocking_time = blocking_time; } +//---------------------------------------------------------------------- +inline bool FKeyboard::setNonBlockingInput() +{ return setNonBlockingInput(true); } + +//---------------------------------------------------------------------- +inline bool FKeyboard::unsetNonBlockingInput() +{ return setNonBlockingInput(false); } + +//---------------------------------------------------------------------- +inline bool FKeyboard::isInputDataPending() const +{ return input_data_pending; } + //---------------------------------------------------------------------- inline void FKeyboard::enableUTF8() { utf8_input = true; } @@ -250,17 +274,6 @@ inline void FKeyboard::setReleaseCommand (const FKeyboardCommand& cmd) inline void FKeyboard::setEscPressedCommand (const FKeyboardCommand& cmd) { escape_key_cmd = cmd; } -//---------------------------------------------------------------------- -inline bool FKeyboard::isInputDataPending() const -{ return input_data_pending; } -//---------------------------------------------------------------------- -inline bool FKeyboard::setNonBlockingInput() -{ return setNonBlockingInput(true); } - -//---------------------------------------------------------------------- -inline bool FKeyboard::unsetNonBlockingInput() -{ return setNonBlockingInput(false); } - } // namespace finalcut #endif // FKEYBOARD_H diff --git a/src/include/final/flabel.h b/src/include/final/flabel.h index d9c82cef..b6e7a637 100644 --- a/src/include/final/flabel.h +++ b/src/include/final/flabel.h @@ -87,7 +87,7 @@ class FLabel : public FWidget const FLabel& operator >> (FString&) const; // Accessors - const FString getClassName() const override; + FString getClassName() const override; FWidget* getAccelWidget(); fc::text_alignment getAlignment() const; FString& getText(); @@ -127,7 +127,7 @@ class FLabel : public FWidget private: // Constants - static constexpr std::size_t NOT_SET = static_cast(-1); + static constexpr auto NOT_SET = static_cast(-1); // Methods void init(); @@ -165,7 +165,7 @@ inline FLabel& FLabel::operator << (const typeT& s) } //---------------------------------------------------------------------- -inline const FString FLabel::getClassName() const +inline FString FLabel::getClassName() const { return "FLabel"; } //---------------------------------------------------------------------- diff --git a/src/include/final/flineedit.h b/src/include/final/flineedit.h index 25c36aa9..7c28aebe 100644 --- a/src/include/final/flineedit.h +++ b/src/include/final/flineedit.h @@ -103,7 +103,7 @@ class FLineEdit : public FWidget const FLineEdit& operator >> (FString&) const; // Accessors - const FString getClassName() const override; + FString getClassName() const override; FString getText() const; std::size_t getMaxLength() const; std::size_t getCursorPosition() const; @@ -175,7 +175,7 @@ class FLineEdit : public FWidget }; // Constants - static constexpr std::size_t NOT_SET = static_cast(-1); + static constexpr auto NOT_SET = static_cast(-1); // Methods void init(); @@ -185,7 +185,7 @@ class FLineEdit : public FWidget std::size_t printTextField(); std::size_t printPassword(); std::size_t getCursorColumnPos() const; - const FString getPasswordText() const; + FString getPasswordText() const; bool isPasswordField() const; offsetPair endPosToOffset (std::size_t); std::size_t clickPosToCursorPos (std::size_t); @@ -237,7 +237,7 @@ inline FLineEdit& FLineEdit::operator << (const typeT& s) } //---------------------------------------------------------------------- -inline const FString FLineEdit::getClassName() const +inline FString FLineEdit::getClassName() const { return "FLineEdit"; } //---------------------------------------------------------------------- diff --git a/src/include/final/flistbox.h b/src/include/final/flistbox.h index e5100a8c..d763a5eb 100644 --- a/src/include/final/flistbox.h +++ b/src/include/final/flistbox.h @@ -35,9 +35,9 @@ * ▕▁▁▁▁▁▁▁▁▁▏ * ▲ * │ - * ▕▔▔▔▔▔▔▔▔▔▔▏1 *▕▔▔▔▔▔▔▔▔▔▔▔▔▔▔▏ - * ▕ FListBox ▏- - - -▕ FListBoxItem ▏ - * ▕▁▁▁▁▁▁▁▁▁▁▏ ▕▁▁▁▁▁▁▁▁▁▁▁▁▁▁▏ + * ▕▔▔▔▔▔▔▔▔▔▔▏1 *▕▔▔▔▔▔▔▔▔▔▔▔▔▔▔▏1 1▕▔▔▔▔▔▔▔▏ + * ▕ FListBox ▏- - - -▕ FListBoxItem ▏- - - -▕ FData ▏ + * ▕▁▁▁▁▁▁▁▁▁▁▏ ▕▁▁▁▁▁▁▁▁▁▁▁▁▁▁▏ ▕▁▁▁▁▁▁▁▏ * */ @@ -48,9 +48,12 @@ #error "Only can be included directly." #endif +#include #include +#include #include +#include "final/fdata.h" #include "final/fscrollbar.h" #include "final/fwidget.h" @@ -72,7 +75,8 @@ class FListBoxItem // Constructors FListBoxItem (); FListBoxItem (const FListBoxItem&); // copy constructor - explicit FListBoxItem (const FString&, FDataPtr = nullptr); + template + explicit FListBoxItem (const FString&, DT&& = DT() ); // Destructor virtual ~FListBoxItem(); @@ -81,21 +85,29 @@ class FListBoxItem FListBoxItem& operator = (const FListBoxItem&); // Accessors - virtual const FString getClassName() const; + virtual FString getClassName() const; virtual FString getText() const; - virtual FDataPtr getData() const; + template + clean_fdata_t
& getData() const; // Mutators void setText (const FString&); - void setData (FDataPtr); + template + void setData (DT&&); + + // Inquiries + bool isSelected() const; // Methods void clear(); private: + // Using-declaration + using FDataAccessPtr = std::shared_ptr; + // Data members FString text{}; - FDataPtr data_pointer{nullptr}; + FDataAccessPtr data_pointer{}; fc::brackets_type brackets{fc::NoBrackets}; bool selected{false}; @@ -106,7 +118,14 @@ class FListBoxItem // FListBoxItem inline functions //---------------------------------------------------------------------- -inline const FString FListBoxItem::getClassName() const +template +inline FListBoxItem::FListBoxItem (const FString& txt, DT&& data) + : text{txt} + , data_pointer{makeFData(std::forward
(data))} +{ } + +//---------------------------------------------------------------------- +inline FString FListBoxItem::getClassName() const { return "FListBoxItem"; } //---------------------------------------------------------------------- @@ -114,16 +133,27 @@ inline FString FListBoxItem::getText() const { return text; } //---------------------------------------------------------------------- -inline FDataPtr FListBoxItem::getData() const -{ return data_pointer; } +template +inline clean_fdata_t
& FListBoxItem::getData() const +{ + return static_cast>&>(*data_pointer).get(); +} //---------------------------------------------------------------------- inline void FListBoxItem::setText (const FString& txt) { text.setString(txt); } //---------------------------------------------------------------------- -inline void FListBoxItem::setData (FDataPtr data) -{ data_pointer = data; } +template +inline void FListBoxItem::setData (DT&& data) +{ + const auto data_obj = makeFData(std::forward
(data)); + data_pointer.reset(data_obj); +} + +//---------------------------------------------------------------------- +inline bool FListBoxItem::isSelected() const +{ return selected; } //---------------------------------------------------------------------- inline void FListBoxItem::clear() @@ -141,13 +171,15 @@ class FListBox : public FWidget using FWidget::setGeometry; // Typedef - typedef std::vector listBoxItems; + typedef std::vector FListBoxItems; // Constructor explicit FListBox (FWidget* = nullptr); - template + template FListBox (Iterator, Iterator, InsertConverter, FWidget* = nullptr); - template + template FListBox (Container, LazyConverter, FWidget* = nullptr); // Disable copy constructor @@ -160,83 +192,94 @@ class FListBox : public FWidget FListBox& operator = (const FListBox&) = delete; // Accessors - const FString getClassName() const override; - std::size_t getCount() const; - FListBoxItem& getItem (std::size_t); - const FListBoxItem& getItem (std::size_t) const; - FListBoxItem& getItem (listBoxItems::iterator); - const FListBoxItem& getItem (listBoxItems::const_iterator) const; - std::size_t currentItem() const; - FString& getText(); + FString getClassName() const override; + std::size_t getCount() const; + FListBoxItem& getItem (std::size_t); + const FListBoxItem& getItem (std::size_t) const; + FListBoxItem& getItem (FListBoxItems::iterator); + const FListBoxItem& getItem (FListBoxItems::const_iterator) const; + std::size_t currentItem() const; + FListBoxItems& getData(); + const FListBoxItems& getData() const; + FString& getText(); // Mutators - void setCurrentItem (std::size_t); - void setCurrentItem (listBoxItems::iterator); - void selectItem (std::size_t); - void selectItem (listBoxItems::iterator) const; - void unselectItem (std::size_t); - void unselectItem (listBoxItems::iterator) const; - void showInsideBrackets (const std::size_t, fc::brackets_type); - void showNoBrackets (std::size_t); - void showNoBrackets (listBoxItems::iterator) const; - void setSize (const FSize&, bool = true) override; - void setGeometry ( const FPoint&, const FSize& - , bool = true ) override; - void setMultiSelection (bool); - void setMultiSelection (); - void unsetMultiSelection (); - bool setDisable() override; - void setText (const FString&); + void setCurrentItem (std::size_t); + void setCurrentItem (FListBoxItems::iterator); + void selectItem (std::size_t); + void selectItem (FListBoxItems::iterator) const; + void unselectItem (std::size_t); + void unselectItem (FListBoxItems::iterator) const; + void showInsideBrackets (const std::size_t, fc::brackets_type); + void showNoBrackets (std::size_t); + void showNoBrackets (FListBoxItems::iterator) const; + void setSize (const FSize&, bool = true) override; + void setGeometry ( const FPoint&, const FSize& + , bool = true ) override; + void setMultiSelection (bool); + void setMultiSelection (); + void unsetMultiSelection (); + bool setDisable() override; + void setText (const FString&); // Inquiries - bool isSelected (std::size_t) const; - bool isSelected (listBoxItems::iterator) const; - bool isMultiSelection() const; - bool hasBrackets (std::size_t) const; - bool hasBrackets (listBoxItems::iterator) const; + bool isSelected (std::size_t) const; + bool isSelected (FListBoxItems::iterator) const; + bool isMultiSelection() const; + bool hasBrackets (std::size_t) const; + bool hasBrackets (FListBoxItems::iterator) const; // Methods - void hide() override; - template - void insert (Iterator, Iterator, InsertConverter); - template - void insert (Container, LazyConverter); - void insert (const FListBoxItem&); - template - void insert ( const std::initializer_list& list - , fc::brackets_type = fc::NoBrackets - , bool = false - , FDataPtr = nullptr ); - template - void insert ( const ItemT& - , fc::brackets_type = fc::NoBrackets - , bool = false - , FDataPtr = nullptr ); - void remove (std::size_t); - void reserve (std::size_t); - void clear(); + void hide() override; + template + void insert ( Iterator, Iterator + , const InsertConverter& ); + template + void insert ( const Container& + , const LazyConverter& ); + template + void insert (Container*, const LazyConverter&); + void insert (const FListBoxItem&); + template + void insert ( const std::initializer_list& list + , fc::brackets_type = fc::NoBrackets + , bool = false + , DT&& = DT() ); + template + void insert ( const ItemT& + , fc::brackets_type = fc::NoBrackets + , bool = false + , DT&& = DT() ); + void remove (std::size_t); + void reserve (std::size_t); + void clear(); // Event handlers - void onKeyPress (FKeyEvent*) override; - void onMouseDown (FMouseEvent*) override; - void onMouseUp (FMouseEvent*) override; - void onMouseMove (FMouseEvent*) override; - void onMouseDoubleClick (FMouseEvent*) override; - void onWheel (FWheelEvent*) override; - void onTimer (FTimerEvent*) override; - void onFocusIn (FFocusEvent*) override; - void onFocusOut (FFocusEvent*) override; + void onKeyPress (FKeyEvent*) override; + void onMouseDown (FMouseEvent*) override; + void onMouseUp (FMouseEvent*) override; + void onMouseMove (FMouseEvent*) override; + void onMouseDoubleClick (FMouseEvent*) override; + void onWheel (FWheelEvent*) override; + void onTimer (FTimerEvent*) override; + void onFocusIn (FFocusEvent*) override; + void onFocusOut (FFocusEvent*) override; protected: // Methods - void adjustYOffset (std::size_t); - void adjustSize() override; + void adjustYOffset (std::size_t); + void adjustSize() override; private: // Typedefs - typedef std::unordered_map> keyMap; - typedef std::unordered_map> keyMapResult; - typedef std::function lazyInsert; + typedef std::unordered_map> KeyMap; + typedef std::unordered_map> KeyMapResult; + typedef std::function LazyInsert; // Enumeration enum convert_type @@ -247,83 +290,83 @@ class FListBox : public FWidget }; // Accessors - static FString getString (listBoxItems::iterator); + static FString getString (FListBoxItems::iterator); // Inquiry - bool isHorizontallyScrollable() const; - bool isVerticallyScrollable() const; + bool isHorizontallyScrollable() const; + bool isVerticallyScrollable() const; // Methods - void init(); - void mapKeyFunctions(); - void processKeyAction (FKeyEvent*); - void draw() override; - void drawBorder() override; - void drawScrollbars() const; - void drawHeadline(); - void drawList(); - void drawListLine (int, listBoxItems::iterator, bool); - void printLeftBracket (fc::brackets_type); - void printRightBracket (fc::brackets_type); - void drawListBracketsLine (int, listBoxItems::iterator, bool); - void setLineAttributes (int, bool, bool, bool&); - void unsetAttributes() const; - void updateDrawing (bool, bool); - void recalculateHorizontalBar (std::size_t, bool); - void recalculateVerticalBar (std::size_t) const; - void getWidgetFocus(); - void multiSelection (std::size_t); - void multiSelectionUpTo (std::size_t); - void wheelUp (int); - void wheelDown (int); - bool dragScrollUp(); - bool dragScrollDown(); - void dragUp (int); - void dragDown (int); - void stopDragScroll(); - void prevListItem (int); - void nextListItem (int); - void scrollToX (int); - void scrollToY (int); - void scrollLeft (int); - void scrollRight (int); - void scrollLeft(); - void scrollRight(); - void onePosUp(); - void onePosDown(); - void onePageUp(); - void onePageDown(); - void firstPos(); - void lastPos(); - bool skipIncrementalSearch(); - void acceptSelection(); - bool spacebarProcessing(); - bool changeSelectionAndPosition(); - bool deletePreviousCharacter(); - bool keyIncSearchInput (FKey); - void processClick() const; - void processSelect() const; - void processChanged() const; - void changeOnResize() const; - void lazyConvert (listBoxItems::iterator, int); - listBoxItems::iterator index2iterator (std::size_t); - listBoxItems::const_iterator index2iterator (std::size_t index) const; + void init(); + void mapKeyFunctions(); + void processKeyAction (FKeyEvent*); + void draw() override; + void drawBorder() override; + void drawScrollbars() const; + void drawHeadline(); + void drawList(); + void drawListLine (int, FListBoxItems::iterator, bool); + void printLeftBracket (fc::brackets_type); + void printRightBracket (fc::brackets_type); + void drawListBracketsLine (int, FListBoxItems::iterator, bool); + void setLineAttributes (int, bool, bool, bool&); + void unsetAttributes() const; + void updateDrawing (bool, bool); + void recalculateHorizontalBar (std::size_t, bool); + void recalculateVerticalBar (std::size_t) const; + void getWidgetFocus(); + void multiSelection (std::size_t); + void multiSelectionUpTo (std::size_t); + void wheelUp (int); + void wheelDown (int); + bool dragScrollUp(); + bool dragScrollDown(); + void dragUp (int); + void dragDown (int); + void stopDragScroll(); + void prevListItem (int); + void nextListItem (int); + void scrollToX (int); + void scrollToY (int); + void scrollLeft (int); + void scrollRight (int); + void scrollLeft(); + void scrollRight(); + void onePosUp(); + void onePosDown(); + void onePageUp(); + void onePageDown(); + void firstPos(); + void lastPos(); + bool skipIncrementalSearch(); + void acceptSelection(); + bool spacebarProcessing(); + bool changeSelectionAndPosition(); + bool deletePreviousCharacter(); + bool keyIncSearchInput (FKey); + void processClick() const; + void processSelect() const; + void processChanged() const; + void changeOnResize() const; + void lazyConvert (FListBoxItems::iterator, std::size_t); + FListBoxItems::iterator index2iterator (std::size_t); + FListBoxItems::const_iterator index2iterator (std::size_t index) const; // Callback methods - void cb_vbarChange (const FWidget*); - void cb_hbarChange (const FWidget*); + void cb_vbarChange (const FWidget*); + void cb_hbarChange (const FWidget*); // Function Pointer - lazyInsert lazy_inserter{}; + LazyInsert lazy_inserter{}; // Data members - listBoxItems itemlist{}; - FDataPtr source_container{nullptr}; + FListBoxItems itemlist{}; + FDataAccess* source_container{nullptr}; FScrollbarPtr vbar{nullptr}; FScrollbarPtr hbar{nullptr}; FString text{}; FString inc_search{}; - keyMap key_map{}; - keyMapResult key_map_result{}; + KeyMap key_map{}; + KeyMapResult key_map_result{}; convert_type conv_type{FListBox::no_convert}; fc::dragScroll drag_scroll{fc::noScroll}; int scroll_repeat{100}; @@ -342,10 +385,23 @@ class FListBox : public FWidget bool click_on_list{false}; }; +// non-member function +//---------------------------------------------------------------------- +namespace flistboxhelper +{ + +template +constexpr clean_fdata_t& getContainer(FDataAccess* container) +{ + return static_cast>&>(*container).get(); +} + +} // namespace flistboxhelper // FListBox inline functions //---------------------------------------------------------------------- -template +template inline FListBox::FListBox ( Iterator first , Iterator last , InsertConverter convert @@ -362,7 +418,8 @@ inline FListBox::FListBox ( Iterator first } //---------------------------------------------------------------------- -template +template inline FListBox::FListBox ( Container container , LazyConverter convert , FWidget* parent ) @@ -373,7 +430,7 @@ inline FListBox::FListBox ( Container container } //---------------------------------------------------------------------- -inline const FString FListBox::getClassName() const +inline FString FListBox::getClassName() const { return "FListBox"; } //---------------------------------------------------------------------- @@ -383,29 +440,37 @@ inline std::size_t FListBox::getCount() const //---------------------------------------------------------------------- inline FListBoxItem& FListBox::getItem (std::size_t index) { - listBoxItems::iterator iter = index2iterator(index - 1); + FListBoxItems::iterator iter = index2iterator(index - 1); return *iter; } //---------------------------------------------------------------------- inline const FListBoxItem& FListBox::getItem (std::size_t index) const { - listBoxItems::const_iterator iter = index2iterator(index - 1); + FListBoxItems::const_iterator iter = index2iterator(index - 1); return *iter; } //---------------------------------------------------------------------- -inline FListBoxItem& FListBox::getItem (listBoxItems::iterator iter) +inline FListBoxItem& FListBox::getItem (FListBoxItems::iterator iter) { return *iter; } //---------------------------------------------------------------------- -inline const FListBoxItem& FListBox::getItem (listBoxItems::const_iterator iter) const +inline const FListBoxItem& FListBox::getItem (FListBoxItems::const_iterator iter) const { return *iter; } //---------------------------------------------------------------------- inline std::size_t FListBox::currentItem() const { return current; } +//---------------------------------------------------------------------- +inline FListBox::FListBoxItems& FListBox::getData() +{ return itemlist; } + +//---------------------------------------------------------------------- +inline const FListBox::FListBoxItems& FListBox::getData() const +{ return itemlist; } + //---------------------------------------------------------------------- inline FString& FListBox::getText() { return text; } @@ -415,7 +480,7 @@ inline void FListBox::selectItem (std::size_t index) { index2iterator(index - 1)->selected = true; } //---------------------------------------------------------------------- -inline void FListBox::selectItem (listBoxItems::iterator iter) const +inline void FListBox::selectItem (FListBoxItems::iterator iter) const { iter->selected = true; } //---------------------------------------------------------------------- @@ -423,7 +488,7 @@ inline void FListBox::unselectItem (std::size_t index) { index2iterator(index - 1)->selected = false; } //---------------------------------------------------------------------- -inline void FListBox::unselectItem (listBoxItems::iterator iter) const +inline void FListBox::unselectItem (FListBoxItems::iterator iter) const { iter->selected = false; } //---------------------------------------------------------------------- @@ -431,7 +496,7 @@ inline void FListBox::showNoBrackets (std::size_t index) { index2iterator(index - 1)->brackets = fc::NoBrackets; } //---------------------------------------------------------------------- -inline void FListBox::showNoBrackets (listBoxItems::iterator iter) const +inline void FListBox::showNoBrackets (FListBoxItems::iterator iter) const { iter->brackets = fc::NoBrackets; } //---------------------------------------------------------------------- @@ -455,7 +520,7 @@ inline bool FListBox::isSelected (std::size_t index) const { return index2iterator(index - 1)->selected; } //---------------------------------------------------------------------- -inline bool FListBox::isSelected (listBoxItems::iterator iter) const +inline bool FListBox::isSelected (FListBoxItems::iterator iter) const { return iter->selected; } //---------------------------------------------------------------------- @@ -467,7 +532,7 @@ inline bool FListBox::hasBrackets(std::size_t index) const { return bool(index2iterator(index - 1)->brackets > 0); } //---------------------------------------------------------------------- -inline bool FListBox::hasBrackets(listBoxItems::iterator iter) const +inline bool FListBox::hasBrackets(FListBoxItems::iterator iter) const { return bool(iter->brackets > 0); } //---------------------------------------------------------------------- @@ -475,10 +540,11 @@ inline void FListBox::reserve (std::size_t new_cap) { itemlist.reserve(new_cap); } //---------------------------------------------------------------------- -template +template inline void FListBox::insert ( Iterator first , Iterator last - , InsertConverter convert ) + , const InsertConverter& convert ) { conv_type = direct_convert; @@ -490,13 +556,14 @@ inline void FListBox::insert ( Iterator first } //---------------------------------------------------------------------- -template -void FListBox::insert (Container container, LazyConverter convert) +template +void FListBox::insert (const Container& container, const LazyConverter& converter) { conv_type = lazy_convert; - source_container = container; - lazy_inserter = convert; - const std::size_t size = container->size(); + source_container = makeFData(container); + lazy_inserter = converter; + const std::size_t size = container.size(); if ( size > 0 ) itemlist.resize(size); @@ -505,15 +572,24 @@ void FListBox::insert (Container container, LazyConverter convert) } //---------------------------------------------------------------------- -template +template +void FListBox::insert (Container* container, const LazyConverter& converter) +{ + insert (*container, converter); +} + +//---------------------------------------------------------------------- +template void FListBox::insert ( const std::initializer_list& list , fc::brackets_type b , bool s - , FDataPtr d ) + , DT&& d ) { for (auto& item : list) { - FListBoxItem listItem (FString() << item, d); + FListBoxItem listItem (FString() << item, std::forward
(d)); listItem.brackets = b; listItem.selected = s; insert (listItem); @@ -521,13 +597,14 @@ void FListBox::insert ( const std::initializer_list& list } //---------------------------------------------------------------------- -template +template void FListBox::insert ( const ItemT& item , fc::brackets_type b , bool s - , FDataPtr d ) + , DT&& d ) { - FListBoxItem listItem (FString() << item, d); + FListBoxItem listItem (FString() << item, std::forward
(d)); listItem.brackets = b; listItem.selected = s; insert (listItem); @@ -542,19 +619,19 @@ inline bool FListBox::isVerticallyScrollable() const { return bool( getCount() > getClientHeight() ); } //---------------------------------------------------------------------- -inline FListBox::listBoxItems::iterator \ +inline FListBox::FListBoxItems::iterator \ FListBox::index2iterator (std::size_t index) { - listBoxItems::iterator iter = itemlist.begin(); + FListBoxItems::iterator iter = itemlist.begin(); std::advance (iter, index); return iter; } //---------------------------------------------------------------------- -inline FListBox::listBoxItems::const_iterator \ +inline FListBox::FListBoxItems::const_iterator \ FListBox::index2iterator (std::size_t index) const { - listBoxItems::const_iterator iter = itemlist.begin(); + FListBoxItems::const_iterator iter = itemlist.begin(); std::advance (iter, index); return iter; } diff --git a/src/include/final/flistview.h b/src/include/final/flistview.h index 6bb84a90..388b83c8 100644 --- a/src/include/final/flistview.h +++ b/src/include/final/flistview.h @@ -35,9 +35,9 @@ * ▕▁▁▁▁▁▁▁▁▁▏ ▕▁▁▁▁▁▁▁▁▁▏ * ▲ ▲ * │ │ - * ▕▔▔▔▔▔▔▔▔▔▔▔▏1 *▕▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▏ - * ▕ FListView ▏- - - -▕ FListViewItem ▏ - * ▕▁▁▁▁▁▁▁▁▁▁▁▏ ▕▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▏ + * ▕▔▔▔▔▔▔▔▔▔▔▔▏1 *▕▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▏1 1▕▔▔▔▔▔▔▔▏ + * ▕ FListView ▏- - - -▕ FListViewItem ▏- - - -▕ FData ▏ + * ▕▁▁▁▁▁▁▁▁▁▁▁▏ ▕▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▏ ▕▁▁▁▁▁▁▁▏ */ #ifndef FLISTVIEW_H @@ -48,12 +48,15 @@ #endif #include +#include #include #include #include +#include "final/fdata.h" #include "final/fscrollbar.h" #include "final/ftermbuffer.h" +#include "final/ftypes.h" #include "final/fwidget.h" namespace finalcut @@ -74,9 +77,8 @@ class FListViewItem : public FObject // Constructor FListViewItem (const FListViewItem&); // copy constructor explicit FListViewItem (iterator); - FListViewItem ( const FStringList& - , FDataPtr - , iterator ); + template + FListViewItem (const FStringList&, DT&&, iterator); // Destructor ~FListViewItem() override; @@ -85,16 +87,18 @@ class FListViewItem : public FObject FListViewItem& operator = (const FListViewItem&); // Accessors - const FString getClassName() const override; + FString getClassName() const override; uInt getColumnCount() const; int getSortColumn() const; FString getText (int) const; - FDataPtr getData() const; + template + clean_fdata_t
& getData() const; uInt getDepth() const; // Mutators void setText (int, const FString&); - void setData (FDataPtr); + template + void setData (DT&&); void setCheckable (bool); void setChecked (bool); @@ -110,6 +114,9 @@ class FListViewItem : public FObject void collapse(); private: + // Using-declaration + using FDataAccessPtr = std::shared_ptr; + // Inquiry bool isExpandable() const; bool isCheckable() const; @@ -124,7 +131,7 @@ class FListViewItem : public FObject // Data members FStringList column_list{}; - FDataPtr data_pointer{nullptr}; + FDataAccessPtr data_pointer{}; iterator root{}; std::size_t visible_lines{1}; bool expandable{false}; @@ -140,7 +147,23 @@ class FListViewItem : public FObject // FListViewItem inline functions //---------------------------------------------------------------------- -inline const FString FListViewItem::getClassName() const +template +inline FListViewItem::FListViewItem ( const FStringList& cols + , DT&& data + , iterator parent_iter ) + : FObject{nullptr} + , column_list{cols} + , data_pointer{makeFData(std::forward
(data))} +{ + if ( cols.empty() ) + return; + + replaceControlCodes(); + insert (this, parent_iter); +} + +//---------------------------------------------------------------------- +inline FString FListViewItem::getClassName() const { return "FListViewItem"; } //---------------------------------------------------------------------- @@ -148,12 +171,19 @@ inline uInt FListViewItem::getColumnCount() const { return uInt(column_list.size()); } //---------------------------------------------------------------------- -inline FDataPtr FListViewItem::getData() const -{ return data_pointer; } +template +inline clean_fdata_t
& FListViewItem::getData() const +{ + return static_cast>&>(*data_pointer).get(); +} //---------------------------------------------------------------------- -inline void FListViewItem::setData (FDataPtr data) -{ data_pointer = data; } +template +inline void FListViewItem::setData (DT&& data) +{ + const auto data_obj = makeFData(std::forward
(data)); + data_pointer = data_obj; +} //---------------------------------------------------------------------- inline void FListViewItem::setChecked (bool checked) @@ -212,7 +242,7 @@ class FListViewIterator bool operator != (const FListViewIterator&) const; // Accessor - const FString getClassName() const; + FString getClassName() const; int& getPosition(); // Methods @@ -248,7 +278,7 @@ inline bool FListViewIterator::operator != (const FListViewIterator& rhs) const { return node != rhs.node; } //---------------------------------------------------------------------- -inline const FString FListViewIterator::getClassName() const +inline FString FListViewIterator::getClassName() const { return "FListViewIterator"; } //---------------------------------------------------------------------- @@ -266,6 +296,9 @@ class FListView : public FWidget // Using-declaration using FWidget::setGeometry; + // Typedef + typedef std::list FListViewItems; + // Constructor explicit FListView (FWidget* = nullptr); @@ -279,212 +312,219 @@ class FListView : public FWidget FListView& operator = (const FListView&) = delete; // Accessors - const FString getClassName() const override; - std::size_t getCount() const; - fc::text_alignment getColumnAlignment (int) const; - FString getColumnText (int) const; - fc::sorting_type getColumnSortType (int) const; - fc::sorting_order getSortOrder() const; - int getSortColumn() const; - FListViewItem* getCurrentItem(); + FString getClassName() const override; + std::size_t getCount() const; + fc::text_alignment getColumnAlignment (int) const; + FString getColumnText (int) const; + fc::sorting_type getColumnSortType (int) const; + fc::sorting_order getSortOrder() const; + int getSortColumn() const; + FListViewItem* getCurrentItem(); // Mutators - void setSize (const FSize&, bool = true) override; - void setGeometry ( const FPoint&, const FSize& - , bool = true ) override; - void setColumnAlignment (int, fc::text_alignment); - void setColumnText (int, const FString&); - void setColumnSortType (int, fc::sorting_type \ - = fc::by_name); - void setColumnSort (int, fc::sorting_order \ - = fc::ascending); + void setSize (const FSize&, bool = true) override; + void setGeometry ( const FPoint&, const FSize& + , bool = true ) override; + void setColumnAlignment (int, fc::text_alignment); + void setColumnText (int, const FString&); + void setColumnSortType (int, fc::sorting_type \ + = fc::by_name); + void setColumnSort (int, fc::sorting_order \ + = fc::ascending); template - void setUserAscendingCompare (Compare); + void setUserAscendingCompare (Compare); template - void setUserDescendingCompare (Compare); - void hideSortIndicator (bool); - bool setTreeView (bool); - bool setTreeView(); - bool unsetTreeView(); + void setUserDescendingCompare (Compare); + void hideSortIndicator (bool); + bool setTreeView (bool); + bool setTreeView(); + bool unsetTreeView(); // Methods - virtual int addColumn (const FString&, int = USE_MAX_SIZE); - void hide() override; - iterator insert (FListViewItem*); - iterator insert (FListViewItem*, iterator); - iterator insert ( const FStringList& - , FDataPtr = nullptr ); - iterator insert ( const FStringList& - , iterator ); - iterator insert ( const FStringList& - , FDataPtr - , iterator ); + virtual int addColumn (const FString&, int = USE_MAX_SIZE); + void hide() override; + iterator insert (FListViewItem*); + iterator insert (FListViewItem*, iterator); + template + iterator insert ( const FStringList& + , DT&& = DT() ); + iterator insert ( const FStringList& + , iterator ); + template + iterator insert ( const FStringList& + , DT&& + , iterator ); + template + iterator insert ( const std::initializer_list& + , DT&& = DT() ); template - iterator insert ( const std::initializer_list& - , FDataPtr = nullptr ); - template - iterator insert ( const std::initializer_list& - , iterator ); - template - iterator insert ( const std::initializer_list& - , FDataPtr - , iterator ); + iterator insert ( const std::initializer_list& + , iterator ); + template + iterator insert ( const std::initializer_list& + , DT&& + , iterator ); + template + iterator insert ( const std::vector& + , DT&& = DT() ); template - iterator insert ( const std::vector& - , FDataPtr = nullptr ); - template - iterator insert ( const std::vector& - , iterator ); - template - iterator insert ( const std::vector& - , FDataPtr - , iterator ); - void remove (FListViewItem*); - void clear(); - iterator beginOfList(); - iterator endOfList(); - virtual void sort(); + iterator insert ( const std::vector& + , iterator ); + template + iterator insert ( const std::vector& + , DT&& + , iterator ); + void remove (FListViewItem*); + void clear(); + FListViewItems& getData(); + const FListViewItems& getData() const; + + virtual void sort(); // Event handlers - void onKeyPress (FKeyEvent*) override; - void onMouseDown (FMouseEvent*) override; - void onMouseUp (FMouseEvent*) override; - void onMouseMove (FMouseEvent*) override; - void onMouseDoubleClick (FMouseEvent*) override; - void onWheel (FWheelEvent*) override; - void onTimer (FTimerEvent*) override; - void onFocusIn (FFocusEvent*) override; - void onFocusOut (FFocusEvent*) override; + void onKeyPress (FKeyEvent*) override; + void onMouseDown (FMouseEvent*) override; + void onMouseUp (FMouseEvent*) override; + void onMouseMove (FMouseEvent*) override; + void onMouseDoubleClick (FMouseEvent*) override; + void onWheel (FWheelEvent*) override; + void onTimer (FTimerEvent*) override; + void onFocusIn (FFocusEvent*) override; + void onFocusOut (FFocusEvent*) override; protected: // Methods - void adjustViewport (const int); - void adjustScrollbars (const std::size_t) const; - void adjustSize() override; + void adjustViewport (const int); + void adjustScrollbars (const std::size_t) const; + void adjustSize() override; private: // Typedefs - typedef std::unordered_map> keyMap; - typedef std::unordered_map> keyMapResult; + typedef std::unordered_map> KeyMap; + typedef std::unordered_map> KeyMapResult; // Constants static constexpr std::size_t checkbox_space = 4; // Typedef struct Header; // forward declaration - typedef std::vector
headerItems; - typedef std::vector sortTypes; + typedef std::vector
HeaderItems; + typedef std::vector SortTypes; // Constants static constexpr int USE_MAX_SIZE = -1; // Accessors - static iterator& getNullIterator(); + static iterator& getNullIterator(); // Mutators - static void setNullIterator (const iterator&); + static void setNullIterator (const iterator&); // Inquiry - bool isHorizontallyScrollable() const; - bool isVerticallyScrollable() const; + bool isHorizontallyScrollable() const; + bool isVerticallyScrollable() const; // Methods - void init(); - void mapKeyFunctions(); - void processKeyAction (FKeyEvent*); + void init(); + void mapKeyFunctions(); + void processKeyAction (FKeyEvent*); template - void sort (Compare); - std::size_t getAlignOffset ( const fc::text_alignment - , const std::size_t - , const std::size_t ) const; - iterator getListEnd (const FListViewItem*); - void draw() override; - void drawBorder() override; - void drawScrollbars() const; - void drawHeadlines(); - void drawList(); - void drawListLine (const FListViewItem*, bool, bool); - void clearList(); - void setLineAttributes (bool, bool) const; - FString getCheckBox (const FListViewItem* item) const; - FString getLinePrefix (const FListViewItem*, std::size_t) const; - void drawSortIndicator (std::size_t&, std::size_t); - void drawHeadlineLabel (const headerItems::const_iterator&); - void drawHeaderBorder (std::size_t); - void drawBufferedHeadline(); - void drawColumnEllipsis ( const headerItems::const_iterator& - , const FString& ); - void updateDrawing (bool, bool); - std::size_t determineLineWidth (FListViewItem*); - void beforeInsertion (FListViewItem*); - void afterInsertion(); - void recalculateHorizontalBar (std::size_t); - void recalculateVerticalBar (std::size_t) const; - void mouseHeaderClicked(); - void wheelUp (int); - void wheelDown (int); - bool dragScrollUp (int); - bool dragScrollDown (int); - void dragUp (int); - void dragDown (int); - void stopDragScroll(); - iterator appendItem (FListViewItem*); - void processClick() const; - void processChanged() const; - void changeOnResize() const; - void toggleCheckbox(); - void collapseAndScrollLeft(); - void expandAndScrollRight(); - void firstPos(); - void lastPos(); - bool expandSubtree(); - bool collapseSubtree(); - void setRelativePosition (int); - void stepForward(); - void stepBackward(); - void stepForward (int); - void stepBackward (int); - void scrollToX (int); - void scrollToY (int); - void scrollTo (const FPoint &); - void scrollTo (int, int); - void scrollBy (int, int); - bool hasCheckableItems() const; + void sort (Compare); + std::size_t getAlignOffset ( const fc::text_alignment + , const std::size_t + , const std::size_t ) const; + iterator getListEnd (const FListViewItem*); + void draw() override; + void drawBorder() override; + void drawScrollbars() const; + void drawHeadlines(); + void drawList(); + void drawListLine (const FListViewItem*, bool, bool); + void clearList(); + void setLineAttributes (bool, bool) const; + FString getCheckBox (const FListViewItem* item) const; + FString getLinePrefix (const FListViewItem*, std::size_t) const; + void drawSortIndicator (std::size_t&, std::size_t); + void drawHeadlineLabel (const HeaderItems::const_iterator&); + void drawHeaderBorder (std::size_t); + void drawBufferedHeadline(); + void drawColumnEllipsis ( const HeaderItems::const_iterator& + , const FString& ); + void updateDrawing (bool, bool); + std::size_t determineLineWidth (FListViewItem*); + void beforeInsertion (FListViewItem*); + void afterInsertion(); + void recalculateHorizontalBar (std::size_t); + void recalculateVerticalBar (std::size_t) const; + void mouseHeaderClicked(); + void wheelUp (int); + void wheelDown (int); + bool dragScrollUp (int); + bool dragScrollDown (int); + void dragUp (int); + void dragDown (int); + void stopDragScroll(); + iterator appendItem (FListViewItem*); + void processClick() const; + void processChanged() const; + void changeOnResize() const; + void toggleCheckbox(); + void collapseAndScrollLeft(); + void expandAndScrollRight(); + void firstPos(); + void lastPos(); + bool expandSubtree(); + bool collapseSubtree(); + void setRelativePosition (int); + void stepForward(); + void stepBackward(); + void stepForward (int); + void stepBackward (int); + void scrollToX (int); + void scrollToY (int); + void scrollTo (const FPoint &); + void scrollTo (int, int); + void scrollBy (int, int); + bool hasCheckableItems() const; // Callback methods - void cb_vbarChange (const FWidget*); - void cb_hbarChange (const FWidget*); + void cb_vbarChange (const FWidget*); + void cb_hbarChange (const FWidget*); // Data members - iterator root{}; - FObjectList selflist{}; - FObjectList itemlist{}; - FListViewIterator current_iter{}; - FListViewIterator first_visible_line{}; - FListViewIterator last_visible_line{}; - headerItems header{}; - FTermBuffer headerline{}; - FScrollbarPtr vbar{nullptr}; - FScrollbarPtr hbar{nullptr}; - sortTypes sort_type{}; - FPoint clicked_expander_pos{-1, -1}; - FPoint clicked_header_pos{-1, -1}; - keyMap key_map{}; - keyMapResult key_map_result{}; - const FListViewItem* clicked_checkbox_item{nullptr}; - std::size_t nf_offset{0}; - std::size_t max_line_width{1}; - fc::dragScroll drag_scroll{fc::noScroll}; - int first_line_position_before{-1}; - int scroll_repeat{100}; - int scroll_distance{1}; - int xoffset{0}; - int sort_column{-1}; - fc::sorting_order sort_order{fc::unsorted}; - bool scroll_timer{false}; - bool tree_view{false}; - bool hide_sort_indicator{false}; - bool has_checkable_items{false}; + iterator root{}; + FObjectList selflist{}; + FObjectList itemlist{}; + FListViewIterator current_iter{}; + FListViewIterator first_visible_line{}; + FListViewIterator last_visible_line{}; + HeaderItems header{}; + FTermBuffer headerline{}; + FScrollbarPtr vbar{nullptr}; + FScrollbarPtr hbar{nullptr}; + SortTypes sort_type{}; + FPoint clicked_expander_pos{-1, -1}; + FPoint clicked_header_pos{-1, -1}; + KeyMap key_map{}; + KeyMapResult key_map_result{}; + const FListViewItem* clicked_checkbox_item{nullptr}; + std::size_t nf_offset{0}; + std::size_t max_line_width{1}; + fc::dragScroll drag_scroll{fc::noScroll}; + int first_line_position_before{-1}; + int scroll_repeat{100}; + int scroll_distance{1}; + int xoffset{0}; + int sort_column{-1}; + fc::sorting_order sort_order{fc::unsorted}; + bool scroll_timer{false}; + bool tree_view{false}; + bool hide_sort_indicator{false}; + bool has_checkable_items{false}; // Function Pointer bool (*user_defined_ascending) (const FObject*, const FObject*){nullptr}; @@ -514,7 +554,7 @@ struct FListView::Header // FListView inline functions //---------------------------------------------------------------------- -inline const FString FListView::getClassName() const +inline FString FListView::getClassName() const { return "FListView"; } //---------------------------------------------------------------------- @@ -560,9 +600,10 @@ inline FObject::iterator FListView::insert (FListViewItem* item) { return insert (item, root); } //---------------------------------------------------------------------- +template inline FObject::iterator - FListView::insert (const FStringList& cols, FDataPtr d) -{ return insert (cols, d, root); } + FListView::insert (const FStringList& cols, DT&& d) +{ return insert (cols, std::forward
(d), root); } //---------------------------------------------------------------------- inline FObject::iterator @@ -571,23 +612,53 @@ inline FObject::iterator { return insert (cols, nullptr, parent_iter); } //---------------------------------------------------------------------- -template -inline FObject::iterator - FListView::insert (const std::initializer_list& list, FDataPtr d) -{ return insert (list, d, root); } +template +inline FObject::iterator FListView::insert ( const FStringList& cols + , DT&& d + , iterator parent_iter ) +{ + FListViewItem* item; + + if ( cols.empty() || parent_iter == getNullIterator() ) + return getNullIterator(); + + if ( ! *parent_iter ) + parent_iter = root; + + try + { + item = new FListViewItem (cols, std::forward
(d), getNullIterator()); + } + catch (const std::bad_alloc&) + { + badAllocOutput ("FListViewItem"); + return getNullIterator(); + } + + item->replaceControlCodes(); + return insert(item, parent_iter); +} //---------------------------------------------------------------------- -template +template +inline FObject::iterator + FListView::insert (const std::initializer_list& list, DT&& d) +{ return insert (list, std::forward
(d), root); } + +//---------------------------------------------------------------------- +template inline FObject::iterator FListView::insert ( const std::initializer_list& list , iterator parent_iter ) { return insert (list, 0, parent_iter); } //---------------------------------------------------------------------- -template +template FObject::iterator FListView::insert ( const std::initializer_list& list - , FDataPtr d + , DT&& d , iterator parent_iter ) { FStringList str_cols; @@ -602,15 +673,16 @@ FObject::iterator } ); - auto item_iter = insert (str_cols, d, parent_iter); + auto item_iter = insert (str_cols, std::forward
(d), parent_iter); return item_iter; } //---------------------------------------------------------------------- -template +template inline FObject::iterator - FListView::insert (const std::vector& cols, FDataPtr d) -{ return insert (cols, d, root); } + FListView::insert (const std::vector& cols, DT&& d) +{ return insert (cols, std::forward
(d), root); } //---------------------------------------------------------------------- template @@ -620,10 +692,11 @@ inline FObject::iterator { return insert (cols, 0, parent_iter); } //---------------------------------------------------------------------- -template +template FObject::iterator FListView::insert ( const std::vector& cols - , FDataPtr d + , DT&& d , iterator parent_iter ) { FStringList str_cols; @@ -638,17 +711,17 @@ FObject::iterator } ); - auto item_iter = insert (str_cols, d, parent_iter); + auto item_iter = insert (str_cols, std::forward
(d), parent_iter); return item_iter; } //---------------------------------------------------------------------- -inline FObject::iterator FListView::beginOfList() -{ return itemlist.begin(); } +inline FListView::FListViewItems& FListView::getData() +{ return reinterpret_cast(itemlist); } //---------------------------------------------------------------------- -inline FObject::iterator FListView::endOfList() -{ return itemlist.end(); } +inline const FListView::FListViewItems& FListView::getData() const +{ return reinterpret_cast(itemlist); } //---------------------------------------------------------------------- inline bool FListView::isHorizontallyScrollable() const diff --git a/src/include/final/flog.h b/src/include/final/flog.h index 20da08b3..ffc5b56f 100644 --- a/src/include/final/flog.h +++ b/src/include/final/flog.h @@ -42,6 +42,7 @@ #include #include +#include #include #include #include @@ -84,7 +85,7 @@ class FLog : public std::stringbuf FLog& operator << (IOManip); FLog& operator << (LogLevel); - virtual const FString getClassName() const; + virtual FString getClassName() const; virtual void info (const std::string&) = 0; virtual void warn (const std::string&) = 0; virtual void error (const std::string&) = 0; @@ -99,15 +100,20 @@ class FLog : public std::stringbuf int sync() override; const LogLevel& getLevel() const; LogLevel& setLevel(); - const LineEnding& getEnding() const; + const LineEnding& getEnding(); LineEnding& setEnding(); + std::mutex& getMutex(); private: // Data member LogLevel level{Info}; LineEnding end_of_line{CRLF}; + std::mutex mut; FLogPrint current_log{std::bind(&FLog::info, this, std::placeholders::_1)}; std::ostream stream{this}; + + // Friend Non-member operator functions + friend std::ostream& operator << (std::ostream&, LogLevel); }; // FLog inline functions @@ -115,6 +121,7 @@ class FLog : public std::stringbuf template inline FLog& FLog::operator << (const T& s) { + std::lock_guard lock_guard(mut); stream << s; return *this; } @@ -122,30 +129,43 @@ inline FLog& FLog::operator << (const T& s) //---------------------------------------------------------------------- inline FLog& FLog::operator << (IOManip pf) { + std::lock_guard lock_guard(mut); pf(stream); return *this; } //---------------------------------------------------------------------- -inline const FString FLog::getClassName() const +inline FString FLog::getClassName() const { return "FLog"; } //---------------------------------------------------------------------- inline const FLog::LogLevel& FLog::getLevel() const -{ return level; } +{ + return level; +} //---------------------------------------------------------------------- inline FLog::LogLevel& FLog::setLevel() -{ return level; } +{ + return level; +} //---------------------------------------------------------------------- -inline const FLog::LineEnding& FLog::getEnding() const -{ return end_of_line; } +inline const FLog::LineEnding& FLog::getEnding() +{ + std::lock_guard lock_guard(mut); + return end_of_line; +} //---------------------------------------------------------------------- inline FLog::LineEnding& FLog::setEnding() -{ return end_of_line; } +{ + return end_of_line; +} +//---------------------------------------------------------------------- +inline std::mutex& FLog::getMutex() +{ return mut; } } // namespace finalcut diff --git a/src/include/final/flogger.h b/src/include/final/flogger.h index 2811bc67..d5caff76 100644 --- a/src/include/final/flogger.h +++ b/src/include/final/flogger.h @@ -72,7 +72,7 @@ class FLogger : public FLog ~FLogger() override; // Methods - const FString getClassName() const override; + FString getClassName() const override; void info (const std::string&) override; void warn (const std::string&) override; void error (const std::string&) override; @@ -86,8 +86,8 @@ class FLogger : public FLog private: // Methods void newlineReplace (std::string&, const std::string&) const; - const std::string getTimeString() const; - const std::string getEOL() const; + std::string getTimeString() const; + std::string getEOL(); void printLogLine (const std::string&); // Data member @@ -97,12 +97,13 @@ class FLogger : public FLog // FLogger inline functions //---------------------------------------------------------------------- -inline const FString FLogger::getClassName() const +inline FString FLogger::getClassName() const { return "FLogger"; } //---------------------------------------------------------------------- inline void FLogger::info (const std::string& msg) { + std::lock_guard lock_guard(getMutex()); setLevel() = Info; printLogLine (msg); } @@ -110,6 +111,7 @@ inline void FLogger::info (const std::string& msg) //---------------------------------------------------------------------- inline void FLogger::warn (const std::string& msg) { + std::lock_guard lock_guard(getMutex()); setLevel() = Warn; printLogLine (msg); } @@ -117,6 +119,7 @@ inline void FLogger::warn (const std::string& msg) //---------------------------------------------------------------------- inline void FLogger::error (const std::string& msg) { + std::lock_guard lock_guard(getMutex()); setLevel() = Error; printLogLine (msg); } @@ -124,29 +127,45 @@ inline void FLogger::error (const std::string& msg) //---------------------------------------------------------------------- inline void FLogger::debug (const std::string& msg) { + std::lock_guard lock_guard(getMutex()); setLevel() = Debug; printLogLine (msg); } //---------------------------------------------------------------------- inline void FLogger::flush() -{ output.flush(); } +{ + std::lock_guard lock_guard(getMutex()); + output.flush(); +} //---------------------------------------------------------------------- inline void FLogger::setOutputStream (const std::ostream& os) -{ output.rdbuf(os.rdbuf()); } +{ + std::lock_guard lock_guard(getMutex()); + output.rdbuf(os.rdbuf()); +} //---------------------------------------------------------------------- inline void FLogger::setLineEnding (LineEnding eol) -{ setEnding() = eol; } +{ + std::lock_guard lock_guard(getMutex()); + setEnding() = eol; +} //---------------------------------------------------------------------- inline void FLogger::enableTimestamp() -{ timestamp = true; } +{ + std::lock_guard lock_guard(getMutex()); + timestamp = true; +} //---------------------------------------------------------------------- inline void FLogger::disableTimestamp() -{ timestamp = false; } +{ + std::lock_guard lock_guard(getMutex()); + timestamp = false; +} } // namespace finalcut diff --git a/src/include/final/fmenu.h b/src/include/final/fmenu.h index 30727eca..a20e0544 100644 --- a/src/include/final/fmenu.h +++ b/src/include/final/fmenu.h @@ -91,7 +91,7 @@ class FMenu : public FWindow, public FMenuList FMenu& operator = (const FMenu&) = delete; // Accessors - const FString getClassName() const override; + FString getClassName() const override; FString getText() const; FMenuItem* getItem(); @@ -133,7 +133,7 @@ class FMenu : public FWindow, public FMenuList private: // Constants - static constexpr std::size_t NOT_SET = static_cast(-1); + static constexpr auto NOT_SET = static_cast(-1); static constexpr bool SELECT_ITEM = true; // Typedef @@ -146,14 +146,14 @@ class FMenu : public FWindow, public FMenuList uChar mouse_over_supermenu : 1; uChar mouse_over_menubar : 1; uChar : 2; // padding bits - } mouseStates; + } MouseStates; typedef struct { FString text; std::size_t hotkeypos; bool no_underline; - } menuText; + } MenuText; // Accessors FWidget* getSuperMenu() const; @@ -187,11 +187,11 @@ class FMenu : public FWindow, public FMenuList void mouseDownSubmenu (const FMenuItem*); void mouseDownSelection (FMenuItem*, bool&); bool mouseUpOverList (const FPoint&); - void mouseMoveOverList (const FPoint&, mouseStates&); - void mouseMoveSelection (FMenuItem*, mouseStates&); - void mouseMoveDeselection (FMenuItem*, mouseStates&); + void mouseMoveOverList (const FPoint&, MouseStates&); + void mouseMoveSelection (FMenuItem*, MouseStates&); + void mouseMoveDeselection (FMenuItem*, MouseStates&); void mouseUpOverBorder(); - void mouseMoveOverBorder (mouseStates&) const; + void mouseMoveOverBorder (MouseStates&) const; void passEventToSubMenu (FMouseEvent* const&); void passEventToSuperMenu (FMouseEvent* const&); void passEventToMenuBar (FMouseEvent* const&) const; @@ -208,7 +208,7 @@ class FMenu : public FWindow, public FMenuList void drawSeparator (int); void drawMenuLine (FMenuItem*, int); void drawCheckMarkPrefix (const FMenuItem*); - void drawMenuText (menuText&); + void drawMenuText (MenuText&); void drawSubMenuIndicator (std::size_t&); void drawAcceleratorKey (std::size_t&, FKey); void drawTrailingSpaces (std::size_t); @@ -248,7 +248,7 @@ std::tuple closeOpenMenus (FMenu*, const FPoint&); // FMenu inline functions //---------------------------------------------------------------------- -inline const FString FMenu::getClassName() const +inline FString FMenu::getClassName() const { return "FMenu"; } //---------------------------------------------------------------------- diff --git a/src/include/final/fmenubar.h b/src/include/final/fmenubar.h index 40961246..ec51b27f 100644 --- a/src/include/final/fmenubar.h +++ b/src/include/final/fmenubar.h @@ -83,7 +83,7 @@ class FMenuBar : public FWindow, public FMenuList FMenuBar& operator = (const FMenuBar&) = delete; // Accessors - const FString getClassName() const override; + FString getClassName() const override; // Methods void resetColors() override; @@ -103,7 +103,7 @@ class FMenuBar : public FWindow, public FMenuList private: // Constants - static constexpr std::size_t NOT_SET = static_cast(-1); + static constexpr auto NOT_SET = static_cast(-1); // Typedef typedef struct @@ -157,7 +157,7 @@ class FMenuBar : public FWindow, public FMenuList // FMenuBar inline functions //---------------------------------------------------------------------- -inline const FString FMenuBar::getClassName() const +inline FString FMenuBar::getClassName() const { return "FMenuBar"; } //---------------------------------------------------------------------- diff --git a/src/include/final/fmenuitem.h b/src/include/final/fmenuitem.h index c535e1ca..c48b8962 100644 --- a/src/include/final/fmenuitem.h +++ b/src/include/final/fmenuitem.h @@ -88,7 +88,7 @@ class FMenuItem : public FWidget FMenuItem& operator = (const FMenuItem&) = delete; // Accessors - const FString getClassName() const override; + FString getClassName() const override; FKey getHotkey() const; FMenu* getMenu() const; std::size_t getTextLength() const; @@ -196,7 +196,7 @@ class FMenuItem : public FWidget // FMenuItem inline functions //---------------------------------------------------------------------- -inline const FString FMenuItem::getClassName() const +inline FString FMenuItem::getClassName() const { return "FMenuItem"; } //---------------------------------------------------------------------- diff --git a/src/include/final/fmenulist.h b/src/include/final/fmenulist.h index ec77e07a..6f34a8e1 100644 --- a/src/include/final/fmenulist.h +++ b/src/include/final/fmenulist.h @@ -71,7 +71,7 @@ class FMenuList FMenuList& operator = (const FMenuList&) = delete; // Accessors - virtual const FString getClassName() const; + virtual FString getClassName() const; std::size_t getCount() const; FMenuItem* getItem (int) const; FMenuItem* getSelectedItem() const; @@ -104,7 +104,7 @@ class FMenuList // FMenuList inline functions //---------------------------------------------------------------------- -inline const FString FMenuList::getClassName() const +inline FString FMenuList::getClassName() const { return "FMenuList"; } //---------------------------------------------------------------------- diff --git a/src/include/final/fmessagebox.h b/src/include/final/fmessagebox.h index 22a63bfa..4b79c0c5 100644 --- a/src/include/final/fmessagebox.h +++ b/src/include/final/fmessagebox.h @@ -92,7 +92,7 @@ class FMessageBox : public FDialog explicit FMessageBox (FWidget* = nullptr); FMessageBox (const FMessageBox&); // copy constructor FMessageBox ( const FString&, const FString& - , int, int, int + , ButtonType, ButtonType, ButtonType , FWidget* = nullptr ); // Destructor ~FMessageBox() override; @@ -101,10 +101,10 @@ class FMessageBox : public FDialog FMessageBox& operator = (const FMessageBox&); // Accessor - const FString getClassName() const override; - const FString getTitlebarText() const; - const FString getHeadline() const; - const FString getText() const override; + FString getClassName() const override; + FString getTitlebarText() const; + FString getHeadline() const; + FString getText() const override; // Mutator void setTitlebarText (const FString&); @@ -119,22 +119,22 @@ class FMessageBox : public FDialog static int info ( FWidget* , const FString& , const messageType& - , int = FMessageBox::Ok - , int = 0 - , int = 0 ); + , ButtonType = FMessageBox::Ok + , ButtonType = FMessageBox::Reject + , ButtonType = FMessageBox::Reject ); template static int error ( FWidget* , const messageType& - , int = FMessageBox::Ok - , int = 0 - , int = 0 ); + , ButtonType = FMessageBox::Ok + , ButtonType = FMessageBox::Reject + , ButtonType = FMessageBox::Reject ); protected: // Method void adjustSize() override; // Callback method - void cb_processClick (int); + void cb_processClick (ButtonType); private: // Constants @@ -157,7 +157,7 @@ class FMessageBox : public FDialog FButton* button[MAX_BUTTONS]{nullptr}; std::size_t max_line_width{0}; FColor emphasis_color{getColorTheme()->dialog_emphasis_fg}; - int button_digit[MAX_BUTTONS]{0}; + ButtonType button_digit[MAX_BUTTONS]{FMessageBox::Reject}; std::size_t num_buttons{0}; std::size_t text_num_lines{0}; bool center_text{false}; @@ -166,22 +166,22 @@ class FMessageBox : public FDialog // FMessageBox inline functions //---------------------------------------------------------------------- -inline const FString FMessageBox::getClassName() const +inline FString FMessageBox::getClassName() const { return "FMessageBox"; } //---------------------------------------------------------------------- -inline const FString FMessageBox::getTitlebarText() const +inline FString FMessageBox::getTitlebarText() const { const FString& title = FDialog::getText(); // initialize text return title; } //---------------------------------------------------------------------- -inline const FString FMessageBox::getHeadline() const +inline FString FMessageBox::getHeadline() const { return headline_text; } //---------------------------------------------------------------------- -inline const FString FMessageBox::getText() const +inline FString FMessageBox::getText() const { return text; } //---------------------------------------------------------------------- @@ -205,9 +205,9 @@ template int FMessageBox::info ( FWidget* parent , const FString& caption , const messageType& message - , int button0 - , int button1 - , int button2 ) + , ButtonType button0 + , ButtonType button1 + , ButtonType button2 ) { FMessageBox mbox ( caption , FString() << message @@ -221,9 +221,9 @@ int FMessageBox::info ( FWidget* parent template int FMessageBox::error ( FWidget* parent , const messageType& message - , int button0 - , int button1 - , int button2 ) + , ButtonType button0 + , ButtonType button1 + , ButtonType button2 ) { const FString caption{"Error message"}; diff --git a/src/include/final/fmouse.h b/src/include/final/fmouse.h index e182c9b7..a0a22e02 100644 --- a/src/include/final/fmouse.h +++ b/src/include/final/fmouse.h @@ -102,7 +102,7 @@ class FMouse { } // Accessors - virtual const FString getClassName() const; + virtual FString getClassName() const; const FPoint& getPos() const; void clearEvent(); @@ -130,7 +130,7 @@ class FMouse bool isInputDataPending() const; // Methods - template + template static FMouse* createMouseObject (); void clearButtonState(); virtual void setRawData (FKeyboard::keybuffer&) = 0; @@ -193,7 +193,7 @@ class FMouse }; //---------------------------------------------------------------------- -template +template inline FMouse* FMouse::createMouseObject() { return new ClassT; @@ -215,7 +215,7 @@ class FMouseGPM final : public FMouse ~FMouseGPM() override; // Accessors - const FString getClassName() const override; + FString getClassName() const override; // Mutators void setStdinNo(int); @@ -283,7 +283,7 @@ class FMouseX11 final : public FMouse ~FMouseX11() override = default; // Accessors - const FString getClassName() const override; + FString getClassName() const override; // Inquiry bool hasData() override; @@ -342,7 +342,7 @@ class FMouseSGR final : public FMouse ~FMouseSGR() override = default; // Accessors - const FString getClassName() const override; + FString getClassName() const override; // Inquiry bool hasData() override; @@ -401,7 +401,7 @@ class FMouseUrxvt final : public FMouse ~FMouseUrxvt() override = default; // Accessors - const FString getClassName() const override; + FString getClassName() const override; // Inquiry bool hasData() override; @@ -466,7 +466,7 @@ class FMouseControl FMouseControl& operator = (const FMouseControl&) = delete; // Accessors - virtual const FString getClassName() const; + virtual FString getClassName() const; const FPoint& getPos(); void clearEvent(); @@ -526,7 +526,7 @@ class FMouseControl // FMouseControl inline functions //---------------------------------------------------------------------- -inline const FString FMouseControl::getClassName() const +inline FString FMouseControl::getClassName() const { return "FMouseControl"; } //---------------------------------------------------------------------- diff --git a/src/include/final/fobject.h b/src/include/final/fobject.h index e4456bb8..836b8fbe 100644 --- a/src/include/final/fobject.h +++ b/src/include/final/fobject.h @@ -78,6 +78,9 @@ class FObject typedef FObjectList::iterator iterator; typedef FObjectList::const_iterator const_iterator; + // Constants + static constexpr auto UNLIMITED = static_cast(-1); + // Constructor explicit FObject (FObject* = nullptr); @@ -91,17 +94,21 @@ class FObject FObject& operator = (const FObject&) = delete; // Accessors - virtual const FString getClassName() const; + virtual FString getClassName() const; FObject* getParent() const; FObject* getChild (int) const; FObjectList& getChildren(); const FObjectList& getChildren() const; - int numOfChildren() const; + std::size_t getMaxChildren() const; + std::size_t numOfChildren() const; iterator begin(); iterator end(); const_iterator begin() const; const_iterator end() const; + // Mutator + void setMaxChildren (std::size_t); + // Inquiries bool hasParent() const; bool hasChildren() const; @@ -160,6 +167,7 @@ class FObject // Data members FObject* parent_obj{nullptr}; FObjectList children_list{}; // no children yet + std::size_t max_children{UNLIMITED}; bool has_parent{false}; bool widget_object{false}; static bool timer_modify_lock; @@ -168,7 +176,7 @@ class FObject //---------------------------------------------------------------------- -inline const FString FObject::getClassName() const +inline FString FObject::getClassName() const { return "FObject"; } //---------------------------------------------------------------------- @@ -184,8 +192,12 @@ inline const FObject::FObjectList& FObject::getChildren() const { return children_list; } //---------------------------------------------------------------------- -inline int FObject::numOfChildren() const -{ return int(children_list.size()); } +inline std::size_t FObject::getMaxChildren() const +{ return max_children; } + +//---------------------------------------------------------------------- +inline std::size_t FObject::numOfChildren() const +{ return children_list.size(); } //---------------------------------------------------------------------- inline FObject::iterator FObject::begin() @@ -203,6 +215,10 @@ inline FObject::const_iterator FObject::begin() const inline FObject::const_iterator FObject::end() const { return children_list.end(); } +//---------------------------------------------------------------------- +inline void FObject::setMaxChildren (std::size_t max) +{ max_children = max; } + //---------------------------------------------------------------------- inline bool FObject::hasParent() const { return has_parent; } diff --git a/src/include/final/foptiattr.h b/src/include/final/foptiattr.h index d0aa7abf..c38e1ede 100644 --- a/src/include/final/foptiattr.h +++ b/src/include/final/foptiattr.h @@ -92,7 +92,7 @@ class FOptiAttr final int max_color; int attr_without_color; bool ansi_default_color; - } termEnv; + } TermEnv; // Constructor FOptiAttr(); @@ -107,10 +107,10 @@ class FOptiAttr final FOptiAttr& operator = (const FOptiAttr&) = delete; // Accessors - const FString getClassName() const; + FString getClassName() const; // Mutators - void setTermEnvironment (const termEnv&); + void setTermEnvironment (const TermEnv&); void setMaxColor (const int&); void setNoColorVideo (int); void setDefaultColorSupport(); @@ -161,13 +161,13 @@ class FOptiAttr final private: // Typedefs and Enumerations - typedef char attributebuffer[SGRoptimizer::ATTR_BUF_SIZE]; + typedef SGRoptimizer::AttributeBuffer AttributeBuffer; typedef struct { const char* cap; bool caused_reset; - } capability; + } Capability; enum init_reset_tests { @@ -263,62 +263,61 @@ class FOptiAttr final bool append_sequence (const char[]); // Data members - capability F_enter_bold_mode{}; - capability F_exit_bold_mode{}; - capability F_enter_dim_mode{}; - capability F_exit_dim_mode{}; - capability F_enter_italics_mode{}; - capability F_exit_italics_mode{}; - capability F_enter_underline_mode{}; - capability F_exit_underline_mode{}; - capability F_enter_blink_mode{}; - capability F_exit_blink_mode{}; - capability F_enter_reverse_mode{}; - capability F_exit_reverse_mode{}; - capability F_enter_standout_mode{}; - capability F_exit_standout_mode{}; - capability F_enter_secure_mode{}; - capability F_exit_secure_mode{}; - capability F_enter_protected_mode{}; - capability F_exit_protected_mode{}; - capability F_enter_crossed_out_mode{}; - capability F_exit_crossed_out_mode{}; - capability F_enter_dbl_underline_mode{}; - capability F_exit_dbl_underline_mode{}; - capability F_set_attributes{}; - capability F_exit_attribute_mode{}; - capability F_enter_alt_charset_mode{}; - capability F_exit_alt_charset_mode{}; - capability F_enter_pc_charset_mode{}; - capability F_exit_pc_charset_mode{}; - capability F_set_a_foreground{}; - capability F_set_a_background{}; - capability F_set_foreground{}; - capability F_set_background{}; - capability F_set_color_pair{}; - capability F_orig_pair{}; - capability F_orig_colors{}; + Capability F_enter_bold_mode{}; + Capability F_exit_bold_mode{}; + Capability F_enter_dim_mode{}; + Capability F_exit_dim_mode{}; + Capability F_enter_italics_mode{}; + Capability F_exit_italics_mode{}; + Capability F_enter_underline_mode{}; + Capability F_exit_underline_mode{}; + Capability F_enter_blink_mode{}; + Capability F_exit_blink_mode{}; + Capability F_enter_reverse_mode{}; + Capability F_exit_reverse_mode{}; + Capability F_enter_standout_mode{}; + Capability F_exit_standout_mode{}; + Capability F_enter_secure_mode{}; + Capability F_exit_secure_mode{}; + Capability F_enter_protected_mode{}; + Capability F_exit_protected_mode{}; + Capability F_enter_crossed_out_mode{}; + Capability F_exit_crossed_out_mode{}; + Capability F_enter_dbl_underline_mode{}; + Capability F_exit_dbl_underline_mode{}; + Capability F_set_attributes{}; + Capability F_exit_attribute_mode{}; + Capability F_enter_alt_charset_mode{}; + Capability F_exit_alt_charset_mode{}; + Capability F_enter_pc_charset_mode{}; + Capability F_exit_pc_charset_mode{}; + Capability F_set_a_foreground{}; + Capability F_set_a_background{}; + Capability F_set_foreground{}; + Capability F_set_background{}; + Capability F_set_color_pair{}; + Capability F_orig_pair{}; + Capability F_orig_colors{}; - FChar on{}; - FChar off{}; - FChar reset_byte_mask{}; + FChar on{}; + FChar off{}; + FChar reset_byte_mask{}; - SGRoptimizer sgr_optimizer{attr_buf}; + SGRoptimizer sgr_optimizer{attr_buf}; + AttributeBuffer attr_buf{}; - int max_color{1}; - int attr_without_color{0}; - char* attr_ptr{attr_buf}; - char attr_buf[SGRoptimizer::ATTR_BUF_SIZE]{'\0'}; - bool ansi_default_color{false}; - bool alt_equal_pc_charset{false}; - bool monochron{true}; - bool fake_reverse{false}; + int max_color{1}; + int attr_without_color{0}; + bool ansi_default_color{false}; + bool alt_equal_pc_charset{false}; + bool monochron{true}; + bool fake_reverse{false}; }; // FOptiAttr inline functions //---------------------------------------------------------------------- -inline const FString FOptiAttr::getClassName() const +inline FString FOptiAttr::getClassName() const { return "FOptiAttr"; } //---------------------------------------------------------------------- @@ -337,26 +336,6 @@ inline void FOptiAttr::setDefaultColorSupport() inline void FOptiAttr::unsetDefaultColorSupport() { ansi_default_color = false; } - -// FChar operator functions -//---------------------------------------------------------------------- -inline bool operator == ( const FChar& lhs, - const FChar& rhs ) -{ - return lhs.ch == rhs.ch - && lhs.fg_color == rhs.fg_color - && lhs.bg_color == rhs.bg_color - && lhs.attr.byte[0] == rhs.attr.byte[0] - && lhs.attr.byte[1] == rhs.attr.byte[1] - && lhs.attr.bit.fullwidth_padding \ - == rhs.attr.bit.fullwidth_padding; -} - -//---------------------------------------------------------------------- -inline bool operator != ( const FChar& lhs, - const FChar& rhs ) -{ return ! ( lhs == rhs ); } - } // namespace finalcut #endif // FOPTIATTR_H diff --git a/src/include/final/foptimove.h b/src/include/final/foptimove.h index dc02ca5a..1fcea1fb 100644 --- a/src/include/final/foptimove.h +++ b/src/include/final/foptimove.h @@ -83,7 +83,7 @@ class FOptiMove final int tabstop; bool automatic_left_margin; bool eat_nl_glitch; - } termEnv; + } TermEnv; // Constructor explicit FOptiMove (int = 0); @@ -92,7 +92,7 @@ class FOptiMove final ~FOptiMove(); // Accessors - const FString getClassName() const; + FString getClassName() const; uInt getCursorHomeLength() const; uInt getCarriageReturnLength() const; uInt getCursorToLLLength() const; @@ -118,7 +118,7 @@ class FOptiMove final void setBaudRate (int); void setTabStop (int); void setTermSize (std::size_t, std::size_t); - void setTermEnvironment (const termEnv&); + void setTermEnvironment (const TermEnv&); void set_cursor_home (const char[]); void set_cursor_to_ll (const char[]); void set_carriage_return (const char[]); @@ -156,7 +156,7 @@ class FOptiMove final const char* cap; int duration; int length; - } capability; + } Capability; // Constants static constexpr int LONG_DURATION{INT_MAX}; @@ -168,7 +168,7 @@ class FOptiMove final void calculateCharDuration(); int capDuration (const char[], int) const; int capDurationToLength (int) const; - int repeatedAppend (const capability&, volatile int, char*) const; + int repeatedAppend (const Capability&, volatile int, char*) const; int relativeMove (char[], int, int, int, int) const; int verticalMove (char[], int, int) const; void downMove (char[], int&, int, int) const; @@ -187,26 +187,26 @@ class FOptiMove final void moveByMethod (int, int, int, int, int); // Data members - capability F_cursor_home{}; - capability F_carriage_return{}; - capability F_cursor_to_ll{}; - capability F_tab{}; - capability F_back_tab{}; - capability F_cursor_up{}; - capability F_cursor_down{}; - capability F_cursor_left{}; - capability F_cursor_right{}; - capability F_cursor_address{}; - capability F_column_address{}; - capability F_row_address{}; - capability F_parm_up_cursor{}; - capability F_parm_down_cursor{}; - capability F_parm_left_cursor{}; - capability F_parm_right_cursor{}; - capability F_erase_chars{}; - capability F_repeat_char{}; - capability F_clr_bol{}; - capability F_clr_eol{}; + Capability F_cursor_home{}; + Capability F_carriage_return{}; + Capability F_cursor_to_ll{}; + Capability F_tab{}; + Capability F_back_tab{}; + Capability F_cursor_up{}; + Capability F_cursor_down{}; + Capability F_cursor_left{}; + Capability F_cursor_right{}; + Capability F_cursor_address{}; + Capability F_column_address{}; + Capability F_row_address{}; + Capability F_parm_up_cursor{}; + Capability F_parm_down_cursor{}; + Capability F_parm_left_cursor{}; + Capability F_parm_right_cursor{}; + Capability F_erase_chars{}; + Capability F_repeat_char{}; + Capability F_clr_bol{}; + Capability F_clr_eol{}; std::size_t screen_width{80}; std::size_t screen_height{24}; @@ -224,7 +224,7 @@ class FOptiMove final // FOptiMove inline functions //---------------------------------------------------------------------- -inline const FString FOptiMove::getClassName() const +inline FString FOptiMove::getClassName() const { return "FOptiMove"; } //---------------------------------------------------------------------- diff --git a/src/include/final/fpoint.h b/src/include/final/fpoint.h index 981d43cd..17ba5628 100644 --- a/src/include/final/fpoint.h +++ b/src/include/final/fpoint.h @@ -66,7 +66,7 @@ class FPoint FPoint& operator -= (const FPoint&); // Accessors - virtual const FString getClassName(); + virtual FString getClassName(); int getX() const; int getY() const; void setX (int); @@ -93,9 +93,9 @@ class FPoint // Friend operator functions friend bool operator == (const FPoint&, const FPoint&); friend bool operator != (const FPoint&, const FPoint&); - friend const FPoint operator + (const FPoint&, const FPoint&); - friend const FPoint operator - (const FPoint&, const FPoint&); - friend const FPoint operator - (const FPoint&); + friend FPoint operator + (const FPoint&, const FPoint&); + friend FPoint operator - (const FPoint&, const FPoint&); + friend FPoint operator - (const FPoint&); friend std::ostream& operator << (std::ostream&, const FPoint&); friend std::istream& operator >> (std::istream&, FPoint&); }; @@ -121,7 +121,7 @@ inline FPoint::FPoint (int x, int y) { } //---------------------------------------------------------------------- -inline const FString FPoint::getClassName() +inline FString FPoint::getClassName() { return "FPoint"; } //---------------------------------------------------------------------- @@ -155,15 +155,15 @@ inline bool operator != (const FPoint& p1, const FPoint& p2) { return p1.xpos != p2.xpos || p1.ypos != p2.ypos; } //---------------------------------------------------------------------- -inline const FPoint operator + (const FPoint& p1, const FPoint& p2) +inline FPoint operator + (const FPoint& p1, const FPoint& p2) { return {p1.xpos + p2.xpos, p1.ypos + p2.ypos}; } //---------------------------------------------------------------------- -inline const FPoint operator - (const FPoint& p1, const FPoint& p2) +inline FPoint operator - (const FPoint& p1, const FPoint& p2) { return {p1.xpos - p2.xpos, p1.ypos - p2.ypos}; } //---------------------------------------------------------------------- -inline const FPoint operator - (const FPoint& p) +inline FPoint operator - (const FPoint& p) { return {-p.xpos, -p.ypos}; } } // namespace finalcut diff --git a/src/include/final/fprogressbar.h b/src/include/final/fprogressbar.h index 8f6bd4e8..05d2005b 100644 --- a/src/include/final/fprogressbar.h +++ b/src/include/final/fprogressbar.h @@ -69,7 +69,7 @@ class FProgressbar : public FWidget ~FProgressbar() override; // Accessors - const FString getClassName() const override; + FString getClassName() const override; std::size_t getPercentage() const; // Mutators @@ -90,7 +90,7 @@ class FProgressbar : public FWidget private: // Constants - static constexpr std::size_t NOT_SET = static_cast(-1); + static constexpr auto NOT_SET = static_cast(-1); // Methods void init(); @@ -108,7 +108,7 @@ class FProgressbar : public FWidget // FProgressbar inline functions //---------------------------------------------------------------------- -inline const FString FProgressbar::getClassName() const +inline FString FProgressbar::getClassName() const { return "FProgressbar"; } //---------------------------------------------------------------------- diff --git a/src/include/final/fradiobutton.h b/src/include/final/fradiobutton.h index d00410b8..5187017f 100644 --- a/src/include/final/fradiobutton.h +++ b/src/include/final/fradiobutton.h @@ -78,7 +78,7 @@ class FRadioButton : public FToggleButton FRadioButton& operator = (const FRadioButton&) = delete; // Accessor - const FString getClassName() const override; + FString getClassName() const override; private: // Methods @@ -92,7 +92,7 @@ class FRadioButton : public FToggleButton // FRadioButton inline functions //---------------------------------------------------------------------- -inline const FString FRadioButton::getClassName() const +inline FString FRadioButton::getClassName() const { return "FRadioButton"; } } // namespace finalcut diff --git a/src/include/final/fradiomenuitem.h b/src/include/final/fradiomenuitem.h index f96672aa..4ba3b0c3 100644 --- a/src/include/final/fradiomenuitem.h +++ b/src/include/final/fradiomenuitem.h @@ -78,7 +78,7 @@ class FRadioMenuItem : public FMenuItem FRadioMenuItem& operator = (const FRadioMenuItem&) = delete; // Accessor - const FString getClassName() const override; + FString getClassName() const override; private: // Methods @@ -89,7 +89,7 @@ class FRadioMenuItem : public FMenuItem // FRadioMenuItem inline functions //---------------------------------------------------------------------- -inline const FString FRadioMenuItem::getClassName() const +inline FString FRadioMenuItem::getClassName() const { return "FRadioMenuItem"; } } // namespace finalcut diff --git a/src/include/final/frect.h b/src/include/final/frect.h index 2f0463de..15c4a25e 100644 --- a/src/include/final/frect.h +++ b/src/include/final/frect.h @@ -74,21 +74,21 @@ class FRect FRect& operator = (FRect&&) noexcept; // Accessors - virtual const FString getClassName(); + virtual FString getClassName(); int getX1() const; int getY1() const; int getX2() const; int getY2() const; int getX() const; int getY() const; - const FPoint getPos() const; - const FPoint getUpperLeftPos() const; - const FPoint getUpperRightPos() const; - const FPoint getLowerLeftPos() const; - const FPoint getLowerRightPos() const; + FPoint getPos() const; + FPoint getUpperLeftPos() const; + FPoint getUpperRightPos() const; + FPoint getLowerLeftPos() const; + FPoint getLowerRightPos() const; std::size_t getWidth() const; std::size_t getHeight() const; - const FSize getSize() const; + FSize getSize() const; // Mutators void setX1 (int); @@ -138,8 +138,8 @@ class FRect int Y2{-1}; // Friend operator functions - friend const FRect operator + (const FRect&, const FSize&); - friend const FRect operator - (const FRect&, const FSize&); + friend FRect operator + (const FRect&, const FSize&); + friend FRect operator - (const FRect&, const FSize&); friend bool operator == (const FRect&, const FRect&); friend bool operator != (const FRect&, const FRect&); friend std::ostream& operator << (std::ostream&, const FRect&); @@ -172,7 +172,7 @@ inline FRect::FRect (int x, int y, std::size_t width, std::size_t height) { } //---------------------------------------------------------------------- -inline const FString FRect::getClassName() +inline FString FRect::getClassName() { return "FRect"; } //---------------------------------------------------------------------- @@ -202,14 +202,14 @@ inline int FRect::getY() const //---------------------------------------------------------------------- inline std::size_t FRect::getWidth() const { - const int w = X2 - X1 + 1; + const int w = X2 - (X1 - 1); // overflow save return ( w < 0 ) ? 0 : std::size_t(w); } //---------------------------------------------------------------------- inline std::size_t FRect::getHeight() const { - const int h = Y2 - Y1 + 1; + const int h = Y2 - (Y1 - 1); // overflow save return ( h < 0 ) ? 0 : std::size_t(h); } diff --git a/src/include/final/fscrollbar.h b/src/include/final/fscrollbar.h index 5433ff4d..f4b7fe95 100644 --- a/src/include/final/fscrollbar.h +++ b/src/include/final/fscrollbar.h @@ -100,7 +100,7 @@ class FScrollbar : public FWidget FScrollbar& operator = (const FScrollbar&) = delete; // Accessors - const FString getClassName() const override; + FString getClassName() const override; int getValue() const; sType getScrollType() const; @@ -170,9 +170,10 @@ class FScrollbar : public FWidget }; -// non-member function forward declarations +// non-member function //---------------------------------------------------------------------- -template +template void initScrollbar ( FScrollbarPtr& bar , fc::orientation o , Instance cb_instance @@ -202,7 +203,7 @@ void initScrollbar ( FScrollbarPtr& bar // FScrollbar inline functions //---------------------------------------------------------------------- -inline const FString FScrollbar::getClassName() const +inline FString FScrollbar::getClassName() const { return "FScrollbar"; } //---------------------------------------------------------------------- diff --git a/src/include/final/fscrollview.h b/src/include/final/fscrollview.h index ad90716f..c0f6eccb 100644 --- a/src/include/final/fscrollview.h +++ b/src/include/final/fscrollview.h @@ -80,14 +80,14 @@ class FScrollView : public FWidget FScrollView& operator = (const FScrollView&) = delete; // Accessors - const FString getClassName() const override; + FString getClassName() const override; std::size_t getViewportWidth() const; std::size_t getViewportHeight() const; - const FSize getViewportSize() const; + FSize getViewportSize() const; std::size_t getScrollWidth() const; std::size_t getScrollHeight() const; - const FSize getScrollSize() const; - const FPoint getScrollPos() const; + FSize getScrollSize() const; + FPoint getScrollPos() const; int getScrollX() const; int getScrollY() const; @@ -150,20 +150,20 @@ class FScrollView : public FWidget private: // Typedefs - typedef std::unordered_map> keyMap; + typedef std::unordered_map> KeyMap; // Constants static constexpr int vertical_border_spacing = 2; static constexpr int horizontal_border_spacing = 2; // Accessors - const FPoint getViewportCursorPos() const; + FPoint getViewportCursorPos() const; // Methods void init(); void mapKeyFunctions(); void calculateScrollbarPos() const; - template + template void initScrollbar ( FScrollbarPtr& , fc::orientation , Callback ); @@ -181,7 +181,7 @@ class FScrollView : public FWidget FTermArea* viewport{nullptr}; // virtual scroll content FScrollbarPtr vbar{nullptr}; FScrollbarPtr hbar{nullptr}; - keyMap key_map{}; + KeyMap key_map{}; uInt8 nf_offset{0}; bool use_own_print_area{false}; bool update_scrollbar{true}; @@ -191,7 +191,7 @@ class FScrollView : public FWidget // FScrollView inline functions //---------------------------------------------------------------------- -inline const FString FScrollView::getClassName() const +inline FString FScrollView::getClassName() const { return "FScrollView"; } //---------------------------------------------------------------------- @@ -203,7 +203,7 @@ inline std::size_t FScrollView::getViewportHeight() const { return getHeight() - horizontal_border_spacing; } //---------------------------------------------------------------------- -inline const FSize FScrollView::getViewportSize() const +inline FSize FScrollView::getViewportSize() const { return FSize(getViewportWidth(), getViewportHeight()); } //---------------------------------------------------------------------- @@ -215,11 +215,11 @@ inline std::size_t FScrollView::getScrollHeight() const { return scroll_geometry.getHeight(); } //---------------------------------------------------------------------- -inline const FSize FScrollView::getScrollSize() const +inline FSize FScrollView::getScrollSize() const { return scroll_geometry.getSize(); } //---------------------------------------------------------------------- -inline const FPoint FScrollView::getScrollPos() const +inline FPoint FScrollView::getScrollPos() const { return viewport_geometry.getPos(); } //---------------------------------------------------------------------- @@ -268,7 +268,7 @@ inline void FScrollView::print (const FPoint& pos) } //---------------------------------------------------------------------- -template +template inline void FScrollView::initScrollbar ( FScrollbarPtr& bar , fc::orientation o , Callback cb_handler ) diff --git a/src/include/final/fsize.h b/src/include/final/fsize.h index 6186a06e..9de799ef 100644 --- a/src/include/final/fsize.h +++ b/src/include/final/fsize.h @@ -71,7 +71,7 @@ class FSize FSize& operator -= (const FSize&); // Accessors - virtual const FString getClassName(); + virtual FString getClassName(); std::size_t getWidth() const; std::size_t getHeight() const; std::size_t getArea() const; @@ -103,8 +103,8 @@ class FSize friend bool operator != (const FSize&, const FSize&); friend bool operator >= (const FSize&, const FSize&); friend bool operator > (const FSize&, const FSize&); - friend const FSize operator + (const FSize&, const FSize&); - friend const FSize operator - (const FSize&, const FSize&); + friend FSize operator + (const FSize&, const FSize&); + friend FSize operator - (const FSize&, const FSize&); friend std::ostream& operator << (std::ostream&, const FSize&); friend std::istream& operator >> (std::istream&, FSize&); @@ -130,7 +130,7 @@ inline FSize::FSize (std::size_t w, std::size_t h) { } //---------------------------------------------------------------------- -inline const FString FSize::getClassName() +inline FString FSize::getClassName() { return "FSize"; } //---------------------------------------------------------------------- @@ -180,7 +180,7 @@ inline bool operator > (const FSize& s1, const FSize& s2) { return s1.width > s2.width && s1.height > s2.height; } //---------------------------------------------------------------------- -inline const FSize operator + (const FSize& s1, const FSize& s2) +inline FSize operator + (const FSize& s1, const FSize& s2) { constexpr std::size_t max = std::numeric_limits::max(); const std::size_t w = ( s1.width < max - s2.width) ? s1.width + s2.width : max; @@ -189,7 +189,7 @@ inline const FSize operator + (const FSize& s1, const FSize& s2) } //---------------------------------------------------------------------- -inline const FSize operator - (const FSize& s1, const FSize& s2) +inline FSize operator - (const FSize& s1, const FSize& s2) { const std::size_t w = ( s1.width >= s2.width ) ? s1.width - s2.width : 0; const std::size_t h = ( s1.height >= s2.height ) ? s1.height - s2.height : 0; diff --git a/src/include/final/fspinbox.h b/src/include/final/fspinbox.h index ba419621..b13c306f 100644 --- a/src/include/final/fspinbox.h +++ b/src/include/final/fspinbox.h @@ -80,7 +80,7 @@ class FSpinBox : public FWidget FSpinBox& operator = (const FSpinBox&) = delete; // Accessors - const FString getClassName() const override; + FString getClassName() const override; sInt64 getValue() const; FString getPrefix() const; FString getSuffix() const; @@ -161,7 +161,7 @@ class FSpinBox : public FWidget // FSpinBox inline functions //---------------------------------------------------------------------- -inline const FString FSpinBox::getClassName() const +inline FString FSpinBox::getClassName() const { return "FSpinBox"; } //---------------------------------------------------------------------- diff --git a/src/include/final/fstartoptions.h b/src/include/final/fstartoptions.h index ab5cffae..a5430228 100644 --- a/src/include/final/fstartoptions.h +++ b/src/include/final/fstartoptions.h @@ -65,7 +65,7 @@ class FStartOptions final FStartOptions& operator = (const FStartOptions&) = delete; // Accessors - static const FString getClassName(); + static FString getClassName(); static FStartOptions& getFStartOptions(); // Mutator @@ -102,7 +102,7 @@ class FStartOptions final }; //---------------------------------------------------------------------- -inline const FString FStartOptions::getClassName() +inline FString FStartOptions::getClassName() { return "FStartOptions"; } } // namespace finalcut diff --git a/src/include/final/fstatusbar.h b/src/include/final/fstatusbar.h index 751543e4..7b7cc1c3 100644 --- a/src/include/final/fstatusbar.h +++ b/src/include/final/fstatusbar.h @@ -87,7 +87,7 @@ class FStatusKey : public FWidget FStatusKey& operator = (const FStatusKey&) = delete; // Accessors - const FString getClassName() const override; + FString getClassName() const override; virtual FKey getKey() const; virtual FString getText() const; @@ -128,7 +128,7 @@ class FStatusKey : public FWidget // FStatusKey inline functions //---------------------------------------------------------------------- -inline const FString FStatusKey::getClassName() const +inline FString FStatusKey::getClassName() const { return "FStatusKey"; } //---------------------------------------------------------------------- @@ -196,7 +196,7 @@ class FStatusBar : public FWindow FStatusBar& operator = (const FStatusBar&) = delete; // Accessors - const FString getClassName() const override; + FString getClassName() const override; FStatusKey* getStatusKey (int) const; FString getMessage() const; std::size_t getCount() const; @@ -231,7 +231,7 @@ class FStatusBar : public FWindow private: // Typedef - typedef std::vector keyList; + typedef std::vector FKeyList; // Methods void init(); @@ -239,11 +239,11 @@ class FStatusBar : public FWindow int getKeyTextWidth (const FStatusKey*) const; void draw() override; void drawKeys(); - void drawKey (keyList::const_iterator); - void drawActiveKey (keyList::const_iterator); + void drawKey (FKeyList::const_iterator); + void drawActiveKey (FKeyList::const_iterator); // Data members - keyList key_list{}; + FKeyList key_list{}; FString text{""}; std::size_t screenWidth{80}; int keyname_len{0}; @@ -255,7 +255,7 @@ class FStatusBar : public FWindow // FStatusBar inline functions //---------------------------------------------------------------------- -inline const FString FStatusBar::getClassName() const +inline FString FStatusBar::getClassName() const { return "FStatusBar"; } //---------------------------------------------------------------------- diff --git a/src/include/final/fstring.h b/src/include/final/fstring.h index 5a89b97b..8102d4cd 100644 --- a/src/include/final/fstring.h +++ b/src/include/final/fstring.h @@ -49,6 +49,7 @@ #include #include +#include #include #include #include @@ -159,7 +160,7 @@ class FString operator const char* () const { return c_str(); } // Accessor - virtual const FString getClassName() const; + virtual FString getClassName() const; // inquiries bool isNull() const; @@ -177,7 +178,7 @@ class FString wchar_t front() const; wchar_t back() const; - template + template FString& sprintf (const FString&, Args&&...); FString clear(); @@ -185,10 +186,10 @@ class FString wchar_t* wc_str(); const char* c_str() const; char* c_str(); - const std::string toString() const; + std::string toString() const; - const FString toLower() const; - const FString toUpper() const; + FString toLower() const; + FString toUpper() const; sInt16 toShort() const; uInt16 toUShort() const; @@ -199,13 +200,13 @@ class FString float toFloat() const; double toDouble() const; - const FString ltrim() const; - const FString rtrim() const; - const FString trim() const; + FString ltrim() const; + FString rtrim() const; + FString trim() const; - const FString left (std::size_t) const; - const FString right (std::size_t) const; - const FString mid (std::size_t, std::size_t) const; + FString left (std::size_t) const; + FString right (std::size_t) const; + FString mid (std::size_t, std::size_t) const; FStringList split (const FString&) const; FString& setString (const FString&); @@ -224,10 +225,10 @@ class FString const FString& insert (const FString&, int); const FString& insert (const FString&, std::size_t); - const FString replace (const FString&, const FString&) const; + FString replace (const FString&, const FString&) const; - const FString replaceControlCodes() const; - const FString expandTabs (int = 8) const; + FString replaceControlCodes() const; + FString expandTabs (int = 8) const; FString removeDel() const; FString removeBackspaces() const; @@ -261,15 +262,15 @@ class FString static const wchar_t const_null_char; // Friend Non-member operator functions - friend const FString operator + (const FString&, const FString&); - friend const FString operator + (const FString&, const wchar_t); - friend const FString operator + (const std::wstring&, const FString&); - friend const FString operator + (const wchar_t[], const FString&); - friend const FString operator + (const std::string&, const FString&); - friend const FString operator + (const char[], const FString&); - friend const FString operator + (const wchar_t, const FString&); - friend const FString operator + (const char, const FString&); - friend const FString operator + (const FString&, const char); + friend FString operator + (const FString&, const FString&); + friend FString operator + (const FString&, const wchar_t); + friend FString operator + (const std::wstring&, const FString&); + friend FString operator + (const wchar_t[], const FString&); + friend FString operator + (const std::string&, const FString&); + friend FString operator + (const char[], const FString&); + friend FString operator + (const wchar_t, const FString&); + friend FString operator + (const char, const FString&); + friend FString operator + (const FString&, const char); friend std::ostream& operator << (std::ostream&, const FString&); friend std::istream& operator >> (std::istream&, FString& s); @@ -366,7 +367,7 @@ inline bool FString::operator > (const CharT& s) const } //---------------------------------------------------------------------- -inline const FString FString::getClassName() const +inline FString FString::getClassName() const { return "FString"; } //---------------------------------------------------------------------- @@ -416,11 +417,10 @@ inline wchar_t FString::back() const } //---------------------------------------------------------------------- -template +template inline FString& FString::sprintf (const FString& format, Args&&... args) { - static constexpr int BUFSIZE = 4096; - wchar_t buf[BUFSIZE]{}; + std::array buf{}; if ( format.isEmpty() ) { @@ -428,9 +428,9 @@ inline FString& FString::sprintf (const FString& format, Args&&... args) return *this; } - std::swprintf ( buf, BUFSIZE, format.wc_str() + std::swprintf ( buf.data(), buf.size(), format.wc_str() , std::forward(args)... ); - _assign(buf); + _assign(buf.data()); return *this; } diff --git a/src/include/final/fstringstream.h b/src/include/final/fstringstream.h index 15ec22a6..ce10acfb 100644 --- a/src/include/final/fstringstream.h +++ b/src/include/final/fstringstream.h @@ -80,7 +80,7 @@ class FStringStream : public std::wiostream // Move assignment operator (=) FStringStream& operator = (FStringStream&& sstream) noexcept; - virtual const FString getClassName() const; + virtual FString getClassName() const; void swap (FStringStream&) noexcept; void clear(); std::wstringbuf* rdbuf() const; @@ -93,7 +93,7 @@ class FStringStream : public std::wiostream // FStringStream inline functions //---------------------------------------------------------------------- -inline const FString FStringStream::getClassName() const +inline FString FStringStream::getClassName() const { return "FStringStream"; } //---------------------------------------------------------------------- diff --git a/src/include/final/fstyle.h b/src/include/final/fstyle.h index bef360fe..dbb93162 100644 --- a/src/include/final/fstyle.h +++ b/src/include/final/fstyle.h @@ -70,7 +70,7 @@ class FStyle } // Accessor - const FString getClassName() const + FString getClassName() const { return "FStyle"; } FColor getStyle() const diff --git a/src/include/final/fswitch.h b/src/include/final/fswitch.h index cd94a57d..3978a4db 100644 --- a/src/include/final/fswitch.h +++ b/src/include/final/fswitch.h @@ -78,7 +78,7 @@ class FSwitch : public FToggleButton FSwitch& operator = (const FSwitch&) = delete; // Accessor - const FString getClassName() const override; + FString getClassName() const override; // Mutator void setText (const FString&) override; @@ -102,7 +102,7 @@ class FSwitch : public FToggleButton // FSwitch inline functions //---------------------------------------------------------------------- -inline const FString FSwitch::getClassName() const +inline FString FSwitch::getClassName() const { return "FSwitch"; } } // namespace finalcut diff --git a/src/include/final/fsystemimpl.h b/src/include/final/fsystemimpl.h index 25bbf3c4..17d56a4b 100644 --- a/src/include/final/fsystemimpl.h +++ b/src/include/final/fsystemimpl.h @@ -145,7 +145,7 @@ class FSystemImpl : public FSystem { va_list args{}; va_start (args, flags); - mode_t mode = static_cast(va_arg (args, int)); + auto mode = static_cast(va_arg (args, int)); int ret = ::open (pathname, flags, mode); va_end (args); return ret; diff --git a/src/include/final/fterm.h b/src/include/final/fterm.h index 3a04d361..55badcc9 100644 --- a/src/include/final/fterm.h +++ b/src/include/final/fterm.h @@ -132,6 +132,7 @@ class FKeyboard; class FMouseControl; class FOptiAttr; class FOptiMove; +class FPoint; class FStartOptions; class FSize; class FString; @@ -178,10 +179,10 @@ class FTerm final FTerm& operator = (const FTerm&) = delete; // Accessors - static const FString getClassName(); + static FString getClassName(); static std::size_t getLineNumber(); static std::size_t getColumnNumber(); - static const FString getKeyName (FKey); + static FString getKeyName (FKey); static int getTTYFileDescriptor(); static const char* getTermType(); static const char* getTermFileName(); @@ -266,7 +267,7 @@ class FTerm final // Methods static bool setVGAFont(); static bool setNewFont(); - static bool setOldFont(); + static bool resetFont(); static int openConsole(); static int closeConsole(); static const char* moveCursorString (int, int, int, int); @@ -278,7 +279,7 @@ class FTerm final static void saveColorMap(); static void resetColorMap(); static void setPalette (FColor, int, int, int); - template + template static void setColorPaletteTheme (const FSetPalette& = &FTerm::setPalette); static void setBeep (int, int); static void resetBeep(); @@ -295,7 +296,7 @@ class FTerm final static bool scrollTermReverse(); static defaultPutChar& putchar(); // function pointer - template + template static void putstringf (const char[], Args&&...); static void putstring (const char[], int = 1); static int putchar_ASCII (int); @@ -406,20 +407,20 @@ bool isReverseNewFontchar (wchar_t); bool hasFullWidthSupports(); wchar_t cp437_to_unicode (uChar); uChar unicode_to_cp437 (wchar_t); -const FString getFullWidth (const FString&); -const FString getHalfWidth (const FString&); -const FString getColumnSubString (const FString&, std::size_t, std::size_t); +FString getFullWidth (const FString&); +FString getHalfWidth (const FString&); +FString getColumnSubString (const FString&, std::size_t, std::size_t); std::size_t getLengthFromColumnWidth (const FString&, std::size_t); std::size_t getColumnWidth (const FString&, std::size_t); std::size_t getColumnWidth (const FString&); std::size_t getColumnWidth (const wchar_t); std::size_t getColumnWidth (FChar&); std::size_t getColumnWidth (const FTermBuffer&); - +FPoint readCursorPos(); // FTerm inline functions //---------------------------------------------------------------------- -inline const FString FTerm::getClassName() +inline FString FTerm::getClassName() { return "FTerm"; } //---------------------------------------------------------------------- @@ -443,7 +444,7 @@ inline bool FTerm::unsetUTF8() { return setUTF8(false); } //---------------------------------------------------------------------- -template +template inline void FTerm::setColorPaletteTheme (const FSetPalette& f) { getColorPaletteTheme() = std::make_shared(f); @@ -451,7 +452,7 @@ inline void FTerm::setColorPaletteTheme (const FSetPalette& f) } //---------------------------------------------------------------------- -template +template inline void FTerm::putstringf (const char format[], Args&&... args) { const int size = std::snprintf (nullptr, 0, format, args...) + 1; @@ -462,7 +463,7 @@ inline void FTerm::putstringf (const char format[], Args&&... args) if ( ! fsys ) getFSystem(); // Trying to set fsys - const std::size_t count = std::size_t(size); + const auto count = std::size_t(size); std::vector buf(count); std::snprintf (&buf[0], count, format, std::forward(args)...); diff --git a/src/include/final/ftermbuffer.h b/src/include/final/ftermbuffer.h index 5d53d733..ab2593ae 100644 --- a/src/include/final/ftermbuffer.h +++ b/src/include/final/ftermbuffer.h @@ -63,7 +63,7 @@ class FTermBuffer // Constructor FTermBuffer() = default; - template + template FTermBuffer (Iterator, Iterator); // Destructor @@ -79,7 +79,7 @@ class FTermBuffer FTermBuffer& operator << (const FColorPair&); // Accessors - virtual const FString getClassName() const; + virtual FString getClassName() const; std::size_t getLength() const; const FCharVector& getBuffer() const; @@ -93,9 +93,9 @@ class FTermBuffer const_iterator end() const; FChar front() const; FChar back() const; - const FString toString() const; + FString toString() const; void clear(); - template + template int writef (const FString&, Args&&...); int write (const FString&); int write (wchar_t); @@ -114,7 +114,7 @@ class FTermBuffer // FTermBuffer inline functions //---------------------------------------------------------------------- -template +template inline FTermBuffer::FTermBuffer(Iterator first, Iterator last) { data.assign(first, last); @@ -169,7 +169,7 @@ inline FTermBuffer& FTermBuffer::operator << (const FColorPair& pair) } //---------------------------------------------------------------------- -inline const FString FTermBuffer::getClassName() const +inline FString FTermBuffer::getClassName() const { return "FTermBuffer"; } //---------------------------------------------------------------------- @@ -216,7 +216,7 @@ inline void FTermBuffer::clear() } //---------------------------------------------------------------------- -template +template inline int FTermBuffer::writef (const FString& format, Args&&... args) { FString str{}; diff --git a/src/include/final/ftermcap.h b/src/include/final/ftermcap.h index e5b1e9b7..c356b1bd 100644 --- a/src/include/final/ftermcap.h +++ b/src/include/final/ftermcap.h @@ -55,6 +55,7 @@ #undef buttons // from term.h #endif +#include #include #include #include @@ -77,16 +78,17 @@ class FTermDetection; class FTermcap final { public: - // Using-declaration - using fn_putc = int (*)(int); - // Typedef typedef struct { const char* string; char tname[alignof(char*)]; } - tcap_map; + TCapMap; + + // Using-declaration + using fn_putc = int (*)(int); + using TCapMapType = std::array; // Constructors FTermcap() = default; @@ -95,18 +97,19 @@ class FTermcap final ~FTermcap() = default; // Accessors - const FString getClassName() const; - template + FString getClassName() const; + template static bool getFlag (const CharT&); - template + template static int getNumber (const CharT&); - template + template static char* getString (const CharT&); - template + template static char* encodeMotionParameter (const CharT&, int, int); - template + template static char* encodeParameter (const CharT&, Args&&...); - template + template static int paddingPrint (const CharT&, int, fn_putc); // Inquiry @@ -128,7 +131,7 @@ class FTermcap final static int max_color; static int tabstop; static int attr_without_color; - static tcap_map strings[]; + static TCapMapType strings; private: // Constant @@ -155,46 +158,47 @@ class FTermcap final // FTermcap inline functions //---------------------------------------------------------------------- -inline const FString FTermcap::getClassName() const +inline FString FTermcap::getClassName() const { return "FTermcap"; } //---------------------------------------------------------------------- -template +template bool FTermcap::getFlag (const CharT& cap) { return ::tgetflag(C_STR(cap)); } //---------------------------------------------------------------------- -template +template int FTermcap::getNumber (const CharT& cap) { return ::tgetnum(C_STR(cap)); } //---------------------------------------------------------------------- -template +template char* FTermcap::getString (const CharT& cap) { return ::tgetstr(C_STR(cap), reinterpret_cast(&string_buf)); } //---------------------------------------------------------------------- -template +template char* FTermcap::encodeMotionParameter (const CharT& cap, int col, int row) { return ::tgoto(C_STR(cap), col, row); } //---------------------------------------------------------------------- -template +template inline char* FTermcap::encodeParameter (const CharT& cap, Args&&... args) { return ::tparm (C_STR(cap), std::forward(args)...); } //---------------------------------------------------------------------- -template +template int FTermcap::paddingPrint (const CharT& str, int affcnt, fn_putc putc) { return _tputs (C_STR(str), affcnt, putc); diff --git a/src/include/final/ftermcapquirks.h b/src/include/final/ftermcapquirks.h index 60148df9..c73df24b 100644 --- a/src/include/final/ftermcapquirks.h +++ b/src/include/final/ftermcapquirks.h @@ -3,7 +3,7 @@ * * * This file is part of the FINAL CUT widget toolkit * * * -* Copyright 2018-2019 Markus Gans * +* Copyright 2018-2020 Markus Gans * * * * FINAL CUT is free software; you can redistribute it and/or modify * * it under the terms of the GNU Lesser General Public License as * @@ -56,7 +56,7 @@ class FTermcapQuirks final ~FTermcapQuirks(); // Accessor - const FString getClassName() const; + FString getClassName() const; // Methods static void terminalFixup(); @@ -85,7 +85,7 @@ class FTermcapQuirks final // FTermcapQuirks inline functions //---------------------------------------------------------------------- -inline const FString FTermcapQuirks::getClassName() const +inline FString FTermcapQuirks::getClassName() const { return "FTermcapQuirks"; } } // namespace finalcut diff --git a/src/include/final/ftermdata.h b/src/include/final/ftermdata.h index 1ba99f3e..5ba213c6 100644 --- a/src/include/final/ftermdata.h +++ b/src/include/final/ftermdata.h @@ -54,7 +54,7 @@ class FTermData final { public: // Typedefs - typedef std::unordered_map encodingMap; + typedef std::unordered_map EncodingMap; // Constructors FTermData() @@ -71,8 +71,8 @@ class FTermData final FTermData& operator = (const FTermData&) = delete; // Accessors - const FString getClassName() const; - encodingMap& getEncodingList(); + FString getClassName() const; + EncodingMap& getEncodingList(); charSubstitution& getCharSubstitutionMap(); fc::encoding getTermEncoding() const; FRect& getTermGeometry(); @@ -132,7 +132,7 @@ class FTermData final private: // Data members - encodingMap encoding_list{}; + EncodingMap encoding_list{}; charSubstitution char_substitution_map{}; FRect term_geometry{}; // current terminal geometry FString xterm_font{}; @@ -166,11 +166,11 @@ class FTermData final // FTermData inline functions //---------------------------------------------------------------------- -inline const FString FTermData::getClassName() const +inline FString FTermData::getClassName() const { return "FTermData"; } //---------------------------------------------------------------------- -inline FTermData::encodingMap& FTermData::getEncodingList() +inline FTermData::EncodingMap& FTermData::getEncodingList() { return encoding_list; } //---------------------------------------------------------------------- diff --git a/src/include/final/ftermdetection.h b/src/include/final/ftermdetection.h index e7d1fe64..89798b87 100644 --- a/src/include/final/ftermdetection.h +++ b/src/include/final/ftermdetection.h @@ -92,7 +92,7 @@ class FTermDetection final FTermDetection& operator = (const FTermDetection&) = delete; // Accessor - static const FString getClassName(); + static FString getClassName(); static const char* getTermType(); static int getGnomeTerminalID(); FTerminalType& getTermTypeStruct(); @@ -174,12 +174,12 @@ class FTermDetection final static bool get256colorEnvString(); static const char* termtype_256color_quirks(); static const char* determineMaxColor (const char[]); - static const FString getXTermColorName (FColor); + static FString getXTermColorName (FColor); static const char* parseAnswerbackMsg (const char[]); - static const FString getAnswerbackMsg(); + static FString getAnswerbackMsg(); static const char* parseSecDA (const char[]); static int str2int (const FString&); - static const FString getSecDA(); + static FString getSecDA(); static const char* secDA_Analysis (const char[]); static const char* secDA_Analysis_0 (const char[]); static const char* secDA_Analysis_1 (const char[]); @@ -210,6 +210,7 @@ class FTermDetection final static const FString* sec_da; static FTermData* fterm_data; static FSystem* fsystem; + static FKeyboard* keyboard; static FTerminalType terminal_type; static colorEnv color_env; static secondaryDA secondary_da; @@ -243,7 +244,7 @@ struct FTermDetection::secondaryDA // FTermDetection inline functions //---------------------------------------------------------------------- -inline const FString FTermDetection::getClassName() +inline FString FTermDetection::getClassName() { return "FTermDetection"; } //---------------------------------------------------------------------- diff --git a/src/include/final/ftermfreebsd.h b/src/include/final/ftermfreebsd.h index 55f0a8a3..93ac5405 100644 --- a/src/include/final/ftermfreebsd.h +++ b/src/include/final/ftermfreebsd.h @@ -95,7 +95,7 @@ class FTermFreeBSD final FTermFreeBSD& operator = (const FTermFreeBSD&) = delete; // Accessors - const FString getClassName() const; + FString getClassName() const; static CursorStyle getCursorStyle(); // Inquiry @@ -137,7 +137,7 @@ class FTermFreeBSD final // FTermFreeBSD inline functions //---------------------------------------------------------------------- -inline const FString FTermFreeBSD::getClassName() const +inline FString FTermFreeBSD::getClassName() const { return "FTermFreeBSD"; } //---------------------------------------------------------------------- diff --git a/src/include/final/ftermios.h b/src/include/final/ftermios.h index e80813f7..e1a31e35 100644 --- a/src/include/final/ftermios.h +++ b/src/include/final/ftermios.h @@ -3,7 +3,7 @@ * * * This file is part of the FINAL CUT widget toolkit * * * -* Copyright 2018-2019 Markus Gans * +* Copyright 2018-2020 Markus Gans * * * * FINAL CUT is free software; you can redistribute it and/or modify * * it under the terms of the GNU Lesser General Public License as * @@ -58,7 +58,7 @@ class FTermios final ~FTermios(); // Accessors - const FString getClassName() const; + FString getClassName() const; static termios getTTY(); static int getStdIn(); static int getStdOut(); @@ -94,7 +94,7 @@ class FTermios final // FTermios inline functions //---------------------------------------------------------------------- -inline const FString FTermios::getClassName() const +inline FString FTermios::getClassName() const { return "FTermios"; } //---------------------------------------------------------------------- diff --git a/src/include/final/ftermlinux.h b/src/include/final/ftermlinux.h index 52e043ee..84b8b0a0 100644 --- a/src/include/final/ftermlinux.h +++ b/src/include/final/ftermlinux.h @@ -93,7 +93,7 @@ class FTermLinux final FTermLinux& operator = (const FTermLinux&) = delete; // Accessors - const FString getClassName() const; + FString getClassName() const; fc::linuxConsoleCursorStyle getCursorStyle() const; char* getCursorStyleString(); int getFramebufferBpp() const; @@ -124,7 +124,7 @@ class FTermLinux final private: // Typedef - struct modifier_key // bit field + struct ModifierKey // bit field { uChar shift : 1; // 0..1 uChar alt_gr : 1; // 0..1 @@ -138,21 +138,21 @@ class FTermLinux final uChar red; uChar green; uChar blue; - } rgb; + } RGB; typedef struct { - rgb color[16]; + RGB color[16]; } ColorMap; // Accessors int getFramebuffer_bpp(); bool getScreenFont(); bool getUnicodeMap (); - modifier_key& getModifierKey(); + ModifierKey& getModifierKey(); // Mutators - int setScreenFont ( uChar[], uInt, uInt, uInt + int setScreenFont ( const uChar[], uInt, uInt, uInt , bool = false ); int setUnicodeMap (struct unimapdesc*); void setLinuxCursorStyle (fc::linuxConsoleCursorStyle) const; @@ -197,14 +197,14 @@ class FTermLinux final ColorMap saved_color_map{}; ColorMap cmap{}; int framebuffer_bpp{-1}; - modifier_key mod_key{}; + ModifierKey mod_key{}; #endif // defined(__linux__) }; // FTermLinux inline functions //---------------------------------------------------------------------- -inline const FString FTermLinux::getClassName() const +inline FString FTermLinux::getClassName() const { return "FTermLinux"; } //---------------------------------------------------------------------- diff --git a/src/include/final/ftermopenbsd.h b/src/include/final/ftermopenbsd.h index b5e470ce..97799dbb 100644 --- a/src/include/final/ftermopenbsd.h +++ b/src/include/final/ftermopenbsd.h @@ -87,7 +87,7 @@ class FTermOpenBSD final FTermOpenBSD& operator = (const FTermOpenBSD&) = delete; // Accessor - const FString getClassName() const; + FString getClassName() const; // Inquiries static bool isBSDConsole(); @@ -122,7 +122,7 @@ class FTermOpenBSD final // FTermOpenBSD inline functions //---------------------------------------------------------------------- -inline const FString FTermOpenBSD::getClassName() const +inline FString FTermOpenBSD::getClassName() const { return "FTermOpenBSD"; } //---------------------------------------------------------------------- diff --git a/src/include/final/ftermxterminal.h b/src/include/final/ftermxterminal.h index 628ed9ae..805f58a3 100644 --- a/src/include/final/ftermxterminal.h +++ b/src/include/final/ftermxterminal.h @@ -41,6 +41,7 @@ namespace finalcut // class forward declaration class FString; class FSystem; +class FKeyboard; class FTermDetection; //---------------------------------------------------------------------- @@ -80,16 +81,16 @@ class FTermXTerminal final void metaSendsESC (bool); // Accessors - const FString getClassName() const; + FString getClassName() const; fc::xtermCursorStyle getCursorStyle() const; - const FString getFont() const; - const FString getTitle() const; - const FString getForeground() const; - const FString getBackground() const; - const FString getCursorColor() const; - const FString getMouseForeground() const; - const FString getMouseBackground() const; - const FString getHighlightBackground() const; + FString getFont() const; + FString getTitle() const; + FString getForeground() const; + FString getBackground() const; + FString getCursorColor() const; + FString getMouseForeground() const; + FString getMouseBackground() const; + FString getHighlightBackground() const; // Inquiries bool hasFont() const; @@ -106,6 +107,7 @@ class FTermXTerminal final void resetMouseBackground(); void resetHighlightBackground(); void resetDefaults(); + void resetTitle(); void captureFontAndTitle(); private: @@ -136,8 +138,8 @@ class FTermXTerminal final bool canResetColor() const; void oscPrefix() const; void oscPostfix() const; - const FString captureXTermFont() const; - const FString captureXTermTitle() const; + FString captureXTermFont() const; + FString captureXTermTitle() const; static void enableXTermMouse(); static void disableXTermMouse(); void enableXTermMetaSendsESC(); @@ -147,6 +149,7 @@ class FTermXTerminal final static bool mouse_support; bool meta_sends_esc{false}; bool xterm_default_colors{false}; + bool title_was_changed{false}; std::size_t term_width{80}; std::size_t term_height{24}; FString xterm_font{}; @@ -158,6 +161,7 @@ class FTermXTerminal final FString mouse_background_color{}; FString highlight_background_color{}; static FSystem* fsystem; + static FKeyboard* keyboard; FTermDetection* term_detection{nullptr}; fc::xtermCursorStyle cursor_style{fc::unknown_cursor_style}; }; @@ -165,7 +169,7 @@ class FTermXTerminal final // FTermXTerminal inline functions //---------------------------------------------------------------------- -inline const FString FTermXTerminal::getClassName() const +inline FString FTermXTerminal::getClassName() const { return "FTermXTerminal"; } //---------------------------------------------------------------------- @@ -177,35 +181,35 @@ inline fc::xtermCursorStyle FTermXTerminal::getCursorStyle() const { return cursor_style; } //---------------------------------------------------------------------- -inline const FString FTermXTerminal::getFont() const +inline FString FTermXTerminal::getFont() const { return xterm_font; } //---------------------------------------------------------------------- -inline const FString FTermXTerminal::getTitle() const +inline FString FTermXTerminal::getTitle() const { return xterm_title; } //---------------------------------------------------------------------- -inline const FString FTermXTerminal::getForeground() const +inline FString FTermXTerminal::getForeground() const { return foreground_color; } //---------------------------------------------------------------------- -inline const FString FTermXTerminal::getBackground() const +inline FString FTermXTerminal::getBackground() const { return background_color; } //---------------------------------------------------------------------- -inline const FString FTermXTerminal::getCursorColor() const +inline FString FTermXTerminal::getCursorColor() const { return cursor_color; } //---------------------------------------------------------------------- -inline const FString FTermXTerminal::getMouseForeground() const +inline FString FTermXTerminal::getMouseForeground() const { return mouse_foreground_color; } //---------------------------------------------------------------------- -inline const FString FTermXTerminal::getMouseBackground() const +inline FString FTermXTerminal::getMouseBackground() const { return mouse_background_color; } //---------------------------------------------------------------------- -inline const FString FTermXTerminal::getHighlightBackground() const +inline FString FTermXTerminal::getHighlightBackground() const { return highlight_background_color; } //---------------------------------------------------------------------- diff --git a/src/include/final/ftextview.h b/src/include/final/ftextview.h index 7d687cbb..8fb66e65 100644 --- a/src/include/final/ftextview.h +++ b/src/include/final/ftextview.h @@ -90,10 +90,10 @@ class FTextView : public FWidget FTextView& operator << (const std::string&); // Accessors - const FString getClassName() const override; + FString getClassName() const override; std::size_t getColumns() const; std::size_t getRows() const; - const FString getText() const; + FString getText() const; const FStringList& getLines() const; // Mutators @@ -112,10 +112,10 @@ class FTextView : public FWidget // Methods void hide() override; - template + template void append (const std::initializer_list&); void append (const FString&); - template + template void insert (const std::initializer_list&, int); void insert (const FString&, int); void replaceRange (const FString&, int, int); @@ -138,7 +138,7 @@ class FTextView : public FWidget private: // Typedefs - typedef std::unordered_map> keyMap; + typedef std::unordered_map> KeyMap; // Accessors std::size_t getTextHeight() const; @@ -168,7 +168,7 @@ class FTextView : public FWidget FStringList data{}; FScrollbarPtr vbar{nullptr}; FScrollbarPtr hbar{nullptr}; - keyMap key_map{}; + KeyMap key_map{}; bool update_scrollbar{true}; int xoffset{0}; int yoffset{0}; @@ -212,7 +212,7 @@ inline FTextView& FTextView::operator << (const std::string& string) } //---------------------------------------------------------------------- -inline const FString FTextView::getClassName() const +inline FString FTextView::getClassName() const { return "FTextView"; } //---------------------------------------------------------------------- @@ -232,7 +232,7 @@ inline void FTextView::scrollTo (const FPoint& pos) { scrollTo(pos.getX(), pos.getY()); } //---------------------------------------------------------------------- -template +template void FTextView::append (const std::initializer_list& list) { for (auto& str : list) @@ -240,7 +240,7 @@ void FTextView::append (const std::initializer_list& list) } //---------------------------------------------------------------------- -template +template void FTextView::insert (const std::initializer_list& list, int pos) { for (auto& str : list) diff --git a/src/include/final/ftogglebutton.h b/src/include/final/ftogglebutton.h index c1b49d63..35e35565 100644 --- a/src/include/final/ftogglebutton.h +++ b/src/include/final/ftogglebutton.h @@ -79,7 +79,7 @@ class FToggleButton : public FWidget FToggleButton& operator = (const FToggleButton&) = delete; // Accessors - const FString getClassName() const override; + FString getClassName() const override; FString& getText(); // Mutators @@ -141,7 +141,7 @@ class FToggleButton : public FWidget private: // Constants - static constexpr std::size_t NOT_SET = static_cast(-1); + static constexpr auto NOT_SET = static_cast(-1); // Mutator void setGroup (FButtonGroup*); @@ -165,7 +165,7 @@ class FToggleButton : public FWidget // FRadioButton inline functions //---------------------------------------------------------------------- -inline const FString FToggleButton::getClassName() const +inline FString FToggleButton::getClassName() const { return "FToggleButton"; } //---------------------------------------------------------------------- diff --git a/src/include/final/ftooltip.h b/src/include/final/ftooltip.h index 4fdc0839..46caa009 100644 --- a/src/include/final/ftooltip.h +++ b/src/include/final/ftooltip.h @@ -80,8 +80,8 @@ class FToolTip : public FWindow FToolTip& operator = (const FToolTip&) = delete; // Accessors - const FString getClassName() const override; - const FString getText() const; + FString getClassName() const override; + FString getText() const; // Mutators void setText (const FString&); @@ -116,9 +116,13 @@ class FToolTip : public FWindow // FToolTip inline functions //---------------------------------------------------------------------- -inline const FString FToolTip::getClassName() const +inline FString FToolTip::getClassName() const { return "FToolTip"; } +//---------------------------------------------------------------------- +inline FString FToolTip::getText() const +{ return text; } + //---------------------------------------------------------------------- inline bool FToolTip::setBorder() { return setBorder(true); } diff --git a/src/include/final/ftypes.h b/src/include/final/ftypes.h index cecfaa8b..7936d795 100644 --- a/src/include/final/ftypes.h +++ b/src/include/final/ftypes.h @@ -36,17 +36,15 @@ #include #include -#include - #define null nullptr -#define badAllocOutput(object_name) \ - *FApplication::getLog() << FLog::Error \ - << __FILE__ << ":" << __LINE__ \ - << ": Not enough memory to alloc " \ - << (object_name) \ - << " in " \ - << __func__ << std::endl; +#define badAllocOutput(object_name) \ + std::clog << FLog::Error \ + << __FILE__ << ":" << __LINE__ \ + << ": Not enough memory to alloc " \ + << (object_name) \ + << " in " \ + << __func__ << std::endl; typedef unsigned char uChar; typedef unsigned short uShort; @@ -75,7 +73,11 @@ typedef std::function FCall; namespace finalcut { -template +namespace internal +{ + +template struct is_negative { inline bool operator () (const T& x) const @@ -93,10 +95,12 @@ struct is_negative } }; +} // namespace internal + template -inline bool isNegative (const T& x) +constexpr bool isNegative (const T& x) { - return is_negative::is_signed>()(x); + return internal::is_negative::is_signed>()(x); } template @@ -183,6 +187,25 @@ FKeyName; } // namespace fc +// FChar operator functions +//---------------------------------------------------------------------- +constexpr bool operator == (const FChar& lhs, const FChar& rhs) +{ + return lhs.ch == rhs.ch + && lhs.fg_color == rhs.fg_color + && lhs.bg_color == rhs.bg_color + && lhs.attr.byte[0] == rhs.attr.byte[0] + && lhs.attr.byte[1] == rhs.attr.byte[1] + && lhs.attr.bit.fullwidth_padding \ + == rhs.attr.bit.fullwidth_padding; +} + +//---------------------------------------------------------------------- +constexpr bool operator != (const FChar& lhs, const FChar& rhs) +{ + return ! ( lhs == rhs ); +} + } // namespace finalcut #endif // FTYPES_H diff --git a/src/include/final/fvterm.h b/src/include/final/fvterm.h index b6d39abf..1107aa86 100644 --- a/src/include/final/fvterm.h +++ b/src/include/final/fvterm.h @@ -143,13 +143,13 @@ class FVTerm FVTerm& operator << (const FColorPair&); // Accessors - virtual const FString getClassName() const; + virtual FString getClassName() const; static FColor getTermForegroundColor(); static FColor getTermBackgroundColor(); FTermArea*& getVWin(); const FTermArea* getVWin() const; - const FPoint getPrintCursor(); - static const FChar getAttribute(); + FPoint getPrintCursor(); + static FChar getAttribute(); FTerm& getFTerm() const; // Mutators @@ -259,7 +259,7 @@ class FVTerm virtual void addPreprocessingHandler ( const FVTerm* , const FPreprocessingFunction& ); virtual void delPreprocessingHandler (const FVTerm*); - template + template int printf (const FString&, Args&&...); int print (const FString&); int print (FTermArea*, const FString&); @@ -292,6 +292,7 @@ class FVTerm void setActiveArea (FTermArea*) const; // Inquiries + bool isActive (const FTermArea*) const; bool hasPrintArea() const; bool hasChildPrintArea() const; bool isVirtualWindow() const; @@ -307,6 +308,7 @@ class FVTerm static void removeArea (FTermArea*&); static void restoreVTerm (const FRect&); bool updateVTermCursor (const FTermArea*) const; + void hideVTermCursor() const; static void setAreaCursor ( const FPoint& , bool, FTermArea* ); static void getArea (const FPoint&, const FTermArea*); @@ -371,12 +373,12 @@ class FVTerm bool hasChildAreaChanges (FTermArea*) const; void clearChildAreaChanges (const FTermArea*) const; static bool isInsideArea (const FPoint&, const FTermArea*); - static const FChar generateCharacter (const FPoint&); - static const FChar getCharacter ( character_type + static FChar generateCharacter (const FPoint&); + static FChar getCharacter ( character_type , const FPoint& , FVTerm* ); - static const FChar getCoveredCharacter (const FPoint&, FVTerm*); - static const FChar getOverlappedCharacter (const FPoint&, FVTerm*); + static FChar getCoveredCharacter (const FPoint&, FVTerm*); + static FChar getOverlappedCharacter (const FPoint&, FVTerm*); void init(); static void init_characterLengths (const FOptiMove*); void finish(); @@ -579,9 +581,9 @@ inline FVTerm& FVTerm::operator << (const std::string& string) //---------------------------------------------------------------------- inline FVTerm& FVTerm::operator << \ - (const std::vector& termString) + (const std::vector& term_string) { - print (termString); + print (term_string); return *this; } @@ -607,7 +609,7 @@ inline FVTerm& FVTerm::operator << (const FColorPair& pair) } //---------------------------------------------------------------------- -inline const FString FVTerm::getClassName() const +inline FString FVTerm::getClassName() const { return "FVTerm"; } //---------------------------------------------------------------------- @@ -627,7 +629,7 @@ inline const FVTerm::FTermArea* FVTerm::getVWin() const { return vwin; } //---------------------------------------------------------------------- -inline const FChar FVTerm::getAttribute() +inline FChar FVTerm::getAttribute() { return next_attribute; } //---------------------------------------------------------------------- @@ -926,7 +928,7 @@ inline bool FVTerm::isInheritBackground() { return next_attribute.attr.bit.inherit_background; } //---------------------------------------------------------------------- -template +template inline int FVTerm::printf (const FString& format, Args&&... args) { FString str{}; @@ -966,6 +968,10 @@ inline void FVTerm::setChildPrintArea (FTermArea* area) inline void FVTerm::setActiveArea (FTermArea* area) const { active_area = area; } +//---------------------------------------------------------------------- +inline bool FVTerm::isActive (const FTermArea* area) const +{ return bool( area == active_area ); } + //---------------------------------------------------------------------- inline bool FVTerm::hasPrintArea() const { return print_area; } @@ -982,6 +988,9 @@ inline bool FVTerm::isVirtualWindow() const inline bool FVTerm::isCursorHideable() const { return cursor_hideable; } +//---------------------------------------------------------------------- +inline void FVTerm::hideVTermCursor() const +{ vterm->input_cursor_visible = false; } } // namespace finalcut diff --git a/src/include/final/fwidget.h b/src/include/final/fwidget.h index dcb36328..20e8c62e 100644 --- a/src/include/final/fwidget.h +++ b/src/include/final/fwidget.h @@ -183,7 +183,7 @@ class FWidget : public FVTerm, public FObject FWidget& operator = (const FWidget&) = delete; // Accessors - const FString getClassName() const override; + FString getClassName() const override; FWidget* getRootWidget() const; FWidget* getParentWidget() const; static FWidget*& getMainWidget(); @@ -206,20 +206,20 @@ class FWidget : public FVTerm, public FObject // Positioning and sizes accessors... int getX() const; int getY() const; - const FPoint getPos() const; + FPoint getPos() const; int getTermX() const; int getTermY() const; - const FPoint getTermPos() const; + FPoint getTermPos() const; std::size_t getWidth() const; std::size_t getHeight() const; - const FSize getSize() const; + FSize getSize() const; int getTopPadding() const; int getLeftPadding() const; int getBottomPadding() const; int getRightPadding() const; std::size_t getClientWidth() const; std::size_t getClientHeight() const; - const FSize getClientSize() const; + FSize getClientSize() const; std::size_t getMaxWidth() const; std::size_t getMaxHeight() const; const FSize& getShadow() const; @@ -230,8 +230,8 @@ class FWidget : public FVTerm, public FObject std::size_t getDesktopWidth() const; std::size_t getDesktopHeight() const; const FWidgetFlags& getFlags() const; - const FPoint getCursorPos() const; - const FPoint getPrintPos(); + FPoint getCursorPos() const; + FPoint getPrintPos(); // Mutators static void setMainWidget (FWidget*); @@ -240,7 +240,7 @@ class FWidget : public FVTerm, public FObject static void setMoveSizeWidget (FWidget*); static void setActiveWindow (FWidget*); static void setOpenMenu (FWidget*); - template + template static void setColorTheme(); FAcceleratorList& setAcceleratorList(); virtual void setStatusbarMessage (const FString&); @@ -317,9 +317,9 @@ class FWidget : public FVTerm, public FObject int numOfFocusableChildren(); virtual bool close(); void clearStatusbarMessage(); - template + template void addCallback (const FString&, Args&&...) noexcept; - template + template void delCallback (Args&&...) noexcept; void emitCallback (const FString&) const; void addAccelerator (FKey); @@ -332,7 +332,7 @@ class FWidget : public FVTerm, public FObject virtual void hide(); virtual bool focusFirstChild(); // widget focusing virtual bool focusLastChild(); - const FPoint termToWidgetPos (const FPoint&) const; + FPoint termToWidgetPos (const FPoint&) const; void print (const FPoint&) override; virtual void move (const FPoint&); virtual void drawBorder(); @@ -452,6 +452,7 @@ class FWidget : public FVTerm, public FObject static bool isDefaultTheme(); static void initColorTheme(); void destroyColorTheme(); + void removeQueuedEvent() const; void setStatusbarText (bool) const; // Data members @@ -540,7 +541,7 @@ void drawNewFontListBox (FWidget*, const FRect&); // FWidget inline functions //---------------------------------------------------------------------- -inline const FString FWidget::getClassName() const +inline FString FWidget::getClassName() const { return "FWidget"; } //---------------------------------------------------------------------- @@ -582,7 +583,7 @@ inline FStatusBar* FWidget::getStatusBar() //---------------------------------------------------------------------- inline FWidget::FWidgetColorsPtr& FWidget::getColorTheme() { - static FWidgetColorsPtr* color_theme = new FWidgetColorsPtr(); + static auto color_theme = new FWidgetColorsPtr(); return *color_theme; } @@ -615,7 +616,7 @@ inline int FWidget::getY() const // y-position relative to the widget { return adjust_wsize.getY(); } //---------------------------------------------------------------------- -inline const FPoint FWidget::getPos() const // position relative to the widget +inline FPoint FWidget::getPos() const // position relative to the widget { const FPoint& pos = adjust_wsize.getPos(); // initialize pos return pos; @@ -630,7 +631,7 @@ inline int FWidget::getTermY() const // y-position on terminal { return woffset.getY1() + adjust_wsize.getY(); } //---------------------------------------------------------------------- -inline const FPoint FWidget::getTermPos() const // position on terminal +inline FPoint FWidget::getTermPos() const // position on terminal { return {getTermX(), getTermY()}; } //---------------------------------------------------------------------- @@ -642,7 +643,7 @@ inline std::size_t FWidget::getHeight() const { return adjust_wsize.getHeight(); } //---------------------------------------------------------------------- -inline const FSize FWidget::getSize() const +inline FSize FWidget::getSize() const { const FSize& size = adjust_wsize.getSize(); // initialize size return size; @@ -673,7 +674,7 @@ inline std::size_t FWidget::getClientHeight() const { return wclient_offset.getHeight(); } //---------------------------------------------------------------------- -inline const FSize FWidget::getClientSize() const +inline FSize FWidget::getClientSize() const { const FSize& size = wclient_offset.getSize(); // initialize size return size; @@ -750,7 +751,7 @@ inline const FWidget::FWidgetFlags& FWidget::getFlags() const { return flags; } //---------------------------------------------------------------------- -inline const FPoint FWidget::getCursorPos() const +inline FPoint FWidget::getCursorPos() const { return widget_cursor_position; } //---------------------------------------------------------------------- @@ -770,7 +771,7 @@ inline void FWidget::setOpenMenu (FWidget* obj) { open_menu = obj; } //---------------------------------------------------------------------- -template +template inline void FWidget::setColorTheme() { getColorTheme() = std::make_shared(); @@ -984,14 +985,14 @@ inline void FWidget::clearStatusbarMessage() { statusbar_message.clear(); } //---------------------------------------------------------------------- -template +template inline void FWidget::addCallback (const FString& cb_signal, Args&&... args) noexcept { callback_impl.addCallback (cb_signal, std::forward(args)...); } //---------------------------------------------------------------------- -template +template inline void FWidget::delCallback (Args&&... args) noexcept { callback_impl.delCallback(std::forward(args)...); @@ -1012,7 +1013,7 @@ inline void FWidget::delAccelerator() { delAccelerator(this); } //---------------------------------------------------------------------- -inline const FPoint FWidget::termToWidgetPos (const FPoint& tPos) const +inline FPoint FWidget::termToWidgetPos (const FPoint& tPos) const { return { tPos.getX() + 1 - woffset.getX1() - adjust_wsize.getX() , tPos.getY() + 1 - woffset.getY1() - adjust_wsize.getY() }; @@ -1057,7 +1058,7 @@ inline void FWidget::processDestroy() const // Non-member elements for NewFont //---------------------------------------------------------------------- -const wchar_t NF_menu_button[4] = +constexpr wchar_t NF_menu_button[] { fc::NF_rev_menu_button1, fc::NF_rev_menu_button2, @@ -1065,49 +1066,49 @@ const wchar_t NF_menu_button[4] = '\0' }; -const wchar_t NF_button_up[3] = +constexpr wchar_t NF_button_up[] { fc::NF_rev_up_pointing_triangle1, fc::NF_rev_up_pointing_triangle2, '\0' }; -const wchar_t NF_button_down[3] = +constexpr wchar_t NF_button_down[] { fc::NF_rev_down_pointing_triangle1, fc::NF_rev_down_pointing_triangle2, '\0' }; -const wchar_t NF_button_arrow_up[3] = +constexpr wchar_t NF_button_arrow_up[] { fc::NF_rev_up_arrow1, fc::NF_rev_up_arrow2, '\0' }; -const wchar_t NF_button_arrow_down[3] = +constexpr wchar_t NF_button_arrow_down[] { fc::NF_rev_down_arrow1, fc::NF_rev_down_arrow2, '\0' }; -const wchar_t NF_button_arrow_left[3] = +constexpr wchar_t NF_button_arrow_left[] { fc::NF_rev_left_arrow1, fc::NF_rev_left_arrow2, '\0' }; -const wchar_t NF_button_arrow_right[3] = +constexpr wchar_t NF_button_arrow_right[] { fc::NF_rev_right_arrow1, fc::NF_rev_right_arrow2, '\0' }; -const wchar_t NF_Drive[5] = +constexpr wchar_t NF_Drive[] { fc::NF_shadow_box_left, fc::NF_shadow_box_middle, @@ -1116,7 +1117,7 @@ const wchar_t NF_Drive[5] = '\0' }; -const wchar_t NF_CD_ROM[5] = +constexpr wchar_t NF_CD_ROM[] { fc::NF_shadow_box_left, fc::NF_shadow_box_middle, @@ -1125,7 +1126,7 @@ const wchar_t NF_CD_ROM[5] = '\0' }; -const wchar_t NF_Net_Drive[5] = +constexpr wchar_t NF_Net_Drive[] { fc::NF_shadow_box_left, fc::NF_shadow_box_middle, @@ -1134,7 +1135,7 @@ const wchar_t NF_Net_Drive[5] = '\0' }; -const wchar_t CHECKBOX[4] = +constexpr wchar_t CHECKBOX[] { fc::NF_shadow_box_left, fc::NF_shadow_box_middle, @@ -1142,7 +1143,7 @@ const wchar_t CHECKBOX[4] = '\0' }; -const wchar_t CHECKBOX_ON[4] = +constexpr wchar_t CHECKBOX_ON[] { fc::NF_shadow_box_left, fc::NF_shadow_box_checked, @@ -1150,7 +1151,7 @@ const wchar_t CHECKBOX_ON[4] = '\0' }; -const wchar_t RADIO_BUTTON[4] = +constexpr wchar_t RADIO_BUTTON[] { fc::NF_radio_button1, fc::NF_radio_button2, @@ -1158,7 +1159,7 @@ const wchar_t RADIO_BUTTON[4] = '\0' }; -const wchar_t CHECKED_RADIO_BUTTON[4] = +constexpr wchar_t CHECKED_RADIO_BUTTON[] { fc::NF_radio_button1, fc::NF_radio_button2_checked, diff --git a/src/include/final/fwidgetcolors.h b/src/include/final/fwidgetcolors.h index 3b00cbf2..38fbed1a 100644 --- a/src/include/final/fwidgetcolors.h +++ b/src/include/final/fwidgetcolors.h @@ -54,7 +54,7 @@ class FWidgetColors virtual ~FWidgetColors(); // Method - virtual const FString getClassName() const; + virtual FString getClassName() const; virtual void setColorTheme() = 0; // Data members @@ -148,7 +148,7 @@ class FWidgetColors // FWidgetColors inline functions //---------------------------------------------------------------------- -inline const FString FWidgetColors::getClassName() const +inline FString FWidgetColors::getClassName() const { return "FWidgetColors"; } @@ -179,13 +179,13 @@ class default8ColorTheme final : public FWidgetColors ~default8ColorTheme() override; // Method - const FString getClassName() const override; + FString getClassName() const override; void setColorTheme() override; }; // default8ColorTheme inline functions //---------------------------------------------------------------------- -inline const FString default8ColorTheme::getClassName() const +inline FString default8ColorTheme::getClassName() const { return "default8ColorTheme"; } @@ -216,13 +216,13 @@ class default16ColorTheme final : public FWidgetColors ~default16ColorTheme() override; // Method - const FString getClassName() const override; + FString getClassName() const override; void setColorTheme() override; }; // default16ColorTheme inline functions //---------------------------------------------------------------------- -inline const FString default16ColorTheme::getClassName() const +inline FString default16ColorTheme::getClassName() const { return "default16ColorTheme"; } @@ -253,13 +253,13 @@ class default8ColorDarkTheme final : public FWidgetColors ~default8ColorDarkTheme() override; // Method - const FString getClassName() const override; + FString getClassName() const override; void setColorTheme() override; }; // default8ColorDarkTheme inline functions //---------------------------------------------------------------------- -inline const FString default8ColorDarkTheme::getClassName() const +inline FString default8ColorDarkTheme::getClassName() const { return "default8ColorDarkTheme"; } @@ -290,13 +290,13 @@ class default16ColorDarkTheme final : public FWidgetColors ~default16ColorDarkTheme() override; // Method - const FString getClassName() const override; + FString getClassName() const override; void setColorTheme() override; }; // default16ColorDarkTheme inline functions //---------------------------------------------------------------------- -inline const FString default16ColorDarkTheme::getClassName() const +inline FString default16ColorDarkTheme::getClassName() const { return "default16ColorDarkTheme"; } } // namespace finalcut diff --git a/src/include/final/fwindow.h b/src/include/final/fwindow.h index 274b5c5d..f2e61c8c 100644 --- a/src/include/final/fwindow.h +++ b/src/include/final/fwindow.h @@ -83,7 +83,7 @@ class FWindow : public FWidget FWindow& operator = (const FWindow&) = delete; // Accessors - const FString getClassName() const override; + FString getClassName() const override; static FWindow* getWindowWidget (const FWidget*); static int getWindowLayer (const FWidget*); FWidget* getWindowFocusWidget() const; @@ -181,7 +181,7 @@ void closeDropDown (const FWidget*, const FPoint&); // FWindow inline functions //---------------------------------------------------------------------- -inline const FString FWindow::getClassName() const +inline FString FWindow::getClassName() const { return "FWindow"; } //---------------------------------------------------------------------- diff --git a/src/include/final/sgr_optimizer.h b/src/include/final/sgr_optimizer.h index ca974cbe..e67dcdd3 100644 --- a/src/include/final/sgr_optimizer.h +++ b/src/include/final/sgr_optimizer.h @@ -35,6 +35,7 @@ #error "Only can be included directly." #endif +#include #include namespace finalcut @@ -51,10 +52,10 @@ class SGRoptimizer final static constexpr std::size_t ATTR_BUF_SIZE{8192}; // Typedefs - typedef char attributebuffer[ATTR_BUF_SIZE]; + typedef std::array AttributeBuffer; // Constructors - explicit SGRoptimizer (attributebuffer&); + explicit SGRoptimizer (AttributeBuffer&); // Disable copy constructor SGRoptimizer (const SGRoptimizer&) = delete; @@ -70,14 +71,14 @@ class SGRoptimizer final private: // Constants - static constexpr std::size_t NOT_SET = static_cast(-1); + static constexpr auto NOT_SET = static_cast(-1); // Methods void findParameter(); void combineParameter(); // Data member - attributebuffer& seq; + AttributeBuffer& seq; struct parameter { diff --git a/src/sgr_optimizer.cpp b/src/sgr_optimizer.cpp index e2d846a6..b38ecbf4 100644 --- a/src/sgr_optimizer.cpp +++ b/src/sgr_optimizer.cpp @@ -35,7 +35,7 @@ namespace finalcut // constructors and destructor //---------------------------------------------------------------------- -SGRoptimizer::SGRoptimizer (attributebuffer& sequence) +SGRoptimizer::SGRoptimizer (AttributeBuffer& sequence) : seq{sequence} { } @@ -59,7 +59,7 @@ void SGRoptimizer::findParameter() { // Find ANSI X3.64 terminal SGR (Select Graphic Rendition) strings - const std::size_t len = std::strlen(seq); + const std::size_t len = std::strlen(seq.data()); csi_parameter.clear(); if ( len < 6 ) diff --git a/test/Makefile.am b/test/Makefile.am index 27420c4d..35396361 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -9,6 +9,7 @@ AM_CPPFLAGS = -I$(top_srcdir)/src/include -Wall -Werror -std=c++11 noinst_PROGRAMS = \ fobject_test \ fcallback_test \ + fdata_test \ fmouse_test \ fkeyboard_test \ ftermdata_test \ @@ -30,6 +31,7 @@ noinst_PROGRAMS = \ fobject_test_SOURCES = fobject-test.cpp fcallback_test_SOURCES = fcallback-test.cpp +fdata_test_SOURCES = fdata-test.cpp fmouse_test_SOURCES = fmouse-test.cpp fkeyboard_test_SOURCES = fkeyboard-test.cpp ftermdata_test_SOURCES = ftermdata-test.cpp @@ -51,6 +53,7 @@ frect_test_SOURCES = frect-test.cpp TESTS = fobject_test \ fcallback_test \ + fdata_test \ fmouse_test \ fkeyboard_test \ ftermdata_test \ diff --git a/test/Makefile.clang b/test/Makefile.clang index f4ae2e58..9d1817f7 100644 --- a/test/Makefile.clang +++ b/test/Makefile.clang @@ -26,7 +26,7 @@ endif # $@ = name of the targets # $^ = all dependency (without double entries) .cpp: - $(CXX) $(CCXFLAGS) $(INCLUDES) $(LDFLAGS) -o $@ $^ + $(CXX) $^ -o $@ $(CCXFLAGS) $(INCLUDES) $(LDFLAGS) all: $(OBJS) diff --git a/test/Makefile.gcc b/test/Makefile.gcc index a3cd0ed1..3df1bbd2 100644 --- a/test/Makefile.gcc +++ b/test/Makefile.gcc @@ -26,7 +26,7 @@ endif # $@ = name of the targets # $^ = all dependency (without double entries) .cpp: - $(CXX) $(CCXFLAGS) $(INCLUDES) $(LDFLAGS) -o $@ $^ + $(CXX) $^ -o $@ $(CCXFLAGS) $(INCLUDES) $(LDFLAGS) all: $(OBJS) diff --git a/test/fcallback-test.cpp b/test/fcallback-test.cpp index 6f21c34e..ed7e83b1 100644 --- a/test/fcallback-test.cpp +++ b/test/fcallback-test.cpp @@ -1,5 +1,5 @@ /*********************************************************************** -* callback-test.cpp - FCallback unit tests * +* fcallback-test.cpp - FCallback unit tests * * * * This file is part of the FINAL CUT widget toolkit * * * @@ -39,13 +39,13 @@ class Widget { public: - template + template void addCallback (const finalcut::FString& cb_signal, Args&&... args) { cb.addCallback (cb_signal, std::forward(args)...); } - template + template void delCallback (Args&&... args) { cb.delCallback (std::forward(args)...); diff --git a/test/fdata-test.cpp b/test/fdata-test.cpp new file mode 100644 index 00000000..00691ba3 --- /dev/null +++ b/test/fdata-test.cpp @@ -0,0 +1,369 @@ +/*********************************************************************** +* fdata-test.cpp - FData unit tests * +* * +* This file is part of the FINAL CUT widget toolkit * +* * +* Copyright 2020 Markus Gans * +* * +* FINAL CUT 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 3 of * +* the License, or (at your option) any later version. * +* * +* FINAL CUT 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 Lesser General Public License for more details. * +* * +* You should have received a copy of the GNU Lesser General Public * +* License along with this program. If not, see * +* . * +***********************************************************************/ + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +//---------------------------------------------------------------------- +// functions +//---------------------------------------------------------------------- +float my_function() +{ + return 13.45F; +} + +//---------------------------------------------------------------------- +long int my_function2 (long int i) +{ + return 2 * i; +} + +//---------------------------------------------------------------------- +long int my_function3 (long int i) +{ + return 3 * i; +} + + +//---------------------------------------------------------------------- +// class FDataTest +//---------------------------------------------------------------------- + +class FDataTest : public CPPUNIT_NS::TestFixture +{ + public: + FDataTest() + { } + + protected: + void classNameTest(); + void fdataTest(); + void copyConstructorTest(); + void moveConstructorTest(); + void copyAssignmentTest(); + void moveAssignmentTest(); + void makeFDataTest(); + + private: + // Adds code needed to register the test suite + CPPUNIT_TEST_SUITE (FDataTest); + + // Add a methods to the test suite + CPPUNIT_TEST (classNameTest); + CPPUNIT_TEST (fdataTest); + CPPUNIT_TEST (copyConstructorTest); + CPPUNIT_TEST (moveConstructorTest); + CPPUNIT_TEST (copyAssignmentTest); + CPPUNIT_TEST (moveAssignmentTest); + CPPUNIT_TEST (makeFDataTest); + + // End of test suite definition + CPPUNIT_TEST_SUITE_END(); + + // Data member + static finalcut::FWidget root_widget; +}; + +// static class attributes +finalcut::FWidget FDataTest::root_widget{nullptr}; + +//---------------------------------------------------------------------- +void FDataTest::classNameTest() +{ + auto da = finalcut::FDataAccess(); + const finalcut::FString& classname2 = da.getClassName(); + CPPUNIT_ASSERT ( classname2 == "FDataAccess" ); + + auto d = finalcut::FData(nullptr); + const finalcut::FString& classname = d.getClassName(); + CPPUNIT_ASSERT ( classname == "FData" ); +} + +//---------------------------------------------------------------------- +void FDataTest::fdataTest() +{ + // nummber + auto data1 = finalcut::FData(5); + CPPUNIT_ASSERT ( data1.isInitializedCopy() ); + CPPUNIT_ASSERT ( ! data1.isInitializedReference() ); + std::stringstream stream{}; + stream << data1; + CPPUNIT_ASSERT ( stream.str() == "5" ); + int i1{data1}; + CPPUNIT_ASSERT ( i1 == 5 ); + CPPUNIT_ASSERT ( data1() == 5 ); + CPPUNIT_ASSERT ( data1.get() == 5 ); + data1.get()++; + CPPUNIT_ASSERT ( data1.get() == 6 ); + data1.set(3); + CPPUNIT_ASSERT ( data1.get() == 3 ); + data1 << 8; + CPPUNIT_ASSERT ( data1.get() == 8 ); + + // int value + int integer_value = 10; + auto data2 = finalcut::FData(std::ref(integer_value)); + CPPUNIT_ASSERT ( ! data2.isInitializedCopy() ); + CPPUNIT_ASSERT ( data2.isInitializedReference() ); + stream.clear(); + stream.str(""); + stream << data2; + CPPUNIT_ASSERT ( stream.str() == "10" ); + int i2{data2}; + CPPUNIT_ASSERT ( i2 == 10 ); + CPPUNIT_ASSERT ( data2() == 10 ); + CPPUNIT_ASSERT ( data2.get() == 10 ); + data2.get()--; + CPPUNIT_ASSERT ( data2.get() == 9 ); + CPPUNIT_ASSERT ( integer_value == 9 ); + data2.set(7); + CPPUNIT_ASSERT ( data2.get() == 7 ); + CPPUNIT_ASSERT ( integer_value == 7 ); + data2 << 15; + CPPUNIT_ASSERT ( integer_value == 15 ); + + // const int value + const int const_integer_value = 12; + auto data3 = finalcut::FData(const_integer_value); + CPPUNIT_ASSERT ( ! data3.isInitializedCopy() ); + CPPUNIT_ASSERT ( data3.isInitializedReference() ); + stream.clear(); + stream.str(""); + stream << data3; + CPPUNIT_ASSERT ( stream.str() == "12" ); + int i3{data3}; + CPPUNIT_ASSERT ( i3 == 12 ); + CPPUNIT_ASSERT ( data3() == 12 ); + CPPUNIT_ASSERT ( data3.get() == 12 ); + + // Function via pointer + auto data4 = finalcut::FData>(&my_function); + CPPUNIT_ASSERT ( data4.isInitializedCopy() ); + CPPUNIT_ASSERT ( ! data4.isInitializedReference() ); + stream.clear(); + stream.str(""); + stream << data4()(); + CPPUNIT_ASSERT ( stream.str() == "13.45" ); + CPPUNIT_ASSERT ( data4()() == 13.45F ); + CPPUNIT_ASSERT ( data4.get()() == 13.45F ); + + // Function via reference -> remove reference + add pointer + auto data5 = finalcut::FData>(my_function); + CPPUNIT_ASSERT ( data5.isInitializedCopy() ); + CPPUNIT_ASSERT ( ! data5.isInitializedReference() ); + stream.clear(); + stream.str(""); + stream << data5()(); + CPPUNIT_ASSERT ( stream.str() == "13.45" ); + CPPUNIT_ASSERT ( data5()() == 13.45F ); + CPPUNIT_ASSERT ( data5.get()() == 13.45F ); + + // Function with parameter via pointer + auto data6 = finalcut::FData>(&my_function2); + CPPUNIT_ASSERT ( data6.isInitializedCopy() ); + CPPUNIT_ASSERT ( ! data6.isInitializedReference() ); + stream.clear(); + stream.str(""); + stream << data6()(4L); + CPPUNIT_ASSERT ( stream.str() == "8" ); + CPPUNIT_ASSERT ( data6()(4) == 8L ); + CPPUNIT_ASSERT ( data6.get()(4) == 8L ); + + // std::string + auto data7 = finalcut::FData("123"); + CPPUNIT_ASSERT ( data7.isInitializedCopy() ); + CPPUNIT_ASSERT ( ! data7.isInitializedReference() ); + stream.clear(); + stream.str(""); + stream << data7; + CPPUNIT_ASSERT ( stream.str() == "123" ); + std::string str{data7}; + CPPUNIT_ASSERT ( str == "123" ); + CPPUNIT_ASSERT ( data7() == "123" ); + CPPUNIT_ASSERT ( data7.get() == "123" ); + data7.get() += "4"; + CPPUNIT_ASSERT ( data7.get() == "1234" ); + data7.set("abc"); + CPPUNIT_ASSERT ( data7.get() == "abc" ); + data7 << "xyz"; + CPPUNIT_ASSERT ( data7.get() == "xyz" ); +} + +//---------------------------------------------------------------------- +void FDataTest::copyConstructorTest() +{ + // value copy + auto data1 = finalcut::FData(2); + CPPUNIT_ASSERT ( data1.isInitializedCopy() ); + CPPUNIT_ASSERT ( data1.get() == 2 ); + auto data2 = finalcut::FData(data1); + CPPUNIT_ASSERT ( data2.isInitializedCopy() ); + data1.get()++; + CPPUNIT_ASSERT ( data1.get() == 3 ); + CPPUNIT_ASSERT ( data2.get() == 2 ); + + // reference copy + uInt n = 100; + auto data3 = finalcut::FData(n); + CPPUNIT_ASSERT ( data3.isInitializedReference() ); + CPPUNIT_ASSERT ( data3.get() == 100 ); + auto data4 = finalcut::FData(data3); + CPPUNIT_ASSERT ( data4.isInitializedReference() ); + data3.get()--; + CPPUNIT_ASSERT ( data3.get() == 99 ); + CPPUNIT_ASSERT ( data4.get() == 99 ); +} + +//---------------------------------------------------------------------- +void FDataTest::moveConstructorTest() +{ + // value copy + auto data1 = finalcut::FData(-5); + CPPUNIT_ASSERT ( data1.isInitializedCopy() ); + CPPUNIT_ASSERT ( data1.get() == -5 ); + auto data2 = finalcut::FData(std::move(data1)); + CPPUNIT_ASSERT ( data2.isInitializedCopy() ); + data1.get() += 10; + CPPUNIT_ASSERT ( data1.get() == 5 ); + CPPUNIT_ASSERT ( data2.get() == -5 ); + + // reference copy + long int n = 0xfffffff; + auto data3 = finalcut::FData(n); + CPPUNIT_ASSERT ( data3.isInitializedReference() ); + CPPUNIT_ASSERT ( data3.get() == 0xfffffff ); + auto data4 = finalcut::FData(std::move(data3)); + CPPUNIT_ASSERT ( data4.isInitializedReference() ); + data3.get()++; + CPPUNIT_ASSERT ( data3.get() == 0x10000000 ); + CPPUNIT_ASSERT ( data4.get() == 0x10000000 ); +} + +//---------------------------------------------------------------------- +void FDataTest::copyAssignmentTest() +{ + // value copy + auto data1 = finalcut::FData(123); + CPPUNIT_ASSERT ( data1.isInitializedCopy() ); + CPPUNIT_ASSERT ( data1.get() == 123 ); + finalcut::FData data2{0}; + data2 = data1; + CPPUNIT_ASSERT ( data2.isInitializedCopy() ); + data1.get() -= 100; + CPPUNIT_ASSERT ( data1.get() == 23 ); + CPPUNIT_ASSERT ( data2.get() == 123 ); + + // reference copy + double c = 299792458.0; // Speed of light + auto data3 = finalcut::FData(c); + CPPUNIT_ASSERT ( data3.isInitializedReference() ); + CPPUNIT_ASSERT ( data3.get() == 299792458 ); + finalcut::FData data4{0.0}; + data4 = data3; + CPPUNIT_ASSERT ( data4.isInitializedReference() ); + data4.get() -= 343.2; // Speed of sound + + CPPUNIT_ASSERT ( data3.get() == 299792114.8 ); + CPPUNIT_ASSERT ( data4.get() == 299792114.8 ); +} + +//---------------------------------------------------------------------- +void FDataTest::moveAssignmentTest() +{ + // value copy + auto data1 = finalcut::FData(9.81F); + CPPUNIT_ASSERT ( data1.isInitializedCopy() ); + CPPUNIT_ASSERT ( data1.get() == 9.81F ); + finalcut::FData data2{0}; + data2 = std::move(data1); + CPPUNIT_ASSERT ( data2.isInitializedCopy() ); + data1.get() -= 0.81; + CPPUNIT_ASSERT ( data1.get() == 9.0F ); + CPPUNIT_ASSERT ( data2.get() == 9.81F ); + + // reference copy + auto au = 149597870700LL; // Astronomical unit + auto data3 = finalcut::FData(au); + CPPUNIT_ASSERT ( data3.isInitializedReference() ); + CPPUNIT_ASSERT ( data3.get() == 149597870700LL ); + finalcut::FData data4{0}; + data4 = std::move(data3); + CPPUNIT_ASSERT ( data4.isInitializedReference() ); + data4.get() /= 2LL; + CPPUNIT_ASSERT ( data3.get() == 74798935350LL ); + CPPUNIT_ASSERT ( data4.get() == 74798935350LL ); +} + +//---------------------------------------------------------------------- +void FDataTest::makeFDataTest() +{ + finalcut::FDataAccess* data_pointer{nullptr}; + + // Array + using ThreeInts = int[3]; + ThreeInts int_array{2, 1, 4}; + data_pointer = finalcut::makeFData(std::move(int_array)); + const auto& ints = static_cast>&>(*data_pointer).get(); + CPPUNIT_ASSERT ( ints[0] == 2 ); + CPPUNIT_ASSERT ( ints[1] == 1 ); + CPPUNIT_ASSERT ( ints[2] == 4 ); + delete data_pointer; + + // Integer + int n = 9; + data_pointer = finalcut::makeFData(std::move(n)); + auto& data = static_cast&>(*data_pointer); + CPPUNIT_ASSERT ( data.isInitializedCopy() ); + CPPUNIT_ASSERT ( ! data.isInitializedReference() ); + auto& n2 = data.get(); + CPPUNIT_ASSERT ( n2 == 9 ); + n2++; + CPPUNIT_ASSERT ( n2 == 10 ); + CPPUNIT_ASSERT ( data() == 10 ); + CPPUNIT_ASSERT ( data_pointer->get() == 10 ); + data_pointer->set(33); + CPPUNIT_ASSERT ( data_pointer->get() == 33 ); + delete data_pointer; + + // Function + data_pointer = finalcut::makeFData(my_function2); + const auto& func = static_cast>&>(*data_pointer).get(); + CPPUNIT_ASSERT ( func(128) == 256 ); + data_pointer->set(&my_function3); + CPPUNIT_ASSERT ( func(128) == 384 ); + delete data_pointer; +} + +// Put the test suite in the registry +CPPUNIT_TEST_SUITE_REGISTRATION (FDataTest); + +// The general unit test main part +#include diff --git a/test/fkeyboard-test.cpp b/test/fkeyboard-test.cpp index 660631b5..3cff23c6 100644 --- a/test/fkeyboard-test.cpp +++ b/test/fkeyboard-test.cpp @@ -32,6 +32,23 @@ #include +#define CPPUNIT_ASSERT_CSTRING(expected, actual) \ + check_c_string (expected, actual, CPPUNIT_SOURCELINE()) + +//---------------------------------------------------------------------- +void check_c_string ( const char* s1 + , const char* s2 + , CppUnit::SourceLine sourceLine ) +{ + if ( s1 == 0 && s2 == 0 ) // Strings are equal + return; + + if ( s1 && s2 && std::strcmp (s1, s2) == 0 ) // Strings are equal + return; + + ::CppUnit::Asserter::fail ("Strings are not equal", sourceLine); +} + namespace test { @@ -43,14 +60,16 @@ typedef struct } FKeyMap; -FKeyMap fkey[] = -{ +using original_type = std::array; +using test_type = std::array; + +test_type fkey = +{{ { finalcut::fc::Fkey_backspace , "\177" , "kb" }, // backspace key { finalcut::fc::Fkey_catab , 0 , "ka" }, // clear-all-tabs key { finalcut::fc::Fkey_clear , 0 , "kC" }, // clear-screen or erase key { finalcut::fc::Fkey_ctab , CSI "3~" , "kt" }, // clear-tab key { finalcut::fc::Fkey_dc , 0 , "kD" }, // delete-character key - { finalcut::fc::Fkey_dc , 0 , "kDx" }, // delete-character key { finalcut::fc::Fkey_dl , 0 , "kL" }, // delete-line key { finalcut::fc::Fkey_down , ESC "OB" , "kd" }, // down-arrow key { finalcut::fc::Fkey_eic , 0 , "kM" }, // sent by rmir or smir in insert mode @@ -196,35 +215,49 @@ FKeyMap fkey[] = { finalcut::fc::Fkey_f62 , ESC "O1;4Q", "Fq" }, // F62 function key { finalcut::fc::Fkey_f63 , ESC "O1;4R", "Fr" }, // F63 function key // vt100 key codes for arrow and function keys - { finalcut::fc::Fkey_down , CSI "B" , "kdx"}, // down-arrow key (standard mode) - { finalcut::fc::Fkey_down , ESC "OB" , "kdX"}, // down-arrow key (application mode) - { finalcut::fc::Fkey_f1 , ESC "OP" , "k1X"}, // PF1 (application mode) - { finalcut::fc::Fkey_f2 , CSI "OQ" , "k2X"}, // PF2 (application mode) - { finalcut::fc::Fkey_f3 , ESC "OR" , "k3X"}, // PF3 (application mode) - { finalcut::fc::Fkey_f4 , ESC "OS" , "k4X"}, // PF4 (application mode) + { finalcut::fc::Fkey_f1 , ESC "OP" , "k1x"}, // PF1 (application mode) + { finalcut::fc::Fkey_f2 , ESC "OQ" , "k2x"}, // PF2 (application mode) + { finalcut::fc::Fkey_f3 , ESC "OR" , "k3x"}, // PF3 (application mode) + { finalcut::fc::Fkey_f4 , ESC "OS" , "k4x"}, // PF4 (application mode) { finalcut::fc::Fkey_left , CSI "D" , "klx"}, // left-arrow key (standard mode) { finalcut::fc::Fkey_left , ESC "OD" , "klX"}, // left-arrow key (application mode) { finalcut::fc::Fkey_right , CSI "C" , "krx"}, // right-arrow key (standard mode) { finalcut::fc::Fkey_right , ESC "OC" , "krX"}, // right-arrow key (application mode) { finalcut::fc::Fkey_up , CSI "A" , "kux"}, // up-arrow key (standard mode) { finalcut::fc::Fkey_up , ESC "OA" , "kuX"}, // up-arrow key (application mode) + { finalcut::fc::Fkey_down , CSI "B" , "kdx"}, // down-arrow key (standard mode) + { finalcut::fc::Fkey_down , ESC "OB" , "kdX"}, // down-arrow key (application mode) + { finalcut::fc::Fkey_sf , CSI "a" , "kFx"}, // scroll-forward key (shift-up) + { finalcut::fc::Fkey_sr , CSI "b" , "kRx"}, // scroll-backward key (shift-down) // Fallback for rxvt with TERM=xterm { finalcut::fc::Fkey_home , CSI "7~" , "khx"}, // home key { finalcut::fc::Fkey_end , CSI "8~" , "@7x"}, // end key - { finalcut::fc::Fkey_f1 , CSI "11~" , "k1x"}, // F1 function key - { finalcut::fc::Fkey_f2 , CSI "12~" , "k2x"}, // F2 function key - { finalcut::fc::Fkey_f3 , CSI "13~" , "k3x"}, // F3 function key - { finalcut::fc::Fkey_f4 , CSI "14~" , "k4x"}, // F4 function key + { finalcut::fc::Fkey_f1 , CSI "11~" , "k1X"}, // F1 function key + { finalcut::fc::Fkey_f2 , CSI "12~" , "k2X"}, // F2 function key + { finalcut::fc::Fkey_f3 , CSI "13~" , "k3X"}, // F3 function key + { finalcut::fc::Fkey_f4 , CSI "14~" , "k4X"}, // F4 function key // Fallback for TERM=ansi - { finalcut::fc::Fkey_end , CSI "K" , "@7X"}, // end key + { finalcut::fc::Fkey_home , CSI "H" , "khX"}, // home key + { finalcut::fc::Fkey_end , CSI "F" , "@7X"}, // end key + { finalcut::fc::Fkey_end , CSI "K" , "@7y"}, // end key (Microsoft HyperTerminal) // Keypad keys { finalcut::fc::Fkey_enter , ESC "OM" , "@8x"}, // enter key { finalcut::fc::Fkey_slash , ESC "Oo" , "KP1"}, // keypad slash { finalcut::fc::Fkey_asterisk , ESC "Oj" , "KP2"}, // keypad asterisk { finalcut::fc::Fkey_minus_sign, ESC "Om" , "KP3"}, // keypad minus sign { finalcut::fc::Fkey_plus_sign , ESC "Ok" , "KP4"}, // keypad plus sign - { 0 , 0 , "\0" } -}; + { finalcut::fc::Fkey_ic , ESC "Op" , "kIx"}, // keypad insert + { finalcut::fc::Fkey_dc , ESC "On" , "kDx"}, // keypad delete + { finalcut::fc::Fkey_left , ESC "Ot" , "kly"}, // keypad left-arrow + { finalcut::fc::Fkey_right , ESC "Ov" , "kry"}, // keypad right-arrow + { finalcut::fc::Fkey_up , ESC "Ox" , "kuy"}, // keypad up-arrow + { finalcut::fc::Fkey_down , ESC "Or" , "kdy"}, // keypad down-arrow + { finalcut::fc::Fkey_a1 , ESC "Ow" , "K1x"}, // keypad upper left + { finalcut::fc::Fkey_a3 , ESC "Oy" , "K3x"}, // keypad upper right + { finalcut::fc::Fkey_b2 , ESC "Ou" , "K2x"}, // keypad center + { finalcut::fc::Fkey_c1 , ESC "Oq" , "K4x"}, // keypad lower left + { finalcut::fc::Fkey_c3 , ESC "Os" , "K5x"} // keypad lower right +}}; } // namespace test @@ -363,6 +396,11 @@ void FKeyboardTest::noArgumentTest() keyboard->setReadBlockingTime(100000); // 100 ms CPPUNIT_ASSERT ( keyboard->getReadBlockingTime() == 100 * 1000 ); + + // Check key map + CPPUNIT_ASSERT ( test::fkey[0].num == finalcut::fc::Fkey_backspace ); + CPPUNIT_ASSERT_CSTRING ( test::fkey[0].string, "\177" ); + CPPUNIT_ASSERT_CSTRING ( test::fkey[0].tname, "kb" ); } //---------------------------------------------------------------------- @@ -2537,6 +2575,13 @@ void FKeyboardTest::sequencesTest() CPPUNIT_ASSERT ( key_pressed == finalcut::fc::Fkey_home ); clear(); + // Home key (ANSI terminal) + input("\033[H"); + processInput(); + std::cout << " - Key: " << keyboard->getKeyName(key_pressed) << std::endl; + CPPUNIT_ASSERT ( key_pressed == finalcut::fc::Fkey_home ); + clear(); + // End key in positioning mode input("\033[8~"); processInput(); @@ -2552,6 +2597,13 @@ void FKeyboardTest::sequencesTest() clear(); // End key (ANSI terminal) + input("\033[F"); + processInput(); + std::cout << " - Key: " << keyboard->getKeyName(key_pressed) << std::endl; + CPPUNIT_ASSERT ( key_pressed == finalcut::fc::Fkey_end ); + clear(); + + // End key (Microsoft HyperTerminal) input("\033[K"); processInput(); std::cout << " - Key: " << keyboard->getKeyName(key_pressed) << std::endl; @@ -2586,6 +2638,13 @@ void FKeyboardTest::sequencesTest() CPPUNIT_ASSERT ( key_pressed == finalcut::fc::Fkey_sf ); clear(); + // Scroll-forward key (shift + up-arrow) in applications mode + input("\033[a"); + processInput(); + std::cout << " - Key: " << keyboard->getKeyName(key_pressed) << std::endl; + CPPUNIT_ASSERT ( key_pressed == finalcut::fc::Fkey_sf ); + clear(); + // Scroll-backward key (shift + down-arrow) input("\033[1;2A"); processInput(); @@ -2593,6 +2652,13 @@ void FKeyboardTest::sequencesTest() CPPUNIT_ASSERT ( key_pressed == finalcut::fc::Fkey_sr ); clear(); + // Scroll-backward key (shift + down-arrow) in applications mode + input("\033[b"); + processInput(); + std::cout << " - Key: " << keyboard->getKeyName(key_pressed) << std::endl; + CPPUNIT_ASSERT ( key_pressed == finalcut::fc::Fkey_sr ); + clear(); + // Center of keypad input("\033[E"); processInput(); @@ -2704,6 +2770,84 @@ void FKeyboardTest::sequencesTest() std::cout << " - Key: " << keyboard->getKeyName(key_pressed) << std::endl; CPPUNIT_ASSERT ( key_pressed == finalcut::fc::Fkey_plus_sign ); clear(); + + // Keypad insert (numlock off) + input("\033Op"); + processInput(); + std::cout << " - Key: " << keyboard->getKeyName(key_pressed) << std::endl; + CPPUNIT_ASSERT ( key_pressed == finalcut::fc::Fkey_ic ); + clear(); + + // Keypad delete (numlock off) + input("\033On"); + processInput(); + std::cout << " - Key: " << keyboard->getKeyName(key_pressed) << std::endl; + CPPUNIT_ASSERT ( key_pressed == finalcut::fc::Fkey_dc ); + clear(); + + // Keypad left-arrow (numlock off) + input("\033Ot"); + processInput(); + std::cout << " - Key: " << keyboard->getKeyName(key_pressed) << std::endl; + CPPUNIT_ASSERT ( key_pressed == finalcut::fc::Fkey_left ); + clear(); + + // Keypad right-arrow (numlock off) + input("\033Ov"); + processInput(); + std::cout << " - Key: " << keyboard->getKeyName(key_pressed) << std::endl; + CPPUNIT_ASSERT ( key_pressed == finalcut::fc::Fkey_right ); + clear(); + + // Keypad up-arrow (numlock off) + input("\033Ox"); + processInput(); + std::cout << " - Key: " << keyboard->getKeyName(key_pressed) << std::endl; + CPPUNIT_ASSERT ( key_pressed == finalcut::fc::Fkey_up ); + clear(); + + // Keypad down-arrow (numlock off) + input("\033Or"); + processInput(); + std::cout << " - Key: " << keyboard->getKeyName(key_pressed) << std::endl; + CPPUNIT_ASSERT ( key_pressed == finalcut::fc::Fkey_down ); + clear(); + + // Keypad upper left (numlock off) + input("\033Ow"); + processInput(); + std::cout << " - Key: " << keyboard->getKeyName(key_pressed) << std::endl; + CPPUNIT_ASSERT ( key_pressed == finalcut::fc::Fkey_a1 ); + clear(); + + // Keypad upper right (numlock off) + input("\033Oy"); + processInput(); + std::cout << " - Key: " << keyboard->getKeyName(key_pressed) << std::endl; + CPPUNIT_ASSERT ( key_pressed == finalcut::fc::Fkey_a3 ); + clear(); + + // Keypad center (numlock off) + input("\033Ou"); + processInput(); + std::cout << " - Key: " << keyboard->getKeyName(key_pressed) << std::endl; + CPPUNIT_ASSERT ( key_pressed == finalcut::fc::Fkey_b2 ); + clear(); + + // Keypad lower left (numlock off) + input("\033Oq"); + processInput(); + std::cout << " - Key: " << keyboard->getKeyName(key_pressed) << std::endl; + CPPUNIT_ASSERT ( key_pressed == finalcut::fc::Fkey_c1 ); + clear(); + + // Keypad lower right (numlock off) + input("\033Os"); + processInput(); + std::cout << " - Key: " << keyboard->getKeyName(key_pressed) << std::endl; + CPPUNIT_ASSERT ( key_pressed == finalcut::fc::Fkey_c3 ); + clear(); + } //---------------------------------------------------------------------- @@ -2826,7 +2970,10 @@ void FKeyboardTest::init() CPPUNIT_ASSERT ( key_pressed == 0 ); keyboard->enableUTF8(); keyboard->enableMouseSequences(); - keyboard->setTermcapMap (reinterpret_cast(test::fkey)); + + auto ptr = &test::fkey; + const auto& ref = *reinterpret_cast(ptr); + keyboard->setTermcapMap (ref); } //---------------------------------------------------------------------- diff --git a/test/flogger-test.cpp b/test/flogger-test.cpp index 21d91247..c3aee10c 100644 --- a/test/flogger-test.cpp +++ b/test/flogger-test.cpp @@ -316,6 +316,9 @@ void FLoggerTest::fileTest() //---------------------------------------------------------------------- void FLoggerTest::applicationObjectTest() { + // Save the rdbuf of clog + std::streambuf* default_clog_rdbuf = std::clog.rdbuf(); + // Generation of a logger in a shared_ptr via a pointer finalcut::FApplication::setLog (std::make_shared()); // Get the shared_ptr with the base class @@ -348,6 +351,15 @@ void FLoggerTest::applicationObjectTest() CPPUNIT_ASSERT ( buf.str() == "[ERROR] test6\r\n" ); buf.str(""); // Clear buffer + // Logging to std::clog + std::clog << finalcut::FLog::Info << "test7" << std::flush; + CPPUNIT_ASSERT ( buf.str() == "[INFO] test7\r\n" ); + buf.str(""); // Clear buffer + + std::clog << finalcut::FLog::Warn << "test8" << std::endl; + CPPUNIT_ASSERT ( buf.str() == "[WARNING] test8\n\r\n" ); + buf.str(""); // Clear buffer + // Replace the logger with another one finalcut::FApplication::setLog(std::make_shared()); log = finalcut::FApplication::getLog(); @@ -369,8 +381,23 @@ void FLoggerTest::applicationObjectTest() CPPUNIT_ASSERT ( buf.str() == "Debug: myLogger 4\n" ); buf.str(""); // Clear buffer - std::shared_ptr* logger = &(finalcut::FApplication::getLog()); - delete logger; + // Logging to std::clog with the replaced logger + std::clog << finalcut::FLog::Info << "myLogger 5" << std::flush; + CPPUNIT_ASSERT ( buf.str() == " Info: myLogger 5\n" ); + buf.str(""); // Clear buffer + + std::clog << finalcut::FLog::Error << "myLogger 6" << std::endl; + CPPUNIT_ASSERT ( buf.str() == "Error: myLogger 6\n\n" ); + buf.str(""); // Clear buffer + + // Reset to the default rdbuf of clog + std::clog.rdbuf(default_clog_rdbuf); + + // Delete the global FApplication logger object + auto logger = &(finalcut::FApplication::getLog()); + + if ( logger ) + delete logger; } diff --git a/test/fobject-test.cpp b/test/fobject-test.cpp index eb356b10..da3da803 100644 --- a/test/fobject-test.cpp +++ b/test/fobject-test.cpp @@ -122,7 +122,12 @@ class FObject_userEvent : public finalcut::FObject virtual void onUserEvent (finalcut::FUserEvent* ev) { if ( ev->getUserId() == 42 ) - value = *(static_cast(ev->getData())); + { + value = ev->getData(); + + if ( ev->getFDataObject().isInitializedReference() ) + ev->getData()++; // this has external effects + } } private: @@ -371,25 +376,57 @@ void FObjectTest::addTest() { // obj -> child - auto obj = new finalcut::FObject(); + auto obj1 = new finalcut::FObject(); auto child = new finalcut::FObject(); - CPPUNIT_ASSERT ( ! obj->hasChildren() ); - CPPUNIT_ASSERT ( obj->numOfChildren() == 0 ); - CPPUNIT_ASSERT ( ! obj->isChild(child) ); + CPPUNIT_ASSERT ( ! obj1->hasChildren() ); + CPPUNIT_ASSERT ( obj1->numOfChildren() == 0 ); + CPPUNIT_ASSERT ( ! obj1->isChild(child) ); CPPUNIT_ASSERT ( ! child->hasParent() ); - CPPUNIT_ASSERT ( child->getParent() != obj ); + CPPUNIT_ASSERT ( child->getParent() != obj1 ); - obj->addChild(child); - CPPUNIT_ASSERT ( obj->hasChildren() ); - CPPUNIT_ASSERT ( obj->numOfChildren() == 1 ); - CPPUNIT_ASSERT ( obj->isChild(child) ); + obj1->addChild(child); + CPPUNIT_ASSERT ( obj1->hasChildren() ); + CPPUNIT_ASSERT ( obj1->numOfChildren() == 1 ); + CPPUNIT_ASSERT ( obj1->isChild(child) ); CPPUNIT_ASSERT ( child->hasParent() ); - CPPUNIT_ASSERT ( child->getParent() == obj ); + CPPUNIT_ASSERT ( child->getParent() == obj1 ); - delete obj; // also deletes the child object + // Switch of the parent by a second addChild + auto obj2 = new finalcut::FObject(); + obj2->addChild(child); + CPPUNIT_ASSERT ( child->hasParent() ); + CPPUNIT_ASSERT ( ! obj1->hasChildren() ); + CPPUNIT_ASSERT ( obj1->numOfChildren() == 0 ); + CPPUNIT_ASSERT ( ! obj1->isChild(child) ); + CPPUNIT_ASSERT ( child->getParent() != obj1 ); + CPPUNIT_ASSERT ( obj2->hasChildren() ); + CPPUNIT_ASSERT ( obj2->numOfChildren() == 1 ); + CPPUNIT_ASSERT ( obj2->isChild(child) ); + CPPUNIT_ASSERT ( child->getParent() == obj2 ); + + // Are the maximum number of child objects reached? + CPPUNIT_ASSERT ( obj2->getMaxChildren() == finalcut::FObject::UNLIMITED ); + obj2->setMaxChildren(1); + CPPUNIT_ASSERT ( obj2->hasChildren() ); + CPPUNIT_ASSERT ( obj2->getMaxChildren() == 1 ); + CPPUNIT_ASSERT ( obj2->numOfChildren() == 1 ); + auto child2 = new finalcut::FObject(); + CPPUNIT_ASSERT ( ! child2->hasParent() ); + CPPUNIT_ASSERT_THROW ( obj2->addChild(child2), std::length_error ); + CPPUNIT_ASSERT ( obj2->numOfChildren() == 1 ); + obj2->setMaxChildren(2); + CPPUNIT_ASSERT ( ! child2->hasParent() ); + CPPUNIT_ASSERT ( obj2->getMaxChildren() == 2 ); + obj2->addChild(child2); + CPPUNIT_ASSERT ( child2->hasParent() ); + CPPUNIT_ASSERT ( obj2->hasChildren() ); + CPPUNIT_ASSERT ( obj2->numOfChildren() == 2 ); + + delete obj1; + delete obj2; // also deletes the child object } //---------------------------------------------------------------------- @@ -438,7 +475,7 @@ void FObjectTest::iteratorTest() finalcut::FObject::const_iterator c_iter, c_last; c_iter = obj->begin(); c_last = obj->end(); - int i = 0; + std::size_t i = 0; while ( c_iter != c_last ) { @@ -625,9 +662,10 @@ void FObjectTest::userEventTest() int n = 9; finalcut::FUserEvent user_ev (finalcut::fc::User_Event, 42); - user_ev.setData( (void*)(&n) ); + user_ev.setData(n); finalcut::FApplication::sendEvent (&user, &user_ev); CPPUNIT_ASSERT ( user.getValue() == 9 ); + CPPUNIT_ASSERT ( n == 10 ); } // Put the test suite in the registry diff --git a/test/foptiattr-test.cpp b/test/foptiattr-test.cpp index a6eb3748..81c6fcbe 100644 --- a/test/foptiattr-test.cpp +++ b/test/foptiattr-test.cpp @@ -224,80 +224,80 @@ void FOptiAttrTest::sgrOptimizerTest() // Test only the optimizer // ----------------------- - char buffer[8192] = { CSI "0;10m" CSI "11m" CSI "36m" CSI "44m" }; + finalcut::SGRoptimizer::AttributeBuffer buffer = { CSI "0;10m" CSI "11m" CSI "36m" CSI "44m" }; finalcut::SGRoptimizer sgr_optimizer(buffer); sgr_optimizer.optimize(); - CPPUNIT_ASSERT_CSTRING ( buffer, CSI "0;10;11;36;44m" ); + CPPUNIT_ASSERT_CSTRING ( buffer.data(), CSI "0;10;11;36;44m" ); - std::strcpy(buffer, CSI "0;1m" CSI "34m"); + std::strcpy(buffer.data(), CSI "0;1m" CSI "34m"); sgr_optimizer.optimize(); - CPPUNIT_ASSERT_CSTRING ( buffer, CSI "0;1;34m" ); + CPPUNIT_ASSERT_CSTRING ( buffer.data(), CSI "0;1;34m" ); - std::strcpy(buffer, CSI "m" CSI "34m"); + std::strcpy(buffer.data(), CSI "m" CSI "34m"); sgr_optimizer.optimize(); - CPPUNIT_ASSERT_CSTRING ( buffer, CSI "0;34m" ); + CPPUNIT_ASSERT_CSTRING ( buffer.data(), CSI "0;34m" ); - std::strcpy(buffer, CSI "1m" CSI "m" CSI "45m"); + std::strcpy(buffer.data(), CSI "1m" CSI "m" CSI "45m"); sgr_optimizer.optimize(); - CPPUNIT_ASSERT_CSTRING ( buffer, CSI "1;0;45m" ); + CPPUNIT_ASSERT_CSTRING ( buffer.data(), CSI "1;0;45m" ); - std::strcpy(buffer, CSI "47m"); + std::strcpy(buffer.data(), CSI "47m"); sgr_optimizer.optimize(); - CPPUNIT_ASSERT_CSTRING ( buffer, CSI "47m" ); + CPPUNIT_ASSERT_CSTRING ( buffer.data(), CSI "47m" ); - std::strcpy(buffer, CSI "47m" CSI "m" CSI "1m"); + std::strcpy(buffer.data(), CSI "47m" CSI "m" CSI "1m"); sgr_optimizer.optimize(); - CPPUNIT_ASSERT_CSTRING ( buffer, CSI "47;0;1m" ); + CPPUNIT_ASSERT_CSTRING ( buffer.data(), CSI "47;0;1m" ); - std::strcpy(buffer, CSI "49m" CSI "m" CSI "0m"); + std::strcpy(buffer.data(), CSI "49m" CSI "m" CSI "0m"); sgr_optimizer.optimize(); - CPPUNIT_ASSERT_CSTRING ( buffer, CSI "49;0;0m" ); + CPPUNIT_ASSERT_CSTRING ( buffer.data(), CSI "49;0;0m" ); - std::strcpy(buffer, CSI "m" CSI "m" CSI "m"); + std::strcpy(buffer.data(), CSI "m" CSI "m" CSI "m"); sgr_optimizer.optimize(); - CPPUNIT_ASSERT_CSTRING ( buffer, CSI "0;0;0m" ); + CPPUNIT_ASSERT_CSTRING ( buffer.data(), CSI "0;0;0m" ); - std::strcpy(buffer, CSI "m"); + std::strcpy(buffer.data(), CSI "m"); sgr_optimizer.optimize(); - CPPUNIT_ASSERT_CSTRING ( buffer, CSI "m" ); + CPPUNIT_ASSERT_CSTRING ( buffer.data(), CSI "m" ); - std::strcpy(buffer, CSI "0;10;1;7m" CSI "3m" CSI "39m" CSI "49m"); + std::strcpy(buffer.data(), CSI "0;10;1;7m" CSI "3m" CSI "39m" CSI "49m"); sgr_optimizer.optimize(); - CPPUNIT_ASSERT_CSTRING ( buffer, CSI "0;10;1;7;3;39;49m" ); + CPPUNIT_ASSERT_CSTRING ( buffer.data(), CSI "0;10;1;7;3;39;49m" ); - std::strcpy(buffer, CSI "m" CSI "38;5;20m" CSI "48;5;229m"); + std::strcpy(buffer.data(), CSI "m" CSI "38;5;20m" CSI "48;5;229m"); sgr_optimizer.optimize(); - CPPUNIT_ASSERT_CSTRING ( buffer, CSI "0;38;5;20;48;5;229m" ); + CPPUNIT_ASSERT_CSTRING ( buffer.data(), CSI "0;38;5;20;48;5;229m" ); - std::strcpy(buffer, CSI "m" CSI "38;5;20m" CSI "11;16H"); + std::strcpy(buffer.data(), CSI "m" CSI "38;5;20m" CSI "11;16H"); sgr_optimizer.optimize(); - CPPUNIT_ASSERT_CSTRING ( buffer, CSI "0;38;5;20m" CSI "11;16H" ); + CPPUNIT_ASSERT_CSTRING ( buffer.data(), CSI "0;38;5;20m" CSI "11;16H" ); - std::strcpy(buffer, CSI "1;1H" CSI "m" CSI "38;5;35m"); + std::strcpy(buffer.data(), CSI "1;1H" CSI "m" CSI "38;5;35m"); sgr_optimizer.optimize(); - CPPUNIT_ASSERT_CSTRING ( buffer, CSI "1;1H" CSI "0;38;5;35m" ); + CPPUNIT_ASSERT_CSTRING ( buffer.data(), CSI "1;1H" CSI "0;38;5;35m" ); - std::strcpy(buffer, CSI "m" CSI "38;5;20m" CSI "11;16H" CSI "48;5;229m"); + std::strcpy(buffer.data(), CSI "m" CSI "38;5;20m" CSI "11;16H" CSI "48;5;229m"); sgr_optimizer.optimize(); - CPPUNIT_ASSERT_CSTRING ( buffer, CSI "0;38;5;20m" CSI "11;16H" CSI "48;5;229m" ); + CPPUNIT_ASSERT_CSTRING ( buffer.data(), CSI "0;38;5;20m" CSI "11;16H" CSI "48;5;229m" ); - std::strcpy(buffer, CSI "m" CSI "38;5;20m" "ABC" CSI "48;5;229m"); + std::strcpy(buffer.data(), CSI "m" CSI "38;5;20m" "ABC" CSI "48;5;229m"); sgr_optimizer.optimize(); - CPPUNIT_ASSERT_CSTRING ( buffer, CSI "0;38;5;20mABC" CSI "48;5;229m" ); + CPPUNIT_ASSERT_CSTRING ( buffer.data(), CSI "0;38;5;20mABC" CSI "48;5;229m" ); - std::strcpy(buffer, CSI "m" CSI "1m" CSI "2m" CSI "3m" CSI "4m" + std::strcpy(buffer.data(), CSI "m" CSI "1m" CSI "2m" CSI "3m" CSI "4m" CSI "5m" CSI "7m" CSI "8m" CSI "9m"); sgr_optimizer.optimize(); - CPPUNIT_ASSERT_CSTRING ( buffer, CSI "0;1;2;3;4;5;7;8;9m" ); + CPPUNIT_ASSERT_CSTRING ( buffer.data(), CSI "0;1;2;3;4;5;7;8;9m" ); - std::strcpy(buffer, CSI "0m" CSI "46;36;1m"); + std::strcpy(buffer.data(), CSI "0m" CSI "46;36;1m"); sgr_optimizer.optimize(); - CPPUNIT_ASSERT_CSTRING ( buffer, CSI "0;46;36;1m" ); + CPPUNIT_ASSERT_CSTRING ( buffer.data(), CSI "0;46;36;1m" ); - std::strcpy(buffer, CSI "m" CSI "38;2;0;139;139m" CSI "48;2;240;255;240m"); + std::strcpy(buffer.data(), CSI "m" CSI "38;2;0;139;139m" CSI "48;2;240;255;240m"); sgr_optimizer.optimize(); - CPPUNIT_ASSERT_CSTRING ( buffer, CSI "0;38;2;0;139;139;48;2;240;255;240m" ); + CPPUNIT_ASSERT_CSTRING ( buffer.data(), CSI "0;38;2;0;139;139;48;2;240;255;240m" ); delete to; delete from; @@ -4163,7 +4163,7 @@ void FOptiAttrTest::wyse50Test() finalcut::FStartOptions::getFStartOptions().sgr_optimizer = false; finalcut::FOptiAttr oa; - finalcut::FOptiAttr::termEnv optiattr_env = + finalcut::FOptiAttr::TermEnv optiattr_env = { 0, // Enter bold ESC "(" ESC "H\003" diff --git a/test/foptimove-test.cpp b/test/foptimove-test.cpp index d98f0509..eaa610d1 100644 --- a/test/foptimove-test.cpp +++ b/test/foptimove-test.cpp @@ -612,7 +612,7 @@ void FOptiMoveTest::teratermTest() om.setTermSize (80, 25); om.setBaudRate (38400); - finalcut::FOptiMove::termEnv optimove_env = + finalcut::FOptiMove::TermEnv optimove_env = { CSI "H", // Cursor home "\r", // Carriage return diff --git a/test/fstring-test.cpp b/test/fstring-test.cpp index a79aa300..38c63c51 100644 --- a/test/fstring-test.cpp +++ b/test/fstring-test.cpp @@ -163,8 +163,8 @@ void FStringTest::noArgumentTest() CPPUNIT_ASSERT ( empty.getLength() == 0 ); CPPUNIT_ASSERT ( empty.capacity() == 0 ); CPPUNIT_ASSERT ( empty.getUTF8length() == 0 ); - CPPUNIT_ASSERT ( empty.wc_str() == 0 ); - CPPUNIT_ASSERT ( empty.c_str() == 0 ); + CPPUNIT_ASSERT ( empty.wc_str() == nullptr ); + CPPUNIT_ASSERT ( empty.c_str() == nullptr ); CPPUNIT_ASSERT_EQUAL ( empty.toString(), std::string() ); CPPUNIT_ASSERT ( strlen(finalcut::FString(99).c_str()) == 0 ); CPPUNIT_ASSERT ( wcslen(finalcut::FString(99).wc_str()) == 0 ); @@ -172,9 +172,9 @@ void FStringTest::noArgumentTest() CPPUNIT_ASSERT ( wcslen(finalcut::FString("").wc_str()) == 0 ); char* cstr = empty.c_str(); - CPPUNIT_ASSERT ( cstr == 0 ); + CPPUNIT_ASSERT ( cstr == nullptr ); wchar_t* wcstr = empty.wc_str(); - CPPUNIT_ASSERT ( wcstr == 0 ); + CPPUNIT_ASSERT ( wcstr == nullptr ); std::string str = empty.toString(); CPPUNIT_ASSERT ( str.length() == 0 ); CPPUNIT_ASSERT ( str.size() == 0 ); @@ -516,7 +516,7 @@ void FStringTest::additionAssignmentTest() //---------------------------------------------------------------------- void FStringTest::additionTest() { - // finalcut::FString member operator + // const finalcut::FString + ... const finalcut::FString s1("abc"); CPPUNIT_ASSERT ( s1.getLength() == 3 ); CPPUNIT_ASSERT ( *(s1.c_str() + s1.getLength()) == '\0' ); @@ -529,8 +529,7 @@ void FStringTest::additionTest() CPPUNIT_ASSERT ( s1 + wchar_t(L'd') == L"abcd" ); CPPUNIT_ASSERT ( s1 + char('d') == L"abcd" ); - - // finalcut::FString non-member operator + // finalcut::FString + ... finalcut::FString s2("abc"); CPPUNIT_ASSERT ( s2.getLength() == 3 ); CPPUNIT_ASSERT ( *(s2.c_str() + s2.getLength()) == '\0' ); @@ -543,25 +542,70 @@ void FStringTest::additionTest() CPPUNIT_ASSERT ( s2 + wchar_t(L'd') == L"abcd" ); CPPUNIT_ASSERT ( s2 + char('d') == L"abcd" ); - const std::wstring& s3 = L"abc"; - CPPUNIT_ASSERT ( s3 + finalcut::FString("def") == L"abcdef" ); + // Empty const finalcut::FString + ... + const finalcut::FString s3; + CPPUNIT_ASSERT ( s3.getLength() == 0 ); + CPPUNIT_ASSERT ( s3.c_str() == nullptr ); + CPPUNIT_ASSERT ( s3.wc_str() == nullptr ); + CPPUNIT_ASSERT ( s3 + finalcut::FString("def") == L"def" ); + CPPUNIT_ASSERT ( s3 + std::wstring(L"def") == L"def" ); + CPPUNIT_ASSERT ( s3 + const_cast(L"def") == L"def" ); + CPPUNIT_ASSERT ( s3 + std::string("def") == L"def" ); + CPPUNIT_ASSERT ( s3 + const_cast("def") == L"def" ); + CPPUNIT_ASSERT ( s3 + wchar_t(L'd') == L"d" ); + CPPUNIT_ASSERT ( s3 + char('d') == L"d" ); - constexpr wchar_t s4[] = L"abc"; - CPPUNIT_ASSERT ( s4 + finalcut::FString("def") == L"abcdef" ); + // Empty finalcut::FString + ... + finalcut::FString s4; + CPPUNIT_ASSERT ( s4.getLength() == 0 ); + CPPUNIT_ASSERT ( s4.c_str() == nullptr ); + CPPUNIT_ASSERT ( s4.wc_str() == nullptr ); + CPPUNIT_ASSERT ( s4 + finalcut::FString("def") == L"def" ); + CPPUNIT_ASSERT ( s4 + std::wstring(L"def") == L"def" ); + CPPUNIT_ASSERT ( s4 + const_cast(L"def") == L"def" ); + CPPUNIT_ASSERT ( s4 + std::string("def") == L"def" ); + CPPUNIT_ASSERT ( s4 + const_cast("def") == L"def" ); + CPPUNIT_ASSERT ( s4 + wchar_t(L'd') == L"d" ); + CPPUNIT_ASSERT ( s4 + char('d') == L"d" ); - const std::string& s5 = "abc"; + // Other string types + finalcut::FString + const std::wstring& s5 = L"abc"; CPPUNIT_ASSERT ( s5 + finalcut::FString("def") == L"abcdef" ); - constexpr char s6[] = "abc"; + constexpr wchar_t s6[] = L"abc"; CPPUNIT_ASSERT ( s6 + finalcut::FString("def") == L"abcdef" ); + const std::string& s7 = "abc"; + CPPUNIT_ASSERT ( s7 + finalcut::FString("def") == L"abcdef" ); + + constexpr char s8[] = "abc"; + CPPUNIT_ASSERT ( s8 + finalcut::FString("def") == L"abcdef" ); + constexpr wchar_t c1 = L'a'; - CPPUNIT_ASSERT ( c1 + s3 == L"aabc" ); + CPPUNIT_ASSERT ( c1 + s5 == L"aabc" ); CPPUNIT_ASSERT ( c1 + finalcut::FString("def") == L"adef" ); constexpr char c2 = 'a'; - CPPUNIT_ASSERT ( c2 + s5 == "aabc" ); + CPPUNIT_ASSERT ( c2 + s7 == "aabc" ); CPPUNIT_ASSERT ( c2 + finalcut::FString("def") == L"adef" ); + + // Other string types + empty const finalcut::FString + CPPUNIT_ASSERT ( s5 + s3 == L"abc" ); + CPPUNIT_ASSERT ( s6 + s3 == L"abc" ); + CPPUNIT_ASSERT ( s7 + s3 == L"abc" ); + CPPUNIT_ASSERT ( s8 + s3 == L"abc" ); + CPPUNIT_ASSERT ( c1 + s3 == L"a" ); + CPPUNIT_ASSERT ( c1 + s3 == L"a" ); + CPPUNIT_ASSERT ( c2 + s3 == "a" ); + + // Other string types + empty finalcut::FString + CPPUNIT_ASSERT ( s5 + s4 == L"abc" ); + CPPUNIT_ASSERT ( s6 + s4 == L"abc" ); + CPPUNIT_ASSERT ( s7 + s4 == L"abc" ); + CPPUNIT_ASSERT ( s8 + s4 == L"abc" ); + CPPUNIT_ASSERT ( c1 + s4 == L"a" ); + CPPUNIT_ASSERT ( c1 + s4 == L"a" ); + CPPUNIT_ASSERT ( c2 + s4 == "a" ); } //---------------------------------------------------------------------- diff --git a/test/ftermcapquirks-test.cpp b/test/ftermcapquirks-test.cpp index bc82fe26..bdd25f47 100644 --- a/test/ftermcapquirks-test.cpp +++ b/test/ftermcapquirks-test.cpp @@ -56,7 +56,7 @@ namespace test typedef struct { const char* string; - char tname[3]; + char tname[alignof(char*)]; } tcap_map; @@ -222,7 +222,7 @@ void FTermcapQuirksTest::classNameTest() //---------------------------------------------------------------------- void FTermcapQuirksTest::generalTest() { - finalcut::FTermcap::tcap_map* caps = finalcut::FTermcap::strings; + auto& caps = finalcut::FTermcap::strings; constexpr int last_item = int(sizeof(test::tcap) / sizeof(test::tcap[0])) - 1; for (std::size_t i = 0; i < last_item; i++) @@ -285,7 +285,7 @@ void FTermcapQuirksTest::generalTest() //---------------------------------------------------------------------- void FTermcapQuirksTest::xtermTest() { - finalcut::FTermcap::tcap_map* caps = finalcut::FTermcap::strings; + auto& caps = finalcut::FTermcap::strings; constexpr int last_item = int(sizeof(test::tcap) / sizeof(test::tcap[0])) - 1; for (std::size_t i = 0; i < last_item; i++) @@ -316,7 +316,7 @@ void FTermcapQuirksTest::xtermTest() //---------------------------------------------------------------------- void FTermcapQuirksTest::freebsdTest() { - finalcut::FTermcap::tcap_map* caps = finalcut::FTermcap::strings; + auto& caps = finalcut::FTermcap::strings; constexpr int last_item = int(sizeof(test::tcap) / sizeof(test::tcap[0])) - 1; for (std::size_t i = 0; i < last_item; i++) @@ -355,7 +355,7 @@ void FTermcapQuirksTest::freebsdTest() //---------------------------------------------------------------------- void FTermcapQuirksTest::cygwinTest() { - finalcut::FTermcap::tcap_map* caps = finalcut::FTermcap::strings; + auto& caps = finalcut::FTermcap::strings; constexpr int last_item = int(sizeof(test::tcap) / sizeof(test::tcap[0])) - 1; for (std::size_t i = 0; i < last_item; i++) @@ -380,7 +380,7 @@ void FTermcapQuirksTest::cygwinTest() //---------------------------------------------------------------------- void FTermcapQuirksTest::linuxTest() { - finalcut::FTermcap::tcap_map* caps = finalcut::FTermcap::strings; + auto& caps = finalcut::FTermcap::strings; constexpr int last_item = int(sizeof(test::tcap) / sizeof(test::tcap[0])) - 1; for (std::size_t i = 0; i < last_item; i++) @@ -452,7 +452,7 @@ void FTermcapQuirksTest::linuxTest() //---------------------------------------------------------------------- void FTermcapQuirksTest::rxvtTest() { - finalcut::FTermcap::tcap_map* caps = finalcut::FTermcap::strings; + auto& caps = finalcut::FTermcap::strings; constexpr int last_item = int(sizeof(test::tcap) / sizeof(test::tcap[0])) - 1; for (std::size_t i = 0; i < last_item; i++) @@ -493,7 +493,7 @@ void FTermcapQuirksTest::rxvtTest() //---------------------------------------------------------------------- void FTermcapQuirksTest::vteTest() { - finalcut::FTermcap::tcap_map* caps = finalcut::FTermcap::strings; + auto& caps = finalcut::FTermcap::strings; constexpr int last_item = int(sizeof(test::tcap) / sizeof(test::tcap[0])) - 1; for (std::size_t i = 0; i < last_item; i++) @@ -517,7 +517,7 @@ void FTermcapQuirksTest::vteTest() //---------------------------------------------------------------------- void FTermcapQuirksTest::puttyTest() { - finalcut::FTermcap::tcap_map* caps = finalcut::FTermcap::strings; + auto& caps = finalcut::FTermcap::strings; constexpr int last_item = int(sizeof(test::tcap) / sizeof(test::tcap[0])) - 1; for (std::size_t i = 0; i < last_item; i++) @@ -607,7 +607,7 @@ void FTermcapQuirksTest::puttyTest() //---------------------------------------------------------------------- void FTermcapQuirksTest::teratermTest() { - finalcut::FTermcap::tcap_map* caps = finalcut::FTermcap::strings; + auto& caps = finalcut::FTermcap::strings; constexpr int last_item = int(sizeof(test::tcap) / sizeof(test::tcap[0])) - 1; for (std::size_t i = 0; i < last_item; i++) @@ -637,7 +637,7 @@ void FTermcapQuirksTest::teratermTest() //---------------------------------------------------------------------- void FTermcapQuirksTest::sunTest() { - finalcut::FTermcap::tcap_map* caps = finalcut::FTermcap::strings; + auto& caps = finalcut::FTermcap::strings; constexpr int last_item = int(sizeof(test::tcap) / sizeof(test::tcap[0])) - 1; for (std::size_t i = 0; i < last_item; i++) @@ -755,7 +755,7 @@ void FTermcapQuirksTest::sunTest() //---------------------------------------------------------------------- void FTermcapQuirksTest::screenTest() { - finalcut::FTermcap::tcap_map* caps = finalcut::FTermcap::strings; + auto& caps = finalcut::FTermcap::strings; constexpr int last_item = int(sizeof(test::tcap) / sizeof(test::tcap[0])) - 1; for (std::size_t i = 0; i < last_item; i++) diff --git a/test/ftermfreebsd-test.cpp b/test/ftermfreebsd-test.cpp index a14a4f00..08f37d34 100644 --- a/test/ftermfreebsd-test.cpp +++ b/test/ftermfreebsd-test.cpp @@ -819,11 +819,11 @@ wchar_t ftermfreebsdTest::charEncode (wchar_t c) { wchar_t ch_enc{L'\0'}; - for (std::size_t i{0}; i <= finalcut::fc::lastCharItem; i++) + for (auto&& entry : finalcut::fc::character) { - if ( finalcut::fc::character[i][finalcut::fc::UTF8] == uInt(c) ) + if ( entry[finalcut::fc::UTF8] == uInt(c) ) { - ch_enc = wchar_t(finalcut::fc::character[i][finalcut::fc::PC]); + ch_enc = wchar_t(entry[finalcut::fc::PC]); break; } } diff --git a/test/ftermlinux-test.cpp b/test/ftermlinux-test.cpp index 6304adb8..017acccd 100644 --- a/test/ftermlinux-test.cpp +++ b/test/ftermlinux-test.cpp @@ -75,18 +75,18 @@ class FSystemTest : public finalcut::FSystem uChar ctrl : 1; uChar alt : 1; uChar : 4; // padding bits - } shiftstate; + } ShiftState; typedef struct { uChar red; uChar green; uChar blue; - } rgb; + } RGB; typedef struct { - rgb color[16]; + RGB color[16]; } ColorMap; enum ac_mode @@ -117,9 +117,9 @@ class FSystemTest : public finalcut::FSystem int getpwuid_r (uid_t, struct passwd*, char* , size_t, struct passwd** ) override; char* realpath (const char*, char*) override; - rgb& getRGB (std::size_t); + RGB& getRGB (std::size_t); console_font_op& getConsoleFont(); - shiftstate& getShiftState(); + ShiftState& getShiftState(); std::string& getCharacters(); private: @@ -129,9 +129,9 @@ class FSystemTest : public finalcut::FSystem // Data members std::string characters; - static shiftstate shift_state; - static rgb terminal_color[16]; - static rgb defaultColor[16]; + static ShiftState shift_state; + static RGB terminal_color[16]; + static RGB defaultColor[16]; static struct console_font_op terminal_font; static unimapdesc terminal_unicode_map; static struct fb_var_screeninfo fb_terminal_info; @@ -948,9 +948,9 @@ struct unipair FSystemTest::unicode_cp437_pairs[] = {0x266c, 0x0e} }; -FSystemTest::rgb FSystemTest::terminal_color[16] { }; +FSystemTest::RGB FSystemTest::terminal_color[16] { }; -FSystemTest::rgb FSystemTest::defaultColor[16] +FSystemTest::RGB FSystemTest::defaultColor[16] { {0x00, 0x00, 0x00}, {0xaa, 0x00, 0x00}, {0x00, 0xaa, 0x00}, {0xaa, 0x55, 0x00}, @@ -965,7 +965,7 @@ FSystemTest::rgb FSystemTest::defaultColor[16] // static class attributes //---------------------------------------------------------------------- -FSystemTest::shiftstate FSystemTest::shift_state{}; +FSystemTest::ShiftState FSystemTest::shift_state{}; struct console_font_op FSystemTest::terminal_font{}; unimapdesc FSystemTest::terminal_unicode_map{}; struct fb_var_screeninfo FSystemTest::fb_terminal_info{}; @@ -1368,7 +1368,7 @@ char* FSystemTest::realpath (const char*, char*) } //---------------------------------------------------------------------- -FSystemTest::rgb& FSystemTest::getRGB (std::size_t i) +FSystemTest::RGB& FSystemTest::getRGB (std::size_t i) { if ( i < 16 ) return terminal_color[i]; @@ -1383,7 +1383,7 @@ console_font_op& FSystemTest::getConsoleFont() } //---------------------------------------------------------------------- -FSystemTest::shiftstate& FSystemTest::getShiftState() +FSystemTest::ShiftState& FSystemTest::getShiftState() { return shift_state; } @@ -1446,7 +1446,7 @@ void FSystemTest::initVScreenInfo() void FSystemTest::initFScreenInfo() { char id[16] { "VESA VGA" }; - std::strncpy (fb_terminal_fix_info.id, id, sizeof(id)); + std::strncpy (fb_terminal_fix_info.id, id, sizeof(fb_terminal_fix_info.id)); fb_terminal_fix_info.smem_start = 0xf9000000; fb_terminal_fix_info.smem_len = 0x00500000; fb_terminal_fix_info.type = 0; @@ -1894,7 +1894,7 @@ void FTermLinuxTest::linuxColorPaletteTest() CPPUNIT_ASSERT ( linux.resetColorMap() == true ); CPPUNIT_ASSERT ( linux.saveColorMap() == true ); FColor index = finalcut::FOptiAttr::vga2ansi(finalcut::fc::Black); - test::FSystemTest::rgb& RGB0 = fsystest->getRGB(index); + test::FSystemTest::RGB& RGB0 = fsystest->getRGB(index); CPPUNIT_ASSERT ( RGB0.red == 0x00 ); CPPUNIT_ASSERT ( RGB0.green == 0x00 ); CPPUNIT_ASSERT ( RGB0.blue == 0x00 ); @@ -1904,7 +1904,7 @@ void FTermLinuxTest::linuxColorPaletteTest() CPPUNIT_ASSERT ( RGB0.blue == 0x03 ); index = finalcut::FOptiAttr::vga2ansi(finalcut::fc::Blue); - test::FSystemTest::rgb& RGB1 = fsystest->getRGB(index); + test::FSystemTest::RGB& RGB1 = fsystest->getRGB(index); CPPUNIT_ASSERT ( RGB1.red == 0x00 ); CPPUNIT_ASSERT ( RGB1.green == 0x00 ); CPPUNIT_ASSERT ( RGB1.blue == 0xaa ); @@ -1914,7 +1914,7 @@ void FTermLinuxTest::linuxColorPaletteTest() CPPUNIT_ASSERT ( RGB1.blue == 0x06 ); index = finalcut::FOptiAttr::vga2ansi(finalcut::fc::Green); - test::FSystemTest::rgb& RGB2 = fsystest->getRGB(index); + test::FSystemTest::RGB& RGB2 = fsystest->getRGB(index); CPPUNIT_ASSERT ( RGB2.red == 0x00 ); CPPUNIT_ASSERT ( RGB2.green == 0xaa ); CPPUNIT_ASSERT ( RGB2.blue == 0x00 ); @@ -1924,7 +1924,7 @@ void FTermLinuxTest::linuxColorPaletteTest() CPPUNIT_ASSERT ( RGB2.blue == 0x09 ); index = finalcut::FOptiAttr::vga2ansi(finalcut::fc::Cyan); - test::FSystemTest::rgb& RGB3 = fsystest->getRGB(index); + test::FSystemTest::RGB& RGB3 = fsystest->getRGB(index); CPPUNIT_ASSERT ( RGB3.red == 0x00 ); CPPUNIT_ASSERT ( RGB3.green == 0xaa ); CPPUNIT_ASSERT ( RGB3.blue == 0xaa ); @@ -1934,7 +1934,7 @@ void FTermLinuxTest::linuxColorPaletteTest() CPPUNIT_ASSERT ( RGB3.blue == 0x0c ); index = finalcut::FOptiAttr::vga2ansi(finalcut::fc::Red); - test::FSystemTest::rgb& RGB4 = fsystest->getRGB(index); + test::FSystemTest::RGB& RGB4 = fsystest->getRGB(index); CPPUNIT_ASSERT ( RGB4.red == 0xaa ); CPPUNIT_ASSERT ( RGB4.green == 0x00 ); CPPUNIT_ASSERT ( RGB4.blue == 0x00 ); @@ -1944,7 +1944,7 @@ void FTermLinuxTest::linuxColorPaletteTest() CPPUNIT_ASSERT ( RGB4.blue == 0x0f ); index = finalcut::FOptiAttr::vga2ansi(finalcut::fc::Magenta); - test::FSystemTest::rgb& RGB5 = fsystest->getRGB(index); + test::FSystemTest::RGB& RGB5 = fsystest->getRGB(index); CPPUNIT_ASSERT ( RGB5.red == 0xaa ); CPPUNIT_ASSERT ( RGB5.green == 0x00 ); CPPUNIT_ASSERT ( RGB5.blue == 0xaa ); @@ -1954,7 +1954,7 @@ void FTermLinuxTest::linuxColorPaletteTest() CPPUNIT_ASSERT ( RGB5.blue == 0x12 ); index = finalcut::FOptiAttr::vga2ansi(finalcut::fc::Brown); - test::FSystemTest::rgb& RGB6 = fsystest->getRGB(index); + test::FSystemTest::RGB& RGB6 = fsystest->getRGB(index); CPPUNIT_ASSERT ( RGB6.red == 0xaa ); CPPUNIT_ASSERT ( RGB6.green == 0x55 ); CPPUNIT_ASSERT ( RGB6.blue == 0x00 ); @@ -1964,7 +1964,7 @@ void FTermLinuxTest::linuxColorPaletteTest() CPPUNIT_ASSERT ( RGB6.blue == 0x15 ); index = finalcut::FOptiAttr::vga2ansi(finalcut::fc::LightGray); - test::FSystemTest::rgb& RGB7 = fsystest->getRGB(index); + test::FSystemTest::RGB& RGB7 = fsystest->getRGB(index); CPPUNIT_ASSERT ( RGB7.red == 0xaa ); CPPUNIT_ASSERT ( RGB7.green == 0xaa ); CPPUNIT_ASSERT ( RGB7.blue == 0xaa ); @@ -1974,7 +1974,7 @@ void FTermLinuxTest::linuxColorPaletteTest() CPPUNIT_ASSERT ( RGB7.blue == 0x18 ); index = finalcut::FOptiAttr::vga2ansi(finalcut::fc::DarkGray); - test::FSystemTest::rgb& RGB8 = fsystest->getRGB(index); + test::FSystemTest::RGB& RGB8 = fsystest->getRGB(index); CPPUNIT_ASSERT ( RGB8.red == 0x55 ); CPPUNIT_ASSERT ( RGB8.green == 0x55 ); CPPUNIT_ASSERT ( RGB8.blue == 0x55 ); @@ -1984,7 +1984,7 @@ void FTermLinuxTest::linuxColorPaletteTest() CPPUNIT_ASSERT ( RGB8.blue == 0x21 ); index = finalcut::FOptiAttr::vga2ansi(finalcut::fc::LightBlue); - test::FSystemTest::rgb& RGB9 = fsystest->getRGB(index); + test::FSystemTest::RGB& RGB9 = fsystest->getRGB(index); CPPUNIT_ASSERT ( RGB9.red == 0x55 ); CPPUNIT_ASSERT ( RGB9.green == 0x55 ); CPPUNIT_ASSERT ( RGB9.blue == 0xff ); @@ -1994,7 +1994,7 @@ void FTermLinuxTest::linuxColorPaletteTest() CPPUNIT_ASSERT ( RGB9.blue == 0x24 ); index = finalcut::FOptiAttr::vga2ansi(finalcut::fc::LightGreen); - test::FSystemTest::rgb& RGB10 = fsystest->getRGB(index); + test::FSystemTest::RGB& RGB10 = fsystest->getRGB(index); CPPUNIT_ASSERT ( RGB10.red == 0x55 ); CPPUNIT_ASSERT ( RGB10.green == 0xff ); CPPUNIT_ASSERT ( RGB10.blue == 0x55 ); @@ -2004,7 +2004,7 @@ void FTermLinuxTest::linuxColorPaletteTest() CPPUNIT_ASSERT ( RGB10.blue == 0x27 ); index = finalcut::FOptiAttr::vga2ansi(finalcut::fc::LightCyan); - test::FSystemTest::rgb& RGB11 = fsystest->getRGB(index); + test::FSystemTest::RGB& RGB11 = fsystest->getRGB(index); CPPUNIT_ASSERT ( RGB11.red == 0x55 ); CPPUNIT_ASSERT ( RGB11.green == 0xff ); CPPUNIT_ASSERT ( RGB11.blue == 0xff ); @@ -2014,7 +2014,7 @@ void FTermLinuxTest::linuxColorPaletteTest() CPPUNIT_ASSERT ( RGB11.blue == 0x30 ); index = finalcut::FOptiAttr::vga2ansi(finalcut::fc::LightRed); - test::FSystemTest::rgb& RGB12 = fsystest->getRGB(index); + test::FSystemTest::RGB& RGB12 = fsystest->getRGB(index); CPPUNIT_ASSERT ( RGB12.red == 0xff ); CPPUNIT_ASSERT ( RGB12.green == 0x55 ); CPPUNIT_ASSERT ( RGB12.blue == 0x55 ); @@ -2024,7 +2024,7 @@ void FTermLinuxTest::linuxColorPaletteTest() CPPUNIT_ASSERT ( RGB12.blue == 0x33 ); index = finalcut::FOptiAttr::vga2ansi(finalcut::fc::LightMagenta); - test::FSystemTest::rgb& RGB13 = fsystest->getRGB(index); + test::FSystemTest::RGB& RGB13 = fsystest->getRGB(index); CPPUNIT_ASSERT ( RGB13.red == 0xff ); CPPUNIT_ASSERT ( RGB13.green == 0x55 ); CPPUNIT_ASSERT ( RGB13.blue == 0xff ); @@ -2034,7 +2034,7 @@ void FTermLinuxTest::linuxColorPaletteTest() CPPUNIT_ASSERT ( RGB13.blue == 0x36 ); index = finalcut::FOptiAttr::vga2ansi(finalcut::fc::Yellow); - test::FSystemTest::rgb& RGB14 = fsystest->getRGB(index); + test::FSystemTest::RGB& RGB14 = fsystest->getRGB(index); CPPUNIT_ASSERT ( RGB14.red == 0xff ); CPPUNIT_ASSERT ( RGB14.green == 0xff ); CPPUNIT_ASSERT ( RGB14.blue == 0x55 ); @@ -2044,7 +2044,7 @@ void FTermLinuxTest::linuxColorPaletteTest() CPPUNIT_ASSERT ( RGB14.blue == 0x39 ); index = finalcut::FOptiAttr::vga2ansi(finalcut::fc::White); - test::FSystemTest::rgb& RGB15 = fsystest->getRGB(index); + test::FSystemTest::RGB& RGB15 = fsystest->getRGB(index); CPPUNIT_ASSERT ( RGB15.red == 0xff ); CPPUNIT_ASSERT ( RGB15.green == 0xff ); CPPUNIT_ASSERT ( RGB15.blue == 0xff ); @@ -2253,7 +2253,7 @@ void FTermLinuxTest::modifierKeyTest() finalcut::FTermLinux linux{}; finalcut::FSystem* fsys(new test::FSystemTest()); test::FSystemTest* fsystest = static_cast(fsys); - test::FSystemTest::shiftstate& mod_key = fsystest->getShiftState(); + test::FSystemTest::ShiftState& mod_key = fsystest->getShiftState(); // Up key keycode = finalcut::fc::Fkey_up;