2010-07-10 08:58:15 -05:00
|
|
|
/*
|
|
|
|
* The contents of this file are subject to the Mozilla Public
|
|
|
|
* License Version 1.1 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS
|
|
|
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
* implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
|
|
|
*
|
|
|
|
* The Original Code is Vision.
|
|
|
|
*
|
2010-05-07 04:47:10 -05:00
|
|
|
* The Initial Developer of the Original Code is The Vision Team.
|
|
|
|
* Portions created by The Vision Team are
|
|
|
|
* Copyright (C) 1999, 2000, 2001 The Vision Team. All Rights
|
|
|
|
* Reserved.
|
2010-07-10 08:58:15 -05:00
|
|
|
*
|
2010-05-07 04:47:10 -05:00
|
|
|
* Contributor(s): Rene Gollent
|
|
|
|
* Todd Lair
|
|
|
|
* Andrea Anzani, andrea.anzani@gmail.com
|
|
|
|
*/
|
2010-07-10 08:58:15 -05:00
|
|
|
|
2010-05-07 04:47:10 -05:00
|
|
|
#define NUMBER_THEME_READERS 1000
|
|
|
|
|
|
|
|
#include <Message.h>
|
|
|
|
#include <Messenger.h>
|
|
|
|
#include <View.h>
|
|
|
|
#include <malloc.h>
|
|
|
|
#include <stdio.h> //fix
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "Theme.h"
|
|
|
|
#include "NormalTextRender.h"
|
|
|
|
|
2012-10-18 15:59:15 -05:00
|
|
|
int Theme::TimestampFore = 0;
|
|
|
|
int Theme::TimestampBack = 0;
|
|
|
|
int Theme::TimestampFont = 0;
|
|
|
|
int Theme::TimespaceFore = 1;
|
|
|
|
int Theme::TimespaceBack = 1;
|
|
|
|
int Theme::TimespaceFont = 1;
|
|
|
|
int Theme::NormalFore = 2;
|
|
|
|
int Theme::NormalBack = 2;
|
|
|
|
int Theme::NormalFont = 2;
|
|
|
|
int Theme::SelectionBack = 3;
|
2010-05-07 04:47:10 -05:00
|
|
|
|
|
|
|
//at least we use a 'normal' text render
|
|
|
|
|
|
|
|
|
2012-10-18 15:59:15 -05:00
|
|
|
Theme::Theme(const char* n, int foreCount, int backCount, int renderCount)
|
|
|
|
:
|
|
|
|
name (NULL),
|
|
|
|
fores (NULL),
|
|
|
|
backs (NULL),
|
|
|
|
text_renders (NULL),
|
|
|
|
fore_count (max_c (foreCount, 4)),
|
|
|
|
back_count (max_c (backCount, 4)),
|
|
|
|
render_count (max_c (renderCount, 4))
|
2010-05-07 04:47:10 -05:00
|
|
|
{
|
2010-07-10 08:58:15 -05:00
|
|
|
|
2010-05-07 04:47:10 -05:00
|
|
|
fSoftLineIndent = (float)(MARGIN_WIDTH / 2.0);
|
|
|
|
fTextMargin = (float)(MARGIN_WIDTH / 2.0);
|
2010-07-10 08:58:15 -05:00
|
|
|
|
|
|
|
name = strcpy (new char [strlen (n) + 1], n);
|
|
|
|
|
|
|
|
fores = new rgb_color [fore_count];
|
|
|
|
backs = new rgb_color [back_count];
|
|
|
|
|
|
|
|
normal_textrender = new NormalTextRender(be_plain_font);
|
|
|
|
|
|
|
|
text_renders = (TextRender**)malloc(render_count * sizeof(TextRender*));
|
|
|
|
for ( int i = 0; i < render_count; i++ )
|
2010-05-07 04:47:10 -05:00
|
|
|
text_renders[i] = normal_textrender;
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-07-10 08:58:15 -05:00
|
|
|
sid = create_sem (NUMBER_THEME_READERS, name);
|
|
|
|
|
|
|
|
rgb_color def_timestamp_fore = {200, 150, 150, 255};
|
|
|
|
rgb_color def_timestamp_back = {255, 255, 255, 255};
|
|
|
|
rgb_color def_fore = {0, 0, 0, 255};
|
|
|
|
rgb_color def_back = {255, 255, 255, 255};
|
2010-05-07 04:47:10 -05:00
|
|
|
|
2010-07-10 08:58:15 -05:00
|
|
|
fores[0] = def_timestamp_fore;
|
|
|
|
|
2012-10-18 15:59:15 -05:00
|
|
|
int i;
|
2010-07-10 08:58:15 -05:00
|
|
|
for (i = 1; i < fore_count; ++i)
|
|
|
|
fores[i] = def_fore;
|
|
|
|
|
|
|
|
backs[0] = def_timestamp_back;
|
|
|
|
for (i = 1; i < back_count; ++i)
|
|
|
|
backs[i] = def_back;
|
2010-05-07 04:47:10 -05:00
|
|
|
}
|
|
|
|
|
2012-10-18 15:59:15 -05:00
|
|
|
|
2010-05-07 04:47:10 -05:00
|
|
|
Theme::~Theme (void)
|
|
|
|
{
|
2010-07-10 08:58:15 -05:00
|
|
|
delete_sem (sid);
|
2010-05-07 04:47:10 -05:00
|
|
|
|
2010-07-10 08:58:15 -05:00
|
|
|
//delete [] fonts;
|
|
|
|
for ( int i = 0; i < render_count; i++ )
|
2010-05-07 04:47:10 -05:00
|
|
|
if ( text_renders[i] )
|
2010-07-10 08:58:15 -05:00
|
|
|
text_renders[i] = NULL;
|
|
|
|
|
|
|
|
delete normal_textrender;
|
|
|
|
|
|
|
|
delete [] backs;
|
|
|
|
delete [] fores;
|
|
|
|
delete [] name;
|
2010-05-07 04:47:10 -05:00
|
|
|
}
|
|
|
|
|
2012-10-18 15:59:15 -05:00
|
|
|
|
|
|
|
int
|
2010-05-07 04:47:10 -05:00
|
|
|
Theme::CountForegrounds (void) const
|
|
|
|
{
|
2010-07-10 08:58:15 -05:00
|
|
|
return fore_count;
|
2010-05-07 04:47:10 -05:00
|
|
|
}
|
|
|
|
|
2012-10-18 15:59:15 -05:00
|
|
|
|
|
|
|
int
|
2010-05-07 04:47:10 -05:00
|
|
|
Theme::CountBackgrounds (void) const
|
|
|
|
{
|
2010-07-10 08:58:15 -05:00
|
|
|
return back_count;
|
2010-05-07 04:47:10 -05:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
int16
|
|
|
|
Theme::CountFonts (void) const
|
|
|
|
{
|
|
|
|
return font_count;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2012-10-18 15:59:15 -05:00
|
|
|
|
|
|
|
int
|
2010-05-07 04:47:10 -05:00
|
|
|
Theme::CountTextRenders (void) const
|
|
|
|
{
|
2010-07-10 08:58:15 -05:00
|
|
|
return render_count;
|
2010-05-07 04:47:10 -05:00
|
|
|
}
|
|
|
|
|
2012-10-18 15:59:15 -05:00
|
|
|
|
2010-05-07 04:47:10 -05:00
|
|
|
void
|
|
|
|
Theme::ReadLock (void)
|
|
|
|
{
|
2010-07-10 08:58:15 -05:00
|
|
|
acquire_sem (sid);
|
2010-05-07 04:47:10 -05:00
|
|
|
}
|
|
|
|
|
2012-10-18 15:59:15 -05:00
|
|
|
|
2010-05-07 04:47:10 -05:00
|
|
|
void
|
|
|
|
Theme::ReadUnlock (void)
|
|
|
|
{
|
2010-07-10 08:58:15 -05:00
|
|
|
release_sem (sid);
|
2010-05-07 04:47:10 -05:00
|
|
|
}
|
|
|
|
|
2012-10-18 15:59:15 -05:00
|
|
|
|
2010-05-07 04:47:10 -05:00
|
|
|
void
|
|
|
|
Theme::WriteLock (void)
|
|
|
|
{
|
2010-07-10 08:58:15 -05:00
|
|
|
acquire_sem_etc (sid, NUMBER_THEME_READERS, 0, 0);
|
2010-05-07 04:47:10 -05:00
|
|
|
}
|
|
|
|
|
2012-10-18 15:59:15 -05:00
|
|
|
|
2010-05-07 04:47:10 -05:00
|
|
|
void
|
|
|
|
Theme::WriteUnlock (void)
|
|
|
|
{
|
2010-07-10 08:58:15 -05:00
|
|
|
release_sem_etc (sid, NUMBER_THEME_READERS, 0);
|
2010-05-07 04:47:10 -05:00
|
|
|
}
|
|
|
|
|
2012-10-18 15:59:15 -05:00
|
|
|
|
2010-07-10 08:58:15 -05:00
|
|
|
const rgb_color
|
2012-10-18 15:59:15 -05:00
|
|
|
Theme::ForegroundAt (int which) const
|
2010-05-07 04:47:10 -05:00
|
|
|
{
|
2010-07-10 08:58:15 -05:00
|
|
|
rgb_color color = {0, 0, 0, 255};
|
2010-05-07 04:47:10 -05:00
|
|
|
|
2010-07-10 08:58:15 -05:00
|
|
|
if (which >= fore_count || which < 0)
|
|
|
|
return color;
|
2010-05-07 04:47:10 -05:00
|
|
|
|
2010-07-10 08:58:15 -05:00
|
|
|
return fores[which];
|
2010-05-07 04:47:10 -05:00
|
|
|
}
|
|
|
|
|
2012-10-18 15:59:15 -05:00
|
|
|
|
2010-05-07 04:47:10 -05:00
|
|
|
const rgb_color
|
2012-10-18 15:59:15 -05:00
|
|
|
Theme::BackgroundAt (int which) const
|
2010-05-07 04:47:10 -05:00
|
|
|
{
|
2010-07-10 08:58:15 -05:00
|
|
|
rgb_color color = {255, 255, 255, 255};
|
2010-05-07 04:47:10 -05:00
|
|
|
|
2010-07-10 08:58:15 -05:00
|
|
|
if (which >= back_count || which < 0)
|
|
|
|
return color;
|
2010-05-07 04:47:10 -05:00
|
|
|
|
2010-07-10 08:58:15 -05:00
|
|
|
return backs[which];
|
2010-05-07 04:47:10 -05:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
const BFont &
|
|
|
|
Theme::FontAt (int16 which) const
|
|
|
|
{
|
|
|
|
if (which >= font_count || which < 0)
|
|
|
|
return *be_plain_font;
|
|
|
|
|
|
|
|
return fonts[which];
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2012-10-18 15:59:15 -05:00
|
|
|
|
2010-05-07 04:47:10 -05:00
|
|
|
TextRender*
|
2012-10-18 15:59:15 -05:00
|
|
|
Theme::TextRenderAt (int which)
|
2010-05-07 04:47:10 -05:00
|
|
|
{
|
2010-07-10 08:58:15 -05:00
|
|
|
if ( which < 0 ) {
|
|
|
|
//printf("Theme::TextRenderAt(): which < 0 (%d)\n", which);
|
|
|
|
return normal_textrender;
|
|
|
|
}
|
|
|
|
if ( which >= render_count ) {
|
|
|
|
//printf("Theme::TextRenderAt(): which >= render_count (%d, %d)\n", which, render_count);
|
|
|
|
return normal_textrender;
|
|
|
|
}
|
|
|
|
|
|
|
|
return text_renders[which];
|
2010-05-07 04:47:10 -05:00
|
|
|
}
|
|
|
|
|
2012-10-18 15:59:15 -05:00
|
|
|
|
2010-05-07 04:47:10 -05:00
|
|
|
bool
|
2012-10-18 15:59:15 -05:00
|
|
|
Theme::SetForeground (int which, const rgb_color color)
|
2010-05-07 04:47:10 -05:00
|
|
|
{
|
2010-07-10 08:58:15 -05:00
|
|
|
if (which >= fore_count || which < 0)
|
|
|
|
return false;
|
2010-05-07 04:47:10 -05:00
|
|
|
|
2010-07-10 08:58:15 -05:00
|
|
|
fores[which] = color;
|
|
|
|
return true;
|
2010-05-07 04:47:10 -05:00
|
|
|
}
|
|
|
|
|
2012-10-18 15:59:15 -05:00
|
|
|
|
2010-05-07 04:47:10 -05:00
|
|
|
bool
|
2012-10-18 15:59:15 -05:00
|
|
|
Theme::SetBackground (int which, const rgb_color color)
|
2010-05-07 04:47:10 -05:00
|
|
|
{
|
2010-07-10 08:58:15 -05:00
|
|
|
if (which >= back_count || which < 0)
|
|
|
|
return false;
|
2010-05-07 04:47:10 -05:00
|
|
|
|
2010-07-10 08:58:15 -05:00
|
|
|
backs[which] = color;
|
|
|
|
return true;
|
2010-05-07 04:47:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
2012-10-18 15:59:15 -05:00
|
|
|
Theme::SetTextRender(int which, TextRender* trender)
|
2010-05-07 04:47:10 -05:00
|
|
|
{
|
2010-07-10 08:58:15 -05:00
|
|
|
|
|
|
|
|
|
|
|
if (which >= render_count || which < 0 || !trender)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
text_renders[which] = trender;
|
|
|
|
return true;
|
2010-05-07 04:47:10 -05:00
|
|
|
}
|
|
|
|
|
2012-10-18 15:59:15 -05:00
|
|
|
|
2010-05-07 04:47:10 -05:00
|
|
|
void
|
2010-07-10 08:58:15 -05:00
|
|
|
Theme::AddView (BView* view)
|
2010-05-07 04:47:10 -05:00
|
|
|
{
|
2010-07-10 08:58:15 -05:00
|
|
|
list.AddItem (view);
|
2010-05-07 04:47:10 -05:00
|
|
|
}
|
|
|
|
|
2012-10-18 15:59:15 -05:00
|
|
|
|
2010-05-07 04:47:10 -05:00
|
|
|
void
|
2010-07-10 08:58:15 -05:00
|
|
|
Theme::RemoveView (BView* view)
|
2010-05-07 04:47:10 -05:00
|
|
|
{
|
2010-07-10 08:58:15 -05:00
|
|
|
list.RemoveItem (view);
|
2010-05-07 04:47:10 -05:00
|
|
|
}
|
|
|
|
|
2012-10-18 15:59:15 -05:00
|
|
|
|
2010-05-07 04:47:10 -05:00
|
|
|
void
|
|
|
|
Theme::SetTextMargin(float margin)
|
|
|
|
{
|
|
|
|
fTextMargin = margin;
|
|
|
|
}
|
|
|
|
|
2012-10-18 15:59:15 -05:00
|
|
|
|
2010-05-07 04:47:10 -05:00
|
|
|
void
|
|
|
|
Theme::SetSoftLineIndent(float indent)
|
|
|
|
{
|
|
|
|
fSoftLineIndent = indent;
|
|
|
|
}
|