signs_gui.cpp

Go to the documentation of this file.
00001 /* $Id: signs_gui.cpp 21413 2010-12-05 22:25:08Z rubidium $ */
00002 
00003 /*
00004  * This file is part of OpenTTD.
00005  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
00006  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00007  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
00008  */
00009 
00012 #include "stdafx.h"
00013 #include "company_gui.h"
00014 #include "company_func.h"
00015 #include "signs_base.h"
00016 #include "signs_func.h"
00017 #include "debug.h"
00018 #include "command_func.h"
00019 #include "strings_func.h"
00020 #include "window_func.h"
00021 #include "map_func.h"
00022 #include "gfx_func.h"
00023 #include "viewport_func.h"
00024 #include "querystring_gui.h"
00025 #include "sortlist_type.h"
00026 #include "string_func.h"
00027 #include "core/geometry_func.hpp"
00028 #include "hotkeys.h"
00029 
00030 #include "table/strings.h"
00031 #include "table/sprites.h"
00032 
00038 struct FilterInfo {
00039   const char *string;  
00040   bool case_sensitive; 
00041 };
00042 
00043 struct SignList {
00048   typedef GUIList<const Sign *, FilterInfo> GUISignList;
00049 
00050   static const Sign *last_sign;
00051   GUISignList signs;
00052 
00053   char filter_string[MAX_LENGTH_SIGN_NAME_CHARS * MAX_CHAR_LENGTH]; 
00054   static bool match_case;                                           
00055 
00059   SignList()
00060   {
00061     filter_string[0] = '\0';
00062   }
00063 
00064   void BuildSignsList()
00065   {
00066     if (!this->signs.NeedRebuild()) return;
00067 
00068     DEBUG(misc, 3, "Building sign list");
00069 
00070     this->signs.Clear();
00071 
00072     const Sign *si;
00073     FOR_ALL_SIGNS(si) *this->signs.Append() = si;
00074 
00075     this->FilterSignList();
00076     this->signs.Compact();
00077     this->signs.RebuildDone();
00078   }
00079 
00081   static int CDECL SignNameSorter(const Sign * const *a, const Sign * const *b)
00082   {
00083     static char buf_cache[64];
00084     char buf[64];
00085 
00086     SetDParam(0, (*a)->index);
00087     GetString(buf, STR_SIGN_NAME, lastof(buf));
00088 
00089     if (*b != last_sign) {
00090       last_sign = *b;
00091       SetDParam(0, (*b)->index);
00092       GetString(buf_cache, STR_SIGN_NAME, lastof(buf_cache));
00093     }
00094 
00095     int r = strnatcmp(buf, buf_cache); // Sort by name (natural sorting).
00096 
00097     return r != 0 ? r : ((*a)->index - (*b)->index);
00098   }
00099 
00100   void SortSignsList()
00101   {
00102     if (!this->signs.Sort(&SignNameSorter)) return;
00103 
00104     /* Reset the name sorter sort cache */
00105     this->last_sign = NULL;
00106   }
00107 
00109   static bool CDECL SignNameFilter(const Sign * const *a, FilterInfo filter_info)
00110   {
00111     /* Get sign string */
00112     char buf1[MAX_LENGTH_SIGN_NAME_CHARS * MAX_CHAR_LENGTH];
00113     SetDParam(0, (*a)->index);
00114     GetString(buf1, STR_SIGN_NAME, lastof(buf1));
00115 
00116     return (filter_info.case_sensitive ? strstr(buf1, filter_info.string) : strcasestr(buf1, filter_info.string)) != NULL;
00117   }
00118 
00120   void FilterSignList()
00121   {
00122     FilterInfo filter_info = {this->filter_string, this->match_case};
00123     this->signs.Filter(&SignNameFilter, filter_info);
00124   }
00125 };
00126 
00127 const Sign *SignList::last_sign = NULL;
00128 bool SignList::match_case = false;
00129 
00131 enum SignListWidgets {
00132   SLW_CAPTION,
00133   SLW_LIST,
00134   SLW_SCROLLBAR,
00135   SLW_FILTER_TEXT,           
00136   SLW_FILTER_MATCH_CASE_BTN, 
00137   SLW_FILTER_CLEAR_BTN,      
00138 };
00139 
00141 enum SignListHotkeys {
00142   SLHK_FOCUS_FILTER_BOX, 
00143 };
00144 
00145 struct SignListWindow : QueryStringBaseWindow, SignList {
00146   int text_offset; 
00147   Scrollbar *vscroll;
00148 
00149   SignListWindow(const WindowDesc *desc, WindowNumber window_number) : QueryStringBaseWindow(MAX_LENGTH_SIGN_NAME_CHARS * MAX_CHAR_LENGTH, MAX_LENGTH_SIGN_NAME_CHARS)
00150   {
00151     this->CreateNestedTree(desc);
00152     this->vscroll = this->GetScrollbar(SLW_SCROLLBAR);
00153     this->FinishInitNested(desc, window_number);
00154     this->SetWidgetLoweredState(SLW_FILTER_MATCH_CASE_BTN, SignList::match_case);
00155 
00156     /* Initialize the text edit widget */
00157     this->afilter = CS_ALPHANUMERAL;
00158     InitializeTextBuffer(&this->text, this->edit_str_buf, MAX_LENGTH_SIGN_NAME_CHARS * MAX_CHAR_LENGTH, MAX_LENGTH_SIGN_NAME_CHARS, MAX_LENGTH_SIGN_NAME_PIXELS);
00159     ClearFilterTextWidget();
00160 
00161     /* Initialize the filtering variables */
00162     this->SetFilterString("");
00163 
00164     /* Create initial list. */
00165     this->signs.ForceRebuild();
00166     this->signs.ForceResort();
00167     this->BuildSignsList();
00168     this->SortSignsList();
00169     this->vscroll->SetCount(this->signs.Length());
00170   }
00171 
00176   void ClearFilterTextWidget()
00177   {
00178     this->edit_str_buf[0] = '\0';
00179     UpdateTextBufferSize(&this->text);
00180 
00181     this->SetWidgetDirty(SLW_FILTER_TEXT);
00182   }
00183 
00190   void SetFilterString(const char *new_filter_string)
00191   {
00192     /* check if there is a new filter string */
00193     if (!StrEmpty(new_filter_string)) {
00194       /* Copy new filter string */
00195       strecpy(this->filter_string, new_filter_string, lastof(this->filter_string));
00196 
00197       this->signs.SetFilterState(true);
00198 
00199       this->EnableWidget(SLW_FILTER_CLEAR_BTN);
00200     } else {
00201       /* There is no new string -> clear this->filter_string */
00202       this->filter_string[0] = '\0';
00203 
00204       this->signs.SetFilterState(false);
00205       this->DisableWidget(SLW_FILTER_CLEAR_BTN);
00206     }
00207 
00208     /* Repaint the clear button since its disabled state may have changed */
00209     this->SetWidgetDirty(SLW_FILTER_CLEAR_BTN);
00210 
00211     /* Rebuild the list of signs */
00212     this->InvalidateData();
00213   }
00214 
00215   virtual void OnPaint()
00216   {
00217     this->DrawWidgets();
00218     if (!this->IsShaded()) this->DrawEditBox(SLW_FILTER_TEXT);
00219   }
00220 
00221   virtual void DrawWidget(const Rect &r, int widget) const
00222   {
00223     switch (widget) {
00224       case SLW_LIST: {
00225         uint y = r.top + WD_FRAMERECT_TOP; // Offset from top of widget.
00226         /* No signs? */
00227         if (this->vscroll->GetCount() == 0) {
00228           DrawString(r.left + WD_FRAMETEXT_LEFT, r.right, y, STR_STATION_LIST_NONE);
00229           return;
00230         }
00231 
00232         bool rtl = _current_text_dir == TD_RTL;
00233         int sprite_offset_y = (FONT_HEIGHT_NORMAL - 10) / 2 + 1;
00234         uint icon_left  = 4 + (rtl ? r.right - this->text_offset : r.left);
00235         uint text_left  = r.left + (rtl ? WD_FRAMERECT_LEFT : this->text_offset);
00236         uint text_right = r.right - (rtl ? this->text_offset : WD_FRAMERECT_RIGHT);
00237 
00238         /* At least one sign available. */
00239         for (uint16 i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < this->vscroll->GetCount(); i++) {
00240           const Sign *si = this->signs[i];
00241 
00242           if (si->owner != OWNER_NONE) DrawCompanyIcon(si->owner, icon_left, y + sprite_offset_y);
00243 
00244           SetDParam(0, si->index);
00245           DrawString(text_left, text_right, y, STR_SIGN_NAME, TC_YELLOW);
00246           y += this->resize.step_height;
00247         }
00248         break;
00249       }
00250     }
00251   }
00252 
00253   virtual void SetStringParameters(int widget) const
00254   {
00255     if (widget == SLW_CAPTION) SetDParam(0, this->vscroll->GetCount());
00256   }
00257 
00258   virtual void OnClick(Point pt, int widget, int click_count)
00259   {
00260     switch (widget) {
00261       case SLW_LIST: {
00262         uint id_v = this->vscroll->GetScrolledRowFromWidget(pt.y, this, SLW_LIST, WD_FRAMERECT_TOP);
00263         if (id_v == INT_MAX) return;
00264 
00265         const Sign *si = this->signs[id_v];
00266         ScrollMainWindowToTile(TileVirtXY(si->x, si->y));
00267         break;
00268       }
00269       case SLW_FILTER_CLEAR_BTN:
00270         this->ClearFilterTextWidget(); // Empty the text in the EditBox widget
00271         this->SetFilterString("");     // Use empty text as filter text (= view all signs)
00272         break;
00273 
00274       case SLW_FILTER_MATCH_CASE_BTN:
00275         SignList::match_case = !SignList::match_case; // Toggle match case
00276         this->SetWidgetLoweredState(SLW_FILTER_MATCH_CASE_BTN, SignList::match_case); // Toggle button pushed state
00277         this->InvalidateData(); // Rebuild the list of signs
00278         break;
00279     }
00280   }
00281 
00282   virtual void OnResize()
00283   {
00284     this->vscroll->SetCapacityFromWidget(this, SLW_LIST, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM);
00285   }
00286 
00287   virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
00288   {
00289     switch (widget) {
00290       case SLW_LIST: {
00291         Dimension spr_dim = GetSpriteSize(SPR_COMPANY_ICON);
00292         this->text_offset = WD_FRAMETEXT_LEFT + spr_dim.width + 2; // 2 pixels space between icon and the sign text.
00293         resize->height = max<uint>(FONT_HEIGHT_NORMAL, GetSpriteSize(SPR_COMPANY_ICON).height);
00294         Dimension d = {this->text_offset + MAX_LENGTH_SIGN_NAME_PIXELS + WD_FRAMETEXT_RIGHT, WD_FRAMERECT_TOP + 5 * resize->height + WD_FRAMERECT_BOTTOM};
00295         *size = maxdim(*size, d);
00296         break;
00297       }
00298 
00299       case SLW_CAPTION:
00300         SetDParam(0, max<size_t>(1000, Sign::GetPoolSize()));
00301         *size = GetStringBoundingBox(STR_SIGN_LIST_CAPTION);
00302         size->height += padding.height;
00303         size->width  += padding.width;
00304         break;
00305     }
00306   }
00307 
00308   virtual EventState OnKeyPress(uint16 key, uint16 keycode)
00309   {
00310     EventState state = ES_NOT_HANDLED;
00311     switch (this->HandleEditBoxKey(SLW_FILTER_TEXT, key, keycode, state)) {
00312       case HEBR_EDITING:
00313         this->SetFilterString(this->text.buf);
00314         break;
00315 
00316       case HEBR_CONFIRM: // Enter pressed -> goto first sign in list
00317         if (this->signs.Length() >= 1) {
00318           const Sign *si = this->signs[0];
00319           ScrollMainWindowToTile(TileVirtXY(si->x, si->y));
00320         }
00321         return state;
00322 
00323       case HEBR_CANCEL: // ESC pressed, clear filter.
00324         this->OnClick(Point(), SLW_FILTER_CLEAR_BTN, 1); // Simulate click on clear button.
00325         this->UnfocusFocusedWidget();                    // Unfocus the text box.
00326         return state;
00327 
00328       case HEBR_NOT_FOCUSED: // The filter text box is not globaly focused.
00329         if (CheckHotkeyMatch(signlist_hotkeys, keycode, this) == SLHK_FOCUS_FILTER_BOX) {
00330           this->SetFocusedWidget(SLW_FILTER_TEXT);
00331           SetFocusedWindow(this); // The user has asked to give focus to the text box, so make sure this window is focused.
00332           state = ES_HANDLED;
00333         }
00334         break;
00335 
00336       default:
00337         NOT_REACHED();
00338     }
00339 
00340     if (state == ES_HANDLED) OnOSKInput(SLW_FILTER_TEXT);
00341 
00342     return state;
00343   }
00344 
00345   virtual void OnOSKInput(int widget)
00346   {
00347     if (widget == SLW_FILTER_TEXT) this->SetFilterString(this->text.buf);
00348   }
00349 
00350   virtual void OnMouseLoop()
00351   {
00352     this->HandleEditBox(SLW_FILTER_TEXT);
00353   }
00354 
00355 
00356   virtual void OnInvalidateData(int data)
00357   {
00358     /* When there is a filter string, we always need to rebuild the list even if
00359      * the amount of signs in total is unchanged, as the subset of signs that is
00360      * accepted by the filter might has changed.
00361      */
00362     if (data == 0 || !StrEmpty(this->filter_string)) { // New or deleted sign, or there is a filter string
00363       this->signs.ForceRebuild();
00364       this->BuildSignsList();
00365       this->SetWidgetDirty(SLW_CAPTION);
00366       this->vscroll->SetCount(this->signs.Length());
00367     } else { // Change of sign contents while there is no filter string
00368       this->signs.ForceResort();
00369     }
00370 
00371     this->SortSignsList();
00372   }
00373 
00374   static Hotkey<SignListWindow> signlist_hotkeys[];
00375 };
00376 
00377 Hotkey<SignListWindow> SignListWindow::signlist_hotkeys[] = {
00378   Hotkey<SignListWindow>('F', "focus_filter_box", SLHK_FOCUS_FILTER_BOX),
00379   HOTKEY_LIST_END(SignListWindow)
00380 };
00381 Hotkey<SignListWindow> *_signlist_hotkeys = SignListWindow::signlist_hotkeys;
00382 
00383 static const NWidgetPart _nested_sign_list_widgets[] = {
00384   NWidget(NWID_HORIZONTAL),
00385     NWidget(WWT_CLOSEBOX, COLOUR_GREY),
00386     NWidget(WWT_CAPTION, COLOUR_GREY, SLW_CAPTION), SetDataTip(STR_SIGN_LIST_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
00387     NWidget(WWT_SHADEBOX, COLOUR_GREY),
00388     NWidget(WWT_STICKYBOX, COLOUR_GREY),
00389   EndContainer(),
00390   NWidget(NWID_HORIZONTAL),
00391     NWidget(NWID_VERTICAL),
00392       NWidget(WWT_PANEL, COLOUR_GREY, SLW_LIST), SetMinimalSize(WD_FRAMETEXT_LEFT + 16 + MAX_LENGTH_SIGN_NAME_PIXELS + WD_FRAMETEXT_RIGHT, 50),
00393                 SetResize(1, 10), SetFill(1, 0), SetScrollbar(SLW_SCROLLBAR), EndContainer(),
00394       NWidget(NWID_HORIZONTAL),
00395         NWidget(WWT_PANEL, COLOUR_GREY), SetFill(1, 1),
00396           NWidget(WWT_EDITBOX, COLOUR_GREY, SLW_FILTER_TEXT), SetMinimalSize(80, 12), SetResize(1, 0), SetFill(1, 0), SetPadding(2, 2, 2, 2),
00397               SetDataTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP),
00398         EndContainer(),
00399         NWidget(WWT_TEXTBTN, COLOUR_GREY, SLW_FILTER_MATCH_CASE_BTN), SetDataTip(STR_SIGN_LIST_MATCH_CASE, STR_SIGN_LIST_MATCH_CASE_TOOLTIP),
00400         NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, SLW_FILTER_CLEAR_BTN), SetDataTip(STR_SIGN_LIST_CLEAR, STR_SIGN_LIST_CLEAR_TOOLTIP),
00401       EndContainer(),
00402     EndContainer(),
00403     NWidget(NWID_VERTICAL),
00404       NWidget(NWID_VERTICAL), SetFill(0, 1),
00405         NWidget(NWID_VSCROLLBAR, COLOUR_GREY, SLW_SCROLLBAR),
00406       EndContainer(),
00407       NWidget(WWT_RESIZEBOX, COLOUR_GREY),
00408     EndContainer(),
00409   EndContainer(),
00410 };
00411 
00412 static const WindowDesc _sign_list_desc(
00413   WDP_AUTO, 358, 138,
00414   WC_SIGN_LIST, WC_NONE,
00415   WDF_UNCLICK_BUTTONS,
00416   _nested_sign_list_widgets, lengthof(_nested_sign_list_widgets)
00417 );
00418 
00424 Window *ShowSignList()
00425 {
00426   return AllocateWindowDescFront<SignListWindow>(&_sign_list_desc, 0);
00427 }
00428 
00429 EventState SignListGlobalHotkeys(uint16 key, uint16 keycode)
00430 {
00431   int num = CheckHotkeyMatch<SignListWindow>(_signlist_hotkeys, keycode, NULL, true);
00432   if (num == -1) return ES_NOT_HANDLED;
00433   Window *w = ShowSignList();
00434   if (w == NULL) return ES_NOT_HANDLED;
00435   return w->OnKeyPress(key, keycode);
00436 }
00437 
00444 static bool RenameSign(SignID index, const char *text)
00445 {
00446   bool remove = StrEmpty(text);
00447   DoCommandP(0, index, 0, CMD_RENAME_SIGN | (StrEmpty(text) ? CMD_MSG(STR_ERROR_CAN_T_DELETE_SIGN) : CMD_MSG(STR_ERROR_CAN_T_CHANGE_SIGN_NAME)), NULL, text);
00448   return remove;
00449 }
00450 
00452 enum QueryEditSignWidgets {
00453   QUERY_EDIT_SIGN_WIDGET_CAPTION,
00454   QUERY_EDIT_SIGN_WIDGET_TEXT,
00455   QUERY_EDIT_SIGN_WIDGET_OK,
00456   QUERY_EDIT_SIGN_WIDGET_CANCEL,
00457   QUERY_EDIT_SIGN_WIDGET_DELETE,
00458   QUERY_EDIT_SIGN_WIDGET_PREVIOUS,
00459   QUERY_EDIT_SIGN_WIDGET_NEXT,
00460 };
00461 
00462 struct SignWindow : QueryStringBaseWindow, SignList {
00463   SignID cur_sign;
00464 
00465   SignWindow(const WindowDesc *desc, const Sign *si) : QueryStringBaseWindow(MAX_LENGTH_SIGN_NAME_CHARS * MAX_CHAR_LENGTH, MAX_LENGTH_SIGN_NAME_CHARS)
00466   {
00467     this->caption = STR_EDIT_SIGN_CAPTION;
00468     this->afilter = CS_ALPHANUMERAL;
00469 
00470     this->InitNested(desc);
00471 
00472     this->LowerWidget(QUERY_EDIT_SIGN_WIDGET_TEXT);
00473     UpdateSignEditWindow(si);
00474     this->SetFocusedWidget(QUERY_EDIT_SIGN_WIDGET_TEXT);
00475   }
00476 
00477   void UpdateSignEditWindow(const Sign *si)
00478   {
00479     char *last_of = &this->edit_str_buf[this->edit_str_size - 1]; // points to terminating '\0'
00480 
00481     /* Display an empty string when the sign hasnt been edited yet */
00482     if (si->name != NULL) {
00483       SetDParam(0, si->index);
00484       GetString(this->edit_str_buf, STR_SIGN_NAME, last_of);
00485     } else {
00486       GetString(this->edit_str_buf, STR_EMPTY, last_of);
00487     }
00488     *last_of = '\0';
00489 
00490     this->cur_sign = si->index;
00491     InitializeTextBuffer(&this->text, this->edit_str_buf, this->edit_str_size, this->max_chars, MAX_LENGTH_SIGN_NAME_PIXELS);
00492 
00493     this->SetWidgetDirty(QUERY_EDIT_SIGN_WIDGET_TEXT);
00494     this->SetFocusedWidget(QUERY_EDIT_SIGN_WIDGET_TEXT);
00495   }
00496 
00502   const Sign *PrevNextSign(bool next)
00503   {
00504     /* Rebuild the sign list */
00505     this->signs.ForceRebuild();
00506     this->signs.NeedResort();
00507     this->BuildSignsList();
00508     this->SortSignsList();
00509 
00510     /* Search through the list for the current sign, excluding
00511      * - the first sign if we want the previous sign or
00512      * - the last sign if we want the next sign */
00513     uint end = this->signs.Length() - (next ? 1 : 0);
00514     for (uint i = next ? 0 : 1; i < end; i++) {
00515       if (this->cur_sign == this->signs[i]->index) {
00516         /* We've found the current sign, so return the sign before/after it */
00517         return this->signs[i + (next ? 1 : -1)];
00518       }
00519     }
00520     /* If we haven't found the current sign by now, return the last/first sign */
00521     return this->signs[next ? 0 : this->signs.Length() - 1];
00522   }
00523 
00524   virtual void SetStringParameters(int widget) const
00525   {
00526     switch (widget) {
00527       case QUERY_EDIT_SIGN_WIDGET_CAPTION:
00528         SetDParam(0, this->caption);
00529         break;
00530     }
00531   }
00532 
00533   virtual void OnPaint()
00534   {
00535     this->DrawWidgets();
00536     if (!this->IsShaded()) this->DrawEditBox(QUERY_EDIT_SIGN_WIDGET_TEXT);
00537   }
00538 
00539   virtual void OnClick(Point pt, int widget, int click_count)
00540   {
00541     switch (widget) {
00542       case QUERY_EDIT_SIGN_WIDGET_PREVIOUS:
00543       case QUERY_EDIT_SIGN_WIDGET_NEXT: {
00544         const Sign *si = this->PrevNextSign(widget == QUERY_EDIT_SIGN_WIDGET_NEXT);
00545 
00546         /* Rebuild the sign list */
00547         this->signs.ForceRebuild();
00548         this->signs.NeedResort();
00549         this->BuildSignsList();
00550         this->SortSignsList();
00551 
00552         /* Scroll to sign and reopen window */
00553         ScrollMainWindowToTile(TileVirtXY(si->x, si->y));
00554         UpdateSignEditWindow(si);
00555         break;
00556       }
00557 
00558       case QUERY_EDIT_SIGN_WIDGET_DELETE:
00559         /* Only need to set the buffer to null, the rest is handled as the OK button */
00560         RenameSign(this->cur_sign, "");
00561         /* don't delete this, we are deleted in Sign::~Sign() -> DeleteRenameSignWindow() */
00562         break;
00563 
00564       case QUERY_EDIT_SIGN_WIDGET_OK:
00565         if (RenameSign(this->cur_sign, this->text.buf)) break;
00566         /* FALL THROUGH */
00567 
00568       case QUERY_EDIT_SIGN_WIDGET_CANCEL:
00569         delete this;
00570         break;
00571     }
00572   }
00573 
00574   virtual EventState OnKeyPress(uint16 key, uint16 keycode)
00575   {
00576     EventState state = ES_NOT_HANDLED;
00577     switch (this->HandleEditBoxKey(QUERY_EDIT_SIGN_WIDGET_TEXT, key, keycode, state)) {
00578       default: break;
00579 
00580       case HEBR_CONFIRM:
00581         if (RenameSign(this->cur_sign, this->text.buf)) break;
00582         /* FALL THROUGH */
00583 
00584       case HEBR_CANCEL: // close window, abandon changes
00585         delete this;
00586         break;
00587     }
00588     return state;
00589   }
00590 
00591   virtual void OnMouseLoop()
00592   {
00593     this->HandleEditBox(QUERY_EDIT_SIGN_WIDGET_TEXT);
00594   }
00595 
00596   virtual void OnOpenOSKWindow(int wid)
00597   {
00598     ShowOnScreenKeyboard(this, wid, QUERY_EDIT_SIGN_WIDGET_CANCEL, QUERY_EDIT_SIGN_WIDGET_OK);
00599   }
00600 };
00601 
00602 static const NWidgetPart _nested_query_sign_edit_widgets[] = {
00603   NWidget(NWID_HORIZONTAL),
00604     NWidget(WWT_CLOSEBOX, COLOUR_GREY),
00605     NWidget(WWT_CAPTION, COLOUR_GREY, QUERY_EDIT_SIGN_WIDGET_CAPTION), SetDataTip(STR_WHITE_STRING, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
00606   EndContainer(),
00607   NWidget(WWT_PANEL, COLOUR_GREY),
00608     NWidget(WWT_EDITBOX, COLOUR_GREY, QUERY_EDIT_SIGN_WIDGET_TEXT), SetMinimalSize(256, 12), SetDataTip(STR_EDIT_SIGN_SIGN_OSKTITLE, STR_NULL), SetPadding(2, 2, 2, 2),
00609   EndContainer(),
00610   NWidget(NWID_HORIZONTAL),
00611     NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, QUERY_EDIT_SIGN_WIDGET_OK), SetMinimalSize(61, 12), SetDataTip(STR_BUTTON_OK, STR_NULL),
00612     NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, QUERY_EDIT_SIGN_WIDGET_CANCEL), SetMinimalSize(60, 12), SetDataTip(STR_BUTTON_CANCEL, STR_NULL),
00613     NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, QUERY_EDIT_SIGN_WIDGET_DELETE), SetMinimalSize(60, 12), SetDataTip(STR_TOWN_VIEW_DELETE_BUTTON, STR_NULL),
00614     NWidget(WWT_PANEL, COLOUR_GREY), SetFill(1, 1), EndContainer(),
00615     NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, QUERY_EDIT_SIGN_WIDGET_PREVIOUS), SetMinimalSize(11, 12), SetDataTip(AWV_DECREASE, STR_EDIT_SIGN_PREVIOUS_SIGN_TOOLTIP),
00616     NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, QUERY_EDIT_SIGN_WIDGET_NEXT), SetMinimalSize(11, 12), SetDataTip(AWV_INCREASE, STR_EDIT_SIGN_NEXT_SIGN_TOOLTIP),
00617   EndContainer(),
00618 };
00619 
00620 static const WindowDesc _query_sign_edit_desc(
00621   WDP_AUTO, 0, 0,
00622   WC_QUERY_STRING, WC_NONE,
00623   WDF_CONSTRUCTION | WDF_UNCLICK_BUTTONS,
00624   _nested_query_sign_edit_widgets, lengthof(_nested_query_sign_edit_widgets)
00625 );
00626 
00627 void HandleClickOnSign(const Sign *si)
00628 {
00629   if (_ctrl_pressed && si->owner == _local_company) {
00630     RenameSign(si->index, NULL);
00631     return;
00632   }
00633   ShowRenameSignWindow(si);
00634 }
00635 
00636 void ShowRenameSignWindow(const Sign *si)
00637 {
00638   /* Delete all other edit windows */
00639   DeleteWindowById(WC_QUERY_STRING, 0);
00640 
00641   new SignWindow(&_query_sign_edit_desc, si);
00642 }
00643 
00644 void DeleteRenameSignWindow(SignID sign)
00645 {
00646   SignWindow *w = dynamic_cast<SignWindow *>(FindWindowById(WC_QUERY_STRING, 0));
00647 
00648   if (w != NULL && w->cur_sign == sign) delete w;
00649 }

Generated on Fri Mar 4 21:37:05 2011 for OpenTTD by  doxygen 1.6.1