namespace wal { int uiClassStaticLabel = GetUiID("StaticLabel"); int StaticLabel::UiGetClassId() { return uiClassStaticLabel; } StaticLabel::StaticLabel(int nId, Win* parent, const unicode_t* txt, Win* _master, crect* rect) : Win(Win::WT_CHILD, 0, parent, rect, nId), text(txt), master(_master) { if (!rect) { GC gc(this); SetLSize(LSize(text.GetTextExtents(gc, GetFont()))); } } void StaticLabel::Paint(GC& gc, const crect& paintRect) { crect rect = ClientRect(); gc.SetFillColor(UiGetColor(uiBackground, uiClassStaticLabel, 0, 0xFFFFFF)/*GetColor(0)*/); gc.FillRect(rect); gc.Set(GetFont()); text.DrawItem(gc, 0, 0, UiGetColor(uiColor, uiClassStaticLabel, 0, 0), UiGetColor(uiHotkeyColor, uiClassStaticLabel, 0, 0)); } Win* StaticLabel::IsHisHotKey(cevent_key* pEvent) { return text.isHotkeyMatching(UnicodeUC(pEvent->Char())) ? master : 0; } }
namespace wal { MenuData::MenuData() {} // временная штука std::unordered_map<int, clPtr<cicon> > iconList; cicon* GetCmdIcon( int cmd ) { { auto i = iconList.find( cmd ); if ( i != iconList.end() ) { return i->second.ptr(); } } clPtr<cicon> pic = new cicon( cmd, 16, 16 ); cicon* t = pic.ptr(); iconList[cmd] = pic; return t; } unsigned short RightMenuPointer[] = {7, 1, 3, 7, 0xF, 7, 3, 1}; #define MENU_SPLITTER_H 3 #define MENU_LEFT_BLOCK 24 #define MENU_RIGHT_BLOCK 16 #define MENU_ITEM_HEIGHT_ADD (8) #define MENU_ICON_SIZE 16 #define MENU_TEXT_OFFSET 3 bool PopupMenu::IsCmd( int n ) { return n >= 0 && n < list.count() && list[n].data->type == MenuData::CMD; } bool PopupMenu::IsSplit( int n ) { return n >= 0 && n < list.count() && list[n].data->type == MenuData::SPLIT; } bool PopupMenu::IsSub( int n ) { return n >= 0 && n < list.count() && list[n].data->type == MenuData::SUB; } bool PopupMenu::IsEnabled( int n ) { return n < 0 || n >= list.count() || list[n].enabled; } int uiClassPopupMenu = GetUiID( "PopupMenu" ); int PopupMenu::UiGetClassId() { return uiClassPopupMenu; } void PopupMenu::DrawItem( GC& gc, int n ) { if ( n < 0 || n >= list.count() ) { return; } UiCondList ucl; if ( n == selected ) { ucl.Set( uiCurrentItem, true ); } int color_text = UiGetColor( uiColor, uiItem, &ucl, 0x0 ); int color_hotkey = UiGetColor( uiHotkeyColor, uiItem, &ucl, 0x0 ); int color_bg = UiGetColor( uiBackground, uiItem, &ucl, 0xFFFFFF ); int color_left = UiGetColor( uiBackground, 0, 0, 0xFFFFFF ); crect r = list[n].rect; int height = r.Height(); r.right = MENU_LEFT_BLOCK; gc.SetFillColor( n == selected ? color_bg : color_left ); gc.FillRect( r ); r = list[n].rect; r.left = MENU_LEFT_BLOCK ; gc.SetFillColor( color_bg ); gc.FillRect( r ); unsigned colorLine = UiGetColor( uiLineColor, uiItem, &ucl, 0 ); gc.SetLine( colorLine ); gc.MoveTo( r.left, r.top ); gc.LineTo( r.left, r.bottom ); if ( IsSplit( n ) ) { gc.SetLine( colorLine ); int y = r.top + ( r.Height() - 1 ) / 2; gc.MoveTo( 1, y ); gc.LineTo( r.right, y ); } else { gc.Set( GetFont() ); MenuTextInfo& lText = ( list[n].data->leftText ); //unicode_t* lText = list[n].data->leftText.data(); unicode_t* rText = list[n].data->rightText.data(); //if ( lText ) { gc.TextOutF( MENU_LEFT_BLOCK + MENU_TEXT_OFFSET, r.top + ( height - fontHeight ) / 2, lText ); } if ( !lText.isEmpty() ) { lText.DrawItem( gc, MENU_LEFT_BLOCK + MENU_TEXT_OFFSET, r.top + ( height - fontHeight ) / 2, color_text, color_hotkey ); } if ( rText ) { gc.SetTextColor( color_text ); gc.TextOutF( MENU_LEFT_BLOCK + MENU_TEXT_OFFSET + leftWidth + fontHeight, r.top + ( height - fontHeight ) / 2, rText ); } if ( IsSub( n ) ) { int y = r.top + ( height - RightMenuPointer[0] ) / 2; DrawPixelList( gc, RightMenuPointer, r.right - 10 , y, UiGetColor( uiPointerColor, uiItem, &ucl, 0 ) ); } if ( IsCmd( n ) ) { int y = r.top + ( height - MENU_ICON_SIZE ) / 2; int x = ( MENU_LEFT_BLOCK - MENU_ICON_SIZE ) / 2; gc.DrawIcon( x, y, GetCmdIcon( list[n].data->id ) ); } } } PopupMenu::PopupMenu( int nId, Win* parent, MenuData* d, int x, int y, Win* _cmdOwner ) : Win( Win::WT_POPUP, Win::WH_CLICKFOCUS, //0, parent, 0, nId ), selected( 0 ), cmdOwner( _cmdOwner ), leftWidth( 0 ), rightWidth( 0 ) { GC gc( this ); gc.Set( GetFont() ); int itemH = gc.GetTextExtents( ABCString ).y; fontHeight = itemH; if ( itemH < MENU_ICON_SIZE ) { itemH = MENU_ICON_SIZE; } itemH += MENU_ITEM_HEIGHT_ADD; int height = 1; int count = d->list.count(); int i; for ( int i = 0; i < count; i++ ) { Node node; node.data = &d->list[i]; node.rect.left = 1; node.rect.top = height; if ( node.data->type == MenuData::SPLIT ) { node.rect.bottom = node.rect.top + MENU_SPLITTER_H; node.enabled = true; } else { cpoint p; MenuTextInfo& leftText = node.data->leftText; if ( !node.data->leftText.isEmpty() ) { p = leftText.GetTextExtents( gc ); if ( leftWidth < p.x ) { leftWidth = p.x; } } if ( node.data->rightText.data() ) { p = gc.GetTextExtents( node.data->rightText.data() ); if ( rightWidth < p.x ) { rightWidth = p.x; } } node.rect.bottom = node.rect.top + itemH; node.enabled = ( node.data->type == MenuData::CMD && cmdOwner ) ? cmdOwner->Command( CMD_CHECK, node.data->id, this, 0 ) : true; } height += node.rect.Height() - 1; list.append( node ); } int maxWidth = 3 + MENU_LEFT_BLOCK + MENU_RIGHT_BLOCK + MENU_TEXT_OFFSET + leftWidth; if ( rightWidth > 0 ) { maxWidth += rightWidth + fontHeight; } height += 2; int itemW = maxWidth - 2; for ( i = 0; i < count; i++ ) { list[i].rect.right = list[i].rect.left + itemW; } crect rect( x, y, x + maxWidth, y + height ); this->Move( rect ); } bool PopupMenu::OpenSubmenu() { if ( !sub.ptr() && IsSub( selected ) ) { crect rect = this->ScreenRect(); sub = new PopupMenu( 0, this, list[selected].data->sub, rect.right, rect.top + list[selected].rect.top, cmdOwner ); sub->Show( Win::SHOW_INACTIVE ); sub->Enable( true ); return true; } return false; } bool PopupMenu::Command( int id, int subId, Win* win, void* d ) { if ( id == CMD_CHECK ) { return Parent() ? Parent()->Command( id, subId, this, d ) : false; } if ( IsModal() ) { EndModal( id ); } return ( Parent() ) ? Parent()->Command( id, subId, win, d ) : false; } bool PopupMenu::SetSelected( int n ) { if ( n == selected ) { return true; } if ( n < 0 || n > list.count() || IsSplit( n ) ) { return false; } if ( sub.ptr() ) { sub.clear(); } int old = selected; selected = n; GC gc( this ); DrawItem( gc, old ); DrawItem( gc, selected ); return true; } bool PopupMenu::EventMouse( cevent_mouse* pEvent ) { int N = -1; cpoint point = pEvent->Point(); for ( int i = 0; i < list.count(); i++ ) { crect* pr = &( list[i].rect ); if ( point.x >= pr->left && point.x < pr->right && point.y >= pr->top && point.y < pr->bottom ) { N = i; break; } } switch ( pEvent->Type() ) { case EV_MOUSE_MOVE: if ( N < 0 ) { if ( !sub.ptr() ) { return false; } crect rect = ScreenRect(); crect sr = sub->ScreenRect(); pEvent->Point().x += rect.left - sr.left; pEvent->Point().y += rect.top - sr.top; return sub->EventMouse( pEvent ); } if ( SetSelected( N ) ) { if ( this->IsSub( selected ) && IsEnabled( selected ) ) { OpenSubmenu(); } } return true; case EV_MOUSE_PRESS: if ( N < 0 ) { if ( sub.ptr() ) { crect rect = ScreenRect(); crect sr = sub->ScreenRect(); pEvent->Point().x += rect.left - sr.left; pEvent->Point().y += rect.top - sr.top; if ( sub->EventMouse( pEvent ) ) { return true; } } if ( IsModal() ) { EndModal( 0 ); } else if ( Parent() ) { Parent()->Command( CMD_MENU_INFO, SCMD_MENU_CANCEL, this, 0 ); } return true; } if ( SetSelected( N ) ) { if ( IsCmd( selected ) && IsEnabled( selected ) ) { int id = list[N].data->id; if ( IsModal() ) { EndModal( id ); } else if ( Parent() ) { Parent()->Command( id, 0, this, 0 ); } } else { OpenSubmenu(); } } return true; } return false; } bool PopupMenu::EventKey( cevent_key* pEvent ) { if ( sub.ptr() && sub->EventKey( pEvent ) ) { return true; } if ( pEvent->Type() == EV_KEYDOWN ) { int i; switch ( pEvent->Key() ) { case VK_DOWN: for ( i = ( selected >= 0 && selected + 1 < list.count() ) ? selected + 1 : 0; i < list.count(); i++ ) { if ( !IsSplit( i ) ) { SetSelected( i ); return true; } } break; case VK_UP: for ( i = ( selected > 0 ) ? selected - 1 : list.count() - 1; i >= 0; i-- ) { if ( !IsSplit( i ) ) { SetSelected( i ); return true; } } break; case VK_RIGHT: if ( OpenSubmenu() ) { return true; }; break; //case VK_LEFT: // return false; // to prevent grabbing default case case VK_NUMPAD_RETURN: case VK_RETURN: if ( IsCmd( selected ) && IsEnabled( selected ) ) { int id = list[selected].data->id; if ( IsModal() ) { EndModal( id ); } else if ( Parent() ) { Parent()->Command( id, 0, this, 0 ); } return true; } return OpenSubmenu(); case VK_ESCAPE: if ( IsModal() ) { EndModal( 0 ); } else if ( Parent() ) { Parent()->Command( CMD_MENU_INFO, SCMD_MENU_CANCEL, this, 0 ); } else {/* Botva */} return true; default: { // check if hotkey matches, and process // XXX: pEvent->Key() returns key (like Shift-F1, etc). isHotkeyMatching() expects unicode char, which is not the same unicode_t c = UnicodeUC( pEvent->Char() ); for ( int i = 0; i < list.count(); i++ ) { MenuData::Node* node = list[i].data; if ( node->leftText.isHotkeyMatching( c ) ) { if ( node->id != 0 ) // menu command { if ( Parent() ) { Parent()->Command( node->id, 0, this, 0 ); } return true; } else // sumbenu { SetSelected( i ); OpenSubmenu(); return true; } } } return false; } } } return false; } void PopupMenu::Paint( GC& gc, const crect& paintRect ) { crect rect = ClientRect(); gc.SetFillColor( UiGetColor( uiBackground, 0, 0, 0xFFFFFF ) ); gc.FillRect( rect ); DrawBorder( gc, rect, UiGetColor( uiFrameColor, 0, 0, 0 ) ); for ( int i = 0; i < list.count(); i++ ) { DrawItem( gc, i ); } } PopupMenu::~PopupMenu() {} int DoPopupMenu( int nId, Win* parent, MenuData* d, int x, int y ) { PopupMenu menu( nId, parent, d, x, y ); menu.Show(); menu.Enable(); menu.SetCapture(); int ret = 0; try { ret = menu.DoModal(); menu.ReleaseCapture(); } catch ( ... ) { menu.ReleaseCapture(); throw; } return ret; } }; //namespace wal
namespace wal { int uiClassVListWin = GetUiID( "VListWin" ); int VListWin::UiGetClassId() { return uiClassVListWin; } VListWin::VListWin( WTYPE wt, unsigned hints, int nId, Win* parent, SelectType st, BorderType bt, crect* rect ) : Win( wt, hints, parent, rect, nId ), selectType( st ), borderType( bt ), itemHeight( 1 ), itemWidth( 1 ), xOffset( 0 ), count( 0 ), first( 0 ), current( -1 ), captureDelta( 0 ), borderColor( 0 ), bgColor( 0x808080 ), vScroll( 0, this, true, true ), hScroll( 0, this, false ), layout( 4, 4 ) { vScroll.Show(); //!!! неясности с порядком ??? vScroll.Enable(); hScroll.Show(); hScroll.Enable(); vScroll.SetManagedWin( this ); hScroll.SetManagedWin( this ); layout.AddWin( &vScroll, 1, 2 ); layout.AddWin( &hScroll, 2, 1 ); layout.AddRect( &listRect, 1, 1 ); layout.AddRect( &scrollRect, 2, 2 ); int borderWidth = ( bt == SINGLE_BORDER ) ? 1 : ( bt == BORDER_3D ? 2 : 0 ); layout.LineSet( 0, borderWidth ); layout.LineSet( 3, borderWidth ); layout.ColSet( 0, borderWidth ); layout.ColSet( 3, borderWidth ); layout.SetColGrowth( 1 ); layout.SetLineGrowth( 1 ); this->SetLayout( &layout ); this->RecalcLayouts(); } void VListWin::CalcScroll() { if ( itemHeight <= 0 ) { itemHeight = 1; } if ( itemWidth <= 0 ) { itemWidth = 1; } int n = listRect.Height() / itemHeight; pageSize = n; ScrollInfo vsi, hsi; vsi.m_PageSize = pageSize; vsi.m_Size = count; vsi.m_Pos = first; hsi.m_PageSize = listRect.Width(); hsi.m_Size = itemWidth; hsi.m_Pos = xOffset; bool vVisible = vScroll.IsVisible(); vScroll.Command( CMD_SCROLL_INFO, SCMD_SCROLL_VCHANGE, this, &vsi ); bool hVisible = hScroll.IsVisible(); hScroll.Command( CMD_SCROLL_INFO, SCMD_SCROLL_HCHANGE, this, &hsi ); if ( vVisible != vScroll.IsVisible() || hVisible != hScroll.IsVisible() ) { this->RecalcLayouts(); } //MB(L"%i,%i,%i", hsi.size, hsi.pageSize, hsi.pos); } void VListWin::MoveFirst( int n ) { if ( n + pageSize >= count ) { n = count - pageSize; } if ( n < 0 ) { n = 0; } if ( first != n ) { first = n; CalcScroll(); Invalidate(); } } void VListWin::MoveXOffset( int n ) { if ( n + listRect.Width() >= itemWidth ) { n = itemWidth - listRect.Width(); } if ( n < 0 ) { n = 0; } if ( xOffset != n ) { xOffset = n; CalcScroll(); Invalidate(); } } bool VListWin::Command( int id, int subId, Win* win, void* data ) { if ( id == CMD_SCROLL_INFO ) { switch ( subId ) { case SCMD_SCROLL_LINE_UP: MoveFirst( first - 1 ); break; case SCMD_SCROLL_LINE_DOWN: MoveFirst( first + 1 ); break; case SCMD_SCROLL_PAGE_UP: MoveFirst( first - pageSize ); break; case SCMD_SCROLL_PAGE_DOWN: MoveFirst( first + pageSize ); break; case SCMD_SCROLL_LINE_LEFT: MoveXOffset( xOffset - 10 ); break; case SCMD_SCROLL_LINE_RIGHT: MoveXOffset( xOffset + 10 ); break; case SCMD_SCROLL_PAGE_LEFT: MoveXOffset( xOffset - listRect.Width() ); break; case SCMD_SCROLL_PAGE_RIGHT: MoveXOffset( xOffset + listRect.Width() ); break; case SCMD_SCROLL_TRACK: ( win == &vScroll ) ? MoveFirst( ( ( int* )data )[0] ) : MoveXOffset( ( ( int* )data )[0] ); break; } return true; } return Win::Command( id, subId, win, data ); } void VListWin::Paint( GC& gc, const crect& paintRect ) { crect rect = ClientRect(); switch ( borderType ) { case SINGLE_BORDER: DrawBorder( gc, rect, InFocus() ? 0x00C000 : borderColor ); break; case BORDER_3D: Draw3DButtonW2( gc, rect, bgColor, false ); default: ; } if ( !scrollRect.IsEmpty() ) { gc.SetFillColor( 0xD0D0D0 ); gc.FillRect( scrollRect ); //CCC } if ( itemHeight > 0 ) { int n = ( rect.Height() + ( itemHeight - 1 ) ) / itemHeight; crect r = this->listRect; int bottom = r.bottom; r.bottom = r.top + itemHeight; for ( int i = 0; i < n; i++ ) { gc.SetClipRgn( &r ); crect r1( r ); r1.left -= xOffset; this->DrawItem( gc, i + first, r1 ); r.top += itemHeight; r.bottom += itemHeight; if ( r.bottom > bottom ) { r.bottom = bottom; } } } else { //на всякий случай rect.Dec(); gc.SetFillColor( bgColor ); gc.FillRect( rect ); } } bool VListWin::EventFocus( bool recv ) { Invalidate(); return true; } void VListWin::EventSize( cevent_size* pEvent ) { this->CalcScroll(); MoveFirst( first ); } bool VListWin::EventMouse( cevent_mouse* pEvent ) { if ( !IsEnabled() ) { return false; } int n = ( pEvent->Point().y - listRect.top ) / this->itemHeight + first; if ( pEvent->Type() == EV_MOUSE_PRESS ) { if ( pEvent->Button() == MB_X1 ) { int n = pageSize / 3; if ( n < 1 ) { n = 1; } MoveFirst( first - n ); return true; } if ( pEvent->Button() == MB_X2 ) { int n = pageSize / 3; if ( n < 1 ) { n = 1; } MoveFirst( first + n ); return true; } } if ( pEvent->Type() == EV_MOUSE_PRESS && pEvent->Button() == MB_L && listRect.In( pEvent->Point() ) ) { captureDelta = 0; MoveCurrent( n ); this->SetCapture( &captureSD ); this->SetTimer( 0, 100 ); return true; } if ( pEvent->Type() == EV_MOUSE_DOUBLE ) { MoveCurrent( n ); Command( CMD_ITEM_CLICK, GetCurrent(), this, 0 ); return true; } if ( pEvent->Type() == EV_MOUSE_MOVE && IsCaptured() ) { if ( pEvent->Point().y >= listRect.top && pEvent->Point().y <= listRect.bottom ) { MoveCurrent( n ); captureDelta = 0; } else { captureDelta = ( pEvent->Point().y > listRect.bottom ) ? 1 : ( pEvent->Point().y < listRect.top ) ? -1 : 0; } return true; } if ( pEvent->Type() == EV_MOUSE_RELEASE && pEvent->Button() == MB_L ) { this->ReleaseCapture( &captureSD ); this->DelTimer( 0 ); if ( selectType == SINGLE_SELECT ) { MoveCurrent( n ); Command( CMD_ITEM_CLICK, GetCurrent(), this, 0 ); } return true; } return Win::EventMouse( pEvent ); } void VListWin::EventTimer( int tid ) { if ( tid == 0 && captureDelta ) { int n = current + captureDelta; if ( n >= 0 && n < this->count ) { MoveCurrent( n ); } } } bool VListWin::EventKey( cevent_key* pEvent ) { if ( pEvent->Type() == EV_KEYDOWN ) { switch ( pEvent->Key() ) { case VK_DOWN: MoveCurrent( current + 1 ); break; case VK_UP: MoveCurrent( current - 1 ); break; case VK_END: MoveCurrent( count - 1 ); break; case VK_HOME: MoveCurrent( 0 ); break; case VK_PRIOR: MoveCurrent( current - ( pageSize <= 1 ? pageSize : pageSize - 1 ) ); break; case VK_NEXT: MoveCurrent( current + ( pageSize <= 1 ? pageSize : pageSize - 1 ) ); break; case VK_LEFT: MoveXOffset( xOffset - 10 ); break; case VK_RIGHT: MoveXOffset( xOffset + 10 ); break; case VK_NUMPAD_RETURN: case VK_RETURN: Command( CMD_ITEM_CLICK, GetCurrent(), this, 0 ); break; default: return false; } Invalidate(); return true; } return false; } void VListWin::SetCount( int c ) { count = c; } void VListWin::SetCurrent( int n ) { current = n; } void VListWin::MoveCurrent( int n, bool mustVisible ) { if ( selectType == NO_SELECT ) { return; } int f = first; if ( n < 0 ) { n = 0; } //count-1; if ( n >= count ) { n = count - 1; //n = 0; } if ( mustVisible ) { if ( n - f >= pageSize ) { f = n - pageSize + 1; } if ( f > n ) { f = n; } if ( f < 0 ) { f = 0; } } bool redraw = ( f != first || n != current ); first = f; bool curChanged = ( n != current ); current = n; if ( redraw ) { CalcScroll(); Invalidate(); } if ( curChanged ) { Command( CMD_ITEM_CHANGED, GetCurrent(), this, 0 ); } } void VListWin::SetNoCurrent() { if ( current == -1 ) { return; } current = -1; Command( CMD_ITEM_CHANGED, GetCurrent(), this, 0 ); if ( IsVisible() ) { Invalidate(); } } void VListWin::SetItemSize( int h, int w ) { if ( itemHeight != h || itemWidth != w ) { itemHeight = h; itemWidth = w; CalcScroll(); Invalidate(); } } void VListWin::DrawItem( GC& gc, int n, crect rect ) { gc.SetFillColor( ( n % 2 ) ? 0xFFFFFF : 0xE0FFE0 ); gc.FillRect( rect ); } void VListWin::ClearSelection() { selectList.clear(); } bool VListWin::IsSelected( int n ) { return selectList.exist( n ); } void VListWin::ClearSelected( int n1, int n2 ) { if ( selectType != MULTIPLE_SELECT ) { return; } for ( int i = n1; i < n2; i++ ) { selectList.del( i ); } } void VListWin::SetSelected( int n1, int n2 ) { if ( selectType != MULTIPLE_SELECT ) { return; } for ( int i = n1; i < n2; i++ ) { selectList.put( i ); } } }; //namespace wal
bool m_Saved; }; class clFileAssociationsListWin: public iContainerListWin<clNCFileAssociation> { public: clFileAssociationsListWin( Win* Parent, std::vector<clNCFileAssociation>* Associations ) : iContainerListWin<clNCFileAssociation>( Parent, Associations ) { } virtual void DrawItem( wal::GC& gc, int n, crect rect ) override; }; static int uiFcColor = GetUiID( "first-char-color" ); void clFileAssociationsListWin::DrawItem( wal::GC& gc, int n, crect rect ) { if ( n < 0 || n >= ( int )m_ItemList->size( ) ) { gc.SetFillColor( UiGetColor( uiBackground, 0, 0, 0xB0B000 ) ); gc.FillRect( rect ); //CCC return; } UiCondList ucl; if ( ( n % 2 ) == 0 ) { ucl.Set( uiOdd, true ); } if ( n == this->GetCurrent() ) { ucl.Set( uiCurrentItem, true ); }
namespace wal { #define LEFTSPACE 5 #define RIGHTSPACE 5 #define ICONX_RIGHTSPACE 1 int uiClassButton = GetUiID( "Button" ); int Button::UiGetClassId() { return uiClassButton; } void Button::OnChangeStyles() { GC gc( this ); gc.Set( GetFont() ); cpoint p = text.GetTextExtents(gc); if ( icon.ptr() ) { if ( p.y < 12 ) { p.y = 12; } p.x += ICONX_RIGHTSPACE + icon->Width(); if ( icon->Width() > p.y + 4 ) { p.y = icon->Width() - 4; } } p.x += LEFTSPACE + RIGHTSPACE; p.x += 8; p.y += 8; SetLSize( LSize( p ) ); } static unicode_t spaceUnicodeStr[] = {' ', 0}; Button::Button( int nId, Win* parent, const unicode_t* txt, int id, crect* rect, int iconX, int iconY ) : Win( Win::WT_CHILD, Win::WH_TABFOCUS | WH_CLICKFOCUS, parent, rect, nId ), pressed( false ), icon( new cicon( id, iconX, iconY ) ), commandId( id ), text(txt && txt[0] ? txt : spaceUnicodeStr) { if ( !icon->Valid() ) { icon.clear(); } if ( !rect ) { OnChangeStyles(); } }; void Button::Set( const unicode_t* txt, int id, int iconX, int iconY ) { text.SetText( txt && txt[0] ? txt : spaceUnicodeStr ); commandId = id; icon = new cicon( id, iconX, iconY ); if ( !icon->Valid() ) { icon.clear(); } } bool Button::EventMouse( cevent_mouse* pEvent ) { switch ( pEvent->Type() ) { case EV_MOUSE_MOVE: if ( IsCaptured() ) { crect r = ClientRect(); cpoint p = pEvent->Point(); if ( pressed ) { if ( p.x < 0 || p.y < 0 || p.x >= r.right || p.y >= r.bottom ) { pressed = false; Invalidate(); } } else { if ( p.x >= 0 && p.y >= 0 && p.x < r.right && p.y < r.bottom ) { pressed = true; Invalidate(); } } } break; case EV_MOUSE_PRESS: case EV_MOUSE_DOUBLE: if ( pEvent->Button() != MB_L ) { break; } SetCapture(); pressed = true; Invalidate(); break; case EV_MOUSE_RELEASE: if ( pEvent->Button() != MB_L ) { break; } ReleaseCapture(); if ( pressed ) { SendCommand(); } pressed = false; Invalidate(); break; }; return true; } bool Button::EventFocus( bool recv ) { bool ret = Win::EventFocus( recv ); if ( !recv && pressed ) { pressed = false; } Invalidate(); return ret; } bool Button::EventKey( cevent_key* pEvent ) { if ((pEvent->Key() == VK_RETURN || pEvent->Key() == VK_NUMPAD_RETURN) || text.isHotkeyMatching(UnicodeUC(pEvent->Char()))) { if (pEvent->Type() == EV_KEYDOWN) { pressed = true; } else if (pressed && pEvent->Type() == EV_KEYUP) { pressed = false; SendCommand(); } else { return false; } } Invalidate(); return true; } Win* Button::IsHisHotKey(cevent_key* pEvent) { return text.isHotkeyMatching(UnicodeUC(pEvent->Char()))? this:0; } void Button::Paint( GC& gc, const crect& paintRect ) { unsigned colorBg = UiGetColor(uiBackground, uiClassButton, 0, 0x808080); //GetColor(0); crect cr = this->ClientRect(); crect rect = cr; DrawBorder( gc, rect, ColorTone( colorBg, +20 ) ); rect.Dec(); DrawBorder( gc, rect, ColorTone( colorBg, -200 ) ); rect.Dec(); gc.SetFillColor( colorBg ); gc.FillRect( rect ); if ( pressed ) { #if USE_3D_BUTTONS Draw3DButtonW2( gc, rect, colorBg, false ); #endif rect.Dec(); rect.Dec(); } else { #if USE_3D_BUTTONS Draw3DButtonW2( gc, rect, colorBg, true ); #endif rect.Dec(); if ( InFocus() ) { DrawBorder( gc, rect, /*GetColor(IC_FOCUS_MARK)*/ UiGetColor( uiFocusFrameColor, 0, 0, 0 ) ); } #if USE_3D_BUTTONS rect.Dec(); #endif } //gc.SetTextColor( /*GetColor(IsEnabled() ? IC_TEXT : IC_GRAY_TEXT)*/ UiGetColor( uiColor, 0, 0, 0 ) ); gc.Set( GetFont() ); cpoint tsize = text.GetTextExtents(gc); /* int l = tsize.x + (icon.ptr() ? icon->Width() + ICONX_RIGHTSPACE : 0); int w = rect.Width() - LEFTSPACE - RIGHTSPACE; if (icon.ptr()) w-=ICONX_RIGHTSPACE; //int x = rect.left + LEFTSPACE + (w > l ? (w - l)/2 : 0) +(pressed?2:0); int x = rect.left + LEFTSPACE + (w-l)/2 +(pressed?2:0); */ int l = tsize.x + ( icon.ptr() ? icon->Width() + ICONX_RIGHTSPACE : 0 ); int w = rect.Width(); int x = rect.left + ( w > l ? ( w - l ) / 2 : 0 ) + ( pressed ? 2 : 0 ); if ( icon.ptr() ) { gc.DrawIcon( x, rect.top + ( rect.Height() - icon->Height() ) / 2 + ( pressed ? 2 : 0 ), icon.ptr() ); x += icon->Width() + ICONX_RIGHTSPACE; } gc.SetClipRgn( &rect ); text.DrawItem(gc, x, rect.top + (rect.Height() - tsize.y) / 2 + (pressed ? 2 : 0), UiGetColor(uiColor, uiClassButton, 0, 0), UiGetColor(uiHotkeyColor, uiClassButton, 0, 0)); } Button::~Button() {} }; //namespace wal
namespace wal { #define SB_WIDTH 16 int uiClassScrollBar = GetUiID( "ScrollBar" ); int ScrollBar::UiGetClassId() { return uiClassScrollBar; } void Draw3DButtonW1( GC& gc, crect r, unsigned bg, bool up ) { static unsigned hp1, lp1; static unsigned lastBg = 0; static bool initialized = false; if ( !initialized || lastBg != bg ) { hp1 = ColorTone( bg, 200 ); lp1 = ColorTone( bg, -150 ); lastBg = bg; initialized = true; } unsigned php1, plp1; if ( up ) { php1 = hp1; plp1 = lp1; } else { php1 = lp1; plp1 = hp1; } gc.SetLine( plp1 ); gc.MoveTo( r.right - 1, r.top ); gc.LineTo( r.right - 1, r.bottom - 1 ); gc.LineTo( r.left, r.bottom - 1 ); gc.SetLine( php1 ); gc.LineTo( r.left, r.top ); gc.LineTo( r.right - 1, r.top ); } /* types: 1 -left 2 - right 3 - horisontal slider 4 - up 5 - down 6 - vert. slider */ void SBCDrawButton( GC& gc, crect rect, int type, unsigned bg, bool pressed ) { static unsigned short up[] = {6, 0x10, 0x38, 0x7c, 0xee, 0x1c7, 0x82}; static unsigned short down[] = {6, 0x82, 0x1c7, 0xee, 0x7c, 0x38, 0x10,}; static unsigned short left[] = {9, 0x10, 0x38, 0x1c, 0x0e, 0x07, 0x0e, 0x1c, 0x38, 0x10}; static unsigned short right[] = {9, 0x02, 0x07, 0x0E, 0x1c, 0x38, 0x1c, 0x0e, 0x07, 0x02}; DrawBorder( gc, rect, ColorTone( bg, -100 ) ); rect.Dec(); Draw3DButtonW1( gc, rect, bg, !pressed ); //rect.Dec(); rect.Dec(); gc.SetFillColor( bg ); gc.FillRect( rect ); int xPlus = 0; int yPlus = 0; if ( pressed ) { // xPlus = 1; yPlus = 1; } unsigned color = ColorTone( bg, -200 ); switch ( type ) { case 1: DrawPixelList( gc, left, rect.left + ( rect.Width() - 6 ) / 2 + xPlus, rect.top + ( rect.Height() - 9 ) / 2 + yPlus, color ); break; case 2: DrawPixelList( gc, right, rect.left + ( rect.Width() - 6 ) / 2 + xPlus, rect.top + ( rect.Height() - 9 ) / 2 + yPlus, color ); break; case 4: DrawPixelList( gc, up, rect.left + ( rect.Width() - 9 ) / 2 + xPlus, rect.top + ( rect.Height() - 6 ) / 2 + yPlus, color ); break; case 5: DrawPixelList( gc, down, rect.left + ( rect.Width() - 9 ) / 2 + xPlus, rect.top + ( rect.Height() - 6 ) / 2 + yPlus, color ); break; }; } ScrollBar::ScrollBar( int nId, Win* parent, bool _vertical, bool _autoHide, crect* rect ) : Win( Win::WT_CHILD, 0, parent, rect, nId ), vertical( _vertical ), si( 100, 10, 0 ), len( 0 ), bsize( 0 ), bpos( 0 ), trace( false ), traceBPoint( 0 ), autoHide( _autoHide ), b1Pressed( false ), b2Pressed( false ), managedWin( 0 ) { LSize ls; int l = SB_WIDTH * 2;// + 2;// + 5; int h = SB_WIDTH;// + 2; if ( vertical ) { ls.Set( cpoint( h, l ) ); ls.y.maximal = 16000; } else { ls.Set( cpoint( l, h ) ); ls.x.maximal = 16000; } SetLSize( ls ); SetScrollInfo( 0 ); // crect r = ClientRect(); // EventSize(&cevent_size(cpoint(r.Width(),r.Height()))); } void ScrollBar::Paint( GC& gc, const crect& paintRect ) { crect cr = ClientRect(); unsigned bgColor = UiGetColor( uiBackground, 0, 0, 0xD8E9EC );/*GetColor(IC_SCROLL_BG)*/; unsigned btnColor = UiGetColor( uiButtonColor, 0, 0, 0xD8E9EC ); //GetColor(IC_SCROLL_BUTTON); gc.SetFillColor( bgColor ); gc.FillRect( cr ); DrawBorder( gc, cr, UiGetColor( uiColor, 0, 0, 0xD8E9EC )/*GetColor(IC_SCROLL_BORDER)*/ ); if ( !b1Rect.IsEmpty() ) { SBCDrawButton( gc, b1Rect, vertical ? 4 : 1, btnColor, b1Pressed ); } if ( !b2Rect.IsEmpty() ) { SBCDrawButton( gc, b2Rect, vertical ? 5 : 2, btnColor, b2Pressed ); } if ( !b3Rect.IsEmpty() ) { SBCDrawButton( gc, b3Rect, vertical ? 6 : 3, btnColor, false ); } } void ScrollBar::SetScrollInfo( ScrollInfo* s ) { ScrollInfo ns; if ( s ) { ns = *s; } else { ns.size = ns.pageSize = ns.pos = 0; } if ( ns.size < 0 ) { ns.size = 0; } if ( ns.pageSize < 0 ) { ns.pageSize = 0; } if ( ns.pos < 0 ) { ns.pos = 0; } if ( si.size == ns.size && si.pageSize == ns.pageSize && si.pos == ns.pos ) { return; } si = ns; Recalc(); if ( autoHide ) { bool v = IsVisible(); if ( si.size <= si.pageSize && si.pos <= 0 ) { if ( v ) { Hide(); if ( Parent() ) { Parent()->RecalcLayouts(); } } } else { if ( !v ) { Show(); if ( Parent() ) { Parent()->RecalcLayouts(); } } } } Invalidate(); } void ScrollBar::Recalc( cpoint* newSize ) { cpoint cs; if ( newSize ) { cs = *newSize; } else { crect r = ClientRect(); cs.Set( r.Width(), r.Height() ); } int s = vertical ? cs.y : cs.x; b1Rect.Set( 0, 0, SB_WIDTH, SB_WIDTH ); if ( vertical ) { b2Rect.Set( 0, s - SB_WIDTH, SB_WIDTH, s ); } else { b2Rect.Set( s - SB_WIDTH , 0 , s, SB_WIDTH ); } len = s - SB_WIDTH * 2; // - 2; b3Rect.Zero(); bpos = 0; if ( len <= 0 ) { return; } if ( si.size <= 0 ) { return; } if ( si.pageSize <= 0 || si.pageSize >= si.size ) { return; } bsize = ( int64( len ) * si.pageSize ) / si.size; if ( bsize < 5 ) { bsize = 5; } if ( len <= bsize ) { return; } int space = ( len - bsize ); bpos = ( int64( space ) * si.pos ) / ( si.size - si.pageSize ); if ( bpos > space ) { bpos = space; } int n = SB_WIDTH + bpos; if ( vertical ) { b3Rect.Set( 0, n, SB_WIDTH, n + bsize ); } else { b3Rect.Set( n , 0 , n + bsize, SB_WIDTH ); } } void ScrollBar::EventSize( cevent_size* pEvent ) { Recalc( &( pEvent->Size() ) ); } bool ScrollBar::Command( int id, int subId, Win* win, void* data ) { if ( id != CMD_SCROLL_INFO || win != managedWin ) { return false; } if ( ( vertical && subId != SCMD_SCROLL_VCHANGE ) || ( !vertical && subId != SCMD_SCROLL_HCHANGE ) ) { return false; } SetScrollInfo( ( ScrollInfo* )data ); return true; } void ScrollBar::SendManagedCmd( int subId, void* data ) { if ( managedWin ) { managedWin->Command( CMD_SCROLL_INFO, subId, this, data ); } else if ( Parent() ) { Parent()->Command( CMD_SCROLL_INFO, subId, this, data ); } } void ScrollBar::EventTimer( int tid ) { SendManagedCmd( tid, 0 ); } bool ScrollBar::EventMouse( cevent_mouse* pEvent ) { switch ( pEvent->Type() ) { case EV_MOUSE_MOVE: if ( trace ) { int p = vertical ? ( pEvent->Point().y - b1Rect.bottom ) : ( pEvent->Point().x - b1Rect.right ); p -= traceBPoint; int n = len - bsize; if ( n <= 0 ) { break; } //if (p>=n) p = n-1; //if (p<0) p = 0; int n1 = si.size - si.pageSize; int x = ( int64( p ) * n1 ) / n; if ( x >= n1 ) { x = n1; } if ( x < 0 ) { x = 0; } SendManagedCmd( SCMD_SCROLL_TRACK, &x ); //(void*)x); } break; case EV_MOUSE_DOUBLE: case EV_MOUSE_PRESS: if ( pEvent->Button() != MB_L ) { break; } { int subId = 0; if ( b1Rect.In( pEvent->Point() ) ) { b1Pressed = true; subId = ( vertical ) ? SCMD_SCROLL_LINE_UP : SCMD_SCROLL_LINE_LEFT; } else if ( b2Rect.In( pEvent->Point() ) ) { b2Pressed = true; subId = ( vertical ) ? SCMD_SCROLL_LINE_DOWN : SCMD_SCROLL_LINE_RIGHT; } else if ( b3Rect.In( pEvent->Point() ) ) { traceBPoint = ( vertical ) ? ( pEvent->Point().y - b3Rect.top ) : ( pEvent->Point().x - b3Rect.left ); trace = true; SetCapture(); break; } else if ( !b3Rect.IsEmpty() ) { if ( vertical ) { if ( pEvent->Point().y < b3Rect.top ) { subId = SCMD_SCROLL_PAGE_UP; } else { subId = SCMD_SCROLL_PAGE_DOWN; } } else { if ( pEvent->Point().x < b3Rect.left ) { subId = SCMD_SCROLL_PAGE_LEFT; } else { subId = SCMD_SCROLL_PAGE_RIGHT; } } } if ( subId != 0 ) { SetCapture(); SendManagedCmd( subId, 0 ); SetTimer( subId, 100 ); } } this->Invalidate(); break; case EV_MOUSE_RELEASE: if ( pEvent->Button() != MB_L ) { break; } if ( IsCaptured() ) { b1Pressed = false ; b2Pressed = false ; ReleaseCapture(); DelAllTimers(); Invalidate(); trace = false; } break; default: ; } return true; } ScrollBar::~ScrollBar() {} }; //namespace wal
if ( id == CMD_CANCEL ) { OnCancel(); } else { CloseDialog( id ); } return true; } return false; } int uiClassNCDialog = GetUiID( "NCDialog" ); int NCDialog::UiGetClassId() { return m_nId; // return uiClassNCDialog; } NCDialog::NCDialog( bool asChild, int nId, NCDialogParent* parent, const unicode_t* headerText, ButtonDataNode* blist ) //, unsigned bcolor, unsigned fcolor) : OperThreadWin( asChild ? Win::WT_CHILD : WT_MAIN /*WT_POPUP*/, 0, nId, parent ), //, &crect(0,0,300,100)), _shadow( parent ), // _fcolor(fcolor), // _bcolor(bcolor), _header( nId, this, headerText ), _lo( 9, 9 ), _buttonLo( 3, 16 ),
namespace wal { int uiClassSButton = GetUiID( "SButton" ); int SButton::UiGetClassId() { return uiClassSButton; } static unsigned short chPix[] = {7, 0x40, 0x60, 0x71, 0x3B, 0x1F, 0x0E, 0x04}; static unsigned short rbPix[] = {5, 0xE, 0x1F, 0x1F, 0x1F, 0xE}; static void DrawCB( GC& gc, int x, int y, bool isSet ) { gc.SetLine( CBC_BOXFRAME ); gc.MoveTo( x, y ); gc.LineTo( x + 13, y ); gc.LineTo( x + 13, y + 13 ); gc.LineTo( x, y + 13 ); gc.LineTo( x, y ); gc.SetFillColor( CBC_BOX_BG ); //CCC gc.FillRect( crect( x + 1, y + 1, x + 13, y + 13 ) ); if ( isSet ) { DrawPixelList( gc, chPix, x + 3, y + 3, CBC_CHECK ); } } static void DrawCE( GC& gc, int x, int y, bool isSet ) { gc.SetLine( CBC_BOXFRAME ); gc.SetFillColor( CBC_BOX_BG ); gc.Ellipce( crect( x, y, x + 13, y + 13 ) ); if ( isSet ) { DrawPixelList( gc, rbPix, x + 4, y + 4, CBC_CHECK ); } } void SButton::Change( bool _isSet ) { bool old = isSet; isSet = _isSet; if ( isSet != old && IsVisible() ) { Invalidate(); } if ( group > 0 && IsSet() && Parent() ) { Parent()->SendBroadcast( CMD_SBUTTON_INFO, IsSet() ? SCMD_SBUTTON_CHECKED : SCMD_SBUTTON_CLEARED, this, &isSet, 2 ); } if ( Parent() && isSet != old ) { Parent()->Command( CMD_SBUTTON_INFO, IsSet() ? SCMD_SBUTTON_CHECKED : SCMD_SBUTTON_CLEARED , this, &isSet ); } } SButton::SButton( int nId, Win* parent, unicode_t* txt, int _group, bool _isSet, crect* rect ) : Win( Win::WT_CHILD, Win::WH_TABFOCUS | WH_CLICKFOCUS, parent, rect, nId ), isSet( _isSet ), text( txt ), group( _group ) { if ( !rect ) { GC gc( this ); gc.Set( GetFont() ); cpoint p = gc.GetTextExtents( txt ); if ( p.y < 16 ) { p.y = 16; } p.x += 17 + 4; p.y += 2; SetLSize( LSize( p ) ); } Change( isSet ); } bool SButton::Broadcast( int id, int subId, Win* win, void* data ) { if ( id == CMD_SBUTTON_INFO && subId == SCMD_SBUTTON_CHECKED && win != this && group && IsSet() && ( ( SButton* )win )->group == group ) { Change( false ); return true; } return false; } void SButton::Paint( GC& gc, const crect& paintRect ) { crect cr = ClientRect(); unsigned colorBg = UiGetColor( uiBackground, 0, 0, 0xFFFFFF ); gc.SetFillColor( colorBg ); //CCC gc.FillRect( cr ); if ( group > 0 ) { DrawCE( gc, 1, ( cr.Height() - 13 ) / 2, IsSet() ); } else { DrawCB( gc, 1, ( cr.Height() - 13 ) / 2, IsSet() ); } gc.Set( GetFont() ); cpoint tsize = text.GetTextExtents(gc); gc.SetFillColor( colorBg ); //gc.SetTextColor( UiGetColor( uiColor, 0, 0, 0 ) ); //gc.TextOutF( 14 + 1 + 1 + 1 , ( cr.Height() - tsize.y ) / 2, text.data() ); UiCondList ucl; int color_text = UiGetColor(uiColor, uiItem, &ucl, 0x0); int color_hotkey = UiGetColor(uiHotkeyColor, uiItem, &ucl, 0x0); text.DrawItem(gc, 14 + 1 + 1 + 1, (cr.Height() - tsize.y) / 2, color_text, color_hotkey); if ( InFocus() ) { crect rect; rect.left = 14 + 2; rect.top = ( cr.Height() - tsize.y - 2 ) / 2; rect.right = rect.left + tsize.x + 4; rect.bottom = rect.top + tsize.y + 2; DrawBorder( gc, rect, UiGetColor( uiFocusFrameColor, 0, 0, 0 ) ); //CCC } } bool SButton::EventMouse( cevent_mouse* pEvent ) { switch ( pEvent->Type() ) { case EV_MOUSE_PRESS: break; case EV_MOUSE_RELEASE: if ( !IsEnabled() ) { break; } if ( group > 0 ) { if ( !IsSet() ) { Change( true ); } } else { Change( !IsSet() ); } break; }; return true; } bool SButton::EventKey( cevent_key* pEvent ) { if ( pEvent->Type() == EV_KEYUP && ( pEvent->Key() == VK_SPACE ) && IsEnabled() ) { if ( group > 0 ) { if ( !IsSet() ) { Change( true ); } } else { Change( !IsSet() ); } return true; } return false; } bool SButton::EventFocus( bool recv ) { Invalidate(); return true; } SButton::~SButton() {} }; // namespace wal
if (!PathList::Compare(sel, m_dataList.GetData(i)->name.data(), true)) { SetCurrent(i); Invalidate(); break; } } } } std::vector<unicode_t> PathListWin::GetItemText( const PathList::Data* Data ) const { return Data->name; } static const int uiFcColor = GetUiID("first-char-color"); void PathListWin::DrawItem(wal::GC& gc, int n, crect rect) { const PathList::Data* curr = m_dataList.GetData(n); if (curr) { std::vector<unicode_t> text = GetItemText( curr ); UiCondList ucl; if ((n % 2) == 0) { ucl.Set(uiOdd, true); } if (n == this->GetCurrent())
namespace wal { bool lessTLNode( TLNode* a, TLNode* b, void* ) { unicode_t* sa = a->str.data(), *sb = b->str.data(); while ( *sa && *sa == *sb ) { sa++; sb++; } return *sa < *sb; } int uiClassTextList = GetUiID( "TextList" ); int TextList::UiGetClassId() { return uiClassTextList; } TextList::TextList( WTYPE tp, unsigned hints, int nId, Win* _parent, SelectType st, BorderType bt, crect* rect ) : VListWin( tp, hints, nId, _parent, st, bt, rect ), valid( false ) { GC gc( this ); gc.Set( GetFont() ); cpoint ts = gc.GetTextExtents( ABCString ); fontW = ( ts.x / ABCStringLen ); fontH = ts.y + 2; this->SetItemSize( fontH + 1, GetItemWidth() ); //+1 for border if current } void TextList::DrawItem( GC& gc, int n, crect rect ) { if ( n >= 0 && n < list.count() ) { UiCondList ucl; if ( ( n % 2 ) == 0 ) { ucl.Set( uiOdd, true ); } if ( n == this->GetCurrent() ) { ucl.Set( uiCurrentItem, true ); } unsigned bg = UiGetColor( uiBackground, uiItem, &ucl, 0xFFFFFF ); unsigned textColor = UiGetColor( uiColor, uiItem, &ucl, 0 ); unsigned frameColor = UiGetColor( uiFrameColor, uiItem, &ucl, 0 );; bool frame = ( n == this->GetCurrent() ); gc.SetFillColor( bg ); gc.FillRect( rect ); unicode_t* txt = list[n].str.data(); if ( txt ) { gc.Set( GetFont() ); gc.SetTextColor( textColor ); gc.SetFillColor( bg ); gc.TextOutF( rect.left, rect.top + ( GetItemHeight() - fontH ) / 2, txt ); } if ( frame ) { DrawBorder( gc, rect, frameColor ); } } else { gc.SetFillColor( UiGetColor( uiBackground, uiItem, 0, 0xFFFFFF ) ); gc.FillRect( rect ); //CCC } } void TextList::Clear() { list.clear(); valid = false; SetCount( list.count() ); } void TextList::Append( const unicode_t* txt, int i, void* p ) { TLNode node( txt, i, p ); list.append( node ); valid = false; SetCount( list.count() ); } void TextList::DataRefresh() { if ( !valid ) { valid = true; GC gc( this ); gc.Set( GetFont() ); int X = 0; int cnt = list.count(); for ( int i = 0; i < cnt; i++ ) { if ( list[i].pixelWidth < 0 ) { list[i].pixelWidth = gc.GetTextExtents( list[i].str.data() ).x; } if ( list[i].pixelWidth > X ) { X = list[i].pixelWidth; } } if ( GetCount() != list.count() ) { SetCount( list.count() ); } if ( X != this->GetItemWidth() ) { SetItemSize( GetItemHeight(), X ); } CalcScroll(); Invalidate(); } } void TextList::SetHeightRange( LSRange range ) { LSize s = GetLSize(); range.minimal *= fontH; range.maximal *= fontH; range.ideal *= fontH; s.y = range; SetLSize( s ); } void TextList::SetWidthRange( LSRange range ) { LSize s = GetLSize(); range.minimal *= fontW; range.maximal *= fontW; range.ideal *= fontW; s.x = range; SetLSize( s ); } TextList::~TextList() {} }; // namespace wal
namespace wal { unicode_t ABCString[]={'A','B','C',0}; int ABCStringLen = 3; static cptr<cfont> pSysFont; static cfont *guiFont = 0; static char uiDefaultRules[] = "* {color: 0; background: 0xD8E9EC; focus-frame-color : 0x00A000; button-color: 0xD8E9EC; }" "*:current-item { color: 0xFFFFFF; background: 0x800000; }" "ScrollBar { button-color: 0xD8E9EC; }" "EditLine:!enabled { background: 0xD8E9EC; }" "EditLine {color: 0; background: 0xFFFFFF; mark-color: 0xFFFFFF; mark-background : 0x800000; }" //"Button {color: 0; background: 0xFFFFFF}" //"ButtonWin { color: 0xFFFFFF; background: 0 }" //"ButtonWin Button {color: 0; background: 0xB0B000 }" ; #ifdef _WIN32 void BaseInit() { static bool initialized = false; if (initialized) return; initialized =true; pSysFont = new cfont((HFONT)GetStockObject(DEFAULT_GUI_FONT)); guiFont = pSysFont.ptr(); // winColors[IC_BG] = ::GetSysColor(COLOR_BTNFACE); // winColors[IC_FG] = winColors[IC_TEXT] = ::GetSysColor(COLOR_BTNTEXT); // winColors[IC_GRAY_TEXT] = ::GetSysColor(COLOR_GRAYTEXT); UiReadMem(uiDefaultRules); } #else void BaseInit() { dbg_printf("BaseInit\n"); static bool initialized = false; if (initialized) return; initialized =true; GC gc((Win*)0); pSysFont = new cfont(gc,"fixed",12,cfont::Normal); // "helvetica",9); guiFont = pSysFont.ptr(); UiReadMem(uiDefaultRules); } #endif static cfont* _SysGetFont(Win *w, int fontId) { return guiFont; } cfont* (*SysGetFont)(Win *w, int fontId) = _SysGetFont; void Draw3DButtonW2(GC &gc, crect r, unsigned bg, bool up) { static unsigned hp1,lp1; static unsigned hp2,lp2; static unsigned lastBg = 0; static bool initialized = false; if (!initialized || lastBg != bg) { hp1 = ColorTone(bg, -10); lp1 = ColorTone(bg, -90); hp2 = ColorTone(bg, +150); lp2 = ColorTone(bg, -60); lastBg = bg; initialized = true; } unsigned php1,plp1,php2,plp2; if (up) { php1 = hp1; plp1 = lp1; php2 = hp2; plp2 = lp2; } else { php1 = lp1; plp1 = hp1; php2 = lp2; plp2 = hp2; } gc.SetLine(plp1); gc.MoveTo(r.right-1,r.top); gc.LineTo(r.right-1,r.bottom-1); gc.LineTo(r.left,r.bottom-1); gc.SetLine(php1); gc.LineTo(r.left,r.top); gc.LineTo(r.right-1,r.top); r.Dec(); gc.MoveTo(r.right-1, r.top); gc.SetLine(php2); gc.LineTo(r.left, r.top); gc.LineTo(r.left, r.bottom-1); gc.SetLine(plp2); gc.LineTo(r.right-1, r.bottom-1); gc.LineTo(r.right-1, r.top); } ////////////////////////////////////////// StaticLine cpoint StaticTextSize(GC &gc, const unicode_t *s, cfont *font) { cpoint p(0,0); if (font) gc.Set(font); while (*s) { const unicode_t *t = unicode_strchr(s,'\n'); int len = (t ? t-s : unicode_strlen(s)); cpoint c = gc.GetTextExtents(s,len); s +=len; if (t) s++; if (*s == '\r') s++; p.y += c.y; if (p.x<c.x) p.x = c.x; } return p; } void DrawStaticText(GC &gc, int x, int y, const unicode_t *s, cfont *font, bool transparent) { if (font) gc.Set(font); while (*s) { const unicode_t *t = unicode_strchr(s,'\n'); int len = (t ? t-s : unicode_strlen(s)); gc.TextOutF(x,y,s,len); cpoint c = gc.GetTextExtents(s,len); s +=len; if (t) s++; if (*s == '\r') s++; y += c.y; } } cpoint GetStaticTextExtent(GC &gc, const unicode_t *s, cfont *font) { cpoint res(0,0),c; if (font) gc.Set(font); while (*s) { const unicode_t *t = unicode_strchr(s,'\n'); int len = (t ? t-s : unicode_strlen(s)); c = gc.GetTextExtents(s,len); s +=len; if (t) s++; if (*s == '\r') s++; res.y += c.y; if (res.x < c.x) res.x = c.x; } return res; } int uiClassStatic = GetUiID("Static"); int StaticLine::UiGetClassId(){ return uiClassStatic;} StaticLine::StaticLine(int nId, Win *parent, const unicode_t *txt, crect *rect) : Win(Win::WT_CHILD, 0, parent, rect, nId), text(new_unicode_str(txt)) { if (!rect) { GC gc(this); SetLSize(LSize(GetStaticTextExtent(gc,txt,GetFont()))); } } void StaticLine::Paint(GC &gc, const crect &paintRect) { crect rect = ClientRect(); gc.SetFillColor(UiGetColor(uiBackground, 0,0, 0xFFFFFF)/*GetColor(0)*/); gc.FillRect(rect); //CCC gc.SetTextColor(UiGetColor(uiColor, 0,0, 0)/*GetColor(IsEnabled() ? IC_TEXT : IC_GRAY_TEXT)*/); //CCC gc.Set(GetFont()); DrawStaticText(gc,0,0,text.ptr()); } StaticLine::~StaticLine(){} //////////////////////////////////// ToolTip class TBToolTip: public Win { carray<unicode_t> text; public: TBToolTip(Win *parent, int x, int y, const unicode_t *s); virtual void Paint(wal::GC &gc, const crect &paintRect); virtual int UiGetClassId(); virtual ~TBToolTip(); }; int uiClassToolTip = GetUiID("ToolTip"); int TBToolTip::UiGetClassId(){ return uiClassToolTip; } TBToolTip::TBToolTip(Win *parent, int x, int y, const unicode_t *s) : Win(Win::WT_POPUP, 0, parent), text(new_unicode_str(s)) { wal::GC gc(this); cpoint p = GetStaticTextExtent(gc, s, GetFont()); Move(crect(x,y,x + p.x + 4, y + p.y + 2)); } void TBToolTip::Paint(wal::GC &gc, const crect &paintRect) { gc.SetFillColor(UiGetColor(uiBackground, 0,0, 0xFFFFFF)/*GetColor(IC_BG)*/); //0x80FFFF); crect r = ClientRect(); gc.FillRect(r); gc.SetTextColor(UiGetColor(uiColor, 0,0, 0)/*GetColor(IC_TEXT)*/); //gc.TextOutF(0,0,text.ptr()); DrawStaticText(gc, 2, 1, text.ptr(), GetFont(), false); } TBToolTip::~TBToolTip(){} static cptr<TBToolTip> tip; void ToolTipShow(Win *w, int x, int y, const unicode_t *s) { ToolTipHide(); if (!w) return; crect r = w->ScreenRect(); tip = new TBToolTip(w, r.left + x, r.top + y, s); tip->Enable(); tip->Show(Win::SHOW_INACTIVE); } void ToolTipShow(Win *w, int x, int y, const char *s) { ToolTipShow(w, x, y, utf8_to_unicode(s).ptr()); } void ToolTipHide() { tip = 0; } }; //anmespace wal
const int SPLITTER_WIDTH = 6; const int XSPACE = 3; const int YSPACE = 1; ToolBar::ToolBar( Win* parent, const crect* rect, int iconSize ) : Win( Win::WT_CHILD, 0, parent, rect ), _iconSize( iconSize ), _pressed( 0 ), _ticks( 0 ), _curTip( 0 ), _nextTip( 0 ) { OnChangeStyles(); } int uiClassToolBar = GetUiID( "ToolBar" ); int ToolBar::UiGetClassId() { return uiClassToolBar; } void ToolBar::RecalcItems() { // crect cr = ClientRect(); int x = 2; int y = 2; wal::GC gc( this ); gc.Set( GetFont() ); for ( size_t i = 0; i < _list.size(); i++ ) { Node* p = _list[i].ptr();