File: vmessage.C

package info (click to toggle)
mixviews 1.20-10.1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 2,928 kB
  • ctags: 5,960
  • sloc: cpp: 32,879; ansic: 2,110; makefile: 445; sh: 17
file content (145 lines) | stat: -rw-r--r-- 3,693 bytes parent folder | download | duplicates (4)
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
// vmessage.C

/******************************************************************************
 *
 *  MiXViews - an X window system based sound & data editor/processor
 *
 *  Copyright (c) 1993, 1994 Regents of the University of California
 *
 *  Author:     Douglas Scott
 *  Date:       December 13, 1994
 *
 *  Permission to use, copy and modify this software and its documentation
 *  for research and/or educational purposes and without fee is hereby granted,
 *  provided that the above copyright notice appear in all copies and that
 *  both that copyright notice and this permission notice appear in
 *  supporting documentation. The author reserves the right to distribute this
 *  software and its documentation.  The University of California and the author
 *  make no representations about the suitability of this software for any 
 *  purpose, and in no event shall University of California be liable for any
 *  damage, loss of data, or profits resulting from its use.
 *  It is provided "as is" without express or implied warranty.
 *
 ******************************************************************************/


#ifdef __GNUG__
#pragma implementation
#endif

#include <InterViews/canvas.h>
#include <InterViews/font.h>
#include <InterViews/pattern.h>
#include <InterViews/painter.h>
#include <InterViews/resource.h>
#include <InterViews/scene.h>
#include <InterViews/shape.h>
#include <InterViews/style.h>
#include <InterViews/window.h>
#include <InterViews/world.h>
#include <IV-X11/xwindow.h>
#include "localdefs.h"
#include "vmessage.h"

VMessage::VMessage(const char* msg, Alignment al, int pad, boolean enabld)
	: Message(msg, al, pad, 0, 0),
		enabled(enabld), grayout(nil), gray_pat(nil) {
	Init(msg);
}

VMessage::VMessage(const char* name, const char* msg, Alignment al, 
		int pad, boolean enabld) : Message(name, msg, al, pad, 0, 0),
			enabled(enabld), grayout(nil), gray_pat(nil) {
	Init(msg);
}

VMessage::~VMessage() {
	delete [] sample;
	Resource::unref(grayout);
	Resource::unref(gray_pat);
}

void
VMessage::Reconfig() {
    const Font* f = output->GetFont();
    shape->Rect(f->Width(sample) + pad + pad, f->Height() + pad + pad);
    shape->Rigid(0, hfil, 0, 0);
	grayout = new Painter(output);
	grayout->ref();
	grayout->SetColors(output->GetBgColor(), output->GetFgColor());
	gray_pat = new Pattern(Pattern::gray);
	gray_pat->ref();
	grayout->SetPattern(gray_pat);
	grayout->FillBg(false);
}

void 
VMessage::Redraw(Coord l, Coord b, Coord r, Coord t) {
	Message::Redraw(l, b, r, t);
	if(!isEnabled()) {
		grayout->Clip(canvas, l, b, r, t);
		grayout->FillRect(canvas, 0, 0, xmax, ymax);
		grayout->NoClip();
	}
}

void 
VMessage::Highlight(boolean b) {
	if(isEnabled())
		Message::Highlight(b);
}

void
VMessage::Init(const char* samp) {
	SetClassName("VMessage");
    sample = newstr(samp);
}

void
VMessage::enable(boolean b) {
	if(b != enabled) {
		enabled = b;
		Draw();
	}
}

void
VMessage::setText(const char *newtext) {
	if(!text || strcmp(text, newtext) != 0) {
		delete [] text;
		text = newstr(newtext);
		if (canvas != nil && canvas->status() == Canvas::mapped)
			Draw();
	}
}

// ************

StatusBar::StatusBar(const char* mesg) : VMessage(mesg, Center, 10) {
	Init();
}

StatusBar::StatusBar(const char* name, const char* mesg)
		: VMessage(name, mesg, Center, 10) {
	Init();
}

void
StatusBar::Init() {
	SetClassName("StatusBar");
}

// make window visible by raising to top of stack and display text

void
StatusBar::setText(const char *newtext) {
	VMessage::setText(newtext);
	World *w = GetWorld();
	if(w != nil) {
		ManagedWindow *top = GetTopLevelWindow();
		if(top != nil)
			top->raise();
//		w->Sync();
		w->flush();
	}
}