| 1 |
bluedwarf |
12 |
# window.rb: the module definition of Edmaru::Window. |
| 2 |
bluedwarf |
10 |
# |
| 3 |
|
|
# Copyright (C) 2007 Takashi Nakamoto |
| 4 |
|
|
# |
| 5 |
|
|
# This program is free software; you can redistribute it and/or modify |
| 6 |
|
|
# it under the terms of the GNU General Public License version 2 as |
| 7 |
|
|
# published by the Free Software Foundation. |
| 8 |
|
|
# |
| 9 |
|
|
# This program is distributed in the hope that it will be useful, but |
| 10 |
|
|
# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 |
|
|
# General Public License for more details. |
| 13 |
|
|
# |
| 14 |
|
|
# You should have received a copy of the GNU General Public License |
| 15 |
|
|
# along with this program; if not, write to the Free Software |
| 16 |
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
| 17 |
|
|
# 02110-1301 USA. |
| 18 |
|
|
# |
| 19 |
bluedwarf |
4 |
|
| 20 |
bluedwarf |
9 |
require "cursor.rb" |
| 21 |
bluedwarf |
5 |
require "modeline.rb" |
| 22 |
|
|
|
| 23 |
bluedwarf |
4 |
module Edmaru |
| 24 |
bluedwarf |
5 |
|
| 25 |
bluedwarf |
6 |
#Abstract class to implement system specific window. |
| 26 |
bluedwarf |
5 |
module Window |
| 27 |
|
|
|
| 28 |
bluedwarf |
6 |
#Construct a window instance. |
| 29 |
bluedwarf |
5 |
# |
| 30 |
bluedwarf |
6 |
#=== Arguments |
| 31 |
|
|
#_view_ :: The parent view. |
| 32 |
|
|
#_x_ :: The left edge position in the parent view. |
| 33 |
|
|
#_y_ :: The top edge position in the parent view. |
| 34 |
|
|
#_col_ :: The max column size allocated for this window. |
| 35 |
|
|
#_row_ :: The max line size allocated for this window including |
| 36 |
|
|
#ModeLine's line size (usually 1). |
| 37 |
|
|
# |
| 38 |
|
|
#=== Warning |
| 39 |
|
|
#This method *MUST* *NOT* be overrided in derived classes. |
| 40 |
|
|
# |
| 41 |
|
|
#=== Return |
| 42 |
|
|
#An initialized instance of Window. |
| 43 |
|
|
def initialize(view, x, y, col, row) |
| 44 |
|
|
@view = view |
| 45 |
bluedwarf |
9 |
@cursor = Cursor.new(0, 0) |
| 46 |
|
|
|
| 47 |
bluedwarf |
6 |
init_ui(x, y, col, row - 1) |
| 48 |
|
|
|
| 49 |
|
|
#Creating modeline bar. |
| 50 |
|
|
@modeline = Edmaru::modeline_class.new(self, x, y + row - 1, col) |
| 51 |
|
|
element = ModeLineElement.new("buffer-name", -1, 1, 1,"*scratch#{$count}*") |
| 52 |
|
|
@modeline.add_element(element) |
| 53 |
|
|
@modeline.show_element("buffer-name") |
| 54 |
bluedwarf |
4 |
end |
| 55 |
|
|
|
| 56 |
bluedwarf |
6 |
#The system specific initialization for this window. |
| 57 |
|
|
# |
| 58 |
|
|
#=== Arguments |
| 59 |
|
|
#_x_ :: The left edge position in the parent view. |
| 60 |
|
|
#_y_ :: The top edge position in the parent view. |
| 61 |
|
|
#_col_ :: The max column size allocated for this window. |
| 62 |
|
|
#_row_ :: The max line size allocated for this window excluding |
| 63 |
|
|
#ModeLine's line size (usually 1). |
| 64 |
|
|
# |
| 65 |
|
|
#=== Warning |
| 66 |
|
|
#This method *SHOULD* be overrided in derived classes. |
| 67 |
|
|
#And it *MUST* *NOT* deal with anything about modeline bar. |
| 68 |
|
|
def init_ui(x, y, col, row) |
| 69 |
bluedwarf |
5 |
end |
| 70 |
|
|
|
| 71 |
bluedwarf |
9 |
#Discard the current buffer and set the specified new buffer. |
| 72 |
|
|
# |
| 73 |
|
|
#=== Argument |
| 74 |
|
|
#_new_buffer_ :: The buffer to be shown in this window. |
| 75 |
|
|
def buffer=(new_buffer) |
| 76 |
|
|
if @buffer != nil |
| 77 |
|
|
@buffer.unlink(self) |
| 78 |
|
|
end |
| 79 |
bluedwarf |
4 |
|
| 80 |
bluedwarf |
9 |
#Linked buffer to this window. |
| 81 |
|
|
@buffer = new_buffer |
| 82 |
|
|
@buffer.link(self) |
| 83 |
|
|
refresh |
| 84 |
bluedwarf |
4 |
end |
| 85 |
|
|
|
| 86 |
bluedwarf |
9 |
def buffer |
| 87 |
|
|
@buffer |
| 88 |
bluedwarf |
4 |
end |
| 89 |
|
|
|
| 90 |
bluedwarf |
9 |
#Redraw this window. |
| 91 |
|
|
# |
| 92 |
|
|
#=== Warning |
| 93 |
|
|
#This method *SHOULD* be overrided in derived clases. |
| 94 |
bluedwarf |
4 |
def refresh |
| 95 |
bluedwarf |
9 |
if @buffer == nil |
| 96 |
|
|
return |
| 97 |
|
|
end |
| 98 |
bluedwarf |
4 |
end |
| 99 |
|
|
|
| 100 |
bluedwarf |
6 |
#Terminate this view instance. |
| 101 |
|
|
# |
| 102 |
|
|
#=== Warning |
| 103 |
bluedwarf |
7 |
#This method *MUST* *NOT* be overrided in derived classes. |
| 104 |
bluedwarf |
4 |
def terminate |
| 105 |
bluedwarf |
7 |
@modeline.terminate |
| 106 |
|
|
|
| 107 |
|
|
terminate_ui |
| 108 |
bluedwarf |
4 |
end |
| 109 |
bluedwarf |
7 |
|
| 110 |
|
|
#Free system specific resources. |
| 111 |
|
|
# |
| 112 |
|
|
#=== Warning |
| 113 |
|
|
#This method *SHOULD* be overrided in derived classes. |
| 114 |
|
|
def terminate_ui |
| 115 |
|
|
end |
| 116 |
bluedwarf |
4 |
end |
| 117 |
|
|
end |