前段时间把 gtk 的 plugin 搞定了, 下一步就得把 scintilla 集成进来了.
这里保存一个简单的 gtk plugin 例子以便以后查阅.
这个 plugin 实现的功能很简单, 就是把 gtk 的 tutorial 里的第二个例子给实现了.
单击 “Hello World” Button 调用 gprintf 在终端显示 Hello World.
这个例子里, widget 有了, event handle 也有了. 麻雀虽小, 五脏俱全地说.

plugin.h

?Download plugin.h
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
#ifndef __PLUGIN_H__
#define __PLUGIN_H__
 
/* Xlib/Xt stuff */
#include <x11 /Xlib.h>
#include </x11><x11 /Intrinsic.h>
#include </x11><x11 /cursorfont.h>
 
#include <gtk /gtk.h>
 
#include "pluginbase.h"
 
class nsPluginInstance : public nsPluginInstanceBase {
public:
    nsPluginInstance(NPP aInstance);
    virtual ~nsPluginInstance();
 
    NPBool init(NPWindow* aWindow);
    void shut();
    NPBool isInitialized() {
        return mInitialized;
    }
    NPError GetValue(NPPVariable variable, void *value);
    NPError SetWindow(NPWindow* aWindow);
 
    // locals
    const char * getVersion();
 
private:
    NPP mInstance;
    NPBool mInitialized;
 
    GtkWidget* m_GtkWidget;
    GtkWidget *button;
 
    Window mWindow;
 
    int mX, mY;
    int mWidth, mHeight;
 
};
 
#endif // __PLUGIN_H__
 
</gtk></x11>

Read the rest of this entry »

Tags: , ,

最近折腾了好久, 才总算大致弄明白了如何编写一个 mozilla 的 plugin. 这玩意儿的资料也实在太少了, 相对与 Extension 和 XPCom 而言…
关于 plugin 的一些机制和原理, 可以从 Gecko_Plugin_API_Reference 获得.
在这我主要是提下怎么编译一个 Plugin(感谢 Paul 的热心帮助)
相关工具: gecko sdk 以及 mozilla source
关于 plugin 的示例我们可以在 mozilla/modules/plugin/tools/sdk/samples 里找到.
以下给出个编译 basic 的 Makefile

?Download Makefile
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
CXX   = g++
CPPFLAGS += -fno-rtti \
-fno-exceptions \
-shared  
 
# Change this to point at your Gecko SDK directory. 
GECKO_SDK_PATH = /home/duo/gecko-sdk
 
GECKO_DEFINES  = -DMOZ_X11 -DMOZILLA_STRICT_API
 
GECKO_INCLUDES = -I $(GECKO_SDK_PATH)/include
 
PLUGIN_INCLUDES = -I ../../include
 
GECKO_LDFLAGS =  -L $(GECKO_SDK_PATH)/lib -rdynamic  -lXi -lXext -lX11 -lm -lXt
 
FILES = plugin.cpp ../../common/*.cpp
 
TARGET = libpluginbasic.so
 
build: 
	$(CXX) -Wall -Os -o $(TARGET) $(GECKO_CONFIG_INCLUDE) $(GECKO_DEFINES) $(PLUGIN_INCLUDES) \
	$(GECKO_INCLUDES) $(GECKO_LDFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(FILES)
 
clean: 
	rm $(TARGET)

编译后将 libpluginbasic.so 拷贝至 .mozilla/plugins 目录下即可.

PS1: 下一步得搞定怎么写一个使用 GTK 库的 Plugin 了…继续研究 mplayer-plugin 中…
PS2: 关于 IE 浏览本 Blog 的时候 simple page 似乎会因为 coolcode 生成的高亮代码过长移动到下方…这个问题我现在也不知道怎么解决, 所以还是推荐大家用 Firefox 吧…

Tags: , ,

放出个 JavaScript 代码语法高亮类, 是根据 Unnamed Blog 上的修改的(原文提供的下载后有不少错误…), 效率比我原来写的高了不少. 当然, 我自己最后估计还是拿 Lex 来做…

主要修改的地方首先是让整个 js 可运行(-_-!)…然后完善了一些功能, 比如对 & 和 < 的处理, 还有把其它语言的支持分离开来.

首先是 cpp 高亮的支持 js 文件

sh.Brushes.Cpp = function() {}

sh.Brushes.Cpp.aliases = ‘cpp’;

sh.Brushes.Cpp.regexList = [
{regex: new RegExp('//.*$', 'gm'), css: 'comment'}, // one line comments
{regex: new RegExp('/\\*[\\s\\S]*?\\*/’, ‘g’), css: ‘comment’}, // multi line comments
{regex: new RegExp(“\’(?:[^\\\\']|\\\\.)*\’|” +
“\”(?:[^\\\\\"]|\\\\.)*\”", ‘g’), css: ’string’}, // string literals
{regex: new RegExp(‘^\\s*#.*’, ‘gm’), css: ‘preprocessor’}, // preprocessor directives
{regex: new RegExp(‘\\b(?:auto|break|case|char|const|continue|default|do’ +
‘double|else|enum|extern|float|for|goto|if|int|long|register’ +
‘return|short|signed|sizeof|static|struct|switch|typedef|union’ +
‘unsigned|void|volatile|while)\\b’, ‘gm’), css: ‘keyword’} // keyword
];

Read the rest of this entry »

Tags: ,