annotate src/gui_haiku.cc @ 32669:448aef880252

normalize line endings
author Christian Brabandt <cb@256bit.org>
date Mon, 26 Jun 2023 09:54:34 +0200
parents c0b3e3c7786c
children 695b50472e85
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
32669
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1 /* vi:set ts=8 sts=4 sw=4:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4 * BeBox GUI support Copyright 1998 by Olaf Seibert.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5 * All Rights Reserved.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
6 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
7 * Do ":help uganda" in Vim to read copying and usage conditions.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
8 * Do ":help credits" in Vim to see a list of people who contributed.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
9 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
10 * Based on "GUI support for the Buzzword Enhanced Operating System."
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
11 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
12 * Ported to R4 by Richard Offer <richard@whitequeen.com> Jul 99
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
13 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
14 * Haiku support by Siarzhuk Zharski <imker@gmx.li> Apr-Mai 2009
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
15 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
16 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
17
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
18 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
19 * Structure of the Haiku GUI code:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
20 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
21 * There are 3 threads.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
22 * 1. The initial thread. In gui_mch_prepare() this gets to run the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
23 * BApplication message loop. But before it starts doing that,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
24 * it creates thread 2
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
25 * 2. The main() thread. This thread is created in gui_mch_prepare()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
26 * and its purpose in life is to call main(argc, argv) again.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
27 * This thread is doing the bulk of the work.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
28 * 3. Sooner or later, a window is opened by the main() thread. This
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
29 * causes a second message loop to be created: the window thread.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
30 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
31 * == alternatively ===
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
32 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
33 * #if RUN_BAPPLICATION_IN_NEW_THREAD...
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
34 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
35 * 1. The initial thread. In gui_mch_prepare() this gets to spawn
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
36 * thread 2. After doing that, it returns to main() to do the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
37 * bulk of the work, being the main() thread.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
38 * 2. Runs the BApplication.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
39 * 3. The window thread, just like in the first case.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
40 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
41 * This second alternative is cleaner from Vim's viewpoint. However,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
42 * the BeBook seems to assume everywhere that the BApplication *must*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
43 * run in the initial thread. So perhaps doing otherwise is very wrong.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
44 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
45 * However, from a B_SINGLE_LAUNCH viewpoint, the first is better.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
46 * If Vim is marked "Single Launch" in its application resources,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
47 * and a file is dropped on the Vim icon, and another Vim is already
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
48 * running, the file is passed on to the earlier Vim. This happens
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
49 * in BApplication::Run(). So we want Vim to terminate if
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
50 * BApplication::Run() terminates. (See the BeBook, on BApplication.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
51 * However, it seems that the second copy of Vim isn't even started
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
52 * in this case... which is for the better since I wouldn't know how
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
53 * to detect this case.)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
54 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
55 * Communication between these threads occurs mostly by translating
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
56 * BMessages that come in and posting an appropriate translation on
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
57 * the VDCMP (Vim Direct Communication Message Port). Therefore the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
58 * actions required for keypresses and window resizes, etc, are mostly
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
59 * performed in the main() thread.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
60 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
61 * A notable exception to this is the Draw() event. The redrawing of
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
62 * the window contents is performed asynchronously from the window
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
63 * thread. To make this work correctly, a locking protocol is used when
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
64 * any thread is accessing the essential variables that are used by
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
65 * the window thread.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
66 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
67 * This locking protocol consists of locking Vim's window. This is both
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
68 * convenient and necessary.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
69 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
70
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
71 extern "C" {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
72
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
73 #include <assert.h>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
74 #include <float.h>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
75 #include <syslog.h>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
76
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
77 #include "vim.h"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
78 #include "version.h"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
79
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
80 } // extern "C"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
81
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
82 // ---------------- start of header part ----------------
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
83
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
84 //#include <Alert.h>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
85 #include <Application.h>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
86 #include <Beep.h>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
87 #include <Bitmap.h>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
88 #include <Box.h>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
89 #include <Button.h>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
90 #include <Clipboard.h>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
91 #include <Debug.h>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
92 //#include <Directory.h>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
93 //#include <Entry.h>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
94 #include <File.h>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
95 #include <FilePanel.h>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
96 #include <FindDirectory.h>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
97 //#include <Font.h>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
98 #include <IconUtils.h>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
99 #include <Input.h>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
100 #include <ListView.h>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
101 #include <MenuBar.h>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
102 #include <MenuItem.h>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
103 //#include <MessageQueue.h>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
104 //#include <OS.h>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
105 #include <Path.h>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
106 #include <PictureButton.h>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
107 #include <PopUpMenu.h>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
108 //#include <Region.h>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
109 #include <Resources.h>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
110 //#include <Roster.h>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
111 #include <Screen.h>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
112 #include <ScrollBar.h>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
113 #include <ScrollView.h>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
114 #include <String.h>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
115 #include <StringView.h>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
116 //#include <SupportDefs.h>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
117 #include <TabView.h>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
118 #include <TextControl.h>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
119 #include <TextView.h>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
120 #include <TranslationUtils.h>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
121 #include <TranslatorFormats.h>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
122 #include <View.h>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
123 #include <Window.h>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
124
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
125 class VimApp;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
126 class VimFormView;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
127 class VimTextAreaView;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
128 class VimWindow;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
129 class VimToolbar;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
130 class VimTabLine;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
131
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
132 extern key_map *keyMap;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
133 extern char *keyMapChars;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
134
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
135 extern int main(int argc, char **argv);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
136
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
137 #ifndef B_MAX_PORT_COUNT
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
138 #define B_MAX_PORT_COUNT 255
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
139 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
140
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
141 // VimApp seems comparable to the X "vimShell"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
142 class VimApp: public BApplication
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
143 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
144 typedef BApplication Inherited;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
145 public:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
146 VimApp(const char *appsig);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
147 ~VimApp();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
148
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
149 // callbacks:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
150 #if 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
151 virtual void DispatchMessage(BMessage *m, BHandler *h)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
152 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
153 m->PrintToStream();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
154 Inherited::DispatchMessage(m, h);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
155 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
156 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
157 virtual void ReadyToRun();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
158 virtual void ArgvReceived(int32 argc, char **argv);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
159 virtual void RefsReceived(BMessage *m);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
160 virtual bool QuitRequested();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
161 virtual void MessageReceived(BMessage *m);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
162
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
163 static void SendRefs(BMessage *m, bool changedir);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
164
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
165 sem_id fFilePanelSem;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
166 BFilePanel* fFilePanel;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
167 BPath fBrowsedPath;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
168 private:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
169 };
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
170
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
171 class VimWindow: public BWindow
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
172 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
173 typedef BWindow Inherited;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
174 public:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
175 VimWindow();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
176 ~VimWindow();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
177
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
178 // virtual void DispatchMessage(BMessage *m, BHandler *h);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
179 virtual void WindowActivated(bool active);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
180 virtual bool QuitRequested();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
181
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
182 VimFormView *formView;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
183
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
184 private:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
185 void init();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
186
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
187 };
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
188
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
189 class VimFormView: public BView
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
190 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
191 typedef BView Inherited;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
192 public:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
193 VimFormView(BRect frame);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
194 ~VimFormView();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
195
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
196 // callbacks:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
197 virtual void AllAttached();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
198 virtual void FrameResized(float new_width, float new_height);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
199
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
200 #define MENUBAR_MARGIN 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
201 float MenuHeight() const
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
202 { return menuBar ? menuBar->Frame().Height() + MENUBAR_MARGIN: 0; }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
203 BMenuBar *MenuBar() const
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
204 { return menuBar; }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
205
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
206 private:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
207 void init(BRect);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
208
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
209 BMenuBar *menuBar;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
210 VimTextAreaView *textArea;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
211
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
212 #ifdef FEAT_TOOLBAR
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
213 public:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
214 float ToolbarHeight() const;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
215 VimToolbar *ToolBar() const
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
216 { return toolBar; }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
217 private:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
218 VimToolbar *toolBar;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
219 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
220
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
221 #ifdef FEAT_GUI_TABLINE
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
222 public:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
223 VimTabLine *TabLine() const { return tabLine; }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
224 bool IsShowingTabLine() const { return showingTabLine; }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
225 void SetShowingTabLine(bool showing) { showingTabLine = showing; }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
226 float TablineHeight() const;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
227 private:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
228 VimTabLine *tabLine;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
229 int showingTabLine;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
230 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
231 };
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
232
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
233 class VimTextAreaView: public BView
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
234 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
235 typedef BView Inherited;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
236 public:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
237 VimTextAreaView(BRect frame);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
238 ~VimTextAreaView();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
239
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
240 // callbacks:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
241 virtual void Draw(BRect updateRect);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
242 virtual void KeyDown(const char *bytes, int32 numBytes);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
243 virtual void MouseDown(BPoint point);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
244 virtual void MouseUp(BPoint point);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
245 virtual void MouseMoved(BPoint point, uint32 transit, const BMessage *message);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
246 virtual void MessageReceived(BMessage *m);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
247
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
248 // own functions:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
249 int mchInitFont(char_u *name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
250 void mchDrawString(int row, int col, char_u *s, int len, int flags);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
251 void mchClearBlock(int row1, int col1, int row2, int col2);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
252 void mchClearAll();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
253 void mchDeleteLines(int row, int num_lines);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
254 void mchInsertLines(int row, int num_lines);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
255
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
256 static void guiSendMouseEvent(int button, int x, int y, int repeated_click, int_u modifiers);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
257 static void guiMouseMoved(int x, int y);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
258 static void guiBlankMouse(bool should_hide);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
259 static int_u mouseModifiersToVim(int32 beModifiers);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
260
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
261 int32 mouseDragEventCount;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
262
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
263 #ifdef FEAT_MBYTE_IME
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
264 void DrawIMString(void);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
265 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
266
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
267 private:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
268 void init(BRect);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
269
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
270 int_u vimMouseButton;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
271 int_u vimMouseModifiers;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
272
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
273 #ifdef FEAT_MBYTE_IME
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
274 struct {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
275 BMessenger* messenger;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
276 BMessage* message;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
277 BPoint location;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
278 int row;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
279 int col;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
280 int count;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
281 } IMData;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
282 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
283 };
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
284
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
285 class VimScrollBar: public BScrollBar
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
286 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
287 typedef BScrollBar Inherited;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
288 public:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
289 VimScrollBar(scrollbar_T *gsb, orientation posture);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
290 ~VimScrollBar();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
291
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
292 virtual void ValueChanged(float newValue);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
293 virtual void MouseUp(BPoint where);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
294 void SetValue(float newval);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
295 scrollbar_T *getGsb()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
296 { return gsb; }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
297
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
298 int32 scrollEventCount;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
299
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
300 private:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
301 scrollbar_T *gsb;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
302 float ignoreValue;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
303 };
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
304
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
305
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
306 #ifdef FEAT_TOOLBAR
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
307
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
308 class VimToolbar : public BBox
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
309 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
310 static BBitmap *normalButtonsBitmap;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
311 static BBitmap *grayedButtonsBitmap;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
312
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
313 BBitmap *LoadVimBitmap(const char* fileName);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
314 bool GetPictureFromBitmap(BPicture *pictureTo, int32 index, BBitmap *bitmapFrom, bool pressed);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
315 bool ModifyBitmapToGrayed(BBitmap *bitmap);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
316
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
317 BList fButtonsList;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
318 void InvalidateLayout();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
319
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
320 public:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
321 VimToolbar(BRect frame, const char * name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
322 ~VimToolbar();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
323
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
324 bool PrepareButtonBitmaps();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
325
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
326 bool AddButton(int32 index, vimmenu_T *menu);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
327 bool RemoveButton(vimmenu_T *menu);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
328 bool GrayButton(vimmenu_T *menu, int grey);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
329
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
330 float ToolbarHeight() const;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
331 virtual void AttachedToWindow();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
332 };
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
333
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
334 BBitmap *VimToolbar::normalButtonsBitmap = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
335 BBitmap *VimToolbar::grayedButtonsBitmap = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
336
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
337 const float ToolbarMargin = 3.;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
338 const float ButtonMargin = 3.;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
339
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
340 #endif //FEAT_TOOLBAR
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
341
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
342 #ifdef FEAT_GUI_TABLINE
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
343
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
344 class VimTabLine : public BTabView
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
345 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
346 public:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
347 class VimTab : public BTab {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
348 public:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
349 VimTab() : BTab(new BView(BRect(), "-Empty-", 0, 0)) {}
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
350
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
351 virtual void Select(BView* owner);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
352 };
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
353
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
354 VimTabLine(BRect r) : BTabView(r, "vimTabLine", B_WIDTH_FROM_LABEL,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
355 B_FOLLOW_LEFT | B_FOLLOW_TOP | B_FOLLOW_RIGHT, B_WILL_DRAW | B_FRAME_EVENTS) {}
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
356
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
357 float TablineHeight() const;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
358 virtual void MouseDown(BPoint point);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
359 };
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
360
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
361 #endif //FEAT_GUI_TABLINE
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
362
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
363
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
364 // For caching the fonts that are used;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
365 // Vim seems rather sloppy in this regard.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
366 class VimFont: public BFont
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
367 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
368 typedef BFont Inherited;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
369 public:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
370 VimFont();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
371 VimFont(const VimFont *rhs);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
372 VimFont(const BFont *rhs);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
373 VimFont(const VimFont &rhs);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
374 ~VimFont();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
375
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
376 VimFont *next;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
377 int refcount;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
378 char_u *name;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
379
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
380 private:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
381 void init();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
382 };
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
383
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
384 #if defined(FEAT_GUI_DIALOG)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
385
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
386 class VimDialog : public BWindow
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
387 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
388 typedef BWindow Inherited;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
389
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
390 BButton* _CreateButton(int32 which, const char* label);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
391
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
392 public:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
393
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
394 class View : public BView {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
395 typedef BView Inherited;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
396
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
397 public:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
398 View(BRect frame);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
399 ~View();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
400
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
401 virtual void Draw(BRect updateRect);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
402 void InitIcon(int32 type);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
403
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
404 private:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
405 BBitmap* fIconBitmap;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
406 };
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
407
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
408 VimDialog(int type, const char *title, const char *message,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
409 const char *buttons, int dfltbutton, const char *textfield,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
410 int ex_cmd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
411 ~VimDialog();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
412
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
413 int Go();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
414
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
415 virtual void MessageReceived(BMessage *msg);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
416
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
417 private:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
418 sem_id fDialogSem;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
419 int fDialogValue;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
420 BList fButtonsList;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
421 BTextView* fMessageView;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
422 BTextControl* fInputControl;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
423 const char* fInputValue;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
424 };
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
425
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
426 class VimSelectFontDialog : public BWindow
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
427 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
428 typedef BWindow Inherited;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
429
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
430 void _CleanList(BListView* list);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
431 void _UpdateFontStyles();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
432 void _UpdateSizeInputPreview();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
433 void _UpdateFontPreview();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
434 bool _UpdateFromListItem(BListView* list, char* text, int textSize);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
435 public:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
436
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
437 VimSelectFontDialog(font_family* family, font_style* style, float* size);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
438 ~VimSelectFontDialog();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
439
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
440 bool Go();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
441
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
442 virtual void MessageReceived(BMessage *msg);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
443
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
444 private:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
445 status_t fStatus;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
446 sem_id fDialogSem;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
447 bool fDialogValue;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
448 font_family* fFamily;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
449 font_style* fStyle;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
450 float* fSize;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
451 font_family fFontFamily;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
452 font_style fFontStyle;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
453 float fFontSize;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
454 BStringView* fPreview;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
455 BListView* fFamiliesList;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
456 BListView* fStylesList;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
457 BListView* fSizesList;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
458 BTextControl* fSizesInput;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
459 };
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
460
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
461 #endif // FEAT_GUI_DIALOG
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
462
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
463 // ---------------- end of GUI classes ----------------
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
464
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
465 struct MainArgs {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
466 int argc;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
467 char **argv;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
468 };
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
469
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
470 // These messages are copied through the VDCMP.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
471 // Therefore they ought not to have anything fancy.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
472 // They must be of POD type (Plain Old Data)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
473 // as the C++ standard calls them.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
474
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
475 #define KEY_MSG_BUFSIZ 7
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
476 #if KEY_MSG_BUFSIZ < MAX_KEY_CODE_LEN
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
477 #error Increase KEY_MSG_BUFSIZ!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
478 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
479
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
480 struct VimKeyMsg {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
481 char_u length;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
482 char_u chars[KEY_MSG_BUFSIZ]; // contains Vim encoding
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
483 bool csi_escape;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
484 };
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
485
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
486 struct VimResizeMsg {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
487 int width;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
488 int height;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
489 };
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
490
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
491 struct VimScrollBarMsg {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
492 VimScrollBar *sb;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
493 long value;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
494 int stillDragging;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
495 };
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
496
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
497 struct VimMenuMsg {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
498 vimmenu_T *guiMenu;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
499 };
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
500
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
501 struct VimMouseMsg {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
502 int button;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
503 int x;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
504 int y;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
505 int repeated_click;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
506 int_u modifiers;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
507 };
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
508
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
509 struct VimMouseMovedMsg {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
510 int x;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
511 int y;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
512 };
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
513
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
514 struct VimFocusMsg {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
515 bool active;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
516 };
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
517
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
518 struct VimRefsMsg {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
519 BMessage *message;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
520 bool changedir;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
521 };
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
522
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
523 struct VimTablineMsg {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
524 int index;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
525 };
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
526
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
527 struct VimTablineMenuMsg {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
528 int index;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
529 int event;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
530 };
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
531
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
532 struct VimMsg {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
533 enum VimMsgType {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
534 Key, Resize, ScrollBar, Menu, Mouse, MouseMoved, Focus, Refs, Tabline, TablineMenu
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
535 };
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
536
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
537 union {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
538 struct VimKeyMsg Key;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
539 struct VimResizeMsg NewSize;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
540 struct VimScrollBarMsg Scroll;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
541 struct VimMenuMsg Menu;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
542 struct VimMouseMsg Mouse;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
543 struct VimMouseMovedMsg MouseMoved;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
544 struct VimFocusMsg Focus;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
545 struct VimRefsMsg Refs;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
546 struct VimTablineMsg Tabline;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
547 struct VimTablineMenuMsg TablineMenu;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
548 } u;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
549 };
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
550
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
551 #define RGB(r, g, b) ((char_u)(r) << 16 | (char_u)(g) << 8 | (char_u)(b) << 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
552 #define GUI_TO_RGB(g) { (char_u)((g) >> 16), (char_u)((g) >> 8), (char_u)((g) >> 0), 255 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
553
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
554 // ---------------- end of header part ----------------
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
555
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
556 static struct specialkey
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
557 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
558 uint16 BeKeys;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
559 #define KEY(a,b) ((a)<<8|(b))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
560 #define K(a) KEY(0,a) // for ASCII codes
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
561 #define F(b) KEY(1,b) // for scancodes
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
562 char_u vim_code0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
563 char_u vim_code1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
564 } special_keys[] =
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
565 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
566 {K(B_UP_ARROW), 'k', 'u'},
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
567 {K(B_DOWN_ARROW), 'k', 'd'},
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
568 {K(B_LEFT_ARROW), 'k', 'l'},
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
569 {K(B_RIGHT_ARROW), 'k', 'r'},
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
570 {K(B_BACKSPACE), 'k', 'b'},
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
571 {K(B_INSERT), 'k', 'I'},
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
572 {K(B_DELETE), 'k', 'D'},
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
573 {K(B_HOME), 'k', 'h'},
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
574 {K(B_END), '@', '7'},
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
575 {K(B_PAGE_UP), 'k', 'P'}, // XK_Prior
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
576 {K(B_PAGE_DOWN), 'k', 'N'}, // XK_Next,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
577
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
578 #define FIRST_FUNCTION_KEY 11
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
579 {F(B_F1_KEY), 'k', '1'},
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
580 {F(B_F2_KEY), 'k', '2'},
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
581 {F(B_F3_KEY), 'k', '3'},
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
582 {F(B_F4_KEY), 'k', '4'},
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
583 {F(B_F5_KEY), 'k', '5'},
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
584 {F(B_F6_KEY), 'k', '6'},
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
585 {F(B_F7_KEY), 'k', '7'},
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
586 {F(B_F8_KEY), 'k', '8'},
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
587 {F(B_F9_KEY), 'k', '9'},
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
588 {F(B_F10_KEY), 'k', ';'},
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
589
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
590 {F(B_F11_KEY), 'F', '1'},
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
591 {F(B_F12_KEY), 'F', '2'},
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
592 // {XK_F13, 'F', '3'}, // would be print screen
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
593 // sysreq
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
594 {F(0x0F), 'F', '4'}, // scroll lock
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
595 {F(0x10), 'F', '5'}, // pause/break
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
596 // {XK_F16, 'F', '6'},
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
597 // {XK_F17, 'F', '7'},
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
598 // {XK_F18, 'F', '8'},
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
599 // {XK_F19, 'F', '9'},
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
600 // {XK_F20, 'F', 'A'},
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
601 // {XK_F21, 'F', 'B'},
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
602 // {XK_F22, 'F', 'C'},
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
603 // {XK_F23, 'F', 'D'},
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
604 // {XK_F24, 'F', 'E'},
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
605 // {XK_F25, 'F', 'F'},
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
606 // {XK_F26, 'F', 'G'},
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
607 // {XK_F27, 'F', 'H'},
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
608 // {XK_F28, 'F', 'I'},
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
609 // {XK_F29, 'F', 'J'},
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
610 // {XK_F30, 'F', 'K'},
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
611 // {XK_F31, 'F', 'L'},
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
612 // {XK_F32, 'F', 'M'},
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
613 // {XK_F33, 'F', 'N'},
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
614 // {XK_F34, 'F', 'O'},
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
615 // {XK_F35, 'F', 'P'}, // keysymdef.h defines up to F35
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
616
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
617 // {XK_Help, '%', '1'}, // XK_Help
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
618 {F(B_PRINT_KEY), '%', '9'},
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
619
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
620 #if 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
621 // Keypad keys:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
622 {F(0x48), 'k', 'l'}, // XK_KP_Left
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
623 {F(0x4A), 'k', 'r'}, // XK_KP_Right
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
624 {F(0x38), 'k', 'u'}, // XK_KP_Up
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
625 {F(0x59), 'k', 'd'}, // XK_KP_Down
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
626 {F(0x64), 'k', 'I'}, // XK_KP_Insert
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
627 {F(0x65), 'k', 'D'}, // XK_KP_Delete
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
628 {F(0x37), 'k', 'h'}, // XK_KP_Home
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
629 {F(0x58), '@', '7'}, // XK_KP_End
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
630 {F(0x39), 'k', 'P'}, // XK_KP_Prior
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
631 {F(0x60), 'k', 'N'}, // XK_KP_Next
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
632 {F(0x49), '&', '8'}, // XK_Undo, keypad 5
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
633 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
634
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
635 // End of list marker:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
636 {0, 0, 0}
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
637 };
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
638
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
639 #define NUM_SPECIAL_KEYS ARRAY_LENGTH(special_keys)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
640
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
641 // ---------------- VimApp ----------------
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
642
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
643 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
644 docd(BPath &path)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
645 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
646 mch_chdir((char *)path.Path());
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
647 // Do this to get the side effects of a :cd command
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
648 do_cmdline_cmd((char_u *)"cd .");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
649 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
650
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
651 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
652 drop_callback(void *cookie)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
653 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
654 // TODO here we could handle going to a specific position in the dropped
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
655 // file (see src/gui_mac.c, deleted in 8.2.1422)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
656 // Update the screen display
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
657 update_screen(UPD_NOT_VALID);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
658 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
659
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
660 // Really handle dropped files and folders.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
661 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
662 RefsReceived(BMessage *m, bool changedir)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
663 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
664 uint32 type;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
665 int32 count;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
666
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
667 m->PrintToStream();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
668 switch (m->what) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
669 case B_REFS_RECEIVED:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
670 case B_SIMPLE_DATA:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
671 m->GetInfo("refs", &type, &count);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
672 if (type != B_REF_TYPE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
673 goto bad;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
674 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
675 case B_ARGV_RECEIVED:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
676 m->GetInfo("argv", &type, &count);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
677 if (type != B_STRING_TYPE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
678 goto bad;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
679 if (changedir) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
680 char *dirname;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
681 if (m->FindString("cwd", (const char **) &dirname) == B_OK) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
682 chdir(dirname);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
683 do_cmdline_cmd((char_u *)"cd .");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
684 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
685 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
686 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
687 default:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
688 bad:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
689 /*fprintf(stderr, "bad!\n"); */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
690 delete m;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
691 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
692 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
693
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
694 #ifdef FEAT_VISUAL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
695 reset_VIsual();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
696 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
697
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
698 char_u **fnames;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
699 fnames = (char_u **) alloc(count * sizeof(char_u *));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
700 int fname_index = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
701
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
702 switch (m->what) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
703 case B_REFS_RECEIVED:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
704 case B_SIMPLE_DATA:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
705 // fprintf(stderr, "case B_REFS_RECEIVED\n");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
706 for (int i = 0; i < count; ++i)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
707 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
708 entry_ref ref;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
709 if (m->FindRef("refs", i, &ref) == B_OK) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
710 BEntry entry(&ref, false);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
711 BPath path;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
712 entry.GetPath(&path);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
713
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
714 // Change to parent directory?
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
715 if (changedir) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
716 BPath parentpath;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
717 path.GetParent(&parentpath);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
718 docd(parentpath);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
719 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
720
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
721 // Is it a directory? If so, cd into it.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
722 BDirectory bdir(&ref);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
723 if (bdir.InitCheck() == B_OK) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
724 // don't cd if we already did it
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
725 if (!changedir)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
726 docd(path);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
727 } else {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
728 mch_dirname(IObuff, IOSIZE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
729 char_u *fname = shorten_fname((char_u *)path.Path(), IObuff);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
730 if (fname == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
731 fname = (char_u *)path.Path();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
732 fnames[fname_index++] = vim_strsave(fname);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
733 // fprintf(stderr, "%s\n", fname);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
734 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
735
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
736 // Only do it for the first file/dir
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
737 changedir = false;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
738 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
739 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
740 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
741 case B_ARGV_RECEIVED:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
742 // fprintf(stderr, "case B_ARGV_RECEIVED\n");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
743 for (int i = 1; i < count; ++i)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
744 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
745 char *fname;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
746
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
747 if (m->FindString("argv", i, (const char **) &fname) == B_OK) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
748 fnames[fname_index++] = vim_strsave((char_u *)fname);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
749 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
750 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
751 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
752 default:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
753 // fprintf(stderr, "case default\n");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
754 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
755 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
756
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
757 delete m;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
758
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
759 // Handle the drop, :edit to get to the file
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
760 if (fname_index > 0) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
761 handle_drop(fname_index, fnames, FALSE, drop_callback, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
762
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
763 setcursor();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
764 out_flush();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
765 } else {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
766 vim_free(fnames);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
767 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
768 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
769
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
770 VimApp::VimApp(const char *appsig):
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
771 BApplication(appsig),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
772 fFilePanelSem(-1),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
773 fFilePanel(NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
774 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
775 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
776
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
777 VimApp::~VimApp()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
778 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
779 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
780
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
781 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
782 VimApp::ReadyToRun()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
783 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
784 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
785 * Apparently signals are inherited by the created thread -
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
786 * disable the most annoying ones.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
787 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
788 mch_signal(SIGINT, SIG_IGN);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
789 mch_signal(SIGQUIT, SIG_IGN);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
790 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
791
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
792 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
793 VimApp::ArgvReceived(int32 arg_argc, char **arg_argv)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
794 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
795 if (!IsLaunching()) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
796 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
797 * This can happen if we are set to Single or Exclusive
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
798 * Launch. Be nice and open the file(s).
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
799 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
800 if (gui.vimWindow)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
801 gui.vimWindow->Minimize(false);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
802 BMessage *m = CurrentMessage();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
803 DetachCurrentMessage();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
804 SendRefs(m, true);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
805 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
806 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
807
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
808 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
809 VimApp::RefsReceived(BMessage *m)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
810 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
811 // Horrible hack!!! XXX XXX XXX
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
812 // The real problem is that b_start_ffc is set too late for
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
813 // the initial empty buffer. As a result the window will be
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
814 // split instead of abandoned.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
815 int limit = 15;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
816 while (--limit >= 0 && (curbuf == NULL || curbuf->b_start_ffc == 0))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
817 snooze(100000); // 0.1 s
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
818 if (gui.vimWindow)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
819 gui.vimWindow->Minimize(false);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
820 DetachCurrentMessage();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
821 SendRefs(m, true);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
822 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
823
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
824 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
825 * Pass a BMessage on to the main() thread.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
826 * Caller must have detached the message.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
827 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
828 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
829 VimApp::SendRefs(BMessage *m, bool changedir)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
830 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
831 VimRefsMsg rm;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
832 rm.message = m;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
833 rm.changedir = changedir;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
834
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
835 write_port(gui.vdcmp, VimMsg::Refs, &rm, sizeof(rm));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
836 // calls ::RefsReceived
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
837 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
838
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
839 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
840 VimApp::MessageReceived(BMessage *m)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
841 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
842 switch (m->what) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
843 case 'save':
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
844 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
845 entry_ref refDirectory;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
846 m->FindRef("directory", &refDirectory);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
847 fBrowsedPath.SetTo(&refDirectory);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
848 BString strName;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
849 m->FindString("name", &strName);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
850 fBrowsedPath.Append(strName.String());
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
851 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
852 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
853 case 'open':
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
854 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
855 entry_ref ref;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
856 m->FindRef("refs", &ref);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
857 fBrowsedPath.SetTo(&ref);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
858 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
859 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
860 case B_CANCEL:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
861 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
862 BFilePanel *panel;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
863 m->FindPointer("source", (void**)&panel);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
864 if (fFilePanelSem != -1 && panel == fFilePanel)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
865 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
866 delete_sem(fFilePanelSem);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
867 fFilePanelSem = -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
868 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
869
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
870 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
871 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
872 default:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
873 Inherited::MessageReceived(m);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
874 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
875 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
876 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
877
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
878 bool
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
879 VimApp::QuitRequested()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
880 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
881 (void)Inherited::QuitRequested();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
882 return false;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
883 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
884
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
885 // ---------------- VimWindow ----------------
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
886
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
887 VimWindow::VimWindow():
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
888 BWindow(BRect(40, 40, 150, 150),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
889 "Vim",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
890 B_TITLED_WINDOW,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
891 0,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
892 B_CURRENT_WORKSPACE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
893
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
894 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
895 init();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
896 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
897
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
898 VimWindow::~VimWindow()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
899 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
900 if (formView) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
901 RemoveChild(formView);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
902 delete formView;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
903 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
904 gui.vimWindow = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
905 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
906
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
907 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
908 VimWindow::init()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
909 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
910 // Attach the VimFormView
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
911 formView = new VimFormView(Bounds());
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
912 if (formView != NULL) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
913 AddChild(formView);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
914 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
915 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
916
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
917 #if 0 // disabled in zeta patch
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
918 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
919 VimWindow::DispatchMessage(BMessage *m, BHandler *h)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
920 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
921 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
922 * Route B_MOUSE_UP messages to MouseUp(), in
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
923 * a manner that should be compatible with the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
924 * intended future system behaviour.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
925 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
926 switch (m->what) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
927 case B_MOUSE_UP:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
928 // if (!h) h = PreferredHandler();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
929 // gcc isn't happy without this extra set of braces, complains about
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
930 // jump to case label crosses init of 'class BView * v'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
931 // richard@whitequeen.com jul 99
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
932 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
933 BView *v = dynamic_cast<BView *>(h);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
934 if (v) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
935 // m->PrintToStream();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
936 BPoint where;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
937 m->FindPoint("where", &where);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
938 v->MouseUp(where);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
939 } else {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
940 Inherited::DispatchMessage(m, h);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
941 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
942 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
943 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
944 default:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
945 Inherited::DispatchMessage(m, h);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
946 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
947 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
948 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
949
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
950 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
951 VimWindow::WindowActivated(bool active)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
952 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
953 Inherited::WindowActivated(active);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
954 // the textArea gets the keyboard action
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
955 if (active && gui.vimTextArea)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
956 gui.vimTextArea->MakeFocus(true);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
957
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
958 struct VimFocusMsg fm;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
959 fm.active = active;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
960
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
961 write_port(gui.vdcmp, VimMsg::Focus, &fm, sizeof(fm));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
962 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
963
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
964 bool
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
965 VimWindow::QuitRequested()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
966 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
967 struct VimKeyMsg km;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
968 km.length = 5;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
969 memcpy((char *)km.chars, "\033:qa\r", km.length);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
970 km.csi_escape = false;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
971 write_port(gui.vdcmp, VimMsg::Key, &km, sizeof(km));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
972 return false;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
973 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
974
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
975 // ---------------- VimFormView ----------------
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
976
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
977 VimFormView::VimFormView(BRect frame):
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
978 BView(frame, "VimFormView", B_FOLLOW_ALL_SIDES,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
979 B_WILL_DRAW | B_FRAME_EVENTS),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
980 menuBar(NULL),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
981 #ifdef FEAT_TOOLBAR
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
982 toolBar(NULL),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
983 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
984 #ifdef FEAT_GUI_TABLINE
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
985 // showingTabLine(false),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
986 tabLine(NULL),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
987 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
988 textArea(NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
989 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
990 init(frame);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
991 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
992
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
993 VimFormView::~VimFormView()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
994 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
995 if (menuBar) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
996 RemoveChild(menuBar);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
997 #ifdef never
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
998 // deleting the menuBar leads to SEGV on exit
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
999 // richard@whitequeen.com Jul 99
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1000 delete menuBar;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1001 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1002 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1003
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1004 #ifdef FEAT_TOOLBAR
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1005 delete toolBar;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1006 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1007
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1008 #ifdef FEAT_GUI_TABLINE
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1009 delete tabLine;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1010 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1011
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1012 if (textArea) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1013 RemoveChild(textArea);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1014 delete textArea;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1015 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1016 gui.vimForm = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1017 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1018
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1019 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1020 VimFormView::init(BRect frame)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1021 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1022 menuBar = new BMenuBar(BRect(0,0,-MENUBAR_MARGIN,-MENUBAR_MARGIN),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1023 "VimMenuBar");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1024
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1025 AddChild(menuBar);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1026
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1027 #ifdef FEAT_TOOLBAR
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1028 toolBar = new VimToolbar(BRect(0,0,0,0), "VimToolBar");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1029 toolBar->PrepareButtonBitmaps();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1030 AddChild(toolBar);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1031 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1032
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1033 #ifdef FEAT_GUI_TABLINE
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1034 tabLine = new VimTabLine(BRect(0,0,0,0));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1035 // tabLine->PrepareButtonBitmaps();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1036 AddChild(tabLine);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1037 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1038
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1039 BRect remaining = frame;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1040 textArea = new VimTextAreaView(remaining);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1041 AddChild(textArea);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1042 // The textArea will be resized later when menus are added
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1043
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1044 gui.vimForm = this;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1045 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1046
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1047 #ifdef FEAT_TOOLBAR
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1048 float
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1049 VimFormView::ToolbarHeight() const
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1050 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1051 return toolBar ? toolBar->ToolbarHeight() : 0.;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1052 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1053 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1054
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1055 #ifdef FEAT_GUI_TABLINE
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1056 float
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1057 VimFormView::TablineHeight() const
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1058 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1059 return (tabLine && IsShowingTabLine()) ? tabLine->TablineHeight() : 0.;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1060 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1061 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1062
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1063 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1064 VimFormView::AllAttached()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1065 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1066 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1067 * Apparently signals are inherited by the created thread -
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1068 * disable the most annoying ones.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1069 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1070 mch_signal(SIGINT, SIG_IGN);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1071 mch_signal(SIGQUIT, SIG_IGN);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1072
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1073 if (menuBar && textArea) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1074 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1075 * Resize the textArea to fill the space left over by the menu.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1076 * This is somewhat futile since it will be done again once
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1077 * menus are added to the menu bar.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1078 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1079 BRect remaining = Bounds();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1080
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1081 #ifdef FEAT_MENU
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1082 remaining.top += MenuHeight();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1083 menuBar->ResizeTo(remaining.right, remaining.top);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1084 gui.menu_height = (int) MenuHeight();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1085 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1086
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1087 #ifdef FEAT_TOOLBAR
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1088 toolBar->MoveTo(remaining.left, remaining.top);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1089 toolBar->ResizeTo(remaining.right, ToolbarHeight());
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1090 remaining.top += ToolbarHeight();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1091 gui.toolbar_height = ToolbarHeight();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1092 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1093
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1094 #ifdef FEAT_GUI_TABLINE
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1095 tabLine->MoveTo(remaining.left, remaining.top);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1096 tabLine->ResizeTo(remaining.right + 1, TablineHeight());
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1097 remaining.top += TablineHeight();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1098 gui.tabline_height = TablineHeight();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1099 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1100
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1101 textArea->ResizeTo(remaining.Width(), remaining.Height());
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1102 textArea->MoveTo(remaining.left, remaining.top);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1103 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1104
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1105
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1106 Inherited::AllAttached();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1107 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1108
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1109 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1110 VimFormView::FrameResized(float new_width, float new_height)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1111 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1112 struct VimResizeMsg sm;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1113 int adjust_h, adjust_w;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1114
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1115 new_width += 1; // adjust from width to number of pixels occupied
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1116 new_height += 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1117
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1118 sm.width = (int) new_width;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1119 sm.height = (int) new_height;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1120 adjust_w = ((int)new_width - gui_get_base_width()) % gui.char_width;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1121 adjust_h = ((int)new_height - gui_get_base_height()) % gui.char_height;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1122
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1123 if (adjust_w > 0 || adjust_h > 0) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1124 sm.width -= adjust_w;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1125 sm.height -= adjust_h;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1126 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1127
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1128 write_port(gui.vdcmp, VimMsg::Resize, &sm, sizeof(sm));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1129 // calls gui_resize_shell(new_width, new_height);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1130
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1131 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1132
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1133 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1134 * The area below the vertical scrollbar is erased to the colour
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1135 * set with SetViewColor() automatically, because we had set
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1136 * B_WILL_DRAW. Resizing the window tight around the vertical
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1137 * scroll bar also helps to avoid debris.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1138 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1139 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1140
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1141 // ---------------- VimTextAreaView ----------------
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1142
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1143 VimTextAreaView::VimTextAreaView(BRect frame):
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1144 BView(frame, "VimTextAreaView", B_FOLLOW_ALL_SIDES,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1145 #ifdef FEAT_MBYTE_IME
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1146 B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE | B_INPUT_METHOD_AWARE
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1147 #else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1148 B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1149 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1150 ),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1151 mouseDragEventCount(0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1152 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1153 #ifdef FEAT_MBYTE_IME
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1154 IMData.messenger = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1155 IMData.message = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1156 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1157 init(frame);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1158 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1159
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1160 VimTextAreaView::~VimTextAreaView()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1161 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1162 gui.vimTextArea = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1163 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1164
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1165 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1166 VimTextAreaView::init(BRect frame)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1167 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1168 // set up global var for fast access
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1169 gui.vimTextArea = this;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1170
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1171 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1172 * Tell the app server not to erase the view: we will
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1173 * fill it in completely by ourselves.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1174 * (Does this really work? Even if not, it won't harm either.)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1175 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1176 SetViewColor(B_TRANSPARENT_32_BIT);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1177 #define PEN_WIDTH 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1178 SetPenSize(PEN_WIDTH);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1179 #define W_WIDTH(curwin) 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1180 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1181
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1182 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1183 VimTextAreaView::Draw(BRect updateRect)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1184 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1185 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1186 * XXX Other ports call here:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1187 * out_flush(); * make sure all output has been processed *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1188 * but we can't do that, since it involves too much information
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1189 * that is owned by other threads...
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1190 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1191
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1192 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1193 * No need to use gui.vimWindow->Lock(): we are locked already.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1194 * However, it would not hurt.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1195 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1196 rgb_color rgb = GUI_TO_RGB(gui.back_pixel);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1197 SetLowColor(rgb);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1198 FillRect(updateRect, B_SOLID_LOW);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1199 gui_redraw((int) updateRect.left, (int) updateRect.top,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1200 (int) (updateRect.Width() + PEN_WIDTH), (int) (updateRect.Height() + PEN_WIDTH));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1201
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1202 // Clear the border areas if needed
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1203 SetLowColor(rgb);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1204
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1205 if (updateRect.left < FILL_X(0)) // left border
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1206 FillRect(BRect(updateRect.left, updateRect.top,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1207 FILL_X(0)-PEN_WIDTH, updateRect.bottom), B_SOLID_LOW);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1208 if (updateRect.top < FILL_Y(0)) // top border
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1209 FillRect(BRect(updateRect.left, updateRect.top,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1210 updateRect.right, FILL_Y(0)-PEN_WIDTH), B_SOLID_LOW);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1211 if (updateRect.right >= FILL_X(Columns)) // right border
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1212 FillRect(BRect(FILL_X((int)Columns), updateRect.top,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1213 updateRect.right, updateRect.bottom), B_SOLID_LOW);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1214 if (updateRect.bottom >= FILL_Y(Rows)) // bottom border
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1215 FillRect(BRect(updateRect.left, FILL_Y((int)Rows),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1216 updateRect.right, updateRect.bottom), B_SOLID_LOW);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1217
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1218 #ifdef FEAT_MBYTE_IME
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1219 DrawIMString();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1220 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1221 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1222
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1223 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1224 VimTextAreaView::KeyDown(const char *bytes, int32 numBytes)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1225 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1226 struct VimKeyMsg km;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1227 char_u *dest = km.chars;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1228
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1229 bool canHaveVimModifiers = false;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1230
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1231 BMessage *msg = Window()->CurrentMessage();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1232 assert(msg);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1233 // msg->PrintToStream();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1234
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1235 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1236 * Convert special keys to Vim codes.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1237 * I think it is better to do it in the window thread
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1238 * so we use at least a little bit of the potential
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1239 * of our 2 CPUs. Besides, due to the fantastic mapping
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1240 * of special keys to UTF-8, we have quite some work to
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1241 * do...
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1242 * TODO: I'm not quite happy with detection of special
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1243 * keys. Perhaps I should use scan codes after all...
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1244 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1245 if (numBytes > 1) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1246 // This cannot be a special key
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1247 if (numBytes > KEY_MSG_BUFSIZ)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1248 numBytes = KEY_MSG_BUFSIZ; // should never happen... ???
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1249 km.length = numBytes;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1250 memcpy((char *)dest, bytes, numBytes);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1251 km.csi_escape = true;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1252 } else {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1253 int32 scancode = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1254 msg->FindInt32("key", &scancode);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1255
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1256 int32 beModifiers = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1257 msg->FindInt32("modifiers", &beModifiers);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1258
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1259 char_u string[3];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1260 int len = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1261 km.length = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1262
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1263 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1264 * For normal, printable ASCII characters, don't look them up
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1265 * to check if they might be a special key. They aren't.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1266 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1267 assert(B_BACKSPACE <= 0x20);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1268 assert(B_DELETE == 0x7F);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1269 if (((char_u)bytes[0] <= 0x20 || (char_u)bytes[0] == 0x7F) &&
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1270 numBytes == 1) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1271 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1272 * Due to the great nature of Be's mapping of special keys,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1273 * viz. into the range of the control characters,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1274 * we can only be sure it is *really* a special key if
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1275 * if it is special without using ctrl. So, only if ctrl is
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1276 * used, we need to check it unmodified.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1277 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1278 if (beModifiers & B_CONTROL_KEY) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1279 int index = keyMap->normal_map[scancode];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1280 int newNumBytes = keyMapChars[index];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1281 char_u *newBytes = (char_u *)&keyMapChars[index + 1];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1282
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1283 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1284 * Check if still special without the control key.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1285 * This is needed for BACKSPACE: that key does produce
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1286 * different values with modifiers (DEL).
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1287 * Otherwise we could simply have checked for equality.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1288 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1289 if (newNumBytes != 1 || (*newBytes > 0x20 &&
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1290 *newBytes != 0x7F )) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1291 goto notspecial;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1292 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1293 bytes = (char *)newBytes;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1294 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1295 canHaveVimModifiers = true;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1296
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1297 uint16 beoskey;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1298 int first, last;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1299
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1300 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1301 * If numBytes == 0 that probably always indicates a special key.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1302 * (does not happen yet)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1303 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1304 if (numBytes == 0 || bytes[0] == B_FUNCTION_KEY) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1305 beoskey = F(scancode);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1306 first = FIRST_FUNCTION_KEY;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1307 last = NUM_SPECIAL_KEYS;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1308 } else if (*bytes == '\n' && scancode == 0x47) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1309 // remap the (non-keypad) ENTER key from \n to \r.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1310 string[0] = '\r';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1311 len = 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1312 first = last = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1313 } else {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1314 beoskey = K(bytes[0]);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1315 first = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1316 last = FIRST_FUNCTION_KEY;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1317 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1318
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1319 for (int i = first; i < last; i++) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1320 if (special_keys[i].BeKeys == beoskey) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1321 string[0] = CSI;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1322 string[1] = special_keys[i].vim_code0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1323 string[2] = special_keys[i].vim_code1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1324 len = 3;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1325 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1326 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1327 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1328 notspecial:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1329 if (len == 0) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1330 string[0] = bytes[0];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1331 len = 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1332 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1333
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1334 // Special keys (and a few others) may have modifiers
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1335 #if 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1336 if (len == 3 ||
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1337 bytes[0] == B_SPACE || bytes[0] == B_TAB ||
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1338 bytes[0] == B_RETURN || bytes[0] == '\r' ||
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1339 bytes[0] == B_ESCAPE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1340 #else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1341 if (canHaveVimModifiers)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1342 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1343 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1344 int modifiers;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1345 modifiers = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1346 if (beModifiers & B_SHIFT_KEY)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1347 modifiers |= MOD_MASK_SHIFT;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1348 if (beModifiers & B_CONTROL_KEY)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1349 modifiers |= MOD_MASK_CTRL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1350 if (beModifiers & B_OPTION_KEY)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1351 modifiers |= MOD_MASK_ALT;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1352
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1353 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1354 * For some keys a shift modifier is translated into another key
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1355 * code. Do we need to handle the case where len != 1 and
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1356 * string[0] != CSI? (Not for BeOS, since len == 3 implies
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1357 * string[0] == CSI...)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1358 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1359 int key;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1360 if (string[0] == CSI && len == 3)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1361 key = TO_SPECIAL(string[1], string[2]);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1362 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1363 key = string[0];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1364 key = simplify_key(key, &modifiers);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1365 if (IS_SPECIAL(key))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1366 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1367 string[0] = CSI;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1368 string[1] = K_SECOND(key);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1369 string[2] = K_THIRD(key);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1370 len = 3;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1371 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1372 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1373 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1374 string[0] = key;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1375 len = 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1376 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1377
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1378 if (modifiers)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1379 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1380 *dest++ = CSI;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1381 *dest++ = KS_MODIFIER;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1382 *dest++ = modifiers;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1383 km.length = 3;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1384 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1385 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1386 memcpy((char *)dest, string, len);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1387 km.length += len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1388 km.csi_escape = false;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1389 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1390
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1391 write_port(gui.vdcmp, VimMsg::Key, &km, sizeof(km));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1392
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1393 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1394 * blank out the pointer if necessary
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1395 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1396 if (p_mh && !gui.pointer_hidden)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1397 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1398 guiBlankMouse(true);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1399 gui.pointer_hidden = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1400 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1401 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1402 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1403 VimTextAreaView::guiSendMouseEvent(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1404 int button,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1405 int x,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1406 int y,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1407 int repeated_click,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1408 int_u modifiers)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1409 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1410 VimMouseMsg mm;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1411
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1412 mm.button = button;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1413 mm.x = x;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1414 mm.y = y;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1415 mm.repeated_click = repeated_click;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1416 mm.modifiers = modifiers;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1417
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1418 write_port(gui.vdcmp, VimMsg::Mouse, &mm, sizeof(mm));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1419 // calls gui_send_mouse_event()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1420
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1421 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1422 * if our pointer is currently hidden, then we should show it.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1423 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1424 if (gui.pointer_hidden)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1425 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1426 guiBlankMouse(false);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1427 gui.pointer_hidden = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1428 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1429 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1430
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1431 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1432 VimTextAreaView::guiMouseMoved(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1433 int x,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1434 int y)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1435 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1436 VimMouseMovedMsg mm;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1437
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1438 mm.x = x;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1439 mm.y = y;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1440
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1441 write_port(gui.vdcmp, VimMsg::MouseMoved, &mm, sizeof(mm));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1442
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1443 if (gui.pointer_hidden)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1444 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1445 guiBlankMouse(false);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1446 gui.pointer_hidden = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1447 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1448 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1449
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1450 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1451 VimTextAreaView::guiBlankMouse(bool should_hide)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1452 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1453 if (should_hide) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1454 // gui.vimApp->HideCursor();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1455 gui.vimApp->ObscureCursor();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1456 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1457 * ObscureCursor() would even be easier, but then
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1458 * Vim's idea of mouse visibility does not necessarily
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1459 * correspond to reality.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1460 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1461 } else {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1462 // gui.vimApp->ShowCursor();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1463 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1464 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1465
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1466 int_u
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1467 VimTextAreaView::mouseModifiersToVim(int32 beModifiers)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1468 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1469 int_u vim_modifiers = 0x0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1470
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1471 if (beModifiers & B_SHIFT_KEY)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1472 vim_modifiers |= MOUSE_SHIFT;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1473 if (beModifiers & B_CONTROL_KEY)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1474 vim_modifiers |= MOUSE_CTRL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1475 if (beModifiers & B_OPTION_KEY) // Alt or Meta key
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1476 vim_modifiers |= MOUSE_ALT;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1477
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1478 return vim_modifiers;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1479 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1480
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1481 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1482 VimTextAreaView::MouseDown(BPoint point)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1483 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1484 BMessage *m = Window()->CurrentMessage();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1485 assert(m);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1486
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1487 int32 buttons = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1488 m->FindInt32("buttons", &buttons);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1489
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1490 int vimButton;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1491
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1492 if (buttons & B_PRIMARY_MOUSE_BUTTON)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1493 vimButton = MOUSE_LEFT;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1494 else if (buttons & B_SECONDARY_MOUSE_BUTTON)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1495 vimButton = MOUSE_RIGHT;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1496 else if (buttons & B_TERTIARY_MOUSE_BUTTON)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1497 vimButton = MOUSE_MIDDLE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1498 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1499 return; // Unknown button
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1500
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1501 vimMouseButton = 1; // don't care which one
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1502
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1503 // Handle multiple clicks
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1504 int32 clicks = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1505 m->FindInt32("clicks", &clicks);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1506
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1507 int32 modifiers = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1508 m->FindInt32("modifiers", &modifiers);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1509
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1510 vimMouseModifiers = mouseModifiersToVim(modifiers);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1511
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1512 guiSendMouseEvent(vimButton, point.x, point.y,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1513 clicks > 1 /* = repeated_click*/, vimMouseModifiers);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1514 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1515
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1516 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1517 VimTextAreaView::MouseUp(BPoint point)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1518 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1519 vimMouseButton = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1520
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1521 BMessage *m = Window()->CurrentMessage();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1522 assert(m);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1523 // m->PrintToStream();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1524
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1525 int32 modifiers = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1526 m->FindInt32("modifiers", &modifiers);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1527
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1528 vimMouseModifiers = mouseModifiersToVim(modifiers);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1529
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1530 guiSendMouseEvent(MOUSE_RELEASE, point.x, point.y,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1531 0 /* = repeated_click*/, vimMouseModifiers);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1532
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1533 Inherited::MouseUp(point);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1534 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1535
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1536 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1537 VimTextAreaView::MouseMoved(BPoint point, uint32 transit, const BMessage *message)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1538 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1539 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1540 * if our pointer is currently hidden, then we should show it.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1541 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1542 if (gui.pointer_hidden)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1543 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1544 guiBlankMouse(false);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1545 gui.pointer_hidden = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1546 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1547
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1548 if (!vimMouseButton) { // could also check m->"buttons"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1549 guiMouseMoved(point.x, point.y);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1550 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1551 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1552
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1553 atomic_add(&mouseDragEventCount, 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1554
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1555 // Don't care much about "transit"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1556 guiSendMouseEvent(MOUSE_DRAG, point.x, point.y, 0, vimMouseModifiers);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1557 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1558
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1559 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1560 VimTextAreaView::MessageReceived(BMessage *m)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1561 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1562 switch (m->what) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1563 case 'menu':
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1564 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1565 VimMenuMsg mm;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1566 mm.guiMenu = NULL; // in case no pointer in msg
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1567 m->FindPointer("VimMenu", (void **)&mm.guiMenu);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1568 write_port(gui.vdcmp, VimMsg::Menu, &mm, sizeof(mm));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1569 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1570 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1571 case B_MOUSE_WHEEL_CHANGED:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1572 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1573 VimScrollBar* scb = curwin->w_scrollbars[1].id;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1574 float small=0, big=0, dy=0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1575 m->FindFloat("be:wheel_delta_y", &dy);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1576 scb->GetSteps(&small, &big);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1577 scb->SetValue(scb->Value()+small*dy*3);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1578 scb->ValueChanged(scb->Value());
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1579 #if 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1580 scb = curwin->w_scrollbars[0].id;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1581 scb->GetSteps(&small, &big);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1582 scb->SetValue(scb->Value()+small*dy);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1583 scb->ValueChanged(scb->Value());
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1584 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1585 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1586 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1587 #ifdef FEAT_MBYTE_IME
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1588 case B_INPUT_METHOD_EVENT:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1589 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1590 int32 opcode;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1591 m->FindInt32("be:opcode", &opcode);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1592 switch(opcode)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1593 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1594 case B_INPUT_METHOD_STARTED:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1595 if (!IMData.messenger) delete IMData.messenger;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1596 IMData.messenger = new BMessenger();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1597 m->FindMessenger("be:reply_to", IMData.messenger);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1598 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1599 case B_INPUT_METHOD_CHANGED:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1600 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1601 BString str;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1602 bool confirmed;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1603 if (IMData.message) *(IMData.message) = *m;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1604 else IMData.message = new BMessage(*m);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1605 DrawIMString();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1606 m->FindBool("be:confirmed", &confirmed);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1607 if (confirmed)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1608 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1609 m->FindString("be:string", &str);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1610 char_u *chars = (char_u*)str.String();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1611 struct VimKeyMsg km;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1612 km.csi_escape = true;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1613 int clen;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1614 int i = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1615 while (i < str.Length())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1616 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1617 clen = utf_ptr2len(chars+i);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1618 memcpy(km.chars, chars+i, clen);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1619 km.length = clen;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1620 write_port(gui.vdcmp, VimMsg::Key, &km, sizeof(km));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1621 i += clen;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1622 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1623 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1624 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1625 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1626 case B_INPUT_METHOD_LOCATION_REQUEST:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1627 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1628 BMessage msg(B_INPUT_METHOD_EVENT);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1629 msg.AddInt32("be:opcode", B_INPUT_METHOD_LOCATION_REQUEST);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1630 msg.AddPoint("be:location_reply", IMData.location);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1631 msg.AddFloat("be:height_reply", FILL_Y(1));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1632 IMData.messenger->SendMessage(&msg);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1633 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1634 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1635 case B_INPUT_METHOD_STOPPED:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1636 delete IMData.messenger;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1637 delete IMData.message;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1638 IMData.messenger = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1639 IMData.message = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1640 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1641 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1642 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1643 // TODO: sz: break here???
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1644 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1645 default:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1646 if (m->WasDropped()) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1647 BWindow *w = Window();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1648 w->DetachCurrentMessage();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1649 w->Minimize(false);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1650 VimApp::SendRefs(m, (modifiers() & B_SHIFT_KEY) != 0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1651 } else {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1652 Inherited::MessageReceived(m);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1653 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1654 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1655 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1656 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1657
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1658 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1659 VimTextAreaView::mchInitFont(char_u *name)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1660 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1661 VimFont *newFont = (VimFont *)gui_mch_get_font(name, 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1662 if (newFont != NOFONT) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1663 gui.norm_font = (GuiFont)newFont;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1664 gui_mch_set_font((GuiFont)newFont);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1665 if (name && STRCMP(name, "*") != 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1666 hl_set_font_name(name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1667
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1668 SetDrawingMode(B_OP_COPY);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1669
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1670 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1671 * Try to load other fonts for bold, italic, and bold-italic.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1672 * We should also try to work out what font to use for these when they are
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1673 * not specified by X resources, but we don't yet.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1674 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1675 return OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1676 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1677 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1678 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1679
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1680 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1681 VimTextAreaView::mchDrawString(int row, int col, char_u *s, int len, int flags)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1682 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1683 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1684 * First we must erase the area, because DrawString won't do
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1685 * that for us. XXX Most of the time this is a waste of effort
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1686 * since the bachground has been erased already... DRAW_TRANSP
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1687 * should be set when appropriate!!!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1688 * (Rectangles include the bottom and right edge)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1689 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1690 if (!(flags & DRAW_TRANSP)) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1691 int cells;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1692 cells = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1693 for (int i=0; i<len; i++) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1694 int cn = utf_ptr2cells((char_u *)(s+i));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1695 if (cn<4) cells += cn;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1696 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1697
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1698 BRect r(FILL_X(col), FILL_Y(row),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1699 FILL_X(col + cells) - PEN_WIDTH, FILL_Y(row + 1) - PEN_WIDTH);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1700 FillRect(r, B_SOLID_LOW);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1701 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1702
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1703 BFont font;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1704 this->GetFont(&font);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1705 if (!font.IsFixed())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1706 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1707 char* p = (char*)s;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1708 int32 clen, lastpos = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1709 BPoint where;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1710 int cells;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1711 while ((p - (char*)s) < len) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1712 clen = utf_ptr2len((u_char*)p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1713 where.Set(TEXT_X(col+lastpos), TEXT_Y(row));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1714 DrawString(p, clen, where);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1715 if (flags & DRAW_BOLD) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1716 where.x += 1.0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1717 SetDrawingMode(B_OP_BLEND);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1718 DrawString(p, clen, where);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1719 SetDrawingMode(B_OP_COPY);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1720 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1721 cells = utf_ptr2cells((char_u *)p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1722 if (cells<4) lastpos += cells;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1723 else lastpos++;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1724 p += clen;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1725 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1726 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1727 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1728 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1729 BPoint where(TEXT_X(col), TEXT_Y(row));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1730 DrawString((char*)s, len, where);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1731 if (flags & DRAW_BOLD) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1732 where.x += 1.0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1733 SetDrawingMode(B_OP_BLEND);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1734 DrawString((char*)s, len, where);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1735 SetDrawingMode(B_OP_COPY);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1736 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1737 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1738
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1739 if (flags & DRAW_UNDERL) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1740 int cells;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1741 cells = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1742 for (int i=0; i<len; i++) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1743 int cn = utf_ptr2cells((char_u *)(s+i));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1744 if (cn<4) cells += cn;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1745 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1746
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1747 BPoint start(FILL_X(col), FILL_Y(row + 1) - PEN_WIDTH);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1748 BPoint end(FILL_X(col + cells) - PEN_WIDTH, start.y);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1749
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1750 StrokeLine(start, end);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1751 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1752 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1753
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1754 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1755 VimTextAreaView::mchClearBlock(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1756 int row1,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1757 int col1,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1758 int row2,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1759 int col2)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1760 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1761 BRect r(FILL_X(col1), FILL_Y(row1),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1762 FILL_X(col2 + 1) - PEN_WIDTH, FILL_Y(row2 + 1) - PEN_WIDTH);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1763 gui_mch_set_bg_color(gui.back_pixel);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1764 FillRect(r, B_SOLID_LOW);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1765 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1766
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1767 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1768 VimTextAreaView::mchClearAll()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1769 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1770 gui_mch_set_bg_color(gui.back_pixel);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1771 FillRect(Bounds(), B_SOLID_LOW);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1772 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1773
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1774 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1775 * mchDeleteLines() Lock()s the window by itself.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1776 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1777 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1778 VimTextAreaView::mchDeleteLines(int row, int num_lines)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1779 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1780 BRect source, dest;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1781 source.left = FILL_X(gui.scroll_region_left);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1782 source.top = FILL_Y(row + num_lines);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1783 source.right = FILL_X(gui.scroll_region_right + 1) - PEN_WIDTH;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1784 source.bottom = FILL_Y(gui.scroll_region_bot + 1) - PEN_WIDTH;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1785
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1786 dest.left = FILL_X(gui.scroll_region_left);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1787 dest.top = FILL_Y(row);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1788 dest.right = FILL_X(gui.scroll_region_right + 1) - PEN_WIDTH;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1789 dest.bottom = FILL_Y(gui.scroll_region_bot - num_lines + 1) - PEN_WIDTH;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1790
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1791 if (gui.vimWindow->Lock()) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1792 // Clear one column more for when bold has spilled over
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1793 CopyBits(source, dest);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1794 gui_clear_block(gui.scroll_region_bot - num_lines + 1,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1795 gui.scroll_region_left,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1796 gui.scroll_region_bot, gui.scroll_region_right);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1797
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1798
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1799 gui.vimWindow->Unlock();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1800 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1801 * The Draw() callback will be called now if some of the source
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1802 * bits were not in the visible region.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1803 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1804 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1805 // gui_x11_check_copy_area();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1806 // }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1807 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1808
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1809 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1810 * mchInsertLines() Lock()s the window by itself.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1811 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1812 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1813 VimTextAreaView::mchInsertLines(int row, int num_lines)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1814 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1815 BRect source, dest;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1816
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1817 // XXX Attempt at a hack:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1818 gui.vimWindow->UpdateIfNeeded();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1819 source.left = FILL_X(gui.scroll_region_left);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1820 source.top = FILL_Y(row);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1821 source.right = FILL_X(gui.scroll_region_right + 1) - PEN_WIDTH;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1822 source.bottom = FILL_Y(gui.scroll_region_bot - num_lines + 1) - PEN_WIDTH;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1823
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1824 dest.left = FILL_X(gui.scroll_region_left);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1825 dest.top = FILL_Y(row + num_lines);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1826 dest.right = FILL_X(gui.scroll_region_right + 1) - PEN_WIDTH;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1827 dest.bottom = FILL_Y(gui.scroll_region_bot + 1) - PEN_WIDTH;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1828
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1829 if (gui.vimWindow->Lock()) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1830 // Clear one column more for when bold has spilled over
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1831 CopyBits(source, dest);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1832 gui_clear_block(row, gui.scroll_region_left,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1833 row + num_lines - 1, gui.scroll_region_right);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1834
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1835 gui.vimWindow->Unlock();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1836 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1837 * The Draw() callback will be called now if some of the source
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1838 * bits were not in the visible region.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1839 * However, if we scroll too fast it can't keep up and the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1840 * update region gets messed up. This seems to be because copying
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1841 * un-Draw()n bits does not generate Draw() calls for the copy...
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1842 * I moved the hack to before the CopyBits() to reduce the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1843 * amount of additional waiting needed.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1844 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1845
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1846 // gui_x11_check_copy_area();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1847
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1848 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1849 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1850
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1851 #ifdef FEAT_MBYTE_IME
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1852 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1853 * DrawIMString draws string with IMData.message.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1854 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1855 void VimTextAreaView::DrawIMString(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1856 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1857 static const rgb_color r_highlight = {255, 152, 152, 255},
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1858 b_highlight = {152, 203, 255, 255};
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1859 BString str;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1860 const char* s;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1861 int len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1862 BMessage* msg = IMData.message;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1863 if (!msg)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1864 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1865 gui_redraw_block(IMData.row, 0,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1866 IMData.row + IMData.count, W_WIDTH(curwin), GUI_MON_NOCLEAR);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1867 bool confirmed = false;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1868 msg->FindBool("be:confirmed", &confirmed);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1869 if (confirmed)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1870 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1871 rgb_color hcolor = HighColor(), lcolor = LowColor();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1872 msg->FindString("be:string", &str);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1873 s = str.String();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1874 len = str.Length();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1875 SetHighColor(0, 0, 0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1876 IMData.row = gui.row;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1877 IMData.col = gui.col;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1878 int32 sel_start = 0, sel_end = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1879 msg->FindInt32("be:selection", 0, &sel_start);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1880 msg->FindInt32("be:selection", 1, &sel_end);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1881 int clen, cn;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1882 BPoint pos(IMData.col, 0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1883 BRect r;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1884 BPoint where;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1885 IMData.location = ConvertToScreen(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1886 BPoint(FILL_X(pos.x), FILL_Y(IMData.row + pos.y)));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1887 for (int i=0; i<len; i+=clen)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1888 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1889 cn = utf_ptr2cells((char_u *)(s+i));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1890 clen = utf_ptr2len((char_u *)(s+i));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1891 if (pos.x + cn > W_WIDTH(curwin))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1892 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1893 pos.y++;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1894 pos.x = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1895 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1896 if (sel_start<=i && i<sel_end)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1897 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1898 SetLowColor(r_highlight);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1899 IMData.location = ConvertToScreen(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1900 BPoint(FILL_X(pos.x), FILL_Y(IMData.row + pos.y)));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1901 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1902 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1903 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1904 SetLowColor(b_highlight);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1905 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1906 r.Set(FILL_X(pos.x), FILL_Y(IMData.row + pos.y),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1907 FILL_X(pos.x + cn) - PEN_WIDTH,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1908 FILL_Y(IMData.row + pos.y + 1) - PEN_WIDTH);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1909 FillRect(r, B_SOLID_LOW);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1910 where.Set(TEXT_X(pos.x), TEXT_Y(IMData.row + pos.y));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1911 DrawString((s+i), clen, where);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1912 pos.x += cn;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1913 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1914 IMData.count = (int)pos.y;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1915
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1916 SetHighColor(hcolor);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1917 SetLowColor(lcolor);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1918 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1919 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1920 // ---------------- VimScrollBar ----------------
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1921
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1922 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1923 * BUG: XXX
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1924 * It seems that BScrollBar determine their direction not from
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1925 * "posture" but from if they are "tall" or "wide" in shape...
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1926 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1927 * Also, place them out of sight, because Vim enables them before
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1928 * they are positioned.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1929 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1930 VimScrollBar::VimScrollBar(scrollbar_T *g, orientation posture):
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1931 BScrollBar(posture == B_HORIZONTAL ? BRect(-100,-100,-10,-90) :
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1932 BRect(-100,-100,-90,-10),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1933 "vim scrollbar", (BView *)NULL,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1934 0.0, 10.0, posture),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1935 ignoreValue(-1),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1936 scrollEventCount(0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1937 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1938 gsb = g;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1939 SetResizingMode(B_FOLLOW_NONE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1940 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1941
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1942 VimScrollBar::~VimScrollBar()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1943 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1944 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1945
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1946 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1947 VimScrollBar::ValueChanged(float newValue)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1948 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1949 if (ignoreValue >= 0.0 && newValue == ignoreValue) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1950 ignoreValue = -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1951 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1952 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1953 ignoreValue = -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1954 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1955 * We want to throttle the amount of scroll messages generated.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1956 * Normally I presume you won't get a new message before we've
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1957 * handled the previous one, but because we're passing them on this
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1958 * happens very quickly. So instead we keep a counter of how many
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1959 * scroll events there are (or will be) in the VDCMP, and the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1960 * throttling happens at the receiving end.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1961 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1962 atomic_add(&scrollEventCount, 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1963
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1964 struct VimScrollBarMsg sm;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1965
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1966 sm.sb = this;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1967 sm.value = (long) newValue;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1968 sm.stillDragging = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1969
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1970 write_port(gui.vdcmp, VimMsg::ScrollBar, &sm, sizeof(sm));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1971
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1972 // calls gui_drag_scrollbar(sb, newValue, TRUE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1973 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1974
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1975 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1976 * When the mouse goes up, report that scrolling has stopped.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1977 * MouseUp() is NOT called when the mouse-up occurs outside
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1978 * the window, even though the thumb does move while the mouse
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1979 * is outside... This has some funny effects... XXX
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1980 * So we do special processing when the window de/activates.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1981 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1982 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1983 VimScrollBar::MouseUp(BPoint where)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1984 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1985 // BMessage *m = Window()->CurrentMessage();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1986 // m->PrintToStream();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1987
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1988 atomic_add(&scrollEventCount, 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1989
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1990 struct VimScrollBarMsg sm;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1991
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1992 sm.sb = this;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1993 sm.value = (long) Value();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1994 sm.stillDragging = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1995
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1996 write_port(gui.vdcmp, VimMsg::ScrollBar, &sm, sizeof(sm));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1997
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1998 // calls gui_drag_scrollbar(sb, newValue, FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
1999
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2000 Inherited::MouseUp(where);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2001 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2002
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2003 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2004 VimScrollBar::SetValue(float newValue)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2005 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2006 if (newValue == Value())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2007 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2008
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2009 ignoreValue = newValue;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2010 Inherited::SetValue(newValue);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2011 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2012
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2013 // ---------------- VimFont ----------------
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2014
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2015 VimFont::VimFont(): BFont()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2016 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2017 init();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2018 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2019
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2020 VimFont::VimFont(const VimFont *rhs): BFont(rhs)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2021 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2022 init();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2023 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2024
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2025 VimFont::VimFont(const BFont *rhs): BFont(rhs)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2026 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2027 init();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2028 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2029
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2030 VimFont::VimFont(const VimFont &rhs): BFont(rhs)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2031 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2032 init();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2033 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2034
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2035 VimFont::~VimFont()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2036 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2037 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2038
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2039 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2040 VimFont::init()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2041 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2042 next = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2043 refcount = 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2044 name = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2045 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2046
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2047 // ---------------- VimDialog ----------------
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2048
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2049 #if defined(FEAT_GUI_DIALOG)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2050
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2051 const unsigned int kVimDialogButtonMsg = 'VMDB';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2052 const unsigned int kVimDialogIconStripeWidth = 30;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2053 const unsigned int kVimDialogButtonsSpacingX = 9;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2054 const unsigned int kVimDialogButtonsSpacingY = 4;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2055 const unsigned int kVimDialogSpacingX = 6;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2056 const unsigned int kVimDialogSpacingY = 10;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2057 const unsigned int kVimDialogMinimalWidth = 310;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2058 const unsigned int kVimDialogMinimalHeight = 75;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2059 const BRect kDefaultRect =
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2060 BRect(0, 0, kVimDialogMinimalWidth, kVimDialogMinimalHeight);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2061
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2062 VimDialog::VimDialog(int type, const char *title, const char *message,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2063 const char *buttons, int dfltbutton, const char *textfield, int ex_cmd)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2064 : BWindow(kDefaultRect, title, B_TITLED_WINDOW_LOOK, B_MODAL_APP_WINDOW_FEEL,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2065 B_NOT_CLOSABLE | B_NOT_RESIZABLE |
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2066 B_NOT_ZOOMABLE | B_NOT_MINIMIZABLE | B_ASYNCHRONOUS_CONTROLS)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2067 , fDialogSem(-1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2068 , fDialogValue(dfltbutton)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2069 , fMessageView(NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2070 , fInputControl(NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2071 , fInputValue(textfield)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2072 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2073 // master view
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2074 VimDialog::View* view = new VimDialog::View(Bounds());
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2075 if (view == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2076 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2077
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2078 if (title == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2079 SetTitle("Vim " VIM_VERSION_MEDIUM);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2080
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2081 AddChild(view);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2082
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2083 // icon
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2084 view->InitIcon(type);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2085
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2086 // buttons
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2087 int32 which = 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2088 float maxButtonWidth = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2089 float maxButtonHeight = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2090 float buttonsWidth = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2091 float buttonsHeight = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2092 BString strButtons(buttons);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2093 strButtons.RemoveAll("&");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2094 do {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2095 int32 end = strButtons.FindFirst('\n');
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2096 if (end != B_ERROR)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2097 strButtons.SetByteAt(end, '\0');
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2098
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2099 BButton *button = _CreateButton(which++, strButtons.String());
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2100 view->AddChild(button);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2101 fButtonsList.AddItem(button);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2102
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2103 maxButtonWidth = max_c(maxButtonWidth, button->Bounds().Width());
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2104 maxButtonHeight = max_c(maxButtonHeight, button->Bounds().Height());
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2105 buttonsWidth += button->Bounds().Width();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2106 buttonsHeight += button->Bounds().Height();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2107
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2108 if (end == B_ERROR)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2109 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2110
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2111 strButtons.Remove(0, end + 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2112 } while (true);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2113
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2114 int32 buttonsCount = fButtonsList.CountItems();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2115 buttonsWidth += kVimDialogButtonsSpacingX * (buttonsCount - 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2116 buttonsHeight += kVimDialogButtonsSpacingY * (buttonsCount - 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2117 float dialogWidth = buttonsWidth + kVimDialogIconStripeWidth +
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2118 kVimDialogSpacingX * 2;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2119 float dialogHeight = maxButtonHeight + kVimDialogSpacingY * 3;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2120
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2121 // Check 'v' flag in 'guioptions': vertical button placement.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2122 bool vertical = (vim_strchr(p_go, GO_VERTICAL) != NULL) ||
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2123 dialogWidth >= gui.vimWindow->Bounds().Width();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2124 if (vertical) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2125 dialogWidth -= buttonsWidth;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2126 dialogWidth += maxButtonWidth;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2127 dialogHeight -= maxButtonHeight;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2128 dialogHeight += buttonsHeight;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2129 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2130
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2131 dialogWidth = max_c(dialogWidth, kVimDialogMinimalWidth);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2132
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2133 // message view
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2134 BRect rect(0, 0, dialogWidth, 0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2135 rect.left += kVimDialogIconStripeWidth + 16 + kVimDialogSpacingX;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2136 rect.top += kVimDialogSpacingY;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2137 rect.right -= kVimDialogSpacingX;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2138 rect.bottom = rect.top;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2139 fMessageView = new BTextView(rect, "_tv_", rect.OffsetByCopy(B_ORIGIN),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2140 B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2141
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2142 fMessageView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2143 rgb_color textColor = ui_color(B_PANEL_TEXT_COLOR);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2144 fMessageView->SetFontAndColor(be_plain_font, B_FONT_ALL, &textColor);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2145 fMessageView->SetText(message);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2146 fMessageView->MakeEditable(false);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2147 fMessageView->MakeSelectable(false);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2148 fMessageView->SetWordWrap(true);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2149 AddChild(fMessageView);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2150
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2151 float messageHeight = fMessageView->TextHeight(0, fMessageView->CountLines());
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2152 fMessageView->ResizeBy(0, messageHeight);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2153 fMessageView->SetTextRect(BRect(0, 0, rect.Width(), messageHeight));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2154
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2155 dialogHeight += messageHeight;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2156
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2157 // input view
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2158 if (fInputValue != NULL) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2159 rect.top =
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2160 rect.bottom += messageHeight + kVimDialogSpacingY;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2161 fInputControl = new BTextControl(rect, "_iv_", NULL, fInputValue, NULL,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2162 B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW | B_NAVIGABLE | B_PULSE_NEEDED);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2163 fInputControl->TextView()->SetText(fInputValue);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2164 fInputControl->TextView()->SetWordWrap(false);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2165 AddChild(fInputControl);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2166
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2167 float width = 0.f, height = 0.f;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2168 fInputControl->GetPreferredSize(&width, &height);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2169 fInputControl->MakeFocus(true);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2170
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2171 dialogHeight += height + kVimDialogSpacingY * 1.5;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2172 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2173
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2174 dialogHeight = max_c(dialogHeight, kVimDialogMinimalHeight);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2175
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2176 ResizeTo(dialogWidth, dialogHeight);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2177 MoveTo((gui.vimWindow->Bounds().Width() - dialogWidth) / 2,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2178 (gui.vimWindow->Bounds().Height() - dialogHeight) / 2);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2179
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2180 // adjust layout of buttons
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2181 float buttonWidth = max_c(maxButtonWidth, rect.Width() * 0.66);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2182 BPoint origin(dialogWidth, dialogHeight);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2183 origin.x -= kVimDialogSpacingX + (vertical ? buttonWidth : buttonsWidth);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2184 origin.y -= kVimDialogSpacingY + (vertical ? buttonsHeight : maxButtonHeight);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2185
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2186 for (int32 i = 0 ; i < buttonsCount; i++) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2187 BButton *button = (BButton*)fButtonsList.ItemAt(i);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2188 button->MoveTo(origin);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2189 if (vertical) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2190 origin.y += button->Frame().Height() + kVimDialogButtonsSpacingY;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2191 button->ResizeTo(buttonWidth, button->Frame().Height());
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2192 } else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2193 origin.x += button->Frame().Width() + kVimDialogButtonsSpacingX;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2194
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2195 if (dfltbutton == i + 1) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2196 button->MakeDefault(true);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2197 button->MakeFocus(fInputControl == NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2198 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2199 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2200 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2201
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2202 VimDialog::~VimDialog()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2203 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2204 if (fDialogSem > B_OK)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2205 delete_sem(fDialogSem);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2206 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2207
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2208 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2209 VimDialog::Go()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2210 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2211 fDialogSem = create_sem(0, "VimDialogSem");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2212 if (fDialogSem < B_OK) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2213 Quit();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2214 return fDialogValue;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2215 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2216
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2217 Show();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2218
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2219 while (acquire_sem(fDialogSem) == B_INTERRUPTED);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2220
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2221 int retValue = fDialogValue;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2222 if (fInputValue != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2223 vim_strncpy((char_u*)fInputValue, (char_u*)fInputControl->Text(), IOSIZE - 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2224
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2225 if (Lock())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2226 Quit();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2227
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2228 return retValue;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2229 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2230
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2231 void VimDialog::MessageReceived(BMessage *msg)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2232 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2233 int32 which = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2234 if (msg->what != kVimDialogButtonMsg ||
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2235 msg->FindInt32("which", &which) != B_OK)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2236 return BWindow::MessageReceived(msg);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2237
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2238 fDialogValue = which;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2239 delete_sem(fDialogSem);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2240 fDialogSem = -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2241 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2242
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2243 BButton* VimDialog::_CreateButton(int32 which, const char* label)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2244 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2245 BMessage *message = new BMessage(kVimDialogButtonMsg);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2246 message->AddInt32("which", which);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2247
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2248 BRect rect(0, 0, 0, 0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2249 BString name;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2250 name << "_b" << which << "_";
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2251
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2252 BButton* button = new BButton(rect, name.String(), label, message,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2253 B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2254
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2255 float width = 0.f, height = 0.f;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2256 button->GetPreferredSize(&width, &height);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2257 button->ResizeTo(width, height);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2258
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2259 return button;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2260 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2261
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2262 VimDialog::View::View(BRect frame)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2263 : BView(frame, "VimDialogView", B_FOLLOW_ALL_SIDES, B_WILL_DRAW),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2264 fIconBitmap(NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2265 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2266 SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2267 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2268
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2269 VimDialog::View::~View()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2270 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2271 delete fIconBitmap;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2272 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2273
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2274 void VimDialog::View::Draw(BRect updateRect)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2275 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2276 BRect stripeRect = Bounds();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2277 stripeRect.right = kVimDialogIconStripeWidth;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2278 SetHighColor(tint_color(ViewColor(), B_DARKEN_1_TINT));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2279 FillRect(stripeRect);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2280
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2281 if (fIconBitmap == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2282 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2283
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2284 SetDrawingMode(B_OP_ALPHA);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2285 SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_OVERLAY);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2286 DrawBitmapAsync(fIconBitmap, BPoint(18, 6));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2287 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2288
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2289 void VimDialog::View::InitIcon(int32 type)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2290 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2291 if (type == VIM_GENERIC)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2292 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2293
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2294 BPath path;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2295 status_t status = find_directory(B_BEOS_SERVERS_DIRECTORY, &path);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2296 if (status != B_OK) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2297 fprintf(stderr, "Cannot retrieve app info:%s\n", strerror(status));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2298 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2299 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2300
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2301 path.Append("app_server");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2302
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2303 BFile file(path.Path(), O_RDONLY);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2304 if (file.InitCheck() != B_OK) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2305 fprintf(stderr, "App file assignment failed:%s\n",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2306 strerror(file.InitCheck()));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2307 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2308 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2309
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2310 BResources resources(&file);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2311 if (resources.InitCheck() != B_OK) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2312 fprintf(stderr, "App server resources assignment failed:%s\n",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2313 strerror(resources.InitCheck()));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2314 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2315 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2316
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2317 const char *name = "";
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2318 switch(type) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2319 case VIM_ERROR: name = "stop"; break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2320 case VIM_WARNING: name = "warn"; break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2321 case VIM_INFO: name = "info"; break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2322 case VIM_QUESTION: name = "idea"; break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2323 default: return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2324 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2325
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2326 int32 iconSize = 32;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2327 fIconBitmap = new BBitmap(BRect(0, 0, iconSize - 1, iconSize - 1), 0, B_RGBA32);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2328 if (fIconBitmap == NULL || fIconBitmap->InitCheck() != B_OK) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2329 fprintf(stderr, "Icon bitmap allocation failed:%s\n",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2330 (fIconBitmap == NULL) ? "null" : strerror(fIconBitmap->InitCheck()));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2331 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2332 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2333
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2334 size_t size = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2335 const uint8* iconData = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2336 // try vector icon first?
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2337 iconData = (const uint8*)resources.LoadResource(B_VECTOR_ICON_TYPE, name, &size);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2338 if (iconData != NULL && BIconUtils::GetVectorIcon(iconData, size, fIconBitmap) == B_OK)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2339 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2340
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2341 // try bitmap icon now
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2342 iconData = (const uint8*)resources.LoadResource(B_LARGE_ICON_TYPE, name, &size);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2343 if (iconData == NULL) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2344 fprintf(stderr, "Bitmap icon resource not found\n");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2345 delete fIconBitmap;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2346 fIconBitmap = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2347 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2348 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2349
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2350 if (fIconBitmap->ColorSpace() != B_CMAP8)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2351 BIconUtils::ConvertFromCMAP8(iconData, iconSize, iconSize, iconSize, fIconBitmap);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2352 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2353
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2354 const unsigned int kVimDialogOKButtonMsg = 'FDOK';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2355 const unsigned int kVimDialogCancelButtonMsg = 'FDCN';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2356 const unsigned int kVimDialogSizeInputMsg = 'SICH';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2357 const unsigned int kVimDialogFamilySelectMsg = 'MSFM';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2358 const unsigned int kVimDialogStyleSelectMsg = 'MSST';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2359 const unsigned int kVimDialogSizeSelectMsg = 'MSSZ';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2360
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2361 VimSelectFontDialog::VimSelectFontDialog(font_family* family, font_style* style, float* size)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2362 : BWindow(kDefaultRect, "Font Selection", B_TITLED_WINDOW_LOOK, B_MODAL_APP_WINDOW_FEEL,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2363 B_NOT_CLOSABLE | B_NOT_RESIZABLE |
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2364 B_NOT_ZOOMABLE | B_NOT_MINIMIZABLE | B_ASYNCHRONOUS_CONTROLS)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2365 , fStatus(B_NO_INIT)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2366 , fDialogSem(-1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2367 , fDialogValue(false)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2368 , fFamily(family)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2369 , fStyle(style)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2370 , fSize(size)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2371 , fFontSize(*size)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2372 , fPreview(0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2373 , fFamiliesList(0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2374 , fStylesList(0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2375 , fSizesList(0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2376 , fSizesInput(0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2377 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2378 strncpy(fFontFamily, *family, B_FONT_FAMILY_LENGTH);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2379 strncpy(fFontStyle, *style, B_FONT_STYLE_LENGTH);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2380
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2381 // "client" area view
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2382 BBox *clientBox = new BBox(Bounds(), B_EMPTY_STRING, B_FOLLOW_ALL_SIDES,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2383 B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP | B_PULSE_NEEDED,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2384 B_PLAIN_BORDER);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2385 AddChild(clientBox);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2386
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2387 // client view
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2388 BRect RC = clientBox->Bounds();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2389 RC.InsetBy(kVimDialogSpacingX, kVimDialogSpacingY);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2390 BRect rc(RC.LeftTop(), RC.LeftTop());
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2391
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2392 // at first create all controls
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2393 fPreview = new BStringView(rc, "preview", "DejaVu Sans Mono");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2394 clientBox->AddChild(fPreview);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2395
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2396 BBox* boxDivider = new BBox(rc, B_EMPTY_STRING,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2397 B_FOLLOW_NONE, B_WILL_DRAW, B_FANCY_BORDER);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2398 clientBox->AddChild(boxDivider);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2399
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2400 BStringView *labelFamily = new BStringView(rc, "labelFamily", "Family:");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2401 clientBox->AddChild(labelFamily);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2402 labelFamily->ResizeToPreferred();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2403
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2404 BStringView *labelStyle = new BStringView(rc, "labelStyle", "Style:");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2405 clientBox->AddChild(labelStyle);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2406 labelStyle->ResizeToPreferred();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2407
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2408 BStringView *labelSize = new BStringView(rc, "labelSize", "Size:");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2409 clientBox->AddChild(labelSize);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2410 labelSize->ResizeToPreferred();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2411
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2412 fFamiliesList = new BListView(rc, "listFamily",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2413 B_SINGLE_SELECTION_LIST, B_FOLLOW_ALL_SIDES);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2414 BScrollView *scrollFamilies = new BScrollView("scrollFamily",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2415 fFamiliesList, B_FOLLOW_LEFT_RIGHT, 0, false, true);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2416 clientBox->AddChild(scrollFamilies);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2417
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2418 fStylesList= new BListView(rc, "listStyles",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2419 B_SINGLE_SELECTION_LIST, B_FOLLOW_ALL_SIDES);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2420 BScrollView *scrollStyles = new BScrollView("scrollStyle",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2421 fStylesList, B_FOLLOW_LEFT_RIGHT, 0, false, true);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2422 clientBox->AddChild(scrollStyles);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2423
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2424 fSizesInput = new BTextControl(rc, "inputSize", NULL, "???",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2425 new BMessage(kVimDialogSizeInputMsg));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2426 clientBox->AddChild(fSizesInput);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2427 fSizesInput->ResizeToPreferred();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2428
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2429 fSizesList = new BListView(rc, "listSizes",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2430 B_SINGLE_SELECTION_LIST, B_FOLLOW_ALL_SIDES);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2431 BScrollView *scrollSizes = new BScrollView("scrollSize",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2432 fSizesList, B_FOLLOW_LEFT_RIGHT, 0, false, true);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2433 clientBox->AddChild(scrollSizes);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2434
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2435 BButton *buttonOK = new BButton(rc, "buttonOK", "OK",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2436 new BMessage(kVimDialogOKButtonMsg));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2437 clientBox->AddChild(buttonOK);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2438 buttonOK->ResizeToPreferred();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2439
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2440 BButton *buttonCancel = new BButton(rc, "buttonCancel", "Cancel",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2441 new BMessage(kVimDialogCancelButtonMsg));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2442 clientBox->AddChild(buttonCancel);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2443 buttonCancel->ResizeToPreferred();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2444
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2445 // layout controls
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2446 float lineHeight = labelFamily->Bounds().Height();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2447 float previewHeight = lineHeight * 3;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2448 float offsetYLabels = previewHeight + kVimDialogSpacingY;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2449 float offsetYLists = offsetYLabels + lineHeight + kVimDialogSpacingY / 2;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2450 float offsetYSizes = offsetYLists + fSizesInput->Bounds().Height() + kVimDialogSpacingY / 2;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2451 float listsHeight = lineHeight * 9;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2452 float offsetYButtons = offsetYLists + listsHeight + kVimDialogSpacingY;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2453 float maxControlsHeight = offsetYButtons + buttonOK->Bounds().Height();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2454 float familiesWidth = labelFamily->Bounds().Width() * 5;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2455 float offsetXStyles = familiesWidth + kVimDialogSpacingX;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2456 float stylesWidth = labelStyle->Bounds().Width() * 4;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2457 float offsetXSizes = offsetXStyles + stylesWidth + kVimDialogSpacingX;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2458 float sizesWidth = labelSize->Bounds().Width() * 2;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2459 float maxControlsWidth = offsetXSizes + sizesWidth;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2460
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2461 ResizeTo(maxControlsWidth + kVimDialogSpacingX * 2,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2462 maxControlsHeight + kVimDialogSpacingY * 2);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2463
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2464 BRect rcVim = gui.vimWindow->Frame();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2465 MoveTo(rcVim.left + (rcVim.Width() - Frame().Width()) / 2,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2466 rcVim.top + (rcVim.Height() - Frame().Height()) / 2);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2467
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2468 fPreview->ResizeTo(maxControlsWidth, previewHeight);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2469 fPreview->SetAlignment(B_ALIGN_CENTER);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2470
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2471 boxDivider->MoveBy(0.f, previewHeight + kVimDialogSpacingY / 2);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2472 boxDivider->ResizeTo(maxControlsWidth, 1.f);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2473
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2474 labelFamily->MoveBy(0.f, offsetYLabels);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2475 labelStyle->MoveBy(offsetXStyles, offsetYLabels);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2476 labelSize->MoveBy(offsetXSizes, offsetYLabels);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2477
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2478 // text control alignment issues
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2479 float insetX = fSizesInput->TextView()->Bounds().Width() - fSizesInput->Bounds().Width();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2480 float insetY = fSizesInput->TextView()->Bounds().Width() - fSizesInput->Bounds().Width();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2481
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2482 scrollFamilies->MoveBy(0.f, offsetYLists);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2483 scrollStyles->MoveBy(offsetXStyles, offsetYLists);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2484 fSizesInput->MoveBy(offsetXSizes + insetX / 2, offsetYLists + insetY / 2);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2485 scrollSizes->MoveBy(offsetXSizes, offsetYSizes);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2486
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2487 fSizesInput->SetAlignment(B_ALIGN_CENTER, B_ALIGN_CENTER);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2488
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2489 scrollFamilies->ResizeTo(familiesWidth, listsHeight);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2490 scrollStyles->ResizeTo(stylesWidth, listsHeight);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2491 fSizesInput->ResizeTo(sizesWidth, fSizesInput->Bounds().Height());
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2492 scrollSizes->ResizeTo(sizesWidth,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2493 listsHeight - (offsetYSizes - offsetYLists));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2494
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2495 buttonOK->MoveBy(maxControlsWidth - buttonOK->Bounds().Width(), offsetYButtons);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2496 buttonCancel->MoveBy(maxControlsWidth - buttonOK->Bounds().Width()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2497 - buttonCancel->Bounds().Width() - kVimDialogSpacingX, offsetYButtons);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2498
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2499 // fill lists
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2500 int selIndex = -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2501 int count = count_font_families();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2502 for (int i = 0; i < count; i++) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2503 font_family family;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2504 if (get_font_family(i, &family ) == B_OK) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2505 fFamiliesList->AddItem(new BStringItem((const char*)family));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2506 if (strncmp(family, fFontFamily, B_FONT_FAMILY_LENGTH) == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2507 selIndex = i;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2508 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2509 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2510
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2511 if (selIndex >= 0) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2512 fFamiliesList->Select(selIndex);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2513 fFamiliesList->ScrollToSelection();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2514 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2515
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2516 _UpdateFontStyles();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2517
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2518 selIndex = -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2519 for (int size = 8, index = 0; size <= 18; size++, index++) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2520 BString str;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2521 str << size;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2522 fSizesList->AddItem(new BStringItem(str));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2523 if (size == fFontSize)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2524 selIndex = index;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2525
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2526 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2527
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2528 if (selIndex >= 0) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2529 fSizesList->Select(selIndex);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2530 fSizesList->ScrollToSelection();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2531 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2532
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2533 fFamiliesList->SetSelectionMessage(new BMessage(kVimDialogFamilySelectMsg));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2534 fStylesList->SetSelectionMessage(new BMessage(kVimDialogStyleSelectMsg));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2535 fSizesList->SetSelectionMessage(new BMessage(kVimDialogSizeSelectMsg));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2536 fSizesInput->SetModificationMessage(new BMessage(kVimDialogSizeInputMsg));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2537
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2538 _UpdateSizeInputPreview();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2539 _UpdateFontPreview();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2540
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2541 fStatus = B_OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2542 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2543
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2544 VimSelectFontDialog::~VimSelectFontDialog()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2545 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2546 _CleanList(fFamiliesList);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2547 _CleanList(fStylesList);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2548 _CleanList(fSizesList);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2549
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2550 if (fDialogSem > B_OK)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2551 delete_sem(fDialogSem);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2552 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2553
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2554 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2555 VimSelectFontDialog::_CleanList(BListView* list)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2556 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2557 while (0 < list->CountItems())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2558 delete (dynamic_cast<BStringItem*>(list->RemoveItem((int32)0)));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2559 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2560
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2561 bool
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2562 VimSelectFontDialog::Go()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2563 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2564 if (fStatus != B_OK) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2565 Quit();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2566 return NOFONT;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2567 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2568
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2569 fDialogSem = create_sem(0, "VimFontSelectDialogSem");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2570 if (fDialogSem < B_OK) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2571 Quit();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2572 return fDialogValue;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2573 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2574
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2575 Show();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2576
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2577 while (acquire_sem(fDialogSem) == B_INTERRUPTED);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2578
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2579 bool retValue = fDialogValue;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2580
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2581 if (Lock())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2582 Quit();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2583
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2584 return retValue;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2585 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2586
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2587
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2588 void VimSelectFontDialog::_UpdateFontStyles()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2589 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2590 _CleanList(fStylesList);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2591
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2592 int32 selIndex = -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2593 int32 count = count_font_styles(fFontFamily);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2594 for (int32 i = 0; i < count; i++) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2595 font_style style;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2596 uint32 flags = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2597 if (get_font_style(fFontFamily, i, &style, &flags) == B_OK) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2598 fStylesList->AddItem(new BStringItem((const char*)style));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2599 if (strncmp(style, fFontStyle, B_FONT_STYLE_LENGTH) == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2600 selIndex = i;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2601 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2602 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2603
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2604 if (selIndex >= 0) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2605 fStylesList->Select(selIndex);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2606 fStylesList->ScrollToSelection();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2607 } else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2608 fStylesList->Select(0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2609 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2610
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2611
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2612 void VimSelectFontDialog::_UpdateSizeInputPreview()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2613 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2614 char buf[10] = {0};
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2615 vim_snprintf(buf, sizeof(buf), (char*)"%.0f", fFontSize);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2616 fSizesInput->SetText(buf);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2617 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2618
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2619
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2620 void VimSelectFontDialog::_UpdateFontPreview()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2621 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2622 BFont font;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2623 fPreview->GetFont(&font);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2624 font.SetSize(fFontSize);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2625 font.SetFamilyAndStyle(fFontFamily, fFontStyle);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2626 fPreview->SetFont(&font, B_FONT_FAMILY_AND_STYLE | B_FONT_SIZE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2627
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2628 BString str;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2629 str << fFontFamily << " " << fFontStyle << ", " << (int)fFontSize << " pt.";
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2630 fPreview->SetText(str);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2631 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2632
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2633
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2634 bool
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2635 VimSelectFontDialog::_UpdateFromListItem(BListView* list, char* text, int textSize)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2636 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2637 int32 index = list->CurrentSelection();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2638 if (index < 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2639 return false;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2640 BStringItem* item = (BStringItem*)list->ItemAt(index);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2641 if (item == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2642 return false;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2643 strncpy(text, item->Text(), textSize);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2644 return true;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2645 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2646
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2647
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2648 void VimSelectFontDialog::MessageReceived(BMessage *msg)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2649 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2650 switch (msg->what) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2651 case kVimDialogOKButtonMsg:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2652 strncpy(*fFamily, fFontFamily, B_FONT_FAMILY_LENGTH);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2653 strncpy(*fStyle, fFontStyle, B_FONT_STYLE_LENGTH);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2654 *fSize = fFontSize;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2655 fDialogValue = true;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2656 case kVimDialogCancelButtonMsg:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2657 delete_sem(fDialogSem);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2658 fDialogSem = -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2659 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2660 case B_KEY_UP:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2661 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2662 int32 key = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2663 if (msg->FindInt32("raw_char", &key) == B_OK
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2664 && key == B_ESCAPE) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2665 delete_sem(fDialogSem);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2666 fDialogSem = -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2667 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2668 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2669 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2670
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2671 case kVimDialogFamilySelectMsg:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2672 if (_UpdateFromListItem(fFamiliesList,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2673 fFontFamily, B_FONT_FAMILY_LENGTH)) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2674 _UpdateFontStyles();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2675 _UpdateFontPreview();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2676 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2677 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2678 case kVimDialogStyleSelectMsg:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2679 if (_UpdateFromListItem(fStylesList,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2680 fFontStyle, B_FONT_STYLE_LENGTH))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2681 _UpdateFontPreview();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2682 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2683 case kVimDialogSizeSelectMsg:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2684 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2685 char buf[10] = {0};
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2686 if (_UpdateFromListItem(fSizesList, buf, sizeof(buf))) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2687 float size = atof(buf);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2688 if (size > 0.f) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2689 fFontSize = size;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2690 _UpdateSizeInputPreview();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2691 _UpdateFontPreview();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2692 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2693 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2694 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2695 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2696 case kVimDialogSizeInputMsg:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2697 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2698 float size = atof(fSizesInput->Text());
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2699 if (size > 0.f) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2700 fFontSize = size;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2701 _UpdateFontPreview();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2702 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2703 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2704 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2705 default:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2706 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2707 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2708 return BWindow::MessageReceived(msg);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2709 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2710
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2711 #endif // FEAT_GUI_DIALOG
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2712
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2713 #ifdef FEAT_TOOLBAR
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2714
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2715 // some forward declaration required by toolbar functions...
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2716 static BMessage * MenuMessage(vimmenu_T *menu);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2717
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2718 VimToolbar::VimToolbar(BRect frame, const char *name) :
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2719 BBox(frame, name, B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW | B_FRAME_EVENTS, B_PLAIN_BORDER)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2720 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2721 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2722
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2723 VimToolbar::~VimToolbar()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2724 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2725 int32 count = fButtonsList.CountItems();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2726 for (int32 i = 0; i < count; i++)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2727 delete (BPictureButton*)fButtonsList.ItemAt(i);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2728 fButtonsList.MakeEmpty();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2729
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2730 delete normalButtonsBitmap;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2731 delete grayedButtonsBitmap;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2732 normalButtonsBitmap = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2733 grayedButtonsBitmap = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2734 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2735
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2736 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2737 VimToolbar::AttachedToWindow()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2738 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2739 BBox::AttachedToWindow();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2740
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2741 SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2742 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2743
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2744 float
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2745 VimToolbar::ToolbarHeight() const
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2746 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2747 float size = NULL == normalButtonsBitmap ? 18. : normalButtonsBitmap->Bounds().Height();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2748 return size + ToolbarMargin * 2 + ButtonMargin * 2 + 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2749 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2750
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2751 bool
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2752 VimToolbar::ModifyBitmapToGrayed(BBitmap *bitmap)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2753 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2754 float height = bitmap->Bounds().Height();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2755 float width = bitmap->Bounds().Width();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2756
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2757 rgb_color *bits = (rgb_color*)bitmap->Bits();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2758 int32 pixels = bitmap->BitsLength() / 4;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2759 for (int32 i = 0; i < pixels; i++) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2760 bits[i].red = bits[i].green =
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2761 bits[i].blue = ((uint32)bits[i].red + bits[i].green + bits[i].blue) / 3;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2762 bits[i].alpha /= 4;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2763 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2764
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2765 return true;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2766 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2767
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2768 bool
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2769 VimToolbar::PrepareButtonBitmaps()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2770 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2771 // first try to load potentially customized $VIRUNTIME/bitmaps/builtin-tools.png
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2772 normalButtonsBitmap = LoadVimBitmap("builtin-tools.png");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2773 if (normalButtonsBitmap == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2774 // customized not found? dig application resources for "builtin-tools" one
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2775 normalButtonsBitmap = BTranslationUtils::GetBitmap(B_PNG_FORMAT, "builtin-tools");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2776
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2777 if (normalButtonsBitmap == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2778 return false;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2779
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2780 BMessage archive;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2781 normalButtonsBitmap->Archive(&archive);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2782
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2783 grayedButtonsBitmap = new BBitmap(&archive);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2784 if (grayedButtonsBitmap == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2785 return false;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2786
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2787 // modify grayed bitmap
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2788 ModifyBitmapToGrayed(grayedButtonsBitmap);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2789
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2790 return true;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2791 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2792
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2793 BBitmap *VimToolbar::LoadVimBitmap(const char* fileName)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2794 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2795 BBitmap *bitmap = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2796
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2797 int mustfree = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2798 char_u* runtimePath = vim_getenv((char_u*)"VIMRUNTIME", &mustfree);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2799 if (runtimePath != NULL && fileName != NULL) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2800 BString strPath((char*)runtimePath);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2801 strPath << "/bitmaps/" << fileName;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2802 bitmap = BTranslationUtils::GetBitmap(strPath.String());
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2803 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2804
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2805 if (mustfree)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2806 vim_free(runtimePath);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2807
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2808 return bitmap;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2809 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2810
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2811 bool
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2812 VimToolbar::GetPictureFromBitmap(BPicture *pictureTo, int32 index, BBitmap *bitmapFrom, bool pressed)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2813 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2814 float size = bitmapFrom->Bounds().Height() + 1.;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2815
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2816 BView view(BRect(0, 0, size, size), "", 0, 0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2817
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2818 AddChild(&view);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2819 view.BeginPicture(pictureTo);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2820
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2821 view.SetHighColor(ui_color(B_PANEL_BACKGROUND_COLOR));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2822 view.FillRect(view.Bounds());
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2823 view.SetDrawingMode(B_OP_OVER);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2824
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2825 BRect source(0, 0, size - 1, size - 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2826 BRect destination(source);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2827
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2828 source.OffsetBy(size * index, 0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2829 destination.OffsetBy(ButtonMargin, ButtonMargin);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2830
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2831 view.DrawBitmap(bitmapFrom, source, destination);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2832
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2833 if (pressed) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2834 rgb_color shineColor = ui_color(B_SHINE_COLOR);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2835 rgb_color shadowColor = ui_color(B_SHADOW_COLOR);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2836 size += ButtonMargin * 2 - 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2837 view.BeginLineArray(4);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2838 view.AddLine(BPoint(0, 0), BPoint(size, 0), shadowColor);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2839 view.AddLine(BPoint(size, 0), BPoint(size, size), shineColor);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2840 view.AddLine(BPoint(size, size), BPoint(0, size), shineColor);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2841 view.AddLine(BPoint(0, size), BPoint(0, 0), shadowColor);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2842 view.EndLineArray();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2843 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2844
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2845 view.EndPicture();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2846 RemoveChild(&view);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2847
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2848 return true;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2849 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2850
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2851 bool
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2852 VimToolbar::AddButton(int32 index, vimmenu_T *menu)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2853 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2854 BPictureButton *button = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2855 if (!menu_is_separator(menu->name)) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2856 float size = normalButtonsBitmap ?
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2857 normalButtonsBitmap->Bounds().Height() + 1. + ButtonMargin * 2 : 18.;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2858 BRect frame(0, 0, size, size);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2859 BPicture pictureOn;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2860 BPicture pictureOff;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2861 BPicture pictureGray;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2862
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2863 if (menu->iconfile == NULL && menu->iconidx >= 0 && normalButtonsBitmap) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2864 GetPictureFromBitmap(&pictureOn, menu->iconidx, normalButtonsBitmap, true);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2865 GetPictureFromBitmap(&pictureOff, menu->iconidx, normalButtonsBitmap, false);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2866 GetPictureFromBitmap(&pictureGray, menu->iconidx, grayedButtonsBitmap, false);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2867 } else {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2868
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2869 char_u buffer[MAXPATHL] = {0};
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2870 BBitmap *bitmap = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2871
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2872 if (menu->iconfile) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2873 gui_find_iconfile(menu->iconfile, buffer, (char*)"png");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2874 bitmap = BTranslationUtils::GetBitmap((char*)buffer);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2875 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2876
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2877 if (bitmap == NULL && gui_find_bitmap(menu->name, buffer, (char*)"png") == OK)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2878 bitmap = BTranslationUtils::GetBitmap((char*)buffer);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2879
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2880 if (bitmap == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2881 bitmap = new BBitmap(BRect(0, 0, size, size), B_RGB32);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2882
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2883 GetPictureFromBitmap(&pictureOn, 0, bitmap, true);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2884 GetPictureFromBitmap(&pictureOff, 0, bitmap, false);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2885 ModifyBitmapToGrayed(bitmap);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2886 GetPictureFromBitmap(&pictureGray, 0, bitmap, false);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2887
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2888 delete bitmap;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2889 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2890
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2891 button = new BPictureButton(frame, (char*)menu->name,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2892 &pictureOff, &pictureOn, MenuMessage(menu));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2893
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2894 button->SetDisabledOn(&pictureGray);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2895 button->SetDisabledOff(&pictureGray);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2896
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2897 button->SetTarget(gui.vimTextArea);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2898
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2899 AddChild(button);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2900
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2901 menu->button = button;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2902 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2903
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2904 bool result = fButtonsList.AddItem(button, index);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2905 InvalidateLayout();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2906 return result;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2907 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2908
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2909 bool
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2910 VimToolbar::RemoveButton(vimmenu_T *menu)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2911 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2912 if (menu->button) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2913 if (fButtonsList.RemoveItem(menu->button)) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2914 delete menu->button;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2915 menu->button = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2916 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2917 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2918 return true;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2919 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2920
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2921 bool
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2922 VimToolbar::GrayButton(vimmenu_T *menu, int grey)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2923 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2924 if (menu->button) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2925 int32 index = fButtonsList.IndexOf(menu->button);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2926 if (index >= 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2927 menu->button->SetEnabled(grey ? false : true);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2928 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2929 return true;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2930 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2931
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2932 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2933 VimToolbar::InvalidateLayout()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2934 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2935 int32 offset = ToolbarMargin;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2936 int32 count = fButtonsList.CountItems();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2937 for (int32 i = 0; i < count; i++) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2938 BPictureButton *button = (BPictureButton *)fButtonsList.ItemAt(i);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2939 if (button) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2940 button->MoveTo(offset, ToolbarMargin);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2941 offset += button->Bounds().Width() + ToolbarMargin;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2942 } else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2943 offset += ToolbarMargin * 3;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2944 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2945 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2946
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2947 #endif /*FEAT_TOOLBAR*/
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2948
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2949 #if defined(FEAT_GUI_TABLINE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2950
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2951 float
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2952 VimTabLine::TablineHeight() const
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2953 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2954 // float size = NULL == normalButtonsBitmap ? 18. : normalButtonsBitmap->Bounds().Height();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2955 // return size + ToolbarMargin * 2 + ButtonMargin * 2 + 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2956 return TabHeight(); // + ToolbarMargin;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2957 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2958
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2959 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2960 VimTabLine::MouseDown(BPoint point)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2961 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2962 if (!gui_mch_showing_tabline())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2963 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2964
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2965 BMessage *m = Window()->CurrentMessage();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2966 assert(m);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2967
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2968 int32 buttons = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2969 m->FindInt32("buttons", &buttons);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2970
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2971 int32 clicks = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2972 m->FindInt32("clicks", &clicks);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2973
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2974 int index = 0; // 0 means here - no tab found
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2975 for (int i = 0; i < CountTabs(); i++) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2976 if (TabFrame(i).Contains(point)) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2977 index = i + 1; // indexes are 1-based
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2978 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2979 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2980 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2981
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2982 int event = -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2983
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2984 if ((buttons & B_PRIMARY_MOUSE_BUTTON) && clicks > 1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2985 // left button double click on - create new tab
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2986 event = TABLINE_MENU_NEW;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2987
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2988 else if (buttons & B_TERTIARY_MOUSE_BUTTON)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2989 // middle button click - close the pointed tab
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2990 // or create new one in case empty space
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2991 event = index > 0 ? TABLINE_MENU_CLOSE : TABLINE_MENU_NEW;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2992
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2993 else if (buttons & B_SECONDARY_MOUSE_BUTTON) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2994 // right button click - show context menu
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2995 BPopUpMenu* popUpMenu = new BPopUpMenu("tabLineContextMenu", false, false);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2996 popUpMenu->AddItem(new BMenuItem(_("Close tabi R"), new BMessage(TABLINE_MENU_CLOSE)));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2997 popUpMenu->AddItem(new BMenuItem(_("New tab T"), new BMessage(TABLINE_MENU_NEW)));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2998 popUpMenu->AddItem(new BMenuItem(_("Open tab..."), new BMessage(TABLINE_MENU_OPEN)));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
2999
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3000 ConvertToScreen(&point);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3001 BMenuItem* item = popUpMenu->Go(point);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3002 if (item != NULL) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3003 event = item->Command();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3004 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3005
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3006 delete popUpMenu;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3007
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3008 } else {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3009 // default processing
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3010 BTabView::MouseDown(point);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3011 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3012 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3013
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3014 if (event < 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3015 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3016
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3017 VimTablineMenuMsg tmm;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3018 tmm.index = index;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3019 tmm.event = event;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3020 write_port(gui.vdcmp, VimMsg::TablineMenu, &tmm, sizeof(tmm));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3021 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3022
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3023 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3024 VimTabLine::VimTab::Select(BView* owner)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3025 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3026 BTab::Select(owner);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3027
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3028 VimTabLine *tabLine = gui.vimForm->TabLine();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3029 if (tabLine != NULL) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3030
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3031 int32 i = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3032 for (; i < tabLine->CountTabs(); i++)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3033 if (this == tabLine->TabAt(i))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3034 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3035
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3036 // printf("%d:%d:%s\n", i, tabLine->CountTabs(), tabLine->TabAt(i)->Label());
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3037 if (i < tabLine->CountTabs()) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3038 VimTablineMsg tm;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3039 tm.index = i + 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3040 write_port(gui.vdcmp, VimMsg::Tabline, &tm, sizeof(tm));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3041 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3042 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3043 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3044
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3045 #endif // defined(FEAT_GUI_TABLINE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3046
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3047 // ---------------- ----------------
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3048
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3049 // some global variables
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3050 static char appsig[] = "application/x-vnd.Haiku-Vim-8";
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3051 key_map *keyMap;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3052 char *keyMapChars;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3053 int main_exitcode = 127;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3054
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3055 status_t
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3056 gui_haiku_process_event(bigtime_t timeout)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3057 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3058 struct VimMsg vm;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3059 int32 what;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3060 ssize_t size;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3061
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3062 size = read_port_etc(gui.vdcmp, &what, &vm, sizeof(vm),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3063 B_TIMEOUT, timeout);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3064
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3065 if (size >= 0) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3066 switch (what) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3067 case VimMsg::Key:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3068 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3069 char_u *string = vm.u.Key.chars;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3070 int len = vm.u.Key.length;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3071 if (len == 1 && string[0] == Ctrl_chr('C')) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3072 trash_input_buf();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3073 got_int = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3074 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3075
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3076 if (vm.u.Key.csi_escape)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3077 #ifndef FEAT_MBYTE_IME
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3078 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3079 int i;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3080 char_u buf[2];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3081
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3082 for (i = 0; i < len; ++i)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3083 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3084 add_to_input_buf(string + i, 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3085 if (string[i] == CSI)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3086 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3087 // Turn CSI into K_CSI.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3088 buf[0] = KS_EXTRA;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3089 buf[1] = (int)KE_CSI;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3090 add_to_input_buf(buf, 2);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3091 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3092 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3093 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3094 #else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3095 add_to_input_buf_csi(string, len);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3096 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3097 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3098 add_to_input_buf(string, len);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3099 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3100 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3101 case VimMsg::Resize:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3102 gui_resize_shell(vm.u.NewSize.width, vm.u.NewSize.height);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3103 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3104 case VimMsg::ScrollBar:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3105 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3106 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3107 * If loads of scroll messages queue up, use only the last
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3108 * one. Always report when the scrollbar stops dragging.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3109 * This is not perfect yet anyway: these events are queued
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3110 * yet again, this time in the keyboard input buffer.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3111 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3112 int32 oldCount =
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3113 atomic_add(&vm.u.Scroll.sb->scrollEventCount, -1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3114 if (oldCount <= 1 || !vm.u.Scroll.stillDragging)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3115 gui_drag_scrollbar(vm.u.Scroll.sb->getGsb(),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3116 vm.u.Scroll.value, vm.u.Scroll.stillDragging);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3117 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3118 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3119 #if defined(FEAT_MENU)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3120 case VimMsg::Menu:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3121 gui_menu_cb(vm.u.Menu.guiMenu);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3122 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3123 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3124 case VimMsg::Mouse:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3125 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3126 int32 oldCount;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3127 if (vm.u.Mouse.button == MOUSE_DRAG)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3128 oldCount =
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3129 atomic_add(&gui.vimTextArea->mouseDragEventCount, -1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3130 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3131 oldCount = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3132 if (oldCount <= 1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3133 gui_send_mouse_event(vm.u.Mouse.button, vm.u.Mouse.x,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3134 vm.u.Mouse.y, vm.u.Mouse.repeated_click,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3135 vm.u.Mouse.modifiers);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3136 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3137 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3138 case VimMsg::MouseMoved:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3139 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3140 gui_mouse_moved(vm.u.MouseMoved.x, vm.u.MouseMoved.y);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3141 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3142 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3143 case VimMsg::Focus:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3144 gui.in_focus = vm.u.Focus.active;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3145 // XXX Signal that scrollbar dragging has stopped?
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3146 // This is needed because we don't get a MouseUp if
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3147 // that happens while outside the window... :-(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3148 if (gui.dragged_sb) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3149 gui.dragged_sb = SBAR_NONE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3150 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3151 // gui_update_cursor(TRUE, FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3152 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3153 case VimMsg::Refs:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3154 ::RefsReceived(vm.u.Refs.message, vm.u.Refs.changedir);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3155 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3156 case VimMsg::Tabline:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3157 send_tabline_event(vm.u.Tabline.index);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3158 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3159 case VimMsg::TablineMenu:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3160 send_tabline_menu_event(vm.u.TablineMenu.index, vm.u.TablineMenu.event);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3161 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3162 default:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3163 // unrecognised message, ignore it
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3164 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3165 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3166 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3167
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3168 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3169 * If size < B_OK, it is an error code.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3170 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3171 return size;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3172 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3173
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3174 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3175 * Here are some functions to protect access to ScreenLines[] and
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3176 * LineOffset[]. These are used from the window thread to respond
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3177 * to a Draw() callback. When that occurs, the window is already
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3178 * locked by the system.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3179 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3180 * Other code that needs to lock is any code that changes these
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3181 * variables. Other read-only access, or access merely to the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3182 * contents of the screen buffer, need not be locked.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3183 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3184 * If there is no window, don't call Lock() but do succeed.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3185 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3186
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3187 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3188 vim_lock_screen()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3189 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3190 return !gui.vimWindow || gui.vimWindow->Lock();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3191 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3192
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3193 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3194 vim_unlock_screen()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3195 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3196 if (gui.vimWindow)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3197 gui.vimWindow->Unlock();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3198 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3199
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3200 #define RUN_BAPPLICATION_IN_NEW_THREAD 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3201
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3202 #if RUN_BAPPLICATION_IN_NEW_THREAD
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3203
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3204 int32
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3205 run_vimapp(void *args)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3206 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3207 VimApp app(appsig);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3208
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3209 gui.vimApp = &app;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3210 app.Run(); // Run until Quit() called
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3211
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3212 return 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3213 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3214
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3215 #else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3216
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3217 int32
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3218 call_main(void *args)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3219 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3220 struct MainArgs *ma = (MainArgs *)args;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3221
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3222 return main(ma->argc, ma->argv);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3223 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3224 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3225
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3226 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3227 * Parse the GUI related command-line arguments. Any arguments used are
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3228 * deleted from argv, and *argc is decremented accordingly. This is called
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3229 * when vim is started, whether or not the GUI has been started.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3230 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3231 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3232 gui_mch_prepare(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3233 int *argc,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3234 char **argv)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3235 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3236 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3237 * We don't have any command line arguments for the BeOS GUI yet,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3238 * but this is an excellent place to create our Application object.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3239 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3240 if (!gui.vimApp) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3241 thread_info tinfo;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3242 get_thread_info(find_thread(NULL), &tinfo);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3243
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3244 // May need the port very early on to process RefsReceived()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3245 gui.vdcmp = create_port(B_MAX_PORT_COUNT, "vim VDCMP");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3246
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3247 #if RUN_BAPPLICATION_IN_NEW_THREAD
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3248 thread_id tid = spawn_thread(run_vimapp, "vim VimApp",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3249 tinfo.priority, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3250 if (tid >= B_OK) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3251 resume_thread(tid);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3252 } else {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3253 getout(1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3254 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3255 #else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3256 MainArgs ma = { *argc, argv };
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3257 thread_id tid = spawn_thread(call_main, "vim main()",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3258 tinfo.priority, &ma);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3259 if (tid >= B_OK) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3260 VimApp app(appsig);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3261
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3262 gui.vimApp = &app;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3263 resume_thread(tid);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3264 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3265 * This is rather horrible.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3266 * call_main will call main() again...
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3267 * There will be no infinite recursion since
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3268 * gui.vimApp is set now.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3269 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3270 app.Run(); // Run until Quit() called
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3271 // fprintf(stderr, "app.Run() returned...\n");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3272 status_t dummy_exitcode;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3273 (void)wait_for_thread(tid, &dummy_exitcode);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3274
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3275 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3276 * This path should be the normal one taken to exit Vim.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3277 * The main() thread calls mch_exit() which calls
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3278 * gui_mch_exit() which terminates its thread.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3279 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3280 exit(main_exitcode);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3281 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3282 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3283 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3284 // Don't fork() when starting the GUI. Spawned threads are not
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3285 // duplicated with a fork(). The result is a mess.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3286 gui.dofork = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3287 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3288 * XXX Try to determine whether we were started from
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3289 * the Tracker or the terminal.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3290 * It would be nice to have this work, because the Tracker
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3291 * follows symlinks, so even if you double-click on gvim,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3292 * when it is a link to vim it will still pass a command name
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3293 * of vim...
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3294 * We try here to see if stdin comes from /dev/null. If so,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3295 * (or if there is an error, which should never happen) start the GUI.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3296 * This does the wrong thing for vim - </dev/null, and we're
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3297 * too early to see the command line parsing. Tough.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3298 * On the other hand, it starts the gui for vim file & which is nice.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3299 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3300 if (!isatty(0)) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3301 struct stat stat_stdin, stat_dev_null;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3302
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3303 if (fstat(0, &stat_stdin) == -1 ||
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3304 stat("/dev/null", &stat_dev_null) == -1 ||
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3305 (stat_stdin.st_dev == stat_dev_null.st_dev &&
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3306 stat_stdin.st_ino == stat_dev_null.st_ino))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3307 gui.starting = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3308 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3309 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3310
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3311 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3312 * Check if the GUI can be started. Called before gvimrc is sourced.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3313 * Return OK or FAIL.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3314 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3315 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3316 gui_mch_init_check(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3317 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3318 return OK; // TODO: GUI can always be started?
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3319 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3320
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3321 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3322 * Initialise the GUI. Create all the windows, set up all the call-backs
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3323 * etc.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3324 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3325 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3326 gui_mch_init()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3327 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3328 display_errors();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3329 gui.def_norm_pixel = RGB(0x00, 0x00, 0x00); // black
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3330 gui.def_back_pixel = RGB(0xFF, 0xFF, 0xFF); // white
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3331 gui.norm_pixel = gui.def_norm_pixel;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3332 gui.back_pixel = gui.def_back_pixel;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3333
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3334 gui.scrollbar_width = (int) B_V_SCROLL_BAR_WIDTH;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3335 gui.scrollbar_height = (int) B_H_SCROLL_BAR_HEIGHT;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3336 #ifdef FEAT_MENU
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3337 gui.menu_height = 19; // initial guess -
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3338 // correct for my default settings
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3339 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3340 gui.border_offset = 3; // coordinates are inside window borders
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3341
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3342 if (gui.vdcmp < B_OK)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3343 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3344 get_key_map(&keyMap, &keyMapChars);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3345
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3346 gui.vimWindow = new VimWindow(); // hidden and locked
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3347 if (!gui.vimWindow)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3348 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3349
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3350 gui.vimWindow->Run(); // Run() unlocks but does not show
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3351
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3352 // Get the colors from the "Normal" group (set in syntax.c or in a vimrc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3353 // file)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3354 set_normal_colors();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3355
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3356 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3357 * Check that none of the colors are the same as the background color
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3358 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3359 gui_check_colors();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3360
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3361 // Get the colors for the highlight groups (gui_check_colors() might have
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3362 // changed them)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3363 highlight_gui_started(); // re-init colors and fonts
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3364
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3365 gui_mch_new_colors(); // window must exist for this
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3366
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3367 return OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3368 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3369
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3370 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3371 * Called when the foreground or background color has been changed.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3372 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3373 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3374 gui_mch_new_colors()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3375 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3376 rgb_color rgb = GUI_TO_RGB(gui.back_pixel);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3377
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3378 if (gui.vimWindow->Lock()) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3379 gui.vimForm->SetViewColor(rgb);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3380 // Does this not have too much effect for those small rectangles?
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3381 gui.vimForm->Invalidate();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3382 gui.vimWindow->Unlock();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3383 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3384 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3385
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3386 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3387 * Open the GUI window which was created by a call to gui_mch_init().
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3388 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3389 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3390 gui_mch_open()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3391 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3392 if (gui_win_x != -1 && gui_win_y != -1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3393 gui_mch_set_winpos(gui_win_x, gui_win_y);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3394
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3395 // Actually open the window
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3396 if (gui.vimWindow->Lock()) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3397 gui.vimWindow->Show();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3398 gui.vimWindow->Unlock();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3399 return OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3400 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3401
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3402 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3403 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3404
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3405 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3406 gui_mch_exit(int vim_exitcode)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3407 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3408 if (gui.vimWindow) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3409 thread_id tid = gui.vimWindow->Thread();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3410 gui.vimWindow->Lock();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3411 gui.vimWindow->Quit();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3412 // Wait until it is truly gone
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3413 int32 exitcode;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3414 wait_for_thread(tid, &exitcode);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3415 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3416 delete_port(gui.vdcmp);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3417 #if !RUN_BAPPLICATION_IN_NEW_THREAD
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3418 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3419 * We are in the main() thread - quit the App thread and
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3420 * quit ourselves (passing on the exitcode). Use a global since the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3421 * value from exit_thread() is only used if wait_for_thread() is
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3422 * called in time (race condition).
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3423 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3424 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3425 if (gui.vimApp) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3426 VimTextAreaView::guiBlankMouse(false);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3427
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3428 main_exitcode = vim_exitcode;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3429 #if RUN_BAPPLICATION_IN_NEW_THREAD
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3430 thread_id tid = gui.vimApp->Thread();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3431 int32 exitcode;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3432 gui.vimApp->Lock();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3433 gui.vimApp->Quit();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3434 gui.vimApp->Unlock();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3435 wait_for_thread(tid, &exitcode);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3436 #else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3437 gui.vimApp->Lock();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3438 gui.vimApp->Quit();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3439 gui.vimApp->Unlock();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3440 // suicide
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3441 exit_thread(vim_exitcode);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3442 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3443 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3444 // If we are somehow still here, let mch_exit() handle things.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3445 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3446
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3447 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3448 * Get the position of the top left corner of the window.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3449 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3450 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3451 gui_mch_get_winpos(int *x, int *y)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3452 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3453 if (gui.vimWindow->Lock()) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3454 BRect r;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3455 r = gui.vimWindow->Frame();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3456 gui.vimWindow->Unlock();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3457 *x = (int)r.left;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3458 *y = (int)r.top;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3459 return OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3460 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3461 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3462 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3463 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3464
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3465 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3466 * Set the position of the top left corner of the window to the given
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3467 * coordinates.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3468 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3469 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3470 gui_mch_set_winpos(int x, int y)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3471 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3472 if (gui.vimWindow->Lock()) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3473 gui.vimWindow->MoveTo(x, y);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3474 gui.vimWindow->Unlock();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3475 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3476 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3477
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3478 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3479 * Set the size of the window to the given width and height in pixels.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3480 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3481 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3482 gui_mch_set_shellsize(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3483 int width,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3484 int height,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3485 int min_width,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3486 int min_height,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3487 int base_width,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3488 int base_height,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3489 int direction) // TODO: utilize?
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3490 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3491 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3492 * We are basically given the size of the VimForm, if I understand
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3493 * correctly. Since it fills the window completely, this will also
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3494 * be the size of the window.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3495 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3496 if (gui.vimWindow->Lock()) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3497 gui.vimWindow->ResizeTo(width - PEN_WIDTH, height - PEN_WIDTH);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3498
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3499 // set size limits
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3500 float minWidth, maxWidth, minHeight, maxHeight;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3501
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3502 gui.vimWindow->GetSizeLimits(&minWidth, &maxWidth,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3503 &minHeight, &maxHeight);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3504 gui.vimWindow->SetSizeLimits(min_width, maxWidth,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3505 min_height, maxHeight);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3506
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3507 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3508 * Set the resizing alignment depending on font size.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3509 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3510 gui.vimWindow->SetWindowAlignment(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3511 B_PIXEL_ALIGNMENT, // window_alignment mode,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3512 1, // int32 h,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3513 0, // int32 hOffset = 0,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3514 gui.char_width, // int32 width = 0,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3515 base_width, // int32 widthOffset = 0,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3516 1, // int32 v = 0,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3517 0, // int32 vOffset = 0,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3518 gui.char_height, // int32 height = 0,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3519 base_height // int32 heightOffset = 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3520 );
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3521
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3522 gui.vimWindow->Unlock();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3523 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3524 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3525
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3526 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3527 gui_mch_get_screen_dimensions(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3528 int *screen_w,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3529 int *screen_h)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3530 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3531 BRect frame;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3532
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3533 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3534 BScreen screen(gui.vimWindow);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3535
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3536 if (screen.IsValid()) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3537 frame = screen.Frame();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3538 } else {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3539 frame.right = 640;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3540 frame.bottom = 480;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3541 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3542 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3543
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3544 // XXX approximations...
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3545 *screen_w = (int) frame.right - 2 * gui.scrollbar_width - 20;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3546 *screen_h = (int) frame.bottom - gui.scrollbar_height
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3547 #ifdef FEAT_MENU
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3548 - gui.menu_height
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3549 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3550 - 30;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3551 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3552
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3553 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3554 gui_mch_set_text_area_pos(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3555 int x,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3556 int y,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3557 int w,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3558 int h)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3559 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3560 if (!gui.vimTextArea)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3561 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3562
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3563 if (gui.vimWindow->Lock()) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3564 gui.vimTextArea->MoveTo(x, y);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3565 gui.vimTextArea->ResizeTo(w - PEN_WIDTH, h - PEN_WIDTH);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3566
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3567 #ifdef FEAT_GUI_TABLINE
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3568 if (gui.vimForm->TabLine() != NULL) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3569 gui.vimForm->TabLine()->ResizeTo(w, gui.vimForm->TablineHeight());
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3570 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3571 #endif // FEAT_GUI_TABLINE
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3572
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3573 gui.vimWindow->Unlock();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3574 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3575 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3576
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3577
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3578 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3579 * Scrollbar stuff:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3580 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3581
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3582 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3583 gui_mch_enable_scrollbar(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3584 scrollbar_T *sb,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3585 int flag)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3586 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3587 VimScrollBar *vsb = sb->id;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3588 if (gui.vimWindow->Lock()) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3589 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3590 * This function is supposed to be idempotent, but Show()/Hide()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3591 * is not. Therefore we test if they are needed.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3592 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3593 if (flag) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3594 if (vsb->IsHidden()) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3595 vsb->Show();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3596 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3597 } else {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3598 if (!vsb->IsHidden()) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3599 vsb->Hide();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3600 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3601 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3602 gui.vimWindow->Unlock();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3603 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3604 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3605
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3606 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3607 gui_mch_set_scrollbar_thumb(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3608 scrollbar_T *sb,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3609 int val,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3610 int size,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3611 int max)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3612 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3613 if (gui.vimWindow->Lock()) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3614 VimScrollBar *s = sb->id;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3615 if (max == 0) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3616 s->SetValue(0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3617 s->SetRange(0.0, 0.0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3618 } else {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3619 s->SetProportion((float)size / (max + 1.0));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3620 s->SetSteps(1.0, size > 5 ? size - 2 : size);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3621 #ifndef SCROLL_PAST_END // really only defined in gui.c...
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3622 max = max + 1 - size;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3623 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3624 if (max < s->Value()) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3625 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3626 * If the new maximum is lower than the current value,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3627 * setting it would cause the value to be clipped and
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3628 * therefore a ValueChanged() call.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3629 * We avoid this by setting the value first, because
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3630 * it presumably is <= max.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3631 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3632 s->SetValue(val);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3633 s->SetRange(0.0, max);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3634 } else {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3635 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3636 * In the other case, set the range first, since the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3637 * new value might be higher than the current max.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3638 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3639 s->SetRange(0.0, max);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3640 s->SetValue(val);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3641 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3642 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3643 gui.vimWindow->Unlock();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3644 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3645 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3646
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3647 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3648 gui_mch_set_scrollbar_pos(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3649 scrollbar_T *sb,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3650 int x,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3651 int y,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3652 int w,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3653 int h)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3654 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3655 if (gui.vimWindow->Lock()) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3656 BRect winb = gui.vimWindow->Bounds();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3657 float vsbx = x, vsby = y;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3658 VimScrollBar *vsb = sb->id;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3659 vsb->ResizeTo(w - PEN_WIDTH, h - PEN_WIDTH);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3660 if (winb.right-(x+w)<w) vsbx = winb.right - (w - PEN_WIDTH);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3661 vsb->MoveTo(vsbx, vsby);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3662 gui.vimWindow->Unlock();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3663 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3664 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3665
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3666 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3667 gui_mch_get_scrollbar_xpadding(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3668 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3669 // TODO: Calculate the padding for adjust scrollbar position when the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3670 // Window is maximized.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3671 return 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3672 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3673
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3674 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3675 gui_mch_get_scrollbar_ypadding(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3676 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3677 // TODO: Calculate the padding for adjust scrollbar position when the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3678 // Window is maximized.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3679 return 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3680 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3681
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3682 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3683 gui_mch_create_scrollbar(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3684 scrollbar_T *sb,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3685 int orient) // SBAR_VERT or SBAR_HORIZ
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3686 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3687 orientation posture =
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3688 (orient == SBAR_HORIZ) ? B_HORIZONTAL : B_VERTICAL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3689
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3690 VimScrollBar *vsb = sb->id = new VimScrollBar(sb, posture);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3691 if (gui.vimWindow->Lock()) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3692 vsb->SetTarget(gui.vimTextArea);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3693 vsb->Hide();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3694 gui.vimForm->AddChild(vsb);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3695 gui.vimWindow->Unlock();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3696 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3697 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3698
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3699 #if defined(FEAT_WINDOWS) || defined(FEAT_GUI_HAIKU) || defined(PROTO)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3700 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3701 gui_mch_destroy_scrollbar(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3702 scrollbar_T *sb)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3703 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3704 if (gui.vimWindow->Lock()) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3705 sb->id->RemoveSelf();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3706 delete sb->id;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3707 gui.vimWindow->Unlock();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3708 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3709 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3710 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3711
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3712 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3713 * Cursor does not flash
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3714 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3715 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3716 gui_mch_is_blink_off(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3717 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3718 return FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3719 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3720
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3721 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3722 * Cursor blink functions.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3723 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3724 * This is a simple state machine:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3725 * BLINK_NONE not blinking at all
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3726 * BLINK_OFF blinking, cursor is not shown
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3727 * BLINK_ON blinking, cursor is shown
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3728 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3729
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3730 #define BLINK_NONE 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3731 #define BLINK_OFF 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3732 #define BLINK_ON 2
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3733
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3734 static int blink_state = BLINK_NONE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3735 static long_u blink_waittime = 700;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3736 static long_u blink_ontime = 400;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3737 static long_u blink_offtime = 250;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3738 static int blink_timer = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3739
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3740 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3741 gui_mch_set_blinking(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3742 long waittime,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3743 long on,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3744 long off)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3745 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3746 // TODO
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3747 blink_waittime = waittime;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3748 blink_ontime = on;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3749 blink_offtime = off;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3750 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3751
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3752 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3753 * Stop the cursor blinking. Show the cursor if it wasn't shown.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3754 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3755 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3756 gui_mch_stop_blink(int may_call_gui_update_cursor)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3757 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3758 // TODO
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3759 if (blink_timer != 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3760 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3761 // XtRemoveTimeOut(blink_timer);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3762 blink_timer = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3763 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3764 if (blink_state == BLINK_OFF)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3765 gui_update_cursor(TRUE, FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3766 blink_state = BLINK_NONE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3767 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3768
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3769 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3770 * Start the cursor blinking. If it was already blinking, this restarts the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3771 * waiting time and shows the cursor.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3772 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3773 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3774 gui_mch_start_blink()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3775 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3776 // TODO
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3777 if (blink_timer != 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3778 ;// XtRemoveTimeOut(blink_timer);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3779 // Only switch blinking on if none of the times is zero
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3780 if (blink_waittime && blink_ontime && blink_offtime && gui.in_focus)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3781 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3782 blink_timer = 1; // XtAppAddTimeOut(app_context, blink_waittime,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3783 blink_state = BLINK_ON;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3784 gui_update_cursor(TRUE, FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3785 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3786 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3787
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3788 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3789 * Initialise vim to use the font with the given name. Return FAIL if the font
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3790 * could not be loaded, OK otherwise.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3791 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3792 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3793 gui_mch_init_font(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3794 char_u *font_name,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3795 int fontset)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3796 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3797 if (gui.vimWindow->Lock())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3798 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3799 int rc = gui.vimTextArea->mchInitFont(font_name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3800 gui.vimWindow->Unlock();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3801
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3802 return rc;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3803 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3804
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3805 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3806 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3807
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3808
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3809 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3810 gui_mch_adjust_charsize()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3811 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3812 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3813 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3814
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3815
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3816 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3817 gui_mch_font_dialog(font_family* family, font_style* style, float* size)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3818 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3819 #if defined(FEAT_GUI_DIALOG)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3820 // gui.vimWindow->Unlock();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3821 VimSelectFontDialog *dialog = new VimSelectFontDialog(family, style, size);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3822 return dialog->Go();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3823 #else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3824 return NOFONT;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3825 #endif // FEAT_GUI_DIALOG
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3826 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3827
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3828
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3829 GuiFont
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3830 gui_mch_get_font(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3831 char_u *name,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3832 int giveErrorIfMissing)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3833 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3834 static VimFont *fontList = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3835
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3836 if (!gui.in_use) // can't do this when GUI not running
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3837 return NOFONT;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3838
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3839 // storage for locally modified name;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3840 const int buff_size = B_FONT_FAMILY_LENGTH + B_FONT_STYLE_LENGTH + 20;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3841 static char font_name[buff_size] = {0};
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3842 font_family family = {0};
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3843 font_style style = {0};
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3844 float size = 0.f;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3845
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3846 if (name == 0 && be_fixed_font == 0) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3847 if (giveErrorIfMissing)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3848 semsg(_(e_unknown_font_str), name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3849 return NOFONT;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3850 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3851
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3852 bool useSelectGUI = false;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3853 if (name != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3854 if (STRCMP(name, "*") == 0) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3855 useSelectGUI = true;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3856 STRNCPY(font_name, hl_get_font_name(), buff_size);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3857 } else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3858 STRNCPY(font_name, name, buff_size);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3859
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3860 if (font_name[0] == 0) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3861 be_fixed_font->GetFamilyAndStyle(&family, &style);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3862 size = be_fixed_font->Size();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3863 vim_snprintf(font_name, buff_size,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3864 (char*)"%s/%s/%.0f", family, style, size);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3865 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3866
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3867 // replace underscores with spaces
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3868 char* end = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3869 while (end = strchr((char *)font_name, '_'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3870 *end = ' ';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3871
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3872 // store the name before strtok corrupt the buffer ;-)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3873 static char buff[buff_size] = {0};
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3874 STRNCPY(buff, font_name, buff_size);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3875 STRNCPY(family, strtok(buff, "/\0"), B_FONT_FAMILY_LENGTH);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3876 char* style_s = strtok(0, "/\0");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3877 if (style_s != 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3878 STRNCPY(style, style_s, B_FONT_STYLE_LENGTH);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3879 size = atof((style_s != 0) ? strtok(0, "/\0") : "0");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3880
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3881 if (useSelectGUI) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3882 if (gui_mch_font_dialog(&family, &style, &size) == NOFONT)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3883 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3884 // compose for further processing
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3885 vim_snprintf(font_name, buff_size,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3886 (char*)"%s/%s/%.0f", family, style, size);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3887 hl_set_font_name((char_u*)font_name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3888
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3889 // Set guifont to the name of the selected font.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3890 char_u* new_p_guifont = (char_u*)alloc(STRLEN(font_name) + 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3891 if (new_p_guifont != NULL) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3892 STRCPY(new_p_guifont, font_name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3893 vim_free(p_guifont);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3894 p_guifont = new_p_guifont;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3895 // Replace spaces in the font name with underscores.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3896 for ( ; *new_p_guifont; ++new_p_guifont)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3897 if (*new_p_guifont == ' ')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3898 *new_p_guifont = '_';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3899 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3900 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3901
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3902 VimFont *flp;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3903 for (flp = fontList; flp; flp = flp->next) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3904 if (STRCMP(font_name, flp->name) == 0) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3905 flp->refcount++;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3906 return (GuiFont)flp;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3907 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3908 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3909
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3910 VimFont *font = new VimFont();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3911 font->name = vim_strsave((char_u*)font_name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3912
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3913 if (count_font_styles(family) <= 0) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3914 if (giveErrorIfMissing)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3915 semsg(_(e_unknown_font_str), font->name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3916 delete font;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3917 return NOFONT;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3918 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3919
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3920 // Remember font in the static list for later use
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3921 font->next = fontList;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3922 fontList = font;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3923
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3924 font->SetFamilyAndStyle(family, style);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3925 if (size > 0.f)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3926 font->SetSize(size);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3927
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3928 font->SetSpacing(B_FIXED_SPACING);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3929 font->SetEncoding(B_UNICODE_UTF8);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3930
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3931 return (GuiFont)font;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3932 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3933
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3934 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3935 * Set the current text font.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3936 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3937 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3938 gui_mch_set_font(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3939 GuiFont font)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3940 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3941 if (gui.vimWindow->Lock()) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3942 VimFont *vf = (VimFont *)font;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3943
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3944 gui.vimTextArea->SetFont(vf);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3945
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3946 gui.char_width = (int) vf->StringWidth("n");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3947 font_height fh;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3948 vf->GetHeight(&fh);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3949 gui.char_height = (int)(fh.ascent + 0.9999)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3950 + (int)(fh.descent + 0.9999) + (int)(fh.leading + 0.9999);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3951 gui.char_ascent = (int)(fh.ascent + 0.9999);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3952
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3953 gui.vimWindow->Unlock();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3954 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3955 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3956
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3957 // XXX TODO This is apparently never called...
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3958 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3959 gui_mch_free_font(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3960 GuiFont font)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3961 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3962 if (font == NOFONT)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3963 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3964 VimFont *f = (VimFont *)font;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3965 if (--f->refcount <= 0) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3966 if (f->refcount < 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3967 fprintf(stderr, "VimFont: refcount < 0\n");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3968 delete f;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3969 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3970 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3971
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3972 char_u *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3973 gui_mch_get_fontname(GuiFont font, char_u *name)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3974 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3975 if (name == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3976 return NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3977 return vim_strsave(name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3978 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3979
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3980 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3981 * Adjust gui.char_height (after 'linespace' was changed).
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3982 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3983 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3984 gui_mch_adjust_charheight()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3985 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3986
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3987 // TODO: linespace support?
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3988
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3989 // #ifdef FEAT_XFONTSET
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3990 // if (gui.fontset != NOFONTSET)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3991 // {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3992 // gui.char_height = fontset_height((XFontSet)gui.fontset) + p_linespace;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3993 // gui.char_ascent = fontset_ascent((XFontSet)gui.fontset)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3994 // + p_linespace / 2;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3995 // }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3996 // else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3997 // #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3998 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
3999 VimFont *font = (VimFont *)gui.norm_font;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4000 font_height fh = {0};
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4001 font->GetHeight(&fh);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4002 gui.char_height = (int)(fh.ascent + fh.descent + 0.5) + p_linespace;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4003 gui.char_ascent = (int)(fh.ascent + 0.5) + p_linespace / 2;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4004 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4005 return OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4006 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4007
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4008 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4009 gui_mch_getmouse(int *x, int *y)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4010 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4011 fprintf(stderr, "gui_mch_getmouse");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4012
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4013 /*int rootx, rooty, winx, winy;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4014 Window root, child;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4015 unsigned int mask;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4016
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4017 if (gui.wid && XQueryPointer(gui.dpy, gui.wid, &root, &child,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4018 &rootx, &rooty, &winx, &winy, &mask)) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4019 *x = winx;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4020 *y = winy;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4021 } else*/ {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4022 *x = -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4023 *y = -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4024 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4025 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4026
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4027 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4028 gui_mch_mousehide(int hide)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4029 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4030 fprintf(stderr, "gui_mch_getmouse");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4031 // TODO
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4032 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4033
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4034 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4035 hex_digit(int c)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4036 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4037 if (isdigit(c))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4038 return c - '0';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4039 c = TOLOWER_ASC(c);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4040 if (c >= 'a' && c <= 'f')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4041 return c - 'a' + 10;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4042 return -1000;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4043 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4044
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4045 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4046 * This function has been lifted from gui_w32.c and extended a bit.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4047 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4048 * Return the Pixel value (color) for the given color name.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4049 * Return INVALCOLOR for error.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4050 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4051 guicolor_T
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4052 gui_mch_get_color(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4053 char_u *name)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4054 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4055 return gui_get_color_cmn(name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4056 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4057
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4058 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4059 * Set the current text foreground color.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4060 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4061 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4062 gui_mch_set_fg_color(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4063 guicolor_T color)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4064 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4065 rgb_color rgb = GUI_TO_RGB(color);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4066 if (gui.vimWindow->Lock()) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4067 gui.vimTextArea->SetHighColor(rgb);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4068 gui.vimWindow->Unlock();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4069 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4070 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4071
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4072 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4073 * Set the current text background color.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4074 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4075 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4076 gui_mch_set_bg_color(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4077 guicolor_T color)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4078 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4079 rgb_color rgb = GUI_TO_RGB(color);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4080 if (gui.vimWindow->Lock()) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4081 gui.vimTextArea->SetLowColor(rgb);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4082 gui.vimWindow->Unlock();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4083 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4084 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4085
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4086 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4087 * Set the current text special color.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4088 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4089 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4090 gui_mch_set_sp_color(guicolor_T color)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4091 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4092 // prev_sp_color = color;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4093 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4094
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4095 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4096 gui_mch_draw_string(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4097 int row,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4098 int col,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4099 char_u *s,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4100 int len,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4101 int flags)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4102 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4103 if (gui.vimWindow->Lock()) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4104 gui.vimTextArea->mchDrawString(row, col, s, len, flags);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4105 gui.vimWindow->Unlock();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4106 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4107 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4108
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4109 guicolor_T
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4110 gui_mch_get_rgb_color(int r, int g, int b)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4111 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4112 return gui_get_rgb_color_cmn(r, g, b);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4113 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4114
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4115
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4116 // Return OK if the key with the termcap name "name" is supported.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4117 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4118 gui_mch_haskey(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4119 char_u *name)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4120 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4121 int i;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4122
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4123 for (i = 0; special_keys[i].BeKeys != 0; i++)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4124 if (name[0] == special_keys[i].vim_code0 &&
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4125 name[1] == special_keys[i].vim_code1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4126 return OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4127 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4128 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4129
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4130 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4131 gui_mch_beep()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4132 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4133 ::beep();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4134 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4135
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4136 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4137 gui_mch_flash(int msec)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4138 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4139 // Do a visual beep by reversing the foreground and background colors
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4140
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4141 if (gui.vimWindow->Lock()) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4142 BRect rect = gui.vimTextArea->Bounds();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4143
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4144 gui.vimTextArea->SetDrawingMode(B_OP_INVERT);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4145 gui.vimTextArea->FillRect(rect);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4146 gui.vimTextArea->Sync();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4147 snooze(msec * 1000); // wait for a few msec
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4148 gui.vimTextArea->FillRect(rect);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4149 gui.vimTextArea->SetDrawingMode(B_OP_COPY);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4150 gui.vimTextArea->Flush();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4151 gui.vimWindow->Unlock();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4152 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4153 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4154
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4155 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4156 * Invert a rectangle from row r, column c, for nr rows and nc columns.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4157 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4158 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4159 gui_mch_invert_rectangle(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4160 int r,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4161 int c,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4162 int nr,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4163 int nc)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4164 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4165 BRect rect;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4166 rect.left = FILL_X(c);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4167 rect.top = FILL_Y(r);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4168 rect.right = rect.left + nc * gui.char_width - PEN_WIDTH;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4169 rect.bottom = rect.top + nr * gui.char_height - PEN_WIDTH;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4170
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4171 if (gui.vimWindow->Lock()) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4172 gui.vimTextArea->SetDrawingMode(B_OP_INVERT);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4173 gui.vimTextArea->FillRect(rect);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4174 gui.vimTextArea->SetDrawingMode(B_OP_COPY);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4175 gui.vimWindow->Unlock();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4176 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4177 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4178
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4179 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4180 * Iconify the GUI window.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4181 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4182 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4183 gui_mch_iconify()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4184 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4185 if (gui.vimWindow->Lock()) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4186 gui.vimWindow->Minimize(true);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4187 gui.vimWindow->Unlock();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4188 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4189 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4190
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4191 #if defined(FEAT_EVAL) || defined(PROTO)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4192 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4193 * Bring the Vim window to the foreground.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4194 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4195 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4196 gui_mch_set_foreground(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4197 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4198 // TODO
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4199 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4200 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4201
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4202 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4203 * Set the window title
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4204 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4205 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4206 gui_mch_settitle(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4207 char_u *title,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4208 char_u *icon)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4209 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4210 if (gui.vimWindow->Lock()) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4211 gui.vimWindow->SetTitle((char *)title);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4212 gui.vimWindow->Unlock();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4213 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4214 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4215
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4216 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4217 * Draw a cursor without focus.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4218 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4219 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4220 gui_mch_draw_hollow_cursor(guicolor_T color)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4221 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4222 gui_mch_set_fg_color(color);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4223
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4224 BRect r;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4225 r.left = FILL_X(gui.col);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4226 r.top = FILL_Y(gui.row);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4227 int cells = utf_off2cells(LineOffset[gui.row] + gui.col, 100); // TODO-TODO
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4228 if (cells>=4) cells = 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4229 r.right = r.left + cells*gui.char_width - PEN_WIDTH;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4230 r.bottom = r.top + gui.char_height - PEN_WIDTH;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4231
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4232 if (gui.vimWindow->Lock()) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4233 gui.vimTextArea->StrokeRect(r);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4234 gui.vimWindow->Unlock();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4235 // gui_mch_flush();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4236 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4237 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4238
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4239 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4240 * Draw part of a cursor, only w pixels wide, and h pixels high.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4241 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4242 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4243 gui_mch_draw_part_cursor(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4244 int w,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4245 int h,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4246 guicolor_T color)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4247 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4248 gui_mch_set_fg_color(color);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4249
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4250 BRect r;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4251 r.left =
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4252 #ifdef FEAT_RIGHTLEFT
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4253 // vertical line should be on the right of current point
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4254 CURSOR_BAR_RIGHT ? FILL_X(gui.col + 1) - w :
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4255 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4256 FILL_X(gui.col);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4257 r.right = r.left + w - PEN_WIDTH;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4258 r.bottom = FILL_Y(gui.row + 1) - PEN_WIDTH;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4259 r.top = r.bottom - h + PEN_WIDTH;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4260
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4261 if (gui.vimWindow->Lock()) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4262 gui.vimTextArea->FillRect(r);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4263 gui.vimWindow->Unlock();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4264 // gui_mch_flush();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4265 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4266 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4267
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4268 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4269 * Catch up with any queued events. This may put keyboard input into the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4270 * input buffer, call resize call-backs, trigger timers etc. If there is
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4271 * nothing in the event queue (& no timers pending), then we return
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4272 * immediately.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4273 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4274 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4275 gui_mch_update()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4276 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4277 gui_mch_flush();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4278 while (port_count(gui.vdcmp) > 0 &&
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4279 !vim_is_input_buf_full() &&
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4280 gui_haiku_process_event(0) >= B_OK)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4281 /* nothing */ ;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4282 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4283
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4284 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4285 * GUI input routine called by gui_wait_for_chars(). Waits for a character
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4286 * from the keyboard.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4287 * wtime == -1 Wait forever.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4288 * wtime == 0 This should never happen.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4289 * wtime > 0 Wait wtime milliseconds for a character.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4290 * Returns OK if a character was found to be available within the given time,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4291 * or FAIL otherwise.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4292 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4293 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4294 gui_mch_wait_for_chars(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4295 int wtime)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4296 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4297 int focus;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4298 bigtime_t until, timeout;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4299 status_t st;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4300
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4301 if (wtime >= 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4302 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4303 timeout = wtime * 1000;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4304 until = system_time() + timeout;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4305 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4306 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4307 timeout = B_INFINITE_TIMEOUT;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4308
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4309 focus = gui.in_focus;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4310 for (;;)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4311 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4312 // Stop or start blinking when focus changes
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4313 if (gui.in_focus != focus)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4314 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4315 if (gui.in_focus)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4316 gui_mch_start_blink();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4317 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4318 gui_mch_stop_blink(TRUE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4319 focus = gui.in_focus;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4320 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4321
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4322 gui_mch_flush();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4323
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4324 #ifdef MESSAGE_QUEUE
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4325 # ifdef FEAT_TIMERS
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4326 did_add_timer = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4327 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4328 parse_queued_messages();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4329 # ifdef FEAT_TIMERS
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4330 if (did_add_timer)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4331 // Need to recompute the waiting time.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4332 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4333 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4334 # ifdef FEAT_JOB_CHANNEL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4335 if (has_any_channel())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4336 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4337 if (wtime < 0 || timeout > 20000)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4338 timeout = 20000;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4339 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4340 else if (wtime < 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4341 timeout = B_INFINITE_TIMEOUT;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4342 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4343 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4344
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4345 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4346 * Don't use gui_mch_update() because then we will spin-lock until a
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4347 * char arrives, instead we use gui_haiku_process_event() to hang until
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4348 * an event arrives. No need to check for input_buf_full because we
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4349 * are returning as soon as it contains a single char.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4350 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4351 st = gui_haiku_process_event(timeout);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4352
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4353 if (input_available())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4354 return OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4355 if (st < B_OK) // includes B_TIMED_OUT
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4356 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4357
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4358 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4359 * Calculate how much longer we're willing to wait for the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4360 * next event.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4361 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4362 if (wtime >= 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4363 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4364 timeout = until - system_time();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4365 if (timeout < 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4366 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4367 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4368 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4369 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4370
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4371 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4372
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4373 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4374 * Output routines.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4375 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4376
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4377 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4378 * Flush any output to the screen. This is typically called before
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4379 * the app goes to sleep.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4380 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4381 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4382 gui_mch_flush()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4383 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4384 // does this need to lock the window? Apparently not but be safe.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4385 if (gui.vimWindow->Lock()) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4386 gui.vimWindow->Flush();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4387 gui.vimWindow->Unlock();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4388 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4389 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4390 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4391
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4392 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4393 * Clear a rectangular region of the screen from text pos (row1, col1) to
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4394 * (row2, col2) inclusive.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4395 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4396 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4397 gui_mch_clear_block(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4398 int row1,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4399 int col1,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4400 int row2,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4401 int col2)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4402 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4403 if (gui.vimWindow->Lock()) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4404 gui.vimTextArea->mchClearBlock(row1, col1, row2, col2);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4405 gui.vimWindow->Unlock();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4406 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4407 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4408
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4409 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4410 gui_mch_clear_all()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4411 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4412 if (gui.vimWindow->Lock()) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4413 gui.vimTextArea->mchClearAll();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4414 gui.vimWindow->Unlock();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4415 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4416 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4417
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4418 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4419 * Delete the given number of lines from the given row, scrolling up any
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4420 * text further down within the scroll region.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4421 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4422 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4423 gui_mch_delete_lines(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4424 int row,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4425 int num_lines)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4426 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4427 gui.vimTextArea->mchDeleteLines(row, num_lines);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4428 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4429
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4430 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4431 * Insert the given number of lines before the given row, scrolling down any
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4432 * following text within the scroll region.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4433 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4434 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4435 gui_mch_insert_lines(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4436 int row,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4437 int num_lines)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4438 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4439 gui.vimTextArea->mchInsertLines(row, num_lines);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4440 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4441
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4442 #if defined(FEAT_MENU) || defined(PROTO)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4443 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4444 * Menu stuff.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4445 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4446
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4447 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4448 gui_mch_enable_menu(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4449 int flag)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4450 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4451 if (gui.vimWindow->Lock())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4452 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4453 BMenuBar *menubar = gui.vimForm->MenuBar();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4454 menubar->SetEnabled(flag);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4455 gui.vimWindow->Unlock();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4456 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4457 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4458
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4459 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4460 gui_mch_set_menu_pos(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4461 int x,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4462 int y,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4463 int w,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4464 int h)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4465 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4466 // It will be in the right place anyway
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4467 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4468
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4469 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4470 * Add a sub menu to the menu bar.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4471 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4472 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4473 gui_mch_add_menu(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4474 vimmenu_T *menu,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4475 int idx)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4476 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4477 vimmenu_T *parent = menu->parent;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4478
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4479 // popup menu - just create it unattached
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4480 if (menu_is_popup(menu->name) && parent == NULL) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4481 BPopUpMenu* popUpMenu = new BPopUpMenu((const char*)menu->name, false, false);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4482 menu->submenu_id = popUpMenu;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4483 menu->id = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4484 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4485 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4486
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4487 if (!menu_is_menubar(menu->name)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4488 || (parent != NULL && parent->submenu_id == NULL))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4489 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4490
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4491 if (gui.vimWindow->Lock())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4492 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4493 // Major re-write of the menu code, it was failing with memory corruption when
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4494 // we started loading multiple files (the Buffer menu)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4495 //
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4496 // Note we don't use the preference values yet, all are inserted into the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4497 // menubar on a first come-first served basis...
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4498 //
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4499 // richard@whitequeen.com jul 99
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4500
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4501 BMenu *tmp;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4502
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4503 if ( parent )
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4504 tmp = parent->submenu_id;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4505 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4506 tmp = gui.vimForm->MenuBar();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4507 // make sure we don't try and add the same menu twice. The Buffers menu tries to
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4508 // do this and Be starts to crash...
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4509
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4510 if ( ! tmp->FindItem((const char *) menu->dname)) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4511
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4512 BMenu *bmenu = new BMenu((char *)menu->dname);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4513
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4514 menu->submenu_id = bmenu;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4515
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4516 // when we add a BMenu to another Menu, it creates the interconnecting BMenuItem
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4517 tmp->AddItem(bmenu);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4518
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4519 // Now it's safe to query the menu for the associated MenuItem...
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4520 menu->id = tmp->FindItem((const char *) menu->dname);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4521
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4522 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4523 gui.vimWindow->Unlock();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4524 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4525 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4526
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4527 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4528 gui_mch_toggle_tearoffs(int enable)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4529 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4530 // no tearoff menus
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4531 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4532
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4533 static BMessage *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4534 MenuMessage(vimmenu_T *menu)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4535 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4536 BMessage *m = new BMessage('menu');
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4537 m->AddPointer("VimMenu", (void *)menu);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4538
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4539 return m;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4540 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4541
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4542 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4543 * Add a menu item to a menu
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4544 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4545 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4546 gui_mch_add_menu_item(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4547 vimmenu_T *menu,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4548 int idx)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4549 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4550 int mnemonic = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4551 vimmenu_T *parent = menu->parent;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4552
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4553 // TODO: use menu->actext
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4554 // This is difficult, since on Be, an accelerator must be a single char
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4555 // and a lot of Vim ones are the standard VI commands.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4556 //
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4557 // Punt for Now...
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4558 // richard@whiequeen.com jul 99
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4559 if (gui.vimWindow->Lock())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4560 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4561 #ifdef FEAT_TOOLBAR
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4562 if (menu_is_toolbar(parent->name)) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4563 VimToolbar *toolbar = gui.vimForm->ToolBar();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4564 if (toolbar != NULL) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4565 toolbar->AddButton(idx, menu);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4566 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4567 } else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4568 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4569
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4570 if (parent->submenu_id != NULL || menu_is_popup(parent->name)) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4571 if (menu_is_separator(menu->name)) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4572 BSeparatorItem *item = new BSeparatorItem();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4573 parent->submenu_id->AddItem(item);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4574 menu->id = item;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4575 menu->submenu_id = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4576 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4577 else {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4578 BMenuItem *item = new BMenuItem((char *)menu->dname,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4579 MenuMessage(menu));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4580 item->SetTarget(gui.vimTextArea);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4581 item->SetTrigger((char) menu->mnemonic);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4582 parent->submenu_id->AddItem(item);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4583 menu->id = item;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4584 menu->submenu_id = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4585 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4586 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4587 gui.vimWindow->Unlock();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4588 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4589 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4590
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4591 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4592 * Destroy the machine specific menu widget.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4593 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4594 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4595 gui_mch_destroy_menu(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4596 vimmenu_T *menu)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4597 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4598 if (gui.vimWindow->Lock())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4599 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4600 #ifdef FEAT_TOOLBAR
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4601 if (menu->parent && menu_is_toolbar(menu->parent->name)) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4602 VimToolbar *toolbar = gui.vimForm->ToolBar();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4603 if (toolbar != NULL) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4604 toolbar->RemoveButton(menu);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4605 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4606 } else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4607 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4608 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4609 assert(menu->submenu_id == NULL || menu->submenu_id->CountItems() == 0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4610 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4611 * Detach this menu from its parent, so that it is not deleted
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4612 * twice once we get to delete that parent.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4613 * Deleting a BMenuItem also deletes the associated BMenu, if any
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4614 * (which does not have any items anymore since they were
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4615 * removed and deleted before).
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4616 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4617 BMenu *bmenu = menu->id->Menu();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4618 if (bmenu)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4619 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4620 bmenu->RemoveItem(menu->id);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4621 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4622 * If we removed the last item from the menu bar,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4623 * resize it out of sight.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4624 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4625 if (bmenu == gui.vimForm->MenuBar() && bmenu->CountItems() == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4626 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4627 bmenu->ResizeTo(-MENUBAR_MARGIN, -MENUBAR_MARGIN);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4628 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4629 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4630 delete menu->id;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4631 menu->id = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4632 menu->submenu_id = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4633
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4634 gui.menu_height = (int) gui.vimForm->MenuHeight();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4635 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4636 gui.vimWindow->Unlock();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4637 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4638 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4639
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4640 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4641 * Make a menu either grey or not grey.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4642 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4643 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4644 gui_mch_menu_grey(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4645 vimmenu_T *menu,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4646 int grey)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4647 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4648 #ifdef FEAT_TOOLBAR
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4649 if (menu->parent && menu_is_toolbar(menu->parent->name)) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4650 if (gui.vimWindow->Lock()) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4651 VimToolbar *toolbar = gui.vimForm->ToolBar();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4652 if (toolbar != NULL) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4653 toolbar->GrayButton(menu, grey);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4654 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4655 gui.vimWindow->Unlock();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4656 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4657 } else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4658 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4659 if (menu->id != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4660 menu->id->SetEnabled(!grey);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4661 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4662
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4663 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4664 * Make menu item hidden or not hidden
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4665 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4666 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4667 gui_mch_menu_hidden(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4668 vimmenu_T *menu,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4669 int hidden)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4670 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4671 if (menu->id != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4672 menu->id->SetEnabled(!hidden);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4673 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4674
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4675 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4676 * This is called after setting all the menus to grey/hidden or not.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4677 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4678 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4679 gui_mch_draw_menubar()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4680 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4681 // Nothing to do in BeOS
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4682 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4683
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4684 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4685 gui_mch_show_popupmenu(vimmenu_T *menu)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4686 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4687 if (!menu_is_popup(menu->name) || menu->submenu_id == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4688 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4689
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4690 BPopUpMenu* popupMenu = dynamic_cast<BPopUpMenu*>(menu->submenu_id);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4691 if (popupMenu == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4692 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4693
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4694 BPoint point;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4695 if (gui.vimWindow->Lock()) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4696 uint32 buttons = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4697 gui.vimTextArea->GetMouse(&point, &buttons);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4698 gui.vimTextArea->ConvertToScreen(&point);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4699 gui.vimWindow->Unlock();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4700 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4701 popupMenu->Go(point, true);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4702 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4703
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4704 #endif // FEAT_MENU
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4705
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4706 // Mouse stuff
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4707
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4708 #ifdef FEAT_CLIPBOARD
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4709 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4710 * Clipboard stuff, for cutting and pasting text to other windows.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4711 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4712 char textplain[] = "text/plain";
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4713 char vimselectiontype[] = "application/x-vnd.Rhialto-Vim-selectiontype";
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4714
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4715 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4716 * Get the current selection and put it in the clipboard register.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4717 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4718 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4719 clip_mch_request_selection(Clipboard_T *cbd)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4720 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4721 if (be_clipboard->Lock())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4722 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4723 BMessage *m = be_clipboard->Data();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4724 // m->PrintToStream();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4725
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4726 char_u *string = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4727 ssize_t stringlen = -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4728
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4729 if (m->FindData(textplain, B_MIME_TYPE,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4730 (const void **)&string, &stringlen) == B_OK
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4731 || m->FindString("text", (const char **)&string) == B_OK)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4732 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4733 if (stringlen == -1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4734 stringlen = STRLEN(string);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4735
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4736 int type;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4737 char *seltype;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4738 ssize_t seltypelen;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4739
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4740 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4741 * Try to get the special vim selection type first
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4742 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4743 if (m->FindData(vimselectiontype, B_MIME_TYPE,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4744 (const void **)&seltype, &seltypelen) == B_OK)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4745 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4746 switch (*seltype)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4747 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4748 default:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4749 case 'L': type = MLINE; break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4750 case 'C': type = MCHAR; break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4751 #ifdef FEAT_VISUAL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4752 case 'B': type = MBLOCK; break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4753 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4754 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4755 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4756 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4757 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4758 // Otherwise use heuristic as documented
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4759 type = memchr(string, stringlen, '\n') ? MLINE : MCHAR;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4760 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4761 clip_yank_selection(type, string, (long)stringlen, cbd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4762 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4763 be_clipboard->Unlock();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4764 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4765 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4766 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4767 * Make vim the owner of the current selection.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4768 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4769 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4770 clip_mch_lose_selection(Clipboard_T *cbd)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4771 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4772 // Nothing needs to be done here
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4773 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4774
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4775 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4776 * Make vim the owner of the current selection. Return OK upon success.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4777 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4778 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4779 clip_mch_own_selection(Clipboard_T *cbd)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4780 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4781 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4782 * Never actually own the clipboard. If another application sets the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4783 * clipboard, we don't want to think that we still own it.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4784 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4785 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4786 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4787
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4788 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4789 * Send the current selection to the clipboard.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4790 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4791 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4792 clip_mch_set_selection(Clipboard_T *cbd)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4793 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4794 if (be_clipboard->Lock())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4795 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4796 be_clipboard->Clear();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4797 BMessage *m = be_clipboard->Data();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4798 assert(m);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4799
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4800 // If the '*' register isn't already filled in, fill it in now
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4801 cbd->owned = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4802 clip_get_selection(cbd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4803 cbd->owned = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4804
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4805 char_u *str = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4806 long_u count;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4807 int type;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4808
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4809 type = clip_convert_selection(&str, &count, cbd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4810
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4811 if (type < 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4812 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4813
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4814 m->AddData(textplain, B_MIME_TYPE, (void *)str, count);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4815
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4816 // Add type of selection
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4817 char vtype;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4818 switch (type)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4819 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4820 default:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4821 case MLINE: vtype = 'L'; break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4822 case MCHAR: vtype = 'C'; break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4823 #ifdef FEAT_VISUAL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4824 case MBLOCK: vtype = 'B'; break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4825 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4826 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4827 m->AddData(vimselectiontype, B_MIME_TYPE, (void *)&vtype, 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4828
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4829 vim_free(str);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4830
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4831 be_clipboard->Commit();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4832 be_clipboard->Unlock();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4833 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4834 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4835
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4836 #endif // FEAT_CLIPBOARD
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4837
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4838 #ifdef FEAT_BROWSE
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4839 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4840 * Pop open a file browser and return the file selected, in allocated memory,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4841 * or NULL if Cancel is hit.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4842 * saving - TRUE if the file will be saved to, FALSE if it will be opened.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4843 * title - Title message for the file browser dialog.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4844 * dflt - Default name of file.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4845 * ext - Default extension to be added to files without extensions.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4846 * initdir - directory in which to open the browser (NULL = current dir)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4847 * filter - Filter for matched files to choose from.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4848 * Has a format like this:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4849 * "C Files (*.c)\0*.c\0"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4850 * "All Files\0*.*\0\0"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4851 * If these two strings were concatenated, then a choice of two file
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4852 * filters will be selectable to the user. Then only matching files will
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4853 * be shown in the browser. If NULL, the default allows all files.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4854 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4855 * *NOTE* - the filter string must be terminated with TWO nulls.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4856 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4857 char_u *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4858 gui_mch_browse(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4859 int saving,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4860 char_u *title,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4861 char_u *dflt,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4862 char_u *ext,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4863 char_u *initdir,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4864 char_u *filter)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4865 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4866 gui.vimApp->fFilePanel = new BFilePanel((saving == TRUE) ? B_SAVE_PANEL : B_OPEN_PANEL,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4867 NULL, NULL, 0, false,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4868 new BMessage((saving == TRUE) ? 'save' : 'open'), NULL, true);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4869
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4870 gui.vimApp->fBrowsedPath.Unset();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4871
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4872 gui.vimApp->fFilePanel->Window()->SetTitle((char*)title);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4873 gui.vimApp->fFilePanel->SetPanelDirectory((const char*)initdir);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4874
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4875 gui.vimApp->fFilePanel->Show();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4876
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4877 gui.vimApp->fFilePanelSem = create_sem(0, "FilePanelSem");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4878
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4879 while (acquire_sem(gui.vimApp->fFilePanelSem) == B_INTERRUPTED);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4880
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4881 char_u *fileName = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4882 status_t result = gui.vimApp->fBrowsedPath.InitCheck();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4883 if (result == B_OK) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4884 fileName = vim_strsave((char_u*)gui.vimApp->fBrowsedPath.Path());
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4885 } else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4886 if (result != B_NO_INIT) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4887 fprintf(stderr, "gui_mch_browse: BPath error: %#08x (%s)\n",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4888 result, strerror(result));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4889 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4890
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4891 delete gui.vimApp->fFilePanel;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4892 gui.vimApp->fFilePanel = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4893
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4894 return fileName;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4895 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4896 #endif // FEAT_BROWSE
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4897
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4898
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4899 #if defined(FEAT_GUI_DIALOG)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4900
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4901 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4902 * Create a dialog dynamically from the parameter strings.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4903 * type = type of dialog (question, alert, etc.)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4904 * title = dialog title. may be NULL for default title.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4905 * message = text to display. Dialog sizes to accommodate it.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4906 * buttons = '\n' separated list of button captions, default first.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4907 * dfltbutton = number of default button.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4908 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4909 * This routine returns 1 if the first button is pressed,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4910 * 2 for the second, etc.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4911 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4912 * 0 indicates Esc was pressed.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4913 * -1 for unexpected error
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4914 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4915 * If stubbing out this fn, return 1.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4916 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4917
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4918 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4919 gui_mch_dialog(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4920 int type,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4921 char_u *title,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4922 char_u *message,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4923 char_u *buttons,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4924 int dfltbutton,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4925 char_u *textfield,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4926 int ex_cmd)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4927 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4928 VimDialog *dialog = new VimDialog(type, (char*)title, (char*)message,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4929 (char*)buttons, dfltbutton, (char*)textfield, ex_cmd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4930 return dialog->Go();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4931 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4932
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4933 #endif // FEAT_GUI_DIALOG
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4934
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4935
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4936 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4937 * Return the RGB value of a pixel as long.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4938 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4939 guicolor_T
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4940 gui_mch_get_rgb(guicolor_T pixel)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4941 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4942 rgb_color rgb = GUI_TO_RGB(pixel);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4943
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4944 return ((rgb.red & 0xff) << 16) + ((rgb.green & 0xff) << 8)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4945 + (rgb.blue & 0xff);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4946 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4947
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4948 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4949 gui_mch_setmouse(int x, int y)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4950 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4951 TRACE();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4952 // TODO
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4953 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4954
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4955 #ifdef FEAT_MBYTE_IME
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4956 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4957 im_set_position(int row, int col)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4958 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4959 if (gui.vimWindow->Lock())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4960 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4961 gui.vimTextArea->DrawIMString();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4962 gui.vimWindow->Unlock();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4963 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4964 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4965 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4966 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4967
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4968 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4969 gui_mch_show_toolbar(int showit)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4970 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4971 VimToolbar *toolbar = gui.vimForm->ToolBar();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4972 gui.toolbar_height = (toolbar && showit) ? toolbar->ToolbarHeight() : 0.;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4973 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4974
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4975 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4976 gui_mch_set_toolbar_pos(int x, int y, int w, int h)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4977 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4978 VimToolbar *toolbar = gui.vimForm->ToolBar();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4979 if (toolbar != NULL) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4980 if (gui.vimWindow->Lock()) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4981 toolbar->MoveTo(x, y);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4982 toolbar->ResizeTo(w - 1, h - 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4983 gui.vimWindow->Unlock();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4984 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4985 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4986 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4987
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4988 #if defined(FEAT_GUI_TABLINE) || defined(PROTO)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4989
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4990 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4991 * Show or hide the tabline.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4992 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4993 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4994 gui_mch_show_tabline(int showit)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4995 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4996 VimTabLine *tabLine = gui.vimForm->TabLine();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4997
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4998 if (tabLine == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
4999 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5000
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5001 if (!showit != !gui.vimForm->IsShowingTabLine()) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5002 gui.vimForm->SetShowingTabLine(showit != 0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5003 gui.tabline_height = gui.vimForm->TablineHeight();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5004 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5005 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5006
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5007 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5008 gui_mch_set_tabline_pos(int x, int y, int w, int h)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5009 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5010 VimTabLine *tabLine = gui.vimForm->TabLine();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5011 if (tabLine != NULL) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5012 if (gui.vimWindow->Lock()) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5013 tabLine->MoveTo(x, y);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5014 tabLine->ResizeTo(w - 1, h - 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5015 gui.vimWindow->Unlock();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5016 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5017 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5018 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5019
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5020 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5021 * Return TRUE when tabline is displayed.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5022 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5023 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5024 gui_mch_showing_tabline()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5025 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5026 VimTabLine *tabLine = gui.vimForm->TabLine();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5027 return tabLine != NULL && gui.vimForm->IsShowingTabLine();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5028 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5029
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5030 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5031 * Update the labels of the tabline.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5032 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5033 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5034 gui_mch_update_tabline()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5035 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5036 tabpage_T *tp;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5037 int nr = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5038 int curtabidx = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5039
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5040 VimTabLine *tabLine = gui.vimForm->TabLine();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5041
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5042 if (tabLine == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5043 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5044
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5045 gui.vimWindow->Lock();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5046
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5047 // Add a label for each tab page. They all contain the same text area.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5048 for (tp = first_tabpage; tp != NULL; tp = tp->tp_next, ++nr) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5049 if (tp == curtab)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5050 curtabidx = nr;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5051
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5052 BTab* tab = tabLine->TabAt(nr);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5053
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5054 if (tab == NULL) {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5055 tab = new VimTabLine::VimTab();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5056 tabLine->AddTab(NULL, tab);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5057 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5058
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5059 get_tabline_label(tp, FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5060 tab->SetLabel((const char*)NameBuff);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5061 tabLine->Invalidate();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5062 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5063
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5064 // Remove any old labels.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5065 while (nr < tabLine->CountTabs())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5066 tabLine->RemoveTab(nr);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5067
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5068 if (tabLine->Selection() != curtabidx)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5069 tabLine->Select(curtabidx);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5070
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5071 gui.vimWindow->Unlock();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5072 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5073
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5074 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5075 * Set the current tab to "nr". First tab is 1.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5076 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5077 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5078 gui_mch_set_curtab(int nr)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5079 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5080 VimTabLine *tabLine = gui.vimForm->TabLine();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5081 if (tabLine == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5082 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5083
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5084 gui.vimWindow->Lock();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5085
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5086 if (tabLine->Selection() != nr -1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5087 tabLine->Select(nr -1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5088
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5089 gui.vimWindow->Unlock();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5090 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5091
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32425
diff changeset
5092 #endif // FEAT_GUI_TABLINE