forked from vim/vim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gui_haiku.cc
5094 lines (4388 loc) · 120 KB
/
gui_haiku.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* vi:set ts=8 sts=4 sw=4:
*
* VIM - Vi IMproved by Bram Moolenaar
* BeBox GUI support Copyright 1998 by Olaf Seibert.
* All Rights Reserved.
*
* Do ":help uganda" in Vim to read copying and usage conditions.
* Do ":help credits" in Vim to see a list of people who contributed.
*
* Based on "GUI support for the Buzzword Enhanced Operating System."
*
* Ported to R4 by Richard Offer <[email protected]> Jul 99
*
* Haiku support by Siarzhuk Zharski <[email protected]> Apr-Mai 2009
*
*/
/*
* Structure of the Haiku GUI code:
*
* There are 3 threads.
* 1. The initial thread. In gui_mch_prepare() this gets to run the
* BApplication message loop. But before it starts doing that,
* it creates thread 2
* 2. The main() thread. This thread is created in gui_mch_prepare()
* and its purpose in life is to call main(argc, argv) again.
* This thread is doing the bulk of the work.
* 3. Sooner or later, a window is opened by the main() thread. This
* causes a second message loop to be created: the window thread.
*
* == alternatively ===
*
* #if RUN_BAPPLICATION_IN_NEW_THREAD...
*
* 1. The initial thread. In gui_mch_prepare() this gets to spawn
* thread 2. After doing that, it returns to main() to do the
* bulk of the work, being the main() thread.
* 2. Runs the BApplication.
* 3. The window thread, just like in the first case.
*
* This second alternative is cleaner from Vim's viewpoint. However,
* the BeBook seems to assume everywhere that the BApplication *must*
* run in the initial thread. So perhaps doing otherwise is very wrong.
*
* However, from a B_SINGLE_LAUNCH viewpoint, the first is better.
* If Vim is marked "Single Launch" in its application resources,
* and a file is dropped on the Vim icon, and another Vim is already
* running, the file is passed on to the earlier Vim. This happens
* in BApplication::Run(). So we want Vim to terminate if
* BApplication::Run() terminates. (See the BeBook, on BApplication.
* However, it seems that the second copy of Vim isn't even started
* in this case... which is for the better since I wouldn't know how
* to detect this case.)
*
* Communication between these threads occurs mostly by translating
* BMessages that come in and posting an appropriate translation on
* the VDCMP (Vim Direct Communication Message Port). Therefore the
* actions required for keypresses and window resizes, etc, are mostly
* performed in the main() thread.
*
* A notable exception to this is the Draw() event. The redrawing of
* the window contents is performed asynchronously from the window
* thread. To make this work correctly, a locking protocol is used when
* any thread is accessing the essential variables that are used by
* the window thread.
*
* This locking protocol consists of locking Vim's window. This is both
* convenient and necessary.
*/
extern "C" {
#include <assert.h>
#include <float.h>
#include <syslog.h>
#include "vim.h"
#include "globals.h"
#include "proto.h"
#include "version.h"
} // extern "C"
// ---------------- start of header part ----------------
//#include <Alert.h>
#include <Application.h>
#include <Beep.h>
#include <Bitmap.h>
#include <Box.h>
#include <Button.h>
#include <Clipboard.h>
#include <Debug.h>
//#include <Directory.h>
//#include <Entry.h>
#include <File.h>
#include <FilePanel.h>
#include <FindDirectory.h>
//#include <Font.h>
#include <IconUtils.h>
#include <Input.h>
#include <ListView.h>
#include <MenuBar.h>
#include <MenuItem.h>
//#include <MessageQueue.h>
//#include <OS.h>
#include <Path.h>
#include <PictureButton.h>
#include <PopUpMenu.h>
//#include <Region.h>
#include <Resources.h>
//#include <Roster.h>
#include <Screen.h>
#include <ScrollBar.h>
#include <ScrollView.h>
#include <String.h>
#include <StringView.h>
//#include <SupportDefs.h>
#include <TabView.h>
#include <TextControl.h>
#include <TextView.h>
#include <TranslationUtils.h>
#include <TranslatorFormats.h>
#include <View.h>
#include <Window.h>
class VimApp;
class VimFormView;
class VimTextAreaView;
class VimWindow;
class VimToolbar;
class VimTabLine;
extern key_map *keyMap;
extern char *keyMapChars;
extern int main(int argc, char **argv);
#ifndef B_MAX_PORT_COUNT
#define B_MAX_PORT_COUNT 255
#endif
// VimApp seems comparable to the X "vimShell"
class VimApp: public BApplication
{
typedef BApplication Inherited;
public:
VimApp(const char *appsig);
~VimApp();
// callbacks:
#if 0
virtual void DispatchMessage(BMessage *m, BHandler *h)
{
m->PrintToStream();
Inherited::DispatchMessage(m, h);
}
#endif
virtual void ReadyToRun();
virtual void ArgvReceived(int32 argc, char **argv);
virtual void RefsReceived(BMessage *m);
virtual bool QuitRequested();
virtual void MessageReceived(BMessage *m);
static void SendRefs(BMessage *m, bool changedir);
sem_id fFilePanelSem;
BFilePanel* fFilePanel;
BPath fBrowsedPath;
private:
};
class VimWindow: public BWindow
{
typedef BWindow Inherited;
public:
VimWindow();
~VimWindow();
// virtual void DispatchMessage(BMessage *m, BHandler *h);
virtual void WindowActivated(bool active);
virtual bool QuitRequested();
VimFormView *formView;
private:
void init();
};
class VimFormView: public BView
{
typedef BView Inherited;
public:
VimFormView(BRect frame);
~VimFormView();
// callbacks:
virtual void AllAttached();
virtual void FrameResized(float new_width, float new_height);
#define MENUBAR_MARGIN 1
float MenuHeight() const
{ return menuBar ? menuBar->Frame().Height() + MENUBAR_MARGIN: 0; }
BMenuBar *MenuBar() const
{ return menuBar; }
private:
void init(BRect);
BMenuBar *menuBar;
VimTextAreaView *textArea;
#ifdef FEAT_TOOLBAR
public:
float ToolbarHeight() const;
VimToolbar *ToolBar() const
{ return toolBar; }
private:
VimToolbar *toolBar;
#endif
#ifdef FEAT_GUI_TABLINE
public:
VimTabLine *TabLine() const { return tabLine; }
bool IsShowingTabLine() const { return showingTabLine; }
void SetShowingTabLine(bool showing) { showingTabLine = showing; }
float TablineHeight() const;
private:
VimTabLine *tabLine;
int showingTabLine;
#endif
};
class VimTextAreaView: public BView
{
typedef BView Inherited;
public:
VimTextAreaView(BRect frame);
~VimTextAreaView();
// callbacks:
virtual void Draw(BRect updateRect);
virtual void KeyDown(const char *bytes, int32 numBytes);
virtual void MouseDown(BPoint point);
virtual void MouseUp(BPoint point);
virtual void MouseMoved(BPoint point, uint32 transit, const BMessage *message);
virtual void MessageReceived(BMessage *m);
// own functions:
int mchInitFont(char_u *name);
void mchDrawString(int row, int col, char_u *s, int len, int flags);
void mchClearBlock(int row1, int col1, int row2, int col2);
void mchClearAll();
void mchDeleteLines(int row, int num_lines);
void mchInsertLines(int row, int num_lines);
static void guiSendMouseEvent(int button, int x, int y, int repeated_click, int_u modifiers);
static void guiMouseMoved(int x, int y);
static void guiBlankMouse(bool should_hide);
static int_u mouseModifiersToVim(int32 beModifiers);
int32 mouseDragEventCount;
#ifdef FEAT_MBYTE_IME
void DrawIMString(void);
#endif
private:
void init(BRect);
int_u vimMouseButton;
int_u vimMouseModifiers;
#ifdef FEAT_MBYTE_IME
struct {
BMessenger* messenger;
BMessage* message;
BPoint location;
int row;
int col;
int count;
} IMData;
#endif
};
class VimScrollBar: public BScrollBar
{
typedef BScrollBar Inherited;
public:
VimScrollBar(scrollbar_T *gsb, orientation posture);
~VimScrollBar();
virtual void ValueChanged(float newValue);
virtual void MouseUp(BPoint where);
void SetValue(float newval);
scrollbar_T *getGsb()
{ return gsb; }
int32 scrollEventCount;
private:
scrollbar_T *gsb;
float ignoreValue;
};
#ifdef FEAT_TOOLBAR
class VimToolbar : public BBox
{
static BBitmap *normalButtonsBitmap;
static BBitmap *grayedButtonsBitmap;
BBitmap *LoadVimBitmap(const char* fileName);
bool GetPictureFromBitmap(BPicture *pictureTo, int32 index, BBitmap *bitmapFrom, bool pressed);
bool ModifyBitmapToGrayed(BBitmap *bitmap);
BList fButtonsList;
void InvalidateLayout();
public:
VimToolbar(BRect frame, const char * name);
~VimToolbar();
bool PrepareButtonBitmaps();
bool AddButton(int32 index, vimmenu_T *menu);
bool RemoveButton(vimmenu_T *menu);
bool GrayButton(vimmenu_T *menu, int grey);
float ToolbarHeight() const;
virtual void AttachedToWindow();
};
BBitmap *VimToolbar::normalButtonsBitmap = NULL;
BBitmap *VimToolbar::grayedButtonsBitmap = NULL;
const float ToolbarMargin = 3.;
const float ButtonMargin = 3.;
#endif //FEAT_TOOLBAR
#ifdef FEAT_GUI_TABLINE
class VimTabLine : public BTabView
{
public:
class VimTab : public BTab {
public:
VimTab() : BTab(new BView(BRect(), "-Empty-", 0, 0)) {}
virtual void Select(BView* owner);
};
VimTabLine(BRect r) : BTabView(r, "vimTabLine", B_WIDTH_FROM_LABEL,
B_FOLLOW_LEFT | B_FOLLOW_TOP | B_FOLLOW_RIGHT, B_WILL_DRAW | B_FRAME_EVENTS) {}
float TablineHeight() const;
virtual void MouseDown(BPoint point);
};
#endif //FEAT_GUI_TABLINE
// For caching the fonts that are used;
// Vim seems rather sloppy in this regard.
class VimFont: public BFont
{
typedef BFont Inherited;
public:
VimFont();
VimFont(const VimFont *rhs);
VimFont(const BFont *rhs);
VimFont(const VimFont &rhs);
~VimFont();
VimFont *next;
int refcount;
char_u *name;
private:
void init();
};
#if defined(FEAT_GUI_DIALOG)
class VimDialog : public BWindow
{
typedef BWindow Inherited;
BButton* _CreateButton(int32 which, const char* label);
public:
class View : public BView {
typedef BView Inherited;
public:
View(BRect frame);
~View();
virtual void Draw(BRect updateRect);
void InitIcon(int32 type);
private:
BBitmap* fIconBitmap;
};
VimDialog(int type, const char *title, const char *message,
const char *buttons, int dfltbutton, const char *textfield,
int ex_cmd);
~VimDialog();
int Go();
virtual void MessageReceived(BMessage *msg);
private:
sem_id fDialogSem;
int fDialogValue;
BList fButtonsList;
BTextView* fMessageView;
BTextControl* fInputControl;
const char* fInputValue;
};
class VimSelectFontDialog : public BWindow
{
typedef BWindow Inherited;
void _CleanList(BListView* list);
void _UpdateFontStyles();
void _UpdateSizeInputPreview();
void _UpdateFontPreview();
bool _UpdateFromListItem(BListView* list, char* text, int textSize);
public:
VimSelectFontDialog(font_family* family, font_style* style, float* size);
~VimSelectFontDialog();
bool Go();
virtual void MessageReceived(BMessage *msg);
private:
status_t fStatus;
sem_id fDialogSem;
bool fDialogValue;
font_family* fFamily;
font_style* fStyle;
float* fSize;
font_family fFontFamily;
font_style fFontStyle;
float fFontSize;
BStringView* fPreview;
BListView* fFamiliesList;
BListView* fStylesList;
BListView* fSizesList;
BTextControl* fSizesInput;
};
#endif // FEAT_GUI_DIALOG
// ---------------- end of GUI classes ----------------
struct MainArgs {
int argc;
char **argv;
};
// These messages are copied through the VDCMP.
// Therefore they ought not to have anything fancy.
// They must be of POD type (Plain Old Data)
// as the C++ standard calls them.
#define KEY_MSG_BUFSIZ 7
#if KEY_MSG_BUFSIZ < MAX_KEY_CODE_LEN
#error Increase KEY_MSG_BUFSIZ!
#endif
struct VimKeyMsg {
char_u length;
char_u chars[KEY_MSG_BUFSIZ]; // contains Vim encoding
bool csi_escape;
};
struct VimResizeMsg {
int width;
int height;
};
struct VimScrollBarMsg {
VimScrollBar *sb;
long value;
int stillDragging;
};
struct VimMenuMsg {
vimmenu_T *guiMenu;
};
struct VimMouseMsg {
int button;
int x;
int y;
int repeated_click;
int_u modifiers;
};
struct VimMouseMovedMsg {
int x;
int y;
};
struct VimFocusMsg {
bool active;
};
struct VimRefsMsg {
BMessage *message;
bool changedir;
};
struct VimTablineMsg {
int index;
};
struct VimTablineMenuMsg {
int index;
int event;
};
struct VimMsg {
enum VimMsgType {
Key, Resize, ScrollBar, Menu, Mouse, MouseMoved, Focus, Refs, Tabline, TablineMenu
};
union {
struct VimKeyMsg Key;
struct VimResizeMsg NewSize;
struct VimScrollBarMsg Scroll;
struct VimMenuMsg Menu;
struct VimMouseMsg Mouse;
struct VimMouseMovedMsg MouseMoved;
struct VimFocusMsg Focus;
struct VimRefsMsg Refs;
struct VimTablineMsg Tabline;
struct VimTablineMenuMsg TablineMenu;
} u;
};
#define RGB(r, g, b) ((char_u)(r) << 16 | (char_u)(g) << 8 | (char_u)(b) << 0)
#define GUI_TO_RGB(g) { (char_u)((g) >> 16), (char_u)((g) >> 8), (char_u)((g) >> 0), 255 }
// ---------------- end of header part ----------------
static struct specialkey
{
uint16 BeKeys;
#define KEY(a,b) ((a)<<8|(b))
#define K(a) KEY(0,a) // for ASCII codes
#define F(b) KEY(1,b) // for scancodes
char_u vim_code0;
char_u vim_code1;
} special_keys[] =
{
{K(B_UP_ARROW), 'k', 'u'},
{K(B_DOWN_ARROW), 'k', 'd'},
{K(B_LEFT_ARROW), 'k', 'l'},
{K(B_RIGHT_ARROW), 'k', 'r'},
{K(B_BACKSPACE), 'k', 'b'},
{K(B_INSERT), 'k', 'I'},
{K(B_DELETE), 'k', 'D'},
{K(B_HOME), 'k', 'h'},
{K(B_END), '@', '7'},
{K(B_PAGE_UP), 'k', 'P'}, // XK_Prior
{K(B_PAGE_DOWN), 'k', 'N'}, // XK_Next,
#define FIRST_FUNCTION_KEY 11
{F(B_F1_KEY), 'k', '1'},
{F(B_F2_KEY), 'k', '2'},
{F(B_F3_KEY), 'k', '3'},
{F(B_F4_KEY), 'k', '4'},
{F(B_F5_KEY), 'k', '5'},
{F(B_F6_KEY), 'k', '6'},
{F(B_F7_KEY), 'k', '7'},
{F(B_F8_KEY), 'k', '8'},
{F(B_F9_KEY), 'k', '9'},
{F(B_F10_KEY), 'k', ';'},
{F(B_F11_KEY), 'F', '1'},
{F(B_F12_KEY), 'F', '2'},
// {XK_F13, 'F', '3'}, // would be print screen
// sysreq
{F(0x0F), 'F', '4'}, // scroll lock
{F(0x10), 'F', '5'}, // pause/break
// {XK_F16, 'F', '6'},
// {XK_F17, 'F', '7'},
// {XK_F18, 'F', '8'},
// {XK_F19, 'F', '9'},
// {XK_F20, 'F', 'A'},
// {XK_F21, 'F', 'B'},
// {XK_F22, 'F', 'C'},
// {XK_F23, 'F', 'D'},
// {XK_F24, 'F', 'E'},
// {XK_F25, 'F', 'F'},
// {XK_F26, 'F', 'G'},
// {XK_F27, 'F', 'H'},
// {XK_F28, 'F', 'I'},
// {XK_F29, 'F', 'J'},
// {XK_F30, 'F', 'K'},
// {XK_F31, 'F', 'L'},
// {XK_F32, 'F', 'M'},
// {XK_F33, 'F', 'N'},
// {XK_F34, 'F', 'O'},
// {XK_F35, 'F', 'P'}, // keysymdef.h defines up to F35
// {XK_Help, '%', '1'}, // XK_Help
{F(B_PRINT_KEY), '%', '9'},
#if 0
// Keypad keys:
{F(0x48), 'k', 'l'}, // XK_KP_Left
{F(0x4A), 'k', 'r'}, // XK_KP_Right
{F(0x38), 'k', 'u'}, // XK_KP_Up
{F(0x59), 'k', 'd'}, // XK_KP_Down
{F(0x64), 'k', 'I'}, // XK_KP_Insert
{F(0x65), 'k', 'D'}, // XK_KP_Delete
{F(0x37), 'k', 'h'}, // XK_KP_Home
{F(0x58), '@', '7'}, // XK_KP_End
{F(0x39), 'k', 'P'}, // XK_KP_Prior
{F(0x60), 'k', 'N'}, // XK_KP_Next
{F(0x49), '&', '8'}, // XK_Undo, keypad 5
#endif
// End of list marker:
{0, 0, 0}
};
#define NUM_SPECIAL_KEYS ARRAY_LENGTH(special_keys)
// ---------------- VimApp ----------------
static void
docd(BPath &path)
{
mch_chdir((char *)path.Path());
// Do this to get the side effects of a :cd command
do_cmdline_cmd((char_u *)"cd .");
}
static void
drop_callback(void *cookie)
{
// TODO here we could handle going to a specific position in the dropped
// file (see src/gui_mac.c, deleted in 8.2.1422)
// Update the screen display
update_screen(UPD_NOT_VALID);
}
// Really handle dropped files and folders.
static void
RefsReceived(BMessage *m, bool changedir)
{
uint32 type;
int32 count;
m->PrintToStream();
switch (m->what) {
case B_REFS_RECEIVED:
case B_SIMPLE_DATA:
m->GetInfo("refs", &type, &count);
if (type != B_REF_TYPE)
goto bad;
break;
case B_ARGV_RECEIVED:
m->GetInfo("argv", &type, &count);
if (type != B_STRING_TYPE)
goto bad;
if (changedir) {
char *dirname;
if (m->FindString("cwd", (const char **) &dirname) == B_OK) {
chdir(dirname);
do_cmdline_cmd((char_u *)"cd .");
}
}
break;
default:
bad:
/*fprintf(stderr, "bad!\n"); */
delete m;
return;
}
#ifdef FEAT_VISUAL
reset_VIsual();
#endif
char_u **fnames;
fnames = (char_u **) alloc(count * sizeof(char_u *));
int fname_index = 0;
switch (m->what) {
case B_REFS_RECEIVED:
case B_SIMPLE_DATA:
// fprintf(stderr, "case B_REFS_RECEIVED\n");
for (int i = 0; i < count; ++i)
{
entry_ref ref;
if (m->FindRef("refs", i, &ref) == B_OK) {
BEntry entry(&ref, false);
BPath path;
entry.GetPath(&path);
// Change to parent directory?
if (changedir) {
BPath parentpath;
path.GetParent(&parentpath);
docd(parentpath);
}
// Is it a directory? If so, cd into it.
BDirectory bdir(&ref);
if (bdir.InitCheck() == B_OK) {
// don't cd if we already did it
if (!changedir)
docd(path);
} else {
mch_dirname(IObuff, IOSIZE);
char_u *fname = shorten_fname((char_u *)path.Path(), IObuff);
if (fname == NULL)
fname = (char_u *)path.Path();
fnames[fname_index++] = vim_strsave(fname);
// fprintf(stderr, "%s\n", fname);
}
// Only do it for the first file/dir
changedir = false;
}
}
break;
case B_ARGV_RECEIVED:
// fprintf(stderr, "case B_ARGV_RECEIVED\n");
for (int i = 1; i < count; ++i)
{
char *fname;
if (m->FindString("argv", i, (const char **) &fname) == B_OK) {
fnames[fname_index++] = vim_strsave((char_u *)fname);
}
}
break;
default:
// fprintf(stderr, "case default\n");
break;
}
delete m;
// Handle the drop, :edit to get to the file
if (fname_index > 0) {
handle_drop(fname_index, fnames, FALSE, drop_callback, NULL);
setcursor();
out_flush();
} else {
vim_free(fnames);
}
}
VimApp::VimApp(const char *appsig):
BApplication(appsig),
fFilePanelSem(-1),
fFilePanel(NULL)
{
}
VimApp::~VimApp()
{
}
void
VimApp::ReadyToRun()
{
/*
* Apparently signals are inherited by the created thread -
* disable the most annoying ones.
*/
signal(SIGINT, SIG_IGN);
signal(SIGQUIT, SIG_IGN);
}
void
VimApp::ArgvReceived(int32 arg_argc, char **arg_argv)
{
if (!IsLaunching()) {
/*
* This can happen if we are set to Single or Exclusive
* Launch. Be nice and open the file(s).
*/
if (gui.vimWindow)
gui.vimWindow->Minimize(false);
BMessage *m = CurrentMessage();
DetachCurrentMessage();
SendRefs(m, true);
}
}
void
VimApp::RefsReceived(BMessage *m)
{
// Horrible hack!!! XXX XXX XXX
// The real problem is that b_start_ffc is set too late for
// the initial empty buffer. As a result the window will be
// split instead of abandoned.
int limit = 15;
while (--limit >= 0 && (curbuf == NULL || curbuf->b_start_ffc == 0))
snooze(100000); // 0.1 s
if (gui.vimWindow)
gui.vimWindow->Minimize(false);
DetachCurrentMessage();
SendRefs(m, true);
}
/*
* Pass a BMessage on to the main() thread.
* Caller must have detached the message.
*/
void
VimApp::SendRefs(BMessage *m, bool changedir)
{
VimRefsMsg rm;
rm.message = m;
rm.changedir = changedir;
write_port(gui.vdcmp, VimMsg::Refs, &rm, sizeof(rm));
// calls ::RefsReceived
}
void
VimApp::MessageReceived(BMessage *m)
{
switch (m->what) {
case 'save':
{
entry_ref refDirectory;
m->FindRef("directory", &refDirectory);
fBrowsedPath.SetTo(&refDirectory);
BString strName;
m->FindString("name", &strName);
fBrowsedPath.Append(strName.String());
}
break;
case 'open':
{
entry_ref ref;
m->FindRef("refs", &ref);
fBrowsedPath.SetTo(&ref);
}
break;
case B_CANCEL:
{
BFilePanel *panel;
m->FindPointer("source", (void**)&panel);
if (fFilePanelSem != -1 && panel == fFilePanel)
{
delete_sem(fFilePanelSem);
fFilePanelSem = -1;
}
}
break;
default:
Inherited::MessageReceived(m);
break;
}
}
bool
VimApp::QuitRequested()
{
(void)Inherited::QuitRequested();
return false;
}
// ---------------- VimWindow ----------------
VimWindow::VimWindow():
BWindow(BRect(40, 40, 150, 150),
"Vim",
B_TITLED_WINDOW,
0,
B_CURRENT_WORKSPACE)
{
init();
}
VimWindow::~VimWindow()
{
if (formView) {
RemoveChild(formView);
delete formView;
}
gui.vimWindow = NULL;
}
void
VimWindow::init()
{
// Attach the VimFormView
formView = new VimFormView(Bounds());
if (formView != NULL) {
AddChild(formView);
}
}
#if 0 // disabled in zeta patch
void
VimWindow::DispatchMessage(BMessage *m, BHandler *h)
{
/*
* Route B_MOUSE_UP messages to MouseUp(), in
* a manner that should be compatible with the
* intended future system behaviour.
*/
switch (m->what) {
case B_MOUSE_UP:
// if (!h) h = PreferredHandler();
// gcc isn't happy without this extra set of braces, complains about
// jump to case label crosses init of 'class BView * v'
// [email protected] jul 99
{
BView *v = dynamic_cast<BView *>(h);
if (v) {
// m->PrintToStream();
BPoint where;
m->FindPoint("where", &where);
v->MouseUp(where);
} else {
Inherited::DispatchMessage(m, h);
}
}
break;
default:
Inherited::DispatchMessage(m, h);
}
}
#endif
void
VimWindow::WindowActivated(bool active)
{
Inherited::WindowActivated(active);
// the textArea gets the keyboard action
if (active && gui.vimTextArea)
gui.vimTextArea->MakeFocus(true);
struct VimFocusMsg fm;
fm.active = active;
write_port(gui.vdcmp, VimMsg::Focus, &fm, sizeof(fm));
}
bool
VimWindow::QuitRequested()
{
struct VimKeyMsg km;
km.length = 5;
memcpy((char *)km.chars, "\033:qa\r", km.length);
km.csi_escape = false;
write_port(gui.vdcmp, VimMsg::Key, &km, sizeof(km));
return false;
}
// ---------------- VimFormView ----------------
VimFormView::VimFormView(BRect frame):
BView(frame, "VimFormView", B_FOLLOW_ALL_SIDES,
B_WILL_DRAW | B_FRAME_EVENTS),
menuBar(NULL),
#ifdef FEAT_TOOLBAR
toolBar(NULL),
#endif
#ifdef FEAT_GUI_TABLINE
// showingTabLine(false),
tabLine(NULL),
#endif
textArea(NULL)
{
init(frame);
}
VimFormView::~VimFormView()
{
if (menuBar) {
RemoveChild(menuBar);
#ifdef never
// deleting the menuBar leads to SEGV on exit